@polymarbot/shared 0.5.0 → 0.5.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polymarbot/shared",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -61,7 +61,7 @@ function normalizeTradeStepBuy(step, options) {
61
61
  const isChaseMode = price > 0.5;
62
62
  if (isLowPriceMode) {
63
63
  if (step.maxUnderlyingChange !== void 0) {
64
- if (step.maxUnderlyingChange >= 1 && step.maxUnderlyingChange <= 1e3) {
64
+ if (step.maxUnderlyingChange >= 1 && step.maxUnderlyingChange <= 1e4) {
65
65
  normalized.maxUnderlyingChange = step.maxUnderlyingChange;
66
66
  } else {
67
67
  }
@@ -71,7 +71,7 @@ function normalizeTradeStepBuy(step, options) {
71
71
  }
72
72
  if (isChaseMode) {
73
73
  if (step.minUnderlyingChange !== void 0) {
74
- if (step.minUnderlyingChange >= 1 && step.minUnderlyingChange <= 1e3) {
74
+ if (step.minUnderlyingChange >= 1 && step.minUnderlyingChange <= 1e4) {
75
75
  normalized.minUnderlyingChange = step.minUnderlyingChange;
76
76
  } else {
77
77
  }
@@ -138,6 +138,12 @@ function normalizeStrategy(config, options = {}) {
138
138
  normalized.push(normalizedStep);
139
139
  }
140
140
  });
141
+ const totalBuySize = normalized.filter((step) => step.side === "BUY" /* BUY */).reduce((sum, step) => sum + step.size, 0);
142
+ for (const step of normalized) {
143
+ if (step.side === "SELL" /* SELL */ && step.size > totalBuySize) {
144
+ step.size = totalBuySize;
145
+ }
146
+ }
141
147
  return normalized;
142
148
  }
143
149
  function hasTradeStepsBuy(config) {
@@ -37,7 +37,7 @@ function normalizeTradeStepBuy(step, options) {
37
37
  const isChaseMode = price > 0.5;
38
38
  if (isLowPriceMode) {
39
39
  if (step.maxUnderlyingChange !== void 0) {
40
- if (step.maxUnderlyingChange >= 1 && step.maxUnderlyingChange <= 1e3) {
40
+ if (step.maxUnderlyingChange >= 1 && step.maxUnderlyingChange <= 1e4) {
41
41
  normalized.maxUnderlyingChange = step.maxUnderlyingChange;
42
42
  } else {
43
43
  }
@@ -47,7 +47,7 @@ function normalizeTradeStepBuy(step, options) {
47
47
  }
48
48
  if (isChaseMode) {
49
49
  if (step.minUnderlyingChange !== void 0) {
50
- if (step.minUnderlyingChange >= 1 && step.minUnderlyingChange <= 1e3) {
50
+ if (step.minUnderlyingChange >= 1 && step.minUnderlyingChange <= 1e4) {
51
51
  normalized.minUnderlyingChange = step.minUnderlyingChange;
52
52
  } else {
53
53
  }
@@ -114,6 +114,12 @@ function normalizeStrategy(config, options = {}) {
114
114
  normalized.push(normalizedStep);
115
115
  }
116
116
  });
117
+ const totalBuySize = normalized.filter((step) => step.side === "BUY" /* BUY */).reduce((sum, step) => sum + step.size, 0);
118
+ for (const step of normalized) {
119
+ if (step.side === "SELL" /* SELL */ && step.size > totalBuySize) {
120
+ step.size = totalBuySize;
121
+ }
122
+ }
117
123
  return normalized;
118
124
  }
119
125
  function hasTradeStepsBuy(config) {
@@ -94,6 +94,8 @@ interface TokenTradeRecordData {
94
94
  interface MarketTradeRecord {
95
95
  marketId: string;
96
96
  strategyJson: string;
97
+
98
+ strategyDataSaved?: boolean;
97
99
  tokens: {
98
100
  [tokenId: string]: TokenTradeRecordData;
99
101
  };
@@ -94,6 +94,8 @@ interface TokenTradeRecordData {
94
94
  interface MarketTradeRecord {
95
95
  marketId: string;
96
96
  strategyJson: string;
97
+
98
+ strategyDataSaved?: boolean;
97
99
  tokens: {
98
100
  [tokenId: string]: TokenTradeRecordData;
99
101
  };
package/wallet.cjs CHANGED
@@ -35,14 +35,24 @@ var import_chains = require("viem/chains");
35
35
  var USDC_ADDRESS = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
36
36
  var USDC_DECIMALS = 6;
37
37
  var USDC_ABI = (0, import_viem.parseAbi)(["function balanceOf(address) view returns (uint256)"]);
38
- var getPublicClient = (() => {
39
- const POLYGON_RPC = process.env.POLYGON_RPC || import_chains.polygon.rpcUrls.default.http[0];
38
+ var getPublicClient = /* @__PURE__ */ (() => {
40
39
  let client = null;
41
- return () => {
40
+ let batchClient = null;
41
+ return (options) => {
42
+ const rpcUrl = process.env.POLYGON_RPC || import_chains.polygon.rpcUrls.default.http[0];
43
+ if (options?.batch) {
44
+ if (!batchClient) {
45
+ batchClient = (0, import_viem.createPublicClient)({
46
+ chain: import_chains.polygon,
47
+ transport: (0, import_viem.http)(rpcUrl, { batch: { batchSize: 100, wait: 0 } })
48
+ });
49
+ }
50
+ return batchClient;
51
+ }
42
52
  if (!client) {
43
53
  client = (0, import_viem.createPublicClient)({
44
54
  chain: import_chains.polygon,
45
- transport: (0, import_viem.http)(POLYGON_RPC)
55
+ transport: (0, import_viem.http)(rpcUrl)
46
56
  });
47
57
  }
48
58
  return client;
package/wallet.d.cts CHANGED
@@ -14,7 +14,9 @@ declare const USDC_ABI: readonly [{
14
14
  }];
15
15
  }];
16
16
 
17
- declare const getPublicClient: () => PublicClient;
17
+ declare const getPublicClient: (options?: {
18
+ batch?: boolean;
19
+ }) => PublicClient;
18
20
 
19
21
  declare function formatBalance(rawBalance: string | bigint, decimals?: number): string;
20
22
 
package/wallet.d.ts CHANGED
@@ -14,7 +14,9 @@ declare const USDC_ABI: readonly [{
14
14
  }];
15
15
  }];
16
16
 
17
- declare const getPublicClient: () => PublicClient;
17
+ declare const getPublicClient: (options?: {
18
+ batch?: boolean;
19
+ }) => PublicClient;
18
20
 
19
21
  declare function formatBalance(rawBalance: string | bigint, decimals?: number): string;
20
22
 
package/wallet.js CHANGED
@@ -6,14 +6,24 @@ import { polygon } from "viem/chains";
6
6
  var USDC_ADDRESS = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
7
7
  var USDC_DECIMALS = 6;
8
8
  var USDC_ABI = parseAbi(["function balanceOf(address) view returns (uint256)"]);
9
- var getPublicClient = (() => {
10
- const POLYGON_RPC = process.env.POLYGON_RPC || polygon.rpcUrls.default.http[0];
9
+ var getPublicClient = /* @__PURE__ */ (() => {
11
10
  let client = null;
12
- return () => {
11
+ let batchClient = null;
12
+ return (options) => {
13
+ const rpcUrl = process.env.POLYGON_RPC || polygon.rpcUrls.default.http[0];
14
+ if (options?.batch) {
15
+ if (!batchClient) {
16
+ batchClient = createPublicClient({
17
+ chain: polygon,
18
+ transport: http(rpcUrl, { batch: { batchSize: 100, wait: 0 } })
19
+ });
20
+ }
21
+ return batchClient;
22
+ }
13
23
  if (!client) {
14
24
  client = createPublicClient({
15
25
  chain: polygon,
16
- transport: http(POLYGON_RPC)
26
+ transport: http(rpcUrl)
17
27
  });
18
28
  }
19
29
  return client;