Skip to content

Commit fa47637

Browse files
authored
Update bedrock address list (#3569)
1 parent 0b81fee commit fa47637

File tree

8 files changed

+199
-26
lines changed

8 files changed

+199
-26
lines changed

.changeset/fuzzy-trees-act.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/por-address-list-adapter': patch
3+
---
4+
5+
Update bedrock address list

packages/sources/por-address-list/src/config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const config = new AdapterConfig({
2727
BEDROCK_UNIBTC_API_ENDPOINT: {
2828
description: 'An API endpoint for Bedrock uniBTC native BTC wallet address',
2929
type: 'string',
30-
default: 'https://bedrock-datacenter.rockx.com/uniBTC/reserve/address',
30+
default: 'https://bedrock-datacenter.rockx.com/data/tvl/reserve_with_native.json',
3131
},
3232
SOLVBTC_API_ENDPOINT: {
3333
description: 'An API endpoint for SolvBTC native BTC wallet address',
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
1-
import {
2-
PoRAddressEndpoint,
3-
PoRAddressResponse,
4-
} from '@chainlink/external-adapter-framework/adapter/por'
5-
import { EmptyInputParameters } from '@chainlink/external-adapter-framework/validation/input-params'
1+
import { PoRAddress, PoRTokenAddress } from '@chainlink/external-adapter-framework/adapter/por'
2+
import { AdapterEndpoint } from '@chainlink/external-adapter-framework/adapter'
3+
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
64
import { config } from '../config'
75
import { bedrockHttpTransport } from '../transport/bedrockUniBTC'
86

7+
export const inputParameters = new InputParameters(
8+
{
9+
type: {
10+
description:
11+
'The type of addresses you are looking for. BTC is native BTC address. tokens is for token-balance EA. vault is for eth-balance EA.',
12+
options: ['BTC', 'tokens', 'vault'],
13+
type: 'string',
14+
required: true,
15+
},
16+
},
17+
[
18+
{
19+
type: 'BTC',
20+
},
21+
],
22+
)
23+
924
export type BaseEndpointTypes = {
10-
Parameters: EmptyInputParameters
11-
Response: PoRAddressResponse
25+
Parameters: typeof inputParameters.definition
26+
Response: {
27+
Result: null
28+
Data: {
29+
result: PoRAddress[] | PoRTokenAddress[]
30+
}
31+
}
1232
Settings: typeof config.settings
1333
}
1434

15-
export const endpoint = new PoRAddressEndpoint({
35+
export const endpoint = new AdapterEndpoint({
1636
name: 'bedrockBtcAddress',
1737
transport: bedrockHttpTransport,
38+
inputParameters,
1839
})

packages/sources/por-address-list/src/transport/bedrockUniBTC.ts

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import { HttpTransport } from '@chainlink/external-adapter-framework/transports'
2+
import { TypeFromDefinition } from '@chainlink/external-adapter-framework/validation/input-params'
23
import { BaseEndpointTypes } from '../endpoint/bedrockBTC'
34

45
interface ResponseSchema {
5-
btc: string[]
6+
btc: {
7+
type: string
8+
addr: string
9+
}[]
610
evm: {
7-
[key: string]: string
11+
[key: string]: {
12+
chain_id: number
13+
vault: string
14+
tokens: string[]
15+
}
816
}
917
}
1018

19+
const VAULT_PLACEHOLDER = '0x0000000000000000000000000000000000000000'
20+
1121
export type HttpTransportTypes = BaseEndpointTypes & {
1222
Provider: {
1323
RequestBody: never
@@ -26,25 +36,31 @@ export const bedrockHttpTransport = new HttpTransport<HttpTransportTypes>({
2636
})
2737
},
2838
parseResponse: (params, response) => {
29-
if (!response.data || response.data.btc.length == 0) {
39+
if (!response.data) {
3040
return [
3141
{
3242
params: params[0],
3343
response: {
34-
errorMessage: `The data provider didn't return any address for solvBTC`,
44+
errorMessage: `The data provider didn't return any data for bedrockBTC`,
3545
statusCode: 502,
3646
},
3747
},
3848
]
3949
}
4050

41-
const addresses = response.data.btc
42-
.map((adr) => ({
43-
address: adr,
44-
network: 'bitcoin',
45-
chainId: 'mainnet',
46-
}))
47-
.sort()
51+
const addresses = getAddresses(params[0].type, response.data)
52+
53+
if (addresses.length == 0) {
54+
return [
55+
{
56+
params: params[0],
57+
response: {
58+
errorMessage: `The data provider didn't return any ${params[0].type} address for bedrockBTC`,
59+
statusCode: 502,
60+
},
61+
},
62+
]
63+
}
4864

4965
return [
5066
{
@@ -59,3 +75,36 @@ export const bedrockHttpTransport = new HttpTransport<HttpTransportTypes>({
5975
]
6076
},
6177
})
78+
79+
const getAddresses = (
80+
type: TypeFromDefinition<BaseEndpointTypes['Parameters']>['type'],
81+
data: ResponseSchema,
82+
) => {
83+
switch (type) {
84+
case 'BTC':
85+
return data.btc
86+
.map((d) => ({
87+
address: d.addr,
88+
network: 'bitcoin',
89+
chainId: 'mainnet',
90+
}))
91+
.sort()
92+
case 'tokens':
93+
return Object.entries(data.evm)
94+
.map(([_, value]) => ({
95+
chainId: value.chain_id.toString(),
96+
contractAddress: value.vault,
97+
wallets: value.tokens.filter((t) => t != VAULT_PLACEHOLDER).sort(),
98+
}))
99+
.sort()
100+
case 'vault':
101+
return Object.entries(data.evm)
102+
.filter(([_, value]) => value.tokens.includes(VAULT_PLACEHOLDER))
103+
.map(([key, value]) => ({
104+
address: value.vault,
105+
network: key,
106+
chainId: value.chain_id.toString(),
107+
}))
108+
.sort()
109+
}
110+
}

packages/sources/por-address-list/test-payload.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"network": "bitcoin",
1212
"batchSize": 100
1313
}, {
14-
"endpoint": "bedrockBtcAddress"
14+
"endpoint": "bedrockBtcAddress",
15+
"type": "BTC"
1516
}, {
1617
"endpoint": "solvBtcAddress"
1718
}, {

packages/sources/por-address-list/test/integration/__snapshots__/adapter.test.ts.snap

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ exports[`execute address endpoint should return success 1`] = `
6565
}
6666
`;
6767

68-
exports[`execute apiAddress endpoint bedrock should return success 1`] = `
68+
exports[`execute apiAddress endpoint bedrock BTC should return success 1`] = `
6969
{
7070
"data": {
7171
"result": [
@@ -90,6 +90,55 @@ exports[`execute apiAddress endpoint bedrock should return success 1`] = `
9090
}
9191
`;
9292

93+
exports[`execute apiAddress endpoint bedrock tokens should return success 1`] = `
94+
{
95+
"data": {
96+
"result": [
97+
{
98+
"chainId": "1",
99+
"contractAddress": "vault_1",
100+
"wallets": [
101+
"token_1",
102+
],
103+
},
104+
{
105+
"chainId": "56",
106+
"contractAddress": "vault_2",
107+
"wallets": [
108+
"token_2",
109+
],
110+
},
111+
],
112+
},
113+
"result": null,
114+
"statusCode": 200,
115+
"timestamps": {
116+
"providerDataReceivedUnixMs": 978347471111,
117+
"providerDataRequestedUnixMs": 978347471111,
118+
},
119+
}
120+
`;
121+
122+
exports[`execute apiAddress endpoint bedrock vault should return success 1`] = `
123+
{
124+
"data": {
125+
"result": [
126+
{
127+
"address": "vault_1",
128+
"chainId": "1",
129+
"network": "eth",
130+
},
131+
],
132+
},
133+
"result": null,
134+
"statusCode": 200,
135+
"timestamps": {
136+
"providerDataReceivedUnixMs": 978347471111,
137+
"providerDataRequestedUnixMs": 978347471111,
138+
},
139+
}
140+
`;
141+
93142
exports[`execute apiAddress endpoint solv should return success 1`] = `
94143
{
95144
"data": {

packages/sources/por-address-list/test/integration/adapter.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,32 @@ describe('execute', () => {
9090
})
9191

9292
describe('apiAddress endpoint', () => {
93-
it('bedrock should return success', async () => {
93+
it('bedrock BTC should return success', async () => {
9494
const data = {
9595
endpoint: 'bedrockBtcAddress',
96+
type: 'BTC',
97+
}
98+
mockBedRockResponseSuccess()
99+
const response = await testAdapter.request(data)
100+
expect(response.statusCode).toBe(200)
101+
expect(response.json()).toMatchSnapshot()
102+
})
103+
104+
it('bedrock tokens should return success', async () => {
105+
const data = {
106+
endpoint: 'bedrockBtcAddress',
107+
type: 'tokens',
108+
}
109+
mockBedRockResponseSuccess()
110+
const response = await testAdapter.request(data)
111+
expect(response.statusCode).toBe(200)
112+
expect(response.json()).toMatchSnapshot()
113+
})
114+
115+
it('bedrock vault should return success', async () => {
116+
const data = {
117+
endpoint: 'bedrockBtcAddress',
118+
type: 'vault',
96119
}
97120
mockBedRockResponseSuccess()
98121
const response = await testAdapter.request(data)

packages/sources/por-address-list/test/integration/fixtures-api.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import nock from 'nock'
22

3+
interface ResponseSchema {
4+
btc: {
5+
type: string
6+
addr: string
7+
}[]
8+
evm: {
9+
[key: string]: {
10+
chain_id: number
11+
vault: string
12+
tokens: string[]
13+
}
14+
}
15+
}
16+
317
export const mockBedRockResponseSuccess = (): nock.Scope =>
418
nock('http://bedrock', {
519
encodedQueryParams: true,
@@ -8,10 +22,21 @@ export const mockBedRockResponseSuccess = (): nock.Scope =>
822
.reply(
923
200,
1024
() => ({
11-
btc: ['btc_1', 'btc_2'],
25+
btc: [
26+
{ type: 'addr', addr: 'btc_1' },
27+
{ type: 'addr', addr: 'btc_2' },
28+
],
1229
evm: {
13-
'1': 'ABC',
14-
'10': 'DEF',
30+
eth: {
31+
chain_id: 1,
32+
vault: 'vault_1',
33+
tokens: ['token_1', '0x0000000000000000000000000000000000000000'],
34+
},
35+
bsc: {
36+
chain_id: 56,
37+
vault: 'vault_2',
38+
tokens: ['token_2'],
39+
},
1540
},
1641
}),
1742
[

0 commit comments

Comments
 (0)