UNPKG

@azuro-org/sdk

Version:

One-stop solution for building betting dApps on the Azuro Protocol.

92 lines (91 loc) 3.17 kB
import { BetOrderState, type ChainId, type CreateBetResult, type Freebet, type Selection } from '@azuro-org/toolkit'; import { type Address, type Hex, type TransactionReceipt } from 'viem'; export declare class BetOrderError extends Error { orderId: string; orderState: BetOrderState; errorCode: string | undefined | null; constructor(errorMessage: string, args: { cause?: Error; orderState: BetOrderState; orderId: string; errorCode?: string | null; }); } export type UseBetProps = { betAmount: string; slippage: number; affiliate: Address; selections: Selection[]; odds: Record<string, number>; totalOdds: number; chainId?: ChainId; freebet?: Pick<Freebet, 'id' | 'params'>; EIP712Attention?: string; deadline?: number; onBetOrderCreated?(order: CreateBetResult): void; onSuccess?(receipt?: TransactionReceipt): void; onError?(err?: Error): void; }; /** * Place a bet on outcomes (single or combo bet). * Handles token approval, EIP-712 signature, and transaction submission through the Azuro relayer. * * Supports both regular wallets and Account Abstraction (AA) wallets. * For AA wallets, approval is handled automatically within the bet transaction. * * - Docs: https://gem.azuro.org/hub/apps/sdk/write/useBet * * @example * import { useBet } from '@azuro-org/sdk' * * const { submit, approveTx, betTx, isApproveRequired } = useBet({ * betAmount: '10', * slippage: 5, * affiliate: '0x...', * selections: [{ conditionId: '123', outcomeId: '1' }], * odds: { '123-1': 1.5 }, * totalOdds: 1.5, * onBetOrderCreated: (order) => console.log('Bet order created!', order), * onSuccess: (receipt) => console.log('Bet placed to blockchain!', receipt), * }) * */ export declare const useBet: (props: UseBetProps) => { submit: () => Promise<void>; isWalletReadyToSubmit: boolean; approveTx: { isPending: boolean; isProcessing: boolean; }; betTx: { data: `0x${string}` | undefined; orderId: string | undefined; receipt: { blobGasPrice?: bigint | undefined; blobGasUsed?: bigint | undefined; blockHash: import("viem").Hash; blockNumber: bigint; blockTimestamp?: bigint | undefined; contractAddress: Address | null | undefined; cumulativeGasUsed: bigint; effectiveGasPrice: bigint; from: Address; gasUsed: bigint; logs: import("viem").Log<bigint, number, false>[]; logsBloom: Hex; root?: `0x${string}` | undefined; status: "success" | "reverted"; to: Address | null; transactionHash: import("viem").Hash; transactionIndex: number; type: import("viem").TransactionType; chainId: number; } | undefined; isPending: boolean; isSubmittingOrder: boolean; isProcessing: boolean; }; relayerFeeAmount: string | undefined; isAllowanceLoading: boolean; isApproveRequired: boolean; isRelayerFeeLoading: boolean; };