@signals-protocol/v1-sdk 1.0.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.
@@ -0,0 +1,309 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_UINT256 = exports.UUNIT = exports.UEXP_MAX_INPUT = void 0;
4
+ exports.expWad = exp;
5
+ exports.lnWad = ln;
6
+ const UUNIT = 1000000000000000000n;
7
+ exports.UUNIT = UUNIT;
8
+ const UHALF_UNIT = 500000000000000000n;
9
+ const ULOG2_E = 1442695040888963407n;
10
+ const UEXP_MAX_INPUT = 133084258667509499440n;
11
+ exports.UEXP_MAX_INPUT = UEXP_MAX_INPUT;
12
+ const UEXP2_MAX_INPUT = 192000000000000000000n - 1n;
13
+ const MAX_UINT256 = (1n << 256n) - 1n;
14
+ exports.MAX_UINT256 = MAX_UINT256;
15
+ function msb(x) {
16
+ let result = 0n;
17
+ if (x >= (1n << 128n)) {
18
+ x >>= 128n;
19
+ result += 128n;
20
+ }
21
+ if (x >= (1n << 64n)) {
22
+ x >>= 64n;
23
+ result += 64n;
24
+ }
25
+ if (x >= (1n << 32n)) {
26
+ x >>= 32n;
27
+ result += 32n;
28
+ }
29
+ if (x >= (1n << 16n)) {
30
+ x >>= 16n;
31
+ result += 16n;
32
+ }
33
+ if (x >= (1n << 8n)) {
34
+ x >>= 8n;
35
+ result += 8n;
36
+ }
37
+ if (x >= (1n << 4n)) {
38
+ x >>= 4n;
39
+ result += 4n;
40
+ }
41
+ if (x >= (1n << 2n)) {
42
+ x >>= 2n;
43
+ result += 2n;
44
+ }
45
+ if (x >= (1n << 1n)) {
46
+ result += 1n;
47
+ }
48
+ return result;
49
+ }
50
+ function exp2_192x64(x) {
51
+ let result = 0x800000000000000000000000000000000000000000000000n;
52
+ if ((x & 0xff00000000000000n) > 0n) {
53
+ if ((x & 0x8000000000000000n) > 0n) {
54
+ result = (result * 0x16a09e667f3bcc909n) >> 64n;
55
+ }
56
+ if ((x & 0x4000000000000000n) > 0n) {
57
+ result = (result * 0x1306fe0a31b7152dfn) >> 64n;
58
+ }
59
+ if ((x & 0x2000000000000000n) > 0n) {
60
+ result = (result * 0x1172b83c7d517adcen) >> 64n;
61
+ }
62
+ if ((x & 0x1000000000000000n) > 0n) {
63
+ result = (result * 0x10b5586cf9890f62an) >> 64n;
64
+ }
65
+ if ((x & 0x800000000000000n) > 0n) {
66
+ result = (result * 0x1059b0d31585743aen) >> 64n;
67
+ }
68
+ if ((x & 0x400000000000000n) > 0n) {
69
+ result = (result * 0x102c9a3e778060ee7n) >> 64n;
70
+ }
71
+ if ((x & 0x200000000000000n) > 0n) {
72
+ result = (result * 0x10163da9fb33356d8n) >> 64n;
73
+ }
74
+ if ((x & 0x100000000000000n) > 0n) {
75
+ result = (result * 0x100b1afa5abcbed61n) >> 64n;
76
+ }
77
+ }
78
+ if ((x & 0xff000000000000n) > 0n) {
79
+ if ((x & 0x80000000000000n) > 0n) {
80
+ result = (result * 0x10058c86da1c09ea2n) >> 64n;
81
+ }
82
+ if ((x & 0x40000000000000n) > 0n) {
83
+ result = (result * 0x1002c605e2e8cec50n) >> 64n;
84
+ }
85
+ if ((x & 0x20000000000000n) > 0n) {
86
+ result = (result * 0x100162f3904051fa1n) >> 64n;
87
+ }
88
+ if ((x & 0x10000000000000n) > 0n) {
89
+ result = (result * 0x1000b175effdc76ban) >> 64n;
90
+ }
91
+ if ((x & 0x8000000000000n) > 0n) {
92
+ result = (result * 0x100058ba01fb9f96dn) >> 64n;
93
+ }
94
+ if ((x & 0x4000000000000n) > 0n) {
95
+ result = (result * 0x10002c5cc37da9492n) >> 64n;
96
+ }
97
+ if ((x & 0x2000000000000n) > 0n) {
98
+ result = (result * 0x1000162e525ee0547n) >> 64n;
99
+ }
100
+ if ((x & 0x1000000000000n) > 0n) {
101
+ result = (result * 0x10000b17255775c04n) >> 64n;
102
+ }
103
+ }
104
+ if ((x & 0xff0000000000n) > 0n) {
105
+ if ((x & 0x800000000000n) > 0n) {
106
+ result = (result * 0x1000058b91b5bc9aen) >> 64n;
107
+ }
108
+ if ((x & 0x400000000000n) > 0n) {
109
+ result = (result * 0x100002c5c89d5ec6dn) >> 64n;
110
+ }
111
+ if ((x & 0x200000000000n) > 0n) {
112
+ result = (result * 0x10000162e43f4f831n) >> 64n;
113
+ }
114
+ if ((x & 0x100000000000n) > 0n) {
115
+ result = (result * 0x100000b1721bcfc9an) >> 64n;
116
+ }
117
+ if ((x & 0x80000000000n) > 0n) {
118
+ result = (result * 0x10000058b90cf1e6en) >> 64n;
119
+ }
120
+ if ((x & 0x40000000000n) > 0n) {
121
+ result = (result * 0x1000002c5c863b73fn) >> 64n;
122
+ }
123
+ if ((x & 0x20000000000n) > 0n) {
124
+ result = (result * 0x100000162e430e5a2n) >> 64n;
125
+ }
126
+ if ((x & 0x10000000000n) > 0n) {
127
+ result = (result * 0x1000000b172183551n) >> 64n;
128
+ }
129
+ }
130
+ if ((x & 0xff00000000n) > 0n) {
131
+ if ((x & 0x8000000000n) > 0n) {
132
+ result = (result * 0x100000058b90c0b49n) >> 64n;
133
+ }
134
+ if ((x & 0x4000000000n) > 0n) {
135
+ result = (result * 0x10000002c5c8601ccn) >> 64n;
136
+ }
137
+ if ((x & 0x2000000000n) > 0n) {
138
+ result = (result * 0x1000000162e42fff0n) >> 64n;
139
+ }
140
+ if ((x & 0x1000000000n) > 0n) {
141
+ result = (result * 0x10000000b17217fbbn) >> 64n;
142
+ }
143
+ if ((x & 0x800000000n) > 0n) {
144
+ result = (result * 0x1000000058b90bfcen) >> 64n;
145
+ }
146
+ if ((x & 0x400000000n) > 0n) {
147
+ result = (result * 0x100000002c5c85fe3n) >> 64n;
148
+ }
149
+ if ((x & 0x200000000n) > 0n) {
150
+ result = (result * 0x10000000162e42ff1n) >> 64n;
151
+ }
152
+ if ((x & 0x100000000n) > 0n) {
153
+ result = (result * 0x100000000b17217f8n) >> 64n;
154
+ }
155
+ }
156
+ if ((x & 0xff000000n) > 0n) {
157
+ if ((x & 0x80000000n) > 0n) {
158
+ result = (result * 0x10000000058b90bfcn) >> 64n;
159
+ }
160
+ if ((x & 0x40000000n) > 0n) {
161
+ result = (result * 0x1000000002c5c85fen) >> 64n;
162
+ }
163
+ if ((x & 0x20000000n) > 0n) {
164
+ result = (result * 0x100000000162e42ffn) >> 64n;
165
+ }
166
+ if ((x & 0x10000000n) > 0n) {
167
+ result = (result * 0x1000000000b17217fn) >> 64n;
168
+ }
169
+ if ((x & 0x8000000n) > 0n) {
170
+ result = (result * 0x100000000058b90c0n) >> 64n;
171
+ }
172
+ if ((x & 0x4000000n) > 0n) {
173
+ result = (result * 0x10000000002c5c860n) >> 64n;
174
+ }
175
+ if ((x & 0x2000000n) > 0n) {
176
+ result = (result * 0x1000000000162e430n) >> 64n;
177
+ }
178
+ if ((x & 0x1000000n) > 0n) {
179
+ result = (result * 0x10000000000b17218n) >> 64n;
180
+ }
181
+ }
182
+ if ((x & 0xff0000n) > 0n) {
183
+ if ((x & 0x800000n) > 0n) {
184
+ result = (result * 0x1000000000058b90cn) >> 64n;
185
+ }
186
+ if ((x & 0x400000n) > 0n) {
187
+ result = (result * 0x100000000002c5c86n) >> 64n;
188
+ }
189
+ if ((x & 0x200000n) > 0n) {
190
+ result = (result * 0x10000000000162e43n) >> 64n;
191
+ }
192
+ if ((x & 0x100000n) > 0n) {
193
+ result = (result * 0x100000000000b1721n) >> 64n;
194
+ }
195
+ if ((x & 0x80000n) > 0n) {
196
+ result = (result * 0x10000000000058b91n) >> 64n;
197
+ }
198
+ if ((x & 0x40000n) > 0n) {
199
+ result = (result * 0x1000000000002c5c8n) >> 64n;
200
+ }
201
+ if ((x & 0x20000n) > 0n) {
202
+ result = (result * 0x100000000000162e4n) >> 64n;
203
+ }
204
+ if ((x & 0x10000n) > 0n) {
205
+ result = (result * 0x1000000000000b172n) >> 64n;
206
+ }
207
+ }
208
+ if ((x & 0xff00n) > 0n) {
209
+ if ((x & 0x8000n) > 0n) {
210
+ result = (result * 0x100000000000058b9n) >> 64n;
211
+ }
212
+ if ((x & 0x4000n) > 0n) {
213
+ result = (result * 0x10000000000002c5dn) >> 64n;
214
+ }
215
+ if ((x & 0x2000n) > 0n) {
216
+ result = (result * 0x1000000000000162en) >> 64n;
217
+ }
218
+ if ((x & 0x1000n) > 0n) {
219
+ result = (result * 0x10000000000000b17n) >> 64n;
220
+ }
221
+ if ((x & 0x800n) > 0n) {
222
+ result = (result * 0x1000000000000058cn) >> 64n;
223
+ }
224
+ if ((x & 0x400n) > 0n) {
225
+ result = (result * 0x100000000000002c6n) >> 64n;
226
+ }
227
+ if ((x & 0x200n) > 0n) {
228
+ result = (result * 0x10000000000000163n) >> 64n;
229
+ }
230
+ if ((x & 0x100n) > 0n) {
231
+ result = (result * 0x100000000000000b1n) >> 64n;
232
+ }
233
+ }
234
+ if ((x & 0xffn) > 0n) {
235
+ if ((x & 0x80n) > 0n) {
236
+ result = (result * 0x10000000000000059n) >> 64n;
237
+ }
238
+ if ((x & 0x40n) > 0n) {
239
+ result = (result * 0x1000000000000002cn) >> 64n;
240
+ }
241
+ if ((x & 0x20n) > 0n) {
242
+ result = (result * 0x10000000000000016n) >> 64n;
243
+ }
244
+ if ((x & 0x10n) > 0n) {
245
+ result = (result * 0x1000000000000000bn) >> 64n;
246
+ }
247
+ if ((x & 0x8n) > 0n) {
248
+ result = (result * 0x10000000000000006n) >> 64n;
249
+ }
250
+ if ((x & 0x4n) > 0n) {
251
+ result = (result * 0x10000000000000003n) >> 64n;
252
+ }
253
+ if ((x & 0x2n) > 0n) {
254
+ result = (result * 0x10000000000000001n) >> 64n;
255
+ }
256
+ if ((x & 0x1n) > 0n) {
257
+ result = (result * 0x10000000000000001n) >> 64n;
258
+ }
259
+ }
260
+ result *= UUNIT;
261
+ result >>= 191n - (x >> 64n);
262
+ return result;
263
+ }
264
+ function exp2(x) {
265
+ if (x > UEXP2_MAX_INPUT) {
266
+ throw new RangeError("exp2 input too large");
267
+ }
268
+ const x192x64 = (x << 64n) / UUNIT;
269
+ return exp2_192x64(x192x64);
270
+ }
271
+ function log2(x) {
272
+ if (x < UUNIT) {
273
+ throw new RangeError("log2 input too small");
274
+ }
275
+ const n = msb(x / UUNIT);
276
+ let result = n * UUNIT;
277
+ let y = x >> n;
278
+ if (y === UUNIT) {
279
+ return result;
280
+ }
281
+ const DOUBLE_UNIT = 2n * UUNIT;
282
+ for (let delta = UHALF_UNIT; delta > 0n; delta >>= 1n) {
283
+ y = (y * y) / UUNIT;
284
+ if (y >= DOUBLE_UNIT) {
285
+ result += delta;
286
+ y >>= 1n;
287
+ }
288
+ }
289
+ return result;
290
+ }
291
+ function ln(x) {
292
+ if (x < UUNIT) {
293
+ throw new RangeError("ln input too small");
294
+ }
295
+ if (x === UUNIT) {
296
+ return 0n;
297
+ }
298
+ return (log2(x) * UUNIT) / ULOG2_E;
299
+ }
300
+ function exp(x) {
301
+ if (x > UEXP_MAX_INPUT) {
302
+ throw new RangeError("exp input too large");
303
+ }
304
+ if (x === 0n) {
305
+ return UUNIT;
306
+ }
307
+ const doubleUnitProduct = x * ULOG2_E;
308
+ return exp2(doubleUnitProduct / UUNIT);
309
+ }
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@signals-protocol/v1-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Signals v1 SDK for CLMSR market calculations and utilities",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "dev": "tsc --watch",
11
+ "test": "jest",
12
+ "test:watch": "jest --watch",
13
+ "lint": "eslint src/**/*.ts",
14
+ "format": "prettier --write src/**/*.ts",
15
+ "clean": "rm -rf dist",
16
+ "rebuild": "npm run clean && npm run build"
17
+ },
18
+ "keywords": [
19
+ "signals",
20
+ "clmsr",
21
+ "v1",
22
+ "prediction-markets",
23
+ "lmsr",
24
+ "typescript",
25
+ "defi"
26
+ ],
27
+ "author": "Signals Team",
28
+ "license": "MIT",
29
+ "devDependencies": {
30
+ "@types/big.js": "^6.2.2",
31
+ "@types/jest": "^30.0.0",
32
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
33
+ "@typescript-eslint/parser": "^6.0.0",
34
+ "eslint": "^8.0.0",
35
+ "jest": "^29.5.0",
36
+ "prettier": "^3.0.0",
37
+ "ts-jest": "^29.1.0",
38
+ "typedoc": "^0.28.10",
39
+ "typedoc-docusaurus-theme": "^1.4.2",
40
+ "typedoc-plugin-markdown": "^4.8.1",
41
+ "typescript": "^5.0.0"
42
+ },
43
+ "dependencies": {
44
+ "big.js": "^6.2.1",
45
+ "ethers": "^6.14.3"
46
+ },
47
+ "files": [
48
+ "dist"
49
+ ],
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/signals-protocol/signals.git"
53
+ },
54
+ "exports": {
55
+ ".": {
56
+ "import": "./dist/index.js",
57
+ "require": "./dist/index.js",
58
+ "types": "./dist/index.d.ts"
59
+ },
60
+ "./package.json": "./package.json"
61
+ }
62
+ }