Skip to content

Commit bca1663

Browse files
committed
check for async order vol
1 parent e83e901 commit bca1663

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/AsyncSwap.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ contract AsyncSwap is BaseHook, IAsyncSwapAMM {
2929
mapping(PoolId poolId => AsyncFiller.State) public asyncOrders;
3030
/// Ordering algortim
3131
IAlgorithm public immutable ALGORITHM;
32+
mapping(uint256 block => uint256 volatility) public kvolatility;
3233

3334
/// Event emitted when a swap is executed.
3435
/// @param id The poolId of the pool where the swap occurred.
@@ -117,6 +118,10 @@ contract AsyncSwap is BaseHook, IAsyncSwapAMM {
117118

118119
/// @inheritdoc IAsyncSwapAMM
119120
function executeOrders(AsyncOrder[] calldata orders, bytes calldata userParams) external {
121+
/// Sort poolIDs
122+
/// Order swaps by poolId
123+
124+
uint256 volatility = ALGORITHM.getVolatility(orders);
120125
for (uint8 i = 0; i < orders.length; i++) {
121126
AsyncOrder calldata order = orders[i];
122127
// Use transaction ordering algorithm to ensure correct execution order

src/algorithms/BaseAlgorithm.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity ^0.8.26;
33

44
import { IAlgorithm } from "@async-swap/interfaces/IAlgorithm.sol";
5+
import { AsyncOrder } from "@async-swap/types/AsyncOrder.sol";
56

67
contract BaseAlgorithm is IAlgorithm {
78

@@ -42,4 +43,9 @@ contract BaseAlgorithm is IAlgorithm {
4243
revert("BaseAlgorithm: orderingRule not implemented");
4344
}
4445

46+
function getVolatility(AsyncOrder[] memory orders) external pure virtual override returns (uint256) {
47+
orders;
48+
revert("BaseAlgorithm: orderingRule not implemented");
49+
}
50+
4551
}

src/algorithms/clvr.sol

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
pragma solidity ^0.8.26;
33

44
import { BaseAlgorithm } from "./BaseAlgorithm.sol";
5+
56
import { IAlgorithm } from "@async-swap/interfaces/IAlgorithm.sol";
7+
import { AsyncOrder } from "@async-swap/types/AsyncOrder.sol";
68

79
/// @title Clever Lookahead Volatility Reduction (CLVR) Ordering Contract.
810
/// @author Meek Msaki @ Async Labs
@@ -30,4 +32,15 @@ contract CLVR is BaseAlgorithm {
3032
/// TODO: Implement the CLVR algorithm logic here.
3133
}
3234

35+
function getVolatility(AsyncOrder[] memory orders) external pure override returns (uint256) {
36+
uint256 accum;
37+
uint256 vol;
38+
for (uint256 i = 0; i < orders.length; i++) {
39+
accum;
40+
AsyncOrder memory order = orders[i];
41+
order.amountIn;
42+
}
43+
return vol;
44+
}
45+
3346
}

src/interfaces/IAlgorithm.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.26;
33

4+
import { AsyncOrder } from "@async-swap/types/AsyncOrder.sol";
5+
46
/// @title Algorithm Interface
57
/// @author Async Labs
68
/// @notice This interface defines the functions for transaction ordering algorithms used in the Async Swap AMM hook.
@@ -20,4 +22,6 @@ interface IAlgorithm {
2022
/// @return The version of the algorithm as a string.
2123
function version() external view returns (string memory);
2224

25+
function getVolatility(AsyncOrder[] memory orders) external pure returns (uint256);
26+
2327
}

0 commit comments

Comments
 (0)