@pump-fun/pump-sdk 1.18.4 → 1.18.6
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/dist/esm/index.js +2146 -328
- package/dist/index.d.mts +46 -48
- package/dist/index.d.ts +46 -48
- package/dist/index.js +2116 -331
- package/package.json +2 -2
- package/src/idl/pump.json +0 -4
- package/src/idl/pump.ts +0 -4
- package/src/index.ts +2 -11
- package/src/onlineSdk.ts +428 -0
- package/src/pda.ts +23 -51
- package/src/sdk.ts +9 -392
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,1806 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// node_modules/base64-js/index.js
|
|
28
|
+
var require_base64_js = __commonJS({
|
|
29
|
+
"node_modules/base64-js/index.js"(exports) {
|
|
30
|
+
"use strict";
|
|
31
|
+
exports.byteLength = byteLength;
|
|
32
|
+
exports.toByteArray = toByteArray;
|
|
33
|
+
exports.fromByteArray = fromByteArray;
|
|
34
|
+
var lookup = [];
|
|
35
|
+
var revLookup = [];
|
|
36
|
+
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
37
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
38
|
+
for (i = 0, len = code.length; i < len; ++i) {
|
|
39
|
+
lookup[i] = code[i];
|
|
40
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
41
|
+
}
|
|
42
|
+
var i;
|
|
43
|
+
var len;
|
|
44
|
+
revLookup["-".charCodeAt(0)] = 62;
|
|
45
|
+
revLookup["_".charCodeAt(0)] = 63;
|
|
46
|
+
function getLens(b64) {
|
|
47
|
+
var len2 = b64.length;
|
|
48
|
+
if (len2 % 4 > 0) {
|
|
49
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
50
|
+
}
|
|
51
|
+
var validLen = b64.indexOf("=");
|
|
52
|
+
if (validLen === -1) validLen = len2;
|
|
53
|
+
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
54
|
+
return [validLen, placeHoldersLen];
|
|
55
|
+
}
|
|
56
|
+
function byteLength(b64) {
|
|
57
|
+
var lens = getLens(b64);
|
|
58
|
+
var validLen = lens[0];
|
|
59
|
+
var placeHoldersLen = lens[1];
|
|
60
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
61
|
+
}
|
|
62
|
+
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
63
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
64
|
+
}
|
|
65
|
+
function toByteArray(b64) {
|
|
66
|
+
var tmp;
|
|
67
|
+
var lens = getLens(b64);
|
|
68
|
+
var validLen = lens[0];
|
|
69
|
+
var placeHoldersLen = lens[1];
|
|
70
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
71
|
+
var curByte = 0;
|
|
72
|
+
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
73
|
+
var i2;
|
|
74
|
+
for (i2 = 0; i2 < len2; i2 += 4) {
|
|
75
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
76
|
+
arr[curByte++] = tmp >> 16 & 255;
|
|
77
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
78
|
+
arr[curByte++] = tmp & 255;
|
|
79
|
+
}
|
|
80
|
+
if (placeHoldersLen === 2) {
|
|
81
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
82
|
+
arr[curByte++] = tmp & 255;
|
|
83
|
+
}
|
|
84
|
+
if (placeHoldersLen === 1) {
|
|
85
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
86
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
87
|
+
arr[curByte++] = tmp & 255;
|
|
88
|
+
}
|
|
89
|
+
return arr;
|
|
90
|
+
}
|
|
91
|
+
function tripletToBase64(num) {
|
|
92
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
93
|
+
}
|
|
94
|
+
function encodeChunk(uint8, start, end) {
|
|
95
|
+
var tmp;
|
|
96
|
+
var output = [];
|
|
97
|
+
for (var i2 = start; i2 < end; i2 += 3) {
|
|
98
|
+
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
99
|
+
output.push(tripletToBase64(tmp));
|
|
100
|
+
}
|
|
101
|
+
return output.join("");
|
|
102
|
+
}
|
|
103
|
+
function fromByteArray(uint8) {
|
|
104
|
+
var tmp;
|
|
105
|
+
var len2 = uint8.length;
|
|
106
|
+
var extraBytes = len2 % 3;
|
|
107
|
+
var parts = [];
|
|
108
|
+
var maxChunkLength = 16383;
|
|
109
|
+
for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) {
|
|
110
|
+
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
111
|
+
}
|
|
112
|
+
if (extraBytes === 1) {
|
|
113
|
+
tmp = uint8[len2 - 1];
|
|
114
|
+
parts.push(
|
|
115
|
+
lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "=="
|
|
116
|
+
);
|
|
117
|
+
} else if (extraBytes === 2) {
|
|
118
|
+
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
119
|
+
parts.push(
|
|
120
|
+
lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return parts.join("");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// node_modules/ieee754/index.js
|
|
129
|
+
var require_ieee754 = __commonJS({
|
|
130
|
+
"node_modules/ieee754/index.js"(exports) {
|
|
131
|
+
"use strict";
|
|
132
|
+
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
133
|
+
var e, m;
|
|
134
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
135
|
+
var eMax = (1 << eLen) - 1;
|
|
136
|
+
var eBias = eMax >> 1;
|
|
137
|
+
var nBits = -7;
|
|
138
|
+
var i = isLE ? nBytes - 1 : 0;
|
|
139
|
+
var d = isLE ? -1 : 1;
|
|
140
|
+
var s = buffer[offset + i];
|
|
141
|
+
i += d;
|
|
142
|
+
e = s & (1 << -nBits) - 1;
|
|
143
|
+
s >>= -nBits;
|
|
144
|
+
nBits += eLen;
|
|
145
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
146
|
+
}
|
|
147
|
+
m = e & (1 << -nBits) - 1;
|
|
148
|
+
e >>= -nBits;
|
|
149
|
+
nBits += mLen;
|
|
150
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
151
|
+
}
|
|
152
|
+
if (e === 0) {
|
|
153
|
+
e = 1 - eBias;
|
|
154
|
+
} else if (e === eMax) {
|
|
155
|
+
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
156
|
+
} else {
|
|
157
|
+
m = m + Math.pow(2, mLen);
|
|
158
|
+
e = e - eBias;
|
|
159
|
+
}
|
|
160
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
161
|
+
};
|
|
162
|
+
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
163
|
+
var e, m, c;
|
|
164
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
165
|
+
var eMax = (1 << eLen) - 1;
|
|
166
|
+
var eBias = eMax >> 1;
|
|
167
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
168
|
+
var i = isLE ? 0 : nBytes - 1;
|
|
169
|
+
var d = isLE ? 1 : -1;
|
|
170
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
171
|
+
value = Math.abs(value);
|
|
172
|
+
if (isNaN(value) || value === Infinity) {
|
|
173
|
+
m = isNaN(value) ? 1 : 0;
|
|
174
|
+
e = eMax;
|
|
175
|
+
} else {
|
|
176
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
177
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
178
|
+
e--;
|
|
179
|
+
c *= 2;
|
|
180
|
+
}
|
|
181
|
+
if (e + eBias >= 1) {
|
|
182
|
+
value += rt / c;
|
|
183
|
+
} else {
|
|
184
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
185
|
+
}
|
|
186
|
+
if (value * c >= 2) {
|
|
187
|
+
e++;
|
|
188
|
+
c /= 2;
|
|
189
|
+
}
|
|
190
|
+
if (e + eBias >= eMax) {
|
|
191
|
+
m = 0;
|
|
192
|
+
e = eMax;
|
|
193
|
+
} else if (e + eBias >= 1) {
|
|
194
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
195
|
+
e = e + eBias;
|
|
196
|
+
} else {
|
|
197
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
198
|
+
e = 0;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
|
|
202
|
+
}
|
|
203
|
+
e = e << mLen | m;
|
|
204
|
+
eLen += mLen;
|
|
205
|
+
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
|
|
206
|
+
}
|
|
207
|
+
buffer[offset + i - d] |= s * 128;
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// node_modules/buffer/index.js
|
|
213
|
+
var require_buffer = __commonJS({
|
|
214
|
+
"node_modules/buffer/index.js"(exports) {
|
|
215
|
+
"use strict";
|
|
216
|
+
var base64 = require_base64_js();
|
|
217
|
+
var ieee754 = require_ieee754();
|
|
218
|
+
var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
|
|
219
|
+
exports.Buffer = Buffer3;
|
|
220
|
+
exports.SlowBuffer = SlowBuffer;
|
|
221
|
+
exports.INSPECT_MAX_BYTES = 50;
|
|
222
|
+
var K_MAX_LENGTH = 2147483647;
|
|
223
|
+
exports.kMaxLength = K_MAX_LENGTH;
|
|
224
|
+
Buffer3.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
225
|
+
if (!Buffer3.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
|
|
226
|
+
console.error(
|
|
227
|
+
"This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
function typedArraySupport() {
|
|
231
|
+
try {
|
|
232
|
+
const arr = new Uint8Array(1);
|
|
233
|
+
const proto = { foo: function() {
|
|
234
|
+
return 42;
|
|
235
|
+
} };
|
|
236
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
237
|
+
Object.setPrototypeOf(arr, proto);
|
|
238
|
+
return arr.foo() === 42;
|
|
239
|
+
} catch (e) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
Object.defineProperty(Buffer3.prototype, "parent", {
|
|
244
|
+
enumerable: true,
|
|
245
|
+
get: function() {
|
|
246
|
+
if (!Buffer3.isBuffer(this)) return void 0;
|
|
247
|
+
return this.buffer;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
Object.defineProperty(Buffer3.prototype, "offset", {
|
|
251
|
+
enumerable: true,
|
|
252
|
+
get: function() {
|
|
253
|
+
if (!Buffer3.isBuffer(this)) return void 0;
|
|
254
|
+
return this.byteOffset;
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
function createBuffer(length) {
|
|
258
|
+
if (length > K_MAX_LENGTH) {
|
|
259
|
+
throw new RangeError('The value "' + length + '" is invalid for option "size"');
|
|
260
|
+
}
|
|
261
|
+
const buf = new Uint8Array(length);
|
|
262
|
+
Object.setPrototypeOf(buf, Buffer3.prototype);
|
|
263
|
+
return buf;
|
|
264
|
+
}
|
|
265
|
+
function Buffer3(arg, encodingOrOffset, length) {
|
|
266
|
+
if (typeof arg === "number") {
|
|
267
|
+
if (typeof encodingOrOffset === "string") {
|
|
268
|
+
throw new TypeError(
|
|
269
|
+
'The "string" argument must be of type string. Received type number'
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
return allocUnsafe(arg);
|
|
273
|
+
}
|
|
274
|
+
return from(arg, encodingOrOffset, length);
|
|
275
|
+
}
|
|
276
|
+
Buffer3.poolSize = 8192;
|
|
277
|
+
function from(value, encodingOrOffset, length) {
|
|
278
|
+
if (typeof value === "string") {
|
|
279
|
+
return fromString(value, encodingOrOffset);
|
|
280
|
+
}
|
|
281
|
+
if (ArrayBuffer.isView(value)) {
|
|
282
|
+
return fromArrayView(value);
|
|
283
|
+
}
|
|
284
|
+
if (value == null) {
|
|
285
|
+
throw new TypeError(
|
|
286
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
|
|
290
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
291
|
+
}
|
|
292
|
+
if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
|
|
293
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
294
|
+
}
|
|
295
|
+
if (typeof value === "number") {
|
|
296
|
+
throw new TypeError(
|
|
297
|
+
'The "value" argument must not be of type number. Received type number'
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
301
|
+
if (valueOf != null && valueOf !== value) {
|
|
302
|
+
return Buffer3.from(valueOf, encodingOrOffset, length);
|
|
303
|
+
}
|
|
304
|
+
const b = fromObject(value);
|
|
305
|
+
if (b) return b;
|
|
306
|
+
if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") {
|
|
307
|
+
return Buffer3.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
|
|
308
|
+
}
|
|
309
|
+
throw new TypeError(
|
|
310
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
Buffer3.from = function(value, encodingOrOffset, length) {
|
|
314
|
+
return from(value, encodingOrOffset, length);
|
|
315
|
+
};
|
|
316
|
+
Object.setPrototypeOf(Buffer3.prototype, Uint8Array.prototype);
|
|
317
|
+
Object.setPrototypeOf(Buffer3, Uint8Array);
|
|
318
|
+
function assertSize(size) {
|
|
319
|
+
if (typeof size !== "number") {
|
|
320
|
+
throw new TypeError('"size" argument must be of type number');
|
|
321
|
+
} else if (size < 0) {
|
|
322
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function alloc(size, fill, encoding) {
|
|
326
|
+
assertSize(size);
|
|
327
|
+
if (size <= 0) {
|
|
328
|
+
return createBuffer(size);
|
|
329
|
+
}
|
|
330
|
+
if (fill !== void 0) {
|
|
331
|
+
return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
|
|
332
|
+
}
|
|
333
|
+
return createBuffer(size);
|
|
334
|
+
}
|
|
335
|
+
Buffer3.alloc = function(size, fill, encoding) {
|
|
336
|
+
return alloc(size, fill, encoding);
|
|
337
|
+
};
|
|
338
|
+
function allocUnsafe(size) {
|
|
339
|
+
assertSize(size);
|
|
340
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0);
|
|
341
|
+
}
|
|
342
|
+
Buffer3.allocUnsafe = function(size) {
|
|
343
|
+
return allocUnsafe(size);
|
|
344
|
+
};
|
|
345
|
+
Buffer3.allocUnsafeSlow = function(size) {
|
|
346
|
+
return allocUnsafe(size);
|
|
347
|
+
};
|
|
348
|
+
function fromString(string, encoding) {
|
|
349
|
+
if (typeof encoding !== "string" || encoding === "") {
|
|
350
|
+
encoding = "utf8";
|
|
351
|
+
}
|
|
352
|
+
if (!Buffer3.isEncoding(encoding)) {
|
|
353
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
354
|
+
}
|
|
355
|
+
const length = byteLength(string, encoding) | 0;
|
|
356
|
+
let buf = createBuffer(length);
|
|
357
|
+
const actual = buf.write(string, encoding);
|
|
358
|
+
if (actual !== length) {
|
|
359
|
+
buf = buf.slice(0, actual);
|
|
360
|
+
}
|
|
361
|
+
return buf;
|
|
362
|
+
}
|
|
363
|
+
function fromArrayLike(array) {
|
|
364
|
+
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
365
|
+
const buf = createBuffer(length);
|
|
366
|
+
for (let i = 0; i < length; i += 1) {
|
|
367
|
+
buf[i] = array[i] & 255;
|
|
368
|
+
}
|
|
369
|
+
return buf;
|
|
370
|
+
}
|
|
371
|
+
function fromArrayView(arrayView) {
|
|
372
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
373
|
+
const copy = new Uint8Array(arrayView);
|
|
374
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
|
|
375
|
+
}
|
|
376
|
+
return fromArrayLike(arrayView);
|
|
377
|
+
}
|
|
378
|
+
function fromArrayBuffer(array, byteOffset, length) {
|
|
379
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
380
|
+
throw new RangeError('"offset" is outside of buffer bounds');
|
|
381
|
+
}
|
|
382
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
383
|
+
throw new RangeError('"length" is outside of buffer bounds');
|
|
384
|
+
}
|
|
385
|
+
let buf;
|
|
386
|
+
if (byteOffset === void 0 && length === void 0) {
|
|
387
|
+
buf = new Uint8Array(array);
|
|
388
|
+
} else if (length === void 0) {
|
|
389
|
+
buf = new Uint8Array(array, byteOffset);
|
|
390
|
+
} else {
|
|
391
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
392
|
+
}
|
|
393
|
+
Object.setPrototypeOf(buf, Buffer3.prototype);
|
|
394
|
+
return buf;
|
|
395
|
+
}
|
|
396
|
+
function fromObject(obj) {
|
|
397
|
+
if (Buffer3.isBuffer(obj)) {
|
|
398
|
+
const len = checked(obj.length) | 0;
|
|
399
|
+
const buf = createBuffer(len);
|
|
400
|
+
if (buf.length === 0) {
|
|
401
|
+
return buf;
|
|
402
|
+
}
|
|
403
|
+
obj.copy(buf, 0, 0, len);
|
|
404
|
+
return buf;
|
|
405
|
+
}
|
|
406
|
+
if (obj.length !== void 0) {
|
|
407
|
+
if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
|
|
408
|
+
return createBuffer(0);
|
|
409
|
+
}
|
|
410
|
+
return fromArrayLike(obj);
|
|
411
|
+
}
|
|
412
|
+
if (obj.type === "Buffer" && Array.isArray(obj.data)) {
|
|
413
|
+
return fromArrayLike(obj.data);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function checked(length) {
|
|
417
|
+
if (length >= K_MAX_LENGTH) {
|
|
418
|
+
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes");
|
|
419
|
+
}
|
|
420
|
+
return length | 0;
|
|
421
|
+
}
|
|
422
|
+
function SlowBuffer(length) {
|
|
423
|
+
if (+length != length) {
|
|
424
|
+
length = 0;
|
|
425
|
+
}
|
|
426
|
+
return Buffer3.alloc(+length);
|
|
427
|
+
}
|
|
428
|
+
Buffer3.isBuffer = function isBuffer(b) {
|
|
429
|
+
return b != null && b._isBuffer === true && b !== Buffer3.prototype;
|
|
430
|
+
};
|
|
431
|
+
Buffer3.compare = function compare(a, b) {
|
|
432
|
+
if (isInstance(a, Uint8Array)) a = Buffer3.from(a, a.offset, a.byteLength);
|
|
433
|
+
if (isInstance(b, Uint8Array)) b = Buffer3.from(b, b.offset, b.byteLength);
|
|
434
|
+
if (!Buffer3.isBuffer(a) || !Buffer3.isBuffer(b)) {
|
|
435
|
+
throw new TypeError(
|
|
436
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
if (a === b) return 0;
|
|
440
|
+
let x = a.length;
|
|
441
|
+
let y = b.length;
|
|
442
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
443
|
+
if (a[i] !== b[i]) {
|
|
444
|
+
x = a[i];
|
|
445
|
+
y = b[i];
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if (x < y) return -1;
|
|
450
|
+
if (y < x) return 1;
|
|
451
|
+
return 0;
|
|
452
|
+
};
|
|
453
|
+
Buffer3.isEncoding = function isEncoding(encoding) {
|
|
454
|
+
switch (String(encoding).toLowerCase()) {
|
|
455
|
+
case "hex":
|
|
456
|
+
case "utf8":
|
|
457
|
+
case "utf-8":
|
|
458
|
+
case "ascii":
|
|
459
|
+
case "latin1":
|
|
460
|
+
case "binary":
|
|
461
|
+
case "base64":
|
|
462
|
+
case "ucs2":
|
|
463
|
+
case "ucs-2":
|
|
464
|
+
case "utf16le":
|
|
465
|
+
case "utf-16le":
|
|
466
|
+
return true;
|
|
467
|
+
default:
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
Buffer3.concat = function concat(list, length) {
|
|
472
|
+
if (!Array.isArray(list)) {
|
|
473
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
474
|
+
}
|
|
475
|
+
if (list.length === 0) {
|
|
476
|
+
return Buffer3.alloc(0);
|
|
477
|
+
}
|
|
478
|
+
let i;
|
|
479
|
+
if (length === void 0) {
|
|
480
|
+
length = 0;
|
|
481
|
+
for (i = 0; i < list.length; ++i) {
|
|
482
|
+
length += list[i].length;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
const buffer = Buffer3.allocUnsafe(length);
|
|
486
|
+
let pos = 0;
|
|
487
|
+
for (i = 0; i < list.length; ++i) {
|
|
488
|
+
let buf = list[i];
|
|
489
|
+
if (isInstance(buf, Uint8Array)) {
|
|
490
|
+
if (pos + buf.length > buffer.length) {
|
|
491
|
+
if (!Buffer3.isBuffer(buf)) buf = Buffer3.from(buf);
|
|
492
|
+
buf.copy(buffer, pos);
|
|
493
|
+
} else {
|
|
494
|
+
Uint8Array.prototype.set.call(
|
|
495
|
+
buffer,
|
|
496
|
+
buf,
|
|
497
|
+
pos
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
} else if (!Buffer3.isBuffer(buf)) {
|
|
501
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
502
|
+
} else {
|
|
503
|
+
buf.copy(buffer, pos);
|
|
504
|
+
}
|
|
505
|
+
pos += buf.length;
|
|
506
|
+
}
|
|
507
|
+
return buffer;
|
|
508
|
+
};
|
|
509
|
+
function byteLength(string, encoding) {
|
|
510
|
+
if (Buffer3.isBuffer(string)) {
|
|
511
|
+
return string.length;
|
|
512
|
+
}
|
|
513
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
514
|
+
return string.byteLength;
|
|
515
|
+
}
|
|
516
|
+
if (typeof string !== "string") {
|
|
517
|
+
throw new TypeError(
|
|
518
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
const len = string.length;
|
|
522
|
+
const mustMatch = arguments.length > 2 && arguments[2] === true;
|
|
523
|
+
if (!mustMatch && len === 0) return 0;
|
|
524
|
+
let loweredCase = false;
|
|
525
|
+
for (; ; ) {
|
|
526
|
+
switch (encoding) {
|
|
527
|
+
case "ascii":
|
|
528
|
+
case "latin1":
|
|
529
|
+
case "binary":
|
|
530
|
+
return len;
|
|
531
|
+
case "utf8":
|
|
532
|
+
case "utf-8":
|
|
533
|
+
return utf8ToBytes(string).length;
|
|
534
|
+
case "ucs2":
|
|
535
|
+
case "ucs-2":
|
|
536
|
+
case "utf16le":
|
|
537
|
+
case "utf-16le":
|
|
538
|
+
return len * 2;
|
|
539
|
+
case "hex":
|
|
540
|
+
return len >>> 1;
|
|
541
|
+
case "base64":
|
|
542
|
+
return base64ToBytes(string).length;
|
|
543
|
+
default:
|
|
544
|
+
if (loweredCase) {
|
|
545
|
+
return mustMatch ? -1 : utf8ToBytes(string).length;
|
|
546
|
+
}
|
|
547
|
+
encoding = ("" + encoding).toLowerCase();
|
|
548
|
+
loweredCase = true;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
Buffer3.byteLength = byteLength;
|
|
553
|
+
function slowToString(encoding, start, end) {
|
|
554
|
+
let loweredCase = false;
|
|
555
|
+
if (start === void 0 || start < 0) {
|
|
556
|
+
start = 0;
|
|
557
|
+
}
|
|
558
|
+
if (start > this.length) {
|
|
559
|
+
return "";
|
|
560
|
+
}
|
|
561
|
+
if (end === void 0 || end > this.length) {
|
|
562
|
+
end = this.length;
|
|
563
|
+
}
|
|
564
|
+
if (end <= 0) {
|
|
565
|
+
return "";
|
|
566
|
+
}
|
|
567
|
+
end >>>= 0;
|
|
568
|
+
start >>>= 0;
|
|
569
|
+
if (end <= start) {
|
|
570
|
+
return "";
|
|
571
|
+
}
|
|
572
|
+
if (!encoding) encoding = "utf8";
|
|
573
|
+
while (true) {
|
|
574
|
+
switch (encoding) {
|
|
575
|
+
case "hex":
|
|
576
|
+
return hexSlice(this, start, end);
|
|
577
|
+
case "utf8":
|
|
578
|
+
case "utf-8":
|
|
579
|
+
return utf8Slice(this, start, end);
|
|
580
|
+
case "ascii":
|
|
581
|
+
return asciiSlice(this, start, end);
|
|
582
|
+
case "latin1":
|
|
583
|
+
case "binary":
|
|
584
|
+
return latin1Slice(this, start, end);
|
|
585
|
+
case "base64":
|
|
586
|
+
return base64Slice(this, start, end);
|
|
587
|
+
case "ucs2":
|
|
588
|
+
case "ucs-2":
|
|
589
|
+
case "utf16le":
|
|
590
|
+
case "utf-16le":
|
|
591
|
+
return utf16leSlice(this, start, end);
|
|
592
|
+
default:
|
|
593
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
594
|
+
encoding = (encoding + "").toLowerCase();
|
|
595
|
+
loweredCase = true;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
Buffer3.prototype._isBuffer = true;
|
|
600
|
+
function swap(b, n, m) {
|
|
601
|
+
const i = b[n];
|
|
602
|
+
b[n] = b[m];
|
|
603
|
+
b[m] = i;
|
|
604
|
+
}
|
|
605
|
+
Buffer3.prototype.swap16 = function swap16() {
|
|
606
|
+
const len = this.length;
|
|
607
|
+
if (len % 2 !== 0) {
|
|
608
|
+
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
609
|
+
}
|
|
610
|
+
for (let i = 0; i < len; i += 2) {
|
|
611
|
+
swap(this, i, i + 1);
|
|
612
|
+
}
|
|
613
|
+
return this;
|
|
614
|
+
};
|
|
615
|
+
Buffer3.prototype.swap32 = function swap32() {
|
|
616
|
+
const len = this.length;
|
|
617
|
+
if (len % 4 !== 0) {
|
|
618
|
+
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
619
|
+
}
|
|
620
|
+
for (let i = 0; i < len; i += 4) {
|
|
621
|
+
swap(this, i, i + 3);
|
|
622
|
+
swap(this, i + 1, i + 2);
|
|
623
|
+
}
|
|
624
|
+
return this;
|
|
625
|
+
};
|
|
626
|
+
Buffer3.prototype.swap64 = function swap64() {
|
|
627
|
+
const len = this.length;
|
|
628
|
+
if (len % 8 !== 0) {
|
|
629
|
+
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
630
|
+
}
|
|
631
|
+
for (let i = 0; i < len; i += 8) {
|
|
632
|
+
swap(this, i, i + 7);
|
|
633
|
+
swap(this, i + 1, i + 6);
|
|
634
|
+
swap(this, i + 2, i + 5);
|
|
635
|
+
swap(this, i + 3, i + 4);
|
|
636
|
+
}
|
|
637
|
+
return this;
|
|
638
|
+
};
|
|
639
|
+
Buffer3.prototype.toString = function toString() {
|
|
640
|
+
const length = this.length;
|
|
641
|
+
if (length === 0) return "";
|
|
642
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length);
|
|
643
|
+
return slowToString.apply(this, arguments);
|
|
644
|
+
};
|
|
645
|
+
Buffer3.prototype.toLocaleString = Buffer3.prototype.toString;
|
|
646
|
+
Buffer3.prototype.equals = function equals(b) {
|
|
647
|
+
if (!Buffer3.isBuffer(b)) throw new TypeError("Argument must be a Buffer");
|
|
648
|
+
if (this === b) return true;
|
|
649
|
+
return Buffer3.compare(this, b) === 0;
|
|
650
|
+
};
|
|
651
|
+
Buffer3.prototype.inspect = function inspect() {
|
|
652
|
+
let str = "";
|
|
653
|
+
const max = exports.INSPECT_MAX_BYTES;
|
|
654
|
+
str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
|
|
655
|
+
if (this.length > max) str += " ... ";
|
|
656
|
+
return "<Buffer " + str + ">";
|
|
657
|
+
};
|
|
658
|
+
if (customInspectSymbol) {
|
|
659
|
+
Buffer3.prototype[customInspectSymbol] = Buffer3.prototype.inspect;
|
|
660
|
+
}
|
|
661
|
+
Buffer3.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
|
|
662
|
+
if (isInstance(target, Uint8Array)) {
|
|
663
|
+
target = Buffer3.from(target, target.offset, target.byteLength);
|
|
664
|
+
}
|
|
665
|
+
if (!Buffer3.isBuffer(target)) {
|
|
666
|
+
throw new TypeError(
|
|
667
|
+
'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
if (start === void 0) {
|
|
671
|
+
start = 0;
|
|
672
|
+
}
|
|
673
|
+
if (end === void 0) {
|
|
674
|
+
end = target ? target.length : 0;
|
|
675
|
+
}
|
|
676
|
+
if (thisStart === void 0) {
|
|
677
|
+
thisStart = 0;
|
|
678
|
+
}
|
|
679
|
+
if (thisEnd === void 0) {
|
|
680
|
+
thisEnd = this.length;
|
|
681
|
+
}
|
|
682
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
683
|
+
throw new RangeError("out of range index");
|
|
684
|
+
}
|
|
685
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
686
|
+
return 0;
|
|
687
|
+
}
|
|
688
|
+
if (thisStart >= thisEnd) {
|
|
689
|
+
return -1;
|
|
690
|
+
}
|
|
691
|
+
if (start >= end) {
|
|
692
|
+
return 1;
|
|
693
|
+
}
|
|
694
|
+
start >>>= 0;
|
|
695
|
+
end >>>= 0;
|
|
696
|
+
thisStart >>>= 0;
|
|
697
|
+
thisEnd >>>= 0;
|
|
698
|
+
if (this === target) return 0;
|
|
699
|
+
let x = thisEnd - thisStart;
|
|
700
|
+
let y = end - start;
|
|
701
|
+
const len = Math.min(x, y);
|
|
702
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
703
|
+
const targetCopy = target.slice(start, end);
|
|
704
|
+
for (let i = 0; i < len; ++i) {
|
|
705
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
706
|
+
x = thisCopy[i];
|
|
707
|
+
y = targetCopy[i];
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
if (x < y) return -1;
|
|
712
|
+
if (y < x) return 1;
|
|
713
|
+
return 0;
|
|
714
|
+
};
|
|
715
|
+
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
716
|
+
if (buffer.length === 0) return -1;
|
|
717
|
+
if (typeof byteOffset === "string") {
|
|
718
|
+
encoding = byteOffset;
|
|
719
|
+
byteOffset = 0;
|
|
720
|
+
} else if (byteOffset > 2147483647) {
|
|
721
|
+
byteOffset = 2147483647;
|
|
722
|
+
} else if (byteOffset < -2147483648) {
|
|
723
|
+
byteOffset = -2147483648;
|
|
724
|
+
}
|
|
725
|
+
byteOffset = +byteOffset;
|
|
726
|
+
if (numberIsNaN(byteOffset)) {
|
|
727
|
+
byteOffset = dir ? 0 : buffer.length - 1;
|
|
728
|
+
}
|
|
729
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
730
|
+
if (byteOffset >= buffer.length) {
|
|
731
|
+
if (dir) return -1;
|
|
732
|
+
else byteOffset = buffer.length - 1;
|
|
733
|
+
} else if (byteOffset < 0) {
|
|
734
|
+
if (dir) byteOffset = 0;
|
|
735
|
+
else return -1;
|
|
736
|
+
}
|
|
737
|
+
if (typeof val === "string") {
|
|
738
|
+
val = Buffer3.from(val, encoding);
|
|
739
|
+
}
|
|
740
|
+
if (Buffer3.isBuffer(val)) {
|
|
741
|
+
if (val.length === 0) {
|
|
742
|
+
return -1;
|
|
743
|
+
}
|
|
744
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
745
|
+
} else if (typeof val === "number") {
|
|
746
|
+
val = val & 255;
|
|
747
|
+
if (typeof Uint8Array.prototype.indexOf === "function") {
|
|
748
|
+
if (dir) {
|
|
749
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
750
|
+
} else {
|
|
751
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
755
|
+
}
|
|
756
|
+
throw new TypeError("val must be string, number or Buffer");
|
|
757
|
+
}
|
|
758
|
+
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
759
|
+
let indexSize = 1;
|
|
760
|
+
let arrLength = arr.length;
|
|
761
|
+
let valLength = val.length;
|
|
762
|
+
if (encoding !== void 0) {
|
|
763
|
+
encoding = String(encoding).toLowerCase();
|
|
764
|
+
if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
765
|
+
if (arr.length < 2 || val.length < 2) {
|
|
766
|
+
return -1;
|
|
767
|
+
}
|
|
768
|
+
indexSize = 2;
|
|
769
|
+
arrLength /= 2;
|
|
770
|
+
valLength /= 2;
|
|
771
|
+
byteOffset /= 2;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
function read(buf, i2) {
|
|
775
|
+
if (indexSize === 1) {
|
|
776
|
+
return buf[i2];
|
|
777
|
+
} else {
|
|
778
|
+
return buf.readUInt16BE(i2 * indexSize);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
let i;
|
|
782
|
+
if (dir) {
|
|
783
|
+
let foundIndex = -1;
|
|
784
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
785
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
786
|
+
if (foundIndex === -1) foundIndex = i;
|
|
787
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
|
|
788
|
+
} else {
|
|
789
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
790
|
+
foundIndex = -1;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
} else {
|
|
794
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
795
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
796
|
+
let found = true;
|
|
797
|
+
for (let j = 0; j < valLength; j++) {
|
|
798
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
799
|
+
found = false;
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
if (found) return i;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return -1;
|
|
807
|
+
}
|
|
808
|
+
Buffer3.prototype.includes = function includes(val, byteOffset, encoding) {
|
|
809
|
+
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
810
|
+
};
|
|
811
|
+
Buffer3.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
|
|
812
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
813
|
+
};
|
|
814
|
+
Buffer3.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
|
|
815
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
816
|
+
};
|
|
817
|
+
function hexWrite(buf, string, offset, length) {
|
|
818
|
+
offset = Number(offset) || 0;
|
|
819
|
+
const remaining = buf.length - offset;
|
|
820
|
+
if (!length) {
|
|
821
|
+
length = remaining;
|
|
822
|
+
} else {
|
|
823
|
+
length = Number(length);
|
|
824
|
+
if (length > remaining) {
|
|
825
|
+
length = remaining;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
const strLen = string.length;
|
|
829
|
+
if (length > strLen / 2) {
|
|
830
|
+
length = strLen / 2;
|
|
831
|
+
}
|
|
832
|
+
let i;
|
|
833
|
+
for (i = 0; i < length; ++i) {
|
|
834
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
835
|
+
if (numberIsNaN(parsed)) return i;
|
|
836
|
+
buf[offset + i] = parsed;
|
|
837
|
+
}
|
|
838
|
+
return i;
|
|
839
|
+
}
|
|
840
|
+
function utf8Write(buf, string, offset, length) {
|
|
841
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
842
|
+
}
|
|
843
|
+
function asciiWrite(buf, string, offset, length) {
|
|
844
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
845
|
+
}
|
|
846
|
+
function base64Write(buf, string, offset, length) {
|
|
847
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
848
|
+
}
|
|
849
|
+
function ucs2Write(buf, string, offset, length) {
|
|
850
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
851
|
+
}
|
|
852
|
+
Buffer3.prototype.write = function write(string, offset, length, encoding) {
|
|
853
|
+
if (offset === void 0) {
|
|
854
|
+
encoding = "utf8";
|
|
855
|
+
length = this.length;
|
|
856
|
+
offset = 0;
|
|
857
|
+
} else if (length === void 0 && typeof offset === "string") {
|
|
858
|
+
encoding = offset;
|
|
859
|
+
length = this.length;
|
|
860
|
+
offset = 0;
|
|
861
|
+
} else if (isFinite(offset)) {
|
|
862
|
+
offset = offset >>> 0;
|
|
863
|
+
if (isFinite(length)) {
|
|
864
|
+
length = length >>> 0;
|
|
865
|
+
if (encoding === void 0) encoding = "utf8";
|
|
866
|
+
} else {
|
|
867
|
+
encoding = length;
|
|
868
|
+
length = void 0;
|
|
869
|
+
}
|
|
870
|
+
} else {
|
|
871
|
+
throw new Error(
|
|
872
|
+
"Buffer.write(string, encoding, offset[, length]) is no longer supported"
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
const remaining = this.length - offset;
|
|
876
|
+
if (length === void 0 || length > remaining) length = remaining;
|
|
877
|
+
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
|
|
878
|
+
throw new RangeError("Attempt to write outside buffer bounds");
|
|
879
|
+
}
|
|
880
|
+
if (!encoding) encoding = "utf8";
|
|
881
|
+
let loweredCase = false;
|
|
882
|
+
for (; ; ) {
|
|
883
|
+
switch (encoding) {
|
|
884
|
+
case "hex":
|
|
885
|
+
return hexWrite(this, string, offset, length);
|
|
886
|
+
case "utf8":
|
|
887
|
+
case "utf-8":
|
|
888
|
+
return utf8Write(this, string, offset, length);
|
|
889
|
+
case "ascii":
|
|
890
|
+
case "latin1":
|
|
891
|
+
case "binary":
|
|
892
|
+
return asciiWrite(this, string, offset, length);
|
|
893
|
+
case "base64":
|
|
894
|
+
return base64Write(this, string, offset, length);
|
|
895
|
+
case "ucs2":
|
|
896
|
+
case "ucs-2":
|
|
897
|
+
case "utf16le":
|
|
898
|
+
case "utf-16le":
|
|
899
|
+
return ucs2Write(this, string, offset, length);
|
|
900
|
+
default:
|
|
901
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
902
|
+
encoding = ("" + encoding).toLowerCase();
|
|
903
|
+
loweredCase = true;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
Buffer3.prototype.toJSON = function toJSON() {
|
|
908
|
+
return {
|
|
909
|
+
type: "Buffer",
|
|
910
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
911
|
+
};
|
|
912
|
+
};
|
|
913
|
+
function base64Slice(buf, start, end) {
|
|
914
|
+
if (start === 0 && end === buf.length) {
|
|
915
|
+
return base64.fromByteArray(buf);
|
|
916
|
+
} else {
|
|
917
|
+
return base64.fromByteArray(buf.slice(start, end));
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
function utf8Slice(buf, start, end) {
|
|
921
|
+
end = Math.min(buf.length, end);
|
|
922
|
+
const res = [];
|
|
923
|
+
let i = start;
|
|
924
|
+
while (i < end) {
|
|
925
|
+
const firstByte = buf[i];
|
|
926
|
+
let codePoint = null;
|
|
927
|
+
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
928
|
+
if (i + bytesPerSequence <= end) {
|
|
929
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
930
|
+
switch (bytesPerSequence) {
|
|
931
|
+
case 1:
|
|
932
|
+
if (firstByte < 128) {
|
|
933
|
+
codePoint = firstByte;
|
|
934
|
+
}
|
|
935
|
+
break;
|
|
936
|
+
case 2:
|
|
937
|
+
secondByte = buf[i + 1];
|
|
938
|
+
if ((secondByte & 192) === 128) {
|
|
939
|
+
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
940
|
+
if (tempCodePoint > 127) {
|
|
941
|
+
codePoint = tempCodePoint;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
break;
|
|
945
|
+
case 3:
|
|
946
|
+
secondByte = buf[i + 1];
|
|
947
|
+
thirdByte = buf[i + 2];
|
|
948
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
949
|
+
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
950
|
+
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
951
|
+
codePoint = tempCodePoint;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
break;
|
|
955
|
+
case 4:
|
|
956
|
+
secondByte = buf[i + 1];
|
|
957
|
+
thirdByte = buf[i + 2];
|
|
958
|
+
fourthByte = buf[i + 3];
|
|
959
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
960
|
+
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
961
|
+
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
962
|
+
codePoint = tempCodePoint;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
if (codePoint === null) {
|
|
968
|
+
codePoint = 65533;
|
|
969
|
+
bytesPerSequence = 1;
|
|
970
|
+
} else if (codePoint > 65535) {
|
|
971
|
+
codePoint -= 65536;
|
|
972
|
+
res.push(codePoint >>> 10 & 1023 | 55296);
|
|
973
|
+
codePoint = 56320 | codePoint & 1023;
|
|
974
|
+
}
|
|
975
|
+
res.push(codePoint);
|
|
976
|
+
i += bytesPerSequence;
|
|
977
|
+
}
|
|
978
|
+
return decodeCodePointsArray(res);
|
|
979
|
+
}
|
|
980
|
+
var MAX_ARGUMENTS_LENGTH = 4096;
|
|
981
|
+
function decodeCodePointsArray(codePoints) {
|
|
982
|
+
const len = codePoints.length;
|
|
983
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
984
|
+
return String.fromCharCode.apply(String, codePoints);
|
|
985
|
+
}
|
|
986
|
+
let res = "";
|
|
987
|
+
let i = 0;
|
|
988
|
+
while (i < len) {
|
|
989
|
+
res += String.fromCharCode.apply(
|
|
990
|
+
String,
|
|
991
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
992
|
+
);
|
|
993
|
+
}
|
|
994
|
+
return res;
|
|
995
|
+
}
|
|
996
|
+
function asciiSlice(buf, start, end) {
|
|
997
|
+
let ret = "";
|
|
998
|
+
end = Math.min(buf.length, end);
|
|
999
|
+
for (let i = start; i < end; ++i) {
|
|
1000
|
+
ret += String.fromCharCode(buf[i] & 127);
|
|
1001
|
+
}
|
|
1002
|
+
return ret;
|
|
1003
|
+
}
|
|
1004
|
+
function latin1Slice(buf, start, end) {
|
|
1005
|
+
let ret = "";
|
|
1006
|
+
end = Math.min(buf.length, end);
|
|
1007
|
+
for (let i = start; i < end; ++i) {
|
|
1008
|
+
ret += String.fromCharCode(buf[i]);
|
|
1009
|
+
}
|
|
1010
|
+
return ret;
|
|
1011
|
+
}
|
|
1012
|
+
function hexSlice(buf, start, end) {
|
|
1013
|
+
const len = buf.length;
|
|
1014
|
+
if (!start || start < 0) start = 0;
|
|
1015
|
+
if (!end || end < 0 || end > len) end = len;
|
|
1016
|
+
let out = "";
|
|
1017
|
+
for (let i = start; i < end; ++i) {
|
|
1018
|
+
out += hexSliceLookupTable[buf[i]];
|
|
1019
|
+
}
|
|
1020
|
+
return out;
|
|
1021
|
+
}
|
|
1022
|
+
function utf16leSlice(buf, start, end) {
|
|
1023
|
+
const bytes = buf.slice(start, end);
|
|
1024
|
+
let res = "";
|
|
1025
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
1026
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1027
|
+
}
|
|
1028
|
+
return res;
|
|
1029
|
+
}
|
|
1030
|
+
Buffer3.prototype.slice = function slice(start, end) {
|
|
1031
|
+
const len = this.length;
|
|
1032
|
+
start = ~~start;
|
|
1033
|
+
end = end === void 0 ? len : ~~end;
|
|
1034
|
+
if (start < 0) {
|
|
1035
|
+
start += len;
|
|
1036
|
+
if (start < 0) start = 0;
|
|
1037
|
+
} else if (start > len) {
|
|
1038
|
+
start = len;
|
|
1039
|
+
}
|
|
1040
|
+
if (end < 0) {
|
|
1041
|
+
end += len;
|
|
1042
|
+
if (end < 0) end = 0;
|
|
1043
|
+
} else if (end > len) {
|
|
1044
|
+
end = len;
|
|
1045
|
+
}
|
|
1046
|
+
if (end < start) end = start;
|
|
1047
|
+
const newBuf = this.subarray(start, end);
|
|
1048
|
+
Object.setPrototypeOf(newBuf, Buffer3.prototype);
|
|
1049
|
+
return newBuf;
|
|
1050
|
+
};
|
|
1051
|
+
function checkOffset(offset, ext, length) {
|
|
1052
|
+
if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
|
|
1053
|
+
if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length");
|
|
1054
|
+
}
|
|
1055
|
+
Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
|
|
1056
|
+
offset = offset >>> 0;
|
|
1057
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1058
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1059
|
+
let val = this[offset];
|
|
1060
|
+
let mul = 1;
|
|
1061
|
+
let i = 0;
|
|
1062
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1063
|
+
val += this[offset + i] * mul;
|
|
1064
|
+
}
|
|
1065
|
+
return val;
|
|
1066
|
+
};
|
|
1067
|
+
Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
|
|
1068
|
+
offset = offset >>> 0;
|
|
1069
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1070
|
+
if (!noAssert) {
|
|
1071
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1072
|
+
}
|
|
1073
|
+
let val = this[offset + --byteLength2];
|
|
1074
|
+
let mul = 1;
|
|
1075
|
+
while (byteLength2 > 0 && (mul *= 256)) {
|
|
1076
|
+
val += this[offset + --byteLength2] * mul;
|
|
1077
|
+
}
|
|
1078
|
+
return val;
|
|
1079
|
+
};
|
|
1080
|
+
Buffer3.prototype.readUint8 = Buffer3.prototype.readUInt8 = function readUInt8(offset, noAssert) {
|
|
1081
|
+
offset = offset >>> 0;
|
|
1082
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1083
|
+
return this[offset];
|
|
1084
|
+
};
|
|
1085
|
+
Buffer3.prototype.readUint16LE = Buffer3.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
|
|
1086
|
+
offset = offset >>> 0;
|
|
1087
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1088
|
+
return this[offset] | this[offset + 1] << 8;
|
|
1089
|
+
};
|
|
1090
|
+
Buffer3.prototype.readUint16BE = Buffer3.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
|
|
1091
|
+
offset = offset >>> 0;
|
|
1092
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1093
|
+
return this[offset] << 8 | this[offset + 1];
|
|
1094
|
+
};
|
|
1095
|
+
Buffer3.prototype.readUint32LE = Buffer3.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
|
|
1096
|
+
offset = offset >>> 0;
|
|
1097
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1098
|
+
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
1099
|
+
};
|
|
1100
|
+
Buffer3.prototype.readUint32BE = Buffer3.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
|
|
1101
|
+
offset = offset >>> 0;
|
|
1102
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1103
|
+
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
1104
|
+
};
|
|
1105
|
+
Buffer3.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {
|
|
1106
|
+
offset = offset >>> 0;
|
|
1107
|
+
validateNumber(offset, "offset");
|
|
1108
|
+
const first = this[offset];
|
|
1109
|
+
const last = this[offset + 7];
|
|
1110
|
+
if (first === void 0 || last === void 0) {
|
|
1111
|
+
boundsError(offset, this.length - 8);
|
|
1112
|
+
}
|
|
1113
|
+
const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;
|
|
1114
|
+
const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;
|
|
1115
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32));
|
|
1116
|
+
});
|
|
1117
|
+
Buffer3.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {
|
|
1118
|
+
offset = offset >>> 0;
|
|
1119
|
+
validateNumber(offset, "offset");
|
|
1120
|
+
const first = this[offset];
|
|
1121
|
+
const last = this[offset + 7];
|
|
1122
|
+
if (first === void 0 || last === void 0) {
|
|
1123
|
+
boundsError(offset, this.length - 8);
|
|
1124
|
+
}
|
|
1125
|
+
const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1126
|
+
const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
|
|
1127
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
1128
|
+
});
|
|
1129
|
+
Buffer3.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
|
|
1130
|
+
offset = offset >>> 0;
|
|
1131
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1132
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1133
|
+
let val = this[offset];
|
|
1134
|
+
let mul = 1;
|
|
1135
|
+
let i = 0;
|
|
1136
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1137
|
+
val += this[offset + i] * mul;
|
|
1138
|
+
}
|
|
1139
|
+
mul *= 128;
|
|
1140
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1141
|
+
return val;
|
|
1142
|
+
};
|
|
1143
|
+
Buffer3.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
|
|
1144
|
+
offset = offset >>> 0;
|
|
1145
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1146
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1147
|
+
let i = byteLength2;
|
|
1148
|
+
let mul = 1;
|
|
1149
|
+
let val = this[offset + --i];
|
|
1150
|
+
while (i > 0 && (mul *= 256)) {
|
|
1151
|
+
val += this[offset + --i] * mul;
|
|
1152
|
+
}
|
|
1153
|
+
mul *= 128;
|
|
1154
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1155
|
+
return val;
|
|
1156
|
+
};
|
|
1157
|
+
Buffer3.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
1158
|
+
offset = offset >>> 0;
|
|
1159
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1160
|
+
if (!(this[offset] & 128)) return this[offset];
|
|
1161
|
+
return (255 - this[offset] + 1) * -1;
|
|
1162
|
+
};
|
|
1163
|
+
Buffer3.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
|
|
1164
|
+
offset = offset >>> 0;
|
|
1165
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1166
|
+
const val = this[offset] | this[offset + 1] << 8;
|
|
1167
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1168
|
+
};
|
|
1169
|
+
Buffer3.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
|
|
1170
|
+
offset = offset >>> 0;
|
|
1171
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1172
|
+
const val = this[offset + 1] | this[offset] << 8;
|
|
1173
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1174
|
+
};
|
|
1175
|
+
Buffer3.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
|
|
1176
|
+
offset = offset >>> 0;
|
|
1177
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1178
|
+
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
1179
|
+
};
|
|
1180
|
+
Buffer3.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
|
|
1181
|
+
offset = offset >>> 0;
|
|
1182
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1183
|
+
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
1184
|
+
};
|
|
1185
|
+
Buffer3.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {
|
|
1186
|
+
offset = offset >>> 0;
|
|
1187
|
+
validateNumber(offset, "offset");
|
|
1188
|
+
const first = this[offset];
|
|
1189
|
+
const last = this[offset + 7];
|
|
1190
|
+
if (first === void 0 || last === void 0) {
|
|
1191
|
+
boundsError(offset, this.length - 8);
|
|
1192
|
+
}
|
|
1193
|
+
const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24);
|
|
1194
|
+
return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24);
|
|
1195
|
+
});
|
|
1196
|
+
Buffer3.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) {
|
|
1197
|
+
offset = offset >>> 0;
|
|
1198
|
+
validateNumber(offset, "offset");
|
|
1199
|
+
const first = this[offset];
|
|
1200
|
+
const last = this[offset + 7];
|
|
1201
|
+
if (first === void 0 || last === void 0) {
|
|
1202
|
+
boundsError(offset, this.length - 8);
|
|
1203
|
+
}
|
|
1204
|
+
const val = (first << 24) + // Overflow
|
|
1205
|
+
this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1206
|
+
return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);
|
|
1207
|
+
});
|
|
1208
|
+
Buffer3.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
|
|
1209
|
+
offset = offset >>> 0;
|
|
1210
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1211
|
+
return ieee754.read(this, offset, true, 23, 4);
|
|
1212
|
+
};
|
|
1213
|
+
Buffer3.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
|
|
1214
|
+
offset = offset >>> 0;
|
|
1215
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1216
|
+
return ieee754.read(this, offset, false, 23, 4);
|
|
1217
|
+
};
|
|
1218
|
+
Buffer3.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
|
|
1219
|
+
offset = offset >>> 0;
|
|
1220
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1221
|
+
return ieee754.read(this, offset, true, 52, 8);
|
|
1222
|
+
};
|
|
1223
|
+
Buffer3.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|
1224
|
+
offset = offset >>> 0;
|
|
1225
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1226
|
+
return ieee754.read(this, offset, false, 52, 8);
|
|
1227
|
+
};
|
|
1228
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
|
1229
|
+
if (!Buffer3.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
1230
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
|
|
1231
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1232
|
+
}
|
|
1233
|
+
Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) {
|
|
1234
|
+
value = +value;
|
|
1235
|
+
offset = offset >>> 0;
|
|
1236
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1237
|
+
if (!noAssert) {
|
|
1238
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1239
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1240
|
+
}
|
|
1241
|
+
let mul = 1;
|
|
1242
|
+
let i = 0;
|
|
1243
|
+
this[offset] = value & 255;
|
|
1244
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1245
|
+
this[offset + i] = value / mul & 255;
|
|
1246
|
+
}
|
|
1247
|
+
return offset + byteLength2;
|
|
1248
|
+
};
|
|
1249
|
+
Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) {
|
|
1250
|
+
value = +value;
|
|
1251
|
+
offset = offset >>> 0;
|
|
1252
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1253
|
+
if (!noAssert) {
|
|
1254
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1255
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1256
|
+
}
|
|
1257
|
+
let i = byteLength2 - 1;
|
|
1258
|
+
let mul = 1;
|
|
1259
|
+
this[offset + i] = value & 255;
|
|
1260
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1261
|
+
this[offset + i] = value / mul & 255;
|
|
1262
|
+
}
|
|
1263
|
+
return offset + byteLength2;
|
|
1264
|
+
};
|
|
1265
|
+
Buffer3.prototype.writeUint8 = Buffer3.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
|
|
1266
|
+
value = +value;
|
|
1267
|
+
offset = offset >>> 0;
|
|
1268
|
+
if (!noAssert) checkInt(this, value, offset, 1, 255, 0);
|
|
1269
|
+
this[offset] = value & 255;
|
|
1270
|
+
return offset + 1;
|
|
1271
|
+
};
|
|
1272
|
+
Buffer3.prototype.writeUint16LE = Buffer3.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
|
|
1273
|
+
value = +value;
|
|
1274
|
+
offset = offset >>> 0;
|
|
1275
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1276
|
+
this[offset] = value & 255;
|
|
1277
|
+
this[offset + 1] = value >>> 8;
|
|
1278
|
+
return offset + 2;
|
|
1279
|
+
};
|
|
1280
|
+
Buffer3.prototype.writeUint16BE = Buffer3.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
|
|
1281
|
+
value = +value;
|
|
1282
|
+
offset = offset >>> 0;
|
|
1283
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1284
|
+
this[offset] = value >>> 8;
|
|
1285
|
+
this[offset + 1] = value & 255;
|
|
1286
|
+
return offset + 2;
|
|
1287
|
+
};
|
|
1288
|
+
Buffer3.prototype.writeUint32LE = Buffer3.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
|
|
1289
|
+
value = +value;
|
|
1290
|
+
offset = offset >>> 0;
|
|
1291
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1292
|
+
this[offset + 3] = value >>> 24;
|
|
1293
|
+
this[offset + 2] = value >>> 16;
|
|
1294
|
+
this[offset + 1] = value >>> 8;
|
|
1295
|
+
this[offset] = value & 255;
|
|
1296
|
+
return offset + 4;
|
|
1297
|
+
};
|
|
1298
|
+
Buffer3.prototype.writeUint32BE = Buffer3.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
|
|
1299
|
+
value = +value;
|
|
1300
|
+
offset = offset >>> 0;
|
|
1301
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1302
|
+
this[offset] = value >>> 24;
|
|
1303
|
+
this[offset + 1] = value >>> 16;
|
|
1304
|
+
this[offset + 2] = value >>> 8;
|
|
1305
|
+
this[offset + 3] = value & 255;
|
|
1306
|
+
return offset + 4;
|
|
1307
|
+
};
|
|
1308
|
+
function wrtBigUInt64LE(buf, value, offset, min, max) {
|
|
1309
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1310
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1311
|
+
buf[offset++] = lo;
|
|
1312
|
+
lo = lo >> 8;
|
|
1313
|
+
buf[offset++] = lo;
|
|
1314
|
+
lo = lo >> 8;
|
|
1315
|
+
buf[offset++] = lo;
|
|
1316
|
+
lo = lo >> 8;
|
|
1317
|
+
buf[offset++] = lo;
|
|
1318
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1319
|
+
buf[offset++] = hi;
|
|
1320
|
+
hi = hi >> 8;
|
|
1321
|
+
buf[offset++] = hi;
|
|
1322
|
+
hi = hi >> 8;
|
|
1323
|
+
buf[offset++] = hi;
|
|
1324
|
+
hi = hi >> 8;
|
|
1325
|
+
buf[offset++] = hi;
|
|
1326
|
+
return offset;
|
|
1327
|
+
}
|
|
1328
|
+
function wrtBigUInt64BE(buf, value, offset, min, max) {
|
|
1329
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1330
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1331
|
+
buf[offset + 7] = lo;
|
|
1332
|
+
lo = lo >> 8;
|
|
1333
|
+
buf[offset + 6] = lo;
|
|
1334
|
+
lo = lo >> 8;
|
|
1335
|
+
buf[offset + 5] = lo;
|
|
1336
|
+
lo = lo >> 8;
|
|
1337
|
+
buf[offset + 4] = lo;
|
|
1338
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1339
|
+
buf[offset + 3] = hi;
|
|
1340
|
+
hi = hi >> 8;
|
|
1341
|
+
buf[offset + 2] = hi;
|
|
1342
|
+
hi = hi >> 8;
|
|
1343
|
+
buf[offset + 1] = hi;
|
|
1344
|
+
hi = hi >> 8;
|
|
1345
|
+
buf[offset] = hi;
|
|
1346
|
+
return offset + 8;
|
|
1347
|
+
}
|
|
1348
|
+
Buffer3.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {
|
|
1349
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1350
|
+
});
|
|
1351
|
+
Buffer3.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {
|
|
1352
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1353
|
+
});
|
|
1354
|
+
Buffer3.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) {
|
|
1355
|
+
value = +value;
|
|
1356
|
+
offset = offset >>> 0;
|
|
1357
|
+
if (!noAssert) {
|
|
1358
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1359
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1360
|
+
}
|
|
1361
|
+
let i = 0;
|
|
1362
|
+
let mul = 1;
|
|
1363
|
+
let sub = 0;
|
|
1364
|
+
this[offset] = value & 255;
|
|
1365
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1366
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1367
|
+
sub = 1;
|
|
1368
|
+
}
|
|
1369
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1370
|
+
}
|
|
1371
|
+
return offset + byteLength2;
|
|
1372
|
+
};
|
|
1373
|
+
Buffer3.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) {
|
|
1374
|
+
value = +value;
|
|
1375
|
+
offset = offset >>> 0;
|
|
1376
|
+
if (!noAssert) {
|
|
1377
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1378
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1379
|
+
}
|
|
1380
|
+
let i = byteLength2 - 1;
|
|
1381
|
+
let mul = 1;
|
|
1382
|
+
let sub = 0;
|
|
1383
|
+
this[offset + i] = value & 255;
|
|
1384
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1385
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1386
|
+
sub = 1;
|
|
1387
|
+
}
|
|
1388
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1389
|
+
}
|
|
1390
|
+
return offset + byteLength2;
|
|
1391
|
+
};
|
|
1392
|
+
Buffer3.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
|
|
1393
|
+
value = +value;
|
|
1394
|
+
offset = offset >>> 0;
|
|
1395
|
+
if (!noAssert) checkInt(this, value, offset, 1, 127, -128);
|
|
1396
|
+
if (value < 0) value = 255 + value + 1;
|
|
1397
|
+
this[offset] = value & 255;
|
|
1398
|
+
return offset + 1;
|
|
1399
|
+
};
|
|
1400
|
+
Buffer3.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
|
|
1401
|
+
value = +value;
|
|
1402
|
+
offset = offset >>> 0;
|
|
1403
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1404
|
+
this[offset] = value & 255;
|
|
1405
|
+
this[offset + 1] = value >>> 8;
|
|
1406
|
+
return offset + 2;
|
|
1407
|
+
};
|
|
1408
|
+
Buffer3.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
|
|
1409
|
+
value = +value;
|
|
1410
|
+
offset = offset >>> 0;
|
|
1411
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1412
|
+
this[offset] = value >>> 8;
|
|
1413
|
+
this[offset + 1] = value & 255;
|
|
1414
|
+
return offset + 2;
|
|
1415
|
+
};
|
|
1416
|
+
Buffer3.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
|
|
1417
|
+
value = +value;
|
|
1418
|
+
offset = offset >>> 0;
|
|
1419
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1420
|
+
this[offset] = value & 255;
|
|
1421
|
+
this[offset + 1] = value >>> 8;
|
|
1422
|
+
this[offset + 2] = value >>> 16;
|
|
1423
|
+
this[offset + 3] = value >>> 24;
|
|
1424
|
+
return offset + 4;
|
|
1425
|
+
};
|
|
1426
|
+
Buffer3.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
|
|
1427
|
+
value = +value;
|
|
1428
|
+
offset = offset >>> 0;
|
|
1429
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1430
|
+
if (value < 0) value = 4294967295 + value + 1;
|
|
1431
|
+
this[offset] = value >>> 24;
|
|
1432
|
+
this[offset + 1] = value >>> 16;
|
|
1433
|
+
this[offset + 2] = value >>> 8;
|
|
1434
|
+
this[offset + 3] = value & 255;
|
|
1435
|
+
return offset + 4;
|
|
1436
|
+
};
|
|
1437
|
+
Buffer3.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {
|
|
1438
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1439
|
+
});
|
|
1440
|
+
Buffer3.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {
|
|
1441
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1442
|
+
});
|
|
1443
|
+
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1444
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1445
|
+
if (offset < 0) throw new RangeError("Index out of range");
|
|
1446
|
+
}
|
|
1447
|
+
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1448
|
+
value = +value;
|
|
1449
|
+
offset = offset >>> 0;
|
|
1450
|
+
if (!noAssert) {
|
|
1451
|
+
checkIEEE754(buf, value, offset, 4, 34028234663852886e22, -34028234663852886e22);
|
|
1452
|
+
}
|
|
1453
|
+
ieee754.write(buf, value, offset, littleEndian, 23, 4);
|
|
1454
|
+
return offset + 4;
|
|
1455
|
+
}
|
|
1456
|
+
Buffer3.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
1457
|
+
return writeFloat(this, value, offset, true, noAssert);
|
|
1458
|
+
};
|
|
1459
|
+
Buffer3.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
1460
|
+
return writeFloat(this, value, offset, false, noAssert);
|
|
1461
|
+
};
|
|
1462
|
+
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1463
|
+
value = +value;
|
|
1464
|
+
offset = offset >>> 0;
|
|
1465
|
+
if (!noAssert) {
|
|
1466
|
+
checkIEEE754(buf, value, offset, 8, 17976931348623157e292, -17976931348623157e292);
|
|
1467
|
+
}
|
|
1468
|
+
ieee754.write(buf, value, offset, littleEndian, 52, 8);
|
|
1469
|
+
return offset + 8;
|
|
1470
|
+
}
|
|
1471
|
+
Buffer3.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
|
|
1472
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
1473
|
+
};
|
|
1474
|
+
Buffer3.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
|
|
1475
|
+
return writeDouble(this, value, offset, false, noAssert);
|
|
1476
|
+
};
|
|
1477
|
+
Buffer3.prototype.copy = function copy(target, targetStart, start, end) {
|
|
1478
|
+
if (!Buffer3.isBuffer(target)) throw new TypeError("argument should be a Buffer");
|
|
1479
|
+
if (!start) start = 0;
|
|
1480
|
+
if (!end && end !== 0) end = this.length;
|
|
1481
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
1482
|
+
if (!targetStart) targetStart = 0;
|
|
1483
|
+
if (end > 0 && end < start) end = start;
|
|
1484
|
+
if (end === start) return 0;
|
|
1485
|
+
if (target.length === 0 || this.length === 0) return 0;
|
|
1486
|
+
if (targetStart < 0) {
|
|
1487
|
+
throw new RangeError("targetStart out of bounds");
|
|
1488
|
+
}
|
|
1489
|
+
if (start < 0 || start >= this.length) throw new RangeError("Index out of range");
|
|
1490
|
+
if (end < 0) throw new RangeError("sourceEnd out of bounds");
|
|
1491
|
+
if (end > this.length) end = this.length;
|
|
1492
|
+
if (target.length - targetStart < end - start) {
|
|
1493
|
+
end = target.length - targetStart + start;
|
|
1494
|
+
}
|
|
1495
|
+
const len = end - start;
|
|
1496
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === "function") {
|
|
1497
|
+
this.copyWithin(targetStart, start, end);
|
|
1498
|
+
} else {
|
|
1499
|
+
Uint8Array.prototype.set.call(
|
|
1500
|
+
target,
|
|
1501
|
+
this.subarray(start, end),
|
|
1502
|
+
targetStart
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
return len;
|
|
1506
|
+
};
|
|
1507
|
+
Buffer3.prototype.fill = function fill(val, start, end, encoding) {
|
|
1508
|
+
if (typeof val === "string") {
|
|
1509
|
+
if (typeof start === "string") {
|
|
1510
|
+
encoding = start;
|
|
1511
|
+
start = 0;
|
|
1512
|
+
end = this.length;
|
|
1513
|
+
} else if (typeof end === "string") {
|
|
1514
|
+
encoding = end;
|
|
1515
|
+
end = this.length;
|
|
1516
|
+
}
|
|
1517
|
+
if (encoding !== void 0 && typeof encoding !== "string") {
|
|
1518
|
+
throw new TypeError("encoding must be a string");
|
|
1519
|
+
}
|
|
1520
|
+
if (typeof encoding === "string" && !Buffer3.isEncoding(encoding)) {
|
|
1521
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
1522
|
+
}
|
|
1523
|
+
if (val.length === 1) {
|
|
1524
|
+
const code = val.charCodeAt(0);
|
|
1525
|
+
if (encoding === "utf8" && code < 128 || encoding === "latin1") {
|
|
1526
|
+
val = code;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
} else if (typeof val === "number") {
|
|
1530
|
+
val = val & 255;
|
|
1531
|
+
} else if (typeof val === "boolean") {
|
|
1532
|
+
val = Number(val);
|
|
1533
|
+
}
|
|
1534
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
1535
|
+
throw new RangeError("Out of range index");
|
|
1536
|
+
}
|
|
1537
|
+
if (end <= start) {
|
|
1538
|
+
return this;
|
|
1539
|
+
}
|
|
1540
|
+
start = start >>> 0;
|
|
1541
|
+
end = end === void 0 ? this.length : end >>> 0;
|
|
1542
|
+
if (!val) val = 0;
|
|
1543
|
+
let i;
|
|
1544
|
+
if (typeof val === "number") {
|
|
1545
|
+
for (i = start; i < end; ++i) {
|
|
1546
|
+
this[i] = val;
|
|
1547
|
+
}
|
|
1548
|
+
} else {
|
|
1549
|
+
const bytes = Buffer3.isBuffer(val) ? val : Buffer3.from(val, encoding);
|
|
1550
|
+
const len = bytes.length;
|
|
1551
|
+
if (len === 0) {
|
|
1552
|
+
throw new TypeError('The value "' + val + '" is invalid for argument "value"');
|
|
1553
|
+
}
|
|
1554
|
+
for (i = 0; i < end - start; ++i) {
|
|
1555
|
+
this[i + start] = bytes[i % len];
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
return this;
|
|
1559
|
+
};
|
|
1560
|
+
var errors = {};
|
|
1561
|
+
function E(sym, getMessage, Base) {
|
|
1562
|
+
errors[sym] = class NodeError extends Base {
|
|
1563
|
+
constructor() {
|
|
1564
|
+
super();
|
|
1565
|
+
Object.defineProperty(this, "message", {
|
|
1566
|
+
value: getMessage.apply(this, arguments),
|
|
1567
|
+
writable: true,
|
|
1568
|
+
configurable: true
|
|
1569
|
+
});
|
|
1570
|
+
this.name = `${this.name} [${sym}]`;
|
|
1571
|
+
this.stack;
|
|
1572
|
+
delete this.name;
|
|
1573
|
+
}
|
|
1574
|
+
get code() {
|
|
1575
|
+
return sym;
|
|
1576
|
+
}
|
|
1577
|
+
set code(value) {
|
|
1578
|
+
Object.defineProperty(this, "code", {
|
|
1579
|
+
configurable: true,
|
|
1580
|
+
enumerable: true,
|
|
1581
|
+
value,
|
|
1582
|
+
writable: true
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
toString() {
|
|
1586
|
+
return `${this.name} [${sym}]: ${this.message}`;
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
E(
|
|
1591
|
+
"ERR_BUFFER_OUT_OF_BOUNDS",
|
|
1592
|
+
function(name) {
|
|
1593
|
+
if (name) {
|
|
1594
|
+
return `${name} is outside of buffer bounds`;
|
|
1595
|
+
}
|
|
1596
|
+
return "Attempt to access memory outside buffer bounds";
|
|
1597
|
+
},
|
|
1598
|
+
RangeError
|
|
1599
|
+
);
|
|
1600
|
+
E(
|
|
1601
|
+
"ERR_INVALID_ARG_TYPE",
|
|
1602
|
+
function(name, actual) {
|
|
1603
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
|
|
1604
|
+
},
|
|
1605
|
+
TypeError
|
|
1606
|
+
);
|
|
1607
|
+
E(
|
|
1608
|
+
"ERR_OUT_OF_RANGE",
|
|
1609
|
+
function(str, range, input) {
|
|
1610
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
1611
|
+
let received = input;
|
|
1612
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
1613
|
+
received = addNumericalSeparator(String(input));
|
|
1614
|
+
} else if (typeof input === "bigint") {
|
|
1615
|
+
received = String(input);
|
|
1616
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
1617
|
+
received = addNumericalSeparator(received);
|
|
1618
|
+
}
|
|
1619
|
+
received += "n";
|
|
1620
|
+
}
|
|
1621
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
1622
|
+
return msg;
|
|
1623
|
+
},
|
|
1624
|
+
RangeError
|
|
1625
|
+
);
|
|
1626
|
+
function addNumericalSeparator(val) {
|
|
1627
|
+
let res = "";
|
|
1628
|
+
let i = val.length;
|
|
1629
|
+
const start = val[0] === "-" ? 1 : 0;
|
|
1630
|
+
for (; i >= start + 4; i -= 3) {
|
|
1631
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
1632
|
+
}
|
|
1633
|
+
return `${val.slice(0, i)}${res}`;
|
|
1634
|
+
}
|
|
1635
|
+
function checkBounds(buf, offset, byteLength2) {
|
|
1636
|
+
validateNumber(offset, "offset");
|
|
1637
|
+
if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
|
|
1638
|
+
boundsError(offset, buf.length - (byteLength2 + 1));
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
function checkIntBI(value, min, max, buf, offset, byteLength2) {
|
|
1642
|
+
if (value > max || value < min) {
|
|
1643
|
+
const n = typeof min === "bigint" ? "n" : "";
|
|
1644
|
+
let range;
|
|
1645
|
+
if (byteLength2 > 3) {
|
|
1646
|
+
if (min === 0 || min === BigInt(0)) {
|
|
1647
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
|
|
1648
|
+
} else {
|
|
1649
|
+
range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
|
|
1650
|
+
}
|
|
1651
|
+
} else {
|
|
1652
|
+
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
1653
|
+
}
|
|
1654
|
+
throw new errors.ERR_OUT_OF_RANGE("value", range, value);
|
|
1655
|
+
}
|
|
1656
|
+
checkBounds(buf, offset, byteLength2);
|
|
1657
|
+
}
|
|
1658
|
+
function validateNumber(value, name) {
|
|
1659
|
+
if (typeof value !== "number") {
|
|
1660
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
function boundsError(value, length, type) {
|
|
1664
|
+
if (Math.floor(value) !== value) {
|
|
1665
|
+
validateNumber(value, type);
|
|
1666
|
+
throw new errors.ERR_OUT_OF_RANGE(type || "offset", "an integer", value);
|
|
1667
|
+
}
|
|
1668
|
+
if (length < 0) {
|
|
1669
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();
|
|
1670
|
+
}
|
|
1671
|
+
throw new errors.ERR_OUT_OF_RANGE(
|
|
1672
|
+
type || "offset",
|
|
1673
|
+
`>= ${type ? 1 : 0} and <= ${length}`,
|
|
1674
|
+
value
|
|
1675
|
+
);
|
|
1676
|
+
}
|
|
1677
|
+
var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1678
|
+
function base64clean(str) {
|
|
1679
|
+
str = str.split("=")[0];
|
|
1680
|
+
str = str.trim().replace(INVALID_BASE64_RE, "");
|
|
1681
|
+
if (str.length < 2) return "";
|
|
1682
|
+
while (str.length % 4 !== 0) {
|
|
1683
|
+
str = str + "=";
|
|
1684
|
+
}
|
|
1685
|
+
return str;
|
|
1686
|
+
}
|
|
1687
|
+
function utf8ToBytes(string, units) {
|
|
1688
|
+
units = units || Infinity;
|
|
1689
|
+
let codePoint;
|
|
1690
|
+
const length = string.length;
|
|
1691
|
+
let leadSurrogate = null;
|
|
1692
|
+
const bytes = [];
|
|
1693
|
+
for (let i = 0; i < length; ++i) {
|
|
1694
|
+
codePoint = string.charCodeAt(i);
|
|
1695
|
+
if (codePoint > 55295 && codePoint < 57344) {
|
|
1696
|
+
if (!leadSurrogate) {
|
|
1697
|
+
if (codePoint > 56319) {
|
|
1698
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1699
|
+
continue;
|
|
1700
|
+
} else if (i + 1 === length) {
|
|
1701
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1702
|
+
continue;
|
|
1703
|
+
}
|
|
1704
|
+
leadSurrogate = codePoint;
|
|
1705
|
+
continue;
|
|
1706
|
+
}
|
|
1707
|
+
if (codePoint < 56320) {
|
|
1708
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1709
|
+
leadSurrogate = codePoint;
|
|
1710
|
+
continue;
|
|
1711
|
+
}
|
|
1712
|
+
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
1713
|
+
} else if (leadSurrogate) {
|
|
1714
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1715
|
+
}
|
|
1716
|
+
leadSurrogate = null;
|
|
1717
|
+
if (codePoint < 128) {
|
|
1718
|
+
if ((units -= 1) < 0) break;
|
|
1719
|
+
bytes.push(codePoint);
|
|
1720
|
+
} else if (codePoint < 2048) {
|
|
1721
|
+
if ((units -= 2) < 0) break;
|
|
1722
|
+
bytes.push(
|
|
1723
|
+
codePoint >> 6 | 192,
|
|
1724
|
+
codePoint & 63 | 128
|
|
1725
|
+
);
|
|
1726
|
+
} else if (codePoint < 65536) {
|
|
1727
|
+
if ((units -= 3) < 0) break;
|
|
1728
|
+
bytes.push(
|
|
1729
|
+
codePoint >> 12 | 224,
|
|
1730
|
+
codePoint >> 6 & 63 | 128,
|
|
1731
|
+
codePoint & 63 | 128
|
|
1732
|
+
);
|
|
1733
|
+
} else if (codePoint < 1114112) {
|
|
1734
|
+
if ((units -= 4) < 0) break;
|
|
1735
|
+
bytes.push(
|
|
1736
|
+
codePoint >> 18 | 240,
|
|
1737
|
+
codePoint >> 12 & 63 | 128,
|
|
1738
|
+
codePoint >> 6 & 63 | 128,
|
|
1739
|
+
codePoint & 63 | 128
|
|
1740
|
+
);
|
|
1741
|
+
} else {
|
|
1742
|
+
throw new Error("Invalid code point");
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
return bytes;
|
|
1746
|
+
}
|
|
1747
|
+
function asciiToBytes(str) {
|
|
1748
|
+
const byteArray = [];
|
|
1749
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1750
|
+
byteArray.push(str.charCodeAt(i) & 255);
|
|
1751
|
+
}
|
|
1752
|
+
return byteArray;
|
|
1753
|
+
}
|
|
1754
|
+
function utf16leToBytes(str, units) {
|
|
1755
|
+
let c, hi, lo;
|
|
1756
|
+
const byteArray = [];
|
|
1757
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1758
|
+
if ((units -= 2) < 0) break;
|
|
1759
|
+
c = str.charCodeAt(i);
|
|
1760
|
+
hi = c >> 8;
|
|
1761
|
+
lo = c % 256;
|
|
1762
|
+
byteArray.push(lo);
|
|
1763
|
+
byteArray.push(hi);
|
|
1764
|
+
}
|
|
1765
|
+
return byteArray;
|
|
1766
|
+
}
|
|
1767
|
+
function base64ToBytes(str) {
|
|
1768
|
+
return base64.toByteArray(base64clean(str));
|
|
1769
|
+
}
|
|
1770
|
+
function blitBuffer(src, dst, offset, length) {
|
|
1771
|
+
let i;
|
|
1772
|
+
for (i = 0; i < length; ++i) {
|
|
1773
|
+
if (i + offset >= dst.length || i >= src.length) break;
|
|
1774
|
+
dst[i + offset] = src[i];
|
|
1775
|
+
}
|
|
1776
|
+
return i;
|
|
1777
|
+
}
|
|
1778
|
+
function isInstance(obj, type) {
|
|
1779
|
+
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
|
1780
|
+
}
|
|
1781
|
+
function numberIsNaN(obj) {
|
|
1782
|
+
return obj !== obj;
|
|
1783
|
+
}
|
|
1784
|
+
var hexSliceLookupTable = function() {
|
|
1785
|
+
const alphabet = "0123456789abcdef";
|
|
1786
|
+
const table = new Array(256);
|
|
1787
|
+
for (let i = 0; i < 16; ++i) {
|
|
1788
|
+
const i16 = i * 16;
|
|
1789
|
+
for (let j = 0; j < 16; ++j) {
|
|
1790
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
return table;
|
|
1794
|
+
}();
|
|
1795
|
+
function defineBigIntMethod(fn) {
|
|
1796
|
+
return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
|
|
1797
|
+
}
|
|
1798
|
+
function BufferBigIntNotDefined() {
|
|
1799
|
+
throw new Error("BigInt not supported");
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
});
|
|
1803
|
+
|
|
1
1804
|
// src/idl/pump.json
|
|
2
1805
|
var pump_default = {
|
|
3
1806
|
address: "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P",
|
|
@@ -740,7 +2543,6 @@ var pump_default = {
|
|
|
740
2543
|
},
|
|
741
2544
|
{
|
|
742
2545
|
name: "fee_config",
|
|
743
|
-
optional: true,
|
|
744
2546
|
pda: {
|
|
745
2547
|
seeds: [
|
|
746
2548
|
{
|
|
@@ -804,7 +2606,6 @@ var pump_default = {
|
|
|
804
2606
|
},
|
|
805
2607
|
{
|
|
806
2608
|
name: "fee_program",
|
|
807
|
-
optional: true,
|
|
808
2609
|
address: "pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ"
|
|
809
2610
|
}
|
|
810
2611
|
],
|
|
@@ -2569,7 +4370,6 @@ var pump_default = {
|
|
|
2569
4370
|
},
|
|
2570
4371
|
{
|
|
2571
4372
|
name: "fee_config",
|
|
2572
|
-
optional: true,
|
|
2573
4373
|
pda: {
|
|
2574
4374
|
seeds: [
|
|
2575
4375
|
{
|
|
@@ -2633,7 +4433,6 @@ var pump_default = {
|
|
|
2633
4433
|
},
|
|
2634
4434
|
{
|
|
2635
4435
|
name: "fee_program",
|
|
2636
|
-
optional: true,
|
|
2637
4436
|
address: "pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ"
|
|
2638
4437
|
}
|
|
2639
4438
|
],
|
|
@@ -4980,15 +6779,31 @@ function ceilDiv(a, b) {
|
|
|
4980
6779
|
}
|
|
4981
6780
|
|
|
4982
6781
|
// src/pda.ts
|
|
4983
|
-
import { PublicKey as
|
|
6782
|
+
import { PublicKey as PublicKey5 } from "@solana/web3.js";
|
|
4984
6783
|
import { NATIVE_MINT as NATIVE_MINT2 } from "@solana/spl-token";
|
|
4985
|
-
import { poolPda } from "@pump-fun/pump-swap-sdk";
|
|
6784
|
+
import { poolPda, pumpFeePda, pumpPda } from "@pump-fun/pump-swap-sdk";
|
|
4986
6785
|
|
|
4987
6786
|
// src/sdk.ts
|
|
4988
6787
|
import { AnchorProvider, Program } from "@coral-xyz/anchor";
|
|
4989
|
-
import {
|
|
6788
|
+
import { PUMP_AMM_SDK as PUMP_AMM_SDK2 } from "@pump-fun/pump-swap-sdk";
|
|
4990
6789
|
import {
|
|
4991
6790
|
createAssociatedTokenAccountIdempotentInstruction,
|
|
6791
|
+
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2
|
|
6792
|
+
} from "@solana/spl-token";
|
|
6793
|
+
import {
|
|
6794
|
+
PublicKey as PublicKey4
|
|
6795
|
+
} from "@solana/web3.js";
|
|
6796
|
+
import BN5 from "bn.js";
|
|
6797
|
+
|
|
6798
|
+
// src/onlineSdk.ts
|
|
6799
|
+
import {
|
|
6800
|
+
coinCreatorVaultAtaPda,
|
|
6801
|
+
coinCreatorVaultAuthorityPda,
|
|
6802
|
+
OnlinePumpAmmSdk,
|
|
6803
|
+
PUMP_AMM_SDK,
|
|
6804
|
+
PumpAmmAdminSdk
|
|
6805
|
+
} from "@pump-fun/pump-swap-sdk";
|
|
6806
|
+
import {
|
|
4992
6807
|
getAssociatedTokenAddressSync,
|
|
4993
6808
|
NATIVE_MINT,
|
|
4994
6809
|
TOKEN_2022_PROGRAM_ID,
|
|
@@ -5059,8 +6874,281 @@ function currentDayTokens(globalVolumeAccumulator, userVolumeAccumulator, curren
|
|
|
5059
6874
|
if (currentDaySolVolume.eqn(0)) {
|
|
5060
6875
|
return new BN3(0);
|
|
5061
6876
|
}
|
|
5062
|
-
return currentSolVolume.mul(currentDayTokenSupply).div(currentDaySolVolume);
|
|
5063
|
-
}
|
|
6877
|
+
return currentSolVolume.mul(currentDayTokenSupply).div(currentDaySolVolume);
|
|
6878
|
+
}
|
|
6879
|
+
|
|
6880
|
+
// src/onlineSdk.ts
|
|
6881
|
+
var OFFLINE_PUMP_PROGRAM = getPumpProgram(null);
|
|
6882
|
+
var OnlinePumpSdk = class {
|
|
6883
|
+
constructor(connection) {
|
|
6884
|
+
this.connection = connection;
|
|
6885
|
+
this.pumpProgram = getPumpProgram(connection);
|
|
6886
|
+
this.offlinePumpProgram = OFFLINE_PUMP_PROGRAM;
|
|
6887
|
+
this.pumpAmmSdk = new OnlinePumpAmmSdk(connection);
|
|
6888
|
+
this.pumpAmmAdminSdk = new PumpAmmAdminSdk(connection);
|
|
6889
|
+
}
|
|
6890
|
+
async fetchGlobal() {
|
|
6891
|
+
return await this.pumpProgram.account.global.fetch(GLOBAL_PDA);
|
|
6892
|
+
}
|
|
6893
|
+
async fetchFeeConfig() {
|
|
6894
|
+
return await this.pumpProgram.account.feeConfig.fetch(PUMP_FEE_CONFIG_PDA);
|
|
6895
|
+
}
|
|
6896
|
+
async fetchBondingCurve(mint) {
|
|
6897
|
+
return await this.pumpProgram.account.bondingCurve.fetch(
|
|
6898
|
+
bondingCurvePda(mint)
|
|
6899
|
+
);
|
|
6900
|
+
}
|
|
6901
|
+
async fetchBuyState(mint, user) {
|
|
6902
|
+
const [bondingCurveAccountInfo, associatedUserAccountInfo] = await this.connection.getMultipleAccountsInfo([
|
|
6903
|
+
bondingCurvePda(mint),
|
|
6904
|
+
getAssociatedTokenAddressSync(mint, user, true)
|
|
6905
|
+
]);
|
|
6906
|
+
if (!bondingCurveAccountInfo) {
|
|
6907
|
+
throw new Error(
|
|
6908
|
+
`Bonding curve account not found for mint: ${mint.toBase58()}`
|
|
6909
|
+
);
|
|
6910
|
+
}
|
|
6911
|
+
const bondingCurve = PUMP_SDK.decodeBondingCurve(bondingCurveAccountInfo);
|
|
6912
|
+
return { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo };
|
|
6913
|
+
}
|
|
6914
|
+
async fetchSellState(mint, user) {
|
|
6915
|
+
const [bondingCurveAccountInfo, associatedUserAccountInfo] = await this.connection.getMultipleAccountsInfo([
|
|
6916
|
+
bondingCurvePda(mint),
|
|
6917
|
+
getAssociatedTokenAddressSync(mint, user, true)
|
|
6918
|
+
]);
|
|
6919
|
+
if (!bondingCurveAccountInfo) {
|
|
6920
|
+
throw new Error(
|
|
6921
|
+
`Bonding curve account not found for mint: ${mint.toBase58()}`
|
|
6922
|
+
);
|
|
6923
|
+
}
|
|
6924
|
+
if (!associatedUserAccountInfo) {
|
|
6925
|
+
throw new Error(
|
|
6926
|
+
`Associated token account not found for mint: ${mint.toBase58()} and user: ${user.toBase58()}`
|
|
6927
|
+
);
|
|
6928
|
+
}
|
|
6929
|
+
const bondingCurve = PUMP_SDK.decodeBondingCurve(bondingCurveAccountInfo);
|
|
6930
|
+
return { bondingCurveAccountInfo, bondingCurve };
|
|
6931
|
+
}
|
|
6932
|
+
async fetchGlobalVolumeAccumulator() {
|
|
6933
|
+
return await this.pumpProgram.account.globalVolumeAccumulator.fetch(
|
|
6934
|
+
GLOBAL_VOLUME_ACCUMULATOR_PDA
|
|
6935
|
+
);
|
|
6936
|
+
}
|
|
6937
|
+
async fetchUserVolumeAccumulator(user) {
|
|
6938
|
+
return await this.pumpProgram.account.userVolumeAccumulator.fetchNullable(
|
|
6939
|
+
userVolumeAccumulatorPda(user)
|
|
6940
|
+
);
|
|
6941
|
+
}
|
|
6942
|
+
async fetchUserVolumeAccumulatorTotalStats(user) {
|
|
6943
|
+
const userVolumeAccumulator = await this.fetchUserVolumeAccumulator(
|
|
6944
|
+
user
|
|
6945
|
+
) ?? {
|
|
6946
|
+
totalUnclaimedTokens: new BN4(0),
|
|
6947
|
+
totalClaimedTokens: new BN4(0),
|
|
6948
|
+
currentSolVolume: new BN4(0)
|
|
6949
|
+
};
|
|
6950
|
+
const userVolumeAccumulatorAmm = await this.pumpAmmSdk.fetchUserVolumeAccumulator(user) ?? {
|
|
6951
|
+
totalUnclaimedTokens: new BN4(0),
|
|
6952
|
+
totalClaimedTokens: new BN4(0),
|
|
6953
|
+
currentSolVolume: new BN4(0)
|
|
6954
|
+
};
|
|
6955
|
+
return {
|
|
6956
|
+
totalUnclaimedTokens: userVolumeAccumulator.totalUnclaimedTokens.add(
|
|
6957
|
+
userVolumeAccumulatorAmm.totalUnclaimedTokens
|
|
6958
|
+
),
|
|
6959
|
+
totalClaimedTokens: userVolumeAccumulator.totalClaimedTokens.add(
|
|
6960
|
+
userVolumeAccumulatorAmm.totalClaimedTokens
|
|
6961
|
+
),
|
|
6962
|
+
currentSolVolume: userVolumeAccumulator.currentSolVolume.add(
|
|
6963
|
+
userVolumeAccumulatorAmm.currentSolVolume
|
|
6964
|
+
)
|
|
6965
|
+
};
|
|
6966
|
+
}
|
|
6967
|
+
async collectCoinCreatorFeeInstructions(coinCreator) {
|
|
6968
|
+
let quoteMint = NATIVE_MINT;
|
|
6969
|
+
let quoteTokenProgram = TOKEN_PROGRAM_ID;
|
|
6970
|
+
let coinCreatorVaultAuthority = coinCreatorVaultAuthorityPda(coinCreator);
|
|
6971
|
+
let coinCreatorVaultAta = coinCreatorVaultAtaPda(
|
|
6972
|
+
coinCreatorVaultAuthority,
|
|
6973
|
+
quoteMint,
|
|
6974
|
+
quoteTokenProgram
|
|
6975
|
+
);
|
|
6976
|
+
let coinCreatorTokenAccount = getAssociatedTokenAddressSync(
|
|
6977
|
+
quoteMint,
|
|
6978
|
+
coinCreator,
|
|
6979
|
+
true,
|
|
6980
|
+
quoteTokenProgram
|
|
6981
|
+
);
|
|
6982
|
+
const [coinCreatorVaultAtaAccountInfo, coinCreatorTokenAccountInfo] = await this.connection.getMultipleAccountsInfo([
|
|
6983
|
+
coinCreatorVaultAta,
|
|
6984
|
+
coinCreatorTokenAccount
|
|
6985
|
+
]);
|
|
6986
|
+
return [
|
|
6987
|
+
await this.offlinePumpProgram.methods.collectCreatorFee().accountsPartial({
|
|
6988
|
+
creator: coinCreator
|
|
6989
|
+
}).instruction(),
|
|
6990
|
+
...await PUMP_AMM_SDK.collectCoinCreatorFee({
|
|
6991
|
+
coinCreator,
|
|
6992
|
+
quoteMint,
|
|
6993
|
+
quoteTokenProgram,
|
|
6994
|
+
coinCreatorVaultAuthority,
|
|
6995
|
+
coinCreatorVaultAta,
|
|
6996
|
+
coinCreatorTokenAccount,
|
|
6997
|
+
coinCreatorVaultAtaAccountInfo,
|
|
6998
|
+
coinCreatorTokenAccountInfo
|
|
6999
|
+
})
|
|
7000
|
+
];
|
|
7001
|
+
}
|
|
7002
|
+
async adminSetCoinCreatorInstructions(newCoinCreator, mint) {
|
|
7003
|
+
const global = await this.fetchGlobal();
|
|
7004
|
+
return [
|
|
7005
|
+
await this.offlinePumpProgram.methods.adminSetCreator(newCoinCreator).accountsPartial({
|
|
7006
|
+
adminSetCreatorAuthority: global.adminSetCreatorAuthority,
|
|
7007
|
+
mint
|
|
7008
|
+
}).instruction(),
|
|
7009
|
+
await this.pumpAmmAdminSdk.adminSetCoinCreator(mint, newCoinCreator)
|
|
7010
|
+
];
|
|
7011
|
+
}
|
|
7012
|
+
async getCreatorVaultBalance(creator) {
|
|
7013
|
+
const creatorVault = creatorVaultPda(creator);
|
|
7014
|
+
const accountInfo = await this.connection.getAccountInfo(creatorVault);
|
|
7015
|
+
if (accountInfo === null) {
|
|
7016
|
+
return new BN4(0);
|
|
7017
|
+
}
|
|
7018
|
+
const rentExemptionLamports = await this.connection.getMinimumBalanceForRentExemption(
|
|
7019
|
+
accountInfo.data.length
|
|
7020
|
+
);
|
|
7021
|
+
if (accountInfo.lamports < rentExemptionLamports) {
|
|
7022
|
+
return new BN4(0);
|
|
7023
|
+
}
|
|
7024
|
+
return new BN4(accountInfo.lamports - rentExemptionLamports);
|
|
7025
|
+
}
|
|
7026
|
+
async getCreatorVaultBalanceBothPrograms(creator) {
|
|
7027
|
+
const balance = await this.getCreatorVaultBalance(creator);
|
|
7028
|
+
const ammBalance = await this.pumpAmmSdk.getCoinCreatorVaultBalance(creator);
|
|
7029
|
+
return balance.add(ammBalance);
|
|
7030
|
+
}
|
|
7031
|
+
async adminUpdateTokenIncentives(startTime, endTime, dayNumber, tokenSupplyPerDay, secondsInADay = new BN4(86400), mint = PUMP_TOKEN_MINT, tokenProgram = TOKEN_2022_PROGRAM_ID) {
|
|
7032
|
+
const { authority } = await this.fetchGlobal();
|
|
7033
|
+
return await this.offlinePumpProgram.methods.adminUpdateTokenIncentives(
|
|
7034
|
+
startTime,
|
|
7035
|
+
endTime,
|
|
7036
|
+
secondsInADay,
|
|
7037
|
+
dayNumber,
|
|
7038
|
+
tokenSupplyPerDay
|
|
7039
|
+
).accountsPartial({
|
|
7040
|
+
authority,
|
|
7041
|
+
mint,
|
|
7042
|
+
tokenProgram
|
|
7043
|
+
}).instruction();
|
|
7044
|
+
}
|
|
7045
|
+
async adminUpdateTokenIncentivesBothPrograms(startTime, endTime, dayNumber, tokenSupplyPerDay, secondsInADay = new BN4(86400), mint = PUMP_TOKEN_MINT, tokenProgram = TOKEN_2022_PROGRAM_ID) {
|
|
7046
|
+
return [
|
|
7047
|
+
await this.adminUpdateTokenIncentives(
|
|
7048
|
+
startTime,
|
|
7049
|
+
endTime,
|
|
7050
|
+
dayNumber,
|
|
7051
|
+
tokenSupplyPerDay,
|
|
7052
|
+
secondsInADay,
|
|
7053
|
+
mint,
|
|
7054
|
+
tokenProgram
|
|
7055
|
+
),
|
|
7056
|
+
await this.pumpAmmAdminSdk.adminUpdateTokenIncentives(
|
|
7057
|
+
startTime,
|
|
7058
|
+
endTime,
|
|
7059
|
+
dayNumber,
|
|
7060
|
+
tokenSupplyPerDay,
|
|
7061
|
+
secondsInADay,
|
|
7062
|
+
mint,
|
|
7063
|
+
tokenProgram
|
|
7064
|
+
)
|
|
7065
|
+
];
|
|
7066
|
+
}
|
|
7067
|
+
async claimTokenIncentives(user, payer) {
|
|
7068
|
+
const { mint } = await this.fetchGlobalVolumeAccumulator();
|
|
7069
|
+
if (mint.equals(PublicKey3.default)) {
|
|
7070
|
+
return [];
|
|
7071
|
+
}
|
|
7072
|
+
const [mintAccountInfo, userAccumulatorAccountInfo] = await this.connection.getMultipleAccountsInfo([
|
|
7073
|
+
mint,
|
|
7074
|
+
userVolumeAccumulatorPda(user)
|
|
7075
|
+
]);
|
|
7076
|
+
if (!mintAccountInfo) {
|
|
7077
|
+
return [];
|
|
7078
|
+
}
|
|
7079
|
+
if (!userAccumulatorAccountInfo) {
|
|
7080
|
+
return [];
|
|
7081
|
+
}
|
|
7082
|
+
return [
|
|
7083
|
+
await this.offlinePumpProgram.methods.claimTokenIncentives().accountsPartial({
|
|
7084
|
+
user,
|
|
7085
|
+
payer,
|
|
7086
|
+
mint,
|
|
7087
|
+
tokenProgram: mintAccountInfo.owner
|
|
7088
|
+
}).instruction()
|
|
7089
|
+
];
|
|
7090
|
+
}
|
|
7091
|
+
async claimTokenIncentivesBothPrograms(user, payer) {
|
|
7092
|
+
return [
|
|
7093
|
+
...await this.claimTokenIncentives(user, payer),
|
|
7094
|
+
...await this.pumpAmmSdk.claimTokenIncentives(user, payer)
|
|
7095
|
+
];
|
|
7096
|
+
}
|
|
7097
|
+
async getTotalUnclaimedTokens(user) {
|
|
7098
|
+
const [
|
|
7099
|
+
globalVolumeAccumulatorAccountInfo,
|
|
7100
|
+
userVolumeAccumulatorAccountInfo
|
|
7101
|
+
] = await this.connection.getMultipleAccountsInfo([
|
|
7102
|
+
GLOBAL_VOLUME_ACCUMULATOR_PDA,
|
|
7103
|
+
userVolumeAccumulatorPda(user)
|
|
7104
|
+
]);
|
|
7105
|
+
if (!globalVolumeAccumulatorAccountInfo || !userVolumeAccumulatorAccountInfo) {
|
|
7106
|
+
return new BN4(0);
|
|
7107
|
+
}
|
|
7108
|
+
const globalVolumeAccumulator = PUMP_SDK.decodeGlobalVolumeAccumulator(
|
|
7109
|
+
globalVolumeAccumulatorAccountInfo
|
|
7110
|
+
);
|
|
7111
|
+
const userVolumeAccumulator = PUMP_SDK.decodeUserVolumeAccumulator(
|
|
7112
|
+
userVolumeAccumulatorAccountInfo
|
|
7113
|
+
);
|
|
7114
|
+
return totalUnclaimedTokens(globalVolumeAccumulator, userVolumeAccumulator);
|
|
7115
|
+
}
|
|
7116
|
+
async getTotalUnclaimedTokensBothPrograms(user) {
|
|
7117
|
+
return (await this.getTotalUnclaimedTokens(user)).add(
|
|
7118
|
+
await this.pumpAmmSdk.getTotalUnclaimedTokens(user)
|
|
7119
|
+
);
|
|
7120
|
+
}
|
|
7121
|
+
async getCurrentDayTokens(user) {
|
|
7122
|
+
const [
|
|
7123
|
+
globalVolumeAccumulatorAccountInfo,
|
|
7124
|
+
userVolumeAccumulatorAccountInfo
|
|
7125
|
+
] = await this.connection.getMultipleAccountsInfo([
|
|
7126
|
+
GLOBAL_VOLUME_ACCUMULATOR_PDA,
|
|
7127
|
+
userVolumeAccumulatorPda(user)
|
|
7128
|
+
]);
|
|
7129
|
+
if (!globalVolumeAccumulatorAccountInfo || !userVolumeAccumulatorAccountInfo) {
|
|
7130
|
+
return new BN4(0);
|
|
7131
|
+
}
|
|
7132
|
+
const globalVolumeAccumulator = PUMP_SDK.decodeGlobalVolumeAccumulator(
|
|
7133
|
+
globalVolumeAccumulatorAccountInfo
|
|
7134
|
+
);
|
|
7135
|
+
const userVolumeAccumulator = PUMP_SDK.decodeUserVolumeAccumulator(
|
|
7136
|
+
userVolumeAccumulatorAccountInfo
|
|
7137
|
+
);
|
|
7138
|
+
return currentDayTokens(globalVolumeAccumulator, userVolumeAccumulator);
|
|
7139
|
+
}
|
|
7140
|
+
async getCurrentDayTokensBothPrograms(user) {
|
|
7141
|
+
return (await this.getCurrentDayTokens(user)).add(
|
|
7142
|
+
await this.pumpAmmSdk.getCurrentDayTokens(user)
|
|
7143
|
+
);
|
|
7144
|
+
}
|
|
7145
|
+
async syncUserVolumeAccumulatorBothPrograms(user) {
|
|
7146
|
+
return [
|
|
7147
|
+
await PUMP_SDK.syncUserVolumeAccumulator(user),
|
|
7148
|
+
await PUMP_AMM_SDK.syncUserVolumeAccumulator(user)
|
|
7149
|
+
];
|
|
7150
|
+
}
|
|
7151
|
+
};
|
|
5064
7152
|
|
|
5065
7153
|
// src/sdk.ts
|
|
5066
7154
|
function getPumpProgram(connection) {
|
|
@@ -5069,29 +7157,22 @@ function getPumpProgram(connection) {
|
|
|
5069
7157
|
new AnchorProvider(connection, null, {})
|
|
5070
7158
|
);
|
|
5071
7159
|
}
|
|
5072
|
-
var PUMP_PROGRAM_ID = new
|
|
7160
|
+
var PUMP_PROGRAM_ID = new PublicKey4(
|
|
5073
7161
|
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"
|
|
5074
7162
|
);
|
|
5075
|
-
var PUMP_AMM_PROGRAM_ID = new
|
|
7163
|
+
var PUMP_AMM_PROGRAM_ID = new PublicKey4(
|
|
5076
7164
|
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA"
|
|
5077
7165
|
);
|
|
5078
|
-
var PUMP_FEE_PROGRAM_ID = new
|
|
7166
|
+
var PUMP_FEE_PROGRAM_ID = new PublicKey4(
|
|
5079
7167
|
"pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ"
|
|
5080
7168
|
);
|
|
5081
7169
|
var BONDING_CURVE_NEW_SIZE = 150;
|
|
5082
|
-
var PUMP_TOKEN_MINT = new
|
|
7170
|
+
var PUMP_TOKEN_MINT = new PublicKey4(
|
|
5083
7171
|
"pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn"
|
|
5084
7172
|
);
|
|
5085
7173
|
var PumpSdk = class {
|
|
5086
|
-
constructor(
|
|
5087
|
-
this.
|
|
5088
|
-
this.pumpProgram = getPumpProgram(connection);
|
|
5089
|
-
this.offlinePumpProgram = getPumpProgram(null);
|
|
5090
|
-
this.pumpAmmSdk = new PumpAmmSdk(connection);
|
|
5091
|
-
this.pumpAmmAdminSdk = new PumpAmmAdminSdk(connection);
|
|
5092
|
-
}
|
|
5093
|
-
programId() {
|
|
5094
|
-
return this.offlinePumpProgram.programId;
|
|
7174
|
+
constructor() {
|
|
7175
|
+
this.offlinePumpProgram = OFFLINE_PUMP_PROGRAM;
|
|
5095
7176
|
}
|
|
5096
7177
|
decodeGlobal(accountInfo) {
|
|
5097
7178
|
return this.offlinePumpProgram.coder.accounts.decode(
|
|
@@ -5139,83 +7220,6 @@ var PumpSdk = class {
|
|
|
5139
7220
|
return null;
|
|
5140
7221
|
}
|
|
5141
7222
|
}
|
|
5142
|
-
async fetchGlobal() {
|
|
5143
|
-
return await this.pumpProgram.account.global.fetch(globalPda());
|
|
5144
|
-
}
|
|
5145
|
-
async fetchFeeConfig() {
|
|
5146
|
-
return await this.pumpProgram.account.feeConfig.fetch(pumpFeeConfigPda());
|
|
5147
|
-
}
|
|
5148
|
-
async fetchBondingCurve(mint) {
|
|
5149
|
-
return await this.pumpProgram.account.bondingCurve.fetch(
|
|
5150
|
-
bondingCurvePda(mint)
|
|
5151
|
-
);
|
|
5152
|
-
}
|
|
5153
|
-
async fetchBuyState(mint, user) {
|
|
5154
|
-
const [bondingCurveAccountInfo, associatedUserAccountInfo] = await this.connection.getMultipleAccountsInfo([
|
|
5155
|
-
bondingCurvePda(mint),
|
|
5156
|
-
getAssociatedTokenAddressSync(mint, user, true)
|
|
5157
|
-
]);
|
|
5158
|
-
if (!bondingCurveAccountInfo) {
|
|
5159
|
-
throw new Error(
|
|
5160
|
-
`Bonding curve account not found for mint: ${mint.toBase58()}`
|
|
5161
|
-
);
|
|
5162
|
-
}
|
|
5163
|
-
const bondingCurve = this.decodeBondingCurve(bondingCurveAccountInfo);
|
|
5164
|
-
return { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo };
|
|
5165
|
-
}
|
|
5166
|
-
async fetchSellState(mint, user) {
|
|
5167
|
-
const [bondingCurveAccountInfo, associatedUserAccountInfo] = await this.connection.getMultipleAccountsInfo([
|
|
5168
|
-
bondingCurvePda(mint),
|
|
5169
|
-
getAssociatedTokenAddressSync(mint, user, true)
|
|
5170
|
-
]);
|
|
5171
|
-
if (!bondingCurveAccountInfo) {
|
|
5172
|
-
throw new Error(
|
|
5173
|
-
`Bonding curve account not found for mint: ${mint.toBase58()}`
|
|
5174
|
-
);
|
|
5175
|
-
}
|
|
5176
|
-
if (!associatedUserAccountInfo) {
|
|
5177
|
-
throw new Error(
|
|
5178
|
-
`Associated token account not found for mint: ${mint.toBase58()} and user: ${user.toBase58()}`
|
|
5179
|
-
);
|
|
5180
|
-
}
|
|
5181
|
-
const bondingCurve = this.decodeBondingCurve(bondingCurveAccountInfo);
|
|
5182
|
-
return { bondingCurveAccountInfo, bondingCurve };
|
|
5183
|
-
}
|
|
5184
|
-
async fetchGlobalVolumeAccumulator() {
|
|
5185
|
-
return await this.pumpProgram.account.globalVolumeAccumulator.fetch(
|
|
5186
|
-
globalVolumeAccumulatorPda()[0]
|
|
5187
|
-
);
|
|
5188
|
-
}
|
|
5189
|
-
async fetchUserVolumeAccumulator(user) {
|
|
5190
|
-
return await this.pumpProgram.account.userVolumeAccumulator.fetchNullable(
|
|
5191
|
-
userVolumeAccumulatorPda(user)[0]
|
|
5192
|
-
);
|
|
5193
|
-
}
|
|
5194
|
-
async fetchUserVolumeAccumulatorTotalStats(user) {
|
|
5195
|
-
const userVolumeAccumulator = await this.fetchUserVolumeAccumulator(
|
|
5196
|
-
user
|
|
5197
|
-
) ?? {
|
|
5198
|
-
totalUnclaimedTokens: new BN4(0),
|
|
5199
|
-
totalClaimedTokens: new BN4(0),
|
|
5200
|
-
currentSolVolume: new BN4(0)
|
|
5201
|
-
};
|
|
5202
|
-
const userVolumeAccumulatorAmm = await this.pumpAmmSdk.fetchUserVolumeAccumulator(user) ?? {
|
|
5203
|
-
totalUnclaimedTokens: new BN4(0),
|
|
5204
|
-
totalClaimedTokens: new BN4(0),
|
|
5205
|
-
currentSolVolume: new BN4(0)
|
|
5206
|
-
};
|
|
5207
|
-
return {
|
|
5208
|
-
totalUnclaimedTokens: userVolumeAccumulator.totalUnclaimedTokens.add(
|
|
5209
|
-
userVolumeAccumulatorAmm.totalUnclaimedTokens
|
|
5210
|
-
),
|
|
5211
|
-
totalClaimedTokens: userVolumeAccumulator.totalClaimedTokens.add(
|
|
5212
|
-
userVolumeAccumulatorAmm.totalClaimedTokens
|
|
5213
|
-
),
|
|
5214
|
-
currentSolVolume: userVolumeAccumulator.currentSolVolume.add(
|
|
5215
|
-
userVolumeAccumulatorAmm.currentSolVolume
|
|
5216
|
-
)
|
|
5217
|
-
};
|
|
5218
|
-
}
|
|
5219
7223
|
async createInstruction({
|
|
5220
7224
|
mint,
|
|
5221
7225
|
name,
|
|
@@ -5249,7 +7253,7 @@ var PumpSdk = class {
|
|
|
5249
7253
|
})
|
|
5250
7254
|
);
|
|
5251
7255
|
}
|
|
5252
|
-
const associatedUser =
|
|
7256
|
+
const associatedUser = getAssociatedTokenAddressSync2(mint, user, true);
|
|
5253
7257
|
if (!associatedUserAccountInfo) {
|
|
5254
7258
|
instructions.push(
|
|
5255
7259
|
createAssociatedTokenAccountIdempotentInstruction(
|
|
@@ -5285,7 +7289,7 @@ var PumpSdk = class {
|
|
|
5285
7289
|
amount,
|
|
5286
7290
|
solAmount
|
|
5287
7291
|
}) {
|
|
5288
|
-
const associatedUser =
|
|
7292
|
+
const associatedUser = getAssociatedTokenAddressSync2(mint, user, true);
|
|
5289
7293
|
return [
|
|
5290
7294
|
await this.createInstruction({ mint, name, symbol, uri, creator, user }),
|
|
5291
7295
|
await this.extendAccountInstruction({
|
|
@@ -5328,7 +7332,7 @@ var PumpSdk = class {
|
|
|
5328
7332
|
feeRecipient: getFeeRecipient(global),
|
|
5329
7333
|
amount,
|
|
5330
7334
|
solAmount: solAmount.add(
|
|
5331
|
-
solAmount.mul(new
|
|
7335
|
+
solAmount.mul(new BN5(Math.floor(slippage * 10))).div(new BN5(1e3))
|
|
5332
7336
|
)
|
|
5333
7337
|
});
|
|
5334
7338
|
}
|
|
@@ -5359,7 +7363,7 @@ var PumpSdk = class {
|
|
|
5359
7363
|
feeRecipient: getFeeRecipient(global),
|
|
5360
7364
|
amount,
|
|
5361
7365
|
solAmount: solAmount.sub(
|
|
5362
|
-
solAmount.mul(new
|
|
7366
|
+
solAmount.mul(new BN5(Math.floor(slippage * 10))).div(new BN5(1e3))
|
|
5363
7367
|
)
|
|
5364
7368
|
})
|
|
5365
7369
|
);
|
|
@@ -5385,191 +7389,13 @@ var PumpSdk = class {
|
|
|
5385
7389
|
withdrawAuthority
|
|
5386
7390
|
}).instruction();
|
|
5387
7391
|
}
|
|
5388
|
-
async collectCoinCreatorFeeInstructions(coinCreator) {
|
|
5389
|
-
let quoteMint = NATIVE_MINT;
|
|
5390
|
-
let quoteTokenProgram = TOKEN_PROGRAM_ID;
|
|
5391
|
-
let coinCreatorVaultAuthority = this.pumpAmmSdk.coinCreatorVaultAuthorityPda(coinCreator);
|
|
5392
|
-
let coinCreatorVaultAta = this.pumpAmmSdk.coinCreatorVaultAta(
|
|
5393
|
-
coinCreatorVaultAuthority,
|
|
5394
|
-
quoteMint,
|
|
5395
|
-
quoteTokenProgram
|
|
5396
|
-
);
|
|
5397
|
-
let coinCreatorTokenAccount = getAssociatedTokenAddressSync(
|
|
5398
|
-
quoteMint,
|
|
5399
|
-
coinCreator,
|
|
5400
|
-
true,
|
|
5401
|
-
quoteTokenProgram
|
|
5402
|
-
);
|
|
5403
|
-
const [coinCreatorVaultAtaAccountInfo, coinCreatorTokenAccountInfo] = await this.connection.getMultipleAccountsInfo([
|
|
5404
|
-
coinCreatorVaultAta,
|
|
5405
|
-
coinCreatorTokenAccount
|
|
5406
|
-
]);
|
|
5407
|
-
return [
|
|
5408
|
-
await this.offlinePumpProgram.methods.collectCreatorFee().accountsPartial({
|
|
5409
|
-
creator: coinCreator
|
|
5410
|
-
}).instruction(),
|
|
5411
|
-
...await this.pumpAmmSdk.collectCoinCreatorFee({
|
|
5412
|
-
coinCreator,
|
|
5413
|
-
quoteMint,
|
|
5414
|
-
quoteTokenProgram,
|
|
5415
|
-
coinCreatorVaultAuthority,
|
|
5416
|
-
coinCreatorVaultAta,
|
|
5417
|
-
coinCreatorTokenAccount,
|
|
5418
|
-
coinCreatorVaultAtaAccountInfo,
|
|
5419
|
-
coinCreatorTokenAccountInfo
|
|
5420
|
-
})
|
|
5421
|
-
];
|
|
5422
|
-
}
|
|
5423
|
-
async adminSetCoinCreatorInstructions(newCoinCreator, mint) {
|
|
5424
|
-
const global = await this.fetchGlobal();
|
|
5425
|
-
return [
|
|
5426
|
-
await this.offlinePumpProgram.methods.adminSetCreator(newCoinCreator).accountsPartial({
|
|
5427
|
-
adminSetCreatorAuthority: global.adminSetCreatorAuthority,
|
|
5428
|
-
mint
|
|
5429
|
-
}).instruction(),
|
|
5430
|
-
await this.pumpAmmAdminSdk.adminSetCoinCreator(mint, newCoinCreator)
|
|
5431
|
-
];
|
|
5432
|
-
}
|
|
5433
|
-
async getCreatorVaultBalance(creator) {
|
|
5434
|
-
const creatorVault = creatorVaultPda(creator);
|
|
5435
|
-
const accountInfo = await this.connection.getAccountInfo(creatorVault);
|
|
5436
|
-
if (accountInfo === null) {
|
|
5437
|
-
return new BN4(0);
|
|
5438
|
-
}
|
|
5439
|
-
const rentExemptionLamports = await this.connection.getMinimumBalanceForRentExemption(
|
|
5440
|
-
accountInfo.data.length
|
|
5441
|
-
);
|
|
5442
|
-
if (accountInfo.lamports < rentExemptionLamports) {
|
|
5443
|
-
return new BN4(0);
|
|
5444
|
-
}
|
|
5445
|
-
return new BN4(accountInfo.lamports - rentExemptionLamports);
|
|
5446
|
-
}
|
|
5447
|
-
async getCreatorVaultBalanceBothPrograms(creator) {
|
|
5448
|
-
const balance = await this.getCreatorVaultBalance(creator);
|
|
5449
|
-
const ammBalance = await this.pumpAmmSdk.getCoinCreatorVaultBalance(creator);
|
|
5450
|
-
return balance.add(ammBalance);
|
|
5451
|
-
}
|
|
5452
|
-
async adminUpdateTokenIncentives(startTime, endTime, dayNumber, tokenSupplyPerDay, secondsInADay = new BN4(86400), mint = PUMP_TOKEN_MINT, tokenProgram = TOKEN_2022_PROGRAM_ID) {
|
|
5453
|
-
const { authority } = await this.fetchGlobal();
|
|
5454
|
-
return await this.offlinePumpProgram.methods.adminUpdateTokenIncentives(
|
|
5455
|
-
startTime,
|
|
5456
|
-
endTime,
|
|
5457
|
-
secondsInADay,
|
|
5458
|
-
dayNumber,
|
|
5459
|
-
tokenSupplyPerDay
|
|
5460
|
-
).accountsPartial({
|
|
5461
|
-
authority,
|
|
5462
|
-
mint,
|
|
5463
|
-
tokenProgram
|
|
5464
|
-
}).instruction();
|
|
5465
|
-
}
|
|
5466
|
-
async adminUpdateTokenIncentivesBothPrograms(startTime, endTime, dayNumber, tokenSupplyPerDay, secondsInADay = new BN4(86400), mint = PUMP_TOKEN_MINT, tokenProgram = TOKEN_2022_PROGRAM_ID) {
|
|
5467
|
-
return [
|
|
5468
|
-
await this.adminUpdateTokenIncentives(
|
|
5469
|
-
startTime,
|
|
5470
|
-
endTime,
|
|
5471
|
-
dayNumber,
|
|
5472
|
-
tokenSupplyPerDay,
|
|
5473
|
-
secondsInADay,
|
|
5474
|
-
mint,
|
|
5475
|
-
tokenProgram
|
|
5476
|
-
),
|
|
5477
|
-
await this.pumpAmmAdminSdk.adminUpdateTokenIncentives(
|
|
5478
|
-
startTime,
|
|
5479
|
-
endTime,
|
|
5480
|
-
dayNumber,
|
|
5481
|
-
tokenSupplyPerDay,
|
|
5482
|
-
secondsInADay,
|
|
5483
|
-
mint,
|
|
5484
|
-
tokenProgram
|
|
5485
|
-
)
|
|
5486
|
-
];
|
|
5487
|
-
}
|
|
5488
|
-
async claimTokenIncentives(user, payer) {
|
|
5489
|
-
const { mint } = await this.fetchGlobalVolumeAccumulator();
|
|
5490
|
-
if (mint.equals(PublicKey3.default)) {
|
|
5491
|
-
return [];
|
|
5492
|
-
}
|
|
5493
|
-
const [mintAccountInfo, userAccumulatorAccountInfo] = await this.connection.getMultipleAccountsInfo([
|
|
5494
|
-
mint,
|
|
5495
|
-
userVolumeAccumulatorPda(user)[0]
|
|
5496
|
-
]);
|
|
5497
|
-
if (!mintAccountInfo) {
|
|
5498
|
-
return [];
|
|
5499
|
-
}
|
|
5500
|
-
if (!userAccumulatorAccountInfo) {
|
|
5501
|
-
return [];
|
|
5502
|
-
}
|
|
5503
|
-
return [
|
|
5504
|
-
await this.offlinePumpProgram.methods.claimTokenIncentives().accountsPartial({
|
|
5505
|
-
user,
|
|
5506
|
-
payer,
|
|
5507
|
-
mint,
|
|
5508
|
-
tokenProgram: mintAccountInfo.owner
|
|
5509
|
-
}).instruction()
|
|
5510
|
-
];
|
|
5511
|
-
}
|
|
5512
|
-
async claimTokenIncentivesBothPrograms(user, payer) {
|
|
5513
|
-
return [
|
|
5514
|
-
...await this.claimTokenIncentives(user, payer),
|
|
5515
|
-
...await this.pumpAmmSdk.claimTokenIncentives(user, payer)
|
|
5516
|
-
];
|
|
5517
|
-
}
|
|
5518
|
-
async getTotalUnclaimedTokens(user) {
|
|
5519
|
-
const [
|
|
5520
|
-
globalVolumeAccumulatorAccountInfo,
|
|
5521
|
-
userVolumeAccumulatorAccountInfo
|
|
5522
|
-
] = await this.connection.getMultipleAccountsInfo([
|
|
5523
|
-
globalVolumeAccumulatorPda()[0],
|
|
5524
|
-
userVolumeAccumulatorPda(user)[0]
|
|
5525
|
-
]);
|
|
5526
|
-
if (!globalVolumeAccumulatorAccountInfo || !userVolumeAccumulatorAccountInfo) {
|
|
5527
|
-
return new BN4(0);
|
|
5528
|
-
}
|
|
5529
|
-
const globalVolumeAccumulator = this.decodeGlobalVolumeAccumulator(
|
|
5530
|
-
globalVolumeAccumulatorAccountInfo
|
|
5531
|
-
);
|
|
5532
|
-
const userVolumeAccumulator = this.decodeUserVolumeAccumulator(
|
|
5533
|
-
userVolumeAccumulatorAccountInfo
|
|
5534
|
-
);
|
|
5535
|
-
return totalUnclaimedTokens(globalVolumeAccumulator, userVolumeAccumulator);
|
|
5536
|
-
}
|
|
5537
|
-
async getTotalUnclaimedTokensBothPrograms(user) {
|
|
5538
|
-
return (await this.getTotalUnclaimedTokens(user)).add(
|
|
5539
|
-
await this.pumpAmmSdk.getTotalUnclaimedTokens(user)
|
|
5540
|
-
);
|
|
5541
|
-
}
|
|
5542
|
-
async getCurrentDayTokens(user) {
|
|
5543
|
-
const [
|
|
5544
|
-
globalVolumeAccumulatorAccountInfo,
|
|
5545
|
-
userVolumeAccumulatorAccountInfo
|
|
5546
|
-
] = await this.connection.getMultipleAccountsInfo([
|
|
5547
|
-
globalVolumeAccumulatorPda()[0],
|
|
5548
|
-
userVolumeAccumulatorPda(user)[0]
|
|
5549
|
-
]);
|
|
5550
|
-
if (!globalVolumeAccumulatorAccountInfo || !userVolumeAccumulatorAccountInfo) {
|
|
5551
|
-
return new BN4(0);
|
|
5552
|
-
}
|
|
5553
|
-
const globalVolumeAccumulator = this.decodeGlobalVolumeAccumulator(
|
|
5554
|
-
globalVolumeAccumulatorAccountInfo
|
|
5555
|
-
);
|
|
5556
|
-
const userVolumeAccumulator = this.decodeUserVolumeAccumulator(
|
|
5557
|
-
userVolumeAccumulatorAccountInfo
|
|
5558
|
-
);
|
|
5559
|
-
return currentDayTokens(globalVolumeAccumulator, userVolumeAccumulator);
|
|
5560
|
-
}
|
|
5561
|
-
async getCurrentDayTokensBothPrograms(user) {
|
|
5562
|
-
return (await this.getCurrentDayTokens(user)).add(
|
|
5563
|
-
await this.pumpAmmSdk.getCurrentDayTokens(user)
|
|
5564
|
-
);
|
|
5565
|
-
}
|
|
5566
7392
|
async syncUserVolumeAccumulator(user) {
|
|
5567
7393
|
return await this.offlinePumpProgram.methods.syncUserVolumeAccumulator().accountsPartial({ user }).instruction();
|
|
5568
7394
|
}
|
|
5569
7395
|
async syncUserVolumeAccumulatorBothPrograms(user) {
|
|
5570
7396
|
return [
|
|
5571
7397
|
await this.syncUserVolumeAccumulator(user),
|
|
5572
|
-
await
|
|
7398
|
+
await PUMP_AMM_SDK2.syncUserVolumeAccumulator(user)
|
|
5573
7399
|
];
|
|
5574
7400
|
}
|
|
5575
7401
|
async setCreator({
|
|
@@ -5601,7 +7427,7 @@ var PumpSdk = class {
|
|
|
5601
7427
|
}) {
|
|
5602
7428
|
return await this.getBuyInstructionInternal({
|
|
5603
7429
|
user,
|
|
5604
|
-
associatedUser:
|
|
7430
|
+
associatedUser: getAssociatedTokenAddressSync2(mint, user, true),
|
|
5605
7431
|
mint,
|
|
5606
7432
|
creator,
|
|
5607
7433
|
feeRecipient,
|
|
@@ -5654,78 +7480,60 @@ var PumpSdk = class {
|
|
|
5654
7480
|
return await this.offlinePumpProgram.methods.sell(amount, solAmount).accountsPartial({
|
|
5655
7481
|
feeRecipient,
|
|
5656
7482
|
mint,
|
|
5657
|
-
associatedUser:
|
|
7483
|
+
associatedUser: getAssociatedTokenAddressSync2(mint, user, true),
|
|
5658
7484
|
user,
|
|
5659
7485
|
creatorVault: creatorVaultPda(creator)
|
|
5660
7486
|
}).instruction();
|
|
5661
7487
|
}
|
|
5662
7488
|
};
|
|
7489
|
+
var PUMP_SDK = new PumpSdk();
|
|
5663
7490
|
function getFeeRecipient(global) {
|
|
5664
7491
|
const feeRecipients = [global.feeRecipient, ...global.feeRecipients];
|
|
5665
7492
|
return feeRecipients[Math.floor(Math.random() * feeRecipients.length)];
|
|
5666
7493
|
}
|
|
5667
7494
|
|
|
5668
7495
|
// src/pda.ts
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
)
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
[Buffer.from("fee_config"), PUMP_PROGRAM_ID.toBuffer()],
|
|
5679
|
-
PUMP_FEE_PROGRAM_ID
|
|
5680
|
-
)[0];
|
|
5681
|
-
}
|
|
7496
|
+
var import_buffer = __toESM(require_buffer());
|
|
7497
|
+
var GLOBAL_PDA = pumpPda([import_buffer.Buffer.from("global")]);
|
|
7498
|
+
var PUMP_FEE_CONFIG_PDA = pumpFeePda([
|
|
7499
|
+
import_buffer.Buffer.from("fee_config"),
|
|
7500
|
+
PUMP_PROGRAM_ID.toBuffer()
|
|
7501
|
+
]);
|
|
7502
|
+
var GLOBAL_VOLUME_ACCUMULATOR_PDA = pumpPda([
|
|
7503
|
+
import_buffer.Buffer.from("global_volume_accumulator")
|
|
7504
|
+
]);
|
|
5682
7505
|
function bondingCurvePda(mint) {
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
);
|
|
5687
|
-
return bondingCurvePda2;
|
|
7506
|
+
return pumpPda([
|
|
7507
|
+
import_buffer.Buffer.from("bonding-curve"),
|
|
7508
|
+
new PublicKey5(mint).toBuffer()
|
|
7509
|
+
]);
|
|
5688
7510
|
}
|
|
5689
7511
|
function creatorVaultPda(creator) {
|
|
5690
|
-
|
|
5691
|
-
[Buffer.from("creator-vault"), creator.toBuffer()],
|
|
5692
|
-
PUMP_PROGRAM_ID
|
|
5693
|
-
);
|
|
5694
|
-
return creatorVault;
|
|
7512
|
+
return pumpPda([import_buffer.Buffer.from("creator-vault"), creator.toBuffer()]);
|
|
5695
7513
|
}
|
|
5696
7514
|
function pumpPoolAuthorityPda(mint) {
|
|
5697
|
-
return
|
|
5698
|
-
[Buffer.from("pool-authority"), mint.toBuffer()],
|
|
5699
|
-
PUMP_PROGRAM_ID
|
|
5700
|
-
);
|
|
7515
|
+
return pumpPda([import_buffer.Buffer.from("pool-authority"), mint.toBuffer()]);
|
|
5701
7516
|
}
|
|
5702
7517
|
var CANONICAL_POOL_INDEX = 0;
|
|
5703
7518
|
function canonicalPumpPoolPda(mint) {
|
|
5704
|
-
const [pumpPoolAuthority] = pumpPoolAuthorityPda(mint);
|
|
5705
7519
|
return poolPda(
|
|
5706
7520
|
CANONICAL_POOL_INDEX,
|
|
5707
|
-
|
|
7521
|
+
pumpPoolAuthorityPda(mint),
|
|
5708
7522
|
mint,
|
|
5709
|
-
NATIVE_MINT2
|
|
5710
|
-
PUMP_AMM_PROGRAM_ID
|
|
5711
|
-
);
|
|
5712
|
-
}
|
|
5713
|
-
function globalVolumeAccumulatorPda() {
|
|
5714
|
-
return PublicKey4.findProgramAddressSync(
|
|
5715
|
-
[Buffer.from("global_volume_accumulator")],
|
|
5716
|
-
PUMP_PROGRAM_ID
|
|
7523
|
+
NATIVE_MINT2
|
|
5717
7524
|
);
|
|
5718
7525
|
}
|
|
5719
7526
|
function userVolumeAccumulatorPda(user) {
|
|
5720
|
-
return
|
|
5721
|
-
[Buffer.from("user_volume_accumulator"), user.toBuffer()],
|
|
5722
|
-
PUMP_PROGRAM_ID
|
|
5723
|
-
);
|
|
7527
|
+
return pumpPda([import_buffer.Buffer.from("user_volume_accumulator"), user.toBuffer()]);
|
|
5724
7528
|
}
|
|
5725
7529
|
export {
|
|
5726
7530
|
BONDING_CURVE_NEW_SIZE,
|
|
5727
7531
|
CANONICAL_POOL_INDEX,
|
|
7532
|
+
GLOBAL_PDA,
|
|
7533
|
+
GLOBAL_VOLUME_ACCUMULATOR_PDA,
|
|
7534
|
+
OnlinePumpSdk,
|
|
5728
7535
|
PUMP_AMM_PROGRAM_ID,
|
|
7536
|
+
PUMP_FEE_CONFIG_PDA,
|
|
5729
7537
|
PUMP_PROGRAM_ID,
|
|
5730
7538
|
PumpSdk,
|
|
5731
7539
|
bondingCurveMarketCap,
|
|
@@ -5741,12 +7549,22 @@ export {
|
|
|
5741
7549
|
getPumpProgram,
|
|
5742
7550
|
getSellSolAmountFromTokenAmount,
|
|
5743
7551
|
getSellSolAmountFromTokenAmountQuote,
|
|
5744
|
-
globalPda,
|
|
5745
|
-
globalVolumeAccumulatorPda,
|
|
5746
7552
|
newBondingCurve,
|
|
5747
|
-
pumpFeeConfigPda,
|
|
5748
7553
|
pump_default as pumpIdl,
|
|
5749
7554
|
pumpPoolAuthorityPda,
|
|
5750
7555
|
totalUnclaimedTokens,
|
|
5751
7556
|
userVolumeAccumulatorPda
|
|
5752
7557
|
};
|
|
7558
|
+
/*! Bundled license information:
|
|
7559
|
+
|
|
7560
|
+
ieee754/index.js:
|
|
7561
|
+
(*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
7562
|
+
|
|
7563
|
+
buffer/index.js:
|
|
7564
|
+
(*!
|
|
7565
|
+
* The buffer module from node.js, for the browser.
|
|
7566
|
+
*
|
|
7567
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
7568
|
+
* @license MIT
|
|
7569
|
+
*)
|
|
7570
|
+
*/
|