-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Add NFT-Based Voting & Dynamic Delegation Support to Votes.behavior.js #5842
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
base: master
Are you sure you want to change the base?
Conversation
…s Tests The changes maintain all existing functionality while adding comprehensive support for NFT-based voting scenarios. The tests cover: Dynamic vote weights based on NFT metadata Proper delegation handling during transfers Metadata changes affecting voting power Batch operations for large collections Edge cases around transfers and delegation
|
Hi @sohamsk13, would you mind fixing the CI? If the tests are good we're happy to get them merged |
Sure I will |
this.other, | ||
this.charlie, | ||
this.dave |
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.
this.other, | |
this.charlie, | |
this.dave | |
this.charlie, | |
this.dave, | |
this.other, |
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.
I'd consider renaming to alice / bruce / chris / david, so that all names are 5 letters long
this.metadata = {}; | ||
tokens.forEach(tokenId => { | ||
this.metadata[tokenId] = { | ||
weight: (tokenId % 10n) + 1n, // Example: weight based on token ID | ||
rarity: ['common', 'uncommon', 'rare', 'legendary'][Number(tokenId % 4n)] // Example metadata | ||
}; | ||
}); |
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.
We can build the metadata registry directly
this.metadata = {}; | |
tokens.forEach(tokenId => { | |
this.metadata[tokenId] = { | |
weight: (tokenId % 10n) + 1n, // Example: weight based on token ID | |
rarity: ['common', 'uncommon', 'rare', 'legendary'][Number(tokenId % 4n)] // Example metadata | |
}; | |
}); | |
this.metadata = Object.fromEntries(tokens.map(tokenId => [ | |
tokenId, | |
{ | |
weight: (tokenId % 10n) + 1n, // Example: weight based on token ID | |
rarity: ['common', 'uncommon', 'rare', 'legendary'][Number(tokenId % 4n)] // Example metadata | |
} | |
])); |
}; | ||
}); | ||
|
||
this.getNFTWeight = (tokenId) => this.metadata[tokenId]?.weight || 1n; |
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.
we should not need that, getWeight
(defined later) should be enough
}); | ||
|
||
shouldBehaveLikeERC6372(mode); | ||
|
||
const getWeight = token => (fungible ? token : 1n); | ||
const getWeight = token => (fungible ? token : (this.getNFTWeight ? this.getNFTWeight(token) : 1n)); |
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.
const getWeight = token => (fungible ? token : (this.getNFTWeight ? this.getNFTWeight(token) : 1n)); | |
const getWeight = token => this?.metadata?.[token]?.weigth ?? 1n; |
Dynamic vote weights based on NFT metadata
Proper delegation handling during transfers
Metadata changes affecting voting power
Batch operations for large collections
Edge cases around transfers and delegation
PR : 5209