@catalyst-team/poly-sdk 0.2.0 → 0.2.1

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.
Files changed (197) hide show
  1. package/LICENSE +1 -1
  2. package/README.en.md +8 -44
  3. package/README.md +5 -3
  4. package/README.zh-CN.md +502 -0
  5. package/dist/__tests__/clob-api.test.d.ts +5 -0
  6. package/dist/__tests__/clob-api.test.d.ts.map +1 -0
  7. package/dist/__tests__/clob-api.test.js +240 -0
  8. package/dist/__tests__/clob-api.test.js.map +1 -0
  9. package/dist/__tests__/integration/bridge-client.integration.test.d.ts +11 -0
  10. package/dist/__tests__/integration/bridge-client.integration.test.d.ts.map +1 -0
  11. package/dist/__tests__/integration/bridge-client.integration.test.js +260 -0
  12. package/dist/__tests__/integration/bridge-client.integration.test.js.map +1 -0
  13. package/dist/__tests__/integration/clob-api.integration.test.d.ts +13 -0
  14. package/dist/__tests__/integration/clob-api.integration.test.d.ts.map +1 -0
  15. package/dist/__tests__/integration/clob-api.integration.test.js +170 -0
  16. package/dist/__tests__/integration/clob-api.integration.test.js.map +1 -0
  17. package/dist/__tests__/integration/ctf-client.integration.test.d.ts +17 -0
  18. package/dist/__tests__/integration/ctf-client.integration.test.d.ts.map +1 -0
  19. package/dist/__tests__/integration/ctf-client.integration.test.js +234 -0
  20. package/dist/__tests__/integration/ctf-client.integration.test.js.map +1 -0
  21. package/dist/__tests__/integration/data-api.integration.test.d.ts +9 -0
  22. package/dist/__tests__/integration/data-api.integration.test.d.ts.map +1 -0
  23. package/dist/__tests__/integration/data-api.integration.test.js +161 -0
  24. package/dist/__tests__/integration/data-api.integration.test.js.map +1 -0
  25. package/dist/__tests__/integration/gamma-api.integration.test.d.ts +9 -0
  26. package/dist/__tests__/integration/gamma-api.integration.test.d.ts.map +1 -0
  27. package/dist/__tests__/integration/gamma-api.integration.test.js +170 -0
  28. package/dist/__tests__/integration/gamma-api.integration.test.js.map +1 -0
  29. package/dist/__tests__/test-utils.d.ts +92 -0
  30. package/dist/__tests__/test-utils.d.ts.map +1 -0
  31. package/dist/__tests__/test-utils.js +143 -0
  32. package/dist/__tests__/test-utils.js.map +1 -0
  33. package/dist/clients/bridge-client.d.ts +388 -0
  34. package/dist/clients/bridge-client.d.ts.map +1 -0
  35. package/dist/clients/bridge-client.js +587 -0
  36. package/dist/clients/bridge-client.js.map +1 -0
  37. package/dist/clients/clob-api.d.ts +318 -0
  38. package/dist/clients/clob-api.d.ts.map +1 -0
  39. package/dist/clients/clob-api.js +388 -0
  40. package/dist/clients/clob-api.js.map +1 -0
  41. package/dist/clients/ctf-client.d.ts +473 -0
  42. package/dist/clients/ctf-client.d.ts.map +1 -0
  43. package/dist/clients/ctf-client.js +915 -0
  44. package/dist/clients/ctf-client.js.map +1 -0
  45. package/dist/clients/data-api.d.ts +134 -0
  46. package/dist/clients/data-api.d.ts.map +1 -0
  47. package/dist/clients/data-api.js +265 -0
  48. package/dist/clients/data-api.js.map +1 -0
  49. package/dist/clients/gamma-api.d.ts +401 -0
  50. package/dist/clients/gamma-api.d.ts.map +1 -0
  51. package/dist/clients/gamma-api.js +352 -0
  52. package/dist/clients/gamma-api.js.map +1 -0
  53. package/dist/clients/trading-client.d.ts +252 -0
  54. package/dist/clients/trading-client.d.ts.map +1 -0
  55. package/dist/clients/trading-client.js +543 -0
  56. package/dist/clients/trading-client.js.map +1 -0
  57. package/dist/clients/websocket-manager.d.ts +100 -0
  58. package/dist/clients/websocket-manager.d.ts.map +1 -0
  59. package/dist/clients/websocket-manager.js +193 -0
  60. package/dist/clients/websocket-manager.js.map +1 -0
  61. package/dist/core/cache-adapter-bridge.d.ts +36 -0
  62. package/dist/core/cache-adapter-bridge.d.ts.map +1 -0
  63. package/dist/core/cache-adapter-bridge.js +81 -0
  64. package/dist/core/cache-adapter-bridge.js.map +1 -0
  65. package/dist/core/cache.d.ts +40 -0
  66. package/dist/core/cache.d.ts.map +1 -0
  67. package/dist/core/cache.js +71 -0
  68. package/dist/core/cache.js.map +1 -0
  69. package/dist/core/errors.d.ts +38 -0
  70. package/dist/core/errors.d.ts.map +1 -0
  71. package/dist/core/errors.js +84 -0
  72. package/dist/core/errors.js.map +1 -0
  73. package/dist/core/rate-limiter.d.ts +31 -0
  74. package/dist/core/rate-limiter.d.ts.map +1 -0
  75. package/dist/core/rate-limiter.js +70 -0
  76. package/dist/core/rate-limiter.js.map +1 -0
  77. package/{src/core/types.ts → dist/core/types.d.ts} +169 -215
  78. package/dist/core/types.d.ts.map +1 -0
  79. package/dist/core/types.js +19 -0
  80. package/dist/core/types.js.map +1 -0
  81. package/dist/core/unified-cache.d.ts +63 -0
  82. package/dist/core/unified-cache.d.ts.map +1 -0
  83. package/dist/core/unified-cache.js +114 -0
  84. package/dist/core/unified-cache.js.map +1 -0
  85. package/dist/index.d.ts +93 -0
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.js +255 -0
  88. package/dist/index.js.map +1 -0
  89. package/dist/services/arbitrage-service.d.ts +408 -0
  90. package/dist/services/arbitrage-service.d.ts.map +1 -0
  91. package/dist/services/arbitrage-service.js +1422 -0
  92. package/dist/services/arbitrage-service.js.map +1 -0
  93. package/dist/services/authorization-service.d.ts +97 -0
  94. package/dist/services/authorization-service.d.ts.map +1 -0
  95. package/dist/services/authorization-service.js +279 -0
  96. package/dist/services/authorization-service.js.map +1 -0
  97. package/dist/services/market-service.d.ts +108 -0
  98. package/dist/services/market-service.d.ts.map +1 -0
  99. package/dist/services/market-service.js +458 -0
  100. package/dist/services/market-service.js.map +1 -0
  101. package/dist/services/realtime-service.d.ts +82 -0
  102. package/dist/services/realtime-service.d.ts.map +1 -0
  103. package/dist/services/realtime-service.js +150 -0
  104. package/dist/services/realtime-service.js.map +1 -0
  105. package/dist/services/swap-service.d.ts +217 -0
  106. package/dist/services/swap-service.d.ts.map +1 -0
  107. package/dist/services/swap-service.js +695 -0
  108. package/dist/services/swap-service.js.map +1 -0
  109. package/dist/services/wallet-service.d.ts +94 -0
  110. package/dist/services/wallet-service.d.ts.map +1 -0
  111. package/dist/services/wallet-service.js +173 -0
  112. package/dist/services/wallet-service.js.map +1 -0
  113. package/dist/utils/price-utils.d.ts +153 -0
  114. package/dist/utils/price-utils.d.ts.map +1 -0
  115. package/dist/utils/price-utils.js +236 -0
  116. package/dist/utils/price-utils.js.map +1 -0
  117. package/package.json +7 -2
  118. package/docs/00-design.md +0 -760
  119. package/docs/02-API.md +0 -1148
  120. package/docs/arb/test-plan.md +0 -387
  121. package/docs/arb/test-results.md +0 -336
  122. package/docs/arbitrage.md +0 -754
  123. package/docs/reports/smart-money-analysis-2025-12-23-cn.md +0 -840
  124. package/examples/01-basic-usage.ts +0 -68
  125. package/examples/02-smart-money.ts +0 -95
  126. package/examples/03-market-analysis.ts +0 -108
  127. package/examples/04-kline-aggregation.ts +0 -158
  128. package/examples/05-follow-wallet-strategy.ts +0 -156
  129. package/examples/06-services-demo.ts +0 -124
  130. package/examples/07-realtime-websocket.ts +0 -117
  131. package/examples/08-trading-orders.ts +0 -278
  132. package/examples/09-rewards-tracking.ts +0 -187
  133. package/examples/10-ctf-operations.ts +0 -336
  134. package/examples/11-live-arbitrage-scan.ts +0 -221
  135. package/examples/12-trending-arb-monitor.ts +0 -406
  136. package/examples/13-arbitrage-service.ts +0 -211
  137. package/examples/README.md +0 -179
  138. package/scripts/README.md +0 -163
  139. package/scripts/approvals/approve-erc1155.ts +0 -129
  140. package/scripts/approvals/approve-neg-risk-erc1155.ts +0 -149
  141. package/scripts/approvals/approve-neg-risk.ts +0 -102
  142. package/scripts/approvals/check-all-allowances.ts +0 -150
  143. package/scripts/approvals/check-allowance.ts +0 -129
  144. package/scripts/approvals/check-ctf-approval.ts +0 -158
  145. package/scripts/arb/faze-bo3-arb.ts +0 -385
  146. package/scripts/arb/settle-position.ts +0 -190
  147. package/scripts/arb/token-rebalancer.ts +0 -420
  148. package/scripts/arb-tests/01-unit-tests.ts +0 -495
  149. package/scripts/arb-tests/02-integration-tests.ts +0 -412
  150. package/scripts/arb-tests/03-e2e-tests.ts +0 -503
  151. package/scripts/arb-tests/README.md +0 -109
  152. package/scripts/datas/001-report.md +0 -486
  153. package/scripts/datas/clone-modal-screenshot.png +0 -0
  154. package/scripts/deposit/deposit-native-usdc.ts +0 -179
  155. package/scripts/deposit/deposit-usdc.ts +0 -155
  156. package/scripts/deposit/swap-usdc-to-usdce.ts +0 -375
  157. package/scripts/research/research-markets.ts +0 -166
  158. package/scripts/trading/check-orders.ts +0 -50
  159. package/scripts/trading/sell-nvidia-positions.ts +0 -206
  160. package/scripts/trading/test-order.ts +0 -172
  161. package/scripts/verify/test-approve-trading.ts +0 -98
  162. package/scripts/verify/test-provider-fix.ts +0 -43
  163. package/scripts/verify/test-search-mcp.ts +0 -113
  164. package/scripts/verify/verify-all-apis.ts +0 -160
  165. package/scripts/wallet/check-wallet-balances.ts +0 -75
  166. package/scripts/wallet/test-wallet-operations.ts +0 -191
  167. package/scripts/wallet/verify-wallet-tools.ts +0 -124
  168. package/src/__tests__/clob-api.test.ts +0 -301
  169. package/src/__tests__/integration/bridge-client.integration.test.ts +0 -314
  170. package/src/__tests__/integration/clob-api.integration.test.ts +0 -218
  171. package/src/__tests__/integration/ctf-client.integration.test.ts +0 -331
  172. package/src/__tests__/integration/data-api.integration.test.ts +0 -194
  173. package/src/__tests__/integration/gamma-api.integration.test.ts +0 -206
  174. package/src/__tests__/test-utils.ts +0 -170
  175. package/src/clients/bridge-client.ts +0 -841
  176. package/src/clients/clob-api.ts +0 -629
  177. package/src/clients/ctf-client.ts +0 -1216
  178. package/src/clients/data-api.ts +0 -469
  179. package/src/clients/gamma-api.ts +0 -597
  180. package/src/clients/trading-client.ts +0 -749
  181. package/src/clients/websocket-manager.ts +0 -267
  182. package/src/core/cache-adapter-bridge.ts +0 -94
  183. package/src/core/cache.ts +0 -85
  184. package/src/core/errors.ts +0 -117
  185. package/src/core/rate-limiter.ts +0 -74
  186. package/src/core/unified-cache.ts +0 -153
  187. package/src/index.ts +0 -461
  188. package/src/services/arbitrage-service.ts +0 -1807
  189. package/src/services/authorization-service.ts +0 -357
  190. package/src/services/market-service.ts +0 -544
  191. package/src/services/realtime-service.ts +0 -196
  192. package/src/services/swap-service.ts +0 -896
  193. package/src/services/wallet-service.ts +0 -259
  194. package/src/utils/price-utils.ts +0 -307
  195. package/tsconfig.json +0 -8
  196. package/vitest.config.ts +0 -19
  197. package/vitest.integration.config.ts +0 -18
