Skip to content

Commit

Permalink
Strategy: erc1155 with multiplier [erc1155-with-multiplier] (snapshot…
Browse files Browse the repository at this point in the history
…-labs#188)

* adds strategy

* runs tests

* updates example.json

* tests green

* Update src/strategies/erc1155-with-multiplier/index.ts

Co-authored-by: Chaitanya <[email protected]>
  • Loading branch information
fabianschu and ChaituVR authored Nov 24, 2021
1 parent 78e9f9e commit 63e1025
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/strategies/erc1155-with-multiplier/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"name": "Example query",
"strategy": {
"name": "erc1155-with-multiplier",
"params": {
"address": "0x2C56b43983Ca77cc29b27B4a731F0f0d54ae7e52",
"tokenId": 1,
"symbol": "DAWN",
"decimals": 0,
"multiplier": 5
}
},
"network": "4",
"addresses": [
"0x9cA70B93CaE5576645F5F069524A9B9c3aef5006",
"0xb5aE5169F4D750e802884d81b4f9eC66c525396F"
],
"snapshot": 9694956
}
]
38 changes: 38 additions & 0 deletions src/strategies/erc1155-with-multiplier/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { formatUnits } from '@ethersproject/units';
import { multicall } from '../../utils';

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

const abi = [
'function balanceOf(address owner, uint256 id) view returns (uint256)'
];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {
const multiplier = options.multiplier || 1;
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
const response = await multicall(
network,
provider,
abi,
addresses.map((address: any) => [
options.address,
'balanceOf',
[address, options.tokenId]
]),
{ blockTag }
);
return Object.fromEntries(
response.map((value, i) => [
addresses[i],
parseFloat(formatUnits(value.toString(), options.decimals)) * multiplier
])
);
}
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import * as pobHash from './pob-hash';
import * as totalAxionShares from './total-axion-shares';
import * as erc1155BalanceOf from './erc1155-balance-of';
import * as erc1155BalanceOfCv from './erc1155-balance-of-cv';
import * as erc1155WithMultiplier from './erc1155-with-multiplier';
import * as compLikeVotes from './comp-like-votes';
import * as governorAlpha from './governor-alpha';
import * as pagination from './pagination';
Expand Down Expand Up @@ -296,6 +297,7 @@ const strategies = {
'tranche-staking': trancheStaking,
pepemon,
'erc1155-all-balances-of': erc1155AllBalancesOf,
'erc1155-with-multiplier': erc1155WithMultiplier,
'saffron-finance': saffronFinance,
'saffron-finance-v2': saffronFinanceV2,
'tranche-staking-lp': trancheStakingLP,
Expand Down
1 change: 0 additions & 1 deletion test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const moreArg =
.find((arg) => arg.includes('--more='))
?.split('--more=')
?.pop();

const strategy = Object.keys(snapshot.strategies).find((s) => strategyArg == s);
if (!strategy) throw 'Strategy not found';
const example = require(`../src/strategies/${strategy}/examples.json`)[0];
Expand Down

0 comments on commit 63e1025

Please sign in to comment.