Skip to main content

Solidity API

InternalStatesOrchestrator

Contract that orchestrates internal state management

_This contract is responsible for:

  • Reading current vault states and market data;
  • Processing deposit requests from LPs;
  • Processing curator fees and high water mark;
  • Updating vault states;
  • Computing state estimations for Liquidity Orchestrator;
  • Trigger the Liquidity Orchestrator._

automationRegistry

address automationRegistry

Chainlink Automation Registry address

config

contract IOrionConfig config

Orion Config contract address

liquidityOrchestrator

contract ILiquidityOrchestrator liquidityOrchestrator

Liquidity Orchestrator contract

registry

contract IPriceAdapterRegistry registry

Price Adapter Registry contract

priceAdapterPrecision

uint256 priceAdapterPrecision

Price Adapter Precision

intentFactor

uint256 intentFactor

Intent factor for calculations

underlyingAsset

address underlyingAsset

Underlying asset address

underlyingDecimals

uint8 underlyingDecimals

Decimals of the underlying asset

vFeeCoefficient

uint16 vFeeCoefficient

Volume fee coefficient

rsFeeCoefficient

uint16 rsFeeCoefficient

Revenue share fee coefficient

pendingProtocolFees

uint256 pendingProtocolFees

Pending protocol fees [assets]

BASIS_POINTS_FACTOR

uint16 BASIS_POINTS_FACTOR

Basis points factor

EpochState

Struct to hold epoch state data

struct EpochState {
mapping(address => uint256) priceArray;
mapping(address => uint256) initialBatchPortfolio;
mapping(address => euint128) encryptedInitialBatchPortfolio;
mapping(address => uint256) vaultsTotalAssets;
mapping(address => euint128) encryptedVaultsTotalAssets;
mapping(address => uint256) finalBatchPortfolio;
mapping(address => euint128) encryptedFinalBatchPortfolio;
mapping(address => uint256) vaultsTotalAssetsForFulfillRedeem;
mapping(address => uint256) sellingOrders;
mapping(address => uint256) buyingOrders;
address[] tokens;
mapping(address => bool) tokenExists;
}

_currentEpoch

struct InternalStatesOrchestrator.EpochState _currentEpoch

Current epoch state

epochDuration

uint32 epochDuration

Epoch duration

epochCounter

uint16 epochCounter

Counter for tracking processing cycles

transparentMinibatchSize

uint8 transparentMinibatchSize

Transparent minibatch size

encryptedMinibatchSize

uint8 encryptedMinibatchSize

Encrypted minibatch size

currentPhase

enum IInternalStateOrchestrator.InternalUpkeepPhase currentPhase

Upkeep phase

currentMinibatchIndex

uint8 currentMinibatchIndex

Current minibatch index

_ezero

euint128 _ezero

FHE zero

transparentVaultsEpoch

address[] transparentVaultsEpoch

Transparent vaults associated to the current epoch

encryptedVaultsEpoch

address[] encryptedVaultsEpoch

Encrypted vaults associated to the current epoch

validEncryptedVaultsCount

uint16 validEncryptedVaultsCount

Number of valid encrypted vaults processed in current epoch

bufferAmount

uint256 bufferAmount

Buffer amount [assets]

_decryptedValues

uint256[] _decryptedValues

Decrypted values from the FHEVM callback

onlyAutomationRegistry

modifier onlyAutomationRegistry()

Restricts function to only Chainlink Automation registry

onlyLiquidityOrchestrator

modifier onlyLiquidityOrchestrator()

Restricts function to only Liquidity Orchestrator

constructor

constructor(address initialOwner, address config_, address automationRegistry_) public

Constructor

Parameters

NameTypeDescription
initialOwneraddressThe address of the initial owner
config_addressThe address of the OrionConfig contract
automationRegistry_addressThe address of the Chainlink Automation Registry

updateAutomationRegistry

function updateAutomationRegistry(address newAutomationRegistry) external

Updates the Chainlink Automation Registry address

Parameters

NameTypeDescription
newAutomationRegistryaddressThe new automation registry address

updateEpochDuration

function updateEpochDuration(uint32 newEpochDuration) external

Updates the epoch duration

Parameters

NameTypeDescription
newEpochDurationuint32The new epoch duration in seconds

updateMinibatchSizes

function updateMinibatchSizes(uint8 _transparentMinibatchSize, uint8 _encryptedMinibatchSize) external

Updates the minibatch sizes

Parameters

NameTypeDescription
_transparentMinibatchSizeuint8The new transparent minibatch size
_encryptedMinibatchSizeuint8The new encrypted minibatch size

updateProtocolFees

function updateProtocolFees(uint16 _vFeeCoefficient, uint16 _rsFeeCoefficient) external

Updates the protocol fees

Parameters

NameTypeDescription
_vFeeCoefficientuint16The new volume fee coefficient
_rsFeeCoefficientuint16The new revenue share fee coefficient

checkUpkeep

function checkUpkeep(bytes) external view returns (bool upkeepNeeded, bytes performData)

Checks if upkeep is needed based on time interval

https://docs.chain.link/chainlink-automation/reference/automation-interfaces

Return Values

NameTypeDescription
upkeepNeededboolTrue if upkeep is needed, false otherwise
performDatabytesEncoded data needed to perform the upkeep

performUpkeep

function performUpkeep(bytes performData) external

Performs state reading and estimation operations

