Skip to content

Commit 3ddd7ce

Browse files
Superstate EA: extend result as per OPDATA-5112 (#4325)
* Superstate EA: extend result as per OPDATA-5112 * Changeset * Update EA-Framework version and README * Update EA-Framework version * Update EA-Framework version * Fix ea-framework version * change navDate to timestamp in ms * Update lockfile * add zip file * Review changes * add new url, unit tests
1 parent d61b0e6 commit 3ddd7ce

File tree

12 files changed

+89
-15
lines changed

12 files changed

+89
-15
lines changed

.changeset/brave-ducks-yawn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/superstate-adapter': minor
3+
---
4+
5+
Modify result data

.pnp.cjs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sources/superstate/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ This document was generated automatically. Please see [README Generator](../../s
66

77
## Environment Variables
88

9-
| Required? | Name | Description | Type | Options | Default |
10-
| :-------: | :--------------------: | :-------------------------------------------------------------------------------------------: | :----: | :-----: | :----------------------------: |
11-
| | API_ENDPOINT | An API endpoint for Superstate | string | | `https://api.superstate.co/v1` |
12-
| | TRANSACTION_API_KEY | Api key for /v2/transactions API endpoints | string | | |
13-
| | TRANSACTION_API_SECRET | Api secret for /v2/transactions API endpoints | string | | |
14-
| | LOOKBACK_DAYS | The number of days of historical data to retrieve | number | | `10` |
15-
| | RETRY_INTERVAL_MS | The amount of time (in ms) to wait before sending a new request for getting an updated price. | number | | `60000` |
16-
| | BACKGROUND_EXECUTE_MS | The amount of time the background execute should sleep before performing the next request | number | | `10000` |
17-
| | NAV_CRON_INTERVAL_MIN | How many minutes do we wait between each cron job that fetches Nav | number | | `10` |
9+
| Required? | Name | Description | Type | Options | Default |
10+
| :-------: | :--------------------: | :-------------------------------------------------------------------------------------------: | :----: | :-----: | :-----: |
11+
| | API_ENDPOINT | An API endpoint for Superstate | string | | |
12+
| | TRANSACTION_API_KEY | Api key for /v2/transactions API endpoints | string | | |
13+
| | TRANSACTION_API_SECRET | Api secret for /v2/transactions API endpoints | string | | |
14+
| | LOOKBACK_DAYS | The number of days of historical data to retrieve | number | | `10` |
15+
| | RETRY_INTERVAL_MS | The amount of time (in ms) to wait before sending a new request for getting an updated price. | number | | `60000` |
16+
| | BACKGROUND_EXECUTE_MS | The amount of time the background execute should sleep before performing the next request | number | | `10000` |
17+
| | NAV_CRON_INTERVAL_MIN | How many minutes do we wait between each cron job that fetches Nav | number | | `10` |
1818

1919
---
2020

packages/sources/superstate/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"typescript": "5.8.3"
3636
},
3737
"dependencies": {
38-
"@chainlink/external-adapter-framework": "2.8.0",
38+
"@chainlink/external-adapter-framework": "2.11.1",
3939
"@superstateinc/api-key-request": "0.1.4",
4040
"date-fns": "3.6.0",
4141
"date-fns-tz": "3.1.3",

packages/sources/superstate/src/config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const config = new AdapterConfig(
55
API_ENDPOINT: {
66
description: 'An API endpoint for Superstate',
77
type: 'string',
8-
default: 'https://api.superstate.co/v1',
8+
default: 'https://api.superstate.com/v1',
99
},
1010
TRANSACTION_API_KEY: {
1111
description: 'Api key for /v2/transactions API endpoints',

packages/sources/superstate/src/transport/nav.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import schedule from 'node-schedule'
1212
import { BaseEndpointTypes, inputParameters } from '../endpoint/nav'
1313
import {
1414
AssetsUnderManagement,
15+
convertToTimestampMs,
1516
getPreviousNonWeekendDay,
1617
getStartingAndEndingDates,
1718
isBeforeTime,
@@ -164,6 +165,10 @@ export class NavTransport implements Transport<BaseEndpointTypes> {
164165
const response = {
165166
data: {
166167
result,
168+
nav: Number(data.net_asset_value),
169+
aum: Number(data.assets_under_management),
170+
navDate: data.net_asset_value_date,
171+
navDateTimestampMs: convertToTimestampMs(data.net_asset_value_date),
167172
},
168173
result,
169174
statusCode: 200,

packages/sources/superstate/src/transport/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { formatInTimeZone } from 'date-fns-tz'
21
import { format, isAfter, isBefore, isSaturday, isSunday, subDays } from 'date-fns'
2+
import { formatInTimeZone } from 'date-fns-tz'
33

44
export const NetAssetValue = 'net_asset_value'
55
export const AssetsUnderManagement = 'assets_under_management'
@@ -48,3 +48,9 @@ export const getPreviousNonWeekendDay = (timezone: string): string => {
4848
}
4949
return format(pnwd, 'MM/dd/yyyy')
5050
}
51+
52+
// Convert date string (MM/DD/YYYY) to Unix timestamp in milliseconds
53+
export const convertToTimestampMs = (dateString: string): number => {
54+
const [month, day, year] = dateString.split('/').map(Number)
55+
return Date.UTC(year, month - 1, day, 0, 0, 0, 0)
56+
}

packages/sources/superstate/test/integration/__snapshots__/adapter.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
exports[`execute price endpoint should return success - aum 1`] = `
44
{
55
"data": {
6+
"aum": 88412710.73007037,
7+
"nav": 10.170643,
8+
"navDate": "11/26/2025",
9+
"navDateTimestampMs": 1764115200000,
610
"result": 88412710.73007037,
711
},
812
"result": 88412710.73007037,
@@ -17,6 +21,10 @@ exports[`execute price endpoint should return success - aum 1`] = `
1721
exports[`execute price endpoint should return success - nav 1`] = `
1822
{
1923
"data": {
24+
"aum": 88412710.73007037,
25+
"nav": 10.170643,
26+
"navDate": "11/26/2025",
27+
"navDateTimestampMs": 1764115200000,
2028
"result": 10.170643,
2129
},
2230
"result": 10.170643,

packages/sources/superstate/test/integration/adapter.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('execute', () => {
3939
const mockDate = new Date('2001-01-01T11:11:11.111Z')
4040
spy = jest.spyOn(Date, 'now').mockReturnValue(mockDate.getTime())
4141

42+
process.env.API_ENDPOINT = 'http://test-api.com'
4243
process.env.TRANSACTION_API_KEY = 'fake-key'
4344
process.env.TRANSACTION_API_SECRET = 'fake-secret'
4445
process.env.BACKGROUND_EXECUTE_MS = process.env.BACKGROUND_EXECUTE_MS ?? '0'

packages/sources/superstate/test/integration/fixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import nock from 'nock'
22
import { getPreviousNonWeekendDay } from '../../src/transport/utils'
33

44
export const mockResponseSuccess = (): nock.Scope =>
5-
nock('https://api.superstate.co/v1/funds', {
5+
nock('http://test-api.com/funds', {
66
encodedQueryParams: true,
77
})
88
.get('/1/nav-daily')

0 commit comments

Comments
 (0)