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 the Gateway contract, which is the single entry point for all on-chain interactions.

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 uses Dynamic Parimutuel (DPM) markets. This means:

  • Prices shift continuously with every trade (no fixed order book)

  • spotImpliedProbability reflects the market's current consensus probability

  • For a binary market: prob[0] + prob[1] = 1e18 (100%)

  • A spot price of 0.65 USDC/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.

Buying Shares

Token approval must exist before buying. The full flow with approval and slippage looks like this:

BuyShares (params)

Field
Type
Description

marketAddress

`0x${string}`

Market proxy address

outcomeIdx

number

Outcome index to buy

sharesOut

bigint

Exact shares to receive (18 decimals)

maxTokensIn

bigint

Max USDC to spend — slippage cap (6 decimals)

Selling Shares

SellShares (params)

Field
Type
Description

marketAddress

`0x${string}`

Market proxy address

outcomeIdx

number

Outcome index to sell

sharesIn

bigint

Exact shares to sell (18 decimals)

minTokensOut

bigint

Min USDC to receive — slippage floor (6 decimals)

Slippage Guidelines

Scenario
Recommended slippage

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

Error
Cause
Fix

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

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.

This defaults to unlimited (uint256 max).

ensureTokenApproval(params)

Check if sufficient allowance exists and only sends an approval transaction if needed. Recommended before buying shares.

Gateway Contract Reference

This section is for advanced users who want to call the Gateway contract directly via viem.

viem Client Setup

Set up your viem client like this:

Gateway Functions

All of the gateway functions, broken down into tables by [1] read and [2] write.

1. Read Functions

Function
Args
Returns
Notes

quoteBuyExactOut

marketProxy, outcomeIdx, sharesOut

tokensIn: uint256

USDC cost (6 dec)

quoteSellExactIn

marketProxy, outcomeIdx, sharesIn

tokensOut: uint256

USDC payout (6 dec)

spotImpliedProbability

marketProxy, outcomeIdx

uint256

1e18 = 100%

spotImpliedProbabilities

marketProxy, outcomeIndices[]

uint256[]

Batch

spotPrice

marketProxy, outcomeIdx

uint256

1e18 = 1.0 USDC/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=Closed, 2=Settled

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.

Function
Args
Notes

buyExactOut

marketProxy, outcomeIdx, sharesOut, maxTokensIn

Use DelphiClient.buyShares()

sellExactIn

marketProxy, outcomeIdx, sharesIn, minTokensOut

Use DelphiClient.sellShares()

redeem

marketProxy

Use DelphiClient.redeemMarket()

Direct Read Examples

Implied Probability for All Outcomes

Spot Prices

Full Market State

Share Balance for a Wallet

Price Impact Estimation

Last updated