Split / Merge / Redeem

Build, sign, and submit Safe transactions for on-chain token operations.

All four operations follow the same pattern: build the transaction, have the user sign it, then submit.

Common Signing Pattern

import { BuilderClient, UserClient } from '@opinion-labs/opinion-clob-sdk';

const builder = new BuilderClient({
  host: 'https://openapi.opinion.trade/openapi',
  builderApiKey: 'YOUR_BUILDER_KEY',
  chainId: 56,
  rpcUrl: 'https://bsc-dataseed.binance.org',
});

// Build any Safe TX (split, merge, redeem, or withdraw)
const txResult = await builder.buildSplitTx(safeAddress, collateral, conditionId, amount);

// User signs the EIP-712 typed data
const user = new UserClient('0xUserPrivateKey...');
const signature = await user.signTypedData(txResult.eip712Data);

// Submit to backend for relay
const result = await builder.submitSafeTx(userAddress, txResult, signature);

Split Position

Convert quote tokens (e.g., USDC) into Yes and No outcome tokens.

Parameter
Type
Required
Description

safeAddress

string

Yes

User's Safe wallet address

collateralToken

string

Yes

Quote token contract address

conditionId

string

Yes

Market condition ID

amount

bigint

Yes

Amount in wei

partition

number[]

No

Outcome partition (default: [1, 2] for binary markets)

Merge Position

Convert equal amounts of Yes and No tokens back into quote tokens.

Parameter
Type
Required
Description

safeAddress

string

Yes

User's Safe wallet address

collateralToken

string

Yes

Quote token contract address

conditionId

string

Yes

Market condition ID

amount

bigint

Yes

Amount in wei

partition

number[]

No

Outcome partition (default: [1, 2])

Redeem Position

Claim winnings from a resolved market. Converts winning outcome tokens back to quote tokens.

Parameter
Type
Required
Description

safeAddress

string

Yes

User's Safe wallet address

collateralToken

string

Yes

Quote token contract address

conditionId

string

Yes

Market condition ID

partition

number[]

No

Outcome partition (default: [1, 2])

Withdraw Tokens

Transfer ERC20 tokens from the Safe wallet to any address.

Parameter
Type
Required
Description

safeAddress

string

Yes

User's Safe wallet address

tokenAddress

string

Yes

ERC20 token contract address

amount

bigint

Yes

Amount in wei

toAddress

string

Yes

Recipient address

Submit Safe Transaction

All build methods return a SafeTxResult. Submit it with a user signature:

Parameter
Type
Required
Description

walletAddress

string

Yes

User's wallet address (Safe owner EOA)

safeTxResult

SafeTxResult

Yes

Result from any build*Tx() method

signature

string

Yes

User's signature on the EIP-712 data

Test Helper

For testing, sign Safe transactions with a private key:

Notes

  • All Safe TX operations require rpcUrl in the BuilderClient config.

  • Transactions are relayed by the backend -- no gas required from the user.

  • Safe TX signing uses user.signTypedData(eip712Data), not signHash().

  • For amount conversions, use safeAmountToWei() from the SDK:

  • The conditionId for split, merge, and redeem is available from getMarket().

  • Redeem only works on resolved markets with winning outcome tokens.