@@ -1,314 +0,0 @@
1
- /**
2
- * Bridge Client Integration Tests
3
- *
4
- * These tests verify the Bridge Client functionality.
5
- * Note: The bridge API (bridge.polymarket.com) may not be publicly accessible.
6
- * These tests are designed to handle both success and failure gracefully.
7
- *
8
- * Run with: pnpm test:integration
9
- */
10
-
11
- import { describe, it, expect } from 'vitest';
12
- import {
13
- BridgeClient,
14
- SUPPORTED_CHAINS,
15
- BRIDGE_TOKENS,
16
- estimateBridgeOutput,
17
- getExplorerUrl,
18
- } from '../../clients/bridge-client.js';
19
-
20
- describe('BridgeClient Integration', () => {
21
- const bridge = new BridgeClient();
22
-
23
- describe('Constants', () => {
24
- it('should have correct Ethereum chain info', () => {
25
- expect(SUPPORTED_CHAINS.ETHEREUM.chainId).toBe(1);
26
- expect(SUPPORTED_CHAINS.ETHEREUM.name).toBe('Ethereum');
27
- expect(SUPPORTED_CHAINS.ETHEREUM.rpcUrl).toBeDefined();
28
-
29
- console.log('Ethereum chain:', SUPPORTED_CHAINS.ETHEREUM);
30
- });
31
-
32
- it('should have correct Polygon chain info', () => {
33
- expect(SUPPORTED_CHAINS.POLYGON.chainId).toBe(137);
34
- expect(SUPPORTED_CHAINS.POLYGON.name).toBe('Polygon');
35
- expect(SUPPORTED_CHAINS.POLYGON.rpcUrl).toBeDefined();
36
-
37
- console.log('Polygon chain:', SUPPORTED_CHAINS.POLYGON);
38
- });
39
-
40
- it('should have correct token addresses', () => {
41
- // Ethereum tokens
42
- expect(BRIDGE_TOKENS.ETH_USDC).toMatch(/^0x[a-fA-F0-9]{40}$/);
43
- expect(BRIDGE_TOKENS.ETH_WETH).toMatch(/^0x[a-fA-F0-9]{40}$/);
44
- expect(BRIDGE_TOKENS.ETH_DAI).toMatch(/^0x[a-fA-F0-9]{40}$/);
45
-
46
- // Polygon tokens
47
- expect(BRIDGE_TOKENS.POLYGON_USDC_E).toMatch(/^0x[a-fA-F0-9]{40}$/);
48
- expect(BRIDGE_TOKENS.POLYGON_NATIVE_USDC).toMatch(/^0x[a-fA-F0-9]{40}$/);
49
-
50
- // Verify well-known addresses
51
- expect(BRIDGE_TOKENS.ETH_USDC.toLowerCase()).toBe(
52
- '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
53
- );
54
- expect(BRIDGE_TOKENS.POLYGON_USDC_E.toLowerCase()).toBe(
55
- '0x2791bca1f2de4661ed88a30c99a7a9449aa84174'
56
- );
57
-
58
- console.log('Token addresses verified:', BRIDGE_TOKENS);
59
- });
60
- });
61
-
62
- describe('Utility Functions', () => {
63
- describe('estimateBridgeOutput', () => {
64
- it('should estimate output for stablecoins', () => {
65
- const input = 1000;
66
- const output = estimateBridgeOutput(input, 'USDC');
67
-
68
- // Should be slightly less than input due to fees (~1%)
69
- expect(output).toBeLessThan(input);
70
- expect(output).toBeGreaterThan(input * 0.95);
71
-
72
- console.log(`Estimated output for ${input} USDC: ${output} USDC.e`);
73
- });
74
-
75
- it('should work for different stablecoins', () => {
76
- const stablecoins = ['USDC', 'USDT', 'DAI', 'BUSD'];
77
-
78
- for (const token of stablecoins) {
79
- const output = estimateBridgeOutput(100, token);
80
- expect(output).toBeCloseTo(99, 0); // ~1% fee
81
- }
82
-
83
- console.log('All stablecoins estimated correctly');
84
- });
85
-
86
- it('should work for ETH', () => {
87
- const output = estimateBridgeOutput(1, 'ETH');
88
- expect(output).toBeLessThan(1);
89
- expect(output).toBeGreaterThan(0.95);
90
-
91
- console.log(`Estimated output for 1 ETH: ${output} (in USDC.e equivalent)`);
92
- });
93
- });
94
-
95
- describe('getExplorerUrl', () => {
96
- const testTxHash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef';
97
-
98
- it('should return Etherscan URL for Ethereum', () => {
99
- const url = getExplorerUrl(1, testTxHash);
100
- expect(url).toContain('etherscan.io/tx/');
101
- expect(url).toContain(testTxHash);
102
-
103
- console.log(`Ethereum explorer URL: ${url}`);
104
- });
105
-
106
- it('should return Polygonscan URL for Polygon', () => {
107
- const url = getExplorerUrl(137, testTxHash);
108
- expect(url).toContain('polygonscan.com/tx/');
109
- expect(url).toContain(testTxHash);
110
-
111
- console.log(`Polygon explorer URL: ${url}`);
112
- });
113
-
114
- it('should return correct URLs for other chains', () => {
115
- const chains = [
116
- { id: 10, expected: 'optimistic.etherscan.io' },
117
- { id: 42161, expected: 'arbiscan.io' },
118
- { id: 8453, expected: 'basescan.org' },
119
- ];
120
-
121
- for (const chain of chains) {
122
- const url = getExplorerUrl(chain.id, testTxHash);
123
- expect(url).toContain(chain.expected);
124
- }
125
-
126
- console.log('All chain explorer URLs verified');
127
- });
128
-
129
- it('should return blockscan URL for unknown chains', () => {
130
- const url = getExplorerUrl(99999, testTxHash);
131
- expect(url).toContain('blockscan.com/tx/');
132
-
133
- console.log(`Unknown chain explorer URL: ${url}`);
134
- });
135
- });
136
- });
137
-
138
- describe('API Calls (may fail if API not accessible)', () => {
139
- it('should attempt to get supported assets', async () => {
140
- try {
141
- const assets = await bridge.getSupportedAssets();
142
-
143
- expect(Array.isArray(assets)).toBe(true);
144
-
145
- if (assets.length > 0) {
146
- // Verify asset structure
147
- for (const asset of assets) {
148
- expect(typeof asset.chainId).toBe('number');
149
- expect(typeof asset.chainName).toBe('string');
150
- expect(typeof asset.tokenAddress).toBe('string');
151
- expect(typeof asset.tokenSymbol).toBe('string');
152
- expect(typeof asset.active).toBe('boolean');
153
- }
154
-
155
- console.log(`Got ${assets.length} supported assets`);
156
- console.log('Sample asset:', assets[0]);
157
- } else {
158
- console.log('No assets returned (API may return empty array)');
159
- }
160
- } catch (error) {
161
- console.log('getSupportedAssets failed (expected if API not public)');
162
- console.log(`Error: ${(error as Error).message}`);
163
-
164
- // Don't fail the test - API may not be publicly accessible
165
- expect(true).toBe(true);
166
- }
167
- }, 30000);
168
-
169
- it('should attempt to check if Ethereum USDC is supported', async () => {
170
- try {
171
- const isSupported = await bridge.isSupported(1, 'USDC');
172
-
173
- expect(typeof isSupported).toBe('boolean');
174
- console.log(`Ethereum USDC supported: ${isSupported}`);
175
- } catch (error) {
176
- console.log('isSupported check failed (expected if API not public)');
177
- console.log(`Error: ${(error as Error).message}`);
178
- expect(true).toBe(true);
179
- }
180
- }, 30000);
181
-
182
- it('should attempt to get minimum deposit for Ethereum USDC', async () => {
183
- try {
184
- const minDeposit = await bridge.getMinDeposit(1, 'USDC');
185
-
186
- if (minDeposit) {
187
- expect(typeof minDeposit.amount).toBe('string');
188
- expect(typeof minDeposit.usd).toBe('number');
189
- console.log(`Min deposit for ETH USDC: ${minDeposit.amount} (~$${minDeposit.usd})`);
190
- } else {
191
- console.log('No minimum deposit info returned');
192
- }
193
- } catch (error) {
194
- console.log('getMinDeposit failed (expected if API not public)');
195
- console.log(`Error: ${(error as Error).message}`);
196
- expect(true).toBe(true);
197
- }
198
- }, 30000);
199
-
200
- it('should attempt to create deposit addresses', async () => {
201
- const testAddress = '0x82a1b239c1ff9bc60a4c86caf5b6bdbd9fddfe20'; // Known whale
202
-
203
- try {
204
- const result = await bridge.createDepositAddresses(testAddress);
205
-
206
- // API returns universal addresses for EVM, Solana, and Bitcoin
207
- expect(typeof result.address.evm).toBe('string');
208
- expect(typeof result.address.svm).toBe('string');
209
- expect(typeof result.address.btc).toBe('string');
210
-
211
- // EVM address should be valid Ethereum address format
212
- expect(result.address.evm).toMatch(/^0x[a-fA-F0-9]{40}$/);
213
-
214
- console.log('Got universal deposit addresses:');
215
- console.log(` EVM: ${result.address.evm}`);
216
- console.log(` Solana: ${result.address.svm}`);
217
- console.log(` Bitcoin: ${result.address.btc}`);
218
- } catch (error) {
219
- console.log('createDepositAddresses failed (expected if API not public)');
220
- console.log(`Error: ${(error as Error).message}`);
221
- expect(true).toBe(true);
222
- }
223
- }, 30000);
224
-
225
- it('should attempt to get deposit instructions', async () => {
226
- const testAddress = '0x82a1b239c1ff9bc60a4c86caf5b6bdbd9fddfe20';
227
-
228
- try {
229
- const instructions = await bridge.getDepositInstructions(testAddress);
230
-
231
- expect(typeof instructions).toBe('string');
232
- expect(instructions.length).toBeGreaterThan(0);
233
-
234
- // Should contain expected sections
235
- expect(instructions).toContain('POLYMARKET');
236
- expect(instructions).toContain(testAddress);
237
-
238
- console.log('Got deposit instructions:');
239
- console.log(instructions.slice(0, 500) + '...');
240
- } catch (error) {
241
- console.log('getDepositInstructions failed (expected if API not public)');
242
- console.log(`Error: ${(error as Error).message}`);
243
- expect(true).toBe(true);
244
- }
245
- }, 30000);
246
- });
247
-
248
- describe('BridgeClient Configuration', () => {
249
- it('should use default configuration', () => {
250
- const client = new BridgeClient();
251
- // Client should be created without errors
252
- expect(client).toBeDefined();
253
- });
254
-
255
- it('should accept custom configuration', () => {
256
- const client = new BridgeClient({
257
- baseUrl: 'https://custom-bridge.example.com',
258
- timeout: 60000,
259
- });
260
- expect(client).toBeDefined();
261
- });
262
- });
263
- });
264
-
265
- describe('Bridge Documentation', () => {
266
- it('should document the bridge deposit flow', () => {
267
- /**
268
- * Polymarket Bridge Deposit Flow:
269
- *
270
- * 1. User calls createDepositAddresses(walletAddress)
271
- * - Returns unique deposit addresses for each supported chain/token
272
- * - These addresses are specific to your Polymarket wallet
273
- *
274
- * 2. User sends tokens to the deposit address on the source chain
275
- * - Example: Send USDC on Ethereum to the ETH/USDC deposit address
276
- * - Must send more than the minimum deposit amount
277
- *
278
- * 3. Bridge automatically:
279
- * - Detects the incoming deposit
280
- * - Bridges funds to Polygon
281
- * - Swaps to USDC.e if necessary
282
- * - Credits USDC.e to user's Polymarket account
283
- *
284
- * 4. User can check deposit status
285
- * - Typical time: 10-30 minutes
286
- * - Status: pending → bridging → swapping → completed
287
- *
288
- * Supported chains (typical):
289
- * - Ethereum (Chain ID: 1)
290
- * - Arbitrum (Chain ID: 42161)
291
- * - Optimism (Chain ID: 10)
292
- * - Base (Chain ID: 8453)
293
- *
294
- * Supported tokens (typical):
295
- * - USDC, USDT, DAI, WETH, ETH
296
- */
297
-
298
- console.log('');
299
- console.log('Bridge Deposit Flow');
300
- console.log('═══════════════════════════════════════════════════════════');
301
- console.log('');
302
- console.log('1. Get deposit addresses: bridge.createDepositAddresses(walletAddress)');
303
- console.log('2. Send tokens to the unique deposit address on source chain');
304
- console.log('3. Wait 10-30 minutes for automatic bridging and conversion');
305
- console.log('4. USDC.e appears in your Polymarket account');
306
- console.log('');
307
- console.log('Supported chains: Ethereum, Arbitrum, Optimism, Base');
308
- console.log('Supported tokens: USDC, USDT, DAI, WETH, ETH');
309
- console.log('');
310
- console.log('═══════════════════════════════════════════════════════════');
311
-
312
- expect(true).toBe(true);
313
- });
314
- });
@@ -1,218 +0,0 @@
1
- /**
2
- * CLOB API Client Integration Tests
3
- *
4
- * These tests make REAL API calls to Polymarket.
5
- * They verify that:
6
- * 1. API endpoints are reachable
7
- * 2. Response structures match our types
8
- * 3. Data normalization works correctly
9
- *
10
- * Run with: pnpm test:integration
11
- */
12
-
13
- import { describe, it, expect, beforeAll } from 'vitest';
14
- import { ClobApiClient } from '../../clients/clob-api.js';
15
- import { RateLimiter } from '../../core/rate-limiter.js';
16
- import { createUnifiedCache } from '../../core/unified-cache.js';
17
-
18
- describe('ClobApiClient Integration', () => {
19
- let client: ClobApiClient;
20
-
21
- beforeAll(() => {
22
- client = new ClobApiClient(new RateLimiter(), createUnifiedCache());
23
- });
24
-
25
- describe('getMarket', () => {
26
- it('should fetch a real market from Polymarket', async () => {
27
- // Get trending markets first to find a valid condition ID
28
- const response = await fetch(
29
- 'https://gamma-api.polymarket.com/markets?active=true&limit=1&order=volume24hr&ascending=false'
30
- );
31
- const markets = await response.json() as Array<{ conditionId: string }>;
32
-
33
- if (markets.length === 0) {
34
- console.log('No active markets found, skipping test');
35
- return;
36
- }
37
-
38
- const conditionId = markets[0].conditionId;
39
- const market = await client.getMarket(conditionId);
40
-
41
- // Verify structure
42
- expect(market.conditionId).toBe(conditionId);
43
- expect(typeof market.question).toBe('string');
44
- expect(market.question.length).toBeGreaterThan(0);
45
- expect(Array.isArray(market.tokens)).toBe(true);
46
- expect(market.tokens.length).toBeGreaterThanOrEqual(2);
47
-
48
- // Verify tokens
49
- for (const token of market.tokens) {
50
- expect(typeof token.tokenId).toBe('string');
51
- expect(token.tokenId.length).toBeGreaterThan(0);
52
- expect(['Yes', 'No']).toContain(token.outcome);
53
- expect(typeof token.price).toBe('number');
54
- expect(token.price).toBeGreaterThanOrEqual(0);
55
- expect(token.price).toBeLessThanOrEqual(1);
56
- }
57
-
58
- // Verify other fields
59
- expect(typeof market.active).toBe('boolean');
60
- expect(typeof market.closed).toBe('boolean');
61
- expect(typeof market.acceptingOrders).toBe('boolean');
62
-
63
- console.log(`✓ Successfully fetched market: "${market.question.slice(0, 50)}..."`);
64
- }, 30000);
65
-
66
- it('should handle non-existent market gracefully', async () => {
67
- await expect(
68
- client.getMarket('0x0000000000000000000000000000000000000000000000000000000000000000')
69
- ).rejects.toThrow();
70
- }, 30000);
71
- });
72
-
73
- describe('getOrderbook', () => {
74
- it('should fetch real orderbook data', async () => {
75
- // First get a market to get token ID
76
- const response = await fetch(
77
- 'https://gamma-api.polymarket.com/markets?active=true&limit=1&order=volume24hr&ascending=false'
78
- );
79
- const markets = await response.json() as Array<{ conditionId: string }>;
80
-
81
- if (markets.length === 0) {
82
- console.log('No active markets found, skipping test');
83
- return;
84
- }
85
-
86
- const market = await client.getMarket(markets[0].conditionId);
87
- const yesToken = market.tokens.find(t => t.outcome === 'Yes');
88
-
89
- if (!yesToken) {
90
- console.log('No YES token found, skipping test');
91
- return;
92
- }
93
-
94
- const orderbook = await client.getOrderbook(yesToken.tokenId);
95
-
96
- // Verify structure
97
- expect(Array.isArray(orderbook.bids)).toBe(true);
98
- expect(Array.isArray(orderbook.asks)).toBe(true);
99
- expect(typeof orderbook.timestamp).toBe('number');
100
- expect(orderbook.timestamp).toBeGreaterThan(0);
101
-
102
- // Verify bids are sorted descending (if any exist)
103
- for (let i = 1; i < orderbook.bids.length; i++) {
104
- expect(orderbook.bids[i].price).toBeLessThanOrEqual(orderbook.bids[i - 1].price);
105
- }
106
-
107
- // Verify asks are sorted ascending (if any exist)
108
- for (let i = 1; i < orderbook.asks.length; i++) {
109
- expect(orderbook.asks[i].price).toBeGreaterThanOrEqual(orderbook.asks[i - 1].price);
110
- }
111
-
112
- // Verify price/size types
113
- if (orderbook.bids.length > 0) {
114
- expect(typeof orderbook.bids[0].price).toBe('number');
115
- expect(typeof orderbook.bids[0].size).toBe('number');
116
- expect(orderbook.bids[0].price).toBeGreaterThan(0);
117
- expect(orderbook.bids[0].price).toBeLessThan(1);
118
- }
119
-
120
- console.log(`✓ Orderbook: ${orderbook.bids.length} bids, ${orderbook.asks.length} asks`);
121
- }, 30000);
122
- });
123
-
124
- describe('getProcessedOrderbook', () => {
125
- it('should return complete processed orderbook with analytics', async () => {
126
- // Get an active market
127
- const response = await fetch(
128
- 'https://gamma-api.polymarket.com/markets?active=true&limit=5&order=volume24hr&ascending=false'
129
- );
130
- const markets = await response.json() as Array<{ conditionId: string; question: string }>;
131
-
132
- // Find a market with good liquidity
133
- let processed = null;
134
- for (const m of markets) {
135
- try {
136
- processed = await client.getProcessedOrderbook(m.conditionId);
137
- if (processed.yes.bid > 0 && processed.yes.ask < 1) {
138
- console.log(`✓ Using market: "${m.question.slice(0, 50)}..."`);
139
- break;
140
- }
141
- } catch {
142
- continue;
143
- }
144
- }
145
-
146
- if (!processed) {
147
- console.log('No liquid market found, skipping test');
148
- return;
149
- }
150
-
151
- // Verify YES orderbook
152
- expect(typeof processed.yes.bid).toBe('number');
153
- expect(typeof processed.yes.ask).toBe('number');
154
- expect(processed.yes.bid).toBeLessThanOrEqual(processed.yes.ask);
155
-
156
- // Verify NO orderbook
157
- expect(typeof processed.no.bid).toBe('number');
158
- expect(typeof processed.no.ask).toBe('number');
159
- expect(processed.no.bid).toBeLessThanOrEqual(processed.no.ask);
160
-
161
- // Verify summary
162
- expect(typeof processed.summary.effectiveLongCost).toBe('number');
163
- expect(typeof processed.summary.effectiveShortRevenue).toBe('number');
164
- expect(typeof processed.summary.longArbProfit).toBe('number');
165
- expect(typeof processed.summary.shortArbProfit).toBe('number');
166
-
167
- // Verify effective prices
168
- expect(typeof processed.summary.effectivePrices.effectiveBuyYes).toBe('number');
169
- expect(typeof processed.summary.effectivePrices.effectiveBuyNo).toBe('number');
170
- expect(typeof processed.summary.effectivePrices.effectiveSellYes).toBe('number');
171
- expect(typeof processed.summary.effectivePrices.effectiveSellNo).toBe('number');
172
-
173
- // Log arbitrage info
174
- console.log(` YES: bid=${processed.yes.bid.toFixed(3)}, ask=${processed.yes.ask.toFixed(3)}`);
175
- console.log(` NO: bid=${processed.no.bid.toFixed(3)}, ask=${processed.no.ask.toFixed(3)}`);
176
- console.log(` Long arb profit: ${(processed.summary.longArbProfit * 100).toFixed(3)}%`);
177
- console.log(` Short arb profit: ${(processed.summary.shortArbProfit * 100).toFixed(3)}%`);
178
- }, 60000);
179
-
180
- it('should correctly calculate effective prices with mirroring', async () => {
181
- const response = await fetch(
182
- 'https://gamma-api.polymarket.com/markets?active=true&limit=1&order=volume24hr&ascending=false'
183
- );
184
- const markets = await response.json() as Array<{ conditionId: string }>;
185
-
186
- if (markets.length === 0) return;
187
-
188
- const processed = await client.getProcessedOrderbook(markets[0].conditionId);
189
-
190
- // Verify mirroring logic:
191
- // effectiveBuyYes should be <= YES.ask (can't be worse than direct buy)
192
- expect(processed.summary.effectivePrices.effectiveBuyYes).toBeLessThanOrEqual(processed.yes.ask || 1);
193
-
194
- // effectiveBuyNo should be <= NO.ask
195
- expect(processed.summary.effectivePrices.effectiveBuyNo).toBeLessThanOrEqual(processed.no.ask || 1);
196
-
197
- // effectiveSellYes should be >= YES.bid (can't be worse than direct sell)
198
- expect(processed.summary.effectivePrices.effectiveSellYes).toBeGreaterThanOrEqual(processed.yes.bid);
199
-
200
- // effectiveSellNo should be >= NO.bid
201
- expect(processed.summary.effectivePrices.effectiveSellNo).toBeGreaterThanOrEqual(processed.no.bid);
202
-
203
- // Long cost should equal sum of effective buy prices
204
- const expectedLongCost =
205
- processed.summary.effectivePrices.effectiveBuyYes +
206
- processed.summary.effectivePrices.effectiveBuyNo;
207
- expect(processed.summary.effectiveLongCost).toBeCloseTo(expectedLongCost, 6);
208
-
209
- // Short revenue should equal sum of effective sell prices
210
- const expectedShortRevenue =
211
- processed.summary.effectivePrices.effectiveSellYes +
212
- processed.summary.effectivePrices.effectiveSellNo;
213
- expect(processed.summary.effectiveShortRevenue).toBeCloseTo(expectedShortRevenue, 6);
214
-
215
- console.log('✓ Effective price calculations verified');
216
- }, 30000);
217
- });
218
- });