UNPKG

@broxus/js-core

Version:

MobX-based JavaScript Core library

163 lines (162 loc) 9.13 kB
import { type Address, type DecodeEventParams, type DecodeTransactionParams, type ProviderRpcClient, type SendInternalParams, type Subscriber, type Transaction } from 'everscale-inpage-provider'; import { SmartContractModel } from '../../core'; import { type Dex } from '../../models/dex'; import { type DexAccountAbi } from '../../models/dex-account/abi'; import { type DexAccountAddPairAbiParams, type DexAccountAddPoolAbiParams, type DexAccountDecodedEvent, type DexAccountDecodedTransaction, type DexAccountDepositLiquidityAbiParams, type DexAccountDepositLiquidityV2AbiParams, DexAccountUtils, type DexAccountWithdrawAbiParams } from '../../models/dex-account/DexAccountUtils'; import { type DexPairDepositLiquiditySuccess, type DexPairDepositLiquiditySuccessV2, type DexPairOperationCancelled } from '../../models/dex-pair'; import { type TvmTokenWalletTransferToWalletAbiParams } from '../../models/tvm-token-wallet'; import { type CallId, type Forceable, type SendMessageCallback, type Silentable, type Syncable, type TransactionCallbacks, type TransactionFailureReason, type TransactionSentDetails, type TransactionSuccessResult, type Watchable } from '../../types'; type DexAccountCallbacks<SendParams = any, SuccessParams = any, FailureParams = any> = SendMessageCallback<SendParams> & TransactionCallbacks<TransactionSuccessResult<SuccessParams>, TransactionFailureReason<FailureParams>, TransactionSentDetails>; export interface DexAccountAddPairSuccessResult { leftRootAddress: Address; pairAddress: Address; rightRootAddress: Address; } export interface DexAccountAddPairCallbacks extends DexAccountCallbacks<unknown, DexAccountAddPairSuccessResult> { } export interface DexAccountAddPairParams extends DexAccountAddPairAbiParams, Partial<CallId>, DexAccountAddPairCallbacks { } export interface DexAccountAddPoolSuccessResult { poolAddress: Address; roots: Address[]; } export interface DexAccountAddPoolCallbacks extends DexAccountCallbacks<unknown, DexAccountAddPoolSuccessResult> { } export interface DexAccountAddPoolParams extends DexAccountAddPoolAbiParams, Partial<CallId>, DexAccountAddPoolCallbacks { } export interface DexAccountDepositTokenSendCallbackParams { amount?: string; tokenAddress?: Address; } export interface DexAccountDepositTokenSuccessResult { amount: string; balance: string; tokenAddress: Address; } export interface DexAccountDepositTokenCallbacks extends DexAccountCallbacks<DexAccountDepositTokenSendCallbackParams, DexAccountDepositTokenSuccessResult> { } export interface DexAccountDepositTokenParams extends TvmTokenWalletTransferToWalletAbiParams, Partial<CallId>, DexAccountDepositTokenCallbacks { senderAddress?: Address | string; senderTokenWalletAddress?: Address | string; tokenAddress?: Address | string; } export interface DexAccountDepositLiquidityCallbacks extends DexAccountCallbacks<unknown, DexPairDepositLiquiditySuccess | DexPairDepositLiquiditySuccessV2, DexPairOperationCancelled> { } export interface DexAccountDepositLiquidityParams extends Omit<DexAccountDepositLiquidityAbiParams, 'sendGasTo'>, DexAccountDepositLiquidityCallbacks { senderAddress: Address | string; sendGasTo?: Address | string; } export interface DexAccountDepositLiquidityV2Params extends Omit<DexAccountDepositLiquidityV2AbiParams, 'sendGasTo'>, DexAccountDepositLiquidityCallbacks { senderAddress: Address | string; sendGasTo?: Address | string; } export interface DexAccountWithdrawTokenSendCallbackParams { amount: string; tokenAddress: Address; } export interface DexAccountWithdrawTokenSuccessResult { amount: string; balance: string; tokenAddress: Address; } export interface DexAccountWithdrawTokenCallbacks extends DexAccountCallbacks<DexAccountWithdrawTokenSendCallbackParams, DexAccountWithdrawTokenSuccessResult> { } export interface DexAccountWithdrawTokenParams extends DexAccountWithdrawAbiParams, DexAccountWithdrawTokenCallbacks { } export interface DexAccountCtorOptions { watchDebounceDelay?: number; } export interface DexAccountCreateOptions extends DexAccountCtorOptions, Syncable, Watchable { watchCallback?: VoidFunction; } export type DexAccountCreateConfig = { address: Address | string; dex: Dex; } | { dex: Dex; ownerAddress: Address | string; }; export interface DexAccountData { balances?: Map<string, string>; ownerAddress: Address; wallets?: Map<string, Address>; } export declare class DexAccount extends SmartContractModel<DexAccountData> { protected readonly _connection: ProviderRpcClient; protected readonly dex: Dex; protected readonly options?: Readonly<DexAccountCtorOptions> | undefined; protected readonly _provider?: ProviderRpcClient | undefined; static Utils: typeof DexAccountUtils; /** * @param {ProviderRpcClient} _connection Standalone RPC client that doesn't require connection to the TVM wallet provider * @param {Address | string} address DexAccount root address * @param {Dex} dex Dex Smart Contract Model instance * @param {Readonly<DexAccountCtorOptions>} [options] (optional) DexAccount Smart Contract Model options * @param {ProviderRpcClient} [_provider] (optional) RPC provider that require connection to the TVM wallet */ constructor(_connection: ProviderRpcClient, address: Address | string, dex: Dex, options?: Readonly<DexAccountCtorOptions> | undefined, _provider?: ProviderRpcClient | undefined); /** * @param {ProviderRpcClient} connection Standalone RPC client that doesn't require connection to the TVM wallet provider * @param {Readonly<DexAccountCreateConfig>} config DexAccount Smart Contract Model config * @param {Readonly<DexAccountCtorOptions>} [options] (optional) DexAccount Smart Contract Model options * @param {ProviderRpcClient} [provider] (optional) RPC provider that require connection to the TVM wallet */ static create(connection: ProviderRpcClient, config: Readonly<DexAccountCreateConfig>, options?: Readonly<DexAccountCreateOptions>, provider?: ProviderRpcClient): Promise<DexAccount>; sync(options?: Forceable & Silentable): Promise<void>; watch(callback?: VoidFunction): Promise<Subscriber>; unwatch(): Promise<void>; check(options?: Forceable): Promise<boolean>; /** * Stream-based method to add pair (constant or stable) to the DexAccount * @param {DexAccountDepositTokenParams} params * @param {Partial<SendInternalParams>} [args] * @deprecated Use `DexAccount.addPool` instead */ addPair(params: DexAccountAddPairParams, args: Pick<SendInternalParams, 'from'> & Omit<Partial<SendInternalParams>, 'from'>): Promise<Transaction | undefined>; /** * Stream-based method to add pool (stable) to the DexAccount * @param {DexAccountDepositTokenParams} params * @param {Partial<SendInternalParams>} [args] */ addPool(params: DexAccountAddPoolParams, args: Pick<SendInternalParams, 'from'> & Omit<Partial<SendInternalParams>, 'from'>): Promise<Transaction | undefined>; /** * Stream-based method to deposit a given token to the DexAccount * @param {DexAccountDepositTokenParams} params * @param {Partial<SendInternalParams>} [args] */ depositToken(params: DexAccountDepositTokenParams, args?: Partial<SendInternalParams>): Promise<Transaction | undefined>; /** * Stream-based method to deposit a liquidity from the DexAccount assets * @param {DexAccountDepositLiquidityParams} params * @param {Partial<SendInternalParams>} [args] */ depositLiquidity(params: DexAccountDepositLiquidityParams, args?: Partial<SendInternalParams>): Promise<Transaction | undefined>; depositLiquidityV2(params: DexAccountDepositLiquidityV2Params, args?: Partial<SendInternalParams>): Promise<Transaction | undefined>; /** Stream-based method to withdraw a given token from the DexAccount * @param {DexAccountWithdrawTokenParams} params * @param {Partial<SendInternalParams>} [args] */ withdrawToken(params: DexAccountWithdrawTokenParams, args?: Partial<SendInternalParams>): Promise<Transaction | undefined>; /** * Returns user lp wallets balances as map where * key is lp wallet address and value is balance. * @returns {DexAccountData["balances"]} */ get balances(): DexAccountData['balances']; /** * Returns account owner address * @returns {DexAccountData["ownerAddress"]} */ get ownerAddress(): DexAccountData['ownerAddress']; /** * Returns user token wallets addresses as map where * key is lp token address and value is token wallet address. * @returns {DexAccountData["wallets"]} */ get wallets(): DexAccountData['wallets']; decodeEvent(args: DecodeEventParams<typeof DexAccountAbi>): Promise<DexAccountDecodedEvent | undefined>; decodeTransaction(args: DecodeTransactionParams<typeof DexAccountAbi>): Promise<DexAccountDecodedTransaction | undefined>; decodeTransactionEvents(transaction: Transaction): Promise<DexAccountDecodedEvent[]>; } export {};