@funkit/connect
Version:
Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.
121 lines (120 loc) • 6.05 kB
TypeScript
import type { FunAddress } from '@funkit/api-base';
export { isCheckoutHistoryDirectExecution, isCheckoutValid, type MergedCheckoutHistoryItem, toMergedCheckoutHistoryItem, } from '@funkit/connect-core';
import { type ApiFunkitCheckoutQuoteResult, type CheckoutQuoteResponse } from '@funkit/utils';
import type { Dnum } from 'dnum';
import { type Address } from 'viem';
import type { ServerCheckoutConfig } from '../domains/clientMetadata';
import type { FunkitCheckoutQuoteResult } from '../domains/quote';
import type { Config, UseConfigReturnType } from '../wagmi/hooks';
import { type FunkitCheckoutActionParams, type FunkitCheckoutConfig } from '../providers/FunkitCheckoutContext';
export declare const MOONPAY_TIME_ESTIMATE_MS = 120000;
export declare const BROKERAGE_TIME_ESTIMATE_MS = 0;
export declare const BANK_TIME_ESTIMATE_MS = 0;
export declare const DUMMY_TRANSFER_PARAMS: {
toAddress: "0x000000000000000000000000000000000000dEaD";
tokenAmount: number;
};
type ValidateCheckoutConfigReturn = Promise<{
config: FunkitCheckoutConfig;
isValid: true;
message: string;
} | {
isValid: false;
message: string;
}>;
/**
* Validates the checkout configuration.
* @param config - The checkout configuration to validate.
* @returns An object indicating whether the configuration is valid and a message if it is not.
*/
export declare function validateCheckoutConfig(config: Partial<FunkitCheckoutConfig>): ValidateCheckoutConfigReturn;
export declare const hasSufficientBalance: (wagmiConfig: UseConfigReturnType, walletAddress: string, tokenAddress: string, tokenChainId: string, requiredAssetAmount: number) => Promise<{
balance: number;
result: boolean;
tokenTicker: string;
} | {
balance: number;
result: boolean;
tokenTicker: null;
}>;
export declare const hasGasToken: (wagmiConfig: UseConfigReturnType, walletAddress: string, chainId: string) => Promise<boolean>;
export type TokenInfo = {
symbol: string;
tokenAddress: null | Address;
tokenUnitPriceUsd: null | number;
pickedChainId: string;
};
export declare function getTimeFromNowSeconds(startTimeMs: number, durationMs: number): number;
export declare function getCheckoutReceivedAmount({ config, quote, }: {
config: FunkitCheckoutConfig | ServerCheckoutConfig;
quote: ApiFunkitCheckoutQuoteResult | null;
}): number;
export declare function getCheckoutReceivedAmountFormatted({ config, quote, }: {
config: FunkitCheckoutConfig | ServerCheckoutConfig;
quote: ApiFunkitCheckoutQuoteResult | null;
}): string;
export declare function getCheckoutSentAmount({ quote, }: {
quote: ApiFunkitCheckoutQuoteResult | null;
}): number;
export declare function getCheckoutSentAmountFormatted({ quote, }: {
quote: ApiFunkitCheckoutQuoteResult | null;
}): string;
/**
* Given a checkout config, returns the display string for the checkout item.
* Arbitrary action checkouts: Display the targetAssetAmount
* - not 100% accurate since userOp will consume some tokens, but FINE now.
* - e.g. "2.1234 aArbUSDCn" or "Staked VRTX"
* Basic buy checkouts: Display the targetAssetAmount with the targetAssetTicker.
* - e.g. "0.12345 ETH"
* Ideally, should be used via the hook `useCheckoutItemDisplay` to handle the customer cutomization check.
*/
export declare function getCheckoutItemDisplay({ checkoutConfig, hideAmount, overrideAmount, }: {
checkoutConfig: FunkitCheckoutConfig | ServerCheckoutConfig;
hideAmount?: boolean;
overrideAmount?: number;
}): string;
/**
* Given the result of a quote, calculate the effective fees (in source asset).
*
* _These are only the fees from our base quote, **not** including the initial transfer / brokerage / card processing fees._
*/
export declare function getBaseQuoteTotalFeesFromAmount(baseQuote: CheckoutQuoteResponse): number;
/**
* Given the result of a quote, calculate the effective exchange rate (target asset / source asset).
*/
export declare function getQuoteExchangeRate(config: FunkitCheckoutConfig, baseQuote: CheckoutQuoteResponse): number;
/**
* Given the result of a quote, estimate the maximum targetAssetAmount for which the checkout should succeed.
* The result is then reduced by 1% to further reduce the risk of insufficient funds.
*
* NOTE: This assumes fees are (roughly) constant, at least when the target amount does not change much.
* Only the API could give us a true number here.
*
* @param sourceAssetBalance - Total source asset balance
* @param config - Checkout config
* @param quoteResult - Failed quote results
*/
export declare function getMaxTargetAssetAmountEstimate(sourceAssetBalance: number, config: FunkitCheckoutConfig, quoteResult: FunkitCheckoutQuoteResult, targetAssetDecimals: number): Dnum;
export declare function getTokenDecimals(wagmiConfig: Config, chainId: string, tokenAddress: FunAddress): Promise<number>;
export declare function evaluateCheckoutGenerateActionsParams(config: FunkitCheckoutConfig): Promise<FunkitCheckoutActionParams[]>;
export declare function isCheckoutCrFlow(config: FunkitCheckoutConfig): boolean;
/**
* @param config can be either be a config from live checkoutItem OR from checkout history's clientMetadata
*/
export declare function isCheckoutPostActionRequired(config: FunkitCheckoutConfig | ServerCheckoutConfig): boolean;
/**
* The amount-input switcher labels the *traded* token, which differs by quote
* mode: in EXACT_IN the entered amount is the source quantity, so it's labelled
* with the input token; in EXACT_OUT it's the destination quantity, labelled
* with the output token. Single source of truth shared by the loaded and
* loading screens so their labels never diverge.
*/
export declare function computeSwitcherDisplayToken({ checkoutConfig, displayAssetAmount, isExactIn, sourceTokenSymbol, }: {
checkoutConfig: FunkitCheckoutConfig | ServerCheckoutConfig | undefined;
displayAssetAmount: number;
isExactIn: boolean;
sourceTokenSymbol: string | null | undefined;
}): {
amount: number;
symbol: string;
};