From 4deab80bfada237d3720c14d86b1e30f7287ce38 Mon Sep 17 00:00:00 2001 From: Michael Xiao Date: Mon, 25 Nov 2024 14:00:55 -0500 Subject: [PATCH] Fix bedrock --- .changeset/strange-parents-press.md | 5 +++ .../src/transport/bedrockUniBTC.ts | 34 ++++++++++++++----- .../__snapshots__/adapter.test.ts.snap | 8 ++--- 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 .changeset/strange-parents-press.md diff --git a/.changeset/strange-parents-press.md b/.changeset/strange-parents-press.md new file mode 100644 index 0000000000..d3b9e763dd --- /dev/null +++ b/.changeset/strange-parents-press.md @@ -0,0 +1,5 @@ +--- +'@chainlink/por-address-list-adapter': patch +--- + +Fix bedrock address logic diff --git a/packages/sources/por-address-list/src/transport/bedrockUniBTC.ts b/packages/sources/por-address-list/src/transport/bedrockUniBTC.ts index 1364f6a63c..b3fb6d2e0b 100644 --- a/packages/sources/por-address-list/src/transport/bedrockUniBTC.ts +++ b/packages/sources/por-address-list/src/transport/bedrockUniBTC.ts @@ -89,14 +89,32 @@ const getAddresses = ( chainId: 'mainnet', })) .sort() - case 'tokens': - return Object.entries(data.evm) - .map(([_, value]) => ({ - chainId: value.chain_id.toString(), - contractAddress: value.vault, - wallets: value.tokens.filter((t) => t != VAULT_PLACEHOLDER).sort(), - })) - .sort() + case 'tokens': { + const list = Object.entries(data.evm) + .flatMap(([_, value]) => + value.tokens.map((token) => ({ + chainId: value.chain_id.toString(), + contractAddress: token, + wallet: value.vault, + })), + ) + .filter((item) => item.contractAddress != VAULT_PLACEHOLDER) + + const walletsByChain = Map.groupBy(list, (item) => item.chainId + item.contractAddress) + + return Array.from( + new Map( + Array.from(walletsByChain, ([k, v]) => [ + k, + { + chainId: v[0].chainId, + contractAddress: v[0].contractAddress, + wallets: v.map((v) => v.wallet).sort(), + }, + ]), + ).values(), + ).sort() + } case 'vault': return Object.entries(data.evm) .filter(([_, value]) => value.tokens.includes(VAULT_PLACEHOLDER)) diff --git a/packages/sources/por-address-list/test/integration/__snapshots__/adapter.test.ts.snap b/packages/sources/por-address-list/test/integration/__snapshots__/adapter.test.ts.snap index 3f612a4726..4828096aac 100644 --- a/packages/sources/por-address-list/test/integration/__snapshots__/adapter.test.ts.snap +++ b/packages/sources/por-address-list/test/integration/__snapshots__/adapter.test.ts.snap @@ -96,16 +96,16 @@ exports[`execute apiAddress endpoint bedrock tokens should return success 1`] = "result": [ { "chainId": "1", - "contractAddress": "vault_1", + "contractAddress": "token_1", "wallets": [ - "token_1", + "vault_1", ], }, { "chainId": "56", - "contractAddress": "vault_2", + "contractAddress": "token_2", "wallets": [ - "token_2", + "vault_2", ], }, ],