Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multiblock rt test #365

Merged
merged 7 commits into from
Jun 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions test/integrations/hyperdrive/RoundTripTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { FixedPointMath } from "contracts/src/libraries/FixedPointMath.sol";
import { HyperdriveMath } from "contracts/src/libraries/HyperdriveMath.sol";
import { YieldSpaceMath } from "contracts/src/libraries/YieldSpaceMath.sol";
import { HyperdriveTest, HyperdriveUtils, IHyperdrive } from "../../utils/HyperdriveTest.sol";
import { Lib } from "../../utils/Lib.sol";

contract RoundTripTest is HyperdriveTest {
using FixedPointMath for uint256;
using Lib for *;

function test_long_round_trip_immediately_at_checkpoint() external {
uint256 apr = 0.05e18;
Expand Down Expand Up @@ -162,4 +164,46 @@ contract RoundTripTest is HyperdriveTest {
// should be exact if out = in
assertEq(poolInfoAfter.bondReserves, poolInfoBefore.bondReserves);
}

function test_long_multiblock_round_trip_end_of_checkpoint(
uint256 apr,
uint256 timeStretchApr,
uint256 basePaid
) external {
apr = apr.normalizeToRange(0.001e18, .4e18);
timeStretchApr = timeStretchApr.normalizeToRange(0.05e18, 0.4e18);

// Deploy the pool and initialize the market
uint256 curveFee = 0.05e18; // 5% of APR
uint256 flatFee = 0.0005e18; // 5 bps
deploy(alice, timeStretchApr, curveFee, flatFee, .015e18);
uint256 contribution = 500_000_000e18;
initialize(alice, apr, contribution);

basePaid = basePaid.normalizeToRange(
jrhea marked this conversation as resolved.
Show resolved Hide resolved
1e14,
HyperdriveUtils.calculateMaxLong(hyperdrive)
);

// Get the poolInfo before opening the long.
IHyperdrive.PoolInfo memory poolInfoBefore = hyperdrive.getPoolInfo();

// fast forward time to almost the end of the checkpoint
advanceTime(CHECKPOINT_DURATION - 1, 0);

// Open a long position.
(uint256 maturityTime, uint256 bondAmount) = openLong(bob, basePaid);

// fast forward time to the end of the checkpoint
advanceTime(1, 0);

// Immediately close the long.
closeLong(bob, maturityTime, bondAmount);

// Get the poolInfo after closing the long.
IHyperdrive.PoolInfo memory poolInfoAfter = hyperdrive.getPoolInfo();

// if they aren't the same, then the pool should be the one that wins
assertGe(poolInfoAfter.shareReserves, poolInfoBefore.shareReserves);
}
}