Skip to content

Commit

Permalink
✅ update zap tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontecoding committed Dec 12, 2024
1 parent 854c1cb commit 3c87cec
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 99 deletions.
2 changes: 1 addition & 1 deletion script/utils/parameters/BaseParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract BaseParameters {

address public constant USDT = address(0);

address public constant TBTC = address(0);
address public constant CBBTC = 0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf;

address public constant USDE = address(0);
}
171 changes: 79 additions & 92 deletions test/Collateral.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,35 +105,32 @@ contract DepositCollateral is CollateralTest {
vm.stopPrank();
}

/// @custom:todo fix OracleDataRequired error
// function test_depositCollateral_zap() public {
// uint256 decimalsFactor = 10 ** (18 - USDT.decimals());
function test_depositCollateral_zap() public {
uint256 decimalsFactor = 10 ** (18 - USDC.decimals());

// deal(address(USDT), ACTOR, SMALLEST_AMOUNT);
deal(address(USDC), ACTOR, SMALLEST_AMOUNT);

// vm.startPrank(ACTOR);
vm.startPrank(ACTOR);

// USDT.approve(address(engine), type(uint256).max);
USDC.approve(address(engine), type(uint256).max);

// uint256 availableMarginBefore =
// uint256(perpsMarketProxy.getAvailableMargin(accountId));
// assertEq(availableMarginBefore, 0);
uint256 availableMarginBefore =
uint256(perpsMarketProxy.getAvailableMargin(accountId));
assertEq(availableMarginBefore, 0);

// engine.modifyCollateralZap({
// _accountId: accountId,
// _amount: int256(SMALLEST_AMOUNT),
// _swapTolerance: SMALLEST_AMOUNT - 3,
// _zapTolerance: SMALLEST_AMOUNT - 3,
// _collateral: USDT
// });
engine.modifyCollateralZap({
_accountId: accountId,
_amount: int256(SMALLEST_AMOUNT),
_zapMinAmountOut: SMALLEST_AMOUNT - 3
});

// vm.stopPrank();
vm.stopPrank();

// uint256 availableMargin =
// uint256(perpsMarketProxy.getAvailableMargin(accountId));
// uint256 expectedMargin = SMALLEST_AMOUNT * decimalsFactor;
// assertWithinTolerance(expectedMargin, availableMargin, 3);
// }
uint256 availableMargin =
uint256(perpsMarketProxy.getAvailableMargin(accountId));
uint256 expectedMargin = SMALLEST_AMOUNT * decimalsFactor;
assertWithinTolerance(expectedMargin, availableMargin, 3);
}

