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-multi] Add babywealthyclub-multi strategy #1126

Open
wants to merge 2 commits 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
67 changes: 67 additions & 0 deletions src/strategies/babywealthyclub-multi/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[
{
"name": "Example query",
"strategy": {
"name": "babywealthyclub-multi",
"params": {
"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": [
"0xe0e4f69A250b10c4e9ce1334fcA51599eA39C0e4",
"0x9feab70f3c4a944b97b7565bac4991df5b7a69ff",
"0xaca39b187352d9805deced6e73a3d72abf86e7a0"
],
"snapshot": 26920121
}
]
56 changes: 56 additions & 0 deletions src/strategies/babywealthyclub-multi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { getProvider, getSnapshots } from '../../utils';
import strategies from '..';

export const author = 'claibornej';
export const version = '0.1.0';

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {
const promises: any = [];
const blocks = await getSnapshots(
network,
snapshot,
provider,
options.strategies.map((s) => s.network || network)
);

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;
Comment on lines +44 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @claibornej I think you can use multiple strategies in your space than a separate strategy, the result of multiple strategies will be sum of them

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to query the nft quantity of multiple chains

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claibornej You can do same from your space settings, you can select different network for different strategy

}, {});

return resp;
}
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ import * as lodestarStakedLp from './lodestar-staked-lp';
import * as jpegdLockedJpegOf from './jpegd-locked-jpeg-of';
import * as litDaoGovernance from './lit-dao-governance';
import * as babywealthyclub from './babywealthyclub';
import * as babywealthyclubMulti from './babywealthyclub-multi';
import * as battleflyVGFLYAndStakedGFLY from './battlefly-vgfly-and-staked-gfly';
import * as nexonArmyNFT from './nexon-army-nft';
import * as moonbeamFreeBalance from './moonbeam-free-balance';
Expand Down Expand Up @@ -865,6 +866,7 @@ const strategies = {
'lodestar-vesting': lodestarVesting,
'lodestar-staked-lp': lodestarStakedLp,
babywealthyclub,
'babywealthyclub-multi': babywealthyclubMulti,
'battlefly-vgfly-and-staked-gfly': battleflyVGFLYAndStakedGFLY,
'nexon-army-nft': nexonArmyNFT,
'moonbeam-free-balance': moonbeamFreeBalance,
Expand Down