Source document: ../LUMENBAZAAR_FULL_PROJECT_DOCUMENTATION.md
Repo role: Soroban contracts for capped metered x402 upto payment sessions, optional smart-wallet policy examples, test token utilities, generated bindings, deployment scripts, and contract security evidence.
Primary stack:
- Rust
- Soroban SDK
- Stellar CLI
- Cargo
Target layout:
contracts/
upto-session/
policy-wallet-example/
test-token/Implementation rules:
- Only put logic on-chain when the project needs on-chain enforcement.
- Keep exact x402 payments contract-free where Stellar/Soroban auth entries and Stellar Asset Contract support are sufficient.
- Build
upto-sessionnarrowly around capped metered settlement. - Testnet comes before mainnet.
- Generate ABI/spec files and TypeScript bindings when applicable.
- Clearly mark the policy wallet as an example, not a production wallet.
Parts:
- Scaffold the Rust workspace.
- Add Soroban SDK dependencies.
- Add
README.md,LICENSE,CONTRIBUTING.md,SECURITY.md, PR template, issue template, and CI. - Add rustfmt and clippy configuration.
Completion check:
- Fresh clone can run formatting, lint, and placeholder tests.
Parts:
- Add
contracts/upto-session. - Add
contracts/policy-wallet-example. - Add
contracts/test-token. - Add shared test helpers if needed.
Completion check:
- Each contract package builds independently.
Parts:
- Define public interface for
initialize. - Define public interface for
create_session. - Define public interface for
settle. - Define public interface for
cancel. - Define public interface for
get_session. - Define public interface for
extend_ttl.
Completion check:
- The intended ABI is visible before implementation complexity is added.
Parts:
- Define
Session. - Define
SessionStatus. - Define storage keys.
- Add storage layout versioning.
- Add typed wrappers for IDs and hashes where helpful.
Completion check:
- Session state can be serialized and retrieved in unit tests.
Parts:
- Add
AlreadyInitialized. - Add
Unauthorized. - Add
InvalidAmount. - Add
ExpiredSession. - Add
SessionNotFound. - Add
SessionAlreadySettled. - Add
SessionCancelled. - Add
AmountExceedsCap. - Add
InvalidAsset. - Add
InvalidSeller. - Add
TtlExtensionFailed.
Completion check:
- Every documented error code exists and is stable.
Parts:
- Implement
initialize(admin: Address). - Store admin once.
- Reject repeat initialization.
- Add initialization tests.
Completion check:
- Contract cannot be initialized twice.
Parts:
- Define deterministic session ID creation.
- Include buyer, seller, asset, max amount, expiry, resource hash, and nonce or equivalent uniqueness input.
- Prevent accidental collision.
- Document ID derivation.
Completion check:
- Tests prove two distinct sessions do not overwrite each other.
Parts:
- Validate buyer address.
- Validate seller address.
- Validate asset address.
- Reject zero or negative
max_amount. - Reject already-expired sessions.
- Require resource hash.
Completion check:
- Invalid inputs fail before storage writes.
Parts:
- Require buyer authorization.
- Bind session to fixed seller.
- Bind session to fixed asset.
- Bind session to fixed resource hash.
- Store unsettled session status.
Completion check:
- Unauthorized callers cannot create sessions on behalf of buyers.
Parts:
- Emit session-created event.
- Include session ID.
- Include buyer, seller, asset, cap, expiry, and resource hash.
- Keep event shape stable.
Completion check:
- Indexers can observe session creation from events.
Parts:
- Implement
get_session(session_id: BytesN<32>) -> Session. - Return full session state.
- Return
SessionNotFoundfor missing sessions.
Completion check:
- Backend bindings can retrieve session state by ID.
Parts:
- Implement
settle. - Require seller or authorized settlement actor according to final design.
- Reject wrong seller.
- Reject missing session.
- Reject cancelled or settled sessions.
Completion check:
- Only the intended recipient path can settle usage.
Parts:
- Reject zero or negative actual amount.
- Reject actual amount above cap.
- Reject settlement after expiry.
- Store actual settled amount.
Completion check:
- Over-cap and expired settlement attempts fail deterministically.
Parts:
- Integrate with Stellar Asset Contract transfer behavior.
- Transfer
actual_amountfrom buyer to seller. - Ensure the asset matches the session asset.
- Surface asset transfer failures.
Completion check:
- Valid settlement transfers the configured asset only.
Parts:
- Require
usage_hash. - Store usage hash on settlement.
- Document hash inputs expected from backend usage receipts.
Completion check:
- A settled session includes verifiable usage evidence hash.
Parts:
- Set session status to settled atomically.
- Reject repeat settlement.
- Add double-settlement tests.
Completion check:
- A session cannot be settled twice even with repeated calls.
Parts:
- Emit session-settled event.
- Include session ID.
- Include actual amount.
- Include usage hash.
- Include seller and asset.
Completion check:
- Backend can index settlement events for receipts.
Parts:
- Implement
cancel(session_id). - Allow buyer cancellation before settlement.
- Reject cancellation after settlement.
- Reject cancellation for missing sessions.
Completion check:
- Buyer can close unused authorization safely.
Parts:
- Emit session-cancelled event.
- Include session ID and buyer.
- Keep event schema stable.
Completion check:
- Backend and docs can track cancellation lifecycle.
Parts:
- Decide instance and persistent storage TTL rules.
- Implement safe TTL extension for active sessions.
- Reject extension for missing or finalized sessions where appropriate.
- Document resource usage implications.
Completion check:
- TTL behavior is tested and documented.
Parts:
- Reject settlement after
expires_at_ledger. - Define whether expired sessions can be cancelled or only observed.
- Add expiry tests.
Completion check:
- Expired sessions cannot move funds.
Parts:
- Add
test-tokencontract only if needed for local tests. - Keep it separate from production session logic.
- Add mint and transfer helpers for tests.
Completion check:
- Contract tests can run without depending on external token state.
Parts:
- Test valid session creation.
- Test unauthorized session creation.
- Test invalid cap rejection.
- Test valid settlement.
- Test wrong seller rejection.
Completion check:
- Core positive and negative paths pass in
cargo test.
Parts:
- Test over-cap rejection.
- Test double-settlement rejection.
- Test expired settlement rejection.
- Test cancellation before settlement.
- Test cancellation after settlement rejection.
Completion check:
- The documented contract guarantees have regression tests.
Parts:
- Test session persistence.
- Test storage layout version.
- Test TTL extension.
- Test emitted event payloads.
- Test
get_sessionresponses.
Completion check:
- Backend and indexer assumptions are stable.
Parts:
- Scaffold
policy-wallet-example. - Add clear documentation banner that it is not production wallet code.
- Implement minimal smart account example shape.
- Add tests that prove it is isolated from
upto-session.
Completion check:
- Example compiles and cannot be mistaken for required production infrastructure.
Parts:
- Add max amount per payment.
- Add max amount per day.
- Add allowed sellers.
- Add allowed assets.
- Add allowed resource hashes.
- Add expiration window checks.
Completion check:
- Agent spending policies are demonstrable in tests.
Parts:
- Add examples for allowed payment.
- Add examples for blocked payment.
- Add examples for expired policy.
- Add examples for wrong seller and wrong asset.
Completion check:
- Docs can reference working policy examples.
Parts:
- Generate contract ABI/spec files.
- Commit generated artifacts if that is the chosen repo policy.
- Add CI check to keep generated artifacts current.
Completion check:
- Backend can consume stable generated contract interfaces.
Parts:
- Generate TypeScript bindings for
upto-session. - Add package output or artifact folder.
- Add binding smoke test.
Completion check:
- Backend integration can call contract methods through generated bindings.
Parts:
- Add local network deployment script.
- Add test token deployment script if used.
- Add initialize script.
- Add sample create, settle, cancel, and inspect commands.
Completion check:
- A developer can deploy and exercise the contract locally.
Parts:
- Add testnet deploy script.
- Add environment example for testnet.
- Add contract ID recording process.
- Add deployment verification command.
Completion check:
- Testnet deployment is reproducible and documented.
Parts:
- Record resource usage for create session.
- Record resource usage for settle.
- Record resource usage for cancel.
- Record resource usage for TTL extension.
Completion check:
- Docs include realistic gas/resource expectations.
Parts:
- Publish contract IDs.
- Publish generated bindings.
- Publish function and error reference.
- Provide example usage hashes.
Completion check:
- Backend
uptoimplementation has everything needed to integrate safely.
Parts:
- Check authorization boundaries.
- Check cap enforcement.
- Check double-settlement prevention.
- Check expiry handling.
- Check asset and seller binding.
- Check event correctness.
Completion check:
- Audit readiness package can reference completed checklist items.
Parts:
- Freeze public interface for review.
- Document known limitations.
- Document threat model.
- Document test coverage.
- Document deployment procedure.
Completion check:
- External reviewers can inspect contract behavior without reverse-engineering intent.
Parts:
- Require completed tests.
- Require documented testnet deployment.
- Require reviewed generated bindings.
- Require operational sign-off.
- Require security review decision.
Completion check:
- Mainnet deployment has explicit gates and does not happen by accident.
Parts:
- Track Soroban SDK updates.
- Regenerate bindings after interface changes.
- Keep storage version notes current.
- Add regression tests for every discovered bug.
Completion check:
- Contract repo remains safe, reproducible, and aligned with backend and docs.