From 65609622b5a91ceeaa8070388d70d77ac90ac0f4 Mon Sep 17 00:00:00 2001 From: 0xPeluche <0xpeluche@proton.me> Date: Mon, 21 Aug 2023 11:49:41 +0200 Subject: [PATCH 1/3] Fix old compound v3 on several chains + add base --- .vscode/launch.json | 1 + src/adapters/compound-v3/arbitrum/index.ts | 27 ++- src/adapters/compound-v3/base/index.ts | 60 +++++++ src/adapters/compound-v3/common/asset.ts | 72 ++++++++ src/adapters/compound-v3/common/balance.ts | 129 ++++++++++++++ src/adapters/compound-v3/common/lend.ts | 189 --------------------- src/adapters/compound-v3/common/rewards.ts | 68 -------- src/adapters/compound-v3/common/stake.ts | 35 ---- src/adapters/compound-v3/ethereum/index.ts | 29 ++-- src/adapters/compound-v3/index.ts | 2 + src/adapters/compound-v3/polygon/index.ts | 27 ++- src/adapters/index.ts | 2 + src/lib/chains.ts | 12 +- src/lib/providers/chains.ts | 4 +- 14 files changed, 314 insertions(+), 343 deletions(-) create mode 100644 src/adapters/compound-v3/base/index.ts create mode 100644 src/adapters/compound-v3/common/asset.ts create mode 100644 src/adapters/compound-v3/common/balance.ts delete mode 100644 src/adapters/compound-v3/common/lend.ts delete mode 100644 src/adapters/compound-v3/common/rewards.ts delete mode 100644 src/adapters/compound-v3/common/stake.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index e0a226c0d..268012ad3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -97,6 +97,7 @@ "badger-dao", "balancer", "bancor-v3", + "baseswap", "beefy", "bella-protocol", "belt-finance", diff --git a/src/adapters/compound-v3/arbitrum/index.ts b/src/adapters/compound-v3/arbitrum/index.ts index 143bf510c..ef256b9c8 100644 --- a/src/adapters/compound-v3/arbitrum/index.ts +++ b/src/adapters/compound-v3/arbitrum/index.ts @@ -1,13 +1,10 @@ +import { getAssetsContracts } from '@adapters/compound-v3/common/asset' +import { getCompLendBalances, getCompRewardBalances } from '@adapters/compound-v3/common/balance' import type { BalancesContext, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter' import { resolveBalances } from '@lib/balance' -import type { BalanceWithExtraProps } from '@lib/compound/v2/lending' -import { getHealthFactor } from '@lib/compound/v2/lending' +import { getSingleStakeBalances } from '@lib/stake' import type { Token } from '@lib/token' -import { getAssetsContracts, getLendBorrowBalances } from '../common/lend' -import { getRewardBalances } from '../common/rewards' -import { getStakeBalances } from '../common/stake' - const USDC: Token = { chain: 'arbitrum', address: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', @@ -15,38 +12,36 @@ const USDC: Token = { symbol: 'USDC', } -const CompoundUSDCv3: Contract = { +const cUSDCv3: Contract = { chain: 'arbitrum', address: '0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA', underlyings: [USDC], } -const CompoundRewards: Contract = { +const rewarder: Contract = { chain: 'arbitrum', address: '0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae', } export const getContracts = async (ctx: BaseContext) => { - const assets = await getAssetsContracts(ctx, [CompoundUSDCv3]) + const assets = await getAssetsContracts(ctx, [cUSDCv3]) return { - contracts: { compounders: [CompoundUSDCv3], assets, CompoundRewards }, + contracts: { compounders: [cUSDCv3], assets, rewarder }, } } const compoundBalances = async (ctx: BalancesContext, compounders: Contract[], rewarder: Contract) => { - return Promise.all([getStakeBalances(ctx, compounders), getRewardBalances(ctx, rewarder, compounders)]) + return Promise.all([getSingleStakeBalances(ctx, compounders), getCompRewardBalances(ctx, rewarder, compounders)]) } export const getBalances: GetBalancesHandler = async (ctx, contracts) => { const balances = await resolveBalances(ctx, contracts, { - assets: (...args) => getLendBorrowBalances(...args, [CompoundUSDCv3]), - compounders: (...args) => compoundBalances(...args, CompoundRewards), + assets: (...args) => getCompLendBalances(...args, [cUSDCv3]), + compounders: (...args) => compoundBalances(...args, rewarder), }) - const healthFactor = await getHealthFactor(balances as BalanceWithExtraProps[]) - return { - groups: [{ balances, healthFactor }], + groups: [{ balances }], } } diff --git a/src/adapters/compound-v3/base/index.ts b/src/adapters/compound-v3/base/index.ts new file mode 100644 index 000000000..5df320a40 --- /dev/null +++ b/src/adapters/compound-v3/base/index.ts @@ -0,0 +1,60 @@ +import { getAssetsContracts } from '@adapters/compound-v3/common/asset' +import { getCompLendBalances, getCompRewardBalances } from '@adapters/compound-v3/common/balance' +import type { BalancesContext, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter' +import { resolveBalances } from '@lib/balance' +import { getSingleStakeBalances } from '@lib/stake' +import type { Token } from '@lib/token' + +const USDbC: Token = { + chain: 'base', + address: '0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca', + decimals: 6, + symbol: 'USDbC', +} + +const WETH: Token = { + chain: 'base', + address: '0x4200000000000000000000000000000000000006', + decimals: 18, + symbol: 'WETH', +} + +const cUSDbCv3: Contract = { + chain: 'base', + address: '0x9c4ec768c28520B50860ea7a15bd7213a9fF58bf', + underlyings: [USDbC], +} + +const cWETHv3: Contract = { + chain: 'base', + address: '0x46e6b214b524310239732D51387075E0e70970bf', + underlyings: [WETH], +} + +const rewarder: Contract = { + chain: 'base', + address: '0x123964802e6ABabBE1Bc9547D72Ef1B69B00A6b1', +} + +export const getContracts = async (ctx: BaseContext) => { + const assets = await getAssetsContracts(ctx, [cUSDbCv3, cWETHv3]) + + return { + contracts: { compounders: [cUSDbCv3, cWETHv3], assets, rewarder }, + } +} + +const compoundBalances = async (ctx: BalancesContext, compounders: Contract[], rewarder: Contract) => { + return Promise.all([getSingleStakeBalances(ctx, compounders), getCompRewardBalances(ctx, rewarder, compounders)]) +} + +export const getBalances: GetBalancesHandler = async (ctx, contracts) => { + const balances = await resolveBalances(ctx, contracts, { + assets: (...args) => getCompLendBalances(...args, [cUSDbCv3, cWETHv3]), + compounders: (...args) => compoundBalances(...args, rewarder), + }) + + return { + groups: [{ balances }], + } +} diff --git a/src/adapters/compound-v3/common/asset.ts b/src/adapters/compound-v3/common/asset.ts new file mode 100644 index 000000000..7a8b43dfe --- /dev/null +++ b/src/adapters/compound-v3/common/asset.ts @@ -0,0 +1,72 @@ +import type { BaseContext, Contract } from '@lib/adapter' +import { mapSuccessFilter, range } from '@lib/array' +import { multicall } from '@lib/multicall' + +const abi = { + getAssetInfo: { + inputs: [{ internalType: 'uint8', name: 'i', type: 'uint8' }], + name: 'getAssetInfo', + outputs: [ + { + components: [ + { internalType: 'uint8', name: 'offset', type: 'uint8' }, + { internalType: 'address', name: 'asset', type: 'address' }, + { internalType: 'address', name: 'priceFeed', type: 'address' }, + { internalType: 'uint64', name: 'scale', type: 'uint64' }, + { + internalType: 'uint64', + name: 'borrowCollateralFactor', + type: 'uint64', + }, + { + internalType: 'uint64', + name: 'liquidateCollateralFactor', + type: 'uint64', + }, + { + internalType: 'uint64', + name: 'liquidationFactor', + type: 'uint64', + }, + { internalType: 'uint128', name: 'supplyCap', type: 'uint128' }, + ], + internalType: 'struct CometCore.AssetInfo', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + numAssets: { + inputs: [], + name: 'numAssets', + outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], + stateMutability: 'view', + type: 'function', + }, +} as const + +export async function getAssetsContracts(ctx: BaseContext, compounders: Contract[]): Promise { + const numberOfAssets = await multicall({ + ctx, + calls: compounders.map((contract) => ({ target: contract.address })), + abi: abi.numAssets, + }) + + const assetsInfoRes = await multicall({ + ctx, + //@ts-expect-error + calls: mapSuccessFilter(numberOfAssets, (responses) => + range(0, responses.output).map((res) => ({ target: responses.input.target, params: [res] })), + ).flat(), + abi: abi.getAssetInfo, + }) + + return mapSuccessFilter(assetsInfoRes, (res) => ({ + chain: ctx.chain, + address: res.output.asset, + compounder: res.input.target, + collateralFactor: res.output.borrowCollateralFactor, + })) +} diff --git a/src/adapters/compound-v3/common/balance.ts b/src/adapters/compound-v3/common/balance.ts new file mode 100644 index 000000000..6d1c92dbb --- /dev/null +++ b/src/adapters/compound-v3/common/balance.ts @@ -0,0 +1,129 @@ +import type { Balance, BalancesContext, Contract } from '@lib/adapter' +import { mapSuccessFilter } from '@lib/array' +import { multicall } from '@lib/multicall' +import { isNotNullish } from '@lib/type' + +const abi = { + borrowBalanceOf: { + inputs: [{ internalType: 'address', name: 'account', type: 'address' }], + name: 'borrowBalanceOf', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + userCollateral: { + inputs: [ + { internalType: 'address', name: '', type: 'address' }, + { internalType: 'address', name: '', type: 'address' }, + ], + name: 'userCollateral', + outputs: [ + { internalType: 'uint128', name: 'balance', type: 'uint128' }, + { internalType: 'uint128', name: '_reserved', type: 'uint128' }, + ], + stateMutability: 'view', + type: 'function', + }, + getRewardOwed: { + inputs: [ + { internalType: 'address', name: 'comet', type: 'address' }, + { internalType: 'address', name: 'account', type: 'address' }, + ], + name: 'getRewardOwed', + outputs: [ + { + components: [ + { internalType: 'address', name: 'token', type: 'address' }, + { internalType: 'uint256', name: 'owed', type: 'uint256' }, + ], + internalType: 'struct CometRewards.RewardOwed', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, +} as const + +const COMP: { [key: string]: `0x${string}` } = { + arbitrum: '0x354A6dA3fcde098F8389cad84b0182725c6C91dE', + base: '0x9e1028F5F1D5eDE59748FFceE5532509976840E0', + ethereum: '0xc00e94cb662c3520282e6f5717214004a7f26888', + polygon: '0x8505b9d2254A7Ae468c0E9dd10Ccea3A837aef5c', +} + +export async function getCompLendBalances( + ctx: BalancesContext, + assets: Contract[], + compounders: Contract[], +): Promise { + const [userLendBalances, userBorrowBalances] = await Promise.all([ + multicall({ + ctx, + calls: assets.map((asset) => ({ target: asset.compounder, params: [ctx.address, asset.address] }) as const), + abi: abi.userCollateral, + }), + multicall({ + ctx, + calls: compounders.map((compounder) => ({ target: compounder.address, params: [ctx.address] }) as const), + abi: abi.borrowBalanceOf, + }), + ]) + + const supplyBalance: Balance[] = mapSuccessFilter(userLendBalances, (res, index) => { + const [balance, _reserved] = res.output + + return { + chain: ctx.chain, + decimals: assets[index].decimals, + symbol: assets[index].symbol, + address: assets[index].address, + amount: balance, + collateralFactor: assets[index].collateralFactor, + category: 'lend', + } + }) + + const borrowBalance: Balance[] = mapSuccessFilter(userBorrowBalances, (res, index) => { + const underlying = compounders[index].underlyings?.[0] as Contract + + if (!underlying) { + return null + } + + return { + chain: ctx.chain, + decimals: underlying.decimals, + symbol: underlying.symbol, + address: underlying.address, + amount: res.output, + category: 'borrow', + } + }).filter(isNotNullish) as Balance[] + + return [...supplyBalance, ...borrowBalance] +} + +export async function getCompRewardBalances( + ctx: BalancesContext, + rewarder: Contract, + compounders: Contract[], +): Promise { + const pendingCompRewards = await multicall({ + ctx, + calls: compounders.map( + (contract) => ({ target: rewarder.address, params: [contract.address, ctx.address] }) as const, + ), + abi: abi.getRewardOwed, + }) + + return mapSuccessFilter(pendingCompRewards, (res) => ({ + chain: ctx.chain, + address: COMP[ctx.chain], + decimals: 18, + symbol: 'COMP', + amount: res.output.owed, + category: 'reward', + })) +} diff --git a/src/adapters/compound-v3/common/lend.ts b/src/adapters/compound-v3/common/lend.ts deleted file mode 100644 index 13d4abf55..000000000 --- a/src/adapters/compound-v3/common/lend.ts +++ /dev/null @@ -1,189 +0,0 @@ -import type { Balance, BalancesContext, BaseContext, Contract } from '@lib/adapter' -import { range } from '@lib/array' -import { multicall } from '@lib/multicall' - -const abi = { - borrowBalanceOf: { - inputs: [{ internalType: 'address', name: 'account', type: 'address' }], - name: 'borrowBalanceOf', - outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], - stateMutability: 'view', - type: 'function', - }, - getAssetInfo: { - inputs: [{ internalType: 'uint8', name: 'i', type: 'uint8' }], - name: 'getAssetInfo', - outputs: [ - { - components: [ - { internalType: 'uint8', name: 'offset', type: 'uint8' }, - { internalType: 'address', name: 'asset', type: 'address' }, - { internalType: 'address', name: 'priceFeed', type: 'address' }, - { internalType: 'uint64', name: 'scale', type: 'uint64' }, - { - internalType: 'uint64', - name: 'borrowCollateralFactor', - type: 'uint64', - }, - { - internalType: 'uint64', - name: 'liquidateCollateralFactor', - type: 'uint64', - }, - { - internalType: 'uint64', - name: 'liquidationFactor', - type: 'uint64', - }, - { internalType: 'uint128', name: 'supplyCap', type: 'uint128' }, - ], - internalType: 'struct CometCore.AssetInfo', - name: '', - type: 'tuple', - }, - ], - stateMutability: 'view', - type: 'function', - }, - numAssets: { - inputs: [], - name: 'numAssets', - outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], - stateMutability: 'view', - type: 'function', - }, - userCollateral: { - inputs: [ - { internalType: 'address', name: '', type: 'address' }, - { internalType: 'address', name: '', type: 'address' }, - ], - name: 'userCollateral', - outputs: [ - { internalType: 'uint128', name: 'balance', type: 'uint128' }, - { internalType: 'uint128', name: '_reserved', type: 'uint128' }, - ], - stateMutability: 'view', - type: 'function', - }, -} as const - -type BalanceWithExtraProps = Balance & { - collateralFactor: string -} - -export async function getAssetsContracts(ctx: BaseContext, compounders: Contract[]): Promise { - const contracts: Contract[] = [] - - const numberOfAssets = await multicall({ - ctx, - calls: compounders.map((contract) => ({ target: contract.address })), - abi: abi.numAssets, - }) - - const assetsInfoRes = await multicall({ - ctx, - calls: numberOfAssets.flatMap((numberOfAsset) => - numberOfAsset.success - ? range(0, numberOfAsset.output).map( - (_, idx) => ({ target: numberOfAsset.input.target, params: [idx] }) as const, - ) - : null, - ), - abi: abi.getAssetInfo, - }) - - for (let contractIdx = 0; contractIdx < compounders.length; contractIdx++) { - for (let i = 0; i < assetsInfoRes.length; i++) { - const assetInfoRes = assetsInfoRes[i] - - if (!assetInfoRes.success) { - continue - } - - contracts.push({ - chain: ctx.chain, - address: assetInfoRes.output.asset, - compounder: assetInfoRes.input.target, - collateralFactor: assetInfoRes.output.borrowCollateralFactor, - }) - } - } - - return contracts -} - -export async function getLendBorrowBalances( - ctx: BalancesContext, - assets: Contract[], - compounders: Contract[], -): Promise { - const balances: Balance[] = [] - - const [userCollateralBalancesRes, userBorrowBalancesRes] = await Promise.all([ - multicall({ - ctx, - calls: assets.map( - (asset) => - ({ - target: asset.compounder, - params: [ctx.address, asset.address], - }) as const, - ), - abi: abi.userCollateral, - }), - - multicall({ - ctx, - calls: compounders.map( - (contract) => - ({ - target: contract.address, - params: [ctx.address], - }) as const, - ), - abi: abi.borrowBalanceOf, - }), - ]) - - for (let supplyIdx = 0; supplyIdx < assets.length; supplyIdx++) { - const asset = assets[supplyIdx] - const userCollateralBalanceRes = userCollateralBalancesRes[supplyIdx] - - if (!userCollateralBalanceRes.success) { - continue - } - - const supplyBalances: BalanceWithExtraProps = { - chain: ctx.chain, - decimals: asset.decimals, - symbol: asset.symbol, - address: asset.address, - amount: userCollateralBalanceRes.output[0], - collateralFactor: asset.collateralFactor, - category: 'lend', - } - - balances.push(supplyBalances) - } - - for (let borrowIdx = 0; borrowIdx < compounders.length; borrowIdx++) { - const compounder = compounders[borrowIdx] - const underlying = compounder.underlyings?.[0] as Contract - const userBorrowBalanceRes = userBorrowBalancesRes[borrowIdx] - - if (!underlying || !userBorrowBalanceRes.success) { - continue - } - - balances.push({ - chain: ctx.chain, - decimals: underlying.decimals, - symbol: underlying.symbol, - address: underlying.address, - amount: userBorrowBalanceRes.output, - category: 'borrow', - }) - } - - return balances -} diff --git a/src/adapters/compound-v3/common/rewards.ts b/src/adapters/compound-v3/common/rewards.ts deleted file mode 100644 index 9f04f9115..000000000 --- a/src/adapters/compound-v3/common/rewards.ts +++ /dev/null @@ -1,68 +0,0 @@ -import type { Balance, BalancesContext, Contract } from '@lib/adapter' -import { multicall } from '@lib/multicall' -import type { Token } from '@lib/token' - -const abi = { - getRewardOwed: { - inputs: [ - { internalType: 'address', name: 'comet', type: 'address' }, - { internalType: 'address', name: 'account', type: 'address' }, - ], - name: 'getRewardOwed', - outputs: [ - { - components: [ - { internalType: 'address', name: 'token', type: 'address' }, - { internalType: 'uint256', name: 'owed', type: 'uint256' }, - ], - internalType: 'struct CometRewards.RewardOwed', - name: '', - type: 'tuple', - }, - ], - stateMutability: 'nonpayable', - type: 'function', - }, -} as const - -const COMP: Token = { - chain: 'ethereum', - address: '0xc00e94cb662c3520282e6f5717214004a7f26888', - decimals: 18, - symbol: 'COMP', -} - -export async function getRewardBalances( - ctx: BalancesContext, - rewarder: Contract, - compounders: Contract[], -): Promise { - const rewards: Balance[] = [] - - const pendingCompRewardsRes = await multicall({ - ctx, - calls: compounders.map( - (contract) => ({ target: rewarder.address, params: [contract.address, ctx.address] }) as const, - ), - abi: abi.getRewardOwed, - }) - - for (let idx = 0; idx < compounders.length; idx++) { - const pendingCompRewardRes = pendingCompRewardsRes[idx] - - if (!pendingCompRewardRes.success) { - continue - } - - rewards.push({ - chain: ctx.chain, - decimals: COMP.decimals, - symbol: COMP.symbol, - address: COMP.address, - amount: pendingCompRewardRes.output.owed, - category: 'reward', - }) - } - - return rewards -} diff --git a/src/adapters/compound-v3/common/stake.ts b/src/adapters/compound-v3/common/stake.ts deleted file mode 100644 index 2eb6ff24f..000000000 --- a/src/adapters/compound-v3/common/stake.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { Balance, BalancesContext, Contract } from '@lib/adapter' -import { abi } from '@lib/erc20' -import { multicall } from '@lib/multicall' - -export async function getStakeBalances(ctx: BalancesContext, contracts: Contract[]): Promise { - const balances: Balance[] = [] - - const balanceOfsRes = await multicall({ - ctx, - calls: contracts.map((contract) => ({ target: contract.address, params: [ctx.address] }) as const), - abi: abi.balanceOf, - }) - - for (let idx = 0; idx < contracts.length; idx++) { - const contract = contracts[idx] - const underlying = contract.underlyings?.[0] as Contract - - const balanceOfRes = balanceOfsRes[idx] - - if (!balanceOfRes.success) { - continue - } - - balances.push({ - chain: ctx.chain, - address: underlying.address, - decimals: underlying.decimals, - symbol: underlying.symbol, - amount: balanceOfRes.output, - category: 'stake', - }) - } - - return balances -} diff --git a/src/adapters/compound-v3/ethereum/index.ts b/src/adapters/compound-v3/ethereum/index.ts index 7a4a05cd1..f235f1476 100644 --- a/src/adapters/compound-v3/ethereum/index.ts +++ b/src/adapters/compound-v3/ethereum/index.ts @@ -1,13 +1,10 @@ +import { getAssetsContracts } from '@adapters/compound-v3/common/asset' +import { getCompLendBalances, getCompRewardBalances } from '@adapters/compound-v3/common/balance' import type { BalancesContext, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter' import { resolveBalances } from '@lib/balance' -import type { BalanceWithExtraProps } from '@lib/compound/v2/lending' -import { getHealthFactor } from '@lib/compound/v2/lending' +import { getSingleStakeBalances } from '@lib/stake' import type { Token } from '@lib/token' -import { getAssetsContracts, getLendBorrowBalances } from '../common/lend' -import { getRewardBalances } from '../common/rewards' -import { getStakeBalances } from '../common/stake' - const USDC: Token = { chain: 'ethereum', address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', @@ -22,44 +19,42 @@ const WETH: Token = { symbol: 'WETH', } -const CompoundUSDCv3: Contract = { +const cUSDCv3: Contract = { chain: 'ethereum', address: '0xc3d688B66703497DAA19211EEdff47f25384cdc3', underlyings: [USDC], } -const CompoundWETHv3: Contract = { +const cWETHv3: Contract = { chain: 'ethereum', address: '0xa17581a9e3356d9a858b789d68b4d866e593ae94', underlyings: [WETH], } -const CompoundRewards: Contract = { +const rewarder: Contract = { chain: 'ethereum', address: '0x1B0e765F6224C21223AeA2af16c1C46E38885a40', } export const getContracts = async (ctx: BaseContext) => { - const assets = await getAssetsContracts(ctx, [CompoundUSDCv3, CompoundWETHv3]) + const assets = await getAssetsContracts(ctx, [cUSDCv3, cWETHv3]) return { - contracts: { compounders: [CompoundUSDCv3, CompoundWETHv3], assets, CompoundRewards }, + contracts: { compounders: [cUSDCv3, cWETHv3], assets, rewarder }, } } const compoundBalances = async (ctx: BalancesContext, compounders: Contract[], rewarder: Contract) => { - return Promise.all([getStakeBalances(ctx, compounders), getRewardBalances(ctx, rewarder, compounders)]) + return Promise.all([getSingleStakeBalances(ctx, compounders), getCompRewardBalances(ctx, rewarder, compounders)]) } export const getBalances: GetBalancesHandler = async (ctx, contracts) => { const balances = await resolveBalances(ctx, contracts, { - assets: (...args) => getLendBorrowBalances(...args, [CompoundUSDCv3, CompoundWETHv3]), - compounders: (...args) => compoundBalances(...args, CompoundRewards), + assets: (...args) => getCompLendBalances(...args, [cUSDCv3, cWETHv3]), + compounders: (...args) => compoundBalances(...args, rewarder), }) - const healthFactor = await getHealthFactor(balances as BalanceWithExtraProps[]) - return { - groups: [{ balances, healthFactor }], + groups: [{ balances }], } } diff --git a/src/adapters/compound-v3/index.ts b/src/adapters/compound-v3/index.ts index 66a764749..579ebecf5 100644 --- a/src/adapters/compound-v3/index.ts +++ b/src/adapters/compound-v3/index.ts @@ -1,6 +1,7 @@ import type { Adapter } from '@lib/adapter' import * as arbitrum from './arbitrum' +import * as base from './base' import * as ethereum from './ethereum' import * as polygon from './polygon' @@ -9,6 +10,7 @@ const adapter: Adapter = { ethereum, polygon, arbitrum, + base, } export default adapter diff --git a/src/adapters/compound-v3/polygon/index.ts b/src/adapters/compound-v3/polygon/index.ts index 610003090..4045a223f 100644 --- a/src/adapters/compound-v3/polygon/index.ts +++ b/src/adapters/compound-v3/polygon/index.ts @@ -1,13 +1,10 @@ +import { getAssetsContracts } from '@adapters/compound-v3/common/asset' +import { getCompLendBalances, getCompRewardBalances } from '@adapters/compound-v3/common/balance' import type { BalancesContext, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter' import { resolveBalances } from '@lib/balance' -import type { BalanceWithExtraProps } from '@lib/compound/v2/lending' -import { getHealthFactor } from '@lib/compound/v2/lending' +import { getSingleStakeBalances } from '@lib/stake' import type { Token } from '@lib/token' -import { getAssetsContracts, getLendBorrowBalances } from '../common/lend' -import { getRewardBalances } from '../common/rewards' -import { getStakeBalances } from '../common/stake' - const USDC: Token = { chain: 'polygon', address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', @@ -15,38 +12,36 @@ const USDC: Token = { symbol: 'USDC', } -const CompoundUSDCv3: Contract = { +const cUSDCv3: Contract = { chain: 'polygon', address: '0xF25212E676D1F7F89Cd72fFEe66158f541246445', underlyings: [USDC], } -const CompoundRewards: Contract = { +const rewarder: Contract = { chain: 'polygon', address: '0x45939657d1CA34A8FA39A924B71D28Fe8431e581', } export const getContracts = async (ctx: BaseContext) => { - const assets = await getAssetsContracts(ctx, [CompoundUSDCv3]) + const assets = await getAssetsContracts(ctx, [cUSDCv3]) return { - contracts: { compounders: [CompoundUSDCv3], assets, CompoundRewards }, + contracts: { compounders: [cUSDCv3], assets, rewarder }, } } const compoundBalances = async (ctx: BalancesContext, compounders: Contract[], rewarder: Contract) => { - return Promise.all([getStakeBalances(ctx, compounders), getRewardBalances(ctx, rewarder, compounders)]) + return Promise.all([getSingleStakeBalances(ctx, compounders), getCompRewardBalances(ctx, rewarder, compounders)]) } export const getBalances: GetBalancesHandler = async (ctx, contracts) => { const balances = await resolveBalances(ctx, contracts, { - assets: (...args) => getLendBorrowBalances(...args, [CompoundUSDCv3]), - compounders: (...args) => compoundBalances(...args, CompoundRewards), + assets: (...args) => getCompLendBalances(...args, [cUSDCv3]), + compounders: (...args) => compoundBalances(...args, rewarder), }) - const healthFactor = await getHealthFactor(balances as BalanceWithExtraProps[]) - return { - groups: [{ balances, healthFactor }], + groups: [{ balances }], } } diff --git a/src/adapters/index.ts b/src/adapters/index.ts index b3d54f4dc..6e0bc0fb4 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -26,6 +26,7 @@ import babylonFinance from '@adapters/babylon-finance' import badgerDao from '@adapters/badger-dao' import balancer from '@adapters/balancer' import bancorV3 from '@adapters/bancor-v3' +import baseswap from '@adapters/baseswap' import beefy from '@adapters/beefy' import bellaProtocol from '@adapters/bella-protocol' import beltFinance from '@adapters/belt-finance' @@ -262,6 +263,7 @@ export const adapters: Adapter[] = [ badgerDao, balancer, bancorV3, + baseswap, beefy, bellaProtocol, beltFinance, diff --git a/src/lib/chains.ts b/src/lib/chains.ts index 0036faa7f..c67490b4a 100644 --- a/src/lib/chains.ts +++ b/src/lib/chains.ts @@ -21,6 +21,9 @@ export const chainsNames = [ 'moonbeam', 'optimism', 'polygon', + 'arbitrum-nova', + 'base', + 'bittorrent', ] as const export type Chain = (typeof chainsNames)[number] @@ -91,7 +94,12 @@ export const chains = [ id: 'base', chainId: 8453, name: 'Base', - rpcUrls: [http('https://mainnet.base.org', { batch: { wait: 0, batchSize: 5_000 } })], + rpcUrls: [ + http('https://base-mainnet.public.blastapi.io', { batch: { wait: 0, batchSize: 5_000 } }), + http('https://mainnet.base.org', { batch: { wait: 0, batchSize: 1_000 } }), + http('https://1rpc.io/base', { batch: { wait: 0, batchSize: 1_000 } }), + http('https://base.blockpi.network/v1/rpc/public', { batch: { wait: 0, batchSize: 1_000 } }), + ], nativeCurrency: { address: ADDRESS_ZERO, decimals: 18, @@ -291,6 +299,7 @@ export const toDefiLlamaChain: { [key in Chain]: string } = { moonbeam: 'moonbeam', optimism: 'optimism', polygon: 'polygon', + base: 'base', } export const fromDefiLlamaChain: { [key: string]: Chain } = { @@ -306,4 +315,5 @@ export const fromDefiLlamaChain: { [key: string]: Chain } = { Moonbeam: 'moonbeam', Optimism: 'optimism', Polygon: 'polygon', + base: 'base', } diff --git a/src/lib/providers/chains.ts b/src/lib/providers/chains.ts index a180875de..29ac5b05d 100644 --- a/src/lib/providers/chains.ts +++ b/src/lib/providers/chains.ts @@ -3,11 +3,12 @@ import type { Chain as _Chain } from 'viem/chains' import { arbitrum, avalanche, + base, bsc, celo, + mainnet as ethereum, fantom, harmonyOne as harmony, - mainnet as ethereum, moonbeam, optimism, polygon, @@ -61,4 +62,5 @@ export const viemChainById: { [key in Chain]: _Chain } = { moonbeam, optimism, polygon, + base, } as const From 7ba41b4497bb5d41ad8d1cb39ef01455d37d5381 Mon Sep 17 00:00:00 2001 From: 0xPeluche <0xpeluche@proton.me> Date: Mon, 21 Aug 2023 11:58:31 +0200 Subject: [PATCH 2/3] pnpm run build --- .vscode/launch.json | 1 - src/adapters/index.ts | 2 -- src/lib/providers/chains.ts | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 268012ad3..e0a226c0d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -97,7 +97,6 @@ "badger-dao", "balancer", "bancor-v3", - "baseswap", "beefy", "bella-protocol", "belt-finance", diff --git a/src/adapters/index.ts b/src/adapters/index.ts index 6e0bc0fb4..b3d54f4dc 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -26,7 +26,6 @@ import babylonFinance from '@adapters/babylon-finance' import badgerDao from '@adapters/badger-dao' import balancer from '@adapters/balancer' import bancorV3 from '@adapters/bancor-v3' -import baseswap from '@adapters/baseswap' import beefy from '@adapters/beefy' import bellaProtocol from '@adapters/bella-protocol' import beltFinance from '@adapters/belt-finance' @@ -263,7 +262,6 @@ export const adapters: Adapter[] = [ badgerDao, balancer, bancorV3, - baseswap, beefy, bellaProtocol, beltFinance, diff --git a/src/lib/providers/chains.ts b/src/lib/providers/chains.ts index 29ac5b05d..123549aed 100644 --- a/src/lib/providers/chains.ts +++ b/src/lib/providers/chains.ts @@ -6,9 +6,9 @@ import { base, bsc, celo, - mainnet as ethereum, fantom, harmonyOne as harmony, + mainnet as ethereum, moonbeam, optimism, polygon, From 5ca268f18fd235fabfc235f8163df718e7b0853f Mon Sep 17 00:00:00 2001 From: 0xPeluche <0xpeluche@proton.me> Date: Mon, 21 Aug 2023 12:58:54 +0200 Subject: [PATCH 3/3] remove chains --- src/lib/chains.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/lib/chains.ts b/src/lib/chains.ts index c67490b4a..b377b4e19 100644 --- a/src/lib/chains.ts +++ b/src/lib/chains.ts @@ -21,9 +21,7 @@ export const chainsNames = [ 'moonbeam', 'optimism', 'polygon', - 'arbitrum-nova', 'base', - 'bittorrent', ] as const export type Chain = (typeof chainsNames)[number] @@ -287,9 +285,7 @@ for (const chain of chains) { export const toDefiLlamaChain: { [key in Chain]: string } = { arbitrum: 'arbitrum', - 'arbitrum-nova': 'arbitrum nova', avalanche: 'avax', - bittorrent: 'bittorrent', bsc: 'bsc', celo: 'celo', ethereum: 'ethereum', @@ -304,9 +300,7 @@ export const toDefiLlamaChain: { [key in Chain]: string } = { export const fromDefiLlamaChain: { [key: string]: Chain } = { Arbitrum: 'arbitrum', - 'Arbitrum Nova': 'arbitrum-nova', Avalanche: 'avalanche', - Bittorrent: 'bittorrent', BSC: 'bsc', Celo: 'celo', Ethereum: 'ethereum',