UNPKG

@funkit/fun-relay

Version:
88 lines 3.9 kB
import { type Execute, type GetQuoteParameters } from '@relayprotocol/relay-sdk'; import type { RelayAddress, RelayChainId, RelayVmType, RelayWallet } from './execution'; import { type FunRelayFeeItem } from './fees'; import type { SolanaAddress } from './solana'; import type { ApiFunkitCheckoutActionParams, CheckoutQuoteResponse, Logger } from './types'; type RelayQuoteOptions = GetQuoteParameters['options'] & { depositFeePayer?: SolanaAddress; }; export type RelayQuoteResult<VmType extends RelayVmType> = { details?: { currencyIn?: NonNullable<Execute['details']>['currencyIn']; currencyOut?: NonNullable<Execute['details']>['currencyOut']; }; steps: Execute['steps']; vmType: VmType; }; export type RelayExecute = Execute; export type GetRelayQuoteParams<SourceVmType extends RelayVmType = RelayVmType, TargetVmType extends RelayVmType = RelayVmType> = { actionParams?: ApiFunkitCheckoutActionParams[]; clientId: string; fromChainId: RelayChainId<SourceVmType>; fromTokenAddress: RelayAddress<SourceVmType>; logger: Logger; /** * {@link getRelayQuote} already sets {@link RelayQuoteOptions.appFees|appFees} and {@link RelayQuoteOptions.referrer|referrer}. * Only include them if you wish to override. */ options?: RelayQuoteOptions; recipientAddress: RelayAddress<TargetVmType> | undefined; toChainId: RelayChainId<TargetVmType>; toTokenAddress: RelayAddress<TargetVmType>; tradeType: 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT'; userAddress: RelayAddress<SourceVmType> | undefined; walletClient?: RelayWallet<SourceVmType>; apiKey: string; /** * Optional explicit user preference for the source-side authorization * step ("Sign message" vs "Approve transaction"). Forwarded to frog's * `/api/fee` so frog's `getUsePermit` can honor the FE toggle's choice. * Only meaningful for FE-driven flows (Wallet checkout); server-driven * flows (UDA, etc.) should omit this and let frog's auto-gasless * fallback decide. */ usePermit?: boolean; } & ({ fromTokenAmountBaseUnit: bigint | string; tradeType: 'EXACT_INPUT'; } | { toTokenAmountBaseUnit: bigint | string; tradeType: 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT'; }); export type RelayQuote<VmType extends RelayVmType = RelayVmType> = CheckoutQuoteResponse & { /** Required for EXACT_INPUT checkouts */ finalToAmountBaseUnit: string; metadata: { fromAmountBaseUnit: string; relayQuote: RelayQuoteResult<VmType>; toAmountBaseUnit: string; }; }; export type RelayBackendQuote<VmType extends RelayVmType = RelayVmType> = CheckoutQuoteResponse & { /** Required for EXACT_INPUT checkouts */ finalToAmountBaseUnit: string; metadata: { fromAmountBaseUnit: string; relayQuote: Execute & { vmType: VmType; }; toAmountBaseUnit: string; }; }; export declare function getReferrer(clientId: string): string; export declare class RelayQuoteClientError extends Error { readonly statusCode: number; readonly relayErrorCode: string; constructor(statusCode: number, relayErrorCode: string, message: string, requestId?: string | undefined); } /** * Get the headers for the quote request by the following logic: * - If subsidizeFeesSecretKey is provided, and subsidizeFees is true, set it to "x-api-key" header * - Apply funRelayConfig.headers as overrides if provided */ export declare const getHeaders: (funRelayConfig: FunRelayFeeItem, apiKey: string) => { 'x-api-key': string; }; export declare function getRelayQuote<SourceVmType extends RelayVmType, TargetVmType extends RelayVmType = RelayVmType>({ logger, walletClient, ...params }: GetRelayQuoteParams<SourceVmType, TargetVmType>): Promise<RelayBackendQuote<SourceVmType>>; export {}; //# sourceMappingURL=quote.d.ts.map