@t2000/sdk 0.37.0 → 0.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/index.cjs +4143 -130
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +4143 -130
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +4247 -237
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4254 -244
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/adapters/index.cjs
CHANGED
|
@@ -1,7 +1,413 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var transactions = require('@mysten/sui/transactions');
|
|
4
|
-
var
|
|
4
|
+
var jsonRpc = require('@mysten/sui/jsonRpc');
|
|
5
|
+
var utils = require('@mysten/sui/utils');
|
|
6
|
+
var pythSuiJs = require('@pythnetwork/pyth-sui-js');
|
|
7
|
+
var bcs$1 = require('@mysten/sui/bcs');
|
|
8
|
+
|
|
9
|
+
var __create = Object.create;
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
14
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __require = /* @__PURE__ */ ((x2) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x2, {
|
|
16
|
+
get: (a, b2) => (typeof require !== "undefined" ? require : a)[b2]
|
|
17
|
+
}) : x2)(function(x2) {
|
|
18
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
19
|
+
throw Error('Dynamic require of "' + x2 + '" is not supported');
|
|
20
|
+
});
|
|
21
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
22
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
+
!mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
|
|
41
|
+
// ../../node_modules/.pnpm/lodash.camelcase@4.3.0/node_modules/lodash.camelcase/index.js
|
|
42
|
+
var require_lodash = __commonJS({
|
|
43
|
+
"../../node_modules/.pnpm/lodash.camelcase@4.3.0/node_modules/lodash.camelcase/index.js"(exports$1, module) {
|
|
44
|
+
var symbolTag = "[object Symbol]";
|
|
45
|
+
var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
|
46
|
+
var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
|
|
47
|
+
var rsAstralRange = "\\ud800-\\udfff";
|
|
48
|
+
var rsComboMarksRange = "\\u0300-\\u036f\\ufe20-\\ufe23";
|
|
49
|
+
var rsComboSymbolsRange = "\\u20d0-\\u20f0";
|
|
50
|
+
var rsDingbatRange = "\\u2700-\\u27bf";
|
|
51
|
+
var rsLowerRange = "a-z\\xdf-\\xf6\\xf8-\\xff";
|
|
52
|
+
var rsMathOpRange = "\\xac\\xb1\\xd7\\xf7";
|
|
53
|
+
var rsNonCharRange = "\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf";
|
|
54
|
+
var rsPunctuationRange = "\\u2000-\\u206f";
|
|
55
|
+
var rsSpaceRange = " \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000";
|
|
56
|
+
var rsUpperRange = "A-Z\\xc0-\\xd6\\xd8-\\xde";
|
|
57
|
+
var rsVarRange = "\\ufe0e\\ufe0f";
|
|
58
|
+
var rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
|
|
59
|
+
var rsApos = "['\u2019]";
|
|
60
|
+
var rsAstral = "[" + rsAstralRange + "]";
|
|
61
|
+
var rsBreak = "[" + rsBreakRange + "]";
|
|
62
|
+
var rsCombo = "[" + rsComboMarksRange + rsComboSymbolsRange + "]";
|
|
63
|
+
var rsDigits = "\\d+";
|
|
64
|
+
var rsDingbat = "[" + rsDingbatRange + "]";
|
|
65
|
+
var rsLower = "[" + rsLowerRange + "]";
|
|
66
|
+
var rsMisc = "[^" + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + "]";
|
|
67
|
+
var rsFitz = "\\ud83c[\\udffb-\\udfff]";
|
|
68
|
+
var rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")";
|
|
69
|
+
var rsNonAstral = "[^" + rsAstralRange + "]";
|
|
70
|
+
var rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}";
|
|
71
|
+
var rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]";
|
|
72
|
+
var rsUpper = "[" + rsUpperRange + "]";
|
|
73
|
+
var rsZWJ = "\\u200d";
|
|
74
|
+
var rsLowerMisc = "(?:" + rsLower + "|" + rsMisc + ")";
|
|
75
|
+
var rsUpperMisc = "(?:" + rsUpper + "|" + rsMisc + ")";
|
|
76
|
+
var rsOptLowerContr = "(?:" + rsApos + "(?:d|ll|m|re|s|t|ve))?";
|
|
77
|
+
var rsOptUpperContr = "(?:" + rsApos + "(?:D|LL|M|RE|S|T|VE))?";
|
|
78
|
+
var reOptMod = rsModifier + "?";
|
|
79
|
+
var rsOptVar = "[" + rsVarRange + "]?";
|
|
80
|
+
var rsOptJoin = "(?:" + rsZWJ + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*";
|
|
81
|
+
var rsSeq = rsOptVar + reOptMod + rsOptJoin;
|
|
82
|
+
var rsEmoji = "(?:" + [rsDingbat, rsRegional, rsSurrPair].join("|") + ")" + rsSeq;
|
|
83
|
+
var rsSymbol = "(?:" + [rsNonAstral + rsCombo + "?", rsCombo, rsRegional, rsSurrPair, rsAstral].join("|") + ")";
|
|
84
|
+
var reApos = RegExp(rsApos, "g");
|
|
85
|
+
var reComboMark = RegExp(rsCombo, "g");
|
|
86
|
+
var reUnicode = RegExp(rsFitz + "(?=" + rsFitz + ")|" + rsSymbol + rsSeq, "g");
|
|
87
|
+
var reUnicodeWord = RegExp([
|
|
88
|
+
rsUpper + "?" + rsLower + "+" + rsOptLowerContr + "(?=" + [rsBreak, rsUpper, "$"].join("|") + ")",
|
|
89
|
+
rsUpperMisc + "+" + rsOptUpperContr + "(?=" + [rsBreak, rsUpper + rsLowerMisc, "$"].join("|") + ")",
|
|
90
|
+
rsUpper + "?" + rsLowerMisc + "+" + rsOptLowerContr,
|
|
91
|
+
rsUpper + "+" + rsOptUpperContr,
|
|
92
|
+
rsDigits,
|
|
93
|
+
rsEmoji
|
|
94
|
+
].join("|"), "g");
|
|
95
|
+
var reHasUnicode = RegExp("[" + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + "]");
|
|
96
|
+
var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
|
|
97
|
+
var deburredLetters = {
|
|
98
|
+
// Latin-1 Supplement block.
|
|
99
|
+
"\xC0": "A",
|
|
100
|
+
"\xC1": "A",
|
|
101
|
+
"\xC2": "A",
|
|
102
|
+
"\xC3": "A",
|
|
103
|
+
"\xC4": "A",
|
|
104
|
+
"\xC5": "A",
|
|
105
|
+
"\xE0": "a",
|
|
106
|
+
"\xE1": "a",
|
|
107
|
+
"\xE2": "a",
|
|
108
|
+
"\xE3": "a",
|
|
109
|
+
"\xE4": "a",
|
|
110
|
+
"\xE5": "a",
|
|
111
|
+
"\xC7": "C",
|
|
112
|
+
"\xE7": "c",
|
|
113
|
+
"\xD0": "D",
|
|
114
|
+
"\xF0": "d",
|
|
115
|
+
"\xC8": "E",
|
|
116
|
+
"\xC9": "E",
|
|
117
|
+
"\xCA": "E",
|
|
118
|
+
"\xCB": "E",
|
|
119
|
+
"\xE8": "e",
|
|
120
|
+
"\xE9": "e",
|
|
121
|
+
"\xEA": "e",
|
|
122
|
+
"\xEB": "e",
|
|
123
|
+
"\xCC": "I",
|
|
124
|
+
"\xCD": "I",
|
|
125
|
+
"\xCE": "I",
|
|
126
|
+
"\xCF": "I",
|
|
127
|
+
"\xEC": "i",
|
|
128
|
+
"\xED": "i",
|
|
129
|
+
"\xEE": "i",
|
|
130
|
+
"\xEF": "i",
|
|
131
|
+
"\xD1": "N",
|
|
132
|
+
"\xF1": "n",
|
|
133
|
+
"\xD2": "O",
|
|
134
|
+
"\xD3": "O",
|
|
135
|
+
"\xD4": "O",
|
|
136
|
+
"\xD5": "O",
|
|
137
|
+
"\xD6": "O",
|
|
138
|
+
"\xD8": "O",
|
|
139
|
+
"\xF2": "o",
|
|
140
|
+
"\xF3": "o",
|
|
141
|
+
"\xF4": "o",
|
|
142
|
+
"\xF5": "o",
|
|
143
|
+
"\xF6": "o",
|
|
144
|
+
"\xF8": "o",
|
|
145
|
+
"\xD9": "U",
|
|
146
|
+
"\xDA": "U",
|
|
147
|
+
"\xDB": "U",
|
|
148
|
+
"\xDC": "U",
|
|
149
|
+
"\xF9": "u",
|
|
150
|
+
"\xFA": "u",
|
|
151
|
+
"\xFB": "u",
|
|
152
|
+
"\xFC": "u",
|
|
153
|
+
"\xDD": "Y",
|
|
154
|
+
"\xFD": "y",
|
|
155
|
+
"\xFF": "y",
|
|
156
|
+
"\xC6": "Ae",
|
|
157
|
+
"\xE6": "ae",
|
|
158
|
+
"\xDE": "Th",
|
|
159
|
+
"\xFE": "th",
|
|
160
|
+
"\xDF": "ss",
|
|
161
|
+
// Latin Extended-A block.
|
|
162
|
+
"\u0100": "A",
|
|
163
|
+
"\u0102": "A",
|
|
164
|
+
"\u0104": "A",
|
|
165
|
+
"\u0101": "a",
|
|
166
|
+
"\u0103": "a",
|
|
167
|
+
"\u0105": "a",
|
|
168
|
+
"\u0106": "C",
|
|
169
|
+
"\u0108": "C",
|
|
170
|
+
"\u010A": "C",
|
|
171
|
+
"\u010C": "C",
|
|
172
|
+
"\u0107": "c",
|
|
173
|
+
"\u0109": "c",
|
|
174
|
+
"\u010B": "c",
|
|
175
|
+
"\u010D": "c",
|
|
176
|
+
"\u010E": "D",
|
|
177
|
+
"\u0110": "D",
|
|
178
|
+
"\u010F": "d",
|
|
179
|
+
"\u0111": "d",
|
|
180
|
+
"\u0112": "E",
|
|
181
|
+
"\u0114": "E",
|
|
182
|
+
"\u0116": "E",
|
|
183
|
+
"\u0118": "E",
|
|
184
|
+
"\u011A": "E",
|
|
185
|
+
"\u0113": "e",
|
|
186
|
+
"\u0115": "e",
|
|
187
|
+
"\u0117": "e",
|
|
188
|
+
"\u0119": "e",
|
|
189
|
+
"\u011B": "e",
|
|
190
|
+
"\u011C": "G",
|
|
191
|
+
"\u011E": "G",
|
|
192
|
+
"\u0120": "G",
|
|
193
|
+
"\u0122": "G",
|
|
194
|
+
"\u011D": "g",
|
|
195
|
+
"\u011F": "g",
|
|
196
|
+
"\u0121": "g",
|
|
197
|
+
"\u0123": "g",
|
|
198
|
+
"\u0124": "H",
|
|
199
|
+
"\u0126": "H",
|
|
200
|
+
"\u0125": "h",
|
|
201
|
+
"\u0127": "h",
|
|
202
|
+
"\u0128": "I",
|
|
203
|
+
"\u012A": "I",
|
|
204
|
+
"\u012C": "I",
|
|
205
|
+
"\u012E": "I",
|
|
206
|
+
"\u0130": "I",
|
|
207
|
+
"\u0129": "i",
|
|
208
|
+
"\u012B": "i",
|
|
209
|
+
"\u012D": "i",
|
|
210
|
+
"\u012F": "i",
|
|
211
|
+
"\u0131": "i",
|
|
212
|
+
"\u0134": "J",
|
|
213
|
+
"\u0135": "j",
|
|
214
|
+
"\u0136": "K",
|
|
215
|
+
"\u0137": "k",
|
|
216
|
+
"\u0138": "k",
|
|
217
|
+
"\u0139": "L",
|
|
218
|
+
"\u013B": "L",
|
|
219
|
+
"\u013D": "L",
|
|
220
|
+
"\u013F": "L",
|
|
221
|
+
"\u0141": "L",
|
|
222
|
+
"\u013A": "l",
|
|
223
|
+
"\u013C": "l",
|
|
224
|
+
"\u013E": "l",
|
|
225
|
+
"\u0140": "l",
|
|
226
|
+
"\u0142": "l",
|
|
227
|
+
"\u0143": "N",
|
|
228
|
+
"\u0145": "N",
|
|
229
|
+
"\u0147": "N",
|
|
230
|
+
"\u014A": "N",
|
|
231
|
+
"\u0144": "n",
|
|
232
|
+
"\u0146": "n",
|
|
233
|
+
"\u0148": "n",
|
|
234
|
+
"\u014B": "n",
|
|
235
|
+
"\u014C": "O",
|
|
236
|
+
"\u014E": "O",
|
|
237
|
+
"\u0150": "O",
|
|
238
|
+
"\u014D": "o",
|
|
239
|
+
"\u014F": "o",
|
|
240
|
+
"\u0151": "o",
|
|
241
|
+
"\u0154": "R",
|
|
242
|
+
"\u0156": "R",
|
|
243
|
+
"\u0158": "R",
|
|
244
|
+
"\u0155": "r",
|
|
245
|
+
"\u0157": "r",
|
|
246
|
+
"\u0159": "r",
|
|
247
|
+
"\u015A": "S",
|
|
248
|
+
"\u015C": "S",
|
|
249
|
+
"\u015E": "S",
|
|
250
|
+
"\u0160": "S",
|
|
251
|
+
"\u015B": "s",
|
|
252
|
+
"\u015D": "s",
|
|
253
|
+
"\u015F": "s",
|
|
254
|
+
"\u0161": "s",
|
|
255
|
+
"\u0162": "T",
|
|
256
|
+
"\u0164": "T",
|
|
257
|
+
"\u0166": "T",
|
|
258
|
+
"\u0163": "t",
|
|
259
|
+
"\u0165": "t",
|
|
260
|
+
"\u0167": "t",
|
|
261
|
+
"\u0168": "U",
|
|
262
|
+
"\u016A": "U",
|
|
263
|
+
"\u016C": "U",
|
|
264
|
+
"\u016E": "U",
|
|
265
|
+
"\u0170": "U",
|
|
266
|
+
"\u0172": "U",
|
|
267
|
+
"\u0169": "u",
|
|
268
|
+
"\u016B": "u",
|
|
269
|
+
"\u016D": "u",
|
|
270
|
+
"\u016F": "u",
|
|
271
|
+
"\u0171": "u",
|
|
272
|
+
"\u0173": "u",
|
|
273
|
+
"\u0174": "W",
|
|
274
|
+
"\u0175": "w",
|
|
275
|
+
"\u0176": "Y",
|
|
276
|
+
"\u0177": "y",
|
|
277
|
+
"\u0178": "Y",
|
|
278
|
+
"\u0179": "Z",
|
|
279
|
+
"\u017B": "Z",
|
|
280
|
+
"\u017D": "Z",
|
|
281
|
+
"\u017A": "z",
|
|
282
|
+
"\u017C": "z",
|
|
283
|
+
"\u017E": "z",
|
|
284
|
+
"\u0132": "IJ",
|
|
285
|
+
"\u0133": "ij",
|
|
286
|
+
"\u0152": "Oe",
|
|
287
|
+
"\u0153": "oe",
|
|
288
|
+
"\u0149": "'n",
|
|
289
|
+
"\u017F": "ss"
|
|
290
|
+
};
|
|
291
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
292
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
293
|
+
var root = freeGlobal || freeSelf || Function("return this")();
|
|
294
|
+
function arrayReduce(array, iteratee, accumulator, initAccum) {
|
|
295
|
+
var index = -1, length = array ? array.length : 0;
|
|
296
|
+
while (++index < length) {
|
|
297
|
+
accumulator = iteratee(accumulator, array[index], index, array);
|
|
298
|
+
}
|
|
299
|
+
return accumulator;
|
|
300
|
+
}
|
|
301
|
+
function asciiToArray(string) {
|
|
302
|
+
return string.split("");
|
|
303
|
+
}
|
|
304
|
+
function asciiWords(string) {
|
|
305
|
+
return string.match(reAsciiWord) || [];
|
|
306
|
+
}
|
|
307
|
+
function basePropertyOf(object) {
|
|
308
|
+
return function(key) {
|
|
309
|
+
return object == null ? void 0 : object[key];
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
var deburrLetter = basePropertyOf(deburredLetters);
|
|
313
|
+
function hasUnicode(string) {
|
|
314
|
+
return reHasUnicode.test(string);
|
|
315
|
+
}
|
|
316
|
+
function hasUnicodeWord(string) {
|
|
317
|
+
return reHasUnicodeWord.test(string);
|
|
318
|
+
}
|
|
319
|
+
function stringToArray(string) {
|
|
320
|
+
return hasUnicode(string) ? unicodeToArray(string) : asciiToArray(string);
|
|
321
|
+
}
|
|
322
|
+
function unicodeToArray(string) {
|
|
323
|
+
return string.match(reUnicode) || [];
|
|
324
|
+
}
|
|
325
|
+
function unicodeWords(string) {
|
|
326
|
+
return string.match(reUnicodeWord) || [];
|
|
327
|
+
}
|
|
328
|
+
var objectProto = Object.prototype;
|
|
329
|
+
var objectToString = objectProto.toString;
|
|
330
|
+
var Symbol2 = root.Symbol;
|
|
331
|
+
var symbolProto = Symbol2 ? Symbol2.prototype : void 0;
|
|
332
|
+
var symbolToString = symbolProto ? symbolProto.toString : void 0;
|
|
333
|
+
function baseSlice(array, start, end) {
|
|
334
|
+
var index = -1, length = array.length;
|
|
335
|
+
if (start < 0) {
|
|
336
|
+
start = -start > length ? 0 : length + start;
|
|
337
|
+
}
|
|
338
|
+
end = end > length ? length : end;
|
|
339
|
+
if (end < 0) {
|
|
340
|
+
end += length;
|
|
341
|
+
}
|
|
342
|
+
length = start > end ? 0 : end - start >>> 0;
|
|
343
|
+
start >>>= 0;
|
|
344
|
+
var result = Array(length);
|
|
345
|
+
while (++index < length) {
|
|
346
|
+
result[index] = array[index + start];
|
|
347
|
+
}
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
function baseToString(value) {
|
|
351
|
+
if (typeof value == "string") {
|
|
352
|
+
return value;
|
|
353
|
+
}
|
|
354
|
+
if (isSymbol(value)) {
|
|
355
|
+
return symbolToString ? symbolToString.call(value) : "";
|
|
356
|
+
}
|
|
357
|
+
var result = value + "";
|
|
358
|
+
return result == "0" && 1 / value == -Infinity ? "-0" : result;
|
|
359
|
+
}
|
|
360
|
+
function castSlice(array, start, end) {
|
|
361
|
+
var length = array.length;
|
|
362
|
+
end = end === void 0 ? length : end;
|
|
363
|
+
return !start && end >= length ? array : baseSlice(array, start, end);
|
|
364
|
+
}
|
|
365
|
+
function createCaseFirst(methodName) {
|
|
366
|
+
return function(string) {
|
|
367
|
+
string = toString(string);
|
|
368
|
+
var strSymbols = hasUnicode(string) ? stringToArray(string) : void 0;
|
|
369
|
+
var chr = strSymbols ? strSymbols[0] : string.charAt(0);
|
|
370
|
+
var trailing = strSymbols ? castSlice(strSymbols, 1).join("") : string.slice(1);
|
|
371
|
+
return chr[methodName]() + trailing;
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function createCompounder(callback) {
|
|
375
|
+
return function(string) {
|
|
376
|
+
return arrayReduce(words(deburr(string).replace(reApos, "")), callback, "");
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function isObjectLike(value) {
|
|
380
|
+
return !!value && typeof value == "object";
|
|
381
|
+
}
|
|
382
|
+
function isSymbol(value) {
|
|
383
|
+
return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
|
|
384
|
+
}
|
|
385
|
+
function toString(value) {
|
|
386
|
+
return value == null ? "" : baseToString(value);
|
|
387
|
+
}
|
|
388
|
+
var camelCase = createCompounder(function(result, word, index) {
|
|
389
|
+
word = word.toLowerCase();
|
|
390
|
+
return result + (index ? capitalize(word) : word);
|
|
391
|
+
});
|
|
392
|
+
function capitalize(string) {
|
|
393
|
+
return upperFirst(toString(string).toLowerCase());
|
|
394
|
+
}
|
|
395
|
+
function deburr(string) {
|
|
396
|
+
string = toString(string);
|
|
397
|
+
return string && string.replace(reLatin, deburrLetter).replace(reComboMark, "");
|
|
398
|
+
}
|
|
399
|
+
var upperFirst = createCaseFirst("toUpperCase");
|
|
400
|
+
function words(string, pattern, guard) {
|
|
401
|
+
string = toString(string);
|
|
402
|
+
pattern = pattern;
|
|
403
|
+
if (pattern === void 0) {
|
|
404
|
+
return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
|
|
405
|
+
}
|
|
406
|
+
return string.match(pattern) || [];
|
|
407
|
+
}
|
|
408
|
+
module.exports = camelCase;
|
|
409
|
+
}
|
|
410
|
+
});
|
|
5
411
|
|
|
6
412
|
// src/errors.ts
|
|
7
413
|
var T2000Error = class extends Error {
|
|
@@ -83,144 +489,3746 @@ var SUPPORTED_ASSETS = {
|
|
|
83
489
|
symbol: "GOLD",
|
|
84
490
|
displayName: "XAUM"
|
|
85
491
|
}
|
|
86
|
-
};
|
|
87
|
-
var STABLE_ASSETS = ["USDC"];
|
|
88
|
-
var ALL_NAVI_ASSETS = Object.keys(SUPPORTED_ASSETS);
|
|
89
|
-
var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
|
|
90
|
-
var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
|
|
91
|
-
var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0xf420ec0dcad44433042fb56e1413fb88d3ff65be94fcf425ef9ff750164590e8";
|
|
92
|
-
process.env.T2000_API_URL ?? "https://api.t2000.ai";
|
|
93
|
-
|
|
94
|
-
// src/adapters/registry.ts
|
|
95
|
-
var ProtocolRegistry = class {
|
|
96
|
-
lending = /* @__PURE__ */ new Map();
|
|
97
|
-
registerLending(adapter) {
|
|
98
|
-
this.lending.set(adapter.id, adapter);
|
|
492
|
+
};
|
|
493
|
+
var STABLE_ASSETS = ["USDC"];
|
|
494
|
+
var ALL_NAVI_ASSETS = Object.keys(SUPPORTED_ASSETS);
|
|
495
|
+
var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
|
|
496
|
+
var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
|
|
497
|
+
var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0xf420ec0dcad44433042fb56e1413fb88d3ff65be94fcf425ef9ff750164590e8";
|
|
498
|
+
process.env.T2000_API_URL ?? "https://api.t2000.ai";
|
|
499
|
+
|
|
500
|
+
// src/adapters/registry.ts
|
|
501
|
+
var ProtocolRegistry = class {
|
|
502
|
+
lending = /* @__PURE__ */ new Map();
|
|
503
|
+
registerLending(adapter) {
|
|
504
|
+
this.lending.set(adapter.id, adapter);
|
|
505
|
+
}
|
|
506
|
+
async bestSaveRate(asset) {
|
|
507
|
+
const candidates = [];
|
|
508
|
+
for (const adapter of this.lending.values()) {
|
|
509
|
+
if (!adapter.supportedAssets.includes(asset)) continue;
|
|
510
|
+
if (!adapter.capabilities.includes("save")) continue;
|
|
511
|
+
try {
|
|
512
|
+
const rate = await adapter.getRates(asset);
|
|
513
|
+
candidates.push({ adapter, rate });
|
|
514
|
+
} catch {
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (candidates.length === 0) {
|
|
518
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `No lending adapter supports saving ${asset}`);
|
|
519
|
+
}
|
|
520
|
+
candidates.sort((a, b2) => b2.rate.saveApy - a.rate.saveApy);
|
|
521
|
+
return candidates[0];
|
|
522
|
+
}
|
|
523
|
+
async bestBorrowRate(asset, opts) {
|
|
524
|
+
const candidates = [];
|
|
525
|
+
for (const adapter of this.lending.values()) {
|
|
526
|
+
if (!adapter.supportedAssets.includes(asset)) continue;
|
|
527
|
+
if (!adapter.capabilities.includes("borrow")) continue;
|
|
528
|
+
if (opts?.requireSameAssetBorrow && !adapter.supportsSameAssetBorrow) continue;
|
|
529
|
+
try {
|
|
530
|
+
const rate = await adapter.getRates(asset);
|
|
531
|
+
candidates.push({ adapter, rate });
|
|
532
|
+
} catch {
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (candidates.length === 0) {
|
|
536
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `No lending adapter supports borrowing ${asset}`);
|
|
537
|
+
}
|
|
538
|
+
candidates.sort((a, b2) => a.rate.borrowApy - b2.rate.borrowApy);
|
|
539
|
+
return candidates[0];
|
|
540
|
+
}
|
|
541
|
+
async bestSaveRateAcrossAssets() {
|
|
542
|
+
const candidates = [];
|
|
543
|
+
for (const asset of STABLE_ASSETS) {
|
|
544
|
+
for (const adapter of this.lending.values()) {
|
|
545
|
+
if (!adapter.supportedAssets.includes(asset)) continue;
|
|
546
|
+
if (!adapter.capabilities.includes("save")) continue;
|
|
547
|
+
try {
|
|
548
|
+
const rate = await adapter.getRates(asset);
|
|
549
|
+
candidates.push({ adapter, rate, asset });
|
|
550
|
+
} catch {
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
if (candidates.length === 0) {
|
|
555
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", "No lending adapter found for any stablecoin");
|
|
556
|
+
}
|
|
557
|
+
candidates.sort((a, b2) => b2.rate.saveApy - a.rate.saveApy);
|
|
558
|
+
return candidates[0];
|
|
559
|
+
}
|
|
560
|
+
async allRatesAcrossAssets() {
|
|
561
|
+
const results = [];
|
|
562
|
+
const seen = /* @__PURE__ */ new Set();
|
|
563
|
+
for (const asset of STABLE_ASSETS) {
|
|
564
|
+
if (seen.has(asset)) continue;
|
|
565
|
+
seen.add(asset);
|
|
566
|
+
for (const adapter of this.lending.values()) {
|
|
567
|
+
if (!adapter.supportedAssets.includes(asset)) continue;
|
|
568
|
+
try {
|
|
569
|
+
const rates = await adapter.getRates(asset);
|
|
570
|
+
if (rates.saveApy > 0 || rates.borrowApy > 0) {
|
|
571
|
+
results.push({ protocol: adapter.name, protocolId: adapter.id, asset, rates });
|
|
572
|
+
}
|
|
573
|
+
} catch {
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return results;
|
|
578
|
+
}
|
|
579
|
+
async allRates(asset) {
|
|
580
|
+
const results = [];
|
|
581
|
+
for (const adapter of this.lending.values()) {
|
|
582
|
+
if (!adapter.supportedAssets.includes(asset)) continue;
|
|
583
|
+
try {
|
|
584
|
+
const rates = await adapter.getRates(asset);
|
|
585
|
+
results.push({ protocol: adapter.name, protocolId: adapter.id, rates });
|
|
586
|
+
} catch {
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return results;
|
|
590
|
+
}
|
|
591
|
+
async allPositions(address) {
|
|
592
|
+
const results = [];
|
|
593
|
+
const errors = [];
|
|
594
|
+
for (const adapter of this.lending.values()) {
|
|
595
|
+
try {
|
|
596
|
+
const positions = await adapter.getPositions(address);
|
|
597
|
+
if (positions.supplies.length > 0 || positions.borrows.length > 0) {
|
|
598
|
+
results.push({ protocol: adapter.name, protocolId: adapter.id, positions });
|
|
599
|
+
}
|
|
600
|
+
} catch (err) {
|
|
601
|
+
errors.push(`${adapter.name}: ${err instanceof Error ? err.message : String(err)}`);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
if (results.length === 0 && errors.length > 0) {
|
|
605
|
+
throw new T2000Error("PROTOCOL_UNAVAILABLE", `Protocol queries failed (${errors.length}/${this.lending.size}): ${errors.join("; ")}`);
|
|
606
|
+
}
|
|
607
|
+
return results;
|
|
608
|
+
}
|
|
609
|
+
getLending(id) {
|
|
610
|
+
return this.lending.get(id);
|
|
611
|
+
}
|
|
612
|
+
listLending() {
|
|
613
|
+
return [...this.lending.values()];
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
// src/utils/format.ts
|
|
618
|
+
function stableToRaw(amount, decimals) {
|
|
619
|
+
return BigInt(Math.round(amount * 10 ** decimals));
|
|
620
|
+
}
|
|
621
|
+
var ASSET_LOOKUP = /* @__PURE__ */ new Map();
|
|
622
|
+
for (const [key, info] of Object.entries(SUPPORTED_ASSETS)) {
|
|
623
|
+
ASSET_LOOKUP.set(key.toUpperCase(), key);
|
|
624
|
+
if (info.displayName && info.displayName.toUpperCase() !== key.toUpperCase()) {
|
|
625
|
+
ASSET_LOOKUP.set(info.displayName.toUpperCase(), key);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
function normalizeAsset(input) {
|
|
629
|
+
return ASSET_LOOKUP.get(input.toUpperCase()) ?? input;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// ../../node_modules/.pnpm/@mysten+bcs@2.0.2/node_modules/@mysten/bcs/dist/uleb.mjs
|
|
633
|
+
function ulebEncode(num) {
|
|
634
|
+
let bigNum = BigInt(num);
|
|
635
|
+
const arr = [];
|
|
636
|
+
let len = 0;
|
|
637
|
+
if (bigNum === 0n) return [0];
|
|
638
|
+
while (bigNum > 0) {
|
|
639
|
+
arr[len] = Number(bigNum & 127n);
|
|
640
|
+
bigNum >>= 7n;
|
|
641
|
+
if (bigNum > 0n) arr[len] |= 128;
|
|
642
|
+
len += 1;
|
|
643
|
+
}
|
|
644
|
+
return arr;
|
|
645
|
+
}
|
|
646
|
+
function ulebDecode(arr) {
|
|
647
|
+
let total = 0n;
|
|
648
|
+
let shift = 0n;
|
|
649
|
+
let len = 0;
|
|
650
|
+
while (true) {
|
|
651
|
+
if (len >= arr.length) throw new Error("ULEB decode error: buffer overflow");
|
|
652
|
+
const byte = arr[len];
|
|
653
|
+
len += 1;
|
|
654
|
+
total += BigInt(byte & 127) << shift;
|
|
655
|
+
if ((byte & 128) === 0) break;
|
|
656
|
+
shift += 7n;
|
|
657
|
+
}
|
|
658
|
+
if (total > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error("ULEB decode error: value exceeds MAX_SAFE_INTEGER");
|
|
659
|
+
return {
|
|
660
|
+
value: Number(total),
|
|
661
|
+
length: len
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// ../../node_modules/.pnpm/@mysten+bcs@2.0.2/node_modules/@mysten/bcs/dist/reader.mjs
|
|
666
|
+
var BcsReader = class {
|
|
667
|
+
/**
|
|
668
|
+
* @param {Uint8Array} data Data to use as a buffer.
|
|
669
|
+
*/
|
|
670
|
+
constructor(data) {
|
|
671
|
+
this.bytePosition = 0;
|
|
672
|
+
this.dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Shift current cursor position by `bytes`.
|
|
676
|
+
*
|
|
677
|
+
* @param {Number} bytes Number of bytes to
|
|
678
|
+
* @returns {this} Self for possible chaining.
|
|
679
|
+
*/
|
|
680
|
+
shift(bytes) {
|
|
681
|
+
this.bytePosition += bytes;
|
|
682
|
+
return this;
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Read U8 value from the buffer and shift cursor by 1.
|
|
686
|
+
* @returns
|
|
687
|
+
*/
|
|
688
|
+
read8() {
|
|
689
|
+
const value = this.dataView.getUint8(this.bytePosition);
|
|
690
|
+
this.shift(1);
|
|
691
|
+
return value;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Read U16 value from the buffer and shift cursor by 2.
|
|
695
|
+
* @returns
|
|
696
|
+
*/
|
|
697
|
+
read16() {
|
|
698
|
+
const value = this.dataView.getUint16(this.bytePosition, true);
|
|
699
|
+
this.shift(2);
|
|
700
|
+
return value;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Read U32 value from the buffer and shift cursor by 4.
|
|
704
|
+
* @returns
|
|
705
|
+
*/
|
|
706
|
+
read32() {
|
|
707
|
+
const value = this.dataView.getUint32(this.bytePosition, true);
|
|
708
|
+
this.shift(4);
|
|
709
|
+
return value;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Read U64 value from the buffer and shift cursor by 8.
|
|
713
|
+
* @returns
|
|
714
|
+
*/
|
|
715
|
+
read64() {
|
|
716
|
+
const value1 = this.read32();
|
|
717
|
+
const result = this.read32().toString(16) + value1.toString(16).padStart(8, "0");
|
|
718
|
+
return BigInt("0x" + result).toString(10);
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Read U128 value from the buffer and shift cursor by 16.
|
|
722
|
+
*/
|
|
723
|
+
read128() {
|
|
724
|
+
const value1 = BigInt(this.read64());
|
|
725
|
+
const result = BigInt(this.read64()).toString(16) + value1.toString(16).padStart(16, "0");
|
|
726
|
+
return BigInt("0x" + result).toString(10);
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Read U128 value from the buffer and shift cursor by 32.
|
|
730
|
+
* @returns
|
|
731
|
+
*/
|
|
732
|
+
read256() {
|
|
733
|
+
const value1 = BigInt(this.read128());
|
|
734
|
+
const result = BigInt(this.read128()).toString(16) + value1.toString(16).padStart(32, "0");
|
|
735
|
+
return BigInt("0x" + result).toString(10);
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Read `num` number of bytes from the buffer and shift cursor by `num`.
|
|
739
|
+
* @param num Number of bytes to read.
|
|
740
|
+
*/
|
|
741
|
+
readBytes(num) {
|
|
742
|
+
const start = this.bytePosition + this.dataView.byteOffset;
|
|
743
|
+
const value = new Uint8Array(this.dataView.buffer, start, num);
|
|
744
|
+
this.shift(num);
|
|
745
|
+
return value;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Read ULEB value - an integer of varying size. Used for enum indexes and
|
|
749
|
+
* vector lengths.
|
|
750
|
+
* @returns {Number} The ULEB value.
|
|
751
|
+
*/
|
|
752
|
+
readULEB() {
|
|
753
|
+
const start = this.bytePosition + this.dataView.byteOffset;
|
|
754
|
+
const { value, length } = ulebDecode(new Uint8Array(this.dataView.buffer, start));
|
|
755
|
+
this.shift(length);
|
|
756
|
+
return value;
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Read a BCS vector: read a length and then apply function `cb` X times
|
|
760
|
+
* where X is the length of the vector, defined as ULEB in BCS bytes.
|
|
761
|
+
* @param cb Callback to process elements of vector.
|
|
762
|
+
* @returns {Array<Any>} Array of the resulting values, returned by callback.
|
|
763
|
+
*/
|
|
764
|
+
readVec(cb) {
|
|
765
|
+
const length = this.readULEB();
|
|
766
|
+
const result = [];
|
|
767
|
+
for (let i = 0; i < length; i++) result.push(cb(this, i, length));
|
|
768
|
+
return result;
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
// ../../node_modules/.pnpm/@scure+base@2.0.0/node_modules/@scure/base/index.js
|
|
773
|
+
function isBytes(a) {
|
|
774
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
775
|
+
}
|
|
776
|
+
function isArrayOf(isString, arr) {
|
|
777
|
+
if (!Array.isArray(arr))
|
|
778
|
+
return false;
|
|
779
|
+
if (arr.length === 0)
|
|
780
|
+
return true;
|
|
781
|
+
if (isString) {
|
|
782
|
+
return arr.every((item) => typeof item === "string");
|
|
783
|
+
} else {
|
|
784
|
+
return arr.every((item) => Number.isSafeInteger(item));
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
function astr(label, input) {
|
|
788
|
+
if (typeof input !== "string")
|
|
789
|
+
throw new Error(`${label}: string expected`);
|
|
790
|
+
return true;
|
|
791
|
+
}
|
|
792
|
+
function anumber(n) {
|
|
793
|
+
if (!Number.isSafeInteger(n))
|
|
794
|
+
throw new Error(`invalid integer: ${n}`);
|
|
795
|
+
}
|
|
796
|
+
function aArr(input) {
|
|
797
|
+
if (!Array.isArray(input))
|
|
798
|
+
throw new Error("array expected");
|
|
799
|
+
}
|
|
800
|
+
function astrArr(label, input) {
|
|
801
|
+
if (!isArrayOf(true, input))
|
|
802
|
+
throw new Error(`${label}: array of strings expected`);
|
|
803
|
+
}
|
|
804
|
+
function anumArr(label, input) {
|
|
805
|
+
if (!isArrayOf(false, input))
|
|
806
|
+
throw new Error(`${label}: array of numbers expected`);
|
|
807
|
+
}
|
|
808
|
+
// @__NO_SIDE_EFFECTS__
|
|
809
|
+
function chain(...args) {
|
|
810
|
+
const id = (a) => a;
|
|
811
|
+
const wrap = (a, b2) => (c) => a(b2(c));
|
|
812
|
+
const encode = args.map((x2) => x2.encode).reduceRight(wrap, id);
|
|
813
|
+
const decode = args.map((x2) => x2.decode).reduce(wrap, id);
|
|
814
|
+
return { encode, decode };
|
|
815
|
+
}
|
|
816
|
+
// @__NO_SIDE_EFFECTS__
|
|
817
|
+
function alphabet(letters) {
|
|
818
|
+
const lettersA = letters.split("") ;
|
|
819
|
+
const len = lettersA.length;
|
|
820
|
+
astrArr("alphabet", lettersA);
|
|
821
|
+
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
822
|
+
return {
|
|
823
|
+
encode: (digits) => {
|
|
824
|
+
aArr(digits);
|
|
825
|
+
return digits.map((i) => {
|
|
826
|
+
if (!Number.isSafeInteger(i) || i < 0 || i >= len)
|
|
827
|
+
throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
|
|
828
|
+
return lettersA[i];
|
|
829
|
+
});
|
|
830
|
+
},
|
|
831
|
+
decode: (input) => {
|
|
832
|
+
aArr(input);
|
|
833
|
+
return input.map((letter) => {
|
|
834
|
+
astr("alphabet.decode", letter);
|
|
835
|
+
const i = indexes.get(letter);
|
|
836
|
+
if (i === void 0)
|
|
837
|
+
throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
838
|
+
return i;
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
// @__NO_SIDE_EFFECTS__
|
|
844
|
+
function join(separator = "") {
|
|
845
|
+
astr("join", separator);
|
|
846
|
+
return {
|
|
847
|
+
encode: (from) => {
|
|
848
|
+
astrArr("join.decode", from);
|
|
849
|
+
return from.join(separator);
|
|
850
|
+
},
|
|
851
|
+
decode: (to) => {
|
|
852
|
+
astr("join.decode", to);
|
|
853
|
+
return to.split(separator);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
function convertRadix(data, from, to) {
|
|
858
|
+
if (from < 2)
|
|
859
|
+
throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
|
|
860
|
+
if (to < 2)
|
|
861
|
+
throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
|
|
862
|
+
aArr(data);
|
|
863
|
+
if (!data.length)
|
|
864
|
+
return [];
|
|
865
|
+
let pos = 0;
|
|
866
|
+
const res = [];
|
|
867
|
+
const digits = Array.from(data, (d) => {
|
|
868
|
+
anumber(d);
|
|
869
|
+
if (d < 0 || d >= from)
|
|
870
|
+
throw new Error(`invalid integer: ${d}`);
|
|
871
|
+
return d;
|
|
872
|
+
});
|
|
873
|
+
const dlen = digits.length;
|
|
874
|
+
while (true) {
|
|
875
|
+
let carry = 0;
|
|
876
|
+
let done = true;
|
|
877
|
+
for (let i = pos; i < dlen; i++) {
|
|
878
|
+
const digit = digits[i];
|
|
879
|
+
const fromCarry = from * carry;
|
|
880
|
+
const digitBase = fromCarry + digit;
|
|
881
|
+
if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
|
|
882
|
+
throw new Error("convertRadix: carry overflow");
|
|
883
|
+
}
|
|
884
|
+
const div = digitBase / to;
|
|
885
|
+
carry = digitBase % to;
|
|
886
|
+
const rounded = Math.floor(div);
|
|
887
|
+
digits[i] = rounded;
|
|
888
|
+
if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
|
|
889
|
+
throw new Error("convertRadix: carry overflow");
|
|
890
|
+
if (!done)
|
|
891
|
+
continue;
|
|
892
|
+
else if (!rounded)
|
|
893
|
+
pos = i;
|
|
894
|
+
else
|
|
895
|
+
done = false;
|
|
896
|
+
}
|
|
897
|
+
res.push(carry);
|
|
898
|
+
if (done)
|
|
899
|
+
break;
|
|
900
|
+
}
|
|
901
|
+
for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
|
|
902
|
+
res.push(0);
|
|
903
|
+
return res.reverse();
|
|
904
|
+
}
|
|
905
|
+
// @__NO_SIDE_EFFECTS__
|
|
906
|
+
function radix(num) {
|
|
907
|
+
anumber(num);
|
|
908
|
+
const _256 = 2 ** 8;
|
|
909
|
+
return {
|
|
910
|
+
encode: (bytes) => {
|
|
911
|
+
if (!isBytes(bytes))
|
|
912
|
+
throw new Error("radix.encode input should be Uint8Array");
|
|
913
|
+
return convertRadix(Array.from(bytes), _256, num);
|
|
914
|
+
},
|
|
915
|
+
decode: (digits) => {
|
|
916
|
+
anumArr("radix.decode", digits);
|
|
917
|
+
return Uint8Array.from(convertRadix(digits, num, _256));
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
|
|
922
|
+
var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
923
|
+
|
|
924
|
+
// ../../node_modules/.pnpm/@mysten+utils@0.3.1/node_modules/@mysten/utils/dist/b58.mjs
|
|
925
|
+
var toBase58 = (buffer) => base58.encode(buffer);
|
|
926
|
+
var fromBase58 = (str) => base58.decode(str);
|
|
927
|
+
|
|
928
|
+
// ../../node_modules/.pnpm/@mysten+utils@0.3.1/node_modules/@mysten/utils/dist/b64.mjs
|
|
929
|
+
function fromBase64(base64String) {
|
|
930
|
+
return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));
|
|
931
|
+
}
|
|
932
|
+
var CHUNK_SIZE = 8192;
|
|
933
|
+
function toBase64(bytes) {
|
|
934
|
+
if (bytes.length < CHUNK_SIZE) return btoa(String.fromCharCode(...bytes));
|
|
935
|
+
let output = "";
|
|
936
|
+
for (var i = 0; i < bytes.length; i += CHUNK_SIZE) {
|
|
937
|
+
const chunk = bytes.slice(i, i + CHUNK_SIZE);
|
|
938
|
+
output += String.fromCharCode(...chunk);
|
|
939
|
+
}
|
|
940
|
+
return btoa(output);
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// ../../node_modules/.pnpm/@mysten+utils@0.3.1/node_modules/@mysten/utils/dist/hex.mjs
|
|
944
|
+
function fromHex(hexStr) {
|
|
945
|
+
const normalized = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr;
|
|
946
|
+
const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}`;
|
|
947
|
+
const intArr = padded.match(/[0-9a-fA-F]{2}/g)?.map((byte) => parseInt(byte, 16)) ?? [];
|
|
948
|
+
if (intArr.length !== padded.length / 2) throw new Error(`Invalid hex string ${hexStr}`);
|
|
949
|
+
return Uint8Array.from(intArr);
|
|
950
|
+
}
|
|
951
|
+
function toHex(bytes) {
|
|
952
|
+
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// ../../node_modules/.pnpm/@mysten+bcs@2.0.2/node_modules/@mysten/bcs/dist/utils.mjs
|
|
956
|
+
function encodeStr(data, encoding) {
|
|
957
|
+
switch (encoding) {
|
|
958
|
+
case "base58":
|
|
959
|
+
return toBase58(data);
|
|
960
|
+
case "base64":
|
|
961
|
+
return toBase64(data);
|
|
962
|
+
case "hex":
|
|
963
|
+
return toHex(data);
|
|
964
|
+
default:
|
|
965
|
+
throw new Error("Unsupported encoding, supported values are: base64, hex");
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
// ../../node_modules/.pnpm/@mysten+bcs@2.0.2/node_modules/@mysten/bcs/dist/writer.mjs
|
|
970
|
+
var BcsWriter = class {
|
|
971
|
+
constructor({ initialSize = 1024, maxSize = Infinity, allocateSize = 1024 } = {}) {
|
|
972
|
+
this.bytePosition = 0;
|
|
973
|
+
this.size = initialSize;
|
|
974
|
+
this.maxSize = maxSize;
|
|
975
|
+
this.allocateSize = allocateSize;
|
|
976
|
+
this.dataView = new DataView(new ArrayBuffer(initialSize));
|
|
977
|
+
}
|
|
978
|
+
ensureSizeOrGrow(bytes) {
|
|
979
|
+
const requiredSize = this.bytePosition + bytes;
|
|
980
|
+
if (requiredSize > this.size) {
|
|
981
|
+
const nextSize = Math.min(this.maxSize, Math.max(this.size + requiredSize, this.size + this.allocateSize));
|
|
982
|
+
if (requiredSize > nextSize) throw new Error(`Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${requiredSize}`);
|
|
983
|
+
this.size = nextSize;
|
|
984
|
+
const nextBuffer = new ArrayBuffer(this.size);
|
|
985
|
+
new Uint8Array(nextBuffer).set(new Uint8Array(this.dataView.buffer));
|
|
986
|
+
this.dataView = new DataView(nextBuffer);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Shift current cursor position by `bytes`.
|
|
991
|
+
*
|
|
992
|
+
* @param {Number} bytes Number of bytes to
|
|
993
|
+
* @returns {this} Self for possible chaining.
|
|
994
|
+
*/
|
|
995
|
+
shift(bytes) {
|
|
996
|
+
this.bytePosition += bytes;
|
|
997
|
+
return this;
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Write a U8 value into a buffer and shift cursor position by 1.
|
|
1001
|
+
* @param {Number} value Value to write.
|
|
1002
|
+
* @returns {this}
|
|
1003
|
+
*/
|
|
1004
|
+
write8(value) {
|
|
1005
|
+
this.ensureSizeOrGrow(1);
|
|
1006
|
+
this.dataView.setUint8(this.bytePosition, Number(value));
|
|
1007
|
+
return this.shift(1);
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Write a U8 value into a buffer and shift cursor position by 1.
|
|
1011
|
+
* @param {Number} value Value to write.
|
|
1012
|
+
* @returns {this}
|
|
1013
|
+
*/
|
|
1014
|
+
writeBytes(bytes) {
|
|
1015
|
+
this.ensureSizeOrGrow(bytes.length);
|
|
1016
|
+
for (let i = 0; i < bytes.length; i++) this.dataView.setUint8(this.bytePosition + i, bytes[i]);
|
|
1017
|
+
return this.shift(bytes.length);
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Write a U16 value into a buffer and shift cursor position by 2.
|
|
1021
|
+
* @param {Number} value Value to write.
|
|
1022
|
+
* @returns {this}
|
|
1023
|
+
*/
|
|
1024
|
+
write16(value) {
|
|
1025
|
+
this.ensureSizeOrGrow(2);
|
|
1026
|
+
this.dataView.setUint16(this.bytePosition, Number(value), true);
|
|
1027
|
+
return this.shift(2);
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Write a U32 value into a buffer and shift cursor position by 4.
|
|
1031
|
+
* @param {Number} value Value to write.
|
|
1032
|
+
* @returns {this}
|
|
1033
|
+
*/
|
|
1034
|
+
write32(value) {
|
|
1035
|
+
this.ensureSizeOrGrow(4);
|
|
1036
|
+
this.dataView.setUint32(this.bytePosition, Number(value), true);
|
|
1037
|
+
return this.shift(4);
|
|
1038
|
+
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Write a U64 value into a buffer and shift cursor position by 8.
|
|
1041
|
+
* @param {bigint} value Value to write.
|
|
1042
|
+
* @returns {this}
|
|
1043
|
+
*/
|
|
1044
|
+
write64(value) {
|
|
1045
|
+
toLittleEndian(BigInt(value), 8).forEach((el) => this.write8(el));
|
|
1046
|
+
return this;
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Write a U128 value into a buffer and shift cursor position by 16.
|
|
1050
|
+
*
|
|
1051
|
+
* @param {bigint} value Value to write.
|
|
1052
|
+
* @returns {this}
|
|
1053
|
+
*/
|
|
1054
|
+
write128(value) {
|
|
1055
|
+
toLittleEndian(BigInt(value), 16).forEach((el) => this.write8(el));
|
|
1056
|
+
return this;
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Write a U256 value into a buffer and shift cursor position by 16.
|
|
1060
|
+
*
|
|
1061
|
+
* @param {bigint} value Value to write.
|
|
1062
|
+
* @returns {this}
|
|
1063
|
+
*/
|
|
1064
|
+
write256(value) {
|
|
1065
|
+
toLittleEndian(BigInt(value), 32).forEach((el) => this.write8(el));
|
|
1066
|
+
return this;
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Write a ULEB value into a buffer and shift cursor position by number of bytes
|
|
1070
|
+
* written.
|
|
1071
|
+
* @param {Number} value Value to write.
|
|
1072
|
+
* @returns {this}
|
|
1073
|
+
*/
|
|
1074
|
+
writeULEB(value) {
|
|
1075
|
+
ulebEncode(value).forEach((el) => this.write8(el));
|
|
1076
|
+
return this;
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Write a vector into a buffer by first writing the vector length and then calling
|
|
1080
|
+
* a callback on each passed value.
|
|
1081
|
+
*
|
|
1082
|
+
* @param {Array<Any>} vector Array of elements to write.
|
|
1083
|
+
* @param {WriteVecCb} cb Callback to call on each element of the vector.
|
|
1084
|
+
* @returns {this}
|
|
1085
|
+
*/
|
|
1086
|
+
writeVec(vector2, cb) {
|
|
1087
|
+
this.writeULEB(vector2.length);
|
|
1088
|
+
Array.from(vector2).forEach((el, i) => cb(this, el, i, vector2.length));
|
|
1089
|
+
return this;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Adds support for iterations over the object.
|
|
1093
|
+
* @returns {Uint8Array}
|
|
1094
|
+
*/
|
|
1095
|
+
*[Symbol.iterator]() {
|
|
1096
|
+
for (let i = 0; i < this.bytePosition; i++) yield this.dataView.getUint8(i);
|
|
1097
|
+
return this.toBytes();
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Get underlying buffer taking only value bytes (in case initial buffer size was bigger).
|
|
1101
|
+
* @returns {Uint8Array} Resulting bcs.
|
|
1102
|
+
*/
|
|
1103
|
+
toBytes() {
|
|
1104
|
+
return new Uint8Array(this.dataView.buffer.slice(0, this.bytePosition));
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Represent data as 'hex' or 'base64'
|
|
1108
|
+
* @param encoding Encoding to use: 'base64' or 'hex'
|
|
1109
|
+
*/
|
|
1110
|
+
toString(encoding) {
|
|
1111
|
+
return encodeStr(this.toBytes(), encoding);
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
function toLittleEndian(bigint, size) {
|
|
1115
|
+
const result = new Uint8Array(size);
|
|
1116
|
+
let i = 0;
|
|
1117
|
+
while (bigint > 0) {
|
|
1118
|
+
result[i] = Number(bigint % BigInt(256));
|
|
1119
|
+
bigint = bigint / BigInt(256);
|
|
1120
|
+
i += 1;
|
|
1121
|
+
}
|
|
1122
|
+
return result;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
// ../../node_modules/.pnpm/@mysten+bcs@2.0.2/node_modules/@mysten/bcs/dist/bcs-type.mjs
|
|
1126
|
+
var BcsType = class BcsType2 {
|
|
1127
|
+
#write;
|
|
1128
|
+
#serialize;
|
|
1129
|
+
constructor(options) {
|
|
1130
|
+
this.name = options.name;
|
|
1131
|
+
this.read = options.read;
|
|
1132
|
+
this.serializedSize = options.serializedSize ?? (() => null);
|
|
1133
|
+
this.#write = options.write;
|
|
1134
|
+
this.#serialize = options.serialize ?? ((value, options$1) => {
|
|
1135
|
+
const writer = new BcsWriter({
|
|
1136
|
+
initialSize: this.serializedSize(value) ?? void 0,
|
|
1137
|
+
...options$1
|
|
1138
|
+
});
|
|
1139
|
+
this.#write(value, writer);
|
|
1140
|
+
return writer.toBytes();
|
|
1141
|
+
});
|
|
1142
|
+
this.validate = options.validate ?? (() => {
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
write(value, writer) {
|
|
1146
|
+
this.validate(value);
|
|
1147
|
+
this.#write(value, writer);
|
|
1148
|
+
}
|
|
1149
|
+
serialize(value, options) {
|
|
1150
|
+
this.validate(value);
|
|
1151
|
+
return new SerializedBcs(this, this.#serialize(value, options));
|
|
1152
|
+
}
|
|
1153
|
+
parse(bytes) {
|
|
1154
|
+
const reader = new BcsReader(bytes);
|
|
1155
|
+
return this.read(reader);
|
|
1156
|
+
}
|
|
1157
|
+
fromHex(hex) {
|
|
1158
|
+
return this.parse(fromHex(hex));
|
|
1159
|
+
}
|
|
1160
|
+
fromBase58(b64) {
|
|
1161
|
+
return this.parse(fromBase58(b64));
|
|
1162
|
+
}
|
|
1163
|
+
fromBase64(b64) {
|
|
1164
|
+
return this.parse(fromBase64(b64));
|
|
1165
|
+
}
|
|
1166
|
+
transform({ name, input, output, validate }) {
|
|
1167
|
+
return new BcsType2({
|
|
1168
|
+
name: name ?? this.name,
|
|
1169
|
+
read: (reader) => output ? output(this.read(reader)) : this.read(reader),
|
|
1170
|
+
write: (value, writer) => this.#write(input ? input(value) : value, writer),
|
|
1171
|
+
serializedSize: (value) => this.serializedSize(input ? input(value) : value),
|
|
1172
|
+
serialize: (value, options) => this.#serialize(input ? input(value) : value, options),
|
|
1173
|
+
validate: (value) => {
|
|
1174
|
+
validate?.(value);
|
|
1175
|
+
this.validate(input ? input(value) : value);
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
var SERIALIZED_BCS_BRAND = /* @__PURE__ */ Symbol.for("@mysten/serialized-bcs");
|
|
1181
|
+
var SerializedBcs = class {
|
|
1182
|
+
#schema;
|
|
1183
|
+
#bytes;
|
|
1184
|
+
get [SERIALIZED_BCS_BRAND]() {
|
|
1185
|
+
return true;
|
|
1186
|
+
}
|
|
1187
|
+
constructor(schema, bytes) {
|
|
1188
|
+
this.#schema = schema;
|
|
1189
|
+
this.#bytes = bytes;
|
|
1190
|
+
}
|
|
1191
|
+
toBytes() {
|
|
1192
|
+
return this.#bytes;
|
|
1193
|
+
}
|
|
1194
|
+
toHex() {
|
|
1195
|
+
return toHex(this.#bytes);
|
|
1196
|
+
}
|
|
1197
|
+
toBase64() {
|
|
1198
|
+
return toBase64(this.#bytes);
|
|
1199
|
+
}
|
|
1200
|
+
toBase58() {
|
|
1201
|
+
return toBase58(this.#bytes);
|
|
1202
|
+
}
|
|
1203
|
+
parse() {
|
|
1204
|
+
return this.#schema.parse(this.#bytes);
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
function fixedSizeBcsType({ size, ...options }) {
|
|
1208
|
+
return new BcsType({
|
|
1209
|
+
...options,
|
|
1210
|
+
serializedSize: () => size
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
function uIntBcsType({ readMethod, writeMethod, ...options }) {
|
|
1214
|
+
return fixedSizeBcsType({
|
|
1215
|
+
...options,
|
|
1216
|
+
read: (reader) => reader[readMethod](),
|
|
1217
|
+
write: (value, writer) => writer[writeMethod](value),
|
|
1218
|
+
validate: (value) => {
|
|
1219
|
+
if (value < 0 || value > options.maxValue) throw new TypeError(`Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`);
|
|
1220
|
+
options.validate?.(value);
|
|
1221
|
+
}
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
function bigUIntBcsType({ readMethod, writeMethod, ...options }) {
|
|
1225
|
+
return fixedSizeBcsType({
|
|
1226
|
+
...options,
|
|
1227
|
+
read: (reader) => reader[readMethod](),
|
|
1228
|
+
write: (value, writer) => writer[writeMethod](BigInt(value)),
|
|
1229
|
+
validate: (val) => {
|
|
1230
|
+
const value = BigInt(val);
|
|
1231
|
+
if (value < 0 || value > options.maxValue) throw new TypeError(`Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`);
|
|
1232
|
+
options.validate?.(value);
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
function dynamicSizeBcsType({ serialize, ...options }) {
|
|
1237
|
+
const type = new BcsType({
|
|
1238
|
+
...options,
|
|
1239
|
+
serialize,
|
|
1240
|
+
write: (value, writer) => {
|
|
1241
|
+
for (const byte of type.serialize(value).toBytes()) writer.write8(byte);
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
return type;
|
|
1245
|
+
}
|
|
1246
|
+
function stringLikeBcsType({ toBytes, fromBytes, ...options }) {
|
|
1247
|
+
return new BcsType({
|
|
1248
|
+
...options,
|
|
1249
|
+
read: (reader) => {
|
|
1250
|
+
const length = reader.readULEB();
|
|
1251
|
+
return fromBytes(reader.readBytes(length));
|
|
1252
|
+
},
|
|
1253
|
+
write: (hex, writer) => {
|
|
1254
|
+
const bytes = toBytes(hex);
|
|
1255
|
+
writer.writeULEB(bytes.length);
|
|
1256
|
+
for (let i = 0; i < bytes.length; i++) writer.write8(bytes[i]);
|
|
1257
|
+
},
|
|
1258
|
+
serialize: (value) => {
|
|
1259
|
+
const bytes = toBytes(value);
|
|
1260
|
+
const size = ulebEncode(bytes.length);
|
|
1261
|
+
const result = new Uint8Array(size.length + bytes.length);
|
|
1262
|
+
result.set(size, 0);
|
|
1263
|
+
result.set(bytes, size.length);
|
|
1264
|
+
return result;
|
|
1265
|
+
},
|
|
1266
|
+
validate: (value) => {
|
|
1267
|
+
if (typeof value !== "string") throw new TypeError(`Invalid ${options.name} value: ${value}. Expected string`);
|
|
1268
|
+
options.validate?.(value);
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
function lazyBcsType(cb) {
|
|
1273
|
+
let lazyType = null;
|
|
1274
|
+
function getType() {
|
|
1275
|
+
if (!lazyType) lazyType = cb();
|
|
1276
|
+
return lazyType;
|
|
1277
|
+
}
|
|
1278
|
+
return new BcsType({
|
|
1279
|
+
name: "lazy",
|
|
1280
|
+
read: (data) => getType().read(data),
|
|
1281
|
+
serializedSize: (value) => getType().serializedSize(value),
|
|
1282
|
+
write: (value, writer) => getType().write(value, writer),
|
|
1283
|
+
serialize: (value, options) => getType().serialize(value, options).toBytes()
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
var BcsStruct = class extends BcsType {
|
|
1287
|
+
constructor({ name, fields, ...options }) {
|
|
1288
|
+
const canonicalOrder = Object.entries(fields);
|
|
1289
|
+
super({
|
|
1290
|
+
name,
|
|
1291
|
+
serializedSize: (values) => {
|
|
1292
|
+
let total = 0;
|
|
1293
|
+
for (const [field, type] of canonicalOrder) {
|
|
1294
|
+
const size = type.serializedSize(values[field]);
|
|
1295
|
+
if (size == null) return null;
|
|
1296
|
+
total += size;
|
|
1297
|
+
}
|
|
1298
|
+
return total;
|
|
1299
|
+
},
|
|
1300
|
+
read: (reader) => {
|
|
1301
|
+
const result = {};
|
|
1302
|
+
for (const [field, type] of canonicalOrder) result[field] = type.read(reader);
|
|
1303
|
+
return result;
|
|
1304
|
+
},
|
|
1305
|
+
write: (value, writer) => {
|
|
1306
|
+
for (const [field, type] of canonicalOrder) type.write(value[field], writer);
|
|
1307
|
+
},
|
|
1308
|
+
...options,
|
|
1309
|
+
validate: (value) => {
|
|
1310
|
+
options?.validate?.(value);
|
|
1311
|
+
if (typeof value !== "object" || value == null) throw new TypeError(`Expected object, found ${typeof value}`);
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1316
|
+
var BcsEnum = class extends BcsType {
|
|
1317
|
+
constructor({ fields, ...options }) {
|
|
1318
|
+
const canonicalOrder = Object.entries(fields);
|
|
1319
|
+
super({
|
|
1320
|
+
read: (reader) => {
|
|
1321
|
+
const index = reader.readULEB();
|
|
1322
|
+
const enumEntry = canonicalOrder[index];
|
|
1323
|
+
if (!enumEntry) throw new TypeError(`Unknown value ${index} for enum ${options.name}`);
|
|
1324
|
+
const [kind, type] = enumEntry;
|
|
1325
|
+
return {
|
|
1326
|
+
[kind]: type?.read(reader) ?? true,
|
|
1327
|
+
$kind: kind
|
|
1328
|
+
};
|
|
1329
|
+
},
|
|
1330
|
+
write: (value, writer) => {
|
|
1331
|
+
const [name, val] = Object.entries(value).filter(([name$1]) => Object.hasOwn(fields, name$1))[0];
|
|
1332
|
+
for (let i = 0; i < canonicalOrder.length; i++) {
|
|
1333
|
+
const [optionName, optionType] = canonicalOrder[i];
|
|
1334
|
+
if (optionName === name) {
|
|
1335
|
+
writer.writeULEB(i);
|
|
1336
|
+
optionType?.write(val, writer);
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
},
|
|
1341
|
+
...options,
|
|
1342
|
+
validate: (value) => {
|
|
1343
|
+
options?.validate?.(value);
|
|
1344
|
+
if (typeof value !== "object" || value == null) throw new TypeError(`Expected object, found ${typeof value}`);
|
|
1345
|
+
const keys = Object.keys(value).filter((k2) => value[k2] !== void 0 && Object.hasOwn(fields, k2));
|
|
1346
|
+
if (keys.length !== 1) throw new TypeError(`Expected object with one key, but found ${keys.length} for type ${options.name}}`);
|
|
1347
|
+
const [variant] = keys;
|
|
1348
|
+
if (!Object.hasOwn(fields, variant)) throw new TypeError(`Invalid enum variant ${variant}`);
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
var BcsTuple = class extends BcsType {
|
|
1354
|
+
constructor({ fields, name, ...options }) {
|
|
1355
|
+
super({
|
|
1356
|
+
name: name ?? `(${fields.map((t) => t.name).join(", ")})`,
|
|
1357
|
+
serializedSize: (values) => {
|
|
1358
|
+
let total = 0;
|
|
1359
|
+
for (let i = 0; i < fields.length; i++) {
|
|
1360
|
+
const size = fields[i].serializedSize(values[i]);
|
|
1361
|
+
if (size == null) return null;
|
|
1362
|
+
total += size;
|
|
1363
|
+
}
|
|
1364
|
+
return total;
|
|
1365
|
+
},
|
|
1366
|
+
read: (reader) => {
|
|
1367
|
+
const result = [];
|
|
1368
|
+
for (const field of fields) result.push(field.read(reader));
|
|
1369
|
+
return result;
|
|
1370
|
+
},
|
|
1371
|
+
write: (value, writer) => {
|
|
1372
|
+
for (let i = 0; i < fields.length; i++) fields[i].write(value[i], writer);
|
|
1373
|
+
},
|
|
1374
|
+
...options,
|
|
1375
|
+
validate: (value) => {
|
|
1376
|
+
options?.validate?.(value);
|
|
1377
|
+
if (!Array.isArray(value)) throw new TypeError(`Expected array, found ${typeof value}`);
|
|
1378
|
+
if (value.length !== fields.length) throw new TypeError(`Expected array of length ${fields.length}, found ${value.length}`);
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1384
|
+
// ../../node_modules/.pnpm/@mysten+bcs@2.0.2/node_modules/@mysten/bcs/dist/bcs.mjs
|
|
1385
|
+
function fixedArray(size, type, options) {
|
|
1386
|
+
return new BcsType({
|
|
1387
|
+
read: (reader) => {
|
|
1388
|
+
const result = new Array(size);
|
|
1389
|
+
for (let i = 0; i < size; i++) result[i] = type.read(reader);
|
|
1390
|
+
return result;
|
|
1391
|
+
},
|
|
1392
|
+
write: (value, writer) => {
|
|
1393
|
+
for (const item of value) type.write(item, writer);
|
|
1394
|
+
},
|
|
1395
|
+
...options,
|
|
1396
|
+
name: options?.name ?? `${type.name}[${size}]`,
|
|
1397
|
+
validate: (value) => {
|
|
1398
|
+
options?.validate?.(value);
|
|
1399
|
+
if (!value || typeof value !== "object" || !("length" in value)) throw new TypeError(`Expected array, found ${typeof value}`);
|
|
1400
|
+
if (value.length !== size) throw new TypeError(`Expected array of length ${size}, found ${value.length}`);
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
function option(type) {
|
|
1405
|
+
return bcs.enum(`Option<${type.name}>`, {
|
|
1406
|
+
None: null,
|
|
1407
|
+
Some: type
|
|
1408
|
+
}).transform({
|
|
1409
|
+
input: (value) => {
|
|
1410
|
+
if (value == null) return { None: true };
|
|
1411
|
+
return { Some: value };
|
|
1412
|
+
},
|
|
1413
|
+
output: (value) => {
|
|
1414
|
+
if (value.$kind === "Some") return value.Some;
|
|
1415
|
+
return null;
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
function vector(type, options) {
|
|
1420
|
+
return new BcsType({
|
|
1421
|
+
read: (reader) => {
|
|
1422
|
+
const length = reader.readULEB();
|
|
1423
|
+
const result = new Array(length);
|
|
1424
|
+
for (let i = 0; i < length; i++) result[i] = type.read(reader);
|
|
1425
|
+
return result;
|
|
1426
|
+
},
|
|
1427
|
+
write: (value, writer) => {
|
|
1428
|
+
writer.writeULEB(value.length);
|
|
1429
|
+
for (const item of value) type.write(item, writer);
|
|
1430
|
+
},
|
|
1431
|
+
...options,
|
|
1432
|
+
name: options?.name ?? `vector<${type.name}>`,
|
|
1433
|
+
validate: (value) => {
|
|
1434
|
+
options?.validate?.(value);
|
|
1435
|
+
if (!value || typeof value !== "object" || !("length" in value)) throw new TypeError(`Expected array, found ${typeof value}`);
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
function compareBcsBytes(a, b2) {
|
|
1440
|
+
for (let i = 0; i < Math.min(a.length, b2.length); i++) if (a[i] !== b2[i]) return a[i] - b2[i];
|
|
1441
|
+
return a.length - b2.length;
|
|
1442
|
+
}
|
|
1443
|
+
function map(keyType, valueType) {
|
|
1444
|
+
return new BcsType({
|
|
1445
|
+
name: `Map<${keyType.name}, ${valueType.name}>`,
|
|
1446
|
+
read: (reader) => {
|
|
1447
|
+
const length = reader.readULEB();
|
|
1448
|
+
const result = /* @__PURE__ */ new Map();
|
|
1449
|
+
for (let i = 0; i < length; i++) result.set(keyType.read(reader), valueType.read(reader));
|
|
1450
|
+
return result;
|
|
1451
|
+
},
|
|
1452
|
+
write: (value, writer) => {
|
|
1453
|
+
const entries = [...value.entries()].map(([key, val]) => [keyType.serialize(key).toBytes(), val]);
|
|
1454
|
+
entries.sort(([a], [b2]) => compareBcsBytes(a, b2));
|
|
1455
|
+
writer.writeULEB(entries.length);
|
|
1456
|
+
for (const [keyBytes, val] of entries) {
|
|
1457
|
+
writer.writeBytes(keyBytes);
|
|
1458
|
+
valueType.write(val, writer);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
var bcs = {
|
|
1464
|
+
u8(options) {
|
|
1465
|
+
return uIntBcsType({
|
|
1466
|
+
readMethod: "read8",
|
|
1467
|
+
writeMethod: "write8",
|
|
1468
|
+
size: 1,
|
|
1469
|
+
maxValue: 2 ** 8 - 1,
|
|
1470
|
+
...options,
|
|
1471
|
+
name: options?.name ?? "u8"
|
|
1472
|
+
});
|
|
1473
|
+
},
|
|
1474
|
+
u16(options) {
|
|
1475
|
+
return uIntBcsType({
|
|
1476
|
+
readMethod: "read16",
|
|
1477
|
+
writeMethod: "write16",
|
|
1478
|
+
size: 2,
|
|
1479
|
+
maxValue: 2 ** 16 - 1,
|
|
1480
|
+
...options,
|
|
1481
|
+
name: options?.name ?? "u16"
|
|
1482
|
+
});
|
|
1483
|
+
},
|
|
1484
|
+
u32(options) {
|
|
1485
|
+
return uIntBcsType({
|
|
1486
|
+
readMethod: "read32",
|
|
1487
|
+
writeMethod: "write32",
|
|
1488
|
+
size: 4,
|
|
1489
|
+
maxValue: 2 ** 32 - 1,
|
|
1490
|
+
...options,
|
|
1491
|
+
name: options?.name ?? "u32"
|
|
1492
|
+
});
|
|
1493
|
+
},
|
|
1494
|
+
u64(options) {
|
|
1495
|
+
return bigUIntBcsType({
|
|
1496
|
+
readMethod: "read64",
|
|
1497
|
+
writeMethod: "write64",
|
|
1498
|
+
size: 8,
|
|
1499
|
+
maxValue: 2n ** 64n - 1n,
|
|
1500
|
+
...options,
|
|
1501
|
+
name: options?.name ?? "u64"
|
|
1502
|
+
});
|
|
1503
|
+
},
|
|
1504
|
+
u128(options) {
|
|
1505
|
+
return bigUIntBcsType({
|
|
1506
|
+
readMethod: "read128",
|
|
1507
|
+
writeMethod: "write128",
|
|
1508
|
+
size: 16,
|
|
1509
|
+
maxValue: 2n ** 128n - 1n,
|
|
1510
|
+
...options,
|
|
1511
|
+
name: options?.name ?? "u128"
|
|
1512
|
+
});
|
|
1513
|
+
},
|
|
1514
|
+
u256(options) {
|
|
1515
|
+
return bigUIntBcsType({
|
|
1516
|
+
readMethod: "read256",
|
|
1517
|
+
writeMethod: "write256",
|
|
1518
|
+
size: 32,
|
|
1519
|
+
maxValue: 2n ** 256n - 1n,
|
|
1520
|
+
...options,
|
|
1521
|
+
name: options?.name ?? "u256"
|
|
1522
|
+
});
|
|
1523
|
+
},
|
|
1524
|
+
bool(options) {
|
|
1525
|
+
return fixedSizeBcsType({
|
|
1526
|
+
size: 1,
|
|
1527
|
+
read: (reader) => reader.read8() === 1,
|
|
1528
|
+
write: (value, writer) => writer.write8(value ? 1 : 0),
|
|
1529
|
+
...options,
|
|
1530
|
+
name: options?.name ?? "bool",
|
|
1531
|
+
validate: (value) => {
|
|
1532
|
+
options?.validate?.(value);
|
|
1533
|
+
if (typeof value !== "boolean") throw new TypeError(`Expected boolean, found ${typeof value}`);
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1536
|
+
},
|
|
1537
|
+
uleb128(options) {
|
|
1538
|
+
return dynamicSizeBcsType({
|
|
1539
|
+
read: (reader) => reader.readULEB(),
|
|
1540
|
+
serialize: (value) => {
|
|
1541
|
+
return Uint8Array.from(ulebEncode(value));
|
|
1542
|
+
},
|
|
1543
|
+
...options,
|
|
1544
|
+
name: options?.name ?? "uleb128"
|
|
1545
|
+
});
|
|
1546
|
+
},
|
|
1547
|
+
bytes(size, options) {
|
|
1548
|
+
return fixedSizeBcsType({
|
|
1549
|
+
size,
|
|
1550
|
+
read: (reader) => reader.readBytes(size),
|
|
1551
|
+
write: (value, writer) => {
|
|
1552
|
+
writer.writeBytes(new Uint8Array(value));
|
|
1553
|
+
},
|
|
1554
|
+
...options,
|
|
1555
|
+
name: options?.name ?? `bytes[${size}]`,
|
|
1556
|
+
validate: (value) => {
|
|
1557
|
+
options?.validate?.(value);
|
|
1558
|
+
if (!value || typeof value !== "object" || !("length" in value)) throw new TypeError(`Expected array, found ${typeof value}`);
|
|
1559
|
+
if (value.length !== size) throw new TypeError(`Expected array of length ${size}, found ${value.length}`);
|
|
1560
|
+
}
|
|
1561
|
+
});
|
|
1562
|
+
},
|
|
1563
|
+
byteVector(options) {
|
|
1564
|
+
return new BcsType({
|
|
1565
|
+
read: (reader) => {
|
|
1566
|
+
const length = reader.readULEB();
|
|
1567
|
+
return reader.readBytes(length);
|
|
1568
|
+
},
|
|
1569
|
+
write: (value, writer) => {
|
|
1570
|
+
const array = new Uint8Array(value);
|
|
1571
|
+
writer.writeULEB(array.length);
|
|
1572
|
+
writer.writeBytes(array);
|
|
1573
|
+
},
|
|
1574
|
+
...options,
|
|
1575
|
+
name: options?.name ?? "vector<u8>",
|
|
1576
|
+
serializedSize: (value) => {
|
|
1577
|
+
const length = "length" in value ? value.length : null;
|
|
1578
|
+
return length == null ? null : ulebEncode(length).length + length;
|
|
1579
|
+
},
|
|
1580
|
+
validate: (value) => {
|
|
1581
|
+
options?.validate?.(value);
|
|
1582
|
+
if (!value || typeof value !== "object" || !("length" in value)) throw new TypeError(`Expected array, found ${typeof value}`);
|
|
1583
|
+
}
|
|
1584
|
+
});
|
|
1585
|
+
},
|
|
1586
|
+
string(options) {
|
|
1587
|
+
return stringLikeBcsType({
|
|
1588
|
+
toBytes: (value) => new TextEncoder().encode(value),
|
|
1589
|
+
fromBytes: (bytes) => new TextDecoder().decode(bytes),
|
|
1590
|
+
...options,
|
|
1591
|
+
name: options?.name ?? "string"
|
|
1592
|
+
});
|
|
1593
|
+
},
|
|
1594
|
+
fixedArray,
|
|
1595
|
+
option,
|
|
1596
|
+
vector,
|
|
1597
|
+
tuple(fields, options) {
|
|
1598
|
+
return new BcsTuple({
|
|
1599
|
+
fields,
|
|
1600
|
+
...options
|
|
1601
|
+
});
|
|
1602
|
+
},
|
|
1603
|
+
struct(name, fields, options) {
|
|
1604
|
+
return new BcsStruct({
|
|
1605
|
+
name,
|
|
1606
|
+
fields,
|
|
1607
|
+
...options
|
|
1608
|
+
});
|
|
1609
|
+
},
|
|
1610
|
+
enum(name, fields, options) {
|
|
1611
|
+
return new BcsEnum({
|
|
1612
|
+
name,
|
|
1613
|
+
fields,
|
|
1614
|
+
...options
|
|
1615
|
+
});
|
|
1616
|
+
},
|
|
1617
|
+
map,
|
|
1618
|
+
lazy(cb) {
|
|
1619
|
+
return lazyBcsType(cb);
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
|
|
1623
|
+
// ../../node_modules/.pnpm/@naviprotocol+lending@1.4.0_patch_hash=f5361914099eac610a549dc571b1248d29f6a1f4195ed017_05ba4b180e35cb4ccd9db84691f20fcb/node_modules/@naviprotocol/lending/dist/index.esm.js
|
|
1624
|
+
__toESM(require_lodash());
|
|
1625
|
+
|
|
1626
|
+
// ../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
|
|
1627
|
+
var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
1628
|
+
var mathceil = Math.ceil;
|
|
1629
|
+
var mathfloor = Math.floor;
|
|
1630
|
+
var bignumberError = "[BigNumber Error] ";
|
|
1631
|
+
var tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ";
|
|
1632
|
+
var BASE = 1e14;
|
|
1633
|
+
var LOG_BASE = 14;
|
|
1634
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
1635
|
+
var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
|
|
1636
|
+
var SQRT_BASE = 1e7;
|
|
1637
|
+
var MAX = 1e9;
|
|
1638
|
+
function clone(configObject) {
|
|
1639
|
+
var div, convertBase, parseNumeric, P2 = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
|
|
1640
|
+
prefix: "",
|
|
1641
|
+
groupSize: 3,
|
|
1642
|
+
secondaryGroupSize: 0,
|
|
1643
|
+
groupSeparator: ",",
|
|
1644
|
+
decimalSeparator: ".",
|
|
1645
|
+
fractionGroupSize: 0,
|
|
1646
|
+
fractionGroupSeparator: "\xA0",
|
|
1647
|
+
// non-breaking space
|
|
1648
|
+
suffix: ""
|
|
1649
|
+
}, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
|
|
1650
|
+
function BigNumber2(v, b2) {
|
|
1651
|
+
var alphabet2, c, caseChanged, e, i, isNum, len, str, x2 = this;
|
|
1652
|
+
if (!(x2 instanceof BigNumber2)) return new BigNumber2(v, b2);
|
|
1653
|
+
if (b2 == null) {
|
|
1654
|
+
if (v && v._isBigNumber === true) {
|
|
1655
|
+
x2.s = v.s;
|
|
1656
|
+
if (!v.c || v.e > MAX_EXP) {
|
|
1657
|
+
x2.c = x2.e = null;
|
|
1658
|
+
} else if (v.e < MIN_EXP) {
|
|
1659
|
+
x2.c = [x2.e = 0];
|
|
1660
|
+
} else {
|
|
1661
|
+
x2.e = v.e;
|
|
1662
|
+
x2.c = v.c.slice();
|
|
1663
|
+
}
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
if ((isNum = typeof v == "number") && v * 0 == 0) {
|
|
1667
|
+
x2.s = 1 / v < 0 ? (v = -v, -1) : 1;
|
|
1668
|
+
if (v === ~~v) {
|
|
1669
|
+
for (e = 0, i = v; i >= 10; i /= 10, e++) ;
|
|
1670
|
+
if (e > MAX_EXP) {
|
|
1671
|
+
x2.c = x2.e = null;
|
|
1672
|
+
} else {
|
|
1673
|
+
x2.e = e;
|
|
1674
|
+
x2.c = [v];
|
|
1675
|
+
}
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
str = String(v);
|
|
1679
|
+
} else {
|
|
1680
|
+
if (!isNumeric.test(str = String(v))) return parseNumeric(x2, str, isNum);
|
|
1681
|
+
x2.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
|
1682
|
+
}
|
|
1683
|
+
if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
|
|
1684
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
1685
|
+
if (e < 0) e = i;
|
|
1686
|
+
e += +str.slice(i + 1);
|
|
1687
|
+
str = str.substring(0, i);
|
|
1688
|
+
} else if (e < 0) {
|
|
1689
|
+
e = str.length;
|
|
1690
|
+
}
|
|
1691
|
+
} else {
|
|
1692
|
+
intCheck(b2, 2, ALPHABET.length, "Base");
|
|
1693
|
+
if (b2 == 10 && alphabetHasNormalDecimalDigits) {
|
|
1694
|
+
x2 = new BigNumber2(v);
|
|
1695
|
+
return round(x2, DECIMAL_PLACES + x2.e + 1, ROUNDING_MODE);
|
|
1696
|
+
}
|
|
1697
|
+
str = String(v);
|
|
1698
|
+
if (isNum = typeof v == "number") {
|
|
1699
|
+
if (v * 0 != 0) return parseNumeric(x2, str, isNum, b2);
|
|
1700
|
+
x2.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
|
|
1701
|
+
if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
|
|
1702
|
+
throw Error(tooManyDigits + v);
|
|
1703
|
+
}
|
|
1704
|
+
} else {
|
|
1705
|
+
x2.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
|
1706
|
+
}
|
|
1707
|
+
alphabet2 = ALPHABET.slice(0, b2);
|
|
1708
|
+
e = i = 0;
|
|
1709
|
+
for (len = str.length; i < len; i++) {
|
|
1710
|
+
if (alphabet2.indexOf(c = str.charAt(i)) < 0) {
|
|
1711
|
+
if (c == ".") {
|
|
1712
|
+
if (i > e) {
|
|
1713
|
+
e = len;
|
|
1714
|
+
continue;
|
|
1715
|
+
}
|
|
1716
|
+
} else if (!caseChanged) {
|
|
1717
|
+
if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
|
|
1718
|
+
caseChanged = true;
|
|
1719
|
+
i = -1;
|
|
1720
|
+
e = 0;
|
|
1721
|
+
continue;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
return parseNumeric(x2, String(v), isNum, b2);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
isNum = false;
|
|
1728
|
+
str = convertBase(str, b2, 10, x2.s);
|
|
1729
|
+
if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
|
|
1730
|
+
else e = str.length;
|
|
1731
|
+
}
|
|
1732
|
+
for (i = 0; str.charCodeAt(i) === 48; i++) ;
|
|
1733
|
+
for (len = str.length; str.charCodeAt(--len) === 48; ) ;
|
|
1734
|
+
if (str = str.slice(i, ++len)) {
|
|
1735
|
+
len -= i;
|
|
1736
|
+
if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
|
|
1737
|
+
throw Error(tooManyDigits + x2.s * v);
|
|
1738
|
+
}
|
|
1739
|
+
if ((e = e - i - 1) > MAX_EXP) {
|
|
1740
|
+
x2.c = x2.e = null;
|
|
1741
|
+
} else if (e < MIN_EXP) {
|
|
1742
|
+
x2.c = [x2.e = 0];
|
|
1743
|
+
} else {
|
|
1744
|
+
x2.e = e;
|
|
1745
|
+
x2.c = [];
|
|
1746
|
+
i = (e + 1) % LOG_BASE;
|
|
1747
|
+
if (e < 0) i += LOG_BASE;
|
|
1748
|
+
if (i < len) {
|
|
1749
|
+
if (i) x2.c.push(+str.slice(0, i));
|
|
1750
|
+
for (len -= LOG_BASE; i < len; ) {
|
|
1751
|
+
x2.c.push(+str.slice(i, i += LOG_BASE));
|
|
1752
|
+
}
|
|
1753
|
+
i = LOG_BASE - (str = str.slice(i)).length;
|
|
1754
|
+
} else {
|
|
1755
|
+
i -= len;
|
|
1756
|
+
}
|
|
1757
|
+
for (; i--; str += "0") ;
|
|
1758
|
+
x2.c.push(+str);
|
|
1759
|
+
}
|
|
1760
|
+
} else {
|
|
1761
|
+
x2.c = [x2.e = 0];
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
BigNumber2.clone = clone;
|
|
1765
|
+
BigNumber2.ROUND_UP = 0;
|
|
1766
|
+
BigNumber2.ROUND_DOWN = 1;
|
|
1767
|
+
BigNumber2.ROUND_CEIL = 2;
|
|
1768
|
+
BigNumber2.ROUND_FLOOR = 3;
|
|
1769
|
+
BigNumber2.ROUND_HALF_UP = 4;
|
|
1770
|
+
BigNumber2.ROUND_HALF_DOWN = 5;
|
|
1771
|
+
BigNumber2.ROUND_HALF_EVEN = 6;
|
|
1772
|
+
BigNumber2.ROUND_HALF_CEIL = 7;
|
|
1773
|
+
BigNumber2.ROUND_HALF_FLOOR = 8;
|
|
1774
|
+
BigNumber2.EUCLID = 9;
|
|
1775
|
+
BigNumber2.config = BigNumber2.set = function(obj) {
|
|
1776
|
+
var p, v;
|
|
1777
|
+
if (obj != null) {
|
|
1778
|
+
if (typeof obj == "object") {
|
|
1779
|
+
if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
|
|
1780
|
+
v = obj[p];
|
|
1781
|
+
intCheck(v, 0, MAX, p);
|
|
1782
|
+
DECIMAL_PLACES = v;
|
|
1783
|
+
}
|
|
1784
|
+
if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
|
|
1785
|
+
v = obj[p];
|
|
1786
|
+
intCheck(v, 0, 8, p);
|
|
1787
|
+
ROUNDING_MODE = v;
|
|
1788
|
+
}
|
|
1789
|
+
if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
|
|
1790
|
+
v = obj[p];
|
|
1791
|
+
if (v && v.pop) {
|
|
1792
|
+
intCheck(v[0], -MAX, 0, p);
|
|
1793
|
+
intCheck(v[1], 0, MAX, p);
|
|
1794
|
+
TO_EXP_NEG = v[0];
|
|
1795
|
+
TO_EXP_POS = v[1];
|
|
1796
|
+
} else {
|
|
1797
|
+
intCheck(v, -MAX, MAX, p);
|
|
1798
|
+
TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
if (obj.hasOwnProperty(p = "RANGE")) {
|
|
1802
|
+
v = obj[p];
|
|
1803
|
+
if (v && v.pop) {
|
|
1804
|
+
intCheck(v[0], -MAX, -1, p);
|
|
1805
|
+
intCheck(v[1], 1, MAX, p);
|
|
1806
|
+
MIN_EXP = v[0];
|
|
1807
|
+
MAX_EXP = v[1];
|
|
1808
|
+
} else {
|
|
1809
|
+
intCheck(v, -MAX, MAX, p);
|
|
1810
|
+
if (v) {
|
|
1811
|
+
MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
|
1812
|
+
} else {
|
|
1813
|
+
throw Error(bignumberError + p + " cannot be zero: " + v);
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
if (obj.hasOwnProperty(p = "CRYPTO")) {
|
|
1818
|
+
v = obj[p];
|
|
1819
|
+
if (v === !!v) {
|
|
1820
|
+
if (v) {
|
|
1821
|
+
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
1822
|
+
CRYPTO = v;
|
|
1823
|
+
} else {
|
|
1824
|
+
CRYPTO = !v;
|
|
1825
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
1826
|
+
}
|
|
1827
|
+
} else {
|
|
1828
|
+
CRYPTO = v;
|
|
1829
|
+
}
|
|
1830
|
+
} else {
|
|
1831
|
+
throw Error(bignumberError + p + " not true or false: " + v);
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
if (obj.hasOwnProperty(p = "MODULO_MODE")) {
|
|
1835
|
+
v = obj[p];
|
|
1836
|
+
intCheck(v, 0, 9, p);
|
|
1837
|
+
MODULO_MODE = v;
|
|
1838
|
+
}
|
|
1839
|
+
if (obj.hasOwnProperty(p = "POW_PRECISION")) {
|
|
1840
|
+
v = obj[p];
|
|
1841
|
+
intCheck(v, 0, MAX, p);
|
|
1842
|
+
POW_PRECISION = v;
|
|
1843
|
+
}
|
|
1844
|
+
if (obj.hasOwnProperty(p = "FORMAT")) {
|
|
1845
|
+
v = obj[p];
|
|
1846
|
+
if (typeof v == "object") FORMAT = v;
|
|
1847
|
+
else throw Error(bignumberError + p + " not an object: " + v);
|
|
1848
|
+
}
|
|
1849
|
+
if (obj.hasOwnProperty(p = "ALPHABET")) {
|
|
1850
|
+
v = obj[p];
|
|
1851
|
+
if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
|
|
1852
|
+
alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
|
|
1853
|
+
ALPHABET = v;
|
|
1854
|
+
} else {
|
|
1855
|
+
throw Error(bignumberError + p + " invalid: " + v);
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
} else {
|
|
1859
|
+
throw Error(bignumberError + "Object expected: " + obj);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
return {
|
|
1863
|
+
DECIMAL_PLACES,
|
|
1864
|
+
ROUNDING_MODE,
|
|
1865
|
+
EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
|
1866
|
+
RANGE: [MIN_EXP, MAX_EXP],
|
|
1867
|
+
CRYPTO,
|
|
1868
|
+
MODULO_MODE,
|
|
1869
|
+
POW_PRECISION,
|
|
1870
|
+
FORMAT,
|
|
1871
|
+
ALPHABET
|
|
1872
|
+
};
|
|
1873
|
+
};
|
|
1874
|
+
BigNumber2.isBigNumber = function(v) {
|
|
1875
|
+
if (!v || v._isBigNumber !== true) return false;
|
|
1876
|
+
if (!BigNumber2.DEBUG) return true;
|
|
1877
|
+
var i, n, c = v.c, e = v.e, s = v.s;
|
|
1878
|
+
out: if ({}.toString.call(c) == "[object Array]") {
|
|
1879
|
+
if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
|
|
1880
|
+
if (c[0] === 0) {
|
|
1881
|
+
if (e === 0 && c.length === 1) return true;
|
|
1882
|
+
break out;
|
|
1883
|
+
}
|
|
1884
|
+
i = (e + 1) % LOG_BASE;
|
|
1885
|
+
if (i < 1) i += LOG_BASE;
|
|
1886
|
+
if (String(c[0]).length == i) {
|
|
1887
|
+
for (i = 0; i < c.length; i++) {
|
|
1888
|
+
n = c[i];
|
|
1889
|
+
if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
|
|
1890
|
+
}
|
|
1891
|
+
if (n !== 0) return true;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
} else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
|
|
1895
|
+
return true;
|
|
1896
|
+
}
|
|
1897
|
+
throw Error(bignumberError + "Invalid BigNumber: " + v);
|
|
1898
|
+
};
|
|
1899
|
+
BigNumber2.maximum = BigNumber2.max = function() {
|
|
1900
|
+
return maxOrMin(arguments, -1);
|
|
1901
|
+
};
|
|
1902
|
+
BigNumber2.minimum = BigNumber2.min = function() {
|
|
1903
|
+
return maxOrMin(arguments, 1);
|
|
1904
|
+
};
|
|
1905
|
+
BigNumber2.random = (function() {
|
|
1906
|
+
var pow2_53 = 9007199254740992;
|
|
1907
|
+
var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
|
|
1908
|
+
return mathfloor(Math.random() * pow2_53);
|
|
1909
|
+
} : function() {
|
|
1910
|
+
return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
|
|
1911
|
+
};
|
|
1912
|
+
return function(dp) {
|
|
1913
|
+
var a, b2, e, k2, v, i = 0, c = [], rand = new BigNumber2(ONE);
|
|
1914
|
+
if (dp == null) dp = DECIMAL_PLACES;
|
|
1915
|
+
else intCheck(dp, 0, MAX);
|
|
1916
|
+
k2 = mathceil(dp / LOG_BASE);
|
|
1917
|
+
if (CRYPTO) {
|
|
1918
|
+
if (crypto.getRandomValues) {
|
|
1919
|
+
a = crypto.getRandomValues(new Uint32Array(k2 *= 2));
|
|
1920
|
+
for (; i < k2; ) {
|
|
1921
|
+
v = a[i] * 131072 + (a[i + 1] >>> 11);
|
|
1922
|
+
if (v >= 9e15) {
|
|
1923
|
+
b2 = crypto.getRandomValues(new Uint32Array(2));
|
|
1924
|
+
a[i] = b2[0];
|
|
1925
|
+
a[i + 1] = b2[1];
|
|
1926
|
+
} else {
|
|
1927
|
+
c.push(v % 1e14);
|
|
1928
|
+
i += 2;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
i = k2 / 2;
|
|
1932
|
+
} else if (crypto.randomBytes) {
|
|
1933
|
+
a = crypto.randomBytes(k2 *= 7);
|
|
1934
|
+
for (; i < k2; ) {
|
|
1935
|
+
v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
|
|
1936
|
+
if (v >= 9e15) {
|
|
1937
|
+
crypto.randomBytes(7).copy(a, i);
|
|
1938
|
+
} else {
|
|
1939
|
+
c.push(v % 1e14);
|
|
1940
|
+
i += 7;
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
i = k2 / 7;
|
|
1944
|
+
} else {
|
|
1945
|
+
CRYPTO = false;
|
|
1946
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
if (!CRYPTO) {
|
|
1950
|
+
for (; i < k2; ) {
|
|
1951
|
+
v = random53bitInt();
|
|
1952
|
+
if (v < 9e15) c[i++] = v % 1e14;
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
k2 = c[--i];
|
|
1956
|
+
dp %= LOG_BASE;
|
|
1957
|
+
if (k2 && dp) {
|
|
1958
|
+
v = POWS_TEN[LOG_BASE - dp];
|
|
1959
|
+
c[i] = mathfloor(k2 / v) * v;
|
|
1960
|
+
}
|
|
1961
|
+
for (; c[i] === 0; c.pop(), i--) ;
|
|
1962
|
+
if (i < 0) {
|
|
1963
|
+
c = [e = 0];
|
|
1964
|
+
} else {
|
|
1965
|
+
for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE) ;
|
|
1966
|
+
for (i = 1, v = c[0]; v >= 10; v /= 10, i++) ;
|
|
1967
|
+
if (i < LOG_BASE) e -= LOG_BASE - i;
|
|
1968
|
+
}
|
|
1969
|
+
rand.e = e;
|
|
1970
|
+
rand.c = c;
|
|
1971
|
+
return rand;
|
|
1972
|
+
};
|
|
1973
|
+
})();
|
|
1974
|
+
BigNumber2.sum = function() {
|
|
1975
|
+
var i = 1, args = arguments, sum = new BigNumber2(args[0]);
|
|
1976
|
+
for (; i < args.length; ) sum = sum.plus(args[i++]);
|
|
1977
|
+
return sum;
|
|
1978
|
+
};
|
|
1979
|
+
convertBase = /* @__PURE__ */ (function() {
|
|
1980
|
+
var decimal = "0123456789";
|
|
1981
|
+
function toBaseOut(str, baseIn, baseOut, alphabet2) {
|
|
1982
|
+
var j, arr = [0], arrL, i = 0, len = str.length;
|
|
1983
|
+
for (; i < len; ) {
|
|
1984
|
+
for (arrL = arr.length; arrL--; arr[arrL] *= baseIn) ;
|
|
1985
|
+
arr[0] += alphabet2.indexOf(str.charAt(i++));
|
|
1986
|
+
for (j = 0; j < arr.length; j++) {
|
|
1987
|
+
if (arr[j] > baseOut - 1) {
|
|
1988
|
+
if (arr[j + 1] == null) arr[j + 1] = 0;
|
|
1989
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
1990
|
+
arr[j] %= baseOut;
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
return arr.reverse();
|
|
1995
|
+
}
|
|
1996
|
+
return function(str, baseIn, baseOut, sign, callerIsToString) {
|
|
1997
|
+
var alphabet2, d, e, k2, r, x2, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
|
|
1998
|
+
if (i >= 0) {
|
|
1999
|
+
k2 = POW_PRECISION;
|
|
2000
|
+
POW_PRECISION = 0;
|
|
2001
|
+
str = str.replace(".", "");
|
|
2002
|
+
y = new BigNumber2(baseIn);
|
|
2003
|
+
x2 = y.pow(str.length - i);
|
|
2004
|
+
POW_PRECISION = k2;
|
|
2005
|
+
y.c = toBaseOut(
|
|
2006
|
+
toFixedPoint(coeffToString(x2.c), x2.e, "0"),
|
|
2007
|
+
10,
|
|
2008
|
+
baseOut,
|
|
2009
|
+
decimal
|
|
2010
|
+
);
|
|
2011
|
+
y.e = y.c.length;
|
|
2012
|
+
}
|
|
2013
|
+
xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet2 = ALPHABET, decimal) : (alphabet2 = decimal, ALPHABET));
|
|
2014
|
+
e = k2 = xc.length;
|
|
2015
|
+
for (; xc[--k2] == 0; xc.pop()) ;
|
|
2016
|
+
if (!xc[0]) return alphabet2.charAt(0);
|
|
2017
|
+
if (i < 0) {
|
|
2018
|
+
--e;
|
|
2019
|
+
} else {
|
|
2020
|
+
x2.c = xc;
|
|
2021
|
+
x2.e = e;
|
|
2022
|
+
x2.s = sign;
|
|
2023
|
+
x2 = div(x2, y, dp, rm, baseOut);
|
|
2024
|
+
xc = x2.c;
|
|
2025
|
+
r = x2.r;
|
|
2026
|
+
e = x2.e;
|
|
2027
|
+
}
|
|
2028
|
+
d = e + dp + 1;
|
|
2029
|
+
i = xc[d];
|
|
2030
|
+
k2 = baseOut / 2;
|
|
2031
|
+
r = r || d < 0 || xc[d + 1] != null;
|
|
2032
|
+
r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x2.s < 0 ? 3 : 2)) : i > k2 || i == k2 && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x2.s < 0 ? 8 : 7));
|
|
2033
|
+
if (d < 1 || !xc[0]) {
|
|
2034
|
+
str = r ? toFixedPoint(alphabet2.charAt(1), -dp, alphabet2.charAt(0)) : alphabet2.charAt(0);
|
|
2035
|
+
} else {
|
|
2036
|
+
xc.length = d;
|
|
2037
|
+
if (r) {
|
|
2038
|
+
for (--baseOut; ++xc[--d] > baseOut; ) {
|
|
2039
|
+
xc[d] = 0;
|
|
2040
|
+
if (!d) {
|
|
2041
|
+
++e;
|
|
2042
|
+
xc = [1].concat(xc);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
for (k2 = xc.length; !xc[--k2]; ) ;
|
|
2047
|
+
for (i = 0, str = ""; i <= k2; str += alphabet2.charAt(xc[i++])) ;
|
|
2048
|
+
str = toFixedPoint(str, e, alphabet2.charAt(0));
|
|
2049
|
+
}
|
|
2050
|
+
return str;
|
|
2051
|
+
};
|
|
2052
|
+
})();
|
|
2053
|
+
div = /* @__PURE__ */ (function() {
|
|
2054
|
+
function multiply(x2, k2, base) {
|
|
2055
|
+
var m, temp, xlo, xhi, carry = 0, i = x2.length, klo = k2 % SQRT_BASE, khi = k2 / SQRT_BASE | 0;
|
|
2056
|
+
for (x2 = x2.slice(); i--; ) {
|
|
2057
|
+
xlo = x2[i] % SQRT_BASE;
|
|
2058
|
+
xhi = x2[i] / SQRT_BASE | 0;
|
|
2059
|
+
m = khi * xlo + xhi * klo;
|
|
2060
|
+
temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
|
|
2061
|
+
carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
|
2062
|
+
x2[i] = temp % base;
|
|
2063
|
+
}
|
|
2064
|
+
if (carry) x2 = [carry].concat(x2);
|
|
2065
|
+
return x2;
|
|
2066
|
+
}
|
|
2067
|
+
function compare2(a, b2, aL, bL) {
|
|
2068
|
+
var i, cmp;
|
|
2069
|
+
if (aL != bL) {
|
|
2070
|
+
cmp = aL > bL ? 1 : -1;
|
|
2071
|
+
} else {
|
|
2072
|
+
for (i = cmp = 0; i < aL; i++) {
|
|
2073
|
+
if (a[i] != b2[i]) {
|
|
2074
|
+
cmp = a[i] > b2[i] ? 1 : -1;
|
|
2075
|
+
break;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
return cmp;
|
|
2080
|
+
}
|
|
2081
|
+
function subtract(a, b2, aL, base) {
|
|
2082
|
+
var i = 0;
|
|
2083
|
+
for (; aL--; ) {
|
|
2084
|
+
a[aL] -= i;
|
|
2085
|
+
i = a[aL] < b2[aL] ? 1 : 0;
|
|
2086
|
+
a[aL] = i * base + a[aL] - b2[aL];
|
|
2087
|
+
}
|
|
2088
|
+
for (; !a[0] && a.length > 1; a.splice(0, 1)) ;
|
|
2089
|
+
}
|
|
2090
|
+
return function(x2, y, dp, rm, base) {
|
|
2091
|
+
var cmp, e, i, more, n, prod, prodL, q2, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x2.s == y.s ? 1 : -1, xc = x2.c, yc = y.c;
|
|
2092
|
+
if (!xc || !xc[0] || !yc || !yc[0]) {
|
|
2093
|
+
return new BigNumber2(
|
|
2094
|
+
// Return NaN if either NaN, or both Infinity or 0.
|
|
2095
|
+
!x2.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : (
|
|
2096
|
+
// Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
|
|
2097
|
+
xc && xc[0] == 0 || !yc ? s * 0 : s / 0
|
|
2098
|
+
)
|
|
2099
|
+
);
|
|
2100
|
+
}
|
|
2101
|
+
q2 = new BigNumber2(s);
|
|
2102
|
+
qc = q2.c = [];
|
|
2103
|
+
e = x2.e - y.e;
|
|
2104
|
+
s = dp + e + 1;
|
|
2105
|
+
if (!base) {
|
|
2106
|
+
base = BASE;
|
|
2107
|
+
e = bitFloor(x2.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
|
2108
|
+
s = s / LOG_BASE | 0;
|
|
2109
|
+
}
|
|
2110
|
+
for (i = 0; yc[i] == (xc[i] || 0); i++) ;
|
|
2111
|
+
if (yc[i] > (xc[i] || 0)) e--;
|
|
2112
|
+
if (s < 0) {
|
|
2113
|
+
qc.push(1);
|
|
2114
|
+
more = true;
|
|
2115
|
+
} else {
|
|
2116
|
+
xL = xc.length;
|
|
2117
|
+
yL = yc.length;
|
|
2118
|
+
i = 0;
|
|
2119
|
+
s += 2;
|
|
2120
|
+
n = mathfloor(base / (yc[0] + 1));
|
|
2121
|
+
if (n > 1) {
|
|
2122
|
+
yc = multiply(yc, n, base);
|
|
2123
|
+
xc = multiply(xc, n, base);
|
|
2124
|
+
yL = yc.length;
|
|
2125
|
+
xL = xc.length;
|
|
2126
|
+
}
|
|
2127
|
+
xi = yL;
|
|
2128
|
+
rem = xc.slice(0, yL);
|
|
2129
|
+
remL = rem.length;
|
|
2130
|
+
for (; remL < yL; rem[remL++] = 0) ;
|
|
2131
|
+
yz = yc.slice();
|
|
2132
|
+
yz = [0].concat(yz);
|
|
2133
|
+
yc0 = yc[0];
|
|
2134
|
+
if (yc[1] >= base / 2) yc0++;
|
|
2135
|
+
do {
|
|
2136
|
+
n = 0;
|
|
2137
|
+
cmp = compare2(yc, rem, yL, remL);
|
|
2138
|
+
if (cmp < 0) {
|
|
2139
|
+
rem0 = rem[0];
|
|
2140
|
+
if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
|
|
2141
|
+
n = mathfloor(rem0 / yc0);
|
|
2142
|
+
if (n > 1) {
|
|
2143
|
+
if (n >= base) n = base - 1;
|
|
2144
|
+
prod = multiply(yc, n, base);
|
|
2145
|
+
prodL = prod.length;
|
|
2146
|
+
remL = rem.length;
|
|
2147
|
+
while (compare2(prod, rem, prodL, remL) == 1) {
|
|
2148
|
+
n--;
|
|
2149
|
+
subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
|
2150
|
+
prodL = prod.length;
|
|
2151
|
+
cmp = 1;
|
|
2152
|
+
}
|
|
2153
|
+
} else {
|
|
2154
|
+
if (n == 0) {
|
|
2155
|
+
cmp = n = 1;
|
|
2156
|
+
}
|
|
2157
|
+
prod = yc.slice();
|
|
2158
|
+
prodL = prod.length;
|
|
2159
|
+
}
|
|
2160
|
+
if (prodL < remL) prod = [0].concat(prod);
|
|
2161
|
+
subtract(rem, prod, remL, base);
|
|
2162
|
+
remL = rem.length;
|
|
2163
|
+
if (cmp == -1) {
|
|
2164
|
+
while (compare2(yc, rem, yL, remL) < 1) {
|
|
2165
|
+
n++;
|
|
2166
|
+
subtract(rem, yL < remL ? yz : yc, remL, base);
|
|
2167
|
+
remL = rem.length;
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
} else if (cmp === 0) {
|
|
2171
|
+
n++;
|
|
2172
|
+
rem = [0];
|
|
2173
|
+
}
|
|
2174
|
+
qc[i++] = n;
|
|
2175
|
+
if (rem[0]) {
|
|
2176
|
+
rem[remL++] = xc[xi] || 0;
|
|
2177
|
+
} else {
|
|
2178
|
+
rem = [xc[xi]];
|
|
2179
|
+
remL = 1;
|
|
2180
|
+
}
|
|
2181
|
+
} while ((xi++ < xL || rem[0] != null) && s--);
|
|
2182
|
+
more = rem[0] != null;
|
|
2183
|
+
if (!qc[0]) qc.splice(0, 1);
|
|
2184
|
+
}
|
|
2185
|
+
if (base == BASE) {
|
|
2186
|
+
for (i = 1, s = qc[0]; s >= 10; s /= 10, i++) ;
|
|
2187
|
+
round(q2, dp + (q2.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
|
2188
|
+
} else {
|
|
2189
|
+
q2.e = e;
|
|
2190
|
+
q2.r = +more;
|
|
2191
|
+
}
|
|
2192
|
+
return q2;
|
|
2193
|
+
};
|
|
2194
|
+
})();
|
|
2195
|
+
function format(n, i, rm, id) {
|
|
2196
|
+
var c0, e, ne2, len, str;
|
|
2197
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
2198
|
+
else intCheck(rm, 0, 8);
|
|
2199
|
+
if (!n.c) return n.toString();
|
|
2200
|
+
c0 = n.c[0];
|
|
2201
|
+
ne2 = n.e;
|
|
2202
|
+
if (i == null) {
|
|
2203
|
+
str = coeffToString(n.c);
|
|
2204
|
+
str = id == 1 || id == 2 && (ne2 <= TO_EXP_NEG || ne2 >= TO_EXP_POS) ? toExponential(str, ne2) : toFixedPoint(str, ne2, "0");
|
|
2205
|
+
} else {
|
|
2206
|
+
n = round(new BigNumber2(n), i, rm);
|
|
2207
|
+
e = n.e;
|
|
2208
|
+
str = coeffToString(n.c);
|
|
2209
|
+
len = str.length;
|
|
2210
|
+
if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
|
2211
|
+
for (; len < i; str += "0", len++) ;
|
|
2212
|
+
str = toExponential(str, e);
|
|
2213
|
+
} else {
|
|
2214
|
+
i -= ne2;
|
|
2215
|
+
str = toFixedPoint(str, e, "0");
|
|
2216
|
+
if (e + 1 > len) {
|
|
2217
|
+
if (--i > 0) for (str += "."; i--; str += "0") ;
|
|
2218
|
+
} else {
|
|
2219
|
+
i += e - len;
|
|
2220
|
+
if (i > 0) {
|
|
2221
|
+
if (e + 1 == len) str += ".";
|
|
2222
|
+
for (; i--; str += "0") ;
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
return n.s < 0 && c0 ? "-" + str : str;
|
|
2228
|
+
}
|
|
2229
|
+
function maxOrMin(args, n) {
|
|
2230
|
+
var k2, y, i = 1, x2 = new BigNumber2(args[0]);
|
|
2231
|
+
for (; i < args.length; i++) {
|
|
2232
|
+
y = new BigNumber2(args[i]);
|
|
2233
|
+
if (!y.s || (k2 = compare(x2, y)) === n || k2 === 0 && x2.s === n) {
|
|
2234
|
+
x2 = y;
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
return x2;
|
|
2238
|
+
}
|
|
2239
|
+
function normalise(n, c, e) {
|
|
2240
|
+
var i = 1, j = c.length;
|
|
2241
|
+
for (; !c[--j]; c.pop()) ;
|
|
2242
|
+
for (j = c[0]; j >= 10; j /= 10, i++) ;
|
|
2243
|
+
if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
|
|
2244
|
+
n.c = n.e = null;
|
|
2245
|
+
} else if (e < MIN_EXP) {
|
|
2246
|
+
n.c = [n.e = 0];
|
|
2247
|
+
} else {
|
|
2248
|
+
n.e = e;
|
|
2249
|
+
n.c = c;
|
|
2250
|
+
}
|
|
2251
|
+
return n;
|
|
2252
|
+
}
|
|
2253
|
+
parseNumeric = /* @__PURE__ */ (function() {
|
|
2254
|
+
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
2255
|
+
return function(x2, str, isNum, b2) {
|
|
2256
|
+
var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
|
|
2257
|
+
if (isInfinityOrNaN.test(s)) {
|
|
2258
|
+
x2.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
|
2259
|
+
} else {
|
|
2260
|
+
if (!isNum) {
|
|
2261
|
+
s = s.replace(basePrefix, function(m, p1, p2) {
|
|
2262
|
+
base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
|
|
2263
|
+
return !b2 || b2 == base ? p1 : m;
|
|
2264
|
+
});
|
|
2265
|
+
if (b2) {
|
|
2266
|
+
base = b2;
|
|
2267
|
+
s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
|
|
2268
|
+
}
|
|
2269
|
+
if (str != s) return new BigNumber2(s, base);
|
|
2270
|
+
}
|
|
2271
|
+
if (BigNumber2.DEBUG) {
|
|
2272
|
+
throw Error(bignumberError + "Not a" + (b2 ? " base " + b2 : "") + " number: " + str);
|
|
2273
|
+
}
|
|
2274
|
+
x2.s = null;
|
|
2275
|
+
}
|
|
2276
|
+
x2.c = x2.e = null;
|
|
2277
|
+
};
|
|
2278
|
+
})();
|
|
2279
|
+
function round(x2, sd, rm, r) {
|
|
2280
|
+
var d, i, j, k2, n, ni, rd, xc = x2.c, pows10 = POWS_TEN;
|
|
2281
|
+
if (xc) {
|
|
2282
|
+
out: {
|
|
2283
|
+
for (d = 1, k2 = xc[0]; k2 >= 10; k2 /= 10, d++) ;
|
|
2284
|
+
i = sd - d;
|
|
2285
|
+
if (i < 0) {
|
|
2286
|
+
i += LOG_BASE;
|
|
2287
|
+
j = sd;
|
|
2288
|
+
n = xc[ni = 0];
|
|
2289
|
+
rd = mathfloor(n / pows10[d - j - 1] % 10);
|
|
2290
|
+
} else {
|
|
2291
|
+
ni = mathceil((i + 1) / LOG_BASE);
|
|
2292
|
+
if (ni >= xc.length) {
|
|
2293
|
+
if (r) {
|
|
2294
|
+
for (; xc.length <= ni; xc.push(0)) ;
|
|
2295
|
+
n = rd = 0;
|
|
2296
|
+
d = 1;
|
|
2297
|
+
i %= LOG_BASE;
|
|
2298
|
+
j = i - LOG_BASE + 1;
|
|
2299
|
+
} else {
|
|
2300
|
+
break out;
|
|
2301
|
+
}
|
|
2302
|
+
} else {
|
|
2303
|
+
n = k2 = xc[ni];
|
|
2304
|
+
for (d = 1; k2 >= 10; k2 /= 10, d++) ;
|
|
2305
|
+
i %= LOG_BASE;
|
|
2306
|
+
j = i - LOG_BASE + d;
|
|
2307
|
+
rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
r = r || sd < 0 || // Are there any non-zero digits after the rounding digit?
|
|
2311
|
+
// The expression n % pows10[d - j - 1] returns all digits of n to the right
|
|
2312
|
+
// of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
|
|
2313
|
+
xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
|
2314
|
+
r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x2.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
|
|
2315
|
+
(i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x2.s < 0 ? 8 : 7));
|
|
2316
|
+
if (sd < 1 || !xc[0]) {
|
|
2317
|
+
xc.length = 0;
|
|
2318
|
+
if (r) {
|
|
2319
|
+
sd -= x2.e + 1;
|
|
2320
|
+
xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
|
2321
|
+
x2.e = -sd || 0;
|
|
2322
|
+
} else {
|
|
2323
|
+
xc[0] = x2.e = 0;
|
|
2324
|
+
}
|
|
2325
|
+
return x2;
|
|
2326
|
+
}
|
|
2327
|
+
if (i == 0) {
|
|
2328
|
+
xc.length = ni;
|
|
2329
|
+
k2 = 1;
|
|
2330
|
+
ni--;
|
|
2331
|
+
} else {
|
|
2332
|
+
xc.length = ni + 1;
|
|
2333
|
+
k2 = pows10[LOG_BASE - i];
|
|
2334
|
+
xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k2 : 0;
|
|
2335
|
+
}
|
|
2336
|
+
if (r) {
|
|
2337
|
+
for (; ; ) {
|
|
2338
|
+
if (ni == 0) {
|
|
2339
|
+
for (i = 1, j = xc[0]; j >= 10; j /= 10, i++) ;
|
|
2340
|
+
j = xc[0] += k2;
|
|
2341
|
+
for (k2 = 1; j >= 10; j /= 10, k2++) ;
|
|
2342
|
+
if (i != k2) {
|
|
2343
|
+
x2.e++;
|
|
2344
|
+
if (xc[0] == BASE) xc[0] = 1;
|
|
2345
|
+
}
|
|
2346
|
+
break;
|
|
2347
|
+
} else {
|
|
2348
|
+
xc[ni] += k2;
|
|
2349
|
+
if (xc[ni] != BASE) break;
|
|
2350
|
+
xc[ni--] = 0;
|
|
2351
|
+
k2 = 1;
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
for (i = xc.length; xc[--i] === 0; xc.pop()) ;
|
|
2356
|
+
}
|
|
2357
|
+
if (x2.e > MAX_EXP) {
|
|
2358
|
+
x2.c = x2.e = null;
|
|
2359
|
+
} else if (x2.e < MIN_EXP) {
|
|
2360
|
+
x2.c = [x2.e = 0];
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
return x2;
|
|
2364
|
+
}
|
|
2365
|
+
function valueOf(n) {
|
|
2366
|
+
var str, e = n.e;
|
|
2367
|
+
if (e === null) return n.toString();
|
|
2368
|
+
str = coeffToString(n.c);
|
|
2369
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
|
|
2370
|
+
return n.s < 0 ? "-" + str : str;
|
|
2371
|
+
}
|
|
2372
|
+
P2.absoluteValue = P2.abs = function() {
|
|
2373
|
+
var x2 = new BigNumber2(this);
|
|
2374
|
+
if (x2.s < 0) x2.s = 1;
|
|
2375
|
+
return x2;
|
|
2376
|
+
};
|
|
2377
|
+
P2.comparedTo = function(y, b2) {
|
|
2378
|
+
return compare(this, new BigNumber2(y, b2));
|
|
2379
|
+
};
|
|
2380
|
+
P2.decimalPlaces = P2.dp = function(dp, rm) {
|
|
2381
|
+
var c, n, v, x2 = this;
|
|
2382
|
+
if (dp != null) {
|
|
2383
|
+
intCheck(dp, 0, MAX);
|
|
2384
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
2385
|
+
else intCheck(rm, 0, 8);
|
|
2386
|
+
return round(new BigNumber2(x2), dp + x2.e + 1, rm);
|
|
2387
|
+
}
|
|
2388
|
+
if (!(c = x2.c)) return null;
|
|
2389
|
+
n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
2390
|
+
if (v = c[v]) for (; v % 10 == 0; v /= 10, n--) ;
|
|
2391
|
+
if (n < 0) n = 0;
|
|
2392
|
+
return n;
|
|
2393
|
+
};
|
|
2394
|
+
P2.dividedBy = P2.div = function(y, b2) {
|
|
2395
|
+
return div(this, new BigNumber2(y, b2), DECIMAL_PLACES, ROUNDING_MODE);
|
|
2396
|
+
};
|
|
2397
|
+
P2.dividedToIntegerBy = P2.idiv = function(y, b2) {
|
|
2398
|
+
return div(this, new BigNumber2(y, b2), 0, 1);
|
|
2399
|
+
};
|
|
2400
|
+
P2.exponentiatedBy = P2.pow = function(n, m) {
|
|
2401
|
+
var half, isModExp, i, k2, more, nIsBig, nIsNeg, nIsOdd, y, x2 = this;
|
|
2402
|
+
n = new BigNumber2(n);
|
|
2403
|
+
if (n.c && !n.isInteger()) {
|
|
2404
|
+
throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
|
|
2405
|
+
}
|
|
2406
|
+
if (m != null) m = new BigNumber2(m);
|
|
2407
|
+
nIsBig = n.e > 14;
|
|
2408
|
+
if (!x2.c || !x2.c[0] || x2.c[0] == 1 && !x2.e && x2.c.length == 1 || !n.c || !n.c[0]) {
|
|
2409
|
+
y = new BigNumber2(Math.pow(+valueOf(x2), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
|
|
2410
|
+
return m ? y.mod(m) : y;
|
|
2411
|
+
}
|
|
2412
|
+
nIsNeg = n.s < 0;
|
|
2413
|
+
if (m) {
|
|
2414
|
+
if (m.c ? !m.c[0] : !m.s) return new BigNumber2(NaN);
|
|
2415
|
+
isModExp = !nIsNeg && x2.isInteger() && m.isInteger();
|
|
2416
|
+
if (isModExp) x2 = x2.mod(m);
|
|
2417
|
+
} else if (n.e > 9 && (x2.e > 0 || x2.e < -1 || (x2.e == 0 ? x2.c[0] > 1 || nIsBig && x2.c[1] >= 24e7 : x2.c[0] < 8e13 || nIsBig && x2.c[0] <= 9999975e7))) {
|
|
2418
|
+
k2 = x2.s < 0 && isOdd(n) ? -0 : 0;
|
|
2419
|
+
if (x2.e > -1) k2 = 1 / k2;
|
|
2420
|
+
return new BigNumber2(nIsNeg ? 1 / k2 : k2);
|
|
2421
|
+
} else if (POW_PRECISION) {
|
|
2422
|
+
k2 = mathceil(POW_PRECISION / LOG_BASE + 2);
|
|
2423
|
+
}
|
|
2424
|
+
if (nIsBig) {
|
|
2425
|
+
half = new BigNumber2(0.5);
|
|
2426
|
+
if (nIsNeg) n.s = 1;
|
|
2427
|
+
nIsOdd = isOdd(n);
|
|
2428
|
+
} else {
|
|
2429
|
+
i = Math.abs(+valueOf(n));
|
|
2430
|
+
nIsOdd = i % 2;
|
|
2431
|
+
}
|
|
2432
|
+
y = new BigNumber2(ONE);
|
|
2433
|
+
for (; ; ) {
|
|
2434
|
+
if (nIsOdd) {
|
|
2435
|
+
y = y.times(x2);
|
|
2436
|
+
if (!y.c) break;
|
|
2437
|
+
if (k2) {
|
|
2438
|
+
if (y.c.length > k2) y.c.length = k2;
|
|
2439
|
+
} else if (isModExp) {
|
|
2440
|
+
y = y.mod(m);
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
if (i) {
|
|
2444
|
+
i = mathfloor(i / 2);
|
|
2445
|
+
if (i === 0) break;
|
|
2446
|
+
nIsOdd = i % 2;
|
|
2447
|
+
} else {
|
|
2448
|
+
n = n.times(half);
|
|
2449
|
+
round(n, n.e + 1, 1);
|
|
2450
|
+
if (n.e > 14) {
|
|
2451
|
+
nIsOdd = isOdd(n);
|
|
2452
|
+
} else {
|
|
2453
|
+
i = +valueOf(n);
|
|
2454
|
+
if (i === 0) break;
|
|
2455
|
+
nIsOdd = i % 2;
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
x2 = x2.times(x2);
|
|
2459
|
+
if (k2) {
|
|
2460
|
+
if (x2.c && x2.c.length > k2) x2.c.length = k2;
|
|
2461
|
+
} else if (isModExp) {
|
|
2462
|
+
x2 = x2.mod(m);
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
if (isModExp) return y;
|
|
2466
|
+
if (nIsNeg) y = ONE.div(y);
|
|
2467
|
+
return m ? y.mod(m) : k2 ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
|
2468
|
+
};
|
|
2469
|
+
P2.integerValue = function(rm) {
|
|
2470
|
+
var n = new BigNumber2(this);
|
|
2471
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
2472
|
+
else intCheck(rm, 0, 8);
|
|
2473
|
+
return round(n, n.e + 1, rm);
|
|
2474
|
+
};
|
|
2475
|
+
P2.isEqualTo = P2.eq = function(y, b2) {
|
|
2476
|
+
return compare(this, new BigNumber2(y, b2)) === 0;
|
|
2477
|
+
};
|
|
2478
|
+
P2.isFinite = function() {
|
|
2479
|
+
return !!this.c;
|
|
2480
|
+
};
|
|
2481
|
+
P2.isGreaterThan = P2.gt = function(y, b2) {
|
|
2482
|
+
return compare(this, new BigNumber2(y, b2)) > 0;
|
|
2483
|
+
};
|
|
2484
|
+
P2.isGreaterThanOrEqualTo = P2.gte = function(y, b2) {
|
|
2485
|
+
return (b2 = compare(this, new BigNumber2(y, b2))) === 1 || b2 === 0;
|
|
2486
|
+
};
|
|
2487
|
+
P2.isInteger = function() {
|
|
2488
|
+
return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
|
2489
|
+
};
|
|
2490
|
+
P2.isLessThan = P2.lt = function(y, b2) {
|
|
2491
|
+
return compare(this, new BigNumber2(y, b2)) < 0;
|
|
2492
|
+
};
|
|
2493
|
+
P2.isLessThanOrEqualTo = P2.lte = function(y, b2) {
|
|
2494
|
+
return (b2 = compare(this, new BigNumber2(y, b2))) === -1 || b2 === 0;
|
|
2495
|
+
};
|
|
2496
|
+
P2.isNaN = function() {
|
|
2497
|
+
return !this.s;
|
|
2498
|
+
};
|
|
2499
|
+
P2.isNegative = function() {
|
|
2500
|
+
return this.s < 0;
|
|
2501
|
+
};
|
|
2502
|
+
P2.isPositive = function() {
|
|
2503
|
+
return this.s > 0;
|
|
2504
|
+
};
|
|
2505
|
+
P2.isZero = function() {
|
|
2506
|
+
return !!this.c && this.c[0] == 0;
|
|
2507
|
+
};
|
|
2508
|
+
P2.minus = function(y, b2) {
|
|
2509
|
+
var i, j, t, xLTy, x2 = this, a = x2.s;
|
|
2510
|
+
y = new BigNumber2(y, b2);
|
|
2511
|
+
b2 = y.s;
|
|
2512
|
+
if (!a || !b2) return new BigNumber2(NaN);
|
|
2513
|
+
if (a != b2) {
|
|
2514
|
+
y.s = -b2;
|
|
2515
|
+
return x2.plus(y);
|
|
2516
|
+
}
|
|
2517
|
+
var xe2 = x2.e / LOG_BASE, ye2 = y.e / LOG_BASE, xc = x2.c, yc = y.c;
|
|
2518
|
+
if (!xe2 || !ye2) {
|
|
2519
|
+
if (!xc || !yc) return xc ? (y.s = -b2, y) : new BigNumber2(yc ? x2 : NaN);
|
|
2520
|
+
if (!xc[0] || !yc[0]) {
|
|
2521
|
+
return yc[0] ? (y.s = -b2, y) : new BigNumber2(xc[0] ? x2 : (
|
|
2522
|
+
// IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
|
|
2523
|
+
ROUNDING_MODE == 3 ? -0 : 0
|
|
2524
|
+
));
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
xe2 = bitFloor(xe2);
|
|
2528
|
+
ye2 = bitFloor(ye2);
|
|
2529
|
+
xc = xc.slice();
|
|
2530
|
+
if (a = xe2 - ye2) {
|
|
2531
|
+
if (xLTy = a < 0) {
|
|
2532
|
+
a = -a;
|
|
2533
|
+
t = xc;
|
|
2534
|
+
} else {
|
|
2535
|
+
ye2 = xe2;
|
|
2536
|
+
t = yc;
|
|
2537
|
+
}
|
|
2538
|
+
t.reverse();
|
|
2539
|
+
for (b2 = a; b2--; t.push(0)) ;
|
|
2540
|
+
t.reverse();
|
|
2541
|
+
} else {
|
|
2542
|
+
j = (xLTy = (a = xc.length) < (b2 = yc.length)) ? a : b2;
|
|
2543
|
+
for (a = b2 = 0; b2 < j; b2++) {
|
|
2544
|
+
if (xc[b2] != yc[b2]) {
|
|
2545
|
+
xLTy = xc[b2] < yc[b2];
|
|
2546
|
+
break;
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
if (xLTy) {
|
|
2551
|
+
t = xc;
|
|
2552
|
+
xc = yc;
|
|
2553
|
+
yc = t;
|
|
2554
|
+
y.s = -y.s;
|
|
2555
|
+
}
|
|
2556
|
+
b2 = (j = yc.length) - (i = xc.length);
|
|
2557
|
+
if (b2 > 0) for (; b2--; xc[i++] = 0) ;
|
|
2558
|
+
b2 = BASE - 1;
|
|
2559
|
+
for (; j > a; ) {
|
|
2560
|
+
if (xc[--j] < yc[j]) {
|
|
2561
|
+
for (i = j; i && !xc[--i]; xc[i] = b2) ;
|
|
2562
|
+
--xc[i];
|
|
2563
|
+
xc[j] += BASE;
|
|
2564
|
+
}
|
|
2565
|
+
xc[j] -= yc[j];
|
|
2566
|
+
}
|
|
2567
|
+
for (; xc[0] == 0; xc.splice(0, 1), --ye2) ;
|
|
2568
|
+
if (!xc[0]) {
|
|
2569
|
+
y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
|
2570
|
+
y.c = [y.e = 0];
|
|
2571
|
+
return y;
|
|
2572
|
+
}
|
|
2573
|
+
return normalise(y, xc, ye2);
|
|
2574
|
+
};
|
|
2575
|
+
P2.modulo = P2.mod = function(y, b2) {
|
|
2576
|
+
var q2, s, x2 = this;
|
|
2577
|
+
y = new BigNumber2(y, b2);
|
|
2578
|
+
if (!x2.c || !y.s || y.c && !y.c[0]) {
|
|
2579
|
+
return new BigNumber2(NaN);
|
|
2580
|
+
} else if (!y.c || x2.c && !x2.c[0]) {
|
|
2581
|
+
return new BigNumber2(x2);
|
|
2582
|
+
}
|
|
2583
|
+
if (MODULO_MODE == 9) {
|
|
2584
|
+
s = y.s;
|
|
2585
|
+
y.s = 1;
|
|
2586
|
+
q2 = div(x2, y, 0, 3);
|
|
2587
|
+
y.s = s;
|
|
2588
|
+
q2.s *= s;
|
|
2589
|
+
} else {
|
|
2590
|
+
q2 = div(x2, y, 0, MODULO_MODE);
|
|
2591
|
+
}
|
|
2592
|
+
y = x2.minus(q2.times(y));
|
|
2593
|
+
if (!y.c[0] && MODULO_MODE == 1) y.s = x2.s;
|
|
2594
|
+
return y;
|
|
2595
|
+
};
|
|
2596
|
+
P2.multipliedBy = P2.times = function(y, b2) {
|
|
2597
|
+
var c, e, i, j, k2, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x2 = this, xc = x2.c, yc = (y = new BigNumber2(y, b2)).c;
|
|
2598
|
+
if (!xc || !yc || !xc[0] || !yc[0]) {
|
|
2599
|
+
if (!x2.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
|
|
2600
|
+
y.c = y.e = y.s = null;
|
|
2601
|
+
} else {
|
|
2602
|
+
y.s *= x2.s;
|
|
2603
|
+
if (!xc || !yc) {
|
|
2604
|
+
y.c = y.e = null;
|
|
2605
|
+
} else {
|
|
2606
|
+
y.c = [0];
|
|
2607
|
+
y.e = 0;
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
return y;
|
|
2611
|
+
}
|
|
2612
|
+
e = bitFloor(x2.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
|
2613
|
+
y.s *= x2.s;
|
|
2614
|
+
xcL = xc.length;
|
|
2615
|
+
ycL = yc.length;
|
|
2616
|
+
if (xcL < ycL) {
|
|
2617
|
+
zc = xc;
|
|
2618
|
+
xc = yc;
|
|
2619
|
+
yc = zc;
|
|
2620
|
+
i = xcL;
|
|
2621
|
+
xcL = ycL;
|
|
2622
|
+
ycL = i;
|
|
2623
|
+
}
|
|
2624
|
+
for (i = xcL + ycL, zc = []; i--; zc.push(0)) ;
|
|
2625
|
+
base = BASE;
|
|
2626
|
+
sqrtBase = SQRT_BASE;
|
|
2627
|
+
for (i = ycL; --i >= 0; ) {
|
|
2628
|
+
c = 0;
|
|
2629
|
+
ylo = yc[i] % sqrtBase;
|
|
2630
|
+
yhi = yc[i] / sqrtBase | 0;
|
|
2631
|
+
for (k2 = xcL, j = i + k2; j > i; ) {
|
|
2632
|
+
xlo = xc[--k2] % sqrtBase;
|
|
2633
|
+
xhi = xc[k2] / sqrtBase | 0;
|
|
2634
|
+
m = yhi * xlo + xhi * ylo;
|
|
2635
|
+
xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
|
|
2636
|
+
c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
|
2637
|
+
zc[j--] = xlo % base;
|
|
2638
|
+
}
|
|
2639
|
+
zc[j] = c;
|
|
2640
|
+
}
|
|
2641
|
+
if (c) {
|
|
2642
|
+
++e;
|
|
2643
|
+
} else {
|
|
2644
|
+
zc.splice(0, 1);
|
|
2645
|
+
}
|
|
2646
|
+
return normalise(y, zc, e);
|
|
2647
|
+
};
|
|
2648
|
+
P2.negated = function() {
|
|
2649
|
+
var x2 = new BigNumber2(this);
|
|
2650
|
+
x2.s = -x2.s || null;
|
|
2651
|
+
return x2;
|
|
2652
|
+
};
|
|
2653
|
+
P2.plus = function(y, b2) {
|
|
2654
|
+
var t, x2 = this, a = x2.s;
|
|
2655
|
+
y = new BigNumber2(y, b2);
|
|
2656
|
+
b2 = y.s;
|
|
2657
|
+
if (!a || !b2) return new BigNumber2(NaN);
|
|
2658
|
+
if (a != b2) {
|
|
2659
|
+
y.s = -b2;
|
|
2660
|
+
return x2.minus(y);
|
|
2661
|
+
}
|
|
2662
|
+
var xe2 = x2.e / LOG_BASE, ye2 = y.e / LOG_BASE, xc = x2.c, yc = y.c;
|
|
2663
|
+
if (!xe2 || !ye2) {
|
|
2664
|
+
if (!xc || !yc) return new BigNumber2(a / 0);
|
|
2665
|
+
if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber2(xc[0] ? x2 : a * 0);
|
|
2666
|
+
}
|
|
2667
|
+
xe2 = bitFloor(xe2);
|
|
2668
|
+
ye2 = bitFloor(ye2);
|
|
2669
|
+
xc = xc.slice();
|
|
2670
|
+
if (a = xe2 - ye2) {
|
|
2671
|
+
if (a > 0) {
|
|
2672
|
+
ye2 = xe2;
|
|
2673
|
+
t = yc;
|
|
2674
|
+
} else {
|
|
2675
|
+
a = -a;
|
|
2676
|
+
t = xc;
|
|
2677
|
+
}
|
|
2678
|
+
t.reverse();
|
|
2679
|
+
for (; a--; t.push(0)) ;
|
|
2680
|
+
t.reverse();
|
|
2681
|
+
}
|
|
2682
|
+
a = xc.length;
|
|
2683
|
+
b2 = yc.length;
|
|
2684
|
+
if (a - b2 < 0) {
|
|
2685
|
+
t = yc;
|
|
2686
|
+
yc = xc;
|
|
2687
|
+
xc = t;
|
|
2688
|
+
b2 = a;
|
|
2689
|
+
}
|
|
2690
|
+
for (a = 0; b2; ) {
|
|
2691
|
+
a = (xc[--b2] = xc[b2] + yc[b2] + a) / BASE | 0;
|
|
2692
|
+
xc[b2] = BASE === xc[b2] ? 0 : xc[b2] % BASE;
|
|
2693
|
+
}
|
|
2694
|
+
if (a) {
|
|
2695
|
+
xc = [a].concat(xc);
|
|
2696
|
+
++ye2;
|
|
2697
|
+
}
|
|
2698
|
+
return normalise(y, xc, ye2);
|
|
2699
|
+
};
|
|
2700
|
+
P2.precision = P2.sd = function(sd, rm) {
|
|
2701
|
+
var c, n, v, x2 = this;
|
|
2702
|
+
if (sd != null && sd !== !!sd) {
|
|
2703
|
+
intCheck(sd, 1, MAX);
|
|
2704
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
2705
|
+
else intCheck(rm, 0, 8);
|
|
2706
|
+
return round(new BigNumber2(x2), sd, rm);
|
|
2707
|
+
}
|
|
2708
|
+
if (!(c = x2.c)) return null;
|
|
2709
|
+
v = c.length - 1;
|
|
2710
|
+
n = v * LOG_BASE + 1;
|
|
2711
|
+
if (v = c[v]) {
|
|
2712
|
+
for (; v % 10 == 0; v /= 10, n--) ;
|
|
2713
|
+
for (v = c[0]; v >= 10; v /= 10, n++) ;
|
|
2714
|
+
}
|
|
2715
|
+
if (sd && x2.e + 1 > n) n = x2.e + 1;
|
|
2716
|
+
return n;
|
|
2717
|
+
};
|
|
2718
|
+
P2.shiftedBy = function(k2) {
|
|
2719
|
+
intCheck(k2, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
2720
|
+
return this.times("1e" + k2);
|
|
2721
|
+
};
|
|
2722
|
+
P2.squareRoot = P2.sqrt = function() {
|
|
2723
|
+
var m, n, r, rep, t, x2 = this, c = x2.c, s = x2.s, e = x2.e, dp = DECIMAL_PLACES + 4, half = new BigNumber2("0.5");
|
|
2724
|
+
if (s !== 1 || !c || !c[0]) {
|
|
2725
|
+
return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x2 : 1 / 0);
|
|
2726
|
+
}
|
|
2727
|
+
s = Math.sqrt(+valueOf(x2));
|
|
2728
|
+
if (s == 0 || s == 1 / 0) {
|
|
2729
|
+
n = coeffToString(c);
|
|
2730
|
+
if ((n.length + e) % 2 == 0) n += "0";
|
|
2731
|
+
s = Math.sqrt(+n);
|
|
2732
|
+
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
2733
|
+
if (s == 1 / 0) {
|
|
2734
|
+
n = "5e" + e;
|
|
2735
|
+
} else {
|
|
2736
|
+
n = s.toExponential();
|
|
2737
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
2738
|
+
}
|
|
2739
|
+
r = new BigNumber2(n);
|
|
2740
|
+
} else {
|
|
2741
|
+
r = new BigNumber2(s + "");
|
|
2742
|
+
}
|
|
2743
|
+
if (r.c[0]) {
|
|
2744
|
+
e = r.e;
|
|
2745
|
+
s = e + dp;
|
|
2746
|
+
if (s < 3) s = 0;
|
|
2747
|
+
for (; ; ) {
|
|
2748
|
+
t = r;
|
|
2749
|
+
r = half.times(t.plus(div(x2, t, dp, 1)));
|
|
2750
|
+
if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
|
|
2751
|
+
if (r.e < e) --s;
|
|
2752
|
+
n = n.slice(s - 3, s + 1);
|
|
2753
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
2754
|
+
if (!rep) {
|
|
2755
|
+
round(t, t.e + DECIMAL_PLACES + 2, 0);
|
|
2756
|
+
if (t.times(t).eq(x2)) {
|
|
2757
|
+
r = t;
|
|
2758
|
+
break;
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
dp += 4;
|
|
2762
|
+
s += 4;
|
|
2763
|
+
rep = 1;
|
|
2764
|
+
} else {
|
|
2765
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
2766
|
+
round(r, r.e + DECIMAL_PLACES + 2, 1);
|
|
2767
|
+
m = !r.times(r).eq(x2);
|
|
2768
|
+
}
|
|
2769
|
+
break;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
|
2775
|
+
};
|
|
2776
|
+
P2.toExponential = function(dp, rm) {
|
|
2777
|
+
if (dp != null) {
|
|
2778
|
+
intCheck(dp, 0, MAX);
|
|
2779
|
+
dp++;
|
|
2780
|
+
}
|
|
2781
|
+
return format(this, dp, rm, 1);
|
|
2782
|
+
};
|
|
2783
|
+
P2.toFixed = function(dp, rm) {
|
|
2784
|
+
if (dp != null) {
|
|
2785
|
+
intCheck(dp, 0, MAX);
|
|
2786
|
+
dp = dp + this.e + 1;
|
|
2787
|
+
}
|
|
2788
|
+
return format(this, dp, rm);
|
|
2789
|
+
};
|
|
2790
|
+
P2.toFormat = function(dp, rm, format2) {
|
|
2791
|
+
var str, x2 = this;
|
|
2792
|
+
if (format2 == null) {
|
|
2793
|
+
if (dp != null && rm && typeof rm == "object") {
|
|
2794
|
+
format2 = rm;
|
|
2795
|
+
rm = null;
|
|
2796
|
+
} else if (dp && typeof dp == "object") {
|
|
2797
|
+
format2 = dp;
|
|
2798
|
+
dp = rm = null;
|
|
2799
|
+
} else {
|
|
2800
|
+
format2 = FORMAT;
|
|
2801
|
+
}
|
|
2802
|
+
} else if (typeof format2 != "object") {
|
|
2803
|
+
throw Error(bignumberError + "Argument not an object: " + format2);
|
|
2804
|
+
}
|
|
2805
|
+
str = x2.toFixed(dp, rm);
|
|
2806
|
+
if (x2.c) {
|
|
2807
|
+
var i, arr = str.split("."), g1 = +format2.groupSize, g2 = +format2.secondaryGroupSize, groupSeparator = format2.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x2.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
|
|
2808
|
+
if (g2) {
|
|
2809
|
+
i = g1;
|
|
2810
|
+
g1 = g2;
|
|
2811
|
+
g2 = i;
|
|
2812
|
+
len -= i;
|
|
2813
|
+
}
|
|
2814
|
+
if (g1 > 0 && len > 0) {
|
|
2815
|
+
i = len % g1 || g1;
|
|
2816
|
+
intPart = intDigits.substr(0, i);
|
|
2817
|
+
for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
|
|
2818
|
+
if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
|
|
2819
|
+
if (isNeg) intPart = "-" + intPart;
|
|
2820
|
+
}
|
|
2821
|
+
str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
|
|
2822
|
+
new RegExp("\\d{" + g2 + "}\\B", "g"),
|
|
2823
|
+
"$&" + (format2.fractionGroupSeparator || "")
|
|
2824
|
+
) : fractionPart) : intPart;
|
|
2825
|
+
}
|
|
2826
|
+
return (format2.prefix || "") + str + (format2.suffix || "");
|
|
2827
|
+
};
|
|
2828
|
+
P2.toFraction = function(md) {
|
|
2829
|
+
var d, d0, d1, d2, e, exp, n, n0, n1, q2, r, s, x2 = this, xc = x2.c;
|
|
2830
|
+
if (md != null) {
|
|
2831
|
+
n = new BigNumber2(md);
|
|
2832
|
+
if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
|
|
2833
|
+
throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
if (!xc) return new BigNumber2(x2);
|
|
2837
|
+
d = new BigNumber2(ONE);
|
|
2838
|
+
n1 = d0 = new BigNumber2(ONE);
|
|
2839
|
+
d1 = n0 = new BigNumber2(ONE);
|
|
2840
|
+
s = coeffToString(xc);
|
|
2841
|
+
e = d.e = s.length - x2.e - 1;
|
|
2842
|
+
d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
|
2843
|
+
md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
|
|
2844
|
+
exp = MAX_EXP;
|
|
2845
|
+
MAX_EXP = 1 / 0;
|
|
2846
|
+
n = new BigNumber2(s);
|
|
2847
|
+
n0.c[0] = 0;
|
|
2848
|
+
for (; ; ) {
|
|
2849
|
+
q2 = div(n, d, 0, 1);
|
|
2850
|
+
d2 = d0.plus(q2.times(d1));
|
|
2851
|
+
if (d2.comparedTo(md) == 1) break;
|
|
2852
|
+
d0 = d1;
|
|
2853
|
+
d1 = d2;
|
|
2854
|
+
n1 = n0.plus(q2.times(d2 = n1));
|
|
2855
|
+
n0 = d2;
|
|
2856
|
+
d = n.minus(q2.times(d2 = d));
|
|
2857
|
+
n = d2;
|
|
2858
|
+
}
|
|
2859
|
+
d2 = div(md.minus(d0), d1, 0, 1);
|
|
2860
|
+
n0 = n0.plus(d2.times(n1));
|
|
2861
|
+
d0 = d0.plus(d2.times(d1));
|
|
2862
|
+
n0.s = n1.s = x2.s;
|
|
2863
|
+
e = e * 2;
|
|
2864
|
+
r = div(n1, d1, e, ROUNDING_MODE).minus(x2).abs().comparedTo(
|
|
2865
|
+
div(n0, d0, e, ROUNDING_MODE).minus(x2).abs()
|
|
2866
|
+
) < 1 ? [n1, d1] : [n0, d0];
|
|
2867
|
+
MAX_EXP = exp;
|
|
2868
|
+
return r;
|
|
2869
|
+
};
|
|
2870
|
+
P2.toNumber = function() {
|
|
2871
|
+
return +valueOf(this);
|
|
2872
|
+
};
|
|
2873
|
+
P2.toPrecision = function(sd, rm) {
|
|
2874
|
+
if (sd != null) intCheck(sd, 1, MAX);
|
|
2875
|
+
return format(this, sd, rm, 2);
|
|
2876
|
+
};
|
|
2877
|
+
P2.toString = function(b2) {
|
|
2878
|
+
var str, n = this, s = n.s, e = n.e;
|
|
2879
|
+
if (e === null) {
|
|
2880
|
+
if (s) {
|
|
2881
|
+
str = "Infinity";
|
|
2882
|
+
if (s < 0) str = "-" + str;
|
|
2883
|
+
} else {
|
|
2884
|
+
str = "NaN";
|
|
2885
|
+
}
|
|
2886
|
+
} else {
|
|
2887
|
+
if (b2 == null) {
|
|
2888
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
|
|
2889
|
+
} else if (b2 === 10 && alphabetHasNormalDecimalDigits) {
|
|
2890
|
+
n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
|
|
2891
|
+
str = toFixedPoint(coeffToString(n.c), n.e, "0");
|
|
2892
|
+
} else {
|
|
2893
|
+
intCheck(b2, 2, ALPHABET.length, "Base");
|
|
2894
|
+
str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b2, s, true);
|
|
2895
|
+
}
|
|
2896
|
+
if (s < 0 && n.c[0]) str = "-" + str;
|
|
2897
|
+
}
|
|
2898
|
+
return str;
|
|
2899
|
+
};
|
|
2900
|
+
P2.valueOf = P2.toJSON = function() {
|
|
2901
|
+
return valueOf(this);
|
|
2902
|
+
};
|
|
2903
|
+
P2._isBigNumber = true;
|
|
2904
|
+
P2[Symbol.toStringTag] = "BigNumber";
|
|
2905
|
+
P2[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = P2.valueOf;
|
|
2906
|
+
if (configObject != null) BigNumber2.set(configObject);
|
|
2907
|
+
return BigNumber2;
|
|
2908
|
+
}
|
|
2909
|
+
function bitFloor(n) {
|
|
2910
|
+
var i = n | 0;
|
|
2911
|
+
return n > 0 || n === i ? i : i - 1;
|
|
2912
|
+
}
|
|
2913
|
+
function coeffToString(a) {
|
|
2914
|
+
var s, z2, i = 1, j = a.length, r = a[0] + "";
|
|
2915
|
+
for (; i < j; ) {
|
|
2916
|
+
s = a[i++] + "";
|
|
2917
|
+
z2 = LOG_BASE - s.length;
|
|
2918
|
+
for (; z2--; s = "0" + s) ;
|
|
2919
|
+
r += s;
|
|
2920
|
+
}
|
|
2921
|
+
for (j = r.length; r.charCodeAt(--j) === 48; ) ;
|
|
2922
|
+
return r.slice(0, j + 1 || 1);
|
|
2923
|
+
}
|
|
2924
|
+
function compare(x2, y) {
|
|
2925
|
+
var a, b2, xc = x2.c, yc = y.c, i = x2.s, j = y.s, k2 = x2.e, l = y.e;
|
|
2926
|
+
if (!i || !j) return null;
|
|
2927
|
+
a = xc && !xc[0];
|
|
2928
|
+
b2 = yc && !yc[0];
|
|
2929
|
+
if (a || b2) return a ? b2 ? 0 : -j : i;
|
|
2930
|
+
if (i != j) return i;
|
|
2931
|
+
a = i < 0;
|
|
2932
|
+
b2 = k2 == l;
|
|
2933
|
+
if (!xc || !yc) return b2 ? 0 : !xc ^ a ? 1 : -1;
|
|
2934
|
+
if (!b2) return k2 > l ^ a ? 1 : -1;
|
|
2935
|
+
j = (k2 = xc.length) < (l = yc.length) ? k2 : l;
|
|
2936
|
+
for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
|
|
2937
|
+
return k2 == l ? 0 : k2 > l ^ a ? 1 : -1;
|
|
2938
|
+
}
|
|
2939
|
+
function intCheck(n, min, max, name) {
|
|
2940
|
+
if (n < min || n > max || n !== mathfloor(n)) {
|
|
2941
|
+
throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
|
|
99
2942
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
2943
|
+
}
|
|
2944
|
+
function isOdd(n) {
|
|
2945
|
+
var k2 = n.c.length - 1;
|
|
2946
|
+
return bitFloor(n.e / LOG_BASE) == k2 && n.c[k2] % 2 != 0;
|
|
2947
|
+
}
|
|
2948
|
+
function toExponential(str, e) {
|
|
2949
|
+
return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
|
|
2950
|
+
}
|
|
2951
|
+
function toFixedPoint(str, e, z2) {
|
|
2952
|
+
var len, zs;
|
|
2953
|
+
if (e < 0) {
|
|
2954
|
+
for (zs = z2 + "."; ++e; zs += z2) ;
|
|
2955
|
+
str = zs + str;
|
|
2956
|
+
} else {
|
|
2957
|
+
len = str.length;
|
|
2958
|
+
if (++e > len) {
|
|
2959
|
+
for (zs = z2, e -= len; --e; zs += z2) ;
|
|
2960
|
+
str += zs;
|
|
2961
|
+
} else if (e < len) {
|
|
2962
|
+
str = str.slice(0, e) + "." + str.slice(e);
|
|
110
2963
|
}
|
|
111
|
-
|
|
112
|
-
|
|
2964
|
+
}
|
|
2965
|
+
return str;
|
|
2966
|
+
}
|
|
2967
|
+
var BigNumber = clone();
|
|
2968
|
+
var bignumber_default = BigNumber;
|
|
2969
|
+
var z = bcs.bytes(32).transform({
|
|
2970
|
+
// To change the input type, you need to provide a type definition for the input
|
|
2971
|
+
input: (e) => fromHex(e),
|
|
2972
|
+
output: (e) => toHex(e)
|
|
2973
|
+
});
|
|
2974
|
+
bcs.struct("IncentiveAPYInfo", {
|
|
2975
|
+
/** Asset identifier */
|
|
2976
|
+
asset_id: bcs.u8(),
|
|
2977
|
+
/** Annual Percentage Yield as a 256-bit integer */
|
|
2978
|
+
apy: bcs.u256(),
|
|
2979
|
+
/** List of supported coin types for this incentive */
|
|
2980
|
+
coin_types: bcs.vector(bcs.string())
|
|
2981
|
+
});
|
|
2982
|
+
var me = bcs.struct("IncentivePoolInfo", {
|
|
2983
|
+
/** Unique pool identifier */
|
|
2984
|
+
pool_id: z,
|
|
2985
|
+
/** Address holding the incentive funds */
|
|
2986
|
+
funds: z,
|
|
2987
|
+
/** Current phase of the incentive program */
|
|
2988
|
+
phase: bcs.u64(),
|
|
2989
|
+
/** Timestamp when the incentive started */
|
|
2990
|
+
start_at: bcs.u64(),
|
|
2991
|
+
/** Timestamp when the incentive ends */
|
|
2992
|
+
end_at: bcs.u64(),
|
|
2993
|
+
/** Timestamp when the incentive was closed */
|
|
2994
|
+
closed_at: bcs.u64(),
|
|
2995
|
+
/** Total supply of incentive tokens */
|
|
2996
|
+
total_supply: bcs.u64(),
|
|
2997
|
+
/** Asset identifier for the incentive */
|
|
2998
|
+
asset_id: bcs.u8(),
|
|
2999
|
+
/** Option type for the incentive */
|
|
3000
|
+
option: bcs.u8(),
|
|
3001
|
+
/** Factor used in incentive calculations */
|
|
3002
|
+
factor: bcs.u256(),
|
|
3003
|
+
/** Amount of incentives already distributed */
|
|
3004
|
+
distributed: bcs.u64(),
|
|
3005
|
+
/** Amount of incentives currently available */
|
|
3006
|
+
available: bcs.u256(),
|
|
3007
|
+
/** Total amount of incentives */
|
|
3008
|
+
total: bcs.u256()
|
|
3009
|
+
});
|
|
3010
|
+
bcs.struct("IncentivePoolInfoByPhase", {
|
|
3011
|
+
/** Phase number */
|
|
3012
|
+
phase: bcs.u64(),
|
|
3013
|
+
/** List of incentive pools in this phase */
|
|
3014
|
+
pools: bcs.vector(me)
|
|
3015
|
+
});
|
|
3016
|
+
bcs.struct("OracleInfo", {
|
|
3017
|
+
/** Oracle identifier */
|
|
3018
|
+
oracle_id: bcs.u8(),
|
|
3019
|
+
/** Current price as a 256-bit integer */
|
|
3020
|
+
price: bcs.u256(),
|
|
3021
|
+
/** Number of decimal places for the price */
|
|
3022
|
+
decimals: bcs.u8(),
|
|
3023
|
+
/** Whether the oracle data is valid */
|
|
3024
|
+
valid: bcs.bool()
|
|
3025
|
+
});
|
|
3026
|
+
bcs.struct("FlashLoanAssetConfig", {
|
|
3027
|
+
/** Unique identifier for the flash loan asset */
|
|
3028
|
+
id: bcs.string(),
|
|
3029
|
+
/** Asset identifier */
|
|
3030
|
+
asset_id: bcs.u8(),
|
|
3031
|
+
/** Coin type for the asset */
|
|
3032
|
+
coin_type: bcs.string(),
|
|
3033
|
+
/** Pool identifier for the flash loan */
|
|
3034
|
+
pool_id: bcs.string(),
|
|
3035
|
+
/** Rate paid to suppliers for flash loans */
|
|
3036
|
+
rate_to_supplier: bcs.u64(),
|
|
3037
|
+
/** Rate paid to treasury for flash loans */
|
|
3038
|
+
rate_to_treasury: bcs.u64(),
|
|
3039
|
+
/** Maximum flash loan amount */
|
|
3040
|
+
max: bcs.u64(),
|
|
3041
|
+
/** Minimum flash loan amount */
|
|
3042
|
+
min: bcs.u64()
|
|
3043
|
+
});
|
|
3044
|
+
bcs.struct("ReserveDataInfo", {
|
|
3045
|
+
/** Reserve identifier */
|
|
3046
|
+
id: bcs.u8(),
|
|
3047
|
+
/** Oracle identifier for price feeds */
|
|
3048
|
+
oracle_id: bcs.u8(),
|
|
3049
|
+
/** Coin type for the reserve */
|
|
3050
|
+
coin_type: bcs.string(),
|
|
3051
|
+
/** Maximum supply capacity */
|
|
3052
|
+
supply_cap: bcs.u256(),
|
|
3053
|
+
/** Maximum borrow capacity */
|
|
3054
|
+
borrow_cap: bcs.u256(),
|
|
3055
|
+
/** Current supply interest rate */
|
|
3056
|
+
supply_rate: bcs.u256(),
|
|
3057
|
+
/** Current borrow interest rate */
|
|
3058
|
+
borrow_rate: bcs.u256(),
|
|
3059
|
+
/** Current supply index for interest calculation */
|
|
3060
|
+
supply_index: bcs.u256(),
|
|
3061
|
+
/** Current borrow index for interest calculation */
|
|
3062
|
+
borrow_index: bcs.u256(),
|
|
3063
|
+
/** Total amount supplied to the reserve */
|
|
3064
|
+
total_supply: bcs.u256(),
|
|
3065
|
+
/** Total amount borrowed from the reserve */
|
|
3066
|
+
total_borrow: bcs.u256(),
|
|
3067
|
+
/** Timestamp of last update */
|
|
3068
|
+
last_update_at: bcs.u64(),
|
|
3069
|
+
/** Loan-to-Value ratio for collateral */
|
|
3070
|
+
ltv: bcs.u256(),
|
|
3071
|
+
/** Treasury factor for fee calculations */
|
|
3072
|
+
treasury_factor: bcs.u256(),
|
|
3073
|
+
/** Current treasury balance */
|
|
3074
|
+
treasury_balance: bcs.u256(),
|
|
3075
|
+
/** Base interest rate */
|
|
3076
|
+
base_rate: bcs.u256(),
|
|
3077
|
+
/** Interest rate multiplier */
|
|
3078
|
+
multiplier: bcs.u256(),
|
|
3079
|
+
/** Jump rate multiplier for high utilization */
|
|
3080
|
+
jump_rate_multiplier: bcs.u256(),
|
|
3081
|
+
/** Reserve factor for protocol fees */
|
|
3082
|
+
reserve_factor: bcs.u256(),
|
|
3083
|
+
/** Optimal utilization rate */
|
|
3084
|
+
optimal_utilization: bcs.u256(),
|
|
3085
|
+
/** Liquidation ratio threshold */
|
|
3086
|
+
liquidation_ratio: bcs.u256(),
|
|
3087
|
+
/** Liquidation bonus for liquidators */
|
|
3088
|
+
liquidation_bonus: bcs.u256(),
|
|
3089
|
+
/** Liquidation threshold */
|
|
3090
|
+
liquidation_threshold: bcs.u256()
|
|
3091
|
+
});
|
|
3092
|
+
var fe = bcs.struct("UserStateInfo", {
|
|
3093
|
+
/** Asset identifier */
|
|
3094
|
+
asset_id: bcs.u8(),
|
|
3095
|
+
/** User's current borrow balance */
|
|
3096
|
+
borrow_balance: bcs.u256(),
|
|
3097
|
+
/** User's current supply balance */
|
|
3098
|
+
supply_balance: bcs.u256()
|
|
3099
|
+
});
|
|
3100
|
+
var ye = "1.4.0";
|
|
3101
|
+
var V = {
|
|
3102
|
+
version: ye
|
|
3103
|
+
};
|
|
3104
|
+
var ge = V.version;
|
|
3105
|
+
var he = () => {
|
|
3106
|
+
if (typeof process < "u" && process.versions && process.versions.node)
|
|
3107
|
+
try {
|
|
3108
|
+
const e = __require("os"), n = process.version, o = e.type(), r = e.arch();
|
|
3109
|
+
return `Node.js ${n.startsWith("v") ? n.substring(1) : n}; ${o}/${r}`;
|
|
3110
|
+
} catch {
|
|
3111
|
+
return `Node.js ${process.version}; OS/Unknown (Error)`;
|
|
113
3112
|
}
|
|
114
|
-
|
|
115
|
-
|
|
3113
|
+
return "Node/Unknown";
|
|
3114
|
+
};
|
|
3115
|
+
var ve = () => {
|
|
3116
|
+
let e = "";
|
|
3117
|
+
return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${ge} (${he()})`), e;
|
|
3118
|
+
};
|
|
3119
|
+
var K = ve();
|
|
3120
|
+
var P = new jsonRpc.SuiJsonRpcClient({
|
|
3121
|
+
url: jsonRpc.getJsonRpcFullnodeUrl("mainnet")
|
|
3122
|
+
});
|
|
3123
|
+
function Q(e) {
|
|
3124
|
+
const n = [];
|
|
3125
|
+
return e.forEach((o, r) => {
|
|
3126
|
+
const t = r === e.length - 1;
|
|
3127
|
+
if (typeof o == "object" && o !== null && t) {
|
|
3128
|
+
const { client: a, disableCache: s, cacheTime: i, ...c } = o;
|
|
3129
|
+
n.push(c);
|
|
3130
|
+
} else
|
|
3131
|
+
n.push(o);
|
|
3132
|
+
}), JSON.stringify(n);
|
|
3133
|
+
}
|
|
3134
|
+
function B(e) {
|
|
3135
|
+
const n = {};
|
|
3136
|
+
return (...o) => {
|
|
3137
|
+
const r = Q(o);
|
|
3138
|
+
return n[r] || (n[r] = e(...o).finally(() => {
|
|
3139
|
+
delete n[r];
|
|
3140
|
+
})), n[r];
|
|
3141
|
+
};
|
|
3142
|
+
}
|
|
3143
|
+
function $(e) {
|
|
3144
|
+
let n = {};
|
|
3145
|
+
return (...o) => {
|
|
3146
|
+
const r = o[o.length - 1], t = Q(o), a = n[t];
|
|
3147
|
+
return !r?.disableCache && typeof a?.data < "u" && (typeof r?.cacheTime > "u" || r.cacheTime > Date.now() - a.cacheAt) ? a.data : e(...o).then((s) => (n[t] = {
|
|
3148
|
+
data: s,
|
|
3149
|
+
cacheAt: Date.now()
|
|
3150
|
+
}, s));
|
|
3151
|
+
};
|
|
3152
|
+
}
|
|
3153
|
+
function g(e, n) {
|
|
3154
|
+
return typeof e == "object" ? e : n(e);
|
|
3155
|
+
}
|
|
3156
|
+
function we(e, n) {
|
|
3157
|
+
return typeof n == "string" ? e.object(n) : typeof n == "object" && n.$kind ? n : e.object(n.contract.pool);
|
|
3158
|
+
}
|
|
3159
|
+
function L(e, n, o) {
|
|
3160
|
+
if (e.results && e.results.length > 0) {
|
|
3161
|
+
if (e.results[0].returnValues && e.results[0].returnValues.length > 0)
|
|
3162
|
+
return e.results[0].returnValues.map((r, t) => (n[t] || n[0]).parse(Uint8Array.from(r[0])));
|
|
3163
|
+
} else if (e.error)
|
|
3164
|
+
return console.log(`Get an error, msg: ${e.error}`), [];
|
|
3165
|
+
return [];
|
|
3166
|
+
}
|
|
3167
|
+
function b(e) {
|
|
3168
|
+
return utils.normalizeStructTag(e);
|
|
3169
|
+
}
|
|
3170
|
+
function X(e) {
|
|
3171
|
+
const n = (e || 0) / Math.pow(10, 27);
|
|
3172
|
+
return n > Math.pow(10, 5) ? 1 / 0 : n;
|
|
3173
|
+
}
|
|
3174
|
+
new pythSuiJs.SuiPriceServiceConnection("https://hermes.pyth.network", {
|
|
3175
|
+
timeout: 2e4
|
|
3176
|
+
});
|
|
3177
|
+
var be = 27;
|
|
3178
|
+
var Y = (e, n) => {
|
|
3179
|
+
if (!Number(e) || !Number(n)) return new bignumber_default(0);
|
|
3180
|
+
const o = new bignumber_default(1).shiftedBy(1 * be), r = o.multipliedBy(new bignumber_default(0.5));
|
|
3181
|
+
return new bignumber_default(e).multipliedBy(new bignumber_default(n)).plus(r).dividedBy(o).integerValue(bignumber_default.ROUND_DOWN);
|
|
3182
|
+
};
|
|
3183
|
+
var E = K ? {
|
|
3184
|
+
"User-Agent": K
|
|
3185
|
+
} : {};
|
|
3186
|
+
function H(e, n = "uniqueId") {
|
|
3187
|
+
return e.reduce(
|
|
3188
|
+
(o, r) => (o[r[n]] = r, o),
|
|
3189
|
+
{}
|
|
3190
|
+
);
|
|
3191
|
+
}
|
|
3192
|
+
function q(e, n) {
|
|
3193
|
+
const o = e.emodes.find((t) => t.emodeId === n.emodeId);
|
|
3194
|
+
if (!o)
|
|
3195
|
+
throw new Error("EMode not found in pool");
|
|
3196
|
+
const r = o.assets.find((t) => t.assetId === e.id);
|
|
3197
|
+
return {
|
|
3198
|
+
...e,
|
|
3199
|
+
emode: {
|
|
3200
|
+
...r,
|
|
3201
|
+
emodeId: o.emodeId
|
|
3202
|
+
},
|
|
3203
|
+
isEMode: true
|
|
3204
|
+
};
|
|
3205
|
+
}
|
|
3206
|
+
function ke(e) {
|
|
3207
|
+
const [n, o] = e.split("-");
|
|
3208
|
+
return !n || !o ? null : {
|
|
3209
|
+
marketKey: n,
|
|
3210
|
+
poolId: parseInt(o)
|
|
3211
|
+
};
|
|
3212
|
+
}
|
|
3213
|
+
function T() {
|
|
3214
|
+
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
3215
|
+
}
|
|
3216
|
+
var R = $(
|
|
3217
|
+
B(
|
|
3218
|
+
async (e) => {
|
|
3219
|
+
const n = (e?.markets || [M.main]).map((t) => _(t)), o = `https://open-api.naviprotocol.io/api/navi/pools?env=${e?.env || "prod"}&sdk=${V.version}&market=${n.map(
|
|
3220
|
+
(t) => t.key
|
|
3221
|
+
)}`, r = await fetch(o, { headers: E }).then((t) => t.json());
|
|
3222
|
+
return r.data.forEach((t) => {
|
|
3223
|
+
const s = r.meta.emodes.filter((h) => {
|
|
3224
|
+
const j = _(h.marketId);
|
|
3225
|
+
return t.market === j.key && h.isActive;
|
|
3226
|
+
}).filter((h) => !!h.assets.find((j) => j.assetId === t.id));
|
|
3227
|
+
t.emodes = s;
|
|
3228
|
+
const i = bignumber_default(t.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(t.token.decimals, bignumber_default.ROUND_DOWN).toString(), c = bignumber_default(t.borrowedAmount).shiftedBy(-9).decimalPlaces(t.token.decimals, bignumber_default.ROUND_DOWN).toString(), u = bignumber_default(i).multipliedBy(t.oracle.price).toString(), d = bignumber_default(c).multipliedBy(t.oracle.price).toString(), f = bignumber_default(t.supplyCapCeiling).shiftedBy(-27).decimalPlaces(t.token.decimals, bignumber_default.ROUND_DOWN).toString(), v = bignumber_default.max(
|
|
3229
|
+
bignumber_default(t.borrowedAmount),
|
|
3230
|
+
bignumber_default(t.validBorrowAmount)
|
|
3231
|
+
).shiftedBy(-9).decimalPlaces(t.token.decimals, bignumber_default.ROUND_DOWN).toString(), y = bignumber_default(f).multipliedBy(t.oracle.price).toString(), l = bignumber_default(v).multipliedBy(t.oracle.price).toString();
|
|
3232
|
+
t.poolSupplyAmount = i, t.poolBorrowAmount = c, t.poolSupplyValue = u, t.poolBorrowValue = d, t.poolSupplyCapAmount = f, t.poolBorrowCapAmount = v, t.poolSupplyCapValue = y, t.poolBorrowCapValue = l;
|
|
3233
|
+
}), r.data;
|
|
3234
|
+
}
|
|
3235
|
+
)
|
|
3236
|
+
);
|
|
3237
|
+
async function A(e, n) {
|
|
3238
|
+
let o = n?.market;
|
|
3239
|
+
if (typeof e == "string") {
|
|
3240
|
+
const a = ke(e);
|
|
3241
|
+
a && (o = a.marketKey, e = a.poolId);
|
|
116
3242
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
3243
|
+
const r = await R({
|
|
3244
|
+
...n,
|
|
3245
|
+
markets: [o || N],
|
|
3246
|
+
cacheTime: w
|
|
3247
|
+
});
|
|
3248
|
+
if (typeof e == "object")
|
|
3249
|
+
return e;
|
|
3250
|
+
const t = r.find((a) => typeof e == "string" ? b(a.suiCoinType) === b(e) : typeof e == "number" ? a.id === e : false);
|
|
3251
|
+
if (!t)
|
|
3252
|
+
throw new Error("Pool not found");
|
|
3253
|
+
return t.isDeprecated && console.log(`The lending pool for coinType ${t.suiCoinType} is going to be deprecated.`), t;
|
|
3254
|
+
}
|
|
3255
|
+
async function Ce(e, n, o, r) {
|
|
3256
|
+
const t = await k({
|
|
3257
|
+
...r,
|
|
3258
|
+
cacheTime: w
|
|
3259
|
+
}), a = await A(n, r);
|
|
3260
|
+
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
3261
|
+
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
3262
|
+
const s = typeof o == "object" && o.$kind === "GasCoin";
|
|
3263
|
+
if (b(a.suiCoinType) === b("0x2::sui::SUI") && s) {
|
|
3264
|
+
if (!r?.amount)
|
|
3265
|
+
throw new Error("Amount is required for sui coin");
|
|
3266
|
+
o = e.splitCoins(o, [r.amount]);
|
|
3267
|
+
}
|
|
3268
|
+
let i;
|
|
3269
|
+
return typeof r?.amount < "u" ? i = g(r.amount, e.pure.u64) : i = e.moveCall({
|
|
3270
|
+
target: "0x2::coin::value",
|
|
3271
|
+
arguments: [g(o, e.object)],
|
|
3272
|
+
typeArguments: [a.suiCoinType]
|
|
3273
|
+
}), r?.accountCap ? e.moveCall({
|
|
3274
|
+
target: `${t.package}::incentive_v3::deposit_with_account_cap`,
|
|
3275
|
+
arguments: [
|
|
3276
|
+
e.object("0x06"),
|
|
3277
|
+
e.object(t.storage),
|
|
3278
|
+
e.object(a.contract.pool),
|
|
3279
|
+
e.pure.u8(a.id),
|
|
3280
|
+
g(o, e.object),
|
|
3281
|
+
e.object(t.incentiveV2),
|
|
3282
|
+
e.object(t.incentiveV3),
|
|
3283
|
+
g(r.accountCap, e.object)
|
|
3284
|
+
],
|
|
3285
|
+
typeArguments: [a.suiCoinType]
|
|
3286
|
+
}) : e.moveCall({
|
|
3287
|
+
target: `${t.package}::incentive_v3::entry_deposit`,
|
|
3288
|
+
arguments: [
|
|
3289
|
+
e.object("0x06"),
|
|
3290
|
+
e.object(t.storage),
|
|
3291
|
+
e.object(a.contract.pool),
|
|
3292
|
+
e.pure.u8(a.id),
|
|
3293
|
+
g(o, e.object),
|
|
3294
|
+
i,
|
|
3295
|
+
e.object(t.incentiveV2),
|
|
3296
|
+
e.object(t.incentiveV3)
|
|
3297
|
+
],
|
|
3298
|
+
typeArguments: [a.suiCoinType]
|
|
3299
|
+
}), t.version === 2 && a.id === 0 && (!r?.env || r?.env === "prod") && e.moveCall({
|
|
3300
|
+
target: `${t.package}::pool::refresh_stake`,
|
|
3301
|
+
arguments: [e.object(a.contract.pool), e.object("0x05")]
|
|
3302
|
+
}), e;
|
|
3303
|
+
}
|
|
3304
|
+
async function Qe(e, n, o, r) {
|
|
3305
|
+
const t = await k({
|
|
3306
|
+
...r,
|
|
3307
|
+
cacheTime: w
|
|
3308
|
+
}), a = await A(n, r), s = g(o, e.pure.u64);
|
|
3309
|
+
let i;
|
|
3310
|
+
if (t.version === 1)
|
|
3311
|
+
if (r?.accountCap) {
|
|
3312
|
+
const [u] = e.moveCall({
|
|
3313
|
+
target: `${t.package}::incentive_v3::withdraw_with_account_cap`,
|
|
3314
|
+
arguments: [
|
|
3315
|
+
e.object("0x06"),
|
|
3316
|
+
e.object(t.priceOracle),
|
|
3317
|
+
e.object(t.storage),
|
|
3318
|
+
e.object(a.contract.pool),
|
|
3319
|
+
e.pure.u8(a.id),
|
|
3320
|
+
s,
|
|
3321
|
+
e.object(t.incentiveV2),
|
|
3322
|
+
e.object(t.incentiveV3),
|
|
3323
|
+
g(r.accountCap, e.object)
|
|
3324
|
+
],
|
|
3325
|
+
typeArguments: [a.suiCoinType]
|
|
3326
|
+
});
|
|
3327
|
+
i = u;
|
|
3328
|
+
} else {
|
|
3329
|
+
const [u] = e.moveCall({
|
|
3330
|
+
target: `${t.package}::incentive_v3::withdraw`,
|
|
3331
|
+
arguments: [
|
|
3332
|
+
e.object("0x06"),
|
|
3333
|
+
e.object(t.priceOracle),
|
|
3334
|
+
e.object(t.storage),
|
|
3335
|
+
e.object(a.contract.pool),
|
|
3336
|
+
e.pure.u8(a.id),
|
|
3337
|
+
s,
|
|
3338
|
+
e.object(t.incentiveV2),
|
|
3339
|
+
e.object(t.incentiveV3)
|
|
3340
|
+
],
|
|
3341
|
+
typeArguments: [a.suiCoinType]
|
|
3342
|
+
});
|
|
3343
|
+
i = u;
|
|
128
3344
|
}
|
|
129
|
-
|
|
130
|
-
|
|
3345
|
+
else if (r?.accountCap) {
|
|
3346
|
+
const [u] = e.moveCall({
|
|
3347
|
+
target: `${t.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
3348
|
+
arguments: [
|
|
3349
|
+
e.object("0x06"),
|
|
3350
|
+
e.object(t.priceOracle),
|
|
3351
|
+
e.object(t.storage),
|
|
3352
|
+
e.object(a.contract.pool),
|
|
3353
|
+
e.pure.u8(a.id),
|
|
3354
|
+
s,
|
|
3355
|
+
e.object(t.incentiveV2),
|
|
3356
|
+
e.object(t.incentiveV3),
|
|
3357
|
+
g(r.accountCap, e.object),
|
|
3358
|
+
e.object("0x05")
|
|
3359
|
+
],
|
|
3360
|
+
typeArguments: [a.suiCoinType]
|
|
3361
|
+
});
|
|
3362
|
+
i = u;
|
|
3363
|
+
} else {
|
|
3364
|
+
const [u] = e.moveCall({
|
|
3365
|
+
target: `${t.package}::incentive_v3::withdraw_v2`,
|
|
3366
|
+
arguments: [
|
|
3367
|
+
e.object("0x06"),
|
|
3368
|
+
e.object(t.priceOracle),
|
|
3369
|
+
e.object(t.storage),
|
|
3370
|
+
e.object(a.contract.pool),
|
|
3371
|
+
e.pure.u8(a.id),
|
|
3372
|
+
s,
|
|
3373
|
+
e.object(t.incentiveV2),
|
|
3374
|
+
e.object(t.incentiveV3),
|
|
3375
|
+
e.object("0x05")
|
|
3376
|
+
],
|
|
3377
|
+
typeArguments: [a.suiCoinType]
|
|
3378
|
+
});
|
|
3379
|
+
i = u;
|
|
3380
|
+
}
|
|
3381
|
+
return e.moveCall({
|
|
3382
|
+
target: "0x2::coin::from_balance",
|
|
3383
|
+
arguments: [i],
|
|
3384
|
+
typeArguments: [a.suiCoinType]
|
|
3385
|
+
});
|
|
3386
|
+
}
|
|
3387
|
+
async function Xe(e, n, o, r) {
|
|
3388
|
+
const t = await k({
|
|
3389
|
+
...r,
|
|
3390
|
+
cacheTime: w
|
|
3391
|
+
}), a = await A(n, r);
|
|
3392
|
+
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
3393
|
+
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
3394
|
+
const s = g(o, e.pure.u64);
|
|
3395
|
+
let i;
|
|
3396
|
+
if (t.version === 1)
|
|
3397
|
+
if (r?.accountCap) {
|
|
3398
|
+
const [u] = e.moveCall({
|
|
3399
|
+
target: `${t.package}::incentive_v3::borrow_with_account_cap`,
|
|
3400
|
+
arguments: [
|
|
3401
|
+
e.object("0x06"),
|
|
3402
|
+
e.object(t.priceOracle),
|
|
3403
|
+
e.object(t.storage),
|
|
3404
|
+
e.object(a.contract.pool),
|
|
3405
|
+
e.pure.u8(a.id),
|
|
3406
|
+
s,
|
|
3407
|
+
e.object(t.incentiveV2),
|
|
3408
|
+
e.object(t.incentiveV3),
|
|
3409
|
+
g(r.accountCap, e.object)
|
|
3410
|
+
],
|
|
3411
|
+
typeArguments: [a.suiCoinType]
|
|
3412
|
+
});
|
|
3413
|
+
i = u;
|
|
3414
|
+
} else {
|
|
3415
|
+
const [u] = e.moveCall({
|
|
3416
|
+
target: `${t.package}::incentive_v3::borrow`,
|
|
3417
|
+
arguments: [
|
|
3418
|
+
e.object("0x06"),
|
|
3419
|
+
e.object(t.priceOracle),
|
|
3420
|
+
e.object(t.storage),
|
|
3421
|
+
e.object(a.contract.pool),
|
|
3422
|
+
e.pure.u8(a.id),
|
|
3423
|
+
s,
|
|
3424
|
+
e.object(t.incentiveV2),
|
|
3425
|
+
e.object(t.incentiveV3)
|
|
3426
|
+
],
|
|
3427
|
+
typeArguments: [a.suiCoinType]
|
|
3428
|
+
});
|
|
3429
|
+
i = u;
|
|
131
3430
|
}
|
|
132
|
-
|
|
133
|
-
|
|
3431
|
+
else if (r?.accountCap) {
|
|
3432
|
+
const [u] = e.moveCall({
|
|
3433
|
+
target: `${t.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
3434
|
+
arguments: [
|
|
3435
|
+
e.object("0x06"),
|
|
3436
|
+
e.object(t.priceOracle),
|
|
3437
|
+
e.object(t.storage),
|
|
3438
|
+
e.object(a.contract.pool),
|
|
3439
|
+
e.pure.u8(a.id),
|
|
3440
|
+
s,
|
|
3441
|
+
e.object(t.incentiveV2),
|
|
3442
|
+
e.object(t.incentiveV3),
|
|
3443
|
+
g(r.accountCap, e.object),
|
|
3444
|
+
e.object("0x05")
|
|
3445
|
+
],
|
|
3446
|
+
typeArguments: [a.suiCoinType]
|
|
3447
|
+
});
|
|
3448
|
+
i = u;
|
|
3449
|
+
} else {
|
|
3450
|
+
const [u] = e.moveCall({
|
|
3451
|
+
target: `${t.package}::incentive_v3::borrow_v2`,
|
|
3452
|
+
arguments: [
|
|
3453
|
+
e.object("0x06"),
|
|
3454
|
+
e.object(t.priceOracle),
|
|
3455
|
+
e.object(t.storage),
|
|
3456
|
+
e.object(a.contract.pool),
|
|
3457
|
+
e.pure.u8(a.id),
|
|
3458
|
+
s,
|
|
3459
|
+
e.object(t.incentiveV2),
|
|
3460
|
+
e.object(t.incentiveV3),
|
|
3461
|
+
e.object("0x05")
|
|
3462
|
+
],
|
|
3463
|
+
typeArguments: [a.suiCoinType]
|
|
3464
|
+
});
|
|
3465
|
+
i = u;
|
|
134
3466
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
3467
|
+
return e.moveCall({
|
|
3468
|
+
target: "0x2::coin::from_balance",
|
|
3469
|
+
arguments: [e.object(i)],
|
|
3470
|
+
typeArguments: [a.suiCoinType]
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
async function xe(e, n, o, r) {
|
|
3474
|
+
const t = await k({
|
|
3475
|
+
...r,
|
|
3476
|
+
cacheTime: w
|
|
3477
|
+
}), a = await A(n, r), s = typeof o == "object" && o.$kind === "GasCoin";
|
|
3478
|
+
if (b(a.suiCoinType) === b("0x2::sui::SUI") && s) {
|
|
3479
|
+
if (!r?.amount)
|
|
3480
|
+
throw new Error("Amount is required for sui coin");
|
|
3481
|
+
o = e.splitCoins(o, [r.amount]);
|
|
3482
|
+
}
|
|
3483
|
+
let i;
|
|
3484
|
+
if (typeof r?.amount < "u" ? i = g(r.amount, e.pure.u64) : i = e.moveCall({
|
|
3485
|
+
target: "0x2::coin::value",
|
|
3486
|
+
arguments: [g(o, e.object)],
|
|
3487
|
+
typeArguments: [a.suiCoinType]
|
|
3488
|
+
}), r?.accountCap) {
|
|
3489
|
+
const [c] = e.moveCall({
|
|
3490
|
+
target: `${t.package}::incentive_v3::repay_with_account_cap`,
|
|
3491
|
+
arguments: [
|
|
3492
|
+
e.object("0x06"),
|
|
3493
|
+
e.object(t.priceOracle),
|
|
3494
|
+
e.object(t.storage),
|
|
3495
|
+
e.object(a.contract.pool),
|
|
3496
|
+
e.pure.u8(a.id),
|
|
3497
|
+
g(o, e.object),
|
|
3498
|
+
e.object(t.incentiveV2),
|
|
3499
|
+
e.object(t.incentiveV3),
|
|
3500
|
+
g(r.accountCap, e.object)
|
|
3501
|
+
],
|
|
3502
|
+
typeArguments: [a.suiCoinType]
|
|
3503
|
+
});
|
|
3504
|
+
return e.moveCall({
|
|
3505
|
+
target: "0x2::coin::from_balance",
|
|
3506
|
+
arguments: [c],
|
|
3507
|
+
typeArguments: [a.suiCoinType]
|
|
3508
|
+
});
|
|
3509
|
+
} else
|
|
3510
|
+
return e.moveCall({
|
|
3511
|
+
target: `${t.package}::incentive_v3::entry_repay`,
|
|
3512
|
+
arguments: [
|
|
3513
|
+
e.object("0x06"),
|
|
3514
|
+
e.object(t.priceOracle),
|
|
3515
|
+
e.object(t.storage),
|
|
3516
|
+
e.object(a.contract.pool),
|
|
3517
|
+
e.pure.u8(a.id),
|
|
3518
|
+
g(o, e.object),
|
|
3519
|
+
i,
|
|
3520
|
+
e.object(t.incentiveV2),
|
|
3521
|
+
e.object(t.incentiveV3)
|
|
3522
|
+
],
|
|
3523
|
+
typeArguments: [a.suiCoinType]
|
|
3524
|
+
}), e;
|
|
3525
|
+
}
|
|
3526
|
+
var N = "main";
|
|
3527
|
+
var M = {
|
|
3528
|
+
main: {
|
|
3529
|
+
id: 0,
|
|
3530
|
+
key: "main",
|
|
3531
|
+
name: "Main Market"
|
|
3532
|
+
}
|
|
3533
|
+
};
|
|
3534
|
+
var _ = (e) => {
|
|
3535
|
+
const o = Object.values(M).find((r) => typeof e == "number" ? r.id === e : typeof e == "string" ? r.key === e : r.id === e.id);
|
|
3536
|
+
if (!o)
|
|
3537
|
+
throw new Error("Market not found");
|
|
3538
|
+
return o;
|
|
3539
|
+
};
|
|
3540
|
+
var k = $(
|
|
3541
|
+
B(
|
|
3542
|
+
async (e) => {
|
|
3543
|
+
const n = _(e?.market || N), o = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${V.version}&market=${n.key}`;
|
|
3544
|
+
return (await fetch(o, { headers: E }).then((t) => t.json())).data;
|
|
147
3545
|
}
|
|
148
|
-
|
|
149
|
-
|
|
3546
|
+
)
|
|
3547
|
+
);
|
|
3548
|
+
var w = 1e3 * 60 * 5;
|
|
3549
|
+
var x = $(
|
|
3550
|
+
B(
|
|
3551
|
+
async (e, n) => {
|
|
3552
|
+
const o = await k({
|
|
3553
|
+
cacheTime: w,
|
|
3554
|
+
...n
|
|
3555
|
+
}), r = new transactions.Transaction(), t = n?.client ?? P;
|
|
3556
|
+
r.moveCall({
|
|
3557
|
+
target: `${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
3558
|
+
arguments: [r.object(o.emode.contract.registryObject), r.pure.address(e)]
|
|
3559
|
+
});
|
|
3560
|
+
const s = (await t.devInspectTransactionBlock({
|
|
3561
|
+
transactionBlock: r,
|
|
3562
|
+
sender: e
|
|
3563
|
+
})).results[0].returnValues, i = bcs$1.bcs.vector(bcs$1.bcs.u64()).parse(Uint8Array.from(s[0][0])), c = bcs$1.bcs.vector(bcs$1.bcs.u64()).parse(Uint8Array.from(s[1][0])), u = bcs$1.bcs.vector(bcs$1.bcs.Address).parse(Uint8Array.from(s[2][0]));
|
|
3564
|
+
return i.map((d, f) => ({
|
|
3565
|
+
marketId: Number(d),
|
|
3566
|
+
emodeId: Number(c[f]),
|
|
3567
|
+
accountCap: u[f].toString()
|
|
3568
|
+
}));
|
|
150
3569
|
}
|
|
151
|
-
|
|
152
|
-
|
|
3570
|
+
)
|
|
3571
|
+
);
|
|
3572
|
+
async function ee(e, n, o, r, t, a, s) {
|
|
3573
|
+
const i = await k({
|
|
3574
|
+
...s,
|
|
3575
|
+
cacheTime: w
|
|
3576
|
+
}), c = await A(o, s);
|
|
3577
|
+
return e.moveCall({
|
|
3578
|
+
target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
3579
|
+
arguments: [
|
|
3580
|
+
e.object("0x06"),
|
|
3581
|
+
e.object(i.storage),
|
|
3582
|
+
e.object(i.oracle.priceOracle),
|
|
3583
|
+
we(e, c),
|
|
3584
|
+
g(n, e.pure.address),
|
|
3585
|
+
g(c.id, e.pure.u8),
|
|
3586
|
+
g(r, e.pure.u64),
|
|
3587
|
+
g(t, e.pure.u64),
|
|
3588
|
+
g(a, e.pure.bool)
|
|
3589
|
+
],
|
|
3590
|
+
typeArguments: [c.suiCoinType]
|
|
3591
|
+
});
|
|
3592
|
+
}
|
|
3593
|
+
async function Ae(e, n, o) {
|
|
3594
|
+
return ee(e, n, 0, 0, 0, false, o);
|
|
3595
|
+
}
|
|
3596
|
+
async function te(e, n, o) {
|
|
3597
|
+
const r = new transactions.Transaction(), t = o?.client ?? P, a = await R({
|
|
3598
|
+
...o,
|
|
3599
|
+
markets: Object.values(M)
|
|
3600
|
+
}), s = H(a);
|
|
3601
|
+
for (let d of n) {
|
|
3602
|
+
const f = await k({
|
|
3603
|
+
...o,
|
|
3604
|
+
cacheTime: w,
|
|
3605
|
+
market: d.market
|
|
3606
|
+
});
|
|
3607
|
+
r.moveCall({
|
|
3608
|
+
target: `${f.uiGetter}::getter_unchecked::get_user_state`,
|
|
3609
|
+
arguments: [r.object(f.storage), r.pure.address(d.address)]
|
|
3610
|
+
});
|
|
153
3611
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
3612
|
+
const c = ((await t.devInspectTransactionBlock({
|
|
3613
|
+
transactionBlock: r,
|
|
3614
|
+
sender: e
|
|
3615
|
+
})).results || []).map((d) => d.returnValues?.map((f) => bcs$1.bcs.vector(fe).parse(Uint8Array.from(f[0])))[0] || []), u = [];
|
|
3616
|
+
return c.forEach((d, f) => {
|
|
3617
|
+
const v = n[f], y = _(v.market);
|
|
3618
|
+
d.forEach((l) => {
|
|
3619
|
+
if (l.supply_balance === "0" && l.borrow_balance === "0" && (v.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
|
|
3620
|
+
return;
|
|
3621
|
+
const h = s[`${y.key}-${l.asset_id}`];
|
|
3622
|
+
if (!h)
|
|
3623
|
+
return;
|
|
3624
|
+
const j = Y(
|
|
3625
|
+
l.supply_balance,
|
|
3626
|
+
h.currentSupplyIndex
|
|
3627
|
+
).toString(), I = Y(
|
|
3628
|
+
l.borrow_balance,
|
|
3629
|
+
h.currentBorrowIndex
|
|
3630
|
+
).toString();
|
|
3631
|
+
u.push({
|
|
3632
|
+
supplyBalance: j,
|
|
3633
|
+
borrowBalance: I,
|
|
3634
|
+
assetId: l.asset_id,
|
|
3635
|
+
market: y.key,
|
|
3636
|
+
pool: h,
|
|
3637
|
+
emodeId: v.emodeId
|
|
3638
|
+
});
|
|
3639
|
+
});
|
|
3640
|
+
}), u;
|
|
3641
|
+
}
|
|
3642
|
+
async function ct(e, n) {
|
|
3643
|
+
const o = n?.client ?? P, r = new transactions.Transaction();
|
|
3644
|
+
await Ae(r, e, n);
|
|
3645
|
+
const t = await o.devInspectTransactionBlock({
|
|
3646
|
+
transactionBlock: r,
|
|
3647
|
+
sender: e
|
|
3648
|
+
}), a = L(t, [bcs$1.bcs.u256()]);
|
|
3649
|
+
return X(Number(a[0]) || 0);
|
|
3650
|
+
}
|
|
3651
|
+
var $e = $(
|
|
3652
|
+
async (e, n) => {
|
|
3653
|
+
const o = [], r = (n?.markets || Object.keys(M)).map((i) => _(i));
|
|
3654
|
+
let t = [];
|
|
3655
|
+
try {
|
|
3656
|
+
t = await x(e, n);
|
|
3657
|
+
} catch (i) {
|
|
3658
|
+
console.error(i);
|
|
3659
|
+
}
|
|
3660
|
+
const a = r.map((i) => ({
|
|
3661
|
+
address: e,
|
|
3662
|
+
market: i.key
|
|
3663
|
+
})).concat(
|
|
3664
|
+
t.filter((i) => !!r.find((c) => c.id === i.marketId)).map((i) => ({
|
|
3665
|
+
address: i.accountCap,
|
|
3666
|
+
market: _(i.marketId).key,
|
|
3667
|
+
emodeId: i.emodeId
|
|
3668
|
+
}))
|
|
3669
|
+
);
|
|
3670
|
+
return (await te(e, a, n)).forEach((i) => {
|
|
3671
|
+
const c = typeof i.emodeId == "number" ? t.find((u) => {
|
|
3672
|
+
const d = _(i.market);
|
|
3673
|
+
return u.emodeId === i.emodeId && u.marketId === d.id;
|
|
3674
|
+
}) : void 0;
|
|
3675
|
+
if (c) {
|
|
3676
|
+
if (!i.pool.emodes.find((d) => d.emodeId === c.emodeId))
|
|
3677
|
+
return;
|
|
3678
|
+
if (bignumber_default(i.supplyBalance).gte(0)) {
|
|
3679
|
+
const d = bignumber_default(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, bignumber_default.ROUND_DOWN), f = q(i.pool, c);
|
|
3680
|
+
if (d.gt(0) || f.emode.isCollateral)
|
|
3681
|
+
try {
|
|
3682
|
+
o.push({
|
|
3683
|
+
id: `${i.pool.uniqueId}_${c.emodeId}_navi-lending-emode-supply-${T()}`,
|
|
3684
|
+
wallet: e,
|
|
3685
|
+
protocol: "navi",
|
|
3686
|
+
market: i.market,
|
|
3687
|
+
type: "navi-lending-emode-supply",
|
|
3688
|
+
"navi-lending-emode-supply": {
|
|
3689
|
+
amount: d.toString(),
|
|
3690
|
+
pool: q(i.pool, c),
|
|
3691
|
+
token: i.pool.token,
|
|
3692
|
+
valueUSD: d.multipliedBy(i.pool.oracle.price).toString(),
|
|
3693
|
+
emodeCap: c
|
|
3694
|
+
}
|
|
3695
|
+
});
|
|
3696
|
+
} catch (v) {
|
|
3697
|
+
console.error(v);
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
if (bignumber_default(i.borrowBalance).gte(0)) {
|
|
3701
|
+
const d = bignumber_default(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, bignumber_default.ROUND_DOWN), f = q(i.pool, c);
|
|
3702
|
+
if (d.gt(0) || f.emode.isDebt)
|
|
3703
|
+
try {
|
|
3704
|
+
o.push({
|
|
3705
|
+
id: `${i.pool.uniqueId}_${c.emodeId}_navi-lending-emode-borrow-${T()}`,
|
|
3706
|
+
wallet: e,
|
|
3707
|
+
protocol: "navi",
|
|
3708
|
+
market: i.market,
|
|
3709
|
+
type: "navi-lending-emode-borrow",
|
|
3710
|
+
"navi-lending-emode-borrow": {
|
|
3711
|
+
amount: d.toString(),
|
|
3712
|
+
pool: q(i.pool, c),
|
|
3713
|
+
token: i.pool.token,
|
|
3714
|
+
valueUSD: d.multipliedBy(i.pool.oracle.price).toString(),
|
|
3715
|
+
emodeCap: c
|
|
3716
|
+
}
|
|
3717
|
+
});
|
|
3718
|
+
} catch (v) {
|
|
3719
|
+
console.error(v);
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
} else {
|
|
3723
|
+
if (bignumber_default(i.supplyBalance).gt(0)) {
|
|
3724
|
+
const u = bignumber_default(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, bignumber_default.ROUND_DOWN);
|
|
3725
|
+
o.push({
|
|
3726
|
+
id: `${i.pool.uniqueId}_navi-lending-supply-${T()}`,
|
|
3727
|
+
wallet: e,
|
|
3728
|
+
protocol: "navi",
|
|
3729
|
+
type: "navi-lending-supply",
|
|
3730
|
+
market: i.market,
|
|
3731
|
+
"navi-lending-supply": {
|
|
3732
|
+
amount: u.toString(),
|
|
3733
|
+
pool: i.pool,
|
|
3734
|
+
token: i.pool.token,
|
|
3735
|
+
valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
|
|
3736
|
+
}
|
|
3737
|
+
});
|
|
3738
|
+
}
|
|
3739
|
+
if (bignumber_default(i.borrowBalance).gt(0)) {
|
|
3740
|
+
const u = bignumber_default(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, bignumber_default.ROUND_DOWN);
|
|
3741
|
+
o.push({
|
|
3742
|
+
id: `${i.pool.uniqueId}_navi-lending-borrow-${T()}`,
|
|
3743
|
+
wallet: e,
|
|
3744
|
+
protocol: "navi",
|
|
3745
|
+
market: i.market,
|
|
3746
|
+
type: "navi-lending-borrow",
|
|
3747
|
+
"navi-lending-borrow": {
|
|
3748
|
+
amount: u.toString(),
|
|
3749
|
+
pool: i.pool,
|
|
3750
|
+
token: i.pool.token,
|
|
3751
|
+
valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
|
|
3752
|
+
}
|
|
3753
|
+
});
|
|
168
3754
|
}
|
|
169
3755
|
}
|
|
170
|
-
}
|
|
171
|
-
return results;
|
|
3756
|
+
}), o;
|
|
172
3757
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
3758
|
+
);
|
|
3759
|
+
var oe = new pythSuiJs.SuiPriceServiceConnection("https://hermes.pyth.network", {
|
|
3760
|
+
timeout: 1e4
|
|
3761
|
+
});
|
|
3762
|
+
async function Pe(e, n) {
|
|
3763
|
+
try {
|
|
3764
|
+
const o = [], r = n?.client ?? P, t = e.map((s) => s.priceInfoObject), a = await r.multiGetObjects({
|
|
3765
|
+
ids: Array.from(new Set(t)),
|
|
3766
|
+
options: { showContent: true }
|
|
3767
|
+
});
|
|
3768
|
+
for (const s of a) {
|
|
3769
|
+
const i = s.data;
|
|
3770
|
+
if (!i || !i.content || i.content.dataType !== "moveObject") {
|
|
3771
|
+
console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
|
|
3772
|
+
continue;
|
|
3773
|
+
}
|
|
3774
|
+
const c = e.find((l) => l.priceInfoObject == i.objectId);
|
|
3775
|
+
if (!c) {
|
|
3776
|
+
console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
|
|
3777
|
+
continue;
|
|
181
3778
|
}
|
|
3779
|
+
const u = i.content.fields.price_info.fields.price_feed.fields.price.fields, { magnitude: d, negative: f } = u.price.fields, v = u.conf, y = u.timestamp;
|
|
3780
|
+
o.push({
|
|
3781
|
+
priceFeedId: c.priceFeedId,
|
|
3782
|
+
priceInfoObject: c.priceInfoObject,
|
|
3783
|
+
price: f ? "-" + d : d,
|
|
3784
|
+
conf: v,
|
|
3785
|
+
publishTime: Number(y),
|
|
3786
|
+
expiration: c.expiration
|
|
3787
|
+
});
|
|
182
3788
|
}
|
|
183
|
-
return
|
|
3789
|
+
return o;
|
|
3790
|
+
} catch (o) {
|
|
3791
|
+
console.error(o, `Polling Sui on-chain price for ${e} failed.`);
|
|
3792
|
+
return;
|
|
184
3793
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
3794
|
+
}
|
|
3795
|
+
async function Se(e, n) {
|
|
3796
|
+
try {
|
|
3797
|
+
const o = [], r = await Pe(e, n);
|
|
3798
|
+
if (!r) return o;
|
|
3799
|
+
const t = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
3800
|
+
for (const a of r) {
|
|
3801
|
+
if (a.publishTime > t) {
|
|
3802
|
+
console.warn(
|
|
3803
|
+
`pyth price feed is invalid, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`
|
|
3804
|
+
);
|
|
3805
|
+
continue;
|
|
196
3806
|
}
|
|
3807
|
+
const s = a.expiration || 60;
|
|
3808
|
+
t - a.publishTime > s && (console.info(
|
|
3809
|
+
`stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`
|
|
3810
|
+
), o.push(a.priceFeedId));
|
|
197
3811
|
}
|
|
198
|
-
|
|
199
|
-
|
|
3812
|
+
return o;
|
|
3813
|
+
} catch (o) {
|
|
3814
|
+
throw new Error(`failed to get pyth stale price feed id, msg: ${o.message}`);
|
|
3815
|
+
}
|
|
3816
|
+
}
|
|
3817
|
+
async function Ve(e, n, o) {
|
|
3818
|
+
const r = o?.client ?? P, t = await k({
|
|
3819
|
+
...o,
|
|
3820
|
+
cacheTime: w
|
|
3821
|
+
});
|
|
3822
|
+
try {
|
|
3823
|
+
const a = await oe.getPriceFeedsUpdateData(n);
|
|
3824
|
+
return await new pythSuiJs.SuiPythClient(
|
|
3825
|
+
r,
|
|
3826
|
+
t.oracle.pythStateId,
|
|
3827
|
+
t.oracle.wormholeStateId
|
|
3828
|
+
).updatePriceFeeds(e, a, n);
|
|
3829
|
+
} catch (a) {
|
|
3830
|
+
throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
async function Ee(e, n, o) {
|
|
3834
|
+
const r = await k({
|
|
3835
|
+
...o,
|
|
3836
|
+
cacheTime: w
|
|
3837
|
+
});
|
|
3838
|
+
if (o?.updatePythPriceFeeds) {
|
|
3839
|
+
const t = n.filter((a) => !!a.pythPriceFeedId && !!a.pythPriceInfoObject).map((a) => ({
|
|
3840
|
+
priceFeedId: a.pythPriceFeedId,
|
|
3841
|
+
priceInfoObject: a.pythPriceInfoObject,
|
|
3842
|
+
expiration: 30
|
|
3843
|
+
}));
|
|
3844
|
+
try {
|
|
3845
|
+
const a = await Se(t, o);
|
|
3846
|
+
a.length > 0 && await Ve(e, a, o);
|
|
3847
|
+
} catch {
|
|
3848
|
+
console.error("Failed to update Pyth price feeds");
|
|
200
3849
|
}
|
|
201
|
-
return results;
|
|
202
3850
|
}
|
|
203
|
-
|
|
204
|
-
|
|
3851
|
+
for (const t of n)
|
|
3852
|
+
o?.env === "dev" ? e.moveCall({
|
|
3853
|
+
target: `${r.oracle.packageId}::oracle_pro::update_single_price`,
|
|
3854
|
+
arguments: [
|
|
3855
|
+
e.object("0x6"),
|
|
3856
|
+
// Clock object
|
|
3857
|
+
e.object(r.oracle.oracleConfig),
|
|
3858
|
+
// Oracle configuration
|
|
3859
|
+
e.object(r.oracle.priceOracle),
|
|
3860
|
+
// Price oracle contract
|
|
3861
|
+
e.object(r.oracle.supraOracleHolder),
|
|
3862
|
+
// Supra oracle holder
|
|
3863
|
+
e.object(t.pythPriceInfoObject),
|
|
3864
|
+
// Pyth price info object
|
|
3865
|
+
e.pure.address(t.feedId)
|
|
3866
|
+
// Price feed ID
|
|
3867
|
+
]
|
|
3868
|
+
}) : e.moveCall({
|
|
3869
|
+
target: `${r.oracle.packageId}::oracle_pro::update_single_price_v2`,
|
|
3870
|
+
arguments: [
|
|
3871
|
+
e.object("0x6"),
|
|
3872
|
+
// Clock object
|
|
3873
|
+
e.object(r.oracle.oracleConfig),
|
|
3874
|
+
// Oracle configuration
|
|
3875
|
+
e.object(r.oracle.priceOracle),
|
|
3876
|
+
// Price oracle contract
|
|
3877
|
+
e.object(r.oracle.supraOracleHolder),
|
|
3878
|
+
// Supra oracle holder
|
|
3879
|
+
e.object(t.pythPriceInfoObject),
|
|
3880
|
+
// Pyth price info object
|
|
3881
|
+
e.object(r.oracle.switchboardAggregator),
|
|
3882
|
+
e.pure.address(t.feedId)
|
|
3883
|
+
// Price feed ID
|
|
3884
|
+
]
|
|
3885
|
+
});
|
|
3886
|
+
return e;
|
|
3887
|
+
}
|
|
3888
|
+
async function ne(e) {
|
|
3889
|
+
return (await k({
|
|
3890
|
+
...e,
|
|
3891
|
+
cacheTime: w
|
|
3892
|
+
})).oracle.feeds;
|
|
3893
|
+
}
|
|
3894
|
+
function Me(e, n) {
|
|
3895
|
+
return e.filter((o) => !!(n?.lendingState && n.lendingState.find((t) => t.assetId === o.assetId) || n?.lendingPositions && n.lendingPositions.find((t) => [
|
|
3896
|
+
"navi-lending-supply",
|
|
3897
|
+
"navi-lending-borrow",
|
|
3898
|
+
"navi-lending-emode-supply",
|
|
3899
|
+
"navi-lending-emode-borrow"
|
|
3900
|
+
].includes(t.type) ? t[t.type]?.pool?.id === o.assetId : false) || n?.pools && n.pools.find((t) => t.id === o.assetId)));
|
|
3901
|
+
}
|
|
3902
|
+
async function mt(e, n, o, r) {
|
|
3903
|
+
try {
|
|
3904
|
+
const t = await ne({
|
|
3905
|
+
...r
|
|
3906
|
+
}), a = [];
|
|
3907
|
+
o.forEach((u) => {
|
|
3908
|
+
a.includes(u.market) || a.push(u.market);
|
|
3909
|
+
});
|
|
3910
|
+
const s = await $e(n, {
|
|
3911
|
+
...r,
|
|
3912
|
+
markets: a
|
|
3913
|
+
}), i = Me(t, {
|
|
3914
|
+
lendingPositions: s,
|
|
3915
|
+
pools: o
|
|
3916
|
+
});
|
|
3917
|
+
return await Ee(e, i, {
|
|
3918
|
+
updatePythPriceFeeds: true,
|
|
3919
|
+
...r
|
|
3920
|
+
});
|
|
3921
|
+
} catch (t) {
|
|
3922
|
+
if (r?.throws)
|
|
3923
|
+
throw t;
|
|
3924
|
+
return console.error(t), e;
|
|
205
3925
|
}
|
|
206
|
-
|
|
207
|
-
|
|
3926
|
+
}
|
|
3927
|
+
async function De(e, n, o) {
|
|
3928
|
+
const r = o?.client ?? P, t = new transactions.Transaction(), a = await R({
|
|
3929
|
+
...o,
|
|
3930
|
+
markets: Object.values(M),
|
|
3931
|
+
cacheTime: w
|
|
3932
|
+
}), s = await ne(o);
|
|
3933
|
+
for (let d of n) {
|
|
3934
|
+
const f = await k({
|
|
3935
|
+
...o,
|
|
3936
|
+
cacheTime: w,
|
|
3937
|
+
market: d.market
|
|
3938
|
+
});
|
|
3939
|
+
t.moveCall({
|
|
3940
|
+
target: `${f.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
|
|
3941
|
+
arguments: [
|
|
3942
|
+
t.object("0x06"),
|
|
3943
|
+
// Clock object
|
|
3944
|
+
t.object(f.storage),
|
|
3945
|
+
// Protocol storage
|
|
3946
|
+
t.object(f.incentiveV3),
|
|
3947
|
+
// Incentive V3 contract
|
|
3948
|
+
t.pure.address(d.address)
|
|
3949
|
+
// User address
|
|
3950
|
+
]
|
|
3951
|
+
});
|
|
208
3952
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
3953
|
+
const i = await r.devInspectTransactionBlock({
|
|
3954
|
+
transactionBlock: t,
|
|
3955
|
+
sender: e
|
|
3956
|
+
}), c = [];
|
|
3957
|
+
i?.results?.forEach((d) => {
|
|
3958
|
+
c.push(
|
|
3959
|
+
L(
|
|
3960
|
+
{
|
|
3961
|
+
results: [d]
|
|
3962
|
+
},
|
|
3963
|
+
[
|
|
3964
|
+
bcs$1.bcs.vector(bcs$1.bcs.string()),
|
|
3965
|
+
// Asset coin types
|
|
3966
|
+
bcs$1.bcs.vector(bcs$1.bcs.string()),
|
|
3967
|
+
// Reward coin types
|
|
3968
|
+
bcs$1.bcs.vector(bcs$1.bcs.u8()),
|
|
3969
|
+
// Reward options
|
|
3970
|
+
bcs$1.bcs.vector(bcs$1.bcs.Address),
|
|
3971
|
+
// Rule IDs
|
|
3972
|
+
bcs$1.bcs.vector(bcs$1.bcs.u256())
|
|
3973
|
+
// Claimable amounts
|
|
3974
|
+
]
|
|
3975
|
+
)
|
|
3976
|
+
);
|
|
3977
|
+
});
|
|
3978
|
+
const u = [];
|
|
3979
|
+
return c.forEach((d, f) => {
|
|
3980
|
+
const v = n[f];
|
|
3981
|
+
if (d.length === 5 && Array.isArray(d[0])) {
|
|
3982
|
+
const y = d[0].length;
|
|
3983
|
+
for (let l = 0; l < y; l++) {
|
|
3984
|
+
const h = s.find(
|
|
3985
|
+
(I) => b(I.coinType) === b(d[1][l])
|
|
3986
|
+
), j = a.find(
|
|
3987
|
+
(I) => b(I.coinType) === b(d[0][l]) && I.market === v.market
|
|
3988
|
+
);
|
|
3989
|
+
!h || !j || u.push({
|
|
3990
|
+
assetId: j.id,
|
|
3991
|
+
assetCoinType: b(d[0][l]),
|
|
3992
|
+
rewardCoinType: b(d[1][l]),
|
|
3993
|
+
option: Number(d[2][l]),
|
|
3994
|
+
userClaimableReward: Number(d[4][l]) / Math.pow(10, h.priceDecimal),
|
|
3995
|
+
ruleIds: Array.isArray(d[3][l]) ? d[3][l] : [d[3][l]],
|
|
3996
|
+
market: v.market,
|
|
3997
|
+
owner: v.owner,
|
|
3998
|
+
address: v.address,
|
|
3999
|
+
emodeId: v.emodeId
|
|
4000
|
+
});
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
4003
|
+
}), u;
|
|
214
4004
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
4005
|
+
async function vt(e, n) {
|
|
4006
|
+
const o = (n?.markets || [M.main]).map((a) => _(a));
|
|
4007
|
+
let r = [];
|
|
4008
|
+
try {
|
|
4009
|
+
r = await x(e, n);
|
|
4010
|
+
} catch (a) {
|
|
4011
|
+
console.error(a);
|
|
220
4012
|
}
|
|
4013
|
+
const t = o.map((a) => ({
|
|
4014
|
+
address: e,
|
|
4015
|
+
owner: e,
|
|
4016
|
+
market: a.key
|
|
4017
|
+
})).concat(
|
|
4018
|
+
r.filter((a) => !!o.find((s) => s.id === a.marketId)).map((a) => {
|
|
4019
|
+
const s = _(a.marketId);
|
|
4020
|
+
return {
|
|
4021
|
+
address: a.accountCap,
|
|
4022
|
+
owner: e,
|
|
4023
|
+
market: s.key,
|
|
4024
|
+
emodeId: a.emodeId
|
|
4025
|
+
};
|
|
4026
|
+
})
|
|
4027
|
+
);
|
|
4028
|
+
return await De(e, t, n);
|
|
221
4029
|
}
|
|
222
|
-
function
|
|
223
|
-
|
|
4030
|
+
function wt(e) {
|
|
4031
|
+
const n = /* @__PURE__ */ new Map();
|
|
4032
|
+
e.forEach((r) => {
|
|
4033
|
+
const t = r.assetId, a = r.option, s = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
|
|
4034
|
+
n.has(s) ? n.get(s).total += r.userClaimableReward : n.set(s, {
|
|
4035
|
+
assetId: t,
|
|
4036
|
+
rewardType: a,
|
|
4037
|
+
coinType: r.rewardCoinType,
|
|
4038
|
+
total: Number(r.userClaimableReward),
|
|
4039
|
+
market: r.market
|
|
4040
|
+
});
|
|
4041
|
+
});
|
|
4042
|
+
const o = /* @__PURE__ */ new Map();
|
|
4043
|
+
for (const { assetId: r, rewardType: t, coinType: a, total: s, market: i } of n.values()) {
|
|
4044
|
+
const c = `${r}-${t}-${i}`;
|
|
4045
|
+
o.has(c) || o.set(c, { assetId: r, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
|
|
4046
|
+
const u = o.get(c);
|
|
4047
|
+
u.rewards.set(a, (u.rewards.get(a) || 0) + s);
|
|
4048
|
+
}
|
|
4049
|
+
return Array.from(o.values()).map((r) => ({
|
|
4050
|
+
assetId: r.assetId,
|
|
4051
|
+
rewardType: r.rewardType,
|
|
4052
|
+
market: r.market,
|
|
4053
|
+
rewards: Array.from(r.rewards.entries()).map(([t, a]) => ({
|
|
4054
|
+
coinType: t,
|
|
4055
|
+
available: a.toFixed(6)
|
|
4056
|
+
}))
|
|
4057
|
+
}));
|
|
4058
|
+
}
|
|
4059
|
+
async function Ct(e, n, o) {
|
|
4060
|
+
const r = await R({
|
|
4061
|
+
...o,
|
|
4062
|
+
markets: Object.values(M),
|
|
4063
|
+
cacheTime: w
|
|
4064
|
+
}), t = /* @__PURE__ */ new Map();
|
|
4065
|
+
for (const s of n) {
|
|
4066
|
+
const { rewardCoinType: i, ruleIds: c, market: u, owner: d, address: f, emodeId: v } = s, y = `${i}___${f}`;
|
|
4067
|
+
for (const l of c) {
|
|
4068
|
+
t.has(y) || t.set(y, {
|
|
4069
|
+
assetIds: [],
|
|
4070
|
+
ruleIds: [],
|
|
4071
|
+
amount: 0,
|
|
4072
|
+
market: u,
|
|
4073
|
+
owner: d,
|
|
4074
|
+
address: f,
|
|
4075
|
+
isEMode: typeof v < "u"
|
|
4076
|
+
});
|
|
4077
|
+
const h = t.get(y);
|
|
4078
|
+
h.assetIds.push(s.assetCoinType.replace("0x", "")), h.ruleIds.push(l), h.amount += s.userClaimableReward;
|
|
4079
|
+
}
|
|
4080
|
+
}
|
|
4081
|
+
const a = [];
|
|
4082
|
+
for (const [
|
|
4083
|
+
s,
|
|
4084
|
+
{ assetIds: i, ruleIds: c, amount: u, market: d, owner: f, address: v, isEMode: y }
|
|
4085
|
+
] of t) {
|
|
4086
|
+
const l = await k({
|
|
4087
|
+
...o,
|
|
4088
|
+
cacheTime: w,
|
|
4089
|
+
market: d
|
|
4090
|
+
}), h = s.split("___")[0], j = r.find(
|
|
4091
|
+
(S) => b(S.suiCoinType) === b(h) && S.market === d
|
|
4092
|
+
);
|
|
4093
|
+
if (!j || !j.contract.rewardFundId)
|
|
4094
|
+
throw new Error(`No matching rewardFund found for reward coin: ${h} ${d}`);
|
|
4095
|
+
const I = j.contract.rewardFundId;
|
|
4096
|
+
if (o?.accountCap && !o.customCoinReceive)
|
|
4097
|
+
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
4098
|
+
if (o?.customCoinReceive) {
|
|
4099
|
+
let S;
|
|
4100
|
+
o.accountCap ? S = e.moveCall({
|
|
4101
|
+
target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
4102
|
+
arguments: [
|
|
4103
|
+
e.object("0x06"),
|
|
4104
|
+
// Clock object
|
|
4105
|
+
e.object(l.incentiveV3),
|
|
4106
|
+
// Incentive V3 contract
|
|
4107
|
+
e.object(l.storage),
|
|
4108
|
+
// Protocol storage
|
|
4109
|
+
e.object(I),
|
|
4110
|
+
// Reward fund
|
|
4111
|
+
e.pure.vector("string", i),
|
|
4112
|
+
// Asset IDs
|
|
4113
|
+
e.pure.vector("address", c),
|
|
4114
|
+
// Rule IDs
|
|
4115
|
+
g(o.accountCap, e.object)
|
|
4116
|
+
// Account capability
|
|
4117
|
+
],
|
|
4118
|
+
typeArguments: [h]
|
|
4119
|
+
}) : y ? S = e.moveCall({
|
|
4120
|
+
target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
4121
|
+
arguments: [
|
|
4122
|
+
e.object("0x06"),
|
|
4123
|
+
// Clock object
|
|
4124
|
+
e.object(l.incentiveV3),
|
|
4125
|
+
// Incentive V3 contract
|
|
4126
|
+
e.object(l.storage),
|
|
4127
|
+
// Protocol storage
|
|
4128
|
+
e.object(I),
|
|
4129
|
+
// Reward fund
|
|
4130
|
+
e.pure.vector("string", i),
|
|
4131
|
+
// Asset IDs
|
|
4132
|
+
e.pure.vector("address", c),
|
|
4133
|
+
// Rule IDs
|
|
4134
|
+
g(v, e.object)
|
|
4135
|
+
// Account capability
|
|
4136
|
+
],
|
|
4137
|
+
typeArguments: [h]
|
|
4138
|
+
}) : S = e.moveCall({
|
|
4139
|
+
target: `${l.package}::incentive_v3::claim_reward`,
|
|
4140
|
+
arguments: [
|
|
4141
|
+
e.object("0x06"),
|
|
4142
|
+
// Clock object
|
|
4143
|
+
e.object(l.incentiveV3),
|
|
4144
|
+
// Incentive V3 contract
|
|
4145
|
+
e.object(l.storage),
|
|
4146
|
+
// Protocol storage
|
|
4147
|
+
e.object(I),
|
|
4148
|
+
// Reward fund
|
|
4149
|
+
e.pure.vector("string", i),
|
|
4150
|
+
// Asset IDs
|
|
4151
|
+
e.pure.vector("address", c)
|
|
4152
|
+
// Rule IDs
|
|
4153
|
+
],
|
|
4154
|
+
typeArguments: [h]
|
|
4155
|
+
});
|
|
4156
|
+
const [D] = e.moveCall({
|
|
4157
|
+
target: "0x2::coin::from_balance",
|
|
4158
|
+
arguments: [S],
|
|
4159
|
+
typeArguments: [h]
|
|
4160
|
+
});
|
|
4161
|
+
if (o?.customCoinReceive.type === "transfer") {
|
|
4162
|
+
if (!o.customCoinReceive.transfer)
|
|
4163
|
+
throw new Error("customCoinReceive.transfer is required");
|
|
4164
|
+
e.transferObjects(
|
|
4165
|
+
[D],
|
|
4166
|
+
g(o.customCoinReceive.transfer, e.pure.address)
|
|
4167
|
+
);
|
|
4168
|
+
}
|
|
4169
|
+
if (o?.customCoinReceive.type === "depositNAVI") {
|
|
4170
|
+
const re = bignumber_default(j.totalSupplyAmount).shiftedBy(-9), ae = bignumber_default(j.supplyCapCeiling).shiftedBy(-27);
|
|
4171
|
+
re.plus(u).isGreaterThan(ae) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
|
|
4172
|
+
[D],
|
|
4173
|
+
e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
4174
|
+
) : await Ce(e, j, D, o);
|
|
4175
|
+
} else
|
|
4176
|
+
a.push({
|
|
4177
|
+
coin: D,
|
|
4178
|
+
identifier: j,
|
|
4179
|
+
owner: f,
|
|
4180
|
+
isEMode: y
|
|
4181
|
+
});
|
|
4182
|
+
} else if (o?.accountCap || y) {
|
|
4183
|
+
const S = e.moveCall({
|
|
4184
|
+
target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
4185
|
+
arguments: [
|
|
4186
|
+
e.object("0x06"),
|
|
4187
|
+
// Clock object
|
|
4188
|
+
e.object(l.incentiveV3),
|
|
4189
|
+
// Incentive V3 contract
|
|
4190
|
+
e.object(l.storage),
|
|
4191
|
+
// Protocol storage
|
|
4192
|
+
e.object(I),
|
|
4193
|
+
// Reward fund
|
|
4194
|
+
e.pure.vector("string", i),
|
|
4195
|
+
// Asset IDs
|
|
4196
|
+
e.pure.vector("address", c),
|
|
4197
|
+
// Rule IDs
|
|
4198
|
+
g(o?.accountCap || v, e.object)
|
|
4199
|
+
// Account capability
|
|
4200
|
+
],
|
|
4201
|
+
typeArguments: [h]
|
|
4202
|
+
}), [D] = e.moveCall({
|
|
4203
|
+
target: "0x2::coin::from_balance",
|
|
4204
|
+
arguments: [S],
|
|
4205
|
+
typeArguments: [h]
|
|
4206
|
+
});
|
|
4207
|
+
e.transferObjects(
|
|
4208
|
+
[D],
|
|
4209
|
+
g(o?.accountCap || f, e.pure.address)
|
|
4210
|
+
);
|
|
4211
|
+
} else
|
|
4212
|
+
e.moveCall({
|
|
4213
|
+
target: `${l.package}::incentive_v3::claim_reward_entry`,
|
|
4214
|
+
arguments: [
|
|
4215
|
+
e.object("0x06"),
|
|
4216
|
+
// Clock object
|
|
4217
|
+
e.object(l.incentiveV3),
|
|
4218
|
+
// Incentive V3 contract
|
|
4219
|
+
e.object(l.storage),
|
|
4220
|
+
// Protocol storage
|
|
4221
|
+
e.object(I),
|
|
4222
|
+
// Reward fund
|
|
4223
|
+
e.pure.vector("string", i),
|
|
4224
|
+
// Asset IDs
|
|
4225
|
+
e.pure.vector("address", c)
|
|
4226
|
+
// Rule IDs
|
|
4227
|
+
],
|
|
4228
|
+
typeArguments: [h]
|
|
4229
|
+
});
|
|
4230
|
+
}
|
|
4231
|
+
return a;
|
|
224
4232
|
}
|
|
225
4233
|
|
|
226
4234
|
// src/protocols/protocolFee.ts
|
|
@@ -265,7 +4273,7 @@ async function refreshOracle(tx, client, address, options) {
|
|
|
265
4273
|
origWarn.apply(console, args);
|
|
266
4274
|
};
|
|
267
4275
|
try {
|
|
268
|
-
const pools = await
|
|
4276
|
+
const pools = await R(sdkOptions(client));
|
|
269
4277
|
const oracleOpts = {
|
|
270
4278
|
...sdkOptions(client),
|
|
271
4279
|
throws: false,
|
|
@@ -273,7 +4281,7 @@ async function refreshOracle(tx, client, address, options) {
|
|
|
273
4281
|
// with sponsored transactions where tx.gas belongs to the sponsor.
|
|
274
4282
|
updatePythPriceFeeds: !options?.skipPythUpdate
|
|
275
4283
|
};
|
|
276
|
-
await
|
|
4284
|
+
await mt(tx, address, pools, oracleOpts);
|
|
277
4285
|
} catch {
|
|
278
4286
|
} finally {
|
|
279
4287
|
console.info = origInfo;
|
|
@@ -335,7 +4343,7 @@ function mergeCoins(tx, coins) {
|
|
|
335
4343
|
}
|
|
336
4344
|
async function getPositions(client, address) {
|
|
337
4345
|
try {
|
|
338
|
-
const naviPositions = await
|
|
4346
|
+
const naviPositions = await $e(address, {
|
|
339
4347
|
...sdkOptions(client),
|
|
340
4348
|
markets: ["main"]
|
|
341
4349
|
});
|
|
@@ -369,7 +4377,7 @@ async function getPositions(client, address) {
|
|
|
369
4377
|
}
|
|
370
4378
|
async function getRates(client) {
|
|
371
4379
|
try {
|
|
372
|
-
const pools = await
|
|
4380
|
+
const pools = await R(sdkOptions(client));
|
|
373
4381
|
const result = {};
|
|
374
4382
|
for (const asset of ALL_NAVI_ASSETS) {
|
|
375
4383
|
const targetType = SUPPORTED_ASSETS[asset].type;
|
|
@@ -402,7 +4410,7 @@ async function getHealthFactor(client, address) {
|
|
|
402
4410
|
}
|
|
403
4411
|
let healthFactor;
|
|
404
4412
|
try {
|
|
405
|
-
const hf = await
|
|
4413
|
+
const hf = await ct(address, sdkOptions(client));
|
|
406
4414
|
healthFactor = hf > 1e5 ? Infinity : hf;
|
|
407
4415
|
} catch {
|
|
408
4416
|
healthFactor = borrowed > 0 ? supplied * 0.75 / borrowed : Infinity;
|
|
@@ -434,7 +4442,7 @@ async function buildSaveTx(client, address, amount, options = {}) {
|
|
|
434
4442
|
}
|
|
435
4443
|
const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
|
|
436
4444
|
try {
|
|
437
|
-
await
|
|
4445
|
+
await Ce(tx, assetInfo.type, coinObj, {
|
|
438
4446
|
...sdkOptions(client),
|
|
439
4447
|
amount: rawAmount
|
|
440
4448
|
});
|
|
@@ -463,7 +4471,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
463
4471
|
tx.setSender(address);
|
|
464
4472
|
await refreshOracle(tx, client, address, { skipPythUpdate: options.sponsored });
|
|
465
4473
|
try {
|
|
466
|
-
const coin = await
|
|
4474
|
+
const coin = await Qe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
467
4475
|
tx.transferObjects([coin], address);
|
|
468
4476
|
} catch (err) {
|
|
469
4477
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -493,7 +4501,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
493
4501
|
}
|
|
494
4502
|
await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
|
|
495
4503
|
try {
|
|
496
|
-
const coin = await
|
|
4504
|
+
const coin = await Qe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
497
4505
|
return { coin, effectiveAmount };
|
|
498
4506
|
} catch (err) {
|
|
499
4507
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -507,7 +4515,7 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
|
|
|
507
4515
|
addCollectFeeToTx(tx, coin, "save");
|
|
508
4516
|
}
|
|
509
4517
|
try {
|
|
510
|
-
await
|
|
4518
|
+
await Ce(tx, assetInfo.type, coin, { env: "prod" });
|
|
511
4519
|
} catch (err) {
|
|
512
4520
|
const msg = err instanceof Error ? err.message : String(err);
|
|
513
4521
|
throw new T2000Error("PROTOCOL_UNAVAILABLE", `NAVI deposit failed: ${msg}`);
|
|
@@ -519,7 +4527,7 @@ async function addRepayToTx(tx, client, address, coin, options = {}) {
|
|
|
519
4527
|
const assetInfo = resolveAssetInfo(asset);
|
|
520
4528
|
await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
|
|
521
4529
|
try {
|
|
522
|
-
await
|
|
4530
|
+
await xe(tx, assetInfo.type, coin, { env: "prod" });
|
|
523
4531
|
} catch (err) {
|
|
524
4532
|
const msg = err instanceof Error ? err.message : String(err);
|
|
525
4533
|
throw new T2000Error("PROTOCOL_UNAVAILABLE", `NAVI repay failed: ${msg}`);
|
|
@@ -536,7 +4544,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
536
4544
|
tx.setSender(address);
|
|
537
4545
|
await refreshOracle(tx, client, address, { skipPythUpdate: options.sponsored });
|
|
538
4546
|
try {
|
|
539
|
-
const borrowedCoin = await
|
|
4547
|
+
const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
540
4548
|
if (options.collectFee) {
|
|
541
4549
|
addCollectFeeToTx(tx, borrowedCoin, "borrow");
|
|
542
4550
|
}
|
|
@@ -570,7 +4578,7 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
570
4578
|
skipOracle: options.skipOracle
|
|
571
4579
|
});
|
|
572
4580
|
try {
|
|
573
|
-
await
|
|
4581
|
+
await xe(tx, assetInfo.type, repayCoin, {
|
|
574
4582
|
...sdkOptions(client),
|
|
575
4583
|
amount: rawAmount
|
|
576
4584
|
});
|
|
@@ -601,12 +4609,12 @@ async function maxBorrowAmount(client, address) {
|
|
|
601
4609
|
}
|
|
602
4610
|
async function getPendingRewards(client, address) {
|
|
603
4611
|
try {
|
|
604
|
-
const rewards = await
|
|
4612
|
+
const rewards = await vt(address, {
|
|
605
4613
|
...sdkOptions(client),
|
|
606
4614
|
markets: ["main"]
|
|
607
4615
|
});
|
|
608
4616
|
if (!rewards || rewards.length === 0) return [];
|
|
609
|
-
const summary =
|
|
4617
|
+
const summary = wt(rewards);
|
|
610
4618
|
const result = [];
|
|
611
4619
|
for (const s of summary) {
|
|
612
4620
|
for (const rw of s.rewards) {
|
|
@@ -630,7 +4638,7 @@ async function getPendingRewards(client, address) {
|
|
|
630
4638
|
}
|
|
631
4639
|
async function addClaimRewardsToTx(tx, client, address) {
|
|
632
4640
|
try {
|
|
633
|
-
const rewards = await
|
|
4641
|
+
const rewards = await vt(address, {
|
|
634
4642
|
...sdkOptions(client),
|
|
635
4643
|
markets: ["main"]
|
|
636
4644
|
});
|
|
@@ -639,7 +4647,7 @@ async function addClaimRewardsToTx(tx, client, address) {
|
|
|
639
4647
|
(r) => Number(r.userClaimableReward) > 0
|
|
640
4648
|
);
|
|
641
4649
|
if (claimable.length === 0) return [];
|
|
642
|
-
const claimed = await
|
|
4650
|
+
const claimed = await Ct(tx, claimable, {
|
|
643
4651
|
env: "prod",
|
|
644
4652
|
customCoinReceive: { type: "transfer", transfer: address }
|
|
645
4653
|
});
|
|
@@ -758,6 +4766,11 @@ var NaviAdapter = class {
|
|
|
758
4766
|
return addClaimRewardsToTx(tx, this.client, address);
|
|
759
4767
|
}
|
|
760
4768
|
};
|
|
4769
|
+
/*! Bundled license information:
|
|
4770
|
+
|
|
4771
|
+
@scure/base/index.js:
|
|
4772
|
+
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
4773
|
+
*/
|
|
761
4774
|
|
|
762
4775
|
exports.NaviAdapter = NaviAdapter;
|
|
763
4776
|
exports.ProtocolRegistry = ProtocolRegistry;
|