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.

FieldTypeDescription
idUIDThe escrow ID used in the link
balanceBalance<T>What the recipient gets
senderaddressThe only address that can refund
ephemeral_pubkeyvector<u8>The link’s Ed25519 public key, 32 bytes
expires_at_msu64The last moment a claim is accepted
water_donationBalance<T>The roundup, or zero
theme_idu8The 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#

IDName
0Yeti Glacial
1Coffee Chill
2Birthday Pop
3Clean 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.

escrow.move
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,
)
ParameterTypeDescription
coinCoin<T>The payment and the roundup together
ephem_pubkeyvector<u8>Must be 32 bytes
duration_msu64More than 0, up to 365 days. The app uses 14 days.
water_cutu64Taken from coin for the treasury. Must be less than its value.
theme_idu8See Theme IDs
clock&ClockThe 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.

escrow.move
public fun claim_escrow<T>(
    escrow: PaymentEscrow<T>,
    signature: vector<u8>,
    recipient: address,
    clock: &Clock,
    ctx: &mut TxContext,
)
ParameterTypeDescription
escrowPaymentEscrow<T>The shared escrow, by value
signaturevector<u8>64-byte Ed25519 signature of the claim message
recipientaddressReceives the payment
clock&ClockThe 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.

escrow.move
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:

Claim message
bytes  0–31   escrow ID
bytes 32–63   recipient address

claimMessage in the client library builds the same bytes.

Events#

EventFields
EscrowCreatedescrow_id, sender, amount, water_donation, theme_id
EscrowClaimedescrow_id, recipient, amount, water_donation
EscrowReclaimedescrow_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#

CodeNameCause
0EInvalidSignatureThe signature doesn’t match the escrow and recipient
1EEscrowExpiredThe claim came after the escrow expired
3EUnauthorizedSomeone other than the sender tried to refund
4EInsufficientBalanceThe coin isn’t worth more than the roundup
5EInvalidPublicKeyThe public key isn’t 32 bytes
6EInvalidDurationThe duration is zero or more than 365 days

Code 2 is not used.

Constants#

NameValue
ED25519_PUBLIC_KEY_LENGTH32
MAX_DURATION_MS31,536,000,000 (365 days)
CLEAN_WATER_TREASURYShown on Clean water roundup