Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jalextowle committed Aug 17, 2024
1 parent 457518d commit 4d8ac7f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -512,7 +512,7 @@ contract WSTETH_USDC_MorphoBlueHyperdriveTest is InstanceTest {
assertApproxEqAbs(
baseProceeds,
withdrawalShares.mulDown(lpSharePrice),
1e3
100
);
}

Expand Down Expand Up @@ -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.
Expand Down
47 changes: 38 additions & 9 deletions test/utils/InstanceTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
);
Expand Down

0 comments on commit 4d8ac7f

Please sign in to comment.