Skip to content

Commit

Permalink
feat:Adapter,BlackRockFund (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpeluche authored Mar 21, 2024
1 parent 1c8bf30 commit 9234ca5
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 @@ -147,6 +147,7 @@
"big-data-protocol",
"binance-staked-eth",
"biswap",
"blackrockfund",
"blast",
"bloom",
"blueberry-lend",
Expand Down
40 changes: 40 additions & 0 deletions src/adapters/blackrockfund/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { getBlackRockFundMasterChefPoolBalances } from '@adapters/blackrockfund/ethereum/masterChef'
import type { AdapterConfig, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter'
import { resolveBalances } from '@lib/balance'
import { getMasterChefPoolsContracts } from '@lib/masterchef/masterChefContract'

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

const masterChef2: Contract = {
chain: 'ethereum',
address: '0x1e4a10d18698e4450e13b4e8ef361a5841850611',
}

export const getContracts = async (ctx: BaseContext) => {
const [pools, pools2] = await Promise.all([
getMasterChefPoolsContracts(ctx, { masterChefAddress: masterChef.address }),
getMasterChefPoolsContracts(ctx, { masterChefAddress: masterChef2.address }),
])

return {
contracts: { pools, pools2 },
}
}

export const getBalances: GetBalancesHandler<typeof getContracts> = async (ctx, contracts) => {
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, {
pools: (...args) => getBlackRockFundMasterChefPoolBalances(...args, masterChef),
pools2: (...args) => getBlackRockFundMasterChefPoolBalances(...args, masterChef2),
})

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

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

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

const BTC: Contract = {
chain: 'ethereum',
address: '0xbD6323A83b613F668687014E8A5852079494fB68',
decimals: 18,
symbol: 'BTC',
}

export async function getBlackRockFundMasterChefPoolBalances(
ctx: BalancesContext,
pools: Contract[],
masterChef: Contract,
): Promise<Balance[]> {
return getMasterChefPoolsBalances(ctx, pools, {
masterChefAddress: masterChef.address,
rewardToken: BTC,
getUserPendingRewards: getUserPendingBTC,
})
}

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

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

return [{ ...reward, amount: res.output }]
})
}
10 changes: 10 additions & 0 deletions src/adapters/blackrockfund/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: 'blackrockfund',
ethereum: ethereum,
}

export default adapter
2 changes: 2 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import bifrostLiquidStaking from '@adapters/bifrost-liquid-staking'
import bigDataProtocol from '@adapters/big-data-protocol'
import binanceStakedEth from '@adapters/binance-staked-eth'
import biswap from '@adapters/biswap'
import blackrockfund from '@adapters/blackrockfund'
import blast from '@adapters/blast'
import bloom from '@adapters/bloom'
import blueberryLend from '@adapters/blueberry-lend'
Expand Down Expand Up @@ -458,6 +459,7 @@ export const adapters: Adapter[] = [
bigDataProtocol,
binanceStakedEth,
biswap,
blackrockfund,
blast,
bloom,
blueberryLend,
Expand Down

0 comments on commit 9234ca5

Please sign in to comment.