Emulate Set instead of Array for generic "many values" #96
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update
handleAddManyValueGeneric
handler to treat "many values" as a Set instead of an Array.I think this is desired behavior, but would love input from others on this.
Current behavior:
100
is added twice, generic json would be{<key>: [100, 100]}
Updated behavior:
100
is added twice, generic json would be:{<key>: [100]}
A Set is typically preferable because how Solidity works so well with mappings, which act more like Sets than Arrays. Emulating a Set in our subgraph eliminates on-chain validation to protect against adding something more than once (reducing gas cost and on-chain complexity). Most relevant current example is this line in our MinterHolder
With this update, smart contract doesn't have to validate if the project is already allowlisted, it simply sets the mapping value to true, and emits an event indicating the project is allowlisted. It is up to the frontend to intelligently avoid duplicate allow/deny requests when queueing up txs.
Cc @mchrupcala since this was based on convo from today 馃檹