@funkit/connect
Version:
Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.
92 lines (91 loc) • 4.53 kB
TypeScript
/**
* Mallard (Zorro Chain) perps deposit via VaultDepositooor.
*
* Wraps the Mallard deposit contract's `initiateDepositReturnToOwner()` inside the
* VaultDepositooor proxy so it composes with EXACT_INPUT quoting:
* 1. approve(token, VAULT_DEPOSITOR, MAX)
* 2. VAULT_DEPOSITOR.deposit(token, MALLARD_DEPOSIT,
* initiateDepositReturnToOwner(recipient, 0, token, AMOUNT_PLACEHOLDER, true), 0)
* VaultDepositooor pulls msg.sender's full token balance at exec time and substitutes
* AMOUNT_PLACEHOLDER with the actual arrived amount, so the deposit amount doesn't need to
* be known at quote time — same pattern as the Rolly/Aave SDK deposits.
*
* VaultDepositooor on Zorro Chain (4663): 0xec70919c52e56a197d2e13b78cb8511db54f3ca2 —
* create2-deployed via the Arachnid factory (not at the usual 0xC8A6… create3 address);
* verified on-chain (owner = the Fun deployer).
*/
import { type Address } from 'viem';
import type { FunkitCheckoutActionParams, TokenInfo, WalletWithdrawalConfig } from '../providers/FunkitCheckoutContext/types';
/** Mallard deposit contract to credit a Mallard (perps) account. */
export declare const MALLARD_DEPOSIT_ADDRESS: `0x${string}`;
/** VaultDepositooor on Zorro chain. */
export declare const VAULT_DEPOSITOR_ZORRO: `0x${string}`;
/** Sentinel the VaultDepositooor replaces with the actual deposit amount at exec time. */
export declare const AMOUNT_PLACEHOLDER = 115792089237316195423570985008687907853269984665640564039457584007912570601199n;
export interface MallardDepositActionsConfig {
/** Mallard account owner credited by the deposit (typically the connected wallet). */
recipientAddress: Address | undefined;
/** Collateral token deposited (USDG on Zorro Chain). */
tokenAddress: Address;
/** VaultDepositooor; defaults to the Zorro Chain deployment. */
vaultDepositorAddress?: Address;
/** Mallard deposit contract; defaults to MALLARD_DEPOSIT_ADDRESS. */
depositAddress?: Address;
}
/**
* Builds the `generateActionsParams` callback for a Mallard deposit routed through
* VaultDepositooor.
*
* Usage:
* ```ts
* generateActionsParams(address) {
* return createMallardDepositActions({
* recipientAddress: address,
* tokenAddress: tokenAddresses.USDG[ZorroChain.id],
* })
* }
* ```
*/
export declare function createMallardDepositActions(config: MallardDepositActionsConfig): () => Promise<FunkitCheckoutActionParams[]>;
/** USDG (the perps/spot collateral token) on the Robinhood chain. */
export declare const MALLARD_USDG_ADDRESS: `0x${string}`;
/** USDG logo served from the Fun CDN. */
export declare const MALLARD_USDG_ICON_SRC = "https://sdk-cdn.fun.xyz/images/usdg.svg";
export interface MallardWithdrawalConfig {
/**
* Source token to withdraw. Defaults to USDG ({@link MALLARD_USDG_ADDRESS})
* on the Robinhood chain.
*/
sourceTokenAddress?: Address;
/** Source chain id. Defaults to the Robinhood mainnet chain. */
sourceChainId?: number;
/** Symbol shown for the source token. Defaults to `'USDG'`. */
sourceTokenSymbol?: string;
/** Title shown in the withdrawal modal. Defaults to the localized "Withdraw". */
modalTitle?: string;
/** Disable the connected-wallet option for email-login users. */
disableConnectedWallet?: boolean;
/** Token logo (50px). Defaults to {@link MALLARD_USDG_ICON_SRC}. */
iconSrc?: string;
/** Default token to preselect in the receive-token dropdown. */
defaultReceiveToken?: string;
/** Minimum USD value required to withdraw, evaluated per receive-token. */
getMinWithdrawalUSD?: (asset: TokenInfo) => number;
/** Maximum USD value allowed for a single withdrawal. */
getMaxWithdrawalUSD?: (asset: TokenInfo) => number;
/** Async hook fired after the withdraw CTA but before any wallet signature. */
onBeforeSign?: () => Promise<void> | void;
}
/**
* React entry point for Mallard withdrawals. Returns a
* {@link WalletWithdrawalConfig} (executing wallet = the connected wallet, via
* {@link createConnectedWalletWithdrawalClient}), or `null` until a config is
* passed and a wallet is connected. Balance isn't read here — the modal sources
* it from the checkout config's `withdrawalSourceTokenBalance`, like
* Lighter/Polymarket.
*
* ```tsx
* const mallard = useMallardWithdrawalConfig(isConnected ? {} : null)
* ```
*/
export declare function useMallardWithdrawalConfig(config: MallardWithdrawalConfig | null): WalletWithdrawalConfig | null;