Skip to content

Commit

Permalink
Fixed the sxDAI test's advanceTime function
Browse files Browse the repository at this point in the history
  • Loading branch information
jalextowle committed Aug 27, 2024
1 parent 4c2fe54 commit 38d54c9
Showing 1 changed file with 12 additions and 44 deletions.
56 changes: 12 additions & 44 deletions test/instances/erc4626/sxDai.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import { InstanceTest } from "../../utils/InstanceTest.sol";
import { HyperdriveUtils } from "../../utils/HyperdriveUtils.sol";
import { Lib } from "../../utils/Lib.sol";

import "forge-std/console2.sol";

contract sxDaiHyperdriveTest is InstanceTest {
using FixedPointMath for uint256;
using HyperdriveUtils for uint256;
using HyperdriveUtils for IHyperdrive;
using Lib for *;
using stdStorage for StdStorage;
Expand Down Expand Up @@ -98,22 +97,14 @@ contract sxDaiHyperdriveTest is InstanceTest {
function convertToShares(
uint256 baseAmount
) internal view override returns (uint256) {
return
ERC4626Conversions.convertToShares(
SXDAI,
baseAmount
);
return ERC4626Conversions.convertToShares(SXDAI, baseAmount);
}

/// @dev Converts share amount to the equivalent amount in base.
function convertToBase(
uint256 shareAmount
) internal view override returns (uint256) {
return
ERC4626Conversions.convertToBase(
SXDAI,
shareAmount
);
return ERC4626Conversions.convertToBase(SXDAI, shareAmount);
}

/// @dev Deploys the ERC4626 deployer coordinator contract.
Expand Down Expand Up @@ -415,7 +406,6 @@ contract sxDaiHyperdriveTest is InstanceTest {
assertApproxEqAbs(baseProceeds, _contribution, 1e10);

// Ensure that the withdrawal was processed as expected.
console2.log("baseProceeds", baseProceeds);
verifyWithdrawal(
bob,
baseProceeds,
Expand Down Expand Up @@ -702,11 +692,6 @@ contract sxDaiHyperdriveTest is InstanceTest {

// The term passes and some interest accrues.
_variableRate = _variableRate.normalizeToRange(0, 2.5e18);
console2.log("variableRate", _variableRate.toString(18));
console2.log("initialVaultSharePrice", hyperdrive.getPoolConfig().initialVaultSharePrice.toString(18));
console2.log("vaultSharePrice", hyperdrive.getPoolInfo().vaultSharePrice.toString(18));
console2.log("totalAssets", SXDAI.totalAssets().toString(18));
console2.log("totalSupply", SXDAI.totalSupply().toString(18));
advanceTime(POSITION_DURATION, int256(_variableRate));

// Get some balance information before the withdrawal.
Expand All @@ -726,9 +711,6 @@ contract sxDaiHyperdriveTest is InstanceTest {
_shortAmount,
false
);
console2.log("_shortAmount", _shortAmount.toString(18));
console2.log("shareProceeds", shareProceeds.toString(18));
console2.log("_variableRate", _variableRate.toString(18));
uint256 baseProceeds = convertToBase(shareProceeds);

// Bob should receive almost exactly the interest that accrued on the
Expand All @@ -752,36 +734,22 @@ contract sxDaiHyperdriveTest is InstanceTest {
}

/// Helpers ///

function advanceTime(
uint256 timeDelta,
int256 variableRate
) internal override {
// Advance the time.
vm.warp(block.timestamp + timeDelta);
(, int256 interest) = HyperdriveUtils.calculateCompoundInterest(
SXDAI.totalAssets(),

// Accrue interest in the sxDAI market. This amounts to manually
// updating the total supply assets.
uint256 totalAssets = SXDAI.totalAssets();
(totalAssets, ) = totalAssets.calculateInterest(
variableRate,
timeDelta
);
console2.log("before XDAI.totalSupply()",SXDAI.totalSupply().toString(18));

if (interest > 0) {
ERC20Mintable(address(XDAI)).mint(
address(SXDAI),
uint256(interest)
);
} else if (interest < 0) {
ERC20Mintable(address(XDAI)).burn(
address(SXDAI),
uint256(-interest)
);
}
console2.log("after XDAI.totalSupply()",SXDAI.totalSupply().toString(18));

console2.log("interest ",interest.toString(18));
//uint256 totalBase = SXDAI.totalAssets() + uint256(interest);
console2.log("SXDAI.totalAssets()",SXDAI.totalAssets().toString(18));
//console2.log("totalBase ", totalBase.toString(18));
// bytes32 balanceLocation = keccak256(abi.encode(address(SXDAI), 12));
// vm.store(address(SXDAI), bytes32(balanceLocation), bytes32(totalBase));
bytes32 balanceLocation = keccak256(abi.encode(address(SXDAI), 3));
vm.store(address(XDAI), balanceLocation, bytes32(totalAssets));
}
}

0 comments on commit 38d54c9

Please sign in to comment.