Skip to main content

Depositing USDC

Add USDC to the 7N7D Trading Vault programmatically.

Coming Soon

The SDK is currently in development. This documentation describes the planned API.

Basic Deposit​

import { SevenNSevenD } from '@7n7d/sdk';

const client = new SevenNSevenD({
rpcUrl: process.env.RPC_URL,
privateKey: process.env.PRIVATE_KEY,
});

// Deposit 1000 USDC
const result = await client.vault.deposit('1000');

console.log(`Transaction hash: ${result.hash}`);
console.log(`Shares received: ${result.shares}`);
console.log(`Share price: ${result.sharePrice}`);

Deposit Workflow​

┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│ Check USDC │ ──► │ Approve │ ──► │ Deposit │
│ Balance │ │ (if needed) │ │ Execute │
└──────────────┘ └──────────────┘ └──────────────┘

Step-by-Step​

1. Check USDC Balance​

const balance = await client.getUSDCBalance();
console.log(`USDC Balance: ${balance}`);

if (parseFloat(balance) < 1000) {
throw new Error('Insufficient USDC balance');
}

2. Check Allowance​

const allowance = await client.vault.getAllowance();
console.log(`Current allowance: ${allowance}`);

// If allowance is insufficient, approve first
if (parseFloat(allowance) < 1000) {
const approvalTx = await client.vault.approve('1000');
await approvalTx.wait();
console.log('Approval confirmed');
}

3. Execute Deposit​

const depositTx = await client.vault.deposit('1000');
const receipt = await depositTx.wait();

console.log(`Deposit confirmed in block ${receipt.blockNumber}`);

Deposit Options​

Specify Amount​

// Deposit exact USDC amount
await client.vault.deposit('1000'); // 1000 USDC
await client.vault.deposit('1000.50'); // 1000.50 USDC
await client.vault.deposit('0.01'); // 0.01 USDC (minimum)

Deposit Maximum​

// Deposit entire USDC balance
const maxDeposit = await client.vault.depositMax();
console.log(`Deposited all USDC: ${maxDeposit.amount}`);

With Options​

const result = await client.vault.deposit('1000', {
// Gas settings
gasLimit: 300000, // Custom gas limit
maxFeePerGas: '0.1', // gwei
maxPriorityFeePerGas: '0.01',

// Slippage protection
minShares: '950', // Minimum shares to receive

// Deadline
deadline: Date.now() + 300000, // 5 minutes
});

Helper Functions​

Estimate Shares​

Before depositing, estimate how many shares you'll receive:

const estimate = await client.vault.estimateDeposit('1000');

console.log(`Depositing: ${estimate.usdcAmount} USDC`);
console.log(`Expected shares: ${estimate.shares}`);
console.log(`Current share price: ${estimate.sharePrice}`);
console.log(`Estimated gas: ${estimate.gasEstimate}`);

Approve with Infinite Allowance​

For frequent depositors:

// Approve unlimited USDC (use with caution)
await client.vault.approveMax();

Check Approval Status​

const needsApproval = await client.vault.needsApproval('1000');

if (needsApproval) {
await client.vault.approve('1000');
}

await client.vault.deposit('1000');

Convenience Method​

One function that handles approval if needed:

// Automatically approves if necessary, then deposits
const result = await client.vault.depositWithApproval('1000');

console.log(`Approval tx: ${result.approvalHash || 'Not needed'}`);
console.log(`Deposit tx: ${result.depositHash}`);
console.log(`Shares received: ${result.shares}`);

Transaction Results​

DepositResult Object​

interface DepositResult {
// Transaction info
hash: string; // Transaction hash
blockNumber: number; // Block number

// Deposit details
usdcAmount: string; // USDC deposited
shares: string; // Shares received
sharePrice: string; // Price per share

// Gas info
gasUsed: string; // Gas consumed
gasCost: string; // Cost in ETH
}

Access Results​

const result = await client.vault.deposit('1000');

// Transaction details
console.log(`TX: ${result.hash}`);
console.log(`Block: ${result.blockNumber}`);

// Deposit details
console.log(`Deposited: ${result.usdcAmount} USDC`);
console.log(`Received: ${result.shares} shares`);
console.log(`At price: $${result.sharePrice} per share`);

// Costs
console.log(`Gas used: ${result.gasUsed}`);
console.log(`Gas cost: ${result.gasCost} ETH`);

Error Handling​

import { SDKError } from '@7n7d/sdk';

try {
await client.vault.deposit('1000');
} catch (error) {
if (error instanceof SDKError) {
switch (error.code) {
case 'INSUFFICIENT_BALANCE':
console.log('Not enough USDC in wallet');
break;

case 'INSUFFICIENT_ALLOWANCE':
console.log('Need to approve USDC spending first');
// Auto-fix:
await client.vault.approve('1000');
await client.vault.deposit('1000');
break;

case 'MIN_SHARES_NOT_MET':
console.log('Share price changed, got fewer shares than expected');
break;

case 'DEADLINE_EXCEEDED':
console.log('Transaction took too long');
break;

case 'TRANSACTION_REVERTED':
console.log('Transaction failed:', error.reason);
break;

default:
console.log('Unknown error:', error.message);
}
}
}

Full Example​

Complete deposit workflow:

import { SevenNSevenD } from '@7n7d/sdk';

async function depositToVault(amount: string) {
const client = new SevenNSevenD({
rpcUrl: process.env.RPC_URL!,
privateKey: process.env.PRIVATE_KEY!,
});

// 1. Check balance
const balance = await client.getUSDCBalance();
console.log(`Current USDC balance: ${balance}`);

if (parseFloat(balance) < parseFloat(amount)) {
throw new Error(`Insufficient balance. Have ${balance}, need ${amount}`);
}

// 2. Estimate deposit
const estimate = await client.vault.estimateDeposit(amount);
console.log(`Will receive ~${estimate.shares} shares`);
console.log(`Estimated gas cost: ${estimate.gasEstimate} ETH`);

// 3. Deposit with auto-approval
console.log(`Depositing ${amount} USDC...`);
const result = await client.vault.depositWithApproval(amount);

console.log('Deposit successful!');
console.log(` TX Hash: ${result.depositHash}`);
console.log(` Shares: ${result.shares}`);
console.log(` Value: $${result.usdcAmount}`);

// 4. Verify new balance
const newBalance = await client.vault.getBalance();
console.log(`New vault balance: ${newBalance.shares} shares ($${newBalance.usdcValue})`);

return result;
}

// Execute
depositToVault('1000')
.then(result => console.log('Done!', result))
.catch(error => console.error('Failed:', error));

Cross-Chain Deposits​

Coming Soon

The SDK does not yet include cross-chain deposit methods. For depositing USDC from Ethereum or Base via Circle CCTP, interact with the DepositRouter contract directly. See the Cross-Chain Deposits guide for details.

Planned SDK method:

// Future API — not yet implemented
const result = await client.vault.crossChainDeposit('1000', {
sourceChain: 'base', // 'ethereum' | 'base'
});

Next: Learn how to Withdraw funds from the vault.