Skip to content

Commit 0ecddb5

Browse files
authored
Added EURR endpoint to the-network-firm adapter (#2951)
1 parent fc9f556 commit 0ecddb5

File tree

11 files changed

+192
-4
lines changed

11 files changed

+192
-4
lines changed

.changeset/thick-cobras-complain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/the-network-firm-adapter': minor
3+
---
4+
5+
Added EURR endpoint
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { AdapterEndpoint } from '@chainlink/external-adapter-framework/adapter'
2+
import { SingleNumberResultResponse } from '@chainlink/external-adapter-framework/util'
3+
import { config } from '../config'
4+
import { httpTransport } from '../transport/eurr'
5+
import { EmptyInputParameters } from '@chainlink/external-adapter-framework/validation/input-params'
6+
7+
export type BaseEndpointTypes = {
8+
Parameters: EmptyInputParameters
9+
Response: SingleNumberResultResponse
10+
Settings: typeof config.settings
11+
}
12+
13+
export const endpoint = new AdapterEndpoint({
14+
name: 'eurr',
15+
transport: httpTransport,
16+
})
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
export { endpoint as backed } from './backed'
2+
export { endpoint as eurr } from './eurr'
13
export { endpoint as mco2 } from './mco2'
24
export { endpoint as stbt } from './stbt'
3-
export { endpoint as backed } from './backed'
45
export { endpoint as usdr } from './usdr'

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { expose, ServerInstance } from '@chainlink/external-adapter-framework'
22
import { Adapter } from '@chainlink/external-adapter-framework/adapter'
33
import { config } from './config'
4-
import { backed, mco2, stbt, usdr } from './endpoint'
4+
import { backed, eurr, mco2, stbt, usdr } from './endpoint'
55

66
export const adapter = new Adapter({
77
defaultEndpoint: mco2.name,
88
name: 'THE_NETWORK_FIRM',
99
config,
10-
endpoints: [mco2, stbt, backed, usdr],
10+
endpoints: [backed, eurr, mco2, stbt, usdr],
1111
rateLimiting: {
1212
tiers: {
1313
default: {
14-
rateLimit1m: 6,
14+
rateLimit1m: 30,
1515
},
1616
},
1717
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { HttpTransport } from '@chainlink/external-adapter-framework/transports'
2+
import { BaseEndpointTypes } from '../endpoint/eurr'
3+
4+
export interface ResponseSchema {
5+
accountName: string
6+
totalReserve: number
7+
totalToken: number
8+
timestamp: string
9+
ripcord: boolean
10+
ripcordDetails: string[]
11+
}
12+
13+
export type HttpTransportTypes = BaseEndpointTypes & {
14+
Provider: {
15+
RequestBody: never
16+
ResponseBody: ResponseSchema
17+
}
18+
}
19+
export const httpTransport = new HttpTransport<HttpTransportTypes>({
20+
prepareRequests: (params, config) => {
21+
return {
22+
params: params,
23+
request: {
24+
baseURL: config.API_ENDPOINT,
25+
url: '/EURR',
26+
},
27+
}
28+
},
29+
parseResponse: (params, response) => {
30+
// Return error if ripcord indicator true
31+
if (response.data.ripcord) {
32+
const message = `Ripcord indicator true. Details: ${response.data.ripcordDetails.join(', ')}`
33+
return [
34+
{
35+
params: params[0],
36+
response: {
37+
errorMessage: message,
38+
statusCode: 502,
39+
timestamps: {
40+
providerIndicatedTimeUnixMs: new Date(response.data.timestamp).getTime(),
41+
},
42+
},
43+
},
44+
]
45+
}
46+
47+
const result = response.data.totalReserve
48+
49+
if (typeof response.data.totalReserve === 'undefined') {
50+
return [
51+
{
52+
params: params[0],
53+
response: {
54+
errorMessage: `Response missing totalReserve`,
55+
statusCode: 502,
56+
timestamps: {
57+
providerIndicatedTimeUnixMs: new Date(response.data.timestamp).getTime(),
58+
},
59+
},
60+
},
61+
]
62+
}
63+
64+
return [
65+
{
66+
params: params[0],
67+
response: {
68+
result,
69+
data: {
70+
result,
71+
},
72+
timestamps: {
73+
providerIndicatedTimeUnixMs: new Date(response.data.timestamp).getTime(),
74+
},
75+
},
76+
},
77+
]
78+
},
79+
})

packages/sources/the-network-firm/test-payload.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
},
1010
{
1111
"endpoint": "usdr"
12+
},
13+
{
14+
"endpoint": "eurr"
1215
}
1316
]
1417
}

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

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ exports[`execute backed endpoint should return success 1`] = `
2727
}
2828
`;
2929

30+
exports[`execute eurr endpoint should return success 1`] = `
31+
{
32+
"data": {
33+
"result": 10000000,
34+
},
35+
"result": 10000000,
36+
"statusCode": 200,
37+
"timestamps": {
38+
"providerDataReceivedUnixMs": 978347471111,
39+
"providerDataRequestedUnixMs": 978347471111,
40+
"providerIndicatedTimeUnixMs": 1692617659477,
41+
},
42+
}
43+
`;
44+
3045
exports[`execute mco2 endpoint should return success 1`] = `
3146
{
3247
"data": {

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

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ exports[`execute backed endpoint when ripcord true should return error 1`] = `
1212
}
1313
`;
1414

15+
exports[`execute eurr endpoint when ripcord true should return error 1`] = `
16+
{
17+
"errorMessage": "Ripcord indicator true. Details: Balances",
18+
"statusCode": 502,
19+
"timestamps": {
20+
"providerDataReceivedUnixMs": 978347471111,
21+
"providerDataRequestedUnixMs": 978347471111,
22+
"providerIndicatedTimeUnixMs": 1692617659477,
23+
},
24+
}
25+
`;
26+
1527
exports[`execute stbt endpoint when ripcord true should return error 1`] = `
1628
{
1729
"errorMessage": "Ripcord indicator true. Details: Balances",

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

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
import * as nock from 'nock'
66
import {
77
mockBackedResponseSuccess,
8+
mockEurrResponseSuccess,
89
mockMCO2Response,
910
mockSTBTResponseSuccess,
1011
mockUSDRResponseSuccess,
@@ -93,4 +94,17 @@ describe('execute', () => {
9394
expect(response.json()).toMatchSnapshot()
9495
})
9596
})
97+
98+
describe('eurr endpoint', () => {
99+
it('should return success', async () => {
100+
const data = {
101+
endpoint: 'eurr',
102+
}
103+
mockEurrResponseSuccess()
104+
105+
const response = await testAdapter.request(data)
106+
expect(response.statusCode).toBe(200)
107+
expect(response.json()).toMatchSnapshot()
108+
})
109+
})
96110
})

