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

Feat: onchain impacts and proof generation #18

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

Agilulfo1820
Copy link
Member

@Agilulfo1820 Agilulfo1820 commented Sep 10, 2024

Centralize the creation of the proof in the X2EarnRewardsPool contract. Apps now only need to pass:

  • proof types (link, image, video, text)
  • proof data (the URL to the proof)
  • the impacts
  • description of the action

This will allow easier integration from apps and fewer errors, and it will open up the possibility of using impacts to do calculations.

A new version of the proof is created now, and indexers will need to align (by checking the version number, if no version is present then it should be treated as version 1):

{
   version: 2,
   description: 'The description of the action',
   proof: { image: 'https://image.png', link: 'https://twitter.com/tweet/1' },
   impact: { carbon: 100, water: 200 }
}

The new function to call is called distributeRewardWithProof().
The original distributeReward() function will now only distribute the reward without emitting any proof (the proof param was deprecated, but left there for retro compatibility).
A new distributeRewardDeprecated can be called to distribute rewards + provide a json proof built by you, but it will removed as well in the future.

The available impacts are:

"carbon",
"water",
"energy",
"waste_mass",
"education_time",
"timber",
"plastic",
"trees_planted"

The deprecated impacts are:

waste_items
people
biodiversity

An additional buildProof() function was added allowing devs to preview what their proof will look like.

Impacts can be added or removed by an address that has the IMPACT_KEY_MANAGER_ROLE.

Proofs and Impact
      ✔ Json proof is created by the contract (1439ms)
      ✔ App can provide multiple proofs (305ms)
      ✔ App can provide only proofs without impact (296ms)
      ✔ App can provide only impact without proofs (301ms)
      ✔ If only description is passed, without proofs and impact, nothing is emitted (301ms)
      ✔ Description is not mandatory if proof or impact is passed (316ms)
      ✔ If no proof, nor impact, nor description is passed, nothing is emitted (320ms)
      ✔ If a non valid proof type is passed, it reverts (318ms)
      ✔ Only valid proofs are image, text, link, video (451ms)
      ✔ If a non valid impact type is passed, it reverts (333ms)
      ✔ If impact values length differs from codes length, it reverts (324ms)
      ✔ If proof values length differs from types length, it reverts (329ms)
      ✔ Anyone can index available impact codes (332ms)
      ✔ IMPACT_KEY_MANAGER_ROLE and DEFAULT_ADMIN can remove an impact code (347ms)
      ✔ IMPACT_KEY_MANAGER_ROLE and DEFAULT_ADMIN can add an impact code (359ms)
      ✔ Non admin users cannot add and remove impact codes (344ms)

Gas increase

Current mainnet gas usage:
distributeReward 98959

This PR:
distributeRewards 99519
distributeRewardWithProof 115531 (14.89% increase)

@Agilulfo1820 Agilulfo1820 requested a review from a team as a code owner September 10, 2024 16:08
Copy link
Contributor

@roisindowling roisindowling left a comment

Choose a reason for hiding this comment

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

LGTM!

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 76.96970% with 38 lines in your changes missing coverage. Please review.

Project coverage is 94.50%. Comparing base (d2eab62) to head (05f55cf).

Files with missing lines Patch % Lines
contracts/deprecated/V1/X2EarnRewardsPoolV1.sol 50.68% 36 Missing ⚠️
contracts/X2EarnRewardsPool.sol 97.82% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #18      +/-   ##
==========================================
- Coverage   96.06%   94.50%   -1.57%     
==========================================
  Files          38       39       +1     
  Lines        2440     2601     +161     
  Branches      515      561      +46     
==========================================
+ Hits         2344     2458     +114     
- Misses         95      142      +47     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Agilulfo1820 Agilulfo1820 merged commit 05df3ae into main Sep 10, 2024
3 checks passed
ifavo added a commit to vechain-energy/subgraph-vebetter-dao that referenced this pull request Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants