Skip to content

Add token approval / spending limits to wallet contract #99

@Miracle656

Description

@Miracle656

Background

Currently, any transaction signed by the passkey can move any token in any amount. Production DeFi usage requires granular spending controls — e.g., approve a DEX to spend up to 500 USDC without a new biometric prompt for each swap. This is the Soroban equivalent of ERC-20's approve/allowance pattern.

What to build

Add a spending-limits system to the wallet contract: a way to pre-approve a specific spender address for a specific token up to a maximum amount, with an optional expiry.

Key files

  • contracts/wallet/src/lib.rs — main wallet contract to extend
  • sdk/src/useInvisibleWallet.ts — expose approve() SDK method

Suggested execution

git checkout -b feat/contract-spending-limits
  1. Add a StorageKey::Allowance(spender, token) variant to the contract's key enum
  2. Implement approve(spender, token, amount, expiry) — requires passkey auth
  3. In __check_auth, check allowance before executing and deduct accordingly
  4. Add get_allowance(spender, token) view function
  5. Write Soroban tests: approve → spend within limit (pass), spend over limit (fail), expired (fail)
  6. Expose approve() and getAllowance() in the TypeScript SDK

Example commit message:
feat(contracts): add token approval and spending limits with passkey auth

Acceptance criteria

  • approve() requires passkey signature
  • Spending over the limit is rejected by the contract
  • Expired allowances are rejected
  • Soroban tests cover happy path + limit exceeded + expired
  • TypeScript SDK exposes approve() and getAllowance()

Drips Wave · Complexity: High · 200 points
Comment below to request assignment. PR must include Closes #[this issue].

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions