Merge pull request #274 from Instadapp/uniswap-v3-createpool-func

[Mainnet][Uniswap-v3] Added Create Pool function
This commit is contained in:
Thrilok kumar 2022-11-01 23:22:52 +05:30 committed by GitHub
commit b96cb2649d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 0 deletions

View File

@ -32,4 +32,11 @@ contract Events {
);
event LogBurnPosition(uint256 tokenId);
event LogcreateAndInitializePool (
address tokenA,
address tokenB,
uint24 fee,
int24 initialTick
);
}

View File

@ -66,6 +66,27 @@ abstract contract Helpers is DSMath, Basic {
}
}
function _createAndInitializePoolIfNecessary (
address tokenA,
address tokenB,
uint24 fee,
int24 initialTick
) internal returns (address pool) {
(TokenInterface token0Contract_, TokenInterface token1Contract_) = changeEthAddress(
tokenA,
tokenB
);
(address token0_, address token1_) = sortTokenAddress(address(token0Contract_), address(token1Contract_));
return nftManager.createAndInitializePoolIfNecessary(
token0_,
token1_,
fee,
TickMath.getSqrtRatioAtTick(initialTick)
);
}
/**
* @dev Mint function which interact with Uniswap v3
*/

View File

@ -12,6 +12,43 @@ import {Helpers} from "./helpers.sol";
import {Events} from "./events.sol";
abstract contract UniswapResolver is Helpers, Events {
/**
* @dev Create and Initialize pool
* @notice Create and Initialize new pool if required
* @param tokenA tokenA addreess
* @param tokenB tokenB addreess
* @param fee fee percentage
* @param initialTick Initial tick for the pool
*/
function createAndInitializePool (
address tokenA,
address tokenB,
uint24 fee,
int24 initialTick
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
address pool = _createAndInitializePoolIfNecessary(
tokenA,
tokenB,
fee,
initialTick
);
_eventName = "LogcreateAndInitializePool(address,address,address,uint24,int24)";
_eventParam = abi.encode(
tokenA,
tokenB,
pool,
fee,
initialTick
);
}
/**
* @dev Mint New Position
* @notice Mint New NFT LP Position