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#
| Field | What it is |
|---|---|
| funds | The coins. |
| limits | One entry per agent: spending limits and expiry. |
| mandates | One entry per lending agent: its lending rules. |
| borrow_mandates | One entry per borrowing agent: its borrow rules. |
| consents | Each sealed-room bid an agent agreed to, stored as a digest that hides the room and the rate. |
| offers | Principal 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.
| Action | Function |
|---|---|
| Issue an agent capability with limits | mint_cap |
| Change an agent's limits or expiry | set_limits |
| Set or replace an agent's lending mandate | set_mandate |
| Allow a collateral type and its loan-to-value ceiling | set_collateral |
| Set or replace a borrowing agent's borrow rules | set_borrow_mandate |
| Revoke an agent | revoke |
| Withdraw | withdraw |
| Take out an object sent to the treasury, such as a LenderClaim | receive |
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.