Skip to content

Commit 3629ea7

Browse files
committed
add deadline
1 parent 509d218 commit 3629ea7

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

script/04_Swap.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ contract SwapScript is FFIHelper {
3131

3232
uint256 amount = 100;
3333
bool zeroForOne = true;
34-
order = AsyncOrder(key, OWNER, zeroForOne, amount, 2 ** 96);
34+
order = AsyncOrder(key, OWNER, zeroForOne, amount, 2 ** 96, block.timestamp + 1 hours);
3535

3636
if (zeroForOne) {
3737
IERC20Minimal(Currency.unwrap(order.key.currency0)).approve(address(router), uint256(amount));

script/FFIHelper.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ contract FFIHelper is Script {
117117
OrderData memory orderData = abi.decode(data, (OrderData));
118118
bool zeroForOne = topics[1] == 0 ? false : true;
119119
uint256 amountIn = uint256(topics[2]);
120+
uint160 sqrtPrice = uint160(uint256(topics[3]));
121+
uint256 deadline = uint256(topics[4]);
120122
PoolKey memory key = _getPoolKey();
121123

122-
AsyncOrder memory order = AsyncOrder(key, orderData.owner, zeroForOne, amountIn, 2 ** 96);
124+
AsyncOrder memory order = AsyncOrder(key, orderData.owner, zeroForOne, amountIn, sqrtPrice, deadline);
123125
return order;
124126
}
125127

src/AsyncSwap.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { AsyncFiller } from "@async-swap/libraries/AsyncFiller.sol";
88
import { AsyncOrder } from "@async-swap/types/AsyncOrder.sol";
99
import { CurrencySettler } from "@uniswap/v4-core/test/utils/CurrencySettler.sol";
1010
import { IPoolManager } from "v4-core/interfaces/IPoolManager.sol";
11-
import { IERC20Minimal } from "v4-core/interfaces/external/IERC20Minimal.sol";
1211
import { Hooks } from "v4-core/libraries/Hooks.sol";
1312
import { LPFeeLibrary } from "v4-core/libraries/LPFeeLibrary.sol";
1413
import { SafeCast } from "v4-core/libraries/SafeCast.sol";
@@ -51,6 +50,7 @@ contract AsyncSwap is BaseHook, IAsyncSwapAMM {
5150

5251
/// @notice Error thrown when liquidity is not supported in this hook.
5352
error UnsupportedLiquidity();
53+
error OrderExpired();
5454

5555
/// Initializes the Async Swap Hook contract with the PoolManager address and sets an transaction ordering algorithm.
5656
/// @param poolManager The address of the PoolManager contract.
@@ -122,7 +122,7 @@ contract AsyncSwap is BaseHook, IAsyncSwapAMM {
122122
/// Sort poolIDs
123123
/// Order swaps by poolId
124124

125-
uint256 volatility = ALGORITHM.getVolatility(orders);
125+
// uint256 volatility = ALGORITHM.getVolatility(orders);
126126
for (uint8 i = 0; i < orders.length; i++) {
127127
AsyncOrder calldata order = orders[i];
128128
// Use transaction ordering algorithm to ensure correct execution order
@@ -140,15 +140,16 @@ contract AsyncSwap is BaseHook, IAsyncSwapAMM {
140140
Currency currency1 = order.key.currency1;
141141
PoolId poolId = order.key.toId();
142142
address filler = abi.decode(fillerData, (address));
143-
143+
uint256 deadline = order.deadline;
144+
if (block.timestamp > deadline) revert OrderExpired();
145+
AsyncFiller.State storage state = asyncOrders[poolId];
146+
require(order.isExecutor(state, msg.sender), "Caller is valid not executor");
144147
if (amountIn == 0) revert ZeroFillOrder();
145148

146149
/// TODO: Document what this does
147150
uint256 amountToFill = uint256(amountIn);
148151
uint256 claimableAmount = asyncOrders[poolId].asyncOrderAmount[owner][zeroForOne];
149152
require(amountToFill <= claimableAmount, "Max fill order limit exceed");
150-
AsyncFiller.State storage state = asyncOrders[poolId];
151-
require(order.isExecutor(state, msg.sender), "Caller is valid not excutor");
152153

153154
/// @dev Transfer currency of async order to user
154155
Currency currencyTake;
@@ -164,7 +165,7 @@ contract AsyncSwap is BaseHook, IAsyncSwapAMM {
164165
asyncOrders[poolId].asyncOrderAmount[owner][zeroForOne] -= amountToFill;
165166
/// we could also burn
166167
poolManager.transfer(filler, currencyTake.toId(), amountToFill);
167-
emit AsyncOrderFilled(poolId, owner, zeroForOne, amountToFill);
168+
emit AsyncOrderFilled(poolId, owner, zeroForOne, amountToFill, deadline);
168169

169170
/// @dev Take currencyFill from filler
170171
/// @dev Hook may charge filler a hook fee

src/interfaces/IAsyncSwapOrder.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ interface IAsyncSwapOrder {
1414
/// @param zeroForOne Whether the order is for a swap from currency0 to currency1 (true) or currency1 to currency0
1515
/// (false).
1616
/// @param amount The amount of the order.
17-
event AsyncOrderFilled(PoolId poolId, address owner, bool zeroForOne, uint256 amount);
17+
/// @param deadline The deadline of the order.
18+
event AsyncOrderFilled(PoolId poolId, address owner, bool zeroForOne, uint256 amount, uint256 deadline);
1819

1920
/// @notice Emitted when an async swap order is created.
2021
/// @param poolId The poolId of the pool where the order is placed.

0 commit comments

Comments
 (0)