Skip to content

Commit 4629f1f

Browse files
authored
feat: deposit to any address (#316)
feat: allowing deposits to secondary addresses
1 parent 101c457 commit 4629f1f

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

AGENTS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This document serves as context for LLM agent sessions working with the Synapse
1717
### Key Components
1818

1919
- `Synapse`: Main SDK entry; minimal interface with `payments` property and `storage` manager; strict network validation (mainnet/calibration).
20-
- `PaymentsService`: Payment operations - deposits, withdrawals, balances, service approvals.
20+
- `PaymentsService`: Payment operations - deposits, withdrawals, balances, service approvals. The `deposit()` method accepts an optional `DepositOptions` object with `to` property to deposit funds to a different address than the signer, plus callback functions for visibility.
2121
- `SPRegistryService`: Service provider registry - registration, updates, product management, provider discovery.
2222
- `WarmStorageService`: Storage coordination - costs, allowances, data sets. Factory method `WarmStorageService.create(provider, address)`. Source of all contract addresses via discovery.
2323
- `StorageManager/StorageContext`: Storage operations with auto-managed or explicit contexts.
@@ -208,6 +208,7 @@ WarmStorageService (storage coordination)
208208
- Manages payment rails between parties
209209
- Supports operator approvals for account management
210210
- Address discovered from WarmStorage
211+
- **Deposit Flexibility**: The `deposit(token, to, amount)` function allows depositing to any address, not just the signer. SDK's `PaymentsService.deposit()` exposes this via `DepositOptions` object with optional `to` property.
211212

212213
#### 5. Curio Storage Provider (Service Node)
213214

docs/src/content/docs/intro/components.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const depositTx = await paymentsService.deposit(amount) // amount in base units
2222
console.log(`Deposit transaction: ${depositTx.hash}`)
2323
await depositTx.wait() // Wait for confirmation
2424

25+
// Optional: Deposit to a different address
26+
const recipientAddress = '0x1234...'
27+
await paymentsService.deposit(amount, TOKENS.USDFC, { to: recipientAddress })
28+
2529
// Check account info
2630
const info = await paymentsService.accountInfo() // Uses USDFC by default
2731
console.log('Available funds:', info.availableFunds)

docs/src/content/docs/intro/getting-started.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ const depositTx = await synapse.payments.deposit(requiredAmount, TOKENS.USDFC, {
170170
console.log(`Deposit transaction: ${depositTx.hash}`)
171171
await depositTx.wait()
172172

173+
// Optional: Deposit to a different address (e.g., for a service or another user)
174+
const recipientAddress = '0x1234...'
175+
await synapse.payments.deposit(amount, TOKENS.USDFC, { to: recipientAddress })
176+
173177
// Service operator approvals (required before creating data sets)
174178
const warmStorageAddress = await synapse.getWarmStorageAddress()
175179

@@ -377,7 +381,7 @@ await synapse.storage.download(pieceCid, { context: storageContext })
377381

378382
**Token Operations:**
379383

380-
- `deposit(amount, token?, callbacks?)` - Deposit funds to payments contract (handles approval automatically), returns `TransactionResponse`
384+
- `deposit(amount, token?, options?)` - Deposit funds to payments contract (handles approval automatically). Options include `to` (recipient address), and callbacks for visibility. Returns `TransactionResponse`
381385
- `withdraw(amount, token?)` - Withdraw funds from payments contract, returns `TransactionResponse`
382386
- `approve(spender, amount, token?)` - Approve token spending (for manual control), returns `TransactionResponse`
383387
- `allowance(spender, token?)` - Check current token allowance
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Exports the PaymentsService and DepositCallbacks types
2+
* Exports the PaymentsService and DepositOptions types
33
*
44
* @module Payments
55
* @example
@@ -8,5 +8,5 @@
88
* ```
99
*/
1010

11-
export type { DepositCallbacks } from './service.ts'
11+
export type { DepositOptions } from './service.ts'
1212
export { PaymentsService } from './service.ts'

packages/synapse-sdk/src/payments/service.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import {
1919
} from '../utils/index.ts'
2020

2121
/**
22-
* Callbacks for deposit operation visibility
22+
* Options for deposit operation
2323
*/
24-
export interface DepositCallbacks {
24+
export interface DepositOptions {
25+
/** Optional recipient address (defaults to signer address if not provided) */
26+
to?: string
2527
/** Called when checking current allowance */
2628
onAllowanceCheck?: (current: bigint, required: bigint) => void
2729
/** Called when approval transaction is sent */
@@ -603,7 +605,7 @@ export class PaymentsService {
603605
async deposit(
604606
amount: TokenAmount,
605607
token: TokenIdentifier = TOKENS.USDFC,
606-
callbacks?: DepositCallbacks
608+
options?: DepositOptions
607609
): Promise<ethers.TransactionResponse> {
608610
// Only support USDFC for now
609611
if (token !== TOKENS.USDFC) {
@@ -616,6 +618,7 @@ export class PaymentsService {
616618
}
617619

618620
const signerAddress = await this._signer.getAddress()
621+
const depositTo = options?.to ?? signerAddress
619622
const usdfcContract = this._getUsdfcContract()
620623
const paymentsContract = this._getPaymentsContract()
621624

@@ -632,24 +635,24 @@ export class PaymentsService {
632635

633636
// Check and update allowance if needed
634637
const currentAllowance = await this.allowance(this._paymentsAddress, token)
635-
callbacks?.onAllowanceCheck?.(currentAllowance, depositAmountBigint)
638+
options?.onAllowanceCheck?.(currentAllowance, depositAmountBigint)
636639

637640
if (currentAllowance < depositAmountBigint) {
638641
// Golden path: automatically approve the exact amount needed
639642
const approveTx = await this.approve(this._paymentsAddress, depositAmountBigint, token)
640-
callbacks?.onApprovalTransaction?.(approveTx)
643+
options?.onApprovalTransaction?.(approveTx)
641644

642645
// Wait for approval to be mined before proceeding
643646
const approvalReceipt = await approveTx.wait(TIMING_CONSTANTS.TRANSACTION_CONFIRMATIONS)
644647
if (approvalReceipt != null) {
645-
callbacks?.onApprovalConfirmed?.(approvalReceipt)
648+
options?.onApprovalConfirmed?.(approvalReceipt)
646649
}
647650
}
648651

649652
// Check if account has sufficient available balance (no frozen account check needed for deposits)
650653

651654
// Notify that deposit is starting
652-
callbacks?.onDepositStarting?.()
655+
options?.onDepositStarting?.()
653656

654657
// Only set explicit nonce if NonceManager is disabled
655658
const txOptions: any = {}
@@ -658,7 +661,7 @@ export class PaymentsService {
658661
txOptions.nonce = currentNonce
659662
}
660663

661-
const depositTx = await paymentsContract.deposit(this._usdfcAddress, signerAddress, depositAmountBigint, txOptions)
664+
const depositTx = await paymentsContract.deposit(this._usdfcAddress, depositTo, depositAmountBigint, txOptions)
662665

663666
return depositTx
664667
}

0 commit comments

Comments
 (0)