UNPKG

@funkit/connect

Version:

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

119 lines (118 loc) 5.89 kB
/** * Aave V3 supply routed through Fun's VaultDepositor proxy. * * Two entry points: * - `createAaveSupplyCheckoutConfig` — high-level; returns a full * `FunkitCheckoutConfig` or `undefined` if the chain isn't Fun-supported. * The `undefined` return is the canonical "is this Fun-routed?" signal. * - `createAaveSupplyActions` — low-level; returns just the actions * closure. Use when you need non-default modal copy. * * Adding a new Aave entrypoint here (e.g. `supplyWithPermit`) requires * coordinating with backend: VaultDepositor selector-whitelists each * forwarded call. Pool addresses, in contrast, are owned by Aave's * registry — callers pass `poolAddress` directly. */ import { type Address } from 'viem'; import type { FunkitCheckoutActionParams, FunkitCheckoutConfig } from '../providers/FunkitCheckoutContext/types'; /** Action type signalling an Aave v3 Core supply, executed server-side after a UDA deposit lands. */ export declare const AAVE_SUPPLY_ACTION_TYPE = "AAVE_SUPPLY"; /** Returns true if Fun has a VaultDepositor deployment on `chainId` ready to route Aave supplies. */ export declare function isAaveSupplySupported(chainId: number): boolean; export interface AaveSupplyActionsConfig { /** Address that receives the aToken receipt. Typically the connected wallet. */ onBehalfOf: Address | undefined; /** Underlying asset to be supplied. Matches Aave's `DashboardReserve.underlyingAsset`. */ underlyingAsset: Address; /** Aave V3 Pool contract on `chainId`. Aave maintains the registry — pass the value from `@aave-dao/aave-address-book` or your own `marketsData`. */ poolAddress: Address; /** Chain ID — selects the Fun VaultDepositor deployment. */ chainId: number; /** Aave referral code. Defaults to 0; partners with a registered code pass theirs. */ referralCode?: number; } /** * Builds the `generateActionsParams` callback for an Aave V3 supply routed * through VaultDepositor. * * Usage: * ```ts * const checkoutConfig: FunkitCheckoutConfig = { * // ... * generateActionsParams: createAaveSupplyActions({ * onBehalfOf: walletAddress, * underlyingAsset: usdtAddress, * poolAddress: AaveV3Ethereum.POOL, * chainId: mainnet.id, * }), * } * ``` */ export declare function createAaveSupplyActions(config: AaveSupplyActionsConfig): () => Promise<FunkitCheckoutActionParams[]>; export interface AaveSupplyCheckoutInput { /** Underlying asset (Aave's `DashboardReserve.underlyingAsset`). */ underlyingAsset: Address; /** Aave V3 Pool contract on `chainId`. From Aave's own registry (`marketsData[market].addresses.LENDING_POOL` or `@aave-dao/aave-address-book`). */ poolAddress: Address; /** Chain ID — typically resolved from Aave's `currentMarket` via `marketsData[market].chainId`. */ chainId: number; /** Connected wallet — becomes `onBehalfOf` for the aToken receipt. Pass `undefined` if the wallet isn't connected yet; actions throw at exec time. */ walletAddress: Address | undefined; /** Reserve metadata used for modal display. Optional, but recommended. */ display?: { /** Token symbol (e.g. "USDT") — drives modal title "Supply USDT" and receipt ticker "aUSDT". */ symbol: string; /** Supply APY as a display string (e.g. "2.79"). When provided, the modal subtitle includes "{apy}% APY". */ supplyAPY?: string; /** * Whether this supply is/will be enabled as collateral for the user — * Aave's "usage as collateral" toggle (the `isCollateral` enablement * concept), NOT the reserve-level "can be collateral" eligibility. When * provided, the modal subtitle includes "Collateralization enabled" / * "disabled". */ collateralizationEnabled?: boolean; /** Override modal icon. If omitted, the modal falls back to its own asset-icon resolver. */ iconSrc?: string; }; /** Aave referral code; defaults to 0. */ referralCode?: number; /** * The aToken receipt the supply mints (Aave's `Reserve.aToken`). When * provided, the post-checkout success screen offers adding it to the user's * wallet via EIP-747 — necessary because the checkout's destination token is * the intermediate underlying (USDT), not the aToken (aUSDT) the user holds * after the supply. Resolve it from Aave reserve data (`@aave/client`'s * `reserve()` → `aToken`, or `@aave-dao/aave-address-book`). Omit if * unavailable — the button is simply not shown. */ receiptToken?: { address: Address; symbol: string; decimals: number; iconSrc?: string; }; /** * Integrator-owned health-factor resolver, called with the live supply amount * to render the Health factor (before → after) row. Compute it against live * on-chain data (e.g. `@aave/math-utils`); `null` if not ready, `"-1"` for ∞. */ resolveHealthFactor?: (underlyingHumanAmount: string) => { before: string | null; after: string | null; } | null; } /** * High-level builder for an Aave V3 supply checkout. Returns a * `FunkitCheckoutConfig` ready to launch via Fun's checkout, or `undefined` * if `chainId` isn't a Fun-supported chain. * * The `undefined` return is the canonical "is this path Fun-routed?" signal — * callers should fall back to Aave's native supply flow when it's returned. * * Modal copy ("Supply {symbol}", the "{apy}% APY · Collateralization * enabled/disabled" subtitle, "a{symbol}" receipt ticker) is owned here so it * stays consistent across SDK consumers. Subtitle segments only appear when * the corresponding `display` signal is provided. */ export declare function createAaveSupplyCheckoutConfig(input: AaveSupplyCheckoutInput): FunkitCheckoutConfig | undefined;