@cypher-zk/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/LICENSE +32 -0
- package/README.md +266 -0
- package/dist/chunk-5WRI5ZAA.js +29 -0
- package/dist/chunk-5WRI5ZAA.js.map +1 -0
- package/dist/client-CO5-Gpyu.d.ts +6414 -0
- package/dist/cypher-WAYH63ZA.json +5288 -0
- package/dist/index.d.ts +507 -0
- package/dist/index.js +3635 -0
- package/dist/index.js.map +1 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +3 -0
- package/dist/node/index.js.map +1 -0
- package/dist/react/index.d.ts +164 -0
- package/dist/react/index.js +163 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +97 -0
- package/src/idl/cypher.json +5288 -0
- package/src/idl/cypher.ts +5294 -0
- package/src/idl/index.ts +8 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3635 @@
|
|
|
1
|
+
import { __commonJS, __toESM } from './chunk-5WRI5ZAA.js';
|
|
2
|
+
import idlJson from './cypher-WAYH63ZA.json';
|
|
3
|
+
import { PublicKey, AddressLookupTableProgram, SystemProgram, Transaction } from '@solana/web3.js';
|
|
4
|
+
import { BN, AnchorProvider, Program, BorshCoder, EventParser } from '@anchor-lang/core';
|
|
5
|
+
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
6
|
+
export { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
|
|
7
|
+
import { getCompDefAccOffset, getMXEAccAddress, getCompDefAccAddress, getArciumProgramId, getLookupTableAddress, getClockAccAddress, getFeePoolAccAddress, getExecutingPoolAccAddress, getMempoolAccAddress, getClusterAccAddress, getComputationAccAddress, awaitComputationFinalization, x25519, RescueCipher, getMXEPublicKey } from '@arcium-hq/client';
|
|
8
|
+
|
|
9
|
+
// node_modules/base64-js/index.js
|
|
10
|
+
var require_base64_js = __commonJS({
|
|
11
|
+
"node_modules/base64-js/index.js"(exports) {
|
|
12
|
+
exports.byteLength = byteLength;
|
|
13
|
+
exports.toByteArray = toByteArray;
|
|
14
|
+
exports.fromByteArray = fromByteArray;
|
|
15
|
+
var lookup = [];
|
|
16
|
+
var revLookup = [];
|
|
17
|
+
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
18
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
19
|
+
for (i = 0, len = code.length; i < len; ++i) {
|
|
20
|
+
lookup[i] = code[i];
|
|
21
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
22
|
+
}
|
|
23
|
+
var i;
|
|
24
|
+
var len;
|
|
25
|
+
revLookup["-".charCodeAt(0)] = 62;
|
|
26
|
+
revLookup["_".charCodeAt(0)] = 63;
|
|
27
|
+
function getLens(b64) {
|
|
28
|
+
var len2 = b64.length;
|
|
29
|
+
if (len2 % 4 > 0) {
|
|
30
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
31
|
+
}
|
|
32
|
+
var validLen = b64.indexOf("=");
|
|
33
|
+
if (validLen === -1) validLen = len2;
|
|
34
|
+
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
35
|
+
return [validLen, placeHoldersLen];
|
|
36
|
+
}
|
|
37
|
+
function byteLength(b64) {
|
|
38
|
+
var lens = getLens(b64);
|
|
39
|
+
var validLen = lens[0];
|
|
40
|
+
var placeHoldersLen = lens[1];
|
|
41
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
42
|
+
}
|
|
43
|
+
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
44
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
45
|
+
}
|
|
46
|
+
function toByteArray(b64) {
|
|
47
|
+
var tmp;
|
|
48
|
+
var lens = getLens(b64);
|
|
49
|
+
var validLen = lens[0];
|
|
50
|
+
var placeHoldersLen = lens[1];
|
|
51
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
52
|
+
var curByte = 0;
|
|
53
|
+
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
54
|
+
var i2;
|
|
55
|
+
for (i2 = 0; i2 < len2; i2 += 4) {
|
|
56
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
57
|
+
arr[curByte++] = tmp >> 16 & 255;
|
|
58
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
59
|
+
arr[curByte++] = tmp & 255;
|
|
60
|
+
}
|
|
61
|
+
if (placeHoldersLen === 2) {
|
|
62
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
63
|
+
arr[curByte++] = tmp & 255;
|
|
64
|
+
}
|
|
65
|
+
if (placeHoldersLen === 1) {
|
|
66
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
67
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
68
|
+
arr[curByte++] = tmp & 255;
|
|
69
|
+
}
|
|
70
|
+
return arr;
|
|
71
|
+
}
|
|
72
|
+
function tripletToBase64(num) {
|
|
73
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
74
|
+
}
|
|
75
|
+
function encodeChunk(uint8, start, end) {
|
|
76
|
+
var tmp;
|
|
77
|
+
var output = [];
|
|
78
|
+
for (var i2 = start; i2 < end; i2 += 3) {
|
|
79
|
+
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
80
|
+
output.push(tripletToBase64(tmp));
|
|
81
|
+
}
|
|
82
|
+
return output.join("");
|
|
83
|
+
}
|
|
84
|
+
function fromByteArray(uint8) {
|
|
85
|
+
var tmp;
|
|
86
|
+
var len2 = uint8.length;
|
|
87
|
+
var extraBytes = len2 % 3;
|
|
88
|
+
var parts = [];
|
|
89
|
+
var maxChunkLength = 16383;
|
|
90
|
+
for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) {
|
|
91
|
+
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
92
|
+
}
|
|
93
|
+
if (extraBytes === 1) {
|
|
94
|
+
tmp = uint8[len2 - 1];
|
|
95
|
+
parts.push(
|
|
96
|
+
lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "=="
|
|
97
|
+
);
|
|
98
|
+
} else if (extraBytes === 2) {
|
|
99
|
+
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
100
|
+
parts.push(
|
|
101
|
+
lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return parts.join("");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// node_modules/ieee754/index.js
|
|
110
|
+
var require_ieee754 = __commonJS({
|
|
111
|
+
"node_modules/ieee754/index.js"(exports) {
|
|
112
|
+
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
113
|
+
var e, m;
|
|
114
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
115
|
+
var eMax = (1 << eLen) - 1;
|
|
116
|
+
var eBias = eMax >> 1;
|
|
117
|
+
var nBits = -7;
|
|
118
|
+
var i = isLE ? nBytes - 1 : 0;
|
|
119
|
+
var d = isLE ? -1 : 1;
|
|
120
|
+
var s = buffer[offset + i];
|
|
121
|
+
i += d;
|
|
122
|
+
e = s & (1 << -nBits) - 1;
|
|
123
|
+
s >>= -nBits;
|
|
124
|
+
nBits += eLen;
|
|
125
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
126
|
+
}
|
|
127
|
+
m = e & (1 << -nBits) - 1;
|
|
128
|
+
e >>= -nBits;
|
|
129
|
+
nBits += mLen;
|
|
130
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
131
|
+
}
|
|
132
|
+
if (e === 0) {
|
|
133
|
+
e = 1 - eBias;
|
|
134
|
+
} else if (e === eMax) {
|
|
135
|
+
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
136
|
+
} else {
|
|
137
|
+
m = m + Math.pow(2, mLen);
|
|
138
|
+
e = e - eBias;
|
|
139
|
+
}
|
|
140
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
141
|
+
};
|
|
142
|
+
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
143
|
+
var e, m, c;
|
|
144
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
145
|
+
var eMax = (1 << eLen) - 1;
|
|
146
|
+
var eBias = eMax >> 1;
|
|
147
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
148
|
+
var i = isLE ? 0 : nBytes - 1;
|
|
149
|
+
var d = isLE ? 1 : -1;
|
|
150
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
151
|
+
value = Math.abs(value);
|
|
152
|
+
if (isNaN(value) || value === Infinity) {
|
|
153
|
+
m = isNaN(value) ? 1 : 0;
|
|
154
|
+
e = eMax;
|
|
155
|
+
} else {
|
|
156
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
157
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
158
|
+
e--;
|
|
159
|
+
c *= 2;
|
|
160
|
+
}
|
|
161
|
+
if (e + eBias >= 1) {
|
|
162
|
+
value += rt / c;
|
|
163
|
+
} else {
|
|
164
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
165
|
+
}
|
|
166
|
+
if (value * c >= 2) {
|
|
167
|
+
e++;
|
|
168
|
+
c /= 2;
|
|
169
|
+
}
|
|
170
|
+
if (e + eBias >= eMax) {
|
|
171
|
+
m = 0;
|
|
172
|
+
e = eMax;
|
|
173
|
+
} else if (e + eBias >= 1) {
|
|
174
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
175
|
+
e = e + eBias;
|
|
176
|
+
} else {
|
|
177
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
178
|
+
e = 0;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
|
|
182
|
+
}
|
|
183
|
+
e = e << mLen | m;
|
|
184
|
+
eLen += mLen;
|
|
185
|
+
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
|
|
186
|
+
}
|
|
187
|
+
buffer[offset + i - d] |= s * 128;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// node_modules/buffer/index.js
|
|
193
|
+
var require_buffer = __commonJS({
|
|
194
|
+
"node_modules/buffer/index.js"(exports) {
|
|
195
|
+
var base64 = require_base64_js();
|
|
196
|
+
var ieee754 = require_ieee754();
|
|
197
|
+
var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
|
|
198
|
+
exports.Buffer = Buffer2;
|
|
199
|
+
exports.SlowBuffer = SlowBuffer;
|
|
200
|
+
exports.INSPECT_MAX_BYTES = 50;
|
|
201
|
+
var K_MAX_LENGTH = 2147483647;
|
|
202
|
+
exports.kMaxLength = K_MAX_LENGTH;
|
|
203
|
+
Buffer2.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
204
|
+
if (!Buffer2.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
|
|
205
|
+
console.error(
|
|
206
|
+
"This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
function typedArraySupport() {
|
|
210
|
+
try {
|
|
211
|
+
const arr = new Uint8Array(1);
|
|
212
|
+
const proto = { foo: function() {
|
|
213
|
+
return 42;
|
|
214
|
+
} };
|
|
215
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
216
|
+
Object.setPrototypeOf(arr, proto);
|
|
217
|
+
return arr.foo() === 42;
|
|
218
|
+
} catch (e) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
Object.defineProperty(Buffer2.prototype, "parent", {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
get: function() {
|
|
225
|
+
if (!Buffer2.isBuffer(this)) return void 0;
|
|
226
|
+
return this.buffer;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
Object.defineProperty(Buffer2.prototype, "offset", {
|
|
230
|
+
enumerable: true,
|
|
231
|
+
get: function() {
|
|
232
|
+
if (!Buffer2.isBuffer(this)) return void 0;
|
|
233
|
+
return this.byteOffset;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
function createBuffer(length) {
|
|
237
|
+
if (length > K_MAX_LENGTH) {
|
|
238
|
+
throw new RangeError('The value "' + length + '" is invalid for option "size"');
|
|
239
|
+
}
|
|
240
|
+
const buf = new Uint8Array(length);
|
|
241
|
+
Object.setPrototypeOf(buf, Buffer2.prototype);
|
|
242
|
+
return buf;
|
|
243
|
+
}
|
|
244
|
+
function Buffer2(arg, encodingOrOffset, length) {
|
|
245
|
+
if (typeof arg === "number") {
|
|
246
|
+
if (typeof encodingOrOffset === "string") {
|
|
247
|
+
throw new TypeError(
|
|
248
|
+
'The "string" argument must be of type string. Received type number'
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
return allocUnsafe(arg);
|
|
252
|
+
}
|
|
253
|
+
return from(arg, encodingOrOffset, length);
|
|
254
|
+
}
|
|
255
|
+
Buffer2.poolSize = 8192;
|
|
256
|
+
function from(value, encodingOrOffset, length) {
|
|
257
|
+
if (typeof value === "string") {
|
|
258
|
+
return fromString(value, encodingOrOffset);
|
|
259
|
+
}
|
|
260
|
+
if (ArrayBuffer.isView(value)) {
|
|
261
|
+
return fromArrayView(value);
|
|
262
|
+
}
|
|
263
|
+
if (value == null) {
|
|
264
|
+
throw new TypeError(
|
|
265
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
|
|
269
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
270
|
+
}
|
|
271
|
+
if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
|
|
272
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
273
|
+
}
|
|
274
|
+
if (typeof value === "number") {
|
|
275
|
+
throw new TypeError(
|
|
276
|
+
'The "value" argument must not be of type number. Received type number'
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
280
|
+
if (valueOf != null && valueOf !== value) {
|
|
281
|
+
return Buffer2.from(valueOf, encodingOrOffset, length);
|
|
282
|
+
}
|
|
283
|
+
const b = fromObject(value);
|
|
284
|
+
if (b) return b;
|
|
285
|
+
if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") {
|
|
286
|
+
return Buffer2.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
|
|
287
|
+
}
|
|
288
|
+
throw new TypeError(
|
|
289
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
Buffer2.from = function(value, encodingOrOffset, length) {
|
|
293
|
+
return from(value, encodingOrOffset, length);
|
|
294
|
+
};
|
|
295
|
+
Object.setPrototypeOf(Buffer2.prototype, Uint8Array.prototype);
|
|
296
|
+
Object.setPrototypeOf(Buffer2, Uint8Array);
|
|
297
|
+
function assertSize(size) {
|
|
298
|
+
if (typeof size !== "number") {
|
|
299
|
+
throw new TypeError('"size" argument must be of type number');
|
|
300
|
+
} else if (size < 0) {
|
|
301
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function alloc(size, fill, encoding) {
|
|
305
|
+
assertSize(size);
|
|
306
|
+
if (size <= 0) {
|
|
307
|
+
return createBuffer(size);
|
|
308
|
+
}
|
|
309
|
+
if (fill !== void 0) {
|
|
310
|
+
return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
|
|
311
|
+
}
|
|
312
|
+
return createBuffer(size);
|
|
313
|
+
}
|
|
314
|
+
Buffer2.alloc = function(size, fill, encoding) {
|
|
315
|
+
return alloc(size, fill, encoding);
|
|
316
|
+
};
|
|
317
|
+
function allocUnsafe(size) {
|
|
318
|
+
assertSize(size);
|
|
319
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0);
|
|
320
|
+
}
|
|
321
|
+
Buffer2.allocUnsafe = function(size) {
|
|
322
|
+
return allocUnsafe(size);
|
|
323
|
+
};
|
|
324
|
+
Buffer2.allocUnsafeSlow = function(size) {
|
|
325
|
+
return allocUnsafe(size);
|
|
326
|
+
};
|
|
327
|
+
function fromString(string, encoding) {
|
|
328
|
+
if (typeof encoding !== "string" || encoding === "") {
|
|
329
|
+
encoding = "utf8";
|
|
330
|
+
}
|
|
331
|
+
if (!Buffer2.isEncoding(encoding)) {
|
|
332
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
333
|
+
}
|
|
334
|
+
const length = byteLength(string, encoding) | 0;
|
|
335
|
+
let buf = createBuffer(length);
|
|
336
|
+
const actual = buf.write(string, encoding);
|
|
337
|
+
if (actual !== length) {
|
|
338
|
+
buf = buf.slice(0, actual);
|
|
339
|
+
}
|
|
340
|
+
return buf;
|
|
341
|
+
}
|
|
342
|
+
function fromArrayLike(array) {
|
|
343
|
+
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
344
|
+
const buf = createBuffer(length);
|
|
345
|
+
for (let i = 0; i < length; i += 1) {
|
|
346
|
+
buf[i] = array[i] & 255;
|
|
347
|
+
}
|
|
348
|
+
return buf;
|
|
349
|
+
}
|
|
350
|
+
function fromArrayView(arrayView) {
|
|
351
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
352
|
+
const copy = new Uint8Array(arrayView);
|
|
353
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
|
|
354
|
+
}
|
|
355
|
+
return fromArrayLike(arrayView);
|
|
356
|
+
}
|
|
357
|
+
function fromArrayBuffer(array, byteOffset, length) {
|
|
358
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
359
|
+
throw new RangeError('"offset" is outside of buffer bounds');
|
|
360
|
+
}
|
|
361
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
362
|
+
throw new RangeError('"length" is outside of buffer bounds');
|
|
363
|
+
}
|
|
364
|
+
let buf;
|
|
365
|
+
if (byteOffset === void 0 && length === void 0) {
|
|
366
|
+
buf = new Uint8Array(array);
|
|
367
|
+
} else if (length === void 0) {
|
|
368
|
+
buf = new Uint8Array(array, byteOffset);
|
|
369
|
+
} else {
|
|
370
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
371
|
+
}
|
|
372
|
+
Object.setPrototypeOf(buf, Buffer2.prototype);
|
|
373
|
+
return buf;
|
|
374
|
+
}
|
|
375
|
+
function fromObject(obj) {
|
|
376
|
+
if (Buffer2.isBuffer(obj)) {
|
|
377
|
+
const len = checked(obj.length) | 0;
|
|
378
|
+
const buf = createBuffer(len);
|
|
379
|
+
if (buf.length === 0) {
|
|
380
|
+
return buf;
|
|
381
|
+
}
|
|
382
|
+
obj.copy(buf, 0, 0, len);
|
|
383
|
+
return buf;
|
|
384
|
+
}
|
|
385
|
+
if (obj.length !== void 0) {
|
|
386
|
+
if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
|
|
387
|
+
return createBuffer(0);
|
|
388
|
+
}
|
|
389
|
+
return fromArrayLike(obj);
|
|
390
|
+
}
|
|
391
|
+
if (obj.type === "Buffer" && Array.isArray(obj.data)) {
|
|
392
|
+
return fromArrayLike(obj.data);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function checked(length) {
|
|
396
|
+
if (length >= K_MAX_LENGTH) {
|
|
397
|
+
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes");
|
|
398
|
+
}
|
|
399
|
+
return length | 0;
|
|
400
|
+
}
|
|
401
|
+
function SlowBuffer(length) {
|
|
402
|
+
if (+length != length) {
|
|
403
|
+
length = 0;
|
|
404
|
+
}
|
|
405
|
+
return Buffer2.alloc(+length);
|
|
406
|
+
}
|
|
407
|
+
Buffer2.isBuffer = function isBuffer(b) {
|
|
408
|
+
return b != null && b._isBuffer === true && b !== Buffer2.prototype;
|
|
409
|
+
};
|
|
410
|
+
Buffer2.compare = function compare(a, b) {
|
|
411
|
+
if (isInstance(a, Uint8Array)) a = Buffer2.from(a, a.offset, a.byteLength);
|
|
412
|
+
if (isInstance(b, Uint8Array)) b = Buffer2.from(b, b.offset, b.byteLength);
|
|
413
|
+
if (!Buffer2.isBuffer(a) || !Buffer2.isBuffer(b)) {
|
|
414
|
+
throw new TypeError(
|
|
415
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
if (a === b) return 0;
|
|
419
|
+
let x = a.length;
|
|
420
|
+
let y = b.length;
|
|
421
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
422
|
+
if (a[i] !== b[i]) {
|
|
423
|
+
x = a[i];
|
|
424
|
+
y = b[i];
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
if (x < y) return -1;
|
|
429
|
+
if (y < x) return 1;
|
|
430
|
+
return 0;
|
|
431
|
+
};
|
|
432
|
+
Buffer2.isEncoding = function isEncoding(encoding) {
|
|
433
|
+
switch (String(encoding).toLowerCase()) {
|
|
434
|
+
case "hex":
|
|
435
|
+
case "utf8":
|
|
436
|
+
case "utf-8":
|
|
437
|
+
case "ascii":
|
|
438
|
+
case "latin1":
|
|
439
|
+
case "binary":
|
|
440
|
+
case "base64":
|
|
441
|
+
case "ucs2":
|
|
442
|
+
case "ucs-2":
|
|
443
|
+
case "utf16le":
|
|
444
|
+
case "utf-16le":
|
|
445
|
+
return true;
|
|
446
|
+
default:
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
Buffer2.concat = function concat(list, length) {
|
|
451
|
+
if (!Array.isArray(list)) {
|
|
452
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
453
|
+
}
|
|
454
|
+
if (list.length === 0) {
|
|
455
|
+
return Buffer2.alloc(0);
|
|
456
|
+
}
|
|
457
|
+
let i;
|
|
458
|
+
if (length === void 0) {
|
|
459
|
+
length = 0;
|
|
460
|
+
for (i = 0; i < list.length; ++i) {
|
|
461
|
+
length += list[i].length;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
const buffer = Buffer2.allocUnsafe(length);
|
|
465
|
+
let pos = 0;
|
|
466
|
+
for (i = 0; i < list.length; ++i) {
|
|
467
|
+
let buf = list[i];
|
|
468
|
+
if (isInstance(buf, Uint8Array)) {
|
|
469
|
+
if (pos + buf.length > buffer.length) {
|
|
470
|
+
if (!Buffer2.isBuffer(buf)) buf = Buffer2.from(buf);
|
|
471
|
+
buf.copy(buffer, pos);
|
|
472
|
+
} else {
|
|
473
|
+
Uint8Array.prototype.set.call(
|
|
474
|
+
buffer,
|
|
475
|
+
buf,
|
|
476
|
+
pos
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
} else if (!Buffer2.isBuffer(buf)) {
|
|
480
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
481
|
+
} else {
|
|
482
|
+
buf.copy(buffer, pos);
|
|
483
|
+
}
|
|
484
|
+
pos += buf.length;
|
|
485
|
+
}
|
|
486
|
+
return buffer;
|
|
487
|
+
};
|
|
488
|
+
function byteLength(string, encoding) {
|
|
489
|
+
if (Buffer2.isBuffer(string)) {
|
|
490
|
+
return string.length;
|
|
491
|
+
}
|
|
492
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
493
|
+
return string.byteLength;
|
|
494
|
+
}
|
|
495
|
+
if (typeof string !== "string") {
|
|
496
|
+
throw new TypeError(
|
|
497
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
const len = string.length;
|
|
501
|
+
const mustMatch = arguments.length > 2 && arguments[2] === true;
|
|
502
|
+
if (!mustMatch && len === 0) return 0;
|
|
503
|
+
let loweredCase = false;
|
|
504
|
+
for (; ; ) {
|
|
505
|
+
switch (encoding) {
|
|
506
|
+
case "ascii":
|
|
507
|
+
case "latin1":
|
|
508
|
+
case "binary":
|
|
509
|
+
return len;
|
|
510
|
+
case "utf8":
|
|
511
|
+
case "utf-8":
|
|
512
|
+
return utf8ToBytes(string).length;
|
|
513
|
+
case "ucs2":
|
|
514
|
+
case "ucs-2":
|
|
515
|
+
case "utf16le":
|
|
516
|
+
case "utf-16le":
|
|
517
|
+
return len * 2;
|
|
518
|
+
case "hex":
|
|
519
|
+
return len >>> 1;
|
|
520
|
+
case "base64":
|
|
521
|
+
return base64ToBytes(string).length;
|
|
522
|
+
default:
|
|
523
|
+
if (loweredCase) {
|
|
524
|
+
return mustMatch ? -1 : utf8ToBytes(string).length;
|
|
525
|
+
}
|
|
526
|
+
encoding = ("" + encoding).toLowerCase();
|
|
527
|
+
loweredCase = true;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
Buffer2.byteLength = byteLength;
|
|
532
|
+
function slowToString(encoding, start, end) {
|
|
533
|
+
let loweredCase = false;
|
|
534
|
+
if (start === void 0 || start < 0) {
|
|
535
|
+
start = 0;
|
|
536
|
+
}
|
|
537
|
+
if (start > this.length) {
|
|
538
|
+
return "";
|
|
539
|
+
}
|
|
540
|
+
if (end === void 0 || end > this.length) {
|
|
541
|
+
end = this.length;
|
|
542
|
+
}
|
|
543
|
+
if (end <= 0) {
|
|
544
|
+
return "";
|
|
545
|
+
}
|
|
546
|
+
end >>>= 0;
|
|
547
|
+
start >>>= 0;
|
|
548
|
+
if (end <= start) {
|
|
549
|
+
return "";
|
|
550
|
+
}
|
|
551
|
+
if (!encoding) encoding = "utf8";
|
|
552
|
+
while (true) {
|
|
553
|
+
switch (encoding) {
|
|
554
|
+
case "hex":
|
|
555
|
+
return hexSlice(this, start, end);
|
|
556
|
+
case "utf8":
|
|
557
|
+
case "utf-8":
|
|
558
|
+
return utf8Slice(this, start, end);
|
|
559
|
+
case "ascii":
|
|
560
|
+
return asciiSlice(this, start, end);
|
|
561
|
+
case "latin1":
|
|
562
|
+
case "binary":
|
|
563
|
+
return latin1Slice(this, start, end);
|
|
564
|
+
case "base64":
|
|
565
|
+
return base64Slice(this, start, end);
|
|
566
|
+
case "ucs2":
|
|
567
|
+
case "ucs-2":
|
|
568
|
+
case "utf16le":
|
|
569
|
+
case "utf-16le":
|
|
570
|
+
return utf16leSlice(this, start, end);
|
|
571
|
+
default:
|
|
572
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
573
|
+
encoding = (encoding + "").toLowerCase();
|
|
574
|
+
loweredCase = true;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
Buffer2.prototype._isBuffer = true;
|
|
579
|
+
function swap(b, n, m) {
|
|
580
|
+
const i = b[n];
|
|
581
|
+
b[n] = b[m];
|
|
582
|
+
b[m] = i;
|
|
583
|
+
}
|
|
584
|
+
Buffer2.prototype.swap16 = function swap16() {
|
|
585
|
+
const len = this.length;
|
|
586
|
+
if (len % 2 !== 0) {
|
|
587
|
+
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
588
|
+
}
|
|
589
|
+
for (let i = 0; i < len; i += 2) {
|
|
590
|
+
swap(this, i, i + 1);
|
|
591
|
+
}
|
|
592
|
+
return this;
|
|
593
|
+
};
|
|
594
|
+
Buffer2.prototype.swap32 = function swap32() {
|
|
595
|
+
const len = this.length;
|
|
596
|
+
if (len % 4 !== 0) {
|
|
597
|
+
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
598
|
+
}
|
|
599
|
+
for (let i = 0; i < len; i += 4) {
|
|
600
|
+
swap(this, i, i + 3);
|
|
601
|
+
swap(this, i + 1, i + 2);
|
|
602
|
+
}
|
|
603
|
+
return this;
|
|
604
|
+
};
|
|
605
|
+
Buffer2.prototype.swap64 = function swap64() {
|
|
606
|
+
const len = this.length;
|
|
607
|
+
if (len % 8 !== 0) {
|
|
608
|
+
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
609
|
+
}
|
|
610
|
+
for (let i = 0; i < len; i += 8) {
|
|
611
|
+
swap(this, i, i + 7);
|
|
612
|
+
swap(this, i + 1, i + 6);
|
|
613
|
+
swap(this, i + 2, i + 5);
|
|
614
|
+
swap(this, i + 3, i + 4);
|
|
615
|
+
}
|
|
616
|
+
return this;
|
|
617
|
+
};
|
|
618
|
+
Buffer2.prototype.toString = function toString() {
|
|
619
|
+
const length = this.length;
|
|
620
|
+
if (length === 0) return "";
|
|
621
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length);
|
|
622
|
+
return slowToString.apply(this, arguments);
|
|
623
|
+
};
|
|
624
|
+
Buffer2.prototype.toLocaleString = Buffer2.prototype.toString;
|
|
625
|
+
Buffer2.prototype.equals = function equals(b) {
|
|
626
|
+
if (!Buffer2.isBuffer(b)) throw new TypeError("Argument must be a Buffer");
|
|
627
|
+
if (this === b) return true;
|
|
628
|
+
return Buffer2.compare(this, b) === 0;
|
|
629
|
+
};
|
|
630
|
+
Buffer2.prototype.inspect = function inspect() {
|
|
631
|
+
let str = "";
|
|
632
|
+
const max = exports.INSPECT_MAX_BYTES;
|
|
633
|
+
str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
|
|
634
|
+
if (this.length > max) str += " ... ";
|
|
635
|
+
return "<Buffer " + str + ">";
|
|
636
|
+
};
|
|
637
|
+
if (customInspectSymbol) {
|
|
638
|
+
Buffer2.prototype[customInspectSymbol] = Buffer2.prototype.inspect;
|
|
639
|
+
}
|
|
640
|
+
Buffer2.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
|
|
641
|
+
if (isInstance(target, Uint8Array)) {
|
|
642
|
+
target = Buffer2.from(target, target.offset, target.byteLength);
|
|
643
|
+
}
|
|
644
|
+
if (!Buffer2.isBuffer(target)) {
|
|
645
|
+
throw new TypeError(
|
|
646
|
+
'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
if (start === void 0) {
|
|
650
|
+
start = 0;
|
|
651
|
+
}
|
|
652
|
+
if (end === void 0) {
|
|
653
|
+
end = target ? target.length : 0;
|
|
654
|
+
}
|
|
655
|
+
if (thisStart === void 0) {
|
|
656
|
+
thisStart = 0;
|
|
657
|
+
}
|
|
658
|
+
if (thisEnd === void 0) {
|
|
659
|
+
thisEnd = this.length;
|
|
660
|
+
}
|
|
661
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
662
|
+
throw new RangeError("out of range index");
|
|
663
|
+
}
|
|
664
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
665
|
+
return 0;
|
|
666
|
+
}
|
|
667
|
+
if (thisStart >= thisEnd) {
|
|
668
|
+
return -1;
|
|
669
|
+
}
|
|
670
|
+
if (start >= end) {
|
|
671
|
+
return 1;
|
|
672
|
+
}
|
|
673
|
+
start >>>= 0;
|
|
674
|
+
end >>>= 0;
|
|
675
|
+
thisStart >>>= 0;
|
|
676
|
+
thisEnd >>>= 0;
|
|
677
|
+
if (this === target) return 0;
|
|
678
|
+
let x = thisEnd - thisStart;
|
|
679
|
+
let y = end - start;
|
|
680
|
+
const len = Math.min(x, y);
|
|
681
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
682
|
+
const targetCopy = target.slice(start, end);
|
|
683
|
+
for (let i = 0; i < len; ++i) {
|
|
684
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
685
|
+
x = thisCopy[i];
|
|
686
|
+
y = targetCopy[i];
|
|
687
|
+
break;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
if (x < y) return -1;
|
|
691
|
+
if (y < x) return 1;
|
|
692
|
+
return 0;
|
|
693
|
+
};
|
|
694
|
+
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
695
|
+
if (buffer.length === 0) return -1;
|
|
696
|
+
if (typeof byteOffset === "string") {
|
|
697
|
+
encoding = byteOffset;
|
|
698
|
+
byteOffset = 0;
|
|
699
|
+
} else if (byteOffset > 2147483647) {
|
|
700
|
+
byteOffset = 2147483647;
|
|
701
|
+
} else if (byteOffset < -2147483648) {
|
|
702
|
+
byteOffset = -2147483648;
|
|
703
|
+
}
|
|
704
|
+
byteOffset = +byteOffset;
|
|
705
|
+
if (numberIsNaN(byteOffset)) {
|
|
706
|
+
byteOffset = dir ? 0 : buffer.length - 1;
|
|
707
|
+
}
|
|
708
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
709
|
+
if (byteOffset >= buffer.length) {
|
|
710
|
+
if (dir) return -1;
|
|
711
|
+
else byteOffset = buffer.length - 1;
|
|
712
|
+
} else if (byteOffset < 0) {
|
|
713
|
+
if (dir) byteOffset = 0;
|
|
714
|
+
else return -1;
|
|
715
|
+
}
|
|
716
|
+
if (typeof val === "string") {
|
|
717
|
+
val = Buffer2.from(val, encoding);
|
|
718
|
+
}
|
|
719
|
+
if (Buffer2.isBuffer(val)) {
|
|
720
|
+
if (val.length === 0) {
|
|
721
|
+
return -1;
|
|
722
|
+
}
|
|
723
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
724
|
+
} else if (typeof val === "number") {
|
|
725
|
+
val = val & 255;
|
|
726
|
+
if (typeof Uint8Array.prototype.indexOf === "function") {
|
|
727
|
+
if (dir) {
|
|
728
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
729
|
+
} else {
|
|
730
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
734
|
+
}
|
|
735
|
+
throw new TypeError("val must be string, number or Buffer");
|
|
736
|
+
}
|
|
737
|
+
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
738
|
+
let indexSize = 1;
|
|
739
|
+
let arrLength = arr.length;
|
|
740
|
+
let valLength = val.length;
|
|
741
|
+
if (encoding !== void 0) {
|
|
742
|
+
encoding = String(encoding).toLowerCase();
|
|
743
|
+
if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
744
|
+
if (arr.length < 2 || val.length < 2) {
|
|
745
|
+
return -1;
|
|
746
|
+
}
|
|
747
|
+
indexSize = 2;
|
|
748
|
+
arrLength /= 2;
|
|
749
|
+
valLength /= 2;
|
|
750
|
+
byteOffset /= 2;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function read(buf, i2) {
|
|
754
|
+
if (indexSize === 1) {
|
|
755
|
+
return buf[i2];
|
|
756
|
+
} else {
|
|
757
|
+
return buf.readUInt16BE(i2 * indexSize);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
let i;
|
|
761
|
+
if (dir) {
|
|
762
|
+
let foundIndex = -1;
|
|
763
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
764
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
765
|
+
if (foundIndex === -1) foundIndex = i;
|
|
766
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
|
|
767
|
+
} else {
|
|
768
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
769
|
+
foundIndex = -1;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
} else {
|
|
773
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
774
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
775
|
+
let found = true;
|
|
776
|
+
for (let j = 0; j < valLength; j++) {
|
|
777
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
778
|
+
found = false;
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (found) return i;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return -1;
|
|
786
|
+
}
|
|
787
|
+
Buffer2.prototype.includes = function includes(val, byteOffset, encoding) {
|
|
788
|
+
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
789
|
+
};
|
|
790
|
+
Buffer2.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
|
|
791
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
792
|
+
};
|
|
793
|
+
Buffer2.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
|
|
794
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
795
|
+
};
|
|
796
|
+
function hexWrite(buf, string, offset, length) {
|
|
797
|
+
offset = Number(offset) || 0;
|
|
798
|
+
const remaining = buf.length - offset;
|
|
799
|
+
if (!length) {
|
|
800
|
+
length = remaining;
|
|
801
|
+
} else {
|
|
802
|
+
length = Number(length);
|
|
803
|
+
if (length > remaining) {
|
|
804
|
+
length = remaining;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
const strLen = string.length;
|
|
808
|
+
if (length > strLen / 2) {
|
|
809
|
+
length = strLen / 2;
|
|
810
|
+
}
|
|
811
|
+
let i;
|
|
812
|
+
for (i = 0; i < length; ++i) {
|
|
813
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
814
|
+
if (numberIsNaN(parsed)) return i;
|
|
815
|
+
buf[offset + i] = parsed;
|
|
816
|
+
}
|
|
817
|
+
return i;
|
|
818
|
+
}
|
|
819
|
+
function utf8Write(buf, string, offset, length) {
|
|
820
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
821
|
+
}
|
|
822
|
+
function asciiWrite(buf, string, offset, length) {
|
|
823
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
824
|
+
}
|
|
825
|
+
function base64Write(buf, string, offset, length) {
|
|
826
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
827
|
+
}
|
|
828
|
+
function ucs2Write(buf, string, offset, length) {
|
|
829
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
830
|
+
}
|
|
831
|
+
Buffer2.prototype.write = function write(string, offset, length, encoding) {
|
|
832
|
+
if (offset === void 0) {
|
|
833
|
+
encoding = "utf8";
|
|
834
|
+
length = this.length;
|
|
835
|
+
offset = 0;
|
|
836
|
+
} else if (length === void 0 && typeof offset === "string") {
|
|
837
|
+
encoding = offset;
|
|
838
|
+
length = this.length;
|
|
839
|
+
offset = 0;
|
|
840
|
+
} else if (isFinite(offset)) {
|
|
841
|
+
offset = offset >>> 0;
|
|
842
|
+
if (isFinite(length)) {
|
|
843
|
+
length = length >>> 0;
|
|
844
|
+
if (encoding === void 0) encoding = "utf8";
|
|
845
|
+
} else {
|
|
846
|
+
encoding = length;
|
|
847
|
+
length = void 0;
|
|
848
|
+
}
|
|
849
|
+
} else {
|
|
850
|
+
throw new Error(
|
|
851
|
+
"Buffer.write(string, encoding, offset[, length]) is no longer supported"
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
const remaining = this.length - offset;
|
|
855
|
+
if (length === void 0 || length > remaining) length = remaining;
|
|
856
|
+
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
|
|
857
|
+
throw new RangeError("Attempt to write outside buffer bounds");
|
|
858
|
+
}
|
|
859
|
+
if (!encoding) encoding = "utf8";
|
|
860
|
+
let loweredCase = false;
|
|
861
|
+
for (; ; ) {
|
|
862
|
+
switch (encoding) {
|
|
863
|
+
case "hex":
|
|
864
|
+
return hexWrite(this, string, offset, length);
|
|
865
|
+
case "utf8":
|
|
866
|
+
case "utf-8":
|
|
867
|
+
return utf8Write(this, string, offset, length);
|
|
868
|
+
case "ascii":
|
|
869
|
+
case "latin1":
|
|
870
|
+
case "binary":
|
|
871
|
+
return asciiWrite(this, string, offset, length);
|
|
872
|
+
case "base64":
|
|
873
|
+
return base64Write(this, string, offset, length);
|
|
874
|
+
case "ucs2":
|
|
875
|
+
case "ucs-2":
|
|
876
|
+
case "utf16le":
|
|
877
|
+
case "utf-16le":
|
|
878
|
+
return ucs2Write(this, string, offset, length);
|
|
879
|
+
default:
|
|
880
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
881
|
+
encoding = ("" + encoding).toLowerCase();
|
|
882
|
+
loweredCase = true;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
Buffer2.prototype.toJSON = function toJSON() {
|
|
887
|
+
return {
|
|
888
|
+
type: "Buffer",
|
|
889
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
890
|
+
};
|
|
891
|
+
};
|
|
892
|
+
function base64Slice(buf, start, end) {
|
|
893
|
+
if (start === 0 && end === buf.length) {
|
|
894
|
+
return base64.fromByteArray(buf);
|
|
895
|
+
} else {
|
|
896
|
+
return base64.fromByteArray(buf.slice(start, end));
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
function utf8Slice(buf, start, end) {
|
|
900
|
+
end = Math.min(buf.length, end);
|
|
901
|
+
const res = [];
|
|
902
|
+
let i = start;
|
|
903
|
+
while (i < end) {
|
|
904
|
+
const firstByte = buf[i];
|
|
905
|
+
let codePoint = null;
|
|
906
|
+
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
907
|
+
if (i + bytesPerSequence <= end) {
|
|
908
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
909
|
+
switch (bytesPerSequence) {
|
|
910
|
+
case 1:
|
|
911
|
+
if (firstByte < 128) {
|
|
912
|
+
codePoint = firstByte;
|
|
913
|
+
}
|
|
914
|
+
break;
|
|
915
|
+
case 2:
|
|
916
|
+
secondByte = buf[i + 1];
|
|
917
|
+
if ((secondByte & 192) === 128) {
|
|
918
|
+
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
919
|
+
if (tempCodePoint > 127) {
|
|
920
|
+
codePoint = tempCodePoint;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
break;
|
|
924
|
+
case 3:
|
|
925
|
+
secondByte = buf[i + 1];
|
|
926
|
+
thirdByte = buf[i + 2];
|
|
927
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
928
|
+
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
929
|
+
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
930
|
+
codePoint = tempCodePoint;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
break;
|
|
934
|
+
case 4:
|
|
935
|
+
secondByte = buf[i + 1];
|
|
936
|
+
thirdByte = buf[i + 2];
|
|
937
|
+
fourthByte = buf[i + 3];
|
|
938
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
939
|
+
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
940
|
+
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
941
|
+
codePoint = tempCodePoint;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
if (codePoint === null) {
|
|
947
|
+
codePoint = 65533;
|
|
948
|
+
bytesPerSequence = 1;
|
|
949
|
+
} else if (codePoint > 65535) {
|
|
950
|
+
codePoint -= 65536;
|
|
951
|
+
res.push(codePoint >>> 10 & 1023 | 55296);
|
|
952
|
+
codePoint = 56320 | codePoint & 1023;
|
|
953
|
+
}
|
|
954
|
+
res.push(codePoint);
|
|
955
|
+
i += bytesPerSequence;
|
|
956
|
+
}
|
|
957
|
+
return decodeCodePointsArray(res);
|
|
958
|
+
}
|
|
959
|
+
var MAX_ARGUMENTS_LENGTH = 4096;
|
|
960
|
+
function decodeCodePointsArray(codePoints) {
|
|
961
|
+
const len = codePoints.length;
|
|
962
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
963
|
+
return String.fromCharCode.apply(String, codePoints);
|
|
964
|
+
}
|
|
965
|
+
let res = "";
|
|
966
|
+
let i = 0;
|
|
967
|
+
while (i < len) {
|
|
968
|
+
res += String.fromCharCode.apply(
|
|
969
|
+
String,
|
|
970
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
971
|
+
);
|
|
972
|
+
}
|
|
973
|
+
return res;
|
|
974
|
+
}
|
|
975
|
+
function asciiSlice(buf, start, end) {
|
|
976
|
+
let ret = "";
|
|
977
|
+
end = Math.min(buf.length, end);
|
|
978
|
+
for (let i = start; i < end; ++i) {
|
|
979
|
+
ret += String.fromCharCode(buf[i] & 127);
|
|
980
|
+
}
|
|
981
|
+
return ret;
|
|
982
|
+
}
|
|
983
|
+
function latin1Slice(buf, start, end) {
|
|
984
|
+
let ret = "";
|
|
985
|
+
end = Math.min(buf.length, end);
|
|
986
|
+
for (let i = start; i < end; ++i) {
|
|
987
|
+
ret += String.fromCharCode(buf[i]);
|
|
988
|
+
}
|
|
989
|
+
return ret;
|
|
990
|
+
}
|
|
991
|
+
function hexSlice(buf, start, end) {
|
|
992
|
+
const len = buf.length;
|
|
993
|
+
if (!start || start < 0) start = 0;
|
|
994
|
+
if (!end || end < 0 || end > len) end = len;
|
|
995
|
+
let out = "";
|
|
996
|
+
for (let i = start; i < end; ++i) {
|
|
997
|
+
out += hexSliceLookupTable[buf[i]];
|
|
998
|
+
}
|
|
999
|
+
return out;
|
|
1000
|
+
}
|
|
1001
|
+
function utf16leSlice(buf, start, end) {
|
|
1002
|
+
const bytes = buf.slice(start, end);
|
|
1003
|
+
let res = "";
|
|
1004
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
1005
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1006
|
+
}
|
|
1007
|
+
return res;
|
|
1008
|
+
}
|
|
1009
|
+
Buffer2.prototype.slice = function slice(start, end) {
|
|
1010
|
+
const len = this.length;
|
|
1011
|
+
start = ~~start;
|
|
1012
|
+
end = end === void 0 ? len : ~~end;
|
|
1013
|
+
if (start < 0) {
|
|
1014
|
+
start += len;
|
|
1015
|
+
if (start < 0) start = 0;
|
|
1016
|
+
} else if (start > len) {
|
|
1017
|
+
start = len;
|
|
1018
|
+
}
|
|
1019
|
+
if (end < 0) {
|
|
1020
|
+
end += len;
|
|
1021
|
+
if (end < 0) end = 0;
|
|
1022
|
+
} else if (end > len) {
|
|
1023
|
+
end = len;
|
|
1024
|
+
}
|
|
1025
|
+
if (end < start) end = start;
|
|
1026
|
+
const newBuf = this.subarray(start, end);
|
|
1027
|
+
Object.setPrototypeOf(newBuf, Buffer2.prototype);
|
|
1028
|
+
return newBuf;
|
|
1029
|
+
};
|
|
1030
|
+
function checkOffset(offset, ext, length) {
|
|
1031
|
+
if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
|
|
1032
|
+
if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
|
|
1033
|
+
}
|
|
1034
|
+
Buffer2.prototype.readUintLE = Buffer2.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
|
|
1035
|
+
offset = offset >>> 0;
|
|
1036
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1037
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1038
|
+
let val = this[offset];
|
|
1039
|
+
let mul = 1;
|
|
1040
|
+
let i = 0;
|
|
1041
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1042
|
+
val += this[offset + i] * mul;
|
|
1043
|
+
}
|
|
1044
|
+
return val;
|
|
1045
|
+
};
|
|
1046
|
+
Buffer2.prototype.readUintBE = Buffer2.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
|
|
1047
|
+
offset = offset >>> 0;
|
|
1048
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1049
|
+
if (!noAssert) {
|
|
1050
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1051
|
+
}
|
|
1052
|
+
let val = this[offset + --byteLength2];
|
|
1053
|
+
let mul = 1;
|
|
1054
|
+
while (byteLength2 > 0 && (mul *= 256)) {
|
|
1055
|
+
val += this[offset + --byteLength2] * mul;
|
|
1056
|
+
}
|
|
1057
|
+
return val;
|
|
1058
|
+
};
|
|
1059
|
+
Buffer2.prototype.readUint8 = Buffer2.prototype.readUInt8 = function readUInt8(offset, noAssert) {
|
|
1060
|
+
offset = offset >>> 0;
|
|
1061
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1062
|
+
return this[offset];
|
|
1063
|
+
};
|
|
1064
|
+
Buffer2.prototype.readUint16LE = Buffer2.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
|
|
1065
|
+
offset = offset >>> 0;
|
|
1066
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1067
|
+
return this[offset] | this[offset + 1] << 8;
|
|
1068
|
+
};
|
|
1069
|
+
Buffer2.prototype.readUint16BE = Buffer2.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
|
|
1070
|
+
offset = offset >>> 0;
|
|
1071
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1072
|
+
return this[offset] << 8 | this[offset + 1];
|
|
1073
|
+
};
|
|
1074
|
+
Buffer2.prototype.readUint32LE = Buffer2.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
|
|
1075
|
+
offset = offset >>> 0;
|
|
1076
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1077
|
+
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
1078
|
+
};
|
|
1079
|
+
Buffer2.prototype.readUint32BE = Buffer2.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
|
|
1080
|
+
offset = offset >>> 0;
|
|
1081
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1082
|
+
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
1083
|
+
};
|
|
1084
|
+
Buffer2.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {
|
|
1085
|
+
offset = offset >>> 0;
|
|
1086
|
+
validateNumber(offset, "offset");
|
|
1087
|
+
const first = this[offset];
|
|
1088
|
+
const last = this[offset + 7];
|
|
1089
|
+
if (first === void 0 || last === void 0) {
|
|
1090
|
+
boundsError(offset, this.length - 8);
|
|
1091
|
+
}
|
|
1092
|
+
const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;
|
|
1093
|
+
const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;
|
|
1094
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32));
|
|
1095
|
+
});
|
|
1096
|
+
Buffer2.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {
|
|
1097
|
+
offset = offset >>> 0;
|
|
1098
|
+
validateNumber(offset, "offset");
|
|
1099
|
+
const first = this[offset];
|
|
1100
|
+
const last = this[offset + 7];
|
|
1101
|
+
if (first === void 0 || last === void 0) {
|
|
1102
|
+
boundsError(offset, this.length - 8);
|
|
1103
|
+
}
|
|
1104
|
+
const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1105
|
+
const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
|
|
1106
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
1107
|
+
});
|
|
1108
|
+
Buffer2.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
|
|
1109
|
+
offset = offset >>> 0;
|
|
1110
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1111
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1112
|
+
let val = this[offset];
|
|
1113
|
+
let mul = 1;
|
|
1114
|
+
let i = 0;
|
|
1115
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1116
|
+
val += this[offset + i] * mul;
|
|
1117
|
+
}
|
|
1118
|
+
mul *= 128;
|
|
1119
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1120
|
+
return val;
|
|
1121
|
+
};
|
|
1122
|
+
Buffer2.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
|
|
1123
|
+
offset = offset >>> 0;
|
|
1124
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1125
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1126
|
+
let i = byteLength2;
|
|
1127
|
+
let mul = 1;
|
|
1128
|
+
let val = this[offset + --i];
|
|
1129
|
+
while (i > 0 && (mul *= 256)) {
|
|
1130
|
+
val += this[offset + --i] * mul;
|
|
1131
|
+
}
|
|
1132
|
+
mul *= 128;
|
|
1133
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1134
|
+
return val;
|
|
1135
|
+
};
|
|
1136
|
+
Buffer2.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
1137
|
+
offset = offset >>> 0;
|
|
1138
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1139
|
+
if (!(this[offset] & 128)) return this[offset];
|
|
1140
|
+
return (255 - this[offset] + 1) * -1;
|
|
1141
|
+
};
|
|
1142
|
+
Buffer2.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
|
|
1143
|
+
offset = offset >>> 0;
|
|
1144
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1145
|
+
const val = this[offset] | this[offset + 1] << 8;
|
|
1146
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1147
|
+
};
|
|
1148
|
+
Buffer2.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
|
|
1149
|
+
offset = offset >>> 0;
|
|
1150
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1151
|
+
const val = this[offset + 1] | this[offset] << 8;
|
|
1152
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1153
|
+
};
|
|
1154
|
+
Buffer2.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
|
|
1155
|
+
offset = offset >>> 0;
|
|
1156
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1157
|
+
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
1158
|
+
};
|
|
1159
|
+
Buffer2.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
|
|
1160
|
+
offset = offset >>> 0;
|
|
1161
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1162
|
+
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
1163
|
+
};
|
|
1164
|
+
Buffer2.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {
|
|
1165
|
+
offset = offset >>> 0;
|
|
1166
|
+
validateNumber(offset, "offset");
|
|
1167
|
+
const first = this[offset];
|
|
1168
|
+
const last = this[offset + 7];
|
|
1169
|
+
if (first === void 0 || last === void 0) {
|
|
1170
|
+
boundsError(offset, this.length - 8);
|
|
1171
|
+
}
|
|
1172
|
+
const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24);
|
|
1173
|
+
return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24);
|
|
1174
|
+
});
|
|
1175
|
+
Buffer2.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) {
|
|
1176
|
+
offset = offset >>> 0;
|
|
1177
|
+
validateNumber(offset, "offset");
|
|
1178
|
+
const first = this[offset];
|
|
1179
|
+
const last = this[offset + 7];
|
|
1180
|
+
if (first === void 0 || last === void 0) {
|
|
1181
|
+
boundsError(offset, this.length - 8);
|
|
1182
|
+
}
|
|
1183
|
+
const val = (first << 24) + // Overflow
|
|
1184
|
+
this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1185
|
+
return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);
|
|
1186
|
+
});
|
|
1187
|
+
Buffer2.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
|
|
1188
|
+
offset = offset >>> 0;
|
|
1189
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1190
|
+
return ieee754.read(this, offset, true, 23, 4);
|
|
1191
|
+
};
|
|
1192
|
+
Buffer2.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
|
|
1193
|
+
offset = offset >>> 0;
|
|
1194
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1195
|
+
return ieee754.read(this, offset, false, 23, 4);
|
|
1196
|
+
};
|
|
1197
|
+
Buffer2.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
|
|
1198
|
+
offset = offset >>> 0;
|
|
1199
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1200
|
+
return ieee754.read(this, offset, true, 52, 8);
|
|
1201
|
+
};
|
|
1202
|
+
Buffer2.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|
1203
|
+
offset = offset >>> 0;
|
|
1204
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1205
|
+
return ieee754.read(this, offset, false, 52, 8);
|
|
1206
|
+
};
|
|
1207
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
|
1208
|
+
if (!Buffer2.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
1209
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
|
|
1210
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1211
|
+
}
|
|
1212
|
+
Buffer2.prototype.writeUintLE = Buffer2.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) {
|
|
1213
|
+
value = +value;
|
|
1214
|
+
offset = offset >>> 0;
|
|
1215
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1216
|
+
if (!noAssert) {
|
|
1217
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1218
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1219
|
+
}
|
|
1220
|
+
let mul = 1;
|
|
1221
|
+
let i = 0;
|
|
1222
|
+
this[offset] = value & 255;
|
|
1223
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1224
|
+
this[offset + i] = value / mul & 255;
|
|
1225
|
+
}
|
|
1226
|
+
return offset + byteLength2;
|
|
1227
|
+
};
|
|
1228
|
+
Buffer2.prototype.writeUintBE = Buffer2.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) {
|
|
1229
|
+
value = +value;
|
|
1230
|
+
offset = offset >>> 0;
|
|
1231
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1232
|
+
if (!noAssert) {
|
|
1233
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1234
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1235
|
+
}
|
|
1236
|
+
let i = byteLength2 - 1;
|
|
1237
|
+
let mul = 1;
|
|
1238
|
+
this[offset + i] = value & 255;
|
|
1239
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1240
|
+
this[offset + i] = value / mul & 255;
|
|
1241
|
+
}
|
|
1242
|
+
return offset + byteLength2;
|
|
1243
|
+
};
|
|
1244
|
+
Buffer2.prototype.writeUint8 = Buffer2.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
|
|
1245
|
+
value = +value;
|
|
1246
|
+
offset = offset >>> 0;
|
|
1247
|
+
if (!noAssert) checkInt(this, value, offset, 1, 255, 0);
|
|
1248
|
+
this[offset] = value & 255;
|
|
1249
|
+
return offset + 1;
|
|
1250
|
+
};
|
|
1251
|
+
Buffer2.prototype.writeUint16LE = Buffer2.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
|
|
1252
|
+
value = +value;
|
|
1253
|
+
offset = offset >>> 0;
|
|
1254
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1255
|
+
this[offset] = value & 255;
|
|
1256
|
+
this[offset + 1] = value >>> 8;
|
|
1257
|
+
return offset + 2;
|
|
1258
|
+
};
|
|
1259
|
+
Buffer2.prototype.writeUint16BE = Buffer2.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
|
|
1260
|
+
value = +value;
|
|
1261
|
+
offset = offset >>> 0;
|
|
1262
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1263
|
+
this[offset] = value >>> 8;
|
|
1264
|
+
this[offset + 1] = value & 255;
|
|
1265
|
+
return offset + 2;
|
|
1266
|
+
};
|
|
1267
|
+
Buffer2.prototype.writeUint32LE = Buffer2.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
|
|
1268
|
+
value = +value;
|
|
1269
|
+
offset = offset >>> 0;
|
|
1270
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1271
|
+
this[offset + 3] = value >>> 24;
|
|
1272
|
+
this[offset + 2] = value >>> 16;
|
|
1273
|
+
this[offset + 1] = value >>> 8;
|
|
1274
|
+
this[offset] = value & 255;
|
|
1275
|
+
return offset + 4;
|
|
1276
|
+
};
|
|
1277
|
+
Buffer2.prototype.writeUint32BE = Buffer2.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
|
|
1278
|
+
value = +value;
|
|
1279
|
+
offset = offset >>> 0;
|
|
1280
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1281
|
+
this[offset] = value >>> 24;
|
|
1282
|
+
this[offset + 1] = value >>> 16;
|
|
1283
|
+
this[offset + 2] = value >>> 8;
|
|
1284
|
+
this[offset + 3] = value & 255;
|
|
1285
|
+
return offset + 4;
|
|
1286
|
+
};
|
|
1287
|
+
function wrtBigUInt64LE(buf, value, offset, min, max) {
|
|
1288
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1289
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1290
|
+
buf[offset++] = lo;
|
|
1291
|
+
lo = lo >> 8;
|
|
1292
|
+
buf[offset++] = lo;
|
|
1293
|
+
lo = lo >> 8;
|
|
1294
|
+
buf[offset++] = lo;
|
|
1295
|
+
lo = lo >> 8;
|
|
1296
|
+
buf[offset++] = lo;
|
|
1297
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1298
|
+
buf[offset++] = hi;
|
|
1299
|
+
hi = hi >> 8;
|
|
1300
|
+
buf[offset++] = hi;
|
|
1301
|
+
hi = hi >> 8;
|
|
1302
|
+
buf[offset++] = hi;
|
|
1303
|
+
hi = hi >> 8;
|
|
1304
|
+
buf[offset++] = hi;
|
|
1305
|
+
return offset;
|
|
1306
|
+
}
|
|
1307
|
+
function wrtBigUInt64BE(buf, value, offset, min, max) {
|
|
1308
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1309
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1310
|
+
buf[offset + 7] = lo;
|
|
1311
|
+
lo = lo >> 8;
|
|
1312
|
+
buf[offset + 6] = lo;
|
|
1313
|
+
lo = lo >> 8;
|
|
1314
|
+
buf[offset + 5] = lo;
|
|
1315
|
+
lo = lo >> 8;
|
|
1316
|
+
buf[offset + 4] = lo;
|
|
1317
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1318
|
+
buf[offset + 3] = hi;
|
|
1319
|
+
hi = hi >> 8;
|
|
1320
|
+
buf[offset + 2] = hi;
|
|
1321
|
+
hi = hi >> 8;
|
|
1322
|
+
buf[offset + 1] = hi;
|
|
1323
|
+
hi = hi >> 8;
|
|
1324
|
+
buf[offset] = hi;
|
|
1325
|
+
return offset + 8;
|
|
1326
|
+
}
|
|
1327
|
+
Buffer2.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {
|
|
1328
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1329
|
+
});
|
|
1330
|
+
Buffer2.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {
|
|
1331
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1332
|
+
});
|
|
1333
|
+
Buffer2.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) {
|
|
1334
|
+
value = +value;
|
|
1335
|
+
offset = offset >>> 0;
|
|
1336
|
+
if (!noAssert) {
|
|
1337
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1338
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1339
|
+
}
|
|
1340
|
+
let i = 0;
|
|
1341
|
+
let mul = 1;
|
|
1342
|
+
let sub = 0;
|
|
1343
|
+
this[offset] = value & 255;
|
|
1344
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1345
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1346
|
+
sub = 1;
|
|
1347
|
+
}
|
|
1348
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1349
|
+
}
|
|
1350
|
+
return offset + byteLength2;
|
|
1351
|
+
};
|
|
1352
|
+
Buffer2.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) {
|
|
1353
|
+
value = +value;
|
|
1354
|
+
offset = offset >>> 0;
|
|
1355
|
+
if (!noAssert) {
|
|
1356
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1357
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1358
|
+
}
|
|
1359
|
+
let i = byteLength2 - 1;
|
|
1360
|
+
let mul = 1;
|
|
1361
|
+
let sub = 0;
|
|
1362
|
+
this[offset + i] = value & 255;
|
|
1363
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1364
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1365
|
+
sub = 1;
|
|
1366
|
+
}
|
|
1367
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1368
|
+
}
|
|
1369
|
+
return offset + byteLength2;
|
|
1370
|
+
};
|
|
1371
|
+
Buffer2.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
|
|
1372
|
+
value = +value;
|
|
1373
|
+
offset = offset >>> 0;
|
|
1374
|
+
if (!noAssert) checkInt(this, value, offset, 1, 127, -128);
|
|
1375
|
+
if (value < 0) value = 255 + value + 1;
|
|
1376
|
+
this[offset] = value & 255;
|
|
1377
|
+
return offset + 1;
|
|
1378
|
+
};
|
|
1379
|
+
Buffer2.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
|
|
1380
|
+
value = +value;
|
|
1381
|
+
offset = offset >>> 0;
|
|
1382
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1383
|
+
this[offset] = value & 255;
|
|
1384
|
+
this[offset + 1] = value >>> 8;
|
|
1385
|
+
return offset + 2;
|
|
1386
|
+
};
|
|
1387
|
+
Buffer2.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
|
|
1388
|
+
value = +value;
|
|
1389
|
+
offset = offset >>> 0;
|
|
1390
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1391
|
+
this[offset] = value >>> 8;
|
|
1392
|
+
this[offset + 1] = value & 255;
|
|
1393
|
+
return offset + 2;
|
|
1394
|
+
};
|
|
1395
|
+
Buffer2.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
|
|
1396
|
+
value = +value;
|
|
1397
|
+
offset = offset >>> 0;
|
|
1398
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1399
|
+
this[offset] = value & 255;
|
|
1400
|
+
this[offset + 1] = value >>> 8;
|
|
1401
|
+
this[offset + 2] = value >>> 16;
|
|
1402
|
+
this[offset + 3] = value >>> 24;
|
|
1403
|
+
return offset + 4;
|
|
1404
|
+
};
|
|
1405
|
+
Buffer2.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
|
|
1406
|
+
value = +value;
|
|
1407
|
+
offset = offset >>> 0;
|
|
1408
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1409
|
+
if (value < 0) value = 4294967295 + value + 1;
|
|
1410
|
+
this[offset] = value >>> 24;
|
|
1411
|
+
this[offset + 1] = value >>> 16;
|
|
1412
|
+
this[offset + 2] = value >>> 8;
|
|
1413
|
+
this[offset + 3] = value & 255;
|
|
1414
|
+
return offset + 4;
|
|
1415
|
+
};
|
|
1416
|
+
Buffer2.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {
|
|
1417
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1418
|
+
});
|
|
1419
|
+
Buffer2.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {
|
|
1420
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1421
|
+
});
|
|
1422
|
+
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1423
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1424
|
+
if (offset < 0) throw new RangeError("Index out of range");
|
|
1425
|
+
}
|
|
1426
|
+
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1427
|
+
value = +value;
|
|
1428
|
+
offset = offset >>> 0;
|
|
1429
|
+
if (!noAssert) {
|
|
1430
|
+
checkIEEE754(buf, value, offset, 4);
|
|
1431
|
+
}
|
|
1432
|
+
ieee754.write(buf, value, offset, littleEndian, 23, 4);
|
|
1433
|
+
return offset + 4;
|
|
1434
|
+
}
|
|
1435
|
+
Buffer2.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
1436
|
+
return writeFloat(this, value, offset, true, noAssert);
|
|
1437
|
+
};
|
|
1438
|
+
Buffer2.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
1439
|
+
return writeFloat(this, value, offset, false, noAssert);
|
|
1440
|
+
};
|
|
1441
|
+
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1442
|
+
value = +value;
|
|
1443
|
+
offset = offset >>> 0;
|
|
1444
|
+
if (!noAssert) {
|
|
1445
|
+
checkIEEE754(buf, value, offset, 8);
|
|
1446
|
+
}
|
|
1447
|
+
ieee754.write(buf, value, offset, littleEndian, 52, 8);
|
|
1448
|
+
return offset + 8;
|
|
1449
|
+
}
|
|
1450
|
+
Buffer2.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
|
|
1451
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
1452
|
+
};
|
|
1453
|
+
Buffer2.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
|
|
1454
|
+
return writeDouble(this, value, offset, false, noAssert);
|
|
1455
|
+
};
|
|
1456
|
+
Buffer2.prototype.copy = function copy(target, targetStart, start, end) {
|
|
1457
|
+
if (!Buffer2.isBuffer(target)) throw new TypeError("argument should be a Buffer");
|
|
1458
|
+
if (!start) start = 0;
|
|
1459
|
+
if (!end && end !== 0) end = this.length;
|
|
1460
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
1461
|
+
if (!targetStart) targetStart = 0;
|
|
1462
|
+
if (end > 0 && end < start) end = start;
|
|
1463
|
+
if (end === start) return 0;
|
|
1464
|
+
if (target.length === 0 || this.length === 0) return 0;
|
|
1465
|
+
if (targetStart < 0) {
|
|
1466
|
+
throw new RangeError("targetStart out of bounds");
|
|
1467
|
+
}
|
|
1468
|
+
if (start < 0 || start >= this.length) throw new RangeError("Index out of range");
|
|
1469
|
+
if (end < 0) throw new RangeError("sourceEnd out of bounds");
|
|
1470
|
+
if (end > this.length) end = this.length;
|
|
1471
|
+
if (target.length - targetStart < end - start) {
|
|
1472
|
+
end = target.length - targetStart + start;
|
|
1473
|
+
}
|
|
1474
|
+
const len = end - start;
|
|
1475
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === "function") {
|
|
1476
|
+
this.copyWithin(targetStart, start, end);
|
|
1477
|
+
} else {
|
|
1478
|
+
Uint8Array.prototype.set.call(
|
|
1479
|
+
target,
|
|
1480
|
+
this.subarray(start, end),
|
|
1481
|
+
targetStart
|
|
1482
|
+
);
|
|
1483
|
+
}
|
|
1484
|
+
return len;
|
|
1485
|
+
};
|
|
1486
|
+
Buffer2.prototype.fill = function fill(val, start, end, encoding) {
|
|
1487
|
+
if (typeof val === "string") {
|
|
1488
|
+
if (typeof start === "string") {
|
|
1489
|
+
encoding = start;
|
|
1490
|
+
start = 0;
|
|
1491
|
+
end = this.length;
|
|
1492
|
+
} else if (typeof end === "string") {
|
|
1493
|
+
encoding = end;
|
|
1494
|
+
end = this.length;
|
|
1495
|
+
}
|
|
1496
|
+
if (encoding !== void 0 && typeof encoding !== "string") {
|
|
1497
|
+
throw new TypeError("encoding must be a string");
|
|
1498
|
+
}
|
|
1499
|
+
if (typeof encoding === "string" && !Buffer2.isEncoding(encoding)) {
|
|
1500
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
1501
|
+
}
|
|
1502
|
+
if (val.length === 1) {
|
|
1503
|
+
const code = val.charCodeAt(0);
|
|
1504
|
+
if (encoding === "utf8" && code < 128 || encoding === "latin1") {
|
|
1505
|
+
val = code;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
} else if (typeof val === "number") {
|
|
1509
|
+
val = val & 255;
|
|
1510
|
+
} else if (typeof val === "boolean") {
|
|
1511
|
+
val = Number(val);
|
|
1512
|
+
}
|
|
1513
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
1514
|
+
throw new RangeError("Out of range index");
|
|
1515
|
+
}
|
|
1516
|
+
if (end <= start) {
|
|
1517
|
+
return this;
|
|
1518
|
+
}
|
|
1519
|
+
start = start >>> 0;
|
|
1520
|
+
end = end === void 0 ? this.length : end >>> 0;
|
|
1521
|
+
if (!val) val = 0;
|
|
1522
|
+
let i;
|
|
1523
|
+
if (typeof val === "number") {
|
|
1524
|
+
for (i = start; i < end; ++i) {
|
|
1525
|
+
this[i] = val;
|
|
1526
|
+
}
|
|
1527
|
+
} else {
|
|
1528
|
+
const bytes = Buffer2.isBuffer(val) ? val : Buffer2.from(val, encoding);
|
|
1529
|
+
const len = bytes.length;
|
|
1530
|
+
if (len === 0) {
|
|
1531
|
+
throw new TypeError('The value "' + val + '" is invalid for argument "value"');
|
|
1532
|
+
}
|
|
1533
|
+
for (i = 0; i < end - start; ++i) {
|
|
1534
|
+
this[i + start] = bytes[i % len];
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
return this;
|
|
1538
|
+
};
|
|
1539
|
+
var errors = {};
|
|
1540
|
+
function E(sym, getMessage, Base) {
|
|
1541
|
+
errors[sym] = class NodeError extends Base {
|
|
1542
|
+
constructor() {
|
|
1543
|
+
super();
|
|
1544
|
+
Object.defineProperty(this, "message", {
|
|
1545
|
+
value: getMessage.apply(this, arguments),
|
|
1546
|
+
writable: true,
|
|
1547
|
+
configurable: true
|
|
1548
|
+
});
|
|
1549
|
+
this.name = `${this.name} [${sym}]`;
|
|
1550
|
+
this.stack;
|
|
1551
|
+
delete this.name;
|
|
1552
|
+
}
|
|
1553
|
+
get code() {
|
|
1554
|
+
return sym;
|
|
1555
|
+
}
|
|
1556
|
+
set code(value) {
|
|
1557
|
+
Object.defineProperty(this, "code", {
|
|
1558
|
+
configurable: true,
|
|
1559
|
+
enumerable: true,
|
|
1560
|
+
value,
|
|
1561
|
+
writable: true
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
toString() {
|
|
1565
|
+
return `${this.name} [${sym}]: ${this.message}`;
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
E(
|
|
1570
|
+
"ERR_BUFFER_OUT_OF_BOUNDS",
|
|
1571
|
+
function(name) {
|
|
1572
|
+
if (name) {
|
|
1573
|
+
return `${name} is outside of buffer bounds`;
|
|
1574
|
+
}
|
|
1575
|
+
return "Attempt to access memory outside buffer bounds";
|
|
1576
|
+
},
|
|
1577
|
+
RangeError
|
|
1578
|
+
);
|
|
1579
|
+
E(
|
|
1580
|
+
"ERR_INVALID_ARG_TYPE",
|
|
1581
|
+
function(name, actual) {
|
|
1582
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
|
|
1583
|
+
},
|
|
1584
|
+
TypeError
|
|
1585
|
+
);
|
|
1586
|
+
E(
|
|
1587
|
+
"ERR_OUT_OF_RANGE",
|
|
1588
|
+
function(str, range, input) {
|
|
1589
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
1590
|
+
let received = input;
|
|
1591
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
1592
|
+
received = addNumericalSeparator(String(input));
|
|
1593
|
+
} else if (typeof input === "bigint") {
|
|
1594
|
+
received = String(input);
|
|
1595
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
1596
|
+
received = addNumericalSeparator(received);
|
|
1597
|
+
}
|
|
1598
|
+
received += "n";
|
|
1599
|
+
}
|
|
1600
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
1601
|
+
return msg;
|
|
1602
|
+
},
|
|
1603
|
+
RangeError
|
|
1604
|
+
);
|
|
1605
|
+
function addNumericalSeparator(val) {
|
|
1606
|
+
let res = "";
|
|
1607
|
+
let i = val.length;
|
|
1608
|
+
const start = val[0] === "-" ? 1 : 0;
|
|
1609
|
+
for (; i >= start + 4; i -= 3) {
|
|
1610
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
1611
|
+
}
|
|
1612
|
+
return `${val.slice(0, i)}${res}`;
|
|
1613
|
+
}
|
|
1614
|
+
function checkBounds(buf, offset, byteLength2) {
|
|
1615
|
+
validateNumber(offset, "offset");
|
|
1616
|
+
if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
|
|
1617
|
+
boundsError(offset, buf.length - (byteLength2 + 1));
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
function checkIntBI(value, min, max, buf, offset, byteLength2) {
|
|
1621
|
+
if (value > max || value < min) {
|
|
1622
|
+
const n = typeof min === "bigint" ? "n" : "";
|
|
1623
|
+
let range;
|
|
1624
|
+
{
|
|
1625
|
+
if (min === 0 || min === BigInt(0)) {
|
|
1626
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
|
|
1627
|
+
} else {
|
|
1628
|
+
range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
throw new errors.ERR_OUT_OF_RANGE("value", range, value);
|
|
1632
|
+
}
|
|
1633
|
+
checkBounds(buf, offset, byteLength2);
|
|
1634
|
+
}
|
|
1635
|
+
function validateNumber(value, name) {
|
|
1636
|
+
if (typeof value !== "number") {
|
|
1637
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
function boundsError(value, length, type) {
|
|
1641
|
+
if (Math.floor(value) !== value) {
|
|
1642
|
+
validateNumber(value, type);
|
|
1643
|
+
throw new errors.ERR_OUT_OF_RANGE("offset", "an integer", value);
|
|
1644
|
+
}
|
|
1645
|
+
if (length < 0) {
|
|
1646
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();
|
|
1647
|
+
}
|
|
1648
|
+
throw new errors.ERR_OUT_OF_RANGE(
|
|
1649
|
+
"offset",
|
|
1650
|
+
`>= ${0} and <= ${length}`,
|
|
1651
|
+
value
|
|
1652
|
+
);
|
|
1653
|
+
}
|
|
1654
|
+
var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1655
|
+
function base64clean(str) {
|
|
1656
|
+
str = str.split("=")[0];
|
|
1657
|
+
str = str.trim().replace(INVALID_BASE64_RE, "");
|
|
1658
|
+
if (str.length < 2) return "";
|
|
1659
|
+
while (str.length % 4 !== 0) {
|
|
1660
|
+
str = str + "=";
|
|
1661
|
+
}
|
|
1662
|
+
return str;
|
|
1663
|
+
}
|
|
1664
|
+
function utf8ToBytes(string, units) {
|
|
1665
|
+
units = units || Infinity;
|
|
1666
|
+
let codePoint;
|
|
1667
|
+
const length = string.length;
|
|
1668
|
+
let leadSurrogate = null;
|
|
1669
|
+
const bytes = [];
|
|
1670
|
+
for (let i = 0; i < length; ++i) {
|
|
1671
|
+
codePoint = string.charCodeAt(i);
|
|
1672
|
+
if (codePoint > 55295 && codePoint < 57344) {
|
|
1673
|
+
if (!leadSurrogate) {
|
|
1674
|
+
if (codePoint > 56319) {
|
|
1675
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1676
|
+
continue;
|
|
1677
|
+
} else if (i + 1 === length) {
|
|
1678
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1679
|
+
continue;
|
|
1680
|
+
}
|
|
1681
|
+
leadSurrogate = codePoint;
|
|
1682
|
+
continue;
|
|
1683
|
+
}
|
|
1684
|
+
if (codePoint < 56320) {
|
|
1685
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1686
|
+
leadSurrogate = codePoint;
|
|
1687
|
+
continue;
|
|
1688
|
+
}
|
|
1689
|
+
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
1690
|
+
} else if (leadSurrogate) {
|
|
1691
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1692
|
+
}
|
|
1693
|
+
leadSurrogate = null;
|
|
1694
|
+
if (codePoint < 128) {
|
|
1695
|
+
if ((units -= 1) < 0) break;
|
|
1696
|
+
bytes.push(codePoint);
|
|
1697
|
+
} else if (codePoint < 2048) {
|
|
1698
|
+
if ((units -= 2) < 0) break;
|
|
1699
|
+
bytes.push(
|
|
1700
|
+
codePoint >> 6 | 192,
|
|
1701
|
+
codePoint & 63 | 128
|
|
1702
|
+
);
|
|
1703
|
+
} else if (codePoint < 65536) {
|
|
1704
|
+
if ((units -= 3) < 0) break;
|
|
1705
|
+
bytes.push(
|
|
1706
|
+
codePoint >> 12 | 224,
|
|
1707
|
+
codePoint >> 6 & 63 | 128,
|
|
1708
|
+
codePoint & 63 | 128
|
|
1709
|
+
);
|
|
1710
|
+
} else if (codePoint < 1114112) {
|
|
1711
|
+
if ((units -= 4) < 0) break;
|
|
1712
|
+
bytes.push(
|
|
1713
|
+
codePoint >> 18 | 240,
|
|
1714
|
+
codePoint >> 12 & 63 | 128,
|
|
1715
|
+
codePoint >> 6 & 63 | 128,
|
|
1716
|
+
codePoint & 63 | 128
|
|
1717
|
+
);
|
|
1718
|
+
} else {
|
|
1719
|
+
throw new Error("Invalid code point");
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
return bytes;
|
|
1723
|
+
}
|
|
1724
|
+
function asciiToBytes(str) {
|
|
1725
|
+
const byteArray = [];
|
|
1726
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1727
|
+
byteArray.push(str.charCodeAt(i) & 255);
|
|
1728
|
+
}
|
|
1729
|
+
return byteArray;
|
|
1730
|
+
}
|
|
1731
|
+
function utf16leToBytes(str, units) {
|
|
1732
|
+
let c, hi, lo;
|
|
1733
|
+
const byteArray = [];
|
|
1734
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1735
|
+
if ((units -= 2) < 0) break;
|
|
1736
|
+
c = str.charCodeAt(i);
|
|
1737
|
+
hi = c >> 8;
|
|
1738
|
+
lo = c % 256;
|
|
1739
|
+
byteArray.push(lo);
|
|
1740
|
+
byteArray.push(hi);
|
|
1741
|
+
}
|
|
1742
|
+
return byteArray;
|
|
1743
|
+
}
|
|
1744
|
+
function base64ToBytes(str) {
|
|
1745
|
+
return base64.toByteArray(base64clean(str));
|
|
1746
|
+
}
|
|
1747
|
+
function blitBuffer(src, dst, offset, length) {
|
|
1748
|
+
let i;
|
|
1749
|
+
for (i = 0; i < length; ++i) {
|
|
1750
|
+
if (i + offset >= dst.length || i >= src.length) break;
|
|
1751
|
+
dst[i + offset] = src[i];
|
|
1752
|
+
}
|
|
1753
|
+
return i;
|
|
1754
|
+
}
|
|
1755
|
+
function isInstance(obj, type) {
|
|
1756
|
+
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
|
1757
|
+
}
|
|
1758
|
+
function numberIsNaN(obj) {
|
|
1759
|
+
return obj !== obj;
|
|
1760
|
+
}
|
|
1761
|
+
var hexSliceLookupTable = (function() {
|
|
1762
|
+
const alphabet = "0123456789abcdef";
|
|
1763
|
+
const table = new Array(256);
|
|
1764
|
+
for (let i = 0; i < 16; ++i) {
|
|
1765
|
+
const i16 = i * 16;
|
|
1766
|
+
for (let j = 0; j < 16; ++j) {
|
|
1767
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
return table;
|
|
1771
|
+
})();
|
|
1772
|
+
function defineBigIntMethod(fn) {
|
|
1773
|
+
return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
|
|
1774
|
+
}
|
|
1775
|
+
function BufferBigIntNotDefined() {
|
|
1776
|
+
throw new Error("BigInt not supported");
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
});
|
|
1780
|
+
|
|
1781
|
+
// node_modules/safe-buffer/index.js
|
|
1782
|
+
var require_safe_buffer = __commonJS({
|
|
1783
|
+
"node_modules/safe-buffer/index.js"(exports, module) {
|
|
1784
|
+
var buffer = require_buffer();
|
|
1785
|
+
var Buffer2 = buffer.Buffer;
|
|
1786
|
+
function copyProps(src, dst) {
|
|
1787
|
+
for (var key in src) {
|
|
1788
|
+
dst[key] = src[key];
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
if (Buffer2.from && Buffer2.alloc && Buffer2.allocUnsafe && Buffer2.allocUnsafeSlow) {
|
|
1792
|
+
module.exports = buffer;
|
|
1793
|
+
} else {
|
|
1794
|
+
copyProps(buffer, exports);
|
|
1795
|
+
exports.Buffer = SafeBuffer;
|
|
1796
|
+
}
|
|
1797
|
+
function SafeBuffer(arg, encodingOrOffset, length) {
|
|
1798
|
+
return Buffer2(arg, encodingOrOffset, length);
|
|
1799
|
+
}
|
|
1800
|
+
SafeBuffer.prototype = Object.create(Buffer2.prototype);
|
|
1801
|
+
copyProps(Buffer2, SafeBuffer);
|
|
1802
|
+
SafeBuffer.from = function(arg, encodingOrOffset, length) {
|
|
1803
|
+
if (typeof arg === "number") {
|
|
1804
|
+
throw new TypeError("Argument must not be a number");
|
|
1805
|
+
}
|
|
1806
|
+
return Buffer2(arg, encodingOrOffset, length);
|
|
1807
|
+
};
|
|
1808
|
+
SafeBuffer.alloc = function(size, fill, encoding) {
|
|
1809
|
+
if (typeof size !== "number") {
|
|
1810
|
+
throw new TypeError("Argument must be a number");
|
|
1811
|
+
}
|
|
1812
|
+
var buf = Buffer2(size);
|
|
1813
|
+
if (fill !== void 0) {
|
|
1814
|
+
if (typeof encoding === "string") {
|
|
1815
|
+
buf.fill(fill, encoding);
|
|
1816
|
+
} else {
|
|
1817
|
+
buf.fill(fill);
|
|
1818
|
+
}
|
|
1819
|
+
} else {
|
|
1820
|
+
buf.fill(0);
|
|
1821
|
+
}
|
|
1822
|
+
return buf;
|
|
1823
|
+
};
|
|
1824
|
+
SafeBuffer.allocUnsafe = function(size) {
|
|
1825
|
+
if (typeof size !== "number") {
|
|
1826
|
+
throw new TypeError("Argument must be a number");
|
|
1827
|
+
}
|
|
1828
|
+
return Buffer2(size);
|
|
1829
|
+
};
|
|
1830
|
+
SafeBuffer.allocUnsafeSlow = function(size) {
|
|
1831
|
+
if (typeof size !== "number") {
|
|
1832
|
+
throw new TypeError("Argument must be a number");
|
|
1833
|
+
}
|
|
1834
|
+
return buffer.SlowBuffer(size);
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
});
|
|
1838
|
+
|
|
1839
|
+
// node_modules/base-x/src/index.js
|
|
1840
|
+
var require_src = __commonJS({
|
|
1841
|
+
"node_modules/base-x/src/index.js"(exports, module) {
|
|
1842
|
+
var _Buffer = require_safe_buffer().Buffer;
|
|
1843
|
+
function base(ALPHABET) {
|
|
1844
|
+
if (ALPHABET.length >= 255) {
|
|
1845
|
+
throw new TypeError("Alphabet too long");
|
|
1846
|
+
}
|
|
1847
|
+
var BASE_MAP = new Uint8Array(256);
|
|
1848
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
1849
|
+
BASE_MAP[j] = 255;
|
|
1850
|
+
}
|
|
1851
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
1852
|
+
var x = ALPHABET.charAt(i);
|
|
1853
|
+
var xc = x.charCodeAt(0);
|
|
1854
|
+
if (BASE_MAP[xc] !== 255) {
|
|
1855
|
+
throw new TypeError(x + " is ambiguous");
|
|
1856
|
+
}
|
|
1857
|
+
BASE_MAP[xc] = i;
|
|
1858
|
+
}
|
|
1859
|
+
var BASE = ALPHABET.length;
|
|
1860
|
+
var LEADER = ALPHABET.charAt(0);
|
|
1861
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
1862
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
1863
|
+
function encode(source) {
|
|
1864
|
+
if (Array.isArray(source) || source instanceof Uint8Array) {
|
|
1865
|
+
source = _Buffer.from(source);
|
|
1866
|
+
}
|
|
1867
|
+
if (!_Buffer.isBuffer(source)) {
|
|
1868
|
+
throw new TypeError("Expected Buffer");
|
|
1869
|
+
}
|
|
1870
|
+
if (source.length === 0) {
|
|
1871
|
+
return "";
|
|
1872
|
+
}
|
|
1873
|
+
var zeroes = 0;
|
|
1874
|
+
var length = 0;
|
|
1875
|
+
var pbegin = 0;
|
|
1876
|
+
var pend = source.length;
|
|
1877
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
1878
|
+
pbegin++;
|
|
1879
|
+
zeroes++;
|
|
1880
|
+
}
|
|
1881
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
1882
|
+
var b58 = new Uint8Array(size);
|
|
1883
|
+
while (pbegin !== pend) {
|
|
1884
|
+
var carry = source[pbegin];
|
|
1885
|
+
var i2 = 0;
|
|
1886
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
1887
|
+
carry += 256 * b58[it1] >>> 0;
|
|
1888
|
+
b58[it1] = carry % BASE >>> 0;
|
|
1889
|
+
carry = carry / BASE >>> 0;
|
|
1890
|
+
}
|
|
1891
|
+
if (carry !== 0) {
|
|
1892
|
+
throw new Error("Non-zero carry");
|
|
1893
|
+
}
|
|
1894
|
+
length = i2;
|
|
1895
|
+
pbegin++;
|
|
1896
|
+
}
|
|
1897
|
+
var it2 = size - length;
|
|
1898
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
1899
|
+
it2++;
|
|
1900
|
+
}
|
|
1901
|
+
var str = LEADER.repeat(zeroes);
|
|
1902
|
+
for (; it2 < size; ++it2) {
|
|
1903
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
1904
|
+
}
|
|
1905
|
+
return str;
|
|
1906
|
+
}
|
|
1907
|
+
function decodeUnsafe(source) {
|
|
1908
|
+
if (typeof source !== "string") {
|
|
1909
|
+
throw new TypeError("Expected String");
|
|
1910
|
+
}
|
|
1911
|
+
if (source.length === 0) {
|
|
1912
|
+
return _Buffer.alloc(0);
|
|
1913
|
+
}
|
|
1914
|
+
var psz = 0;
|
|
1915
|
+
var zeroes = 0;
|
|
1916
|
+
var length = 0;
|
|
1917
|
+
while (source[psz] === LEADER) {
|
|
1918
|
+
zeroes++;
|
|
1919
|
+
psz++;
|
|
1920
|
+
}
|
|
1921
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
1922
|
+
var b256 = new Uint8Array(size);
|
|
1923
|
+
while (psz < source.length) {
|
|
1924
|
+
var charCode = source.charCodeAt(psz);
|
|
1925
|
+
if (charCode > 255) {
|
|
1926
|
+
return;
|
|
1927
|
+
}
|
|
1928
|
+
var carry = BASE_MAP[charCode];
|
|
1929
|
+
if (carry === 255) {
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
var i2 = 0;
|
|
1933
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
1934
|
+
carry += BASE * b256[it3] >>> 0;
|
|
1935
|
+
b256[it3] = carry % 256 >>> 0;
|
|
1936
|
+
carry = carry / 256 >>> 0;
|
|
1937
|
+
}
|
|
1938
|
+
if (carry !== 0) {
|
|
1939
|
+
throw new Error("Non-zero carry");
|
|
1940
|
+
}
|
|
1941
|
+
length = i2;
|
|
1942
|
+
psz++;
|
|
1943
|
+
}
|
|
1944
|
+
var it4 = size - length;
|
|
1945
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
1946
|
+
it4++;
|
|
1947
|
+
}
|
|
1948
|
+
var vch = _Buffer.allocUnsafe(zeroes + (size - it4));
|
|
1949
|
+
vch.fill(0, 0, zeroes);
|
|
1950
|
+
var j2 = zeroes;
|
|
1951
|
+
while (it4 !== size) {
|
|
1952
|
+
vch[j2++] = b256[it4++];
|
|
1953
|
+
}
|
|
1954
|
+
return vch;
|
|
1955
|
+
}
|
|
1956
|
+
function decode5(string) {
|
|
1957
|
+
var buffer = decodeUnsafe(string);
|
|
1958
|
+
if (buffer) {
|
|
1959
|
+
return buffer;
|
|
1960
|
+
}
|
|
1961
|
+
throw new Error("Non-base" + BASE + " character");
|
|
1962
|
+
}
|
|
1963
|
+
return {
|
|
1964
|
+
encode,
|
|
1965
|
+
decodeUnsafe,
|
|
1966
|
+
decode: decode5
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
module.exports = base;
|
|
1970
|
+
}
|
|
1971
|
+
});
|
|
1972
|
+
|
|
1973
|
+
// node_modules/bs58/index.js
|
|
1974
|
+
var require_bs58 = __commonJS({
|
|
1975
|
+
"node_modules/bs58/index.js"(exports, module) {
|
|
1976
|
+
var basex = require_src();
|
|
1977
|
+
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1978
|
+
module.exports = basex(ALPHABET);
|
|
1979
|
+
}
|
|
1980
|
+
});
|
|
1981
|
+
var IDL = idlJson;
|
|
1982
|
+
var IDL_PROGRAM_ID = IDL.address;
|
|
1983
|
+
var PROGRAM_ID = new PublicKey(IDL.address);
|
|
1984
|
+
var KNOWN_MINTS = {
|
|
1985
|
+
/** Cypher Coin (CSDC) — accepted mint on devnet builds. */
|
|
1986
|
+
devnetCSDC: new PublicKey("8AF9BABNWwEhipRxtXPYoWSZW24SKjUn6YqbKd9ZqhwB"),
|
|
1987
|
+
/** Circle USDC — accepted mint on mainnet builds. */
|
|
1988
|
+
mainnetUSDC: new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")
|
|
1989
|
+
};
|
|
1990
|
+
var CLUSTERS = {
|
|
1991
|
+
devnet: {
|
|
1992
|
+
name: "devnet",
|
|
1993
|
+
rpc: "https://api.devnet.solana.com",
|
|
1994
|
+
arciumClusterOffset: 456,
|
|
1995
|
+
expectedMint: KNOWN_MINTS.devnetCSDC
|
|
1996
|
+
},
|
|
1997
|
+
mainnet: {
|
|
1998
|
+
name: "mainnet",
|
|
1999
|
+
rpc: "https://api.mainnet-beta.solana.com",
|
|
2000
|
+
arciumClusterOffset: 0,
|
|
2001
|
+
expectedMint: KNOWN_MINTS.mainnetUSDC
|
|
2002
|
+
},
|
|
2003
|
+
localnet: {
|
|
2004
|
+
name: "localnet",
|
|
2005
|
+
rpc: "http://localhost:8899",
|
|
2006
|
+
arciumClusterOffset: 1116522022,
|
|
2007
|
+
expectedMint: KNOWN_MINTS.devnetCSDC
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
var ACCOUNT_DISCRIMINATOR_SIZE = 8;
|
|
2011
|
+
var MIN_BET_USDC = 1000000n;
|
|
2012
|
+
var CREATOR_BOND = 10000000n;
|
|
2013
|
+
var DEFAULT_RESOLUTION_WINDOW_SECS = 7 * 24 * 3600;
|
|
2014
|
+
var DEFAULT_CLAIM_PERIOD_SECS = 14 * 24 * 3600;
|
|
2015
|
+
var DEFAULT_REFUND_PERIOD_SECS = 14 * 24 * 3600;
|
|
2016
|
+
var MAX_PROTOCOL_FEE_BPS = 100;
|
|
2017
|
+
var MAX_LP_FEE_BPS = 500;
|
|
2018
|
+
var BPS_DENOMINATOR = 10000n;
|
|
2019
|
+
var ODDS_SCALE = 1000000000n;
|
|
2020
|
+
var MarketState = {
|
|
2021
|
+
Active: 0,
|
|
2022
|
+
Closed: 1,
|
|
2023
|
+
Resolved: 2,
|
|
2024
|
+
Unresolved: 3
|
|
2025
|
+
};
|
|
2026
|
+
var MarketType = {
|
|
2027
|
+
YesNo: 0,
|
|
2028
|
+
MultiOutcome: 1
|
|
2029
|
+
};
|
|
2030
|
+
var MarketCategory = {
|
|
2031
|
+
Crypto: 0,
|
|
2032
|
+
Politics: 1,
|
|
2033
|
+
Sports: 2,
|
|
2034
|
+
Tech: 3,
|
|
2035
|
+
Economy: 4,
|
|
2036
|
+
Culture: 5,
|
|
2037
|
+
Beyond: 6
|
|
2038
|
+
};
|
|
2039
|
+
var MAX_QUESTION_BYTES = 200;
|
|
2040
|
+
var MIN_OUTCOMES_MULTI = 2;
|
|
2041
|
+
var MAX_OUTCOMES_MULTI = 4;
|
|
2042
|
+
function u64LeBytes(n) {
|
|
2043
|
+
const buf = Buffer.alloc(8);
|
|
2044
|
+
const asBig = typeof n === "bigint" ? n : BigInt(n.toString());
|
|
2045
|
+
buf.writeBigUInt64LE(asBig);
|
|
2046
|
+
return buf;
|
|
2047
|
+
}
|
|
2048
|
+
function globalStatePda(programId = PROGRAM_ID) {
|
|
2049
|
+
return PublicKey.findProgramAddressSync([Buffer.from("global_state")], programId);
|
|
2050
|
+
}
|
|
2051
|
+
function marketPda(marketId, programId = PROGRAM_ID) {
|
|
2052
|
+
return PublicKey.findProgramAddressSync(
|
|
2053
|
+
[Buffer.from("market"), u64LeBytes(marketId)],
|
|
2054
|
+
programId
|
|
2055
|
+
);
|
|
2056
|
+
}
|
|
2057
|
+
function marketVaultPda(market, programId = PROGRAM_ID) {
|
|
2058
|
+
return PublicKey.findProgramAddressSync(
|
|
2059
|
+
[Buffer.from("market_vault"), market.toBuffer()],
|
|
2060
|
+
programId
|
|
2061
|
+
);
|
|
2062
|
+
}
|
|
2063
|
+
function positionPda(market, user, programId = PROGRAM_ID) {
|
|
2064
|
+
return PublicKey.findProgramAddressSync(
|
|
2065
|
+
[Buffer.from("position"), market.toBuffer(), user.toBuffer()],
|
|
2066
|
+
programId
|
|
2067
|
+
);
|
|
2068
|
+
}
|
|
2069
|
+
function lpPositionPda(market, creator, programId = PROGRAM_ID) {
|
|
2070
|
+
return PublicKey.findProgramAddressSync(
|
|
2071
|
+
[Buffer.from("lp-position"), market.toBuffer(), creator.toBuffer()],
|
|
2072
|
+
programId
|
|
2073
|
+
);
|
|
2074
|
+
}
|
|
2075
|
+
function arciumSignerPda(programId = PROGRAM_ID) {
|
|
2076
|
+
return PublicKey.findProgramAddressSync(
|
|
2077
|
+
[Buffer.from("ArciumSignerAccount")],
|
|
2078
|
+
programId
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
2081
|
+
function keypairToWallet(keypair) {
|
|
2082
|
+
return {
|
|
2083
|
+
publicKey: keypair.publicKey,
|
|
2084
|
+
payer: keypair,
|
|
2085
|
+
async signTransaction(tx) {
|
|
2086
|
+
if ("version" in tx) {
|
|
2087
|
+
tx.sign([keypair]);
|
|
2088
|
+
} else {
|
|
2089
|
+
tx.partialSign(keypair);
|
|
2090
|
+
}
|
|
2091
|
+
return tx;
|
|
2092
|
+
},
|
|
2093
|
+
async signAllTransactions(txs) {
|
|
2094
|
+
for (const tx of txs) {
|
|
2095
|
+
if ("version" in tx) {
|
|
2096
|
+
tx.sign([keypair]);
|
|
2097
|
+
} else {
|
|
2098
|
+
tx.partialSign(keypair);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
return txs;
|
|
2102
|
+
}
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
function readonlyWallet(publicKey) {
|
|
2106
|
+
return {
|
|
2107
|
+
publicKey,
|
|
2108
|
+
async signTransaction() {
|
|
2109
|
+
throw new Error("readonlyWallet cannot sign transactions");
|
|
2110
|
+
},
|
|
2111
|
+
async signAllTransactions() {
|
|
2112
|
+
throw new Error("readonlyWallet cannot sign transactions");
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
// src/fees.ts
|
|
2118
|
+
function computeFees(amount, rates) {
|
|
2119
|
+
if (amount < 0n) throw new Error("computeFees: amount must be >= 0");
|
|
2120
|
+
assertBps(rates.protocolFeeRateBps, "protocolFeeRateBps");
|
|
2121
|
+
assertBps(rates.lpFeeRateBps, "lpFeeRateBps");
|
|
2122
|
+
const protocolFee = amount * BigInt(rates.protocolFeeRateBps) / BPS_DENOMINATOR;
|
|
2123
|
+
const lpFee = amount * BigInt(rates.lpFeeRateBps) / BPS_DENOMINATOR;
|
|
2124
|
+
const netAmount = amount - protocolFee - lpFee;
|
|
2125
|
+
if (netAmount < 0n) {
|
|
2126
|
+
throw new Error("computeFees: net amount went negative");
|
|
2127
|
+
}
|
|
2128
|
+
return { amount, protocolFee, lpFee, netAmount };
|
|
2129
|
+
}
|
|
2130
|
+
function isBetAmountValid(amount, rates, minBet = MIN_BET_USDC) {
|
|
2131
|
+
if (amount < minBet) return false;
|
|
2132
|
+
const { netAmount } = computeFees(amount, rates);
|
|
2133
|
+
return netAmount > 0n;
|
|
2134
|
+
}
|
|
2135
|
+
function assertBps(bps, name) {
|
|
2136
|
+
if (!Number.isInteger(bps) || bps < 0 || bps > 1e4) {
|
|
2137
|
+
throw new Error(`computeFees: ${name} must be an integer in [0, 10000]`);
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
// src/deadlines.ts
|
|
2142
|
+
function unixNowSecs() {
|
|
2143
|
+
return BigInt(Math.floor(Date.now() / 1e3));
|
|
2144
|
+
}
|
|
2145
|
+
function marketPhase(market, nowSec = unixNowSecs()) {
|
|
2146
|
+
if (market.state === MarketState.Closed) {
|
|
2147
|
+
return "cancelled";
|
|
2148
|
+
}
|
|
2149
|
+
if (market.state === MarketState.Resolved) {
|
|
2150
|
+
if (market.claimDeadline > 0n && nowSec <= market.claimDeadline) {
|
|
2151
|
+
return "claimable";
|
|
2152
|
+
}
|
|
2153
|
+
return "expired";
|
|
2154
|
+
}
|
|
2155
|
+
if (nowSec < market.closeTime) return "betting";
|
|
2156
|
+
if (nowSec <= market.resolutionDeadline) return "awaitingResolve";
|
|
2157
|
+
if (market.refundDeadline > 0n && nowSec <= market.refundDeadline) {
|
|
2158
|
+
return "refundable";
|
|
2159
|
+
}
|
|
2160
|
+
return "expired";
|
|
2161
|
+
}
|
|
2162
|
+
function projectDeadlines(closeTime) {
|
|
2163
|
+
const resolutionDeadline = closeTime + BigInt(DEFAULT_RESOLUTION_WINDOW_SECS);
|
|
2164
|
+
return {
|
|
2165
|
+
closeTime,
|
|
2166
|
+
resolutionDeadline,
|
|
2167
|
+
// Both downstream deadlines anchor on the resolution event, not on
|
|
2168
|
+
// close_time, so the projections assume "resolved exactly at the
|
|
2169
|
+
// resolution deadline" — the worst-case window for winners/bettors.
|
|
2170
|
+
projectedClaimDeadline: resolutionDeadline + BigInt(DEFAULT_CLAIM_PERIOD_SECS),
|
|
2171
|
+
projectedRefundDeadline: resolutionDeadline + BigInt(DEFAULT_REFUND_PERIOD_SECS)
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
function isValidCloseTime(closeTime, nowSec = unixNowSecs()) {
|
|
2175
|
+
return closeTime >= nowSec + 60n;
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
// src/errors.ts
|
|
2179
|
+
var CypherErrorCode = {
|
|
2180
|
+
MarketNotActive: 6e3,
|
|
2181
|
+
MarketClosed: 6001,
|
|
2182
|
+
MarketStillOpen: 6002,
|
|
2183
|
+
AlreadyResolved: 6003,
|
|
2184
|
+
NotResolved: 6004,
|
|
2185
|
+
UnauthorizedResolver: 6005,
|
|
2186
|
+
UnauthorizedAdmin: 6006,
|
|
2187
|
+
AlreadyClaimed: 6007,
|
|
2188
|
+
PositionLost: 6008,
|
|
2189
|
+
BetTooSmall: 6009,
|
|
2190
|
+
InsufficientVaultBalance: 6010,
|
|
2191
|
+
NoFeesToClaim: 6011,
|
|
2192
|
+
LiquidityTooLow: 6012,
|
|
2193
|
+
InvalidCloseTime: 6013,
|
|
2194
|
+
EmptyQuestion: 6014,
|
|
2195
|
+
QuestionTooLong: 6015,
|
|
2196
|
+
Overflow: 6016,
|
|
2197
|
+
InvalidOutcome: 6017,
|
|
2198
|
+
InvalidFeeRate: 6018,
|
|
2199
|
+
InvalidTreasury: 6019,
|
|
2200
|
+
BondAlreadyWithdrawn: 6020,
|
|
2201
|
+
NotMarketCreator: 6021,
|
|
2202
|
+
MarketHasBets: 6022,
|
|
2203
|
+
ResolutionDeadlinePassed: 6023,
|
|
2204
|
+
MarketNotUnresolved: 6024,
|
|
2205
|
+
ResolutionDeadlineNotReached: 6025,
|
|
2206
|
+
ClaimPeriodExpired: 6026,
|
|
2207
|
+
RefundPeriodExpired: 6027,
|
|
2208
|
+
AbortedComputation: 6028,
|
|
2209
|
+
ComputationVerificationFailed: 6029,
|
|
2210
|
+
CannotWithdrawFromUnresolved: 6030,
|
|
2211
|
+
AdminAlreadyClaimed: 6031,
|
|
2212
|
+
WrongMarketType: 6032,
|
|
2213
|
+
WrongMint: 6033,
|
|
2214
|
+
NotAcceptedMint: 6034,
|
|
2215
|
+
InvalidCategory: 6035
|
|
2216
|
+
};
|
|
2217
|
+
var CYPHER_ERROR_MESSAGES = Object.freeze(
|
|
2218
|
+
Object.fromEntries(
|
|
2219
|
+
IDL.errors.map((e) => [e.name, e.msg])
|
|
2220
|
+
)
|
|
2221
|
+
);
|
|
2222
|
+
var codeToName = Object.fromEntries(
|
|
2223
|
+
Object.entries(CypherErrorCode).map(([name, code]) => [
|
|
2224
|
+
code,
|
|
2225
|
+
name
|
|
2226
|
+
])
|
|
2227
|
+
);
|
|
2228
|
+
function cypherErrorName(code) {
|
|
2229
|
+
return codeToName[code];
|
|
2230
|
+
}
|
|
2231
|
+
function parseCypherError(input) {
|
|
2232
|
+
if (input == null) return null;
|
|
2233
|
+
const err = input;
|
|
2234
|
+
const fromAnchor = err.error?.errorCode?.number;
|
|
2235
|
+
if (typeof fromAnchor === "number") {
|
|
2236
|
+
return materialize(fromAnchor);
|
|
2237
|
+
}
|
|
2238
|
+
const namedCode = err.error?.errorCode?.code;
|
|
2239
|
+
if (namedCode && namedCode in CypherErrorCode) {
|
|
2240
|
+
return materialize(CypherErrorCode[namedCode]);
|
|
2241
|
+
}
|
|
2242
|
+
const logCandidates = [];
|
|
2243
|
+
if (Array.isArray(err.errorLogs)) logCandidates.push(...err.errorLogs);
|
|
2244
|
+
if (Array.isArray(err.logs)) logCandidates.push(...err.logs);
|
|
2245
|
+
if (typeof err.message === "string") logCandidates.push(err.message);
|
|
2246
|
+
for (const line of logCandidates) {
|
|
2247
|
+
const hex = line.match(/custom program error:\s*0x([0-9a-fA-F]+)/);
|
|
2248
|
+
if (hex && hex[1]) {
|
|
2249
|
+
const parsed = parseInt(hex[1], 16);
|
|
2250
|
+
const out = materialize(parsed);
|
|
2251
|
+
if (out) return out;
|
|
2252
|
+
}
|
|
2253
|
+
const dec = line.match(/Error Number:\s*(\d+)/);
|
|
2254
|
+
if (dec && dec[1]) {
|
|
2255
|
+
const parsed = parseInt(dec[1], 10);
|
|
2256
|
+
const out = materialize(parsed);
|
|
2257
|
+
if (out) return out;
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
return null;
|
|
2261
|
+
}
|
|
2262
|
+
function materialize(code) {
|
|
2263
|
+
const name = codeToName[code];
|
|
2264
|
+
if (!name) return null;
|
|
2265
|
+
return {
|
|
2266
|
+
code,
|
|
2267
|
+
name,
|
|
2268
|
+
msg: CYPHER_ERROR_MESSAGES[name]
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
// src/accounts/globalState.ts
|
|
2273
|
+
function decode(raw) {
|
|
2274
|
+
return {
|
|
2275
|
+
marketCounter: BigInt(raw.marketCounter.toString()),
|
|
2276
|
+
protocolFeeRate: raw.protocolFeeRate,
|
|
2277
|
+
lpFeeRate: raw.lpFeeRate,
|
|
2278
|
+
protocolTreasury: raw.protocolTreasury,
|
|
2279
|
+
acceptedMint: raw.acceptedMint,
|
|
2280
|
+
admin: raw.admin,
|
|
2281
|
+
bump: raw.bump
|
|
2282
|
+
};
|
|
2283
|
+
}
|
|
2284
|
+
async function fetchGlobalState(client) {
|
|
2285
|
+
const [pda] = globalStatePda(client.programId);
|
|
2286
|
+
const acc = client.program.account.globalState;
|
|
2287
|
+
const raw = await acc.fetch(pda);
|
|
2288
|
+
return decode(raw);
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
// src/accounts/filter.ts
|
|
2292
|
+
var import_bs58 = __toESM(require_bs58(), 1);
|
|
2293
|
+
|
|
2294
|
+
// src/accounts/layout.ts
|
|
2295
|
+
var MARKET_OFFSETS = {
|
|
2296
|
+
marketId: 0,
|
|
2297
|
+
question: 8,
|
|
2298
|
+
questionLen: 208,
|
|
2299
|
+
marketType: 209,
|
|
2300
|
+
numOutcomes: 210,
|
|
2301
|
+
category: 211,
|
|
2302
|
+
creator: 212,
|
|
2303
|
+
resolver: 244,
|
|
2304
|
+
creatorBond: 276,
|
|
2305
|
+
bondWithdrawn: 284,
|
|
2306
|
+
totalBetsCount: 285,
|
|
2307
|
+
encryptedPool0: 293,
|
|
2308
|
+
encryptedPool1: 325,
|
|
2309
|
+
encryptedPool2: 357,
|
|
2310
|
+
encryptedPool3: 389,
|
|
2311
|
+
mxeNonce: 421,
|
|
2312
|
+
revealedPool0: 437,
|
|
2313
|
+
revealedPool1: 445,
|
|
2314
|
+
revealedPool2: 453,
|
|
2315
|
+
revealedPool3: 461,
|
|
2316
|
+
state: 469,
|
|
2317
|
+
outcome: 470,
|
|
2318
|
+
pendingOutcome: 471,
|
|
2319
|
+
closeTime: 472,
|
|
2320
|
+
resolutionTime: 480,
|
|
2321
|
+
payoutRatio: 488,
|
|
2322
|
+
accumulatedLpFees: 496,
|
|
2323
|
+
accumulatedProtocolFees: 504,
|
|
2324
|
+
minBet: 512,
|
|
2325
|
+
totalPayoutsClaimed: 520,
|
|
2326
|
+
totalRefundsClaimed: 528,
|
|
2327
|
+
adminClaimedRemaining: 536,
|
|
2328
|
+
resolutionDeadline: 537,
|
|
2329
|
+
claimDeadline: 545,
|
|
2330
|
+
refundDeadline: 553,
|
|
2331
|
+
bump: 561,
|
|
2332
|
+
vaultBump: 562
|
|
2333
|
+
};
|
|
2334
|
+
var ENCRYPTED_POSITION_OFFSETS = {
|
|
2335
|
+
user: 0,
|
|
2336
|
+
market: 32,
|
|
2337
|
+
encryptedAmount: 64,
|
|
2338
|
+
encryptedSide: 96,
|
|
2339
|
+
userPubkey: 128,
|
|
2340
|
+
nonce: 160,
|
|
2341
|
+
entryOdds: 176,
|
|
2342
|
+
netAmount: 184,
|
|
2343
|
+
claimed: 192,
|
|
2344
|
+
bump: 193
|
|
2345
|
+
};
|
|
2346
|
+
var LP_POSITION_OFFSETS = {
|
|
2347
|
+
lpProvider: 0,
|
|
2348
|
+
market: 32,
|
|
2349
|
+
liquidityProvided: 64,
|
|
2350
|
+
feesEarned: 72,
|
|
2351
|
+
feesClaimed: 80,
|
|
2352
|
+
feesClaimedAmount: 81,
|
|
2353
|
+
bump: 89
|
|
2354
|
+
};
|
|
2355
|
+
var GLOBAL_STATE_OFFSETS = {
|
|
2356
|
+
marketCounter: 0,
|
|
2357
|
+
protocolFeeRate: 8,
|
|
2358
|
+
lpFeeRate: 10,
|
|
2359
|
+
protocolTreasury: 12,
|
|
2360
|
+
acceptedMint: 44,
|
|
2361
|
+
admin: 76,
|
|
2362
|
+
bump: 108
|
|
2363
|
+
};
|
|
2364
|
+
|
|
2365
|
+
// src/accounts/filter.ts
|
|
2366
|
+
var DISCRIMINATORS = Object.fromEntries(
|
|
2367
|
+
IDL.accounts.map((a) => [
|
|
2368
|
+
a.name,
|
|
2369
|
+
Uint8Array.from(a.discriminator)
|
|
2370
|
+
])
|
|
2371
|
+
);
|
|
2372
|
+
function memcmp(offset, value) {
|
|
2373
|
+
return { memcmp: { offset, bytes: value } };
|
|
2374
|
+
}
|
|
2375
|
+
function discriminatorFilter(accountName) {
|
|
2376
|
+
const disc = DISCRIMINATORS[accountName];
|
|
2377
|
+
if (!disc) throw new Error(`discriminatorFilter: unknown account '${accountName}'`);
|
|
2378
|
+
return memcmp(0, import_bs58.default.encode(disc));
|
|
2379
|
+
}
|
|
2380
|
+
function byteFilter(offset, value) {
|
|
2381
|
+
if (!Number.isInteger(value) || value < 0 || value > 255) {
|
|
2382
|
+
throw new Error(`byteFilter: value must be a u8, got ${value}`);
|
|
2383
|
+
}
|
|
2384
|
+
return memcmp(offset, import_bs58.default.encode(Uint8Array.from([value])));
|
|
2385
|
+
}
|
|
2386
|
+
var marketFilters = {
|
|
2387
|
+
discriminator: () => discriminatorFilter("Market"),
|
|
2388
|
+
byCreator: (creator) => memcmp(ACCOUNT_DISCRIMINATOR_SIZE + MARKET_OFFSETS.creator, creator.toBase58()),
|
|
2389
|
+
byResolver: (resolver) => memcmp(ACCOUNT_DISCRIMINATOR_SIZE + MARKET_OFFSETS.resolver, resolver.toBase58()),
|
|
2390
|
+
byState: (state) => byteFilter(ACCOUNT_DISCRIMINATOR_SIZE + MARKET_OFFSETS.state, state),
|
|
2391
|
+
byCategory: (category) => byteFilter(ACCOUNT_DISCRIMINATOR_SIZE + MARKET_OFFSETS.category, category),
|
|
2392
|
+
byMarketType: (mt) => byteFilter(ACCOUNT_DISCRIMINATOR_SIZE + MARKET_OFFSETS.marketType, mt)
|
|
2393
|
+
};
|
|
2394
|
+
var positionFilters = {
|
|
2395
|
+
discriminator: () => discriminatorFilter("EncryptedPosition"),
|
|
2396
|
+
byUser: (user) => memcmp(ACCOUNT_DISCRIMINATOR_SIZE + ENCRYPTED_POSITION_OFFSETS.user, user.toBase58()),
|
|
2397
|
+
byMarket: (market) => memcmp(ACCOUNT_DISCRIMINATOR_SIZE + ENCRYPTED_POSITION_OFFSETS.market, market.toBase58())
|
|
2398
|
+
};
|
|
2399
|
+
var lpPositionFilters = {
|
|
2400
|
+
discriminator: () => discriminatorFilter("LPPosition"),
|
|
2401
|
+
byProvider: (lpProvider) => memcmp(ACCOUNT_DISCRIMINATOR_SIZE + LP_POSITION_OFFSETS.lpProvider, lpProvider.toBase58()),
|
|
2402
|
+
byMarket: (market) => memcmp(ACCOUNT_DISCRIMINATOR_SIZE + LP_POSITION_OFFSETS.market, market.toBase58())
|
|
2403
|
+
};
|
|
2404
|
+
|
|
2405
|
+
// src/accounts/market.ts
|
|
2406
|
+
function decode2(raw) {
|
|
2407
|
+
const questionLen = raw.questionLen;
|
|
2408
|
+
const question = Buffer.from(raw.question.slice(0, questionLen)).toString("utf8");
|
|
2409
|
+
return {
|
|
2410
|
+
marketId: BigInt(raw.marketId.toString()),
|
|
2411
|
+
question,
|
|
2412
|
+
questionLen,
|
|
2413
|
+
marketType: raw.marketType,
|
|
2414
|
+
numOutcomes: raw.numOutcomes,
|
|
2415
|
+
category: raw.category,
|
|
2416
|
+
creator: raw.creator,
|
|
2417
|
+
resolver: raw.resolver,
|
|
2418
|
+
creatorBond: BigInt(raw.creatorBond.toString()),
|
|
2419
|
+
bondWithdrawn: raw.bondWithdrawn,
|
|
2420
|
+
totalBetsCount: BigInt(raw.totalBetsCount.toString()),
|
|
2421
|
+
encryptedPool0: Uint8Array.from(raw.encryptedPool0),
|
|
2422
|
+
encryptedPool1: Uint8Array.from(raw.encryptedPool1),
|
|
2423
|
+
encryptedPool2: Uint8Array.from(raw.encryptedPool2),
|
|
2424
|
+
encryptedPool3: Uint8Array.from(raw.encryptedPool3),
|
|
2425
|
+
mxeNonce: BigInt(raw.mxeNonce.toString()),
|
|
2426
|
+
revealedPool0: BigInt(raw.revealedPool0.toString()),
|
|
2427
|
+
revealedPool1: BigInt(raw.revealedPool1.toString()),
|
|
2428
|
+
revealedPool2: BigInt(raw.revealedPool2.toString()),
|
|
2429
|
+
revealedPool3: BigInt(raw.revealedPool3.toString()),
|
|
2430
|
+
state: raw.state,
|
|
2431
|
+
outcome: raw.outcome,
|
|
2432
|
+
pendingOutcome: raw.pendingOutcome,
|
|
2433
|
+
closeTime: BigInt(raw.closeTime.toString()),
|
|
2434
|
+
resolutionTime: BigInt(raw.resolutionTime.toString()),
|
|
2435
|
+
payoutRatio: BigInt(raw.payoutRatio.toString()),
|
|
2436
|
+
accumulatedLpFees: BigInt(raw.accumulatedLpFees.toString()),
|
|
2437
|
+
accumulatedProtocolFees: BigInt(raw.accumulatedProtocolFees.toString()),
|
|
2438
|
+
minBet: BigInt(raw.minBet.toString()),
|
|
2439
|
+
totalPayoutsClaimed: BigInt(raw.totalPayoutsClaimed.toString()),
|
|
2440
|
+
totalRefundsClaimed: BigInt(raw.totalRefundsClaimed.toString()),
|
|
2441
|
+
adminClaimedRemaining: raw.adminClaimedRemaining,
|
|
2442
|
+
resolutionDeadline: BigInt(raw.resolutionDeadline.toString()),
|
|
2443
|
+
claimDeadline: BigInt(raw.claimDeadline.toString()),
|
|
2444
|
+
refundDeadline: BigInt(raw.refundDeadline.toString()),
|
|
2445
|
+
bump: raw.bump,
|
|
2446
|
+
vaultBump: raw.vaultBump
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
function marketAccountFacade(client) {
|
|
2450
|
+
return client.program.account.market;
|
|
2451
|
+
}
|
|
2452
|
+
async function fetchMarket(client, idOrPda) {
|
|
2453
|
+
const pda = idOrPda instanceof PublicKey ? idOrPda : marketPda(idOrPda, client.programId)[0];
|
|
2454
|
+
const raw = await marketAccountFacade(client).fetchNullable(pda);
|
|
2455
|
+
return raw ? decode2(raw) : null;
|
|
2456
|
+
}
|
|
2457
|
+
async function fetchAllMarkets(client) {
|
|
2458
|
+
const raw = await marketAccountFacade(client).all();
|
|
2459
|
+
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
|
|
2460
|
+
}
|
|
2461
|
+
async function fetchMarketsByCreator(client, creator) {
|
|
2462
|
+
const raw = await marketAccountFacade(client).all([marketFilters.byCreator(creator)]);
|
|
2463
|
+
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
|
|
2464
|
+
}
|
|
2465
|
+
async function fetchMarketsByState(client, state) {
|
|
2466
|
+
const raw = await marketAccountFacade(client).all([marketFilters.byState(state)]);
|
|
2467
|
+
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
|
|
2468
|
+
}
|
|
2469
|
+
function decode3(raw) {
|
|
2470
|
+
return {
|
|
2471
|
+
user: raw.user,
|
|
2472
|
+
market: raw.market,
|
|
2473
|
+
encryptedAmount: Uint8Array.from(raw.encryptedAmount),
|
|
2474
|
+
encryptedSide: Uint8Array.from(raw.encryptedSide),
|
|
2475
|
+
userPubkey: Uint8Array.from(raw.userPubkey),
|
|
2476
|
+
nonce: BigInt(raw.nonce.toString()),
|
|
2477
|
+
entryOdds: BigInt(raw.entryOdds.toString()),
|
|
2478
|
+
netAmount: BigInt(raw.netAmount.toString()),
|
|
2479
|
+
claimed: raw.claimed,
|
|
2480
|
+
bump: raw.bump
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2483
|
+
function facade(client) {
|
|
2484
|
+
return client.program.account.encryptedPosition;
|
|
2485
|
+
}
|
|
2486
|
+
async function fetchPosition(client, market, user) {
|
|
2487
|
+
const [pda] = positionPda(market, user, client.programId);
|
|
2488
|
+
const raw = await facade(client).fetchNullable(pda);
|
|
2489
|
+
return raw ? decode3(raw) : null;
|
|
2490
|
+
}
|
|
2491
|
+
async function fetchUserPositions(client, user) {
|
|
2492
|
+
const raw = await facade(client).all([positionFilters.byUser(user)]);
|
|
2493
|
+
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode3(account) }));
|
|
2494
|
+
}
|
|
2495
|
+
async function fetchPositionsForMarket(client, market) {
|
|
2496
|
+
const raw = await facade(client).all([positionFilters.byMarket(market)]);
|
|
2497
|
+
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode3(account) }));
|
|
2498
|
+
}
|
|
2499
|
+
function decode4(raw) {
|
|
2500
|
+
return {
|
|
2501
|
+
lpProvider: raw.lpProvider,
|
|
2502
|
+
market: raw.market,
|
|
2503
|
+
liquidityProvided: BigInt(raw.liquidityProvided.toString()),
|
|
2504
|
+
feesEarned: BigInt(raw.feesEarned.toString()),
|
|
2505
|
+
feesClaimed: raw.feesClaimed,
|
|
2506
|
+
feesClaimedAmount: BigInt(raw.feesClaimedAmount.toString()),
|
|
2507
|
+
bump: raw.bump
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
function facade2(client) {
|
|
2511
|
+
return client.program.account.lpPosition;
|
|
2512
|
+
}
|
|
2513
|
+
async function fetchLpPosition(client, market, creator) {
|
|
2514
|
+
const [pda] = lpPositionPda(market, creator, client.programId);
|
|
2515
|
+
const raw = await facade2(client).fetchNullable(pda);
|
|
2516
|
+
return raw ? decode4(raw) : null;
|
|
2517
|
+
}
|
|
2518
|
+
async function fetchLpPositionsByProvider(client, provider) {
|
|
2519
|
+
const raw = await facade2(client).all([lpPositionFilters.byProvider(provider)]);
|
|
2520
|
+
return raw.map(({ publicKey, account }) => ({ publicKey, account: decode4(account) }));
|
|
2521
|
+
}
|
|
2522
|
+
var ADDRESS_LOOKUP_TABLE_PROGRAM_ID = AddressLookupTableProgram.programId;
|
|
2523
|
+
function method(client, methodName) {
|
|
2524
|
+
const m = client.program.methods[methodName];
|
|
2525
|
+
if (!m) {
|
|
2526
|
+
throw new Error(
|
|
2527
|
+
`instructions: unknown program method '${methodName}' \u2014 IDL out of sync?`
|
|
2528
|
+
);
|
|
2529
|
+
}
|
|
2530
|
+
return m;
|
|
2531
|
+
}
|
|
2532
|
+
function toBN(v) {
|
|
2533
|
+
if (v instanceof BN) return v;
|
|
2534
|
+
return new BN(typeof v === "bigint" ? v.toString() : v);
|
|
2535
|
+
}
|
|
2536
|
+
function userAta(owner, mint) {
|
|
2537
|
+
return getAssociatedTokenAddressSync(mint, owner, true);
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
// src/instructions/admin.ts
|
|
2541
|
+
async function initializeIx(client, params) {
|
|
2542
|
+
if (!Number.isInteger(params.protocolFeeRateBps) || params.protocolFeeRateBps < 0 || params.protocolFeeRateBps > MAX_PROTOCOL_FEE_BPS) {
|
|
2543
|
+
throw new Error(
|
|
2544
|
+
`initializeIx: protocolFeeRateBps must be in [0, ${MAX_PROTOCOL_FEE_BPS}]`
|
|
2545
|
+
);
|
|
2546
|
+
}
|
|
2547
|
+
if (!Number.isInteger(params.lpFeeRateBps) || params.lpFeeRateBps < 0 || params.lpFeeRateBps > MAX_LP_FEE_BPS) {
|
|
2548
|
+
throw new Error(
|
|
2549
|
+
`initializeIx: lpFeeRateBps must be in [0, ${MAX_LP_FEE_BPS}]`
|
|
2550
|
+
);
|
|
2551
|
+
}
|
|
2552
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2553
|
+
return method(client, "initialize")(params.protocolFeeRateBps, params.lpFeeRateBps).accountsPartial({
|
|
2554
|
+
admin: params.admin,
|
|
2555
|
+
globalState: gsPda,
|
|
2556
|
+
protocolTreasury: params.protocolTreasury,
|
|
2557
|
+
acceptedMint: params.acceptedMint,
|
|
2558
|
+
systemProgram: SystemProgram.programId
|
|
2559
|
+
}).instruction();
|
|
2560
|
+
}
|
|
2561
|
+
async function updateAcceptedMintIx(client, params) {
|
|
2562
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2563
|
+
return method(client, "updateAcceptedMint")().accountsPartial({
|
|
2564
|
+
admin: params.admin,
|
|
2565
|
+
globalState: gsPda,
|
|
2566
|
+
newMint: params.newMint,
|
|
2567
|
+
newTreasury: params.newTreasury
|
|
2568
|
+
}).instruction();
|
|
2569
|
+
}
|
|
2570
|
+
async function adminClaimRemainingIx(client, params) {
|
|
2571
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2572
|
+
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2573
|
+
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2574
|
+
return method(client, "adminClaimRemaining")().accountsPartial({
|
|
2575
|
+
admin: params.admin,
|
|
2576
|
+
globalState: gsPda,
|
|
2577
|
+
market: marketPdaKey,
|
|
2578
|
+
marketVault: vaultPda,
|
|
2579
|
+
protocolTreasury: params.protocolTreasury,
|
|
2580
|
+
tokenProgram: TOKEN_PROGRAM_ID
|
|
2581
|
+
}).instruction();
|
|
2582
|
+
}
|
|
2583
|
+
var CIRCUITS = {
|
|
2584
|
+
placePrivateBetYesno: "place_private_bet_yesno",
|
|
2585
|
+
revealMarketOutcomeYesno: "reveal_market_outcome_yesno",
|
|
2586
|
+
computeYesnoPayout: "compute_yesno_payout",
|
|
2587
|
+
computeYesnoRefund: "compute_yesno_refund",
|
|
2588
|
+
placePrivateBetMulti: "place_private_bet_multi",
|
|
2589
|
+
revealMarketOutcomeMulti: "reveal_market_outcome_multi",
|
|
2590
|
+
computeMultiPayout: "compute_multi_payout",
|
|
2591
|
+
computeMultiRefund: "compute_multi_refund"
|
|
2592
|
+
};
|
|
2593
|
+
var ALL_CIRCUITS = Object.values(CIRCUITS);
|
|
2594
|
+
function compDefOffsetBytes(circuit) {
|
|
2595
|
+
return getCompDefAccOffset(circuit);
|
|
2596
|
+
}
|
|
2597
|
+
function compDefOffsetU32(circuit) {
|
|
2598
|
+
const bytes = compDefOffsetBytes(circuit);
|
|
2599
|
+
return Buffer.from(bytes).readUInt32LE(0);
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
// src/instructions/compDef.ts
|
|
2603
|
+
var INIT_COMP_DEF_INSTRUCTIONS = {
|
|
2604
|
+
initPlaceBetYesnoCompDef: CIRCUITS.placePrivateBetYesno,
|
|
2605
|
+
initRevealYesnoCompDef: CIRCUITS.revealMarketOutcomeYesno,
|
|
2606
|
+
initPayoutYesnoCompDef: CIRCUITS.computeYesnoPayout,
|
|
2607
|
+
initRefundYesnoCompDef: CIRCUITS.computeYesnoRefund,
|
|
2608
|
+
initPlaceBetMultiCompDef: CIRCUITS.placePrivateBetMulti,
|
|
2609
|
+
initRevealMultiCompDef: CIRCUITS.revealMarketOutcomeMulti,
|
|
2610
|
+
initPayoutMultiCompDef: CIRCUITS.computeMultiPayout,
|
|
2611
|
+
initRefundMultiCompDef: CIRCUITS.computeMultiRefund
|
|
2612
|
+
};
|
|
2613
|
+
async function initCompDefIx(client, methodName, params) {
|
|
2614
|
+
const circuit = INIT_COMP_DEF_INSTRUCTIONS[methodName];
|
|
2615
|
+
if (!circuit) {
|
|
2616
|
+
throw new Error(`initCompDefIx: unknown method '${methodName}'`);
|
|
2617
|
+
}
|
|
2618
|
+
const mxeAccount = getMXEAccAddress(client.programId);
|
|
2619
|
+
const compDefAccount = getCompDefAccAddress(
|
|
2620
|
+
client.programId,
|
|
2621
|
+
compDefOffsetU32(circuit)
|
|
2622
|
+
);
|
|
2623
|
+
return method(client, methodName)().accountsPartial({
|
|
2624
|
+
payer: params.payer,
|
|
2625
|
+
mxeAccount,
|
|
2626
|
+
compDefAccount,
|
|
2627
|
+
addressLookupTable: params.addressLookupTable,
|
|
2628
|
+
lutProgram: ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
|
|
2629
|
+
arciumProgram: getArciumProgramId(),
|
|
2630
|
+
systemProgram: SystemProgram.programId
|
|
2631
|
+
}).instruction();
|
|
2632
|
+
}
|
|
2633
|
+
async function buildAllInitCompDefIx(client, params) {
|
|
2634
|
+
const out = [];
|
|
2635
|
+
for (const [methodName, circuit] of Object.entries(INIT_COMP_DEF_INSTRUCTIONS)) {
|
|
2636
|
+
const ix = await initCompDefIx(client, methodName, params);
|
|
2637
|
+
out.push({ circuit, ix });
|
|
2638
|
+
}
|
|
2639
|
+
return out;
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
// src/instructions/market.ts
|
|
2643
|
+
function validateMarketDraft(params) {
|
|
2644
|
+
const qBytes = new TextEncoder().encode(params.question).length;
|
|
2645
|
+
if (qBytes === 0) throw new Error("createMarketIx: question is empty");
|
|
2646
|
+
if (qBytes > MAX_QUESTION_BYTES) {
|
|
2647
|
+
throw new Error(
|
|
2648
|
+
`createMarketIx: question is ${qBytes} bytes (max ${MAX_QUESTION_BYTES})`
|
|
2649
|
+
);
|
|
2650
|
+
}
|
|
2651
|
+
if (!Number.isInteger(params.category) || params.category < 0 || params.category > 6) {
|
|
2652
|
+
throw new Error("createMarketIx: category must be a u8 in [0, 6]");
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
async function createMarketIx(client, params) {
|
|
2656
|
+
validateMarketDraft(params);
|
|
2657
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2658
|
+
const [marketPdaKey] = marketPda(toBN(params.expectedMarketId), client.programId);
|
|
2659
|
+
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2660
|
+
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2661
|
+
const creatorAta = userAta(params.creator, params.acceptedMint);
|
|
2662
|
+
return method(client, "createMarket")(
|
|
2663
|
+
params.question,
|
|
2664
|
+
toBN(params.closeTime),
|
|
2665
|
+
params.category
|
|
2666
|
+
).accountsPartial({
|
|
2667
|
+
creator: params.creator,
|
|
2668
|
+
globalState: gsPda,
|
|
2669
|
+
market: marketPdaKey,
|
|
2670
|
+
lpPosition: lpPda,
|
|
2671
|
+
marketVault: vaultPda,
|
|
2672
|
+
creatorTokenAccount: creatorAta,
|
|
2673
|
+
acceptedMint: params.acceptedMint,
|
|
2674
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
2675
|
+
systemProgram: SystemProgram.programId
|
|
2676
|
+
}).instruction();
|
|
2677
|
+
}
|
|
2678
|
+
async function createMarketMultiIx(client, params) {
|
|
2679
|
+
validateMarketDraft(params);
|
|
2680
|
+
if (!Number.isInteger(params.numOutcomes) || params.numOutcomes < MIN_OUTCOMES_MULTI || params.numOutcomes > MAX_OUTCOMES_MULTI) {
|
|
2681
|
+
throw new Error(
|
|
2682
|
+
`createMarketMultiIx: numOutcomes must be in [${MIN_OUTCOMES_MULTI}, ${MAX_OUTCOMES_MULTI}]`
|
|
2683
|
+
);
|
|
2684
|
+
}
|
|
2685
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2686
|
+
const [marketPdaKey] = marketPda(toBN(params.expectedMarketId), client.programId);
|
|
2687
|
+
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2688
|
+
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2689
|
+
const creatorAta = userAta(params.creator, params.acceptedMint);
|
|
2690
|
+
return method(client, "createMarketMulti")(
|
|
2691
|
+
params.question,
|
|
2692
|
+
toBN(params.closeTime),
|
|
2693
|
+
params.category,
|
|
2694
|
+
params.numOutcomes
|
|
2695
|
+
).accountsPartial({
|
|
2696
|
+
creator: params.creator,
|
|
2697
|
+
globalState: gsPda,
|
|
2698
|
+
market: marketPdaKey,
|
|
2699
|
+
lpPosition: lpPda,
|
|
2700
|
+
marketVault: vaultPda,
|
|
2701
|
+
creatorTokenAccount: creatorAta,
|
|
2702
|
+
acceptedMint: params.acceptedMint,
|
|
2703
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
2704
|
+
systemProgram: SystemProgram.programId
|
|
2705
|
+
}).instruction();
|
|
2706
|
+
}
|
|
2707
|
+
async function cancelMarketIx(client, params) {
|
|
2708
|
+
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2709
|
+
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2710
|
+
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2711
|
+
const creatorAta = userAta(params.creator, params.acceptedMint);
|
|
2712
|
+
return method(client, "cancelMarket")().accountsPartial({
|
|
2713
|
+
creator: params.creator,
|
|
2714
|
+
market: marketPdaKey,
|
|
2715
|
+
marketVault: vaultPda,
|
|
2716
|
+
lpPosition: lpPda,
|
|
2717
|
+
creatorTokenAccount: creatorAta,
|
|
2718
|
+
tokenProgram: TOKEN_PROGRAM_ID
|
|
2719
|
+
}).instruction();
|
|
2720
|
+
}
|
|
2721
|
+
async function withdrawCreatorFundsIx(client, params) {
|
|
2722
|
+
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2723
|
+
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2724
|
+
const [lpPda] = lpPositionPda(marketPdaKey, params.creator, client.programId);
|
|
2725
|
+
const creatorAta = userAta(params.creator, params.acceptedMint);
|
|
2726
|
+
return method(client, "withdrawCreatorFunds")().accountsPartial({
|
|
2727
|
+
creator: params.creator,
|
|
2728
|
+
market: marketPdaKey,
|
|
2729
|
+
lpPosition: lpPda,
|
|
2730
|
+
marketVault: vaultPda,
|
|
2731
|
+
creatorTokenAccount: creatorAta,
|
|
2732
|
+
tokenProgram: TOKEN_PROGRAM_ID
|
|
2733
|
+
}).instruction();
|
|
2734
|
+
}
|
|
2735
|
+
function buildArciumQueueAccounts(client, params) {
|
|
2736
|
+
const clusterOffset = client.cluster.arciumClusterOffset;
|
|
2737
|
+
const offsetBN = params.computationOffset instanceof BN ? params.computationOffset : new BN(params.computationOffset.toString());
|
|
2738
|
+
const mxeAccount = getMXEAccAddress(client.programId);
|
|
2739
|
+
const addressLookupTable = params.addressLookupTable ?? (params.lutOffsetSlot ? getLookupTableAddress(client.programId, params.lutOffsetSlot) : (
|
|
2740
|
+
// The LUT offset slot is stored on the MXE account; callers that
|
|
2741
|
+
// don't have it cached can pre-fetch via `fetchMxeLut(client)` or
|
|
2742
|
+
// pass it through after the first call. Throwing here forces them
|
|
2743
|
+
// to be explicit rather than silently submitting a tx with a stale
|
|
2744
|
+
// LUT.
|
|
2745
|
+
(() => {
|
|
2746
|
+
throw new Error(
|
|
2747
|
+
"buildArciumQueueAccounts: pass addressLookupTable or lutOffsetSlot"
|
|
2748
|
+
);
|
|
2749
|
+
})()
|
|
2750
|
+
));
|
|
2751
|
+
return {
|
|
2752
|
+
computationAccount: getComputationAccAddress(clusterOffset, offsetBN),
|
|
2753
|
+
clusterAccount: getClusterAccAddress(clusterOffset),
|
|
2754
|
+
mxeAccount,
|
|
2755
|
+
mempoolAccount: getMempoolAccAddress(clusterOffset),
|
|
2756
|
+
executingPool: getExecutingPoolAccAddress(clusterOffset),
|
|
2757
|
+
compDefAccount: getCompDefAccAddress(
|
|
2758
|
+
client.programId,
|
|
2759
|
+
compDefOffsetU32(params.circuit)
|
|
2760
|
+
),
|
|
2761
|
+
poolAccount: getFeePoolAccAddress(),
|
|
2762
|
+
clockAccount: getClockAccAddress(),
|
|
2763
|
+
signPdaAccount: arciumSignerPda(client.programId)[0],
|
|
2764
|
+
arciumProgram: getArciumProgramId(),
|
|
2765
|
+
addressLookupTable
|
|
2766
|
+
};
|
|
2767
|
+
}
|
|
2768
|
+
var _mxeLutCache = /* @__PURE__ */ new WeakMap();
|
|
2769
|
+
async function fetchMxeLookupTable(client) {
|
|
2770
|
+
const cached = _mxeLutCache.get(client);
|
|
2771
|
+
if (cached) return cached;
|
|
2772
|
+
const mxe = getMXEAccAddress(client.programId);
|
|
2773
|
+
const arciumProgram = (
|
|
2774
|
+
// dynamic import keeps this off the import graph for browser-only
|
|
2775
|
+
// surface that never queues a computation
|
|
2776
|
+
(await import('@arcium-hq/client')).getArciumProgram(client.provider)
|
|
2777
|
+
);
|
|
2778
|
+
const facade3 = arciumProgram.account.mxeAccount;
|
|
2779
|
+
const mxeAcc = await facade3.fetch(mxe);
|
|
2780
|
+
const slot = mxeAcc.lutOffsetSlot;
|
|
2781
|
+
const lut = getLookupTableAddress(client.programId, slot);
|
|
2782
|
+
const result = { lut, slot };
|
|
2783
|
+
_mxeLutCache.set(client, result);
|
|
2784
|
+
return result;
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
// src/instructions/bet.ts
|
|
2788
|
+
function assertU8(name, v) {
|
|
2789
|
+
if (!Number.isInteger(v) || v < 0 || v > 255) {
|
|
2790
|
+
throw new Error(`placePrivateBet*Ix: ${name} must be a u8`);
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
function assertCiphertext(name, v) {
|
|
2794
|
+
if (v.length !== 32) {
|
|
2795
|
+
throw new Error(`placePrivateBet*Ix: ${name} must be exactly 32 bytes`);
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
async function buildPlaceBetIx(client, circuit, methodName, params) {
|
|
2799
|
+
assertCiphertext("encryptedAmount", params.encryptedAmount);
|
|
2800
|
+
assertCiphertext("encryptedSide", params.encryptedSide);
|
|
2801
|
+
assertCiphertext("userX25519Pubkey", params.userX25519Pubkey);
|
|
2802
|
+
assertU8("(amount sanity)", 0);
|
|
2803
|
+
const [gsPda] = globalStatePda(client.programId);
|
|
2804
|
+
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2805
|
+
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2806
|
+
const [positionPdaKey] = positionPda(marketPdaKey, params.user, client.programId);
|
|
2807
|
+
const userTokenAccount = userAta(params.user, params.acceptedMint);
|
|
2808
|
+
const arcium = buildArciumQueueAccounts(client, {
|
|
2809
|
+
circuit,
|
|
2810
|
+
computationOffset: toBN(params.computationOffset),
|
|
2811
|
+
addressLookupTable: params.addressLookupTable
|
|
2812
|
+
});
|
|
2813
|
+
return method(client, methodName)(
|
|
2814
|
+
toBN(params.computationOffset),
|
|
2815
|
+
toBN(params.betAmountUsdc),
|
|
2816
|
+
Array.from(params.encryptedAmount),
|
|
2817
|
+
Array.from(params.encryptedSide),
|
|
2818
|
+
Array.from(params.userX25519Pubkey),
|
|
2819
|
+
toBN(params.nonce)
|
|
2820
|
+
).accountsPartial({
|
|
2821
|
+
payer: params.payer,
|
|
2822
|
+
signPdaAccount: arcium.signPdaAccount,
|
|
2823
|
+
mxeAccount: arcium.mxeAccount,
|
|
2824
|
+
mempoolAccount: arcium.mempoolAccount,
|
|
2825
|
+
executingPool: arcium.executingPool,
|
|
2826
|
+
computationAccount: arcium.computationAccount,
|
|
2827
|
+
compDefAccount: arcium.compDefAccount,
|
|
2828
|
+
clusterAccount: arcium.clusterAccount,
|
|
2829
|
+
poolAccount: arcium.poolAccount,
|
|
2830
|
+
clockAccount: arcium.clockAccount,
|
|
2831
|
+
systemProgram: SystemProgram.programId,
|
|
2832
|
+
arciumProgram: arcium.arciumProgram,
|
|
2833
|
+
user: params.user,
|
|
2834
|
+
globalState: gsPda,
|
|
2835
|
+
market: marketPdaKey,
|
|
2836
|
+
marketVault: vaultPda,
|
|
2837
|
+
userTokenAccount,
|
|
2838
|
+
protocolTreasury: params.protocolTreasury,
|
|
2839
|
+
position: positionPdaKey,
|
|
2840
|
+
tokenProgram: TOKEN_PROGRAM_ID
|
|
2841
|
+
}).instruction();
|
|
2842
|
+
}
|
|
2843
|
+
function placePrivateBetYesnoIx(client, params) {
|
|
2844
|
+
return buildPlaceBetIx(
|
|
2845
|
+
client,
|
|
2846
|
+
CIRCUITS.placePrivateBetYesno,
|
|
2847
|
+
"placePrivateBetYesno",
|
|
2848
|
+
params
|
|
2849
|
+
);
|
|
2850
|
+
}
|
|
2851
|
+
function placePrivateBetMultiIx(client, params) {
|
|
2852
|
+
return buildPlaceBetIx(
|
|
2853
|
+
client,
|
|
2854
|
+
CIRCUITS.placePrivateBetMulti,
|
|
2855
|
+
"placePrivateBetMulti",
|
|
2856
|
+
params
|
|
2857
|
+
);
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
// src/instructions/resolve.ts
|
|
2861
|
+
async function buildResolveIx(client, circuit, methodName, params) {
|
|
2862
|
+
if (!Number.isInteger(params.outcomeValue) || params.outcomeValue < 0 || params.outcomeValue > 255) {
|
|
2863
|
+
throw new Error("resolveMarketIx: outcomeValue must be a u8");
|
|
2864
|
+
}
|
|
2865
|
+
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2866
|
+
const arcium = buildArciumQueueAccounts(client, {
|
|
2867
|
+
circuit,
|
|
2868
|
+
computationOffset: toBN(params.computationOffset),
|
|
2869
|
+
addressLookupTable: params.addressLookupTable
|
|
2870
|
+
});
|
|
2871
|
+
return method(client, methodName)(toBN(params.computationOffset), params.outcomeValue).accountsPartial({
|
|
2872
|
+
payer: params.payer,
|
|
2873
|
+
signPdaAccount: arcium.signPdaAccount,
|
|
2874
|
+
mxeAccount: arcium.mxeAccount,
|
|
2875
|
+
mempoolAccount: arcium.mempoolAccount,
|
|
2876
|
+
executingPool: arcium.executingPool,
|
|
2877
|
+
computationAccount: arcium.computationAccount,
|
|
2878
|
+
compDefAccount: arcium.compDefAccount,
|
|
2879
|
+
clusterAccount: arcium.clusterAccount,
|
|
2880
|
+
poolAccount: arcium.poolAccount,
|
|
2881
|
+
clockAccount: arcium.clockAccount,
|
|
2882
|
+
systemProgram: SystemProgram.programId,
|
|
2883
|
+
arciumProgram: arcium.arciumProgram,
|
|
2884
|
+
resolver: params.resolver,
|
|
2885
|
+
market: marketPdaKey
|
|
2886
|
+
}).instruction();
|
|
2887
|
+
}
|
|
2888
|
+
function resolveMarketYesnoIx(client, params) {
|
|
2889
|
+
return buildResolveIx(
|
|
2890
|
+
client,
|
|
2891
|
+
CIRCUITS.revealMarketOutcomeYesno,
|
|
2892
|
+
"resolveMarketYesno",
|
|
2893
|
+
params
|
|
2894
|
+
);
|
|
2895
|
+
}
|
|
2896
|
+
function resolveMarketMultiIx(client, params) {
|
|
2897
|
+
return buildResolveIx(
|
|
2898
|
+
client,
|
|
2899
|
+
CIRCUITS.revealMarketOutcomeMulti,
|
|
2900
|
+
"resolveMarketMulti",
|
|
2901
|
+
params
|
|
2902
|
+
);
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2905
|
+
// src/instructions/claim.ts
|
|
2906
|
+
async function buildClaimIx(client, circuit, methodName, params) {
|
|
2907
|
+
const [marketPdaKey] = marketPda(toBN(params.marketId), client.programId);
|
|
2908
|
+
const [vaultPda] = marketVaultPda(marketPdaKey, client.programId);
|
|
2909
|
+
const [positionPdaKey] = positionPda(marketPdaKey, params.user, client.programId);
|
|
2910
|
+
const userTokenAccount = userAta(params.user, params.acceptedMint);
|
|
2911
|
+
const arcium = buildArciumQueueAccounts(client, {
|
|
2912
|
+
circuit,
|
|
2913
|
+
computationOffset: toBN(params.computationOffset),
|
|
2914
|
+
addressLookupTable: params.addressLookupTable
|
|
2915
|
+
});
|
|
2916
|
+
return method(client, methodName)(toBN(params.computationOffset)).accountsPartial({
|
|
2917
|
+
payer: params.payer,
|
|
2918
|
+
signPdaAccount: arcium.signPdaAccount,
|
|
2919
|
+
mxeAccount: arcium.mxeAccount,
|
|
2920
|
+
mempoolAccount: arcium.mempoolAccount,
|
|
2921
|
+
executingPool: arcium.executingPool,
|
|
2922
|
+
computationAccount: arcium.computationAccount,
|
|
2923
|
+
compDefAccount: arcium.compDefAccount,
|
|
2924
|
+
clusterAccount: arcium.clusterAccount,
|
|
2925
|
+
poolAccount: arcium.poolAccount,
|
|
2926
|
+
clockAccount: arcium.clockAccount,
|
|
2927
|
+
systemProgram: SystemProgram.programId,
|
|
2928
|
+
arciumProgram: arcium.arciumProgram,
|
|
2929
|
+
user: params.user,
|
|
2930
|
+
market: marketPdaKey,
|
|
2931
|
+
position: positionPdaKey,
|
|
2932
|
+
marketVault: vaultPda,
|
|
2933
|
+
userTokenAccount,
|
|
2934
|
+
tokenProgram: TOKEN_PROGRAM_ID
|
|
2935
|
+
}).instruction();
|
|
2936
|
+
}
|
|
2937
|
+
function claimPayoutYesnoIx(client, params) {
|
|
2938
|
+
return buildClaimIx(
|
|
2939
|
+
client,
|
|
2940
|
+
CIRCUITS.computeYesnoPayout,
|
|
2941
|
+
"claimPayoutYesno",
|
|
2942
|
+
params
|
|
2943
|
+
);
|
|
2944
|
+
}
|
|
2945
|
+
function claimPayoutMultiIx(client, params) {
|
|
2946
|
+
return buildClaimIx(
|
|
2947
|
+
client,
|
|
2948
|
+
CIRCUITS.computeMultiPayout,
|
|
2949
|
+
"claimPayoutMulti",
|
|
2950
|
+
params
|
|
2951
|
+
);
|
|
2952
|
+
}
|
|
2953
|
+
function claimRefundYesnoIx(client, params) {
|
|
2954
|
+
return buildClaimIx(
|
|
2955
|
+
client,
|
|
2956
|
+
CIRCUITS.computeYesnoRefund,
|
|
2957
|
+
"claimRefundYesno",
|
|
2958
|
+
params
|
|
2959
|
+
);
|
|
2960
|
+
}
|
|
2961
|
+
function claimRefundMultiIx(client, params) {
|
|
2962
|
+
return buildClaimIx(
|
|
2963
|
+
client,
|
|
2964
|
+
CIRCUITS.computeMultiRefund,
|
|
2965
|
+
"claimRefundMulti",
|
|
2966
|
+
params
|
|
2967
|
+
);
|
|
2968
|
+
}
|
|
2969
|
+
async function awaitComputation(client, computationOffset, opts = {}) {
|
|
2970
|
+
const started = Date.now();
|
|
2971
|
+
const offsetBN = computationOffset instanceof BN ? computationOffset : new BN(computationOffset.toString());
|
|
2972
|
+
const signature = await awaitComputationFinalization(
|
|
2973
|
+
client.provider,
|
|
2974
|
+
offsetBN,
|
|
2975
|
+
client.programId,
|
|
2976
|
+
opts.commitment ?? "confirmed",
|
|
2977
|
+
opts.timeoutMs ?? 12e4
|
|
2978
|
+
);
|
|
2979
|
+
return { status: "finalized", signature, durationMs: Date.now() - started };
|
|
2980
|
+
}
|
|
2981
|
+
function randomComputationOffset() {
|
|
2982
|
+
const buf = crypto.getRandomValues(new Uint8Array(8));
|
|
2983
|
+
let v = 0n;
|
|
2984
|
+
for (let i = 7; i >= 0; i--) v = v << 8n | BigInt(buf[i]);
|
|
2985
|
+
return v === 0n ? 1n : v;
|
|
2986
|
+
}
|
|
2987
|
+
|
|
2988
|
+
// src/actions/common.ts
|
|
2989
|
+
async function sendIx(client, ix, opts = {}) {
|
|
2990
|
+
const tx = new Transaction().add(ix);
|
|
2991
|
+
try {
|
|
2992
|
+
return await client.provider.sendAndConfirm(
|
|
2993
|
+
tx,
|
|
2994
|
+
opts.signers ?? [],
|
|
2995
|
+
opts.confirmOptions
|
|
2996
|
+
);
|
|
2997
|
+
} catch (err) {
|
|
2998
|
+
rethrowCypher(err);
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
async function sendIxAndAwaitArcium(client, ix, params) {
|
|
3002
|
+
const signature = await sendIx(client, ix, {
|
|
3003
|
+
signers: params.signers,
|
|
3004
|
+
confirmOptions: params.confirmOptions
|
|
3005
|
+
});
|
|
3006
|
+
const computation = await awaitComputation(
|
|
3007
|
+
client,
|
|
3008
|
+
params.computationOffset,
|
|
3009
|
+
{ timeoutMs: params.timeoutMs }
|
|
3010
|
+
);
|
|
3011
|
+
return { signature, computation };
|
|
3012
|
+
}
|
|
3013
|
+
function rethrowCypher(err) {
|
|
3014
|
+
const parsed = parseCypherError(err);
|
|
3015
|
+
if (parsed) {
|
|
3016
|
+
const wrapped = new Error(`${parsed.name}: ${parsed.msg}`);
|
|
3017
|
+
wrapped.cause = err;
|
|
3018
|
+
wrapped.cypherError = parsed;
|
|
3019
|
+
throw wrapped;
|
|
3020
|
+
}
|
|
3021
|
+
throw err;
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
// src/actions/createMarket.ts
|
|
3025
|
+
async function createMarketCommon(client, inputs) {
|
|
3026
|
+
if (!isValidCloseTime(BigInt(inputs.closeTime))) {
|
|
3027
|
+
throw new Error(
|
|
3028
|
+
"createMarket: closeTime must be at least 60 seconds in the future"
|
|
3029
|
+
);
|
|
3030
|
+
}
|
|
3031
|
+
const gs = await client.globalState.fetch({ refresh: true });
|
|
3032
|
+
const acceptedMint = inputs.acceptedMint ?? gs.acceptedMint;
|
|
3033
|
+
const expectedMarketId = gs.marketCounter;
|
|
3034
|
+
const ix = inputs.kind === "yesno" ? await createMarketIx(client, {
|
|
3035
|
+
...inputs,
|
|
3036
|
+
acceptedMint,
|
|
3037
|
+
expectedMarketId
|
|
3038
|
+
}) : await createMarketMultiIx(client, {
|
|
3039
|
+
...inputs,
|
|
3040
|
+
acceptedMint,
|
|
3041
|
+
expectedMarketId
|
|
3042
|
+
});
|
|
3043
|
+
const signature = await sendIx(client, ix);
|
|
3044
|
+
const [marketPdaKey] = marketPda(expectedMarketId, client.programId);
|
|
3045
|
+
const market = await client.markets.fetchByPda(marketPdaKey);
|
|
3046
|
+
return {
|
|
3047
|
+
signature,
|
|
3048
|
+
marketId: expectedMarketId,
|
|
3049
|
+
marketPda: marketPdaKey,
|
|
3050
|
+
market
|
|
3051
|
+
};
|
|
3052
|
+
}
|
|
3053
|
+
async function createMarketAction(client, inputs) {
|
|
3054
|
+
return createMarketCommon(client, { ...inputs, kind: "yesno" });
|
|
3055
|
+
}
|
|
3056
|
+
async function createMarketMultiAction(client, inputs) {
|
|
3057
|
+
return createMarketCommon(client, { ...inputs, kind: "multi" });
|
|
3058
|
+
}
|
|
3059
|
+
async function cancelMarketAction(client, inputs) {
|
|
3060
|
+
const acceptedMint = inputs.acceptedMint ?? (await client.globalState.fetch()).acceptedMint;
|
|
3061
|
+
const ix = await cancelMarketIx(client, { ...inputs, acceptedMint });
|
|
3062
|
+
const signature = await sendIx(client, ix);
|
|
3063
|
+
const [pda] = marketPda(inputs.marketId, client.programId);
|
|
3064
|
+
return { signature, market: await client.markets.fetchByPda(pda) };
|
|
3065
|
+
}
|
|
3066
|
+
async function withdrawCreatorFundsAction(client, inputs) {
|
|
3067
|
+
const acceptedMint = inputs.acceptedMint ?? (await client.globalState.fetch()).acceptedMint;
|
|
3068
|
+
const ix = await withdrawCreatorFundsIx(client, { ...inputs, acceptedMint });
|
|
3069
|
+
const signature = await sendIx(client, ix);
|
|
3070
|
+
return { signature };
|
|
3071
|
+
}
|
|
3072
|
+
function createUserKeypair() {
|
|
3073
|
+
const privateKey = crypto.getRandomValues(new Uint8Array(32));
|
|
3074
|
+
const publicKey = x25519.getPublicKey(privateKey);
|
|
3075
|
+
return { privateKey, publicKey };
|
|
3076
|
+
}
|
|
3077
|
+
function deriveSharedSecret(userPrivateKey, mxePublicKey) {
|
|
3078
|
+
return x25519.getSharedSecret(userPrivateKey, mxePublicKey);
|
|
3079
|
+
}
|
|
3080
|
+
function freshNonce() {
|
|
3081
|
+
return crypto.getRandomValues(new Uint8Array(16));
|
|
3082
|
+
}
|
|
3083
|
+
function leBytesToBigInt(bytes) {
|
|
3084
|
+
let n = 0n;
|
|
3085
|
+
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
3086
|
+
n = n << 8n | BigInt(bytes[i]);
|
|
3087
|
+
}
|
|
3088
|
+
return n;
|
|
3089
|
+
}
|
|
3090
|
+
function createCipher(userPrivateKey, mxePublicKey) {
|
|
3091
|
+
return new RescueCipher(deriveSharedSecret(userPrivateKey, mxePublicKey));
|
|
3092
|
+
}
|
|
3093
|
+
var _mxePubkeyCache = /* @__PURE__ */ new WeakMap();
|
|
3094
|
+
async function fetchMxePublicKey(client) {
|
|
3095
|
+
const cached = _mxePubkeyCache.get(client);
|
|
3096
|
+
if (cached) return cached;
|
|
3097
|
+
const key = await getMXEPublicKey(client.provider, client.programId);
|
|
3098
|
+
if (!key) return null;
|
|
3099
|
+
_mxePubkeyCache.set(client, key);
|
|
3100
|
+
return key;
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
// src/arcium/encoding.ts
|
|
3104
|
+
function toUint8(arr) {
|
|
3105
|
+
return Uint8Array.from(arr);
|
|
3106
|
+
}
|
|
3107
|
+
function encryptBetInput(input, cipher, nonceBytes = freshNonce()) {
|
|
3108
|
+
if (nonceBytes.length !== 16) {
|
|
3109
|
+
throw new Error("encryptBetInput: nonce must be exactly 16 bytes");
|
|
3110
|
+
}
|
|
3111
|
+
if (input.amount < 0n) throw new Error("encryptBetInput: amount must be >= 0");
|
|
3112
|
+
if (!Number.isInteger(input.side) || input.side < 0 || input.side > 255) {
|
|
3113
|
+
throw new Error("encryptBetInput: side must be a u8");
|
|
3114
|
+
}
|
|
3115
|
+
const cts = cipher.encrypt(
|
|
3116
|
+
[input.amount, BigInt(input.side)],
|
|
3117
|
+
nonceBytes
|
|
3118
|
+
);
|
|
3119
|
+
if (cts.length !== 2 || cts[0].length !== 32 || cts[1].length !== 32) {
|
|
3120
|
+
throw new Error(
|
|
3121
|
+
`encryptBetInput: unexpected ciphertext shape ${JSON.stringify(cts.map((c) => c.length))}`
|
|
3122
|
+
);
|
|
3123
|
+
}
|
|
3124
|
+
return {
|
|
3125
|
+
encryptedAmount: toUint8(cts[0]),
|
|
3126
|
+
encryptedSide: toUint8(cts[1]),
|
|
3127
|
+
nonceBytes,
|
|
3128
|
+
nonce: leBytesToBigInt(nonceBytes)
|
|
3129
|
+
};
|
|
3130
|
+
}
|
|
3131
|
+
function encryptRefundInput(input, cipher, nonceBytes = freshNonce()) {
|
|
3132
|
+
if (nonceBytes.length !== 16) {
|
|
3133
|
+
throw new Error("encryptRefundInput: nonce must be exactly 16 bytes");
|
|
3134
|
+
}
|
|
3135
|
+
if (input.amount < 0n) throw new Error("encryptRefundInput: amount must be >= 0");
|
|
3136
|
+
const cts = cipher.encrypt([input.amount], nonceBytes);
|
|
3137
|
+
if (cts.length !== 1 || cts[0].length !== 32) {
|
|
3138
|
+
throw new Error(
|
|
3139
|
+
`encryptRefundInput: unexpected ciphertext shape ${JSON.stringify(cts.map((c) => c.length))}`
|
|
3140
|
+
);
|
|
3141
|
+
}
|
|
3142
|
+
return {
|
|
3143
|
+
encryptedAmount: toUint8(cts[0]),
|
|
3144
|
+
nonceBytes,
|
|
3145
|
+
nonce: leBytesToBigInt(nonceBytes)
|
|
3146
|
+
};
|
|
3147
|
+
}
|
|
3148
|
+
function decryptBetInput(encrypted, cipher, nonceBytes) {
|
|
3149
|
+
if (nonceBytes.length !== 16) {
|
|
3150
|
+
throw new Error("decryptBetInput: nonce must be exactly 16 bytes");
|
|
3151
|
+
}
|
|
3152
|
+
const out = cipher.decrypt(
|
|
3153
|
+
[Array.from(encrypted.encryptedAmount), Array.from(encrypted.encryptedSide)],
|
|
3154
|
+
nonceBytes
|
|
3155
|
+
);
|
|
3156
|
+
return { amount: out[0], side: Number(out[1]) };
|
|
3157
|
+
}
|
|
3158
|
+
function bigIntToLeBytes(value, byteLength) {
|
|
3159
|
+
if (value < 0n) throw new Error("bigIntToLeBytes: value must be >= 0");
|
|
3160
|
+
const out = new Uint8Array(byteLength);
|
|
3161
|
+
let v = value;
|
|
3162
|
+
for (let i = 0; i < byteLength; i++) {
|
|
3163
|
+
out[i] = Number(v & 0xffn);
|
|
3164
|
+
v >>= 8n;
|
|
3165
|
+
}
|
|
3166
|
+
if (v !== 0n) {
|
|
3167
|
+
throw new Error(`bigIntToLeBytes: value does not fit in ${byteLength} bytes`);
|
|
3168
|
+
}
|
|
3169
|
+
return out;
|
|
3170
|
+
}
|
|
3171
|
+
|
|
3172
|
+
// src/actions/placeBet.ts
|
|
3173
|
+
async function placeBetAction(client, inputs) {
|
|
3174
|
+
const market = await client.markets.fetch(inputs.marketId);
|
|
3175
|
+
if (!market) {
|
|
3176
|
+
throw new Error(`placeBet: market ${inputs.marketId} not found`);
|
|
3177
|
+
}
|
|
3178
|
+
if (market.state !== MarketState.Active) {
|
|
3179
|
+
throw new Error(`placeBet: market state is ${market.state}, expected Active`);
|
|
3180
|
+
}
|
|
3181
|
+
const grossAmount = BigInt(inputs.amountUsdc);
|
|
3182
|
+
if (grossAmount < market.minBet) {
|
|
3183
|
+
throw new Error(
|
|
3184
|
+
`placeBet: amount ${grossAmount} < market.minBet ${market.minBet}`
|
|
3185
|
+
);
|
|
3186
|
+
}
|
|
3187
|
+
if (grossAmount < MIN_BET_USDC) {
|
|
3188
|
+
throw new Error(`placeBet: amount ${grossAmount} < protocol MIN_BET_USDC`);
|
|
3189
|
+
}
|
|
3190
|
+
const gs = await client.globalState.fetch();
|
|
3191
|
+
const { netAmount } = computeFees(grossAmount, {
|
|
3192
|
+
protocolFeeRateBps: gs.protocolFeeRate,
|
|
3193
|
+
lpFeeRateBps: gs.lpFeeRate
|
|
3194
|
+
});
|
|
3195
|
+
if (netAmount <= 0n) {
|
|
3196
|
+
throw new Error("placeBet: net amount after fees would be zero or negative");
|
|
3197
|
+
}
|
|
3198
|
+
validateSide(inputs.side, market.marketType, market.numOutcomes);
|
|
3199
|
+
const mxePubkey = await fetchMxePublicKey(client);
|
|
3200
|
+
if (!mxePubkey) {
|
|
3201
|
+
throw new Error(
|
|
3202
|
+
"placeBet: MXE public key not yet published; is the Arcium cluster ready?"
|
|
3203
|
+
);
|
|
3204
|
+
}
|
|
3205
|
+
const { lut } = await fetchMxeLookupTable(client);
|
|
3206
|
+
const userKeypair = inputs.userKeypair ?? createUserKeypair();
|
|
3207
|
+
const cipher = createCipher(userKeypair.privateKey, mxePubkey);
|
|
3208
|
+
const encrypted = encryptBetInput({ amount: netAmount, side: inputs.side }, cipher);
|
|
3209
|
+
const computationOffset = inputs.computationOffset ?? randomComputationOffset();
|
|
3210
|
+
const isMulti = market.marketType === MarketType.MultiOutcome;
|
|
3211
|
+
const builder = isMulti ? placePrivateBetMultiIx : placePrivateBetYesnoIx;
|
|
3212
|
+
const ix = await builder(client, {
|
|
3213
|
+
payer: inputs.payer,
|
|
3214
|
+
user: inputs.user,
|
|
3215
|
+
marketId: inputs.marketId,
|
|
3216
|
+
acceptedMint: gs.acceptedMint,
|
|
3217
|
+
protocolTreasury: gs.protocolTreasury,
|
|
3218
|
+
computationOffset,
|
|
3219
|
+
betAmountUsdc: grossAmount,
|
|
3220
|
+
encryptedAmount: encrypted.encryptedAmount,
|
|
3221
|
+
encryptedSide: encrypted.encryptedSide,
|
|
3222
|
+
userX25519Pubkey: userKeypair.publicKey,
|
|
3223
|
+
nonce: encrypted.nonce,
|
|
3224
|
+
addressLookupTable: lut
|
|
3225
|
+
});
|
|
3226
|
+
const { signature, computation } = await sendIxAndAwaitArcium(client, ix, {
|
|
3227
|
+
computationOffset,
|
|
3228
|
+
timeoutMs: inputs.timeoutMs
|
|
3229
|
+
});
|
|
3230
|
+
const [marketPdaKey] = marketPda(inputs.marketId, client.programId);
|
|
3231
|
+
const position = await client.positions.fetch(marketPdaKey, inputs.user);
|
|
3232
|
+
return {
|
|
3233
|
+
signature,
|
|
3234
|
+
computation,
|
|
3235
|
+
computationOffset,
|
|
3236
|
+
userKeypair,
|
|
3237
|
+
position
|
|
3238
|
+
};
|
|
3239
|
+
}
|
|
3240
|
+
function validateSide(side, marketType, numOutcomes) {
|
|
3241
|
+
if (!Number.isInteger(side) || side < 0) {
|
|
3242
|
+
throw new Error(`placeBet: side ${side} must be a non-negative integer`);
|
|
3243
|
+
}
|
|
3244
|
+
const ceiling = marketType === MarketType.YesNo ? 2 : numOutcomes;
|
|
3245
|
+
if (side >= ceiling) {
|
|
3246
|
+
throw new Error(
|
|
3247
|
+
`placeBet: side ${side} out of range \u2014 valid range for this market is [0, ${ceiling - 1}]`
|
|
3248
|
+
);
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
|
|
3252
|
+
// src/actions/resolveMarket.ts
|
|
3253
|
+
async function resolveMarketAction(client, inputs) {
|
|
3254
|
+
const market = await client.markets.fetch(inputs.marketId);
|
|
3255
|
+
if (!market) throw new Error(`resolveMarket: market ${inputs.marketId} not found`);
|
|
3256
|
+
if (market.state === MarketState.Resolved) {
|
|
3257
|
+
throw new Error("resolveMarket: market already resolved");
|
|
3258
|
+
}
|
|
3259
|
+
if (market.state === MarketState.Closed) {
|
|
3260
|
+
throw new Error("resolveMarket: market was cancelled");
|
|
3261
|
+
}
|
|
3262
|
+
validateOutcome(inputs.outcomeValue, market.marketType, market.numOutcomes);
|
|
3263
|
+
const { lut } = await fetchMxeLookupTable(client);
|
|
3264
|
+
const computationOffset = inputs.computationOffset ?? randomComputationOffset();
|
|
3265
|
+
const isMulti = market.marketType === MarketType.MultiOutcome;
|
|
3266
|
+
const builder = isMulti ? resolveMarketMultiIx : resolveMarketYesnoIx;
|
|
3267
|
+
const ix = await builder(client, {
|
|
3268
|
+
payer: inputs.payer,
|
|
3269
|
+
resolver: inputs.resolver,
|
|
3270
|
+
marketId: inputs.marketId,
|
|
3271
|
+
computationOffset,
|
|
3272
|
+
outcomeValue: inputs.outcomeValue,
|
|
3273
|
+
addressLookupTable: lut
|
|
3274
|
+
});
|
|
3275
|
+
const { signature, computation } = await sendIxAndAwaitArcium(client, ix, {
|
|
3276
|
+
computationOffset,
|
|
3277
|
+
timeoutMs: inputs.timeoutMs
|
|
3278
|
+
});
|
|
3279
|
+
const [pda] = marketPda(inputs.marketId, client.programId);
|
|
3280
|
+
return {
|
|
3281
|
+
signature,
|
|
3282
|
+
computation,
|
|
3283
|
+
computationOffset,
|
|
3284
|
+
market: await client.markets.fetchByPda(pda)
|
|
3285
|
+
};
|
|
3286
|
+
}
|
|
3287
|
+
function validateOutcome(outcome, marketType, numOutcomes) {
|
|
3288
|
+
if (!Number.isInteger(outcome) || outcome < 0) {
|
|
3289
|
+
throw new Error(`resolveMarket: outcome ${outcome} must be a non-negative integer`);
|
|
3290
|
+
}
|
|
3291
|
+
const ceiling = marketType === MarketType.YesNo ? 2 : numOutcomes;
|
|
3292
|
+
if (outcome >= ceiling) {
|
|
3293
|
+
throw new Error(
|
|
3294
|
+
`resolveMarket: outcome ${outcome} out of range \u2014 valid for this market is [0, ${ceiling - 1}]`
|
|
3295
|
+
);
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
// src/actions/claim.ts
|
|
3300
|
+
async function commonClaim(client, inputs, flavor) {
|
|
3301
|
+
const market = await client.markets.fetch(inputs.marketId);
|
|
3302
|
+
if (!market) throw new Error(`claim${cap(flavor)}: market not found`);
|
|
3303
|
+
const [pda] = marketPda(inputs.marketId, client.programId);
|
|
3304
|
+
const position = await client.positions.fetch(pda, inputs.user);
|
|
3305
|
+
if (!position) {
|
|
3306
|
+
throw new Error(
|
|
3307
|
+
`claim${cap(flavor)}: no position for user on market ${pda.toBase58()}`
|
|
3308
|
+
);
|
|
3309
|
+
}
|
|
3310
|
+
if (position.claimed) {
|
|
3311
|
+
throw new Error(`claim${cap(flavor)}: position already claimed`);
|
|
3312
|
+
}
|
|
3313
|
+
const phase = marketPhase(market);
|
|
3314
|
+
if (flavor === "payout" && phase !== "claimable") {
|
|
3315
|
+
throw new Error(
|
|
3316
|
+
`claimPayout: market phase is '${phase}' \u2014 payouts require 'claimable'`
|
|
3317
|
+
);
|
|
3318
|
+
}
|
|
3319
|
+
if (flavor === "refund" && phase !== "refundable") {
|
|
3320
|
+
throw new Error(
|
|
3321
|
+
`claimRefund: market phase is '${phase}' \u2014 refunds require 'refundable'`
|
|
3322
|
+
);
|
|
3323
|
+
}
|
|
3324
|
+
if (flavor === "payout" && market.state !== MarketState.Resolved) {
|
|
3325
|
+
throw new Error("claimPayout: market is not resolved");
|
|
3326
|
+
}
|
|
3327
|
+
const { acceptedMint } = await client.globalState.fetch();
|
|
3328
|
+
const { lut } = await fetchMxeLookupTable(client);
|
|
3329
|
+
const computationOffset = inputs.computationOffset ?? randomComputationOffset();
|
|
3330
|
+
const isMulti = market.marketType === MarketType.MultiOutcome;
|
|
3331
|
+
const builder = flavor === "payout" ? isMulti ? claimPayoutMultiIx : claimPayoutYesnoIx : isMulti ? claimRefundMultiIx : claimRefundYesnoIx;
|
|
3332
|
+
const ix = await builder(client, {
|
|
3333
|
+
payer: inputs.payer,
|
|
3334
|
+
user: inputs.user,
|
|
3335
|
+
marketId: inputs.marketId,
|
|
3336
|
+
acceptedMint,
|
|
3337
|
+
computationOffset,
|
|
3338
|
+
addressLookupTable: lut
|
|
3339
|
+
});
|
|
3340
|
+
const { signature, computation } = await sendIxAndAwaitArcium(client, ix, {
|
|
3341
|
+
computationOffset,
|
|
3342
|
+
timeoutMs: inputs.timeoutMs
|
|
3343
|
+
});
|
|
3344
|
+
return {
|
|
3345
|
+
signature,
|
|
3346
|
+
computation,
|
|
3347
|
+
computationOffset,
|
|
3348
|
+
position: await client.positions.fetch(pda, inputs.user),
|
|
3349
|
+
market: await client.markets.fetchByPda(pda)
|
|
3350
|
+
};
|
|
3351
|
+
}
|
|
3352
|
+
function claimPayoutAction(client, inputs) {
|
|
3353
|
+
return commonClaim(client, inputs, "payout");
|
|
3354
|
+
}
|
|
3355
|
+
function claimRefundAction(client, inputs) {
|
|
3356
|
+
return commonClaim(client, inputs, "refund");
|
|
3357
|
+
}
|
|
3358
|
+
function cap(s) {
|
|
3359
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
3360
|
+
}
|
|
3361
|
+
var ALL_EVENT_NAMES = /* @__PURE__ */ new Set([
|
|
3362
|
+
"MarketCreatedEvent",
|
|
3363
|
+
"BetPlacedEvent",
|
|
3364
|
+
"MarketResolvedEvent",
|
|
3365
|
+
"MarketCancelledEvent",
|
|
3366
|
+
"CreatorWithdrawnEvent",
|
|
3367
|
+
"PayoutClaimedEvent",
|
|
3368
|
+
"RefundClaimedEvent"
|
|
3369
|
+
]);
|
|
3370
|
+
var _coder = null;
|
|
3371
|
+
var _parser = null;
|
|
3372
|
+
function getParser() {
|
|
3373
|
+
if (!_parser) {
|
|
3374
|
+
_coder = new BorshCoder(IDL);
|
|
3375
|
+
_parser = new EventParser(PROGRAM_ID, _coder);
|
|
3376
|
+
}
|
|
3377
|
+
return _parser;
|
|
3378
|
+
}
|
|
3379
|
+
function parseLogs(logs) {
|
|
3380
|
+
const parser = getParser();
|
|
3381
|
+
const results = [];
|
|
3382
|
+
for (const event of parser.parseLogs(logs)) {
|
|
3383
|
+
results.push(event);
|
|
3384
|
+
}
|
|
3385
|
+
return results;
|
|
3386
|
+
}
|
|
3387
|
+
function parseLogsFor(logs, name) {
|
|
3388
|
+
return parseLogs(logs).filter((e) => e.name === name).map((e) => e.data);
|
|
3389
|
+
}
|
|
3390
|
+
|
|
3391
|
+
// src/events/subscribe.ts
|
|
3392
|
+
function subscribeAll(connection, callback, opts = {}) {
|
|
3393
|
+
const pid = opts.programId ?? PROGRAM_ID;
|
|
3394
|
+
const subscriptionId = connection.onLogs(
|
|
3395
|
+
pid,
|
|
3396
|
+
(logInfo) => {
|
|
3397
|
+
if (logInfo.err) return;
|
|
3398
|
+
const events = parseLogs(logInfo.logs);
|
|
3399
|
+
for (const evt of events) {
|
|
3400
|
+
callback(evt);
|
|
3401
|
+
}
|
|
3402
|
+
},
|
|
3403
|
+
opts.commitment ?? "confirmed"
|
|
3404
|
+
);
|
|
3405
|
+
return {
|
|
3406
|
+
subscriptionId,
|
|
3407
|
+
unsubscribe: () => {
|
|
3408
|
+
connection.removeOnLogsListener(subscriptionId);
|
|
3409
|
+
}
|
|
3410
|
+
};
|
|
3411
|
+
}
|
|
3412
|
+
function subscribeEvent(connection, name, callback, opts = {}) {
|
|
3413
|
+
return subscribeAll(
|
|
3414
|
+
connection,
|
|
3415
|
+
(event) => {
|
|
3416
|
+
if (event.name === name) {
|
|
3417
|
+
callback(event.data, event);
|
|
3418
|
+
}
|
|
3419
|
+
},
|
|
3420
|
+
opts
|
|
3421
|
+
);
|
|
3422
|
+
}
|
|
3423
|
+
function onMarketCreated(connection, callback, opts) {
|
|
3424
|
+
return subscribeEvent(connection, "MarketCreatedEvent", callback, opts);
|
|
3425
|
+
}
|
|
3426
|
+
function onBetPlaced(connection, callback, opts) {
|
|
3427
|
+
return subscribeEvent(connection, "BetPlacedEvent", callback, opts);
|
|
3428
|
+
}
|
|
3429
|
+
function onMarketResolved(connection, callback, opts) {
|
|
3430
|
+
return subscribeEvent(connection, "MarketResolvedEvent", callback, opts);
|
|
3431
|
+
}
|
|
3432
|
+
function onMarketCancelled(connection, callback, opts) {
|
|
3433
|
+
return subscribeEvent(connection, "MarketCancelledEvent", callback, opts);
|
|
3434
|
+
}
|
|
3435
|
+
function onCreatorWithdrawn(connection, callback, opts) {
|
|
3436
|
+
return subscribeEvent(connection, "CreatorWithdrawnEvent", callback, opts);
|
|
3437
|
+
}
|
|
3438
|
+
function onPayoutClaimed(connection, callback, opts) {
|
|
3439
|
+
return subscribeEvent(connection, "PayoutClaimedEvent", callback, opts);
|
|
3440
|
+
}
|
|
3441
|
+
function onRefundClaimed(connection, callback, opts) {
|
|
3442
|
+
return subscribeEvent(connection, "RefundClaimedEvent", callback, opts);
|
|
3443
|
+
}
|
|
3444
|
+
async function pollEvents(connection, opts = {}) {
|
|
3445
|
+
const pid = opts.programId ?? PROGRAM_ID;
|
|
3446
|
+
const sigs = await connection.getSignaturesForAddress(pid, {
|
|
3447
|
+
limit: opts.limit ?? 50,
|
|
3448
|
+
until: opts.afterSignature
|
|
3449
|
+
}, opts.commitment ?? "confirmed");
|
|
3450
|
+
const results = [];
|
|
3451
|
+
for (const sigInfo of sigs) {
|
|
3452
|
+
if (sigInfo.err) continue;
|
|
3453
|
+
const tx = await connection.getTransaction(sigInfo.signature, {
|
|
3454
|
+
commitment: opts.commitment ?? "confirmed",
|
|
3455
|
+
maxSupportedTransactionVersion: 0
|
|
3456
|
+
});
|
|
3457
|
+
if (!tx?.meta?.logMessages) continue;
|
|
3458
|
+
const events = parseLogs(tx.meta.logMessages);
|
|
3459
|
+
for (const event of events) {
|
|
3460
|
+
results.push({
|
|
3461
|
+
signature: sigInfo.signature,
|
|
3462
|
+
slot: sigInfo.slot,
|
|
3463
|
+
event
|
|
3464
|
+
});
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
return results;
|
|
3468
|
+
}
|
|
3469
|
+
|
|
3470
|
+
// src/client.ts
|
|
3471
|
+
var CypherClient = class {
|
|
3472
|
+
connection;
|
|
3473
|
+
wallet;
|
|
3474
|
+
provider;
|
|
3475
|
+
program;
|
|
3476
|
+
programId;
|
|
3477
|
+
cluster;
|
|
3478
|
+
_globalStateCache = null;
|
|
3479
|
+
/**
|
|
3480
|
+
* High-level account accessors. Each namespace is a thin facade over
|
|
3481
|
+
* the per-account fetch helpers in `./accounts/`.
|
|
3482
|
+
*/
|
|
3483
|
+
globalState;
|
|
3484
|
+
markets;
|
|
3485
|
+
positions;
|
|
3486
|
+
lpPositions;
|
|
3487
|
+
/**
|
|
3488
|
+
* High-level action helpers. Each orchestrates a full flow:
|
|
3489
|
+
* encrypt → build ix → send tx → await Arcium callback → refetch.
|
|
3490
|
+
*
|
|
3491
|
+
* For raw instruction building (advanced composition), use the
|
|
3492
|
+
* lower-level `client.admin`, `client.bets`, etc. namespaces below.
|
|
3493
|
+
*/
|
|
3494
|
+
actions;
|
|
3495
|
+
/**
|
|
3496
|
+
* Event subscription helpers. Subscribe via WebSocket (`onLogs`) or
|
|
3497
|
+
* poll-based fetching for environments without WS.
|
|
3498
|
+
*/
|
|
3499
|
+
events;
|
|
3500
|
+
/**
|
|
3501
|
+
* Instruction-builder facades. Each returns a `TransactionInstruction`
|
|
3502
|
+
* ready to drop into a `Transaction` / `TransactionMessage`.
|
|
3503
|
+
*
|
|
3504
|
+
* For end-to-end flows (encrypt → send → await callback → decode) use
|
|
3505
|
+
* the higher-level `client.actions.*` helpers.
|
|
3506
|
+
*/
|
|
3507
|
+
admin;
|
|
3508
|
+
compDefs;
|
|
3509
|
+
marketIx;
|
|
3510
|
+
bets;
|
|
3511
|
+
resolveIx;
|
|
3512
|
+
claimIx;
|
|
3513
|
+
constructor(opts) {
|
|
3514
|
+
this.connection = opts.connection;
|
|
3515
|
+
this.wallet = opts.wallet;
|
|
3516
|
+
this.programId = opts.programId ?? PROGRAM_ID;
|
|
3517
|
+
this.cluster = resolveCluster(opts.cluster, opts.connection.rpcEndpoint);
|
|
3518
|
+
const confirmOptions = opts.confirmOptions ?? {
|
|
3519
|
+
commitment: opts.commitment ?? "confirmed",
|
|
3520
|
+
preflightCommitment: opts.commitment ?? "confirmed",
|
|
3521
|
+
skipPreflight: false
|
|
3522
|
+
};
|
|
3523
|
+
this.provider = new AnchorProvider(this.connection, this.wallet, confirmOptions);
|
|
3524
|
+
const idlForProgram = this.programId.equals(PROGRAM_ID) ? IDL : { ...IDL, address: this.programId.toBase58() };
|
|
3525
|
+
this.program = new Program(idlForProgram, this.provider);
|
|
3526
|
+
this.globalState = {
|
|
3527
|
+
fetch: async (o = {}) => {
|
|
3528
|
+
if (o.refresh || !this._globalStateCache) {
|
|
3529
|
+
this._globalStateCache = await fetchGlobalState(this);
|
|
3530
|
+
}
|
|
3531
|
+
return this._globalStateCache;
|
|
3532
|
+
},
|
|
3533
|
+
invalidate: () => {
|
|
3534
|
+
this._globalStateCache = null;
|
|
3535
|
+
}
|
|
3536
|
+
};
|
|
3537
|
+
this.markets = {
|
|
3538
|
+
fetch: (id) => fetchMarket(this, id),
|
|
3539
|
+
fetchByPda: (pda) => fetchMarket(this, pda),
|
|
3540
|
+
all: () => fetchAllMarkets(this),
|
|
3541
|
+
byCreator: (creator) => fetchMarketsByCreator(this, creator),
|
|
3542
|
+
byState: (state) => fetchMarketsByState(this, state)
|
|
3543
|
+
};
|
|
3544
|
+
this.positions = {
|
|
3545
|
+
fetch: (market, user) => fetchPosition(this, market, user),
|
|
3546
|
+
byUser: (user) => fetchUserPositions(this, user),
|
|
3547
|
+
forMarket: (market) => fetchPositionsForMarket(this, market)
|
|
3548
|
+
};
|
|
3549
|
+
this.lpPositions = {
|
|
3550
|
+
fetch: (market, creator) => fetchLpPosition(this, market, creator),
|
|
3551
|
+
byProvider: (provider) => fetchLpPositionsByProvider(this, provider)
|
|
3552
|
+
};
|
|
3553
|
+
this.actions = {
|
|
3554
|
+
createMarket: (inputs) => createMarketAction(this, inputs),
|
|
3555
|
+
createMarketMulti: (inputs) => createMarketMultiAction(this, inputs),
|
|
3556
|
+
cancelMarket: (inputs) => cancelMarketAction(this, inputs),
|
|
3557
|
+
withdrawCreatorFunds: (inputs) => withdrawCreatorFundsAction(this, inputs),
|
|
3558
|
+
placeBet: (inputs) => placeBetAction(this, inputs),
|
|
3559
|
+
resolveMarket: (inputs) => resolveMarketAction(this, inputs),
|
|
3560
|
+
claimPayout: (inputs) => claimPayoutAction(this, inputs),
|
|
3561
|
+
claimRefund: (inputs) => claimRefundAction(this, inputs)
|
|
3562
|
+
};
|
|
3563
|
+
this.events = {
|
|
3564
|
+
subscribeAll: (cb, opts2) => subscribeAll(this.connection, cb, opts2),
|
|
3565
|
+
subscribe: (name, cb, opts2) => subscribeEvent(this.connection, name, cb, opts2),
|
|
3566
|
+
onMarketCreated: (cb, opts2) => onMarketCreated(this.connection, cb, opts2),
|
|
3567
|
+
onBetPlaced: (cb, opts2) => onBetPlaced(this.connection, cb, opts2),
|
|
3568
|
+
onMarketResolved: (cb, opts2) => onMarketResolved(this.connection, cb, opts2),
|
|
3569
|
+
onMarketCancelled: (cb, opts2) => onMarketCancelled(this.connection, cb, opts2),
|
|
3570
|
+
onCreatorWithdrawn: (cb, opts2) => onCreatorWithdrawn(this.connection, cb, opts2),
|
|
3571
|
+
onPayoutClaimed: (cb, opts2) => onPayoutClaimed(this.connection, cb, opts2),
|
|
3572
|
+
onRefundClaimed: (cb, opts2) => onRefundClaimed(this.connection, cb, opts2),
|
|
3573
|
+
pollEvents: (opts2) => pollEvents(this.connection, opts2),
|
|
3574
|
+
parseLogs: (logs) => parseLogs(logs)
|
|
3575
|
+
};
|
|
3576
|
+
this.admin = {
|
|
3577
|
+
initializeIx: (p) => initializeIx(this, p),
|
|
3578
|
+
updateAcceptedMintIx: (p) => updateAcceptedMintIx(this, p),
|
|
3579
|
+
adminClaimRemainingIx: (p) => adminClaimRemainingIx(this, p)
|
|
3580
|
+
};
|
|
3581
|
+
this.compDefs = {
|
|
3582
|
+
initIx: (name, p) => initCompDefIx(this, name, p),
|
|
3583
|
+
buildAllInitIx: ((p) => buildAllInitCompDefIx(this, p))
|
|
3584
|
+
};
|
|
3585
|
+
this.marketIx = {
|
|
3586
|
+
createIx: (p) => createMarketIx(this, p),
|
|
3587
|
+
createMultiIx: (p) => createMarketMultiIx(this, p),
|
|
3588
|
+
cancelIx: (p) => cancelMarketIx(this, p),
|
|
3589
|
+
withdrawCreatorFundsIx: (p) => withdrawCreatorFundsIx(this, p)
|
|
3590
|
+
};
|
|
3591
|
+
this.bets = {
|
|
3592
|
+
placeYesnoIx: (p) => placePrivateBetYesnoIx(this, p),
|
|
3593
|
+
placeMultiIx: (p) => placePrivateBetMultiIx(this, p)
|
|
3594
|
+
};
|
|
3595
|
+
this.resolveIx = {
|
|
3596
|
+
yesnoIx: (p) => resolveMarketYesnoIx(this, p),
|
|
3597
|
+
multiIx: (p) => resolveMarketMultiIx(this, p)
|
|
3598
|
+
};
|
|
3599
|
+
this.claimIx = {
|
|
3600
|
+
payoutYesnoIx: (p) => claimPayoutYesnoIx(this, p),
|
|
3601
|
+
payoutMultiIx: (p) => claimPayoutMultiIx(this, p),
|
|
3602
|
+
refundYesnoIx: (p) => claimRefundYesnoIx(this, p),
|
|
3603
|
+
refundMultiIx: (p) => claimRefundMultiIx(this, p)
|
|
3604
|
+
};
|
|
3605
|
+
}
|
|
3606
|
+
};
|
|
3607
|
+
function resolveCluster(cluster, rpcEndpoint) {
|
|
3608
|
+
if (typeof cluster === "object" && cluster !== null) return cluster;
|
|
3609
|
+
if (typeof cluster === "string") return CLUSTERS[cluster];
|
|
3610
|
+
const lower = rpcEndpoint.toLowerCase();
|
|
3611
|
+
if (lower.includes("devnet")) return CLUSTERS.devnet;
|
|
3612
|
+
if (lower.includes("mainnet") || lower.includes("api.solana.com")) return CLUSTERS.mainnet;
|
|
3613
|
+
if (lower.includes("localhost") || lower.includes("127.0.0.1")) return CLUSTERS.localnet;
|
|
3614
|
+
return CLUSTERS.devnet;
|
|
3615
|
+
}
|
|
3616
|
+
/*! Bundled license information:
|
|
3617
|
+
|
|
3618
|
+
ieee754/index.js:
|
|
3619
|
+
(*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
3620
|
+
|
|
3621
|
+
buffer/index.js:
|
|
3622
|
+
(*!
|
|
3623
|
+
* The buffer module from node.js, for the browser.
|
|
3624
|
+
*
|
|
3625
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
3626
|
+
* @license MIT
|
|
3627
|
+
*)
|
|
3628
|
+
|
|
3629
|
+
safe-buffer/index.js:
|
|
3630
|
+
(*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
3631
|
+
*/
|
|
3632
|
+
|
|
3633
|
+
export { ACCOUNT_DISCRIMINATOR_SIZE, ADDRESS_LOOKUP_TABLE_PROGRAM_ID, ALL_CIRCUITS, ALL_EVENT_NAMES, BPS_DENOMINATOR, CIRCUITS, CLUSTERS, CREATOR_BOND, CYPHER_ERROR_MESSAGES, CypherClient, CypherErrorCode, DEFAULT_CLAIM_PERIOD_SECS, DEFAULT_REFUND_PERIOD_SECS, DEFAULT_RESOLUTION_WINDOW_SECS, ENCRYPTED_POSITION_OFFSETS, GLOBAL_STATE_OFFSETS, IDL, IDL_PROGRAM_ID, INIT_COMP_DEF_INSTRUCTIONS, KNOWN_MINTS, LP_POSITION_OFFSETS, MARKET_OFFSETS, MAX_LP_FEE_BPS, MAX_OUTCOMES_MULTI, MAX_PROTOCOL_FEE_BPS, MAX_QUESTION_BYTES, MIN_BET_USDC, MIN_OUTCOMES_MULTI, MarketCategory, MarketState, MarketType, ODDS_SCALE, PROGRAM_ID, adminClaimRemainingIx, arciumSignerPda, awaitComputation, bigIntToLeBytes, buildAllInitCompDefIx, buildArciumQueueAccounts, cancelMarketAction, cancelMarketIx, claimPayoutAction, claimPayoutMultiIx, claimPayoutYesnoIx, claimRefundAction, claimRefundMultiIx, claimRefundYesnoIx, compDefOffsetBytes, compDefOffsetU32, computeFees, createCipher, createMarketAction, createMarketIx, createMarketMultiAction, createMarketMultiIx, createUserKeypair, cypherErrorName, decryptBetInput, deriveSharedSecret, discriminatorFilter, encryptBetInput, encryptRefundInput, fetchAllMarkets, fetchGlobalState, fetchLpPosition, fetchLpPositionsByProvider, fetchMarket, fetchMarketsByCreator, fetchMarketsByState, fetchMxeLookupTable, fetchMxePublicKey, fetchPosition, fetchPositionsForMarket, fetchUserPositions, freshNonce, globalStatePda, initCompDefIx, initializeIx, isBetAmountValid, isValidCloseTime, keypairToWallet, leBytesToBigInt, lpPositionFilters, lpPositionPda, marketFilters, marketPda, marketPhase, marketVaultPda, onBetPlaced, onCreatorWithdrawn, onMarketCancelled, onMarketCreated, onMarketResolved, onPayoutClaimed, onRefundClaimed, parseCypherError, parseLogs, parseLogsFor, placeBetAction, placePrivateBetMultiIx, placePrivateBetYesnoIx, pollEvents, positionFilters, positionPda, projectDeadlines, randomComputationOffset, readonlyWallet, resolveMarketAction, resolveMarketMultiIx, resolveMarketYesnoIx, sendIx, sendIxAndAwaitArcium, subscribeAll, subscribeEvent, toBN, updateAcceptedMintIx, userAta, withdrawCreatorFundsAction, withdrawCreatorFundsIx };
|
|
3634
|
+
//# sourceMappingURL=index.js.map
|
|
3635
|
+
//# sourceMappingURL=index.js.map
|