-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add MinterCommitEmissionTest for emission rate update (#811)
* test: Add MinterCommitEmissionTest for emission rate update * test: Update test comments
- Loading branch information
Showing
4 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
branch = v1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule forge-std
updated
19 files
+29 −0 | .github/workflows/sync.yml | |
+1 −1 | foundry.toml | |
+1 −1 | lib/ds-test | |
+2 −2 | package.json | |
+5 −3 | src/Base.sol | |
+91 −40 | src/StdAssertions.sol | |
+17 −19 | src/StdChains.sol | |
+106 −2 | src/StdCheats.sol | |
+333 −0 | src/StdStyle.sol | |
+12 −3 | src/StdUtils.sol | |
+1 −0 | src/Test.sol | |
+108 −11 | src/Vm.sol | |
+394 −382 | src/console2.sol | |
+13,248 −0 | src/safeconsole.sol | |
+176 −0 | test/StdAssertions.t.sol | |
+20 −20 | test/StdChains.t.sol | |
+181 −3 | test/StdCheats.t.sol | |
+110 −0 | test/StdStyle.t.sol | |
+15 −0 | test/StdUtils.t.sol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
import {TestWithConstants} from "../../forge-script/TestWithConstants.sol"; | ||
import {console2 as console} from "forge-std/console2.sol"; | ||
|
||
interface IMinter { | ||
function rate() external view returns (uint256); | ||
|
||
function committed_rate() external view returns (uint256); | ||
|
||
function commit_next_emission(uint256) external; | ||
|
||
function admin() external view returns (address); | ||
|
||
function mint(address) external; | ||
|
||
function start_epoch_time_write() external returns (uint256); | ||
|
||
function update_mining_parameters() external; | ||
|
||
function start_epoch_time() external view returns (uint256); | ||
} | ||
|
||
interface IRootGuage { | ||
struct InflationParams { | ||
uint256 rate; | ||
uint256 finish_time; | ||
} | ||
|
||
function inflation_params() external view returns (InflationParams memory); | ||
} | ||
|
||
interface ILiquidityGaugeV5 { | ||
function inflation_rate() external view returns (uint256); | ||
} | ||
|
||
contract MinterCommitEmissionTest is TestWithConstants { | ||
IMinter public minter; | ||
address public minterAdmin; | ||
IRootGuage public rootGauge; | ||
ILiquidityGaugeV5 public liqGaugeV5; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
// Fork mainnet at block 17565727 | ||
vm.createSelectFork("mainnet", 17565727); | ||
minter = IMinter(getDeploymentAddress("Minter")); | ||
liqGaugeV5 = ILiquidityGaugeV5( | ||
getDeploymentAddress( | ||
"LiquidityGaugeV5_SaddleFRAXalUSDMetaPoolLPToken" | ||
) | ||
); | ||
rootGauge = IRootGuage( | ||
getDeploymentAddress("RootGauge_42161_SaddleFRAXBPPoolLPToken") | ||
); | ||
minterAdmin = minter.admin(); | ||
|
||
vm.label(address(minter), "Minter"); | ||
} | ||
|
||
// Test lowering the emission rate applies the new rate after the next mining epoch | ||
// and the new rate is applied to the gauges of both types | ||
function test_commitEmission() public { | ||
vm.startPrank(minterAdmin); | ||
// Assert that the current rate is 30M / 24 weeks | ||
uint256 currentRate = minter.rate(); | ||
assertEq(currentRate, (uint256(30_000_000 * 1e18) / 24) / 1 weeks); | ||
console.log("current rate: %s", currentRate); | ||
console.log("current commited_rate: %s", minter.committed_rate()); | ||
|
||
// Apply the new rate of 20M / 24 weeks | ||
uint256 nextWeeklyRate = (uint256(20_000_000 * 1e18) / 24); | ||
minter.commit_next_emission(nextWeeklyRate); | ||
|
||
// Assert that the commited rate is updated but the rate is not updated yet | ||
uint256 commitedRate = minter.committed_rate(); | ||
assertEq(commitedRate, nextWeeklyRate / 1 weeks); | ||
assertEq(minter.rate(), currentRate); | ||
|
||
// Skip to next mining epoch which is in every 2 weeks | ||
// Since voting epoch is every 1 week, there may be a week with old rate until | ||
// the next mining epoch starts that applies the new rate | ||
vm.warp(((block.timestamp + 2 weeks) / 1 weeks) * 1 weeks); | ||
|
||
// Update mining parameters manually to ensure that the rate is updated | ||
minter.update_mining_parameters(); | ||
|
||
// Ensure that the rate is updated with the commited rate | ||
uint256 newRate = minter.rate(); | ||
assertEq(newRate, commitedRate); | ||
|
||
// Mint for liqGaugeV5 type gauge and expect that the internal rate var is updated | ||
minter.mint(address(liqGaugeV5)); | ||
assertEq(newRate, liqGaugeV5.inflation_rate()); | ||
|
||
// Mint for rootGauge type gauge and expect that the internal rate var is updated | ||
minter.mint(address(rootGauge)); | ||
assertEq(newRate, rootGauge.inflation_params().rate); | ||
} | ||
} |