Skip to content

Commit

Permalink
update Virtuswap,arbitrum
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpeluche committed Mar 11, 2024
1 parent 199f7aa commit 9fd6a37
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
46 changes: 33 additions & 13 deletions src/adapters/virtuswap/arbitrum/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
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<typeof getContracts> = 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<typeof getContracts>(ctx, contracts, {})
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, {
pairs: getPairsBalances,
farmer: (...args) => getVirtuFarmBalances(...args, contracts.pairs || []),
})

return {
groups: [{ balances }],
}
}

export const config: AdapterConfig = {
startDate: 1709683200,
startDate: 1694649600,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/virtuswap/polygon/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 9fd6a37

Please sign in to comment.