function test_depositCollateral_wrap() public {
deal(address(WETH), ACTOR, SMALLER_AMOUNT);
Expand Down Expand Up @@ -162,13 +159,12 @@ contract DepositCollateral is CollateralTest {
assertWithinTolerance(expectedMargin, availableMargin, 2);
}

/// @custom:todo fix OracleDataRequired error
// function test_depositCollateral_wrapTBTC() public {
// deal(address(tBTC), ACTOR, 1);
// function test_depositCollateral_wrapCBBTC() public {
// deal(address(cbBTC), ACTOR, 1);

// vm.startPrank(ACTOR);

// tBTC.approve(address(engine), type(uint256).max);
// cbBTC.approve(address(engine), type(uint256).max);

// uint256 availableMarginBefore =
// uint256(perpsMarketProxy.getAvailableMargin(accountId));
Expand All @@ -178,8 +174,8 @@ contract DepositCollateral is CollateralTest {
// _accountId: accountId,
// _amount: int256(1),
// _tolerance: 1,
// _collateral: tBTC,
// _synthMarketId: 3
// _collateral: cbBTC,
// _synthMarketId: CBBTC_SYNTH_MARKET_ID
// });

// vm.stopPrank();
Expand All @@ -189,26 +185,27 @@ contract DepositCollateral is CollateralTest {
// // assertWithinTolerance(expectedMargin, availableMargin, 2);
// }

/// @custom:todo fix OracleDataRequired error
// function test_depositCollateral_wrapUSDE() public {
// uint256 decimalsFactor = 10 ** (18 - USDe.decimals());
// function test_depositCollateral_wrapUSDC() public {
// uint256 decimalsFactor = 10 ** (18 - USDC.decimals());

// deal(address(USDe), ACTOR, SMALLER_AMOUNT);
// uint256 amount = 1 * decimalsFactor;

// deal(address(USDC), ACTOR, amount);

// vm.startPrank(ACTOR);

// USDe.approve(address(engine), type(uint256).max);
// USDC.approve(address(engine), type(uint256).max);

// uint256 availableMarginBefore =
// uint256(perpsMarketProxy.getAvailableMargin(accountId));
// assertEq(availableMarginBefore, 0);

// engine.modifyCollateralWrap({
// _accountId: accountId,
// _amount: int256(SMALLER_AMOUNT),
// _tolerance: SMALLER_AMOUNT,
// _collateral: USDe,
// _synthMarketId: 5
// _amount: int256(amount),
// _tolerance: amount,
// _collateral: USDC,
// _synthMarketId: USDC_SYNTH_MARKET_ID
// });

// vm.stopPrank();
Expand Down Expand Up @@ -415,77 +412,67 @@ contract WithdrawCollateral is CollateralTest {
vm.stopPrank();
}

/// @custom:todo fix OracleDataRequired error
// function test_withdrawCollateral_zap() public {
// uint256 decimalsFactor = 10 ** (18 - USDT.decimals());
function test_withdrawCollateral_zap() public {
uint256 decimalsFactor = 10 ** (18 - USDC.decimals());

// deal(address(USDT), ACTOR, SMALLER_AMOUNT);
deal(address(USDC), ACTOR, SMALLEST_AMOUNT);

// vm.startPrank(ACTOR);
vm.startPrank(ACTOR);

// USDT.approve(address(engine), type(uint256).max);
USDC.approve(address(engine), type(uint256).max);

// // add the collateral
// engine.modifyCollateralZap({
// _accountId: accountId,
// _amount: int256(SMALLER_AMOUNT),
// _swapTolerance: 1,
// _zapTolerance: 1,
// _collateral: USDT
// });
// add the collateral
engine.modifyCollateralZap({
_accountId: accountId,
_amount: int256(SMALLEST_AMOUNT),
_zapMinAmountOut: SMALLEST_AMOUNT - 3
});

// uint256 postBalanceUSDT = USDT.balanceOf(ACTOR);
// assertEq(postBalanceUSDT, 0);
uint256 postBalanceUSDT = USDC.balanceOf(ACTOR);
assertEq(postBalanceUSDT, 0);

// uint256 preBalanceUSDC = USDC.balanceOf(ACTOR);
// assertEq(preBalanceUSDC, 0);
uint256 preBalanceUSDC = USDC.balanceOf(ACTOR);
assertEq(preBalanceUSDC, 0);

// uint256 availableMargin =
// uint256(perpsMarketProxy.getAvailableMargin(accountId)); // 78_133551009252750000
uint256 availableMargin =
uint256(perpsMarketProxy.getAvailableMargin(accountId));

// // remove the collateral
// engine.modifyCollateralZap({
// _accountId: accountId,
// _amount: -int256(availableMargin),
// _swapTolerance: 1,
// _zapTolerance: 1,
// _collateral: USDT
// });
// remove the collateral
engine.modifyCollateralZap({
_accountId: accountId,
_amount: -int256(availableMargin),
_zapMinAmountOut: SMALLEST_AMOUNT - 3
});

// vm.stopPrank();
// uint256 postBalanceUSDC = USDC.balanceOf(ACTOR);
// uint256 expectedBalance = postBalanceUSDC * decimalsFactor;
// assertWithinTolerance(expectedBalance, availableMargin, 30);
// }
vm.stopPrank();
uint256 postBalanceUSDC = USDC.balanceOf(ACTOR);
uint256 expectedBalance = postBalanceUSDC * decimalsFactor;
assertWithinTolerance(expectedBalance, availableMargin, 3);
}

/// @custom:todo fix OracleDataRequired error
// function test_withdrawCollateral_zap_Unauthorized() public {
// deal(address(USDT), ACTOR, SMALLER_AMOUNT);
function test_withdrawCollateral_zap_Unauthorized() public {
deal(address(USDC), ACTOR, SMALLEST_AMOUNT);

// vm.startPrank(ACTOR);
vm.startPrank(ACTOR);

// USDT.approve(address(engine), type(uint256).max);
USDC.approve(address(engine), type(uint256).max);

// engine.modifyCollateralZap({
// _accountId: accountId,
// _amount: int256(SMALLER_AMOUNT),
// _swapTolerance: 1,
// _zapTolerance: 1,
// _collateral: USDT
// });
engine.modifyCollateralZap({
_accountId: accountId,
_amount: int256(SMALLEST_AMOUNT),
_zapMinAmountOut: 1
});

// vm.stopPrank();
vm.stopPrank();

// vm.expectRevert(abi.encodeWithSelector(IEngine.Unauthorized.selector));
vm.expectRevert(abi.encodeWithSelector(IEngine.Unauthorized.selector));

// engine.modifyCollateralZap({
// _accountId: accountId,
// _amount: -int256(1),
// _swapTolerance: 1,
// _zapTolerance: 1,
// _collateral: USDT
// });
// }
engine.modifyCollateralZap({
_accountId: accountId,
_amount: -int256(1),
_zapMinAmountOut: 1
});
}

function test_withdrawCollateral_wrap() public {
deal(address(WETH), ACTOR, SMALLER_AMOUNT);
Expand Down
8 changes: 4 additions & 4 deletions test/utils/Bootstrap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract Bootstrap is
IERC20 public USDC;
IERC20 public WETH;
IERC20 public USDT;
IERC20 public tBTC;
IERC20 public cbBTC;
IERC20 public USDe;
address public zap;
address public usdc;
Expand All @@ -86,7 +86,7 @@ contract Bootstrap is
address _usdcAddress,
address _wethAddress,
address _usdtAddress,
address _tBTCAddress,
address _cbBTCAddress,
address _usdeAddress
) = bootstrap.init();

Expand All @@ -98,7 +98,7 @@ contract Bootstrap is
USDC = IERC20(_usdcAddress);
WETH = IERC20(_wethAddress);
USDT = IERC20(_usdtAddress);
tBTC = IERC20(_tBTCAddress);
cbBTC = IERC20(_cbBTCAddress);
USDe = IERC20(_usdeAddress);
synthMinter = new SynthMinter(_sUSDAddress, _spotMarketProxyAddress);
pDAO = _pDAOAddress;
Expand Down Expand Up @@ -174,7 +174,7 @@ contract BootstrapBase is Setup, BaseParameters {
USDC,
WETH,
USDT,
TBTC,
CBBTC,
USDE
);
}
Expand Down
8 changes: 6 additions & 2 deletions test/utils/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ pragma solidity 0.8.27;
/// @title Contract for defining constants used in testing
/// @author JaredBorders ([email protected])
contract Constants {
/// @dev Dec-10-2024 09:34:19 PM +UTC
uint256 public constant BASE_BLOCK_NUMBER = 23_538_556;
// /// @dev Dec-10-2024 09:34:19 PM +UTC
// uint256 public constant BASE_BLOCK_NUMBER = 23_538_556;
//
uint256 public constant BASE_BLOCK_NUMBER = 23_579_166;

address internal constant OWNER = address(0x01);

Expand Down Expand Up @@ -56,6 +58,8 @@ contract Constants {

uint128 constant WETH_SYNTH_MARKET_ID = 6;

uint128 constant CBBTC_SYNTH_MARKET_ID = 4;

/// @dev this is the ETH price in USD at the block number 23_538_556
uint256 internal constant ETH_PRICE = 3630;

Expand Down

0 comments on commit 3c87cec

Please sign in to comment.