@funkit/connect
Version:
Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.
67 lines (66 loc) • 3.03 kB
TypeScript
/**
* Nado direct-transfer fast-path: a same-token same-chain deposit is a single
* ERC-20 transfer to the subaccount DDA (`customRecipient`), bypassing
* Relay/quoteV2 (which can't price a QQQx → QQQx "route"). Signs the transfer
* and records a direct execution for history parity. Mirrors `useAaveNativeSupply`.
*/
import type { Dnum } from 'dnum';
import { type Hex } from 'viem';
import { type CheckoutConfirmationError } from '../../../domains/checkoutErrors';
import type { FunkitCheckoutConfig } from '../../../providers/FunkitCheckoutContext';
/**
* Base-unit string for the transfer + DE record. Dnum present → exact;
* otherwise derive from `assetAmount` + `decimals`. Neither → `'0'` + warn.
*/
export declare function getTransferAmountBaseUnit(tokenAmountBaseUnit: Dnum | null, fallbackAssetAmount: number | undefined, decimals: number | null): bigint;
interface UseNadoDirectTransferResult {
/** Reads the committed amount/source from `checkoutItem` and executes. */
submit: () => Promise<{
txHash: Hex;
} | null>;
isPending: boolean;
error: CheckoutConfirmationError | null;
/**
* Whether this checkout takes the direct-transfer fast-path — see
* `isNadoDirectTransferContext`. False until a source is selected and, for a
* wrapper source, until the wrapper address resolves.
*/
isApplicable: boolean;
}
interface NadoDirectTransferContextArgs {
apiKey: string;
sourceAsset: {
chainId: string | number;
address: string;
};
checkoutConfig: Pick<FunkitCheckoutConfig, 'targetChain' | 'targetAsset' | 'customRecipient'>;
/**
* Whether the target is an xStock asset (`assetClass === 'xstock'`). Gates the
* fast-path to xStocks so a same-token route like USDT → USDT keeps using Relay.
*/
isXstockTarget: boolean;
/**
* Target token's wrapped version (xStocks `wrapperAddressV2`) on the target
* chain — a held balance (e.g. wSPYx for SPYx) is an equivalent source. From
* `useXstocksWrappedTokenAddress`; omit when there's none.
*/
wrappedTokenAddress?: string;
}
/**
* True when the customer is Nado, the target is an xStock, the checkout has an
* explicit recipient (the subaccount DDA), and the source matches the target
* token or its wrapper (same chain) — a direct ERC-20 transfer, not a Relay swap.
*
* - Customer-gated (not config-driven) to bound blast radius to Nado.
* - xStocks-gated so a same-token route (USDT → USDT) keeps using Relay.
*/
export declare function isNadoDirectTransferContext({ apiKey, sourceAsset, checkoutConfig, isXstockTarget, wrappedTokenAddress, }: NadoDirectTransferContextArgs): boolean;
/**
* Predicate over a source asset: does it qualify for the Nado direct-transfer fast-path?
*/
export declare function useIsNadoDirectTransferSource(): (source: {
chainId: string | number;
address: string;
}) => boolean;
export declare function useNadoDirectTransfer(): UseNadoDirectTransferResult;
export {};