Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-ducks-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/superstate-adapter': minor
---

Modify result data
21 changes: 20 additions & 1 deletion .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
18 changes: 9 additions & 9 deletions packages/sources/superstate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |

---

Expand Down
2 changes: 1 addition & 1 deletion packages/sources/superstate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"typescript": "5.8.3"
},
"dependencies": {
"@chainlink/external-adapter-framework": "2.8.0",
"@chainlink/external-adapter-framework": "2.11.0",
"@superstateinc/api-key-request": "0.1.4",
"date-fns": "3.6.0",
"date-fns-tz": "3.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/superstate/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
required: true,
},
TRANSACTION_API_KEY: {
description: 'Api key for /v2/transactions API endpoints',
Expand Down
9 changes: 9 additions & 0 deletions packages/sources/superstate/src/transport/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const END_TIME = '12:00:00'

type ReportValueType = typeof inputParameters.validated.reportValue

// Convert date string (MM/DD/YYYY) to Unix timestamp in milliseconds
const convertToTimestampMs = (dateString: string): number => {
const [month, day, year] = dateString.split('/').map(Number)
return Date.UTC(year, month - 1, day, 0, 0, 0, 0)
}

// Custom transport implementation that takes incoming requests, adds them into a SET, and makes requests to DP
// on a specific time every day, after receiving a signal from scheduler.
export class NavTransport implements Transport<BaseEndpointTypes> {
Expand Down Expand Up @@ -164,6 +170,9 @@ export class NavTransport implements Transport<BaseEndpointTypes> {
const response = {
data: {
result,
nav: Number(data.net_asset_value),
aum: Number(data.assets_under_management),
navDate: convertToTimestampMs(data.net_asset_value_date),
},
result,
statusCode: 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
exports[`execute price endpoint should return success - aum 1`] = `
{
"data": {
"aum": 88412710.73007037,
"nav": 10.170643,
"navDate": 1764028800000,
"result": 88412710.73007037,
},
"result": 88412710.73007037,
Expand All @@ -17,6 +20,9 @@ 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": 1764028800000,
"result": 10.170643,
},
"result": 10.170643,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/superstate/test/integration/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3975,6 +3975,28 @@ __metadata:
languageName: node
linkType: hard

"@chainlink/external-adapter-framework@npm:2.11.0":
version: 2.11.0
resolution: "@chainlink/external-adapter-framework@npm:2.11.0"
dependencies:
"@date-fns/tz": "npm:1.4.1"
ajv: "npm:8.17.1"
axios: "npm:1.13.2"
eventsource: "npm:4.0.0"
fastify: "npm:5.6.2"
ioredis: "npm:5.8.2"
mock-socket: "npm:9.3.1"
pino: "npm:10.1.0"
pino-pretty: "npm:13.1.2"
prom-client: "npm:15.1.3"
redlock: "npm:5.0.0-beta.2"
ws: "npm:8.18.3"
bin:
create-external-adapter: adapter-generator.js
checksum: 10/7a892deca87eacad95fe7032f92bbea70e52ead8f03041d40f5c159095874f9dba501ddd37d7404a9e2a9d091150cdd862f799a821ccd264016b7c18c0daef1d
languageName: node
linkType: hard

"@chainlink/external-adapter-framework@npm:2.11.1":
version: 2.11.1
resolution: "@chainlink/external-adapter-framework@npm:2.11.1"
Expand Down Expand Up @@ -5724,7 +5746,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.0"
"@superstateinc/api-key-request": "npm:0.1.4"
"@types/jest": "npm:^29.5.14"
"@types/node": "npm:22.14.1"
Expand Down
Loading