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

Create ERC721-With-Balance strategy #207

Closed
wants to merge 4 commits into from
Closed
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
15 changes: 15 additions & 0 deletions src/strategies/erc721-with-balance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# erc721-with-balance

This is a strategy to allow egalitarian voting power to holders of an ERC-721 token.

A `minBalance` can be defined. It returns a voting power of `1` if the balance of the voter for a specific ERC-721 token is **greater than or equal** to the minBalance.

Here is an example of parameters:

```json
{
"address": "0x25ed58c027921e14d86380ea2646e3a1b5c55a8b",
"symbol": "DEVS",
"minBalance": 1
}
```
25 changes: 25 additions & 0 deletions src/strategies/erc721-with-balance/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"name": "Example query with minimum ERC-721 balance",
"strategy": {
"name": "erc721-with-balance",
"params": {
"address": "0x25ed58c027921e14d86380ea2646e3a1b5c55a8b",
"symbol": "DEVS",
"minBalance": 1
}
},
"network": "1",
"addresses": [
"0x0000000000000000000000000000000000baddad",
"0x76da95534c57516625948baA9d069D5ed371b324",
"0xb1c015bc96958e42b670c502bc29be791e754127",
"0x03f9bc4648a98cdc61fca7a177d809edab2c14fc",
"0x27f8602e403b6ea18f8711a7858fa4a94ef3269b",
"0xa703b1cb89f50939173a124ba76571369cf69953",
"0x184e2d53a04bc87a6b597703edcd62d768da1f27",
"0xa4a13b3f22bc0e90235e17ae9343b2c7e04e96c8"
],
"snapshot": 13647430
}
]
33 changes: 33 additions & 0 deletions src/strategies/erc721-with-balance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { formatUnits } from '@ethersproject/units';
import { multicall } from '../../utils';

export const author = 'WillBlackburn';
export const version = '0.1.1';

const abi = [
'function balanceOf(address account) external view returns (uint256)'
];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
const response = await multicall(
network,
provider,
abi,
addresses.map((address: any) => [options.address, 'balanceOf', [address]]),
{ blockTag }
);
return Object.fromEntries(
response.map((value, i) => [
addresses[i],
parseInt(formatUnits(value.toString(), 0)) >= (options.minBalance || 1) ? 1 : 0
])
);
}
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ import * as xseen from './xseen';
import * as molochAll from './moloch-all';
import * as molochLoot from './moloch-loot';
import * as erc721Enumerable from './erc721-enumerable';
import * as erc721WithBalance from './erc721-with-balance';
import * as erc721WithMultiplier from './erc721-with-multiplier';
import * as erc721WithTokenId from './erc721-with-tokenid';
import * as hoprUniLpFarm from './hopr-uni-lp-farm';
Expand Down Expand Up @@ -235,6 +236,7 @@ const strategies = {
'maker-ds-chief': makerDsChief,
erc721,
'erc721-enumerable': erc721Enumerable,
'erc721-with-balance': erc721WithBalance,
'erc721-with-multiplier': erc721WithMultiplier,
'erc721-with-tokenid': erc721WithTokenId,
'erc721-multi-registry': erc721MultiRegistry,
Expand Down