-
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.
- Loading branch information
Showing
5 changed files
with
98 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,10 @@ | ||
import type { Adapter } from '@lib/adapter' | ||
|
||
import * as polygon from './polygon' | ||
|
||
const adapter: Adapter = { | ||
id: 'nasdex', | ||
polygon: polygon, | ||
} | ||
|
||
export default adapter |
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,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, | ||
} |
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,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 }] | ||
}) | ||
} |