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:

NameTypeDescription

name

string

Name of the contract

versionAddress

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

Address of the contract at a given version

Parameters:

NameTypeDescription

name

string

Name of the contract

version

string

Version of the contract

latestVersion

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

Latest version of the contract

Parameters:

NameTypeDescription

name

string

Name of the contract

registerContract

⛽ 256K (254K - 259K)

  function registerContract(address target) external

Register a new contract

Parameters:

NameTypeDescription

target

address

Address of the contract to be registered

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:

NameTypeDescription

admin

address

Initial admin of the contract

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:

NameTypeDescription

i

uint256

The number of address

Return Values:

NameTypeDescription

Validator

address

address

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:

NameTypeDescription

permissionId

uint8

Id of the permission to check.

Return Values:

NameTypeDescription

A

address[]

list of dirty addresses.

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:

NameTypeDescription

addr

address

Address to check

permissionId

uint8

Permission to check

hasAllPermissions

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

Checks if address has all permissions.

Parameters:

NameTypeDescription

target

address

Address to check

permissionIds

uint8[]

A list of permissions to check

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:

NameTypeDescription

token

address

Address of the token

Return Values:

NameTypeDescription

Withdraw

uint256

limit per token per block

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:

NameTypeDescription

target

address

The given address

validator

address

The validator for the given address

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:

NameTypeDescription

target

address

The given address.

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:

NameTypeDescription

Addresses

address[]

for which validators were committed

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:

NameTypeDescription

target

address

The given address

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:

NameTypeDescription

target

address

The given address.

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:

NameTypeDescription

An

address[]

array of addresses for which permission grants were committed.

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:

NameTypeDescription

target

address

The given address.

permissionIds

uint8[]

A list of permission ids to revoke.

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:

NameTypeDescription

target

address

Target address

permissionIds

uint8[]

A list of permission ids to grant

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:

NameTypeDescription

newParams

struct IProtocolGovernance.Params

New protocol parameters to set.

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:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

target

address

Target address

validator

address

Staged validator

at

uint256

Timestamp when the staged permissions could be committed

ValidatorRevoked

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

Validator revoked

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

target

address

Target address

AllStagedValidatorsRolledBack

  event AllStagedValidatorsRolledBack(address origin, address sender)

Emitted when staged validators are rolled back

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

ValidatorCommitted

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

Emitted when staged validators are comitted for specific address

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

target

address

Target address

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:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

target

address

Target address

permissionIds

uint8[]

Permission IDs to be granted

at

uint256

Timestamp when the staged permissions could be committed

PermissionsRevoked

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

Emitted when permissions are revoked

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

target

address

Target address

permissionIds

uint8[]

Permission IDs to be revoked

AllStagedPermissionGrantsRolledBack

  event AllStagedPermissionGrantsRolledBack(address origin, address sender)

Emitted when staged permissions are rolled back

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

PermissionGrantsCommitted

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

Emitted when staged permissions are comitted for specific address

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

target

address

Target address

ParamsStaged

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

Emitted when pending parameters are set

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

at

uint256

Timestamp when the pending parameters could be committed

params

struct IProtocolGovernance.Params

Pending parameters

ParamsCommitted

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

Emitted when pending parameters are committed

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

params

struct IProtocolGovernance.Params

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:

NameTypeDescription

token

address

Address of the token

value

uint256

The amount of token

rollbackUnitPrice

⛽ 31K (30K - 31K)

  function rollbackUnitPrice(address token) external

Reset staged value

Parameters:

NameTypeDescription

token

address

Address of the token

commitUnitPrice

⛽ 50K

  function commitUnitPrice(address token) external

Commit staged unit price

Parameters:

NameTypeDescription

token

address

Address of the token

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:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

token

address

Token address

unitPrice

uint256

Unit price

UnitPriceRolledBack

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

UnitPrice rolled back

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

token

address

Token address

UnitPriceCommitted

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

UnitPrice committed

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

token

address

Token address

unitPrice

uint256

Unit price

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:

NameTypeDescription

name

string

ERC721 token name

symbol

string

ERC721 token symbol

protocolGovernance_

contract IProtocolGovernance

Reference to ProtocolGovernance

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:

NameTypeDescription

nftId

uint256

NFT ID

Return Values:

NameTypeDescription

vault

address

Address of the Vault contract

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:

NameTypeDescription

vault

address

Address of the Vault contract

Return Values:

NameTypeDescription

nftId

uint256

NFT ID

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:

NameTypeDescription

nft

uint256

NFT to check for lock

Return Values:

NameTypeDescription

if

bool

locked, false otherwise

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:

NameTypeDescription

vault

address

address of the vault

owner

address

owner of the NFT

Return Values:

NameTypeDescription

nft

uint256

Nft minted for the given Vault

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:

NameTypeDescription

newProtocolGovernance

contract IProtocolGovernance

new ProtocolGovernance

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:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

nft

uint256

NFT to be locked

VaultRegistered

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

Emitted when new Vault is registered in VaultRegistry

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

nft

uint256

VaultRegistry NFT of the vault

vault

address

Address of the Vault contract

owner

address

Owner of the VaultRegistry NFT

StagedProtocolGovernance

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

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

newProtocolGovernance

contract IProtocolGovernance

Address of the new ProtocolGovernance

start

uint256

Timestamp of the start of the new ProtocolGovernance

CommitedProtocolGovernance

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

Parameters:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

newProtocolGovernance

contract IProtocolGovernance

Address of the new ProtocolGovernance that has been committed

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:

NameTypeDescription

token

address

token address

Return Values:

NameTypeDescription

if

bool

token is allowed, false o/w

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:

NameTypeDescription

token0

address

Reference to token0

token1

address

Reference to token1

safetyIndicesSet

uint256

Bitmask of safety indices that are allowed for the return prices. For set of safety indexes = { 1 }, safetyIndicesSet = 0x2

Return Values:

NameTypeDescription

pricesX96

uint256[]

Prices that satisfy safetyIndex and tokens

safetyIndices

uint256[]

Safety indices for those prices

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:

NameTypeDescription

tokens

address[]

ERC20 tokens for the feed

oracles

address[]

Chainlink oracle price feeds (token / USD)

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:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

tokens

address[]

Tokens added

oracles

address[]

Orecles added for the tokens

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:

NameTypeDescription

token0

address

Reference to token0

token1

address

Reference to token1

safetyIndicesSet

uint256

Bitmask of safety indices that are allowed for the return prices. For set of safety indexes = { 1 }, safetyIndicesSet = 0x2

Return Values:

NameTypeDescription

pricesX96

uint256[]

Prices that satisfy safetyIndex and tokens

safetyIndices

uint256[]

Safety indices for those prices

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:

NameTypeDescription

token0

address

Reference to token0

token1

address

Reference to token1

safetyIndicesSet

uint256

Bitmask of safety indices that are allowed for the return prices. For set of safety indexes = { 1 }, safetyIndicesSet = 0x2

Return Values:

NameTypeDescription

pricesX96

uint256[]

Prices that satisfy safetyIndex and tokens

safetyIndices

uint256[]

Safety indices for those prices

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:

NameTypeDescription

pools

contract IUniswapV3Pool[]

Pools to add

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:

NameTypeDescription

origin

address

Origin of the transaction (tx.origin)

sender

address

Sender of the call (msg.sender)

pools

contract IUniswapV3Pool[]

UniV3 pools added

replacedPools

contract IUniswapV3Pool[]

UniV3 pools updated

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:

NameTypeDescription

positionManager_

contract INonfungiblePositionManager

the position manager for uniV3

router_

contract ISwapRouter

the uniV3 router for swapping tokens

uniV3Helper_

address

the address of the helper contract for uniV3

hStrategyHelper_

address

the address of the strategy helper contract

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:

NameTypeDescription

tokens_

address[]

the addresses of the tokens managed by the strategy

erc20Vault_

contract IERC20Vault

the address of the erc20 vault

moneyVault_

contract IIntegrationVault

the address of the moneyVault. It is expected to be yEarn or AAVE

uniV3Vault_

contract IUniV3Vault

the address of uniV3Vault. It is expected to not hold the position

fee_

uint24

the fee of the uniV3 pool on which the vault operates

admin_

address

the addres of the admin of the strategy

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:

NameTypeDescription

tokens_

address[]

the addresses of the tokens managed by the strategy

erc20Vault_

contract IERC20Vault

the address of the erc20 vault

moneyVault_

contract IIntegrationVault

the address of the moneyVault. It is expected to be yEarn or AAVE

uniV3Vault_

contract IUniV3Vault

the address of uniV3Vault. It is expected to not hold the position

fee_

uint24

the fee of the uniV3 pool on which the vault operates

admin_

address

the addres of the admin of the strategy

Return Values:

NameTypeDescription

strategy

contract HStrategy

the address of new strategy

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:

NameTypeDescription

newStrategyParams

struct HStrategy.StrategyParams

the new parameters

updateMintingParams

  function updateMintingParams(struct HStrategy.MintingParams newMintingParams) external

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

Parameters:

NameTypeDescription

newMintingParams

struct HStrategy.MintingParams

the new parameters

updateOracleParams

  function updateOracleParams(struct HStrategy.OracleParams newOracleParams) external

updates oracle parameters. Can be called only by admin

Parameters:

NameTypeDescription

newOracleParams

struct HStrategy.OracleParams

the new 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:

NameTypeDescription

newRatioParams

struct HStrategy.RatioParams

the new parameters

updateSwapFees

  function updateSwapFees(uint24 newSwapFees) external

updates swap fees for uniswapV3Pool swaps

Parameters:

NameTypeDescription

newSwapFees

uint24

the new 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:

NameTypeDescription

fromVault

contract IIntegrationVault

the address of the vault to pull tokens from

toVault

contract IIntegrationVault

the address of the vault to pull tokens to

tokenAmounts

uint256[]

the amount of tokens to be pulled

vaultOptions

bytes

additional options for pull method

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:

NameTypeDescription

restrictions

struct HStrategy.RebalanceTokenAmounts

the restrictions of the amount of tokens to be transferred

moneyVaultOptions

bytes

additional parameters for pulling for pull method for money vault

Return Values:

NameTypeDescription

actualPulledAmounts

struct HStrategy.RebalanceTokenAmounts

actual transferred amounts

burnedAmounts

uint256[]

actual burned amounts from uniV3 position

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;