diff --git a/src/adapters/virtuswap/arbitrum/index.ts b/src/adapters/virtuswap/arbitrum/index.ts index f63a6af31..fd2c08946 100644 --- a/src/adapters/virtuswap/arbitrum/index.ts +++ b/src/adapters/virtuswap/arbitrum/index.ts @@ -1,22 +1,42 @@ -import type { AdapterConfig, BaseContext, GetBalancesHandler } from '@lib/adapter' +import { getVirtuFarmBalances } from '@adapters/virtuswap/common/balance' +import type { AdapterConfig, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter' import { resolveBalances } from '@lib/balance' +import { getPairsContracts } from '@lib/uniswap/v2/factory' +import { getPairsBalances } from '@lib/uniswap/v2/pair' + +const farmer: Contract = { + chain: 'arbitrum', + address: '0x68748818983cd5b4cd569e92634b8505cfc41fe8', +} + +export const getContracts = async (ctx: BaseContext, props: any) => { + const offset = props.pairOffset || 0 + const limit = 200 + + const { pairs, allPairsLength } = await getPairsContracts({ + ctx, + factoryAddress: '0x389DB0B69e74A816f1367aC081FdF24B5C7C2433', + offset, + limit, + }) -export const getContracts = async (ctx: BaseContext) => { return { - // Contracts grouped by keys. They will be passed to getBalances, filtered by user interaction - contracts: {}, - // Optional revalidate time (in seconds). - // Contracts returned by the adapter are cached by default and can be updated by interval with this parameter. - // This is mostly used for Factory contracts, where the number of contracts deployed increases over time - // revalidate: 60 * 60, + contracts: { + pairs, + farmer, + }, + revalidate: 60 * 60, + revalidateProps: { + pairOffset: Math.min(offset + limit, allPairsLength), + }, } } export const getBalances: GetBalancesHandler = async (ctx, contracts) => { - // Any method to check the contracts retrieved above (based on user interaction). - // This function will be run each time a user queries his balances. - // As static contracts info is filled in getContracts, this should ideally only fetch the current amount of each contract (+ underlyings and rewards) - const balances = await resolveBalances(ctx, contracts, {}) + const balances = await resolveBalances(ctx, contracts, { + pairs: getPairsBalances, + farmer: (...args) => getVirtuFarmBalances(...args, contracts.pairs || []), + }) return { groups: [{ balances }], @@ -24,5 +44,5 @@ export const getBalances: GetBalancesHandler = async (ctx, } export const config: AdapterConfig = { - startDate: 1709683200, + startDate: 1694649600, } diff --git a/src/adapters/virtuswap/polygon/balance.ts b/src/adapters/virtuswap/common/balance.ts similarity index 86% rename from src/adapters/virtuswap/polygon/balance.ts rename to src/adapters/virtuswap/common/balance.ts index 4c3e16307..4beb17766 100644 --- a/src/adapters/virtuswap/polygon/balance.ts +++ b/src/adapters/virtuswap/common/balance.ts @@ -47,6 +47,18 @@ const fxVRSW: Contract = { symbol: 'fxVRSW', } +const VRSW: Contract = { + chain: 'arbitrum', + address: '0xd1E094CabC5aCB9D3b0599C3F76f2D01fF8d3563', + decimals: 18, + symbol: 'VRSW', +} + +const token: { [key: string]: Contract } = { + polygon: fxVRSW, + arbitrum: VRSW, +} + export async function getVirtuFarmBalances( ctx: BalancesContext, farmer: Contract, @@ -64,7 +76,7 @@ export async function getVirtuFarmBalances( const [lpToken, amount] = res.output if (lpToken === ADDRESS_ZERO) { - return { ...fxVRSW, amount, category: 'farm' } + return { ...token[ctx.chain], amount, category: 'farm' } } const matchingPair = pairs.find((pair) => pair.address.toLowerCase() === lpToken.toLowerCase()) @@ -76,14 +88,14 @@ export async function getVirtuFarmBalances( const pendingRewards = await multicall({ ctx, calls: poolBalances.map( - (pool) => ({ target: farmer.address, params: [ctx.address, pool.address, fxVRSW.address] }) as const, + (pool) => ({ target: farmer.address, params: [ctx.address, pool.address, token[ctx.chain].address] }) as const, ), abi: abi.viewRewards, }) const poolBalancesWithRewards = mapSuccessFilter(pendingRewards, (res, index) => ({ ...poolBalances[index], - rewards: [{ ...fxVRSW, amount: res.output }], + rewards: [{ ...token[ctx.chain], amount: res.output }], })) return getUnderlyingBalances(ctx, poolBalancesWithRewards) diff --git a/src/adapters/virtuswap/polygon/index.ts b/src/adapters/virtuswap/polygon/index.ts index bd63a808a..8e41af4c5 100644 --- a/src/adapters/virtuswap/polygon/index.ts +++ b/src/adapters/virtuswap/polygon/index.ts @@ -1,4 +1,4 @@ -import { getVirtuFarmBalances } from '@adapters/virtuswap/polygon/balance' +import { getVirtuFarmBalances } from '@adapters/virtuswap/common/balance' import type { AdapterConfig, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter' import { resolveBalances } from '@lib/balance' import { getPairsContracts } from '@lib/uniswap/v2/factory'