Code formatting

This commit is contained in:
Shriya Tyagi 2022-04-12 01:33:43 +04:00
parent e5c318d4e2
commit 89ba057da9
4 changed files with 167 additions and 168 deletions

View File

@ -1,5 +1,6 @@
pragma solidity ^0.7.0; pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
contract Events { contract Events {

View File

@ -6,8 +6,8 @@ import { Basic, TokenInterface } from "../../common/basic.sol";
import "./interface.sol"; import "./interface.sol";
contract Helpers is Basic { contract Helpers is Basic {
IUniLimitOrder public constant limitCon_ =
IUniLimitOrder public constant limitCon_ = IUniLimitOrder(0x94F401fAD3ebb89fB7380f5fF6E875A88E6Af916); IUniLimitOrder(0x94F401fAD3ebb89fB7380f5fF6E875A88E6Af916);
struct MintParams { struct MintParams {
address token0; address token0;
@ -20,9 +20,11 @@ contract Helpers is Basic {
} }
/** /**
* @dev Mint function which interact with Uniswap v3 * @dev Create position
* @notice Create position that interacts with UniLimitOrder
* @param params_ Create Position params.
*/ */
function _createPosition (MintParams memory params_) function _createPosition(MintParams memory params_)
internal internal
returns ( returns (
uint256 tokenId_, uint256 tokenId_,
@ -37,18 +39,29 @@ contract Helpers is Basic {
params_.token1 params_.token1
); );
if(params_.tokenDirectn){ if (params_.tokenDirectn) {
amountSend_ = params_.amount == type(uint128).max ? getTokenBal(TokenInterface(params_.token0)) : params_.amount; amountSend_ = params_.amount == type(uint128).max
convertMaticToWmatic(params_.token0 == maticAddr, token0_, amountSend_); ? getTokenBal(TokenInterface(params_.token0))
: params_.amount;
convertMaticToWmatic(
params_.token0 == maticAddr,
token0_,
amountSend_
);
approve(token0_, address(limitCon_), amountSend_); approve(token0_, address(limitCon_), amountSend_);
} else { } else {
amountSend_ = params_.amount == type(uint128).max ? getTokenBal(TokenInterface(params_.token1)) : params_.amount; amountSend_ = params_.amount == type(uint128).max
convertMaticToWmatic(params_.token1 == maticAddr, token1_, amountSend_); ? getTokenBal(TokenInterface(params_.token1))
: params_.amount;
convertMaticToWmatic(
params_.token1 == maticAddr,
token1_,
amountSend_
);
approve(token1_, address(limitCon_), amountSend_); approve(token1_, address(limitCon_), amountSend_);
} }
IUniLimitOrder.MintParams memory parameter = IUniLimitOrder.MintParams memory parameter = IUniLimitOrder.MintParams(
IUniLimitOrder.MintParams(
address(token0_), address(token0_),
address(token1_), address(token1_),
params_.fee, params_.fee,
@ -58,7 +71,8 @@ contract Helpers is Basic {
params_.tokenDirectn params_.tokenDirectn
); );
(tokenId_, liquidity_, mintAmount_) = limitCon_.createPosition(parameter); (tokenId_, liquidity_, mintAmount_) = limitCon_.createPosition(
parameter
);
} }
} }

View File

@ -2,9 +2,9 @@ pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import {Helpers} from "./helpers.sol"; import { Helpers } from "./helpers.sol";
import {IUniLimitOrder} from "./interface.sol"; import { IUniLimitOrder } from "./interface.sol";
import {TokenInterface} from "../../common/interfaces.sol"; import { TokenInterface } from "../../common/interfaces.sol";
/** /**
* @title LimitOrderConnector. * @title LimitOrderConnector.
@ -12,6 +12,17 @@ import {TokenInterface} from "../../common/interfaces.sol";
*/ */
contract LimitOrderConnector is Helpers { contract LimitOrderConnector is Helpers {
/**
* @dev Create NFT
* @notice Create NFT
* @param token0_ Token0 Address.
* @param token1_ Token1 Amount.
* @param fee_ Pool fee.
* @param tickLower_ Lower tick.
* @param tickUpper_ Upper tick.
* @param amount_ Amount to deposit
* @param tokenDirectn_ Token 0 to 1 bool
*/
function create( function create(
address token0_, address token0_,
address token1_, address token1_,
@ -25,7 +36,6 @@ contract LimitOrderConnector is Helpers {
payable payable
returns (string memory eventName_, bytes memory eventParam_) returns (string memory eventName_, bytes memory eventParam_)
{ {
MintParams memory params_ = MintParams( MintParams memory params_ = MintParams(
token0_, token0_,
token1_, token1_,
@ -52,7 +62,13 @@ contract LimitOrderConnector is Helpers {
); );
} }
/**
* @dev Close NFT in Mid
* @notice Close NFT in Mid
* @param tokenId_ Token ID.
* @param amountAMin_ Amount A Min.
* @param amountBMin_ Amount B Min.
*/
function closeMid( function closeMid(
uint256 tokenId_, uint256 tokenId_,
uint256 amountAMin_, uint256 amountAMin_,
@ -62,28 +78,28 @@ contract LimitOrderConnector is Helpers {
payable payable
returns (string memory eventName_, bytes memory eventParam_) returns (string memory eventName_, bytes memory eventParam_)
{ {
(uint128 liquidity_, uint256 amount0, uint256 amount1) = limitCon_
(uint128 liquidity_, uint256 amount0, uint256 amount1) = limitCon_.closeMidPosition(tokenId_, amountAMin_, amountBMin_); .closeMidPosition(tokenId_, amountAMin_, amountBMin_);
eventName_ = "LogWithdrawMid(uint256,uint256,uint256,uint256)"; eventName_ = "LogWithdrawMid(uint256,uint256,uint256,uint256)";
eventParam_ = abi.encode(tokenId_, liquidity_, amount0, amount1); eventParam_ = abi.encode(tokenId_, liquidity_, amount0, amount1);
} }
/**
function closeFull( * @dev Close NFT after swap completion
uint256 tokenId_ * @notice Close NFT after swap completion
) * @param tokenId_ Token ID.
*/
function closeFull(uint256 tokenId_)
external external
payable payable
returns (string memory eventName_, bytes memory eventParam_) returns (string memory eventName_, bytes memory eventParam_)
{ {
uint256 closeAmount_ = limitCon_.closeFullPosition(tokenId_);
(uint256 closeAmount_) = limitCon_.closeFullPosition(tokenId_);
eventName_ = "LogWithdrawFull(uint256,uint256)"; eventName_ = "LogWithdrawFull(uint256,uint256)";
eventParam_ = abi.encode(tokenId_, closeAmount_); eventParam_ = abi.encode(tokenId_, closeAmount_);
} }
} }
contract ConnectV2LimitOrder is LimitOrderConnector { contract ConnectV2LimitOrder is LimitOrderConnector {

View File

@ -1,32 +0,0 @@
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
//
// If this script is run directly using `node` you may want to call compile
// manually to make sure everything is compiled
// await hre.run('compile');
// We get the contract to deploy
const Greeter = await hre.ethers.getContractFactory("ConnectV2LimitOrder");
const greeter = await Greeter.deploy();
await greeter.deployed();
console.log("Greeter deployed to:", greeter.address);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});