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

[erc721-and-erc1155-flattened] added erc721-and-erc115-flattened project #1208

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
16 changes: 16 additions & 0 deletions src/strategies/erc721-and-erc1155-flattened/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# nft-and-rep-flattened

A strategy where you can check to see if addresses have a specified balance of ERC721s and ERC1155s with multi-chain support.

Here is an example of parameters:

```json
{
"erc721Address": "0x63f8F23ce0f3648097447622209E95A391c44b00",
"erc1155Address": "0x57AA5fd0914A46b8A426cC33DB842D1BB1aeADa2",
"erc721MinTokens": 1,
"erc1155MinTokens": 10,
"erc721NetworkId": "1",
"erc1155NetworkId": "137"
}
```
52 changes: 52 additions & 0 deletions src/strategies/erc721-and-erc1155-flattened/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"name": "Example query without specifying block tags",
"strategy": {
"name": "erc721-and-erc1155-flattened",
"params": {
"erc721Address": "0x63f8F23ce0f3648097447622209E95A391c44b00",
"erc1155Address": "0x57AA5fd0914A46b8A426cC33DB842D1BB1aeADa2",
"erc721MinTokens": 1,
"erc1155MinTokens": 10,
"erc721NetworkId": "1",
"erc1155NetworkId": "137"
}
},
"network": "10",
"addresses": [
"0x407Cf0e5Dd3C2c4bCE5a32B92109c2c6f7f1ce23",
"0x6d7ddD863eB2Dad990bC05BDd3357E32850509E9",
"0x9AfD4F7aD03A03d306B41a4604Ea2928cFf78fd1",
"0x17AB342e3Bd3c080b4f48fe20165D5E94185EE2d",
"0xf83b3A823653E8351b173Fa2Ae083Af37EAbCC01",
"0xc4f6578c24c599F195c0758aD3D4861758d703A3"
],
"snapshot": 45008012
},
{
"name": "Example query with specifying block tags",
"strategy": {
"name": "erc721-and-erc1155-flattened",
"params": {
"erc721Address": "0x63f8F23ce0f3648097447622209E95A391c44b00",
"erc1155Address": "0x57AA5fd0914A46b8A426cC33DB842D1BB1aeADa2",
"erc721MinTokens": 1,
"erc1155MinTokens": 10,
"erc721NetworkId": "1",
"erc1155NetworkId": "137",
"erc721BlockTag": 17680834,
"erc1155BlockTag": 45008012
}
},
"network": "10",
"addresses": [
"0x407Cf0e5Dd3C2c4bCE5a32B92109c2c6f7f1ce23",
"0x6d7ddD863eB2Dad990bC05BDd3357E32850509E9",
"0x9AfD4F7aD03A03d306B41a4604Ea2928cFf78fd1",
"0x17AB342e3Bd3c080b4f48fe20165D5E94185EE2d",
"0xf83b3A823653E8351b173Fa2Ae083Af37EAbCC01",
"0xc4f6578c24c599F195c0758aD3D4861758d703A3"
],
"snapshot": 45008012
}
]
85 changes: 85 additions & 0 deletions src/strategies/erc721-and-erc1155-flattened/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { multicall } from '../../utils';
import snapshotjs from '@snapshot-labs/snapshot.js';

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

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

const abi1155 = [
'function balanceOf(address _owner, uint256 _id) external view returns (uint256)'
];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
Copy link
Member

Choose a reason for hiding this comment

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

