Skip to content

Commit 229ac4c

Browse files
Feat/df 21516 uranium (#3926)
* DF-21516 the-network-firm uranium endpoint * add comment * add changeset
1 parent 03d4c1d commit 229ac4c

File tree

14 files changed

+294
-56
lines changed

14 files changed

+294
-56
lines changed

.changeset/lazy-coats-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/the-network-firm-adapter': minor
3+
---
4+
5+
Add uranium endpoint

packages/sources/the-network-firm/src/config/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,11 @@ export const config = new AdapterConfig({
1818
sensitive: true,
1919
default: '',
2020
},
21+
URANIUM_API_KEY: {
22+
description: 'API key used for uranium endpoint',
23+
type: 'string',
24+
required: false,
25+
sensitive: true,
26+
default: '',
27+
},
2128
})

packages/sources/the-network-firm/src/endpoint/emgemx.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
import {
2-
PoRProviderEndpoint,
3-
PoRProviderResponse,
4-
} from '@chainlink/external-adapter-framework/adapter/por'
5-
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
1+
import { PoRProviderEndpoint } from '@chainlink/external-adapter-framework/adapter/por'
62
import { AdapterInputError } from '@chainlink/external-adapter-framework/validation/error'
7-
import { config } from '../config'
3+
import { inputParameters } from '../transport/common'
84
import { httpTransport } from '../transport/emgemx'
95

