On-Chain Methods
Trading, quoting, token approvals, and direct Gateway contract interaction via RPC.
Overview
On-chain methods send transactions or read directly from the Gensyn blockchain via a Gateway contract.
Market Deployments & Routing
Testnet and mainnet have automated-settlement and legacy deployments. Each market belongs to one of those deployments.
The client checks both factories with marketProxiesExist. It caches the result, then routes market-scoped calls to the owning gateway. This applies to buys, sells, quotes, redemptions, and liquidations.
Use resolveGateway() before making direct Gateway calls:
const gateway = await client.resolveGateway(marketAddress);Setting gatewayAddress or DELPHI_GATEWAY_CONTRACT pins every call. Pinning disables automatic routing. If you incorrectly pin a gateway, you can revert with MarketProxyNotDeployedByFactory.
Contract Addresses
You can find Testnet and mainnet RPC endpoints, contract addresses, and more by visiting Network Information on the Gensyn Foundation docs.
Trading
Pricing Mechanism (DPM)
Delphi app markets on testnet and mainnet use Dynamic Parimutuel (DPM) markets. This means:
Prices shift continuously with every trade (no fixed order book)
spotImpliedProbabilityreflects the market's current consensus probabilityFor a binary market:
prob[0] + prob[1] = 1e18(100%)A spot price of 0.65 collateral tokens per share means ~65% implied probability
Quoting Trades
These are read-only and therefore do not consume any gas.
quoteBuy
The cost to receive an exact number of shares.
quoteSell
The payout for selling an exact number of shares.
quoteRedeem and quoteLiquidate
quoteRedeem() estimates redemption for a settled market. quoteLiquidate() estimates exit value for an expired or failed market.
Use redeemMarket() only after settlement. Use liquidate() for expired and failed markets.
Buying Shares
Token approval must exist before buying. The full flow with approval and slippage looks like this:
BuyShares (params)
marketAddress
`0x${string}`
Market proxy address
outcomeIdx
number
Outcome index to buy
sharesOut
bigint
Exact shares to receive (18 decimals)
maxTokensIn
bigint
Maximum collateral spend — slippage cap (6 decimals)
Selling Shares
SellShares (params)
marketAddress
`0x${string}`
Market proxy address
outcomeIdx
number
Outcome index to sell
sharesIn
bigint
Exact shares to sell (18 decimals)
minTokensOut
bigint
Minimum collateral received — slippage floor (6 decimals)
Liquidating Positions
Liquidation exits positions without a winning outcome. It applies to expired and failed markets.
liquidate(params)
marketAddress
`0x${string}`
Market proxy address
outcomeIndices
number[]
Outcomes to liquidate
Pass every outcome index where you hold shares. Omitted indices are not liquidated, and their funds remain locked. [0, 1] covers a binary market.
getMarketStatus(marketAddress)
Reads a market's lifecycle status from the owning gateway. This value is fresher than the REST API.
Slippage Guidelines
Quiet market
1–2%
Active market
2–5%
Large trade (>$100)
5–10%
Time-sensitive execution
5%
Here's an example of using integer arithmetic to avoid floating point:
Common Contract Errors
TokensInExceedsMax
Actual cost > maxTokensIn
Re-quote and increase slippage
TokensOutBelowMin
Actual payout < minTokensOut
Re-quote and increase slippage
MarketNotOpen
Market closed or settled
Cannot trade; check status
SharesInExceedSupply
Selling more than held
Query balance first
GrossTokensOutNotPositive
Nothing to sell
Position is empty
ZeroTokensIn
sharesOut too small
Use a larger share amount
MarketProxyNotDeployedByFactory
Gateway does not own the market
Resolve the gateway or remove the pinned override
Token Approvals
getTokenAllowance(params)
Read the current ERC-20 allowance your wallet has granted to a market.
approveToken(params)
Approve the ERC-20 token for spending by a market.
ensureTokenApproval(params)
Check if sufficient allowance exists and only sends an approval transaction if needed. Recommended before buying shares.
Testnet
$TEST
Mainnet
USDC
Competition testnet
TST
Gateway Contract Reference
This section is for advanced users who want to call the Gateway contract directly via viem.
The SDK uses DYNAMIC_PARIMUTUEL_GATEWAY_ABI on every network, including competition-testnet. The competition LMSR gateway exposes identical call signatures.
Competition differs in its underlying pricing math. Its MarketSettled event also omits market-creator economics fields.
viem Client Setup
Set up your viem client like this:
resolveGateway() creates a signer-backed client internally. Configure WALLET_PRIVATE_KEY or CDP credentials, even for read-only use.
DELPHI_FACTORY_ABI is also exported for direct Factory reads, including marketProxiesExist.
Gateway Functions
All of the gateway functions, broken down into tables by [1] read and [2] write.
1. Read Functions
quoteBuyExactOut
marketProxy, outcomeIdx, sharesOut
tokensIn: uint256
Collateral cost (6 dec)
quoteSellExactIn
marketProxy, outcomeIdx, sharesIn
tokensOut: uint256
Collateral payout (6 dec)
spotImpliedProbability
marketProxy, outcomeIdx
uint256
1e18 = 100%
spotImpliedProbabilities
marketProxy, outcomeIndices[]
uint256[]
Batch
spotPrice
marketProxy, outcomeIdx
uint256
1e18 = 1.0 collateral tokens per share
spotPrices
marketProxy, outcomeIndices[]
uint256[]
Batch
balanceOf
marketProxy, owner, outcomeIdx
uint256
Shares (18 dec)
batchBalanceOf
marketProxy, owners[], outcomeIndices[]
uint256[]
Batch
totalSupply
marketProxy, outcomeIdx
uint256
Total shares (18 dec)
totalSupplies
marketProxy, outcomeIndices[]
uint256[]
Batch
getMarket
marketProxy
Market struct
Full on-chain state
marketStatus
marketProxy
uint8
0=Open, 1=Awaiting settlement, 2=Settled, 3=Expired, 4=Failed
token
marketProxy
address
Collateral token address
2. Write Functions
Prefer the SDK methods over calling the Gateway directly, as they handle simulation, approval, and receipt waiting.
buyExactOut
marketProxy, outcomeIdx, sharesOut, maxTokensIn
Use DelphiClient.buyShares()
sellExactIn
marketProxy, outcomeIdx, sharesIn, minTokensOut
Use DelphiClient.sellShares()
redeem
marketProxy
Use DelphiClient.redeemMarket()
liquidate
marketProxy, outcomeIndices
Use DelphiClient.liquidate()
Direct Read Examples
Implied Probability for All Outcomes
Spot Prices
Full Market State
Share Balance for a Wallet
Price Impact Estimation
Last updated
Was this helpful?
