You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After an order is expired, we should use earningsFactorAtInterval[expiration] as the latestEarningsFactor to calculate the tokensOwed instead of using the earningsFactorCurrent.
Expected Behavior
Fix to use earningsFactorAtInterval[expiration] in _updateOrder() function to calculate the tokensOwed.
To Reproduce
test function:
function testTWAMM_updatedOrder_CalculateTokensOwedAfterExpiration() public {
ITWAMM.OrderKey memory orderKey1;
ITWAMM.OrderKey memory orderKey2;
uint256 orderAmount;
(orderKey1, orderKey2, orderAmount) =submitOrdersBothDirections();
// submit two more orders so the `earningsFactorCurrent` will continue growing after expiration of order1 & order2uint256 extraOrderAmount =2ether;
ITWAMM.OrderKey memory orderKey3 = ITWAMM.OrderKey(address(this), 60000, true);
ITWAMM.OrderKey memory orderKey4 = ITWAMM.OrderKey(address(this), 60000, false);
token0.approve(address(twamm), extraOrderAmount);
token1.approve(address(twamm), extraOrderAmount);
twamm.submitOrder(poolKey, orderKey3, extraOrderAmount);
twamm.submitOrder(poolKey, orderKey4, extraOrderAmount);
// set timestamp to after order1 & order2 expire
vm.warp(40000);
// update order1 & order2 after expiration, should use the earningsFactorAtInterval at expiration to settle
twamm.updateOrder(poolKey, orderKey1, 0);
twamm.updateOrder(poolKey, orderKey2, 0);
uint256 token0Owed = twamm.tokensOwed(poolKey.currency0, orderKey2.owner);
uint256 token1Owed = twamm.tokensOwed(poolKey.currency1, orderKey2.owner);
assertEq(token0Owed, orderAmount);
assertEq(token1Owed, orderAmount);
}
result:
❯ forge test -vv --match-test 'testTWAMM_updatedOrder_CalculateTokensOwedAfterExpiration'
[⠒] Compiling...
[⠒] Compiling 1 files with 0.8.19
[⠆] Solc 0.8.19 finished in 3.08s
Compiler run successful!
Running 1 testfor test/TWAMM.t.sol:TWAMMTest
[FAIL. Reason: Assertion failed.] testTWAMM_updatedOrder_CalculateTokensOwedAfterExpiration() (gas: 727152)
Logs:
Error: a == b not satisfied [uint]
Left: 1500000000000000000
Right: 1000000000000000000
Error: a == b not satisfied [uint]
Left: 1500000000000000000
Right: 1000000000000000000
Test result: FAILED. 0 passed; 1 failed; finished in 6.76ms
Failing tests:
Encountered 1 failing testin test/TWAMM.t.sol:TWAMMTest
[FAIL. Reason: Assertion failed.] testTWAMM_updatedOrder_CalculateTokensOwedAfterExpiration() (gas: 727152)
Encountered a total of 1 failing tests, 0 tests succeeded
Additional context
No response
The text was updated successfully, but these errors were encountered:
Describe the bug
After an order is expired, we should use
earningsFactorAtInterval[expiration]
as the latestEarningsFactor to calculate the tokensOwed instead of using theearningsFactorCurrent
.Expected Behavior
Fix to use
earningsFactorAtInterval[expiration]
in_updateOrder()
function to calculate the tokensOwed.To Reproduce
test function:
result:
Additional context
No response
The text was updated successfully, but these errors were encountered: