From d43f0a228a2068449259d7ee8e465dc51e14cf64 Mon Sep 17 00:00:00 2001 From: x Date: Thu, 23 Dec 2021 14:28:25 -0600 Subject: [PATCH] interfaces and skeleton done --- contracts/mainnet/connectors/lixir/events.sol | 22 +- .../mainnet/connectors/lixir/helpers.sol | 45 ++++ .../mainnet/connectors/lixir/interface.sol | 217 +++++++++++++++++- contracts/mainnet/connectors/lixir/main.sol | 36 ++- 4 files changed, 296 insertions(+), 24 deletions(-) diff --git a/contracts/mainnet/connectors/lixir/events.sol b/contracts/mainnet/connectors/lixir/events.sol index 6726ee7e..f6c3b2d7 100644 --- a/contracts/mainnet/connectors/lixir/events.sol +++ b/contracts/mainnet/connectors/lixir/events.sol @@ -2,18 +2,20 @@ pragma solidity ^0.7.0; contract Events { event LogDeposit( - uint256 indexed tokenId, - uint256 liquidity, - uint256 amtA, - uint256 amtB, - int24 tickLower, - int24 tickUpper + address indexed depositor, + address indexed recipient, + uint256 shares, + uint256 amount0In, + uint256 amount1In, + uint256 total0, + uint256 total1 ); event LogWithdraw( - uint256 indexed tokenId, - uint256 liquidity, - uint256 amountA, - uint256 amountB + uint256 indexed withdrawer, + uint256 indexed recipient, + uint256 shares, + uint256 amount0Out, + uint256 amount1Out, ); } \ No newline at end of file diff --git a/contracts/mainnet/connectors/lixir/helpers.sol b/contracts/mainnet/connectors/lixir/helpers.sol index 39aedd0b..9f211cc1 100644 --- a/contracts/mainnet/connectors/lixir/helpers.sol +++ b/contracts/mainnet/connectors/lixir/helpers.sol @@ -7,4 +7,49 @@ import {Basic} from "../../common/basic.sol"; import "./interface.sol"; abstract contract Helpers is DSMath, Basic { + ILixirFactory constant factory = + ILixirFactory(0xfbc744df515f8962c18e79795f469d57ec460691); + + function _deposit( + uint256 amount0Desired, + uint256 amount1Desired, + uint256 amount0Min, + uint256 amount1Min, + address recipient, + uint256 deadline + ) returns ( + uint256 shares, + uint256 amount0In, + uint256 amount1In + ) { + + } + + + function _depositETH( + uint256 amountDesired, + uint256 amountEthMin, + uint256 amountMin, + address recipient, + uint256 deadline + ) returns ( + uint256 shares, + uint256 amountEthIn, + uint256 amountIn + ) { + + } + + + function _withdraw( + + ) returns () { + + } + + function _withdrawETH( + + ) returns () { + + } } diff --git a/contracts/mainnet/connectors/lixir/interface.sol b/contracts/mainnet/connectors/lixir/interface.sol index 20c82549..7964b353 100644 --- a/contracts/mainnet/connectors/lixir/interface.sol +++ b/contracts/mainnet/connectors/lixir/interface.sol @@ -1,5 +1,218 @@ pragma solidity ^0.7.6; -interface anInterface { - function aFunction() external; +import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol'; +import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; + +interface IERC20Permit { + /** + * @dev Sets `value` as the allowance of `spender` over `owner`'s tokens, + * given `owner`'s signed approval. + * + * IMPORTANT: The same issues {IERC20-approve} has related to transaction + * ordering also apply here. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `deadline` must be a timestamp in the future. + * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` + * over the EIP712-formatted function arguments. + * - the signature must use ``owner``'s current nonce (see {nonces}). + * + * For more information on the signature format, see the + * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP + * section]. + */ + function permit( + address owner, + address spender, + uint256 value, + uint256 deadline, + uint8 v, + bytes32 r, + bytes32 s + ) external; + + /** + * @dev Returns the current nonce for `owner`. This value must be + * included whenever a signature is generated for {permit}. + * + * Every successful call to {permit} increases ``owner``'s nonce by one. This + * prevents a signature from being used multiple times. + */ + function nonces(address owner) external view returns (uint256); + + /** + * @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}. + */ + // solhint-disable-next-line func-name-mixedcase + function DOMAIN_SEPARATOR() external view returns (bytes32); } + +interface ILixirVaultToken is IERC20, IERC20Permit { +} + +interface ILixirVault is ILixirVaultToken { + function initialize( + string memory name, + string memory symbol, + address _token0, + address _token1, + address _strategist, + address _keeper, + address _strategy + ) external; + + function token0() external view returns (IERC20); + + function token1() external view returns (IERC20); + + function activeFee() external view returns (uint24); + + function activePool() external view returns (IUniswapV3Pool); + + function performanceFee() external view returns (uint24); + + function strategist() external view returns (address); + + function strategy() external view returns (address); + + function keeper() external view returns (address); + + function setKeeper(address _keeper) external; + + function setStrategist(address _strategist) external; + + function setStrategy(address _strategy) external; + + function setPerformanceFee(uint24 newFee) external; + + function mainPosition() + external + view + returns (int24 tickLower, int24 tickUpper); + + function rangePosition() + external + view + returns (int24 tickLower, int24 tickUpper); + + function rebalance( + int24 mainTickLower, + int24 mainTickUpper, + int24 rangeTickLower0, + int24 rangeTickUpper0, + int24 rangeTickLower1, + int24 rangeTickUpper1, + uint24 fee + ) external; + + function withdraw( + uint256 shares, + uint256 amount0Min, + uint256 amount1Min, + address receiver, + uint256 deadline + ) external returns (uint256 amount0Out, uint256 amount1Out); + + function withdrawFrom( + address withdrawer, + uint256 shares, + uint256 amount0Min, + uint256 amount1Min, + address recipient, + uint256 deadline + ) external returns (uint256 amount0Out, uint256 amount1Out); + + function deposit( + uint256 amount0Desired, + uint256 amount1Desired, + uint256 amount0Min, + uint256 amount1Min, + address recipient, + uint256 deadline + ) + external + returns ( + uint256 shares, + uint256 amount0, + uint256 amount1 + ); + + function calculateTotals() + external + view + returns ( + uint256 total0, + uint256 total1, + uint128 mL, + uint128 rL + ); + + function calculateTotalsFromTick(int24 virtualTick) + external + view + returns ( + uint256 total0, + uint256 total1, + uint128 mL, + uint128 rL + ); +} + +interface ILixirVaultETH is ILixirVault { + + enum TOKEN {ZERO, ONE} + + function WETH_TOKEN() external view returns (TOKEN); + + function depositETH( + uint256 amountDesired, + uint256 amountEthMin, + uint256 amountMin, + address recipient, + uint256 deadline + ) + external + payable + returns ( + uint256 shares, + uint256 amountEthIn, + uint256 amountIn + ); + + function withdrawETHFrom( + address withdrawer, + uint256 shares, + uint256 amountEthMin, + uint256 amountMin, + address payable recipient, + uint256 deadline + ) external returns (uint256 amountEthOut, uint256 amountOut); + + function withdrawETH( + uint256 shares, + uint256 amountEthMin, + uint256 amountMin, + address payable recipient, + uint256 deadline + ) external returns (uint256 amountEthOut, uint256 amountOut); + + receive() external payable; +} + +interface ILixirFactory { // is LixirBase // don't think we need this + function vault( + address token0, + address token1, + uint256 index + ) public view returns (address); + + function vaultsLengthForPair(address token0, address token1) + external + view + returns (uint256); +} + diff --git a/contracts/mainnet/connectors/lixir/main.sol b/contracts/mainnet/connectors/lixir/main.sol index cf53d332..355aa6e5 100644 --- a/contracts/mainnet/connectors/lixir/main.sol +++ b/contracts/mainnet/connectors/lixir/main.sol @@ -14,17 +14,22 @@ abstract contract LixirResolver is Helpers, Events { /** * @dev Add liqudity to the vault * @notice Mint Lixir Vault Tokens - * @param vault vault address + * @param token0 token0 address + * @param token1 token1 address * @param amount0 amount of tokenA * @param amount1 amount of tokenB * @param getIds ID to retrieve amtA * @param setId ID stores the amount of LP token */ function desosit( - address vault, - uint256 amount0, - uint256 amount1, - // split amount0/1 into amount0/1Desired and amount0/1Min? + address token0, + address token1, + uint256 amount0Desired, + uint256 amount1Desired, + uint256 amount0Min, + uint256 amount1Min, + address recipient, + uint256 deadline, uint256[] calldata getIds, uint256 setId ) @@ -32,7 +37,10 @@ abstract contract LixirResolver is Helpers, Events { payable returns (string memory _eventName, bytes memory _eventParam) { + // grab the correct vault from the factory + // check if one of these is ETH, you have to use depositETH, not deposit + // MintParams memory params; // { // params = MintParams( @@ -67,18 +75,22 @@ abstract contract LixirResolver is Helpers, Events { /** * @dev Decrease Liquidity * @notice Withdraw Liquidity from Lixir Vault - * @param vault Lixir Vault address - * @param liquidity LP Token amount. - * @param amountAMin Min amount of tokenA. - * @param amountBMin Min amount of tokenB. + * @param vault Lixir vault address + * @param withdrawer the DSA account + * @param shares the amount of Lixir Vault Tokens to remove + * @param amount0Min Min amount of token0. + * @param amount1Min Min amount of token1. * @param getId ID to retrieve LP token amounts * @param setIds stores the amount of output tokens */ function withdraw( address vault, - uint256 liquidity, - uint256 amountAMin, - uint256 amountBMin, + address withdrawer, + uint256 shares, + uint256 amount0Min, + uint256 amount1Min, + address recipient, + uint256 deadline, uint256 getId, uint256[] calldata setIds )