UNPKG

@akashicpay/sdk

Version:

SDK to interact with the Akashic ecosystem

233 lines (232 loc) 6.95 kB
import type { IKey } from '@activeledger/sdk'; import type { NodeStatus } from './APACTypes'; import type { ACDevNode, ACNode, AkashicBaseUrl, AkashicBaseUrlDev, AkashicBaseUrlStaging, AkashicPayBaseUrl, AkashicPayBaseUrlDev, Environment } from './constants'; import type { AkashicErrorCode } from './error'; export interface IBaseAcTransaction { $selfsign?: boolean; $sigs: any; $tx: IAcTxBody; $unanimous?: boolean; } interface IAcTxBody { $entry?: string; $contract: string; $namespace: string; $i: any; $o?: any; $r?: any; _dbIndex?: number; $expire?: string; metadata?: IMetadata; } export interface IMetadata { initiatedToNonL2?: string; identifier?: string; referenceId?: string; feesEstimate?: string; } export type Otk = Required<IKey>; export interface HTTPResponse<ResponseDataT = unknown> { data: ResponseDataT; status: number; } export interface IHttpClient { post: <ResponseDataT = unknown>(url: string, payload: unknown) => Promise<HTTPResponse<ResponseDataT>>; get: <ResponseDataT = unknown>(url: string) => Promise<HTTPResponse<ResponseDataT>>; } export declare enum TronSymbol { Tron = "TRX", Tron_Shasta = "TRX-SHASTA" } export declare enum EthereumSymbol { Ethereum_Mainnet = "ETH", Ethereum_Sepolia = "SEP" } export declare enum BinanceSymbol { Binance_Smart_Chain_Mainnet = "BNB", Binance_Smart_Chain_Testnet = "tBNB" } export declare enum SolanaSymbol { Solana = "SOL", Solana_Devnet = "SOLDEV" } export declare const NonEthEvmNetworks: { Binance_Smart_Chain_Mainnet: BinanceSymbol.Binance_Smart_Chain_Mainnet; Binance_Smart_Chain_Testnet: BinanceSymbol.Binance_Smart_Chain_Testnet; }; export declare const NetworkSymbol: { Solana: SolanaSymbol.Solana; Solana_Devnet: SolanaSymbol.Solana_Devnet; Binance_Smart_Chain_Mainnet: BinanceSymbol.Binance_Smart_Chain_Mainnet; Binance_Smart_Chain_Testnet: BinanceSymbol.Binance_Smart_Chain_Testnet; Ethereum_Mainnet: EthereumSymbol.Ethereum_Mainnet; Ethereum_Sepolia: EthereumSymbol.Ethereum_Sepolia; Tron: TronSymbol.Tron; Tron_Shasta: TronSymbol.Tron_Shasta; }; export type NetworkSymbol = TronSymbol | EthereumSymbol | BinanceSymbol | SolanaSymbol; export declare const MainNets: (BinanceSymbol | TronSymbol | EthereumSymbol | SolanaSymbol)[]; export declare const TestNets: (BinanceSymbol | TronSymbol | EthereumSymbol | SolanaSymbol)[]; export declare enum TokenSymbol { USDT = "USDT", USDC = "USDC", TETHER = "Tether" } export declare enum Currency { USDT = "USDT", USDC = "USDC", TRX = "TRX", ETH = "ETH", BNB = "BNB", SOL = "SOL", CHF = "CHF", CNY = "CNY", EUR = "EUR", HKD = "HKD", IDR = "IDR", INR = "INR", JPY = "JPY", KHR = "KHR", KRW = "KRW", MYR = "MYR", PHP = "PHP", SGD = "SGD", THB = "THB", TWD = "TWD", USD = "USD", VND = "VND" } export interface IGetTransactions { page?: number; limit?: number; startDate?: Date; endDate?: Date; layer?: TransactionLayer; status?: TransactionStatus; type?: TransactionType; hideSmallTransactions?: boolean; identifier?: string; referenceId?: string; } export interface IDepositAddress { address: string; identifier: string; referenceId?: string; requestedAmount?: string; requestedCurrency?: Currency; network?: NetworkSymbol; token?: TokenSymbol; exchangeRate?: string; amount?: string; expires?: string; markupPercentage?: string; } export interface IBalance { readonly networkSymbol: NetworkSymbol; readonly tokenSymbol?: TokenSymbol; readonly balance: string; } export interface IGetExchangeRatesResult { [key: string]: string; } export interface ILookForL2AddressResult { readonly l2Address?: string; readonly alias?: string; } export interface IPayoutResponse { error?: AkashicErrorCode; l2Hash?: string; } export interface IGetByOwnerAndIdentifier { identifier: string; coinSymbol: NetworkSymbol; } export interface IGetKeysByOwnerAndIdentifier { identifier: string; } export interface ICreateDepositOrder { identity: string; expires: number; referenceId: string; identifier: string; toAddress?: string; coinSymbol?: NetworkSymbol; signature: string; markupPercentage?: string; } interface IDepositRequest { readonly id: string; readonly requestedValue?: { amount: string; currency: Currency; }; readonly exchangeRate?: string; } interface IUserInfo { identity: string; walletType: string; } export interface ITransaction { readonly fromAddress: string; readonly toAddress: string; readonly layer: TransactionLayer; readonly initiatedAt: string; readonly confirmededAt: string; readonly amount: string; readonly coinSymbol: NetworkSymbol; readonly status: TransactionStatus; readonly txHash?: string; readonly feesPaid?: string; readonly l2TxnHash?: string; readonly tokenSymbol?: TokenSymbol; readonly internalFee?: IInternalFee; readonly identifier?: string; readonly referenceId?: string; readonly depositRequest?: IDepositRequest; readonly receiverInfo?: IUserInfo; readonly senderInfo?: IUserInfo; readonly feeIsDelegated?: boolean; } export declare enum TransactionLayer { L1 = "L1Transaction", L2 = "L2Transaction" } export declare enum TransactionStatus { PENDING = "Pending", CONFIRMED = "Confirmed", FAILED = "Failed" } export declare enum TransactionResult { SUCCESS = "Success", FAILURE = "Failure" } export declare enum TransactionType { DEPOSIT = "Deposit", WITHDRAWAL = "Withdrawal" } export interface IInternalFee { deposit?: string; withdraw?: string; } export type ACNodeT<Env extends Environment> = Env extends Environment.Production ? ACNode : ACDevNode; export type AkashicUrlT<Env extends Environment> = Env extends Environment.Production ? typeof AkashicBaseUrl : Env extends Environment.Preprod ? typeof AkashicBaseUrlDev : typeof AkashicBaseUrlStaging; export type AkashicPayUrlT<Env extends Environment> = Env extends Environment.Production ? typeof AkashicPayBaseUrl : typeof AkashicPayBaseUrlDev; export type APConstructorArgs<Env extends Environment = Environment.Production> = { environment?: Env; targetNode?: Env extends Environment.Production ? ACNode : ACDevNode; apiSecret?: string; }; type OTKPair = { l2Address: string; } & ({ recoveryPhrase: string; } | { privateKey: string; }); export type APInitialisationArgs = OTKPair; export type APBuilderArgs<Env extends Environment = Environment.Production> = APConstructorArgs<Env> & APInitialisationArgs; export interface NodeResponsiveness<Env extends Environment> extends NodeStatus { ping: number; node: ACNodeT<Env>; } export {};