UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

360 lines (352 loc) 13.4 kB
import { PublicKey, Commitment, Connection, Transaction, Signer, TransactionInstruction, Keypair, EpochInfo } from '@solana/web3.js'; import { Api } from './api/api.js'; import { CpmmKeys, ApiV3PoolInfoStandardItemCpmm, JupTokenType, ApiV3Token, ApiV3TokenRes, AvailabilityCheckAPI3 } from './api/type.js'; import { API_URL_CONFIG } from './api/url.js'; import { Owner } from './common/owner.js'; import { Cluster } from './solana/type.js'; import { E as TxBuilder, A as AddInstructionParam, i as BigNumberish, V as ReturnTypeFetchMultipleMintInfos, D as MakeTxData, Q as GetTransferAmountFee, O as LoadParams, S as SignAllTransactions } from './type-B-18QLgR.js'; import { Logger } from './common/logger.js'; import { TxVersion } from './common/txTool/txType.js'; import BN__default from 'bn.js'; import Decimal from 'decimal.js'; import { CpmmRpcData, CpmmComputeData, CreateCpmmPoolParam, CreateCpmmPoolAddress, AddCpmmLiquidityParams, WithdrawCpmmLiquidityParams, CpmmSwapParams, ComputePairAmountParams } from './sega/cpmm/type.js'; import { Structure } from './marshmallow/index.js'; import { TokenInfo } from './sega/token/type.js'; import { TokenAccount, TokenAccountRaw, GetOrCreateTokenAccountParams, HandleTokenAccountParams } from './sega/account/types.js'; interface ModuleBaseProps { scope: Sega; moduleName: string; } declare class ModuleBase { scope: Sega; private disabled; protected logger: Logger; constructor({ scope, moduleName }: ModuleBaseProps); protected createTxBuilder(feePayer?: PublicKey): TxBuilder; logDebug(...args: (string | number | Record<string, any>)[]): void; logInfo(...args: (string | number | Record<string, any>)[]): void; logAndCreateError(...args: (string | number | Record<string, any>)[]): void; checkDisabled(): void; } interface TokenAccountDataProp { tokenAccounts?: TokenAccount[]; tokenAccountRawInfos?: TokenAccountRaw[]; notSubscribeAccountChange?: boolean; } declare class Account extends ModuleBase { private _tokenAccounts; private _tokenAccountRawInfos; private _accountChangeListenerId?; private _accountListener; private _clientOwnedToken; private _notSubscribeAccountChange; private _accountFetchTime; constructor(params: TokenAccountDataProp & ModuleBaseProps); get tokenAccounts(): TokenAccount[]; get tokenAccountRawInfos(): TokenAccountRaw[]; set notSubscribeAccountChange(subscribe: boolean); updateTokenAccount({ tokenAccounts, tokenAccountRawInfos }: TokenAccountDataProp): Account; addAccountChangeListener(cbk: (data: TokenAccountDataProp) => void): Account; removeAccountChangeListener(cbk: (data: TokenAccountDataProp) => void): Account; getAssociatedTokenAccount(mint: PublicKey, programId?: PublicKey): PublicKey; resetTokenAccounts(): void; fetchWalletTokenAccounts(config?: { forceUpdate?: boolean; commitment?: Commitment; }): Promise<{ tokenAccounts: TokenAccount[]; tokenAccountRawInfos: TokenAccountRaw[]; }>; clearAccountChangeCkb(): void; getCreatedTokenAccount({ mint, programId, associatedOnly, }: { mint: PublicKey; programId?: PublicKey; associatedOnly?: boolean; }): Promise<PublicKey | undefined>; getOrCreateTokenAccount(params: GetOrCreateTokenAccountParams): Promise<{ account?: PublicKey; instructionParams?: AddInstructionParam; }>; checkOrCreateAta({ mint, programId, autoUnwrapWSOLToSOL, }: { mint: PublicKey; programId?: PublicKey; autoUnwrapWSOLToSOL?: boolean; }): Promise<{ pubKey: PublicKey; newInstructions: AddInstructionParam; }>; handleTokenAccount(params: HandleTokenAccountParams): Promise<AddInstructionParam & { tokenAccount: PublicKey; }>; processTokenAccount(props: { mint: PublicKey; programId?: PublicKey; amount?: BigNumberish; useSOLBalance?: boolean; handleTokenAccount?: boolean; feePayer?: PublicKey; }): Promise<Promise<AddInstructionParam & { tokenAccount?: PublicKey; }>>; } declare class CpmmModule extends ModuleBase { constructor(params: ModuleBaseProps); load(): Promise<void>; getCpmmPoolKeys(poolId: string): Promise<CpmmKeys>; getRpcPoolInfo(poolId: string, fetchConfigInfo?: boolean): Promise<CpmmRpcData>; getRpcPoolInfos(poolIds: string[], fetchConfigInfo?: boolean): Promise<{ [poolId: string]: CpmmRpcData; }>; toComputePoolInfos({ pools, mintInfos, }: { pools: Record<string, CpmmRpcData>; mintInfos: ReturnTypeFetchMultipleMintInfos; }): Record<string, CpmmComputeData>; getPoolInfoFromRpc(poolId: string): Promise<{ poolInfo: ApiV3PoolInfoStandardItemCpmm; poolKeys: CpmmKeys; rpcData: CpmmRpcData; }>; createPool<T extends TxVersion>({ poolId, programId, poolFeeAccount, startTime, ownerInfo, associatedOnly, checkCreateATAOwner, txVersion, feeConfig, computeBudgetConfig, txTipConfig, feePayer, ...params }: CreateCpmmPoolParam<T>): Promise<MakeTxData<T, { address: CreateCpmmPoolAddress; }>>; addLiquidity<T extends TxVersion>(params: AddCpmmLiquidityParams<T>): Promise<MakeTxData<T>>; withdrawLiquidity<T extends TxVersion>(params: WithdrawCpmmLiquidityParams<T>): Promise<MakeTxData<T>>; swap<T extends TxVersion>(params: CpmmSwapParams<T>): Promise<MakeTxData<T>>; computeSwapAmount({ pool, amountIn, outputMint, slippage, }: { pool: CpmmComputeData; amountIn: BN__default; outputMint: string | PublicKey; slippage: number; }): { allTrade: boolean; amountIn: BN__default; amountOut: BN__default; minAmountOut: BN__default; fee: BN__default; executionPrice: Decimal; priceImpact: any; }; computePairAmount({ poolInfo, baseReserve, quoteReserve, amount, slippage, epochInfo, baseIn, }: ComputePairAmountParams): { inputAmountFee: GetTransferAmountFee; anotherAmount: GetTransferAmountFee; maxAnotherAmount: GetTransferAmountFee; minAnotherAmount: GetTransferAmountFee; liquidity: BN__default; }; } interface SHOW_INFO { programId: PublicKey; poolId: PublicKey; ammId: PublicKey; ownerAccountId: PublicKey; snapshotLpAmount: BN__default; openTime: number; endTime: number; project: typeof Utils1216.VERSION_PROJECT[number]; canClaim: boolean; canClaimErrorType: canClaimErrorType; tokenInfo: { mintAddress: PublicKey; mintVault: PublicKey; mintDecimals: number; perLpLoss: BN__default; debtAmount: BN__default; }[]; } type canClaimErrorType = "outOfOperationalTime" | "alreadyClaimIt" | undefined; declare class Utils1216 extends ModuleBase { static CLAIMED_NUM: number; static POOL_LAYOUT: Structure<number | PublicKey | Buffer | BN__default | BN__default[] | { mintDecimals: number; mintAddress: PublicKey; mintVault: PublicKey; perLpLoss: BN__default; totalClaimedAmount: BN__default; }[], "", { status: number; bump: number; openTime: BN__default; endTime: BN__default; ammId: PublicKey; tokenInfo: { mintDecimals: number; mintAddress: PublicKey; mintVault: PublicKey; perLpLoss: BN__default; totalClaimedAmount: BN__default; }[]; padding: BN__default[]; }>; static OWNER_LAYOUT: Structure<number | PublicKey | Buffer | BN__default | BN__default[] | { mintAddress: PublicKey; debtAmount: BN__default; claimedAmount: BN__default; }[], "", { owner: PublicKey; poolId: PublicKey; bump: number; lpAmount: BN__default; tokenInfo: { mintAddress: PublicKey; debtAmount: BN__default; claimedAmount: BN__default; }[]; padding: BN__default[]; version: number; }>; static DEFAULT_POOL_ID: PublicKey[]; static SEED_CONFIG: { pool: { id: Buffer; }; owner: { id: Buffer; }; }; static VERSION_PROJECT: readonly [undefined, "Francium", "Tulip", "Larix"]; static getPdaPoolId(programId: PublicKey, ammId: PublicKey): { publicKey: PublicKey; nonce: number; }; static getPdaOwnerId(programId: PublicKey, poolId: PublicKey, owner: PublicKey, version: number): { publicKey: PublicKey; nonce: number; }; static getAllInfo({ connection, programId, poolIds, wallet, chainTime, }: { connection: Connection; programId: PublicKey; poolIds: PublicKey[]; wallet: PublicKey; chainTime: number; }): Promise<SHOW_INFO[]>; makeClaimTransaction({ poolInfo, ownerInfo, feePayer, }: { connection: Connection; poolInfo: SHOW_INFO; ownerInfo: { wallet?: PublicKey; associatedOnly: boolean; }; feePayer?: PublicKey; }): Promise<{ transaction: Transaction; signer: Signer[]; }[]>; makeClaimAllTransaction({ poolInfos, ownerInfo, feePayer, }: { poolInfos: SHOW_INFO[]; ownerInfo: { wallet?: PublicKey; associatedOnly: boolean; }; feePayer?: PublicKey; }): Promise<{ transaction: Transaction; signer: Signer[]; }[]>; static makeClaimInstruction({ programId, poolInfo, ownerInfo, }: { programId: PublicKey; poolInfo: SHOW_INFO; ownerInfo: { wallet: PublicKey; ownerPda: PublicKey; claimAddress: PublicKey[]; }; }): TransactionInstruction; } declare class TokenModule extends ModuleBase { private _tokenList; private _tokenMap; private _blackTokenMap; private _mintGroup; private _whiteMap; private _extraTokenList; constructor(params: ModuleBaseProps); load(params?: LoadParams & { type?: JupTokenType; }): Promise<void>; get tokenList(): TokenInfo[]; get tokenMap(): Map<string, TokenInfo>; get blackTokenMap(): Set<string>; get mintGroup(): { official: Set<string>; jup: Set<string>; }; get whiteListMap(): Set<string>; /** === util functions === */ getTokenInfo(mint: string | PublicKey): Promise<ApiV3Token>; } interface SegaLoadParams extends TokenAccountDataProp, Omit<SegaApiBatchRequestParams, "api"> { connection: Connection; cluster?: Cluster; owner?: PublicKey | Keypair; apiRequestInterval?: number; apiRequestTimeout?: number; apiCacheTime?: number; signAllTransactions?: SignAllTransactions; urlConfigs?: API_URL_CONFIG; logRequests?: boolean; logCount?: number; jupTokenType?: JupTokenType; disableFeatureCheck?: boolean; disableLoadToken?: boolean; blockhashCommitment?: Commitment; loopMultiTxStatus?: boolean; } interface SegaApiBatchRequestParams { api: Api; defaultChainTimeOffset?: number; defaultChainTime?: number; } type SegaConstructorParams = Required<SegaLoadParams> & SegaApiBatchRequestParams; interface DataBase<T> { fetched: number; data: T; extInfo?: Record<string, any>; } interface ApiData { tokens?: DataBase<ApiV3Token[]>; tokenList?: DataBase<ApiV3TokenRes>; jupTokenList?: DataBase<ApiV3Token[]>; } declare class Sega { cluster: Cluster; account: Account; cpmm: CpmmModule; utils1216: Utils1216; token: TokenModule; rawBalances: Map<string, string>; apiData: ApiData; availability: Partial<AvailabilityCheckAPI3>; blockhashCommitment: Commitment; loopMultiTxStatus?: boolean; private _connection; private _owner; api: Api; private _apiCacheTime; private _signAllTransactions?; private logger; private _chainTime?; private _epochInfo?; constructor(config: SegaConstructorParams); static load(config: SegaLoadParams): Promise<Sega>; get owner(): Owner | undefined; get ownerPubKey(): PublicKey; setOwner(owner?: PublicKey | Keypair): Sega; get connection(): Connection; setConnection(connection: Connection): Sega; get signAllTransactions(): SignAllTransactions | undefined; setSignAllTransactions(signAllTransactions?: SignAllTransactions): Sega; checkOwner(): void; private isCacheInvalidate; fetchChainTime(): Promise<void>; fetchV3TokenList(forceUpdate?: boolean): Promise<ApiV3TokenRes>; fetchJupTokenList(forceUpdate?: boolean): Promise<ApiV3Token[]>; get chainTimeData(): { offset: number; chainTime: number; } | undefined; chainTimeOffset(): Promise<number>; currentBlockChainTime(): Promise<number>; fetchEpochInfo(): Promise<EpochInfo>; fetchAvailabilityStatus(skipCheck?: boolean): Promise<Partial<AvailabilityCheckAPI3>>; } export { Account as A, CpmmModule as C, ModuleBase as M, type SegaLoadParams as S, type TokenAccountDataProp as T, Utils1216 as U, type SegaApiBatchRequestParams as a, type SegaConstructorParams as b, Sega as c, type SHOW_INFO as d, type canClaimErrorType as e, type ModuleBaseProps as f, TokenModule as g };