Skip to content

Commit

Permalink
feat: add arbitrum to adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Apr 11, 2024
1 parent 03ce908 commit 4a3d38f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/adapter/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const ADDRESS_PROVIDER_V3 = "0x9ea7b04da02a5373317d745c1571c84aad03321d";
export const ADDRESS_PROVIDER_V3: Record<string, string> = {
ethereum: "0x9ea7b04da02a5373317d745c1571c84aad03321d",
arbitrum: "0x7d04eCdb892Ae074f03B5D0aBA03796F90F3F2af",
};
19 changes: 14 additions & 5 deletions src/adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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);
});

Expand All @@ -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,
};
2 changes: 1 addition & 1 deletion src/adapter/pools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function getCreditManagersV210(
): Promise<CreditManagerData[]> {
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",
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function getV3TVL(
): Promise<TokenAndOwner[]> {
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",
Expand Down

0 comments on commit 4a3d38f

Please sign in to comment.