-
Notifications
You must be signed in to change notification settings - Fork 308
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
Showing
25 changed files
with
378 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@chainlink/ignition-address-list-adapter': major | ||
'@chainlink/proof-of-reserves-adapter': minor | ||
--- | ||
|
||
Add ignition address list |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Empty file.
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,3 @@ | ||
# Chainlink External Adapter for ignition-address-list | ||
|
||
This README will be generated automatically when code is merged to `main`. If you would like to generate a preview of the README, please run `yarn generate:readme ignition-address-list`. |
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,40 @@ | ||
{ | ||
"name": "@chainlink/ignition-address-list-adapter", | ||
"version": "0.0.0", | ||
"description": "Chainlink ignition-address-list adapter.", | ||
"keywords": [ | ||
"Chainlink", | ||
"LINK", | ||
"blockchain", | ||
"oracle", | ||
"ignition-address-list" | ||
], | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"repository": { | ||
"url": "https://github.com/smartcontractkit/external-adapters-js", | ||
"type": "git" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"clean": "rm -rf dist && rm -f tsconfig.tsbuildinfo", | ||
"prepack": "yarn build", | ||
"build": "tsc -b", | ||
"server": "node -e 'require(\"./index.js\").server()'", | ||
"server:dist": "node -e 'require(\"./dist/index.js\").server()'", | ||
"start": "yarn server:dist" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "27.5.2", | ||
"@types/node": "16.11.68", | ||
"nock": "13.5.4", | ||
"typescript": "5.0.4" | ||
}, | ||
"dependencies": { | ||
"@chainlink/external-adapter-framework": "1.5.0", | ||
"tslib": "2.4.1" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/sources/ignition-address-list/src/config/index.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,15 @@ | ||
import { AdapterConfig } from '@chainlink/external-adapter-framework/config' | ||
|
||
export const config = new AdapterConfig({ | ||
API_KEY: { | ||
description: 'An API key for Data Provider', | ||
type: 'string', | ||
required: true, | ||
sensitive: true, | ||
}, | ||
API_ENDPOINT: { | ||
description: 'An API endpoint for Data Provider', | ||
type: 'string', | ||
default: 'https://fbtc.phalcon.blocksec.com/api/v1/extension/fbtc-reserved-addr', | ||
}, | ||
}) |
41 changes: 41 additions & 0 deletions
41
packages/sources/ignition-address-list/src/endpoint/address.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,41 @@ | ||
import { InputParameters } from '@chainlink/external-adapter-framework/validation' | ||
import { | ||
PoRAddressEndpoint, | ||
PoRAddressResponse, | ||
} from '@chainlink/external-adapter-framework/adapter/por' | ||
import { config } from '../config' | ||
import { httpTransport } from '../transport/address' | ||
|
||
export const inputParameters = new InputParameters( | ||
{ | ||
network: { | ||
description: 'The network name to associate with the addresses', | ||
type: 'string', | ||
required: true, | ||
}, | ||
chainId: { | ||
description: 'The chain ID to associate with the addresses', | ||
type: 'string', | ||
required: true, | ||
}, | ||
}, | ||
[ | ||
{ | ||
network: 'bitcoin', | ||
chainId: 'mainnet', | ||
}, | ||
], | ||
) | ||
|
||
export type BaseEndpointTypes = { | ||
Parameters: typeof inputParameters.definition | ||
Response: PoRAddressResponse | ||
Settings: typeof config.settings | ||
} | ||
|
||
export const endpoint = new PoRAddressEndpoint({ | ||
name: 'address', | ||
aliases: [], | ||
transport: httpTransport, | ||
inputParameters, | ||
}) |
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 @@ | ||
export { endpoint as address } from './address' |
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,21 @@ | ||
import { expose, ServerInstance } from '@chainlink/external-adapter-framework' | ||
import { PoRAdapter } from '@chainlink/external-adapter-framework/adapter/por' | ||
import { config } from './config' | ||
import { address } from './endpoint' | ||
|
||
export const adapter = new PoRAdapter({ | ||
defaultEndpoint: address.name, | ||
name: 'IGNITION_ADDRESS_LIST', | ||
config, | ||
endpoints: [address], | ||
rateLimiting: { | ||
tiers: { | ||
default: { | ||
rateLimit1m: 6, | ||
note: 'The same IP address can only send one request within 5 seconds', | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
export const server = (): Promise<ServerInstance | undefined> => expose(adapter) |
63 changes: 63 additions & 0 deletions
63
packages/sources/ignition-address-list/src/transport/address.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,63 @@ | ||
import { HttpTransport } from '@chainlink/external-adapter-framework/transports' | ||
import { BaseEndpointTypes } from '../endpoint/address' | ||
|
||
export interface ResponseSchema { | ||
total_records: number | ||
result: { | ||
address: string | ||
address_type: string | ||
balance: number | ||
}[] | ||
} | ||
|
||
export type HttpTransportTypes = BaseEndpointTypes & { | ||
Provider: { | ||
RequestBody: never | ||
ResponseBody: ResponseSchema & { message: string } | ||
} | ||
} | ||
export const httpTransport = new HttpTransport<HttpTransportTypes>({ | ||
prepareRequests: (params, config) => { | ||
return params.map((param) => { | ||
return { | ||
params: [param], | ||
request: { | ||
baseURL: config.API_ENDPOINT, | ||
headers: { | ||
'access-token': config.API_KEY, | ||
}, | ||
}, | ||
} | ||
}) | ||
}, | ||
parseResponse: (params, response) => { | ||
return params.map((param) => { | ||
if (!response.data || response.data.result.length == 0) { | ||
return { | ||
params: param, | ||
response: { | ||
errorMessage: response.data?.message || `The data provider didn't return any value`, | ||
statusCode: 502, | ||
}, | ||
} | ||
} | ||
const addresses = response.data.result | ||
.map((r) => ({ | ||
address: r.address, | ||
network: param.network, | ||
chainId: param.chainId, | ||
})) | ||
.sort((a, b) => a.address.localeCompare(b.address)) | ||
|
||
return { | ||
params: param, | ||
response: { | ||
result: null, | ||
data: { | ||
result: addresses, | ||
}, | ||
}, | ||
} | ||
}) | ||
}, | ||
}) |
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,6 @@ | ||
{ | ||
"requests": [{ | ||
"network": "bitcoin", | ||
"chainId": "mainnet" | ||
}] | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/sources/ignition-address-list/test/integration/__snapshots__/adapter.test.ts.snap
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,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`execute address endpoint should return success 1`] = ` | ||
{ | ||
"data": { | ||
"result": [ | ||
{ | ||
"address": "bc1qhu98nf6ddz6ja73rn72encdr8ezsyhexwpdzap0vcs7lg2wpmrnq5ygfsl", | ||
"chainId": "mainnet", | ||
"network": "bitcoin", | ||
}, | ||
{ | ||
"address": "bc1qsdq75g6pmk6uz9a897pmgsmzr44822hg55adz8", | ||
"chainId": "mainnet", | ||
"network": "bitcoin", | ||
}, | ||
], | ||
}, | ||
"result": null, | ||
"statusCode": 200, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 978347471111, | ||
"providerDataRequestedUnixMs": 978347471111, | ||
}, | ||
} | ||
`; |
Oops, something went wrong.