Initialize SDK
- TypeScript
- Python
import { OricaSDK } from "@neko/orica-sdk";
import { Connection } from "@solana/web3.js";
const connection = new Connection("https://api.mainnet-beta.solana.com");
const sdk = await OricaSDK.createFromChain(connection);
from orica_sdk import OricaSDK
from solana.rpc.async_api import AsyncClient
connection = AsyncClient("https://api.mainnet-beta.solana.com")
sdk = await OricaSDK.create(connection)
Fetch All Markets
- TypeScript
- Python
const markets = await sdk.orica.fetchAllMarkets();
for (const { publicKey, account } of markets) {
console.log(account.question);
console.log("Close time:", new Date(account.closeTime.toNumber() * 1000));
}
markets = await sdk.orica.fetch_all_markets()
for address, market in markets:
print(market.question)
print(f"Close time: {market.close_time}")
Fetch Single Market
- TypeScript
- Python
const marketAddress = new PublicKey("ABC123...");
const market = await sdk.orica.fetchMarket(marketAddress);
console.log("Question:", market.question);
console.log("Options:", market.optionNames);
console.log("Status:", market.status);
market_address = Pubkey.from_string("ABC123...")
market = await sdk.orica.fetch_market(market_address)
print(f"Question: {market.question}")
print(f"Options: {market.option_names}")
print(f"Status: {market.status.value}")
Get Market Prices
- TypeScript
- Python
const prices = sdk.orica.calculatePrices(market);
console.log("Prices:", prices); // [0.65, 0.35] for binary market
prices = sdk.orica.calculate_prices(market)
print(f"Prices: {prices}") # [0.65, 0.35] for binary market
Buy Shares
- TypeScript
- Python
import { BN } from "@coral-xyz/anchor";
import { Transaction } from "@solana/web3.js";
const amount = new BN(1_000_000); // 1 USDC
const outcomeIndex = 0; // Buy first outcome
const instructions = await sdk.orica.buildBuy(
wallet.publicKey,
userUsdcAccount,
marketAddress,
amount,
outcomeIndex
);
const tx = new Transaction().add(...instructions);
const sig = await connection.sendTransaction(tx, [wallet]);
from solana.transaction import Transaction
amount = 1_000_000 # 1 USDC
outcome_index = 0 # Buy first outcome
instructions = await sdk.orica.build_buy(
user=wallet.pubkey(),
user_usdc=user_usdc_account,
market_address=market_pubkey,
amount=amount,
outcome_index=outcome_index,
)
tx = Transaction()
tx.add(*instructions)
sig = await connection.send_transaction(tx, wallet)
Sell Shares
- TypeScript
- Python
const sharesToSell = new BN(5000);
const outcomeIndex = 0;
const instructions = await sdk.orica.buildSell(
wallet.publicKey,
userUsdcAccount,
marketAddress,
sharesToSell,
outcomeIndex
);
const tx = new Transaction().add(...instructions);
await connection.sendTransaction(tx, [wallet]);
shares_to_sell = 5000
outcome_index = 0
instructions = await sdk.orica.build_sell(
user=wallet.pubkey(),
user_usdc=user_usdc_account,
market_address=market_pubkey,
shares=shares_to_sell,
outcome_index=outcome_index,
)
tx = Transaction()
tx.add(*instructions)
await connection.send_transaction(tx, wallet)
Check Position
- TypeScript
- Python
const position = await sdk.orica.fetchPosition(marketAddress, wallet.publicKey);
if (position) {
console.log("Yes shares:", position.outcomeAmounts[0].toString());
console.log("No shares:", position.outcomeAmounts[1].toString());
} else {
console.log("No position in this market");
}
position = await sdk.orica.fetch_position(market_address, wallet.pubkey())
if position:
print(f"Yes shares: {position.outcome_amounts[0]}")
print(f"No shares: {position.outcome_amounts[1]}")
else:
print("No position in this market")
Redeem Winnings
- TypeScript
- Python
const instruction = await sdk.orica.buildRedeem(
wallet.publicKey,
userUsdcAccount,
marketAddress
);
const tx = new Transaction().add(instruction);
await connection.sendTransaction(tx, [wallet]);
instruction = await sdk.orica.build_redeem(
user=wallet.pubkey(),
user_usdc=user_usdc_account,
market_address=market_pubkey,
)
tx = Transaction()
tx.add(instruction)
await connection.send_transaction(tx, wallet)
Vote on Dispute
- TypeScript
- Python
const [globalState] = sdk.orica.pda.globalState();
const [position] = sdk.orica.pda.position(marketAddress, wallet.publicKey);
const instruction = await sdk.disputes.buildVoteForDispute(
wallet.publicKey,
marketAddress,
position,
globalState
);
const tx = new Transaction().add(instruction);
await connection.sendTransaction(tx, [wallet]);
global_state, _ = sdk.orica.pda.global_state()
position, _ = sdk.orica.pda.position(market_address, wallet.pubkey())
instruction = await sdk.disputes.build_vote_for_dispute(
user=wallet.pubkey(),
market=market_address,
position=position,
global_state=global_state,
)
tx = Transaction()
tx.add(instruction)
await connection.send_transaction(tx, wallet)
Post Dispute Message
- TypeScript
- Python
const content = "The resolution is incorrect because...";
const encoder = new TextEncoder();
const hashBuffer = await crypto.subtle.digest('SHA-256', encoder.encode(content));
const messageHash = Array.from(new Uint8Array(hashBuffer));
const [globalState] = sdk.orica.pda.globalState();
const [position] = sdk.orica.pda.position(marketAddress, wallet.publicKey);
const instruction = await sdk.disputes.buildPostMessage(
wallet.publicKey,
marketAddress,
position,
globalState,
messageHash,
content,
null // No parent message
);
const tx = new Transaction().add(instruction);
await connection.sendTransaction(tx, [wallet]);
import hashlib
content = "The resolution is incorrect because..."
message_hash = hashlib.sha256(content.encode()).digest()
global_state, _ = sdk.orica.pda.global_state()
position, _ = sdk.orica.pda.position(market_address, wallet.pubkey())
instruction = await sdk.disputes.build_post_message(
author=wallet.pubkey(),
market=market_address,
position=position,
global_state=global_state,
message_hash=message_hash,
ipfs_uri="ipfs://...",
parent_message=None,
)
tx = Transaction()
tx.add(instruction)
await connection.send_transaction(tx, wallet)
Fetch Disputes
- TypeScript
- Python
const disputes = await sdk.disputes.fetchAllDisputes();
for (const { publicKey, account } of disputes) {
console.log(`Market: ${account.market.toBase58()}`);
console.log(`Status: ${account.status}`);
}
disputes = await sdk.disputes.fetch_all_disputes()
for address, dispute in disputes:
print(f"Market: {dispute.market}")
print(f"Status: {dispute.status.value}")