Skip to content

Commit

Permalink
[DO NOT MERGE] Refactor Anchorage input params (#3433)
Browse files Browse the repository at this point in the history
* anchorage changes

* remove apiKeyName input

---------

Co-authored-by: app-token-issuer-data-feeds[bot] <134377064+app-token-issuer-data-feeds[bot]@users.noreply.github.com>
  • Loading branch information
1 parent f926a16 commit 88991ff
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 46 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-cats-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/anchorage-adapter': patch
---

Added support for coin input param
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('execute', () => {
chainId: 'mainnet',
anchorage: {
vaultId: 'b0bb5449c1e4926542ce693b4db2e883',
apiKeyName: 'BTC',
coin: 'BTC',
},
bitgo: {
coin: 'tbtc',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const mockAnchorageSuccess = (): nock.Scope =>
.post('/', {
data: {
vaultId: 'b0bb5449c1e4926542ce693b4db2e883',
apiKeyName: 'BTC',
coin: 'BTC',
network: 'bitcoin',
chainId: 'mainnet',
endpoint: 'wallet',
Expand Down
28 changes: 14 additions & 14 deletions packages/sources/anchorage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

## Environment Variables

| Required? | Name | Description | Type | Options | Default |
| :-------: | :---------------------: | :---------------------------------------------------------------------------------------: | :----: | :-----: | :-----: |
|| {API_KEY_NAME}\_API_KEY | An API key for Anchorage | string | | |
|| API_ENDPOINT | An API endpoint for Anchorage | string | | |
| | API_LIMIT | The maximum number of results to request from the API | number | | `50` |
| | BACKGROUND_EXECUTE_MS | The amount of time the background execute should sleep before performing the next request | number | | `10000` |
| Required? | Name | Description | Type | Options | Default |
| :-------: | :-------------------: | :---------------------------------------------------------------------------------------: | :----: | :-----: | :-----: |
|| {COIN}\_API_KEY | An API key for Anchorage | string | | |
|| API_ENDPOINT | An API endpoint for Anchorage | string | | |
| | API_LIMIT | The maximum number of results to request from the API | number | | `50` |
| | BACKGROUND_EXECUTE_MS | The amount of time the background execute should sleep before performing the next request | number | | `10000` |

---

Expand All @@ -31,12 +31,12 @@ There are no rate limits for this adapter.

### Input Params

| Required? | Name | Aliases | Description | Type | Options | Default | Depends On | Not Valid With |
| :-------: | :--------: | :-------: | :------------------------------------------------------------: | :----: | :------------------: | :-------: | :--------: | :------------: |
|| vaultId | `vaultID` | customerId | string | | | | |
| | chainId | | The ID of the chain to return | string | `mainnet`, `testnet` | `mainnet` | | |
| | network | | The network to return | string | | `bitcoin` | | |
| | apiKeyName | | Used to select {$apiKeyName}\_API_KEY in environment variables | string | | | | |
| Required? | Name | Aliases | Description | Type | Options | Default | Depends On | Not Valid With |
| :-------: | :-----: | :-------: | :-------------------------------------------------------------------------: | :----: | :------------------: | :-------: | :--------: | :------------: |
|| vaultId | `vaultID` | Id of the vault | string | | | | |
| | coin | | Asset ticker name. Used to select {$coin}\_API_KEY in environment variables | string | | | | |
| | chainId | | The ID of the chain to return | string | `mainnet`, `testnet` | `mainnet` | | |
| | network | | The network to return | string | | `bitcoin` | | |

### Example

Expand All @@ -47,9 +47,9 @@ Request:
"data": {
"endpoint": "wallet",
"vaultId": "22ds243sa24f652dsa3",
"coin": "BTC",
"chainId": "mainnet",
"network": "bitcoin",
"apiKeyName": "BTC"
"network": "bitcoin"
}
}
```
Expand Down
18 changes: 9 additions & 9 deletions packages/sources/anchorage/src/endpoint/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export const inputParameters = new InputParameters(
required: true,
aliases: ['vaultID'],
type: 'string',
description: 'customerId',
description: 'Id of the vault',
},
coin: {
required: true,
type: 'string',
description: 'Asset ticker name',
},
chainId: {
type: 'string',
Expand All @@ -27,18 +32,13 @@ export const inputParameters = new InputParameters(
description: 'The network to return',
default: 'bitcoin',
},
apiKeyName: {
type: 'string',
description: 'Used to select {$apiKeyName}_API_KEY in environment variables',
required: true,
},
},
[
{
vaultId: '22ds243sa24f652dsa3',
coin: 'BTC',
chainId: 'mainnet',
network: 'bitcoin',
apiKeyName: 'BTC',
},
],
)
Expand All @@ -54,8 +54,8 @@ export const endpoint = new PoRAddressEndpoint({
transport: walletTransport,
inputParameters,
customInputValidation: (request): AdapterError | undefined => {
if (request.requestContext.data.apiKeyName) {
getApiInfo(request.requestContext.data.apiKeyName)
if (request.requestContext.data.coin) {
getApiInfo(request.requestContext.data.coin)
}
return
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/anchorage/src/transport/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AdapterInputError } from '@chainlink/external-adapter-framework/validation/error'

export const getApiInfo = (apiKeyName: string) => {
const apiKeyEnvName = `${apiKeyName}_API_KEY`
const apiKeyEnvName = `${apiKeyName}_API_KEY`.toUpperCase()

const apiKey = process.env[apiKeyEnvName]

Expand Down
14 changes: 9 additions & 5 deletions packages/sources/anchorage/src/transport/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ export class WalletTransport extends SubscriptionTransport<WalletTransportTypes>
async _handleRequest(
params: RequestParams,
): Promise<AdapterResponse<WalletTransportTypes['Response']>> {
const { vaultId, chainId, network, apiKeyName } = params
const { vaultId, chainId, network, coin } = params

const providerDataRequestedUnixMs = Date.now()

const apiKey = getApiInfo(apiKeyName)
const apiKey = getApiInfo(coin)

const wallets = await this.fetchWallets(vaultId, apiKey)
const wallets = await this.fetchWallets(vaultId, coin, apiKey)

const addresses = wallets.map((w) => {
return {
Expand All @@ -130,7 +130,7 @@ export class WalletTransport extends SubscriptionTransport<WalletTransportTypes>
}
}

async fetchWallets(vaultId: string, apiKey: string) {
async fetchWallets(vaultId: string, coin: string, apiKey: string) {
const wallets = []
let hasNext = true
const requestConfig = {
Expand All @@ -144,7 +144,11 @@ export class WalletTransport extends SubscriptionTransport<WalletTransportTypes>
while (hasNext) {
const reqKey = `${requestConfig.baseURL}${requestConfig.url}`
const response = await this.requester.request<WalletResponse>(reqKey, requestConfig)
wallets.push(...response.response.data.data)
wallets.push(
...response.response.data.data.filter(
(w) => w.networkId.toUpperCase() === coin.toUpperCase(),
),
)
hasNext = response.response.data.page.next !== null
if (response.response.data.page.next) {
requestConfig.url = response.response.data.page.next
Expand Down
16 changes: 9 additions & 7 deletions packages/sources/anchorage/test-payload.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"requests": [{
"endpoint": "wallet",
"vaultId": "b0bb5449c1e4926542ce693b4db2e883",
"chainId": "mainnet",
"network": "bitcoin",
"apiKeyName": "BTC"
}]
"requests": [
{
"endpoint": "wallet",
"vaultId": "b0bb5449c1e4926542ce693b4db2e883",
"chainId": "mainnet",
"network": "bitcoin",
"coin": "ETHHOL"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ exports[`execute wallet endpoint should return success 1`] = `
"chainId": "testnet",
"network": "ethereum",
},
{
"address": "0xFd0F90034628aC5000bA8562196ff1F306c16584",
"chainId": "testnet",
"network": "ethereum",
},
],
},
"result": null,
Expand Down
4 changes: 2 additions & 2 deletions packages/sources/anchorage/test/integration/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('execute', () => {

beforeAll(async () => {
oldEnv = JSON.parse(JSON.stringify(process.env))
process.env.BTC_API_KEY = process.env.BTC_API_KEY ?? 'fake-api-key'
process.env.ETHHOL_API_KEY = process.env.ETHHOL_API_KEY ?? 'fake-api-key'
process.env.API_ENDPOINT = process.env.API_ENDPOINT ?? 'https://localhost:3324'
process.env.API_LIMIT = process.env.API_LIMIT ?? '1'
process.env.BACKGROUND_EXECUTE_MS = process.env.BACKGROUND_EXECUTE_MS ?? '0'
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('execute', () => {
network: 'ethereum',
chainId: 'testnet',
endpoint: 'wallet',
apiKeyName: 'BTC',
coin: 'ETHHOL',
}
mockResponseSuccess()
const response = await testAdapter.request(data)
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/anchorage/test/integration/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const mockResponseSuccess = (): nock.Scope =>
'a384ac79e37e5619a5ed18d2094be6c4aed1f5db79effd1a4c3484640e446456fb4162721214c3891fde6eda21a6a8c8999b0a3e4b92e8b5bafd657363274009',
},
isDefault: false,
networkId: 'ETHHOL',
networkId: 'ETH',
subaccountId: '0ec207d4-9b4e-4428-9a6e-bfd52cdb0d0c',
type: 'WALLET',
vaultId: '123',
Expand Down

0 comments on commit 88991ff

Please sign in to comment.