packages/sources/the-network-firm/test/integration/fixtures.ts

+30
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,33 @@ export const mockUSDRResponseFailure = (): nock.Scope =>
169169
ripcordDetails: ['Balances'],
170170
})
171171
.persist()
172+
173+
export const mockEurrResponseSuccess = (): nock.Scope =>
174+
nock('https://api.oracle-services.ledgerlens.io/v1/chainlink/proof-of-reserves/', {
175+
encodedQueryParams: true,
176+
})
177+
.get('/EURR')
178+
.reply(200, {
179+
accountName: 'EURR',
180+
totalReserve: 10000000,
181+
totalToken: 10000000,
182+
timestamp: '2023-08-21T11:34:19.477Z',
183+
ripcord: false,
184+
ripcordDetails: [],
185+
})
186+
.persist()
187+
188+
export const mockEurrResponseFailure = (): nock.Scope =>
189+
nock('https://api.oracle-services.ledgerlens.io/v1/chainlink/proof-of-reserves/', {
190+
encodedQueryParams: true,
191+
})
192+
.get('/EURR')
193+
.reply(200, {
194+
accountName: 'EURR',
195+
totalReserve: 10000000,
196+
totalToken: 10000000,
197+
timestamp: '2023-08-21T11:34:19.477Z',
198+
ripcord: true,
199+
ripcordDetails: ['Balances'],
200+
})
201+
.persist()

packages/sources/the-network-firm/test/integration/ripcord.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
import * as nock from 'nock'
66
import {
77
mockBackedResponseFailure,
8+
mockEurrResponseFailure,
89
mockSTBTResponseFailure,
910
mockUSDRResponseFailure,
1011
} from './fixtures'
@@ -72,4 +73,16 @@ describe('execute', () => {
7273
expect(response.json()).toMatchSnapshot()
7374
})
7475
})
76+
77+
describe('eurr endpoint when ripcord true ', () => {
78+
it('should return error', async () => {
79+
const data = {
80+
endpoint: 'eurr',
81+
}
82+
mockEurrResponseFailure()
83+
const response = await testAdapter.request(data)
84+
expect(response.statusCode).toBe(502)
85+
expect(response.json()).toMatchSnapshot()
86+
})
87+
})
7588
})

0 commit comments

Comments
 (0)