Skip to content

Commit

Permalink
Sakeperp (#1389)
Browse files Browse the repository at this point in the history
* feat:Adapter,SakePerp

* run build
  • Loading branch information
0xpeluche authored Apr 3, 2024
1 parent 4ad6e54 commit 6cd5fb1
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"rocketswap-base",
"rook",
"rubicon",
"sakeperp",
"scale",
"scream",
"sdai",
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -723,6 +724,7 @@ export const adapters: Adapter[] = [
rocketswapBase,
rook,
rubicon,
sakeperp,
scale,
scream,
sdai,
Expand Down
62 changes: 62 additions & 0 deletions src/adapters/sakeperp/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -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<typeof getContracts> = async (ctx, contracts) => {
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, {
pairs: getPairsBalances,
pools: (...args) =>
getMasterChefPoolsBalances(...args, {
masterChefAddress: masterChef.address,
rewardToken: SAKE,
getUserPendingRewards: getSakePendingRewards,
}),
})

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

export const config: AdapterConfig = {
startDate: 1617235200,
}
32 changes: 32 additions & 0 deletions src/adapters/sakeperp/ethereum/masterchef.ts
Original file line number Diff line number Diff line change
@@ -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 }]
})
}
10 changes: 10 additions & 0 deletions src/adapters/sakeperp/index.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6cd5fb1

Please sign in to comment.