post https://sandbox.kyan.sh/deposit
Deposit USDC funds into a specific margin account to use as collateral for trading. Each trading pair has its own isolated margin account, so you must specify which pair's account to fund.
Prerequisites
Before depositing, ensure:
- USDC Balance: Your wallet has sufficient USDC tokens
- Token Approval: You've approved the ClearingHouse contract to spend your USDC
- Smart Account: Your smart account is deployed (happens automatically on first deposit)
How Deposits Work
- You sign an EIP-712 message authorizing the deposit
- System validates your signature and checks your USDC balance
- Protocol executes the on-chain transfer from your wallet
- Funds appear in your margin account, ready for trading
Security Features
- Signature Required: Only you can authorize deposits from your wallet
- Deadline Protection: Signatures expire after the specified deadline
- Amount Validation: System verifies you have sufficient USDC balance
- Atomic Execution: Deposits either complete fully or fail entirely
Common Issues and Solutions
- "Insufficient allowance": Approve the ClearingHouse contract for USDC spending
- "Signature expired": Ensure deadline is at least 30 seconds in the future
- "Pair not found": Check that you're using valid base/quote token addresses
- "Invalid signature": Verify you're signing with the correct wallet and chain ID
EIP-712 Signature Example (TypeScript)
import { parseUnits } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
// Domain parameters for EIP-712 signature
const EIP712Domain = {
chainId: 421614, // Arbitrum Sepolia (use 42161 for Arbitrum One mainnet)
name: 'Premia',
verifyingContract: '0x...' // ClearingHouseProxy address from deployment
version: '1'
};
// Type definitions
const Pair = [
{ name: 'base', type: 'address' },
{ name: 'quote', type: 'address' }
];
const UserDeposit = [
{ name: 'deadline', type: 'uint256' },
{ name: 'to', type: 'address' },
{ name: 'from', type: 'address' },
{ name: 'amount', type: 'uint256' },
{ name: 'pair', type: 'Pair' }
];
// Example deposit data
const deposit = {
to: '0xYourSmartAccount', // Smart account address
from: '0xYourWalletAddress', // EOA wallet address
amount: 1000, // Amount to deposit
pair: {
base: '0xBaseTokenAddress', // e.g., WETH address
quote: '0xQuoteTokenAddress' // e.g., USDC address
}
};
// Calculate deadline (30 seconds from now)
const deadline = Math.floor(Date.now() / 1000) + 30;
// Setup wallet
const account = privateKeyToAccount('0xYourPrivateKey');
// Sign the typed data
const signature = await account.signTypedData({
domain: EIP712Domain,
types: {
UserDeposit,
Pair
},
primaryType: 'UserDeposit',
message: {
deadline,
to: deposit.to,
from: deposit.from,
amount: parseUnits(deposit.amount.toString(), 6),
pair: deposit.pair
}
});
// Final request payload
const requestPayload = {
...deposit,
signature,
signature_deadline: deadline
};