import type { Call } from "starknet"; import type { WalletInterface } from "../wallet/interface.js"; import type { Tx } from "../tx/index.js"; import type { SwapInput } from "../swap/index.js"; import type { DcaCancelInput, DcaCreateInput } from "../dca/index.js"; import type { LendingBorrowRequest, LendingDepositRequest, LendingWithdrawMaxRequest, LendingRepayRequest, LendingWithdrawRequest } from "../lending/index.js"; import type { TrovesDepositParams, TrovesWithdrawParams } from "../troves/index.js"; import type { Address, Amount, ExecuteOptions, PreflightResult, Token } from "../types/index.js"; import type { ConfidentialProvider, ConfidentialFundDetails, ConfidentialTransferDetails, ConfidentialWithdrawDetails } from "../confidential/index.js"; /** * Fluent transaction builder for batching multiple operations into a single transaction. * * Instead of executing each operation separately, `TxBuilder` collects contract calls * and submits them all at once via `wallet.execute()`. This saves gas and ensures * atomicity — either every operation succeeds or none of them do. * * Create a builder via `wallet.tx()`, chain operations, then call `.send()`. * * @example * ```ts * // Approve + stake in one transaction * const tx = await wallet.tx() * .enterPool(poolAddress, Amount.parse("100", STRK)) * .send(); * await tx.wait(); * ``` * * @example * ```ts * // Transfer multiple tokens + claim rewards atomically * const tx = await wallet.tx() * .transfer(USDC, [ * { to: alice, amount: Amount.parse("50", USDC) }, * { to: bob, amount: Amount.parse("25", USDC) }, * ]) * .claimPoolRewards(poolAddress) * .send(); * ``` * * @example * ```ts * // Mix high-level helpers with raw calls * const tx = await wallet.tx() * .approve(STRK, dexAddress, amount) * .add({ contractAddress: dexAddress, entrypoint: "swap", calldata: [...] }) * .transfer(USDC, { to: alice, amount: usdcAmount }) * .send(); * ``` */ export declare class TxBuilder { private readonly wallet; private readonly pending; private readonly pendingErrors; private sent; private sendPromise; constructor(wallet: WalletInterface); private queueAsyncCalls; private queuePreparedCalls; private throwPendingErrorsIfAny; /** * The number of pending operations in the builder. * * Each chained method counts as one operation, even if it expands * into multiple calls once resolved. */ get length(): number; /** * Whether the builder has no pending operations. */ get isEmpty(): boolean; /** * Whether `send()` has already been called successfully on this builder. */ get isSent(): boolean; /** * Add one or more raw contract calls to the transaction. * * Use this for custom contract interactions not covered by the * built-in helpers. * * @param calls - Raw Call objects to include * @returns this (for chaining) * * @example * ```ts * wallet.tx() * .add({ * contractAddress: "0x...", * entrypoint: "my_function", * calldata: [1, 2, 3], * }) * .send(); * ``` */ add(...calls: Call[]): this; /** * Approve an address to spend ERC20 tokens on behalf of the wallet. * * @param token - The ERC20 token to approve * @param spender - The address to approve spending for * @param amount - The amount to approve * @returns this (for chaining) * * @example * ```ts * wallet.tx() * .approve(USDC, dexAddress, Amount.parse("1000", USDC)) * .add(dexSwapCall) * .send(); * ``` */ approve(token: Token, spender: Address, amount: Amount): this; /** * Transfer ERC20 tokens to one or more recipients. * * Accepts a single transfer object or an array of transfers. * Multiple transfers to the same token are batched efficiently. * * @param token - The ERC20 token to transfer * @param transfers - A single transfer or array of transfers * @returns this (for chaining) * * @example * ```ts * // Single transfer * wallet.tx() * .transfer(USDC, { to: alice, amount: Amount.parse("50", USDC) }) * .send(); * * // Multiple transfers * wallet.tx() * .transfer(USDC, [ * { to: alice, amount: Amount.parse("50", USDC) }, * { to: bob, amount: Amount.parse("25", USDC) }, * ]) * .send(); * ``` */ transfer(token: Token, transfers: { to: Address; amount: Amount; } | { to: Address; amount: Amount; }[]): this; /** * Add a provider-driven swap operation. * * Validates the request synchronously before delegating to * `wallet.prepareSwap(...)` so invalid providers/chains fail fast and the * builder only mutates when a swap can actually be prepared. */ swap(request: SwapInput): this; /** * Add a lending deposit operation. */ lendDeposit(request: LendingDepositRequest): this; /** * Add a lending withdraw operation. */ lendWithdraw(request: LendingWithdrawRequest): this; /** * Add a max-withdraw lending operation. */ lendWithdrawMax(request: LendingWithdrawMaxRequest): this; /** * Add a lending borrow operation. */ lendBorrow(request: LendingBorrowRequest): this; /** * Add a lending repay operation. */ lendRepay(request: LendingRepayRequest): this; /** * Add a DCA order creation operation. */ dcaCreate(request: DcaCreateInput): this; /** * Add a DCA cancellation operation. */ dcaCancel(request: DcaCancelInput): this; /** * Add a Troves strategy deposit operation. */ trovesDeposit(params: TrovesDepositParams): this; /** * Add a Troves strategy withdraw operation. */ trovesWithdraw(params: TrovesWithdrawParams): this; /** * Stake tokens in a delegation pool, automatically choosing the right * action based on current membership status. * * - If the wallet is **not** a member, calls `enter_delegation_pool`. * - If the wallet **is** already a member, calls `add_to_delegation_pool`. * * In both cases the token approve call is included automatically. * * This is the **recommended** way to stake via the builder. Prefer this * over {@link enterPool} and {@link addToPool} unless you need explicit * control over which entrypoint is called. * * @param poolAddress - The pool contract address * @param amount - The amount of tokens to stake * @returns this (for chaining) * * @example * ```ts * // Works whether the wallet is a new or existing member * const tx = await wallet.tx() * .stake(poolAddress, Amount.parse("100", STRK)) * .send(); * await tx.wait(); * ``` */ stake(poolAddress: Address, amount: Amount): this; /** * Enter a delegation pool as a new member. * * Automatically includes the token approve call before the pool entry call. * * **Prefer {@link stake}** which auto-detects membership. Only use this if * you are certain the wallet is not already a member — the transaction will * revert on-chain otherwise. * * @param poolAddress - The pool contract address to enter * @param amount - The amount of tokens to stake * @returns this (for chaining) * * @example * ```ts * wallet.tx() * .enterPool(poolAddress, Amount.parse("100", STRK)) * .send(); * ``` */ enterPool(poolAddress: Address, amount: Amount): this; /** * Add more tokens to an existing stake in a pool. * * Automatically includes the token approve call before the add-to-pool call. * * **Prefer {@link stake}** which auto-detects membership. Only use this if * you are certain the wallet is already a member — the transaction will * revert on-chain otherwise. * * @param poolAddress - The pool contract address * @param amount - The amount of tokens to add * @returns this (for chaining) * * @example * ```ts * wallet.tx() * .addToPool(poolAddress, Amount.parse("50", STRK)) * .send(); * ``` */ addToPool(poolAddress: Address, amount: Amount): this; /** * Claim accumulated staking rewards from a pool. * * **Note:** Unlike `wallet.claimPoolRewards()`, this does not verify * membership. The transaction will revert on-chain if the wallet is not * a member of the pool. * * @param poolAddress - The pool contract address * @returns this (for chaining) * * @example * ```ts * wallet.tx() * .claimPoolRewards(poolAddress) * .send(); * ``` */ claimPoolRewards(poolAddress: Address): this; /** * Initiate an exit from a delegation pool. * * After this, wait for the exit window to pass, then call {@link exitPool} * to complete the withdrawal. * * **Note:** Unlike `wallet.exitPoolIntent()`, this does not verify * membership or balance. The transaction will revert on-chain if the * wallet is not a member or has insufficient stake. * * @param poolAddress - The pool contract address * @param amount - The amount to unstake * @returns this (for chaining) * * @example * ```ts * wallet.tx() * .exitPoolIntent(poolAddress, Amount.parse("50", STRK)) * .send(); * ``` */ exitPoolIntent(poolAddress: Address, amount: Amount): this; /** * Complete the exit from a delegation pool after the exit window has passed. * * **Note:** Unlike `wallet.exitPool()`, this does not verify that an exit * intent exists. The transaction will revert on-chain if no prior * {@link exitPoolIntent} was submitted or the exit window has not elapsed. * * @param poolAddress - The pool contract address * @returns this (for chaining) * * @example * ```ts * wallet.tx() * .exitPool(poolAddress) * .send(); * ``` */ exitPool(poolAddress: Address): this; /** * Fund a confidential account. * * The provider returns all necessary calls (including ERC20 approve * when required), so no manual approve step is needed. * * @param confidential - A {@link ConfidentialProvider} instance * @param details - Fund parameters (amount, sender) * @returns this (for chaining) * * @example * ```ts * wallet.tx() * .confidentialFund(confidential, { amount: Amount.fromRaw(100n, token), sender: wallet.address }) * .send(); * ``` */ confidentialFund(confidential: ConfidentialProvider, details: ConfidentialFundDetails): this; /** * Transfer between confidential accounts. * * Generates ZK proofs for the confidential transfer. * * @param confidential - A {@link ConfidentialProvider} instance * @param details - Transfer parameters (amount, recipient pubkey, sender) * @returns this (for chaining) * * @example * ```ts * wallet.tx() * .confidentialTransfer(confidential, { * amount: Amount.fromRaw(50n, token), * to: recipientPubKey, * sender: wallet.address, * }) * .send(); * ``` */ confidentialTransfer(confidential: ConfidentialProvider, details: ConfidentialTransferDetails): this; /** * Withdraw from a confidential account to a public address. * * @param confidential - A {@link ConfidentialProvider} instance * @param details - Withdraw parameters (amount, recipient, sender) * @returns this (for chaining) * * @example * ```ts * wallet.tx() * .confidentialWithdraw(confidential, { * amount: Amount.fromRaw(50n, token), * to: wallet.address, * sender: wallet.address, * }) * .send(); * ``` */ confidentialWithdraw(confidential: ConfidentialProvider, details: ConfidentialWithdrawDetails): this; /** * Resolve all pending operations into a flat array of Calls without executing. * * Useful for inspection, preflight simulation, or fee estimation. * * @returns A flat array of all collected Call objects * * @example * ```ts * const calls = await wallet.tx() * .transfer(USDC, { to: alice, amount }) * .enterPool(poolAddress, stakeAmount) * .calls(); * * const fee = await wallet.estimateFee(calls); * ``` */ calls(): Promise; /** * Estimate the fee for all collected calls. * * Resolves any pending async operations and estimates the execution fee. * * @returns Fee estimation including overall fee, gas price, and gas bounds * * @example * ```ts * const fee = await wallet.tx() * .transfer(USDC, { to: alice, amount }) * .stake(poolAddress, stakeAmount) * .estimateFee(); * * console.log("Estimated fee:", fee.overall_fee); * ``` */ estimateFee(): Promise; /** * Simulate the transaction to check if it would succeed. * * Resolves all pending operations and runs them through the wallet's * preflight simulation without submitting on-chain. Use this to * validate the transaction before calling {@link send}. * * @returns `{ ok: true }` if the simulation succeeds, or * `{ ok: false, reason: string }` with a human-readable error * * @example * ```ts * const builder = wallet.tx() * .stake(poolAddress, amount) * .transfer(USDC, { to: alice, amount: usdcAmount }); * * const result = await builder.preflight(); * if (!result.ok) { * console.error("Transaction would fail:", result.reason); * } else { * await builder.send(); * } * ``` */ preflight(): Promise; /** * Execute all collected calls as a single atomic transaction. * * Resolves any pending async operations (e.g., staking pool lookups), * flattens all calls, and submits them via `wallet.execute()`. * * Can only be called once per builder instance. * * @param options - Optional execution options (e.g., fee mode, gas settings) * @returns A Tx object to track the transaction * @throws Error if no calls have been added or if already sent * * @example * ```ts * const tx = await wallet.tx() * .approve(STRK, poolAddress, stakeAmount) * .enterPool(poolAddress, stakeAmount) * .transfer(USDC, { to: alice, amount: usdcAmount }) * .send(); * * console.log(tx.explorerUrl); * await tx.wait(); * ``` */ send(options?: ExecuteOptions): Promise; } //# sourceMappingURL=builder.d.ts.map