Skip to content

Commit

Permalink
feat: uniswapV3LiquidityPosition (#717)
Browse files Browse the repository at this point in the history
* feat:  add UniswapV3LiquidityPosition lib, parser, and helper contracts

* chore: add uniswap peripheral contracts and openzeppelin solc 7 npm dependencies

* refactor: copy necessary interfaces for use in this external position only, due to solc 7

* chore: add deployment scripts

* chore: add helper utils

* test: add test suite

* chore: update codegen to handle contract namespace clashes

Co-authored-by: Sean Casey <[email protected]>
  • Loading branch information
buendiadas and SeanJCasey authored Nov 10, 2021
1 parent 016e3ad commit 702818b
Show file tree
Hide file tree
Showing 30 changed files with 2,392 additions and 94 deletions.
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "solhint:recommended",
"rules": {
"compiler-version": ["error", "0.6.12"],
"compiler-version": ["error", "0.6.12 || 0.7.6"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"no-empty-blocks": "off",
"not-rely-on-time": "off",
"avoid-low-level-calls": "off",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-3.0

/*
This file is part of the Enzyme Protocol.
(c) Enzyme Council <[email protected]>
For the full license information, please view the LICENSE
file that was distributed with this source code.
*/

pragma solidity 0.7.6;

/// @title UniswapV3LiquidityPositionLibBase1 Contract
/// @author Enzyme Council <[email protected]>
/// @notice A persistent contract containing all required storage variables and
/// required functions for a UniswapV3LiquidityPositionLib implementation
/// @dev DO NOT EDIT CONTRACT. If new events or storage are necessary, they should be added to
/// a numbered UniswapV3LiquidityPositionLibBaseXXX that inherits the previous base.
/// e.g., `UniswapV3LiquidityPositionLibBase2 is UniswapV3LiquidityPositionLibBase1`
abstract contract UniswapV3LiquidityPositionLibBase1 {
event Initialized(address token0, address token1);

event NFTPositionAdded(uint256 indexed tokenId);

event NFTPositionRemoved(uint256 indexed tokenId);

uint256[] internal nftIds;
// token0 and token1 are assigned deterministically by sort order,
// so will be the same for all fees
address internal token0;
address internal token1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: GPL-3.0

/*
This file is part of the Enzyme Protocol.
(c) Enzyme Council <[email protected]>
For the full license information, please view the LICENSE
file that was distributed with this source code.
*/

pragma solidity 0.7.6;

/// @title UniswapV3LiquidityPositionDataDecoder Contract
/// @author Enzyme Council <[email protected]>
/// @notice Abstract contract containing data decodings for UniswapV3LiquidityPosition payloads
abstract contract UniswapV3LiquidityPositionDataDecoder {
/// @dev Helper to decode args used during the AddLiquidity action
function __decodeAddLiquidityActionArgs(bytes memory _actionArgs)
internal
pure
returns (
uint256 nftId_,
uint256 amount0Desired_,
uint256 amount1Desired_,
uint256 amount0Min_,
uint256 amount1Min_
)
{
return abi.decode(_actionArgs, (uint256, uint256, uint256, uint256, uint256));
}

/// @dev Helper to decode args used during the Collect action
function __decodeCollectActionArgs(bytes memory _actionArgs)
internal
pure
returns (uint256 nftId_)
{
return abi.decode(_actionArgs, (uint256));
}

/// @dev Helper to decode args used during init()
function __decodeInitArgs(bytes memory _initArgs)
internal
pure
returns (address token0_, address token1_)
{
return abi.decode(_initArgs, (address, address));
}

/// @dev Helper to decode args used during the Mint action
function __decodeMintActionArgs(bytes memory _actionArgs)
internal
pure
returns (
uint24 fee_,
int24 tickLower_,
int24 tickUpper_,
uint256 amount0Desired_,
uint256 amount1Desired_,
uint256 amount0Min_,
uint256 amount1Min_
)
{
return abi.decode(_actionArgs, (uint24, int24, int24, uint256, uint256, uint256, uint256));
}

/// @dev Helper to decode args used during the Purge action
function __decodePurgeActionArgs(bytes memory _actionArgs)
internal
pure
returns (
uint256 nftId_,
uint128 liquidity_,
uint256 amount0Min_,
uint256 amount1Min_
)
{
return abi.decode(_actionArgs, (uint256, uint128, uint256, uint256));
}

/// @dev Helper to decode args used during the RemoveLiquidity action
function __decodeRemoveLiquidityActionArgs(bytes memory _actionArgs)
internal
pure
returns (
uint256 nftId_,
uint128 liquidity_,
uint256 amount0Min_,
uint256 amount1Min_
)
{
return abi.decode(_actionArgs, (uint256, uint128, uint256, uint256));
}
}
Loading

0 comments on commit 702818b

Please sign in to comment.