Skip to content

Commit

Permalink
publish: package v0.1.2
Browse files Browse the repository at this point in the history
* chore: add natspec

* chore: remove manager balance check on callback

* chore: remove vault version
  • Loading branch information
Gevarist committed Dec 2, 2022
1 parent e49c5da commit 264f4b3
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 19 deletions.
32 changes: 32 additions & 0 deletions contracts/ArrakisV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import {Position} from "./libraries/Position.sol";
import {Pool} from "./libraries/Pool.sol";
import {Underlying as UnderlyingHelper} from "./libraries/Underlying.sol";

/// @title Arrakis vault version 2
/// @notice Smart contract managing liquidity providing strategy using
/// multiple LP positions on multiple uniswap v3 pools.
/// @author Arrakis Finance
/// @dev DO NOT ADD STATE VARIABLES - APPEND THEM TO ArrakisV2Storage
contract ArrakisV2 is IUniswapV3MintCallback, ArrakisV2Storage {
using SafeERC20 for IERC20;
Expand All @@ -46,6 +50,15 @@ contract ArrakisV2 is IUniswapV3MintCallback, ArrakisV2Storage {
_uniswapV3CallBack(amount0Owed_, amount1Owed_);
}

/// @notice mint Arrakis V2 tokens by participating to the
/// vault strategy
/// @param mintAmount_ represent the amount of Arrakis V2 tokens
/// we want to mint.
/// @param receiver_ address that will receive Arrakis V2 tokens.
/// @return amount0 amount of token0 needed to mint mintAmount_
/// vault tokens.
/// @return amount1 amount of token1 needed to mint mintAmount_
/// vault tokens.
// solhint-disable-next-line function-max-lines
function mint(uint256 mintAmount_, address receiver_)
external
Expand Down Expand Up @@ -119,6 +132,14 @@ contract ArrakisV2 is IUniswapV3MintCallback, ArrakisV2Storage {
emit LogMint(receiver_, mintAmount_, amount0, amount1);
}

/// @notice burn Arrakis V2 tokens functions
/// @param burns_ ranges where burns lps and collect tokens.
/// @param burnAmount_ amount of vault token to burn.
/// @param receiver_ address of tokens receiver.
/// @return amount0 amount of token0 associated to burnAmount of
/// vault tokens, and returned to receiver.
/// @return amount1 amount of token1 associated to burnAmount of
/// vault tokens, and returned to receiver.
// solhint-disable-next-line function-max-lines, code-complexity
function burn(
BurnLiquidity[] calldata burns_,
Expand Down Expand Up @@ -246,6 +267,15 @@ contract ArrakisV2 is IUniswapV3MintCallback, ArrakisV2Storage {
emit LogBurn(receiver_, burnAmount_, amount0, amount1);
}

/// @notice rebalance vault position on uniswap v3
/// @param rangesToAdd_ list of ranges whiteslisted to provide
/// liquidity on these ranges.
/// @param rebalanceParams_ rebalance params, containing ranges where
/// we need to collect tokens and ranges where we need to mint tokens.
/// Also contain swap payload to changes token0/token1 proportion.
/// @param rangesToRemove_ list of ranges to unwhiteslist, will check if
/// they still contain liquidity on these ranges.
/// @dev only Manager contract can call this contract.
// solhint-disable-next-line function-max-lines
function rebalance(
Range[] calldata rangesToAdd_,
Expand Down Expand Up @@ -294,6 +324,8 @@ contract ArrakisV2 is IUniswapV3MintCallback, ArrakisV2Storage {
}
}

/// @notice will send managers fees to manager
/// @dev anyone can call this function.
function withdrawManagerBalance() external {
uint256 amount0 = managerBalance0;
uint256 amount1 = managerBalance1;
Expand Down
1 change: 1 addition & 0 deletions contracts/ArrakisV2Beacon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
UpgradeableBeacon
} from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";

/// @title ArrakisV2Beacon sm containing vault implementation.
contract ArrakisV2Beacon is UpgradeableBeacon {
// solhint-disable-next-line no-empty-blocks
constructor(address implementation_, address owner_)
Expand Down
15 changes: 15 additions & 0 deletions contracts/ArrakisV2Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ import {
} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {_getTokenOrder, _append} from "./functions/FArrakisV2Factory.sol";

/// @title ArrakisV2Factory factory for creating vault instances.
contract ArrakisV2Factory is ArrakisV2FactoryStorage {
using EnumerableSet for EnumerableSet.AddressSet;

constructor(IArrakisV2Beacon arrakisV2Beacon_)
ArrakisV2FactoryStorage(arrakisV2Beacon_)
{} // solhint-disable-line no-empty-blocks

/// @notice will deploy an instance of Vault using Beacon or
/// transparentProxy
/// @param params_ contains all data needed to create an instance of
/// ArrakisV2 vault.
/// @param isBeacon_ boolean, if true the instance will be a beacon proxy
/// or a transparent proxy.
/// @return vault the address of the Arrakis V2 vault instance created.
function deployVault(InitializePayload calldata params_, bool isBeacon_)
external
returns (address vault)
Expand All @@ -38,6 +46,11 @@ contract ArrakisV2Factory is ArrakisV2FactoryStorage {

// #region public external view functions.

/// @notice get Arrakis V2 vault token name for
/// two corresponding tokens.
/// @param token0_ address of the first token.
/// @param token1_ address of the second token.
/// @return name name of the arrakis V2 vault.
function getTokenName(address token0_, address token1_)
external
view
Expand All @@ -54,6 +67,8 @@ contract ArrakisV2Factory is ArrakisV2FactoryStorage {
return _vaults.length();
}

/// @notice get a list of vaults created by this factory
/// @return vaults list of all created vaults.
function vaults() public view returns (address[] memory) {
uint256 length = numVaults();
address[] memory vs = new address[](length);
Expand Down
31 changes: 31 additions & 0 deletions contracts/ArrakisV2Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ contract ArrakisV2Helper is IArrakisV2Helper {
factory = factory_;
}

/// @notice get underlying, fees and left over separatly.
/// @param vault_ Arrakis V2 vault to get underlying info about.
/// @return underlying struct containing underlying amounts of
/// token0 and token1, fees of token0 and token1, finally left over
/// on vault of token0 and token1.
function totalUnderlyingWithFeesAndLeftOver(IArrakisV2 vault_)
external
view
Expand Down Expand Up @@ -54,6 +59,12 @@ contract ArrakisV2Helper is IArrakisV2Helper {
IArrakisV2(underlyingPayload.self).managerBalance1();
}

/// @notice get underlying, fees.
/// @param vault_ Arrakis V2 vault to get underlying info about.
/// @return amount0 amount of underlying of token 0.
/// @return amount1 amount of underlying of token 1.
/// @return fee0 amount of fee of token 0.
/// @return fee1 amount of fee of token 0.
function totalUnderlyingWithFees(IArrakisV2 vault_)
external
view
Expand All @@ -76,6 +87,10 @@ contract ArrakisV2Helper is IArrakisV2Helper {
.totalUnderlyingWithFees(underlyingPayload);
}

/// @notice get underlying.
/// @param vault_ Arrakis V2 vault to get underlying info about.
/// @return amount0 amount of underlying of token 0.
/// @return amount1 amount of underlying of token 1.
function totalUnderlying(IArrakisV2 vault_)
external
view
Expand All @@ -96,6 +111,13 @@ contract ArrakisV2Helper is IArrakisV2Helper {

// #region Rebalance helper functions

/// @notice get underlyings of token0 and token1 in two lists.
/// @param ranges_ list of range to get underlying info about.
/// @param token0_ address of first token.
/// @param token1_ address of second token.
/// @param vaultV2_ address of Arrakis V2 vault.
/// @return amount0s amounts of underlying of token 0.
/// @return amount1s amounts of underlying of token 1.
function token0AndToken1ByRange(
Range[] calldata ranges_,
address token0_,
Expand Down Expand Up @@ -126,6 +148,15 @@ contract ArrakisV2Helper is IArrakisV2Helper {
}
}

/// @notice get underlyings and fees of token0 and token1 in two lists.
/// @param ranges_ list of range to get underlying info about.
/// @param token0_ address of first token.
/// @param token1_ address of second token.
/// @param vaultV2_ address of Arrakis V2 vault.
/// @return amount0s amounts of underlying of token 1.
/// @return amount1s amounts of underlying of token 1.
/// @return fee0s amounts of fees of token 0.
/// @return fee1s amounts of fees of token 1.
function token0AndToken1PlusFeesByRange(
Range[] calldata ranges_,
address token0_,
Expand Down
25 changes: 24 additions & 1 deletion contracts/ArrakisV2Resolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
} from "./structs/SArrakisV2.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";

/// @title Smart contract for resolver/ computing payload
/// that need to be sent to Arrakis V2 vault.
contract ArrakisV2Resolver is IArrakisV2Resolver {
IUniswapV3Factory public immutable factory;
IArrakisV2Helper public immutable helper;
Expand All @@ -48,7 +50,11 @@ contract ArrakisV2Resolver is IArrakisV2Resolver {
swapRouter = swapRouter_;
}

// Standard rebalance (without swapping)
/// @notice Standard rebalance (without swapping)
/// @param rangeWeights_ list of ranges by weights.
/// @param vaultV2_ Arrakis V2 vault.
/// @return rebalanceParams payload to send to rebalance
/// function on Arrakis V2 contract.
// solhint-disable-next-line function-max-lines, code-complexity
function standardRebalance(
RangeWeight[] memory rangeWeights_,
Expand Down Expand Up @@ -139,6 +145,11 @@ contract ArrakisV2Resolver is IArrakisV2Resolver {
}
}

/// @notice Standard Burn proportional burn.
/// @param amountToBurn_ amount of Arrakis V2 token to burn.
/// @param vaultV2_ Arrakis V2 vault.
/// @return burns list of ranges and liquidities to burn.
/// function on Arrakis V2 contract.
// solhint-disable-next-line function-max-lines
function standardBurnParams(uint256 amountToBurn_, IArrakisV2 vaultV2_)
external
Expand Down Expand Up @@ -224,6 +235,16 @@ contract ArrakisV2Resolver is IArrakisV2Resolver {
}
}

/// @notice Mint Amount.
/// @param vaultV2_ Arrakis V2 vault.
/// @param amount0Max_ max amount of token 0.
/// @param amount1Max_ max amount of token 1.
/// @return amount0 of token 0 need to be approved to Arrakis V2 vault
/// before calling mint function of Arrakis V2
/// @return amount1 of token 1 need to be approved to Arrakis V2 vault
/// before calling mint function of Arrakis V2
/// @return mintAmount amount to be sent as param to mint function of
/// Arrakis V2 vault.
// solhint-disable-next-line function-max-lines
function getMintAmounts(
IArrakisV2 vaultV2_,
Expand Down Expand Up @@ -261,6 +282,8 @@ contract ArrakisV2Resolver is IArrakisV2Resolver {
);
}

/// @notice return amount0 and amount1 of token0 and token1
/// for a correspond amount of liquidity.
function getAmountsForLiquidity(
int24 currentTick_,
int24 lowerTick_,
Expand Down
20 changes: 16 additions & 4 deletions contracts/abstract/ArrakisV2FactoryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ import {
EnumerableSet
} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

/// @title Arrakis Factory Storage Smart Contract
// solhint-disable-next-line max-states-count
abstract contract ArrakisV2FactoryStorage is
IArrakisV2Factory,
OwnableUpgradeable
{
using EnumerableSet for EnumerableSet.AddressSet;

// solhint-disable-next-line const-name-snakecase
string public constant version = "1.0.0";

IArrakisV2Beacon public immutable arrakisV2Beacon;
EnumerableSet.AddressSet internal _vaults;

Expand All @@ -43,7 +41,9 @@ abstract contract ArrakisV2FactoryStorage is
}

// #region admin set functions

/// @notice upgrade vaults instance using transparent proxy
/// with the current implementation
/// @param vaults_ the list of vault.
function upgradeVaults(address[] memory vaults_) external onlyOwner {
for (uint256 i = 0; i < vaults_.length; i++) {
ITransparentUpgradeableProxy(vaults_[i]).upgradeTo(
Expand All @@ -52,6 +52,10 @@ abstract contract ArrakisV2FactoryStorage is
}
}

/// @notice upgrade vaults instance using transparent proxy
/// with the current implementation and call the instance
/// @param vaults_ the list of vault.
/// @param datas_ payloads of instances call.
function upgradeVaultsAndCall(
address[] memory vaults_,
bytes[] calldata datas_
Expand All @@ -65,6 +69,8 @@ abstract contract ArrakisV2FactoryStorage is
}
}

/// @notice make the vault immutable
/// @param vaults_ the list of vault.
function makeVaultsImmutable(address[] memory vaults_) external onlyOwner {
for (uint256 i = 0; i < vaults_.length; i++) {
ITransparentUpgradeableProxy(vaults_[i]).changeAdmin(address(1));
Expand All @@ -75,6 +81,9 @@ abstract contract ArrakisV2FactoryStorage is

// #region admin view call.

/// @notice get vault instance admin
/// @param proxy instance of Arrakis V2.
/// @return admin address of Arrakis V2 instance admin.
function getProxyAdmin(address proxy) public view returns (address) {
// We need to manually run the static call since the getter cannot be flagged as view
// bytes4(keccak256("admin()")) == 0xf851a440
Expand All @@ -85,6 +94,9 @@ abstract contract ArrakisV2FactoryStorage is
return abi.decode(returndata, (address));
}

/// @notice get vault implementation
/// @param proxy instance of Arrakis V2.
/// @return implementation address of Arrakis V2 implementation.
function getProxyImplementation(address proxy)
public
view
Expand Down
Loading

0 comments on commit 264f4b3

Please sign in to comment.