Skip to content

feat: add deposit_for() for third-party vault funding - #94

Open
Bigmehelen wants to merge 1 commit into
clevercon-protocol:mainfrom
Bigmehelen:Add-deposit-for-so-a-third-party-can-fund-another-user-vault
Open

feat: add deposit_for() for third-party vault funding#94
Bigmehelen wants to merge 1 commit into
clevercon-protocol:mainfrom
Bigmehelen:Add-deposit-for-so-a-third-party-can-fund-another-user-vault

Conversation

@Bigmehelen

@Bigmehelen Bigmehelen commented Jul 26, 2026

Copy link
Copy Markdown

closed #84

  • Add deposit_for() method to CleverVault contract (Soroban)
  • Add DepositForEvent for third-party deposit tracking
  • Add buildDepositForXdr to server-side vault client
  • Add POST /api/vault/deposit-for-xdr API endpoint
  • Add buildDepositForXdr to frontend vault client
  • Add 6 tests covering success, validation, multi-funder, and downstream use

Summary

What does this PR do, and why?

Related issue

Closes #

Changes

Testing

How did you verify this works? Include commands run and their output where
useful (e.g. cargo test, npm test, manual testnet transaction links).

Checklist

  • npm run lint passes
  • npm run typecheck passes
  • npm test passes
  • npm run format:check passes
  • If a contract changed: cargo fmt --check, cargo clippy, cargo test
    pass in contracts/<contract>
  • Docs updated if behavior, setup, or APIs changed
  • If a contract's public interface or storage layout changed, CONTRACT_VERSION was bumped in that contract

Summary by CodeRabbit

  • New Features
    • Added support for depositing funds into another user’s vault.
    • Added validation for supported assets and positive deposit amounts.
    • Added dashboard and backend support for creating unsigned deposit transactions.
    • Deposited funds can be withdrawn or used to create tasks by the recipient.
    • Multiple funders can contribute to the same recipient’s vault balance.

- Add deposit_for() method to CleverVault contract (Soroban)
- Add DepositForEvent for third-party deposit tracking
- Add buildDepositForXdr to server-side vault client
- Add POST /api/vault/deposit-for-xdr API endpoint
- Add buildDepositForXdr to frontend vault client
- Add 6 tests covering success, validation, multi-funder, and downstream use
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Third-party vault funding

Layer / File(s) Summary
Contract deposit_for flow
contracts/agent-vault/src/lib.rs, contracts/agent-vault/src/tests.rs
Adds deposit_for, DepositForEvent, beneficiary balance updates, validation, TTL refresh, token transfers, and coverage for success, failures, cumulative funding, withdrawal, and task creation.
Unsigned XDR orchestration
packages/orchestrator/src/agent-vault-client.ts, packages/orchestrator/src/server.ts
Builds unsigned deposit_for XDR and exposes a validated endpoint with inactive-contract and error responses.
Dashboard XDR client
packages/dashboard/src/lib/vault-client.ts
Adds a client helper for requesting deposit-for XDR from the orchestrator. שמ

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Funder
  participant Dashboard
  participant VaultAPI
  participant AgentVault
  Funder->>Dashboard: provide recipient and amount
  Dashboard->>VaultAPI: request deposit-for XDR
  VaultAPI->>AgentVault: build deposit_for transaction
  AgentVault-->>VaultAPI: unsigned XDR
  VaultAPI-->>Dashboard: return XDR
  Dashboard-->>Funder: provide transaction for signing
Loading

Possibly related PRs

Suggested reviewers: bosun-josh121, tijesunimi004, dopezapha

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding deposit_for for third-party vault funding.
Linked Issues check ✅ Passed [#84] deposit_for debits the funder, credits the beneficiary, handles new accounts, enforces guards, and adds tests plus client/API support.
Out of Scope Changes check ✅ Passed The client and API additions align with the requested deposit_for feature and do not appear unrelated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/orchestrator/src/agent-vault-client.ts`:
- Around line 173-183: Update buildDepositForXdr in
packages/orchestrator/src/agent-vault-client.ts (lines 173-183) to accept
assetAddress and encode it between recipientAddress and the i128 amount. In
packages/orchestrator/src/server.ts (lines 641-659), require asset_address and
pass it through to buildDepositForXdr. In
packages/dashboard/src/lib/vault-client.ts (lines 39-52), accept and include
asset_address in the request payload so the full deposit_for argument flow is
preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bf6a877d-3e38-4e64-b4df-529c3f1056d7

📥 Commits

Reviewing files that changed from the base of the PR and between e486283 and 5e89259.

📒 Files selected for processing (5)
  • contracts/agent-vault/src/lib.rs
  • contracts/agent-vault/src/tests.rs
  • packages/dashboard/src/lib/vault-client.ts
  • packages/orchestrator/src/agent-vault-client.ts
  • packages/orchestrator/src/server.ts

Comment on lines +173 to +183
export async function buildDepositForXdr(
funderAddress: string,
recipientAddress: string,
amountUsdc: number,
): Promise<string | null> {
if (!VAULT_ACTIVE) return null;
return buildUnsignedXdr(funderAddress, 'deposit_for', [
new Address(funderAddress).toScVal(),
new Address(recipientAddress).toScVal(),
nativeToScVal(usdcToStroops(amountUsdc), { type: 'i128' }),
]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Pass the required asset argument through the full flow.

deposit_for(from, user, asset, amount) requires four contract arguments, but this XDR encodes only from, user, and amount. The simulator will reject the call because the i128 amount occupies the required asset: Address position.

  • packages/orchestrator/src/agent-vault-client.ts#L173-L183: accept assetAddress and encode new Address(assetAddress).toScVal() before the i128 amount.
  • packages/orchestrator/src/server.ts#L641-L659: require asset_address and pass it to buildDepositForXdr.
  • packages/dashboard/src/lib/vault-client.ts#L39-L52: accept and send asset_address.
📍 Affects 3 files
  • packages/orchestrator/src/agent-vault-client.ts#L173-L183 (this comment)
  • packages/orchestrator/src/server.ts#L641-L659
  • packages/dashboard/src/lib/vault-client.ts#L39-L52
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/orchestrator/src/agent-vault-client.ts` around lines 173 - 183,
Update buildDepositForXdr in packages/orchestrator/src/agent-vault-client.ts
(lines 173-183) to accept assetAddress and encode it between recipientAddress
and the i128 amount. In packages/orchestrator/src/server.ts (lines 641-659),
require asset_address and pass it through to buildDepositForXdr. In
packages/dashboard/src/lib/vault-client.ts (lines 39-52), accept and include
asset_address in the request payload so the full deposit_for argument flow is
preserved.

@Bosun-Josh121

Bosun-Josh121 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

lgtm. Address the failing CI and coderabbit comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Add deposit_for() so a third party can fund another user's vault

2 participants