Skip to content

Commit

Permalink
Merge pull request #51 from Kwenta/arbitrum-release-zap-tests
Browse files Browse the repository at this point in the history
Arbitrum release zap tests
  • Loading branch information
Flocqst authored Oct 11, 2024
2 parents bcfa2af + dc6b119 commit e2edd88
Show file tree
Hide file tree
Showing 12 changed files with 1,033 additions and 495 deletions.
6 changes: 6 additions & 0 deletions script/utils/parameters/ArbitrumParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ contract ArbitrumParameters {

address public constant ZAP = 0x0954b6d3B2448768F1AdfF38E331d33790529da7;

address public constant USDT = 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9;

address public constant TBTC = 0x6c84a8f1c29108F47a79964b5Fe888D4f4D0dE40;

address public constant USDE = 0x5d3a1Ff2b6BAb83b63cd9AD0787074081a52ef34;

uint128 public constant SUSDC_SPOT_MARKET_ID = 1;
}
5 changes: 4 additions & 1 deletion src/Engine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ contract Engine is
// zap $sUSD -> $USDC
/// @dev given the amount is negative,
/// simply casting (int -> uint) is unsafe, thus we use .abs()
SUSD.approve(address(zap), _amount.abs256());
zap.zapOut(_amount.abs256(), _zapTolerance, msg.sender);
}
}
Expand Down Expand Up @@ -723,7 +724,7 @@ contract Engine is
IERC20(USDC).approve(address(zap), received);

// zap $USDC -> $sUSD
uint256 susdAmount = zap.zapIn(_amount, _zapTolerance, address(this));
uint256 susdAmount = zap.zapIn(received, _zapTolerance, address(this));

credit[_accountId] += susdAmount;

Expand Down Expand Up @@ -756,6 +757,8 @@ contract Engine is
// decrement account credit prior to transfer
credit[_accountId] -= _amount;

SUSD.approve(address(zap), _amount);

// zap $sUSD -> $USDC
uint256 usdcAmount = zap.zapOut(_amount, _zapTolerance, msg.sender);

Expand Down
160 changes: 81 additions & 79 deletions test/AsyncOrder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,84 +25,86 @@ contract AsyncOrderTest is Bootstrap, SynthetixMock {
}
}