It should depend on proposal snapshot

) {
const erc1155BlockTag =
typeof options.erc1155BlockTag === 'number'
? options.erc1155BlockTag
: 'latest';

const erc721BlockTag =
typeof options.erc721BlockTag === 'number'
? options.erc721BlockTag
: 'latest';
Comment on lines +23 to +31
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to avoid issues, better to use two https://snapshot.org/#/strategy/validation strategies inside voting validation https://docs.snapshot.org/user-guides/strategies/validation-strategies#voting-validation-in-space-settings

Will the validation strategies flatten to 1 vote for X validations? Or is it X votes for X validations?
I am looking to do: if (user.erc721balance >= 1 && user.erc1155balance >= 10) { user.votingPower = 1 }

Copy link
Member

Choose a reason for hiding this comment

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

Yep that should work


const erc1155Response = await multicall(
options.erc1155NetworkId,
snapshotjs.utils.getProvider(options.erc1155NetworkId),
abi1155,
addresses.map((address: any) => [
options.erc1155Address,
'balanceOf',
[address, 1]
]),
{ blockTag: erc1155BlockTag }
);

const erc721Response = await multicall(
options.erc721NetworkId,
snapshotjs.utils.getProvider(options.erc721NetworkId),
abi721,
addresses.map((address: any) => [
options.erc721Address,
'balanceOf',
[address]
]),
{ blockTag: erc721BlockTag }
);

const values = <any>[];

for (let i = 0; i < addresses.length; i++) {
const val = {
address: addresses[i],
hasERC721Requirement: false,
hasERC1155Requirement: false
};

if (erc1155Response[i] >= options.erc1155MinTokens) {
val.hasERC1155Requirement = true;
}

if (parseFloat(erc721Response[i]) >= options.erc721MinTokens) {
val.hasERC721Requirement = true;
}

values.push(val);
}

const finalObj = {};

for (let i = 0; i < values.length; i++) {
finalObj[values[i].address] =
values[i].hasERC721Requirement && values[i].hasERC1155Requirement ? 1 : 0;
}

return finalObj;
}
64 changes: 64 additions & 0 deletions src/strategies/erc721-and-erc1155-flattened/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Strategy",
"definitions": {
"Strategy": {
"title": "erc721-and-erc1155-flattened",
"type": "object",
"properties": {
"erc721Address": {
"type": "string",
"title": "erc721Address",
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"erc1155Address": {
"type": "string",
"title": "erc1155Address",
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"erc721MinTokens": {
"type": "number",
"title": "Minimum ERC 721 Tokens",
"examples": ["e.g. 1"]
},
"erc1155MinTokens": {
"type": "number",
"title": "Minimum ERC 1155 Tokens",
"examples": ["e.g. 50"]
},
"erc721NetworkId": {
"type": "string",
"title": "ERC 721 Network Id",
"examples": ["e.g. 1"],
"minLength": 1,
"maxLength": 42
},
"erc1155NetworkId": {
"type": "string",
"title": "ERC 1155 Network Id",
"examples": ["e.g. 137"],
"minLength": 1,
"maxLength": 42
},
"erc721BlockTag": {
"type": "number",
"title": "ERC 721 Block Tag",
"examples": ["e.g. 17680834"]
},
"erc1155BlockTag": {
"type": "number",
"title": "ERC 1155 Block Tag",
"examples": ["e.g. 45008012"]
}
},
"required": ["erc721Address", "erc1155Address", "erc721MinTokens", "erc1155MinTokens", "erc721NetworkId", "erc1155NetworkId"],
"additionalProperties": false
}
}
}
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ import * as erc721CollateralHeld from './erc721-collateral-held';
import * as starlayVeBalanceOfLockerId from './starlay-ve-balance-of-locker-id';
import * as winrStaking from './winr-staking';
import * as spaceid from './spaceid';
import * as erc721AndErc1155Flattened from './erc721-and-erc1155-flattened';
import * as seedifyHoldStakingFarming from './seedify-cumulative-voting-power-hodl-staking-farming';

const strategies = {
Expand Down Expand Up @@ -900,6 +901,7 @@ const strategies = {
'starlay-ve-balance-of-locker-id': starlayVeBalanceOfLockerId,
'winr-staking': winrStaking,
spaceid,
'erc721-and-erc1155-flattened': erc721AndErc1155Flattened,
'seedify-cumulative-voting-power-hodl-staking-farming':
seedifyHoldStakingFarming
};
Expand Down
Loading