Deposit Wallets & Cross-Chain Swaps
Relevant source files
The following files were used as context for generating this wiki page:
- src/lib/wallet/transactions.ts
- src/app/[locale]/(platform)/_components/WalletFlow.tsx
- src/app/[locale]/(platform)/_components/WalletModal.tsx
- src/app/[locale]/(platform)/_providers/TradingOnboardingProvider.tsx
- src/app/[locale]/(platform)/_actions/approve-tokens.ts
- src/app/[locale]/(platform)/_components/wallet-modal/WalletSuccessStep.tsx
- src/lib/db/queries/user.ts
Introduction
The Deposit Wallet system serves as a non-custodial smart contract wallet architecture that enables users to interact with event-based contracts and prediction markets. By deploying a dedicated smart contract wallet for each user, the platform facilitates complex on-chain operations—such as token approvals, position splitting, and automated redemptions—without requiring the user to hold private keys for trade execution directly.
This system integrates with third-party providers like LI.FI for cross-chain swaps and Meld for fiat-to-crypto on-ramping. These integrations allow users to fund their dedicated prediction market accounts using assets from various blockchain networks or traditional payment methods, ensuring a seamless onboarding experience into the decentralized trading environment.
Sources: src/app/[locale]/(platform)/tos/page.tsx:75-96, src/app/[locale]/(platform)/_providers/TradingOnboardingProvider.tsx:49-74
Deposit Wallet Architecture
The Deposit Wallet is a smart contract deployed via the DEPOSIT_WALLET_FACTORY_ADDRESS. It operates using a batch execution model where multiple calls can be signed by a user's Externally Owned Account (EOA) and submitted via a relayer.
Core Components
- Wallet Factory: Responsible for deploying the user's smart contract wallet.
- Relayer Integration: Submits signed transaction batches to the blockchain, handling gas costs or transaction sequencing on behalf of the user.
- Typed Data Signing: Uses EIP-712 structured data for signing batches, including fields for
walletaddress,nonce,deadline, and the array ofcalls.
The following diagram illustrates the relationship between the user's EOA, the Relayer, and the Smart Contract Wallet:
The diagram shows the flow from the user's signature to final contract interaction.
Sources: src/lib/wallet/transactions.ts:109-122, src/app/[locale]/(platform)/_actions/approve-tokens.ts:258-300
Transaction Batching
Transaction batches are defined by the Batch primary type, which contains an array of Call objects. Each call specifies a target address, a value (in wei), and the encoded data.
| Field | Type | Description |
|---|---|---|
wallet | address | The address of the user's deployed smart contract wallet. |
nonce | uint256 | A unique number to prevent replay attacks. |
deadline | uint256 | The Unix timestamp after which the signature is invalid. |
calls | Call[] | An array of objects containing target, value, and data. |
Sources: src/lib/wallet/transactions.ts:109-122
Cross-Chain Swaps and Funding
The platform leverages the LI.FI SDK to allow users to deposit funds from any supported chain into their Polygon-based Deposit Wallet.
LI.FI Integration
The WalletModal and WalletFlow components utilize useLiFiWalletTokens and useLiFiQuote to provide a list of available assets across chains and calculate the expected output when swapping to the platform's collateral token (USDC).
- Token Discovery: The system fetches tokens held by the user's EOA across multiple networks.
- Quoting: A quote is generated for the swap, including the destination amount and estimated gas fees in USD.
- Execution: Swaps are routed through LI.FI to ensure the user receives the correct collateral on the target network (Polygon).
This sequence shows how LI.FI facilitates the transfer of funds into the prediction market wallet.
Sources: src/app/[locale]/(platform)/_components/WalletModal.tsx:109-144, src/app/[locale]/(platform)/_components/wallet-modal/WalletSuccessStep.tsx:35-50
Meld On-Ramping
For fiat funding, the application opens a Meld popup with destinationCurrencyCodeLocked set to USDC_POLYGON and the walletAddressLocked set to the user's deposit_wallet_address.
Sources: src/app/[locale]/(platform)/_components/WalletFlow.tsx:184-210, src/app/[locale]/(platform)/_providers/TradingOnboardingProvider.tsx:1350-1360
Onboarding and Requirements
Trading is restricted until specific onboarding criteria are met. The TradingOnboardingProvider manages a sequence of requirements:
- Username Selection: Users must set a unique username, which is also synced with a community profile.
- Email Verification: Optional or mandatory email capture for notifications.
- Identity Verification (Sumsub): Identity checks based on jurisdiction and enforcement levels (Observe vs. Required).
- Wallet Deployment: The smart contract wallet must be deployed on-chain.
- Token Approvals: One-time signature to allow the exchange to spend the wallet's collateral.
Token Approval Workflow
Users must approve several spenders and operators to enable full functionality:
- USDC Allowance: Required for
CONDITIONAL_TOKENS_CONTRACT,CTF_EXCHANGE_ADDRESS, andUMA_NEG_RISK_ADAPTER_ADDRESS. - ERC1155 Operator Approval: Required for the
CTF_AUTO_REDEEM_ADDRESSto automate winnings redemption.
Flowchart showing the mandatory approval steps before trading.
Sources: src/app/[locale]/(platform)/_providers/TradingOnboardingProvider.tsx:1044-1150, src/lib/wallet/transactions.ts:192-212
Implementation Details
Building Wallet Calls
The transactions.ts library provides helper functions to encode function data for common wallet operations.
// Example: Building a transfer call for the Deposit Wallet
export function buildSendErc20Call(params: {
token: `0x${string}`
to: `0x${string}`
amount: string | number | bigint
decimals?: number
}): WalletCall {
const value = parseAmountToBaseUnits(params.amount, params.decimals ?? 6)
return createWalletCall(
params.token,
encodeFunctionData({
abi: erc20Abi,
functionName: 'transfer',
args: [params.to, value],
}),
)
}
Sources: src/lib/wallet/transactions.ts:258-280
Deposit Wallet Statuses
The deployment state of the wallet is tracked in the database and monitored via polling.
| Status | Description |
|---|---|
not_started | Initial state before deployment request. |
signed | User has signed the deployment transaction. |
deploying | Transaction has been submitted to the network. |
deployed | Contract is verified as active on-chain. |
Sources: src/lib/db/queries/user.ts:500-530, src/app/[locale]/(platform)/_providers/TradingOnboardingProvider.tsx:244-255
Conclusion
The Deposit Wallet and Cross-Chain Swap infrastructure provides a bridge between diverse crypto assets and a specialized prediction market environment. By abstracting the complexities of multi-chain routing and smart contract interactions through batch signatures and relayers, the system offers a non-custodial but user-friendly trading experience. The integration of onboarding providers ensures compliance and account security while maintaining the decentralized nature of user asset control.