@tiplink/api
Version:
Api for creating and sending TipLinks
67 lines (66 loc) • 2.94 kB
TypeScript
import "dotenv/config";
import { IdlEvents } from "@coral-xyz/anchor";
import { PublicKey, Connection, MessageCompiledInstruction, CompiledInstruction } from "@solana/web3.js";
import { Mint } from "@solana/spl-token";
import { TiplinkEscrow } from "./anchor-generated/types/tiplink_escrow";
export type DepositEvent = IdlEvents<TiplinkEscrow>["DepositEvent"];
export type WithdrawEvent = IdlEvents<TiplinkEscrow>["WithdrawEvent"];
export declare enum EscrowActionType {
DepositLamport = "DepositLamport",
WithdrawLamport = "WithdrawLamport",
DepositSpl = "DepositSpl",
WithdrawSpl = "WithdrawSpl"
}
export type EscrowActionDepositLamport = {
type: EscrowActionType.DepositLamport;
depositor: PublicKey;
pda: PublicKey;
receiverTipLink: PublicKey;
amount: number;
};
export type EscrowActionWithdrawLamport = {
type: EscrowActionType.WithdrawLamport;
authority: PublicKey;
destination: PublicKey;
pda: PublicKey;
};
export type EscrowActionDepositSpl = {
type: EscrowActionType.DepositSpl;
depositor: PublicKey;
pda: PublicKey;
receiverTipLink: PublicKey;
amount: number;
mint: Mint;
};
export type EscrowActionWithdrawSpl = {
type: EscrowActionType.WithdrawSpl;
authority: PublicKey;
destination: PublicKey;
pda: PublicKey;
mint: Mint;
};
export type EscrowAction = EscrowActionDepositLamport | EscrowActionWithdrawLamport | EscrowActionDepositSpl | EscrowActionWithdrawSpl;
export type RecordedEscrowAction = {
slot: number;
blockTime: number | null | undefined;
txSig: string;
ixIndex: number;
innerIxIndex?: number;
action: EscrowAction;
};
export declare function serializeRecordedEscrowActions(recordedActions: RecordedEscrowAction[]): any[];
export declare function deserializeRecordedEscrowActions(connection: Connection, serializedRecordedActions: any[]): Promise<RecordedEscrowAction[]>;
export declare function parseEscrowIx(connection: Connection, compIx: MessageCompiledInstruction | CompiledInstruction, accountKeys: PublicKey[]): Promise<EscrowAction | undefined>;
/**
* @remarks Only use this on the backend for a custom parsing setup. Otherwise,
* use `getRecordedEscrowActionsFromTx`
*/
export declare function parseEscrowTx(connection: Connection, sig: string): Promise<RecordedEscrowAction[]>;
/**
* @remarks Only use this on the backend for a custom parsing setup. Otherwise,
* use `getRecordedEscrowActionsFromVault`
* @param delay - Delay between RPC requests to avoid rate limiting
*/
export declare function getAllRecordedEscrowActions(connection: Connection, pda: PublicKey, delayMs?: number): Promise<RecordedEscrowAction[]>;
export declare function getRecordedEscrowActionsFromVault(connection: Connection, pda: PublicKey): Promise<RecordedEscrowAction[]>;
export declare function getRecordedEscrowActionsFromTx(connection: Connection, sig: string): Promise<RecordedEscrowAction[]>;