-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from GenerationSoftware/gen-1941-re-test-stet…
…h-4626-on-mainnet update stETH integration tests
- Loading branch information
Showing
3 changed files
with
107 additions
and
4 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
67 changes: 67 additions & 0 deletions
67
test/invariant/PrizeVault/stethWrapperYieldDaddy/StethPrizeVaultFuzzHarness.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,67 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import { PrizeVaultFuzzHarness, IERC4626, IERC20, PrizeVault, PrizePool } from "../PrizeVaultFuzzHarness.sol"; | ||
|
||
contract StethPrizeVaultFuzzHarness is PrizeVaultFuzzHarness { | ||
|
||
IERC20 public steth = IERC20(address(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84)); | ||
address public stethWhale = address(0x93c4b944D05dfe6df7645A86cd2206016c51564D); | ||
|
||
constructor (address _yieldVault, uint256 _yieldBuffer) PrizeVaultFuzzHarness(_yieldBuffer) { | ||
// override the yield vault, vault, and asset: | ||
yieldVault = IERC4626(_yieldVault); | ||
vault = new PrizeVault( | ||
vaultName, | ||
vaultSymbol, | ||
yieldVault, | ||
PrizePool(address(prizePool)), | ||
address(this), // changes as tests run | ||
address(this), // yield fee recipient (changes as tests run) | ||
0, // yield fee percent (changes as tests run) | ||
_yieldBuffer, // yield buffer | ||
owner // owner | ||
); | ||
} | ||
|
||
/* ============ Asset Helpers ============ */ | ||
|
||
function _dealAssets(address to, uint256 amount) internal override { | ||
(,address callerBefore,) = vm.readCallers(); | ||
vm.stopPrank(); | ||
|
||
vm.prank(stethWhale); | ||
steth.transfer(to, amount); | ||
|
||
(,address callerNow,) = vm.readCallers(); | ||
if (callerNow != callerBefore) { | ||
vm.startPrank(callerBefore); // restart prank | ||
} | ||
} | ||
|
||
function _maxDealAssets() internal view override returns(uint256) { | ||
return steth.balanceOf(stethWhale); | ||
} | ||
|
||
/* ============ Yield Helpers ============ */ | ||
|
||
function accrueYield(int88 yield) public override useCurrentTime { | ||
// yield accrues over time, so no need to mint it | ||
// we use `accrueTimeBasedYield` instead | ||
} | ||
|
||
function accrueTimeBasedYield(uint256 secondsPassed) public useCurrentTime { | ||
secondsPassed = _bound(secondsPassed, 1, 7 days); // max 7 days passed, min 1 second | ||
uint256 startBalance = yieldVault.totalAssets(); | ||
setCurrentTime(currentTime + secondsPassed); | ||
|
||
(bool success, bytes memory data) = address(steth).call(abi.encodeWithSignature("totalSupply()")); | ||
uint256 currentTotalSupply = abi.decode(data, (uint256)); | ||
require(success, "failed to get totalSupply"); | ||
vm.mockCall(address(steth), abi.encodeWithSignature("totalSupply()"), abi.encode((currentTotalSupply * (1e18 + 9.5e8 * secondsPassed)) / 1e18)); // ~3% APR | ||
|
||
uint256 endBalance = yieldVault.totalAssets(); | ||
vm.assume(endBalance > startBalance); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
test/invariant/PrizeVault/stethWrapperYieldDaddy/StethPrizeVaultInvariant.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,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import { console2 } from "forge-std/console2.sol"; | ||
import { PrizeVaultInvariant } from "../PrizeVaultInvariant.t.sol"; | ||
import { StethPrizeVaultFuzzHarness, PrizeVault } from "./StethPrizeVaultFuzzHarness.sol"; | ||
|
||
/// @dev This contract runs tests in a scenario where the yield vault can never lose funds (strictly increasing). | ||
contract StethPrizeVaultInvariant is PrizeVaultInvariant { | ||
|
||
uint256 mainnetFork; | ||
uint256 forkBlock = 20636046; | ||
uint256 forkBlockTimestamp = 1724956295; | ||
|
||
address wrappedSteth = address(0xF9A98A9452485ed55cd3Ce5260C2b71c9807b11a); | ||
|
||
StethPrizeVaultFuzzHarness public aaveVaultHarness; | ||
|
||
function setUp() external override { | ||
// optimism fork: | ||
mainnetFork = vm.createFork(vm.rpcUrl("mainnet"), forkBlock); | ||
vm.selectFork(mainnetFork); | ||
|
||
vm.warp(forkBlockTimestamp); | ||
aaveVaultHarness = new StethPrizeVaultFuzzHarness(wrappedSteth, 1e5); | ||
vaultHarness = StethPrizeVaultFuzzHarness(aaveVaultHarness); | ||
targetContract(address(aaveVaultHarness)); | ||
assertEq(vaultHarness.currentTime(), forkBlockTimestamp); | ||
|
||
// send some assets to cover initial yield buffer | ||
vm.startPrank(aaveVaultHarness.stethWhale()); | ||
aaveVaultHarness.steth().transfer(address(aaveVaultHarness.vault()), 1e5); | ||
vm.stopPrank(); | ||
} | ||
|
||
} |