Skip to content

Commit

Permalink
feat:Adapter,Nasdex,polygon (#1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpeluche authored Mar 25, 2024
1 parent 129c582 commit 882f649
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
"mantisswap",
"mantle-staked-eth",
"maple",
"matrix-farm",
"mdex",
"mean-finance",
"mendi-finance",
Expand All @@ -315,6 +316,7 @@
"mu-exchange",
"mugenfinance",
"multichain",
"nasdex",
"nemesis-dao",
"nexus-mutual",
"nf3-ape",
Expand Down Expand Up @@ -357,6 +359,7 @@
"proxy",
"pstake-finance",
"puffer-finance",
"purple-bridge-dex",
"qidao",
"quickswap-dex",
"radiant-v1",
Expand Down
6 changes: 6 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ import makerdao from '@adapters/makerdao'
import mantisswap from '@adapters/mantisswap'
import mantleStakedEth from '@adapters/mantle-staked-eth'
import maple from '@adapters/maple'
import matrixFarm from '@adapters/matrix-farm'
import mdex from '@adapters/mdex'
import meanFinance from '@adapters/mean-finance'
import mendiFinance from '@adapters/mendi-finance'
Expand All @@ -224,6 +225,7 @@ import mstable from '@adapters/mstable'
import muExchange from '@adapters/mu-exchange'
import mugenfinance from '@adapters/mugenfinance'
import multichain from '@adapters/multichain'
import nasdex from '@adapters/nasdex'
import nemesisDao from '@adapters/nemesis-dao'
import nexusMutual from '@adapters/nexus-mutual'
import nf3Ape from '@adapters/nf3-ape'
Expand Down Expand Up @@ -266,6 +268,7 @@ import protectorateProtocol from '@adapters/protectorate-protocol'
import proxy from '@adapters/proxy'
import pstakeFinance from '@adapters/pstake-finance'
import pufferFinance from '@adapters/puffer-finance'
import purpleBridgeDex from '@adapters/purple-bridge-dex'
import qidao from '@adapters/qidao'
import quickswapDex from '@adapters/quickswap-dex'
import radiantV1 from '@adapters/radiant-v1'
Expand Down Expand Up @@ -612,6 +615,7 @@ export const adapters: Adapter[] = [
mantisswap,
mantleStakedEth,
maple,
matrixFarm,
mdex,
meanFinance,
mendiFinance,
Expand All @@ -633,6 +637,7 @@ export const adapters: Adapter[] = [
muExchange,
mugenfinance,
multichain,
nasdex,
nemesisDao,
nexusMutual,
nf3Ape,
Expand Down Expand Up @@ -675,6 +680,7 @@ export const adapters: Adapter[] = [
proxy,
pstakeFinance,
pufferFinance,
purpleBridgeDex,
qidao,
quickswapDex,
radiantV1,
Expand Down
10 changes: 10 additions & 0 deletions src/adapters/nasdex/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Adapter } from '@lib/adapter'

import * as polygon from './polygon'

const adapter: Adapter = {
id: 'nasdex',
polygon: polygon,
}

export default adapter
44 changes: 44 additions & 0 deletions src/adapters/nasdex/polygon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { getNasdexPendingRewards } from '@adapters/nasdex/polygon/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'

const masterChef: Contract = {
chain: 'ethereum',
address: '0x35cA0e02C4c16c94c4cC8B67D13d660b78414f95',
}

const NSDX: Contract = {
chain: 'ethereum',
address: '0x35cA0e02C4c16c94c4cC8B67D13d660b78414f95',
decimals: 18,
symbol: 'NSDX',
}

export const getContracts = async (ctx: BaseContext) => {
const pools = await getMasterChefPoolsContracts(ctx, { masterChefAddress: masterChef.address })

return {
contracts: { pools },
}
}

export const getBalances: GetBalancesHandler<typeof getContracts> = async (ctx, contracts) => {
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, {
pools: (...args) =>
getMasterChefPoolsBalances(...args, {
masterChefAddress: masterChef.address,
rewardToken: NSDX,
getUserPendingRewards: getNasdexPendingRewards,
}),
})

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

export const config: AdapterConfig = {
startDate: 1635379200,
}
35 changes: 35 additions & 0 deletions src/adapters/nasdex/polygon/masterchef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { BalancesContext, Contract } from '@lib/adapter'
import { mapSuccessFilter } from '@lib/array'
import type { GetUsersInfosParams } from '@lib/masterchef/masterChefBalance'
import { multicall } from '@lib/multicall'

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

export async function getNasdexPendingRewards(
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.pendingNSDX,
})

return mapSuccessFilter(userPendingRewards, (res: any, index) => {
const pool = pools[index]
const reward = rewardToken || (pool.rewards?.[0] as Contract)

return [{ ...reward, amount: res.output }]
})
}

0 comments on commit 882f649

Please sign in to comment.