How Masayume uses DreamDEX
Follow the Somnia Markets SDK from a product feature to its exact calls, code and on-chain evidence.
DreamDEX supplies the event markets that Masayume uses. The Somnia Markets SDK, installed as @somnia-chain/markets-sdk version 0.28.1, connects our TypeScript application to market discovery, books, prices, balances and trading. Masayume adds the user experience, risk checks, agents, X integration and its own contracts around those markets. The configured network is Somnia Shannon testnet, chain 50312.
This guide is an implementation map for judges and developers. Every call below is present in the reviewed application source. It describes the SDK capabilities we use, not every capability the SDK offers. The dependency is pinned in the market package.
Start with the integration boundary
Explore each part and its connections. Expand to use more of your screen.
Follow an arrow to explore a connected part.
Web app · agents · X
What this part does
The web app and operator services use the same market package. Masayume adds product flows, model decisions, risk checks and recovery around DreamDEX markets.
Outgoing connections
- From MasayumeMarket readsRead or display
- From MasayumeAuthorized actionAction or record
The web app and operator services use the same market package. Masayume adds product flows, model decisions, risk checks and recovery around DreamDEX markets.
Read the map as text
- Masayume Markets SDK reader: Market reads.
- Markets SDK reader DreamDEX data: SDK clients.
- Masayume Signer + submitter: Authorized action.
- Markets SDK reader Signer + submitter: Fresh executable quote.
- Signer + submitter Masayume contracts: Vault / ticket route.
- Masayume contracts DreamDEX contracts: Orders / oracle / redeem.
- Signer + submitter DreamDEX contracts: Direct wallet · SDK trader.
Download the architecture image (PNG) · Download the vector image (SVG)
The map in three paths:
- Public reads: Masayume web, agents and X → account-free Markets SDK reader → DreamDEX indexer, chain and price data.
- Direct wallet: fresh SDK quote → separate signer and checked submitter → SDK trader → DreamDEX orders and settlement.
- Vault or specialist ticket: fresh market facts → authorized signer → Masayume contracts → DreamDEX orders, redemption or OracleHub resolution, depending on the product. Range and Moonshot use oracle settlement rather than placing a venue order.
Product screens and operator services call our @masayume/markets package. That package owns the SDK imports and adapts SDK data into the types used by the rest of the app.
- Read:
configureMarketscreates one account-freeSomniaMarketsruntime per browser tab or server process. Its configuration supplies the chain, indexer, WebSocket, pinned addresses and price feed. - Share:
marketsProviderexposes the same market-reading interface to the web app, strategy runner and X executor. React hooks and the book coordinator share live subscriptions. - Sign:
createSubmitterSessioncreates a separate SDK instance for one signer and role. Its nonce queue serializes sends. The public reader never gains that account's authority. - Execute: the common submitter chooses the direct SDK trader or a Masayume contract route, verifies the result and records actual fills.
Follow runtime construction, the shared read interface, signing sessions and order routing. The system map shows the wider app and service boundaries.
Which SDK calls power which features?
The client below is the SDK client returned by our shared runtime. trader belongs to a signing session. File links point to an immutable reviewed commit.
| Product need | SDK capability used | Where it connects |
|---|---|---|
| Find live and past Windows | listLiveBinaryMarkets, listPastBinaryMarkets, getBinaryMarket | Market discovery groups markets into the lanes shown in the app and scanned by operators. |
| Read current executable liquidity | getBinaryOrderBook, getBinaryBookParams | Book reads supply depth, tick size, lot size and minimum quantity. |
| Turn a stake into a bounded quote | quoteBinaryStakeOverBook, quoteBinaryOrderOverBook | Quote calculation calculates quantity and cost; freshQuoteStake rereads the chain book before execution. |
| Keep the ticket and charts current | watchMarket, subscribeLive, getLiveBinaryOrderBookByMarket; SomniaMarketsProvider, useWatchMarket, useLiveBinaryOrderBookByMarket, useLiveStatus, useWatchPrice, useLivePrice | Book coordination, ticket hooks and price hooks connect live SDK state to React. |
| Build price context for charts and agents | getOpeningPrices, fetchPrice, fetchPriceHistory | Price adapter provides the opening print, spot/EMA and price path. |
| Verify the Window and its fees | getMarketOnchain, getMarketFees, getMarketResolution | Chain state, fees and resolution support entry checks and outcome display. |
| Show wallet funds and positions | getErc20Balance, getNativeBalance, getPortfolio, getVaultBalance, getVaultPayoutFallbacks, getOpenPositionsWithPnL, getBalances | Balance sheet and positions distinguish wallet funds, venue escrow and outcome-token holdings. Our Trading Balance also has its own EventVault reads. |
| Reconstruct trading history | getUserFills, getRouterActions, getBinaryMarket, getBalances | Wallet history paginates records and associates fills with their actual Window. |
| Build venue activity and reconcile an uncertain direct order | getFills, getUserFills, getOwnOpenOrdersOnchain, getViemClient | Venue scans feed activity statistics. Direct-order recovery checks the receipt, fills and open orders. Vault executions have a separate exact-event recovery path. |
| Submit a direct wallet order | trader.placeOrder, ORDER_TYPE.MARKET, autoApprove | Order send sends an immediate-or-cancel order with a protective limit. This is the direct wallet route. |
| Obtain test collateral or redeem outcomes | trader.faucet, trader.redeem | Transaction routing uses explicit outcome IDs and checks transaction status. Masayume-contract settlements take their own routes. |
| Keep identity correct when a pool is reused | marketKey, outcomeId, decodeOutcomeId, binaryModuleReadAbi, binarySettlementAbi | Identity adapter separates the durable marketId, pool-generation outcome IDs and settlement key. |
Test-funds onboarding: the tUSDC mint above remains a wallet-signed SDK call. Masayume's separate STT faucet first sends eligible wallets a bounded native-token top-up through viem/RPC, with durable PostgreSQL reservations. That STT transfer is Masayume infrastructure, not a DreamDEX SDK faucet feature. The wallet guide connects the two prompts, and configuration describes its limits and funding key.
Supporting calls include getErc20Metadata for collateral decimals, getErc20Allowance for funding checks, and getLiveStatus/getWatchStatus for subscription health. The SDK also supplies Shannon chain/address defaults, interval helpers, typed errors and React query keys. Our address check detects drift from the pinned deployment manifest. These primitives are inside the same market package; the contract reference lists the upstream and Masayume-owned addresses separately.
Trace one call from the app to DreamDEX
Consider a BTC UP ticket for one active Window:
- The market adapter discovers the Window and its opening print through SDK reads.
- Live book subscriptions update the ticket. The SDK's quote helpers translate the requested tUSDC stake into outcome quantity, cost and a protective price.
- On confirmation, the submitter checks fresh chain state, fees, funding, expiry and a fresh quote. A cached screen value is not sufficient permission to send.
- A direct wallet route calls
trader.placeOrder. A Trading Balance or delegated route calls Masayume'sEventVaultwriter instead; its on-chain venue gateway reaches DreamDEX's market and order-book contracts. - The result records the transaction and actual cost/quantity from execution evidence. A submitted transaction, an unfilled order and a filled position have different states.
- At resolution, the owner or the authorized settlement path redeems the held outcome tokens. A grant's proceeds return to available Trading Balance; settlement does not silently renew its spending budget.
The two execution paths meet the same venue, but the JavaScript SDK does not implement our Solidity permission logic. Follow the vault adapter into VenueGateway for that contract-to-contract connection.
How agents and X reuse the integration
Momentum and AI agents use the same market discovery, price feed, opening prints and executable quotes. readAgentContext combines those SDK-backed reads into a fresh model input, including normalized price units and both sides' costs. The language-model call, decision journal and strategy risk rules belong to Masayume. A model verdict still needs to pass the trade gates.
Both strategy execution and X execution submit through this route:
route: { kind: "vault-grant", grantId }That is an excerpt of the route shape, not a standalone trading script. A strategy uses a STRATEGY grant; X uses a separate EXECUTOR grant. The X account-to-wallet link identifies whose permission to inspect. It does not itself authorize spending.
Read agent context, subscriber execution, strategy settlement and X execution. The agent architecture and X architecture explain their database and recovery responsibilities.
How the specialist products connect
These are Masayume contracts and rules using DreamDEX infrastructure. They are not additional features supplied by the TypeScript SDK.
| Product | Connection to DreamDEX | Read more |
|---|---|---|
| Parlay | Its reserve reads the underlying Windows' resolved outcomes and applies the multi-leg payout rules. | Parlay and event contracts |
| Range and Moonshot | RangeReserve reads the Window's numeric OracleHub answer and compares it with the chosen band. Moonshot uses the Range path; it does not place a directional CLOB order. | Range settlement, Moonshot |
| Boost | LeverageReserve finances actual outcome-token purchases and manages close, knock-out and settlement. | Leverage |
| Earn | MarketMakerVault holds capital and inventory; the maker service manages bounded venue quotes. | Market making |
| Private mode | PrivateDesk funds separate slots holding venue positions; the desk's owner/claim association is an additional trust boundary. | Private architecture |
| Duel | GameArena buys and redeems picks through the venue and records match accounting. Room messages are separate from chain results. | Game architecture |
| Practice and arcade | Local simulation or server-verified scores; these are not proof that an SDK order or on-chain payout occurred. | Practice, Candle Hop |
Our directly integrated Somnia tools are the Markets SDK, DreamDEX contracts/indexer, RPC/WebSocket and price-feed/OracleHub paths described here. The reviewed application does not make a separate direct Reactor or Somnia Data Streams SDK call. Upstream automation is not presented as an application-owned integration.
Follow the live evidence
The 6–7 September 2026 rehearsal used faucet assets only. These dated records demonstrate specific paths, not a promise of future returns or current service health.
| Scenario | Actual result | Evidence |
|---|---|---|
| X command | One BTC UP fill, 0.908520 tUSDC actual spend; matching sender/hash image delivered. | Transaction, image reply |
| AI strategy | A real model decision produced an ETH UP fill; it lost and settled for zero payout. | Fill, settlement |
| Corrected Momentum strategy | ETH DOWN settled for 1.661 tUSDC; a new BTC Window fill followed. | Settlement, subsequent fill |
| Moonshot | A winning numeric-price ticket paid 2.000132 tUSDC through RangeReserve. | Claim |
The acceptance ledger preserves failures, the invalid pre-fix Momentum signal, test/deployment revisions and evidence limits. Source links currently require repository access; the public guide, transaction links and demo can be read independently.
Read this with an AI tool
Use llms.txt for the documentation index, this guide as Markdown, or llms-full.txt for all guide text with canonical URLs and source notes. The correct index filename is lowercase llms.txt.
For upstream reference material, see DreamDEX Event Contracts documentation and its llms.txt. The call-site map above is verified against Masayume's installed SDK version and source, independently of changes to upstream documentation.
Source notes
This guide follows the application code reviewed on 2026-09-07. Links point to that reviewed commit and require repository access. GitHub may show 404 if you are signed out or do not have access.
- packages/markets/src/faucet/index.ts
- web/src/features/markets/faucet/useFaucet.ts
- packages/markets/package.json
- packages/markets/src/runtime/read-runtime.ts
- packages/markets/src/provider/index.ts
- packages/markets/src/provider/markets.ts
- packages/markets/src/provider/books.ts
- packages/markets/src/provider/quotes.ts
- packages/markets/src/provider/prices.ts
- packages/markets/src/provider/onchain.ts
- packages/markets/src/provider/fees.ts
- packages/markets/src/provider/resolution.ts
- packages/markets/src/provider/balances.ts
- packages/markets/src/provider/positions.ts
- packages/markets/src/provider/history.ts
- packages/markets/src/provider/scan.ts
- packages/markets/src/submitter/reconcile.ts
- packages/markets/src/submitter/steps/funding.ts
- packages/markets/src/collateral.ts
- packages/markets/src/runtime/coordinator.ts
- packages/markets/src/react/provider.tsx
- packages/markets/src/react/useStakeQuote.ts
- packages/markets/src/react/useAssetPrice.ts
- packages/markets/src/sessions/submitter-session.ts
- packages/markets/src/submitter/order-lane.ts
- packages/markets/src/submitter/steps/send.ts
- packages/markets/src/submitter/tx-lane.ts
- packages/markets/src/identity.ts
- packages/markets/src/vault/order.ts
- packages/markets/src/strategies/agent-context.ts
- services/ops/src/actors/strategy-runner/execute.ts
- services/ops/src/actors/strategy-runner/lifecycle.ts
- services/ops/src/actors/x-relay/execute.ts
- contracts/src/vault/VenueGateway.sol
- contracts/src/range/RangeReserve.sol
- contracts/src/parlay/ParlayReserve.sol
- contracts/src/games/ArenaGateway.sol
- contracts/src/leverage/LeverageReserve.sol
- contracts/src/maker/MarketMakerVault.sol
- contracts/src/private/PrivateDesk.sol
- docs/implementation/acceptance-2026-09-06.md