mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
update
This commit is contained in:
parent
90ff0eedf0
commit
69ce278335
67
contracts/arbitrum/connectors/uniswap-sell-beta/helpers.sol
Normal file
67
contracts/arbitrum/connectors/uniswap-sell-beta/helpers.sol
Normal file
|
@ -0,0 +1,67 @@
|
|||
pragma solidity ^0.7.6;
|
||||
pragma abicoder v2;
|
||||
|
||||
import "./interface.sol";
|
||||
import {SqrtPriceMath} from "./libraries/SqrtPriceMath.sol";
|
||||
import "./libraries/TransferHelper.sol";
|
||||
|
||||
abstract contract Helpers is ISwapRouter {
|
||||
ISwapRouter router =
|
||||
ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);
|
||||
|
||||
UniswapV3Pool state =
|
||||
UniswapV3Pool(0xCEda10b4d3bdE429DdA3A6daB87b38360313CBdB);
|
||||
|
||||
function getPriceLimit(uint256 amountIn, bool zeroForOne)
|
||||
public
|
||||
returns (uint160)
|
||||
{
|
||||
return (
|
||||
SqrtPriceMath.getNextSqrtPriceFromInput(
|
||||
state.slot0().sqrtPriceX96,
|
||||
state.liquidity(),
|
||||
amountIn,
|
||||
zeroForOne
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function getParams(
|
||||
address tokenIn,
|
||||
address tokenOut,
|
||||
address recipient,
|
||||
uint24 fee,
|
||||
uint256 amountIn,
|
||||
uint256 amountOutMinimum,
|
||||
bool zeroForOne
|
||||
) public returns (ISwapRouter.ExactInputSingleParams memory params) {
|
||||
params = ISwapRouter.ExactInputSingleParams({
|
||||
tokenIn: tokenIn,
|
||||
tokenOut: tokenOut,
|
||||
fee: fee,
|
||||
recipient: recipient,
|
||||
deadline: block.timestamp + 1,
|
||||
amountIn: amountIn,
|
||||
amountOutMinimum: amountOutMinimum,
|
||||
sqrtPriceLimitX96: getPriceLimit(amountIn, zeroForOne)
|
||||
});
|
||||
}
|
||||
|
||||
function approveTransfer(
|
||||
address tokenIn,
|
||||
address sender,
|
||||
address recipient,
|
||||
uint256 amountIn
|
||||
) public {
|
||||
TransferHelper.safeTransferFrom(tokenIn, sender, recipient, amountIn);
|
||||
|
||||
TransferHelper.safeApprove(tokenIn, address(router), amountIn);
|
||||
}
|
||||
|
||||
function getSingleInput(ISwapRouter.ExactInputSingleParams memory params)
|
||||
public
|
||||
returns (uint256)
|
||||
{
|
||||
return (uint256(router.exactInputSingle(params)));
|
||||
}
|
||||
}
|
32
contracts/arbitrum/connectors/uniswap-sell-beta/main.sol
Normal file
32
contracts/arbitrum/connectors/uniswap-sell-beta/main.sol
Normal file
|
@ -0,0 +1,32 @@
|
|||
pragma solidity ^0.7.6;
|
||||
pragma abicoder v2;
|
||||
|
||||
import "./helpers.sol";
|
||||
|
||||
abstract contract uniswapSellBeta is Helpers {
|
||||
function sell(
|
||||
address tokenIn,
|
||||
address tokenOut,
|
||||
uint24 fee,
|
||||
uint256 amountIn,
|
||||
uint256 amountOutMinimum,
|
||||
bool zeroForOne
|
||||
) public returns (uint256 amountOut) {
|
||||
approveTransfer(tokenIn, msg.sender, address(this), amountIn);
|
||||
amountOut = getSingleInput(
|
||||
getParams(
|
||||
tokenIn,
|
||||
tokenOut,
|
||||
msg.sender,
|
||||
fee,
|
||||
amountIn,
|
||||
amountOutMinimum,
|
||||
zeroForOne
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract contract UniswapSellBetaArbitrum is uniswapSellBeta {
|
||||
string public constant name = "UniswapSample-v1";
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
pragma solidity ^0.7.6;
|
||||
pragma abicoder v2;
|
||||
|
||||
import "./interface.sol";
|
||||
import {SqrtPriceMath} from "./libraries/SqrtPriceMath.sol";
|
||||
import "./libraries/TransferHelper.sol";
|
||||
|
||||
abstract contract Helpers is ISwapRouter {
|
||||
ISwapRouter router =
|
||||
ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);
|
||||
|
||||
UniswapV3Pool state =
|
||||
UniswapV3Pool(0xCEda10b4d3bdE429DdA3A6daB87b38360313CBdB);
|
||||
|
||||
uint24 public constant poolFee = 3000;
|
||||
|
||||
function getPriceLimit(
|
||||
ISwapRouter.ExactInputSingleParams memory params,
|
||||
bool zeroForOne
|
||||
) public returns (uint160) {
|
||||
return (
|
||||
SqrtPriceMath.getNextSqrtPriceFromInput(
|
||||
state.slot0().sqrtPriceX96,
|
||||
state.liquidity(),
|
||||
params.amountIn,
|
||||
zeroForOne
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function approveTransfer(
|
||||
ISwapRouter.ExactInputSingleParams memory params,
|
||||
address sender,
|
||||
address recipient
|
||||
) public {
|
||||
TransferHelper.safeTransferFrom(
|
||||
params.tokenIn,
|
||||
sender,
|
||||
recipient,
|
||||
params.amountIn
|
||||
);
|
||||
|
||||
TransferHelper.safeApprove(
|
||||
params.tokenIn,
|
||||
address(router),
|
||||
params.amountIn
|
||||
);
|
||||
}
|
||||
|
||||
function getSingleInput(ISwapRouter.ExactInputSingleParams memory params)
|
||||
public
|
||||
returns (uint256)
|
||||
{
|
||||
return (uint256(router.exactInputSingle(params)));
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
pragma solidity ^0.7.6;
|
||||
pragma abicoder v2;
|
||||
|
||||
import "./helpers.sol";
|
||||
import "./interface.sol";
|
||||
|
||||
abstract contract uniswapSample is Helpers {
|
||||
function sell(
|
||||
ISwapRouter.ExactInputSingleParams memory params,
|
||||
bool zeroForOne
|
||||
) public returns (uint256 amountOut) {
|
||||
approveTransfer(params, msg.sender, address(this));
|
||||
|
||||
ISwapRouter.ExactInputSingleParams memory params1 = ISwapRouter
|
||||
.ExactInputSingleParams({
|
||||
tokenIn: params.tokenIn,
|
||||
tokenOut: params.tokenOut,
|
||||
fee: poolFee,
|
||||
recipient: address(this),
|
||||
deadline: block.timestamp + 1,
|
||||
amountIn: params.amountIn,
|
||||
amountOutMinimum: 0,
|
||||
sqrtPriceLimitX96: getPriceLimit(params, true)
|
||||
});
|
||||
|
||||
amountOut = getSingleInput(params1);
|
||||
}
|
||||
}
|
||||
|
||||
abstract contract UniswapArbitrum is uniswapSample {
|
||||
string public constant name = "UniswapSample-v1";
|
||||
}
|
Loading…
Reference in New Issue
Block a user