Skip to content

Wallet connection and sessions ​

The terminal uses wagmi and viem. MetaMask is the default browser wallet. Dynamic integration is planned and is not installed as the connection flow.

Sources: web/src/lib/wallet.ts (wallet configuration), web/src/components/top-bar/wallet-button.tsx (connect button), web/src/lib/use-collateral.ts (collateral actions), and web/src/lib/use-trading-session.ts (session actions).

Connection ​

The configured connector is injected({ target: 'metaMask' }). The connect button first selects the discovered io.metamask connector, then the explicit metaMask connector. It requests the configured chain. The UI reports a missing extension or failed connection.

Without browser environment settings, the app selects local chain 31337. For Monad testnet, copy web/.env.example to web/.env.local; this selects chain 10143. Restart or rebuild the web app after changing public environment values. The API deployment chain and browser chain must agree.

Wallet connection itself does not need test MON. Transactions do.

Steps in the terminal ​

  1. Select Connect wallet in the top bar. Approve the request in MetaMask.
  2. Select Faucet. It mints 10,000 test USDC to the wallet. This token has no cash value.
  3. Select the wallet address to open the Account dialog. Select the market.
  4. Enter an amount, then select Approve and deposit.
  5. Select Enable on the trading session row. Approve the authorization in MetaMask.

Each market has its own collateral and its own session. Do the deposit and the session step again for the second market.

Signing and gas ​

ActionSignerGas payer
Mint demo USDC, approve, deposit, or withdrawMain wallet in MetaMaskBrowser account
Authorize or revoke a sessionMain wallet in MetaMaskBrowser account
Place or cancel through the terminalBrowser session key signs EIP-712 dataRelayer account submits the transaction
Sign a test oracle price and submit it with a quoteDeployer, which owns TestOracleDeployer account
Post demo maker quotesEach maker accountThat maker account

Session permission ​

The UI creates a random private key in the browser. The main wallet authorizes its address for one market for 24 hours with an exposure limit of 1000 contracts. The UI stores the key in sessionStorage, scoped by chain, registry, owner, and market. The relayer receives signed actions, not the session private key.

The signature binds the account, session, order fields, nonce, deadline, chain, and verifying market. The contract checks authorization, expiry, revocation, exposure, and nonce before execution. The action definitions are in packages/shared/src/actions.ts. The EIP-712 domain has the name VarianceMarket and the version 1.

Each signed order has a deadline of 60 seconds for the relayer and an order expiry of 120 seconds.

A session can place and cancel orders. It cannot withdraw funds or grant another session permission. It can still create trading losses within its allowed scope. Browser session storage is not a hardware key store.

Disconnecting MetaMask does not revoke the session onchain. Closing a tab does not cancel existing orders. Revocation blocks new signed actions but does not cancel orders already accepted. Cancel those orders separately. If the tab key is lost, the current UI cannot reconstruct it; the main wallet can use contract calls to revoke its known session address and cancel orders.

Confirmed state ​

The relayer simulates the action, estimates gas, submits it, and waits for a receipt. submitted means a hash exists but confirmation was not obtained. confirmed means a successful receipt exists. A confirmed order may still have zero fills; use OrderResult to read filled, resting, and canceled amounts.

The terminal currently needs the API and relayer for its session-order flow. Although contracts support direct main-wallet orders, automatic UI fallback to that path is not implemented.

Deployed on Monad testnet.