Docs/Core concepts

Treasury & OwnerCap

A Treasury is a shared object that holds one coin type and the rules for every agent allowed to use it. An OwnerCap is the key to it: whoever holds the OwnerCap controls the treasury.

What a treasury holds#

FieldWhat it is
fundsThe coins.
limitsOne entry per agent: spending limits and expiry.
mandatesOne entry per lending agent: its lending rules.
borrow_mandatesOne entry per borrowing agent: its borrow rules.
consentsEach sealed-room bid an agent agreed to, stored as a digest that hides the room and the rate.
offersPrincipal still out on each offer, kept here so a repayment lands even after the offer is cancelled.

The rules live in the treasury, not in the agent's capability, because the agent owns its capability and only a shared object can be changed by the owner.

What only the owner can do#

Every one of these takes the OwnerCap and checks it belongs to this treasury.

ActionFunction
Issue an agent capability with limitsmint_cap
Change an agent's limits or expiryset_limits
Set or replace an agent's lending mandateset_mandate
Allow a collateral type and its loan-to-value ceilingset_collateral
Set or replace a borrowing agent's borrow rulesset_borrow_mandate
Revoke an agentrevoke
Withdrawwithdraw
Take out an object sent to the treasury, such as a LenderClaimreceive

Anyone may deposit.

Creating one#

new_with_cap creates the treasury and issues the first agent capability, and returns the treasury unshared, its OwnerCap and the agent capability's ID. The same transaction then sets the rules and deposits into it, and share shares it. The treasury can be neither dropped nor transferred, so a transaction that does not share it fails. This is the one signature behind a hosted agent's setup. A plain create makes a shared treasury with no agent.

Lifecycle#

  • created — shared, with an OwnerCap in the creator's hands.
  • in use — agents act inside their limits and mandates.
  • agent revoked — the agent's limits, lend mandate and borrow rules are removed; every open offer of that agent fails at its next fill.
  • repaid after revoke — a repayment to a revoked agent's loan still lands.

Revoking an agent does not touch the funds. The OwnerCap can withdraw at any time.