diff --git a/.changeset/brave-ducks-yawn.md b/.changeset/brave-ducks-yawn.md new file mode 100644 index 0000000000..7df51cd597 --- /dev/null +++ b/.changeset/brave-ducks-yawn.md @@ -0,0 +1,5 @@ +--- +'@chainlink/superstate-adapter': minor +--- + +Modify result data diff --git a/.pnp.cjs b/.pnp.cjs index a3e6336536..3db96094bd 100644 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -8791,7 +8791,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./packages/sources/superstate/",\ "packageDependencies": [\ ["@chainlink/superstate-adapter", "workspace:packages/sources/superstate"],\ - ["@chainlink/external-adapter-framework", "npm:2.8.0"],\ + ["@chainlink/external-adapter-framework", "npm:2.11.1"],\ ["@superstateinc/api-key-request", "npm:0.1.4"],\ ["@types/jest", "npm:29.5.14"],\ ["@types/node", "npm:22.14.1"],\ diff --git a/packages/sources/superstate/README.md b/packages/sources/superstate/README.md index 6b760682fe..415b964725 100644 --- a/packages/sources/superstate/README.md +++ b/packages/sources/superstate/README.md @@ -6,15 +6,15 @@ This document was generated automatically. Please see [README Generator](../../s ## Environment Variables -| Required? | Name | Description | Type | Options | Default | -| :-------: | :--------------------: | :-------------------------------------------------------------------------------------------: | :----: | :-----: | :----------------------------: | -| | API_ENDPOINT | An API endpoint for Superstate | string | | `https://api.superstate.co/v1` | -| | TRANSACTION_API_KEY | Api key for /v2/transactions API endpoints | string | | | -| | TRANSACTION_API_SECRET | Api secret for /v2/transactions API endpoints | string | | | -| | LOOKBACK_DAYS | The number of days of historical data to retrieve | number | | `10` | -| | RETRY_INTERVAL_MS | The amount of time (in ms) to wait before sending a new request for getting an updated price. | number | | `60000` | -| | BACKGROUND_EXECUTE_MS | The amount of time the background execute should sleep before performing the next request | number | | `10000` | -| | NAV_CRON_INTERVAL_MIN | How many minutes do we wait between each cron job that fetches Nav | number | | `10` | +| Required? | Name | Description | Type | Options | Default | +| :-------: | :--------------------: | :-------------------------------------------------------------------------------------------: | :----: | :-----: | :-----: | +| ✅ | API_ENDPOINT | An API endpoint for Superstate | string | | | +| | TRANSACTION_API_KEY | Api key for /v2/transactions API endpoints | string | | | +| | TRANSACTION_API_SECRET | Api secret for /v2/transactions API endpoints | string | | | +| | LOOKBACK_DAYS | The number of days of historical data to retrieve | number | | `10` | +| | RETRY_INTERVAL_MS | The amount of time (in ms) to wait before sending a new request for getting an updated price. | number | | `60000` | +| | BACKGROUND_EXECUTE_MS | The amount of time the background execute should sleep before performing the next request | number | | `10000` | +| | NAV_CRON_INTERVAL_MIN | How many minutes do we wait between each cron job that fetches Nav | number | | `10` | --- diff --git a/packages/sources/superstate/package.json b/packages/sources/superstate/package.json index 0f599200a1..a3b45a38c2 100644 --- a/packages/sources/superstate/package.json +++ b/packages/sources/superstate/package.json @@ -35,7 +35,7 @@ "typescript": "5.8.3" }, "dependencies": { - "@chainlink/external-adapter-framework": "2.8.0", + "@chainlink/external-adapter-framework": "2.11.1", "@superstateinc/api-key-request": "0.1.4", "date-fns": "3.6.0", "date-fns-tz": "3.1.3", diff --git a/packages/sources/superstate/src/config/index.ts b/packages/sources/superstate/src/config/index.ts index b1cd91a98f..0c15150678 100644 --- a/packages/sources/superstate/src/config/index.ts +++ b/packages/sources/superstate/src/config/index.ts @@ -5,7 +5,7 @@ export const config = new AdapterConfig( API_ENDPOINT: { description: 'An API endpoint for Superstate', type: 'string', - default: 'https://api.superstate.co/v1', + default: 'https://api.superstate.com/v1', }, TRANSACTION_API_KEY: { description: 'Api key for /v2/transactions API endpoints', diff --git a/packages/sources/superstate/src/transport/nav.ts b/packages/sources/superstate/src/transport/nav.ts index 5bbf73e945..5e049d61e5 100644 --- a/packages/sources/superstate/src/transport/nav.ts +++ b/packages/sources/superstate/src/transport/nav.ts @@ -12,6 +12,7 @@ import schedule from 'node-schedule' import { BaseEndpointTypes, inputParameters } from '../endpoint/nav' import { AssetsUnderManagement, + convertToTimestampMs, getPreviousNonWeekendDay, getStartingAndEndingDates, isBeforeTime, @@ -164,6 +165,10 @@ export class NavTransport implements Transport { const response = { data: { result, + nav: Number(data.net_asset_value), + aum: Number(data.assets_under_management), + navDate: data.net_asset_value_date, + navDateTimestampMs: convertToTimestampMs(data.net_asset_value_date), }, result, statusCode: 200, diff --git a/packages/sources/superstate/src/transport/utils.ts b/packages/sources/superstate/src/transport/utils.ts index bd5e45ce7e..dc76ebd336 100644 --- a/packages/sources/superstate/src/transport/utils.ts +++ b/packages/sources/superstate/src/transport/utils.ts @@ -1,5 +1,5 @@ -import { formatInTimeZone } from 'date-fns-tz' import { format, isAfter, isBefore, isSaturday, isSunday, subDays } from 'date-fns' +import { formatInTimeZone } from 'date-fns-tz' export const NetAssetValue = 'net_asset_value' export const AssetsUnderManagement = 'assets_under_management' @@ -48,3 +48,9 @@ export const getPreviousNonWeekendDay = (timezone: string): string => { } return format(pnwd, 'MM/dd/yyyy') } + +// Convert date string (MM/DD/YYYY) to Unix timestamp in milliseconds +export const convertToTimestampMs = (dateString: string): number => { + const [month, day, year] = dateString.split('/').map(Number) + return Date.UTC(year, month - 1, day, 0, 0, 0, 0) +} diff --git a/packages/sources/superstate/test/integration/__snapshots__/adapter.test.ts.snap b/packages/sources/superstate/test/integration/__snapshots__/adapter.test.ts.snap index de8f7db2d3..1bf2218879 100644 --- a/packages/sources/superstate/test/integration/__snapshots__/adapter.test.ts.snap +++ b/packages/sources/superstate/test/integration/__snapshots__/adapter.test.ts.snap @@ -3,6 +3,10 @@ exports[`execute price endpoint should return success - aum 1`] = ` { "data": { + "aum": 88412710.73007037, + "nav": 10.170643, + "navDate": "11/26/2025", + "navDateTimestampMs": 1764115200000, "result": 88412710.73007037, }, "result": 88412710.73007037, @@ -17,6 +21,10 @@ exports[`execute price endpoint should return success - aum 1`] = ` exports[`execute price endpoint should return success - nav 1`] = ` { "data": { + "aum": 88412710.73007037, + "nav": 10.170643, + "navDate": "11/26/2025", + "navDateTimestampMs": 1764115200000, "result": 10.170643, }, "result": 10.170643, diff --git a/packages/sources/superstate/test/integration/adapter.test.ts b/packages/sources/superstate/test/integration/adapter.test.ts index 18811563a8..1b1994e23c 100644 --- a/packages/sources/superstate/test/integration/adapter.test.ts +++ b/packages/sources/superstate/test/integration/adapter.test.ts @@ -39,6 +39,7 @@ describe('execute', () => { const mockDate = new Date('2001-01-01T11:11:11.111Z') spy = jest.spyOn(Date, 'now').mockReturnValue(mockDate.getTime()) + process.env.API_ENDPOINT = 'http://test-api.com' process.env.TRANSACTION_API_KEY = 'fake-key' process.env.TRANSACTION_API_SECRET = 'fake-secret' process.env.BACKGROUND_EXECUTE_MS = process.env.BACKGROUND_EXECUTE_MS ?? '0' diff --git a/packages/sources/superstate/test/integration/fixtures.ts b/packages/sources/superstate/test/integration/fixtures.ts index 73667febcd..b75fb0e900 100644 --- a/packages/sources/superstate/test/integration/fixtures.ts +++ b/packages/sources/superstate/test/integration/fixtures.ts @@ -2,7 +2,7 @@ import nock from 'nock' import { getPreviousNonWeekendDay } from '../../src/transport/utils' export const mockResponseSuccess = (): nock.Scope => - nock('https://api.superstate.co/v1/funds', { + nock('http://test-api.com/funds', { encodedQueryParams: true, }) .get('/1/nav-daily') diff --git a/packages/sources/superstate/test/unit/utils.test.ts b/packages/sources/superstate/test/unit/utils.test.ts index 08e8fe32e0..050e072fcf 100644 --- a/packages/sources/superstate/test/unit/utils.test.ts +++ b/packages/sources/superstate/test/unit/utils.test.ts @@ -1,4 +1,5 @@ import { + convertToTimestampMs, getPreviousNonWeekendDay, getStartingAndEndingDates, isAfterTime, @@ -161,4 +162,52 @@ describe('timeFunctions', () => { expect(pnwd).toBe('05/17/2024') // Friday }) }) + + describe('convertToTimestampMs', () => { + it('should convert MM/DD/YYYY date string to Unix timestamp in milliseconds', () => { + const dateString = '01/23/2024' + const result = convertToTimestampMs(dateString) + // January 23, 2024 at 00:00:00 UTC + expect(result).toBe(1705968000000) + }) + + it('should handle single digit month and day', () => { + const dateString = '5/3/2024' + const result = convertToTimestampMs(dateString) + // May 3, 2024 at 00:00:00 UTC + expect(result).toBe(1714694400000) + }) + + it('should handle end of year date', () => { + const dateString = '12/31/2024' + const result = convertToTimestampMs(dateString) + // December 31, 2024 at 00:00:00 UTC + expect(result).toBe(1735603200000) + }) + + it('should handle start of year date', () => { + const dateString = '01/01/2025' + const result = convertToTimestampMs(dateString) + // January 1, 2025 at 00:00:00 UTC + expect(result).toBe(1735689600000) + }) + + it('should handle leap year date', () => { + const dateString = '02/29/2024' + const result = convertToTimestampMs(dateString) + // February 29, 2024 at 00:00:00 UTC (2024 is a leap year) + expect(result).toBe(1709164800000) + }) + + it('should return timestamp at midnight UTC', () => { + const dateString = '06/15/2024' + const result = convertToTimestampMs(dateString) + const date = new Date(result) + + expect(date.getUTCHours()).toBe(0) + expect(date.getUTCMinutes()).toBe(0) + expect(date.getUTCSeconds()).toBe(0) + expect(date.getUTCMilliseconds()).toBe(0) + }) + }) }) diff --git a/yarn.lock b/yarn.lock index 4d91ab5ec6..91cdba20d3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5724,7 +5724,7 @@ __metadata: version: 0.0.0-use.local resolution: "@chainlink/superstate-adapter@workspace:packages/sources/superstate" dependencies: - "@chainlink/external-adapter-framework": "npm:2.8.0" + "@chainlink/external-adapter-framework": "npm:2.11.1" "@superstateinc/api-key-request": "npm:0.1.4" "@types/jest": "npm:^29.5.14" "@types/node": "npm:22.14.1"