UNPKG

@funkit/connect

Version:

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

99 lines (96 loc) 3.53 kB
"use client"; import { AMOUNT_PLACEHOLDER, COLLATERAL_ONRAMP_ABI, COLLATERAL_ONRAMP_ADDRESS, POLYGON_USDCE, PUSD_TOKEN, VAULT_DEPOSITOR_ABI, VAULT_DEPOSITOR_POLYGON, createPerpsGenerateActionParams } from "./chunk-6PIIYPQK.js"; // src/clients/polymarket/createPolymarketDepositConfig.ts import { encodeFunctionData, erc20Abi, getAddress, maxUint256 } from "viem"; import { polygon } from "viem/chains"; var POLYMARKET_PREDICTIONS_ROUTING_ID = "POLYMARKET_PREDICTIONS"; var POLYMARKET_PERPS_ROUTING_ID = "POLYMARKET_PERPS"; function createPredictionsGenerateActionParams(config) { const { recipientAddress } = config; return async () => { const wrapUsdceToPusd = encodeFunctionData({ abi: COLLATERAL_ONRAMP_ABI, functionName: "wrap", args: [POLYGON_USDCE, recipientAddress, AMOUNT_PLACEHOLDER] }); return [ // Approve USDC.e to the VaultDepositor (infinite). { contractAbi: erc20Abi, contractAddress: POLYGON_USDCE, functionName: "approve", functionArgs: [VAULT_DEPOSITOR_POLYGON, maxUint256] }, // VaultDepositor pulls the USDC.e and forwards to CollateralOnramp.wrap, // minting pUSD to the predictions proxy. { contractAbi: VAULT_DEPOSITOR_ABI, contractAddress: VAULT_DEPOSITOR_POLYGON, functionName: "deposit", functionArgs: [ POLYGON_USDCE, COLLATERAL_ONRAMP_ADDRESS, wrapUsdceToPusd, 0n ] } ]; }; } var PERPS_MIN_DEPOSIT_USD = 5; function createPolymarketDepositConfig({ predictions, perps, modalTitleMeta, modalTitles, defaultAccount = "predictions" }) { const isPerpsRoute = (routingId) => routingId === POLYMARKET_PERPS_ROUTING_ID; const defaultsToPerps = defaultAccount === "perps"; const predictionsRecipient = getAddress(predictions.address); const perpsRecipient = getAddress(perps.address); return { targetChain: polygon.id.toString(), targetAsset: POLYGON_USDCE, targetAssetAmount: 0, targetAssetTicker: PUSD_TOKEN.symbol, checkoutItemTitle: PUSD_TOKEN.symbol, iconSrc: PUSD_TOKEN.iconSrc, modalTitleMeta, // The preselected destination (the "Deposit to" dropdown derives its // selection from `dynamicRoutingId`, so both fields must agree). dynamicRoutingId: defaultsToPerps ? POLYMARKET_PERPS_ROUTING_ID : POLYMARKET_PREDICTIONS_ROUTING_ID, customRecipient: defaultsToPerps ? perpsRecipient : predictionsRecipient, modalTitle: ({ dynamicRoutingId }) => isPerpsRoute(dynamicRoutingId) ? modalTitles?.perps ?? "Deposit (Perps)" : modalTitles?.predictions ?? "Deposit (Predictions)", getMinDepositUSD: ({ dynamicRoutingId }) => isPerpsRoute(dynamicRoutingId) ? PERPS_MIN_DEPOSIT_USD : 0, generateActionsParams: (_targetAssetAmount, outputConfig) => isPerpsRoute( outputConfig?.dynamicRoutingId ) ? createPerpsGenerateActionParams({ recipientAddress: perpsRecipient })() : createPredictionsGenerateActionParams({ recipientAddress: predictionsRecipient })(), // Both transfer directions are integrator-owned; the step picks the source // account's transfer. The accounts already have exactly the handle shape // the step consumes, so they pass through as-is. polymarketPerpsTransfer: { predictions, perps } }; } export { POLYMARKET_PREDICTIONS_ROUTING_ID, POLYMARKET_PERPS_ROUTING_ID, createPredictionsGenerateActionParams, createPolymarketDepositConfig };