internet-court/internet-court-skill / vendored/pnp/pnp-solana
pnp-markets-solana
FlaggedCreate, trade, and settle permissionless prediction markets on Solana. Use when building prediction market infrastructure, creating social media markets (Twitter/YouTube/DeFiLlama), setting up custom oracle resolution, P2P betting, or autonomous agent-driven forecasting. Supports V2 AMM, P2P (V3), and custom oracle markets with any SPL token collateral (including Token-2022).
| File | Kind | Size |
|---|---|---|
| .gitignore | other | 272 B |
| LICENSE | other | 1.6 KB |
| README.md | markdown | 3.5 KB |
| SKILL.md | skill md | 29.5 KB |
| package-lock.json | manifest | 69.8 KB |
| package.json | manifest | 52 B |
| references/api-reference.md | markdown | 15.7 KB |
| references/examples.md | markdown | 6.3 KB |
| references/program-addresses.md | markdown | 7.4 KB |
| references/types-and-precision.md | markdown | 7.3 KB |
| references/use-cases.md | markdown | 4.1 KB |
| scripts/create-market-custom.ts | script | 1.5 KB |
| scripts/create-market-p2p.ts | script | 4.0 KB |
| scripts/create-market-x.ts | script | 1.5 KB |
| scripts/create-market-yt.ts | script | 1.4 KB |
| scripts/create-market.ts | script | 1.4 KB |
| scripts/market-data.ts | script | 3.5 KB |
| scripts/package.json | manifest | 549 B |
| scripts/redeem.ts | script | 3.0 KB |
| scripts/settle.ts | script | 5.5 KB |
| scripts/trade.ts | script | 5.8 KB |
| scripts/tsconfig.json | config | 346 B |
scripts/trade.ts
View on GitHub#!/usr/bin/env npx ts-node
/**
* Trade on a prediction market (buy/sell YES or NO tokens) on Solana
* Run with --help for usage
*/
import { PNPClient } from "pnp-sdk";
import { PublicKey } from "@solana/web3.js";
interface Args {
market: string;
action: "buy" | "sell";
outcome: "YES" | "NO";
amount: string;
decimals: number;
help?: boolean;
info?: boolean;
}
function printHelp(): void {
console.log(`
PNP Markets (Solana) - Trade on Market
USAGE:
npx ts-node trade.ts [OPTIONS]
ACTIONS:
--buy Buy outcome tokens with collateral
--sell Sell outcome tokens for collateral
REQUIRED:
--market <address> Market address (base58)
--outcome <YES|NO> Outcome to trade
--amount <number> Amount to trade (in collateral token units)
OPTIONAL:
--decimals <number> Token decimals (default: 6 for USDC)
--info Show market info only, don't trade
--help Show this help message
ENVIRONMENT:
PRIVATE_KEY Solana wallet private key (base58)
RPC_URL Solana RPC endpoint (optional)
EXAMPLES:
# Buy YES tokens with 10 USDC
npx ts-node trade.ts --buy --market <address> --outcome YES --amount 10
# Sell 5 NO tokens
npx ts-node trade.ts --sell --market <address> --outcome NO --amount 5
# Check market prices
npx ts-node trade.ts --info --market <address>
`);
}
function parseArgs(): Args {
const args = process.argv.slice(2);
const parsed: Partial<Args> = {};
for (let i = 0; i < args.length; i++) {
switch (args[i]) {
case "--help":
case "-h":
parsed.help = true;
break;
case "--info":
parsed.info = true;
break;
case "--buy":
parsed.action = "buy";
break;
case "--sell":
parsed.action = "sell";
break;
case "--market":
parsed.market = args[++i];
break;
case "--outcome":
parsed.outcome = args[++i]?.toUpperCase() as "YES" | "NO";
break;
case "--amount":
parsed.amount = args[++i];
break;
case "--decimals":
parsed.decimals = parseInt(args[++i], 10);
break;
}
}
return {
market: parsed.market || "",
action: parsed.action || "buy",
outcome: parsed.outcome || "YES",
amount: parsed.amount || "0",
decimals: parsed.decimals ?? 6,
help: parsed.help,
info: parsed.info,
};
}
async function main(): Promise<void> {
const args = parseArgs();
if (args.help) {
printHelp();
process.exit(0);
}
if (!args.market) {
console.error("Error: --market is required");
printHelp();
process.exit(1);
}
// Validate market address
let marketPubkey: PublicKey;
try {
marketPubkey = new PublicKey(args.market);
} catch {
console.error("Error: Invalid market address");
process.exit(1);
}
const rpcUrl = process.env.RPC_URL || "https://api.mainnet-beta.solana.com";
// For info-only, we can use read-only client
const client = args.info && !process.env.PRIVATE_KEY
? new PNPClient(rpcUrl)
: new PNPClient(rpcUrl, process.env.PRIVATE_KEY);
if (!args.info && !process.env.PRIVATE_KEY) {
console.error("Error: PRIVATE_KEY environment variable is required for trading");
process.exit(1);
}
// Fetch market info
console.log("\nπ Market Info\n");
try {
const prices = await client.getMarketPriceV2(marketPubkey);
console.log(`Market: ${args.market}`);
console.log(`YES Price: ${(Number(prices.yesPrice) * 100).toFixed(2)}%`);
console.log(`NO Price: ${(Number(prices.noPrice) * 100).toFixed(2)}%`);
if (args.info) {
console.log("\n--- JSON OUTPUT ---");
console.log(JSON.stringify({
market: args.market,
yesPrice: prices.yesPrice,
noPrice: prices.noPrice,
yesPricePercent: `${(Number(prices.yesPrice) * 100).toFixed(2)}%`,
noPricePercent: `${(Number(prices.noPrice) * 100).toFixed(2)}%`,
}, null, 2));
process.exit(0);
}
// Validate trade params
if (!args.amount || parseFloat(args.amount) <= 0) {
console.error("\nError: --amount must be a positive number");
process.exit(1);
}
if (args.outcome !== "YES" && args.outcome !== "NO") {
console.error("\nError: --outcome must be YES or NO");
process.exit(1);
}
console.log(`\nπ± Executing ${args.action.toUpperCase()}\n`);
console.log(`Action: ${args.action.toUpperCase()} ${args.outcome}`);
console.log(`Amount: ${args.amount}`);
console.log("");
let signature: string | undefined;
if (args.action === "buy") {
const result = await client.trading!.buyTokensUsdc({
market: marketPubkey,
buyYesToken: args.outcome === "YES",
amountUsdc: parseFloat(args.amount),
});
signature = result.signature;
} else {
// For selling, use burnDecisionTokensDerived
const amountRaw = BigInt(Math.floor(parseFloat(args.amount) * Math.pow(10, 18))); // Tokens have 18 decimals
const result = await client.trading!.burnDecisionTokensDerived({
market: marketPubkey,
amount: amountRaw,
burnYesToken: args.outcome === "YES",
});
signature = result.signature;
}
console.log("β
Trade Executed!\n");
console.log(`Signature: ${signature}`);
console.log(`\nSolscan: https://solscan.io/tx/${signature}`);
// Show updated prices
const newPrices = await client.getMarketPriceV2(marketPubkey);
console.log(`\nUpdated Prices:`);
console.log(` YES: ${(Number(newPrices.yesPrice) * 100).toFixed(2)}%`);
console.log(` NO: ${(Number(newPrices.noPrice) * 100).toFixed(2)}%`);
} catch (error: any) {
console.error("\nβ Failed:", error.message);
process.exit(1);
}
}
main();
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path β even casually (like "the xlsx in my downloads") β and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |