Skip to main content

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 endpoints.

weirollVm

Address of the Weiroll VM.

function weirollVm() external view returns (address);

hubMachineEndpoint

Address of the hub machine endpoint.

function hubMachineEndpoint() external view returns (address);

accountingToken

Address of the accounting token.

function accountingToken() external view returns (address);

positionStaleThreshold

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

function positionStaleThreshold() external view returns (uint256);

allowedInstrRoot

Root of the Merkle tree containing allowed instructions.

function allowedInstrRoot() external view returns (bytes32);

timelockDuration

Duration of the allowedInstrRoot update timelock.

function timelockDuration() external view returns (uint256);

pendingAllowedInstrRoot

Value of the pending allowedInstrRoot, if any.

function pendingAllowedInstrRoot() external view returns (bytes32);

pendingTimelockExpiry

Effective time of the last scheduled allowedInstrRoot update.

function pendingTimelockExpiry() external view returns (uint256);

maxPositionIncreaseLossBps

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

function maxPositionIncreaseLossBps() external view returns (uint256);

maxPositionDecreaseLossBps

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

function maxPositionDecreaseLossBps() external view returns (uint256);

maxSwapLossBps

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

function maxSwapLossBps() external view returns (uint256);

cooldownDuration

Duration of the cooldown period for swaps and position management.

function cooldownDuration() external view returns (uint256);

getPositionsLength

Length of the position IDs list.

function getPositionsLength() external view returns (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);

getPosition

Position ID => Position data

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

isBaseToken

Token => Registered as base token in this caliber

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

getBaseTokensLength

Length of the base tokens list.

function getBaseTokensLength() external view returns (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);

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

isAccountingFresh

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

function isAccountingFresh() external view returns (bool);

getDetailedAum

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

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).
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 Token Inflow - Whether the contract's base token balance increases during operation
  • Debt Position - Whether position represents protocol liability (true) vs asset (false)
  • Position Δ direction - Direction of position value change (increase/decrease) ┌───────────────────┬───────────────┬──────────────────────┬───────────────────────────┐ │ Base Token Inflow │ Debt Position │ Position Δ direction │ Action │ ├───────────────────┼───────────────┼──────────────────────┼───────────────────────────┤ │ No │ No │ Decrease │ Revert: Invalid direction │ │ No │ Yes │ Increase │ Revert: Invalid direction │ │ No │ No │ Increase │ Minimum Δ Check │ │ No │ Yes │ Decrease │ Minimum Δ Check │ │ Yes │ No │ Decrease │ Maximum Δ Check │ │ Yes │ Yes │ Increase │ Maximum Δ Check │ │ Yes │ No │ Increase │ No check (favorable move) │ │ Yes │ Yes │ Decrease │ 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 flashLoan funds.

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

Parameters

NameTypeDescription
instructionInstructionThe flashLoan 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 swapModule 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 newMerkleRoot) external;

Parameters

NameTypeDescription
newMerkleRootbytes32The 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

BaseTokenAdded

event BaseTokenAdded(address indexed token);

BaseTokenRemoved

event BaseTokenRemoved(address indexed token);

CooldownDurationChanged

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

IncomingTransfer

event IncomingTransfer(address indexed token, uint256 amount);

InstrRootGuardianAdded

event InstrRootGuardianAdded(address indexed newGuardian);

InstrRootGuardianRemoved

event InstrRootGuardianRemoved(address indexed guardian);

MaxPositionDecreaseLossBpsChanged

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

MaxPositionIncreaseLossBpsChanged

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

MaxSwapLossBpsChanged

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

NewAllowedInstrRootCancelled

event NewAllowedInstrRootCancelled(bytes32 indexed cancelledMerkleRoot);

NewAllowedInstrRootScheduled

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

PositionClosed

event PositionClosed(uint256 indexed id);

PositionCreated

event PositionCreated(uint256 indexed id, uint256 value);

PositionUpdated

event PositionUpdated(uint256 indexed id, uint256 value);

PositionStaleThresholdChanged

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

TimelockDurationChanged

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

TransferToHubMachine

event TransferToHubMachine(address indexed token, uint256 amount);

Structs

CaliberInitParams

Initialization parameters.

struct CaliberInitParams {
uint256 initialPositionStaleThreshold;
bytes32 initialAllowedInstrRoot;
uint256 initialTimelockDuration;
uint256 initialMaxPositionIncreaseLossBps;
uint256 initialMaxPositionDecreaseLossBps;
uint256 initialMaxSwapLossBps;
uint256 initialCooldownDuration;
}

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 point) for position increases.
initialMaxPositionDecreaseLossBpsuint256The max allowed value loss (in basis point) for position decreases.
initialMaxSwapLossBpsuint256The max allowed value loss (in basis point) for base token swaps.
initialCooldownDurationuint256The duration of the cooldown period for swaps and position management.

Instruction

Instruction parameters.

struct Instruction {
uint256 positionId;
bool isDebt;
uint256 groupId;
InstructionType instructionType;
address[] affectedTokens;
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.
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 expressed in accounting token.
isDebtboolWhether the position is a debt.

Enums

InstructionType

enum InstructionType {
MANAGEMENT,
ACCOUNTING,
HARVEST,
FLASHLOAN_MANAGEMENT
}