Skip to content

[8] Add TTL extend_ttl() to liquidity-pool and vendor-registry contracts #8

Description

@EmeditWeb

Problem

Only creditline-contract consistently calls extend_ttl() after persistent storage writes. The liquidity-pool and vendor-registry contracts write to persistent storage but never extend TTL, meaning their data will expire and the contract will appear to "lose" deposits or registered vendors.

Context

Soroban persistent entries expire if not refreshed. A sponsor's pool balance disappearing because of TTL would be catastrophic — funds become unrecoverable. This is a latent bug that only surfaces after weeks of inactivity on testnet but would be irrecoverable on mainnet.

Before Starting

Read these context files first:

  • context/architecture-context.md
  • context/code-standards.md
  • context/progress-tracker.md
  • contracts/liquidity-pool-contract/src/lib.rs
  • contracts/vendor-registry-contract/src/lib.rs

What To Build

  1. Audit liquidity-pool: locate every env.storage().persistent().set(...). After each, call env.storage().persistent().extend_ttl(&key, MIN_TTL, MAX_TTL) where MIN_TTL = 100_000, MAX_TTL = 1_000_000 (define in constants.rs).
  2. Same for vendor-registry: every set(...) followed by extend_ttl().
  3. Centralize the constants in a shared contracts/common/src/ttl.rs if not yet present; otherwise define locally per contract.
  4. Add a storage::write_and_extend(env, key, value) helper to enforce the pattern at the source.
  5. Write a test per contract: deposit to pool, advance ledger by MIN_TTL - 1, read — assert value still present.
  6. Update code-standards.md to make the helper mandatory.

Files To Touch

  • contracts/liquidity-pool-contract/src/storage.rs
  • contracts/liquidity-pool-contract/src/lib.rs
  • contracts/vendor-registry-contract/src/storage.rs
  • contracts/vendor-registry-contract/src/lib.rs
  • contracts/liquidity-pool-contract/src/tests.rs
  • contracts/vendor-registry-contract/src/tests.rs
  • context/code-standards.md

Acceptance Criteria

  • Every persistent set() in both contracts is followed by extend_ttl()
  • TTL constants are named and centralized
  • 2 new tests prove data survives near-expiry
  • Helper function exists and is used by all writes
  • code-standards.md mandates the pattern

Mandatory Checks Before PR

  • cargo build passes with zero errors
  • cargo test — all 93 existing tests still pass
  • require_auth() is FIRST line of every mutating function
  • extend_ttl() called after EVERY persistent storage write
  • New unit tests written for every new function
  • context/progress-tracker.md updated

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