MachineUtils
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
| Name | Type | Description |
|---|---|---|
| $ | Machine.MachineStorage | The machine storage struct. |
| oracleRegistry | address | The address of the oracle registry. |
| sharePriceChangeCheck | bool | True to perform share price change check, false to bypass it. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 | The 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
| Name | Type | Description |
|---|---|---|
| $ | Machine.MachineStorage | The machine storage struct. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 | The 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
| Name | Type | Description |
|---|---|---|
| $ | Machine.MachineStorage | The machine storage struct. |
| tokenRegistry | address | The address of the token registry. |
| report | bytes | The 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
| Name | Type | Description |
|---|---|---|
| $ | Machine.MachineStorage | The machine storage struct. |
| preDepositVault | address | The address of the pre-deposit vault. |
| oracleRegistry | address | The 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
| Name | Type | Description |
|---|---|---|
| spokeCaliberData | IMachine.SpokeCaliberData | The 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
| Name | Type | Description |
|---|---|---|
| aum | uint256 | The AUM of the machine. |
| supply | uint256 | The supply of the share token. |
| shareTokenDecimalsOffset | uint256 | The decimals offset between share token and accounting token. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 | The 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
| Name | Type | Description |
|---|---|---|
| $ | Machine.MachineStorage | The machine storage struct. |
| tokenRegistry | address | The address of the token registry. |
| snapshot | ICaliberMailbox.SpokeCaliberAccountingData | The 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
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| data | bytes[] | |
| map | EnumerableMap.AddressToUintMap | |
| tokenRegistry | address |
_getTotalAum
Computes the total AUM of the machine.
function _getTotalAum(Machine.MachineStorage storage $, address oracleRegistry) private view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| $ | Machine.MachineStorage | The machine storage struct. |
| oracleRegistry | address | The address of the oracle registry. |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| insMap | EnumerableMap.AddressToUintMap | |
| outsMap | EnumerableMap.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
| Name | Type | Description |
|---|---|---|
| oracleRegistry | address | |
| accountingToken | address | |
| token | address | |
| amount | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| previousValue | uint256 | |
| newValue | uint256 | |
| maxPercentDeltaPerSecond | uint256 | |
| elapsedTime | uint256 |