Skip to content
LogoLogo

ICaliber

Git Source

Functions

initialize

Initializer of the contract.

function initialize(CaliberInitParams calldata cParams, address _accountingToken, address _hubMachineEndpoint)
        external;

Parameters

NameTypeDescription
cParamsCaliberInitParamsThe caliber initialization parameters.
_accountingTokenaddressThe address of the accounting token.
_hubMachineEndpointaddressThe address of the hub machine endpoint.

weirollVm

Address of the Weiroll VM.

function weirollVm() external view returns (address);

Returns

NameTypeDescription
<none>address

hubMachineEndpoint

Address of the hub machine endpoint.

function hubMachineEndpoint() external view returns (address);

Returns

NameTypeDescription
<none>address

accountingToken

Address of the accounting token.

function accountingToken() external view returns (address);

Returns

NameTypeDescription
<none>address

positionStaleThreshold

Maximum duration a position can remain unaccounted for before it is considered stale.

function positionStaleThreshold() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

allowedInstrRoot

Root of the Merkle tree containing allowed instructions.

function allowedInstrRoot() external view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32

timelockDuration

Duration of the allowedInstrRoot update timelock.

function timelockDuration() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

pendingAllowedInstrRoot

Value of the pending allowedInstrRoot, if any.

function pendingAllowedInstrRoot() external view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32

pendingTimelockExpiry

Effective time of the last scheduled allowedInstrRoot update.

function pendingTimelockExpiry() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

maxPositionIncreaseLossBps

Max allowed value loss (in basis points) when increasing a position.

function maxPositionIncreaseLossBps() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

maxPositionDecreaseLossBps

Max allowed value loss (in basis points) when decreasing a position.

function maxPositionDecreaseLossBps() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

maxSwapLossBps

Max allowed value loss (in basis points) for base token swaps.

function maxSwapLossBps() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

cooldownDuration

Duration of the cooldown period for swaps and position management.

function cooldownDuration() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

getPositionsLength

Length of the position IDs list.

function getPositionsLength() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

getPositionId

Position index => Position ID

There are no guarantees on the ordering of values inside the Position ID list, and it may change when values are added or removed.

function getPositionId(uint256 idx) external view returns (uint256);

Parameters

NameTypeDescription
idxuint256

Returns

NameTypeDescription
<none>uint256

getPosition

Position ID => Position data

function getPosition(uint256 posId) external view returns (Position memory);

Parameters

NameTypeDescription
posIduint256

Returns

NameTypeDescription
<none>Position

isBaseToken

Token => Registered as base token in this caliber

function isBaseToken(address token) external view returns (bool);

Parameters

NameTypeDescription
tokenaddress

Returns

NameTypeDescription
<none>bool

getBaseTokensLength

Length of the base tokens list.

function getBaseTokensLength() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

getBaseToken

Base token index => Base token address

There are no guarantees on the ordering of values inside the base tokens list, and it may change when values are added or removed.

function getBaseToken(uint256 idx) external view returns (address);

Parameters

NameTypeDescription
idxuint256

Returns

NameTypeDescription
<none>address

isInstrRootGuardian

User => Whether the user is a root guardian Guardians have veto power over updates of the Merkle root.

function isInstrRootGuardian(address user) external view returns (bool);

Parameters

NameTypeDescription
useraddress

Returns

NameTypeDescription
<none>bool

isAccountingFresh

Checks if the accounting age of each position is below the position staleness threshold.

function isAccountingFresh() external view returns (bool);

Returns

NameTypeDescription
<none>bool

getNetAum

Returns the caliber's net AUM denominated in the accounting token.

Reverts if any position's accounting is stale.

function getNetAum() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

getDetailedAum

Returns the caliber's net AUM along with detailed position and base token breakdowns.

Does not revert on stale positions. Staleness is surfaced per position via the isStale flag instead.

function getDetailedAum()
        external
        view
        returns (uint256 netAum, bytes[] memory positions, bytes[] memory baseTokens);

Returns

NameTypeDescription
netAumuint256The total value of all base token balances and positive positions, minus total debts.
positionsbytes[]The array of encoded tuples of the form (positionId, value, isDebt, isStale).
baseTokensbytes[]The array of encoded tuples of the form (token, value).

addBaseToken

Adds a new base token.

function addBaseToken(address token) external;

Parameters

NameTypeDescription
tokenaddressThe address of the base token.

removeBaseToken

Removes a base token.

function removeBaseToken(address token) external;

Parameters

NameTypeDescription
tokenaddressThe address of the base token.

accountForPosition

Accounts for a position.

If the position value goes to zero, it is closed.

