Skip to content

feat: SEP-41 allowance / approve / transfer_from flows #550

Description

@joelpeace48-cell

Background & current state

SEP-41 token mode (NEW-009) introduces transfers, but delegated spending (a dApp/operator spending a user's tokens with consent) needs allowances. This is distinct from claim-rights delegation (#323). Without approve/transfer_from, integrators can't build spend-on-behalf flows.

Goal

Implement SEP-41 allowance semantics — approve, allowance, transfer_from, burn_from — with ledger-based expiration.

Technical design

fn approve(env: Env, from: Address, spender: Address, amount: i128, expiration_ledger: u32);
fn allowance(env: Env, from: Address, spender: Address) -> i128;
fn transfer_from(env: Env, spender: Address, from: Address, to: Address, amount: i128);
fn burn_from(env: Env, spender: Address, from: Address, amount: i128);
  • Store (from, spender) -> (amount, expiration_ledger). transfer_from checks ledger ≤ expiration_ledger and decrements allowance.
  • Standard approve/transfer events.

Edge cases

  • Spend after expiration_ledger → revert.
  • Over-spend beyond allowance → revert.
  • Re-approve resets amount + expiration (per spec).
  • Allowance to self / zero amount handling.
  • Interaction with confidential mode (NEW-003) → document mutual exclusivity.

Task breakdown

  • Allowance storage + expiration.
  • transfer_from/burn_from with checks + events.
  • TS bindings + docs (docs/CONTRACTS_API.md).
  • Tests for expiry, over-spend, re-approve.

Acceptance criteria

  • A spender can move up to the approved amount before expiry; over-spend and post-expiry revert.
  • Events match the SEP-41 schema.

Testing & verification

  • Unit tests incl. expiry edge cases; conformance with SEP-41 allowance section.

Out of scope

Dependencies / related

  • Depends on NEW-009 (SEP-41 token mode).

References

  • SEP-41 allowance semantics.

Difficulty: medium · Effort: M

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions