UNPKG

@funkit/connect

Version:

Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.

100 lines (99 loc) 5.11 kB
/** * Native-supply fast-path: same-token same-chain deposits go straight to the * Aave Pool, bypassing Relay. Toggle visibility is gated centrally in * `FunkitQuoteContext` (`showApprovalMethodToggle`), not here. */ import { type ERC712Signature, type SupplyRequest } from '@aave/client'; import type { ApiFunkitCheckoutConfig } from '@funkit/utils'; import type { Dnum } from 'dnum'; import { type Address, type Hex, type WalletClient } from 'viem'; import { type CheckoutConfirmationError } from '../../../domains/checkoutErrors'; import type { FunkitActiveCheckoutItem, FunkitCheckoutConfig } from '../../../providers/FunkitCheckoutContext'; import { type Config } from '../../../wagmi/hooks'; /** * Stringify an amount for Aave's `bigDecimal()`. Prefers the precise * base-unit Dnum (carries the token's real decimals) so we don't ship * float noise like "0.30000000000000004" to the API. Falls back to the * raw JS-number string when the Dnum isn't populated (EXACT_OUT path). */ export declare function formatSupplyAmount(tokenAmountBaseUnit: Dnum | null, fallbackAssetAmount: number | undefined): string; /** * Base-unit string for the DE record's `fromAmountBaseUnit` / * `toAmountBaseUnit`. Dnum present → `[0]` exact. Dnum null * (EXACT_OUT) → derive from `assetAmount` + `decimals`. Neither → * `'0'` + warn (would corrupt volume metrics). */ export declare function getSupplyAmountBaseUnit(tokenAmountBaseUnit: Dnum | null, fallbackAssetAmount: number | undefined, decimals: number | null): string; /** * Serializable checkout config persisted on the Aave native DE record. * Overrides the init-time `targetAssetAmount` (undefined on this path — * no Relay quote populates it) with the fresh input amount so the success * screen's "You receive" doesn't read 0, and drops the non-serializable * `generateActionsParams`. */ export declare function buildAaveNativeSupplyConfig(config: FunkitCheckoutConfig, assetAmount: number): ApiFunkitCheckoutConfig; /** Upper bound on waiting for the USDT zero-reset to mine before giving up. */ export declare const USDT_RESET_RECEIPT_TIMEOUT_MS = 90000; /** * USDT's `approve` reverts on a non-zero → non-zero change — zeroing first * lets the SDK's approve(amount) succeed. Same quirk handled by the * VaultDepositor path (`createAaveSupplyActions`). */ export declare function resetUsdtAllowanceIfNeeded(wagmiConfig: Config, walletClient: WalletClient, { owner, market, currency, targetChainNum, }: { owner: Address; market: Address; currency: Address; targetChainNum: number; }): Promise<void>; /** * `undefined` user preference (toggle not surfaced) defaults to * permit-when-capable — preserves the auto behavior that pre-dated the toggle. * An explicit `false` always wins. When `allowanceCoversAmount`, no permit is * needed at all (the SDK will return a plain TransactionRequest) — skipping * the signature saves the user one popup, matching aave/interface. */ export declare function shouldUsePermitForSupply(userPreference: boolean | undefined, reservePermitSupported: boolean | undefined, allowanceCoversAmount: boolean): boolean; /** * `permitSig` presence is what drives the SDK to build a single * `supplyWithPermit` tx vs an `ApprovalRequired` plan (approve + supply). */ export declare function buildAaveSupplyRequest({ targetChainNum, market, currency, humanAmount, walletAddress, permitSig, }: { targetChainNum: number; market: Address; currency: Address; humanAmount: string; walletAddress: Address; permitSig?: ERC712Signature; }): SupplyRequest; /** Amount inputs passed from the call site (not read from * `checkoutItem`, to avoid closure staleness after `flushSync`). */ export interface AaveNativeSupplyAmount { /** `null` in EXACT_OUT mode; see `state.ts:373`. */ tokenAmountBaseUnit: Dnum | null; /** Call site guards `assetAmount === undefined` upstream. */ assetAmount: number; decimals: number | null; /** USD the user saw at input. `null` → `0` at the API boundary. */ usdAmount: number | null; } /** * Pre-fetches the on-chain ERC-20 allowance from the user to the Aave Pool, so * `showApprovalMethodToggle` can hide the toggle when an existing approval * already covers the supply amount (matches aave/interface's behavior — a * supply that needs no approval/permit is a single tx, no toggle). */ export declare function useAaveTargetPoolAllowance(checkoutItem: FunkitActiveCheckoutItem | null, owner: Address | undefined): bigint | undefined; /** * Pre-fetches reserve permit capability so the InputAmount toggle's * visibility is decidable synchronously when the user lands there. */ export declare function useAaveTargetReservePermit(checkoutItem: FunkitActiveCheckoutItem | null): boolean | undefined; interface UseAaveNativeSupplyResult { submit: (amount: AaveNativeSupplyAmount) => Promise<{ txHash: Hex; } | null>; isPending: boolean; error: CheckoutConfirmationError | null; } export declare function useAaveNativeSupply(): UseAaveNativeSupplyResult; export {};