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

L2: linear rewards, and minting in L2 #700

Merged
merged 18 commits into from
Mar 27, 2023
Merged

L2: linear rewards, and minting in L2 #700

merged 18 commits into from
Mar 27, 2023

Conversation

pcarranzav
Copy link
Member

No description provided.

@codecov
Copy link

codecov bot commented Sep 1, 2022

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.07 🎉

Comparison is base (3fe26fa) 91.59% compared to head (dc40106) 91.66%.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #700      +/-   ##
==========================================
+ Coverage   91.59%   91.66%   +0.07%     
==========================================
  Files          42       41       -1     
  Lines        1999     2016      +17     
  Branches      361      365       +4     
==========================================
+ Hits         1831     1848      +17     
  Misses        168      168              
Flag Coverage Δ
unittests 91.66% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
contracts/gateway/L1GraphTokenGateway.sol 100.00% <100.00%> (ø)
contracts/rewards/RewardsManager.sol 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@tmigone tmigone added the L2 label Sep 2, 2022
@pcarranzav pcarranzav force-pushed the pcv/l2-linear-rewards branch from ba07101 to 8b9efa8 Compare September 2, 2022 19:05
@tmigone tmigone force-pushed the pcv/l2-bridge branch 2 times, most recently from ae18852 to 5073920 Compare September 7, 2022 10:15
@pcarranzav pcarranzav force-pushed the pcv/l2-linear-rewards branch from 6d96ff5 to 08617fa Compare September 7, 2022 16:48
Copy link
Contributor

@abarmat abarmat left a comment

Choose a reason for hiding this comment

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

I've did a first pass on the RewardsManager, haven't checked the tests nor the Gateway yet. Overall, I'm loving how simple it looking

* @param _block Block at which allowance will be computed
* @return The accumulated GRT amount that can be minted from L2 at the specified block
*/
function accumulatedL2MintAllowanceAtBlock(uint256 _block) public view returns (uint256) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think if we use _blockNum to make it consistent with the _updateBlockNum in updateL2MintAllowance()?

@@ -209,28 +202,18 @@ contract RewardsManager is RewardsManagerV3Storage, GraphUpgradeable, IRewardsMa
return 0;
}

// Zero issuance under a rate of 1.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Just an observation: we could still keep this check to avoid the CALL to graphToken() and curation() contract if issuance rate is zero. However, as we are deploying it in L2 initially, it will be cheaper and don't have a big effect.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, adding it back


// New issuance of tokens during time steps
uint256 x = a.sub(p);
uint256 x = issuancePerBlock.mul(t);
Copy link
Contributor

Choose a reason for hiding this comment

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

I love how simple this is

using SafeMath for uint256;

uint256 private constant TOKEN_DECIMALS = 1e18;
uint256 private constant MIN_ISSUANCE_RATE = 1e18;
uint256 private constant FIXED_POINT_SCALING_FACTOR = 1e18;
Copy link
Contributor

Choose a reason for hiding this comment

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

This name is more precise

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the auditors had commented TOKEN_DECIMALS could be confusing in #571 so I used this name there as well

* Called from the Curation contract on mint() and burn()
* @return Accumulated rewards per signal
*/
function updateAccRewardsPerSignal() public override returns (uint256) {
accRewardsPerSignal = getAccRewardsPerSignal();
accRewardsPerSignalLastBlockUpdated = block.number;
tokenSupplySnapshot = graphToken().totalSupply();
Copy link
Contributor

Choose a reason for hiding this comment

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

And we could get rid of this 👍

@@ -8,7 +8,7 @@ import "../governance/Managed.sol";
contract RewardsManagerV1Storage is Managed {
// -- State --

uint256 public issuanceRate;
uint256 public issuanceRateDeprecated;
Copy link
Contributor

Choose a reason for hiding this comment

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

Small optimization: we can make this variable private to avoid including a getter in the bytecode

Copy link
Contributor

@abarmat abarmat left a comment

Choose a reason for hiding this comment

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

Just some small comments

abarmat
abarmat previously approved these changes Sep 7, 2022
await expect(
await l1GraphTokenGateway.accumulatedL2MintAllowanceAtBlock(await latestBlock()),
).to.eq(issuancePerBlock.mul(3))
await expect(await l1GraphTokenGateway.accumulatedL2MintAllowanceSnapshot()).to.eq(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove the outer await as the internal one returns the promised value

.emit(l1GraphTokenGateway, 'L2MintAllowanceUpdated')
.withArgs(snapshotValue, issuancePerBlock, issuanceUpdatedAtBlock)
// Now the mint allowance should be 10 + issuancePerBlock * 3
await expect(
Copy link
Contributor

Choose a reason for hiding this comment

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

no-op await

toBN('0'),
encodedCalldata,
)
await expect(tx)
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to combine this like:

        await expect(tx)
          .emit(l1GraphTokenGateway, 'WithdrawalFinalized')
          .withArgs(grt.address, l2Receiver.address, tokenSender.address, toBN('0'), toGRT('18'))
          .emit(l1GraphTokenGateway, 'TokensMintedFromL2')
          .withArgs(toGRT('8'))

@pcarranzav pcarranzav force-pushed the pcv/l2-linear-rewards branch from 7a8f68b to d8d009b Compare September 26, 2022 16:59
@tmigone tmigone mentioned this pull request Sep 26, 2022
@pcarranzav pcarranzav force-pushed the pcv/l2-linear-rewards branch from d8d009b to 0f9bca8 Compare September 27, 2022 00:36
@pcarranzav pcarranzav marked this pull request as ready for review September 27, 2022 00:44
@pcarranzav pcarranzav changed the base branch from pcv/l2-bridge to dev November 24, 2022 00:40
@pcarranzav pcarranzav dismissed abarmat’s stale review November 24, 2022 00:40

The base branch was changed.

Conflicts fixed for:
- contracts/gateway/L1GraphTokenGateway.sol
- test/gateway/l1GraphTokenGateway.test.ts
- test/rewards/rewards.test.ts
tmigone
tmigone previously approved these changes Mar 9, 2023
config/graph.mainnet.yml Show resolved Hide resolved
config/graph.mainnet.yml Show resolved Hide resolved
Copy link
Contributor

@abarmat abarmat left a comment

Choose a reason for hiding this comment

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

⚡️

Copy link
Contributor

@tmigone tmigone left a comment

Choose a reason for hiding this comment

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

🚀

@pcarranzav pcarranzav merged commit 23611af into dev Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants