Skip to content

Commit

Permalink
Merge pull request #129 from GenerationSoftware/gen-1941-re-test-stet…
Browse files Browse the repository at this point in the history
…h-4626-on-mainnet

update stETH integration tests
  • Loading branch information
trmid authored Aug 29, 2024
2 parents 90bcdc9 + c9bec4d commit c27009e
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/integration/lido/YieldDaddyLidoEthereum.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { BaseIntegration, IERC20, IERC4626 } from "../BaseIntegration.t.sol";

contract YieldDaddyLidoEthereumIntegrationTest is BaseIntegration {
uint256 fork;
uint256 forkBlock = 19311723;
uint256 forkBlockTimestamp = 1708950275;
uint256 forkBlock = 20636046;
uint256 forkBlockTimestamp = 1724956295;

address internal _asset = address(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
address internal _assetWhale = address(0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0);
address internal _assetWhale = address(0x93c4b944D05dfe6df7645A86cd2206016c51564D);
address internal _yieldVault = address(0xF9A98A9452485ed55cd3Ce5260C2b71c9807b11a);


Expand All @@ -43,7 +43,7 @@ contract YieldDaddyLidoEthereumIntegrationTest is BaseIntegration {
function beforeSetup() public virtual override {
lowGasPriceEstimate = 3 gwei;
assetPrecisionLoss = 1; // loses 1 decimal of precision due to extra 1-wei rounding errors on transfer
roundingErrorOnTransfer = 1; // loses 1 wei on asset transfer
roundingErrorOnTransfer = 2; // loses 1-2 wei on asset transfer
}

function afterSetup() public virtual override { }
Expand Down
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);
}

}
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();
}

}

0 comments on commit c27009e

Please sign in to comment.