Skip to content

⏳ Implement Time-Based Expiration and Auto-Refund Mechanism #35

@Cedarich

Description

@Cedarich

Description
Protect buyers from unresponsive sellers by implementing a time-lock mechanism. If the deadline passes without confirmation or dispute, the buyer can reclaim their funds.

Requirements and Context

  • Background: If a seller vanishes, the buyer's funds shouldn't be locked forever.
  • Problem: Currently, funds rely on manual action. We need a fail-safe based on the ledger timestamp.
  • Success Criteria:
    • Use env.ledger().timestamp() to compare against escrow.deadline.
    • Implement refund_expired(env, escrow_id).
    • Ensure logic handles "Disputed" state (disputes should pause expiration).
  • Impact: Automates trustlessness; the contract enforces time limits without human intervention.

Suggested Execution

  1. Ensure Escrow struct has a deadline: u64 field.
  2. Implement refund_expired:
    • Retrieve escrow.
    • Check current_timestamp > escrow.deadline.
    • Check status is Funded (not Disputed/Completed).
    • Transfer funds back to Buyer.
    • Update status to Refunded.

Test and Commit

  • Testing: Mock the ledger timestamp in tests to fast-forward time. Verify refund works after deadline but fails before.
  • Commit Message: feat(contract): implement expiration and auto-refund logic

Guidelines

  • Handle time carefully (Stellar ledger timestamps are seconds since epoch).
  • PR Requirement: Closes #issue

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions