diff --git a/.vscode/launch.json b/.vscode/launch.json index 834d0c76a..535330321 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -392,6 +392,7 @@ "rocketswap-base", "rook", "rubicon", + "sakeperp", "scale", "scream", "sdai", diff --git a/src/adapters/index.ts b/src/adapters/index.ts index cfa4fc7ac..6a2ba1663 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -301,6 +301,7 @@ import rocketPool from '@adapters/rocket-pool' import rocketswapBase from '@adapters/rocketswap-base' import rook from '@adapters/rook' import rubicon from '@adapters/rubicon' +import sakeperp from '@adapters/sakeperp' import scale from '@adapters/scale' import scream from '@adapters/scream' import sdai from '@adapters/sdai' @@ -723,6 +724,7 @@ export const adapters: Adapter[] = [ rocketswapBase, rook, rubicon, + sakeperp, scale, scream, sdai, diff --git a/src/adapters/sakeperp/ethereum/index.ts b/src/adapters/sakeperp/ethereum/index.ts new file mode 100644 index 000000000..a1e45ca44 --- /dev/null +++ b/src/adapters/sakeperp/ethereum/index.ts @@ -0,0 +1,62 @@ +import { getSakePendingRewards } from '@adapters/sakeperp/ethereum/masterchef' +import type { AdapterConfig, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter' +import { resolveBalances } from '@lib/balance' +import { getMasterChefPoolsBalances } from '@lib/masterchef/masterChefBalance' +import { getMasterChefPoolsContracts } from '@lib/masterchef/masterChefContract' +import { getPairsContracts } from '@lib/uniswap/v2/factory' +import { getPairsBalances } from '@lib/uniswap/v2/pair' + +const SAKE: Contract = { + chain: 'ethereum', + address: '0x066798d9ef0833ccc719076dab77199ecbd178b0', + decimals: 18, + symbol: 'SAKE', +} + +const masterChef: Contract = { + chain: 'ethereum', + address: '0x0ec1f1573f3a2db0ad396c843e6a079e2a53e557', +} + +export const getContracts = async (ctx: BaseContext, props: any) => { + const offset = props.pairOffset || 0 + const limit = 500 + + const [pools, { pairs, allPairsLength }] = await Promise.all([ + getMasterChefPoolsContracts(ctx, { masterChefAddress: masterChef.address }), + getPairsContracts({ + ctx, + factoryAddress: '0x75e48C954594d64ef9613AeEF97Ad85370F13807', + offset, + limit, + }), + ]) + + return { + contracts: { pairs, pools }, + revalidate: 60 * 60, + revalidateProps: { + pairOffset: Math.min(offset + limit, allPairsLength), + }, + } +} + +export const getBalances: GetBalancesHandler = async (ctx, contracts) => { + const balances = await resolveBalances(ctx, contracts, { + pairs: getPairsBalances, + pools: (...args) => + getMasterChefPoolsBalances(...args, { + masterChefAddress: masterChef.address, + rewardToken: SAKE, + getUserPendingRewards: getSakePendingRewards, + }), + }) + + return { + groups: [{ balances }], + } +} + +export const config: AdapterConfig = { + startDate: 1617235200, +} diff --git a/src/adapters/sakeperp/ethereum/masterchef.ts b/src/adapters/sakeperp/ethereum/masterchef.ts new file mode 100644 index 000000000..35ec477d5 --- /dev/null +++ b/src/adapters/sakeperp/ethereum/masterchef.ts @@ -0,0 +1,32 @@ +import type { BalancesContext } from '@lib/adapter' +import { mapSuccessFilter } from '@lib/array' +import type { GetUsersInfosParams } from '@lib/masterchef/masterChefBalance' +import { multicall } from '@lib/multicall' + +const abi = { + pendingSake: { + inputs: [ + { internalType: 'uint256', name: '_pid', type: 'uint256' }, + { internalType: 'address', name: '_user', type: 'address' }, + ], + name: 'pendingSake', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, +} as const + +export async function getSakePendingRewards( + ctx: BalancesContext, + { masterChefAddress, pools, rewardToken }: GetUsersInfosParams, +) { + const userPendingRewards = await multicall({ + ctx, + calls: pools.map((pool) => ({ target: masterChefAddress, params: [pool.pid, ctx.address] }) as const), + abi: abi.pendingSake, + }) + + return mapSuccessFilter(userPendingRewards, (res: any) => { + return [{ ...rewardToken, amount: res.output }] + }) +} diff --git a/src/adapters/sakeperp/index.ts b/src/adapters/sakeperp/index.ts new file mode 100644 index 000000000..584d8041a --- /dev/null +++ b/src/adapters/sakeperp/index.ts @@ -0,0 +1,10 @@ +import type { Adapter } from '@lib/adapter' + +import * as ethereum from './ethereum' + +const adapter: Adapter = { + id: 'sakeperp', + ethereum: ethereum, +} + +export default adapter