Quick Start

This section provides a quick start guide for common use cases, including checking allowances, setting up wallet clients, providing approvals, signing permits, and creating positions.

  1. Check Token Allowance

const tokenAllowance = await DZapDcaClient.getAllowance({
   account: /* Your account address */,
   chainId: 42161, // arbitrum
   fromToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC
});
  1. Set Up Wallet Client

Use walletClient as per the viem library's requirements.

import { createWalletClient, custom } from 'viem';
import { arbitrum } from 'viem/chains';

const client = createWalletClient({
   chain: arbitrum,
   transport: custom(window.ethereum),
});
  1. Provide Approval

const approvalResponse = await DZapDcaClient.approve({
   account: /* Your account address */,
   chainId: 42161,
   fromToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
   walletClient: client,
   amount: maxUint256, // Defaults to max amount
});
  1. Sign Permit

const permitDetails = await DZapDcaClient.sign({
   account,
   chainId: 42161,
   fromToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
   walletClient: client,
   amount: 3n * 1000000n, // noOfSwaps * amountInWeiPerSwap
});
  1. Create a Position

const positionData = {
   from: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC
   to: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", // Wrapped Ether
   swapInterval: 86400, // Daily
   amount: 1000000n, // 1 USD
   noOfSwaps: 3n,
   permit: permitDetails.permitData,
};

const txnResponse = await DZapDcaClient.createPosition({
   chainId: 42161,
   account: /* Your wallet address */,
   walletClient: client,
   positionData,
});

Last updated