Skip to content

[Smart Contract] Implement Soroban Escrow Contract #583

@mftee

Description

@mftee

Description:
Create the on-chain payment escrow contract. When a shipment is funded, tokens are locked in the contract. They are released to the carrier on confirmed delivery, or refunded to the shipper on cancellation. Uses the SEP-41 token interface (token::Client) for actual token transfers.

Create:

  • contracts/escrow/Cargo.toml
  • contracts/escrow/src/lib.rs

Acceptance Criteria:

  • EscrowError: AlreadyFunded, NotFunded, Unauthorized, NotInitialized, InvalidState, AlreadyDisputed
  • EscrowStatus: Unfunded, Funded, Released, Refunded, Disputed
  • EscrowRecord struct: shipment_id: u64, shipper: Address, carrier: Option<Address>, token: Address, amount: i128, status: EscrowStatus
  • DataKey: Escrow(u64), Admin
  • initialize(env, admin)
  • fund_escrow(env, shipment_id, shipper, carrier, token, amount)shipper.require_auth(), calls token::Client.transfer_from(contract, shipper, contract, amount) (requires prior approve), stores record
  • release_payment(env, shipment_id, caller) — only admin or shipper; status must be Funded; calls token::Client.transfer(contract, carrier, amount); sets status Released
  • refund_payment(env, shipment_id, caller) — only admin; status must be Funded; refunds to shipper; sets status Refunded
  • raise_dispute(env, shipment_id, caller) — shipper or carrier, from Funded only
  • resolve_dispute(env, shipment_id, admin, release: bool) — admin only from Disputed; releases or refunds
  • get_escrow(env, shipment_id)
  • TTL extended on all write operations
  • 8 unit tests including full happy path using StellarAssetClient for test token setup

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions