Skip to content

Commit d52f4c7

Browse files
committed
✨ use async filler lib, updated public method for claimable amount
1 parent cf719de commit d52f4c7

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/AsyncSwapCSMM.sol

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
3030
/// @notice Algorithm used for ordering transactions in our Async Swap AMM.
3131
IAlgorithm public algorithm;
3232
/// @notice Mapping to store async orders.
33-
mapping(PoolId poolId => mapping(address user => mapping(bool zeroForOne => uint256 claimable))) public asyncOrders;
34-
// mapping(PoolId poolId => AsyncFiller.State) public asyncOrders;
33+
mapping(PoolId poolId => AsyncFiller.State) public asyncOrders;
3534
/// @notice Mapping to store executor permissions for users.
3635
mapping(address owner => mapping(address executor => bool)) public setExecutor;
3736

@@ -102,6 +101,10 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
102101
return setExecutor[owner][executor];
103102
}
104103

104+
function asyncOrder(PoolId poolId, address user, bool zeroForOne) external view returns (uint256 claimable) {
105+
return asyncOrders[poolId].asyncOrders[user][zeroForOne];
106+
}
107+
105108
function calculateHookFee(uint256) public pure returns (uint256) {
106109
return 0;
107110
}
@@ -136,7 +139,7 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
136139
/// TODO: Document what this does
137140
uint256 amountToFill = uint256(amountIn);
138141
// AsyncFiller.State storage _asyncOrders = asyncOrders[poolId];
139-
uint256 claimableAmount = asyncOrders[poolId][owner][zeroForOne];
142+
uint256 claimableAmount = asyncOrders[poolId].asyncOrders[owner][zeroForOne];
140143
require(amountToFill <= claimableAmount, "Max fill order limit exceed");
141144
require(isExecutor(owner, msg.sender), "Caller is valid not excutor");
142145

@@ -151,7 +154,7 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
151154
currencyFill = currency0;
152155
}
153156

154-
asyncOrders[poolId][owner][zeroForOne] -= amountToFill;
157+
asyncOrders[poolId].asyncOrders[owner][zeroForOne] -= amountToFill;
155158
/// TODO: check if this is needed, we could just burn
156159
poolManager.transfer(owner, currencyTake.toId(), amountToFill);
157160
emit AsyncOrderFilled(poolId, owner, zeroForOne, amountToFill);
@@ -192,8 +195,8 @@ contract AsyncSwapCSMM is BaseHook, IAsyncSwapAMM {
192195

193196
/// @dev Issue 1:1 claimableAmount - pool fee to user
194197
/// @dev Add amount taken to previous claimableAmount
195-
uint256 currClaimables = asyncOrders[poolId][hookData.user][params.zeroForOne];
196-
asyncOrders[poolId][hookData.user][params.zeroForOne] = currClaimables + finalTaken;
198+
uint256 currClaimables = asyncOrders[poolId].asyncOrders[hookData.user][params.zeroForOne];
199+
asyncOrders[poolId].asyncOrders[hookData.user][params.zeroForOne] = currClaimables + finalTaken;
197200

198201
/// @dev Hook event
199202
/// @reference

src/interfaces/IAsyncSwapOrder.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ interface IAsyncSwapOrder {
3737
/// @param zeroForOne Whether the order is for a swap from currency0 to currency1 (true) or currency1 to currency0
3838
/// (false).
3939
/// @return claimable The amount that can be claimed by the user.
40-
function asyncOrders(PoolId poolId, address user, bool zeroForOne) external view returns (uint256 claimable);
40+
function asyncOrder(PoolId poolId, address user, bool zeroForOne) external view returns (uint256 claimable);
4141

4242
/// @notice Checks if the given executor is valid for the async order.
4343
/// @param owner The async order owner be checked against.

test/AsyncCSMM.t.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ contract AsyncCsmmTest is SetupHook {
6262

6363
function testFuzzAsyncSwapAndFillOrder(address _user, uint256 amountIn, bool zeroForOne) public {
6464
vm.assume(amountIn >= 1);
65-
vm.assume(amountIn < 2 ** 128 / 2);
65+
vm.assume(amountIn < 2 ** 96 / 2);
6666
user = _user;
6767
topUp(user, amountIn);
6868
topUp(user2, amountIn);
@@ -86,7 +86,7 @@ contract AsyncCsmmTest is SetupHook {
8686
assertEq(balance1Before - balance1After, amountIn);
8787
assertEq(balance0Before, balance0After);
8888
}
89-
assertEq(hook.asyncOrders(poolId, user, zeroForOne), amountIn);
89+
assertEq(hook.asyncOrder(poolId, user, zeroForOne), amountIn);
9090
assertEq(hook.setExecutor(user, asyncFiller), true);
9191

9292
balance0Before = currency0.balanceOf(user2);
@@ -101,11 +101,11 @@ contract AsyncCsmmTest is SetupHook {
101101
if (zeroForOne) {
102102
assertEq(balance0Before, balance0After);
103103
assertEq(balance1Before - balance1After, amountIn);
104-
assertEq(hook.asyncOrders(poolId, user, zeroForOne), 0);
104+
assertEq(hook.asyncOrder(poolId, user, zeroForOne), 0);
105105
} else {
106106
assertEq(balance1Before, balance1After);
107107
assertEq(balance0Before - balance0After, amountIn);
108-
assertEq(hook.asyncOrders(poolId, user, zeroForOne), 0);
108+
assertEq(hook.asyncOrder(poolId, user, zeroForOne), 0);
109109
}
110110
if (zeroForOne) {
111111
assertEq(manager.balanceOf(user, currency0.toId()), uint256(amountIn));
@@ -148,7 +148,7 @@ contract AsyncCsmmTest is SetupHook {
148148
assertEq(manager.balanceOf(address(hook), currency1.toId()), balance1Before + uint256(amount));
149149
}
150150

151-
assertEq(hook.asyncOrders(poolId, user, zeroForOne), uint256(amount));
151+
assertEq(hook.asyncOrder(poolId, user, zeroForOne), uint256(amount));
152152
}
153153

154154
}

0 commit comments

Comments
 (0)