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