function accountForPosition(Instruction calldata instruction) external returns (uint256 value, int256 change);

Parameters

NameTypeDescription
instructionInstructionThe accounting instruction.

Returns

NameTypeDescription
valueuint256The new position value.
changeint256The change in the position value.

accountForPositionBatch

Accounts for a batch of positions.

function accountForPositionBatch(Instruction[] calldata instructions, uint256[] calldata groupIds)
        external
        returns (uint256[] memory values, int256[] memory changes);

Parameters

NameTypeDescription
instructionsInstruction[]The array of accounting instructions.
groupIdsuint256[]The array of position group IDs.
An accounting instruction must be provided for every open position in each specified group.
If an instruction's groupId corresponds to a group of open positions of size greater than 1,
the group ID must be included in this array.

Returns

NameTypeDescription
valuesuint256[]The new position values.
changesint256[]The changes in the position values.

managePosition

Manages a position's state through paired management and accounting instructions.

Performs accounting updates and modifies contract storage by:

  • Adding new positions to storage when created.
  • Removing positions from storage when value reaches zero.

Applies value preservation checks using a validation matrix to prevent economic inconsistencies between position changes and token flows.

The matrix evaluates three factors to determine required validations:

  • Base Tokens flow - Whether the contract globally spent or received base tokens during operation
  • Debt Position - Whether position represents protocol liability (true) vs asset (false)
  • Position Δ direction - Direction of position value change (increase/decrease/null)

┌──────────────────┬───────────────┬──────────────────────┬───────────────────────────┐ │ Base Tokens flow │ Debt Position │ Position Δ direction │ Action │ ├──────────────────┼───────────────┼──────────────────────┼───────────────────────────┤ │ Outflow │ No │ Decrease │ Revert: Invalid direction │ │ Outflow │ Yes │ Increase │ Revert: Invalid direction │ │ Outflow │ No │ Increase / Null │ Minimum Δ Check │ │ Outflow │ Yes │ Decrease / Null │ Minimum Δ Check │ │ Inflow / Null │ No │ Decrease │ Maximum Δ Check │ │ Inflow / Null │ Yes │ Increase │ Maximum Δ Check │ │ Inflow / Null │ No │ Increase / Null │ No check (favorable move) │ │ Inflow / Null │ Yes │ Decrease / Null │ No check (favorable move) │ └──────────────────┴───────────────┴──────────────────────┴───────────────────────────┘

function managePosition(Instruction calldata mgmtInstruction, Instruction calldata acctInstruction)
        external
        returns (uint256 value, int256 change);

Parameters

NameTypeDescription
mgmtInstructionInstructionThe management instruction.
acctInstructionInstructionThe accounting instruction.

Returns

NameTypeDescription
valueuint256The new position value.
changeint256The signed position value delta.

managePositionBatch

Manages a batch of positions.

Convenience function to manage multiple positions in a single transaction.

function managePositionBatch(Instruction[] calldata mgmtInstructions, Instruction[] calldata acctInstructions)
        external
        returns (uint256[] memory values, int256[] memory changes);

Parameters

NameTypeDescription
mgmtInstructionsInstruction[]The array of management instructions.
acctInstructionsInstruction[]The array of accounting instructions.

Returns

NameTypeDescription
valuesuint256[]The new position values.
changesint256[]The changes in the position values.

manageFlashLoan

Manages flash loan funds.

function manageFlashLoan(Instruction calldata instruction, address token, uint256 amount) external;

Parameters

NameTypeDescription
instructionInstructionThe flash loan management instruction.
tokenaddressThe loan token.
amountuint256The loan amount.

harvest

Harvests one or multiple positions.

function harvest(Instruction calldata instruction, ISwapModule.SwapOrder[] calldata swapOrders) external;

Parameters

NameTypeDescription
instructionInstructionThe harvest instruction.
swapOrdersISwapModule.SwapOrder[]The array of swap orders to be executed after the harvest.

swap

Performs a swap via the swap module.

function swap(ISwapModule.SwapOrder calldata order) external;

Parameters

NameTypeDescription
orderISwapModule.SwapOrderThe swap order parameters.

transferToHubMachine

Initiates a token transfer to the hub machine.

function transferToHubMachine(address token, uint256 amount, bytes calldata data) external;

Parameters

NameTypeDescription
tokenaddressThe address of the token to transfer.
amountuint256The amount of tokens to transfer.
databytesABI-encoded parameters required for bridge-related transfers. Ignored when called from a hub caliber.

notifyIncomingTransfer

Instructs the Caliber to pull the specified token amount from the calling hub machine endpoint.

