Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/generate-mcp-tools/generate-tools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ function renderSchema(jsonSchema) {
const type = Array.isArray(prop.type)
? prop.type.join(" | ")
: (prop.type ?? "unknown");
const requiredStr = required.has(key) ? "βœ…" : "";
const requiredStr = required.has(key) ? "true" : "false";
const description = prop.description ?? "";
const defaultVal = prop.default !== undefined ? String(prop.default) : "";

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Add the following configuration to your MCP client settings (e.g., `claude_deskt
"args": ["-y", "@iqai/mcp-polymarket"],
"env": {
"POLYMARKET_PRIVATE_KEY": "your_private_key_here",
"POLYMARKET_RPC_URL": "https://polygon-mainnet.g.alchemy.com/v2/<YOUR_KEY>"
"POLYGON_RPC_URL": "https://polygon-mainnet.g.alchemy.com/v2/<YOUR_KEY>"
}
}
}
Expand All @@ -75,7 +75,7 @@ Add the following configuration to your MCP client settings (e.g., `claude_deskt
| Variable | Required | Description | Default |
| :--- | :--- | :--- | :--- |
| `POLYMARKET_PRIVATE_KEY` | No | Private key for trading (enables trading tools) | - |
| `POLYMARKET_RPC_URL` | No | Polygon RPC URL for transactions | `https://polygon-rpc.com` |
| `POLYGON_RPC_URL` | No | Polygon RPC URL for transactions | `https://polygon-rpc.com` |
| `CLOB_API_BASE` | No | Polymarket CLOB API base URL | `https://clob.polymarket.com` |
| `CHAIN_ID` | No | Blockchain network chain ID | `137` (Polygon) |
| `SIGNATURE_TYPE` | No | Signature type for signing transactions | `2` |
Expand Down
50 changes: 25 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ async function main() {
server.addTool(tools.redeemPositionsTool);
server.addTool(tools.getPositionsTool);

console.log(
"βœ… Trading features enabled (POLYMARKET_PRIVATE_KEY is configured)",
process.stderr.write(
"Trading features enabled (POLYMARKET_PRIVATE_KEY is configured)\n",
);
} else {
console.warn(
"ℹ️ Read-only mode: Set POLYMARKET_PRIVATE_KEY environment variable to enable trading features",
process.stderr.write(
"Read-only mode: Set POLYMARKET_PRIVATE_KEY environment variable to enable trading features\n",
);
}

Expand All @@ -57,6 +57,6 @@ async function main() {
}

main().catch((error) => {
console.error("🚨 Failed to start MCP server:", error);
console.error("Failed to start MCP server:", error);
process.exit(1);
});
14 changes: 7 additions & 7 deletions src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { tradeApi } from "./services/trading.js";
*/
async function placeMarketOrder() {
try {
console.log("πŸš€ Placing market order...");
console.log("Placing market order...");

// Market order parameters
const params = {
Expand All @@ -20,17 +20,17 @@ async function placeMarketOrder() {
amount: 1, // For BUY orders, this is the dollar amount ($USD) to spend
};

console.log("πŸ“‹ Order parameters:", JSON.stringify(params, null, 2));
console.log("Order parameters:", JSON.stringify(params, null, 2));

// Execute the market order
const result = await tradeApi.placeMarketOrder(params);

console.log("βœ… Market order placed successfully!");
console.log("πŸ“Š Result:", JSON.stringify(result, null, 2));
console.log("Market order placed successfully!");
console.log("Result:", JSON.stringify(result, null, 2));

return result;
} catch (error) {
console.error("❌ Error placing market order:", error);
console.error("Error placing market order:", error);

// Check if it's an approval error
if (error && typeof error === "object" && "message" in error) {
Expand All @@ -44,10 +44,10 @@ async function placeMarketOrder() {
// Run the script
placeMarketOrder()
.then(() => {
console.log("πŸŽ‰ Script completed successfully");
console.log("Script completed successfully");
process.exit(0);
})
.catch((error) => {
console.error("πŸ’₯ Script failed:", error);
console.error("Script failed:", error);
process.exit(1);
});
16 changes: 8 additions & 8 deletions src/services/approvals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,37 +187,37 @@ export class PolymarketApprovals {
{
key: "USDC_ALLOWANCE_FOR_CTF",
fn: () => usdc.approve(CTF_ADDRESS, constants.MaxUint256),
label: "USDC→CTF",
label: "USDC->CTF",
},
{
key: "USDC_ALLOWANCE_FOR_EXCHANGE",
fn: () => usdc.approve(EXCHANGE_ADDRESS, constants.MaxUint256),
label: "USDC→Exchange",
label: "USDC->Exchange",
},
{
key: "CTF_APPROVAL_FOR_EXCHANGE",
fn: () => ctf.setApprovalForAll(EXCHANGE_ADDRESS, true),
label: "CTF→Exchange",
label: "CTF->Exchange",
},
{
key: "USDC_ALLOWANCE_FOR_NEG_RISK_EXCHANGE",
fn: () => usdc.approve(NEG_RISK_EXCHANGE_ADDRESS, constants.MaxUint256),
label: "USDC→NegRiskExchange",
label: "USDC->NegRiskExchange",
},
{
key: "USDC_ALLOWANCE_FOR_NEG_RISK_ADAPTER",
fn: () => usdc.approve(NEG_RISK_ADAPTER_ADDRESS, constants.MaxUint256),
label: "USDC→NegRiskAdapter",
label: "USDC->NegRiskAdapter",
},
{
key: "CTF_APPROVAL_FOR_NEG_RISK_EXCHANGE",
fn: () => ctf.setApprovalForAll(NEG_RISK_EXCHANGE_ADDRESS, true),
label: "CTF→NegRiskExchange",
label: "CTF->NegRiskExchange",
},
{
key: "CTF_APPROVAL_FOR_NEG_RISK_ADAPTER",
fn: () => ctf.setApprovalForAll(NEG_RISK_ADAPTER_ADDRESS, true),
label: "CTF→NegRiskAdapter",
label: "CTF->NegRiskAdapter",
},
] as const;

Expand All @@ -226,7 +226,7 @@ export class PolymarketApprovals {
if (current.missing.includes(key)) {
const hash = await this.sendTx(fn, nonce++, waitConfs);
txHashes.push(hash);
console.log(`Approved ${label}: ${hash}`);
process.stderr.write(`Approved ${label}: ${hash}\n`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function getConfig(overrides: Partial<BaseConfig> = {}): BaseConfig {

const rpcUrl =
overrides.rpcUrl ??
process.env.POLYMARKET_RPC_URL ??
process.env.POLYGON_RPC_URL ??
Comment thread
Timonwa marked this conversation as resolved.
"https://polygon-rpc.com";

const privateKey = overrides.privateKey ?? process.env.POLYMARKET_PRIVATE_KEY;
Expand Down
16 changes: 8 additions & 8 deletions src/services/redemption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class PolymarketRedemption {
"No CTF tokens to redeem. Balance is 0 - position may have already been redeemed.",
};
}
console.log(`Token balance: ${tokenBalance.toString()}`);
process.stderr.write(`Token balance: ${tokenBalance.toString()}` + "\n");
}

// Check if market is resolved
Expand Down Expand Up @@ -220,9 +220,9 @@ export class PolymarketRedemption {
amounts = [tokenBalance, 0n];
}

console.log(`Redeeming negRisk position:`);
console.log(` Condition ID: ${conditionIdBytes32}`);
console.log(` Amounts: [${amounts[0]}, ${amounts[1]}]`);
process.stderr.write(`Redeeming negRisk position:` + "\n");
process.stderr.write(` Condition ID: ${conditionIdBytes32}` + "\n");
process.stderr.write(` Amounts: [${amounts[0]}, ${amounts[1]}]` + "\n");

const negRiskAdapter = this.getNegRiskAdapterContract();
tx = await negRiskAdapter.redeemPositions(conditionIdBytes32, amounts, {
Expand All @@ -240,9 +240,9 @@ export class PolymarketRedemption {
};
}

console.log(`Redeeming CTF position:`);
console.log(` Condition ID: ${conditionIdBytes32}`);
console.log(` Winning index sets: [${winningIndexSets.join(", ")}]`);
process.stderr.write(`Redeeming CTF position:` + "\n");
process.stderr.write(` Condition ID: ${conditionIdBytes32}` + "\n");
process.stderr.write(` Winning index sets: [${winningIndexSets.join(", ")}]` + "\n");

const ctf = this.getCtfContract();
tx = await ctf.redeemPositions(
Expand All @@ -256,7 +256,7 @@ export class PolymarketRedemption {
);
}

console.log(`Transaction submitted: ${tx.hash}`);
process.stderr.write(`Transaction submitted: ${tx.hash}` + "\n");

// Wait for confirmation
const receipt = await tx.wait(1);
Expand Down
26 changes: 13 additions & 13 deletions src/services/trading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ export class PolymarketTrading {
cfg.funderAddress,
);

console.log("βœ“ Polymarket trading client initialized");
console.log(` - Signer: ${await ethersSigner.getAddress()}`);
console.log(` - Signature Type: ${cfg.signatureType}`);
process.stderr.write("Polymarket trading client initialized");
process.stderr.write(` - Signer: ${await ethersSigner.getAddress()}` + "\n");
process.stderr.write(` - Signature Type: ${cfg.signatureType}` + "\n");
if (cfg.funderAddress) {
console.log(` - Funder/Proxy: ${cfg.funderAddress}`);
process.stderr.write(` - Funder/Proxy: ${cfg.funderAddress}` + "\n");
}
}

Expand Down Expand Up @@ -253,11 +253,11 @@ export class PolymarketTrading {

const client = this.getClient();

console.log(`πŸ“ Placing ${args.side} order:`);
console.log(` Token: ${args.tokenId}`);
console.log(` Price: ${args.price}`);
console.log(` Size: ${args.size}`);
console.log(
process.stderr.write(`Placing ${args.side} order:` + "\n");
process.stderr.write(` Token: ${args.tokenId}` + "\n");
process.stderr.write(` Price: ${args.price}` + "\n");
process.stderr.write(` Size: ${args.size}` + "\n");
process.stderr.write(
` Market: negRisk=${marketParams.negRisk}, tickSize=${marketParams.tickSize}`,
);

Expand Down Expand Up @@ -304,10 +304,10 @@ export class PolymarketTrading {

const client = this.getClient();

console.log(`πŸš€ Placing ${args.side} market order:`);
console.log(` Token: ${args.tokenId}`);
console.log(` Amount: ${args.amount}`);
console.log(
process.stderr.write(`Placing ${args.side} market order:` + "\n");
process.stderr.write(` Token: ${args.tokenId}` + "\n");
process.stderr.write(` Amount: ${args.amount}` + "\n");
process.stderr.write(
` Market: negRisk=${marketParams.negRisk}, tickSize=${marketParams.tickSize}`,
);

Expand Down