@@ -26,13 +26,12 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
2626 using SafeCast for * ;
2727 using CurrencySettler for Currency;
2828 using PoolIdLibrary for PoolKey;
29+ using AsyncFiller for AsyncOrder;
2930
30- /// @notice Algorithm used for ordering transactions in our Async Swap AMM.
31- IAlgorithm public algorithm;
3231 /// @notice Mapping to store async orders.
3332 mapping (PoolId poolId => AsyncFiller.State) public asyncOrders;
34- /// @notice Mapping to store executor permissions for users.
35- mapping ( address owner = > mapping ( address executor = > bool )) public setExecutor ;
33+ /// Ordering algortim
34+ IAlgorithm public immutable algorithm ;
3635
3736 /// Event emitted when a swap is executed.
3837 /// @param id The poolId of the pool where the swap occurred.
@@ -63,6 +62,9 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
6362 /// @inheritdoc BaseHook
6463 function _beforeInitialize (address , PoolKey calldata key , uint160 ) internal virtual override returns (bytes4 ) {
6564 require (key.fee == LPFeeLibrary.DYNAMIC_FEE_FLAG, "Dude use dynamic fees flag " );
65+ /// set algorithm for the pool being initialized
66+ asyncOrders[key.toId ()].algorithm = algorithm;
67+ asyncOrders[key.toId ()].poolManager = poolManager;
6668 return this .beforeInitialize.selector ;
6769 }
6870
@@ -96,13 +98,14 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
9698 revert UnsupportedLiquidity ();
9799 }
98100
99- /// @inheritdoc IAsyncSwapOrder
100- function isExecutor ( address owner , address executor ) public view returns ( bool ) {
101- return setExecutor[owner][executor ];
101+ function asyncOrder (PoolId poolId , address user , bool zeroForOne ) external view returns ( uint256 claimable ) {
102+ AsyncFiller.State storage state = asyncOrders[poolId];
103+ return state.asyncOrders[user][zeroForOne ];
102104 }
103105
104- function asyncOrder (PoolId poolId , address user , bool zeroForOne ) external view returns (uint256 claimable ) {
105- return asyncOrders[poolId].asyncOrders[user][zeroForOne];
106+ function isExecutor (PoolId poolId , address user , address executor ) external view returns (bool ) {
107+ AsyncFiller.State storage state = asyncOrders[poolId];
108+ return state.setExecutor[user][executor];
106109 }
107110
108111 function calculateHookFee (uint256 ) public pure returns (uint256 ) {
@@ -120,7 +123,7 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
120123 for (uint8 i = 0 ; i < orders.length ; i++ ) {
121124 AsyncOrder calldata order = orders[i];
122125 // Use transaction ordering algorithm to ensure correct execution order
123- algorithm.orderingRule (order.zeroForOne, uint256 (order.amountIn));
126+ asyncOrders[order.key. toId ()]. algorithm.orderingRule (order.zeroForOne, uint256 (order.amountIn));
124127 this .executeOrder (order, userParams);
125128 }
126129 }
@@ -138,10 +141,10 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
138141
139142 /// TODO: Document what this does
140143 uint256 amountToFill = uint256 (amountIn);
141- // AsyncFiller.State storage _asyncOrders = asyncOrders[poolId];
142144 uint256 claimableAmount = asyncOrders[poolId].asyncOrders[owner][zeroForOne];
143145 require (amountToFill <= claimableAmount, "Max fill order limit exceed " );
144- require (isExecutor (owner, msg .sender ), "Caller is valid not excutor " );
146+ AsyncFiller.State storage state = asyncOrders[poolId];
147+ require (order.isExecutor (state, msg .sender ), "Caller is valid not excutor " );
145148
146149 /// @dev Transfer currency of async order to user
147150 Currency currencyTake;
@@ -190,7 +193,7 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
190193 /// @dev Take pool fee for LP
191194 uint256 feeAmount = calculatePoolFee (key.fee, amountTaken);
192195 uint256 finalTaken = amountTaken - feeAmount;
193- setExecutor[hookData.user][hookData.executor] = true ;
196+ asyncOrders[poolId]. setExecutor[hookData.user][hookData.executor] = true ;
194197 emit AsyncSwapOrder (poolId, hookData.user, params.zeroForOne, finalTaken.toInt256 ());
195198
196199 /// @dev Issue 1:1 claimableAmount - pool fee to user
0 commit comments