@catalyst-team/poly-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +0 -0
- package/README.md +803 -0
- package/dist/__tests__/clob-api.test.d.ts +5 -0
- package/dist/__tests__/clob-api.test.d.ts.map +1 -0
- package/dist/__tests__/clob-api.test.js +240 -0
- package/dist/__tests__/clob-api.test.js.map +1 -0
- package/dist/__tests__/integration/bridge-client.integration.test.d.ts +11 -0
- package/dist/__tests__/integration/bridge-client.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/bridge-client.integration.test.js +260 -0
- package/dist/__tests__/integration/bridge-client.integration.test.js.map +1 -0
- package/dist/__tests__/integration/clob-api.integration.test.d.ts +13 -0
- package/dist/__tests__/integration/clob-api.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/clob-api.integration.test.js +170 -0
- package/dist/__tests__/integration/clob-api.integration.test.js.map +1 -0
- package/dist/__tests__/integration/ctf-client.integration.test.d.ts +17 -0
- package/dist/__tests__/integration/ctf-client.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/ctf-client.integration.test.js +234 -0
- package/dist/__tests__/integration/ctf-client.integration.test.js.map +1 -0
- package/dist/__tests__/integration/data-api.integration.test.d.ts +9 -0
- package/dist/__tests__/integration/data-api.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/data-api.integration.test.js +161 -0
- package/dist/__tests__/integration/data-api.integration.test.js.map +1 -0
- package/dist/__tests__/integration/gamma-api.integration.test.d.ts +9 -0
- package/dist/__tests__/integration/gamma-api.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/gamma-api.integration.test.js +170 -0
- package/dist/__tests__/integration/gamma-api.integration.test.js.map +1 -0
- package/dist/__tests__/test-utils.d.ts +92 -0
- package/dist/__tests__/test-utils.d.ts.map +1 -0
- package/dist/__tests__/test-utils.js +143 -0
- package/dist/__tests__/test-utils.js.map +1 -0
- package/dist/clients/bridge-client.d.ts +388 -0
- package/dist/clients/bridge-client.d.ts.map +1 -0
- package/dist/clients/bridge-client.js +587 -0
- package/dist/clients/bridge-client.js.map +1 -0
- package/dist/clients/clob-api.d.ts +318 -0
- package/dist/clients/clob-api.d.ts.map +1 -0
- package/dist/clients/clob-api.js +388 -0
- package/dist/clients/clob-api.js.map +1 -0
- package/dist/clients/ctf-client.d.ts +473 -0
- package/dist/clients/ctf-client.d.ts.map +1 -0
- package/dist/clients/ctf-client.js +915 -0
- package/dist/clients/ctf-client.js.map +1 -0
- package/dist/clients/data-api.d.ts +134 -0
- package/dist/clients/data-api.d.ts.map +1 -0
- package/dist/clients/data-api.js +265 -0
- package/dist/clients/data-api.js.map +1 -0
- package/dist/clients/gamma-api.d.ts +401 -0
- package/dist/clients/gamma-api.d.ts.map +1 -0
- package/dist/clients/gamma-api.js +352 -0
- package/dist/clients/gamma-api.js.map +1 -0
- package/dist/clients/trading-client.d.ts +252 -0
- package/dist/clients/trading-client.d.ts.map +1 -0
- package/dist/clients/trading-client.js +543 -0
- package/dist/clients/trading-client.js.map +1 -0
- package/dist/clients/websocket-manager.d.ts +100 -0
- package/dist/clients/websocket-manager.d.ts.map +1 -0
- package/dist/clients/websocket-manager.js +193 -0
- package/dist/clients/websocket-manager.js.map +1 -0
- package/dist/core/cache-adapter-bridge.d.ts +36 -0
- package/dist/core/cache-adapter-bridge.d.ts.map +1 -0
- package/dist/core/cache-adapter-bridge.js +81 -0
- package/dist/core/cache-adapter-bridge.js.map +1 -0
- package/dist/core/cache.d.ts +40 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js +71 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/errors.d.ts +38 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +84 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/rate-limiter.d.ts +31 -0
- package/dist/core/rate-limiter.d.ts.map +1 -0
- package/dist/core/rate-limiter.js +70 -0
- package/dist/core/rate-limiter.js.map +1 -0
- package/dist/core/types.d.ts +314 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +19 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/unified-cache.d.ts +63 -0
- package/dist/core/unified-cache.d.ts.map +1 -0
- package/dist/core/unified-cache.js +114 -0
- package/dist/core/unified-cache.js.map +1 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +258 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/errors.d.ts +33 -0
- package/dist/mcp/errors.d.ts.map +1 -0
- package/dist/mcp/errors.js +86 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/index.d.ts +62 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +173 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.d.ts +17 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +155 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/guide.d.ts +12 -0
- package/dist/mcp/tools/guide.d.ts.map +1 -0
- package/dist/mcp/tools/guide.js +801 -0
- package/dist/mcp/tools/guide.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +11 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +27 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/market.d.ts +11 -0
- package/dist/mcp/tools/market.d.ts.map +1 -0
- package/dist/mcp/tools/market.js +314 -0
- package/dist/mcp/tools/market.js.map +1 -0
- package/dist/mcp/tools/order.d.ts +10 -0
- package/dist/mcp/tools/order.d.ts.map +1 -0
- package/dist/mcp/tools/order.js +258 -0
- package/dist/mcp/tools/order.js.map +1 -0
- package/dist/mcp/tools/trade.d.ts +38 -0
- package/dist/mcp/tools/trade.d.ts.map +1 -0
- package/dist/mcp/tools/trade.js +314 -0
- package/dist/mcp/tools/trade.js.map +1 -0
- package/dist/mcp/tools/trader.d.ts +11 -0
- package/dist/mcp/tools/trader.d.ts.map +1 -0
- package/dist/mcp/tools/trader.js +277 -0
- package/dist/mcp/tools/trader.js.map +1 -0
- package/dist/mcp/tools/wallet.d.ts +274 -0
- package/dist/mcp/tools/wallet.d.ts.map +1 -0
- package/dist/mcp/tools/wallet.js +579 -0
- package/dist/mcp/tools/wallet.js.map +1 -0
- package/dist/mcp/types.d.ts +413 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +5 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/services/authorization-service.d.ts +97 -0
- package/dist/services/authorization-service.d.ts.map +1 -0
- package/dist/services/authorization-service.js +279 -0
- package/dist/services/authorization-service.js.map +1 -0
- package/dist/services/market-service.d.ts +108 -0
- package/dist/services/market-service.d.ts.map +1 -0
- package/dist/services/market-service.js +458 -0
- package/dist/services/market-service.js.map +1 -0
- package/dist/services/realtime-service.d.ts +82 -0
- package/dist/services/realtime-service.d.ts.map +1 -0
- package/dist/services/realtime-service.js +150 -0
- package/dist/services/realtime-service.js.map +1 -0
- package/dist/services/swap-service.d.ts +217 -0
- package/dist/services/swap-service.d.ts.map +1 -0
- package/dist/services/swap-service.js +695 -0
- package/dist/services/swap-service.js.map +1 -0
- package/dist/services/wallet-service.d.ts +94 -0
- package/dist/services/wallet-service.d.ts.map +1 -0
- package/dist/services/wallet-service.js +173 -0
- package/dist/services/wallet-service.js.map +1 -0
- package/dist/utils/price-utils.d.ts +153 -0
- package/dist/utils/price-utils.d.ts.map +1 -0
- package/dist/utils/price-utils.js +236 -0
- package/dist/utils/price-utils.js.map +1 -0
- package/docs/00-design.md +760 -0
- package/docs/01-mcp.md +2041 -0
- package/docs/02-API.md +1148 -0
- package/docs/e2e/01-trader-tools.md +159 -0
- package/docs/e2e/02-market-tools.md +180 -0
- package/docs/e2e/03-order-tools.md +166 -0
- package/docs/e2e/04-wallet-tools.md +224 -0
- package/docs/e2e/05-trading-tools.md +327 -0
- package/docs/e2e/06-integration-scenarios.md +481 -0
- package/docs/e2e/coordinator.md +376 -0
- package/examples/01-basic-usage.ts +68 -0
- package/examples/02-smart-money.ts +95 -0
- package/examples/03-market-analysis.ts +108 -0
- package/examples/04-kline-aggregation.ts +158 -0
- package/examples/05-follow-wallet-strategy.ts +156 -0
- package/examples/06-services-demo.ts +124 -0
- package/examples/07-realtime-websocket.ts +117 -0
- package/examples/08-trading-orders.ts +278 -0
- package/examples/09-rewards-tracking.ts +187 -0
- package/examples/10-ctf-operations.ts +336 -0
- package/examples/11-live-arbitrage-scan.ts +221 -0
- package/examples/12-trending-arb-monitor.ts +406 -0
- package/examples/README.md +179 -0
- package/package.json +62 -0
- package/scripts/README.md +163 -0
- package/scripts/approvals/approve-erc1155.ts +129 -0
- package/scripts/approvals/approve-neg-risk-erc1155.ts +149 -0
- package/scripts/approvals/approve-neg-risk.ts +102 -0
- package/scripts/approvals/check-all-allowances.ts +150 -0
- package/scripts/approvals/check-allowance.ts +129 -0
- package/scripts/approvals/check-ctf-approval.ts +158 -0
- package/scripts/datas/001-report.md +486 -0
- package/scripts/datas/clone-modal-screenshot.png +0 -0
- package/scripts/deposit/deposit-native-usdc.ts +179 -0
- package/scripts/deposit/deposit-usdc.ts +155 -0
- package/scripts/deposit/swap-usdc-to-usdce.ts +375 -0
- package/scripts/research/research-markets.ts +166 -0
- package/scripts/trading/check-orders.ts +50 -0
- package/scripts/trading/sell-nvidia-positions.ts +206 -0
- package/scripts/trading/test-order.ts +172 -0
- package/scripts/truth.md +440 -0
- package/scripts/verify/test-approve-trading.ts +98 -0
- package/scripts/verify/test-provider-fix.ts +43 -0
- package/scripts/verify/test-search-mcp.ts +113 -0
- package/scripts/verify/verify-all-apis.ts +160 -0
- package/scripts/wallet/check-wallet-balances.ts +75 -0
- package/scripts/wallet/test-wallet-operations.ts +191 -0
- package/scripts/wallet/verify-wallet-tools.ts +124 -0
- package/src/__tests__/clob-api.test.ts +301 -0
- package/src/__tests__/integration/bridge-client.integration.test.ts +314 -0
- package/src/__tests__/integration/clob-api.integration.test.ts +218 -0
- package/src/__tests__/integration/ctf-client.integration.test.ts +331 -0
- package/src/__tests__/integration/data-api.integration.test.ts +194 -0
- package/src/__tests__/integration/gamma-api.integration.test.ts +206 -0
- package/src/__tests__/test-utils.ts +170 -0
- package/src/clients/bridge-client.ts +841 -0
- package/src/clients/clob-api.ts +629 -0
- package/src/clients/ctf-client.ts +1216 -0
- package/src/clients/data-api.ts +469 -0
- package/src/clients/gamma-api.ts +597 -0
- package/src/clients/trading-client.ts +749 -0
- package/src/clients/websocket-manager.ts +267 -0
- package/src/core/cache-adapter-bridge.ts +94 -0
- package/src/core/cache.ts +85 -0
- package/src/core/errors.ts +117 -0
- package/src/core/rate-limiter.ts +74 -0
- package/src/core/types.ts +360 -0
- package/src/core/unified-cache.ts +153 -0
- package/src/index.ts +455 -0
- package/src/mcp/README.md +380 -0
- package/src/mcp/errors.ts +124 -0
- package/src/mcp/index.ts +309 -0
- package/src/mcp/server.ts +183 -0
- package/src/mcp/tools/guide.ts +821 -0
- package/src/mcp/tools/index.ts +73 -0
- package/src/mcp/tools/market.ts +363 -0
- package/src/mcp/tools/order.ts +326 -0
- package/src/mcp/tools/trade.ts +417 -0
- package/src/mcp/tools/trader.ts +322 -0
- package/src/mcp/tools/wallet.ts +683 -0
- package/src/mcp/types.ts +472 -0
- package/src/services/authorization-service.ts +357 -0
- package/src/services/market-service.ts +544 -0
- package/src/services/realtime-service.ts +196 -0
- package/src/services/swap-service.ts +896 -0
- package/src/services/wallet-service.ts +259 -0
- package/src/utils/price-utils.ts +307 -0
- package/tsconfig.json +8 -0
- package/vitest.config.ts +19 -0
- package/vitest.integration.config.ts +18 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Poly-SDK Scripts
|
|
2
|
+
|
|
3
|
+
Utility scripts for testing and operating with Polymarket.
|
|
4
|
+
|
|
5
|
+
## Environment Setup
|
|
6
|
+
|
|
7
|
+
Set environment variable:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
export POLY_PRIVKEY=0x... # Your private key
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or pass inline:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
POLY_PRIVKEY=0x... npx tsx scripts/...
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Directory Structure
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
scripts/
|
|
25
|
+
├── approvals/ # ERC20/ERC1155 approval scripts
|
|
26
|
+
├── deposit/ # USDC deposit and swap scripts
|
|
27
|
+
├── trading/ # Order and position management
|
|
28
|
+
├── wallet/ # Wallet balance and verification
|
|
29
|
+
├── verify/ # API verification tests
|
|
30
|
+
└── research/ # Market research and analysis
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Scripts Reference
|
|
36
|
+
|
|
37
|
+
### `approvals/` - Token Approvals
|
|
38
|
+
|
|
39
|
+
| Script | Description |
|
|
40
|
+
|--------|-------------|
|
|
41
|
+
| `check-allowance.ts` | Check USDC allowance for CTF Exchange |
|
|
42
|
+
| `check-all-allowances.ts` | Check all token allowances at once |
|
|
43
|
+
| `check-ctf-approval.ts` | Check CTF/ERC1155 approval status |
|
|
44
|
+
| `approve-neg-risk.ts` | Approve USDC for Neg Risk Exchange |
|
|
45
|
+
| `approve-erc1155.ts` | Approve ERC1155 for CTF Exchange |
|
|
46
|
+
| `approve-neg-risk-erc1155.ts` | Approve ERC1155 for Neg Risk Exchange |
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Check all allowances
|
|
50
|
+
npx tsx scripts/approvals/check-all-allowances.ts
|
|
51
|
+
|
|
52
|
+
# Approve for neg risk markets
|
|
53
|
+
npx tsx scripts/approvals/approve-neg-risk.ts
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
### `deposit/` - Deposits & Swaps
|
|
59
|
+
|
|
60
|
+
| Script | Description |
|
|
61
|
+
|--------|-------------|
|
|
62
|
+
| `deposit-native-usdc.ts` | Deposit Native USDC via Bridge |
|
|
63
|
+
| `deposit-usdc.ts` | Deposit USDC.e directly |
|
|
64
|
+
| `swap-usdc-to-usdce.ts` | Swap Native USDC → USDC.e on DEX |
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Check deposit address and status
|
|
68
|
+
npx tsx scripts/deposit/deposit-native-usdc.ts check
|
|
69
|
+
|
|
70
|
+
# Deposit $50 via Bridge
|
|
71
|
+
npx tsx scripts/deposit/deposit-native-usdc.ts deposit 50
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Important:** USDC.e is required for Polymarket CTF operations. Native USDC must be swapped or bridged first.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### `trading/` - Orders & Positions
|
|
79
|
+
|
|
80
|
+
| Script | Description |
|
|
81
|
+
|--------|-------------|
|
|
82
|
+
| `check-orders.ts` | View open orders and recent trades |
|
|
83
|
+
| `test-order.ts` | Test order placement |
|
|
84
|
+
| `sell-nvidia-positions.ts` | Sell specific positions |
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Check open orders
|
|
88
|
+
npx tsx scripts/trading/check-orders.ts
|
|
89
|
+
|
|
90
|
+
# Test order placement
|
|
91
|
+
npx tsx scripts/trading/test-order.ts
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
### `wallet/` - Wallet Management
|
|
97
|
+
|
|
98
|
+
| Script | Description |
|
|
99
|
+
|--------|-------------|
|
|
100
|
+
| `check-wallet-balances.ts` | Check all wallet balances |
|
|
101
|
+
| `verify-wallet-tools.ts` | Verify wallet MCP tools |
|
|
102
|
+
| `test-wallet-operations.ts` | Test wallet operations |
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Check balances
|
|
106
|
+
npx tsx scripts/wallet/check-wallet-balances.ts
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### `verify/` - API Verification
|
|
112
|
+
|
|
113
|
+
| Script | Description |
|
|
114
|
+
|--------|-------------|
|
|
115
|
+
| `verify-all-apis.ts` | Verify all API endpoints |
|
|
116
|
+
| `test-search-mcp.ts` | Test MCP search tools |
|
|
117
|
+
| `test-approve-trading.ts` | Test trading approvals |
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Verify all APIs work
|
|
121
|
+
npx tsx scripts/verify/verify-all-apis.ts
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
### `research/` - Market Research
|
|
127
|
+
|
|
128
|
+
| Script | Description |
|
|
129
|
+
|--------|-------------|
|
|
130
|
+
| `research-markets.ts` | ARB/MM/Hybrid market analysis |
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Find arbitrage and MM opportunities
|
|
134
|
+
npx tsx scripts/research/research-markets.ts
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Important Concepts
|
|
140
|
+
|
|
141
|
+
### USDC Types
|
|
142
|
+
|
|
143
|
+
| Token | Address | Use |
|
|
144
|
+
|-------|---------|-----|
|
|
145
|
+
| USDC.e (Bridged) | `0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174` | **Required for CTF** |
|
|
146
|
+
| Native USDC | `0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359` | Must swap to USDC.e |
|
|
147
|
+
|
|
148
|
+
### Effective Prices
|
|
149
|
+
|
|
150
|
+
Polymarket orderbooks have mirroring:
|
|
151
|
+
- Buying YES @ P = Selling NO @ (1-P)
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
effectiveBuyYes = min(YES.bestAsk, 1 - NO.bestBid)
|
|
155
|
+
effectiveBuyNo = min(NO.bestAsk, 1 - YES.bestBid)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Arbitrage Detection
|
|
159
|
+
|
|
160
|
+
| Type | Condition | Action |
|
|
161
|
+
|------|-----------|--------|
|
|
162
|
+
| Long | `effectiveBuyYes + effectiveBuyNo < 1` | Buy both, merge |
|
|
163
|
+
| Short | `effectiveSellYes + effectiveSellNo > 1` | Split, sell both |
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env npx tsx
|
|
2
|
+
/**
|
|
3
|
+
* Approve ERC1155 for selling YES/NO tokens
|
|
4
|
+
*
|
|
5
|
+
* This sets setApprovalForAll on the Conditional Tokens contract
|
|
6
|
+
* to allow the exchanges to transfer your YES/NO tokens.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { ethers } from 'ethers';
|
|
10
|
+
import * as fs from 'fs';
|
|
11
|
+
import * as path from 'path';
|
|
12
|
+
import { fileURLToPath } from 'url';
|
|
13
|
+
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = path.dirname(__filename);
|
|
16
|
+
|
|
17
|
+
// Read private key
|
|
18
|
+
const envPath = path.resolve(__dirname, '../../earning-engine/dashboard-api/.env');
|
|
19
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
20
|
+
const match = envContent.match(/^PRIVATE_KEY=(.+)$/m);
|
|
21
|
+
const PRIVATE_KEY = match ? match[1].trim() : '';
|
|
22
|
+
|
|
23
|
+
if (!PRIVATE_KEY) {
|
|
24
|
+
console.error('PRIVATE_KEY not found');
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Contract addresses
|
|
29
|
+
const CONDITIONAL_TOKENS = '0x4D97DCd97eC945f40cF65F87097ACe5EA0476045';
|
|
30
|
+
const CTF_EXCHANGE = '0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E';
|
|
31
|
+
const NEG_RISK_CTF_EXCHANGE = '0xC5d563A36AE78145C45a50134d48A1215220f80a';
|
|
32
|
+
|
|
33
|
+
const ERC1155_ABI = [
|
|
34
|
+
'function setApprovalForAll(address operator, bool approved) external',
|
|
35
|
+
'function isApprovedForAll(address account, address operator) view returns (bool)',
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
async function main() {
|
|
39
|
+
console.log('╔════════════════════════════════════════════════════════════════╗');
|
|
40
|
+
console.log('║ ERC1155 APPROVAL FOR SELLING YES/NO TOKENS ║');
|
|
41
|
+
console.log('╚════════════════════════════════════════════════════════════════╝');
|
|
42
|
+
console.log('');
|
|
43
|
+
|
|
44
|
+
const rpcs = [
|
|
45
|
+
'https://polygon-bor-rpc.publicnode.com',
|
|
46
|
+
'https://polygon.drpc.org',
|
|
47
|
+
'https://polygon-rpc.com',
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
for (const rpc of rpcs) {
|
|
51
|
+
console.log(`Trying RPC: ${rpc}`);
|
|
52
|
+
try {
|
|
53
|
+
const provider = new ethers.providers.JsonRpcProvider({
|
|
54
|
+
url: rpc,
|
|
55
|
+
timeout: 30000,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const network = await provider.getNetwork();
|
|
59
|
+
console.log(`Connected to chain ${network.chainId}`);
|
|
60
|
+
|
|
61
|
+
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
|
|
62
|
+
console.log(`Wallet: ${wallet.address}`);
|
|
63
|
+
console.log('');
|
|
64
|
+
|
|
65
|
+
const conditionalTokens = new ethers.Contract(CONDITIONAL_TOKENS, ERC1155_ABI, wallet);
|
|
66
|
+
|
|
67
|
+
const operators = [
|
|
68
|
+
{ name: 'CTF Exchange', address: CTF_EXCHANGE },
|
|
69
|
+
{ name: 'Neg Risk CTF Exchange', address: NEG_RISK_CTF_EXCHANGE },
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
// Check current approvals
|
|
73
|
+
console.log('─── Current ERC1155 Approvals ───');
|
|
74
|
+
let needsApproval = [];
|
|
75
|
+
|
|
76
|
+
for (const op of operators) {
|
|
77
|
+
const isApproved = await conditionalTokens.isApprovedForAll(wallet.address, op.address);
|
|
78
|
+
console.log(`${op.name}: ${isApproved ? '✅ Approved' : '❌ Not Approved'}`);
|
|
79
|
+
if (!isApproved) {
|
|
80
|
+
needsApproval.push(op);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
console.log('');
|
|
84
|
+
|
|
85
|
+
if (needsApproval.length === 0) {
|
|
86
|
+
console.log('✅ All ERC1155 approvals are set!');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Approve missing operators
|
|
91
|
+
console.log('─── Setting Approvals ───');
|
|
92
|
+
const gasPrice = await provider.getGasPrice();
|
|
93
|
+
const adjustedGas = gasPrice.mul(2);
|
|
94
|
+
console.log(`Gas price: ${ethers.utils.formatUnits(adjustedGas, 'gwei')} Gwei`);
|
|
95
|
+
console.log('');
|
|
96
|
+
|
|
97
|
+
for (const op of needsApproval) {
|
|
98
|
+
console.log(`Approving ${op.name}...`);
|
|
99
|
+
try {
|
|
100
|
+
const tx = await conditionalTokens.setApprovalForAll(op.address, true, {
|
|
101
|
+
gasPrice: adjustedGas,
|
|
102
|
+
gasLimit: 100000,
|
|
103
|
+
});
|
|
104
|
+
console.log(` TX: ${tx.hash}`);
|
|
105
|
+
const receipt = await tx.wait();
|
|
106
|
+
console.log(` ✅ Confirmed in block ${receipt.blockNumber}`);
|
|
107
|
+
} catch (error: any) {
|
|
108
|
+
console.log(` ❌ Failed: ${error.message}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
console.log('');
|
|
113
|
+
console.log('─── Verifying Approvals ───');
|
|
114
|
+
for (const op of operators) {
|
|
115
|
+
const isApproved = await conditionalTokens.isApprovedForAll(wallet.address, op.address);
|
|
116
|
+
console.log(`${op.name}: ${isApproved ? '✅ Approved' : '❌ Not Approved'}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return;
|
|
120
|
+
} catch (error: any) {
|
|
121
|
+
console.log(`Failed: ${error.message}`);
|
|
122
|
+
console.log('');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log('❌ All RPCs failed!');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env npx tsx
|
|
2
|
+
/**
|
|
3
|
+
* Check and Approve ERC1155 for Neg Risk Adapter
|
|
4
|
+
*
|
|
5
|
+
* 检查并授权 Neg Risk Adapter 的 ERC1155 转账权限
|
|
6
|
+
* 这可能是 SELL 订单在 Neg Risk 市场失败的原因
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { ethers } from 'ethers';
|
|
10
|
+
import * as fs from 'fs';
|
|
11
|
+
import * as path from 'path';
|
|
12
|
+
import { fileURLToPath } from 'url';
|
|
13
|
+
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = path.dirname(__filename);
|
|
16
|
+
|
|
17
|
+
// Read private key
|
|
18
|
+
const envPath = path.resolve(__dirname, '../../earning-engine/dashboard-api/.env');
|
|
19
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
20
|
+
const match = envContent.match(/^PRIVATE_KEY=(.+)$/m);
|
|
21
|
+
const PRIVATE_KEY = match ? match[1].trim() : '';
|
|
22
|
+
|
|
23
|
+
if (!PRIVATE_KEY) {
|
|
24
|
+
console.error('PRIVATE_KEY not found');
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Contract addresses
|
|
29
|
+
const CONDITIONAL_TOKENS = '0x4D97DCd97eC945f40cF65F87097ACe5EA0476045';
|
|
30
|
+
const CTF_EXCHANGE = '0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E';
|
|
31
|
+
const NEG_RISK_CTF_EXCHANGE = '0xC5d563A36AE78145C45a50134d48A1215220f80a';
|
|
32
|
+
const NEG_RISK_ADAPTER = '0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296';
|
|
33
|
+
|
|
34
|
+
const ERC1155_ABI = [
|
|
35
|
+
'function setApprovalForAll(address operator, bool approved) external',
|
|
36
|
+
'function isApprovedForAll(address account, address operator) view returns (bool)',
|
|
37
|
+
'function balanceOf(address account, uint256 id) view returns (uint256)',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
async function main() {
|
|
41
|
+
console.log('╔════════════════════════════════════════════════════════════════╗');
|
|
42
|
+
console.log('║ NEG RISK ERC1155 AUTHORIZATION CHECK ║');
|
|
43
|
+
console.log('╚════════════════════════════════════════════════════════════════╝');
|
|
44
|
+
console.log('');
|
|
45
|
+
|
|
46
|
+
const rpcs = [
|
|
47
|
+
'https://polygon-bor-rpc.publicnode.com',
|
|
48
|
+
'https://polygon.drpc.org',
|
|
49
|
+
'https://polygon-rpc.com',
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
for (const rpc of rpcs) {
|
|
53
|
+
console.log(`Trying RPC: ${rpc}`);
|
|
54
|
+
try {
|
|
55
|
+
const provider = new ethers.providers.JsonRpcProvider({
|
|
56
|
+
url: rpc,
|
|
57
|
+
timeout: 30000,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const network = await provider.getNetwork();
|
|
61
|
+
console.log(`Connected to chain ${network.chainId}`);
|
|
62
|
+
|
|
63
|
+
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
|
|
64
|
+
console.log(`Wallet: ${wallet.address}`);
|
|
65
|
+
console.log('');
|
|
66
|
+
|
|
67
|
+
const conditionalTokens = new ethers.Contract(CONDITIONAL_TOKENS, ERC1155_ABI, wallet);
|
|
68
|
+
|
|
69
|
+
// All operators to check
|
|
70
|
+
const operators = [
|
|
71
|
+
{ name: 'CTF Exchange', address: CTF_EXCHANGE },
|
|
72
|
+
{ name: 'Neg Risk CTF Exchange', address: NEG_RISK_CTF_EXCHANGE },
|
|
73
|
+
{ name: 'Neg Risk Adapter', address: NEG_RISK_ADAPTER },
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
// Check current approvals
|
|
77
|
+
console.log('─── Current ERC1155 Approvals (Conditional Tokens) ───');
|
|
78
|
+
let needsApproval = [];
|
|
79
|
+
|
|
80
|
+
for (const op of operators) {
|
|
81
|
+
const isApproved = await conditionalTokens.isApprovedForAll(wallet.address, op.address);
|
|
82
|
+
console.log(`${op.name}: ${isApproved ? '✅ Approved' : '❌ Not Approved'}`);
|
|
83
|
+
if (!isApproved) {
|
|
84
|
+
needsApproval.push(op);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
console.log('');
|
|
88
|
+
|
|
89
|
+
// Check token balances (YES and NO for NVIDIA market)
|
|
90
|
+
const yesTokenId = '94850533403292240972948844256810904078895883844462287088135166537739765648754';
|
|
91
|
+
const noTokenId = '69263280792958981516606123639467754139758192236863611059536531765186180114584';
|
|
92
|
+
|
|
93
|
+
console.log('─── Token Balances ───');
|
|
94
|
+
const yesBalance = await conditionalTokens.balanceOf(wallet.address, yesTokenId);
|
|
95
|
+
const noBalance = await conditionalTokens.balanceOf(wallet.address, noTokenId);
|
|
96
|
+
console.log(`YES Token: ${ethers.utils.formatUnits(yesBalance, 6)} tokens`);
|
|
97
|
+
console.log(`NO Token: ${ethers.utils.formatUnits(noBalance, 6)} tokens`);
|
|
98
|
+
console.log('');
|
|
99
|
+
|
|
100
|
+
if (needsApproval.length === 0) {
|
|
101
|
+
console.log('✅ All ERC1155 approvals are set!');
|
|
102
|
+
console.log('');
|
|
103
|
+
console.log('If SELL orders are still failing, the issue might be:');
|
|
104
|
+
console.log('1. Neg Risk market uses wrapped tokens through the Adapter');
|
|
105
|
+
console.log('2. The CLOB might require a different approval mechanism');
|
|
106
|
+
console.log('3. Check if tokens need to be "unwrapped" before selling');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Approve missing operators
|
|
111
|
+
console.log('─── Setting Approvals ───');
|
|
112
|
+
const gasPrice = await provider.getGasPrice();
|
|
113
|
+
const adjustedGas = gasPrice.mul(2);
|
|
114
|
+
console.log(`Gas price: ${ethers.utils.formatUnits(adjustedGas, 'gwei')} Gwei`);
|
|
115
|
+
console.log('');
|
|
116
|
+
|
|
117
|
+
for (const op of needsApproval) {
|
|
118
|
+
console.log(`Approving ${op.name}...`);
|
|
119
|
+
try {
|
|
120
|
+
const tx = await conditionalTokens.setApprovalForAll(op.address, true, {
|
|
121
|
+
gasPrice: adjustedGas,
|
|
122
|
+
gasLimit: 100000,
|
|
123
|
+
});
|
|
124
|
+
console.log(` TX: ${tx.hash}`);
|
|
125
|
+
const receipt = await tx.wait();
|
|
126
|
+
console.log(` ✅ Confirmed in block ${receipt.blockNumber}`);
|
|
127
|
+
} catch (error: any) {
|
|
128
|
+
console.log(` ❌ Failed: ${error.message}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
console.log('');
|
|
133
|
+
console.log('─── Verifying Approvals ───');
|
|
134
|
+
for (const op of operators) {
|
|
135
|
+
const isApproved = await conditionalTokens.isApprovedForAll(wallet.address, op.address);
|
|
136
|
+
console.log(`${op.name}: ${isApproved ? '✅ Approved' : '❌ Not Approved'}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return;
|
|
140
|
+
} catch (error: any) {
|
|
141
|
+
console.log(`Failed: ${error.message}`);
|
|
142
|
+
console.log('');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
console.log('❌ All RPCs failed!');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env npx tsx
|
|
2
|
+
/**
|
|
3
|
+
* Simple script to approve Neg Risk Adapter
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ethers } from 'ethers';
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
|
|
14
|
+
// Read private key
|
|
15
|
+
const envPath = path.resolve(__dirname, '../../earning-engine/dashboard-api/.env');
|
|
16
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
17
|
+
const match = envContent.match(/^PRIVATE_KEY=(.+)$/m);
|
|
18
|
+
const PRIVATE_KEY = match ? match[1].trim() : '';
|
|
19
|
+
|
|
20
|
+
if (!PRIVATE_KEY) {
|
|
21
|
+
console.error('PRIVATE_KEY not found');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const USDC_E = '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174';
|
|
26
|
+
const NEG_RISK_ADAPTER = '0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296';
|
|
27
|
+
|
|
28
|
+
const ERC20_ABI = [
|
|
29
|
+
'function approve(address spender, uint256 amount) returns (bool)',
|
|
30
|
+
'function allowance(address owner, address spender) view returns (uint256)',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
async function main() {
|
|
34
|
+
console.log('Approving Neg Risk Adapter...');
|
|
35
|
+
|
|
36
|
+
// Try multiple RPCs
|
|
37
|
+
const rpcs = [
|
|
38
|
+
'https://polygon-bor-rpc.publicnode.com',
|
|
39
|
+
'https://polygon.drpc.org',
|
|
40
|
+
'https://polygon-rpc.com',
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
for (const rpc of rpcs) {
|
|
44
|
+
console.log(`\nTrying RPC: ${rpc}`);
|
|
45
|
+
try {
|
|
46
|
+
const provider = new ethers.providers.JsonRpcProvider({
|
|
47
|
+
url: rpc,
|
|
48
|
+
timeout: 30000,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Test connection
|
|
52
|
+
const network = await provider.getNetwork();
|
|
53
|
+
console.log(`Connected to chain ${network.chainId}`);
|
|
54
|
+
|
|
55
|
+
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
|
|
56
|
+
console.log(`Wallet: ${wallet.address}`);
|
|
57
|
+
|
|
58
|
+
const usdc = new ethers.Contract(USDC_E, ERC20_ABI, wallet);
|
|
59
|
+
|
|
60
|
+
// Check current allowance
|
|
61
|
+
const currentAllowance = await usdc.allowance(wallet.address, NEG_RISK_ADAPTER);
|
|
62
|
+
console.log(`Current allowance: ${ethers.utils.formatUnits(currentAllowance, 6)} USDC`);
|
|
63
|
+
|
|
64
|
+
if (currentAllowance.gt(ethers.utils.parseUnits('1000000000', 6))) {
|
|
65
|
+
console.log('✅ Already approved!');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Get gas price
|
|
70
|
+
const gasPrice = await provider.getGasPrice();
|
|
71
|
+
const adjustedGas = gasPrice.mul(2); // 2x for safety
|
|
72
|
+
console.log(`Gas price: ${ethers.utils.formatUnits(adjustedGas, 'gwei')} Gwei`);
|
|
73
|
+
|
|
74
|
+
// Approve
|
|
75
|
+
console.log('Sending approval transaction...');
|
|
76
|
+
const tx = await usdc.approve(NEG_RISK_ADAPTER, ethers.constants.MaxUint256, {
|
|
77
|
+
gasPrice: adjustedGas,
|
|
78
|
+
gasLimit: 100000,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
console.log(`TX Hash: ${tx.hash}`);
|
|
82
|
+
console.log('Waiting for confirmation...');
|
|
83
|
+
|
|
84
|
+
const receipt = await tx.wait();
|
|
85
|
+
console.log(`✅ Confirmed in block ${receipt.blockNumber}`);
|
|
86
|
+
|
|
87
|
+
// Verify
|
|
88
|
+
const newAllowance = await usdc.allowance(wallet.address, NEG_RISK_ADAPTER);
|
|
89
|
+
console.log(`New allowance: Unlimited`);
|
|
90
|
+
|
|
91
|
+
return;
|
|
92
|
+
} catch (error: any) {
|
|
93
|
+
console.log(`Failed: ${error.message}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log('\n❌ All RPCs failed!');
|
|
98
|
+
console.log('Please approve manually on Polygonscan:');
|
|
99
|
+
console.log('https://polygonscan.com/token/0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174#writeContract');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env npx tsx
|
|
2
|
+
/**
|
|
3
|
+
* Check all Polymarket contract allowances
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ethers } from 'ethers';
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
|
|
14
|
+
// Read private key from dashboard-api .env
|
|
15
|
+
const envPath = path.resolve(__dirname, '../../earning-engine/dashboard-api/.env');
|
|
16
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
17
|
+
const match = envContent.match(/^PRIVATE_KEY=(.+)$/m);
|
|
18
|
+
const PRIVATE_KEY = match ? match[1].trim() : '';
|
|
19
|
+
|
|
20
|
+
if (!PRIVATE_KEY) {
|
|
21
|
+
console.error('Error: PRIVATE_KEY not found in .env');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Contract addresses on Polygon
|
|
26
|
+
const USDC_E_ADDRESS = '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174';
|
|
27
|
+
const CTF_EXCHANGE = '0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E';
|
|
28
|
+
const NEG_RISK_CTF_EXCHANGE = '0xC5d563A36AE78145C45a50134d48A1215220f80a';
|
|
29
|
+
const NEG_RISK_ADAPTER = '0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296';
|
|
30
|
+
|
|
31
|
+
// Additional contracts that might need approval
|
|
32
|
+
const CONDITIONAL_TOKENS = '0x4D97DCd97eC945f40cF65F87097ACe5EA0476045';
|
|
33
|
+
|
|
34
|
+
const ERC20_ABI = [
|
|
35
|
+
'function balanceOf(address owner) view returns (uint256)',
|
|
36
|
+
'function allowance(address owner, address spender) view returns (uint256)',
|
|
37
|
+
'function approve(address spender, uint256 amount) returns (bool)',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
async function main() {
|
|
41
|
+
console.log('╔════════════════════════════════════════════════════════════════╗');
|
|
42
|
+
console.log('║ POLYMARKET ALLOWANCE CHECKER (ALL CONTRACTS) ║');
|
|
43
|
+
console.log('╚════════════════════════════════════════════════════════════════╝');
|
|
44
|
+
console.log('');
|
|
45
|
+
|
|
46
|
+
// Use multiple RPC providers for reliability
|
|
47
|
+
const rpcUrls = [
|
|
48
|
+
'https://polygon-mainnet.g.alchemy.com/v2/demo',
|
|
49
|
+
'https://polygon.llamarpc.com',
|
|
50
|
+
'https://polygon-rpc.com',
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
let provider: ethers.providers.JsonRpcProvider | null = null;
|
|
54
|
+
for (const rpcUrl of rpcUrls) {
|
|
55
|
+
try {
|
|
56
|
+
const p = new ethers.providers.JsonRpcProvider(rpcUrl);
|
|
57
|
+
await p.getNetwork(); // Test connection
|
|
58
|
+
provider = p;
|
|
59
|
+
console.log(`Using RPC: ${rpcUrl}`);
|
|
60
|
+
break;
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.log(`RPC failed: ${rpcUrl}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!provider) {
|
|
67
|
+
console.error('All RPC providers failed!');
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
|
|
71
|
+
const address = wallet.address;
|
|
72
|
+
const usdc = new ethers.Contract(USDC_E_ADDRESS, ERC20_ABI, wallet);
|
|
73
|
+
|
|
74
|
+
console.log(`Wallet: ${address}`);
|
|
75
|
+
console.log('');
|
|
76
|
+
|
|
77
|
+
// Check USDC balance
|
|
78
|
+
const balance = await usdc.balanceOf(address);
|
|
79
|
+
console.log(`USDC.e Balance: ${(parseFloat(balance.toString()) / 1e6).toFixed(6)} USDC`);
|
|
80
|
+
console.log('');
|
|
81
|
+
|
|
82
|
+
// Check all allowances
|
|
83
|
+
console.log('─── Contract Allowances ───');
|
|
84
|
+
|
|
85
|
+
const contracts = [
|
|
86
|
+
{ name: 'CTF Exchange', address: CTF_EXCHANGE },
|
|
87
|
+
{ name: 'Neg Risk CTF Exchange', address: NEG_RISK_CTF_EXCHANGE },
|
|
88
|
+
{ name: 'Neg Risk Adapter', address: NEG_RISK_ADAPTER },
|
|
89
|
+
{ name: 'Conditional Tokens', address: CONDITIONAL_TOKENS },
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
let needsApproval = [];
|
|
93
|
+
|
|
94
|
+
for (const contract of contracts) {
|
|
95
|
+
const allowance = await usdc.allowance(address, contract.address);
|
|
96
|
+
const allowanceNum = parseFloat(allowance.toString()) / 1e6;
|
|
97
|
+
const isUnlimited = allowanceNum > 1e12;
|
|
98
|
+
const status = isUnlimited ? '✅ Unlimited' : allowanceNum > 0 ? `⚠️ ${allowanceNum.toFixed(2)}` : '❌ None';
|
|
99
|
+
console.log(`${contract.name}: ${status}`);
|
|
100
|
+
if (!isUnlimited) {
|
|
101
|
+
needsApproval.push(contract);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log('');
|
|
106
|
+
|
|
107
|
+
if (needsApproval.length > 0) {
|
|
108
|
+
console.log('─── Approval Needed ───');
|
|
109
|
+
console.log('The following contracts need unlimited approval:');
|
|
110
|
+
for (const contract of needsApproval) {
|
|
111
|
+
console.log(` - ${contract.name} (${contract.address})`);
|
|
112
|
+
}
|
|
113
|
+
console.log('');
|
|
114
|
+
console.log('Run with --approve flag to approve all:');
|
|
115
|
+
console.log(' npx tsx scripts/check-all-allowances.ts --approve');
|
|
116
|
+
console.log('');
|
|
117
|
+
|
|
118
|
+
if (process.argv.includes('--approve')) {
|
|
119
|
+
console.log('─── Approving Contracts ───');
|
|
120
|
+
const MAX_UINT256 = ethers.constants.MaxUint256;
|
|
121
|
+
|
|
122
|
+
// Get current gas price and add buffer for Polygon
|
|
123
|
+
const gasPrice = await provider.getGasPrice();
|
|
124
|
+
const adjustedGasPrice = gasPrice.mul(150).div(100); // 1.5x current gas price
|
|
125
|
+
console.log(`Using gas price: ${(adjustedGasPrice.toNumber() / 1e9).toFixed(2)} Gwei`);
|
|
126
|
+
|
|
127
|
+
for (const contract of needsApproval) {
|
|
128
|
+
console.log(`Approving ${contract.name}...`);
|
|
129
|
+
try {
|
|
130
|
+
const tx = await usdc.approve(contract.address, MAX_UINT256, { gasPrice: adjustedGasPrice });
|
|
131
|
+
console.log(` TX: ${tx.hash}`);
|
|
132
|
+
await tx.wait();
|
|
133
|
+
console.log(` ✓ Approved`);
|
|
134
|
+
} catch (error: any) {
|
|
135
|
+
console.log(` ✗ Failed: ${error.message}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
console.log('');
|
|
139
|
+
console.log('✅ Done! Please re-run without --approve to verify.');
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
console.log('✅ All contracts have unlimited approval!');
|
|
143
|
+
console.log('');
|
|
144
|
+
console.log('If orders are still failing, the issue may be:');
|
|
145
|
+
console.log('1. Polymarket requires a deposit via their UI to create a trading account');
|
|
146
|
+
console.log('2. Or there may be a different issue with the API key');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
main().catch(console.error);
|