Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[babywealthyclub] Change babywealthyclub strategy #1124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 54 additions & 10 deletions src/strategies/babywealthyclub/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
76 changes: 43 additions & 33 deletions src/strategies/babywealthyclub/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
}