Skip to content

Commit

Permalink
Merge pull request #133 from cryptoalgebra/integral-v1.2-periphery
Browse files Browse the repository at this point in the history
Integral v1.2 periphery
  • Loading branch information
IliaAzhel authored Sep 27, 2024
2 parents 86cf458 + 43f761e commit d6e1812
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 155 deletions.
5 changes: 3 additions & 2 deletions src/periphery/contracts/base/PoolInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ abstract contract PoolInitializer is IPoolInitializer, PeripheryImmutableState {
address token0,
address token1,
address deployer,
uint160 sqrtPriceX96
uint160 sqrtPriceX96,
bytes calldata data
) external payable override returns (address pool) {
require(token0 < token1, 'Invalid order of tokens');

Expand All @@ -32,7 +33,7 @@ abstract contract PoolInitializer is IPoolInitializer, PeripheryImmutableState {

if (pool == address(0)) {
if (deployer == address(0)) {
pool = _factory.createPool(token0, token1, '');
pool = _factory.createPool(token0, token1, data);

_initializePool(pool, sqrtPriceX96);
}
Expand Down
4 changes: 3 additions & 1 deletion src/periphery/contracts/interfaces/IPoolInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ interface IPoolInitializer {
/// @param token0 The contract address of token0 of the pool
/// @param token1 The contract address of token1 of the pool
/// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value
/// @param data Data for plugin initialization
/// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary
function createAndInitializePoolIfNecessary(
address token0,
address token1,
address deployer,
uint160 sqrtPriceX96
uint160 sqrtPriceX96,
bytes calldata data
) external payable returns (address pool);
}
16 changes: 8 additions & 8 deletions src/periphery/contracts/interfaces/IQuoterV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ interface IQuoterV2 {
/// @notice Returns the amount out received for a given exact input swap without executing the swap
/// @param path The path of the swap, i.e. each token pair
/// @param amountInRequired The desired amount of the first token to swap
/// @return amountOut The amount of the last token that would be received
/// @return amountIn The amount of the last token that should be paid
/// @return amountOutList The amount of the last token that would be received
/// @return amountInList The amount of the last token that should be paid
/// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path
/// @return initializedTicksCrossedList List of the initialized ticks that the swap crossed for each pool in the path
/// @return gasEstimate The estimate of the gas that the swap consumes
Expand All @@ -25,8 +25,8 @@ interface IQuoterV2 {
)
external
returns (
uint256 amountOut,
uint256 amountIn,
uint256[] memory amountOutList,
uint256[] memory amountInList,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList,
uint256 gasEstimate,
Expand Down Expand Up @@ -69,8 +69,8 @@ interface IQuoterV2 {
/// @notice Returns the amount in required for a given exact output swap without executing the swap
/// @param path The path of the swap, i.e. each token pair. Path must be provided in reverse order
/// @param amountOutRequired The amount of the last token to receive
/// @return amountOut The amount of the last token that would be received
/// @return amountIn The amount of first token required to be paid
/// @return amountOutList The amount of the last token that would be received
/// @return amountInList The amount of first token required to be paid
/// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path
/// @return initializedTicksCrossedList List of the initialized ticks that the swap crossed for each pool in the path
/// @return gasEstimate The estimate of the gas that the swap consumes
Expand All @@ -81,8 +81,8 @@ interface IQuoterV2 {
)
external
returns (
uint256 amountOut,
uint256 amountIn,
uint256[] memory amountOutList,
uint256[] memory amountInList,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList,
uint256 gasEstimate,
Expand Down
40 changes: 18 additions & 22 deletions src/periphery/contracts/lens/QuoterV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,16 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState {
public
override
returns (
uint256 amountOut,
uint256 amountIn,
uint256[] memory amountOutList,
uint256[] memory amountInList,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList,
uint256 gasEstimate,
uint16[] memory feeList
)
{
amountOutList = new uint256[](path.numPools());
amountInList = new uint256[](path.numPools());
sqrtPriceX96AfterList = new uint160[](path.numPools());
initializedTicksCrossedList = new uint32[](path.numPools());
feeList = new uint16[](path.numPools());
Expand All @@ -185,21 +187,17 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState {
}

// the outputs of prior swaps become the inputs to subsequent ones
uint256 _amountOut;
uint256 _amountIn;
uint256 _gasEstimate;
(
_amountOut,
_amountIn,
amountOutList[i],
amountInList[i],
sqrtPriceX96AfterList[i],
initializedTicksCrossedList[i],
_gasEstimate,
feeList[i]
) = quoteExactInputSingle(params);

if (i == 0) amountIn = _amountIn;

amountInRequired = _amountOut;
amountInRequired = amountOutList[i];
gasEstimate += _gasEstimate;
i++;

Expand All @@ -208,8 +206,8 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState {
path = path.skipToken();
} else {
return (
amountInRequired,
amountIn,
amountOutList,
amountInList,
sqrtPriceX96AfterList,
initializedTicksCrossedList,
gasEstimate,
Expand Down Expand Up @@ -264,14 +262,16 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState {
public
override
returns (
uint256 amountOut,
uint256 amountIn,
uint256[] memory amountOutList,
uint256[] memory amountInList,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList,
uint256 gasEstimate,
uint16[] memory feeList
)
{
amountOutList = new uint256[](path.numPools());
amountInList = new uint256[](path.numPools());
sqrtPriceX96AfterList = new uint160[](path.numPools());
initializedTicksCrossedList = new uint32[](path.numPools());
feeList = new uint16[](path.numPools());
Expand All @@ -289,21 +289,17 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState {
}

// the inputs of prior swaps become the outputs of subsequent ones
uint256 _amountOut;
uint256 _amountIn;
uint256 _gasEstimate;
(
_amountOut,
_amountIn,
amountOutList[i],
amountInList[i],
sqrtPriceX96AfterList[i],
initializedTicksCrossedList[i],
_gasEstimate,
feeList[i]
) = quoteExactOutputSingle(params);

if (i == 0) amountOut = _amountOut;

amountOutRequired = _amountIn;
amountOutRequired = amountInList[i];
gasEstimate += _gasEstimate;
i++;

Expand All @@ -312,8 +308,8 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState {
path = path.skipToken();
} else {
return (
amountOut,
amountOutRequired,
amountOutList,
amountInList,
sqrtPriceX96AfterList,
initializedTicksCrossedList,
gasEstimate,
Expand Down
Loading

0 comments on commit d6e1812

Please sign in to comment.