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 |
references/examples.md
View on GitHub# PNP Markets - Complete Examples (Solana)
## Full Market Lifecycle
```typescript
import { PNPClient } from "pnp-sdk";
import { PublicKey } from "@solana/web3.js";
async function fullLifecycle() {
const client = new PNPClient(
process.env.RPC_URL || "https://api.mainnet-beta.solana.com",
process.env.PRIVATE_KEY!
);
const USDC = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
// 1. CREATE MARKET
console.log("Creating market...");
const { market, signature } = await client.market.createMarket({
question: "Will our community reach 1000 members this month?",
endTime: BigInt(Math.floor(Date.now() / 1000) + 86400 * 7),
initialLiquidity: 50_000_000n, // 50 USDC
baseMint: USDC,
});
console.log("Market created:", market.toBase58());
// 2. CHECK PRICES
const prices = await client.getMarketPriceV2(market);
console.log("YES:", (prices.yesPrice * 100).toFixed(2) + "%");
console.log("NO:", (prices.noPrice * 100).toFixed(2) + "%");
// 3. BUY TOKENS
await client.trading.buyTokensUsdc({
market,
buyYesToken: true,
amountUsdc: 10,
});
console.log("Bought YES tokens");
// 4. SELL TOKENS (partial)
await client.trading.sellTokensUsdc({
market,
sellYesToken: true,
amountTokens: 2_000_000_000_000_000_000n, // 2 tokens
});
console.log("Sold some YES tokens");
// 5. SETTLE (after endTime, for custom oracle markets)
await client.settleMarket({ market, yesWinner: true });
console.log("Market settled as YES");
// 6. REDEEM
await client.redeemPosition(market);
console.log("Winnings redeemed");
}
```
## P2P Market Example
```typescript
import { PNPClient } from "pnp-sdk";
import { PublicKey } from "@solana/web3.js";
async function p2pMarketExample() {
const client = new PNPClient(
process.env.RPC_URL || "https://api.mainnet-beta.solana.com",
process.env.PRIVATE_KEY!
);
const USDC = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
// Create P2P market where creator bets YES
const { market, signature } = await client.createP2PMarketGeneral({
question: "Will our DAO pass Proposal #42?",
initialAmount: 100_000_000n, // 100 USDC
side: "yes",
creatorSideCap: 500_000_000n, // Max 500 USDC on YES side
endTime: BigInt(Math.floor(Date.now() / 1000) + 86400 * 14),
collateralTokenMint: USDC,
});
console.log("P2P Market:", market.toBase58());
// Counter-party takes NO side
await client.tradeP2PMarket({
market,
side: "no",
amount: 50_000_000n, // 50 USDC
});
}
```
## Custom Token Collateral
```typescript
import { PNPClient } from "pnp-sdk";
import { PublicKey } from "@solana/web3.js";
async function customTokenMarket() {
const client = new PNPClient(
process.env.RPC_URL || "https://api.mainnet-beta.solana.com",
process.env.PRIVATE_KEY!
);
const MY_TOKEN = new PublicKey("YourTokenMintAddress");
const TOKEN_DECIMALS = 9;
const { market } = await client.market.createMarket({
question: "Will our DAO pass Proposal #42?",
endTime: BigInt(Math.floor(Date.now() / 1000) + 86400 * 14),
initialLiquidity: BigInt(10000 * Math.pow(10, TOKEN_DECIMALS)),
baseMint: MY_TOKEN,
});
console.log("Market with custom token:", market.toBase58());
}
```
## Market Monitoring
```typescript
import { PNPClient } from "pnp-sdk";
import { PublicKey } from "@solana/web3.js";
async function monitorMarket(marketAddress: string) {
// Read-only client (no private key needed)
const client = new PNPClient(
process.env.RPC_URL || "https://api.mainnet-beta.solana.com"
);
const market = new PublicKey(marketAddress);
const info = await client.getMarketInfo(market);
const prices = await client.getMarketPriceV2(market);
return {
market: marketAddress,
endTime: new Date(Number(info.endTime) * 1000),
yesPrice: (prices.yesPrice * 100).toFixed(2) + "%",
noPrice: (prices.noPrice * 100).toFixed(2) + "%",
isSettled: info.isSettled,
winner: info.isSettled ? (info.yesWinner ? "YES" : "NO") : null,
};
}
```
## Trading Bot Pattern
```typescript
import { PNPClient } from "pnp-sdk";
import { PublicKey } from "@solana/web3.js";
async function simpleTradingStrategy(marketAddress: string) {
const client = new PNPClient(
process.env.RPC_URL || "https://api.mainnet-beta.solana.com",
process.env.PRIVATE_KEY!
);
const market = new PublicKey(marketAddress);
const prices = await client.getMarketPriceV2(market);
// Simple strategy: buy YES if price < 0.3, buy NO if YES price > 0.7
const tradeAmount = 5; // 5 USDC
if (prices.yesPrice < 0.3) {
console.log("YES undervalued, buying...");
await client.trading.buyTokensUsdc({
market,
buyYesToken: true,
amountUsdc: tradeAmount,
});
} else if (prices.yesPrice > 0.7) {
console.log("NO undervalued, buying...");
await client.trading.buyTokensUsdc({
market,
buyYesToken: false,
amountUsdc: tradeAmount,
});
} else {
console.log("No trade signal");
}
}
```
## Batch Market Creation
```typescript
import { PNPClient } from "pnp-sdk";
import { PublicKey } from "@solana/web3.js";
interface MarketConfig {
question: string;
durationHours: number;
liquidity: number;
}
async function createBatchMarkets(configs: MarketConfig[]) {
const client = new PNPClient(
process.env.RPC_URL || "https://api.mainnet-beta.solana.com",
process.env.PRIVATE_KEY!
);
const USDC = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
const results = [];
for (const config of configs) {
const endTime = BigInt(Math.floor(Date.now() / 1000) + config.durationHours * 3600);
const liquidity = BigInt(config.liquidity * 1_000_000);
const { market, signature } = await client.market.createMarket({
question: config.question,
endTime,
initialLiquidity: liquidity,
baseMint: USDC,
});
results.push({
question: config.question,
market: market.toBase58(),
signature,
});
// Brief pause between transactions
await new Promise(r => setTimeout(r, 500));
}
return results;
}
// Usage
const markets = await createBatchMarkets([
{ question: "Will BTC hit $100k in 2025?", durationHours: 720, liquidity: 100 },
{ question: "Will ETH flip BTC by 2026?", durationHours: 8760, liquidity: 100 },
{ question: "Will Solana TPS exceed 100k?", durationHours: 2160, liquidity: 50 },
]);
```
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 |