function notifyIncomingTransfer(address token, uint256 amount) external;

Parameters

NameTypeDescription
tokenaddressThe address of the token being transferred.
amountuint256The amount of tokens being transferred.

setPositionStaleThreshold

Sets the position accounting staleness threshold.

function setPositionStaleThreshold(uint256 newPositionStaleThreshold) external;

Parameters

NameTypeDescription
newPositionStaleThresholduint256The new threshold in seconds.

setTimelockDuration

Sets the duration of the allowedInstrRoot update timelock.

function setTimelockDuration(uint256 newTimelockDuration) external;

Parameters

NameTypeDescription
newTimelockDurationuint256The new duration in seconds.

scheduleAllowedInstrRootUpdate

Schedules an update of the root of the Merkle tree containing allowed instructions.

The update will take effect after the timelock duration stored in the contract at the time of the call.

function scheduleAllowedInstrRootUpdate(bytes32 newAllowedInstrRoot) external;

Parameters

NameTypeDescription
newAllowedInstrRootbytes32The new Merkle root.

cancelAllowedInstrRootUpdate

Cancels a scheduled update of the root of the Merkle tree containing allowed instructions.

Reverts if no pending update exists or if the timelock has expired.

function cancelAllowedInstrRootUpdate() external;

setMaxPositionIncreaseLossBps

Sets the max allowed value loss for position increases.

function setMaxPositionIncreaseLossBps(uint256 newMaxPositionIncreaseLossBps) external;

Parameters

NameTypeDescription
newMaxPositionIncreaseLossBpsuint256The new max value loss in basis points.

setMaxPositionDecreaseLossBps

Sets the max allowed value loss for position decreases.

function setMaxPositionDecreaseLossBps(uint256 newMaxPositionDecreaseLossBps) external;

Parameters

NameTypeDescription
newMaxPositionDecreaseLossBpsuint256The new max value loss in basis points.

setMaxSwapLossBps

Sets the max allowed value loss for base token swaps.

function setMaxSwapLossBps(uint256 newMaxSwapLossBps) external;

Parameters

NameTypeDescription
newMaxSwapLossBpsuint256The new max value loss in basis points.

setCooldownDuration

Sets the duration of the cooldown period for swaps and position management.

function setCooldownDuration(uint256 newCooldownDuration) external;

Parameters

NameTypeDescription
newCooldownDurationuint256The new duration in seconds.

addInstrRootGuardian

Adds a new guardian for the Merkle tree containing allowed instructions.

function addInstrRootGuardian(address newGuardian) external;

Parameters

NameTypeDescription
newGuardianaddressThe address of the new guardian.

removeInstrRootGuardian

Removes a guardian for the Merkle tree containing allowed instructions.

function removeInstrRootGuardian(address guardian) external;

Parameters

NameTypeDescription
guardianaddressThe address of the guardian to remove.

Events

AllowedInstrRootSet

event AllowedInstrRootSet(bytes32 indexed newAllowedInstrRoot);

Parameters

NameTypeDescription
newAllowedInstrRootbytes32

BaseTokenAdded

event BaseTokenAdded(address indexed token);

Parameters

NameTypeDescription
tokenaddress

BaseTokenRemoved

event BaseTokenRemoved(address indexed token);

Parameters

NameTypeDescription
tokenaddress

CooldownDurationChanged

event CooldownDurationChanged(uint256 indexed oldDuration, uint256 indexed newDuration);

Parameters

NameTypeDescription
oldDurationuint256
newDurationuint256

IncomingTransfer

event IncomingTransfer(address indexed token, uint256 amount);

Parameters

NameTypeDescription
tokenaddress
amountuint256

InstrRootGuardianAdded

event InstrRootGuardianAdded(address indexed newGuardian);

Parameters

NameTypeDescription
newGuardianaddress

InstrRootGuardianRemoved

event InstrRootGuardianRemoved(address indexed guardian);

Parameters

NameTypeDescription
guardianaddress

MaxPositionDecreaseLossBpsChanged

event MaxPositionDecreaseLossBpsChanged(
        uint256 indexed oldMaxPositionDecreaseLossBps, uint256 indexed newMaxPositionDecreaseLossBps
    );

Parameters

NameTypeDescription
oldMaxPositionDecreaseLossBpsuint256
newMaxPositionDecreaseLossBpsuint256

MaxPositionIncreaseLossBpsChanged

event MaxPositionIncreaseLossBpsChanged(
        uint256 indexed oldMaxPositionIncreaseLossBps, uint256 indexed newMaxPositionIncreaseLossBps
    );

Parameters

