Skip to content
LogoLogo

MachineUtils

Git Source

Constants

RATE_SCALE

uint256 private constant RATE_SCALE = 1e18;

MAX_SNAPSHOT_FUTURE_TOLERANCE

Max seconds a snapshot timestamp may be ahead of the current hub block timestamp and still be accepted, to absorb cross-chain clock skew.

uint256 private constant MAX_SNAPSHOT_FUTURE_TOLERANCE = 60;

Functions

updateTotalAum

Updates the total AUM of the machine and performs share price change check.

function updateTotalAum(Machine.MachineStorage storage $, address oracleRegistry, bool sharePriceChangeCheck)
        external
        returns (uint256);

Parameters

NameTypeDescription
$Machine.MachineStorageThe machine storage struct.
oracleRegistryaddressThe address of the oracle registry.
sharePriceChangeCheckboolTrue to perform share price change check, false to bypass it.

Returns

NameTypeDescription
<none>uint256The updated total AUM.

manageFees

Manages the fee minting process, including calculating and minting fixed and performance fees.

function manageFees(Machine.MachineStorage storage $) external returns (uint256);

Parameters

NameTypeDescription
$Machine.MachineStorageThe machine storage struct.

Returns

NameTypeDescription
<none>uint256The fees minted in share tokens.

reportSpokeAccountingSnapshots

Reports spoke caliber accounting snapshots by decoding the report payload and updating the machine storage accordingly.

function reportSpokeAccountingSnapshots(
        Machine.MachineStorage storage $,
        address tokenRegistry,
        bytes calldata report
    ) external;

Parameters

NameTypeDescription
$Machine.MachineStorageThe machine storage struct.
tokenRegistryaddressThe address of the token registry.
reportbytesThe report payload containing the accounting data.

migrateFromPreDeposit

Manages the migration from a pre-deposit vault to a machine, and initializes the machine's AUM.

function migrateFromPreDeposit(Machine.MachineStorage storage $, address preDepositVault, address oracleRegistry)
        external;

Parameters

NameTypeDescription
$Machine.MachineStorageThe machine storage struct.
preDepositVaultaddressThe address of the pre-deposit vault.
oracleRegistryaddressThe address of the oracle registry.

checkBridgeTransfersSettled

Checks that there are no pending bridge transfers between the machine and a spoke caliber.

function checkBridgeTransfersSettled(IMachine.SpokeCaliberData storage spokeCaliberData) external view;

Parameters

NameTypeDescription
spokeCaliberDataIMachine.SpokeCaliberDataThe spoke caliber data struct containing the bridge transfer records.

getSharePrice

Calculates the share price based on given AUM, share supply and share token decimals offset.

function getSharePrice(uint256 aum, uint256 supply, uint256 shareTokenDecimalsOffset)
        public
        pure
        returns (uint256);

Parameters

NameTypeDescription
aumuint256The AUM of the machine.
supplyuint256The supply of the share token.
shareTokenDecimalsOffsetuint256The decimals offset between share token and accounting token.

Returns

NameTypeDescription
<none>uint256The calculated share price.

_handlePerChainSnapshot

Handles an accounting snapshot received from a spoke chain and updates the corresponding accounting state stored in the machine.

function _handlePerChainSnapshot(
        Machine.MachineStorage storage $,
        address tokenRegistry,
        ICaliberMailbox.SpokeCaliberAccountingData memory snapshot
    ) private;

Parameters

NameTypeDescription
$Machine.MachineStorageThe machine storage struct.
tokenRegistryaddressThe address of the token registry.
snapshotICaliberMailbox.SpokeCaliberAccountingDataThe accounting snapshot data.

_decodeAndMapBridgeAmounts

Decodes (foreignToken, amount) pairs, resolves local tokens, and stores amounts in the map.

function _decodeAndMapBridgeAmounts(
        uint256 chainId,
        bytes[] memory data,
        EnumerableMap.AddressToUintMap storage map,
        address tokenRegistry
    ) private;

Parameters

NameTypeDescription
chainIduint256
databytes[]
mapEnumerableMap.AddressToUintMap
tokenRegistryaddress

_getTotalAum

Computes the total AUM of the machine.

function _getTotalAum(Machine.MachineStorage storage $, address oracleRegistry) private view returns (uint256);

Parameters

NameTypeDescription
$Machine.MachineStorageThe machine storage struct.
oracleRegistryaddressThe address of the oracle registry.

Returns

NameTypeDescription
<none>uint256

_checkBridgeState

Checks if the bridge state is consistent between the machine and spoke caliber.

function _checkBridgeState(
        EnumerableMap.AddressToUintMap storage insMap,
        EnumerableMap.AddressToUintMap storage outsMap
    ) private view;

Parameters

NameTypeDescription
insMapEnumerableMap.AddressToUintMap
outsMapEnumerableMap.AddressToUintMap

_accountingValueOf

Computes the accounting value of a given token amount.

function _accountingValueOf(address oracleRegistry, address accountingToken, address token, uint256 amount)
        private
        view
        returns (uint256);

Parameters

NameTypeDescription
oracleRegistryaddress
accountingTokenaddress
tokenaddress
amountuint256

Returns

NameTypeDescription
<none>uint256

_checkMaxRelativeChange

Checks that the relative change between two values does not exceed the maximum allowed rate over elapsed time.

function _checkMaxRelativeChange(
        uint256 previousValue,
        uint256 newValue,
        uint256 maxPercentDeltaPerSecond,
        uint256 elapsedTime
    ) private pure;

Parameters

NameTypeDescription
previousValueuint256
newValueuint256
maxPercentDeltaPerSeconduint256
elapsedTimeuint256