mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Uniswap v3 erc20 pool basic setup done
This commit is contained in:
parent
eaef5a43a7
commit
5656c94717
4
contracts/mainnet/connectors/uniswap_v3_erc20/events.sol
Normal file
4
contracts/mainnet/connectors/uniswap_v3_erc20/events.sol
Normal file
|
@ -0,0 +1,4 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
}
|
10
contracts/mainnet/connectors/uniswap_v3_erc20/helpers.sol
Normal file
10
contracts/mainnet/connectors/uniswap_v3_erc20/helpers.sol
Normal file
|
@ -0,0 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import { ListInterface } from "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
|
||||
}
|
53
contracts/mainnet/connectors/uniswap_v3_erc20/interface.sol
Normal file
53
contracts/mainnet/connectors/uniswap_v3_erc20/interface.sol
Normal file
|
@ -0,0 +1,53 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
interface ERC20WrapperInterface {
|
||||
|
||||
function token0() external view returns (IERC20);
|
||||
|
||||
function token1() external view returns (IERC20);
|
||||
|
||||
function mint(
|
||||
uint256 amount0Max,
|
||||
uint256 amount1Max,
|
||||
address receiver
|
||||
) external
|
||||
returns (
|
||||
uint256 amount0,
|
||||
uint256 amount1,
|
||||
uint256 mintAmount
|
||||
);
|
||||
|
||||
function burn(
|
||||
uint256 _burnAmount,
|
||||
address _receiver
|
||||
) external
|
||||
returns (
|
||||
uint256 amount0,
|
||||
uint256 amount1,
|
||||
uint128 liquidityBurned
|
||||
);
|
||||
|
||||
function getMintAmounts(
|
||||
uint256 amount0Max,
|
||||
uint256 amount1Max
|
||||
) external view
|
||||
returns (
|
||||
uint256 amount0,
|
||||
uint256 amount1,
|
||||
uint256 mintAmount
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
interface TokenInterface {
|
||||
function approve(address, uint256) external;
|
||||
function transfer(address, uint) external;
|
||||
function transferFrom(address, address, uint) external;
|
||||
function deposit() external payable;
|
||||
function withdraw(uint) external;
|
||||
function balanceOf(address) external view returns (uint);
|
||||
function decimals() external view returns (uint);
|
||||
}
|
86
contracts/mainnet/connectors/uniswap_v3_erc20/main.sol
Normal file
86
contracts/mainnet/connectors/uniswap_v3_erc20/main.sol
Normal file
|
@ -0,0 +1,86 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Authority.
|
||||
* @dev Manage Authorities to DSA.
|
||||
*/
|
||||
|
||||
import { ERC20WrapperInterface, IERC20, TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
abstract contract AuthorityResolver is Events, Helpers {
|
||||
|
||||
function deposit(
|
||||
address pool,
|
||||
uint256 amt0Max,
|
||||
uint256 amt0Min,
|
||||
uint256 amt1Max,
|
||||
uint256 amt1Min,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
|
||||
ERC20WrapperInterface poolContract = ERC20WrapperInterface(pool);
|
||||
|
||||
(uint256 amount0In, uint256 amount1In, ) = poolContract.getMintAmounts(amt0Max, amt1Max);
|
||||
|
||||
require(
|
||||
amount0In >= amount0Min && amount1In >= amount1Min,
|
||||
"below min amounts"
|
||||
);
|
||||
|
||||
if (amount0In > 0) {
|
||||
IERC20 _token0 = pool.token0();
|
||||
convertEthToWeth(address(_token0) == wethAddr, TokenInterface(address(_token0)), amount0In);
|
||||
_token0.safeAllowance(address(pool), amount0In);
|
||||
}
|
||||
if (amount1In > 0) {
|
||||
IERC20 _token1 = pool.token0();
|
||||
convertEthToWeth(address(_token1) == wethAddr, TokenInterface(address(_token1)), amount1In);
|
||||
_token1.safeAllowance(address(pool), amount1In);
|
||||
}
|
||||
|
||||
(uint amount0, uint amount1, uint mintAmount) = poolContract.mint(amount0In, amount1In, address(this));
|
||||
|
||||
require(amount0 == amount0In && amount1 == amount1In, "unexpected amounts deposited");
|
||||
|
||||
// TODO: Add event
|
||||
}
|
||||
|
||||
function withdraw(
|
||||
address pool,
|
||||
uint256 liqAmt,
|
||||
uint256 minAmtA,
|
||||
uint256 minAmtB,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
|
||||
ERC20WrapperInterface poolContract = ERC20WrapperInterface(pool);
|
||||
|
||||
(uint amount0, uint amount1, uint128 liquidityBurned) = poolContract.burn(liqAmt, address(this));
|
||||
|
||||
if (amount0 > 0) {
|
||||
IERC20 _token0 = poolContract.token0();
|
||||
convertWethToEth(address(_token0) == wethAddr, TokenInterface(address(_token0)), _amt);
|
||||
}
|
||||
|
||||
if (amount1 > 0) {
|
||||
IERC20 _token1 = poolContract.token0();
|
||||
convertWethToEth(address(_token1) == wethAddr, TokenInterface(address(_token1)), _amt);
|
||||
}
|
||||
|
||||
require(amount0 >= minAmtA && amount1 >= minAmtB, "received below minimum");
|
||||
|
||||
// TODO: Add event
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
contract ConnectV2Auth is AuthorityResolver {
|
||||
|
||||
string public constant name = "Uniswap-v3-erc20";
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user