NameTypeDescription
oldMaxPositionIncreaseLossBpsuint256
newMaxPositionIncreaseLossBpsuint256

MaxSwapLossBpsChanged

event MaxSwapLossBpsChanged(uint256 indexed oldMaxSwapLossBps, uint256 indexed newMaxSwapLossBps);

Parameters

NameTypeDescription
oldMaxSwapLossBpsuint256
newMaxSwapLossBpsuint256

NewAllowedInstrRootCancelled

event NewAllowedInstrRootCancelled(bytes32 indexed cancelledMerkleRoot);

Parameters

NameTypeDescription
cancelledMerkleRootbytes32

NewAllowedInstrRootScheduled

event NewAllowedInstrRootScheduled(bytes32 indexed newMerkleRoot, uint256 indexed effectiveTime);

Parameters

NameTypeDescription
newMerkleRootbytes32
effectiveTimeuint256

PositionClosed

event PositionClosed(uint256 indexed id);

Parameters

NameTypeDescription
iduint256

PositionCreated

event PositionCreated(uint256 indexed id, uint256 value);

Parameters

NameTypeDescription
iduint256
valueuint256

PositionUpdated

event PositionUpdated(uint256 indexed id, uint256 value);

Parameters

NameTypeDescription
iduint256
valueuint256

PositionStaleThresholdChanged

event PositionStaleThresholdChanged(uint256 indexed oldThreshold, uint256 indexed newThreshold);

Parameters

NameTypeDescription
oldThresholduint256
newThresholduint256

TimelockDurationChanged

event TimelockDurationChanged(uint256 indexed oldDuration, uint256 indexed newDuration);

Parameters

NameTypeDescription
oldDurationuint256
newDurationuint256

TransferToHubMachine

event TransferToHubMachine(address indexed token, uint256 amount);

Parameters

NameTypeDescription
tokenaddress
amountuint256

Structs

CaliberInitParams

Initialization parameters.

struct CaliberInitParams {
        uint256 initialPositionStaleThreshold;
        bytes32 initialAllowedInstrRoot;
        uint256 initialTimelockDuration;
        uint256 initialMaxPositionIncreaseLossBps;
        uint256 initialMaxPositionDecreaseLossBps;
        uint256 initialMaxSwapLossBps;
        uint256 initialCooldownDuration;
        address[] initialBaseTokens;
    }

Properties

NameTypeDescription
initialPositionStaleThresholduint256The position accounting staleness threshold in seconds.
initialAllowedInstrRootbytes32The root of the Merkle tree containing allowed instructions.
initialTimelockDurationuint256The duration of the allowedInstrRoot update timelock.
initialMaxPositionIncreaseLossBpsuint256The max allowed value loss (in basis points) for position increases.
initialMaxPositionDecreaseLossBpsuint256The max allowed value loss (in basis points) for position decreases.
initialMaxSwapLossBpsuint256The max allowed value loss (in basis points) for base token swaps.
initialCooldownDurationuint256The duration of the cooldown period for swaps and position management.
initialBaseTokensaddress[]The array of initial base tokens.

Instruction

Instruction parameters.

struct Instruction {
        uint256 positionId;
        bool isDebt;
        uint256 groupId;
        InstructionType instructionType;
        address[] affectedTokens;
        address[] positionTokens;
        bytes32[] commands;
        bytes[] state;
        uint128 stateBitmap;
        bytes32[] merkleProof;
    }

Properties

NameTypeDescription
positionIduint256The ID of the involved position.
isDebtboolWhether the position is a debt.
groupIduint256The ID of the position accounting group.
Set to 0 if the instruction is not of type ACCOUNTING, or if the involved position is ungrouped.
instructionTypeInstructionTypeThe type of the instruction.
affectedTokensaddress[]The array of affected tokens.
positionTokensaddress[]The array of position tokens.
commandsbytes32[]The array of commands.
statebytes[]The array of state.
stateBitmapuint128The state bitmap.
merkleProofbytes32[]The array of Merkle proof elements.

Position

Position data.

struct Position {
        uint256 lastAccountingTime;
        uint256 value;
        bool isDebt;
    }

Properties

NameTypeDescription
lastAccountingTimeuint256The last block timestamp when the position was accounted for.
valueuint256The value of the position denominated in accounting token.
isDebtboolWhether the position is a debt.

Enums

InstructionType

enum InstructionType {
        MANAGEMENT,
        ACCOUNTING,
        HARVEST,
        FLASHLOAN_MANAGEMENT
    }

Variants

NameDescription
MANAGEMENT
ACCOUNTING
HARVEST
FLASHLOAN_MANAGEMENT