@chorus-one/ton
Version:
All-in-one tooling for building staking dApps on TON
177 lines (176 loc) • 7.11 kB
TypeScript
import type { Signer } from '@chorus-one/signer';
import type { TonNetworkConfig, AddressDerivationConfig, UnsignedTx, SignedTx, TonTxStatus, PoolData } from './types';
import { Transaction } from '@ton/ton';
import { TonClient } from './TonClient';
/**
* This class provides the functionality to stake assets on the Ton network.
*
* It also provides the ability to retrieve staking information and rewards for a delegator.
*/
export declare class TonBaseStaker {
/** @ignore */
protected readonly networkConfig: Required<TonNetworkConfig>;
/** @ignore */
protected readonly addressDerivationConfig: AddressDerivationConfig;
/** @ignore */
protected client?: TonClient;
/**
* This **static** method is used to derive an address from a public key.
*
* It can be used for signer initialization, e.g. `FireblocksSigner` or `LocalSigner`.
*
* @param params - Parameters for the address derivation
* @param params.addressDerivationConfig - TON address derivation configuration
*
* @returns Returns a single address derived from the public key
*/
static getAddressDerivationFn: (params?: {
addressDerivationConfig: AddressDerivationConfig | undefined;
}) => (publicKey: Uint8Array, _derivationPath: string) => Promise<Array<string>>;
/**
* This **static** method is used to convert BIP39 mnemonic to seed. In TON
* network the seed is used as a private key.
*
* It can be used for signer initialization, e.g. `FireblocksSigner` or `LocalSigner`.
*
* @param params.addressDerivationConfig - TON address derivation configuration
*
* @returns Returns a seed derived from the mnemonic
*/
static getMnemonicToSeedFn: (params?: {
addressDerivationConfig: AddressDerivationConfig | undefined;
}) => (mnemonic: string, password?: string) => Promise<Uint8Array>;
/**
* This **static** method is used to convert a seed to a keypair. Note that
* TON network doesn't use BIP44 HD Path for address derivation.
*
* It can be used for signer initialization, e.g. `FireblocksSigner` or `LocalSigner`.
*
* @param params.addressDerivationConfig - TON address derivation configuration
*
* @returns Returns a public and private keypair derived from the seed
*/
static getSeedToKeypairFn: (params?: {
addressDerivationConfig: AddressDerivationConfig | undefined;
}) => (seed: Uint8Array, hdPath?: string) => Promise<{
publicKey: Uint8Array;
privateKey: Uint8Array;
}>;
/**
* This creates a new TonStaker instance.
*
* @param params - Initialization parameters
* @param params.rpcUrl - RPC URL (e.g. https://toncenter.com/api/v2/jsonRPC)
* @param params.allowSeamlessWalletDeployment - (Optional) If enabled, the wallet contract is deployed automatically when needed
* @param params.allowTransferToInactiveAccount - (Optional) Allow token transfers to inactive accounts
* @param params.minimumExistentialBalance - (Optional) The amount of TON to keep in the wallet
* @param params.addressDerivationConfig - (Optional) TON address derivation configuration
*
* @returns An instance of TonStaker.
*/
constructor(params: {
rpcUrl: string;
allowSeamlessWalletDeployment?: boolean;
allowTransferToInactiveAccount?: boolean;
minimumExistentialBalance?: string;
addressDerivationConfig?: AddressDerivationConfig;
});
/**
* Initializes the TonStaker instance and connects to the blockchain.
*
* @returns A promise which resolves once the TonStaker instance has been initialized.
*/
init(): Promise<void>;
/** @ignore */
buildTransferTx(params: {
destinationAddress: string;
amount: string;
validUntil?: number;
memo?: string;
}): Promise<{
tx: UnsignedTx;
}>;
/**
* Builds a wallet deployment transaction
*
* @param params - Parameters for building the transaction
* @param params.address - The address to deploy the wallet contract to
* @param params.validUntil - (Optional) The Unix timestamp when the transaction expires
*
* @returns Returns a promise that resolves to a TON wallet deployment transaction.
*/
buildDeployWalletTx(params: {
address: string;
validUntil?: number;
}): Promise<{
tx: UnsignedTx;
}>;
/** @ignore */
getBalance(params: {
address: string;
}): Promise<{
amount: string;
}>;
/**
* Signs a transaction using the provided signer.
*
* @param params - Parameters for the signing process
* @param params.signer - Signer instance
* @param params.signerAddress - The address of the signer
* @param params.tx - The transaction to sign
*
* @returns A promise that resolves to an object containing the signed transaction.
*/
sign(params: {
signer: Signer;
signerAddress: string;
tx: UnsignedTx;
}): Promise<SignedTx>;
/**
* This method is used to broadcast a signed transaction to the TON network.
*
* @param params - Parameters for the broadcast
* @param params.signedTx - The signed transaction to be broadcasted
*
* @returns Returns a promise that resolves to the response of the transaction that was broadcast to the network.
*/
broadcast(params: {
signedTx: SignedTx;
}): Promise<string>;
/**
* Retrieves the status of a transaction using the transaction hash.
*
* This method is intended to check for transactions made recently (within limit) and not for historical transactions.
*
* @param params - Parameters for the transaction status request
* @param params.address - The account address to query
* @param params.txHash - The transaction hash to query
* @param params.limit - (Optional) The maximum number of transactions to fetch
*
* @returns A promise that resolves to an object containing the transaction status.
*/
getTxStatus(params: {
address: string;
txHash: string;
limit?: number;
}): Promise<TonTxStatus>;
/** @ignore */
protected matchTransactionStatus(transaction: Transaction | undefined): TonTxStatus;
/** @ignore */
protected getTransactionByHash(params: {
address: string;
txHash: string;
limit?: number;
}): Promise<Transaction | undefined>;
/** @ignore */
protected getClient(): TonClient;
/** @ignore */
protected checkIfAddressTestnetFlagMatches(address: string): void;
/** @ignore */
protected checkMinimumExistentialBalance(address: string, amount: string): Promise<void>;
/** @ignore */
protected getNominatorContractPoolData(contractAddress: string): Promise<PoolData>;
}
export declare function defaultValidUntil(validUntil?: number): number;
export declare function getRandomQueryId(): number;
export declare function getDefaultGas(): number;