-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd1b913
commit 50cb91b
Showing
5 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/sources/por-address-list/src/endpoint/coinbaseCBBTC.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
packages/sources/por-address-list/src/transport/coinbaseBTC.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |