Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/proof of reserves #184

Merged
merged 165 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 161 commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
e5ba1a3
Refactor Blockchair adapter for multiple endpoints
justinkaseman Nov 12, 2020
d8e7a1b
Add ExecuteWithDefaults global type
justinkaseman Nov 12, 2020
45c7aca
Blockchair balance endpoint
justinkaseman Nov 12, 2020
8124f9d
Update previous adapter's test execute calls with required Config type
justinkaseman Nov 12, 2020
e084d3e
Fix json-rpc/aion test for new execute type
justinkaseman Nov 12, 2020
776179e
Fix more tests for new Execute type
justinkaseman Nov 13, 2020
baafae2
Add ExecuteWithDefaults type to composite adapter
justinkaseman Nov 13, 2020
efeae85
Add to composite
justinkaseman Nov 13, 2020
da29a3f
Remove unneeded try/catch
justinkaseman Nov 13, 2020
8064967
Refactor Amberdata adapter
justinkaseman Nov 13, 2020
0dc1698
Balance endpoint returns original response
justinkaseman Nov 13, 2020
095c07a
Add Amberdata to composite adapter
justinkaseman Nov 13, 2020
0d1619f
Add SoChain integration (WIP)
krebernisak Oct 29, 2020
c713d34
Complete SoChain adapter & add to releases
justinkaseman Nov 11, 2020
d0edae2
Lint
justinkaseman Nov 11, 2020
af7c738
Add 'testnet' to ChainType def
justinkaseman Nov 11, 2020
9b9839d
Add BTC.com adapter
justinkaseman Nov 11, 2020
72f1ad2
Add BTC.com adapter to composite Proof of Reserves
justinkaseman Nov 11, 2020
374c7c3
Balance endpoint returns original response
justinkaseman Nov 13, 2020
152fc9d
Remove SoChain from btc PR
justinkaseman Nov 13, 2020
5452943
Add SoChain to composite adapter
justinkaseman Nov 11, 2020
82e4293
Replay SoChain adapter after rebase
justinkaseman Nov 13, 2020
450039a
Bring in changes from newer PoR adapter: balance endpoint returns res…
justinkaseman Nov 13, 2020
477703d
Refactor cryptoapis adapter with balance endpoint
justinkaseman Nov 13, 2020
4e09b70
Update README
justinkaseman Nov 13, 2020
6edc3bc
Fix price endpoint import
justinkaseman Nov 13, 2020
fb53767
Fix .eslint import
justinkaseman Nov 13, 2020
513832b
Balance endpoint returns original response
justinkaseman Nov 13, 2020
8e10172
Remove try/catches that were stifling fail from API_KEY not being upg…
justinkaseman Nov 13, 2020
7ff1725
Add to composite
justinkaseman Nov 13, 2020
ad52423
Remove console.log, update composite cryptoapis version
justinkaseman Nov 13, 2020
ed2909d
Add to CHANGELOG & regen lock file
justinkaseman Nov 19, 2020
456bef0
@chainlink/external-adapter to TypeScript
justinkaseman Nov 19, 2020
6dc6e78
Add additional types & move config to 'external-adapter/requester'
justinkaseman Nov 20, 2020
c4e31f7
Convert @chainlink/ea-bootstrap to TS
justinkaseman Nov 23, 2020
c76edb7
Fix cache test with mocked ExecuteWrappedResponse
justinkaseman Nov 23, 2020
c92cfeb
Requested changes
justinkaseman Dec 2, 2020
f7c50a1
Refactor wbtc-address-set, blockchain.com, & renvm-address-set with e…
justinkaseman Dec 2, 2020
33afc01
Fix Defi-Pulse composite adapter types
justinkaseman Dec 2, 2020
d841aec
Lint
justinkaseman Dec 2, 2020
0bfde56
Housekeeping on ea/package.json
justinkaseman Dec 2, 2020
be51971
Fix validator Error typings
justinkaseman Dec 2, 2020
14cc63d
Additional @ea/config tests
justinkaseman Dec 2, 2020
4399f06
Lint
justinkaseman Dec 2, 2020
32988f9
Type AdapterErrorResponse & redis cache keys
justinkaseman Dec 2, 2020
bbd8e0c
Ensure zip make command works for core @chainlink lib packages
justinkaseman Dec 2, 2020
9683a58
Add to CHANGELOG & regen lock file
justinkaseman Nov 19, 2020
33fdae9
Refactor Blockchair adapter for multiple endpoints
justinkaseman Nov 12, 2020
1ab0ed2
Blockchair balance endpoint
justinkaseman Nov 12, 2020
d00e3f8
Update previous adapter's test execute calls with required Config type
justinkaseman Nov 12, 2020
1b51492
Fix json-rpc/aion test for new execute type
justinkaseman Nov 12, 2020
75fbafc
Fix more tests for new Execute type
justinkaseman Nov 13, 2020
89dc0ca
Add ExecuteWithDefaults type to composite adapter
justinkaseman Nov 13, 2020
5d5b7ba
Add to composite
justinkaseman Nov 13, 2020
0022cd0
Remove unneeded try/catch
justinkaseman Nov 13, 2020
7f2db35
Update tests for @chainlink/adapter-test-helpers
justinkaseman Nov 19, 2020
9a61625
Add '-adapter' to package names
justinkaseman Dec 3, 2020
f5d23c6
Add Address & Account types
justinkaseman Dec 3, 2020
c0aa257
Add re-usable toVendorName method to Requester
justinkaseman Dec 3, 2020
8be7497
Make requested changes & bring in chainlink core TS changes
justinkaseman Dec 3, 2020
92f619a
Fix types for composite PoR
justinkaseman Dec 3, 2020
36c640e
doc: Modify CHANGELOG
justinkaseman Dec 4, 2020
299a89e
Refactor Blockchair adapter for multiple endpoints
justinkaseman Nov 12, 2020
c47a18c
Refactor Amberdata adapter
justinkaseman Nov 13, 2020
00b6abd
Balance endpoint returns original response
justinkaseman Nov 13, 2020
1fe8655
Add Amberdata to composite adapter
justinkaseman Nov 13, 2020
ae6f6fd
Requested changes
justinkaseman Dec 4, 2020
21915c4
Refactor Blockchair adapter for multiple endpoints
justinkaseman Nov 12, 2020
94624ab
Refactor Amberdata adapter
justinkaseman Nov 13, 2020
64a6fb5
Add SoChain integration (WIP)
krebernisak Oct 29, 2020
cdcd0e8
Complete SoChain adapter & add to releases
justinkaseman Nov 11, 2020
a22a5d4
Lint
justinkaseman Nov 11, 2020
103a762
Add 'testnet' to ChainType def
justinkaseman Nov 11, 2020
50ca114
Add BTC.com adapter
justinkaseman Nov 11, 2020
92a30a8
Add BTC.com adapter to composite Proof of Reserves
justinkaseman Nov 11, 2020
25a2738
Balance endpoint returns original response
justinkaseman Nov 13, 2020
afa180f
Remove SoChain from btc PR
justinkaseman Nov 13, 2020
5baf573
Remove console.log
justinkaseman Nov 13, 2020
06b8421
Requested changes
justinkaseman Dec 4, 2020
1e94de0
Add to CHANGELOG & regen lock file
justinkaseman Nov 19, 2020
a59c670
Refactor Blockchair adapter for multiple endpoints
justinkaseman Nov 12, 2020
8e428f2
Blockchair balance endpoint
justinkaseman Nov 12, 2020
c597008
Update previous adapter's test execute calls with required Config type
justinkaseman Nov 12, 2020
dad13ce
Fix json-rpc/aion test for new execute type
justinkaseman Nov 12, 2020
8efad8a
Fix more tests for new Execute type
justinkaseman Nov 13, 2020
f545ab0
Add ExecuteWithDefaults type to composite adapter
justinkaseman Nov 13, 2020
4c813d9
Add to composite
justinkaseman Nov 13, 2020
8d85341
Remove unneeded try/catch
justinkaseman Nov 13, 2020
114b6e2
Update tests for @chainlink/adapter-test-helpers
justinkaseman Nov 19, 2020
6144fec
Add Address & Account types
justinkaseman Dec 3, 2020
b9980b6
Add re-usable toVendorName method to Requester
justinkaseman Dec 3, 2020
0b3b12f
Make requested changes & bring in chainlink core TS changes
justinkaseman Dec 3, 2020
cd05d60
Fix types for composite PoR
justinkaseman Dec 3, 2020
37db870
doc: Modify CHANGELOG
justinkaseman Dec 4, 2020
df03b3a
Add Blockchair to composite implementations
justinkaseman Dec 8, 2020
5294226
Blockchair adapter
justinkaseman Dec 8, 2020
7dbeb01
btc.com adapter
justinkaseman Dec 8, 2020
89df544
cryptoapis adapter
justinkaseman Dec 8, 2020
8ce797d
Update CHANGELOG
justinkaseman Dec 8, 2020
9ff7b67
Merge branch 'develop' into feature/proof-of-reserves
justinkaseman Dec 8, 2020
3796fed
Add ea-factories package & make ExecuteFactory a generic
justinkaseman Dec 10, 2020
0d793c3
Config should be optional on ExecuteFactory
justinkaseman Dec 10, 2020
702e0ae
Add to CHANGELOG
justinkaseman Dec 10, 2020
3937550
Merge branch 'feature/impl-factories' into feature/proof-of-reserves
justinkaseman Dec 10, 2020
b8e2727
More requested changes & types
justinkaseman Dec 11, 2020
d7352ff
Start of balance EA-factory
justinkaseman Dec 11, 2020
9df1a6d
Requested changes
justinkaseman Dec 11, 2020
7cb9975
Merge branch 'develop' into feature/proof-of-reserves
justinkaseman Dec 11, 2020
8858ee0
Merge EA-factories
justinkaseman Dec 11, 2020
c819e90
Balance EA factory handles warnings & type improvements + additions
justinkaseman Dec 12, 2020
4a8318c
Amberdata dropped rinkeby testnet support
justinkaseman Dec 14, 2020
5e375a2
Add additional blockchains to balance test-helpers
justinkaseman Dec 14, 2020
965c1e3
Add balance ea-factory batch endpoint functionality
justinkaseman Dec 15, 2020
c9e16ae
Add more balance test helper networks
justinkaseman Dec 15, 2020
56f370b
Refactor PoR adapters with balance ea-factory
justinkaseman Dec 15, 2020
7a2aecb
Merge develop
justinkaseman Dec 15, 2020
e850c44
Add to github strategy
justinkaseman Dec 15, 2020
1f2002e
Add @chainlink/ea-factories dependency
justinkaseman Dec 15, 2020
af3a2ee
Regen yarn.lock
justinkaseman Dec 15, 2020
52c4247
Requested changes
justinkaseman Dec 15, 2020
a835234
Remove util package from strategy, add to workspaces
justinkaseman Dec 15, 2020
190b57b
Revert test changes from bad merge
justinkaseman Dec 15, 2020
302c4f5
Revert yarn.lock
justinkaseman Dec 15, 2020
d5e0acb
Wsrun uses serial mode to avoid parallelism
justinkaseman Dec 15, 2020
bb68218
Build core packages before adapters
justinkaseman Dec 15, 2020
a0e20d5
make build 2-step handles TS
justinkaseman Dec 15, 2020
44cd6e4
Attempt to fix TS 'cannot write file... because it would overwrite in…
justinkaseman Dec 15, 2020
68bba67
Revert
justinkaseman Dec 15, 2020
bdd2659
Fix circular type import
justinkaseman Dec 15, 2020
a68b303
build 2-step looks for actual adapter.js file
justinkaseman Dec 15, 2020
46943c0
Add file flag
justinkaseman Dec 15, 2020
c18d898
Requested changes round 4
justinkaseman Dec 16, 2020
dc5bdb8
https://github.com/smartcontractkit/external-adapters-js/issues/205
justinkaseman Dec 18, 2020
ccb0909
Revert setup script
justinkaseman Dec 18, 2020
38c4274
Merge branch 'develop' into feature/proof-of-reserves
justinkaseman Dec 18, 2020
b847ff2
Retry setup
justinkaseman Dec 18, 2020
788d8c4
Merge develop
justinkaseman Jan 5, 2021
59c0342
Add DNS-QUERY makeExecute generic type
justinkaseman Jan 5, 2021
e60576f
Add DNS-RECORD-CHECK makeExecute generic type
justinkaseman Jan 5, 2021
b13e2a6
Clean up types comment & unused data type
justinkaseman Jan 6, 2021
7a7e300
Balance adapters only give valid addresses to be processed by getBala…
justinkaseman Jan 6, 2021
967959c
Use returnVerboseResponse and remove overrideBalance env vars
justinkaseman Jan 6, 2021
07f9578
Merge branch 'develop' into feature/proof-of-reserves
justinkaseman Jan 6, 2021
38c5a87
returnVerboseResponse less verbose, balance ea processes accounts wit…
justinkaseman Jan 6, 2021
abd4b20
Fix boolean typo
justinkaseman Jan 6, 2021
82a01c5
Add 'clean' step to external-adapter setup script
justinkaseman Jan 7, 2021
8826111
merge develop
justinkaseman Jan 7, 2021
943aa0a
Remove adapter.js merge fragments from PoR adapters
justinkaseman Jan 7, 2021
e94513f
Reduce adapter uses BN
justinkaseman Jan 8, 2021
8ec7abe
Use correct reduce-adapter package
justinkaseman Jan 8, 2021
d70bd47
Fix: btc.com NAME needs an underscore
justinkaseman Jan 9, 2021
9b9296b
Fix: CryptoAPIs adapter uses correct data path for result
justinkaseman Jan 9, 2021
eeb2a2f
Reduce BigNumber package switched to 'bignumber.js' to handle floats
justinkaseman Jan 9, 2021
31d54f6
Merge develop
justinkaseman Jan 9, 2021
695e63c
Add Config type to merge from develop
justinkaseman Jan 9, 2021
7861c5f
Remove redundant Config type from merge
justinkaseman Jan 9, 2021
fa239f8
Merge branch 'develop' into feature/proof-of-reserves
krebernisak Jan 12, 2021
f24c1ff
Fix merge
krebernisak Jan 12, 2021
6e53693
Improve how PoR loads underlying adapters from the env
krebernisak Jan 12, 2021
7d041fb
Adds convertUnit util, sochain and cryptoapis balance endpoint return…
justinkaseman Jan 12, 2021
d911081
Requested changes
justinkaseman Jan 12, 2021
f6fc9d8
Fix to bootstrap util import
justinkaseman Jan 12, 2021
394855a
Apply suggestions from code review
krebernisak Jan 12, 2021
0b6d87c
Fix: argument given to convertUnits must be the coin
justinkaseman Jan 12, 2021
e917a94
Merge branch 'develop' into feature/proof-of-reserves
justinkaseman Jan 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- `finage` to get Financial data from finage.co.uk
- `coincodex` to get crypto prices from CoinCodex
- `coinranking` to get crypto prices from Coinranking
- `btc.com` to get on-chain balances from BTC.com
justinkaseman marked this conversation as resolved.
Show resolved Hide resolved
- `sochain` to get on-chain balances from SoChain
- `dns-query` to query DNS over HTTPS
- `dns-record-check` to check whether some record provided exists on DNS
- `outlier-detection`: composite adapter to check for outlier values between multiple sets of data providers
- `dydx-stark` to sign the input price data with your private STARK key, and send it to the destination endpoint.
- Added support for metadata in requests. This gives adapters access to the FM on-chain round state.
- Moves re-usable test behaviors & testing utils to a new package - `@chainlink/adapter-test-helpers`
- Added support for using query string parameters as input to adapters.
- Add a package re-usable adapter factory implementations to - `@chainlink/ea-factories`

- Added support for using multiple API Keys per-adapter

### Changed
Expand All @@ -32,7 +36,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Market closure is now a composite adapter, and now follows the build instructions for composite adapters. Market
now also supports using metadata.
- Coinlore now accepts an optional environment variable to set the default API endpoint
- migrates @chainlink/ea-bootstrap and @chainlink/external-adapter packages to TS.
- Migrates @chainlink/ea-bootstrap and @chainlink/external-adapter packages to TS.
- Updates the following adapters with a second endpoint for getting an account's on-chain balance
- `amberdata`
- `blockchair`
- `cryptoapis`
- dxFeed now uses OTC feeds for FTSE and N225, rather than licensed data feeds

### Removed
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ deps: clean
# Call the build script for the adapter if defined (TypeScript adapters have this extra build/compile step)
# We use `wsrun` to build workspace dependencies in topological order (TODO: use native `yarn workspaces foreach -pt run setup` with Yarn 2)
yarn wsrun -mre -p @chainlink/ea-bootstrap -t setup
yarn wsrun -mre -p @chainlink/ea-factories -t setup
yarn wsrun -mre -p @chainlink/external-adapter -t setup
yarn wsrun -mre -p @chainlink/$(if $(name),$(name),$(adapter))-adapter -t setup
yarn --frozen-lockfile --production
Expand All @@ -57,7 +58,10 @@ clean-2-step:

build-2-step:
cp -r $(adapter) 2-step/
mv 2-step/$(adapter)/adapter.js 2-step/$(adapter)/priceAdapter.js
if [ -f "2-step/$(adapter)/dist/adapter.js" ]; then \
krebernisak marked this conversation as resolved.
Show resolved Hide resolved
mv 2-step/$(adapter)/dist/adapter.js 2-step/$(adapter)/priceAdapter.js; \
else mv 2-step/$(adapter)/adapter.js 2-step/$(adapter)/priceAdapter.js; \
fi
cp 2-step/adapter.js 2-step/$(adapter)
cp -r helpers 2-step/helpers
npx @vercel/ncc@0.25.1 build 2-step/$(adapter) -o 2-step/$(adapter)/dist
Expand Down
4 changes: 3 additions & 1 deletion amberdata/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = require('../.eslintrc.js')
module.exports = {
...require('../.eslintrc.ts.js'),
}
140 changes: 126 additions & 14 deletions amberdata/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Chainlink External Adapter for Amberdata

## Configuration

The adapter takes the following environment variables:

- `API_KEY`: Optional API key to use
- `API_TIMEOUT`: Optional timeout param, defaults to `30000`

## Input Params

- `endpoint`: The endpoint to use, one of (price|balance). Default: "price"

### Price endpoint

Gets the [latest spot VWAP price](https://docs.amberdata.io/reference#spot-price-pair-latest) from Amberdata.

## Input Params
Expand All @@ -11,20 +24,119 @@ Gets the [latest spot VWAP price](https://docs.amberdata.io/reference#spot-price

```json
{
"jobRunID": "1",
"data": {
"status": 200,
"title": "OK",
"description": "Successful request",
"payload": {
"timestamp": 1603800660000,
"pair": "link_usd",
"price": "12.02087667",
"volume": "508.31"
"jobRunID": "1",
"data": {
"status": 200,
"title": "OK",
"description": "Successful request",
"payload": {
"timestamp": 1603800660000,
"pair": "link_usd",
"price": "12.02087667",
"volume": "508.31"
},
"result": 12.02087667
},
"result": 12.02087667,
"statusCode": 200
}
```

### Balance endpoint

- `dataPath`: Optional path where to find the addresses array, defaults to `result`
- `confirmations`: Optional confirmations param, defaults to `6`

- `addresses`: Addresses to query

{

- `address`: Address to query
- `coin`: Optional currency to query, defaults to `btc`, one of `(btc|eth|bch|ltc|btsv|zec)`
- `chain`: Optional chain to query, defaults to `mainnet`, one of `(mainnet|testnet)` when querying ethereum. Returns Rinkeby data.

}

```json
{
"id": "1",
"data": {
"addresses": [
{
"address": "3EyjZ6CtEZEKyc719NZMyWaJpJG5jsVJL1"
},
{
"address": "38bzm6nhQMFJe71jJw1U7CbgNrVNpkonZF"
}
],
"dataPath": "addresses"
}
}
```

### Output

```json
{
"jobRunID": "1",
"data": {
"responses": [
{
"status": 200,
"title": "OK",
"description": "Successful request",
"payload": {
"address": { "address": "3EyjZ6CtEZEKyc719NZMyWaJpJG5jsVJL1" },
"blockchainId": "408fa195a34b533de9ad9889f076045e",
"blockNumber": "656338",
"timestampNanoseconds": 0,
"value": "547",
"timestamp": "2020-11-10T19:54:09.000Z"
}
},
{
"status": 200,
"title": "OK",
"description": "Successful request",
"payload": {
"address": { "address": "38bzm6nhQMFJe71jJw1U7CbgNrVNpkonZF" },
"blockchainId": "408fa195a34b533de9ad9889f076045e",
"blockNumber": "653986",
"timestampNanoseconds": 0,
"value": "3282",
"timestamp": "2020-10-23T17:28:35.000Z"
}
}
],
"result": [
{
"address": "3EyjZ6CtEZEKyc719NZMyWaJpJG5jsVJL1",
"coin": "btc",
"chain": "mainnet",
"balance": "547"
},
{
"address": "38bzm6nhQMFJe71jJw1U7CbgNrVNpkonZF",
"coin": "btc",
"chain": "mainnet",
"balance": "3282"
}
]
},
"result": 12.02087667
},
"result": 12.02087667,
"statusCode": 200
"result": [
{
"address": "3EyjZ6CtEZEKyc719NZMyWaJpJG5jsVJL1",
"coin": "btc",
"chain": "mainnet",
"balance": "547"
},
{
"address": "38bzm6nhQMFJe71jJw1U7CbgNrVNpkonZF",
"coin": "btc",
"chain": "mainnet",
"balance": "3282"
}
],
justinkaseman marked this conversation as resolved.
Show resolved Hide resolved
"statusCode": 200
}
```
41 changes: 0 additions & 41 deletions amberdata/adapter.js

This file was deleted.

4 changes: 0 additions & 4 deletions amberdata/index.js

This file was deleted.

35 changes: 29 additions & 6 deletions amberdata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,37 @@
"name": "@chainlink/amberdata-adapter",
"version": "0.0.1",
"license": "MIT",
"main": "index.js",
"main": "dist/index.js",
"scripts": {
"server": "node -e 'require(\"./index.js\").server()'",
"prepublishOnly": "yarn build && yarn test:unit",
"setup": "yarn build",
"build": "tsc -b",
"lint": "eslint --ignore-path ../.eslintignore . --ext .js,.jsx,.ts,.tsx",
"lint:fix": "eslint --ignore-path ../.eslintignore . --ext .js,.jsx,.ts,.tsx --fix",
"test": "yarn _mocha --timeout 0",
"test:unit": "yarn _mocha --grep @integration --invert --timeout 0",
"test:integration": "yarn _mocha --grep @integration --timeout 0"
"test": "yarn test:unit && yarn test:integration",
"test:unit": "mocha --exit --grep @integration --invert -r ts-node/register 'test/**/*.test.ts'",
"test:integration": "mocha --timeout 5000 --exit --grep @integration -r ts-node/register 'test/**/*.test.ts'",
"server": "node -e 'require(\"./index.js\").server()'",
"server:dist": "node -e 'require(\"./dist/index.js\").server()'",
"start": "yarn server:dist"
},
"dependencies": {},
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/express": "^4.17.6",
"@types/mocha": "^7.0.2",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"ts-node": "^8.10.2",
"typescript": "^3.9.7"
},
"repository": {
"url": "https://github.com/smartcontractkit/external-adapters-js",
"type": "git"
},
"dependencies": {}
"types": "dist/index.d.ts",
"files": [
"dist"
]
}
39 changes: 39 additions & 0 deletions amberdata/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Requester, Validator, AdapterError } from '@chainlink/external-adapter'
import { ExecuteWithConfig, ExecuteFactory, Config } from '@chainlink/types'
import { makeConfig, DEFAULT_ENDPOINT } from './config'
import { price, balance } from './endpoint'

