Contracts API

ContractRegistry

Inherits from Multicall, ContractMeta

⛽ 1.82M

Functions

constructor

  function constructor(address _governance) public

addresses

  function addresses() external returns (address[])

Addresses of the registered contracts

names

  function names() external returns (string[] result)

Names of the registered contracts

versions

  function versions(string name_) external returns (string[] result)

All versions of the contract

Parameters:

versionAddress

  function versionAddress(string name_, string version) external returns (address)

Address of the contract at a given version

Parameters:

latestVersion

  function latestVersion(string name_) external returns (string, address)

Latest version of the contract

Parameters:

registerContract

⛽ 256K (254K - 259K)

  function registerContract(address target) external

Register a new contract

Parameters:

Specs

  • ✅ registers IContractMeta compatible contract and updates respective view methods - #addresses - #versions - #names - #latestVersion - #versionAddress

Access control

  • ✅ allowed: operator (deployer)

  • ✅ denied with FRB: random address

  • ✅ allowed: protocol admin

Edge cases

  • ✅ when new contract major version differs more, than on one reverts with INVA

  • ✅ when new contract version lower or equal existing one reverts with INVA

  • ✅ when contract has invalid version reverts with INVA

  • ✅ when contract name is not alphanumeric reverts with INV

  • ✅ when address is already registered reverts with DUP

Events

ContractRegistered

  event ContractRegistered(address origin, address sender, bytes32 name, bytes32 version, address target)

ProtocolGovernance

Inherits from Multicall, UnitPricesGovernance, DefaultAccessControl, AccessControlEnumerable, AccessControl, ERC165, Context, ContractMeta

⛽ 4.68M

Governance that manages all params common for Mellow Permissionless Vaults protocol.

Functions

constructor

  function constructor(address admin) public

Creates a new contract

Parameters:

Specs

  • ✅ deploys a new contract

stagedParams

  function stagedParams() public returns (struct IProtocolGovernance.Params)

Staged pending protocol parameters.

Specs

  • ✅ imestamp timestamp equals #stageParams's block.timestamp + governanceDelay

  • ✅ imestamp clears by #commitParams

  • ✅ imestamp edge cases when nothing is set returns zero

  • ✅ imestamp access control allowed: any address

Access control

  • ✅ allowed: any address

Properties

  • ✅ updates by #stageParams

  • ✅ clears by #commitParams

params

  function params() public returns (struct IProtocolGovernance.Params)

Current protocol parameters.

stagedValidatorsAddresses

  function stagedValidatorsAddresses() external returns (address[])

validatorsAddresses

  function validatorsAddresses() external returns (address[])

Addresses that has validators.

validatorsAddress

  function validatorsAddress(uint256 i) external returns (address)

Address that has validators.

Parameters:

Return Values:

Specs

  • ✅ returns correct value

  • ✅ s properties @property: updates when committed validator grant for a new address

  • ✅ s properties @property: doesn't update when committed validator grant for an existing address

  • ✅ s access control allowed: any address

permissionAddresses

  function permissionAddresses() external returns (address[])

Addresses for which non-zero permissions are set.

stagedPermissionGrantsAddresses

  function stagedPermissionGrantsAddresses() external returns (address[])

Permission addresses staged for commit.

addressesByPermission

  function addressesByPermission(uint8 permissionId) external returns (address[] addresses)

Return all addresses where rawPermissionMask bit for permissionId is set to 1.

Parameters:

Return Values:

Specs

  • ✅ returns addresses that has the given permission set to true

Access control

  • ✅ allowed: any address

Properties

  • ✅ updates by #stagePermissionGrants + #commitPermissionGrants or #revokePermissions

  • ✅ is not affected by forceAllowMask

  • ✅ returns empty array on unknown permissionId

hasPermission

  function hasPermission(address target, uint8 permissionId) external returns (bool)

Checks if address has permission or given permission is force allowed for any address.

Parameters:

hasAllPermissions

  function hasAllPermissions(address target, uint8[] permissionIds) external returns (bool)

Checks if address has all permissions.

Parameters:

Specs

  • ✅ checks if an address has all permissions set to true

Access control

  • ✅ allowed: any address

Properties

  • ✅ returns false on random address

  • ✅ is not affected by staged permissions

  • ✅ is affected by committed permissions

  • ✅ returns true for any address when forceAllowMask is set to true

Edge cases

  • ✅ on unknown permission id returns false

maxTokensPerVault

  function maxTokensPerVault() external returns (uint256)

Max different ERC20 token addresses that could be managed by the protocol.

Specs

  • ✅ returns correct value

governanceDelay

  function governanceDelay() external returns (uint256)

The delay for committing any governance params.

Specs

  • ✅ returns correct value

protocolTreasury

  function protocolTreasury() external returns (address)

The address of the protocol treasury.

Specs

  • ✅ returns correct value

forceAllowMask

  function forceAllowMask() external returns (uint256)

Permissions mask which defines if ordinary permission should be reverted. This bitmask is xored with ordinary mask.

Specs

  • ✅ returns correct value

withdrawLimit

  function withdrawLimit(address token) external returns (uint256)

Withdraw limit per token per block.

Parameters:

Return Values:

Specs

  • ✅ returns correct value

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

Specs

  • ✅ returns true for IProtocolGovernance interface (0xca11fe03)

  • ✅ access control: allowed: any address

  • ✅ edge cases: when contract does not support the given interface returns false

stageValidator

⛽ 129K (43K - 142K)

  function stageValidator(address target, address validator) external

Stages a new validator for the given address

Parameters:

Specs

  • ✅ emits ValidatorStaged event

Access control

  • ✅ allowed: admin

  • ✅ denied: deployer

  • ✅ denied: random address

Edge cases

  • ✅ when attempting to stage grant to zero address reverts with AZ when target has zero address

  • ✅ when attempting to stage grant to zero address reverts with AZ when validator has zero address

rollbackStagedValidators

⛽ 39K (28K - 42K)

  function rollbackStagedValidators() external

Rollback all staged validators.

Specs

  • ✅ rolls back all staged validators

  • ✅ emits AllStagedValidatorsRolledBack event

Access control

  • ✅ allowed: admin

  • ✅ denied: deployer

  • ✅ denied: random address

commitValidator

⛽ 86K (47K - 117K)

  function commitValidator(address stagedAddress) external

Commits validator for the given address.

📕 Reverts if governance delay has not passed yet.

Parameters:

Specs

  • ✅ commits staged validators

  • ✅ emits ValidatorCommitted event

Access control

  • ✅ allowed: admin

  • ✅ denied: deployer

  • ✅ denied: random address

Edge cases

  • ✅ when attempting to commit validator for zero address reverts with NULL

  • ✅ when nothing is staged for the given address reverts with NULL

  • ✅ when attempting to commit validator too early reverts with TS

commitAllValidatorsSurpassedDelay

⛽ 132K (27K - 463K)

  function commitAllValidatorsSurpassedDelay() external returns (address[] addressesCommitted)

Commites all staged validators for which governance delay passed

Return Values:

Specs

  • ✅ emits ValidatorCommitted event

Access control

  • ✅ allowed: admin

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ commits all staged validators

  • ✅ commits all staged validators after delay

Edge cases

  • ✅ when attempting to commit a single validator too early does not commit validator

  • ✅ when attempting to commit multiple validators too early does not commit these validators

revokeValidator

⛽ 38K

  function revokeValidator(address target) external

Revoke validator instantly from the given address.

Parameters:

Specs

  • ✅ emits ValidatorRevoked event

Edge cases

  • ✅ when attempting to revoke from zero address reverts with NULL

rollbackStagedPermissionGrants

⛽ 37K (28K - 42K)

  function rollbackStagedPermissionGrants() external

Rollback all staged granted permission grant.

Specs

  • ✅ rolls back all staged permission grants

  • ✅ emits AllStagedPermissionGrantsRolledBack event

Access control

  • ✅ allowed: admin

  • ✅ denied: deployer

  • ✅ denied: random address

commitPermissionGrants

⛽ 71K (46K - 117K)

  function commitPermissionGrants(address stagedAddress) external

Commits permission grants for the given address.

📕 Reverts if governance delay has not passed yet.

Parameters:

Specs

  • ✅ commits staged permission grants

  • ✅ emits PermissionGrantsCommitted event

Access control

  • ✅ allowed: admin

  • ✅ denied: deployer

  • ✅ denied: random address

Edge cases

  • ✅ when attempting to commit permissions for zero address reverts with NULL

  • ✅ when nothing is staged for the given address reverts with NULL

  • ✅ when attempting to commit permissions too early reverts with TS

commitAllPermissionGrantsSurpassedDelay

⛽ 145K (27K - 248K)

  function commitAllPermissionGrantsSurpassedDelay() external returns (address[] addresses)

Commites all staged permission grants for which governance delay passed.

Return Values:

Specs

  • ✅ emits PermissionGrantsCommitted event

Access control

  • ✅ allowed: admin

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ commits all staged permission grants

  • ✅ commits all staged permission grants after delay

Edge cases

  • ✅ when attempting to commit a single permission too early does not commit permission

  • ✅ when attempting to commit multiple permissions too early does not commit these permissions

revokePermissions

⛽ 62K (32K - 275K)

  function revokePermissions(address target, uint8[] permissionIds) external

Revoke permission instantly from the given address.

Parameters:

Specs

  • ✅ emits PermissionRevoked event

Edge cases

  • ✅ when attempting to revoke from zero address reverts with NULL

commitParams

⛽ 66K (54K - 81K)

  function commitParams() external

Commits staged protocol params. Reverts if governance delay has not passed yet.

Specs

  • ✅ emits ParamsCommitted event

Access control

  • ✅ allowed: protocol admin

  • ✅ denied: deployer

  • ✅ denied: random address

Edge cases

  • ✅ when attempting to commit params too early reverts with TS

  • ✅ when attempting to commit params without setting pending params reverts with NULL

stagePermissionGrants

⛽ 166K (44K - 383K)

  function stagePermissionGrants(address target, uint8[] permissionIds) external

Stage granted permissions that could have been committed after governance delay expires. Resets commit delay and permissions if there are already staged permissions for this address.

Parameters:

Specs

  • ✅ emits PermissionGrantsStaged event

Access control

  • ✅ allowed: admin

  • ✅ denied: deployer

  • ✅ denied: random address

Edge cases

  • ✅ when attempting to stage grant to zero address reverts with NULL

stageParams

⛽ 140K (62K - 165K)

  function stageParams(struct IProtocolGovernance.Params newParams) external

Sets new pending params that could have been committed after governance delay expires.

Parameters:

Specs

  • ✅ emits ParamsStaged event

Access control

  • ✅ allowed: admin

  • ✅ denied: random address

Edge cases

  • ✅ when given invalid params when maxTokensPerVault is zero reverts with NULL

  • ✅ when given invalid params when governanceDelay is zero reverts with NULL

  • ✅ when given invalid params when governanceDelay exceeds MAX_GOVERNANCE_DELAY reverts with LIMO

  • ✅ when given invalid params when withdrawLimit less than MIN_WITHDRAW_LIMIT reverts with LIMO

Structs

struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}
struct Params {
    uint256 maxTokensPerVault;
    uint256 governanceDelay;
    address protocolTreasury;
    uint256 forceAllowMask;
    uint256 withdrawLimit;
}

Events

ValidatorStaged

  event ValidatorStaged(address origin, address sender, address target, address validator, uint256 at)

Emitted when validators are staged to be granted for specific address.

Parameters:

ValidatorRevoked

  event ValidatorRevoked(address origin, address sender, address target)

Validator revoked

Parameters:

AllStagedValidatorsRolledBack

  event AllStagedValidatorsRolledBack(address origin, address sender)

Emitted when staged validators are rolled back

Parameters:

ValidatorCommitted

  event ValidatorCommitted(address origin, address sender, address target)

Emitted when staged validators are comitted for specific address

Parameters:

PermissionGrantsStaged

  event PermissionGrantsStaged(address origin, address sender, address target, uint8[] permissionIds, uint256 at)

Emitted when new permissions are staged to be granted for specific address.

Parameters:

PermissionsRevoked

  event PermissionsRevoked(address origin, address sender, address target, uint8[] permissionIds)

Emitted when permissions are revoked

Parameters:

AllStagedPermissionGrantsRolledBack

  event AllStagedPermissionGrantsRolledBack(address origin, address sender)

Emitted when staged permissions are rolled back

Parameters:

PermissionGrantsCommitted

  event PermissionGrantsCommitted(address origin, address sender, address target)

Emitted when staged permissions are comitted for specific address

Parameters:

ParamsStaged

  event ParamsStaged(address origin, address sender, uint256 at, struct IProtocolGovernance.Params params)

Emitted when pending parameters are set

Parameters:

ParamsCommitted

  event ParamsCommitted(address origin, address sender, struct IProtocolGovernance.Params params)

Emitted when pending parameters are committed

Parameters:

UnitPricesGovernance

Inherits from DefaultAccessControl, AccessControlEnumerable, AccessControl, ERC165, Context

⛽ 1.82M

Functions

constructor

  function constructor(address admin) public

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

stageUnitPrice

⛽ 72K (54K - 74K)

  function stageUnitPrice(address token, uint256 value) external

Stage estimated amount of token worth 1 USD staged for commit.

Parameters:

rollbackUnitPrice

⛽ 31K (30K - 31K)

  function rollbackUnitPrice(address token) external

Reset staged value

Parameters:

commitUnitPrice

⛽ 50K

  function commitUnitPrice(address token) external

Commit staged unit price

Parameters:

Structs

struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

UnitPriceStaged

  event UnitPriceStaged(address origin, address sender, address token, uint256 unitPrice)

UnitPrice staged for commit

Parameters:

UnitPriceRolledBack

  event UnitPriceRolledBack(address origin, address sender, address token)

UnitPrice rolled back

Parameters:

UnitPriceCommitted

  event UnitPriceCommitted(address origin, address sender, address token, uint256 unitPrice)

UnitPrice committed

Parameters:

VaultRegistry

Inherits from ERC721, ERC165, Context, ContractMeta

⛽ 3.07M

This contract is used to manage ERC721 NFT for all Vaults.

Functions

constructor

  function constructor(string name, string symbol, contract IProtocolGovernance protocolGovernance_) public

Creates a new contract.

Parameters:

Specs

  • ✅ creates VaultRegistry

  • ✅ initializes ProtocolGovernance address

  • ✅ initializes ERC721 token name

  • ✅ initializes ERC721 token symbol

vaults

  function vaults() external returns (address[])

Specs

  • ✅ returns all registered vaults

  • ✅ access control: allowed: any address

  • ✅ ount returns the number of registered vaults

  • ✅ ount access control: allowed: any address

  • ✅ ount properties @property: when N new vaults have been registered, vaults count will be increased by N

vaultForNft

  function vaultForNft(uint256 nft) external returns (address)

Get Vault for the giver NFT ID.

Parameters:

Return Values:

Specs

  • ✅ resolves Vault address by VaultRegistry NFT

  • ✅ access control: allowed: any address

Edge cases

  • ✅ when Vault NFT is not registered in VaultRegistry returns zero address

nftForVault

  function nftForVault(address vault) external returns (uint256)

Get NFT ID for given Vault contract address.

Parameters:

Return Values:

Specs

  • ✅ resolves VaultRegistry NFT by Vault address

  • ✅ access control: allowed: any address

Edge cases

  • ✅ when Vault is not registered in VaultRegistry returns zero

isLocked

  function isLocked(uint256 nft) external returns (bool)

Checks if the nft is locked for all transfers

Parameters:

Return Values:

Specs

  • ✅ checks if token is locked (not transferable)

  • ✅ access control: allowed: any address

Edge cases

  • ✅ when VaultRegistry NFT is not registered in VaultRegistry returns false

protocolGovernance

  function protocolGovernance() external returns (contract IProtocolGovernance)

Address of the ProtocolGovernance.

Specs

  • ✅ returns ProtocolGovernance address

  • ✅ access control: allowed: any address

stagedProtocolGovernance

  function stagedProtocolGovernance() external returns (contract IProtocolGovernance)

Address of the staged ProtocolGovernance.

Specs

  • ✅ returns ProtocolGovernance address staged for commit

  • ✅ access control: allowed: any address

  • ✅ imestamp returns timestamp after which #commitStagedProtocolGovernance can be called

  • ✅ imestamp access control: allowed: any address

  • ✅ imestamp edge cases when nothing is staged returns 0

  • ✅ imestamp edge cases right after #commitStagedProtocolGovernance was called returns 0

Edge cases

  • ✅ when nothing is staged returns zero address

  • ✅ right after #commitStagedProtocolGovernance was called returns zero address

stagedProtocolGovernanceTimestamp

  function stagedProtocolGovernanceTimestamp() external returns (uint256)

Minimal timestamp when staged ProtocolGovernance can be applied.

Specs

  • ✅ returns timestamp after which #commitStagedProtocolGovernance can be called

  • ✅ access control: allowed: any address

Edge cases

  • ✅ when nothing is staged returns 0

  • ✅ right after #commitStagedProtocolGovernance was called returns 0

vaultsCount

  function vaultsCount() external returns (uint256)

Number of Vaults registered.

Specs

  • ✅ returns the number of registered vaults

  • ✅ access control: allowed: any address

Properties

  • ✅ when N new vaults have been registered, vaults count will be increased by N

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

Specs

  • ✅ returns true if this contract supports a certain interface

  • ✅ access control: allowed: any address

  • ✅ edge cases: when contract does not support the given interface returns false

registerVault

⛽ 167K (154K - 188K)

  function registerVault(address vault, address owner) external returns (uint256 nft)

Register new Vault and mint NFT.

Parameters:

Return Values:

Specs

  • ✅ binds minted ERC721 NFT to Vault address and transfers minted NFT to owner specified in args

  • ✅ emits VaultRegistered event

  • ✅ access control: allowed: any account with Register Vault permissions

  • ✅ access control: denied: any other address

  • ✅ access control: denied: protocol governance admin

Properties

  • ✅ minted NFT equals to vaultRegistry#vaultsCount

Edge cases

  • ✅ when address doesn't conform to IVault interface (IERC165) reverts with INVI

  • ✅ when vault has already been registered reverts with DUP

  • ✅ when owner address is zero reverts with AZ

stageProtocolGovernance

⛽ 75K (43K - 80K)

  function stageProtocolGovernance(contract IProtocolGovernance newProtocolGovernance) external

Stage new ProtocolGovernance.

Parameters:

Specs

  • ✅ stages new ProtocolGovernance for commit

  • ✅ sets the stagedProtocolGovernanceTimestamp after which #commitStagedProtocolGovernance can be called

  • ✅ access control: allowed: ProtocolGovernance Admin

  • ✅ access control: denied: any other address

  • ✅ access control: denied: deployer

Edge cases

  • ✅ when new ProtocolGovernance is a zero address reverts with AZ

commitStagedProtocolGovernance

⛽ 34K

  function commitStagedProtocolGovernance() external

Commit new ProtocolGovernance.

Specs

  • ✅ commits staged ProtocolGovernance

  • ✅ resets staged ProtocolGovernanceTimestamp

  • ✅ resets staged ProtocolGovernance

  • ✅ access control: allowed: ProtocolGovernance Admin

  • ✅ access control: denied: any other address

Edge cases

  • ✅ when nothing is staged reverts with INIT

  • ✅ when called before stagedProtocolGovernanceTimestamp reverts with TS

  • ✅ when called before stagedProtocolGovernanceTimestamp reverts with TS

lockNft

⛽ 46K (29K - 49K)

  function lockNft(uint256 nft) external

Specs

  • ✅ locks NFT (disables any transfer)

  • ✅ emits TokenLocked event

  • ✅ access control: allowed: NFT owner

  • ✅ access control: denied: any other address

  • ✅ access control: denied: protocol admin

Edge cases

  • ✅ when NFT has already been locked succeeds

Events

TokenLocked

  event TokenLocked(address origin, address sender, uint256 nft)

Emitted when token is locked for transfers

Parameters:

VaultRegistered

  event VaultRegistered(address origin, address sender, uint256 nft, address vault, address owner)

Emitted when new Vault is registered in VaultRegistry

Parameters:

StagedProtocolGovernance

  event StagedProtocolGovernance(address origin, address sender, contract IProtocolGovernance newProtocolGovernance, uint256 start)

Parameters:

CommitedProtocolGovernance

  event CommitedProtocolGovernance(address origin, address sender, contract IProtocolGovernance newProtocolGovernance)

Parameters:

CommonLibrary

CommonLibrary shared utilities

ExceptionsLibrary

