Reference
Move contract
Reference for floe::escrow: one object, three functions and three events.
On this page
Overview#
The module is in move/sources/escrow.move, written in Move 2024. Every function is generic over the coin type T. There is no admin capability, fee or registry.
PaymentEscrow#
A shared object that holds one payment. It has key only, so it can’t be wrapped or transferred.
| Field | Type | Description |
|---|---|---|
| id | UID | The escrow ID used in the link |
| balance | Balance<T> | What the recipient gets |
| sender | address | The only address that can refund |
| ephemeral_pubkey | vector<u8> | The link’s Ed25519 public key, 32 bytes |
| expires_at_ms | u64 | The last moment a claim is accepted |
| water_donation | Balance<T> | The roundup, or zero |
| theme_id | u8 | The envelope, for display only |
The app decodes this layout by field order. If you change it, update EscrowLayout in src/lib/chain/escrow.ts.
Theme IDs#
| ID | Name |
|---|---|
| 0 | Yeti Glacial |
| 1 | Coffee Chill |
| 2 | Birthday Pop |
| 3 | Clean Water Blue |
The contract accepts any value. The app shows unknown IDs as Yeti Glacial.
Functions#
All three are public and return nothing.
create_escrow#
Locks a coin and shares the escrow.
public fun create_escrow<T>(
mut coin: Coin<T>,
ephem_pubkey: vector<u8>,
duration_ms: u64,
water_cut: u64,
theme_id: u8,
clock: &Clock,
ctx: &mut TxContext,
)| Parameter | Type | Description |
|---|---|---|
| coin | Coin<T> | The payment and the roundup together |
| ephem_pubkey | vector<u8> | Must be 32 bytes |
| duration_ms | u64 | More than 0, up to 365 days. The app uses 14 days. |
| water_cut | u64 | Taken from coin for the treasury. Must be less than its value. |
| theme_id | u8 | See Theme IDs |
| clock | &Clock | The shared clock, 0x6 |
Aborts with EInsufficientBalance, EInvalidPublicKey or EInvalidDuration. Emits EscrowCreated.
claim_escrow#
Pays the recipient and the treasury, then deletes the escrow. Anyone may submit it, because the signature decides where the money goes.
public fun claim_escrow<T>(
escrow: PaymentEscrow<T>,
signature: vector<u8>,
recipient: address,
clock: &Clock,
ctx: &mut TxContext,
)| Parameter | Type | Description |
|---|---|---|
| escrow | PaymentEscrow<T> | The shared escrow, by value |
| signature | vector<u8> | 64-byte Ed25519 signature of the claim message |
| recipient | address | Receives the payment |
| clock | &Clock | The shared clock, 0x6 |
Aborts with EEscrowExpired after expires_at_ms, or EInvalidSignature. Emits EscrowClaimed.
reclaim_escrow#
Returns the payment and the roundup to the sender, and deletes the escrow. Works at any time while the escrow exists.
public fun reclaim_escrow<T>(escrow: PaymentEscrow<T>, ctx: &mut TxContext)Aborts with EUnauthorized unless the caller is the sender. Emits EscrowReclaimed.
The claim message#
The link’s key signs exactly 64 bytes, with no prefix or hash applied first:
bytes 0–31 escrow ID
bytes 32–63 recipient addressclaimMessage in the client library builds the same bytes.
Events#
| Event | Fields |
|---|---|
| EscrowCreated | escrow_id, sender, amount, water_donation, theme_id |
| EscrowClaimed | escrow_id, recipient, amount, water_donation |
| EscrowReclaimed | escrow_id, sender, amount |
Amounts are in base units. In EscrowCreated and EscrowClaimed the amount leaves out the roundup. In EscrowReclaimed it includes it.
Error codes#
| Code | Name | Cause |
|---|---|---|
| 0 | EInvalidSignature | The signature doesn’t match the escrow and recipient |
| 1 | EEscrowExpired | The claim came after the escrow expired |
| 3 | EUnauthorized | Someone other than the sender tried to refund |
| 4 | EInsufficientBalance | The coin isn’t worth more than the roundup |
| 5 | EInvalidPublicKey | The public key isn’t 32 bytes |
| 6 | EInvalidDuration | The duration is zero or more than 365 days |
Code 2 is not used.
Constants#
| Name | Value |
|---|---|
| ED25519_PUBLIC_KEY_LENGTH | 32 |
| MAX_DURATION_MS | 31,536,000,000 (365 days) |
| CLEAN_WATER_TREASURY | Shown on Clean water roundup |