Skip to content

Commit

Permalink
rename initializedTicksCrossed to initializedTicksLoaded
Browse files Browse the repository at this point in the history
  • Loading branch information
ConjunctiveNormalForm committed Nov 16, 2023
1 parent e3f6c7e commit a8a0ed1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 63 deletions.
4 changes: 2 additions & 2 deletions contracts/interfaces/IQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ interface IQuoter {

function quoteExactInputSingle(ExactInputSingleParams calldata params)
external
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed);
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded);

function quoteExactInput(ExactInputParams memory params)
external
returns (
int128[] memory deltaAmounts,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList
uint32[] memory initializedTicksLoadedList
);
}
49 changes: 26 additions & 23 deletions contracts/lens/Quoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract Quoter is IQuoter {
function quoteExactInputSingle(ExactInputSingleParams memory params)
external
override
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed)
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded)
{
try poolManager.lock(abi.encode(SwapInfo(SwapType.ExactInputSingle, abi.encode(params)))) {}
catch (bytes memory reason) {
Expand All @@ -44,7 +44,7 @@ contract Quoter is IQuoter {
returns (
int128[] memory deltaAmounts,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList
uint32[] memory initializedTicksLoadedList
)
{
try poolManager.lock(abi.encode(SwapInfo(SwapType.ExactInput, abi.encode(params)))) {}
Expand Down Expand Up @@ -72,26 +72,29 @@ contract Quoter is IQuoter {
(
int128[] memory deltaAmounts,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList
uint32[] memory initializedTicksLoadedList
) = _quoteExactInput(abi.decode(swapInfo.params, (ExactInputParams)));

// bytes memory result = abi.encode(deltaAmounts, sqrtPriceX96AfterList, initializedTicksLoadedList);
// uint256 resultLength = result.length;
assembly {
// function storeArray(offset, length, array) {
// mstore(offset, length)
// offset := add(offset, 0x20)
// for { let i := 0 } lt(i, length) { i := add(i, 1) } {
// let value := mload(add(array, add(mul(i, 0x20), 0x20)))
// mstore(offset, value)
// offset := add(offset, 0x20)
// }
// }
//revert(result, resultLength)
function storeArray(offset, length, array) {
mstore(offset, length)
offset := add(offset, 0x20)
for { let i := 0 } lt(i, length) { i := add(i, 1) } {
let value := mload(add(array, add(mul(i, 0x20), 0x20)))
mstore(offset, value)
offset := add(offset, 0x20)
}
}

let originalPtr := mload(0x40)
let ptr := mload(0x40)

let deltaLength := mload(deltaAmounts)
let sqrtPriceLength := mload(sqrtPriceX96AfterList)
let initializedTicksLength := mload(initializedTicksCrossedList)
let initializedTicksLength := mload(initializedTicksLoadedList)

let deltaOffset := 0x60
let sqrtPriceOffset := add(deltaOffset, add(0x20, mul(0x20, deltaLength)))
Expand Down Expand Up @@ -125,7 +128,7 @@ contract Quoter is IQuoter {
mstore(ptr, initializedTicksLength)
ptr := add(ptr, 0x20)
for { let i := 0 } lt(i, initializedTicksLength) { i := add(i, 1) } {
let value := mload(add(initializedTicksCrossedList, add(mul(i, 0x20), 0x20)))
let value := mload(add(initializedTicksLoadedList, add(mul(i, 0x20), 0x20)))
mstore(ptr, value)
ptr := add(ptr, 0x20)
}
Expand Down Expand Up @@ -154,7 +157,7 @@ contract Quoter is IQuoter {
function _handleRevertExactInputSingle(bytes memory reason, PoolKey memory poolKey)
private
view
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed)
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded)
{
int24 tickBefore;
int24 tickAfter;
Expand All @@ -166,8 +169,8 @@ contract Quoter is IQuoter {
deltaAmounts[0] = deltas.amount0();
deltaAmounts[1] = deltas.amount1();

initializedTicksCrossed =
PoolTicksCounter.countInitializedTicksCrossed(poolManager, poolKey, tickBefore, tickAfter);
initializedTicksLoaded =
PoolTicksCounter.countInitializedTicksLoaded(poolManager, poolKey, tickBefore, tickAfter);
}

function _handleRevertExactInput(bytes memory reason)
Expand All @@ -176,11 +179,11 @@ contract Quoter is IQuoter {
returns (
int128[] memory deltaAmounts,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList
uint32[] memory initializedTicksLoadedList
)
{
reason = validateRevertReason(reason);
(deltaAmounts, sqrtPriceX96AfterList, initializedTicksCrossedList) =
(deltaAmounts, sqrtPriceX96AfterList, initializedTicksLoadedList) =
abi.decode(reason, (int128[], uint160[], uint32[]));
}

Expand All @@ -189,14 +192,14 @@ contract Quoter is IQuoter {
returns (
int128[] memory deltaAmounts,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList
uint32[] memory initializedTicksLoadedList
)
{
uint256 pathLength = params.path.length;

deltaAmounts = new int128[](pathLength + 1);
sqrtPriceX96AfterList = new uint160[](pathLength);
initializedTicksCrossedList = new uint32[](pathLength);
initializedTicksLoadedList = new uint32[](pathLength);
Currency prevCurrencyOut;
uint128 prevAmountOut;

Expand All @@ -223,8 +226,8 @@ contract Quoter is IQuoter {
prevAmountOut = zeroForOne ? uint128(-curDeltas.amount1()) : uint128(-curDeltas.amount0());
prevCurrencyOut = params.path[i].intermediateCurrency;
sqrtPriceX96AfterList[i] = sqrtPriceX96After;
initializedTicksCrossedList[i] =
PoolTicksCounter.countInitializedTicksCrossed(poolManager, poolKey, tickBefore, tickAfter);
initializedTicksLoadedList[i] =
PoolTicksCounter.countInitializedTicksLoaded(poolManager, poolKey, tickBefore, tickAfter);
}
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/PoolTicksCounter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ library PoolTicksCounter {
/// When tickBefore and/or tickAfter themselves are initialized, the logic over whether we should count them depends on the
/// direction of the swap. If we are swapping upwards (tickAfter > tickBefore) we don't want to count tickBefore but we do
/// want to count tickAfter. The opposite is true if we are swapping downwards.
function countInitializedTicksCrossed(IPoolManager self, PoolKey memory key, int24 tickBefore, int24 tickAfter)
function countInitializedTicksLoaded(IPoolManager self, PoolKey memory key, int24 tickBefore, int24 tickAfter)
internal
view
returns (uint32 initializedTicksCrossed)
Expand Down
Loading

0 comments on commit a8a0ed1

Please sign in to comment.