mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Code formatting
This commit is contained in:
parent
e5c318d4e2
commit
89ba057da9
|
|
@ -1,25 +1,26 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
contract Events {
|
||||
event LogCreate(
|
||||
uint256 indexed tokenId,
|
||||
uint256 liquidity,
|
||||
uint256 amount,
|
||||
int24 tickLower,
|
||||
int24 tickUpper
|
||||
);
|
||||
event LogCreate(
|
||||
uint256 indexed tokenId,
|
||||
uint256 liquidity,
|
||||
uint256 amount,
|
||||
int24 tickLower,
|
||||
int24 tickUpper
|
||||
);
|
||||
|
||||
event LogWithdrawMid(
|
||||
uint256 indexed tokenId,
|
||||
uint256 liquidity,
|
||||
uint256 amountA,
|
||||
uint256 amountB
|
||||
);
|
||||
event LogWithdrawMid(
|
||||
uint256 indexed tokenId,
|
||||
uint256 liquidity,
|
||||
uint256 amountA,
|
||||
uint256 amountB
|
||||
);
|
||||
|
||||
event LogWithdrawFull(
|
||||
uint256 indexed tokenId,
|
||||
uint256 liquidity
|
||||
);
|
||||
event LogWithdrawFull(
|
||||
uint256 indexed tokenId,
|
||||
uint256 liquidity
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,59 +6,73 @@ import { Basic, TokenInterface } from "../../common/basic.sol";
|
|||
import "./interface.sol";
|
||||
|
||||
contract Helpers is Basic {
|
||||
IUniLimitOrder public constant limitCon_ =
|
||||
IUniLimitOrder(0x94F401fAD3ebb89fB7380f5fF6E875A88E6Af916);
|
||||
|
||||
IUniLimitOrder public constant limitCon_ = IUniLimitOrder(0x94F401fAD3ebb89fB7380f5fF6E875A88E6Af916);
|
||||
struct MintParams {
|
||||
address token0;
|
||||
address token1;
|
||||
uint24 fee;
|
||||
int24 tickLower;
|
||||
int24 tickUpper;
|
||||
uint256 amount;
|
||||
bool tokenDirectn;
|
||||
}
|
||||
|
||||
struct MintParams {
|
||||
address token0;
|
||||
address token1;
|
||||
uint24 fee;
|
||||
int24 tickLower;
|
||||
int24 tickUpper;
|
||||
uint256 amount;
|
||||
bool tokenDirectn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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_)
|
||||
internal
|
||||
returns (
|
||||
uint256 tokenId_,
|
||||
uint128 liquidity_,
|
||||
uint256 mintAmount_
|
||||
)
|
||||
{
|
||||
uint256 amountSend_;
|
||||
function _createPosition(MintParams memory params_)
|
||||
internal
|
||||
returns (
|
||||
uint256 tokenId_,
|
||||
uint128 liquidity_,
|
||||
uint256 mintAmount_
|
||||
)
|
||||
{
|
||||
uint256 amountSend_;
|
||||
|
||||
(TokenInterface token0_, TokenInterface token1_) = changeMaticAddress(
|
||||
params_.token0,
|
||||
params_.token1
|
||||
);
|
||||
(TokenInterface token0_, TokenInterface token1_) = changeMaticAddress(
|
||||
params_.token0,
|
||||
params_.token1
|
||||
);
|
||||
|
||||
if(params_.tokenDirectn){
|
||||
amountSend_ = params_.amount == type(uint128).max ? getTokenBal(TokenInterface(params_.token0)) : params_.amount;
|
||||
convertMaticToWmatic(params_.token0 == maticAddr, token0_, amountSend_);
|
||||
approve(token0_, address(limitCon_), amountSend_);
|
||||
} else {
|
||||
amountSend_ = params_.amount == type(uint128).max ? getTokenBal(TokenInterface(params_.token1)) : params_.amount;
|
||||
convertMaticToWmatic(params_.token1 == maticAddr, token1_, amountSend_);
|
||||
approve(token1_, address(limitCon_), amountSend_);
|
||||
}
|
||||
if (params_.tokenDirectn) {
|
||||
amountSend_ = params_.amount == type(uint128).max
|
||||
? getTokenBal(TokenInterface(params_.token0))
|
||||
: params_.amount;
|
||||
convertMaticToWmatic(
|
||||
params_.token0 == maticAddr,
|
||||
token0_,
|
||||
amountSend_
|
||||
);
|
||||
approve(token0_, address(limitCon_), amountSend_);
|
||||
} else {
|
||||
amountSend_ = params_.amount == type(uint128).max
|
||||
? getTokenBal(TokenInterface(params_.token1))
|
||||
: params_.amount;
|
||||
convertMaticToWmatic(
|
||||
params_.token1 == maticAddr,
|
||||
token1_,
|
||||
amountSend_
|
||||
);
|
||||
approve(token1_, address(limitCon_), amountSend_);
|
||||
}
|
||||
|
||||
IUniLimitOrder.MintParams memory parameter =
|
||||
IUniLimitOrder.MintParams(
|
||||
address(token0_),
|
||||
address(token1_),
|
||||
params_.fee,
|
||||
params_.tickLower,
|
||||
params_.tickUpper,
|
||||
amountSend_,
|
||||
params_.tokenDirectn
|
||||
);
|
||||
IUniLimitOrder.MintParams memory parameter = IUniLimitOrder.MintParams(
|
||||
address(token0_),
|
||||
address(token1_),
|
||||
params_.fee,
|
||||
params_.tickLower,
|
||||
params_.tickUpper,
|
||||
amountSend_,
|
||||
params_.tokenDirectn
|
||||
);
|
||||
|
||||
(tokenId_, liquidity_, mintAmount_) = limitCon_.createPosition(parameter);
|
||||
|
||||
}
|
||||
(tokenId_, liquidity_, mintAmount_) = limitCon_.createPosition(
|
||||
parameter
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ pragma solidity ^0.7.0;
|
|||
pragma experimental ABIEncoderV2;
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import {Helpers} from "./helpers.sol";
|
||||
import {IUniLimitOrder} from "./interface.sol";
|
||||
import {TokenInterface} from "../../common/interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { IUniLimitOrder } from "./interface.sol";
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
|
||||
/**
|
||||
* @title LimitOrderConnector.
|
||||
|
|
@ -12,80 +12,96 @@ import {TokenInterface} from "../../common/interfaces.sol";
|
|||
*/
|
||||
contract LimitOrderConnector is Helpers {
|
||||
|
||||
function create(
|
||||
address token0_,
|
||||
address token1_,
|
||||
uint24 fee_,
|
||||
int24 tickLower_,
|
||||
int24 tickUpper_,
|
||||
uint256 amount_,
|
||||
bool tokenDirectn_
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory eventName_, bytes memory eventParam_)
|
||||
{
|
||||
/**
|
||||
* @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(
|
||||
address token0_,
|
||||
address token1_,
|
||||
uint24 fee_,
|
||||
int24 tickLower_,
|
||||
int24 tickUpper_,
|
||||
uint256 amount_,
|
||||
bool tokenDirectn_
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory eventName_, bytes memory eventParam_)
|
||||
{
|
||||
MintParams memory params_ = MintParams(
|
||||
token0_,
|
||||
token1_,
|
||||
fee_,
|
||||
tickLower_,
|
||||
tickUpper_,
|
||||
amount_,
|
||||
tokenDirectn_
|
||||
);
|
||||
|
||||
MintParams memory params_ = MintParams(
|
||||
token0_,
|
||||
token1_,
|
||||
fee_,
|
||||
tickLower_,
|
||||
tickUpper_,
|
||||
amount_,
|
||||
tokenDirectn_
|
||||
);
|
||||
(
|
||||
uint256 tokenId_,
|
||||
uint256 liquidity_,
|
||||
uint256 minAmount_
|
||||
) = _createPosition(params_);
|
||||
|
||||
(
|
||||
uint256 tokenId_,
|
||||
uint256 liquidity_,
|
||||
uint256 minAmount_
|
||||
) = _createPosition(params_);
|
||||
eventName_ = "LogCreate(uint256,uint256,uint256,int24,int24)";
|
||||
eventParam_ = abi.encode(
|
||||
tokenId_,
|
||||
liquidity_,
|
||||
minAmount_,
|
||||
params_.tickLower,
|
||||
params_.tickUpper
|
||||
);
|
||||
}
|
||||
|
||||
eventName_ = "LogCreate(uint256,uint256,uint256,int24,int24)";
|
||||
eventParam_ = abi.encode(
|
||||
tokenId_,
|
||||
liquidity_,
|
||||
minAmount_,
|
||||
params_.tickLower,
|
||||
params_.tickUpper
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @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(
|
||||
uint256 tokenId_,
|
||||
uint256 amountAMin_,
|
||||
uint256 amountBMin_
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory eventName_, bytes memory eventParam_)
|
||||
{
|
||||
(uint128 liquidity_, uint256 amount0, uint256 amount1) = limitCon_
|
||||
.closeMidPosition(tokenId_, amountAMin_, amountBMin_);
|
||||
|
||||
eventName_ = "LogWithdrawMid(uint256,uint256,uint256,uint256)";
|
||||
eventParam_ = abi.encode(tokenId_, liquidity_, amount0, amount1);
|
||||
}
|
||||
|
||||
function closeMid(
|
||||
uint256 tokenId_,
|
||||
uint256 amountAMin_,
|
||||
uint256 amountBMin_
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory eventName_, bytes memory eventParam_)
|
||||
{
|
||||
|
||||
(uint128 liquidity_, uint256 amount0, uint256 amount1) = limitCon_.closeMidPosition(tokenId_, amountAMin_, amountBMin_);
|
||||
|
||||
eventName_ = "LogWithdrawMid(uint256,uint256,uint256,uint256)";
|
||||
eventParam_ = abi.encode(tokenId_, liquidity_, amount0, amount1);
|
||||
}
|
||||
|
||||
|
||||
function closeFull(
|
||||
uint256 tokenId_
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory eventName_, bytes memory eventParam_)
|
||||
{
|
||||
|
||||
(uint256 closeAmount_) = limitCon_.closeFullPosition(tokenId_);
|
||||
|
||||
eventName_ = "LogWithdrawFull(uint256,uint256)";
|
||||
eventParam_ = abi.encode(tokenId_, closeAmount_);
|
||||
}
|
||||
/**
|
||||
* @dev Close NFT after swap completion
|
||||
* @notice Close NFT after swap completion
|
||||
* @param tokenId_ Token ID.
|
||||
*/
|
||||
function closeFull(uint256 tokenId_)
|
||||
external
|
||||
payable
|
||||
returns (string memory eventName_, bytes memory eventParam_)
|
||||
{
|
||||
uint256 closeAmount_ = limitCon_.closeFullPosition(tokenId_);
|
||||
|
||||
eventName_ = "LogWithdrawFull(uint256,uint256)";
|
||||
eventParam_ = abi.encode(tokenId_, closeAmount_);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2LimitOrder is LimitOrderConnector {
|
||||
string public constant name = "Limit-Order-Connector";
|
||||
}
|
||||
string public constant name = "Limit-Order-Connector";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user