Skip to content

Latest commit

 

History

History
169 lines (133 loc) · 7.04 KB

File metadata and controls

169 lines (133 loc) · 7.04 KB

Contract reference

Every public function across the three contracts, with parameters, return types, authorization, and error codes. All values here are read from the deployed source, not from the specification.

Deployed addresses (testnet)

Contract ID
registry CB7K56KG3KHC43FROV534M55FMVGBW24NUFQSXSRMH7OS54242GFYMGN
rent_vault CACRDSINFHJFMH4ADZO3PA376VZQW7PXPWCZAFIFFEB5X4ZJLFJZMUTF
long_escrow (example) CASBZNG6KRKZYRQ22TVOGEYSRDIV7QSCJDFIMSII5LA7XXKIUXOX6NZ6

Testnet resets periodically. Verify these on a block explorer before relying on them; if they no longer resolve, the contracts need redeploying.


registry

A permissionless directory mapping a contract address to its maintenance manifest. No administrator, no upgrade authority, no pause.

register

register(contract: Address, keys_xdr: Vec<Bytes>, threshold: u32, extend_to: u32)
  -> Result<(), RegistryError>

Publishes a manifest for contract. Authorization: contract.require_auth() — only the contract itself can register its own address, because a contract address has no private key and authorization can only come from inside the contract's own code. Errors: AlreadyRegistered, EmptyManifest, InvalidParams.

update

update(contract: Address, keys_xdr: Vec<Bytes>, threshold: u32, extend_to: u32)
  -> Result<(), RegistryError>

Replaces an existing manifest. Authorization: contract.require_auth(). Errors: NotRegistered, EmptyManifest, InvalidParams.

deregister

deregister(contract: Address) -> Result<(), RegistryError>

Removes a manifest. Authorization: contract.require_auth(). Errors: NotRegistered.

get

get(contract: Address) -> Option<RegistryEntry>

Returns the manifest for a contract, or nothing if it is not registered. Read-only, no authorization.

count

count() -> u32

Returns the number of registered contracts. Read-only.

page

page(start: u32, limit: u32) -> Result<Vec<RegistryEntry>, RegistryError>

Returns a window of registered entries for discovery. Read-only. limit is capped at 50. Errors: LimitTooLarge.

extend_all, lk_state

The registry adopts the maintainable standard and maintains its own state. See the maintainable interface below. Its own terms: threshold 100,000, extend-to 500,000, instance storage only.

RegistryError

Code Name Meaning
101 AlreadyRegistered register called for an address that already has an entry
102 NotRegistered update or deregister called for an address with no entry
103 EmptyManifest A manifest with no keys was supplied
104 InvalidParams threshold was not below extend_to
105 LimitTooLarge page called with a limit above 50

rent_vault

Lets a protocol pre-fund maintenance and pay whoever performs it.

initialize

initialize(token: Address) -> Result<(), VaultError>

Sets the tip asset for the whole contract, once. No authorization — it is first-caller-wins, guarded only by AlreadyInitialized. On a fresh deployment anyone can call it, so the deployment must initialize the vault in the same session, before anyone else can. Errors: AlreadyInitialized.

open

open(target: Address, owner: Address, tip: i128, interval: u32)
  -> Result<(), VaultError>

Creates a vault pointing at target, owned by owner. Authorization: owner.require_auth(). Errors: NotInitialized, VaultExists, InvalidTerms.

fund

fund(target: Address, from: Address, amount: i128) -> Result<(), VaultError>

Adds balance to a vault. Authorization: from.require_auth() — anyone may fund a vault they do not own. Errors: VaultMissing, InvalidAmount.

withdraw

withdraw(target: Address, to: Address, amount: i128) -> Result<(), VaultError>

Removes balance. Authorization: owner.require_auth(), read from vault storage rather than passed in — so the check comes after the vault loads. Errors: VaultMissing, InvalidAmount, InsufficientBalance.

set_terms

set_terms(target: Address, tip: i128, interval: u32) -> Result<(), VaultError>

Changes tip and interval. Authorization: owner.require_auth(), read from storage. Errors: VaultMissing, InvalidTerms.

claim

claim(target: Address, keeper: Address) -> Result<i128, VaultError>

Pays the tip to a keeper that maintained the target. Authorization: keeper.require_auth(). Verifies, by reading the target's lk_state: maintenance occurred since the last claim, the claimant is the recorded keeper, and the interval has elapsed. Errors: VaultMissing, NotTheKeeper, NoMaintenance, TooSoon, InsufficientBalance.

get_vault

get_vault(target: Address) -> Option<VaultState>

Returns a vault's current state. Read-only.

VaultError

Code Name Meaning
201 AlreadyInitialized initialize called after the token was already set
202 NotInitialized An operation needs the tip token, but initialize has not run
203 VaultExists open called for a target that already has a vault
204 VaultMissing The referenced vault does not exist
205 InvalidTerms tip <= 0 or interval == 0
206 InvalidAmount A funding or withdrawal amount was not positive
207 InsufficientBalance Balance below the requested or required amount
208 NotTheKeeper The claimant is not the address recorded as last keeper
209 NoMaintenance No maintenance since the last claim
210 TooSoon The interval since the last claim has not elapsed

maintainable interface

Adopted by a contract through the impl_maintainable! macro. It generates the maintenance function and exposes the state accessor. See Adopting the standard for how to apply it.

extend_all

extend_all(keeper: Address) -> u32

Extends the contract's instance storage and each declared persistent key, then records the maintenance. Authorization: keeper.require_auth() — the first statement in the generated function. Extension is conditional: a key already above its threshold is not touched. Returns the ledger sequence at which maintenance ran — not a count of keys extended. A key count is computed internally but is used only in the emitted event.

lk_state

lk_state() -> Result<MaintenanceState, MaintainableError>

Returns the maintenance record: { last_maintained: u32, last_keeper: Address }. Read-only. Errors: NotMaintained if read before any maintenance has run.

Cross-contract client

For calling a maintainable contract from another contract (as the vault does):

#[contractclient(name = "MaintainableClient")]
pub trait Maintainable {
    fn extend_all(env: Env, keeper: Address) -> u32;
    fn lk_state(env: Env) -> MaintenanceState;
}

MaintainableError

Code Name Meaning
301 ExtendTooLarge The macro's extend_to is above the network maximum TTL
302 NotMaintained lk_state read before any maintenance run recorded state