escrow-market-sdk
Version:
SDK for Escrow Market Solana Program
126 lines (125 loc) • 5.11 kB
TypeScript
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
import * as Types from './types';
/**
* Client class để tương tác với Escrow Market program
*/
export declare class EscrowMarketClient {
private connection;
private program;
/**
* Khởi tạo EscrowMarketClient
* @param connection Connection đến Solana cluster
* @param programId Địa chỉ program (string)
*/
constructor(connection: Connection, programId: string);
/**
* Initialize Config account cho escrow market
* @param feePayer Địa chỉ người trả phí
* @param admin Admin public key
* @param operator Operator public key
* @returns Transaction object
*/
initialize(feePayer: PublicKey, admin: PublicKey, operator: PublicKey): Promise<Transaction>;
/**
* Initialize vault cho một mint cụ thể
* @param feePayer Địa chỉ người trả phí
* @param mint Mint của token
* @returns Transaction object
*/
initializeVault(feePayer: PublicKey, mint: PublicKey): Promise<Transaction>;
/**
* Deposit token vào vault
* @param depositor Địa chỉ của người gửi token
* @param mint Mint của token
* @param amount Số lượng token
* @returns Transaction object
*/
deposit(depositor: PublicKey, mint: PublicKey, amount: number | bigint): Promise<Transaction>;
/**
* Withdraw token từ vault (chỉ operator mới có quyền gọi)
* @param operatorPubkey Địa chỉ của operator
* @param user Địa chỉ của user nhận token
* @param mint Mint của token
* @param amount Số lượng token
* @param nonce Số duy nhất để chống replay attack
* @param opts Options cho transaction
* @returns Transaction object
*/
withdraw(operatorPubkey: PublicKey, user: PublicKey, mint: PublicKey, amount: number | bigint, nonce: number | bigint, opts?: {
userTokenAccount?: PublicKey;
vaultTokenAccount?: PublicKey;
}): Promise<Transaction>;
/**
* Parse events emitted by the program from a transaction signature using Anchor's EventParser
* @param signature Transaction signature to parse events from
* @returns Array of decoded events from the transaction
*/
parseEventsFromTransaction(signature: string): Promise<any[]>;
/**
* Settle một deal
* @param operatorPubkey Địa chỉ của operator
* @param dealId ID của deal
* @param buyer Địa chỉ của buyer
* @param seller Địa chỉ của seller
* @param tokenTransfer Địa chỉ mint của token transfer
* @param tokenWithdraw Địa chỉ mint của token withdraw
* @param transferAmount Số lượng token chuyển
* @param withdrawAmount Số lượng token rút
* @param opts Options cho transaction
* @returns Transaction object
*/
settle(operatorPubkey: PublicKey, dealId: string, buyer: PublicKey, seller: PublicKey, tokenTransfer: PublicKey, tokenWithdraw: PublicKey, transferAmount: number | bigint, withdrawAmount: number | bigint, opts?: {
skipBalanceCheck?: boolean;
}): Promise<Transaction>;
/**
* Operator cancel một deal
* @param operatorPubkey Địa chỉ của operator
* @param dealId ID của deal
* @param buyer Địa chỉ của buyer
* @param tokenWithdraw Địa chỉ mint của token
* @param amount Số lượng token hoàn lại
* @returns Transaction object
*/
operatorCancel(operatorPubkey: PublicKey, dealId: string, buyer: PublicKey, tokenWithdraw: PublicKey, amount: number | bigint): Promise<Transaction>;
/**
* Lấy thông tin Config
* @returns Config account
*/
getConfig(): Promise<Types.Config>;
/**
* Lấy thông tin Deal
* @param dealId ID của deal
* @returns Deal account hoặc null nếu không tồn tại
*/
getDeal(dealId: string): Promise<Types.Deal | null>;
/**
* Lấy số dư trong vault của một mint
* @param mint Mint của token
* @returns Số dư token trong vault
*/
getVaultBalance(mint: PublicKey): Promise<bigint>;
/**
* Kiểm tra địa chỉ có quyền admin không
* @param pubkey Địa chỉ cần kiểm tra
* @returns true nếu là admin
*/
isAdmin(pubkey: PublicKey): Promise<boolean>;
/**
* Kiểm tra địa chỉ có quyền operator không
* @param pubkey Địa chỉ cần kiểm tra
* @returns true nếu là operator
*/
isOperator(pubkey: PublicKey): Promise<boolean>;
/**
* Đăng ký lắng nghe sự kiện
* @param eventName Tên sự kiện
* @param callback Hàm callback xử lý sự kiện
* @returns ID của listener
*/
subscribeToEvents(eventName: string, callback: (event: any) => void): number;
/**
* Hủy đăng ký lắng nghe sự kiện
* @param listenerId ID của listener
*/
unsubscribeFromEvent(listenerId: number): Promise<void>;
}