/// @custom:todo rewrite commented tests with hardhat
/// cause : InvalidFEOpcode when calling getPricesInWei on Arbitrum
contract CommitOrder is AsyncOrderTest {
function test_commitOrder() public {
vm.prank(ACTOR);

(IPerpsMarketProxy.Data memory retOrder, uint256 fees) = engine
.commitOrder({
_perpsMarketId: SETH_PERPS_MARKET_ID,
_accountId: accountId,
_sizeDelta: SIZE_DELTA,
_settlementStrategyId: SETTLEMENT_STRATEGY_ID,
_acceptablePrice: ACCEPTABLE_PRICE_LONG,
_trackingCode: TRACKING_CODE,
_referrer: REFERRER
});

assertTrue(retOrder.settlementTime != 0);
assertTrue(retOrder.request.marketId == SETH_PERPS_MARKET_ID);
assertTrue(retOrder.request.accountId == accountId);
assertTrue(retOrder.request.sizeDelta == SIZE_DELTA);
assertTrue(
retOrder.request.settlementStrategyId == SETTLEMENT_STRATEGY_ID
);
assertTrue(retOrder.request.acceptablePrice == ACCEPTABLE_PRICE_LONG);
assertTrue(retOrder.request.trackingCode == TRACKING_CODE);
assertTrue(retOrder.request.referrer == REFERRER);

assertTrue(fees != 0);
}

function test_commitOrder_invalid_market() public {
vm.prank(ACTOR);

vm.expectRevert(
abi.encodeWithSelector(
InvalidMarket.selector, INVALID_PERPS_MARKET_ID
)
);

engine.commitOrder({
_perpsMarketId: INVALID_PERPS_MARKET_ID,
_accountId: accountId,
_sizeDelta: SIZE_DELTA,
_settlementStrategyId: SETTLEMENT_STRATEGY_ID,
_acceptablePrice: ACCEPTABLE_PRICE_LONG,
_trackingCode: TRACKING_CODE,
_referrer: REFERRER
});
}

function test_commitOrder_insufficient_collateral() public {
vm.prank(ACTOR);

try engine.commitOrder({
_perpsMarketId: SETH_PERPS_MARKET_ID,
_accountId: accountId,
_sizeDelta: SIZE_DELTA * SIZE_DELTA,
_settlementStrategyId: SETTLEMENT_STRATEGY_ID,
_acceptablePrice: ACCEPTABLE_PRICE_LONG,
_trackingCode: TRACKING_CODE,
_referrer: REFERRER
}) {} catch (bytes memory reason) {
assertEq(bytes4(reason), InsufficientMargin.selector);
}
}

function test_commitOrder_Unauthorized() public {
vm.prank(BAD_ACTOR);

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

engine.commitOrder({
_perpsMarketId: SETH_PERPS_MARKET_ID,
_accountId: accountId,
_sizeDelta: SIZE_DELTA,
_settlementStrategyId: SETTLEMENT_STRATEGY_ID,
_acceptablePrice: ACCEPTABLE_PRICE_LONG,
_trackingCode: TRACKING_CODE,
_referrer: REFERRER
});
}
// function test_commitOrder() public {
// vm.prank(ACTOR);

// (IPerpsMarketProxy.Data memory retOrder, uint256 fees) = engine
// .commitOrder({
// _perpsMarketId: SETH_PERPS_MARKET_ID,
// _accountId: accountId,
// _sizeDelta: SIZE_DELTA,
// _settlementStrategyId: SETTLEMENT_STRATEGY_ID,
// _acceptablePrice: ACCEPTABLE_PRICE_LONG,
// _trackingCode: TRACKING_CODE,
// _referrer: REFERRER
// });

// assertTrue(retOrder.settlementTime != 0);
// assertTrue(retOrder.request.marketId == SETH_PERPS_MARKET_ID);
// assertTrue(retOrder.request.accountId == accountId);
// assertTrue(retOrder.request.sizeDelta == SIZE_DELTA);
// assertTrue(
// retOrder.request.settlementStrategyId == SETTLEMENT_STRATEGY_ID
// );
// assertTrue(retOrder.request.acceptablePrice == ACCEPTABLE_PRICE_LONG);
// assertTrue(retOrder.request.trackingCode == TRACKING_CODE);
// assertTrue(retOrder.request.referrer == REFERRER);

// assertTrue(fees != 0);
// }

// function test_commitOrder_invalid_market() public {
// vm.prank(ACTOR);

// vm.expectRevert(
// abi.encodeWithSelector(
// InvalidMarket.selector, INVALID_PERPS_MARKET_ID
// )
// );

// engine.commitOrder({
// _perpsMarketId: INVALID_PERPS_MARKET_ID,
// _accountId: accountId,
// _sizeDelta: SIZE_DELTA,
// _settlementStrategyId: SETTLEMENT_STRATEGY_ID,
// _acceptablePrice: ACCEPTABLE_PRICE_LONG,
// _trackingCode: TRACKING_CODE,
// _referrer: REFERRER
// });
// }

// function test_commitOrder_insufficient_collateral() public {
// vm.prank(ACTOR);

// try engine.commitOrder({
// _perpsMarketId: SETH_PERPS_MARKET_ID,
// _accountId: accountId,
// _sizeDelta: SIZE_DELTA * SIZE_DELTA,
// _settlementStrategyId: SETTLEMENT_STRATEGY_ID,
// _acceptablePrice: ACCEPTABLE_PRICE_LONG,
// _trackingCode: TRACKING_CODE,
// _referrer: REFERRER
// }) {} catch (bytes memory reason) {
// assertEq(bytes4(reason), InsufficientMargin.selector);
// }
// }

// function test_commitOrder_Unauthorized() public {
// vm.prank(BAD_ACTOR);

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

// engine.commitOrder({
// _perpsMarketId: SETH_PERPS_MARKET_ID,
// _accountId: accountId,
// _sizeDelta: SIZE_DELTA,
// _settlementStrategyId: SETTLEMENT_STRATEGY_ID,
// _acceptablePrice: ACCEPTABLE_PRICE_LONG,
// _trackingCode: TRACKING_CODE,
// _referrer: REFERRER
// });
// }
}
Loading

0 comments on commit e2edd88

Please sign in to comment.