TypeScript Types

TypeScript types and interfaces of Azoth SDK

The Azoth SDK provides full TypeScript typing for better development experience and autocompletion.

Main Types

AzothSDK

The main SDK class for interacting with the AzothPay Protocol.

class AzothSDK {
  static create(
    provider: ethers.Provider | ethers.Signer,
    network?: NetworkName,
    tokenSymbol?: TokenSymbol,
    contractVersion?: string
  ): AzothSDK;
  
  static getAvailableNetworks(): NetworkName[];
  static getAvailableTokens(network: NetworkName): TokenSymbol[];
}

NetworkName

Type of supported networks

type NetworkName =
| 'polygon'
| 'bsc'
| 'avalanche'
| 'base'
| 'scroll'
| 'arbitrum'
| 'mainnet'
| 'sei'
| 'zksync';

TokenSymbol

Type for supported token symbols.

type TokenSymbol = 'USDT' | 'USDC' | 'PYUSD';

RatePeriod

Enum for time periods of rates.

enum RatePeriod {
  SECOND = 'second',
  HOUR = 'hour',
  DAY = 'day',
  WEEK = 'week',
  MONTH = 'month',
  YEAR = 'year'
}

Data Interfaces

UserInfo

Interface for user information.

interface UserInfo {
  balance: bigint;
  incomeRate: bigint;
  outgoingRate: bigint;
  updated: bigint;
}

Subscription

Interface for subscription information.

interface Subscription {
  recipient: string;
  incomeRate: bigint;
  outgoingRate: bigint;
  projectId: number;
}

SubscriptionInfo

Interface for detailed subscription information.

interface SubscriptionInfo {
  isSubscribed: boolean;
  outgoingRate: bigint;
  projectId: number;
}

Type Usage Examples

Creating a Typed Instance

import { AzothSDK, NetworkName, TokenSymbol } from '@azothpay/sdk';

// Typed parameters
const network: NetworkName = 'polygon';
const token: TokenSymbol = 'USDT';

const azoth = AzothSDK.create(provider, network, token);

Working with User Information

import { UserInfo, formatOutput, convertRateToPeriod, RatePeriod } from '@azothpay/sdk';

async function displayUserInfo() {
  const userInfo: UserInfo = await azoth.getUserInfo();
  
  const formattedInfo = {
    balance: formatOutput(userInfo.balance, 18),
    incomeRate: convertRateToPeriod(
      Number(formatOutput(userInfo.incomeRate, 18)), 
      RatePeriod.MONTH
    ),
    outgoingRate: convertRateToPeriod(
      Number(formatOutput(userInfo.outgoingRate, 18)), 
      RatePeriod.MONTH
    ),
    updated: new Date(Number(userInfo.updated) * 1000)
  };
  
  return formattedInfo;
}

Working with Subscriptions

import { Subscription, convertRateToPeriod, RatePeriod } from '@azothpay/sdk';

async function getFormattedSubscriptions() {
  const subscriptions: Subscription[] = await azoth.getSubscriptions();
  
  return subscriptions.map((sub: Subscription) => ({
    recipient: sub.recipient,
    monthlyRate: convertRateToPeriod(
      Number(formatOutput(sub.outgoingRate, 18)), 
      RatePeriod.MONTH
    ),
    projectId: sub.projectId
  }));
}

Checking Subscriptions

import { SubscriptionInfo } from '@azothpay/sdk';

async function checkSubscription(creatorAddress: string) {
  const subInfo: SubscriptionInfo = await azoth.isSubscribed(creatorAddress);
  
  if (subInfo.isSubscribed) {
    const monthlyRate = convertRateToPeriod(
      Number(formatOutput(subInfo.outgoingRate, 18)), 
      RatePeriod.MONTH
    );
    console.log(`Subscribed to ${creatorAddress} with rate ${monthlyRate} USDT/month`);
  } else {
    console.log(`Not subscribed to ${creatorAddress}`);
  }
}

Utility Types

BigNumberish

Type for numbers that can be converted to BigNumber.

type BigNumberish = string | number | bigint;

TransactionResponse

Type for ethers.js transaction responses.

import { TransactionResponse } from 'ethers';

async function sendTransaction(): Promise<TransactionResponse> {
  return await azoth.deposit(amount);
}

Last updated