dsa-connectors/contracts/mainnet/connectors/uniswapV3/main.sol

211 lines
5.9 KiB
Solidity
Raw Normal View History

2021-08-10 14:54:21 +00:00
pragma solidity ^0.7.6;
2021-08-08 09:29:35 +00:00
pragma abicoder v2;
/**
* @title Uniswap v3.
* @dev Decentralized Exchange.
*/
import {TokenInterface} from "../../common/interfaces.sol";
import {Helpers} from "./helpers.sol";
import {Events} from "./events.sol";
abstract contract UniswapResolver is Helpers, Events {
/**
* @dev Mint New Position
2021-08-18 20:11:29 +00:00
* @notice Mint New NFT LP Position
2021-08-20 20:19:15 +00:00
* @param tokenA tokenA addreess
* @param tokenB tokenB addreess
* @param fee fee percentage
* @param tickLower Lower tick
* @param tickUpper Upper tick
* @param amtA amount of tokenA
* @param amtB amount of tokenB
* @param slippage slippage percentage
2021-08-18 20:11:29 +00:00
* @param getIds ID to retrieve amtA
* @param setId ID stores the amount of LP token
2021-08-08 09:29:35 +00:00
*/
function mint(
2021-08-20 20:10:38 +00:00
address tokenA,
address tokenB,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint256 amtA,
uint256 amtB,
uint256 slippage,
uint256[] calldata getIds,
2021-08-08 09:29:35 +00:00
uint256 setId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
2021-08-20 20:10:38 +00:00
MintParams memory params;
{
params = MintParams(
tokenA,
tokenB,
fee,
tickLower,
tickUpper,
amtA,
amtB,
slippage
);
}
params.amtA = getUint(getIds[0], params.amtA);
params.amtB = getUint(getIds[1], params.amtB);
2021-08-10 14:54:21 +00:00
2021-08-08 09:29:35 +00:00
(
uint256 _tokenId,
uint256 liquidity,
2021-08-12 22:12:11 +00:00
uint256 amountA,
uint256 amountB
2021-08-08 09:29:35 +00:00
) = _mint(params);
2021-08-12 22:12:11 +00:00
setUint(setId, liquidity);
2021-08-12 22:12:11 +00:00
_eventName = "LogMint(uint256,uint256,uint256,uint256,int24,int24)";
_eventParam = abi.encode(
_tokenId,
liquidity,
amountA,
amountB,
params.tickLower,
params.tickUpper
);
2021-08-08 09:29:35 +00:00
}
/**
* @dev Increase Liquidity
2021-08-18 20:11:29 +00:00
* @notice Increase Liquidity of NFT Position
* @param tokenId NFT LP Token ID.
* @param amountA tokenA amounts.
* @param amountB tokenB amounts.
* @param slippage slippage.
* @param getIds IDs to retrieve token amounts
* @param setId stores the liquidity amount
2021-08-08 09:29:35 +00:00
*/
2021-08-12 22:12:11 +00:00
function deposit(
2021-08-08 09:29:35 +00:00
uint256 tokenId,
uint256 amountA,
uint256 amountB,
2021-08-12 22:12:11 +00:00
uint256 slippage,
2021-08-08 09:29:35 +00:00
uint256[] calldata getIds,
uint256 setId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
2021-08-12 22:12:11 +00:00
if (tokenId == 0) tokenId = _getLastNftId(address(this));
amountA = getUint(getIds[0], amountA);
amountB = getUint(getIds[1], amountB);
(
uint256 _liquidity,
uint256 _amtA,
uint256 _amtB
) = _addLiquidityWrapper(tokenId, amountA, amountB, slippage);
2021-08-08 09:29:35 +00:00
setUint(setId, _liquidity);
2021-08-12 22:12:11 +00:00
_eventName = "LogDeposit(uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(tokenId, _liquidity, _amtA, _amtB);
2021-08-08 09:29:35 +00:00
}
/**
* @dev Decrease Liquidity
2021-08-18 20:11:29 +00:00
* @notice Decrease Liquidity of NFT Position
* @param tokenId NFT LP Token ID.
* @param liquidity LP Token amount.
* @param amountAMin Min amount of tokenA.
* @param amountBMin Min amount of tokenB.
* @param getId ID to retrieve LP token amounts
* @param setIds stores the amount of output tokens
2021-08-08 09:29:35 +00:00
*/
2021-08-12 22:12:11 +00:00
function withdraw(
2021-08-08 09:29:35 +00:00
uint256 tokenId,
2021-08-12 22:12:11 +00:00
uint256 liquidity,
2021-08-09 14:58:28 +00:00
uint256 amountAMin,
uint256 amountBMin,
2021-08-08 09:29:35 +00:00
uint256 getId,
uint256[] calldata setIds
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
2021-08-12 22:12:11 +00:00
if (tokenId == 0) tokenId = _getLastNftId(address(this));
2021-08-08 09:29:35 +00:00
uint128 _liquidity = uint128(getUint(getId, liquidity));
(uint256 _amtA, uint256 _amtB) = _decreaseLiquidity(
tokenId,
2021-08-09 14:58:28 +00:00
_liquidity,
amountAMin,
amountBMin
2021-08-08 09:29:35 +00:00
);
setUint(setIds[0], _amtA);
setUint(setIds[1], _amtB);
2021-08-12 22:12:11 +00:00
_eventName = "LogWithdraw(uint256,uint256,uint256,uint256)";
2021-08-08 09:29:35 +00:00
_eventParam = abi.encode(tokenId, _liquidity, _amtA, _amtB);
}
2021-08-09 14:58:28 +00:00
/**
* @dev Collect function
2021-08-18 20:11:29 +00:00
* @notice Collect from NFT Position
* @param tokenId NFT LP Token ID.
* @param amount0Max Max amount of token0.
* @param amount1Max Max amount of token1.
* @param getIds IDs to retrieve amounts
* @param setIds stores the amount of output tokens
2021-08-09 14:58:28 +00:00
*/
function collect(
uint256 tokenId,
2021-08-12 22:12:11 +00:00
uint256 amount0Max,
uint256 amount1Max,
2021-08-09 14:58:28 +00:00
uint256[] calldata getIds,
uint256[] calldata setIds
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
2021-08-12 22:12:11 +00:00
if (tokenId == 0) tokenId = _getLastNftId(address(this));
2021-08-09 20:08:48 +00:00
uint128 _amount0Max = uint128(getUint(getIds[0], amount0Max));
uint128 _amount1Max = uint128(getUint(getIds[1], amount1Max));
2021-08-09 14:58:28 +00:00
(uint256 amount0, uint256 amount1) = _collect(
tokenId,
_amount0Max,
_amount1Max
);
setUint(setIds[0], amount0);
setUint(setIds[1], amount1);
2021-08-12 22:12:11 +00:00
_eventName = "LogCollect(uint256,uint256,uint256)";
2021-08-09 14:58:28 +00:00
_eventParam = abi.encode(tokenId, amount0, amount1);
}
2021-08-10 15:18:33 +00:00
/**
* @dev Burn Function
2021-08-18 20:11:29 +00:00
* @notice Burn NFT LP Position
* @param tokenId NFT LP Token ID
2021-08-10 15:18:33 +00:00
*/
2021-08-12 22:12:11 +00:00
function burn(uint256 tokenId)
2021-08-10 15:18:33 +00:00
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
2021-08-12 22:12:11 +00:00
if (tokenId == 0) tokenId = _getLastNftId(address(this));
2021-08-10 15:18:33 +00:00
_burn(tokenId);
2021-08-12 22:12:11 +00:00
_eventName = "LogBurnPosition(uint256)";
2021-08-10 15:18:33 +00:00
_eventParam = abi.encode(tokenId);
}
2021-08-08 09:29:35 +00:00
}
contract ConnectV2UniswapV3 is UniswapResolver {
2021-08-10 16:42:18 +00:00
string public constant name = "UniswapV3-v1";
2021-08-08 09:29:35 +00:00
}