Skip to content

Commit

Permalink
[holds-tokens] Combined meebits strat (snapshot-labs#85)
Browse files Browse the repository at this point in the history
* Fix example and readme in meebitsdao strategy

* holding token strategy

* meebit strat not working

* fix rpc issue, but strat still broken

* snapshot voting working

* changes to readme

* change readme

* rever package-lock.json

* fetching the block number if we are not using latest

* updating readme

* updating token strategy to utilize multicall and erc20-with-balance

* remove console.log

* Update src/strategies/holds-tokens/examples.json

Co-authored-by: Chaitanya <[email protected]>

* add comma to example

Co-authored-by: Josh Peters <[email protected]>
Co-authored-by: Patrick Lu <[email protected]>
Co-authored-by: lightninglu10 <[email protected]>
Co-authored-by: Chaitanya <[email protected]>
  • Loading branch information
5 people authored Oct 1, 2021
1 parent b858b6a commit a8bba53
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/strategies/holds-tokens/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# holds-tokens

This strategy return the balances of the voters for a specific ERC20 or ERC721 and maps them to the number of votes that voter gets based on holding a set of tokens.

Here is an example of parameters:

```json
{
"tokenAddresses": [
{"address": "0x7Bd29408f11D2bFC23c34f18275bBf23bB716Bc7", "network": "1", "decimals": 0, "minBalance": 1},
{"address": "0xc34cbca32e355636c7f52dd8beab0af2396ebd79", "network": "137", "decimals": 0, "minBalance": 1}
]
}
```
24 changes: 24 additions & 0 deletions src/strategies/holds-tokens/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"name": "Example query",
"strategy": {
"name": "holds-tokens",
"params": {
"symbol": "ABC",
"tokenAddresses": [
{"address": "0x7Bd29408f11D2bFC23c34f18275bBf23bB716Bc7", "network": "1", "decimals": 0, "minBalance": 0},
{"address": "0xc34cbca32e355636c7f52dd8beab0af2396ebd79", "network": "137", "decimals": 0, "minBalance": 0}
]
}
},
"network": "1",
"addresses": [
"0xC5e38233Cc0D7CFf9340e6139367aBA498EC9b18",
"0x2009a752a50D3CDe486d7b5921944377B729E747",
"0x7b15e6c439b27a553b65a9904ce571da6691a0fb",
"0x8d2f3a76a76f055d62a931678ab16b042e7badeb",
"0xEDe64a571CFe98B936271B935a955620f387E05A"
],
"snapshot": 13317369
}
]
41 changes: 41 additions & 0 deletions src/strategies/holds-tokens/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { strategy as multichainStrategy } from '../multichain';

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

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {
const tokens = options.tokenAddresses || [];

options.strategies = tokens.map((token) => ({
"name": "erc20-with-balance",
"network": token.network,
"params": {
"address": token.address,
"decimals": token.decimals,
"minBalance": token.minBalance
}
}));

const scores: any = await multichainStrategy(
space,
network,
provider,
addresses,
options,
snapshot
);

return Object.fromEntries(
Object.entries(scores).map((address: any) => [
address[0],
(address[1] === tokens.length) ? 1 : 0
])
);
}
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ import * as eglVote from './egl-vote';
import * as mcnFarm from './mcn-farm';
import * as snowswap from './snowswap';
import * as meebitsdao from './meebitsdao';
import * as holdsTokens from './holds-tokens';
import * as crucibleERC20BalanceOf from './crucible-erc20-balance-of';
import * as hasrock from './has-rock';
import * as flexaCapacityStaking from './flexa-capacity-staking';
Expand Down Expand Up @@ -309,6 +310,7 @@ const strategies = {
'hopr-staking': hoprStaking,
'hopr-bridged-balance': hoprBridgedBalance,
'occ-stake-of': occStakeOf,
'holds-tokens': holdsTokens,
'loot-character-guilds': lootCharacterGuilds
};

Expand Down

0 comments on commit a8bba53

Please sign in to comment.