UNPKG

@atomiqlabs/chain-starknet

Version:
161 lines (160 loc) 6.89 kB
import { StarknetModule } from "../StarknetModule"; import { Call, DeployAccountContractPayload, DeployAccountContractTransaction, Invocation, InvocationsSignerDetails, BigNumberish, BlockTag } from "starknet"; import { StarknetSigner } from "../../wallet/StarknetSigner"; export type StarknetTxBase = { details: InvocationsSignerDetails & { maxFee?: BigNumberish; }; txId?: string; }; /** * "INVOKE" type of transaction, used to call smart contracts on Starknet * * @category Chain Interface */ export type StarknetTxInvoke = StarknetTxBase & { type: "INVOKE"; tx: Array<Call>; signed?: Invocation; }; /** * Type-guard for the "INVOKE" type of transaction, used to call smart contracts on Starknet * * @category Chain Interface */ export declare function isStarknetTxInvoke(obj: any): obj is StarknetTxInvoke; /** * "DEPLOY_ACCOUNT" type of transaction, used as a first transaction that the account does to deploy its smart * account contract on the Starknet * * @category Chain Interface */ export type StarknetTxDeployAccount = StarknetTxBase & { type: "DEPLOY_ACCOUNT"; tx: DeployAccountContractPayload; signed?: DeployAccountContractTransaction; }; /** * Type-guard for the "DEPLOY_ACCOUNT" type of transaction, used as a first transaction that the account does * to deploy its smart account contract on the Starknet * * @category Chain Interface */ export declare function isStarknetTxDeployAccount(obj: any): obj is StarknetTxDeployAccount; /** * Represents a Starknet transactions, which can either be an "INVOKE" or "DEPLOY_ACCOUNT" type, use the * {@link isStarknetTxInvoke} & {@link isStarknetTxDeployAccount} to narrow down the type. * * @category Chain Interface */ export type StarknetTx = StarknetTxInvoke | StarknetTxDeployAccount; /** * Represents a signed Starknet transactions, which can either be an "INVOKE" or "DEPLOY_ACCOUNT" type, use the * {@link isStarknetTxInvoke} & {@link isStarknetTxDeployAccount} to narrow down the type. * * @remarks For Starknet this is just an alias for {@link StarknetTx} * * @category Chain Interface */ export type SignedStarknetTx = StarknetTx; export type StarknetTraceCall = { calldata: string[]; contract_address: string; entry_point_selector: string; calls: StarknetTraceCall[]; }; export declare class StarknetTransactions extends StarknetModule { private readonly latestConfirmedNonces; private readonly latestPendingNonces; private readonly latestSignedNonces; readonly _cbksBeforeTxReplace: ((oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>)[]; private readonly cbksBeforeTxSigned; readonly _knownTxSet: Set<string>; sendTransaction(tx: StarknetTx): Promise<string>; /** * Returns the nonce of the account or 0, if the account is not deployed yet * * @param address * @param blockTag */ getNonce(address: string, blockTag?: BlockTag): Promise<bigint>; private confirmTransactionWs; private confirmTransactionPolling; /** * Waits for transaction confirmation using WS subscription and occasional HTTP polling, also re-sends * the transaction at regular interval * * @param tx starknet transaction to wait for confirmation for & keep re-sending until it confirms * @param abortSignal signal to abort waiting for tx confirmation * @private */ private confirmTransaction; /** * Prepares starknet transactions, checks if the account is deployed, assigns nonces if needed * & calls beforeTxSigned callback (only if signer is passed!) * * @param signer * @param txs */ prepareTransactions(txs: (StarknetTx & { addedInPrepare?: boolean; })[], signer?: StarknetSigner): Promise<void>; /** * Sends out a signed transaction to the RPC * * @param tx Starknet tx to send * @param onBeforePublish a callback called before every transaction is published * @private */ private sendSignedTransaction; /** * Prepares, signs , sends (in parallel or sequentially) & optionally waits for confirmation * of a batch of starknet transactions * * @param signer * @param _txs transactions to send * @param waitForConfirmation whether to wait for transaction confirmations (this also makes sure the transactions * are re-sent at regular intervals) * @param abortSignal abort signal to abort waiting for transaction confirmations * @param parallel whether the send all the transaction at once in parallel or sequentially (such that transactions * are executed in order) * @param onBeforePublish a callback called before every transaction is published */ sendAndConfirm(signer: StarknetSigner, _txs: StarknetTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>; sendSignedAndConfirm(signedTxs: SignedStarknetTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>; /** * Serializes the starknet transaction, saves the transaction, signers & last valid blockheight * * @param tx */ static serializeTx(tx: StarknetTx): string; /** * Deserializes saved starknet transaction, extracting the transaction, signers & last valid blockheight * * @param txData */ static deserializeTx(txData: string): StarknetTx; /** * Gets the status of the raw starknet transaction * * @param tx */ getTxStatus(tx: string): Promise<"pending" | "success" | "not_found" | "reverted">; /** * Gets the status of the starknet transaction with a specific txId * * @param txId */ _getTxIdStatus(txId: string): Promise<"pending" | "success" | "not_found" | "reverted" | "rejected">; /** * Gets the status of the starknet transaction with a specific txId * * @param txId */ getTxIdStatus(txId: string): Promise<"pending" | "success" | "not_found" | "reverted">; traceTransaction(txId: string, blockHash?: string): Promise<StarknetTraceCall | null>; onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void; offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean; onBeforeTxSigned(callback: (tx: StarknetTx) => Promise<void>): void; offBeforeTxSigned(callback: (tx: StarknetTx) => Promise<void>): boolean; }