Skip to content

Commit f1d2baf

Browse files
pblivin0xckoopmann
andauthored
feat(extension): Add AaveMigrationExtension (#162)
* begin aave migration extension base branch * Add AaveMigrationExtension and ETH2x Migration Tests (#161) * Reconfigure UniV3 LP Parmeters and Add BTC2x Migration Tests (#164) * add internal function for liquidity mint * remove unnecessary check * update tokenId natspec * remove receive() * refactor token sweep --------- Co-authored-by: ckoopmann <[email protected]>
1 parent f780e9c commit f1d2baf

File tree

10 files changed

+1884
-11
lines changed

10 files changed

+1884
-11
lines changed

contracts/adapters/AaveMigrationExtension.sol

Lines changed: 632 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: AGPL-3.0
2+
pragma solidity 0.6.10;
3+
4+
import {IPoolAddressesProvider} from "./IPoolAddressesProvider.sol";
5+
import {IPool} from "./IPool.sol";
6+
7+
/**
8+
* @title IFlashLoanSimpleReceiver
9+
* @author Aave
10+
* @notice Defines the basic interface of a flashloan-receiver contract.
11+
* @dev Implement this interface to develop a flashloan-compatible flashLoanReceiver contract
12+
*/
13+
interface IFlashLoanSimpleReceiver {
14+
/**
15+
* @notice Executes an operation after receiving the flash-borrowed asset
16+
* @dev Ensure that the contract can return the debt + premium, e.g., has
17+
* enough funds to repay and has approved the Pool to pull the total amount
18+
* @param asset The address of the flash-borrowed asset
19+
* @param amount The amount of the flash-borrowed asset
20+
* @param premium The fee of the flash-borrowed asset
21+
* @param initiator The address of the flashloan initiator
22+
* @param params The byte-encoded params passed when initiating the flashloan
23+
* @return True if the execution of the operation succeeds, false otherwise
24+
*/
25+
function executeOperation(
26+
address asset,
27+
uint256 amount,
28+
uint256 premium,
29+
address initiator,
30+
bytes calldata params
31+
) external returns (bool);
32+
33+
function ADDRESSES_PROVIDER() external view returns (IPoolAddressesProvider);
34+
35+
function POOL() external view returns (IPool);
36+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity 0.6.10;
3+
pragma experimental ABIEncoderV2;
4+
5+
/// @title Non-fungible token for positions
6+
/// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred
7+
/// and authorized.
8+
/// https://github.com/Uniswap/v3-periphery/blob/main/contracts/interfaces/INonfungiblePositionManager.sol
9+
interface INonfungiblePositionManager {
10+
/// @notice Returns the position information associated with a given token ID.
11+
/// @dev Throws if the token ID is not valid.
12+
/// @param tokenId The ID of the token that represents the position
13+
/// @return nonce The nonce for permits
14+
/// @return operator The address that is approved for spending
15+
/// @return token0 The address of the token0 for a specific pool
16+
/// @return token1 The address of the token1 for a specific pool
17+
/// @return fee The fee associated with the pool
18+
/// @return tickLower The lower end of the tick range for the position
19+
/// @return tickUpper The higher end of the tick range for the position
20+
/// @return liquidity The liquidity of the position
21+
/// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
22+
/// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
23+
/// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
24+
/// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
25+
function positions(uint256 tokenId)
26+
external
27+
view
28+
returns (
29+
uint96 nonce,
30+
address operator,
31+
address token0,
32+
address token1,
33+
uint24 fee,
34+
int24 tickLower,
35+
int24 tickUpper,
36+
uint128 liquidity,
37+
uint256 feeGrowthInside0LastX128,
38+
uint256 feeGrowthInside1LastX128,
39+
uint128 tokensOwed0,
40+
uint128 tokensOwed1
41+
);
42+
43+
struct MintParams {
44+
address token0;
45+
address token1;
46+
uint24 fee;
47+
int24 tickLower;
48+
int24 tickUpper;
49+
uint256 amount0Desired;
50+
uint256 amount1Desired;
51+
uint256 amount0Min;
52+
uint256 amount1Min;
53+
address recipient;
54+
uint256 deadline;
55+
}
56+
57+
/// @notice Creates a new position wrapped in a NFT
58+
/// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
59+
/// a method does not exist, i.e. the pool is assumed to be initialized.
60+
/// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
61+
/// @return tokenId The ID of the token that represents the minted position
62+
/// @return liquidity The amount of liquidity for this position
63+
/// @return amount0 The amount of token0
64+
/// @return amount1 The amount of token1
65+
function mint(MintParams calldata params)
66+
external
67+
payable
68+
returns (
69+
uint256 tokenId,
70+
uint128 liquidity,
71+
uint256 amount0,
72+
uint256 amount1
73+
);
74+
75+
struct IncreaseLiquidityParams {
76+
uint256 tokenId;
77+
uint256 amount0Desired;
78+
uint256 amount1Desired;
79+
uint256 amount0Min;
80+
uint256 amount1Min;
81+
uint256 deadline;
82+
}
83+
84+
/// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
85+
/// @param params tokenId The ID of the token for which liquidity is being increased,
86+
/// amount0Desired The desired amount of token0 to be spent,
87+
/// amount1Desired The desired amount of token1 to be spent,
88+
/// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
89+
/// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
90+
/// deadline The time by which the transaction must be included to effect the change
91+
/// @return liquidity The new liquidity amount as a result of the increase
92+
/// @return amount0 The amount of token0 to acheive resulting liquidity
93+
/// @return amount1 The amount of token1 to acheive resulting liquidity
94+
function increaseLiquidity(IncreaseLiquidityParams calldata params)
95+
external
96+
payable
97+
returns (
98+
uint128 liquidity,
99+
uint256 amount0,
100+
uint256 amount1
101+
);
102+
103+
struct DecreaseLiquidityParams {
104+
uint256 tokenId;
105+
uint128 liquidity;
106+
uint256 amount0Min;
107+
uint256 amount1Min;
108+
uint256 deadline;
109+
}
110+
111+
/// @notice Decreases the amount of liquidity in a position and accounts it to the position
112+
/// @param params tokenId The ID of the token for which liquidity is being decreased,
113+
/// amount The amount by which liquidity will be decreased,
114+
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
115+
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
116+
/// deadline The time by which the transaction must be included to effect the change
117+
/// @return amount0 The amount of token0 accounted to the position's tokens owed
118+
/// @return amount1 The amount of token1 accounted to the position's tokens owed
119+
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
120+
external
121+
payable
122+
returns (uint256 amount0, uint256 amount1);
123+
124+
struct CollectParams {
125+
uint256 tokenId;
126+
address recipient;
127+
uint128 amount0Max;
128+
uint128 amount1Max;
129+
}
130+
131+
/// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
132+
/// @param params tokenId The ID of the NFT for which tokens are being collected,
133+
/// recipient The account that should receive the tokens,
134+
/// amount0Max The maximum amount of token0 to collect,
135+
/// amount1Max The maximum amount of token1 to collect
136+
/// @return amount0 The amount of fees collected in token0
137+
/// @return amount1 The amount of fees collected in token1
138+
function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
139+
140+
/// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
141+
/// must be collected first.
142+
/// @param tokenId The ID of the token that is being burned
143+
function burn(uint256 tokenId) external payable;
144+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity 0.6.10;
3+
pragma experimental ABIEncoderV2;
4+
5+
/// @title Permissionless pool actions
6+
/// @notice Contains pool methods that can be called by anyone
7+
/// https://github.com/Uniswap/v3-core/blob/main/contracts/interfaces/pool/IUniswapV3PoolActions.sol
8+
interface IUniswapV3Pool {
9+
/// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
10+
/// when accessed externally.
11+
/// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
12+
/// tick The current tick of the pool, i.e. according to the last tick transition that was run.
13+
/// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
14+
/// boundary.
15+
/// observationIndex The index of the last oracle observation that was written,
16+
/// observationCardinality The current maximum number of observations stored in the pool,
17+
/// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
18+
/// feeProtocol The protocol fee for both tokens of the pool.
19+
/// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
20+
/// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
21+
/// unlocked Whether the pool is currently locked to reentrancy
22+
function slot0()
23+
external
24+
view
25+
returns (
26+
uint160 sqrtPriceX96,
27+
int24 tick,
28+
uint16 observationIndex,
29+
uint16 observationCardinality,
30+
uint16 observationCardinalityNext,
31+
uint8 feeProtocol,
32+
bool unlocked
33+
);
34+
35+
/// @notice Sets the initial price for the pool
36+
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
37+
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
38+
function initialize(uint160 sqrtPriceX96) external;
39+
40+
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
41+
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
42+
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
43+
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
44+
/// @param recipient The address for which the liquidity will be created
45+
/// @param tickLower The lower tick of the position in which to add liquidity
46+
/// @param tickUpper The upper tick of the position in which to add liquidity
47+
/// @param amount The amount of liquidity to mint
48+
/// @param data Any data that should be passed through to the callback
49+
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
50+
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
51+
function mint(
52+
address recipient,
53+
int24 tickLower,
54+
int24 tickUpper,
55+
uint128 amount,
56+
bytes calldata data
57+
) external returns (uint256 amount0, uint256 amount1);
58+
59+
/// @notice Collects tokens owed to a position
60+
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
61+
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
62+
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
63+
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
64+
/// @param recipient The address which should receive the fees collected
65+
/// @param tickLower The lower tick of the position for which to collect fees
66+
/// @param tickUpper The upper tick of the position for which to collect fees
67+
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
68+
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
69+
/// @return amount0 The amount of fees collected in token0
70+
/// @return amount1 The amount of fees collected in token1
71+
function collect(
72+
address recipient,
73+
int24 tickLower,
74+
int24 tickUpper,
75+
uint128 amount0Requested,
76+
uint128 amount1Requested
77+
) external returns (uint128 amount0, uint128 amount1);
78+
79+
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
80+
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
81+
/// @dev Fees must be collected separately via a call to #collect
82+
/// @param tickLower The lower tick of the position for which to burn liquidity
83+
/// @param tickUpper The upper tick of the position for which to burn liquidity
84+
/// @param amount How much liquidity to burn
85+
/// @return amount0 The amount of token0 sent to the recipient
86+
/// @return amount1 The amount of token1 sent to the recipient
87+
function burn(
88+
int24 tickLower,
89+
int24 tickUpper,
90+
uint128 amount
91+
) external returns (uint256 amount0, uint256 amount1);
92+
93+
/// @notice Swap token0 for token1, or token1 for token0
94+
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
95+
/// @param recipient The address to receive the output of the swap
96+
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
97+
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
98+
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
99+
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
100+
/// @param data Any data to be passed through to the callback
101+
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
102+
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
103+
function swap(
104+
address recipient,
105+
bool zeroForOne,
106+
int256 amountSpecified,
107+
uint160 sqrtPriceLimitX96,
108+
bytes calldata data
109+
) external returns (int256 amount0, int256 amount1);
110+
111+
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
112+
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
113+
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
114+
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
115+
/// @param recipient The address which will receive the token0 and token1 amounts
116+
/// @param amount0 The amount of token0 to send
117+
/// @param amount1 The amount of token1 to send
118+
/// @param data Any data to be passed through to the callback
119+
function flash(
120+
address recipient,
121+
uint256 amount0,
122+
uint256 amount1,
123+
bytes calldata data
124+
) external;
125+
126+
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
127+
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
128+
/// the input observationCardinalityNext.
129+
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
130+
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
131+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: AGPL-3.0
2+
pragma solidity 0.6.10;
3+
4+
import {IFlashLoanSimpleReceiver} from "../interfaces/IFlashLoanSimpleReceiver.sol";
5+
import {IPoolAddressesProvider} from "../interfaces/IPoolAddressesProvider.sol";
6+
import {IPool} from "../interfaces/IPool.sol";
7+
8+
/**
9+
* @title FlashLoanSimpleReceiverBase
10+
* @author Aave
11+
* @notice Base contract to develop a flashloan-receiver contract.
12+
*/
13+
abstract contract FlashLoanSimpleReceiverBase is IFlashLoanSimpleReceiver {
14+
IPoolAddressesProvider public immutable override ADDRESSES_PROVIDER;
15+
IPool public immutable override POOL;
16+
17+
constructor(IPoolAddressesProvider provider) public {
18+
ADDRESSES_PROVIDER = provider;
19+
POOL = IPool(provider.getPool());
20+
}
21+
}

0 commit comments

Comments
 (0)