diff --git a/.vscode/launch.json b/.vscode/launch.json index 9cd30acd2..556d5a5e3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -147,6 +147,7 @@ "big-data-protocol", "binance-staked-eth", "biswap", + "blackrockfund", "blast", "bloom", "blueberry-lend", diff --git a/src/adapters/blackrockfund/ethereum/index.ts b/src/adapters/blackrockfund/ethereum/index.ts new file mode 100644 index 000000000..7a2a0bd45 --- /dev/null +++ b/src/adapters/blackrockfund/ethereum/index.ts @@ -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 = async (ctx, contracts) => { + const balances = await resolveBalances(ctx, contracts, { + pools: (...args) => getBlackRockFundMasterChefPoolBalances(...args, masterChef), + pools2: (...args) => getBlackRockFundMasterChefPoolBalances(...args, masterChef2), + }) + + return { + groups: [{ balances }], + } +} + +export const config: AdapterConfig = { + startDate: 1708560000, +} diff --git a/src/adapters/blackrockfund/ethereum/masterChef.ts b/src/adapters/blackrockfund/ethereum/masterChef.ts new file mode 100644 index 000000000..e1bc72f94 --- /dev/null +++ b/src/adapters/blackrockfund/ethereum/masterChef.ts @@ -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 { + 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 }] + }) +} diff --git a/src/adapters/blackrockfund/index.ts b/src/adapters/blackrockfund/index.ts new file mode 100644 index 000000000..7b4f083c0 --- /dev/null +++ b/src/adapters/blackrockfund/index.ts @@ -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 diff --git a/src/adapters/index.ts b/src/adapters/index.ts index b3d158ecf..495275f11 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -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' @@ -458,6 +459,7 @@ export const adapters: Adapter[] = [ bigDataProtocol, binanceStakedEth, biswap, + blackrockfund, blast, bloom, blueberryLend,