Parameters

NameTypeDescription
performDatabytesEncoded data containing the action type and minibatch index

_computeNextUpdateTime

function _computeNextUpdateTime(uint256 currentTime) internal view returns (uint256)

Computes the next update time based on current timestamp

Parameters

NameTypeDescription
currentTimeuint256Current block timestamp

Return Values

NameTypeDescription
[0]uint256Next update time

_shouldTriggerUpkeep

function _shouldTriggerUpkeep() internal view returns (bool)

Checks if upkeep should be triggered based on time

Return Values

NameTypeDescription
[0]boolTrue if upkeep should be triggered

_handleStart

function _handleStart() internal

Updates the next update time and resets the previous epoch state variables

_preprocessTransparentMinibatch

function _preprocessTransparentMinibatch(uint8 minibatchIndex) internal

Preprocesses minibatch of transparent vaults

Parameters

NameTypeDescription
minibatchIndexuint8The index of the minibatch to process

_preprocessEncryptedMinibatch

function _preprocessEncryptedMinibatch(uint8 minibatchIndex) internal

Preprocesses minibatch of encrypted vaults

Parameters

NameTypeDescription
minibatchIndexuint8The index of the minibatch to process

callbackPreProcessDecrypt

function callbackPreProcessDecrypt(uint256 requestID, bytes cleartexts, bytes decryptionProof) external

Callback function to decrypt the encrypted values

Parameters

NameTypeDescription
requestIDuint256The request ID
cleartextsbytesThe cleartexts
decryptionProofbytesThe decryption proof

_processDecryptedValues

function _processDecryptedValues() internal

Processes decrypted values from encrypted vaults to complete preprocessing

This function completes the fee calculations and state updates for encrypted vaults using the decrypted values from the FHEVM callback

_buffer

function _buffer() internal

Updates the protocol buffer to maintain solvency and capital efficiency

_In general, this function implements a stochastic optimal control framework for buffer management that balances critical objectives and acts as a clearing house for market impact.

  1. Solvency Constraint: The buffer must remain non-negative at all times to ensure protocol solvency.

  2. Capital Efficiency: The buffer size should be minimized relative to Total Value Locked (TVL) to reduce capital inefficiency.

Buffer Management Strategy:

  • Calculates the total protocol assets across all vaults (transparent and encrypted)
  • Determines the target buffer amount based on the configured target ratio
  • Only increases the buffer if current buffer is below target (no buffer reduction)
  • Distributes the buffer cost proportionally across all vaults_

_postprocessTransparentMinibatch

function _postprocessTransparentMinibatch(uint8 minibatchIndex) internal

Postprocesses minibatch of transparent vaults

Parameters

NameTypeDescription
minibatchIndexuint8The index of the minibatch to postprocess

_postprocessEncryptedMinibatch

function _postprocessEncryptedMinibatch(uint8 minibatchIndex) internal

Postprocesses minibatch of encrypted vaults

Parameters

NameTypeDescription
minibatchIndexuint8The index of the minibatch to postprocess

_addTokenIfNotExists

function _addTokenIfNotExists(address token) internal

Adds a token to the current epoch if it doesn't exist

Parameters

NameTypeDescription
tokenaddressThe token address to add

_buildOrders

function _buildOrders() internal

Builds selling and buying orders based on portfolio differences

_Compares _finalBatchPortfolio with _initialBatchPortfolio to determine rebalancing needs Orders are stored in _currentEpoch.sellingOrders and currentEpoch.buyingOrders.

getOrders

function getOrders() external view returns (address[] sellingTokens, uint256[] sellingAmounts, address[] buyingTokens, uint256[] buyingAmounts, uint256[] sellingEstimatedUnderlyingAmounts, uint256[] buyingEstimatedUnderlyingAmounts)

Get selling and buying orders

Return Values

NameTypeDescription
sellingTokensaddress[]The tokens to sell
sellingAmountsuint256[]The amounts to sell in shares
buyingTokensaddress[]The tokens to buy
buyingAmountsuint256[]The amounts to buy in underlying assets
sellingEstimatedUnderlyingAmountsuint256[]The estimated underlying amounts to sell
buyingEstimatedUnderlyingAmountsuint256[]The estimated underlying amounts to buy

getPriceOf

function getPriceOf(address token) external view returns (uint256 price)

Get price for a specific token

Parameters

NameTypeDescription
tokenaddressThe token to get the price of

Return Values

NameTypeDescription
priceuint256The corresponding price [shares/assets]

subtractPendingProtocolFees

function subtractPendingProtocolFees(uint256 amount) external

Subtracts a specified amount from the pending protocol fees

Parameters

NameTypeDescription
amountuint256The amount to subtract from pending protocol fees

updateBufferAmount

function updateBufferAmount(int256 deltaAmount) external

Updates the buffer amount based on execution vs estimated amounts

Can only be called by the Liquidity Orchestrator

Parameters

NameTypeDescription
deltaAmountint256The amount to add/subtract from the buffer (can be negative)

getVaultTotalAssetsForFulfillRedeem

function getVaultTotalAssetsForFulfillRedeem(address vault) external view returns (uint256 totalAssets)

Get total assets for fulfill redeem for a specific vault

Parameters

NameTypeDescription
vaultaddressThe vault address

Return Values

NameTypeDescription
totalAssetsuint256The total assets for fulfill redeem