TrussDocs

Integrating with a vault

Building multicall batches

How operator keys batch restricted calls through their OwnedMulticall, how the vault's own multicall differs, and worked batches for common operations.

Operator keys in a Truss vault do not hold roles themselves. Each key owns an OwnedMulticall, a small contract that holds the key's roles and can call several contracts in one transaction. The vault and each sub-account also have a multicall of their own, for one caller's calls to that contract. This page shows how to build both kinds of batch, how a delayed call goes through a multicall, and four batches for common operations. Operator multicalls explains why the setup is built this way.

Key points

  • An operator key calls multicall(targets, calls) on its own OwnedMulticall, which makes each inner call as itself.
  • The vault's multicall(bytes[]) keeps the original caller, so each inner call is checked against that caller.
  • Either kind is all or nothing: the first failing call reverts the whole batch.
  • Deliver claims in a later transaction than a settlement, so one failing claim cannot undo the settlement.

The two kinds of multicall

OwnedMulticall.multicall(targets, calls)multicall(calls) on the vault or a sub-account
Who may call itOnly its owner key, fixed for lifeAnyone
ReachesAny contracts, one target per callThat one contract
Caller each target seesThe multicall, which holds the rolesThe original caller
EventsOne Executed(target, data, result) per inner call, after the target's ownThe targets' own

A holder can use the vault's multicall to, say, claim and open a new request in one transaction. Restricted calls in it are still checked against the holder, so it grants nothing.

Encoding a batch

Encode each inner call with the target's ABI: abi.encodeCall(TrussVault.settleDeposit, (ids)) in Solidity, or encodeFunctionData in a client library. Put the target addresses and the calldata in two arrays of the same length, in the order the calls should run, and send multicall(targets, calls) from the owner key.

Delayed calls through a multicall

When a role has a delay, its holder schedules the exact call on the vault's AccessManager, waits, then executes it. The multicall holds the role, so the multicall must schedule and execute:

targets = [manager]
calls   = [ schedule(vault, raiseEntryFee(newBps), 0) ]        // 0: the earliest time allowed
// after the delay:
targets = [vault]
calls   = [ raiseEntryFee(newBps) ]                            // or manager.execute(vault, data)

OperationScheduled carries the full calldata, so anyone can see what is coming and when.

Example batches

Each batch is sent by the key that owns the multicall, which must hold every role the batch uses.

// 1. A settler settles, then delivers claims in a second transaction.
[vault]                     [ settleRedeem(ids, shares) ]
[vault, vault]              [ claimRedeemFor(c1), claimRedeemFor(c2) ]

// 2. A vault manager, or a trader that is also a settler, brings capital home and settles.
[subAccount, subAccount, vault]
                            [ executeModule(lendModule, intent, executionData, ""),   // withdraw USDC from a venue
                              returnAssetsToVault(ALL),                            // ALL = type(uint256).max
                              settleRedeem(ids, shares) ]

// 3. A vault manager sends capital out and puts it to work.
[vault, subAccount]         [ pushToSubAccount(subAccount, amount, ""),
                              executeModule(lendModule, intent, executionData, "") ]

// 4. A vault manager moves capital between sub-accounts: there is no direct transfer.
[subAccountA, vault]        [ returnAssetsToVault(amount), pushToSubAccount(subAccountB, amount, "") ]

ALL returns what is available once the earlier calls have run. An Allocator can push but not trade, and a Trader can trade and return only on the sub-accounts that name it, so batches 3 and 4 need a vault manager's key. Skip a claim that reverts, such as one for a controller a withdrawal policy refuses, rather than retrying the whole batch.

Where to read more

PageWhat it covers
Operator multicallsWhy operator keys act through a multicall, and how keys are rotated
ProfilesWhat each profile's multicall holds
WithdrawalsSettling redemptions and delivering claims