DZap Documentation
  • 🌐Overview
  • Features
    • Aggregation
      • Usecases
      • Fee Structure
      • Chains, Bridge and Liquidity
      • Different Transaction Status
      • Price Imapct Handling
      • Technical Details
    • DCA
      • Creating Positions
      • Additional Actions
      • Swap properties
      • Fees
      • Supported Tokens
    • Zapping (Coming soon)
      • Use Cases
      • Liquidity Migration
      • Supported Routes
  • Protocol
    • Contract address
    • Dzap Aggregation API
    • Uniswap Permit V2
    • Backend API
  • Terms & Security
    • Troubleshooting & Self Serve Guide
    • Terms
    • Audit Reports
    • Privacy
    • Security
  • Tutorial
    • Batch Swap via DEX Aggregator
    • Batch swap via Bridge Aggregator
    • Minting LST from Any Chain
  • Socials
    • 🌐Website
    • 🐦Twitter
    • 👾Discord
    • Ⓜ️Medium
  • DZap SDK
    • Dollar Cost Averaging (DCA)
      • Overview
      • Installation
      • Quick Start
      • Usage Guide
      • Methods
      • Data Types
Powered by GitBook
On this page
  1. DZap SDK
  2. Dollar Cost Averaging (DCA)

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,
});
PreviousInstallationNextUsage Guide

Last updated 6 months ago