Skip to main content
Prepares transaction data for a deposit using an EIP-2612 permit signature. This enables single-transaction deposits without a separate approval step.
For most use cases, use the unified deposit workflow which handles authorization automatically.

Import

import { prepareDepositWithPermitTxData } from '@paxoslabs/amplify-sdk'

Usage

// First discover the vault
const [vault] = await getVaultsByConfig({
  yieldType: YieldType.CORE,
  chainId: 1,
  depositAssetAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})

const txData = await prepareDepositWithPermitTxData({
  vaultName: vault.name,
  depositAsset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
  depositAmount: '1000',
  to: '0x...',
  chainId: 1,
  signature: '0x...', // From wallet signing
  deadline: 1234567890n,
})

Parameters

ParameterTypeRequiredDescription
vaultNamestringYesVault name from AmplifyVault.name (e.g. from getVaultsByConfig())
depositAssetAddressYesToken contract address to deposit
depositAmountstringYesAmount to deposit as decimal string (e.g., "100.50")
toAddressYesRecipient address for vault shares
chainIdnumberYesBlockchain network ID
signatureHexYesPermit signature from wallet signing
deadlinebigintYesPermit deadline (must match signed deadline)
slippagenumberNoSlippage tolerance in basis points (default: 50)
distributorCodestringNoDistributor code for fee attribution
interface PrepareDepositWithPermitTxDataParams {
  /** Vault name (from AmplifyVault.name) */
  vaultName: string
  /** Token contract address to deposit */
  depositAsset: Address
  /** Amount to deposit as decimal string */
  depositAmount: string
  /** Recipient address for vault shares */
  to: Address
  /** Blockchain network ID */
  chainId: number
  /** Permit signature (hex string from wallet signing) */
  signature: Hex
  /** Permit deadline (must match signature deadline) */
  deadline: bigint
  /** Slippage in basis points (default: 50 = 0.5%) */
  slippage?: number
  /** Distributor code for fee attribution */
  distributorCode?: string
}

Return Type

Returns a discriminated union based on vault configuration, matching the same flat shape as prepareDepositTxData().
type DepositWithPermitData =
  | StandardDepositWithPermitData
  | KytDepositWithPermitData;

interface StandardDepositWithPermitData {
  depositType: "standard";
  abi: Abi;
  address: Address;
  functionName: "depositWithPermit";
  args: readonly [Address, bigint, bigint, Address, Hex, bigint, number, Hex, Hex];
  chainId: number;
}

interface KytDepositWithPermitData {
  depositType: "kyt";
  abi: Abi;
  address: Address;
  functionName: "depositWithPermit";
  args: readonly [Address, bigint, bigint, Address, Hex, Attestation, bigint, number, Hex, Hex];
  chainId: number;
}
As of v0.5.2, the return structure is flatabi, functionName, and args are top-level properties, matching prepareDepositTxData(). You can spread the result directly into writeContract.

Examples

import { encodeFunctionData } from "viem";
import { usePrivy, useWallets } from "@privy-io/react-auth";
import {
  getVaultsByConfig,
  prepareDepositAuthorization,
  prepareDepositWithPermitTxData,
  isPermitAuth,
  YieldType,
} from "@paxoslabs/amplify-sdk";

const { sendTransaction } = usePrivy();
const { wallets } = useWallets();
const wallet = wallets[0];
const owner = wallet.address as `0x${string}`;

const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" as const;

// Discover vault first
const [vault] = await getVaultsByConfig({
  yieldType: YieldType.CORE,
  chainId: 1,
  depositAssetAddress: USDC,
});

const params = {
  vaultName: vault.name,
  depositAsset: USDC,
  depositAmount: "1000",
  to: owner,
  chainId: 1,
};

// Step 1: Get permit data
const auth = await prepareDepositAuthorization(params);

if (isPermitAuth(auth)) {
  // Step 2: Sign the permit
  const provider = await wallet.getEthereumProvider();
  const signature = await provider.request({
    method: "eth_signTypedData_v4",
    params: [owner, JSON.stringify(auth.permitData)],
  }) as `0x${string}`;

  // Step 3: Execute deposit with permit
  const txData = await prepareDepositWithPermitTxData({
    ...params,
    signature,
    deadline: auth.permitData.message.deadline,
  });

  await sendTransaction({
    chainId: txData.chainId,
    to: txData.address,
    data: encodeFunctionData({
      abi: txData.abi,
      functionName: txData.functionName,
      args: txData.args,
    }),
  });
}

Permit Support

Not all tokens support EIP-2612 permits. Use prepareDepositAuthorization() to check:
TokenSupports Permit
USDCYes
USDGYes
pyUSDYes
USDTNo
Smart contract wallets (like Privy Smart Wallets or Safe) cannot sign permits. Use the approval flow with transaction batching instead.

Error Handling

Error Message PatternDescriptionResolution
"SDK not initialized"SDK not initializedCall initAmplifySDK() first
"Vault not found"No vault matches vaultNameVerify vault name via getVaultsByConfig()
"does not support EIP-2612 permit"Token lacks permit supportUse approval flow instead
"Invalid permit signature format"Signature parsing failedRe-sign with correct typed data
"Invalid slippage value"Slippage outside 0–10000 bpsProvide value between 0 and 10000