Skip to content

Commit

Permalink
Coinbase cbBTC por address list
Browse files Browse the repository at this point in the history
  • Loading branch information
Subarna-Singh committed Feb 20, 2025
1 parent bd1b913 commit 50cb91b
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/sources/por-address-list/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({
description:
'The RPC URL to connect to the EVM chain the address manager contract is deployed to.',
type: 'string',
required: true,
required: false,
},
CHAIN_ID: {
description: 'The chain id to connect to for the RPC URL',
Expand All @@ -24,6 +24,11 @@ export const config = new AdapterConfig({
type: 'number',
default: 10_000,
},
COINBASE_CBBTC_API_ENDPOINT: {
description: 'An API endpoint for Coinbase cbBTC native BTC wallet address',
type: 'string',
default: 'https://coinbase.com/cbbtc/proof-of-reserves.json',
},
BEDROCK_UNIBTC_API_ENDPOINT: {
description: 'An API endpoint for Bedrock uniBTC native BTC wallet address',
type: 'string',
Expand Down
22 changes: 22 additions & 0 deletions packages/sources/por-address-list/src/endpoint/coinbaseCBBTC.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { PoRAddress } from '@chainlink/external-adapter-framework/adapter/por'
import { AdapterEndpoint } from '@chainlink/external-adapter-framework/adapter'
import { EmptyInputParameters } from '@chainlink/external-adapter-framework/validation/input-params'
import { config } from '../config'
import { coinbaseHttpTransport } from '../transport/coinbaseBTC'


export type BaseEndpointTypes = {
Parameters: EmptyInputParameters
Response: {
Result: null
Data: {
result: PoRAddress[]
}
}
Settings: typeof config.settings
}

export const endpoint = new AdapterEndpoint({
name: 'coinbaseBtcAddress',
transport: coinbaseHttpTransport,
})
1 change: 1 addition & 0 deletions packages/sources/por-address-list/src/endpoint/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { endpoint as address } from './address'
export { endpoint as solvBTC } from './solvBTC'
export { endpoint as bedrockBTC } from './bedrockBTC'
export { endpoint as coinbaseBTC} from './coinbaseCBBTC'
export { endpoint as multichainAddress } from './multichainAddress'
4 changes: 2 additions & 2 deletions packages/sources/por-address-list/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expose, ServerInstance } from '@chainlink/external-adapter-framework'
import { PoRAdapter } from '@chainlink/external-adapter-framework/adapter/por'
import { config } from './config'
import { address, solvBTC, bedrockBTC, multichainAddress } from './endpoint'
import { address, solvBTC, bedrockBTC, coinbaseBTC, multichainAddress } from './endpoint'

export const adapter = new PoRAdapter({
defaultEndpoint: address.name,
name: 'POR_ADDRESS_LIST',
config,
endpoints: [address, solvBTC, bedrockBTC, multichainAddress],
endpoints: [address, solvBTC, bedrockBTC, coinbaseBTC, multichainAddress],
rateLimiting: {
tiers: {
default: {
Expand Down
115 changes: 115 additions & 0 deletions packages/sources/por-address-list/src/transport/coinbaseBTC.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { HttpTransport } from '@chainlink/external-adapter-framework/transports'
import { BaseEndpointTypes } from '../endpoint/coinbaseCBBTC'

interface ResponseSchema {
schema: string
lastUpdatedAt: string
reservesTotal: {
amount: string
currency: {
name: string
}
network: {
name: string
}
}
reserveAddresses: {
address: string
balance: {
amount: string
currency: {
name: string
}
network: {
name: string
}
}
}[]
wrappedAssetsByNetwork: {
amount: string
currency: {
name: string
address: string
}
network: {
name: string
chainId: string
}
}[]
wrappedAssetsTotal: {
amount: string
currency: {
name: string
}
}
}

export type HttpTransportTypes = BaseEndpointTypes & {
Provider: {
RequestBody: never
ResponseBody: ResponseSchema
}
}

export const coinbaseHttpTransport = new HttpTransport<HttpTransportTypes>({
prepareRequests: (params, config) => {
return {
params,
request: {
baseURL: config.COINBASE_CBBTC_API_ENDPOINT,
},
}
},

parseResponse: (params, response) => {
if (!response.data) {
return [
{
params: params[0],
response: {
errorMessage: `The data provider didn't return any data for coinbaseBTC`,
statusCode: 502,
},
},
]
}

const addresses = getAddresses(response.data)

if (addresses.length == 0) {
return [
{
params: params[0],
response: {
errorMessage: `The data provider didn't return any address for coinbaseBTC`,
statusCode: 502,
},
},
]
}

return [
{
params: params[0],
response: {
result: null,
data: {
result: addresses,
},
},
},
]
},
})

const getAddresses = (
data: ResponseSchema,
) => {
return data.reserveAddresses
.map((d) => ({
address: d.address,
network: d.balance.network.name,
chainId: 'mainnet',
}))
.sort()
}

0 comments on commit 50cb91b

Please sign in to comment.