@funkit/connect
Version:
Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.
67 lines (66 loc) • 3.93 kB
TypeScript
import type { ApiFunkitCheckoutQuoteResult, CheckoutQuoteResponse } from '@funkit/utils';
import type { Dnum } from 'dnum';
import { type Address } from 'viem';
import type { Config } from '../wagmi/hooks';
import type { BluvoBrokerageQuote } from '../hooks/useBluvo';
import type { FunkitDirectExecutionInfo } from '../hooks/useCheckoutDirectExecution';
import type { FunkitActiveCheckoutItem } from '../providers/FunkitCheckoutContext';
import type { LoginType } from '../providers/GeneralWalletProvider';
import { type BrokerageDetails, type CheckoutFees } from './fees';
import { type PaymentMethodInfo } from './paymentMethods';
import type { QuoteBuilder } from './quoteMode';
export interface FunkitCheckoutQuoteResult extends Omit<ApiFunkitCheckoutQuoteResult, 'finalFeesBreakdown'> {
finalSpreadUsd: string;
finalFeesBreakdown: CheckoutFees;
}
export declare function getCheckoutBaseQuote(checkoutItem: FunkitActiveCheckoutItem, userId: string, walletAddress: Address, apiKey: string, wagmiConfig: Config, directExecutionInfo: FunkitDirectExecutionInfo, senderAddress?: Address, isWithdrawal?: boolean, quoteBuilder?: QuoteBuilder,
/**
* User-driven preference for the source-side authorization step. Forwarded
* to the direct-execution branch (`getDirectExecutionQuote` →
* `getCheckoutQuoteV2`) where Relay's `usePermit` flag actually flows. The
* legacy `getApiCheckoutQuote` branch ignores this. On the Aave native
* fast path it drives `shouldUsePermitForSupply` instead of flowing here.
*/
usePermit?: boolean): Promise<CheckoutQuoteResponse>;
/**
* In EXACT_IN/ONE_TO_ONE mode, the user's input is the source (from) amount.
* When a canonical bigint is available, use formatUnits to produce the precise
* human-readable string, avoiding precision loss from bigint->Number->string.
*/
export declare function resolveFromTokenAmount(checkoutItem: FunkitActiveCheckoutItem, isExactInViaBuilder: boolean, userInputAmount: number, fromTokenDecimals: number): string;
/**
* Derives estSubtotalToAmount from metadata.toAmountBaseUnit for EXACT_IN quotes.
* Returns null when derivation isn't needed or isn't possible.
**/
export declare function deriveEstSubtotalToAmountIfNeeded(baseQuote: CheckoutQuoteResponse, isExactIn: boolean, toTokenDecimals: number): string | null;
export declare function getQuoteFinalEstimation(baseQuote: CheckoutQuoteResponse, checkoutItem: FunkitActiveCheckoutItem, newPaymentMethodInfo: PaymentMethodInfo, wagmiConfig: Config, apiKey: string, loginType: LoginType, isWithdrawal?: boolean, brokerageQuote?: BluvoBrokerageQuote): Promise<{
finalEstimation: FunkitCheckoutQuoteResult;
brokerage?: BrokerageDetails;
}>;
export interface CheckedAssetAmount {
isAboveMaximum: boolean;
isBelowMinimum: boolean;
maxTargetAssetAmount?: Dnum;
minTargetAssetAmount?: Dnum;
}
export declare function checkAssetAmount(checkoutItem: FunkitActiveCheckoutItem, finalEstimation: FunkitCheckoutQuoteResult, wagmiConfig: Config, walletAddress: Address, brokerage?: BrokerageDetails): Promise<CheckedAssetAmount>;
export interface CheckoutQuoteParams {
checkoutItem: FunkitActiveCheckoutItem;
userId: string;
walletAddress: Address;
apiKey: string;
newPaymentMethodInfo: PaymentMethodInfo;
wagmiConfig: Config;
loginType: LoginType;
directExecutionInfo: FunkitDirectExecutionInfo;
/** when sender address is different from wallet address
* this happens when withdrawing from a different wallet
**/
senderAddress?: Address;
isWithdrawal?: boolean;
}
export declare function getQuoteAndEstimation({ checkoutItem, userId, walletAddress, apiKey, newPaymentMethodInfo, wagmiConfig, loginType, directExecutionInfo, senderAddress, isWithdrawal, }: CheckoutQuoteParams): Promise<{
baseQuote: CheckoutQuoteResponse;
checkedAssetAmount: CheckedAssetAmount;
finalEstimation: FunkitCheckoutQuoteResult;
}>;