const inputParams = {
endpoint: false,
}

// Export function to integrate with Chainlink node
export const execute: ExecuteWithConfig<Config> = async (request, config) => {
const validator = new Validator(request, inputParams)
if (validator.error) throw validator.error

Requester.logConfig(config)

const jobRunID = validator.validated.id
const endpoint = validator.validated.data.endpoint || DEFAULT_ENDPOINT

switch (endpoint) {
case price.Name: {
return price.execute(request, config)
}
case balance.Name: {
return balance.makeExecute(config)(request)
}
default: {
throw new AdapterError({
jobRunID,
message: `Endpoint ${endpoint} not supported.`,
statusCode: 400,
})
}
}
}

export const makeExecute: ExecuteFactory<Config> = (config) => {
return async (request) => execute(request, config || makeConfig())
}
13 changes: 13 additions & 0 deletions amberdata/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Requester } from '@chainlink/external-adapter'
import { Config } from '@chainlink/types'

export const DEFAULT_API_ENDPOINT = 'https://web3api.io'

export const DEFAULT_ENDPOINT = 'price'

export const makeConfig = (prefix = ''): Config => {
const config = Requester.getDefaultConfig(prefix)
config.api.headers['x-api-key'] = config.apiKey
config.api.baseURL = config.api.baseURL || DEFAULT_API_ENDPOINT
return config
}
34 changes: 34 additions & 0 deletions amberdata/src/endpoint/balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { balance } from '@chainlink/ea-factories'
import { Config } from '@chainlink/types'
import { Requester } from '@chainlink/external-adapter'
import { isChainType, isCoinType, BLOCKCHAINS } from '.'

export const Name = 'balance'

const getBalanceURI = (address: string) => `/api/v2/addresses/${address}/account-balances/latest`

const getBlockchainHeader = (chain?: string, coin?: string) => {
const network = Requester.toVendorName(coin, BLOCKCHAINS)
return `${network}-mainnet`
}

const getBalance: balance.GetBalance = async (account, config) => {
const reqConfig: any = {
...config.api,
url: getBalanceURI(account.address),
headers: {
...config.api.headers,
'x-amberdata-blockchain-id': getBlockchainHeader(account.chain, account.coin),
},
}

const response = await Requester.request(reqConfig)
return {
payload: response.data,
result: [{ ...account, balance: response.data.payload.value }],
}
}

const isSupported: balance.IsSupported = (coin, chain) => isChainType(chain) && isCoinType(coin)

export const makeExecute = (config: Config) => balance.make({ ...config, getBalance, isSupported })
Loading