TypeScript Types
TypeScript types and interfaces of Papaya SDK
Main Types
PapayaSDK
PapayaSDK
The main SDK class for interacting with the Papaya Protocol.
class PapayaSDK {
static create(
provider: ethers.Provider | ethers.Signer,
network?: NetworkName,
tokenSymbol?: TokenSymbol,
contractVersion?: string
): PapayaSDK;
static getAvailableNetworks(): NetworkName[];
static getAvailableTokens(network: NetworkName): TokenSymbol[];
}
NetworkName
NetworkName
Type for supported network names.
type NetworkName =
| 'polygon'
| 'bsc'
| 'avalanche'
| 'base'
| 'scroll'
| 'arbitrum'
| 'mainnet'
| 'sei'
| 'zksync';
TokenSymbol
TokenSymbol
Type for supported token symbols.
type TokenSymbol = 'USDT' | 'USDC' | 'PYUSD';
RatePeriod
RatePeriod
Enum for time periods of rates.
enum RatePeriod {
SECOND = 'second',
HOUR = 'hour',
DAY = 'day',
WEEK = 'week',
MONTH = 'month',
YEAR = 'year'
}
Data Interfaces
UserInfo
UserInfo
Interface for user information.
interface UserInfo {
balance: bigint;
incomeRate: bigint;
outgoingRate: bigint;
updated: bigint;
}
Subscription
Subscription
Interface for subscription information.
interface Subscription {
recipient: string;
incomeRate: bigint;
outgoingRate: bigint;
projectId: number;
}
SubscriptionInfo
SubscriptionInfo
Interface for detailed subscription information.
interface SubscriptionInfo {
isSubscribed: boolean;
outgoingRate: bigint;
projectId: number;
}
Type Usage Examples
Creating a Typed Instance
import { PapayaSDK, NetworkName, TokenSymbol } from '@papaya_fi/sdk';
// Typed parameters
const network: NetworkName = 'polygon';
const token: TokenSymbol = 'USDT';
const papaya = PapayaSDK.create(provider, network, token);
Working with User Information
import { UserInfo, formatOutput, convertRateToPeriod, RatePeriod } from '@papaya_fi/sdk';
async function displayUserInfo() {
const userInfo: UserInfo = await papaya.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 '@papaya_fi/sdk';
async function getFormattedSubscriptions() {
const subscriptions: Subscription[] = await papaya.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 '@papaya_fi/sdk';
async function checkSubscription(creatorAddress: string) {
const subInfo: SubscriptionInfo = await papaya.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
BigNumberish
Type for numbers that can be converted to BigNumber.
type BigNumberish = string | number | bigint;
TransactionResponse
TransactionResponse
Type for ethers.js transaction responses.
import { TransactionResponse } from 'ethers';
async function sendTransaction(): Promise<TransactionResponse> {
return await papaya.deposit(amount);
}
Last updated