diff --git a/.changeset/warm-otters-prove.md b/.changeset/warm-otters-prove.md new file mode 100644 index 00000000000..e847e11d20c --- /dev/null +++ b/.changeset/warm-otters-prove.md @@ -0,0 +1,5 @@ +--- +'@chainlink/wbtc-address-set-adapter': major +--- + +Update wbtc-address-set to use V2 API diff --git a/.pnp.cjs b/.pnp.cjs index abb5972cd53..7feb5adbf53 100644 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -6377,6 +6377,27 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["npm:2.16.0", {\ + "packageLocation": "./.yarn/cache/@chainlink-external-adapter-framework-npm-2.16.0-d3eb751c90-428328556e.zip/node_modules/@chainlink/external-adapter-framework/",\ + "packageDependencies": [\ + ["@chainlink/external-adapter-framework", "npm:2.16.0"],\ + ["@date-fns/tz", "npm:1.5.0"],\ + ["@solana/kit", "virtual:e164854d300ea35b7fa3cd6a156e91619b18483c375f0e19e840c2407b9c2b3cb28559dd82b52bd774a11ef6eda89d1c73e1df84aa088be71b59fe686bdc8d15#npm:6.9.0"],\ + ["ajv", "npm:8.20.0"],\ + ["axios", "npm:1.16.1"],\ + ["ethers", "npm:6.16.0"],\ + ["eventsource", "npm:4.1.0"],\ + ["fastify", "npm:5.8.5"],\ + ["ioredis", "npm:5.11.0"],\ + ["mock-socket", "npm:9.3.1"],\ + ["pino", "npm:10.3.1"],\ + ["pino-pretty", "npm:13.1.3"],\ + ["prom-client", "npm:15.1.3"],\ + ["redlock", "npm:5.0.0-beta.2"],\ + ["ws", "virtual:e164854d300ea35b7fa3cd6a156e91619b18483c375f0e19e840c2407b9c2b3cb28559dd82b52bd774a11ef6eda89d1c73e1df84aa088be71b59fe686bdc8d15#npm:8.21.0"]\ + ],\ + "linkType": "HARD"\ + }],\ ["npm:2.8.0", {\ "packageLocation": "./.yarn/cache/@chainlink-external-adapter-framework-npm-2.8.0-2b0ebd2740-5eee866738.zip/node_modules/@chainlink/external-adapter-framework/",\ "packageDependencies": [\ @@ -8614,7 +8635,7 @@ const RAW_RUNTIME_STATE = ["workspace:packages/sources/wbtc-address-set", {\ "packageLocation": "./packages/sources/wbtc-address-set/",\ "packageDependencies": [\ - ["@chainlink/external-adapter-framework", "npm:2.11.6"],\ + ["@chainlink/external-adapter-framework", "npm:2.16.0"],\ ["@chainlink/wbtc-address-set-adapter", "workspace:packages/sources/wbtc-address-set"],\ ["@types/jest", "npm:29.5.14"],\ ["@types/node", "npm:22.14.1"],\ diff --git a/.yarn/cache/@chainlink-external-adapter-framework-npm-2.16.0-d3eb751c90-428328556e.zip b/.yarn/cache/@chainlink-external-adapter-framework-npm-2.16.0-d3eb751c90-428328556e.zip new file mode 100644 index 00000000000..a455fd70635 Binary files /dev/null and b/.yarn/cache/@chainlink-external-adapter-framework-npm-2.16.0-d3eb751c90-428328556e.zip differ diff --git a/packages/sources/wbtc-address-set/package.json b/packages/sources/wbtc-address-set/package.json index 7136320ea6d..2020c67bd50 100644 --- a/packages/sources/wbtc-address-set/package.json +++ b/packages/sources/wbtc-address-set/package.json @@ -37,7 +37,7 @@ "typescript": "5.8.3" }, "dependencies": { - "@chainlink/external-adapter-framework": "2.11.6", + "@chainlink/external-adapter-framework": "2.16.0", "tslib": "2.4.1" } } diff --git a/packages/sources/wbtc-address-set/src/transport/addresses.ts b/packages/sources/wbtc-address-set/src/transport/addresses.ts index 8c902e749fb..f311ff2a860 100644 --- a/packages/sources/wbtc-address-set/src/transport/addresses.ts +++ b/packages/sources/wbtc-address-set/src/transport/addresses.ts @@ -1,15 +1,20 @@ import { HttpTransport } from '@chainlink/external-adapter-framework/transports' import { BaseEndpointTypes } from '../endpoint/addresses' +const PAGE_SIZE = 500 + +interface AddressEntry { + id: string + address: string + balance?: string + type: 'custodial' | 'merchant' | 'deposit' +} + export interface ResponseSchema { - result: { - id: string - address: string - balance?: string - type: 'custodial' | 'merchant' | 'deposit' - verified: boolean - }[] - count: number + data: AddressEntry[] + total: number + pageIndex: number + pageSize: number } export type HttpTransportTypes = BaseEndpointTypes & { @@ -18,19 +23,44 @@ export type HttpTransportTypes = BaseEndpointTypes & { ResponseBody: ResponseSchema } } + +const mapCustodialAddress = (address: AddressEntry) => ({ + id: address.id, + address: address.address, + balance: address.balance, + type: address.type, + coin: 'btc', + chainId: 'mainnet', + network: 'bitcoin', +}) + export const httpTransport = new HttpTransport({ prepareRequests: (params, config) => { return [ { params, - request: { baseURL: config.ADDRESSES_ENDPOINT }, + request: { + baseURL: config.ADDRESSES_ENDPOINT, + params: { + pageSize: PAGE_SIZE, + pageIndex: 1, + }, + }, }, ] }, parseResponse: (params, response) => { - const result = response.data.result + const { data, total } = response.data + + if (total > data.length) { + throw new Error( + `wBTC custodial addresses API returned ${data.length} of ${total} addresses; increase PAGE_SIZE (currently ${PAGE_SIZE}) or add pagination`, + ) + } + + const result = data .filter((a) => a.type == 'custodial' && a.balance && Number(a.balance) > 0) - .map((a) => ({ ...a, coin: 'btc', chainId: 'mainnet', network: 'bitcoin' })) + .map(mapCustodialAddress) return [ { diff --git a/packages/sources/wbtc-address-set/test/integration/__snapshots__/adapter.test.ts.snap b/packages/sources/wbtc-address-set/test/integration/__snapshots__/adapter.test.ts.snap index 54069e4ed23..78f2d416e02 100644 --- a/packages/sources/wbtc-address-set/test/integration/__snapshots__/adapter.test.ts.snap +++ b/packages/sources/wbtc-address-set/test/integration/__snapshots__/adapter.test.ts.snap @@ -12,7 +12,6 @@ exports[`execute addresses endpoint should return success 1`] = ` "id": "601c5e4b11b1d4001e37091aa2618ee9", "network": "bitcoin", "type": "custodial", - "verified": false, }, ], }, diff --git a/packages/sources/wbtc-address-set/test/integration/fixtures.ts b/packages/sources/wbtc-address-set/test/integration/fixtures.ts index bfaac06e476..6a9c74051e9 100644 --- a/packages/sources/wbtc-address-set/test/integration/fixtures.ts +++ b/packages/sources/wbtc-address-set/test/integration/fixtures.ts @@ -6,26 +6,29 @@ export const mockAddressesResponseSuccess = (): nock.Scope => }) .persist() .get('/') + .query({ pageSize: '500', pageIndex: '1' }) .reply( 200, () => ({ - result: [ + data: [ { id: '601c5e4b11b1d4001e37091aa2618ee9', address: '31h6SJ58NqVrifuyXN5A19ByD6vgyKVHEY', balance: '123', type: 'custodial', - verified: false, + chain: 'btc', }, { id: '602412a8a8f831001e0395eeeca68779', address: '31rbKHDMsFpTF9T4u74osP24ZejMJnHukj', balance: '0', type: 'custodial', - verified: false, + chain: 'btc', }, ], - count: 1, + total: 2, + pageIndex: 1, + pageSize: 500, }), [ 'Content-Type', diff --git a/yarn.lock b/yarn.lock index 3195e0e81cb..b0bda4bd8be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3753,6 +3753,30 @@ __metadata: languageName: node linkType: hard +"@chainlink/external-adapter-framework@npm:2.16.0": + version: 2.16.0 + resolution: "@chainlink/external-adapter-framework@npm:2.16.0" + dependencies: + "@date-fns/tz": "npm:1.5.0" + "@solana/kit": "npm:6.9.0" + ajv: "npm:8.20.0" + axios: "npm:1.16.1" + ethers: "npm:6.16.0" + eventsource: "npm:4.1.0" + fastify: "npm:5.8.5" + ioredis: "npm:5.11.0" + mock-socket: "npm:9.3.1" + pino: "npm:10.3.1" + pino-pretty: "npm:13.1.3" + prom-client: "npm:15.1.3" + redlock: "npm:5.0.0-beta.2" + ws: "npm:8.21.0" + bin: + create-external-adapter: adapter-generator.js + checksum: 10/428328556ef58f80af31ba2a541ae6cbe799155e0052860a05e90ffd66f14461ce8b419da1430c14426a36ab5c797e13ba24f0f5c454a9fbf21ca7ea00f9ed28 + languageName: node + linkType: hard + "@chainlink/external-adapter-framework@npm:2.8.0": version: 2.8.0 resolution: "@chainlink/external-adapter-framework@npm:2.8.0" @@ -5746,7 +5770,7 @@ __metadata: version: 0.0.0-use.local resolution: "@chainlink/wbtc-address-set-adapter@workspace:packages/sources/wbtc-address-set" dependencies: - "@chainlink/external-adapter-framework": "npm:2.11.6" + "@chainlink/external-adapter-framework": "npm:2.16.0" "@types/jest": "npm:^29.5.14" "@types/node": "npm:22.14.1" nock: "npm:13.5.6"