Skip to content

feat: Add Polymarket connector with Gamma API integration#109

Open
vale9888 wants to merge 1 commit intoStackOneHQ:mainfrom
vale9888:valentinaSDev
Open

feat: Add Polymarket connector with Gamma API integration#109
vale9888 wants to merge 1 commit intoStackOneHQ:mainfrom
vale9888:valentinaSDev

Conversation

@vale9888
Copy link

@vale9888 vale9888 commented Aug 28, 2025

Team 18!

  • Add Polymarket connector with 7 tools for prediction markets
  • Implement Gamma API client with proper error handling
  • Add comprehensive test suite following project standards
  • Update TypeScript config to include DOM lib for fetch support
  • Add detailed integration plan documentation
  • Support both public data (no API key) and private data (with API key)
  • Tools include: get markets, search markets, trending markets, user profile, positions, trade history

Summary by cubic

Add a Polymarket connector powered by the Gamma API, exposing 7 tools for prediction markets with solid error handling and full tests. Public data works without a key; user tools require an API key.

  • New Features

    • Polymarket connector with 7 tools: get markets, get market, search, trending, user profile, positions, trade history.
    • Gamma API client with consistent errors and readable output formatting.
    • Comprehensive tests using MSW; detailed integration plan docs.
    • Connector exported in index; fetch enabled via DOM lib in tsconfig.
  • Migration

    • No breaking changes.
    • Set the apiKey credential to use user-specific tools (profile, positions, trade history).

- Add Polymarket connector with 7 tools for prediction markets
- Implement Gamma API client with proper error handling
- Add comprehensive test suite following project standards
- Update TypeScript config to include DOM lib for fetch support
- Add detailed integration plan documentation
- Support both public data (no API key) and private data (with API key)
- Tools include: get markets, search markets, trending markets, user profile, positions, trade history
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 5 files

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

{
"compilerOptions": {
"lib": ["ESNext"],
"lib": ["ESNext", "DOM"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including DOM in lib for a Node package is unnecessary with @types/node v22 and can pollute globals or cause subtle type conflicts; rely on Node’s fetch types instead.

(Based on your PR description about enabling fetch support by adding the DOM lib.)

Prompt for AI agents
Address the following comment on packages/mcp-connectors/tsconfig.json at line 3:

<comment>Including DOM in lib for a Node package is unnecessary with @types/node v22 and can pollute globals or cause subtle type conflicts; rely on Node’s fetch types instead.

(Based on your PR description about enabling fetch support by adding the DOM lib.)</comment>

<file context>
@@ -1,6 +1,6 @@
 {
     &quot;compilerOptions&quot;: {
-        &quot;lib&quot;: [&quot;ESNext&quot;],
+        &quot;lib&quot;: [&quot;ESNext&quot;, &quot;DOM&quot;],
         &quot;target&quot;: &quot;ESNext&quot;,
         &quot;module&quot;: &quot;ESNext&quot;,
</file context>

it('returns formatted markets list', async () => {
const tool = PolymarketConnectorConfig.tools.GET_MARKETS as MCPToolDefinition;
const mockContext = createMockConnectorContext({
apiKey: 'test-api-key',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded API key ('test-api-key') found in test file; secrets should not be committed to source control.

Prompt for AI agents
Address the following comment on packages/mcp-connectors/src/connectors/polymarket.spec.ts at line 126:

<comment>Hardcoded API key (&#39;test-api-key&#39;) found in test file; secrets should not be committed to source control.</comment>

<file context>
@@ -0,0 +1,406 @@
+        it(&#39;returns formatted markets list&#39;, async () =&gt; {
+          const tool = PolymarketConnectorConfig.tools.GET_MARKETS as MCPToolDefinition;
+          const mockContext = createMockConnectorContext({
+            apiKey: &#39;test-api-key&#39;,
+          });
+
</file context>

Outcome ID: ${pos.outcomeId}
Amount: ${pos.amount}
Average Price: $${pos.averagePrice}
${pos.unrealizedPnL ? `Unrealized P&L: $${pos.unrealizedPnL.toLocaleString()}` : ''}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zero value hidden by truthiness check; check for undefined/null instead so 0 is shown.

Prompt for AI agents
Address the following comment on packages/mcp-connectors/src/connectors/polymarket.ts at line 382:

<comment>Zero value hidden by truthiness check; check for undefined/null instead so 0 is shown.</comment>

<file context>
@@ -0,0 +1,431 @@
+   Outcome ID: ${pos.outcomeId}
+   Amount: ${pos.amount}
+   Average Price: $${pos.averagePrice}
+   ${pos.unrealizedPnL ? `Unrealized P&amp;L: $${pos.unrealizedPnL.toLocaleString()}` : &#39;&#39;}`
+          ).join(&#39;\n\n&#39;);
+          
</file context>

return `User Profile:
Username: ${user.username || 'N/A'}
Balance: $${user.balance.toLocaleString()}
${user.totalPnL ? `Total P&L: $${user.totalPnL.toLocaleString()}` : ''}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zero value hidden by truthiness check; use an undefined/null check so 0 is displayed correctly.

Prompt for AI agents
Address the following comment on packages/mcp-connectors/src/connectors/polymarket.ts at line 352:

<comment>Zero value hidden by truthiness check; use an undefined/null check so 0 is displayed correctly.</comment>

<file context>
@@ -0,0 +1,431 @@
+          return `User Profile:
+Username: ${user.username || &#39;N/A&#39;}
+Balance: $${user.balance.toLocaleString()}
+${user.totalPnL ? `Total P&amp;L: $${user.totalPnL.toLocaleString()}` : &#39;&#39;}
+Active Positions: ${user.positions.length}`;
+        } catch (error) {
</file context>

}

const formatted = markets.map((market, index) => {
const topOutcome = market.outcomes.reduce((prev, current) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible crash: reduce on potentially empty outcomes array; guard for empty outcomes before reducing or provide a safe fallback.

Prompt for AI agents
Address the following comment on packages/mcp-connectors/src/connectors/polymarket.ts at line 216:

<comment>Possible crash: reduce on potentially empty outcomes array; guard for empty outcomes before reducing or provide a safe fallback.</comment>

<file context>
@@ -0,0 +1,431 @@
+  }
+
+  const formatted = markets.map((market, index) =&gt; {
+    const topOutcome = market.outcomes.reduce((prev, current) =&gt; 
+      current.probability &gt; prev.probability ? current : prev
+    );
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant