-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat:Adapter,Zoodao,arbitrum * rm abi
- Loading branch information
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |