Skip to content

Commit

Permalink
Zoodao (#1387)
Browse files Browse the repository at this point in the history
* feat:Adapter,Zoodao,arbitrum

* rm abi
  • Loading branch information
0xpeluche authored Apr 2, 2024
1 parent 8643db0 commit 4ad6e54
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@
"vesper",
"virtuswap",
"volta-club",
"vulcandex",
"wagmi",
"wallet",
"wepiggy",
Expand All @@ -505,6 +506,7 @@
"yoshi-exchange",
"zerolend",
"zircuit-staking",
"zoodao",
"zyberswap"
],
"default": "curve"
Expand Down
4 changes: 4 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ import verse from '@adapters/verse'
import vesper from '@adapters/vesper'
import virtuswap from '@adapters/virtuswap'
import voltaClub from '@adapters/volta-club'
import vulcandex from '@adapters/vulcandex'
import wagmi from '@adapters/wagmi'
import wallet from '@adapters/wallet'
import wepiggy from '@adapters/wepiggy'
Expand All @@ -414,6 +415,7 @@ import yieldflow from '@adapters/yieldflow'
import yoshiExchange from '@adapters/yoshi-exchange'
import zerolend from '@adapters/zerolend'
import zircuitStaking from '@adapters/zircuit-staking'
import zoodao from '@adapters/zoodao'
import zyberswap from '@adapters/zyberswap'
import type { Adapter } from '@lib/adapter'

Expand Down Expand Up @@ -818,6 +820,7 @@ export const adapters: Adapter[] = [
vesper,
virtuswap,
voltaClub,
vulcandex,
wagmi,
wallet,
wepiggy,
Expand All @@ -834,6 +837,7 @@ export const adapters: Adapter[] = [
yoshiExchange,
zerolend,
zircuitStaking,
zoodao,
zyberswap,
]

Expand Down
60 changes: 60 additions & 0 deletions src/adapters/zoodao/arbitrum/balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { Balance, BalancesContext, Contract } from '@lib/adapter'
import { mapMultiSuccessFilter } from '@lib/array'
import { abi as erc20Abi } from '@lib/erc20'
import { multicall } from '@lib/multicall'
import { isNotNullish } from '@lib/type'
import { getUnderlyingBalances } from '@lib/uniswap/v2/pair'

const abi = {
earned: {
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
name: 'earned',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
} as const

const ZOO: Contract = {
chain: 'arbitrum',
address: '0x1689a6e1f09658ff37d0bb131514e701045876da',
decimals: 18,
stmbol: 'ZOO',
}

export async function getZooBalances(ctx: BalancesContext, pools: Contract[]): Promise<Balance[]> {
const [userShares, userRewards] = await Promise.all([
multicall({
ctx,
calls: pools.map((pool) => ({ target: pool.address, params: [ctx.address] }) as const),
abi: erc20Abi.balanceOf,
}),
multicall({
ctx,
calls: pools.map((pool) => ({ target: pool.address, params: [ctx.address] }) as const),
abi: abi.earned,
}),
])

const poolBalances: Balance[] = mapMultiSuccessFilter(
userShares.map((_, i) => [userShares[i], userRewards[i]]),

(res, index) => {
const pool = pools[index]
const underlyings = pool.underlyings as Contract[]
if (!underlyings) return null

const [{ output: amount }, { output: pendingReward }] = res.inputOutputPairs

return {
...pool,
amount,
underlyings,
rewards: [{ ...ZOO, amount: pendingReward }],
category: 'farm',
}
},
).filter(isNotNullish)

return getUnderlyingBalances(ctx, poolBalances, { getAddress: (contract) => contract.token! })
}
31 changes: 31 additions & 0 deletions src/adapters/zoodao/arbitrum/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { getZooBalances } from '@adapters/zoodao/arbitrum/balance'
import type { AdapterConfig, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter'
import { resolveBalances } from '@lib/balance'
import { getPairsDetails } from '@lib/uniswap/v2/factory'

const ZooLP: Contract = {
chain: 'arbitrum',
address: '0x96ebfd5dfabf5e94f55940fc1872f39031fb332c',
token: '0x2517cd42eE966862e8EcaAc9Abd1CcD272d897b6',
}

export const getContracts = async (ctx: BaseContext) => {
const pools = await getPairsDetails(ctx, [ZooLP], { getAddress: (contract) => contract.token! })
return {
contracts: { pools },
}
}

export const getBalances: GetBalancesHandler<typeof getContracts> = async (ctx, contracts) => {
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, {
pools: getZooBalances,
})

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

export const config: AdapterConfig = {
startDate: 1706140800,
}
10 changes: 10 additions & 0 deletions src/adapters/zoodao/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Adapter } from '@lib/adapter'

import * as arbitrum from './arbitrum'

const adapter: Adapter = {
id: 'zoodao',
arbitrum: arbitrum,
}

export default adapter

0 comments on commit 4ad6e54

Please sign in to comment.