diff --git a/test/instances/morpho-blue/MorphoBlue_USDe_DAI_Hyperdrive.t.sol b/test/instances/morpho-blue/MorphoBlue_USDe_DAI_Hyperdrive.t.sol index 215a563fb..68237fd80 100644 --- a/test/instances/morpho-blue/MorphoBlue_USDe_DAI_Hyperdrive.t.sol +++ b/test/instances/morpho-blue/MorphoBlue_USDe_DAI_Hyperdrive.t.sol @@ -685,6 +685,7 @@ contract MorphoBlue_USDe_DAI_HyperdriveTest is InstanceTest { // Bob should receive approximately as much base as he paid since no // time as passed and the fees are zero. + assertLt(baseProceeds, basePaid + 1000); assertApproxEqAbs(baseProceeds, basePaid, 1e9); // Ensure that the withdrawal was processed as expected. diff --git a/test/instances/morpho-blue/MorphoBlue_wstETH_USDC_Hyperdrive.t.sol b/test/instances/morpho-blue/MorphoBlue_wstETH_USDC_Hyperdrive.t.sol index f45d144cd..8b8ac9688 100644 --- a/test/instances/morpho-blue/MorphoBlue_wstETH_USDC_Hyperdrive.t.sol +++ b/test/instances/morpho-blue/MorphoBlue_wstETH_USDC_Hyperdrive.t.sol @@ -28,7 +28,7 @@ import { InstanceTest } from "../../utils/InstanceTest.sol"; import { HyperdriveUtils } from "../../utils/HyperdriveUtils.sol"; import { Lib } from "../../utils/Lib.sol"; -contract WSTETH_USDC_MorphoBlueHyperdriveTest is InstanceTest { +contract MorphoBlue_wstETH_USDC_HyperdriveTest is InstanceTest { using FixedPointMath for uint256; using HyperdriveUtils for IHyperdrive; using MarketParamsLib for MarketParams; @@ -86,7 +86,7 @@ contract WSTETH_USDC_MorphoBlueHyperdriveTest is InstanceTest { // converting between base and vault shares. We included more // assertions than normal to the round trip tests to verify that // the calculations satisfy our expectations of accuracy. - shareTolerance: 1e8, + shareTolerance: 1e3, minimumShareReserves: 1e6, minimumTransactionAmount: 1e6, positionDuration: POSITION_DURATION, @@ -316,7 +316,7 @@ contract WSTETH_USDC_MorphoBlueHyperdriveTest is InstanceTest { assertApproxEqAbs( totalSupplyShares, totalSharesBefore - hyperdrive.convertToShares(baseProceeds), - 1e6 + 10 ); // Ensure that the ETH balances didn't change. @@ -512,7 +512,7 @@ contract WSTETH_USDC_MorphoBlueHyperdriveTest is InstanceTest { assertApproxEqAbs( baseProceeds, withdrawalShares.mulDown(lpSharePrice), - 1e3 + 100 ); } @@ -751,7 +751,7 @@ contract WSTETH_USDC_MorphoBlueHyperdriveTest is InstanceTest { assertApproxEqAbs( baseProceeds, _shortAmount.mulDown(_variableRate), - 1e10 + 10 ); // Ensure that the withdrawal was processed as expected. diff --git a/test/utils/InstanceTest.sol b/test/utils/InstanceTest.sol index 54b4424da..0cf74c91f 100644 --- a/test/utils/InstanceTest.sol +++ b/test/utils/InstanceTest.sol @@ -149,26 +149,42 @@ abstract contract InstanceTest is HyperdriveTest { deployerCoordinator = deployCoordinator(address(factory)); factory.addDeployerCoordinator(deployerCoordinator); - // Deploy all Hyperdrive contracts using deployer coordinator contract. + // If share deposits are enabled and the vault shares token isn't a + // rebasing token, the contribution is the minimum of a tenth of Alice's + // vault shares balance and 1000 vault shares in units of vault shares. uint256 contribution; if (config.enableShareDeposits && !config.isRebasing) { contribution = (poolConfig.vaultSharesToken.balanceOf(alice) / 10) .min(1_000 * 10 ** config.decimals); - } else if (config.enableShareDeposits) { + } + // If share deposits are enabled and the vault shares token is a + // rebasing token, the contribution is the minimum of a tenth of Alice's + // vault shares balance and 1000 vault shares in units of base. + else if (config.enableShareDeposits) { contribution = convertToShares( (poolConfig.vaultSharesToken.balanceOf(alice) / 10).min( 1_000 * 10 ** config.decimals ) ); - } else if (!isBaseETH) { + } + // If share deposits are disabled and the base token isn't ETH, the + // contribution is the minimum of a tenth of Alice's base balance and + // 1000 base. + else if (!isBaseETH) { contribution = (poolConfig.baseToken.balanceOf(alice) / 10).min( 1_000 * 10 ** config.decimals ); - } else { + } + // If share deposits are disabled and the base token is ETH, the + // contribution is the minimum of a tenth of Alice's ETH balance and + // 1000 base. + else { contribution = (alice.balance / 10).min( 1_000 * 10 ** config.decimals ); } + + // Deploy all Hyperdrive contracts using deployer coordinator contract. deployHyperdrive( DEFAULT_DEPLOYMENT_ID, // Deployment Id DEFAULT_DEPLOYMENT_SALT, // Deployment Salt @@ -265,12 +281,21 @@ abstract contract InstanceTest is HyperdriveTest { ); } - // Alice gives approval to the deployer coordinator to fund the market. + // If base is being used and the base token isn't ETH, we set an + // approval on the deployer coordinator with the contribution in base. if (asBase && !isBaseETH) { config.baseToken.approve(deployerCoordinator, contribution); - } else if (!asBase && !config.isRebasing) { + } + // If vault shares is being used and the vault shares token isn't a + // rebasing token, we set an approval on the deployer coordinator + // with the contribution in vault shares. + else if (!asBase && !config.isRebasing) { config.vaultSharesToken.approve(deployerCoordinator, contribution); - } else if (!asBase) { + } + // If vault shares is being used and the vault shares token is a + // rebasing token, we set an approval on the deployer coordinator + // with the contribution in base. + else if (!asBase) { config.vaultSharesToken.approve( deployerCoordinator, convertToBase(contribution) @@ -521,13 +546,17 @@ abstract contract InstanceTest is HyperdriveTest { return; } - // Contribution in terms of base. + // If the base asset isn't ETH, the contribution is the minimum of a + // tenth of Alice's balance and 1000 base tokens. uint256 contribution; if (!isBaseETH) { contribution = (poolConfig.baseToken.balanceOf(alice) / 10).min( 1_000 * 10 ** config.decimals ); - } else { + } + // Otherwise, if the base asset is eth, the contribution is the minimum + // of a tenth of Alice's balance and 1000 base tokens. + else { contribution = (alice.balance / 10).min( 1_000 * 10 ** config.decimals );