UNPKG

zebec-instant-card-sdk

Version:

An sdk for interacting with zebec instant card program in solana.

113 lines (112 loc) 5.67 kB
/// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" /> import BigNumber from "bignumber.js"; import { AnchorProvider, IdlEvents } from "@coral-xyz/anchor"; import { ConfirmOptions, Connection, ParsedTransaction, PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from "@solana/web3.js"; import { ZebecCardContract } from "./idl"; import { ParsedFeeTier } from "./instructions"; import { ZebecConnectionProvider } from "./provider"; import { CardPurchaseEvent, DepositToUserPdaEvent, FeeTier, QuoteInfo } from "./service"; import { BigIntString, DecimalString, EmailString, PercentString, PublicKeyString } from "./types"; /** * Gets decimals for given mint * @param connection * @param mint * @returns */ export declare function getMintDecimals(connection: Connection, mint: PublicKey): Promise<number>; /** * Converts percentage value to bps * @param percent * @returns */ export declare function percentToBps(percent: PercentString): number; export declare function bpsToPercent(bps: number): PercentString; /** * Parse jupiter quote response * @param connection * @param quoteInfo * @returns */ export declare function parseQuoteInfo(quoteInfo: unknown): Promise<QuoteInfo>; /** * Parse deposit event * @param event * @returns */ export declare function parseDepositToUserPdaEvent(event: IdlEvents<ZebecCardContract>["DepositToUserPda"]): DepositToUserPdaEvent; export declare function parseCardPurchaseEvent(event: IdlEvents<ZebecCardContract>["PrepaidDigitalCardPurshase"]): CardPurchaseEvent; /** * Wallet interface used by Anchor Framework */ export interface AnchorWallet { signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>; signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>; publicKey: PublicKey; } /** * Create anchor provider * @param connection Solana web3 connection * @param wallet Anchor wallet * @param opts Confirm options * * @example * ``` * const connection = new Connection(process.env.RPC_URL || clusterApiUrl("mainnet-beta")) * const wallet = useWallet(); * const provider = getAnchorProvider(connection, wallet); * ``` */ export declare function getAnchorProvider(connection: Connection, wallet: AnchorWallet, opts: ConfirmOptions): AnchorProvider; /** * Create Zebec Connection Provider. Can we used for readonly operation to solana program * @param connection Solana web3 connection * @returns */ export declare function getZebecConnectionProvider(connection: Connection): ZebecConnectionProvider; /** * Construct a CreateAssociatedTokenAccount instruction * * @param payer Payer of the initialization fees * @param associatedToken New associated token account * @param owner Owner of the new account * @param mint Token mint account * @param programId SPL Token program account * @param associatedTokenProgramId SPL Associated Token program account * * @return Instruction to add to a transaction */ export declare function createAssociatedTokenAccountInstruction(payer: PublicKey, associatedToken: PublicKey, owner: PublicKey, mint: PublicKey, programId?: PublicKey, associatedTokenProgramId?: PublicKey): TransactionInstruction; /** * Get the address of the associated token account for a given mint and owner * * @param mint Token mint account * @param owner Owner of the new account * @param allowOwnerOffCurve Allow the owner account to be a PDA (Program Derived Address) * @param programId SPL Token program account * @param associatedTokenProgramId SPL Associated Token program account * * @return Address of the associated token account */ export declare function getAssociatedTokenAddressSync(mint: PublicKey, owner: PublicKey, allowOwnerOffCurve?: boolean, programId?: PublicKey, associatedTokenProgramId?: PublicKey): PublicKey; export declare function sortFeeTierDesc(feeTiers: ParsedFeeTier[]): ParsedFeeTier[]; export declare function assertValidDecimalString(input: string): asserts input is DecimalString; export declare function assertValidPercentString(input: string): asserts input is PercentString; export declare function assertValidPublicKeyString(input: string): asserts input is PublicKeyString; export declare function assertValidBigIntString(input: string | number): asserts input is BigIntString; export declare function parseBigIntString(input: string | number): BigIntString; export declare function parseDecimalString(input: string | number): DecimalString; export declare function parsePercentString(input: string | number): PercentString; export declare function parsePublicKeyString(input: string | PublicKey): PublicKeyString; export declare function parseFeeTiers(input: { minAmount: string; maxAmount: string; feePercent: string; }[]): FeeTier[]; export declare function assertEmailString(value: string): asserts value is EmailString; export declare function parseEmailString(input: string): EmailString; export declare function hashSHA256(input: string): Promise<string>; export declare function getBuyCardMemoFromParsedTransaction(transaction: ParsedTransaction): object & Record<"buyer", unknown>; export declare function areDateOfSameDay(date1: Date, date2: Date): boolean; export declare function sleep(ms: number): Promise<unknown>; export type PriorityLevel = "low" | "medium" | "high"; export declare function getRecentPriorityFee(connection: Connection, instructions: TransactionInstruction[], priorityLevel: PriorityLevel, maxFeeCap: BigNumber): Promise<BigNumber>;