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 Euclidean Protocol 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

vaults3

  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:

Euclidean Oracle

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;
}