Exceptions stores project`s smart-contracts exceptions

PermissionIdsLibrary

Stores permission ids for addresses

SemverLibrary

ChainlinkOracle

Inherits from DefaultAccessControl, AccessControlEnumerable, AccessControl, ERC165, Context, ContractMeta

⛽ 2.77M

Contract for getting chainlink data

Functions

constructor

  function constructor(address[] tokens, address[] oracles, address admin) public

hasOracle

  function hasOracle(address token) external returns (bool)

Checks if token has chainlink oracle

Parameters:

Return Values:

Specs

  • ✅ returns true if oracle is supported

  • ✅ edge cases: when oracle is not supported returns false

supportedTokens

  function supportedTokens() external returns (address[])

A list of supported tokens

Specs

  • ✅ returns list of supported tokens

priceX96

  function priceX96(address token0, address token1, uint256 safetyIndicesSet) external returns (uint256[] pricesX96, uint256[] safetyIndices)

Oracle price for tokens as a Q64.96 value. Returns pricing information based on the indexes of non-zero bits in safetyIndicesSet. It is possible that not all indices will have their respective prices returned.

📕 The price is token1 / token0 i.e. how many weis of token1 required for 1 wei of token0. The safety indexes are:

1 - unsafe, this is typically a spot price that can be easily manipulated,

2 - 4 - more or less safe, this is typically a uniV3 oracle, where the safety is defined by the timespan of the average price

5 - safe - this is typically a chailink oracle

Parameters:

Return Values:

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true for ChainlinkOracle interface (0x8e3bd5d7)

  • ✅ edge cases: when contract does not support the given interface returns false

addChainlinkOracles

⛽ 82K (81K - 83K)

  function addChainlinkOracles(address[] tokens, address[] oracles) external

Add a Chainlink price feed for a token

Parameters:

Specs

  • ✅ emits OraclesAdded event

  • ✅ when oracles have set by addChainLinkOracles function returns prices

  • ✅ edge cases: when arrays have different lengths reverts with INV

  • ✅ edge cases: when sender has no admin righs reverts with FRB

Structs

struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

OraclesAdded

  event OraclesAdded(address origin, address sender, address[] tokens, address[] oracles)

Emitted when new Chainlink oracle is added

Parameters:

MellowOracle

Inherits from ERC165, ContractMeta

⛽ 783K

constructor

  function constructor(contract IUniV2Oracle univ2Oracle_, contract IUniV3Oracle univ3Oracle_, contract IChainlinkOracle chainlinkOracle_) public

priceX96

  function priceX96(address token0, address token1, uint256 safetyIndicesSet) external returns (uint256[] pricesX96, uint256[] safetyIndices)

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true for IUniV3Oracle interface (0x6d80125b)

  • ✅ edge cases: when contract does not support the given interface returns false

UniV2Oracle

Inherits from ERC165, ContractMeta

⛽ 671K

constructor

  function constructor(contract IUniswapV2Factory factory_) public

priceX96

  function priceX96(address token0, address token1, uint256 safetyIndicesSet) external returns (uint256[] pricesX96, uint256[] safetyIndices)

Oracle price for tokens as a Q64.96 value. Returns pricing information based on the indexes of non-zero bits in safetyIndicesSet. It is possible that not all indices will have their respective prices returned.

📕 The price is token1 / token0 i.e. how many weis of token1 required for 1 wei of token0. The safety indexes are:

1 - unsafe, this is typically a spot price that can be easily manipulated,

2 - 4 - more or less safe, this is typically a uniV3 oracle, where the safety is defined by the timespan of the average price

5 - safe - this is typically a chailink oracle

Parameters:

Return Values:

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true for IUniV2Oracle interface (0x2748645e)

  • ✅ edge cases: when contract does not support the given interface returns false

UniV3Oracle

Inherits from DefaultAccessControl, AccessControlEnumerable, AccessControl, ERC165, Context, ContractMeta

⛽ 3.44M

Functions

constructor

  function constructor(contract IUniswapV3Factory factory_, contract IUniswapV3Pool[] pools, address admin) public

priceX96

  function priceX96(address token0, address token1, uint256 safetyIndicesSet) external returns (uint256[] pricesX96, uint256[] safetyIndices)

Oracle price for tokens as a Q64.96 value. Returns pricing information based on the indexes of non-zero bits in safetyIndicesSet. It is possible that not all indices will have their respective prices returned.

📕 Logic of this function is next: If there is no initialized pool for the passed tokens, empty arrays will be returned. Depending on safetyIndicesSet if the 1st bit in safetyIndicesSet is non-zero, then the response will contain the spot price. If there is a non-zero 2nd bit in the safetyIndicesSet and the corresponding position in the pool was created no later than LOW_OBS_DELTA seconds ago, then the average price for the last LOW_OBS_DELTA seconds will be returned. The same logic exists for the 3rd and MID_OBS_DELTA, and 4th index and HIGH_OBS_DELTA.

Parameters:

Return Values:

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true for IUniV3Oracle interface (0x2a3602d6)

  • ✅ when contract does not support the given interface returns false

addUniV3Pools

⛽ 73K (39K - 89K)

  function addUniV3Pools(contract IUniswapV3Pool[] pools) external

Add UniV3 pools for prices.

Parameters:

Specs

  • ✅ when adding [weth, usdc] pools with fee = 500 adds pools

  • ✅ when adding [weth, usdc] pools with fee = 3000 adds pools

  • ✅ when adding [weth, usdc] pools with fee = 10000 does not return prices

Structs

struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

PoolsUpdated

  event PoolsUpdated(address origin, address sender, contract IUniswapV3Pool[] pools, contract IUniswapV3Pool[] replacedPools)

Emitted when new pool is added or updated and become available for oracle prices

Parameters:

HStrategy

Inherits from DefaultAccessControlLateInit, AccessControlEnumerable, AccessControl, ERC165, Context, Multicall, ContractMeta

⛽ 7.59M

Functions

constructor

  function constructor(contract INonfungiblePositionManager positionManager_, contract ISwapRouter router_, address uniV3Helper_, address hStrategyHelper_) public

constructs a strategy

Parameters:

Specs

  • ✅ deploys a new contract

initialize

  function initialize(address[] tokens_, contract IERC20Vault erc20Vault_, contract IIntegrationVault moneyVault_, contract IUniV3Vault uniV3Vault_, uint24 fee_, address admin_) external

initializes the strategy

Parameters:

createStrategy

⛽ 536K (536K - 539K)

  function createStrategy(address[] tokens_, contract IERC20Vault erc20Vault_, contract IIntegrationVault moneyVault_, contract IUniV3Vault uniV3Vault_, uint24 fee_, address admin_) external returns (contract HStrategy strategy)

creates the clone of the strategy

Parameters:

Return Values:

Specs

  • ✅ creates a new strategy and initializes it

updateStrategyParams

⛽ 48K (44K - 51K)

  function updateStrategyParams(struct HStrategy.StrategyParams newStrategyParams) external

updates parameters of the strategy. Can be called only by admin

Parameters:

updateMintingParams

  function updateMintingParams(struct HStrategy.MintingParams newMintingParams) external

updates parameters for minting position. Can be called only by admin

Parameters:

updateOracleParams

  function updateOracleParams(struct HStrategy.OracleParams newOracleParams) external

updates oracle parameters. Can be called only by admin

Parameters:

updateRatioParams

⛽ 39K (38K - 40K)

  function updateRatioParams(struct HStrategy.RatioParams newRatioParams) external

updates parameters of the capital ratios and deviation. Can be called only by admin

Parameters:

updateSwapFees

  function updateSwapFees(uint24 newSwapFees) external

updates swap fees for uniswapV3Pool swaps

Parameters:

manualPull

⛽ 468K (256K - 517K)

  function manualPull(contract IIntegrationVault fromVault, contract IIntegrationVault toVault, uint256[] tokenAmounts, bytes vaultOptions) external

manual pulling tokens from vault. Can be called only by admin

Parameters:

Specs

  • ✅ pulls token amounts from fromVault to toVault

rebalance

⛽ 1.44M (352K - 1.75M)

  function rebalance(struct HStrategy.RebalanceTokenAmounts restrictions, bytes moneyVaultOptions) external returns (struct HStrategy.RebalanceTokenAmounts actualPulledAmounts, uint256[] burnedAmounts)

rebalance method. Need to be called if the new position is needed

Parameters:

Return Values:

Specs

  • ✅ performs a rebalance according to strategy params

Structs

struct StrategyParams {
    int24 halfOfShortInterval;
    int24 tickNeighborhood;
    int24 domainLowerTick;
    int24 domainUpperTick;
}
struct MintingParams {
    uint256 minToken0ForOpening;
    uint256 minToken1ForOpening;
}
struct OracleParams {
    uint32 averagePriceTimeSpan;
    uint24 maxTickDeviation;
}
struct RatioParams {
    uint256 erc20CapitalRatioD;
    uint256 minCapitalDeviationD;
    uint256 minRebalanceDeviationD;
}
struct Interval {
    int24 lowerTick;
    int24 upperTick;
}
struct RebalanceTokenAmounts {
    uint256[] pulledToUniV3Vault;
    uint256[] pulledFromUniV3Vault;
    int256[] swappedAmounts;
    uint256[] burnedAmounts;
    uint256 deadline;
}
struct TokenAmountsInToken0 {
    uint256 erc20TokensAmountInToken0;
    uint256 moneyTokensAmountInToken0;
    uint256 uniV3TokensAmountInToken0;
    uint256 totalTokensInToken0;
}
struct TokenAmounts {
    uint256 erc20Token0;
    uint256 erc20Token1;
    uint256 moneyToken0;
    uint256 moneyToken1;
    uint256 uniV3Token0;
    uint256 uniV3Token1;
}
struct ExpectedRatios {
    uint32 token0RatioD;
    uint32 token1RatioD;
    uint32 uniV3RatioD;
}
struct DomainPositionParams {
    uint256 nft;
    uint128 liquidity;
    int24 lowerTick;
    int24 upperTick;
    int24 domainLowerTick;
    int24 domainUpperTick;
    uint160 lowerPriceSqrtX96;
    uint160 upperPriceSqrtX96;
    uint160 domainLowerPriceSqrtX96;
    uint160 domainUpperPriceSqrtX96;
    uint160 intervalPriceSqrtX96;
    uint256 spotPriceX96;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

MintUniV3Position

  event MintUniV3Position(uint256 uniV3Nft, int24 lowerTick, int24 upperTick)

Emitted when new position in UniV3Pool has been minted.

Parameters:

BurnUniV3Position

  event BurnUniV3Position(uint256 uniV3Nft)

Emitted when position in UniV3Pool has been burnt.

Parameters:

SwapTokensOnERC20Vault

  event SwapTokensOnERC20Vault(address origin, struct ISwapRouter.ExactInputSingleParams swapParams)

Emitted when swap is initiated.

Parameters:

UpdateStrategyParams

  event UpdateStrategyParams(address origin, address sender, struct HStrategy.StrategyParams strategyParams)

Emitted when Strategy strategyParams are set.

Parameters:

UpdateMintingParams

  event UpdateMintingParams(address origin, address sender, struct HStrategy.MintingParams mintingParams)

Emitted when Strategy mintingParams are set.

Parameters:

UpdateOracleParams

  event UpdateOracleParams(address origin, address sender, struct HStrategy.OracleParams oracleParams)

Emitted when Strategy oracleParams are set.

Parameters:

UpdateRatioParams

  event UpdateRatioParams(address origin, address sender, struct HStrategy.RatioParams ratioParams)

Emitted when Strategy ratioParams are set.

Parameters:

UpdateSwapFees

  event UpdateSwapFees(address origin, address sender, uint24 newSwapFees)

Emitted when new swap fees for UniV3Pool swaps are set.

Parameters:

LStrategy

Inherits from DefaultAccessControl, AccessControlEnumerable, AccessControl, ERC165, Context

⛽ 7.65M

Functions

constructor

  function constructor(contract INonfungiblePositionManager positionManager_, address cowswapSettlement_, address cowswapVaultRelayer_, contract IERC20Vault erc20vault_, contract IUniV3Vault vault1_, contract IUniV3Vault vault2_, contract ILStrategyHelper orderHelper_, address admin_, uint16 intervalWidthInTicks_) public

getTargetPriceX96

  function getTargetPriceX96(address token0, address token1, struct LStrategy.TradingParams tradingParams_) public returns (uint256 priceX96)

Target price based on mutable params, as a Q64.96 value

targetUniV3LiquidityRatio

  function targetUniV3LiquidityRatio(int24 targetTick_) public returns (uint128 liquidityRatioD, bool isNegative)

Target liquidity ratio for UniV3 vaults

rebalanceERC20UniV3Vaults

⛽ 505K (326K - 1.69M)

  function rebalanceERC20UniV3Vaults(uint256[] minLowerVaultTokens, uint256[] minUpperVaultTokens, uint256 deadline) public returns (uint256[] totalPulledAmounts, bool isNegativeCapitalDelta, uint256 percentageIncreaseD)

Make a rebalance between ERC20 and UniV3 Vaults

Parameters:

Return Values:

rebalanceUniV3Vaults

⛽ 432K (138K - 900K)

  function rebalanceUniV3Vaults(uint256[] minWithdrawTokens, uint256[] minDepositTokens, uint256 deadline) external returns (uint256[] pulledAmounts, uint256[] pushedAmounts, uint128 depositLiquidity, uint128 withdrawLiquidity, bool lowerToUpper)

Make a rebalance of UniV3 vaults

Parameters:

Return Values:

postPreOrder

⛽ 144K (140K - 180K)

  function postPreOrder(uint256 minAmountOut) external returns (struct LStrategy.PreOrder preOrder_)

Post preorder for ERC20 vault rebalance.

Parameters:

Return Values:

signOrder

⛽ 210K (103K - 233K)

  function signOrder(struct GPv2Order.Data order, bytes uuid, bool signed) external

Sign offchain cowswap order onchain

Parameters:

resetCowswapAllowance

⛽ 117K (116K - 118K)

  function resetCowswapAllowance(uint8 tokenNumber) external

Reset cowswap allowance to 0

Parameters:

collectUniFees

⛽ 279K (239K - 320K)

  function collectUniFees() external returns (uint256[] totalCollectedEarnings)

Collect Uniswap pool fees to erc20 vault

Return Values:

manualPull

⛽ 345K (297K - 487K)

  function manualPull(contract IIntegrationVault fromVault, contract IIntegrationVault toVault, uint256[] tokenAmounts, uint256[] minTokensAmounts, uint256 deadline) external returns (uint256[] actualTokenAmounts)

Manually pull tokens from fromVault to toVault

Parameters:

updateTradingParams

⛽ 68K (42K - 119K)

  function updateTradingParams(struct LStrategy.TradingParams newTradingParams) external

Sets new trading params

Parameters:

updateRatioParams

⛽ 37K (36K - 53K)

  function updateRatioParams(struct LStrategy.RatioParams newRatioParams) external

Sets new ratio params

Parameters:

updateOtherParams

⛽ 41K (33K - 94K)

  function updateOtherParams(struct LStrategy.OtherParams newOtherParams) external

Sets new other params

Parameters:

Structs

struct TradingParams {
    IOracle oracle;
    uint32 maxSlippageD;
    uint32 orderDeadline;
    uint256 oracleSafetyMask;
    uint256 maxFee0;
    uint256 maxFee1;
}
struct RatioParams {
    uint32 erc20UniV3CapitalRatioD;
    uint32 erc20TokenRatioD;
    uint32 minErc20UniV3CapitalRatioDeviationD;
    uint32 minErc20TokenRatioDeviationD;
    uint32 minUniV3LiquidityRatioDeviationD;
}
struct OtherParams {
    uint256 minToken0ForOpening;
    uint256 minToken1ForOpening;
    uint256 secondsBetweenRebalances;
}
struct PreOrder {
    address tokenIn;
    address tokenOut;
    uint64 deadline;
    uint256 amountIn;
    uint256 minAmountOut;
}
struct LiquidityParams {
    uint128 targetUniV3LiquidityRatioD;
    bool isNegativeLiquidityRatio;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

PreOrderPosted

  event PreOrderPosted(address origin, address sender, struct LStrategy.PreOrder preOrder)

Emitted when a new cowswap preOrder is posted.

Parameters:

OrderSigned

  event OrderSigned(address origin, address sender, bytes uuid, struct GPv2Order.Data order, struct LStrategy.PreOrder preOrder, bool signed)

Emitted when cowswap preOrder was signed onchain.

Parameters:

ManualPull

  event ManualPull(address origin, address sender, uint256[] tokenAmounts, uint256[] actualTokenAmounts)

Emitted when manual pull from vault is executed.

Parameters:

SwapVault

  event SwapVault(uint256 oldNft, uint256 newNft, int24 newTickLower, int24 newTickUpper)

Emitted when vault is swapped.

Parameters:

RebalancedErc20UniV3

  event RebalancedErc20UniV3(address origin, address sender, bool fromErc20, uint256[] pulledAmounts)

Emitted when rebalance from UniV3 to ERC20 or vice versa happens

Parameters:

RebalancedUniV3

  event RebalancedUniV3(address origin, address sender, address fromVault, address toVault, uint256[] pulledAmounts, uint256[] pushedAmounts, uint128 desiredLiquidity, uint128 liquidity)

Parameters:

TradingParamsUpdated

  event TradingParamsUpdated(address origin, address sender, struct LStrategy.TradingParams tradingParams)

Emitted when trading params were updated

Parameters:

RatioParamsUpdated

  event RatioParamsUpdated(address origin, address sender, struct LStrategy.RatioParams ratioParams)

Emitted when ratio params were updated

Parameters:

OtherParamsUpdated

  event OtherParamsUpdated(address origin, address sender, struct LStrategy.OtherParams otherParams)

Emitted when other params were updated

Parameters:

CowswapAllowanceReset

  event CowswapAllowanceReset(address origin, address sender)

FeesCollected

  event FeesCollected(address origin, address sender, uint256[] collectedEarnings)

MStrategy

Inherits from DefaultAccessControlLateInit, AccessControlEnumerable, AccessControl, ERC165, Context, Multicall, ContractMeta

⛽ 6.64M

Functions

constructor

  function constructor(contract INonfungiblePositionManager positionManager_, contract ISwapRouter router_) public

Deploys a new contract

Parameters:

Specs

  • ✅ deploys a new contract

Edge cases

  • ✅ when positionManager_ address is zero reverts with AZ

  • ✅ when router_ address is zero passes

getAverageTick

  function getAverageTick() external returns (int24 averageTick, int24 deviation)

UniV3 pool price stats

Return Values:

Specs

  • ✅ returns average UniswapV3Pool price tick

initialize

  function initialize(contract INonfungiblePositionManager positionManager_, contract ISwapRouter router_, address[] tokens_, contract IERC20Vault erc20Vault_, contract IIntegrationVault moneyVault_, uint24 fee_, address admin_) external

Set initial values.

📕 Can be only called once.

Parameters:

createStrategy

⛽ 571K (570K - 573K)

  function createStrategy(address[] tokens_, contract IERC20Vault erc20Vault_, contract IIntegrationVault moneyVault_, uint24 fee_, address admin_) external returns (contract MStrategy strategy)

Deploy a new strategy.

Parameters:

Specs

  • ✅ creates a new strategy and initializes it

Access control

  • ✅ allowed: any address

Edge cases

  • ✅ when tokens.length is not equal 2 reverts with INVL

  • ✅ when erc20Vault vaultTokens do not match tokens_ reverts with INVA

  • ✅ when moneyVault vaultTokens do not match tokens_ reverts with INVA

  • ✅ when UniSwapV3 pool for tokens does not exist reverts with AZ

rebalance

⛽ 725K (240K - 851K)

  function rebalance(uint256[] minTokensAmount, bytes vaultOptions) external returns (int256[] poolAmounts, uint256[] tokenAmounts, bool zeroToOne)

Perform a rebalance according to target ratios

Parameters:

Return Values:

Specs

  • ✅ performs a rebalance according to target ratios when token0/token1 ratio is greater than required

  • ✅ performs a rebalance according to target ratios when token0/token1 ratio is less than required

Access control

  • ✅ allowed: MStrategy admin

  • ✅ allowed: MStrategy operator

  • ✅ denied: any other address

Edge cases

  • ✅ when absolute tick deviation >= oracle.maxTickDeviation reverts with INVA

  • ✅ when tick is greater than tickMax - tickNeiborhood the upper bound of the interval is expanded by tickIncrease amount

  • ✅ when tick is less than tickMin + tickNeiborhood the lower bound of the interval is expanded by tickIncrease amount

  • ✅ when current tick has not deviated from the previous rebalance tick reverts with LIMU

manualPull

  function manualPull(contract IIntegrationVault fromVault, contract IIntegrationVault toVault, uint256[] tokenAmounts, bytes vaultOptions) external

Manually pull tokens from fromVault to toVault

Parameters:

Specs

  • ✅ pulls token amounts from fromVault to toVault

Access control

  • ✅ allowed: MStrategy admin

  • ✅ denied: any other address

Edge cases

  • ✅ when token pull amounts are 0 passes

setOracleParams

⛽ 64K (41K - 75K)

  function setOracleParams(struct MStrategy.OracleParams params) external

Set new Oracle params

Parameters:

Specs

  • ✅ sets new params for oracle

  • ✅ edge cases: when maxSlippageD is more than DENOMINATOR reverts with INVA

Access control

  • ✅ allowed: MStrategy admin

  • ✅ denied: any other address

setRatioParams

⛽ 65K (44K - 124K)

  function setRatioParams(struct MStrategy.RatioParams params) external

Set new Ratio params

Parameters:

Specs

  • ✅ sets new ratio params

  • ✅ edge cases: tickMin is greater than tickMax reverts with INVA

  • ✅ edge cases: when erc20MoneyRatioD is more than DENOMINATOR reverts with INVA

  • ✅ edge cases: when minErc20MoneyRatioDeviationD is more than DENOMINATOR reverts with INVA

Access control

  • ✅ allowed: MStrategy admin

  • ✅ denied: any other address

Structs

struct OracleParams {
    uint32 oracleObservationDelta;
    uint24 maxTickDeviation;
    uint256 maxSlippageD;
}
struct RatioParams {
    int24 tickMin;
    int24 tickMax;
    int24 minTickRebalanceThreshold;
    int24 tickNeighborhood;
    int24 tickIncrease;
    uint256 erc20MoneyRatioD;
    uint256 minErc20MoneyRatioDeviation0D;
    uint256 minErc20MoneyRatioDeviation1D;
}
struct SwapToTargetParams {
    uint256 amountIn;
    address[] tokens;
    uint8 tokenInIndex;
    uint256 priceX96;
    uint256[] erc20Tvl;
    IUniswapV3Pool pool;
    ISwapRouter router;
    IIntegrationVault erc20Vault;
    IIntegrationVault moneyVault;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

RebalancedPools

  event RebalancedPools(int256[] tokenAmounts)

Emitted when pool rebalance is initiated.

Parameters:

SwappedTokens

  event SwappedTokens(struct MStrategy.SwapToTargetParams params)

Emitted when swap is initiated.

Parameters:

SetOracleParams

  event SetOracleParams(address origin, address sender, struct MStrategy.OracleParams params)

Emitted when Oracle params are set.

Parameters:

SetRatioParams

  event SetRatioParams(address origin, address sender, struct MStrategy.RatioParams params)

Emitted when Ratio params are set.

Parameters:

MultiPoolHStrategy

Inherits from DefaultAccessControlLateInit, AccessControlEnumerable, AccessControl, ERC165, Context, Multicall, ContractMeta

⛽ 5.84M

Functions

constructor

  function constructor() public

constructs a strategy

initialize

  function initialize(struct MultiPoolHStrategy.ImmutableParams immutableParams_, struct MultiPoolHStrategy.MutableParams mutableParams_, address admin) external

initializes the strategy

Parameters:

createStrategy

⛽ 1.2M (1.18M - 1.25M)

  function createStrategy(struct MultiPoolHStrategy.ImmutableParams immutableParams_, struct MultiPoolHStrategy.MutableParams mutableParams_, address admin) external returns (contract MultiPoolHStrategy strategy)

creates the clone of the strategy

Parameters:

Return Values:

updateMutableParams

  function updateMutableParams(struct MultiPoolHStrategy.MutableParams mutableParams_) external

updates parameters of the strategy. Can be called only by admin

Parameters:

rebalance

⛽ 3.41M

  function rebalance(struct MultiPoolHStrategyRebalancer.Restrictions restrictions) external returns (struct MultiPoolHStrategyRebalancer.Restrictions actualAmounts)

rebalance method. Need to be called if the new position is needed

Parameters:

Return Values:

Specs

  • ✅ works correctly

checkMutableParams

  function checkMutableParams(struct MultiPoolHStrategy.MutableParams mutableParams_) public

the function checks that mutableParams_ pass the necessary checks

Parameters:

Structs

struct ImmutableParams {
    address[] tokens;
    IERC20Vault erc20Vault;
    IIntegrationVault moneyVault;
    address router;
    MultiPoolHStrategyRebalancer rebalancer;
    IUniV3Vault[] uniV3Vaults;
    int24 tickSpacing;
}
struct MutableParams {
    int24 halfOfShortInterval;
    int24 domainLowerTick;
    int24 domainUpperTick;
    int24 maxTickDeviation;
    uint32 averageTickTimespan;
    uint256 amount0ForMint;
    uint256 amount1ForMint;
    uint256 erc20CapitalRatioD;
    uint256[] uniV3Weights;
    IUniswapV3Pool swapPool;
}
struct Interval {
    int24 lowerTick;
    int24 upperTick;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

UpdateMutableParams

  event UpdateMutableParams(address origin, address sender, struct MultiPoolHStrategy.MutableParams mutableParams)

Emitted when Strategy mutableParams are set.

Parameters:

Rebalance

  event Rebalance(address sender, address origin, struct MultiPoolHStrategyRebalancer.Restrictions expectedAmounts, struct MultiPoolHStrategyRebalancer.Restrictions actualAmounts)

Emitted when Strategy mutableParams are set.

Parameters:

PulseRouteStrategy

Inherits from DefaultAccessControlLateInit, AccessControlEnumerable, AccessControl, ERC165, Context, Multicall, ContractMeta

Functions

constructor

  function constructor(contract INonfungiblePositionManager positionManager_) public

Parameters:

initialize

  function initialize(struct PulseRouteStrategy.ImmutableParams immutableParams_, address admin) external

Parameters:

updateMutableParams

  function updateMutableParams(struct PulseRouteStrategy.MutableParams mutableParams_) external

📕 updates mutable params of the strategy. Only the admin can call the function

Parameters:

rebalance

  function rebalance(uint256 deadline) external

📕 Rebalancing goes like this:

  1. Function checks the current states of the pools, and if the volatility is significant, the transaction reverts.

  2. If necessary, a new position is minted on uniV3Vault, and the previous one is burned.

  3. Tokens on erc20Vault are swapped via swapRouter so that the proportion matches the tokens on uniV3Vault.

  4. The strategy transfers all possible tokens from erc20Vault to uniV3Vault. Only users with administrator or operator roles can call the function.

Parameters:

calculateNewInterval

  function calculateNewInterval(struct PulseRouteStrategy.MutableParams mutableParams_, int24 tick, contract IUniswapV3Pool pool) public returns (int24 lowerTick, int24 upperTick)

📕 calculates a new interval according to the mutable params, the tickSpacing of the pool and the spot tick

Parameters:

Return Values:

checkMutableParams

  function checkMutableParams(struct PulseRouteStrategy.MutableParams params, struct PulseRouteStrategy.ImmutableParams immutableParams_) public

📕 checks mutable params according to strategy restrictions

Parameters:

checkImmutableParams

  function checkImmutableParams(struct PulseRouteStrategy.ImmutableParams params) public

📕 checks immutable params according to strategy restrictions

Parameters:

checkTickDeviations

  function checkTickDeviations(struct PulseRouteStrategy.MutableParams mutableParams_, contract IUniswapV3Pool vaultPool, int24 spotTick) public

Parameters:

calculateTargetRatioOfToken1

  function calculateTargetRatioOfToken1(struct PulseRouteStrategy.Interval interval, uint160 sqrtSpotPriceX96, uint256 spotPriceX96) public returns (uint256 targetRatioOfToken1X96)

📕 calculate target ratio of token 1 to total capital after rebalance

Parameters:

Return Values:

calculateAmountsForSwap

  function calculateAmountsForSwap(struct PulseRouteStrategy.ImmutableParams immutableParams_, struct PulseRouteStrategy.MutableParams mutableParams_, uint256 priceX96, uint256 targetRatioOfToken1X96) public returns (uint256 tokenInIndex, uint256 amountIn)

📕 notion link: https://www.notion.so/mellowprotocol/Swap-formula-53807cbf5c5641eda937dd1847d70f43 calculates the token that needs to be swapped and its amount to get the target ratio of tokens in the erc20Vault.

Parameters:

Return Values:

depositCallback

  function depositCallback() external

Function, that ERC20RootVault calling after deposit

withdrawCallback

  function withdrawCallback() external

Function, that ERC20RootVault calling after withdraw

Structs

struct ImmutableParams {
    address router;
    IERC20Vault erc20Vault;
    IUniV3Vault uniV3Vault;
    address[] tokens;
}
struct MutableParams {
    uint24 priceImpactD6;
    int24 intervalWidth;
    int24 tickNeighborhood;
    int24 maxDeviationForVaultPool;
    uint32 timespanForAverageTick;
    bytes pathZeroToOne;
    bytes pathOneToZero;
    uint256 amount0Desired;
    uint256 amount1Desired;
    uint256 swapSlippageD;
    uint256[] minSwapAmounts;
}
struct Interval {
    int24 lowerTick;
    int24 upperTick;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

TokensSwapped

  event TokensSwapped(struct ISwapRouter.ExactInputParams swapParams, uint256 amountOut)

Emitted after a successful token swap

Parameters:

UpdateMutableParams

  event UpdateMutableParams(address origin, address sender, struct PulseRouteStrategy.MutableParams mutableParams)

Emited when mutable parameters are successfully updated

Parameters:

Rebalance

  event Rebalance(address origin, address sender)

Emited when the rebalance is successfully completed

Parameters:

PositionMinted

  event PositionMinted(uint256 tokenId)

Emited when a new uniswap position is created

Parameters:

PositionBurned

  event PositionBurned(uint256 tokenId)

Emited when a uniswap position is burned

Parameters:

PulseStrategy

Inherits from DefaultAccessControlLateInit, AccessControlEnumerable, AccessControl, ERC165, Context, Multicall, ContractMeta

Functions

constructor

  function constructor(contract INonfungiblePositionManager positionManager_) public

Parameters:

initialize

  function initialize(struct PulseStrategy.ImmutableParams immutableParams_, address admin) external

Parameters:

updateMutableParams

  function updateMutableParams(struct PulseStrategy.MutableParams mutableParams_) external

📕 updates mutable params of the strategy. Only the admin can call the function

Parameters:

rebalance

  function rebalance(uint256 deadline, bytes swapData) external

📕 Rebalancing goes like this:

  1. Function checks the current states of the pools, and if the volatility is significant, the transaction reverts.

  2. If necessary, a new position is minted on uniV3Vault, and the previous one is burned.

  3. Tokens on erc20Vault are swapped via AggregationRouterV5 so that the proportion matches the tokens on uniV3Vault.

  4. The strategy transfers all possible tokens from erc20Vault to uniV3Vault. Only users with administrator or operator roles can call the function.

Parameters:

checkMutableParams

  function checkMutableParams(struct PulseStrategy.MutableParams params, struct PulseStrategy.ImmutableParams immutableParams_) public

📕 checks mutable params according to strategy restrictions

Parameters:

checkImmutableParams

  function checkImmutableParams(struct PulseStrategy.ImmutableParams params) public

📕 checks immutable params according to strategy restrictions

Parameters:

checkTickDeviation

  function checkTickDeviation(struct PulseStrategy.MutableParams mutableParams_, contract IUniswapV3Pool vaultPool) public

📕 checks deviation of spot ticks of all pools in strategy from corresponding average ticks. If any deviation is large than maxDevation parameter for the pool, then the transaction will be reverted with a LIMIT_OVERFLOW error. If there are no observations 10 seconds ago in any of the considered pools, then the transaction will be reverted with an INVALID_STATE error.

Parameters:

calculateNewPosition

  function calculateNewPosition(struct PulseStrategy.MutableParams mutableParams_, int24 spotTick, contract IUniswapV3Pool pool, uint256 uniV3Nft) public returns (struct PulseStrategy.Interval newInterval, bool neededNewInterval)

Parameters:

Return Values:

calculateTargetRatioOfToken1

  function calculateTargetRatioOfToken1(struct PulseStrategy.Interval interval, uint160 sqrtSpotPriceX96, uint256 spotPriceX96) public returns (uint256 targetRatioOfToken1X96)

📕 calculate target ratio of token 1 to total capital after rebalance

Parameters:

Return Values:

calculateAmountsForSwap

  function calculateAmountsForSwap(struct PulseStrategy.ImmutableParams immutableParams_, struct PulseStrategy.MutableParams mutableParams_, uint256 priceX96, uint256 targetRatioOfToken1X96) public returns (uint256 tokenInIndex, uint256 amountIn)

📕 notion link: https://www.notion.so/mellowprotocol/Swap-formula-53807cbf5c5641eda937dd1847d70f43 calculates the token that needs to be swapped and its amount to get the target ratio of tokens in the erc20Vault.

Parameters:

Return Values:

depositCallback

  function depositCallback() external

Function, that ERC20RootVault calling after deposit

withdrawCallback

  function withdrawCallback() external

Function, that ERC20RootVault calling after withdraw

Structs

struct ImmutableParams {
    address router;
    IERC20Vault erc20Vault;
    IUniV3Vault uniV3Vault;
    address[] tokens;
}
struct MutableParams {
    int24 priceImpactD6;
    int24 intervalWidth;
    int24 tickNeighborhood;
    int24 maxDeviationForVaultPool;
    uint32 timespanForAverageTick;
    uint256 amount0Desired;
    uint256 amount1Desired;
    uint256 swapSlippageD;
    uint256 swappingAmountsCoefficientD;
    uint256[] minSwapAmounts;
}
struct Interval {
    int24 lowerTick;
    int24 upperTick;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

TokensSwapped

  event TokensSwapped(uint256 amountIn, uint256 amountOut, uint256 tokenInIndex)

Emitted after a successful token swap

Parameters:

UpdateMutableParams

  event UpdateMutableParams(address origin, address sender, struct PulseStrategy.MutableParams mutableParams)

Emited when mutable parameters are successfully updated

Parameters:

Rebalance

  event Rebalance(address origin, address sender)

Emited when the rebalance is successfully completed

Parameters:

PositionMinted

  event PositionMinted(uint256 tokenId)

Emited when a new uniswap position is created

Parameters:

PositionBurned

  event PositionBurned(uint256 tokenId)

Emited when a uniswap position is burned

Parameters:

PulseStrategyV2

Inherits from DefaultAccessControlLateInit, AccessControlEnumerable, AccessControl, ERC165, Context, Multicall, ContractMeta

Functions

constructor

  function constructor(contract INonfungiblePositionManager positionManager_) public

Parameters:

initialize

  function initialize(struct PulseStrategyV2.ImmutableParams immutableParams_, address admin) external

Parameters:

setForceRebalanceFlag

  function setForceRebalanceFlag(bool newValue) external

updateDesiredAmounts

  function updateDesiredAmounts(struct PulseStrategyV2.DesiredAmounts params) external

updateMutableParams

  function updateMutableParams(struct PulseStrategyV2.MutableParams mutableParams_) external

📕 updates mutable params of the strategy. Only the admin can call the function

Parameters:

rebalance

  function rebalance(uint256 deadline, bytes swapData, uint256 minAmountOutInCaseOfSwap) external

📕 Rebalancing goes like this:

  1. Function checks the current states of the pools, and if the volatility is significant, the transaction reverts.

  2. If necessary, a new position is minted on uniV3Vault, and the previous one is burned.

  3. Tokens on erc20Vault are swapped via AggregationRouterV5 so that the proportion matches the tokens on uniV3Vault.

  4. The strategy transfers all possible tokens from erc20Vault to uniV3Vault. Only users with administrator or operator roles can call the function.

Parameters:

checkMutableParams

  function checkMutableParams(struct PulseStrategyV2.MutableParams params, struct PulseStrategyV2.ImmutableParams immutableParams_) public

📕 checks mutable params according to strategy restrictions

Parameters:

checkImmutableParams

  function checkImmutableParams(struct PulseStrategyV2.ImmutableParams params) public

📕 checks immutable params according to strategy restrictions

Parameters:

checkTickDeviation

  function checkTickDeviation(struct PulseStrategyV2.MutableParams mutableParams_, contract IUniswapV3Pool vaultPool) public

📕 checks deviation of spot ticks of all pools in strategy from corresponding average ticks. If any deviation is large than maxDevation parameter for the pool, then the transaction will be reverted with a LIMIT_OVERFLOW error. If there are no observations 10 seconds ago in any of the considered pools, then the transaction will be reverted with an INVALID_STATE error.

Parameters:

formPositionWithSpotTickInCenter

  function formPositionWithSpotTickInCenter(struct PulseStrategyV2.MutableParams mutableParams_, int24 spotTick, int24 tickSpacing) public returns (struct PulseStrategyV2.Interval newInterval)

calculateNewPosition

  function calculateNewPosition(struct PulseStrategyV2.MutableParams mutableParams_, int24 spotTick, contract IUniswapV3Pool pool, uint256 uniV3Nft) public returns (struct PulseStrategyV2.Interval newInterval, bool neededNewInterval)

Parameters:

Return Values:

calculateTargetRatioOfToken1

  function calculateTargetRatioOfToken1(struct PulseStrategyV2.Interval interval, uint160 sqrtSpotPriceX96, uint256 spotPriceX96) public returns (uint256 targetRatioOfToken1X96)

📕 calculate target ratio of token 1 to total capital after rebalance

Parameters:

Return Values:

calculateAmountsForSwap

  function calculateAmountsForSwap(struct PulseStrategyV2.ImmutableParams immutableParams_, struct PulseStrategyV2.MutableParams mutableParams_, uint256 priceX96, uint256 targetRatioOfToken1X96) public returns (uint256 tokenInIndex, uint256 amountIn)

📕 notion link: https://www.notion.so/mellowprotocol/Swap-formula-53807cbf5c5641eda937dd1847d70f43 calculates the token that needs to be swapped and its amount to get the target ratio of tokens in the erc20Vault.

Parameters:

Return Values:

depositCallback

  function depositCallback() external

Function, that ERC20RootVault calling after deposit

withdrawCallback

  function withdrawCallback() external

Function, that ERC20RootVault calling after withdraw

Structs

struct ImmutableParams {
    IERC20Vault erc20Vault;
    IUniV3Vault uniV3Vault;
    address router;
    address[] tokens;
}
struct MutableParams {
    int24 priceImpactD6;
    int24 defaultIntervalWidth;
    int24 maxPositionLengthInTicks;
    int24 maxDeviationForVaultPool;
    uint32 timespanForAverageTick;
    uint256 neighborhoodFactorD;
    uint256 extensionFactorD;
    uint256 swapSlippageD;
    uint256 swappingAmountsCoefficientD;
    uint256[] minSwapAmounts;
}
struct DesiredAmounts {
    uint256 amount0Desired;
    uint256 amount1Desired;
}
struct Interval {
    int24 lowerTick;
    int24 upperTick;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

TokensSwapped

  event TokensSwapped(uint256 amountIn, uint256 amountOut, uint256 tokenInIndex)

Emitted after a successful token swap

Parameters:

UpdateMutableParams

  event UpdateMutableParams(address origin, address sender, struct PulseStrategyV2.MutableParams mutableParams)

Emited when mutable parameters are successfully updated

Parameters:

Rebalance

  event Rebalance(address origin, address sender)

Emited when the rebalance is successfully completed

Parameters:

PositionMinted

  event PositionMinted(uint256 tokenId)

Emited when a new uniswap position is created

Parameters:

PositionBurned

  event PositionBurned(uint256 tokenId)

Emited when a uniswap position is burned

Parameters:

QuickPulseStrategy

Inherits from DefaultAccessControlLateInit, AccessControlEnumerable, AccessControl, ERC165, Context, Multicall, ContractMeta

Functions

constructor

  function constructor(contract IAlgebraNonfungiblePositionManager positionManager_) public

Parameters:

initialize

  function initialize(struct QuickPulseStrategy.ImmutableParams immutableParams_, address admin) external

Parameters:

updateMutableParams

  function updateMutableParams(struct QuickPulseStrategy.MutableParams mutableParams_) external

📕 updates mutable params of the strategy. Only the admin can call the function

Parameters:

rebalance

  function rebalance(uint256 deadline, bytes swapData) external

📕 Rebalancing goes like this:

  1. Function checks the current states of the pools, and if the volatility is significant, the transaction reverts.

  2. If necessary, a new position is minted on quickSwapVault, and the previous one is burned.

  3. Tokens on erc20Vault are swapped via AggregationRouterV5 so that the proportion matches the tokens on quickSwapVault.

  4. The strategy transfers all possible tokens from erc20Vault to quickSwapVault. Only users with administrator or operator roles can call the function.

Parameters:

checkMutableParams

  function checkMutableParams(struct QuickPulseStrategy.MutableParams params) public

📕 checks mutable params according to strategy restrictions

Parameters:

checkImmutableParams

  function checkImmutableParams(struct QuickPulseStrategy.ImmutableParams params) public

📕 checks immutable params according to strategy restrictions

Parameters:

checkTickDeviation

  function checkTickDeviation(struct QuickPulseStrategy.MutableParams mutableParams_, contract IAlgebraPool vaultPool) public

📕 checks deviation of spot ticks of all pools in strategy from corresponding average ticks. If any deviation is large than maxDevation parameter for the pool, then the transaction will be reverted with a LIMIT_OVERFLOW error. If there are no observations 10 seconds ago in any of the considered pools, then the transaction will be reverted with an INVALID_STATE error.

Parameters:

calculateNewPosition

  function calculateNewPosition(struct QuickPulseStrategy.MutableParams mutableParams_, int24 spotTick, contract IAlgebraPool pool, uint256 positionNft) public returns (struct QuickPulseStrategy.Interval newInterval, bool neededNewInterval)

Parameters:

Return Values:

calculateTargetRatioOfToken1

  function calculateTargetRatioOfToken1(struct QuickPulseStrategy.Interval interval, uint160 sqrtSpotPriceX96, uint256 spotPriceX96) public returns (uint256 targetRatioOfToken1X96)

📕 calculate target ratio of token 1 to total capital after rebalance

Parameters:

Return Values:

calculateAmountsForSwap

  function calculateAmountsForSwap(struct QuickPulseStrategy.ImmutableParams immutableParams_, struct QuickPulseStrategy.MutableParams mutableParams_, uint256 priceX96, uint256 targetRatioOfToken1X96) public returns (uint256 tokenInIndex, uint256 amountIn)

📕 notion link: https://www.notion.so/mellowprotocol/Swap-formula-53807cbf5c5641eda937dd1847d70f43 calculates the token that needs to be swapped and its amount to get the target ratio of tokens in the erc20Vault.

Parameters:

Return Values:

depositCallback

  function depositCallback() external

Function, that ERC20RootVault calling after deposit

withdrawCallback

  function withdrawCallback() external

Function, that ERC20RootVault calling after withdraw

onERC721Received

⛽ 105K

  function onERC721Received(address, address, uint256, bytes) external returns (bytes4)

📕 Whenever an {IERC721} tokenId token is transferred to this contract via {IERC721-safeTransferFrom} by operator from from, this function is called. It must return its Solidity selector to confirm the token transfer. If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. The selector can be obtained in Solidity with IERC721.onERC721Received.selector.

Structs

struct ImmutableParams {
    address router;
    IERC20Vault erc20Vault;
    IQuickSwapVault quickSwapVault;
    address[] tokens;
}
struct MutableParams {
    int24 priceImpactD6;
    int24 intervalWidth;
    int24 tickNeighborhood;
    int24 maxDeviationForVaultPool;
    uint32 timespanForAverageTick;
    uint256 amount0Desired;
    uint256 amount1Desired;
    uint256 swapSlippageD;
    uint256 swappingAmountsCoefficientD;
    uint256[] minSwapAmounts;
}
struct Interval {
    int24 lowerTick;
    int24 upperTick;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

TokensSwapped

  event TokensSwapped(uint256 amountIn, uint256 amountOut, uint256 tokenInIndex)

Emitted after a successful token swap

Parameters:

UpdateMutableParams

  event UpdateMutableParams(address origin, address sender, struct QuickPulseStrategy.MutableParams mutableParams)

Emited when mutable parameters are successfully updated

Parameters:

Rebalance

  event Rebalance(address origin, address sender)

Emited when the rebalance is successfully completed

Parameters:

PositionMinted

  event PositionMinted(uint256 tokenId)

Emited when a new algebra position is created

Parameters:

PositionBurned

  event PositionBurned(uint256 tokenId)

Emited when a algebra position is burned

Parameters:

SinglePositionQuickSwapStrategy

Inherits from DefaultAccessControlLateInit, AccessControlEnumerable, AccessControl, ERC165, Context, Multicall, ContractMeta

Functions

constructor

  function constructor(contract IUniswapV3Factory uniswapV3Factory_, contract IAlgebraNonfungiblePositionManager algebraPositionManager_, contract SinglePositionStrategyHelper helper_) public

Parameters:

initialize

  function initialize(struct SinglePositionQuickSwapStrategy.ImmutableParams immutableParams_, address admin) external

Parameters:

updateMutableParams

  function updateMutableParams(struct SinglePositionQuickSwapStrategy.MutableParams mutableParams_) external

📕 updates mutable params of the strategy. Only the admin can call the function

Parameters:

rebalance

  function rebalance(uint256 deadline) external

📕 Rebalancing goes like this:

  1. Function checks the current states of the pools, and if the volatility is significant, the transaction reverts.

  2. If necessary, a new position is minted on quickSwapVault, and the previous one is burned.

  3. Tokens on erc20Vault are swapped via swapRouter so that the proportion matches the tokens on quickSwapVault.

  4. The strategy transfers all possible tokens from erc20Vault to quickSwapVault. Only users with administrator or operator roles can call the function.

Parameters:

calculateNewInterval

  function calculateNewInterval(struct SinglePositionQuickSwapStrategy.MutableParams mutableParams_, int24 tick, contract IAlgebraPool pool) public returns (int24 lowerTick, int24 upperTick)

📕 calculates a new interval according to the mutable params, the tickSpacing of the pool and the spot tick

Parameters:

Return Values:

checkMutableParams

  function checkMutableParams(struct SinglePositionQuickSwapStrategy.MutableParams params) public

📕 checks mutable params according to strategy restrictions

Parameters:

checkImmutableParams

  function checkImmutableParams(struct SinglePositionQuickSwapStrategy.ImmutableParams params) public

📕 checks immutable params according to strategy restrictions

Parameters:

checkTickDeviations

  function checkTickDeviations(struct SinglePositionQuickSwapStrategy.ImmutableParams immutableParams_, struct SinglePositionQuickSwapStrategy.MutableParams mutableParams_, contract IAlgebraPool vaultPool) public

📕 checks deviation of spot ticks of all pools in strategy from corresponding average ticks. If any deviation is large than maxDevation parameter for the pool, then the transaction will be reverted with a LIMIT_OVERFLOW error. If there are no observations 10 seconds ago in any of the considered pools, then the transaction will be reverted with an INVALID_STATE error.

Parameters:

calculateTargetRatioOfToken1

  function calculateTargetRatioOfToken1(struct SinglePositionQuickSwapStrategy.Interval interval, uint160 sqrtSpotPriceX96, uint256 spotPriceX96) public returns (uint256 targetRatioOfToken1X96)

📕 calculate target ratio of token 1 to total capital after rebalance

Parameters:

Return Values:

calculateAmountsForSwap

  function calculateAmountsForSwap(struct SinglePositionQuickSwapStrategy.ImmutableParams immutableParams_, struct SinglePositionQuickSwapStrategy.MutableParams mutableParams_, uint256 priceX96, uint256 targetRatioOfToken1X96) public returns (uint256 tokenInIndex, uint256 amountIn)

📕 notion link: https://www.notion.so/mellowprotocol/Swap-formula-53807cbf5c5641eda937dd1847d70f43 calculates the token that needs to be swapped and its amount to get the target ratio of tokens in the erc20Vault.

Parameters:

Return Values:

depositCallback

  function depositCallback() external

Function, that ERC20RootVault calling after deposit

withdrawCallback

  function withdrawCallback() external

Function, that ERC20RootVault calling after withdraw

Structs

struct ImmutableParams {
    address router;
    IERC20Vault erc20Vault;
    IQuickSwapVault quickSwapVault;
    address[] tokens;
}
struct MutableParams {
    uint24 feeTierOfPoolOfAuxiliaryAnd0Tokens;
    uint24 feeTierOfPoolOfAuxiliaryAnd1Tokens;
    int24 priceImpactD6;
    int24 intervalWidth;
    int24 tickNeighborhood;
    int24 maxDeviationForVaultPool;
    int24 maxDeviationForPoolOfAuxiliaryAnd0Tokens;
    int24 maxDeviationForPoolOfAuxiliaryAnd1Tokens;
    uint32 timespanForAverageTick;
    address auxiliaryToken;
    uint256 amount0Desired;
    uint256 amount1Desired;
    uint256 swapSlippageD;
    uint256[] minSwapAmounts;
}
struct Interval {
    int24 lowerTick;
    int24 upperTick;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

TokensSwapped

  event TokensSwapped(struct ISwapRouter.ExactInputParams swapParams, uint256 amountOut)

Emitted after a successful token swap

Parameters:

UpdateMutableParams

  event UpdateMutableParams(address origin, address sender, struct SinglePositionQuickSwapStrategy.MutableParams mutableParams)

Emited when mutable parameters are successfully updated

Parameters:

Rebalance

  event Rebalance(address origin, address sender)

Emited when the rebalance is successfully completed

Parameters:

PositionMinted

  event PositionMinted(uint256 tokenId)

Emited when a new uniswap position is created

Parameters:

PositionBurned

  event PositionBurned(uint256 tokenId)

Emited when a uniswap position is burned

Parameters:

SinglePositionStrategy

Inherits from DefaultAccessControlLateInit, AccessControlEnumerable, AccessControl, ERC165, Context, Multicall, ContractMeta

⛽ 7.31M

Functions

constructor

  function constructor(contract INonfungiblePositionManager positionManager_) public

Parameters:

Specs

  • ✅ creates contract

initialize

⛽ 671K

  function initialize(struct SinglePositionStrategy.ImmutableParams immutableParams_, address admin) external

Parameters:

updateMutableParams

⛽ 120K (89K - 245K)

  function updateMutableParams(struct SinglePositionStrategy.MutableParams mutableParams_) external

📕 updates mutable params of the strategy. Only the admin can call the function

Parameters:

rebalance

⛽ 1.16M (804K - 1.38M)

  function rebalance(uint256 deadline) external

📕 Rebalancing goes like this:

  1. Function checks the current states of the pools, and if the volatility is significant, the transaction reverts.

  2. If necessary, a new position is minted on uniV3Vault, and the previous one is burned.

  3. Tokens on erc20Vault are swapped via swapRouter so that the proportion matches the tokens on uniV3Vault.

  4. The strategy transfers all possible tokens from erc20Vault to uniV3Vault. Only users with administrator or operator roles can call the function.

Parameters:

Specs

  • ✅ works correctly

calculateNewInterval

  function calculateNewInterval(struct SinglePositionStrategy.MutableParams mutableParams_, int24 tick, contract IUniswapV3Pool pool) public returns (int24 lowerTick, int24 upperTick)

📕 calculates a new interval according to the mutable params, the tickSpacing of the pool and the spot tick

Parameters:

Return Values:

checkMutableParams

  function checkMutableParams(struct SinglePositionStrategy.MutableParams params, struct SinglePositionStrategy.ImmutableParams immutableParams_) public

📕 checks mutable params according to strategy restrictions

Parameters:

checkImmutableParams

  function checkImmutableParams(struct SinglePositionStrategy.ImmutableParams params) public

📕 checks immutable params according to strategy restrictions

Parameters:

checkTickDeviations

  function checkTickDeviations(struct SinglePositionStrategy.ImmutableParams immutableParams_, struct SinglePositionStrategy.MutableParams mutableParams_, contract IUniswapV3Pool vaultPool) public

📕 checks deviation of spot ticks of all pools in strategy from corresponding average ticks. If any deviation is large than maxDevation parameter for the pool, then the transaction will be reverted with a LIMIT_OVERFLOW error. If there are no observations 10 seconds ago in any of the considered pools, then the transaction will be reverted with an INVALID_STATE error.

Parameters:

calculateTargetRatioOfToken1

  function calculateTargetRatioOfToken1(struct SinglePositionStrategy.Interval interval, uint160 sqrtSpotPriceX96, uint256 spotPriceX96) public returns (uint256 targetRatioOfToken1X96)

📕 calculate target ratio of token 1 to total capital after rebalance

Parameters:

Return Values:

calculateAmountsForSwap

  function calculateAmountsForSwap(struct SinglePositionStrategy.ImmutableParams immutableParams_, struct SinglePositionStrategy.MutableParams mutableParams_, uint256 priceX96, uint256 targetRatioOfToken1X96) public returns (uint256 tokenInIndex, uint256 amountIn)

📕 notion link: https://www.notion.so/mellowprotocol/Swap-formula-53807cbf5c5641eda937dd1847d70f43 calculates the token that needs to be swapped and its amount to get the target ratio of tokens in the erc20Vault.

Parameters:

Return Values:

depositCallback

  function depositCallback() external

Function, that ERC20RootVault calling after deposit

withdrawCallback

  function withdrawCallback() external

Function, that ERC20RootVault calling after withdraw

Structs

struct ImmutableParams {
    address router;
    IERC20Vault erc20Vault;
    IUniV3Vault uniV3Vault;
    address[] tokens;
}
struct MutableParams {
    uint24 feeTierOfPoolOfAuxiliaryAnd0Tokens;
    uint24 feeTierOfPoolOfAuxiliaryAnd1Tokens;
    int24 priceImpactD6;
    int24 intervalWidth;
    int24 tickNeighborhood;
    int24 maxDeviationForVaultPool;
    int24 maxDeviationForPoolOfAuxiliaryAnd0Tokens;
    int24 maxDeviationForPoolOfAuxiliaryAnd1Tokens;
    uint32 timespanForAverageTick;
    address auxiliaryToken;
    uint256 amount0Desired;
    uint256 amount1Desired;
    uint256 swapSlippageD;
    uint256[] minSwapAmounts;
}
struct Interval {
    int24 lowerTick;
    int24 upperTick;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

TokensSwapped

  event TokensSwapped(struct ISwapRouter.ExactInputParams swapParams, uint256 amountOut)

Emitted after a successful token swap

Parameters:

UpdateMutableParams

  event UpdateMutableParams(address origin, address sender, struct SinglePositionStrategy.MutableParams mutableParams)

Emited when mutable parameters are successfully updated

Parameters:

Rebalance

  event Rebalance(address origin, address sender)

Emited when the rebalance is successfully completed

Parameters:

PositionMinted

  event PositionMinted(uint256 tokenId)

Emited when a new uniswap position is created

Parameters:

PositionBurned

  event PositionBurned(uint256 tokenId)

Emited when a uniswap position is burned

Parameters:

BatchCall

⛽ 435K

batchcall

⛽ 23K

  function batchcall(address[] targets, bytes[] data) external returns (bytes[] results)

Specs

  • ✅ returns results

  • ✅ edge cases: when arrays have different lengths reverts with INVL

  • ✅ edge cases: when targets arrays not only of contracts reverts with "Address: delegate call to non-contract"

ContractMeta

contractName

  function contractName() external returns (string)

contractNameBytes

  function contractNameBytes() external returns (bytes32)

contractVersion

  function contractVersion() external returns (string)

contractVersionBytes

  function contractVersionBytes() external returns (bytes32)

DefaultAccessControl

Inherits from AccessControlEnumerable, AccessControl, ERC165, Context

⛽ 1.35M

This is a default access control with 3 roles:

  • ADMIN: allowed to do anything

  • ADMIN_DELEGATE: allowed to do anything except assigning ADMIN and ADMIN_DELEGATE roles

  • OPERATOR: low-privileged role, generally keeper or some other bot

Functions

constructor

  function constructor(address admin) public

Creates a new contract.

Parameters:

isAdmin

  function isAdmin(address sender) public returns (bool)

Checks if the address is ADMIN or ADMIN_DELEGATE.

Parameters:

Return Values:

isOperator

  function isOperator(address sender) public returns (bool)

Checks if the address is OPERATOR.

Parameters:

Return Values:

Structs

struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

DefaultAccessControlLateInit

Inherits from AccessControlEnumerable, AccessControl, ERC165, Context

⛽ 1.25M

This is a default access control with 3 roles:

  • ADMIN: allowed to do anything

  • ADMIN_DELEGATE: allowed to do anything except assigning ADMIN and ADMIN_DELEGATE roles

  • OPERATOR: low-privileged role, generally keeper or some other bot

Functions

isAdmin

  function isAdmin(address sender) public returns (bool)

Checks that the address is contract admin.

Parameters:

Return Values:

Specs

  • ✅ returns true if sender is an admin, false otherwise

isOperator

  function isOperator(address sender) public returns (bool)

Checks that the address is contract admin.

Parameters:

Return Values:

Specs

  • ✅ returns true if sender is an operator, false otherwise

init

⛽ 301K

  function init(address admin) public

Initializes a new contract with roles and single ADMIN.

Parameters:

Structs

struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

DefaultProxy

Inherits from TransparentUpgradeableProxy, ERC1967Proxy, ERC1967Upgrade, Proxy

constructor

  function constructor(address _logic, address admin_, bytes _data) public

DefaultProxyAdmin

Inherits from ProxyAdmin, Ownable, Context

ERC20RootVaultHelper

⛽ 445K

getTvlToken0

  function getTvlToken0(uint256[] tvls, address[] tokens, contract IOracle oracle) external returns (uint256 tvl0)

ERC20Token

⛽ 1.01M

DOMAIN_SEPARATOR

  function DOMAIN_SEPARATOR() public returns (bytes32)

Specs

  • ✅ returns domaint separator

approve

  function approve(address spender, uint256 amount) public returns (bool)

Specs

  • ✅ allows sender to transfer spender an amount and emits Approval

transfer

  function transfer(address to, uint256 amount) public returns (bool)

Specs

  • ✅ transfers amount from msg.sender to to

  • ✅ rom transfers amount from from to to if allowed

transferFrom

  function transferFrom(address from, address to, uint256 amount) public returns (bool)

Specs

  • ✅ transfers amount from from to to if allowed

permit

  function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public

Specs

  • ✅ emits Approval

  • ✅ edge cases: when deadline less than current timestamp reverts with TS

  • ✅ edge cases: when incorrect signature reverts with FRB

GearboxHelper

Functions

setParameters

  function setParameters(contract ICreditFacade creditFacade_, contract ICreditManagerV2 creditManager_, address curveAdapter_, address convexAdapter_, address primaryToken_, address depositToken_, uint256 nft_) external

verifyInstances

  function verifyInstances() external returns (int128 primaryIndex, address convexOutputToken, uint256 poolId)

calculateEarnedCvxAmountByEarnedCrvAmount

  function calculateEarnedCvxAmountByEarnedCrvAmount(uint256 crvAmount, address cvxTokenAddress) public returns (uint256)

calculateClaimableRewards

  function calculateClaimableRewards(address creditAccount, address vaultGovernance) public returns (uint256)

calculateDesiredTotalValue

  function calculateDesiredTotalValue(address creditAccount, address vaultGovernance, uint256 marginalFactorD9) external returns (uint256 expectedAllAssetsValue, uint256 currentAllAssetsValue)

calcConvexTokensToWithdraw

  function calcConvexTokensToWithdraw(uint256 desiredValueNominatedUnderlying, address creditAccount, address convexOutputToken) public returns (uint256)

calcRateRAY

  function calcRateRAY(address tokenFrom, address tokenTo) public returns (uint256)

calculateAmountInMaximum

  function calculateAmountInMaximum(address fromToken, address toToken, uint256 amount, uint256 maxSlippageD9) public returns (uint256)

createUniswapMulticall

  function createUniswapMulticall(address tokenFrom, address tokenTo, uint256 fee, address adapter, uint256 slippage) public returns (struct MultiCall)

checkNecessaryDepositExchange

  function checkNecessaryDepositExchange(uint256 expectedMaximalDepositTokenValueNominatedUnderlying, address vaultGovernance, address creditAccount) public

claimRewards

  function claimRewards(address vaultGovernance, address creditAccount, address convexOutputToken) public

withdrawFromConvex

  function withdrawFromConvex(uint256 amount, address vaultGovernance, int128 primaryIndex) public

depositToConvex

  function depositToConvex(struct MultiCall debtManagementCall, struct IGearboxVaultGovernance.DelayedProtocolParams protocolParams, uint256 poolId, int128 primaryIndex) public

adjustPosition

  function adjustPosition(uint256 expectedAllAssetsValue, uint256 currentAllAssetsValue, address vaultGovernance, uint256 marginalFactorD9, int128 primaryIndex, uint256 poolId, address convexOutputToken, address creditAccount_) external

swapExactOutput

  function swapExactOutput(address fromToken, address toToken, uint256 amount, uint256 untouchableSum, address vaultGovernance, address creditAccount) external

pullFromAddress

  function pullFromAddress(uint256 amount, address vaultGovernance) external returns (uint256[] actualAmounts)

openCreditAccount

  function openCreditAccount(address creditAccount, address vaultGovernance, uint256 marginalFactorD9) external

Events

CreditAccountOpened

  event CreditAccountOpened(address origin, address sender, address creditAccount)

Emitted when a credit account linked to this vault is opened in Gearbox

Parameters:

PositionAdjusted

  event PositionAdjusted(address origin, address sender, uint256 newTotalAssetsValue)

Emitted when an adjusment of the position made in Gearbox

Parameters:

HStrategyHelper

⛽ 3.26M

calculateExpectedRatios

  function calculateExpectedRatios(struct HStrategy.DomainPositionParams domainPositionParams) external returns (struct HStrategy.ExpectedRatios ratios)

calculates the ratios of the capital on all vaults using price from the oracle

Parameters:

Return Values:

calculateMissingTokenAmounts

  function calculateMissingTokenAmounts(contract IIntegrationVault moneyVault, struct HStrategy.TokenAmounts expectedTokenAmounts, struct HStrategy.DomainPositionParams domainPositionParams, uint128 liquidity) external returns (struct HStrategy.TokenAmounts missingTokenAmounts)

calculates amount of missing tokens for uniV3 and money vaults

Parameters:

Return Values:

calculateExtraTokenAmountsForUniV3Vault

  function calculateExtraTokenAmountsForUniV3Vault(struct HStrategy.TokenAmounts expectedTokenAmounts, struct HStrategy.DomainPositionParams domainPositionParams) external returns (uint256[] tokenAmounts)

calculates extra tokens on uniV3 vault

Parameters:

Return Values:

calculateExtraTokenAmountsForMoneyVault

  function calculateExtraTokenAmountsForMoneyVault(contract IIntegrationVault moneyVault, struct HStrategy.TokenAmounts expectedTokenAmounts) external returns (uint256[] tokenAmounts)

calculates extra tokens on money vault

Parameters:

Return Values:

calculateExpectedTokenAmountsByExpectedRatios

  function calculateExpectedTokenAmountsByExpectedRatios(struct HStrategy.ExpectedRatios expectedRatios, struct HStrategy.TokenAmountsInToken0 expectedTokenAmountsInToken0, struct HStrategy.DomainPositionParams domainPositionParams, contract UniV3Helper uniV3Helper) external returns (struct HStrategy.TokenAmounts amounts)

calculates expected amounts of tokens after rebalance

Parameters:

Return Values:

calculateCurrentTokenAmounts

  function calculateCurrentTokenAmounts(contract IIntegrationVault erc20Vault, contract IIntegrationVault moneyVault, struct HStrategy.DomainPositionParams params) external returns (struct HStrategy.TokenAmounts amounts)

calculates current amounts of tokens

Parameters:

Return Values:

calculateCurrentCapitalInToken0

  function calculateCurrentCapitalInToken0(struct HStrategy.DomainPositionParams params, struct HStrategy.TokenAmounts currentTokenAmounts) external returns (uint256 capital)

calculates current capital of the strategy in token0

Parameters:

Return Values:

calculateExpectedTokenAmountsInToken0

  function calculateExpectedTokenAmountsInToken0(uint256 totalCapitalInToken0, struct HStrategy.ExpectedRatios expectedRatios, struct HStrategy.RatioParams ratioParams_) external returns (struct HStrategy.TokenAmountsInToken0 amounts)

calculates expected capitals on the vaults after rebalance

Parameters:

Return Values:

swapNeeded

  function swapNeeded(struct HStrategy.TokenAmounts currentTokenAmounts, struct HStrategy.TokenAmounts expectedTokenAmounts, struct HStrategy.RatioParams ratioParams, struct HStrategy.DomainPositionParams domainPositionParams) external returns (bool needed)

return true if the token swap is needed. It is needed if we cannot mint a new position without it

Parameters:

Return Values:

tokenRebalanceNeeded

  function tokenRebalanceNeeded(struct HStrategy.TokenAmounts currentTokenAmounts, struct HStrategy.TokenAmounts expectedTokenAmounts, struct HStrategy.RatioParams ratioParams) external returns (bool needed)

returns true if the rebalance between assets on different vaults is needed

Parameters:

Return Values:

calculateAndCheckDomainPositionParams

  function calculateAndCheckDomainPositionParams(int24 tick, struct HStrategy.StrategyParams strategyParams_, uint256 uniV3Nft, contract INonfungiblePositionManager positionManager_) external returns (struct HStrategy.DomainPositionParams params)

Parameters:

checkSpotTickDeviationFromAverage

  function checkSpotTickDeviationFromAverage(int24 tick, address pool_, struct HStrategy.OracleParams oracleParams_, contract UniV3Helper uniV3Helper) external

Parameters:

calculateNewPositionTicks

  function calculateNewPositionTicks(int24 spotTick, struct HStrategy.StrategyParams strategyParams_) external returns (int24 lowerTick, int24 upperTick)

Parameters:

Return Values:

calculateExpectedTokenAmounts

  function calculateExpectedTokenAmounts(struct HStrategy.TokenAmounts currentTokenAmounts, struct HStrategy.DomainPositionParams domainPositionParams, contract HStrategyHelper hStrategyHelper_, contract UniV3Helper uniV3Helper, struct HStrategy.RatioParams ratioParams) external returns (struct HStrategy.TokenAmounts expectedTokenAmounts)

Parameters:

Return Values:

LStrategyHelper

⛽ 1.5M

constructor

  function constructor(address cowswap_) public

checkOrder

  function checkOrder(struct GPv2Order.Data order, bytes uuid, address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut, uint256 deadline, address erc20Vault, uint256 fee) external

tickFromPriceX96

  function tickFromPriceX96(uint256 priceX96) external returns (int24)

MultiPoolHStrategyRebalancer

Inherits from DefaultAccessControlLateInit, AccessControlEnumerable, AccessControl, ERC165, Context

⛽ 7.09M

Functions

constructor

  function constructor(contract INonfungiblePositionManager positionManager_) public

constructs a rebalancer

Parameters:

initialize

  function initialize(address strategy) external

initializes the rebalancer

Parameters:

createRebalancer

  function createRebalancer(address strategy) external returns (contract MultiPoolHStrategyRebalancer rebalancer)

creates the clone of the rebalancer

Parameters:

Return Values:

getTvls

  function getTvls(struct MultiPoolHStrategyRebalancer.StrategyData data) public returns (struct MultiPoolHStrategyRebalancer.Tvls tvls)

Parameters:

processRebalance

  function processRebalance(struct MultiPoolHStrategyRebalancer.StrategyData data, struct MultiPoolHStrategyRebalancer.Restrictions restrictions) external returns (struct MultiPoolHStrategyRebalancer.Restrictions actualAmounts)

Parameters:

calculateExpectedAmounts

  function calculateExpectedAmounts(struct MultiPoolHStrategyRebalancer.StrategyData data, uint160 sqrtPriceX96, uint256 totalToken0, uint256 totalToken1) public returns (uint256[] moneyExpected, uint256[][] uniV3Expected, uint256 expectedAmountOfToken0)

Parameters:

calculateNewPosition

  function calculateNewPosition(struct MultiPoolHStrategyRebalancer.StrategyData data, int24 tick) public returns (int24 newShortLowerTick, int24 newShortUpperTick)

Parameters:

Structs

struct StrategyData {
    int24 halfOfShortInterval;
    int24 domainLowerTick;
    int24 domainUpperTick;
    int24 shortLowerTick;
    int24 shortUpperTick;
    int24 maxTickDeviation;
    uint32 averageTickTimespan;
    IERC20Vault erc20Vault;
    IIntegrationVault moneyVault;
    IUniswapV3Pool swapPool;
    address router;
    uint256 amount0ForMint;
    uint256 amount1ForMint;
    uint256 erc20CapitalRatioD;
    uint256[] uniV3Weights;
    address[] tokens;
    IUniV3Vault[] uniV3Vaults;
}
struct Tvls {
    uint256[] money;
    uint256[][] uniV3;
    uint256[] erc20;
    uint256[] total;
    uint256[] totalUniV3;
}
struct SqrtRatios {
    uint160 sqrtShortLowerX96;
    uint160 sqrtShortUpperX96;
    uint160 sqrtDomainLowerX96;
    uint160 sqrtDomainUpperX96;
}
struct Restrictions {
    int24 newShortLowerTick;
    int24 newShortUpperTick;
    int256[] swappedAmounts;
    uint256[][] drainedAmounts;
    uint256[][] pulledToUniV3;
    uint256[][] pulledFromUniV3;
    uint256 deadline;
}
struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

PositionsMinted

  event PositionsMinted(uint256[] uniV3Nfts)

Emitted when new short positions minted in uniV3Vaults

Parameters:

PositionsBurned

  event PositionsBurned(uint256[] uniV3Nfts)

Emitted when old short positions burned in uniV3Vaults

Parameters:

TokensSwapped

  event TokensSwapped(struct ISwapRouter.ExactInputSingleParams swapParams, uint256 amountOut)

Emitted when a swap is called on the router

Parameters:

PulseStrategyHelper

getStrategyParams

  function getStrategyParams(contract PulseStrategy strategy) public returns (struct PulseStrategy.ImmutableParams immutableParams, struct PulseStrategy.MutableParams mutableParams)

calculateAmountForSwap

  function calculateAmountForSwap(contract PulseStrategy strategy) public returns (uint256 amountIn, address from, address to, contract IERC20Vault erc20Vault)

PulseStrategyV2Helper

getStrategyParams

  function getStrategyParams(contract PulseStrategyV2 strategy) public returns (struct PulseStrategyV2.ImmutableParams immutableParams, struct PulseStrategyV2.MutableParams mutableParams)

calculateAmountForSwap

  function calculateAmountForSwap(contract PulseStrategyV2 strategy) public returns (uint256 amountIn, address from, address to, contract IERC20Vault erc20Vault)

QuickPulseStrategyHelper

getStrategyParams

  function getStrategyParams(contract QuickPulseStrategy strategy) public returns (struct QuickPulseStrategy.ImmutableParams immutableParams, struct QuickPulseStrategy.MutableParams mutableParams)

calculateAmountForSwap

  function calculateAmountForSwap(contract QuickPulseStrategy strategy) public returns (uint256 amountIn, address from, address to, contract IERC20Vault erc20Vault)

QuickSwapHelper

constructor

  function constructor(contract IAlgebraNonfungiblePositionManager positionManager_, address quickToken_, address dQuickToken_) public

calculateTvl

  function calculateTvl(uint256 nft, struct IQuickSwapVaultGovernance.StrategyParams strategyParams, contract IFarmingCenter farmingCenter, address token0) public returns (uint256[] tokenAmounts)

liquidityToTokenAmounts

  function liquidityToTokenAmounts(uint256 nft, uint160 sqrtRatioX96, uint128 liquidity) public returns (uint256 amount0, uint256 amount1)

tokenAmountsToLiquidity

  function tokenAmountsToLiquidity(uint256 nft, uint160 sqrtRatioX96, uint256[] amounts) public returns (uint128 liquidity)

tokenAmountsToMaxLiquidity

  function tokenAmountsToMaxLiquidity(uint256 nft, uint160 sqrtRatioX96, uint256[] amounts) public returns (uint128 liquidity)

calculateLiquidityToPull

  function calculateLiquidityToPull(uint256 nft, uint160 sqrtRatioX96, uint256[] tokenAmounts) public returns (uint128 liquidity)

increaseCumulative

  function increaseCumulative(uint32 currentTimestamp, contract IAlgebraEternalVirtualPool virtualPool) public returns (uint256 deltaTotalRewardGrowth0, uint256 deltaTotalRewardGrowth1)

calculateInnerFeesGrow

  function calculateInnerFeesGrow(contract IAlgebraEternalVirtualPool virtualPool, int24 tickLower, int24 tickUpper) public returns (uint256 virtualPoolInnerRewardGrowth0, uint256 virtualPoolInnerRewardGrowth1)

calculateCollectableRewards

  function calculateCollectableRewards(contract IAlgebraEternalFarming farming, struct IIncentiveKey.IncentiveKey key, uint256 nft) public returns (uint256 rewardAmount, uint256 bonusRewardAmount)

convertTokenToUnderlying

  function convertTokenToUnderlying(uint256 amount, address from, address to, uint32 timespan) public returns (uint256)

SinglePositionStrategyHelper

checkUniV3PoolState

  function checkUniV3PoolState(address pool, int24 maxDeviation, uint32 timespan) public

checkAlgebraPoolState

  function checkAlgebraPoolState(address pool, int24 maxDeviation, uint32 timespan) public

UniV3Helper

⛽ 2.82M

constructor

  function constructor(contract INonfungiblePositionManager positionManager_) public

liquidityToTokenAmounts

  function liquidityToTokenAmounts(uint128 liquidity, contract IUniswapV3Pool pool, uint256 uniV3Nft) external returns (uint256[] tokenAmounts)

Specs

  • ✅ returns correct vaulues for type(uint128).max

tokenAmountsToLiquidity

  function tokenAmountsToLiquidity(uint256[] tokenAmounts, contract IUniswapV3Pool pool, uint256 uniV3Nft) external returns (uint128 liquidity)

tokenAmountsToMaximalLiquidity

  function tokenAmountsToMaximalLiquidity(uint160 sqrtRatioX96, int24 tickLower, int24 tickUpper, uint256 amount0, uint256 amount1) external returns (uint128 liquidity)

getPoolByNft

  function getPoolByNft(uint256 uniV3Nft) public returns (contract IUniswapV3Pool pool)

📕 returns with "Invalid Token ID" for non-existent nfts

getFeesByNft

  function getFeesByNft(uint256 uniV3Nft) external returns (uint256 fees0, uint256 fees1)

📕 returns with "Invalid Token ID" for non-existent nfts

calculateTvlBySqrtPriceX96

  function calculateTvlBySqrtPriceX96(uint256 uniV3Nft, uint160 sqrtPriceX96) public returns (uint256[] tokenAmounts)

📕 returns with "Invalid Token ID" for non-existent nfts

calculateTvlByMinMaxPrices

  function calculateTvlByMinMaxPrices(uint256 uniV3Nft, uint256 minPriceX96, uint256 maxPriceX96) external returns (uint256[] minTokenAmounts, uint256[] maxTokenAmounts)

📕 returns with "Invalid Token ID" for non-existent nfts

getTickDeviationForTimeSpan

  function getTickDeviationForTimeSpan(int24 tick, address pool_, uint32 secondsAgo) external returns (bool withFail, int24 deviation)

Specs

  • ✅ returns withFail=true if there is no observation in the pool that was not made before secondsAgo

getPositionTokenAmountsByCapitalOfToken0

  function getPositionTokenAmountsByCapitalOfToken0(uint256 lowerPriceSqrtX96, uint256 upperPriceSqrtX96, uint256 spotPriceForSqrtFormulasX96, uint256 spotPriceX96, uint256 capital) external returns (uint256 token0Amount, uint256 token1Amount)

📕 calculates the distribution of tokens that can be added to the position after swap for given capital in token 0

Specs

  • ✅ test uniV3Helper, borders: -600 0

  • ✅ test uniV3Helper, borders: 600 1200

  • ✅ test uniV3Helper, borders: -600 600

WhiteList

Inherits from DefaultAccessControl, AccessControlEnumerable, AccessControl, ERC165, Context

⛽ 2.49M

Functions

constructor

  function constructor(address admin) public

deposit

⛽ 483K

  function deposit(contract IERC20RootVault vault, uint256[] tokenAmounts, uint256 minLpTokens, bytes vaultOptions, bytes32[] proof) external returns (uint256[] actualTokenAmounts)

Specs

  • ✅ works correctly

  • ✅ reverts on wrong address

updateRoot

⛽ 47K

  function updateRoot(bytes32 root_) external

Structs

struct RoleData {
    mapping(address => bool) members;
    bytes32 adminRole;
}

Events

Deposit

  event Deposit(address from, address to, address[] tokens, uint256[] actualTokenAmounts, uint256 lpTokenMinted)

Emitted when liquidity is deposited

Parameters:

AllowAllValidator

Inherits from Validator, BaseValidator, ERC165, ContractMeta

⛽ 851K

Functions

constructor

  function constructor(contract IProtocolGovernance protocolGovernance_) public

Specs

  • ✅ deploys a new contract

validate

  function validate(address, address, uint256, bytes4, bytes) external

Specs

  • ✅ successful validate

Structs

struct ValidatorParams {
    IProtocolGovernance protocolGovernance;
}

BaseValidator

Functions

constructor

  function constructor(contract IProtocolGovernance protocolGovernance) public

stagedValidatorParams

  function stagedValidatorParams() external returns (struct IBaseValidator.ValidatorParams)

Validator params staged to commit.

stagedValidatorParamsTimestamp

  function stagedValidatorParamsTimestamp() external returns (uint256)

Timestamp after which validator params can be committed.

validatorParams

  function validatorParams() external returns (struct IBaseValidator.ValidatorParams)

Current validator params.

stageValidatorParams

  function stageValidatorParams(struct IBaseValidator.ValidatorParams newParams) external

Stages params that could have been committed after governance delay expires.

Parameters:

commitValidatorParams

  function commitValidatorParams() external

Commits staged params

Structs

struct ValidatorParams {
    IProtocolGovernance protocolGovernance;
}

Events

StagedValidatorParams

  event StagedValidatorParams(address origin, address sender, struct IBaseValidator.ValidatorParams newParams, uint256 when)

Emitted when new params are staged for commit

Parameters:

CommittedValidatorParams

  event CommittedValidatorParams(address origin, address sender, struct IBaseValidator.ValidatorParams params)

Emitted when new params are staged for commit

Parameters:

CowswapValidator

Inherits from Validator, BaseValidator, ERC165, ContractMeta

⛽ 909K

Functions

constructor

  function constructor(contract IProtocolGovernance protocolGovernance_) public

Specs

  • ✅ deploys a new contract

validate

  function validate(address, address, uint256, bytes4 selector, bytes) external

Specs

  • ✅ successful validate

  • ✅ edge cases: when selector is not 0xec6cb13f reverts with INVS

Structs

struct ValidatorParams {
    IProtocolGovernance protocolGovernance;
}

CurveValidator

Inherits from Validator, BaseValidator, ERC165, ContractMeta

⛽ 1.14M

Functions

constructor

  function constructor(contract IProtocolGovernance protocolGovernance_) public

Specs

  • ✅ deploys a new contract

validate

  function validate(address, address addr, uint256, bytes4 selector, bytes data) external

Specs

  • ✅ successful validate

  • ✅ edge cases: when selector is not 0x3df02124 reverts with INVS

  • ✅ edge cases: when token ids are equal reverts with INV

  • ✅ edge cases: when not a vault token reverts with INVTO

  • ✅ edge cases: when pool has no approve permission reverts with FRB

Structs

struct ValidatorParams {
    IProtocolGovernance protocolGovernance;
}

ERC20Validator

Inherits from Validator, BaseValidator, ERC165, ContractMeta

⛽ 1.14M

Functions

constructor

  function constructor(contract IProtocolGovernance protocolGovernance_) public

Specs

  • ✅ deploys a new contract

validate

  function validate(address sender, address addr, uint256 value, bytes4 selector, bytes data) external

Specs

  • ✅ successful validate, spender can approve

  • ✅ successful validate, sender is trusted strategy

  • ✅ edge cases: when value is not zero reverts with INV

  • ✅ edge cases: when selector is not 0x095ea7b3 reverts with INVS

  • ✅ edge cases: when no transfer permission reverts with FRB

  • ✅ edge cases: when no approve permission reverts with FRB

Structs

struct ValidatorParams {
    IProtocolGovernance protocolGovernance;
}

QuickSwapValidator

Inherits from Validator, BaseValidator, ERC165, ContractMeta

Functions

constructor

  function constructor(contract IProtocolGovernance protocolGovernance_, address swapRouter_, contract IAlgebraFactory factory_) public

validate

  function validate(address, address addr, uint256 value, bytes4 selector, bytes data) external

Structs

struct ValidatorParams {
    IProtocolGovernance protocolGovernance;
}

UniV2Validator

Inherits from Validator, BaseValidator, ERC165, ContractMeta

⛽ 1.58M

Functions

constructor

  function constructor(contract IProtocolGovernance protocolGovernance_, address swapRouter_, contract IUniswapV2Factory factory_) public

Specs

  • ✅ deploys a new contract

validate

  function validate(address, address addr, uint256 value, bytes4 selector, bytes data) external

Specs

  • ✅ selector is 0x7ff36ab5 or 0xfb3bdb41 successful validate

  • ✅ selector is 0x7ff36ab5 or 0xfb3bdb41 edge cases: when addr is not swap reverts with INVTR

  • ✅ selector is 0x7ff36ab5 or 0xfb3bdb41 edge cases: when selector is wrong reverts with INVS

  • ✅ selector is 0x7ff36ab5 or 0xfb3bdb41 edge cases: when path is too small reverts with INVL

  • ✅ selector is 0x7ff36ab5 or 0xfb3bdb41 edge cases: when not a vault token reverts with INVTO

  • ✅ selector is 0x7ff36ab5 or 0xfb3bdb41 edge cases: when tokens are the same reverts with INVTO

  • ✅ selector is 0x7ff36ab5 or 0xfb3bdb41 edge cases: when pool has no approve permission reverts with FRB

  • ✅ selector is 0x7ff36ab5 or 0xfb3bdb41 edge cases: when sender is not a reciever reverts

  • ✅ selector is one of: 0x4a25d94a, 0x18cbafe5, 0x38ed1739, 0x8803dbee successful validate

  • ✅ selector is one of: 0x4a25d94a, 0x18cbafe5, 0x38ed1739, 0x8803dbee edge cases: when value is not zero reverts with INV

  • ✅ selector is one of: 0x4a25d94a, 0x18cbafe5, 0x38ed1739, 0x8803dbee edge cases: when sender is not reciever reverts

  • ✅ selector is one of: 0x4a25d94a, 0x18cbafe5, 0x38ed1739, 0x8803dbee edge cases: when path too small reverts with INVL

  • ✅ selector is one of: 0x4a25d94a, 0x18cbafe5, 0x38ed1739, 0x8803dbee edge cases: when not a vault token reverts with INVTO

  • ✅ selector is one of: 0x4a25d94a, 0x18cbafe5, 0x38ed1739, 0x8803dbee edge cases: when tokens are the same reverts with INVTO

  • ✅ selector is one of: 0x4a25d94a, 0x18cbafe5, 0x38ed1739, 0x8803dbee edge cases: when pool has no approve permission reverts with FRB

Structs

struct TokenInput {
    uint256 amount;
    uint256 amountMax;
    address[] path;
    address to;
    uint256 deadline;
}
struct EthInput {
    uint256 amountMax;
    address[] path;
    address to;
    uint256 deadline;
}
struct ValidatorParams {
    IProtocolGovernance protocolGovernance;
}

UniV3Validator

Inherits from Validator, BaseValidator, ERC165, ContractMeta

⛽ 1.75M

Functions

constructor

  function constructor(contract IProtocolGovernance protocolGovernance_, address swapRouter_, contract IUniswapV3Factory factory_) public

Specs

  • ✅ deploys a new contract

validate

  function validate(address, address addr, uint256 value, bytes4 selector, bytes data) external

Specs

  • ✅ edge cases: if addr is not swap reverts with INVTR

  • ✅ edge cases: if value is not zero reverts with INV

  • ✅ edge cases: if selector is wrong reverts with INVS

  • ✅ selector is 0x414bf389 successful validate

  • ✅ selector is 0x414bf389 edge cases: if recipient is not sender reverts with INVTR

  • ✅ selector is 0x414bf389 edge cases: if not a vault token reverts with INVTO

  • ✅ selector is 0x414bf389 edge cases: if tokens are the same reverts with INVTO

  • ✅ selector is 0x414bf389 edge cases: if pool has no permisson reverts with FRB

  • ✅ selector is 0xdb3e2198 successfull validate

  • ✅ selector is 0xdb3e2198 edge cases: if recipient is not sender reverts with INVTR

  • ✅ selector is 0xdb3e2198 edge cases: if not a vault token reverts with INVTO

  • ✅ selector is 0xdb3e2198 edge cases: if tokens are the same reverts with INVTO

  • ✅ selector is 0xdb3e2198 edge cases: if pool has no permisson reverts with FRB

  • ✅ selector is 0xc04b8d59 successfull validate

  • ✅ selector is 0xc04b8d59 edge cases: if recipient is not sender reverts with INVTR

  • ✅ selector is 0xc04b8d59 edge cases: if tokens are the same reverts with INVTO

  • ✅ selector is 0xc04b8d59 edge cases: if pool has no approve permission reverts with FRB

  • ✅ selector is 0xc04b8d59 edge cases: if not a vault token reverts with INVTO

  • ✅ selector is 0xf28c0498 successfull validate

  • ✅ selector is 0xf28c0498 edge cases: if recipient is not sender reverts with INVTR

  • ✅ selector is 0xf28c0498 edge cases: if tokens are the same reverts with INVTO

  • ✅ selector is 0xf28c0498 edge cases: if pool has no approve permission reverts with FRB

  • ✅ selector is 0xf28c0498 edge cases: if not a vault token reverts with INVTO

Structs

struct ValidatorParams {
    IProtocolGovernance protocolGovernance;
}

Validator

Inherits from BaseValidator, ERC165

Functions

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Structs

struct ValidatorParams {
    IProtocolGovernance protocolGovernance;
}

AaveVault

Inherits from Vault, ERC165, ReentrancyGuard

⛽ 4.96M

Vault that interfaces Aave protocol in the integration layer.

📕 Notes: TVL

The TVL of the vault is cached and updated after each deposit withdraw. So essentially tvl call doesn't take into account accrued interest / donations to Aave since the last deposit / withdraw

aTokens aTokens are fixed at the token creation and addresses are taken from Aave Lending Pool. So essentially each aToken is fixed for life of the AaveVault. If the aToken is missing for some vaultToken, the AaveVault cannot be created.

Push / Pull It is assumed that any amounts of tokens can be deposited / withdrawn from Aave. The contract's vaultTokens are fully allowed to Aave Lending Pool.

tvl

  function tvl() public returns (uint256[] minTokenAmounts, uint256[] maxTokenAmounts)

Total value locked for this contract.

📕 Generally it is the underlying token value of this contract in some other DeFi protocol. For example, for USDC Yearn Vault this would be total USDC balance that could be withdrawn for Yearn to this contract. The tvl itself is estimated in some range. Sometimes the range is exact, sometimes it's not

Return Values:

Specs

  • ✅ returns total value locked

  • ✅ returns total value locked, no time passed from initialization

  • ✅ edge cases: when there are no initial funds returns zeroes

lendingPool

  function lendingPool() external returns (contract ILendingPool)

Reference to Aave protocol lending pool.

Specs

  • ✅ returns ILendingPool

  • ✅ access control: allowed: any address

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true if this contract supports 0x18026500 interface

  • ✅ access control: allowed: any address

  • ✅ returns true if this contract supports 0x7a63aa3a interface

  • ✅ access control: allowed: any address

  • ✅ edge cases: when contract does not support the given interface returns false

updateTvls

⛽ 94K (93K - 95K)

  function updateTvls() external

Update all tvls to current aToken balances.

Specs

  • ✅ updates total value locked

initialize

⛽ 200K (159K - 245K)

  function initialize(uint256 nft_, address[] vaultTokens_) external

Initialized a new contract.

📕 Can only be initialized by vault governance

Parameters:

Specs

  • ✅ emits Initialized event

  • ✅ initializes contract successfully

  • ✅ edge cases: when vault's nft is not 0 reverts with INIT

  • ✅ edge cases: when tokens are not sorted reverts with INVA

  • ✅ edge cases: when tokens are not unique reverts with INVA

  • ✅ edge cases: when setting zero nft reverts with VZ

  • ✅ edge cases: when setting token with address zero reverts with AZ

  • ✅ edge cases: when token has no permission to become a vault token reverts with FRB

AaveVaultGovernance

Inherits from VaultGovernance, ERC165, ContractMeta

⛽ 2.31M

Governance that manages all Aave Vaults params and can deploy a new Aave Vault.

Functions

constructor

  function constructor(struct IVaultGovernance.InternalParams internalParams_, struct IAaveVaultGovernance.DelayedProtocolParams delayedProtocolParams_) public

Creates a new contract.

Parameters:

Specs

  • ✅ deploys a new contract

  • ✅ initializes internalParams

Edge cases

  • ✅ when lendingPool address is 0 reverts

  • ✅ when estimatedAaveAPY is 0 reverts

  • ✅ when estimatedAaaveAPY is larger than limit reverts

  • ✅ when protocolGovernance address is 0 reverts

  • ✅ when vaultRegistry address is 0 reverts

delayedProtocolParams

  function delayedProtocolParams() public returns (struct IAaveVaultGovernance.DelayedProtocolParams)

Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Specs

  • ✅ returns current DelayedProtocolParams

Access control

  • ✅ allowed: any address

Properties

  • ✅ staging DelayedProtocolParams doesn't change delayedProtocolParams

Edge cases

  • ✅ when no params were committed returns non-zero params initialized in constructor

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true if this contract supports 0x2f8c3ff3 interface

  • ✅ access control: allowed: any address

stagedDelayedProtocolParams

  function stagedDelayedProtocolParams() external returns (struct IAaveVaultGovernance.DelayedProtocolParams)

Delayed Protocol Params staged for commit after delay.

Specs

  • ✅ returns DelayedProtocolParams staged for commit

Access control

  • ✅ allowed: any address

Properties

  • ✅ always equals to params that were just staged

Edge cases

  • ✅ when no params are staged for commit returns zero struct

  • ✅ when params were just committed returns zero struct

stageDelayedProtocolParams

⛽ 88K (52K - 129K)

  function stageDelayedProtocolParams(struct IAaveVaultGovernance.DelayedProtocolParams params) external

Stage Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

📕 Can only be called after delayedProtocolParamsTimestamp.

Parameters:

Specs

  • ✅ stages DelayedProtocolParams for commit

  • ✅ sets delay for commit

  • ✅ emits StageDelayedProtocolParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

Edge cases

  • ✅ when estimated Aave APY is larger than limit reverts

  • ✅ when called twice succeeds with the last value

  • ✅ when called with zero params reverts with zero params

commitDelayedProtocolParams

⛽ 50K (49K - 54K)

  function commitDelayedProtocolParams() external

Commit Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Specs

  • ✅ commits staged DelayedProtocolParams

  • ✅ resets delay for commit

  • ✅ emits CommitDelayedProtocolParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

  • ✅ reverts if called before the delay has elapsed

  • ✅ succeeds if called after the delay has elapsed

Edge cases

  • ✅ when called twice reverts

  • ✅ when nothing is staged reverts

  • ✅ when delay has not elapsed reverts

createVault

⛽ 729K (665K - 942K)

  function createVault(address[] vaultTokens_, address owner_) external returns (contract IAaveVault vault, uint256 nft)

Deploys a new vault.

Parameters:

Specs

  • ✅ deploys a new vault

  • ✅ registers vault with vault registry and issues nft

  • ✅ the nft is owned by the owner from #createVault arguments

  • ✅ vault is initialized with nft

Access control

  • ✅ when permissionless allowed: any address

  • ✅ when not permissionless allowed: protocol governance admin

  • ✅ when not permissionless denied: any address

Structs

struct DelayedProtocolParams {
    ILendingPool lendingPool;
    uint256 estimatedAaveAPY;
}
struct InternalParams {
    IProtocolGovernance protocolGovernance;
    IVaultRegistry registry;
    IVault singleton;
}

Events

StageDelayedProtocolParams

  event StageDelayedProtocolParams(address origin, address sender, struct IAaveVaultGovernance.DelayedProtocolParams params, uint256 when)

Emitted when new DelayedProtocolParams are staged for commit

Parameters:

CommitDelayedProtocolParams

  event CommitDelayedProtocolParams(address origin, address sender, struct IAaveVaultGovernance.DelayedProtocolParams params)

Emitted when new DelayedProtocolParams are committed

Parameters:

AggregateVault

Inherits from Vault, ERC165

Vault that combines several integration layer Vaults into one Vault.

subvaultNfts

  function subvaultNfts() external returns (uint256[])

Get all subvalutNfts in the current Vault

Return Values:

subvaultOneBasedIndex

  function subvaultOneBasedIndex(uint256 nft_) external returns (uint256)

Get index of subvault by nft

Parameters:

Return Values:

hasSubvault

  function hasSubvault(uint256 nft_) external returns (bool)

Checks if subvault is present

Parameters:

Return Values:

subvaultAt

  function subvaultAt(uint256 index) external returns (address)

Get subvault by index

Parameters:

Return Values:

tvl

  function tvl() public returns (uint256[] minTokenAmounts, uint256[] maxTokenAmounts)

Total value locked for this contract.

📕 Generally it is the underlying token value of this contract in some other DeFi protocol. For example, for USDC Yearn Vault this would be total USDC balance that could be withdrawn for Yearn to this contract. The tvl itself is estimated in some range. Sometimes the range is exact, sometimes it's not

Return Values:

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

ERC20RootVault

Inherits from AggregateVault, Vault, ERC165, ReentrancyGuard, ERC20Token

⛽ 7.12M

Contract that mints and burns LP tokens in exchange for ERC20 liquidity.

Functions

depositorsAllowlist

  function depositorsAllowlist() external returns (address[])

List of addresses of depositors from which interaction with private vaults is allowed

Specs

  • ✅ returns non zero length of depositorsAllowlist

  • ✅ access control: allowed: any address

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true if this contract supports 0x23040f0a interface

  • ✅ edge cases: when contract does not support the given interface returns false

  • ✅ access control: allowed: any address

addDepositorsToAllowlist

⛽ 112K (22K - 126K)

  function addDepositorsToAllowlist(address[] depositors) external

Add new depositors in the depositorsAllowlist

📕 The action can be done only by user with admins, owners or by approved rights

Parameters:

Specs

  • ✅ adds depositor to allow list

  • ✅ access control: allowed: admin

  • ✅ access control: not allowed: deployer

  • ✅ access control: not allowed: any address

removeDepositorsFromAllowlist

⛽ 50K (49K - 53K)

  function removeDepositorsFromAllowlist(address[] depositors) external

Remove depositors from the depositorsAllowlist

📕 The action can be done only by user with admins, owners or by approved rights

Parameters:

Specs

  • ✅ removes depositor to allow list

  • ✅ access control: allowed: admin

  • ✅ access control: not allowed: deployer

  • ✅ access control: not allowed: any address

initialize

  function initialize(uint256 nft_, address[] vaultTokens_, address strategy_, uint256[] subvaultNfts_, contract IERC20RootVaultHelper helper_) external

Initialized a new contract.

📕 Can only be initialized by vault governance

Parameters:

Specs

  • ✅ edge cases: when root vault is not owner of subvault nft reverts with FRB

  • ✅ edge cases: when subVault index is 0 (rootVault has itself as subVaul) reverts with DUP

  • ✅ edge cases: when subVault index index is 0 reverts with DUP

deposit

⛽ 467K (357K - 750K)

  function deposit(uint256[] tokenAmounts, uint256 minLpTokens, bytes vaultOptions) external returns (uint256[] actualTokenAmounts)

The function of depositing the amount of tokens in exchange

Parameters:

Return Values:

Specs

  • ✅ rsAllowlist returns non zero length of depositorsAllowlist

  • ✅ rsAllowlist access control: allowed: any address

  • ✅ emits Deposit event

  • ✅ checking protocol fees charges fees

  • ✅ edge cases: when performance fee is zero do not charge performance fees

  • ✅ edge cases: when management fee is zero not charges management fees

  • ✅ edge cases: when deposit is disabled reverts with FRB

  • ✅ edge cases: when there is no depositor in allow list reverts with FRB

  • ✅ edge cases: when there is a private vault in delayedStrategyParams reverts with FRB

  • ✅ edge cases: when minLpTokens is greater than lpAmount reverts with LIMU

  • ✅ edge cases: when tokenAmounts is less than or equal to FIRST_DEPOSIT_LIMIT reverts with LIMU

  • ✅ edge cases: when depositCallback Address is set emits deposits callback called

  • ✅ edge cases: when lpAmount is zero reverts with VZ

  • ✅ edge cases: when sum of lpAmount and sender balance is greater than tokenLimitPerAddress reverts with LIMO

  • ✅ edge cases: when sum of lpAmount and totalSupply is greater than tokenLimit reverts with LIMO

  • ✅ access control: allowed: any address

withdraw

⛽ 499K (364K - 983K)

  function withdraw(address to, uint256 lpTokenAmount, uint256[] minTokenAmounts, bytes[] vaultsOptions) external returns (uint256[] actualTokenAmounts)

The function of withdrawing the amount of tokens in exchange

Parameters:

Return Values:

Specs

  • ✅ emits Withdraw event

  • ✅ edge cases: when total supply is 0 reverts with VZ

  • ✅ edge cases: when length of vaultsOptions and length of _subvaultNfts are different reverts with INVL

  • ✅ edge cases: when withdrawn is larger than protocol governance withdraw limit for vault token reverts with LIMO

  • ✅ edge cases: When address of lpCallback is not null emits withdrawCallback

  • ✅ edge cases: When address of lpCallback is not null and lpCallback throws empty error emits WithdrawCallbackLog

  • ✅ edge cases: When address of lpCallback is not null and lpCallback throws non empty error emits WithdrawCallbackLog

  • ✅ access control: allowed: any address

Events

ManagementFeesCharged

  event ManagementFeesCharged(address treasury, uint256 feeRate, uint256 amount)

Emitted when management fees are charged

Parameters:

ProtocolFeesCharged

  event ProtocolFeesCharged(address treasury, uint256 feeRate, uint256 amount)

Emitted when protocol fees are charged

Parameters:

PerformanceFeesCharged

  event PerformanceFeesCharged(address treasury, uint256 feeRate, uint256 amount)

Emitted when performance fees are charged

Parameters:

Deposit

  event Deposit(address from, address[] tokens, uint256[] actualTokenAmounts, uint256 lpTokenMinted)

Emitted when liquidity is deposited

Parameters:

Withdraw

  event Withdraw(address from, address[] tokens, uint256[] actualTokenAmounts, uint256 lpTokenBurned)

Emitted when liquidity is withdrawn

Parameters:

DepositCallbackLog

  event DepositCallbackLog(string reason)

Emitted when callback in deposit failed

Parameters:

WithdrawCallbackLog

  event WithdrawCallbackLog(string reason)

Emitted when callback in withdraw failed

Parameters:

ERC20RootVaultGovernance

Inherits from VaultGovernance, ERC165, ContractMeta

⛽ 4.53M

Governance that manages all Lp Issuers params and can deploy a new LpIssuer Vault.

Functions

constructor

  function constructor(struct IVaultGovernance.InternalParams internalParams_, struct IERC20RootVaultGovernance.DelayedProtocolParams delayedProtocolParams_, contract IERC20RootVaultHelper helper_) public

Creates a new contract.

Parameters:

Specs

  • ✅ deploys a new contract

  • ✅ initializes internalParams

Edge cases

  • ✅ when protocolGovernance address is 0 reverts

  • ✅ when vaultRegistry address is 0 reverts

delayedProtocolParams

  function delayedProtocolParams() public returns (struct IERC20RootVaultGovernance.DelayedProtocolParams)

Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Specs

  • ✅ returns current DelayedProtocolParams

Access control

  • ✅ allowed: any address

Properties

  • ✅ staging DelayedProtocolParams doesn't change delayedProtocolParams

Edge cases

  • ✅ when no params were committed returns non-zero params initialized in constructor

stagedDelayedProtocolParams

  function stagedDelayedProtocolParams() external returns (struct IERC20RootVaultGovernance.DelayedProtocolParams)

Delayed Protocol Params staged for commit after delay.

Specs

  • ✅ returns DelayedProtocolParams staged for commit

Access control

  • ✅ allowed: any address

Properties

  • ✅ always equals to params that were just staged

Edge cases

  • ✅ when no params are staged for commit returns zero struct

  • ✅ when params were just committed returns zero struct

delayedProtocolPerVaultParams

  function delayedProtocolPerVaultParams(uint256 nft) external returns (struct IERC20RootVaultGovernance.DelayedProtocolPerVaultParams)

Delayed Protocol Per Vault Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Parameters:

Specs

  • ✅ returns current DelayedProtocolPerVaultParams

Access control

  • ✅ allowed: any address

Properties

  • ✅ staging DelayedProtocolPerVaultParams doesn't change delayedProtocolPerVaultParams

Edge cases

  • ✅ when no params were committed returns zero params

stagedDelayedProtocolPerVaultParams

  function stagedDelayedProtocolPerVaultParams(uint256 nft) external returns (struct IERC20RootVaultGovernance.DelayedProtocolPerVaultParams)

Delayed Protocol Per Vault Params staged for commit after delay.

Parameters:

Specs

  • ✅ returns DelayedProtocolPerVaultParams staged for commit

Access control

  • ✅ allowed: any address

Properties

  • ✅ always equals to params that were just staged

Edge cases

  • ✅ when no params are staged for commit returns zero struct

  • ✅ when params were just committed returns zero struct

stagedDelayedStrategyParams

  function stagedDelayedStrategyParams(uint256 nft) external returns (struct IERC20RootVaultGovernance.DelayedStrategyParams)

Delayed Strategy Params staged for commit after delay.

Parameters:

Specs

  • ✅ returns DelayedStrategyParams staged for commit

Access control

  • ✅ allowed: any address

Properties

  • ✅ always equals to params that were just staged

Edge cases

  • ✅ when no params are staged for commit returns zero struct

  • ✅ when params were just committed returns zero struct

operatorParams

  function operatorParams() external returns (struct IERC20RootVaultGovernance.OperatorParams)

Operator Params.

Specs

  • ✅ returns operatorParams

Access control

  • ✅ allowed: any address

Edge cases

  • ✅ when operatorParams have not been set returns zero params

delayedStrategyParams

  function delayedStrategyParams(uint256 nft) external returns (struct IERC20RootVaultGovernance.DelayedStrategyParams)

Delayed Strategy Params

Parameters:

Specs

  • ✅ returns current DelayedStrategyParams

Access control

  • ✅ allowed: any address

Properties

  • ✅ staging DelayedStrategyParams doesn't change delayedStrategyParams

Edge cases

  • ✅ when no params were committed returns zero params

strategyParams

  function strategyParams(uint256 nft) external returns (struct IERC20RootVaultGovernance.StrategyParams)

Strategy Params.

Parameters:

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

Specs

  • ✅ returns true if this contract supports 0x6a2c3330 interface

  • ✅ access control: allowed: any address

stageDelayedStrategyParams

⛽ 160K (67K - 244K)

  function stageDelayedStrategyParams(uint256 nft, struct IERC20RootVaultGovernance.DelayedStrategyParams params) external

Stage Delayed Strategy Params, i.e. Params that could be changed by Strategy or Protocol Governance with Protocol Governance delay.

Parameters:

Specs

  • ✅ stages DelayedStrategyParams for commit

  • ✅ sets zero delay for commit when #commitDelayedStrategyParams was called 0 times (init)

  • ✅ sets governance delay for commit after #commitDelayedStrategyParams was called at least once

  • ✅ emits StageDelayedStrategyParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ allowed: Vault NFT Approved (aka strategy)

  • ✅ allowed: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

Edge cases

  • ✅ when managementFee is exceeds MAX_MANAGEMENT_FEE reverts with LIMO

  • ✅ when performnaceFee is exceeds MAX_PERFORMANCE_FEE reverts with LIMO

  • ✅ when called twice succeeds with the last value

  • ✅ when called with zero params succeeds with zero params

commitDelayedStrategyParams

⛽ 118K (75K - 195K)

  function commitDelayedStrategyParams(uint256 nft) external

Commit Delayed Strategy Params, i.e. Params that could be changed by Strategy or Protocol Governance with Protocol Governance delay.

📕 Can only be called after delayedStrategyParamsTimestamp

Parameters:

Specs

  • ✅ commits staged DelayedStrategyParams

  • ✅ resets delay for commit

  • ✅ emits CommitDelayedStrategyParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ allowed: Vault NFT Owner (aka liquidity provider)

  • ✅ allowed: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

  • ✅ reverts if called before the delay has elapsed (after commit was called initally)

  • ✅ succeeds if called after the delay has elapsed

Edge cases

  • ✅ when called twice reverts

  • ✅ when nothing is staged reverts

  • ✅ when delay has not elapsed (after initial commit call) reverts

stageDelayedProtocolPerVaultParams

⛽ 108K (54K - 108K)

  function stageDelayedProtocolPerVaultParams(uint256 nft, struct IERC20RootVaultGovernance.DelayedProtocolPerVaultParams params) external

Stage Delayed Protocol Per Vault Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Parameters:

Specs

  • ✅ stages DelayedProtocolPerVaultParams for commit

  • ✅ sets delay for commit

  • ✅ emits StageDelayedProtocolPerVaultParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

Edge cases

  • ✅ when called twice succeeds with the last value

  • ✅ when called with zero params succeeds with zero params

  • ✅ when protocol fee is greater than MAX_PROTOCOL_FEE reverts

commitDelayedProtocolPerVaultParams

⛽ 80K (44K - 80K)

  function commitDelayedProtocolPerVaultParams(uint256 nft) external

Commit Delayed Protocol Per Vault Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

📕 Can only be called after delayedProtocolPerVaultParamsTimestamp

Parameters:

Specs

  • ✅ commits staged DelayedProtocolPerVaultParams

  • ✅ resets delay for commit

  • ✅ emits CommitDelayedProtocolPerVaultParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

  • ✅ reverts if called before the delay has elapsed only if params have already been commited

  • ✅ succeeds if called after the delay has elapsed

Edge cases

  • ✅ when called twice reverts

  • ✅ when nothing is staged reverts

  • ✅ when delay has not elapsed and params have not been commited reverts

  • ✅ when params have already been set and delay has not elapsed reverts

setStrategyParams

⛽ 113K (37K - 115K)

  function setStrategyParams(uint256 nft, struct IERC20RootVaultGovernance.StrategyParams params) external

Set Strategy params, i.e. Params that could be changed by Strategy or Protocol Governance immediately.

Parameters:

setOperatorParams

⛽ 51K (35K - 77K)

  function setOperatorParams(struct IERC20RootVaultGovernance.OperatorParams params) external

Set Operator params, i.e. Params that could be changed by Operator or Protocol Governance immediately.

Parameters:

Specs

  • ✅ sets new operatorParams

  • ✅ access constrol allowed: ProtocolGovernance admin or Operator

  • ✅ access constrol denied: any other address

Properties

  • ✅ setting new oprator params overwrites old params immediately

stageDelayedProtocolParams

⛽ 88K (52K - 129K)

  function stageDelayedProtocolParams(struct IERC20RootVaultGovernance.DelayedProtocolParams params) external

Stage Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

📕 Can only be called after delayedProtocolParamsTimestamp.

Parameters:

Specs

  • ✅ stages DelayedProtocolParams for commit

  • ✅ sets delay for commit

  • ✅ emits StageDelayedProtocolParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

Edge cases

  • ✅ when called twice succeeds with the last value

  • ✅ when called with zero params reverts with zero params

commitDelayedProtocolParams

⛽ 50K (49K - 54K)

  function commitDelayedProtocolParams() external

Commit Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Specs

  • ✅ commits staged DelayedProtocolParams

  • ✅ resets delay for commit

  • ✅ emits CommitDelayedProtocolParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

  • ✅ reverts if called before the delay has elapsed

  • ✅ succeeds if called after the delay has elapsed

Edge cases

  • ✅ when called twice reverts

  • ✅ when nothing is staged reverts

  • ✅ when delay has not elapsed reverts

createVault

⛽ 915K (794K - 1.32M)

  function createVault(address[] vaultTokens_, address strategy_, uint256[] subvaultNfts_, address owner_) external returns (contract IERC20RootVault vault, uint256 nft)

Deploys a new vault.

Parameters:

Specs

  • ✅ deploys a new vault

  • ✅ registers vault with vault registry and issues nft

  • ✅ the nft is owned by the owner from #createVault arguments

  • ✅ vault is initialized with nft

Access control

  • ✅ when permissionless allowed: any address

  • ✅ when not permissionless allowed: protocol governance admin

  • ✅ when not permissionless denied: any address

Structs

struct DelayedStrategyParams {
    address strategyTreasury;
    address strategyPerformanceTreasury;
    bool privateVault;
    uint256 managementFee;
    uint256 performanceFee;
    address depositCallbackAddress;
    address withdrawCallbackAddress;
}
struct DelayedProtocolParams {
    uint256 managementFeeChargeDelay;
    IOracle oracle;
}
struct StrategyParams {
    uint256 tokenLimitPerAddress;
    uint256 tokenLimit;
}
struct DelayedProtocolPerVaultParams {
    uint256 protocolFee;
}
struct OperatorParams {
    bool disableDeposit;
}
struct InternalParams {
    IProtocolGovernance protocolGovernance;
    IVaultRegistry registry;
    IVault singleton;
}

Events

StageDelayedProtocolPerVaultParams

  event StageDelayedProtocolPerVaultParams(address origin, address sender, uint256 nft, struct IERC20RootVaultGovernance.DelayedProtocolPerVaultParams params, uint256 when)

Emitted when new DelayedProtocolPerVaultParams are staged for commit

Parameters:

CommitDelayedProtocolPerVaultParams

  event CommitDelayedProtocolPerVaultParams(address origin, address sender, uint256 nft, struct IERC20RootVaultGovernance.DelayedProtocolPerVaultParams params)

Emitted when new DelayedProtocolPerVaultParams are committed

Parameters:

StageDelayedStrategyParams

  event StageDelayedStrategyParams(address origin, address sender, uint256 nft, struct IERC20RootVaultGovernance.DelayedStrategyParams params, uint256 when)

Emitted when new DelayedStrategyParams are staged for commit

Parameters:

CommitDelayedStrategyParams

  event CommitDelayedStrategyParams(address origin, address sender, uint256 nft, struct IERC20RootVaultGovernance.DelayedStrategyParams params)

Emitted when new DelayedStrategyParams are committed

Parameters:

SetStrategyParams

  event SetStrategyParams(address origin, address sender, uint256 nft, struct IERC20RootVaultGovernance.StrategyParams params)

Emitted when new StrategyParams are set.

Parameters:

SetOperatorParams

  event SetOperatorParams(address origin, address sender, struct IERC20RootVaultGovernance.OperatorParams params)

Emitted when new OperatorParams are set.

Parameters:

StageDelayedProtocolParams

  event StageDelayedProtocolParams(address origin, address sender, struct IERC20RootVaultGovernance.DelayedProtocolParams params, uint256 when)

Emitted when new DelayedProtocolParams are staged for commit

Parameters:

CommitDelayedProtocolParams

  event CommitDelayedProtocolParams(address origin, address sender, struct IERC20RootVaultGovernance.DelayedProtocolParams params)

Emitted when new DelayedProtocolParams are committed

Parameters:

ERC20Vault

Inherits from Vault, ERC165, ReentrancyGuard

⛽ 4.41M

Vault that stores ERC20 tokens.

tvl

  function tvl() public returns (uint256[] minTokenAmounts, uint256[] maxTokenAmounts)

Total value locked for this contract.

📕 Generally it is the underlying token value of this contract in some other DeFi protocol. For example, for USDC Yearn Vault this would be total USDC balance that could be withdrawn for Yearn to this contract. The tvl itself is estimated in some range. Sometimes the range is exact, sometimes it's not

Return Values:

Specs

  • ✅ returns total value locked

  • ✅ edge cases: when there are no initial funds returns zeroes

initialize

  function initialize(uint256 nft_, address[] vaultTokens_) external

Initialized a new contract.

📕 Can only be initialized by vault governance

Parameters:

Specs

  • ✅ emits Initialized event

  • ✅ initializes contract successfully

  • ✅ edge cases: when vault's nft is not 0 reverts with INIT

  • ✅ edge cases: not initialized when vault's nft is 0 returns false

  • ✅ edge cases: when tokens are not sorted reverts with INVA

  • ✅ edge cases: when tokens are not unique reverts with INVA

  • ✅ edge cases: when setting zero nft reverts with VZ

  • ✅ edge cases: when setting empty tokens array reverts with INV

  • ✅ edge cases: when token has no permission to become a vault token reverts with FRB

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true if this contract supports 0x7a63aa3a interface

  • ✅ access control: allowed: any address

  • ✅ edge cases: when contract does not support the given interface returns false

ERC20VaultGovernance

Inherits from VaultGovernance, ERC165, ContractMeta

⛽ 1.59M

Governance that manages all ERC20 Vaults params and can deploy a new ERC20 Vault.

Functions

constructor

  function constructor(struct IVaultGovernance.InternalParams internalParams_) public

Creates a new contract.

Parameters:

Specs

  • ✅ deploys a new contract

  • ✅ initializes internalParams

Edge cases

  • ✅ when protocolGovernance address is 0 reverts

  • ✅ when vaultRegistry address is 0 reverts

createVault

⛽ 475K (463K - 648K)

  function createVault(address[] vaultTokens_, address owner_) external returns (contract IERC20Vault vault, uint256 nft)

Deploys a new vault.

Parameters:

Specs

  • ✅ deploys a new vault

  • ✅ registers vault with vault registry and issues nft

  • ✅ the nft is owned by the owner from #createVault arguments

  • ✅ vault is initialized with nft

Access control

  • ✅ when permissionless allowed: any address

  • ✅ when not permissionless allowed: protocol governance admin

  • ✅ when not permissionless denied: any address

Structs

struct InternalParams {
    IProtocolGovernance protocolGovernance;
    IVaultRegistry registry;
    IVault singleton;
}

GearboxRootVault

Inherits from AggregateVault, Vault, ERC165, ReentrancyGuard, ERC20Token

Contract that mints and burns LP tokens in exchange for ERC20 liquidity.

Functions

depositorsAllowlist

  function depositorsAllowlist() external returns (address[])

List of addresses of depositors from which interaction with private vaults is allowed

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

addDepositorsToAllowlist

  function addDepositorsToAllowlist(address[] depositors) external

Add new depositors in the depositorsAllowlist

📕 The action can be done only by user with admins, owners or by approved rights

Parameters:

removeDepositorsFromAllowlist

  function removeDepositorsFromAllowlist(address[] depositors) external

Remove depositors from the depositorsAllowlist

📕 The action can be done only by user with admins, owners or by approved rights

Parameters:

initialize

  function initialize(uint256 nft_, address[] vaultTokens_, address strategy_, uint256[] subvaultNfts_, address) external

Initialized a new contract.

📕 Can only be initialized by vault governance

Parameters:

deposit

  function deposit(uint256[] tokenAmounts, uint256 minLpTokens, bytes vaultOptions) external returns (uint256[] actualTokenAmounts)

The function of depositing the amount of tokens in exchange

Parameters:

Return Values:

registerWithdrawal

  function registerWithdrawal(uint256 lpTokenAmount) external returns (uint256 amountRegistered)

The function of registering withdrawal of lp tokens amount

Parameters:

Return Values:

cancelWithdrawal

  function cancelWithdrawal(uint256 lpTokenAmount) external returns (uint256 amountRemained)

The function of cancelling withdrawal of lp tokens amount

Parameters:

Return Values:

invokeExecution

  function invokeExecution() public

The function of invoking the execution of withdrawal orders and transfers corresponding funds to ERC20 vault

withdraw

  function withdraw(address to, bytes[] vaultsOptions) external returns (uint256[] actualTokenAmounts)

The function of withdrawing the amount of tokens in exchange

Parameters:

Return Values:

shutdown

  function shutdown() external

The function of invoking the emergency execution of withdrawal orders, transfers corresponding funds to ERC20 vault and stops deposits

reopen

  function reopen() external

The function of opening deposits back in case of a previous shutdown

Events

ManagementFeesCharged

  event ManagementFeesCharged(address treasury, uint256 feeRate, uint256 amount)

Emitted when management fees are charged

Parameters:

WithdrawalRegistered

  event WithdrawalRegistered(address sender, uint256 lpAmountRegistered)

Emitted when a witdrawal request registered

Parameters:

WithdrawalCancelled

  event WithdrawalCancelled(address sender, uint256 lpAmountCancelled)

Emitted when some piece of the witdrawal request cancelled

Parameters:

ExecutionInvoked

  event ExecutionInvoked(address sender, uint256 amountWithdrawnToERC20)

Emitted when the withdrawal orderd execution completed

Parameters:

ProtocolFeesCharged

  event ProtocolFeesCharged(address treasury, uint256 feeRate, uint256 amount)

Emitted when protocol fees are charged

Parameters:

PerformanceFeesCharged

  event PerformanceFeesCharged(address treasury, uint256 feeRate, uint256 amount)

Emitted when performance fees are charged

Parameters:

Deposit

  event Deposit(address from, address[] tokens, uint256[] actualTokenAmounts, uint256 lpTokenMinted)

Emitted when liquidity is deposited

Parameters:

Withdraw

  event Withdraw(address from, uint256[] actualTokenAmounts, uint256 lpTokenBurned)

Emitted when liquidity is withdrawn

Parameters:

DepositCallbackLog

  event DepositCallbackLog(string reason)

Emitted when callback in deposit failed

Parameters:

WithdrawCallbackLog

  event WithdrawCallbackLog(string reason)

Emitted when callback in withdraw failed

Parameters:

GearboxVault

Inherits from Vault, ERC165, ReentrancyGuard

Functions

tvl

  function tvl() public returns (uint256[] minTokenAmounts, uint256[] maxTokenAmounts)

Total value locked for this contract.

📕 Generally it is the underlying token value of this contract in some other DeFi protocol. For example, for USDC Yearn Vault this would be total USDC balance that could be withdrawn for Yearn to this contract. The tvl itself is estimated in some range. Sometimes the range is exact, sometimes it's not

Return Values:

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

getCreditAccount

  function getCreditAccount() public returns (address)

Returns an address of the credit account connected to the address of the vault

getAllAssetsOnCreditAccountValue

  function getAllAssetsOnCreditAccountValue() external returns (uint256 currentAllAssetsValue)

Returns value of all assets located on the vault, including taken with leverage (nominated in primary tokens)

getClaimableRewardsValue

  function getClaimableRewardsValue() external returns (uint256)

Returns value of rewards (CRV, CVX) we can obtain from Convex (nominated in primary tokens)

getMerkleProof

  function getMerkleProof() external returns (bytes32[])

initialize

  function initialize(uint256 nft_, address[] vaultTokens_, address helper_) external

Initialized a new contract.

📕 Can only be initialized by vault governance

Parameters:

openCreditAccount

  function openCreditAccount() external

Opens a new credit account on the address of the vault

adjustPosition

  function adjustPosition() external

Adjust a position (takes more debt or repays some, depending on the past performance) to achieve the required marginalFactorD9

setMerkleParameters

  function setMerkleParameters(uint256 merkleIndex_, uint256 merkleTotalAmount_, bytes32[] merkleProof_) public

Sets merkle tree parameters for claiming Gearbox V2 Degen NFT (can be successfully called only by an admin or a strategist)

Parameters:

updateTargetMarginalFactor

  function updateTargetMarginalFactor(uint256 marginalFactorD9_) external

Updates marginalFactorD9 (can be successfully called only by an admin or a strategist)

Parameters:

multicall

  function multicall(struct MultiCall[] calls) external

A helper function to be able to call Gearbox multicalls from the helper, but on behalf of the vault Can be successfully called only by the helper

swap

  function swap(contract ISwapRouter router, struct ISwapRouter.ExactOutputParams uniParams, address token, uint256 amount) external

A helper function to be able to call Gearbox multicalls from the helper, but on behalf of the vault Can be successfully called only by the helper

openCreditAccountInManager

  function openCreditAccountInManager(uint256 currentPrimaryTokenAmount, uint16 referralCode) external

A helper function to be able to call Gearbox multicalls from the helper, but on behalf of the vault Can be successfully called only by the helper

Events

TargetMarginalFactorUpdated

  event TargetMarginalFactorUpdated(address origin, address sender, uint256 newMarginalFactorD9)

Emitted when target marginal factor is updated

Parameters:

GearboxVaultGovernance

Inherits from VaultGovernance, ERC165, ContractMeta

Functions

constructor

  function constructor(struct IVaultGovernance.InternalParams internalParams_, struct IGearboxVaultGovernance.DelayedProtocolParams delayedProtocolParams_) public

Creates a new contract

delayedProtocolParams

  function delayedProtocolParams() public returns (struct IGearboxVaultGovernance.DelayedProtocolParams)

Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

stagedDelayedProtocolParams

  function stagedDelayedProtocolParams() external returns (struct IGearboxVaultGovernance.DelayedProtocolParams)

Delayed Protocol Params staged for commit after delay.

stagedDelayedProtocolPerVaultParams

  function stagedDelayedProtocolPerVaultParams(uint256 nft) external returns (struct IGearboxVaultGovernance.DelayedProtocolPerVaultParams)

Delayed Protocol Per Vault Params staged for commit after delay.

Parameters:

strategyParams

  function strategyParams(uint256 nft) external returns (struct IGearboxVaultGovernance.StrategyParams)

Strategy Params.

delayedProtocolPerVaultParams

  function delayedProtocolPerVaultParams(uint256 nft) external returns (struct IGearboxVaultGovernance.DelayedProtocolPerVaultParams)

Delayed Protocol Per Vault Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Parameters:

stageDelayedProtocolParams

  function stageDelayedProtocolParams(struct IGearboxVaultGovernance.DelayedProtocolParams params) external

Stage Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

📕 Can only be called after delayedProtocolParamsTimestamp.

Parameters:

commitDelayedProtocolParams

  function commitDelayedProtocolParams() external

Commit Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

stageDelayedProtocolPerVaultParams

  function stageDelayedProtocolPerVaultParams(uint256 nft, struct IGearboxVaultGovernance.DelayedProtocolPerVaultParams params) external

commitDelayedProtocolPerVaultParams

  function commitDelayedProtocolPerVaultParams(uint256 nft) external

Commit Delayed Protocol Per Vault Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

📕 Can only be called after delayedProtocolPerVaultParamsTimestamp

Parameters:

setStrategyParams

  function setStrategyParams(uint256 nft, struct IGearboxVaultGovernance.StrategyParams params) external

Set Strategy params, i.e. Params that could be changed by Strategy or Protocol Governance immediately.

Parameters:

createVault

  function createVault(address[] vaultTokens_, address owner_, address helper_) external returns (contract IGearboxVault vault, uint256 nft)

Deploys a new vault.

Parameters:

Structs

struct DelayedProtocolParams {
    uint256 withdrawDelay;
    uint16 referralCode;
    address univ3Adapter;
    address crv;
    address cvx;
    uint256 maxSlippageD9;
    uint256 maxSmallPoolsSlippageD9;
    uint256 maxCurveSlippageD9;
    address uniswapRouter;
}
struct DelayedProtocolPerVaultParams {
    address primaryToken;
    address curveAdapter;
    address convexAdapter;
    address facade;
    uint256 initialMarginalValueD9;
}
struct StrategyParams {
    uint24 largePoolFeeUsed;
}
struct InternalParams {
    IProtocolGovernance protocolGovernance;
    IVaultRegistry registry;
    IVault singleton;
}

Events

StageDelayedProtocolPerVaultParams

  event StageDelayedProtocolPerVaultParams(address origin, address sender, uint256 nft, struct IGearboxVaultGovernance.DelayedProtocolPerVaultParams params, uint256 when)

Emitted when new DelayedProtocolPerVaultParams are staged for commit

Parameters:

CommitDelayedProtocolPerVaultParams

  event CommitDelayedProtocolPerVaultParams(address origin, address sender, uint256 nft, struct IGearboxVaultGovernance.DelayedProtocolPerVaultParams params)

Emitted when new DelayedProtocolPerVaultParams are committed

Parameters:

StageDelayedProtocolParams

  event StageDelayedProtocolParams(address origin, address sender, struct IGearboxVaultGovernance.DelayedProtocolParams params, uint256 when)

Emitted when new DelayedProtocolParams are staged for commit

Parameters:

SetStrategyParams

  event SetStrategyParams(address origin, address sender, struct IGearboxVaultGovernance.StrategyParams params)

Emitted when new StrategyParams are set.

Parameters:

CommitDelayedProtocolParams

  event CommitDelayedProtocolParams(address origin, address sender, struct IGearboxVaultGovernance.DelayedProtocolParams params)

Emitted when new DelayedProtocolParams are committed

Parameters:

IntegrationVault

Inherits from Vault, ERC165, ReentrancyGuard

Abstract contract that has logic common for every Vault.

📕 Notes:

ERC-721

Each Vault should be registered in VaultRegistry and get corresponding VaultRegistry NFT.

Access control

push and pull methods are only allowed for owner / approved person of the NFT. However, pull for approved person also checks that pull destination is another vault of the Vault System.

The semantics is: NFT owner owns all Vault liquidity, Approved person is liquidity manager. ApprovedForAll person cannot do anything except ERC-721 token transfers.

Both NFT owner and approved person can call externalCall method which claims liquidity mining rewards (if any)

reclaimTokens for claiming rewards given by an underlying protocol to erc20Vault in order to sell them there

Functions

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

push

  function push(address[] tokens, uint256[] tokenAmounts, bytes options) public returns (uint256[] actualTokenAmounts)

Pushes tokens on the vault balance to the underlying protocol. For example, for Yearn this operation will take USDC from the contract balance and convert it to yUSDC.

📕 Tokens must be a subset of Vault Tokens. However, the convention is that if tokenAmount == 0 it is the same as token is missing.

Also notice that this operation doesn't guarantee that tokenAmounts will be invested in full.

Parameters:

Return Values:

transferAndPush

  function transferAndPush(address from, address[] tokens, uint256[] tokenAmounts, bytes options) external returns (uint256[] actualTokenAmounts)

The same as push method above but transfers tokens to vault balance prior to calling push. After the push it returns all the leftover tokens back (push method doesn't guarantee that tokenAmounts will be invested in full).

Parameters:

Return Values:

pull

  function pull(address to, address[] tokens, uint256[] tokenAmounts, bytes options) external returns (uint256[] actualTokenAmounts)

Pulls tokens from the underlying protocol to the to address.

📕 Can only be called but Vault Owner or Strategy. Vault owner is the owner of NFT for this vault in VaultManager. Strategy is approved address for the vault NFT. When called by vault owner this method just pulls the tokens from the protocol to the to address When called by strategy on vault other than zero vault it pulls the tokens to zero vault (required to == zero vault) When called by strategy on zero vault it pulls the tokens to zero vault, pushes tokens on the to vault, and reclaims everything that's left. Thus any vault other than zero vault cannot have any tokens on it

Tokens must be a subset of Vault Tokens. However, the convention is that if tokenAmount == 0 it is the same as token is missing.

Pull is fulfilled on the best effort basis, i.e. if the tokenAmounts overflows available funds it withdraws all the funds.

Parameters:

Return Values:

reclaimTokens

  function reclaimTokens(address[] tokens) external returns (uint256[] actualTokenAmounts)

Claim ERC20 tokens from vault balance to zero vault.

📕 Cannot be called from zero vault.

Parameters:

Return Values:

isValidSignature

  function isValidSignature(bytes32 _hash, bytes _signature) external returns (bytes4 magicValue)

Verifies offchain signature.

📕 Should return whether the signature provided is valid for the provided hash

MUST return the bytes4 magic value 0x1626ba7e when function passes.

MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5)

MUST allow external calls

Parameters:

Return Values:

externalCall

  function externalCall(address to, bytes4 selector, bytes data) external returns (bytes result)

Execute one of whitelisted calls.

📕 Can only be called by Vault Owner or Strategy. Vault owner is the owner of NFT for this vault in VaultManager. Strategy is approved address for the vault NFT.

Since this method allows sending arbitrary transactions, the destinations of the calls are whitelisted by Protocol Governance.

Parameters:

Return Values:

Events

Push

  event Push(uint256[] tokenAmounts)

Emitted on successful push

Parameters:

Pull

  event Pull(address to, uint256[] tokenAmounts)

Emitted on successful pull

Parameters:

ReclaimTokens

  event ReclaimTokens(address to, address[] tokens, uint256[] tokenAmounts)

Emitted when tokens are reclaimed

Parameters:

MellowVault

Inherits from Vault, ERC165, ReentrancyGuard

⛽ 4.91M

Vault that stores ERC20 tokens.

tvl

  function tvl() public returns (uint256[] minTokenAmounts, uint256[] maxTokenAmounts)

Total value locked for this contract.

📕 Generally it is the underlying token value of this contract in some other DeFi protocol. For example, for USDC Yearn Vault this would be total USDC balance that could be withdrawn for Yearn to this contract. The tvl itself is estimated in some range. Sometimes the range is exact, sometimes it's not

Return Values:

initialize

  function initialize(uint256 nft_, address[] vaultTokens_, contract IERC20RootVault vault_) external

Initialized a new contract.

📕 Can only be initialized by vault governance

Parameters:

MellowVaultGovernance

Inherits from VaultGovernance, ERC165, ContractMeta

⛽ 1.6M

Governance that manages all Mellow Vaults params and can deploy a new Mellow Vault.

Functions

constructor

  function constructor(struct IVaultGovernance.InternalParams internalParams_) public

Creates a new contract.

Parameters:

createVault

  function createVault(address[] vaultTokens_, address owner_, contract IERC20RootVault underlyingVault) external returns (contract IMellowVault vault, uint256 nft)

Deploys a new vault.

Parameters:

Structs

struct InternalParams {
    IProtocolGovernance protocolGovernance;
    IVaultRegistry registry;
    IVault singleton;
}

QuickSwapVault

Inherits from Vault, ERC165, ReentrancyGuard

Vault that interfaces QuickSwap protocol in the integration layer.

Functions

constructor

  function constructor(contract IAlgebraNonfungiblePositionManager positionManager_, contract IQuickSwapHelper helper_, contract IAlgebraSwapRouter swapRouter_, contract IFarmingCenter farmingCenter_, address dQuickToken_, address quickToken_) public

initialize

  function initialize(uint256 nft_, address erc20Vault_, address[] vaultTokens_) external

Initialized a new contract.

📕 Can only be initialized by vault governance

Parameters:

onERC721Received

  function onERC721Received(address operator, address from, uint256 tokenId, bytes) external returns (bytes4)

📕 Whenever an {IERC721} tokenId token is transferred to this contract via {IERC721-safeTransferFrom} by operator from from, this function is called. It must return its Solidity selector to confirm the token transfer. If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. The selector can be obtained in Solidity with IERC721.onERC721Received.selector.

openFarmingPosition

  function openFarmingPosition(uint256 nft, contract IFarmingCenter farmingCenter_) public

Parameters:

burnFarmingPosition

  function burnFarmingPosition(uint256 nft, contract IFarmingCenter farmingCenter_) public

Parameters:

collectEarnings

⛽ 135K (121K - 195K)

  function collectEarnings() external returns (uint256[] collectedFees)

Return Values:

collectRewards

  function collectRewards() public returns (uint256[] collectedRewards)

Parameters:

tvl

  function tvl() public returns (uint256[] minTokenAmounts, uint256[] maxTokenAmounts)

Total value locked for this contract.

📕 Generally it is the underlying token value of this contract in some other DeFi protocol. For example, for USDC Yearn Vault this would be total USDC balance that could be withdrawn for Yearn to this contract. The tvl itself is estimated in some range. Sometimes the range is exact, sometimes it's not

Return Values:

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

strategyParams

  function strategyParams() public returns (struct IQuickSwapVaultGovernance.StrategyParams params)

Return Values:

Events

CollectedEarnings

  event CollectedEarnings(address origin, address sender, uint256 amount0, uint256 amount1)

Emitted when earnings are collected

Parameters:

CollectedRewards

  event CollectedRewards(address origin, address sender, uint256 amount0, uint256 amount1)

Emitted when rewards are collected

Parameters:

QuickSwapVaultGovernance

Inherits from VaultGovernance, ERC165, ContractMeta

Governance that manages all QuickSwap Vaults params and can deploy a new QuickSwap Vault.

Functions

constructor

  function constructor(struct IVaultGovernance.InternalParams internalParams_) public

Creates a new contract.

Parameters:

strategyParams

  function strategyParams(uint256 nft) external returns (struct IQuickSwapVaultGovernance.StrategyParams)

Delayed Strategy Params

Parameters:

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

setStrategyParams

  function setStrategyParams(uint256 nft, struct IQuickSwapVaultGovernance.StrategyParams params) external

Delayed Strategy Params staged for commit after delay.

Parameters:

createVault

  function createVault(address[] vaultTokens_, address owner_, address erc20Vault_) external returns (contract IQuickSwapVault vault, uint256 nft)

Deploys a new vault.

Parameters:

Structs

struct StrategyParams {
    struct IIncentiveKey.IncentiveKey key;
    address bonusTokenToUnderlying;
    address rewardTokenToUnderlying;
    uint256 swapSlippageD;
    uint32 rewardPoolTimespan;
}
struct InternalParams {
    IProtocolGovernance protocolGovernance;
    IVaultRegistry registry;
    IVault singleton;
}

Events

SetStrategyParams

  event SetStrategyParams(address origin, address sender, uint256 nft, struct IQuickSwapVaultGovernance.StrategyParams params)

Emitted when new StrategyParams are set

Parameters:

UniV3Vault

Inherits from Vault, ERC165, ReentrancyGuard

⛽ 6.61M

Vault that interfaces UniswapV3 protocol in the integration layer.

Functions

tvl

  function tvl() public returns (uint256[] minTokenAmounts, uint256[] maxTokenAmounts)

Total value locked for this contract.

📕 Generally it is the underlying token value of this contract in some other DeFi protocol. For example, for USDC Yearn Vault this would be total USDC balance that could be withdrawn for Yearn to this contract. The tvl itself is estimated in some range. Sometimes the range is exact, sometimes it's not

Return Values:

Specs

  • ✅ returns total value locked

  • ✅ edge cases: when there are no initial funds returns zeroes

  • ✅ edge cases: when push was made but there was no minted position returns zeroes

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true if this contract supports 0x88878d28 interface

  • ✅ access control: allowed: any address

  • ✅ returns true if this contract supports 0x7a63aa3a interface

  • ✅ access control: allowed: any address

  • ✅ edge cases: when contract does not support the given interface returns false

positionManager

  function positionManager() external returns (contract INonfungiblePositionManager)

Reference to INonfungiblePositionManager of UniswapV3 protocol.

Specs

  • ✅ returns INonfungiblePositionManager

  • ✅ access control: allowed: any address

liquidityToTokenAmounts

  function liquidityToTokenAmounts(uint128 liquidity) external returns (uint256[] tokenAmounts)

Returns tokenAmounts corresponding to liquidity, based on the current Uniswap position

Parameters:

Return Values:

Specs

  • ✅ returns tokenAmounts corresponding to liquidity

tokenAmountsToLiquidity

  function tokenAmountsToLiquidity(uint256[] tokenAmounts) public returns (uint128 liquidity)

Returns liquidity corresponding to token amounts, based on the current Uniswap position

Parameters:

Return Values:

Specs

  • ✅ returns zero in case of zero amounts

  • ✅ returns more than zero in case of non-zero amounts

  • ✅ returns proportionally correct

  • ✅ returns correctly in case of tick being out of position by the left

  • ✅ returns correctly in case of tick being out of position by the right

initialize

⛽ 186K

  function initialize(uint256 nft_, address[] vaultTokens_, uint24 fee_, address uniV3Hepler_) external

Initialized a new contract.

📕 Can only be initialized by vault governance

Parameters:

Specs

  • ✅ emits Initialized event

  • ✅ initializes contract successfully

  • ✅ edge cases: when vault's nft is not 0 reverts with INIT

  • ✅ edge cases: when tokens are not sorted reverts with INVA

  • ✅ edge cases: when tokens are not unique reverts with INVA

  • ✅ edge cases: when tokens length is not equal to 2 reverts with INV

  • ✅ edge cases: when setting zero nft reverts with VZ

  • ✅ edge cases: when token has no permission to become a vault token reverts with FRB

onERC721Received

  function onERC721Received(address operator, address from, uint256 tokenId, bytes) external returns (bytes4)

📕 Whenever an {IERC721} tokenId token is transferred to this contract via {IERC721-safeTransferFrom} by operator from from, this function is called. It must return its Solidity selector to confirm the token transfer. If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. The selector can be obtained in Solidity with IERC721.onERC721Received.selector.

Specs

  • ✅ updates vault's uniV3Nft

  • ✅ edge cases: when msg.sender is not a position manager reverts

  • ✅ edge cases: when operator is not a strategy reverts

  • ✅ edge cases: when UniV3 token is not valid reverts

  • ✅ edge cases: prevent from adding nft while liquidity is not empty reverts

  • ✅ access control: position manager: allowed

  • ✅ access control: any other address: not allowed

collectEarnings

  function collectEarnings() external returns (uint256[] collectedEarnings)

Collect UniV3 fees to zero vault.

Specs

  • ✅ emits CollectedEarnings event

  • ✅ collecting fees

  • ✅ edge cases: when there is no minted position reverts

  • ✅ access control: allowed: all addresses

Structs

struct Pair {
    uint256 a0;
    uint256 a1;
}
struct Options {
    uint256 amount0Min;
    uint256 amount1Min;
    uint256 deadline;
}

Events

CollectedEarnings

  event CollectedEarnings(address origin, address sender, address to, uint256 amount0, uint256 amount1)

Emitted when earnings are collected

Parameters:

UniV3VaultGovernance

Inherits from VaultGovernance, ERC165, ContractMeta

⛽ 3.02M

Governance that manages all UniV3 Vaults params and can deploy a new UniV3 Vault.

Functions

constructor

  function constructor(struct IVaultGovernance.InternalParams internalParams_, struct IUniV3VaultGovernance.DelayedProtocolParams delayedProtocolParams_) public

Creates a new contract.

Parameters:

Specs

  • ✅ deploys a new contract

  • ✅ initializes internalParams

Edge cases

  • ✅ when positionManager address is 0 reverts

  • ✅ when oracle address is 0 reverts

  • ✅ when protocolGovernance address is 0 reverts

  • ✅ when vaultRegistry address is 0 reverts

delayedProtocolParams

  function delayedProtocolParams() public returns (struct IUniV3VaultGovernance.DelayedProtocolParams)

Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Specs

  • ✅ returns current DelayedProtocolParams

Access control

  • ✅ allowed: any address

Properties

  • ✅ staging DelayedProtocolParams doesn't change delayedProtocolParams

Edge cases

  • ✅ when no params were committed returns non-zero params initialized in constructor

stagedDelayedProtocolParams

  function stagedDelayedProtocolParams() external returns (struct IUniV3VaultGovernance.DelayedProtocolParams)

Delayed Protocol Params staged for commit after delay.

Specs

  • ✅ returns DelayedProtocolParams staged for commit

Access control

  • ✅ allowed: any address

Properties

  • ✅ always equals to params that were just staged

Edge cases

  • ✅ when no params are staged for commit returns zero struct

  • ✅ when params were just committed returns zero struct

stagedDelayedStrategyParams

  function stagedDelayedStrategyParams(uint256 nft) external returns (struct IUniV3VaultGovernance.DelayedStrategyParams)

Delayed Strategy Params staged for commit after delay.

Parameters:

delayedStrategyParams

  function delayedStrategyParams(uint256 nft) external returns (struct IUniV3VaultGovernance.DelayedStrategyParams)

Delayed Strategy Params

Parameters:

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true if this contract supports 0xa2e9c513 interface

  • ✅ access control: allowed: any address

stageDelayedProtocolParams

⛽ 88K (52K - 129K)

  function stageDelayedProtocolParams(struct IUniV3VaultGovernance.DelayedProtocolParams params) external

Stage Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Parameters:

Specs

  • ✅ stages DelayedProtocolParams for commit

  • ✅ sets delay for commit

  • ✅ emits StageDelayedProtocolParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

Edge cases

  • ✅ when called twice succeeds with the last value

  • ✅ when called with zero params reverts with zero params

commitDelayedProtocolParams

⛽ 50K (50K - 54K)

  function commitDelayedProtocolParams() external

Commit Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Specs

  • ✅ commits staged DelayedProtocolParams

  • ✅ resets delay for commit

  • ✅ emits CommitDelayedProtocolParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

  • ✅ reverts if called before the delay has elapsed

  • ✅ succeeds if called after the delay has elapsed

Edge cases

  • ✅ when called twice reverts

  • ✅ when nothing is staged reverts

  • ✅ when delay has not elapsed reverts

stageDelayedStrategyParams

⛽ 121K

  function stageDelayedStrategyParams(uint256 nft, struct IUniV3VaultGovernance.DelayedStrategyParams params) external

Stage Delayed Strategy Params, i.e. Params that could be changed by Strategy or Protocol Governance with Protocol Governance delay.

Parameters:

commitDelayedStrategyParams

⛽ 94K

  function commitDelayedStrategyParams(uint256 nft) external

Commit Delayed Strategy Params, i.e. Params that could be changed by Strategy or Protocol Governance with Protocol Governance delay.

📕 Can only be called after delayedStrategyParamsTimestamp

Parameters:

createVault

⛽ 563K (550K - 577K)

  function createVault(address[] vaultTokens_, address owner_, uint24 fee_, address uniV3Helper_) external returns (contract IUniV3Vault vault, uint256 nft)

Deploys a new vault.

Parameters:

Specs

  • ✅ deploys a new vault

  • ✅ registers vault with vault registry and issues nft

  • ✅ the nft is owned by the owner from #createVault arguments

  • ✅ vault is initialized with nft

Access control

  • ✅ when permissionless allowed: any address

  • ✅ when not permissionless allowed: protocol governance admin

  • ✅ when not permissionless denied: any address

Edge cases

  • ✅ when fee is not supported by uni v3 reverts

Structs

struct DelayedProtocolParams {
    INonfungiblePositionManager positionManager;
    IOracle oracle;
}
struct DelayedStrategyParams {
    uint32 safetyIndicesSet;
}
struct InternalParams {
    IProtocolGovernance protocolGovernance;
    IVaultRegistry registry;
    IVault singleton;
}

Events

StageDelayedProtocolParams

  event StageDelayedProtocolParams(address origin, address sender, struct IUniV3VaultGovernance.DelayedProtocolParams params, uint256 when)

Emitted when new DelayedProtocolParams are staged for commit

Parameters:

CommitDelayedProtocolParams

  event CommitDelayedProtocolParams(address origin, address sender, struct IUniV3VaultGovernance.DelayedProtocolParams params)

Emitted when new DelayedProtocolParams are committed

Parameters:

StageDelayedStrategyParams

  event StageDelayedStrategyParams(address origin, address sender, uint256 nft, struct IUniV3VaultGovernance.DelayedStrategyParams params, uint256 when)

Emitted when new DelayedStrategyParams are staged for commit

Parameters:

CommitDelayedStrategyParams

  event CommitDelayedStrategyParams(address origin, address sender, uint256 nft, struct IUniV3VaultGovernance.DelayedStrategyParams params)

Emitted when new DelayedStrategyParams are committed

Parameters:

Vault

Inherits from ERC165

Abstract contract that has logic common for every Vault.

📕 Notes:

ERC-721

Each Vault should be registered in VaultRegistry and get corresponding VaultRegistry NFT.

Access control

push and pull methods are only allowed for owner / approved person of the NFT. However, pull for approved person also checks that pull destination is another vault of the Vault System.

The semantics is: NFT owner owns all Vault liquidity, Approved person is liquidity manager. ApprovedForAll person cannot do anything except ERC-721 token transfers.

Both NFT owner and approved person can call externalCall method which claims liquidity mining rewards (if any)

reclaimTokens for mistakenly transfered tokens (not included into vaultTokens) additionally can be withdrawn by the protocol admin

Functions

initialized

  function initialized() external returns (bool)

Checks if the vault is initialized

isVaultToken

  function isVaultToken(address token) public returns (bool)

Checks if a token is vault token

Parameters:

Return Values:

vaultGovernance

  function vaultGovernance() external returns (contract IVaultGovernance)

Address of the Vault Governance for this contract.

vaultTokens

  function vaultTokens() external returns (address[])

ERC20 tokens under Vault management.

nft

  function nft() external returns (uint256)

VaultRegistry NFT for this vault

tvl

  function tvl() public returns (uint256[] minTokenAmounts, uint256[] maxTokenAmounts)

Total value locked for this contract.

📕 Generally it is the underlying token value of this contract in some other DeFi protocol. For example, for USDC Yearn Vault this would be total USDC balance that could be withdrawn for Yearn to this contract. The tvl itself is estimated in some range. Sometimes the range is exact, sometimes it's not

Return Values:

pullExistentials

  function pullExistentials() external returns (uint256[])

Existential amounts for each token

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Events

Initialized

  event Initialized(address origin, address sender, address[] vaultTokens_, uint256 nft_)

Emitted when Vault is intialized

Parameters:

VaultGovernance

Inherits from ERC165

Internal contract for managing different params.

📕 The contract should be overriden by the concrete VaultGovernance, define different params structs and use abi.decode / abi.encode to serialize to bytes in this contract. It also should emit events on params change.

Functions

delayedStrategyParamsTimestamp

  function delayedStrategyParamsTimestamp(uint256 nft) external returns (uint256)

Timestamp in unix time seconds after which staged Delayed Strategy Params could be committed.

Parameters:

delayedProtocolPerVaultParamsTimestamp

  function delayedProtocolPerVaultParamsTimestamp(uint256 nft) external returns (uint256)

Timestamp in unix time seconds after which staged Delayed Protocol Params Per Vault could be committed.

Parameters:

delayedProtocolParamsTimestamp

  function delayedProtocolParamsTimestamp() external returns (uint256)

Timestamp in unix time seconds after which staged Delayed Protocol Params could be committed.

internalParamsTimestamp

  function internalParamsTimestamp() external returns (uint256)

Timestamp in unix time seconds after which staged Internal Params could be committed.

internalParams

  function internalParams() external returns (struct IVaultGovernance.InternalParams)

Internal Params of the contract.

stagedInternalParams

  function stagedInternalParams() external returns (struct IVaultGovernance.InternalParams)

Staged new Internal Params.

📕 The Internal Params could be committed after internalParamsTimestamp

supportsInterface

  function supportsInterface(bytes4 interfaceID) public returns (bool)

stageInternalParams

  function stageInternalParams(struct IVaultGovernance.InternalParams newParams) external

Stage new Internal Params.

Parameters:

commitInternalParams

  function commitInternalParams() external

Commit staged Internal Params.

Structs

struct InternalParams {
    IProtocolGovernance protocolGovernance;
    IVaultRegistry registry;
    IVault singleton;
}

Events

StagedInternalParams

  event StagedInternalParams(address origin, address sender, struct IVaultGovernance.InternalParams params, uint256 when)

Emitted when InternalParams are staged for commit

Parameters:

CommitedInternalParams

  event CommitedInternalParams(address origin, address sender, struct IVaultGovernance.InternalParams params)

Emitted when InternalParams are staged for commit

Parameters:

DeployedVault

  event DeployedVault(address origin, address sender, address[] vaultTokens, bytes options, address owner, address vaultAddress, uint256 vaultNft)

Emitted when New Vault is deployed

Parameters:

YearnVault

Inherits from Vault, ERC165, ReentrancyGuard

⛽ 4.81M

Vault that interfaces Yearn protocol in the integration layer.

📕 Notes: TVL

The TVL of the vault is updated after each deposit withdraw.

yTokens yTokens are fixed at the token creation and addresses are taken from YearnVault governance and if missing there

  • in YearnVaultRegistry. So essentially each yToken is fixed for life of the YearnVault. If the yToken is missing for some vaultToken, the YearnVault cannot be created.

Push / Pull There are some deposit limits imposed by Yearn vaults. The contract's vaultTokens are fully allowed to corresponding yTokens.

yTokens

  function yTokens() external returns (address[])

Yearn protocol vaults used by this contract

Specs

  • ✅ returns list of yTokens

tvl

  function tvl() public returns (uint256[] minTokenAmounts, uint256[] maxTokenAmounts)

Total value locked for this contract.

📕 Generally it is the underlying token value of this contract in some other DeFi protocol. For example, for USDC Yearn Vault this would be total USDC balance that could be withdrawn for Yearn to this contract. The tvl itself is estimated in some range. Sometimes the range is exact, sometimes it's not

Return Values:

Specs

  • ✅ returns total value locked

  • ✅ edge cases: when there are no initial funds returns zeroes

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true if this contract supports 0x073ab565 interface

  • ✅ access control: allowed: any address

  • ✅ returns true if this contract supports 0x7a63aa3a interface

  • ✅ access control: allowed: any address

  • ✅ edge cases: when contract does not support the given interface returns false

initialize

  function initialize(uint256 nft_, address[] vaultTokens_) external

Initialized a new contract.

📕 Can only be initialized by vault governance

Parameters:

Specs

  • ✅ emits Initialized event

  • ✅ initializes contract successfully

  • ✅ edge cases: when vault's nft is not 0 reverts with INIT

  • ✅ edge cases: when tokens are not sorted reverts with INVA

  • ✅ edge cases: when tokens are not unique reverts with INVA

  • ✅ edge cases: when setting zero nft reverts with VZ

  • ✅ edge cases: when token has no permission to become a vault token reverts with FRB

YearnVaultGovernance

Inherits from VaultGovernance, ERC165, ContractMeta

⛽ 2.4M

Governance that manages all Aave Vaults params and can deploy a new Aave Vault.

Functions

constructor

  function constructor(struct IVaultGovernance.InternalParams internalParams_, struct IYearnVaultGovernance.DelayedProtocolParams delayedProtocolParams_) public

Creates a new contract

Parameters:

Specs

  • ✅ deploys a new contract

  • ✅ initializes internalParams

Edge cases

  • ✅ when YearnVaultRegistry address is 0 reverts

  • ✅ when protocolGovernance address is 0 reverts

  • ✅ when vaultRegistry address is 0 reverts

yTokenForToken

  function yTokenForToken(address token) external returns (address)

Determines a corresponding Yearn vault for token

Parameters:

Return Values:

Specs

  • ✅ returns yToken (yVault) in yToken overrides (set by #setYTokenForToken) or corresponding to ERC20 token in YearnVaultRegistry

Access control

  • ✅ allowed: any address

Edge cases

  • ✅ when yToken doesn't exist in overrides or YearnVaultRegistry returns 0

  • ✅ when yToken was not overridden by #setYTokenForToken returns token from YearnVaultRegistry

  • ✅ when yToken was overridden by #setYTokenForToken returns overridden token

stagedDelayedProtocolParams

  function stagedDelayedProtocolParams() external returns (struct IYearnVaultGovernance.DelayedProtocolParams)

Delayed Protocol Params staged for commit after delay.

Specs

  • ✅ returns DelayedProtocolParams staged for commit

Access control

  • ✅ allowed: any address

Properties

  • ✅ always equals to params that were just staged

Edge cases

  • ✅ when no params are staged for commit returns zero struct

  • ✅ when params were just committed returns zero struct

delayedProtocolParams

  function delayedProtocolParams() public returns (struct IYearnVaultGovernance.DelayedProtocolParams)

Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Specs

  • ✅ returns current DelayedProtocolParams

Access control

  • ✅ allowed: any address

Properties

  • ✅ staging DelayedProtocolParams doesn't change delayedProtocolParams

Edge cases

  • ✅ when no params were committed returns non-zero params initialized in constructor

supportsInterface

  function supportsInterface(bytes4 interfaceId) public returns (bool)

📕 Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Specs

  • ✅ returns true if this contract supports 0x15482137 interface

  • ✅ access control: allowed: any address

stageDelayedProtocolParams

⛽ 75K (49K - 106K)

  function stageDelayedProtocolParams(struct IYearnVaultGovernance.DelayedProtocolParams params) external

Stage Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

📕 Can only be called after delayedProtocolParamsTimestamp.

Parameters:

Specs

  • ✅ stages DelayedProtocolParams for commit

  • ✅ sets delay for commit

  • ✅ emits StageDelayedProtocolParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

Edge cases

  • ✅ when called twice succeeds with the last value

  • ✅ when called with zero params reverts with zero params

commitDelayedProtocolParams

⛽ 43K (43K - 45K)

  function commitDelayedProtocolParams() external

Commit Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay.

Specs

  • ✅ commits staged DelayedProtocolParams

  • ✅ resets delay for commit

  • ✅ emits CommitDelayedProtocolParams event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Properties

  • ✅ cannot be called by random address

  • ✅ reverts if called before the delay has elapsed

  • ✅ succeeds if called after the delay has elapsed

Edge cases

  • ✅ when called twice reverts

  • ✅ when nothing is staged reverts

  • ✅ when delay has not elapsed reverts

setYTokenForToken

⛽ 51K (35K - 56K)

  function setYTokenForToken(address token, address yToken) external

Sets the manual override for yToken vaults map

📕 Can only be called by Protocol Admin

Parameters:

Specs

  • ✅ sets a yToken override for a ERC20 token

  • ✅ emits SetYToken event

Access control

  • ✅ allowed: ProtocolGovernance admin

  • ✅ denied: Vault NFT Owner (aka liquidity provider)

  • ✅ denied: Vault NFT Approved (aka strategy)

  • ✅ denied: deployer

  • ✅ denied: random address

Edge cases

  • ✅ when yToken is 0 succeeds

  • ✅ when called twice succeeds

createVault

⛽ 569K (559K - 810K)

  function createVault(address[] vaultTokens_, address owner_) external returns (contract IYearnVault vault, uint256 nft)

Deploys a new vault.

Parameters:

Specs

  • ✅ deploys a new vault

  • ✅ registers vault with vault registry and issues nft

  • ✅ the nft is owned by the owner from #createVault arguments

  • ✅ vault is initialized with nft

Access control

  • ✅ when permissionless allowed: any address

  • ✅ when not permissionless allowed: protocol governance admin

  • ✅ when not permissionless denied: any address

Structs

struct DelayedProtocolParams {
    IYearnProtocolVaultRegistry yearnVaultRegistry;
}
struct InternalParams {
    IProtocolGovernance protocolGovernance;
    IVaultRegistry registry;
    IVault singleton;
}

Events

SetYToken

  event SetYToken(address origin, address sender, address token, address yToken)

Emitted when new yToken is set

Parameters:

StageDelayedProtocolParams

  event StageDelayedProtocolParams(address origin, address sender, struct IYearnVaultGovernance.DelayedProtocolParams params, uint256 when)

Emitted when new DelayedProtocolParams are staged for commit

Parameters:

CommitDelayedProtocolParams

  event CommitDelayedProtocolParams(address origin, address sender, struct IYearnVaultGovernance.DelayedProtocolParams params)

Emitted when new DelayedProtocolParams are committed

Parameters:

Last updated