-
Notifications
You must be signed in to change notification settings - Fork 787
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
base: master
Are you sure you want to change the base?
Changes from all commits
1a6b5e9
b7e3fbe
21b04d5
0daef72
9dc132a
4d04bb1
4cc66ab
0868d21
beebee9
3fe72ca
26f5cc5
dd7bee1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
} | ||
``` |
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 | ||
} | ||
] |
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 | ||
) { | ||
const erc1155BlockTag = | ||
typeof options.erc1155BlockTag === 'number' | ||
? options.erc1155BlockTag | ||
: 'latest'; | ||
|
||
const erc721BlockTag = | ||
typeof options.erc721BlockTag === 'number' | ||
? options.erc721BlockTag | ||
: 'latest'; | ||
Comment on lines
+23
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Will the validation strategies flatten to 1 vote for X validations? Or is it X votes for X validations? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
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 | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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