Data Types

Common types used in the SDK include:

  • HexString: 0x${string}

  • SupportedChainIds: 137 | 42161 | 10 | 324 | 8453 | 40

  • PositionData, EditPositionData, PositionDetails

  • TxnResponse, SignatureResponse, PositionFrequency, PositionStatus

HexString

Represents a string starting with 0x, commonly used for hexadecimal addresses.

HexString = `0x${string}`;

SupportedChainIds

Enumeration of supported EVM chain IDs.

SupportedChainIds = 137 | 42161 | 10 | 324 | 8453 | 40;

SignatureResponse

The response from a permit signature request, containing optional error messages, a status code, and permit data.

SignatureResponse = {
  errorMsg?: string;
  code: number;
  status: string;
  permitData: HexString;
};
  • errorMsg: An optional field indicating any error that occurred during the permit signing.

  • code: Status code representing the result of the signing attempt.

  • status: A string describing the success or failure status of the operation.

  • permitData: The data from the signed permit, needed for DCA operations

TxnResponse

Transaction response type, providing optional error messages, a status code, and the transaction hash.

TxnResponse = {
  errorMsg?: string;
  code: number;
  status: string;
  txnHash: HexString;
};
  • errorMsg: Optional message if an error occurred during the transaction.

  • code: Status code showing the result of the transaction.

  • status: Description of the transaction status (e.g., success, failure).

  • txnHash: The hash for the executed transaction, allowing tracking on-chain.

PositionData

Data required to create a new DCA position, including token addresses, swap intervals, and amounts.

PositionData = {
  from: HexString;
  to: HexString;
  swapInterval: PositionFrequency;
  noOfSwaps: bigint;
  permit: HexString;
  amount: bigint;
};

EditPositionData

Details for editing an existing DCA position, with parameters for updating swap frequency, token allowances, and total swaps.

EditPositionData = {
  id: number;
  fromToken: HexString;
  amount: bigint;
  noOfSwaps: bigint;
  permit: HexString;
  frequency: PositionFrequency;
  totalSwaps: number;
};

PositionDetails

Comprehensive details about a DCA position, including swap history, profit/loss metrics, token amounts, and timestamps.

PositionDetails = {
  id: string;
  chainId: SupportedChainIds;
  fromAmountPerSwapInWei: string;
  swapsExecuted: number;
  profitLoss: {
    isProfit: boolean;
    percent: number;
    amountInUSD: number;
  } | null;
  averageBuyingCost: {
    amountInUSD: number | null;
    amount: number | null;
  };
  frequency: PositionFrequency;
  remainingAmount: {
    amountInWei: string;
    amount: string;
  };
  totalSwaps: number;
  status: PositionStatus;
  fromToken: PositionToken;
  toToken: PositionToken;
  totalDepositsInWei: string;
  claimedAmountInWei: string;
  claimableAmountInWei: string;
  swapHistory: PositionHistory[];
  lastUpdatedAt: number;
  createdAt: number;
};

PositionFrequency

Defines allowable frequencies for DCA swaps in seconds.

PositionFrequency = 3600 | 86400 | 604800; // 1 hour, 1 day, 1 week
  • 3600: Executes a swap every hour.

  • 86400: Executes a swap daily.

  • 604800: Executes a swap weekly.

PositionStatus

Enumerates the possible statuses of a DCA position.

PositionStatus =
  'ACTIVE' | 'TERMINATED' | 'COMPLETED' | 'SWAPPED' | 'MODIFIED_RATE' |
  'MODIFIED_DURATION' | 'MODIFIED_RATE_AND_DURATION' | 'MODIFIED' |
  'WITHDRAWN';

A breakdown of each position status:

  • ACTIVE: The DCA position is ongoing and swaps are executing as scheduled.

  • TERMINATED: The position was manually ended before all swaps completed.

  • COMPLETED: All scheduled swaps were successfully executed, and the position has reached its end.

  • SWAPPED: A swap has occurred within the position, typically indicating recent activity.

  • MODIFIED_RATE: The swap rate for the position was changed.

  • MODIFIED_DURATION: The duration or interval of swaps in the position was adjusted.

  • MODIFIED_RATE_AND_DURATION: Both the swap rate and duration of the position were altered.

  • MODIFIED: A general modification was made to the position, without specifying rate or duration changes.

  • WITHDRAWN: Funds were withdrawn from the position, potentially impacting future swaps.

PositionsByChainId

A record type mapping chain IDs to an array of PositionDetails.

PositionsByChainId = Record<number, PositionDetails[]>;

PositionHistory

Historical record of actions taken on a position, including transaction hash, timestamp, and amounts.

PositionHistory = {
  id: string;
  txnHash: string;
  timestamp: number;
  action: PositionStatus;
  fromAmountInWei: string;
  toAmountInWei: string;
};

PositionToken

Defines token metadata for a position, including contract address, symbol, decimal points, and balance.

PositionToken = {
  contract: HexString;
  name: string;
  symbol: string;
  decimals: number;
  chainId: SupportedChainIds;
  logo: string;
  price?: number | null;
  amountInWei: string;
  amountInUSD?: string;
  amount: string;
};

Token

General token structure used in allowances and balances, containing metadata like contract address, balance, and price.

Token = {
  contract: HexString;
  name: string;
  chainId: SupportedChainIds;
  symbol: string;
  balance: string;
  decimals: number;
  price: number;
  logo: string;
};

TokenList

An object where each token address is a key, mapped to a Token object.

TokenList = {
  [address: string]: Token;
};

Last updated