TrussDocs

Guides

Add a sub-account

How to add a tracked or attested sub-account to a live vault, from building it with an expansion kit to granting its roles and opening its limits.

A vault can take a new sub-account after launch, up to the most sub-accounts fixed at deployment. An expansion kit builds the new account, and the VaultAdmin then wires its roles and adds it at the CRITICAL tier. It takes no capital until its limits are raised.

Key points

  • Check there is room: the most sub-accounts a vault may hold is fixed at deployment.
  • An expansion kit creates and sets up the new contracts in one transaction, and holds no power afterwards.
  • Adding the account, its modules and its assets each wait the CRITICAL tier.
  • The account receives nothing until its cap and push limit are raised, which waits HIGH.

Steps

All steps after the first are the VaultAdmin's. With timelocks on, schedule them for the same moment, at least the CRITICAL tier away, and execute them as one batch in this order.

  1. Build the account with an expansion kit. Deploying the kit creates and initializes everything in its constructor, so no one can initialize a contract in between. The kit holds no role.
    • SubAccountExpansionKit builds a tracked account, with a swap module and its policy and a lend module, as wanted.
    • AttestedSubAccountExpansionKit builds an attested account, with its call verifier and a NAV provider under the vault's NavAdmin. The account starts at an accepted value of zero.
  2. Wire its roles on the AccessManager. Map the account's functions, and its new swap policy's, to the vault's existing roles. Then grant its own execute and return roles, from allSubAccountScoped(subAccount) on the roles table, to the VaultAdmin, each vault manager's multicall and any trader the account should have. Put both roles under the delegation admin, with the HIGH tier as the execute role's grant delay and none on the return role.
  3. Bind its allocation policy with setSubAccountAllocationPolicy and, on a tracked account, each module with addModule(module, policy) (both CRITICAL).
  4. Add it to the vault with addSubAccount(subAccount) (CRITICAL). The vault refuses an account that answers to another AccessManager or NAV oracle, or a tracked one with another price oracle or asset registry.
  5. Register each of a tracked account's assets with registerAsset (CRITICAL). See Onboard an asset.
  6. Open it by raising its cap with raiseSubAccountCap, then its push, swap and lend limits (HIGH).

An attested account's extra steps

  • Allow its calls. The VaultAdmin admits each permitted call with allowCallShape on the account's verifier (CRITICAL). Without one, the account can make no call.
  • Set up its attesters. The NavAdmin appoints and removes the provider's NavManagers, the keys that post its value, with setNavManager.
  • For a permissioned token, have the issuer allow the account's address before its first call. The address is known once the kit is deployed.

Traders added later

A trader granted an execute role after launch waits the HIGH grant delay before it can trade, as RoleGranted shows. Its return role acts at once. The VaultAdmin or a vault manager grants both.

Events

SubAccountAdded, ModuleAdded, SubAccountAllocationPolicySet, AssetRegistered, CallShapeSet and the policy raises, with the AccessManager's TargetFunctionRoleUpdated and RoleGranted.

Where to read more

PageWhat it covers
Extending a vaultWhat can be added to a live vault
Tracked sub-accountsHow a tracked account works
Attested sub-accountsHow an attested account works
Rate limitsCaps and push limits