10-
export const inputParameters = new InputParameters({})
11-
12-
export type BaseEndpointTypes = {
13-
Parameters: typeof inputParameters.definition
14-
Response: PoRProviderResponse
15-
Settings: typeof config.settings
16-
}
17-
186
export const endpoint = new PoRProviderEndpoint({
197
name: 'emgemx',
208
transport: httpTransport,

packages/sources/the-network-firm/src/endpoint/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export { endpoint as eurr } from './eurr'
44
export { endpoint as gift } from './gift'
55
export { endpoint as mco2 } from './mco2'
66
export { endpoint as stbt } from './stbt'
7+
export { endpoint as uranium } from './uranium'
78
export { endpoint as usdr } from './usdr'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { PoRProviderEndpoint } from '@chainlink/external-adapter-framework/adapter/por'
2+
import { AdapterInputError } from '@chainlink/external-adapter-framework/validation/error'
3+
import { inputParameters } from '../transport/common'
4+
import { httpTransport } from '../transport/uranium'
5+
6+
export const endpoint = new PoRProviderEndpoint({
7+
name: 'uranium',
8+
transport: httpTransport,
9+
inputParameters,
10+
customInputValidation: (_, adapterSettings): AdapterInputError | undefined => {
11+
if (!adapterSettings.URANIUM_API_KEY) {
12+
throw new AdapterInputError({
13+
statusCode: 500,
14+
message: 'missing URANIUM_API_KEY env var',
15+
})
16+
}
17+
return
18+
},
19+
})

packages/sources/the-network-firm/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { expose, ServerInstance } from '@chainlink/external-adapter-framework'
22
import { PoRAdapter } from '@chainlink/external-adapter-framework/adapter/por'
33
import { config } from './config'
4-
import { backed, emgemx, eurr, gift, mco2, stbt, usdr } from './endpoint'
4+
import { backed, emgemx, eurr, gift, mco2, stbt, uranium, usdr } from './endpoint'
55

66
export const adapter = new PoRAdapter({
77
defaultEndpoint: mco2.name,
88
name: 'THE_NETWORK_FIRM',
99
config,
10-
endpoints: [backed, eurr, gift, mco2, stbt, usdr, emgemx],
10+
endpoints: [backed, emgemx, eurr, gift, mco2, stbt, uranium, usdr],
1111
rateLimiting: {
1212
tiers: {
1313
default: {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { PoRProviderResponse } from '@chainlink/external-adapter-framework/adapter/por'
2+
import { ProviderRequestConfig } from '@chainlink/external-adapter-framework/transports'
3+
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
4+
import { TypeFromDefinition } from '@chainlink/external-adapter-framework/validation/input-params'
5+
import { config } from '../config'
6+
7+
export const inputParameters = new InputParameters({})
8+
9+
export type BaseEndpointTypes = {
10+
Parameters: typeof inputParameters.definition
11+
Response: PoRProviderResponse
12+
Settings: typeof config.settings
13+
}
14+
15+
export interface ResponseSchema {
16+
totalReserve: string
17+
totalToken: string
18+
ripcord: boolean
19+
ripcordDetails: string[]
20+
timestamp: string
21+
}
22+
23+
export type HttpTransportTypes = BaseEndpointTypes & {
24+
Provider: {
25+
RequestBody: never
26+
ResponseBody: ResponseSchema
27+
}
28+
}
29+
30+
export function prepareRequests(
31+
params: TypeFromDefinition<BaseEndpointTypes['Parameters']>[],
32+
baseURL: string,
33+
url: string,
34+
apikey: string,
35+
): ProviderRequestConfig<HttpTransportTypes> {
36+
return {
37+
params,
38+
request: {
39+
baseURL,
40+
url,
41+
headers: {
42+
apikey,
43+
},
44+
},
45+
}
46+
}

packages/sources/the-network-firm/src/transport/emgemx.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
11
import { HttpTransport } from '@chainlink/external-adapter-framework/transports'
2-
import { BaseEndpointTypes } from '../endpoint/emgemx'
3-
4-
export interface ResponseSchema {
5-
totalReserve: string
6-
totalToken: string
7-
ripcord: boolean
8-
ripcordDetails: string[]
9-
timestamp: string
10-
}
11-
12-
export type HttpTransportTypes = BaseEndpointTypes & {
13-
Provider: {
14-
RequestBody: never
15-
ResponseBody: ResponseSchema
16-
}
17-
}
2+
import { HttpTransportTypes, prepareRequests } from './common'
183

194
export const httpTransport = new HttpTransport<HttpTransportTypes>({
20-
prepareRequests: (params, config) => {
21-
return {
22-
params,
23-
request: {
24-
baseURL: config.ALT_API_ENDPOINT,
25-
url: '/emgemx-tdfkf3',
26-
headers: {
27-
apikey: config.EMGEMX_API_KEY,
28-
},
29-
},
30-
}
31-
},
5+
prepareRequests: (params, config) =>
6+
prepareRequests(params, config.ALT_API_ENDPOINT, '/emgemx-tdfkf3', config.EMGEMX_API_KEY),
327
parseResponse: (params, response) => {
338
return params.map((param) => {
349
const timestamps = {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { HttpTransport } from '@chainlink/external-adapter-framework/transports'
2+
import { makeLogger } from '@chainlink/external-adapter-framework/util'
3+
import { HttpTransportTypes, prepareRequests } from './common'
4+
5+
const logger = makeLogger('UraniumHTTPTransport')
6+
7+
export const httpTransport = new HttpTransport<HttpTransportTypes>({
8+
prepareRequests: (params, config) =>
9+
prepareRequests(
10+
params,
11+
config.ALT_API_ENDPOINT,
12+
'/uranium-digital-qohmmjqaf4jk',
13+
config.URANIUM_API_KEY,
14+
),
15+
parseResponse: (params, response) => {
16+
return params.map((param) => {
17+
const timestamps = {
18+
providerIndicatedTimeUnixMs: new Date(response.data.timestamp).getTime(),
19+
}
20+
21+
const reserve = response.data.totalReserve
22+
const supply = response.data.totalToken
23+
24+
if (!response.data || isNaN(Number(reserve)) || isNaN(Number(supply))) {
25+
return {
26+
params: param,
27+
response: {
28+
errorMessage:
29+
'Response is missing response fields (expected: totalReserve & totalToken)',
30+
ripcord: response.data.ripcord ?? undefined,
31+
statusCode: 502,
32+
timestamps,
33+
},
34+
}
35+
}
36+
37+
if (response.data.ripcord) {
38+
logger.debug(`Ripcord indicator true. Details: ${response.data.ripcordDetails.join(', ')}`)
39+
}
40+
41+
const result = Number(reserve)
42+
return {
43+
params: param,
44+
response: {
45+
result,
46+
data: {
47+
result,
48+
ripcord: response.data.ripcord,
49+
ripcordAsInt: Number(response.data.ripcord),
50+
},
51+
timestamps,
52+
},
53+
}
54+
})
55+
},
56+
})

packages/sources/the-network-firm/test/integration/__snapshots__/adapter.test.ts.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,36 @@ exports[`execute stbt endpoint should return success 1`] = `
107107
}
108108
`;
109109

110+
exports[`execute uranium endpoint should fail 1`] = `
111+
{
112+
"errorMessage": "Response is missing response fields (expected: totalReserve & totalToken)",
113+
"ripcord": true,
114+
"statusCode": 502,
115+
"timestamps": {
116+
"providerDataReceivedUnixMs": 978347471111,
117+
"providerDataRequestedUnixMs": 978347471111,
118+
"providerIndicatedTimeUnixMs": 1751500917131,
119+
},
120+
}
121+
`;
122+
123+
exports[`execute uranium endpoint should return success 1`] = `
124+
{
125+
"data": {
126+
"result": 1000000,
127+
"ripcord": false,
128+
"ripcordAsInt": 0,
129+
},
130+
"result": 1000000,
131+
"statusCode": 200,
132+
"timestamps": {
133+
"providerDataReceivedUnixMs": 978347471111,
134+
"providerDataRequestedUnixMs": 978347471111,
135+
"providerIndicatedTimeUnixMs": 1751500917131,
136+
},
137+
}
138+
`;
139+
110140
exports[`execute usdr endpoint should return success 1`] = `
111141
{
112142
"data": {

0 commit comments

Comments
 (0)