Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Virtuswap,arbitrum #1352

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading