From 4a3d38f2d0b34d043967f18f6d9c90cdf20831ec Mon Sep 17 00:00:00 2001 From: doomsower <12031673+doomsower@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:58:17 -0400 Subject: [PATCH] feat: add arbitrum to adapter --- src/adapter/constants.ts | 5 ++++- src/adapter/index.ts | 19 ++++++++++++++----- src/adapter/pools/index.ts | 2 +- src/adapter/v1/index.ts | 2 +- src/adapter/v2/index.ts | 2 +- src/adapter/v3/index.ts | 2 +- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/adapter/constants.ts b/src/adapter/constants.ts index b1e3dd3..c8e77ae 100644 --- a/src/adapter/constants.ts +++ b/src/adapter/constants.ts @@ -1 +1,4 @@ -export const ADDRESS_PROVIDER_V3 = "0x9ea7b04da02a5373317d745c1571c84aad03321d"; +export const ADDRESS_PROVIDER_V3: Record = { + ethereum: "0x9ea7b04da02a5373317d745c1571c84aad03321d", + arbitrum: "0x7d04eCdb892Ae074f03B5D0aBA03796F90F3F2af", +}; diff --git a/src/adapter/index.ts b/src/adapter/index.ts index bd6a695..0dda13c 100644 --- a/src/adapter/index.ts +++ b/src/adapter/index.ts @@ -2,6 +2,7 @@ import type { ChainApi } from "@defillama/sdk"; import { getPools } from "./pools"; import { getV1TVL } from "./v1"; +import type { TokenAndOwner } from "./v1/types"; import { getV2TVL } from "./v2"; import { getV3TVL } from "./v3"; @@ -18,16 +19,21 @@ async function tvl( // Pool TVL (Current token balances) const tokensAndOwners = await getPools(block, api); - // v1 and v2: - // return sum of balances of all credit accounts by credit manager in underlying - const v1Balances = await getV1TVL(block, api); - const v2Balances = await getV2TVL(block, api); + const allBalances: TokenAndOwner[] = []; + if (api.chain === "ethereum") { + // v1 and v2: + // return sum of balances of all credit accounts by credit manager in underlying + const v1Balances = await getV1TVL(block, api); + const v2Balances = await getV2TVL(block, api); + allBalances.push(...v1Balances, ...v2Balances); + } // v3 is different: // return balances of each credit account const v3Balances = await getV3TVL(block, api); + allBalances.push(...v3Balances); // Merge all balances for each token - [...v1Balances, ...v2Balances, ...v3Balances].forEach(i => { + allBalances.forEach(i => { api.add(i.token, i.bal); }); @@ -39,6 +45,9 @@ export default { ethereum: { tvl, }, + arbitrum: { + tvl, + }, methodology: `Retrieves the tokens in each Gearbox pool (WETH/DAI/WBTC/USDC/wstETH) & value of all Credit Accounts (V1/V2/V3) denominated in the underlying token.`, misrepresentedTokens: true, }; diff --git a/src/adapter/pools/index.ts b/src/adapter/pools/index.ts index 795869e..0c93078 100644 --- a/src/adapter/pools/index.ts +++ b/src/adapter/pools/index.ts @@ -10,7 +10,7 @@ export async function getPools( const contractsRegisterAddr: string = await api.call({ block, abi: poolAbis["getAddressOrRevert"], - target: ADDRESS_PROVIDER_V3, + target: ADDRESS_PROVIDER_V3[api.chain], params: [ // cast format-bytes32-string "CONTRACTS_REGISTER" "0x434f4e5452414354535f52454749535445520000000000000000000000000000", diff --git a/src/adapter/v1/index.ts b/src/adapter/v1/index.ts index 3fc5bec..c6e610c 100644 --- a/src/adapter/v1/index.ts +++ b/src/adapter/v1/index.ts @@ -40,7 +40,7 @@ async function getCreditManagersV1( const contractsRegisterAddr: string = await api.call({ block, abi: v1Abis["getAddressOrRevert"], - target: ADDRESS_PROVIDER_V3, + target: ADDRESS_PROVIDER_V3[api.chain], params: [ // cast format-bytes32-string "CONTRACTS_REGISTER" "0x434f4e5452414354535f52454749535445520000000000000000000000000000", diff --git a/src/adapter/v2/index.ts b/src/adapter/v2/index.ts index 2985e23..8423aac 100644 --- a/src/adapter/v2/index.ts +++ b/src/adapter/v2/index.ts @@ -40,7 +40,7 @@ async function getCreditManagersV210( ): Promise { const dataCompressor210: string = await api.call({ abi: v2Abis["getAddressOrRevert"], - target: ADDRESS_PROVIDER_V3, + target: ADDRESS_PROVIDER_V3[api.chain], params: [ // cast format-bytes32-string "DATA_COMPRESSOR" "0x444154415f434f4d50524553534f520000000000000000000000000000000000", diff --git a/src/adapter/v3/index.ts b/src/adapter/v3/index.ts index 924d053..1299294 100644 --- a/src/adapter/v3/index.ts +++ b/src/adapter/v3/index.ts @@ -14,7 +14,7 @@ export async function getV3TVL( ): Promise { const dc300 = await api.call({ abi: v3Abis["getAddressOrRevert"], - target: ADDRESS_PROVIDER_V3, + target: ADDRESS_PROVIDER_V3[api.chain], params: [ // cast format-bytes32-string "DATA_COMPRESSOR" "0x444154415f434f4d50524553534f520000000000000000000000000000000000",