Skip to content

Commit

Permalink
✅ Test executor fee changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredBorders committed Jul 13, 2023
1 parent d42a8ff commit e1bb9b5
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 99 deletions.
115 changes: 45 additions & 70 deletions test/integration/order.public.behavior.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ contract OrderPublicBehaviorTest is Test, ConsolidatedEvents {
IPermit2 private PERMIT2;

// conditional order variables
uint256 conditionalOrderId;
uint256 private conditionalOrderId;

/*//////////////////////////////////////////////////////////////
SETUP
Expand Down Expand Up @@ -145,50 +145,54 @@ contract OrderPublicBehaviorTest is Test, ConsolidatedEvents {
/*//////////////////////////////////////////////////////////////
TESTS
//////////////////////////////////////////////////////////////*/
function test_ExecuteConditionalOrder() public {

function test_ExecuteConditionalOrder_Public() public {
vm.deal(USER, 1 ether);
vm.prank(USER);
account.executeConditionalOrder(conditionalOrderId);
IAccount.ConditionalOrder memory conditionalOrder =
account.getConditionalOrder(conditionalOrderId);
assertEq(conditionalOrder.sizeDelta, 0);
}

function test_UpdatePythPrice() public {
/// @custom:todo will likely need to mock
}

function test_PayExecutorFee() public {
/// @custom:todo
}

function test_ExecuteConditionalOrderWithPriceUpdate() public {
/// @custom:todo
}

function test_ExecuteConditionalOrderWithPriceUpdate_Executor_Fee()
public
{
/// @custom:todo
function test_ExecuteConditionalOrder_Public_PayExecutorFee() public {
vm.deal(USER, 1 ether);
uint256 balanceBefore = USER.balance;
vm.prank(USER);
account.executeConditionalOrder(conditionalOrderId);
uint256 balanceAfter = USER.balance;
assertGt(balanceAfter, balanceBefore);
}

function test_ExecuteConditionalOrderWithPriceUpdate_Pyth_Updated()
function test_ExecuteConditionalOrder_Public_Cannot_PayExecutorFee()
public
{
/// @custom:todo
}

function test_ExecuteConditionalOrderWithPriceUpdate_Pyth_Fee() public {
/// @custom:todo
withdrawEth(address(account).balance);
vm.startPrank(USER);
vm.expectRevert(
abi.encodeWithSelector(
IAccount.CannotPayExecutorFee.selector,
settings.executorFee(),
USER
)
);
account.executeConditionalOrder(conditionalOrderId);
vm.stopPrank();
}

function test_ExecuteConditionalOrderWithPriceUpdate_Invalid_PriceFeed()
function test_ExecuteConditionalOrder_Public_Invalid_ConditionalOrder()
public
{
/// @custom:todo
}

function test_ExecuteConditionalOrder_Invalid_ConditionalOrder() public {
/// @custom:todo
// expect -> CannotExecuteConditionalOrder Custom Error
suspendPerpsV2Market(sETHPERP);
vm.prank(USER);
vm.expectRevert(
abi.encodeWithSelector(
IAccount.CannotExecuteConditionalOrder.selector,
conditionalOrderId,
USER
)
);
account.executeConditionalOrder(conditionalOrderId);
}

/*//////////////////////////////////////////////////////////////
Expand All @@ -209,43 +213,6 @@ contract OrderPublicBehaviorTest is Test, ConsolidatedEvents {
modifyAccountMargin({amount: int256(amount)});
}

function getMarketAddressFromKey(bytes32 key)
private
view
returns (address market)
{
market = address(
IPerpsV2MarketConsolidated(
IFuturesMarketManager(
IAddressResolver(ADDRESS_RESOLVER).getAddress(
"FuturesMarketManager"
)
).marketForKey(key)
)
);
}

function generateGelatoModuleData(uint256 conditionalOrderId)
internal
view
returns (bytes memory executionData, IOps.ModuleData memory moduleData)
{
executionData =
abi.encodeCall(account.executeConditionalOrder, conditionalOrderId);

moduleData = IOps.ModuleData({
modules: new IOps.Module[](1),
args: new bytes[](1)
});

moduleData.modules[0] = IOps.Module.RESOLVER;

moduleData.args[0] = abi.encode(
address(account),
abi.encodeCall(account.checker, conditionalOrderId)
);
}

function suspendPerpsV2Market(bytes32 market) internal {
// fetch owner address of SystemStatus contract
(bool success, bytes memory response) =
Expand Down Expand Up @@ -283,7 +250,7 @@ contract OrderPublicBehaviorTest is Test, ConsolidatedEvents {
IAccount.ConditionalOrderTypes conditionalOrderType,
uint256 desiredFillPrice,
bool reduceOnly
) private returns (uint256 conditionalOrderId) {
) private returns (uint256) {
IAccount.Command[] memory commands = new IAccount.Command[](1);
commands[0] = IAccount.Command.GELATO_PLACE_CONDITIONAL_ORDER;
bytes[] memory inputs = new bytes[](1);
Expand All @@ -297,6 +264,14 @@ contract OrderPublicBehaviorTest is Test, ConsolidatedEvents {
reduceOnly
);
account.execute(commands, inputs);
conditionalOrderId = account.conditionalOrderId() - 1;
return account.conditionalOrderId() - 1;
}

function withdrawEth(uint256 amount) private {
IAccount.Command[] memory commands = new IAccount.Command[](1);
commands[0] = IAccount.Command.ACCOUNT_WITHDRAW_ETH;
bytes[] memory inputs = new bytes[](1);
inputs[0] = abi.encode(amount);
account.execute(commands, inputs);
}
}
27 changes: 2 additions & 25 deletions test/unit/Account.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ contract AccountTest is Test, ConsolidatedEvents {
IAccount.Command[] memory commands = new IAccount.Command[](1);
commands[0] = IAccount.Command.ACCOUNT_MODIFY_MARGIN;
bytes[] memory inputs = new bytes[](1);
assertEq(1, accountExposed.expose_locked());
assertEq(0, accountExposed.expose_locked());
account.execute(commands, inputs);
assertEq(1, accountExposed.expose_locked());
assertEq(0, accountExposed.expose_locked());
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -981,29 +981,6 @@ contract AccountTest is Test, ConsolidatedEvents {
}
}

/*//////////////////////////////////////////////////////////////
SETTER UTILITIES
//////////////////////////////////////////////////////////////*/

function test_SetExecutorFee_OnlyOwner() public {
uint256 fee = 1;
vm.prank(DELEGATE);
vm.expectRevert(abi.encodeWithSelector(Auth.Unauthorized.selector));
account.setExecutorFee(fee);
}

function test_SetExecutorFee(uint256 fee) public {
account.setExecutorFee(fee);
assertEq(account.executorFee(), fee);
}

function test_SetExecutorFee_Event() public {
uint256 fee = 1 ether;
vm.expectEmit(true, true, true, true);
emit ExecutorFeeSet(address(account), fee);
account.setExecutorFee(fee);
}

/*//////////////////////////////////////////////////////////////
HELPERS
//////////////////////////////////////////////////////////////*/
Expand Down
23 changes: 23 additions & 0 deletions test/unit/Settings.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ contract SettingsTest is Test, ConsolidatedEvents {
settings.setAccountExecutionEnabled(false);
}

/*//////////////////////////////////////////////////////////////
EXECUTOR FEE
//////////////////////////////////////////////////////////////*/

function test_setExecutorFee() public {
assertEq(settings.executorFee(), 1 ether / 1000);
settings.setExecutorFee(1 ether / 100);
assertEq(settings.executorFee(), 1 ether / 100);
}

function test_setExecutorFee_OnlyOwner() public {
vm.expectRevert("UNAUTHORIZED");
vm.prank(USER);
settings.setExecutorFee(1 ether / 100);
}

function test_setExecutorFee_Event() public {
vm.expectEmit(true, true, true, true);
emit ExecutorFeeSet(1 ether / 100);
settings.setExecutorFee(1 ether / 100);
}


/*//////////////////////////////////////////////////////////////
WHITELISTING TOKENS
//////////////////////////////////////////////////////////////*/
Expand Down
4 changes: 0 additions & 4 deletions test/utils/AccountExposed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ contract AccountExposed is Account {
return _getTokenInTokenOut(_path);
}

function expose_updatePythPrice(bytes[] calldata priceUpdateData) public {
_updatePythPrice(priceUpdateData);
}

function expose_payExecutorFee() public returns (uint256) {
return _payExecutorFee();
}
Expand Down
2 changes: 2 additions & 0 deletions test/utils/ConsolidatedEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,7 @@ contract ConsolidatedEvents {

event AccountExecutionEnabledSet(bool enabled);

event ExecutorFeeSet(uint256 executorFee);

event TokenWhitelistStatusUpdated(address token);
}

0 comments on commit e1bb9b5

Please sign in to comment.