From e96dd774ac55315b4c604634bef1af78bc8b7653 Mon Sep 17 00:00:00 2001 From: claibornej <> Date: Fri, 7 Apr 2023 12:18:56 +0800 Subject: [PATCH] Change babywealthyclub strategy --- src/strategies/babywealthyclub/examples.json | 64 ++++++++++++++--- src/strategies/babywealthyclub/index.ts | 76 +++++++++++--------- 2 files changed, 97 insertions(+), 43 deletions(-) diff --git a/src/strategies/babywealthyclub/examples.json b/src/strategies/babywealthyclub/examples.json index d77fe1f8a..27ba10055 100644 --- a/src/strategies/babywealthyclub/examples.json +++ b/src/strategies/babywealthyclub/examples.json @@ -4,20 +4,64 @@ "strategy": { "name": "babywealthyclub", "params": { - "address": "0x1f9655c660B915b4344b71e2A6d3155C57AD1bB6", - "symbol": "BRC", - "decimals": "9", - "weighted": 20000000000 + "strategies": [ + { + "name": "erc721", + "network": "1", + "params": { + "address": "0x75009fB6e3d4401b8C64548d33e9a3A9415F5d70", + "symbol": "BWC" + } + }, + { + "name": "erc721", + "network": "42161", + "params": { + "address": "0x75009fB6e3d4401b8C64548d33e9a3A9415F5d70", + "symbol": "BWC" + } + }, + { + "name": "erc721", + "network": "137", + "params": { + "address": "0x75009fB6e3d4401b8C64548d33e9a3A9415F5d70", + "symbol": "BWC" + } + }, + { + "name": "erc721", + "network": "43114", + "params": { + "address": "0x75009fB6e3d4401b8C64548d33e9a3A9415F5d70", + "symbol": "BWC" + } + }, + { + "name": "erc721", + "network": "10", + "params": { + "address": "0x75009fB6e3d4401b8C64548d33e9a3A9415F5d70", + "symbol": "BWC" + } + }, + { + "name": "erc721", + "network": "56", + "params": { + "address": "0x75009fB6e3d4401b8C64548d33e9a3A9415F5d70", + "symbol": "BWC" + } + } + ] } }, "network": "56", "addresses": [ - "0x7F57612b01689a0E4f133730AE20cC19E3dF0208", - "0x4A7998DF2Cd16815271bb6b7d3aE7EB30f50a73a", - "0x08D816526BdC9d077DD685Bd9FA49F58A5Ab8e48", - "0x21fF20E7e1B820020415707298b92299CF0951fE", - "0xa7A01B93B889ff0639d5ec02914A77529924a46F" + "0xe0e4f69A250b10c4e9ce1334fcA51599eA39C0e4", + "0x9feab70f3c4a944b97b7565bac4991df5b7a69ff", + "0xaca39b187352d9805deced6e73a3d72abf86e7a0" ], - "snapshot": 23976608 + "snapshot": 26920121 } ] diff --git a/src/strategies/babywealthyclub/index.ts b/src/strategies/babywealthyclub/index.ts index aea541d04..ac1e13302 100644 --- a/src/strategies/babywealthyclub/index.ts +++ b/src/strategies/babywealthyclub/index.ts @@ -1,14 +1,10 @@ -import { strategy as erc20BalanceOfStrategy } from '../erc20-balance-of'; -import { formatUnits } from '@ethersproject/units'; -import { multicall } from '../../utils'; +// import { formatUnits } from '@ethersproject/units'; +import { getProvider, getSnapshots } from '../../utils'; +import strategies from '..'; +// import { multicall } from '../../utils'; -export const author = 'gp6284'; -export const version = '0.1.0'; - -const abi = [ - 'function balanceOf(address account) external view returns (uint256)' -]; -const BWC_ADDRESS = '0xb7F7c7D91Ede27b019e265F8ba04c63333991e02'; +export const author = 'claibornej'; +export const version = '0.2.0'; export async function strategy( space, @@ -18,31 +14,45 @@ export async function strategy( options, snapshot ) { - const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; - const erc20Balance = await erc20BalanceOfStrategy( - space, - network, - provider, - addresses, - options, - snapshot - ); - const response = await multicall( + const promises: any = []; + const blocks = await getSnapshots( network, + snapshot, provider, - abi, - addresses.map((address: any) => [BWC_ADDRESS, 'balanceOf', [address]]), - { blockTag } + options.strategies.map((s) => s.network || network) ); - return Object.fromEntries( - addresses.map((address, i) => [ - address, - parseFloat(formatUnits(response[i].toString(), 0)) > 0 - ? Math.floor( - erc20Balance[addresses[i]] / (options.weighted || 10000000000) - ) - : 0 - ]) - ); + for (const strategy of options.strategies) { + // If snapshot is taken before a network is activated then ignore its strategies + if ( + options.startBlocks && + blocks[strategy.network] < options.startBlocks[strategy.network] + ) { + continue; + } + + promises.push( + strategies[strategy.name].strategy( + space, + strategy.network, + getProvider(strategy.network), + addresses, + strategy.params, + blocks[strategy.network] + ) + ); + } + + const results = await Promise.all(promises); + const resp = results.reduce((finalResults: any, strategyResult: any) => { + for (const [address, value] of Object.entries(strategyResult)) { + if (!finalResults[address]) { + finalResults[address] = 0; + } + finalResults[address] += value; + } + return finalResults; + }, {}); + + return resp; }