@hyr0-xyz/program 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,3896 @@
1
+ import { getStructEncoder, getAddressEncoder, getBooleanEncoder, getStructDecoder, getAddressDecoder, getBooleanDecoder, combineCodec, getEnumEncoder, getEnumDecoder, getU16Encoder, getU64Encoder, getU16Decoder, getU64Decoder, fixEncoderSize, getBytesEncoder, transformEncoder, fixDecoderSize, getBytesDecoder, getArrayEncoder, addEncoderSizePrefix, getU32Encoder, getArrayDecoder, addDecoderSizePrefix, getU32Decoder, getProgramDerivedAddress, getUtf8Encoder, getUtf8Decoder, AccountRole, upgradeRoleToSigner, assertAccountExists, isTransactionSigner as isTransactionSigner$1, fetchEncodedAccount, decodeAccount, getOptionDecoder } from '@solana/kit';
2
+
3
+ // src/sdk/vault.ts
4
+
5
+ // node_modules/decimal.js/decimal.mjs
6
+ var EXP_LIMIT = 9e15;
7
+ var MAX_DIGITS = 1e9;
8
+ var NUMERALS = "0123456789abcdef";
9
+ var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
10
+ var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
11
+ var DEFAULTS = {
12
+ // These values must be integers within the stated ranges (inclusive).
13
+ // Most of these values can be changed at run-time using the `Decimal.config` method.
14
+ // The maximum number of significant digits of the result of a calculation or base conversion.
15
+ // E.g. `Decimal.config({ precision: 20 });`
16
+ precision: 20,
17
+ // 1 to MAX_DIGITS
18
+ // The rounding mode used when rounding to `precision`.
19
+ //
20
+ // ROUND_UP 0 Away from zero.
21
+ // ROUND_DOWN 1 Towards zero.
22
+ // ROUND_CEIL 2 Towards +Infinity.
23
+ // ROUND_FLOOR 3 Towards -Infinity.
24
+ // ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
25
+ // ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
26
+ // ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
27
+ // ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
28
+ // ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
29
+ //
30
+ // E.g.
31
+ // `Decimal.rounding = 4;`
32
+ // `Decimal.rounding = Decimal.ROUND_HALF_UP;`
33
+ rounding: 4,
34
+ // 0 to 8
35
+ // The modulo mode used when calculating the modulus: a mod n.
36
+ // The quotient (q = a / n) is calculated according to the corresponding rounding mode.
37
+ // The remainder (r) is calculated as: r = a - n * q.
38
+ //
39
+ // UP 0 The remainder is positive if the dividend is negative, else is negative.
40
+ // DOWN 1 The remainder has the same sign as the dividend (JavaScript %).
41
+ // FLOOR 3 The remainder has the same sign as the divisor (Python %).
42
+ // HALF_EVEN 6 The IEEE 754 remainder function.
43
+ // EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). Always positive.
44
+ //
45
+ // Truncated division (1), floored division (3), the IEEE 754 remainder (6), and Euclidian
46
+ // division (9) are commonly used for the modulus operation. The other rounding modes can also
47
+ // be used, but they may not give useful results.
48
+ modulo: 1,
49
+ // 0 to 9
50
+ // The exponent value at and beneath which `toString` returns exponential notation.
51
+ // JavaScript numbers: -7
52
+ toExpNeg: -7,
53
+ // 0 to -EXP_LIMIT
54
+ // The exponent value at and above which `toString` returns exponential notation.
55
+ // JavaScript numbers: 21
56
+ toExpPos: 21,
57
+ // 0 to EXP_LIMIT
58
+ // The minimum exponent value, beneath which underflow to zero occurs.
59
+ // JavaScript numbers: -324 (5e-324)
60
+ minE: -EXP_LIMIT,
61
+ // -1 to -EXP_LIMIT
62
+ // The maximum exponent value, above which overflow to Infinity occurs.
63
+ // JavaScript numbers: 308 (1.7976931348623157e+308)
64
+ maxE: EXP_LIMIT,
65
+ // 1 to EXP_LIMIT
66
+ // Whether to use cryptographically-secure random number generation, if available.
67
+ crypto: false
68
+ // true/false
69
+ };
70
+ var inexact;
71
+ var quadrant;
72
+ var external = true;
73
+ var decimalError = "[DecimalError] ";
74
+ var invalidArgument = decimalError + "Invalid argument: ";
75
+ var precisionLimitExceeded = decimalError + "Precision limit exceeded";
76
+ var cryptoUnavailable = decimalError + "crypto unavailable";
77
+ var tag = "[object Decimal]";
78
+ var mathfloor = Math.floor;
79
+ var mathpow = Math.pow;
80
+ var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
81
+ var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
82
+ var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
83
+ var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
84
+ var BASE = 1e7;
85
+ var LOG_BASE = 7;
86
+ var MAX_SAFE_INTEGER = 9007199254740991;
87
+ var LN10_PRECISION = LN10.length - 1;
88
+ var PI_PRECISION = PI.length - 1;
89
+ var P = { toStringTag: tag };
90
+ P.absoluteValue = P.abs = function() {
91
+ var x = new this.constructor(this);
92
+ if (x.s < 0) x.s = 1;
93
+ return finalise(x);
94
+ };
95
+ P.ceil = function() {
96
+ return finalise(new this.constructor(this), this.e + 1, 2);
97
+ };
98
+ P.clampedTo = P.clamp = function(min2, max2) {
99
+ var k, x = this, Ctor = x.constructor;
100
+ min2 = new Ctor(min2);
101
+ max2 = new Ctor(max2);
102
+ if (!min2.s || !max2.s) return new Ctor(NaN);
103
+ if (min2.gt(max2)) throw Error(invalidArgument + max2);
104
+ k = x.cmp(min2);
105
+ return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x);
106
+ };
107
+ P.comparedTo = P.cmp = function(y) {
108
+ var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
109
+ if (!xd || !yd) {
110
+ return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
111
+ }
112
+ if (!xd[0] || !yd[0]) return xd[0] ? xs : yd[0] ? -ys : 0;
113
+ if (xs !== ys) return xs;
114
+ if (x.e !== y.e) return x.e > y.e ^ xs < 0 ? 1 : -1;
115
+ xdL = xd.length;
116
+ ydL = yd.length;
117
+ for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
118
+ if (xd[i] !== yd[i]) return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
119
+ }
120
+ return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
121
+ };
122
+ P.cosine = P.cos = function() {
123
+ var pr, rm, x = this, Ctor = x.constructor;
124
+ if (!x.d) return new Ctor(NaN);
125
+ if (!x.d[0]) return new Ctor(1);
126
+ pr = Ctor.precision;
127
+ rm = Ctor.rounding;
128
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
129
+ Ctor.rounding = 1;
130
+ x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
131
+ Ctor.precision = pr;
132
+ Ctor.rounding = rm;
133
+ return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
134
+ };
135
+ P.cubeRoot = P.cbrt = function() {
136
+ var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
137
+ if (!x.isFinite() || x.isZero()) return new Ctor(x);
138
+ external = false;
139
+ s = x.s * mathpow(x.s * x, 1 / 3);
140
+ if (!s || Math.abs(s) == 1 / 0) {
141
+ n = digitsToString(x.d);
142
+ e = x.e;
143
+ if (s = (e - n.length + 1) % 3) n += s == 1 || s == -2 ? "0" : "00";
144
+ s = mathpow(n, 1 / 3);
145
+ e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
146
+ if (s == 1 / 0) {
147
+ n = "5e" + e;
148
+ } else {
149
+ n = s.toExponential();
150
+ n = n.slice(0, n.indexOf("e") + 1) + e;
151
+ }
152
+ r = new Ctor(n);
153
+ r.s = x.s;
154
+ } else {
155
+ r = new Ctor(s.toString());
156
+ }
157
+ sd = (e = Ctor.precision) + 3;
158
+ for (; ; ) {
159
+ t = r;
160
+ t3 = t.times(t).times(t);
161
+ t3plusx = t3.plus(x);
162
+ r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
163
+ if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
164
+ n = n.slice(sd - 3, sd + 1);
165
+ if (n == "9999" || !rep && n == "4999") {
166
+ if (!rep) {
167
+ finalise(t, e + 1, 0);
168
+ if (t.times(t).times(t).eq(x)) {
169
+ r = t;
170
+ break;
171
+ }
172
+ }
173
+ sd += 4;
174
+ rep = 1;
175
+ } else {
176
+ if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
177
+ finalise(r, e + 1, 1);
178
+ m = !r.times(r).times(r).eq(x);
179
+ }
180
+ break;
181
+ }
182
+ }
183
+ }
184
+ external = true;
185
+ return finalise(r, e, Ctor.rounding, m);
186
+ };
187
+ P.decimalPlaces = P.dp = function() {
188
+ var w, d = this.d, n = NaN;
189
+ if (d) {
190
+ w = d.length - 1;
191
+ n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
192
+ w = d[w];
193
+ if (w) for (; w % 10 == 0; w /= 10) n--;
194
+ if (n < 0) n = 0;
195
+ }
196
+ return n;
197
+ };
198
+ P.dividedBy = P.div = function(y) {
199
+ return divide(this, new this.constructor(y));
200
+ };
201
+ P.dividedToIntegerBy = P.divToInt = function(y) {
202
+ var x = this, Ctor = x.constructor;
203
+ return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
204
+ };
205
+ P.equals = P.eq = function(y) {
206
+ return this.cmp(y) === 0;
207
+ };
208
+ P.floor = function() {
209
+ return finalise(new this.constructor(this), this.e + 1, 3);
210
+ };
211
+ P.greaterThan = P.gt = function(y) {
212
+ return this.cmp(y) > 0;
213
+ };
214
+ P.greaterThanOrEqualTo = P.gte = function(y) {
215
+ var k = this.cmp(y);
216
+ return k == 1 || k === 0;
217
+ };
218
+ P.hyperbolicCosine = P.cosh = function() {
219
+ var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
220
+ if (!x.isFinite()) return new Ctor(x.s ? 1 / 0 : NaN);
221
+ if (x.isZero()) return one;
222
+ pr = Ctor.precision;
223
+ rm = Ctor.rounding;
224
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
225
+ Ctor.rounding = 1;
226
+ len = x.d.length;
227
+ if (len < 32) {
228
+ k = Math.ceil(len / 3);
229
+ n = (1 / tinyPow(4, k)).toString();
230
+ } else {
231
+ k = 16;
232
+ n = "2.3283064365386962890625e-10";
233
+ }
234
+ x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
235
+ var cosh2_x, i = k, d8 = new Ctor(8);
236
+ for (; i--; ) {
237
+ cosh2_x = x.times(x);
238
+ x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
239
+ }
240
+ return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
241
+ };
242
+ P.hyperbolicSine = P.sinh = function() {
243
+ var k, pr, rm, len, x = this, Ctor = x.constructor;
244
+ if (!x.isFinite() || x.isZero()) return new Ctor(x);
245
+ pr = Ctor.precision;
246
+ rm = Ctor.rounding;
247
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
248
+ Ctor.rounding = 1;
249
+ len = x.d.length;
250
+ if (len < 3) {
251
+ x = taylorSeries(Ctor, 2, x, x, true);
252
+ } else {
253
+ k = 1.4 * Math.sqrt(len);
254
+ k = k > 16 ? 16 : k | 0;
255
+ x = x.times(1 / tinyPow(5, k));
256
+ x = taylorSeries(Ctor, 2, x, x, true);
257
+ var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
258
+ for (; k--; ) {
259
+ sinh2_x = x.times(x);
260
+ x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
261
+ }
262
+ }
263
+ Ctor.precision = pr;
264
+ Ctor.rounding = rm;
265
+ return finalise(x, pr, rm, true);
266
+ };
267
+ P.hyperbolicTangent = P.tanh = function() {
268
+ var pr, rm, x = this, Ctor = x.constructor;
269
+ if (!x.isFinite()) return new Ctor(x.s);
270
+ if (x.isZero()) return new Ctor(x);
271
+ pr = Ctor.precision;
272
+ rm = Ctor.rounding;
273
+ Ctor.precision = pr + 7;
274
+ Ctor.rounding = 1;
275
+ return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
276
+ };
277
+ P.inverseCosine = P.acos = function() {
278
+ var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
279
+ if (k !== -1) {
280
+ return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
281
+ }
282
+ if (x.isZero()) return getPi(Ctor, pr + 4, rm).times(0.5);
283
+ Ctor.precision = pr + 6;
284
+ Ctor.rounding = 1;
285
+ x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
286
+ Ctor.precision = pr;
287
+ Ctor.rounding = rm;
288
+ return x.times(2);
289
+ };
290
+ P.inverseHyperbolicCosine = P.acosh = function() {
291
+ var pr, rm, x = this, Ctor = x.constructor;
292
+ if (x.lte(1)) return new Ctor(x.eq(1) ? 0 : NaN);
293
+ if (!x.isFinite()) return new Ctor(x);
294
+ pr = Ctor.precision;
295
+ rm = Ctor.rounding;
296
+ Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
297
+ Ctor.rounding = 1;
298
+ external = false;
299
+ x = x.times(x).minus(1).sqrt().plus(x);
300
+ external = true;
301
+ Ctor.precision = pr;
302
+ Ctor.rounding = rm;
303
+ return x.ln();
304
+ };
305
+ P.inverseHyperbolicSine = P.asinh = function() {
306
+ var pr, rm, x = this, Ctor = x.constructor;
307
+ if (!x.isFinite() || x.isZero()) return new Ctor(x);
308
+ pr = Ctor.precision;
309
+ rm = Ctor.rounding;
310
+ Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
311
+ Ctor.rounding = 1;
312
+ external = false;
313
+ x = x.times(x).plus(1).sqrt().plus(x);
314
+ external = true;
315
+ Ctor.precision = pr;
316
+ Ctor.rounding = rm;
317
+ return x.ln();
318
+ };
319
+ P.inverseHyperbolicTangent = P.atanh = function() {
320
+ var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
321
+ if (!x.isFinite()) return new Ctor(NaN);
322
+ if (x.e >= 0) return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
323
+ pr = Ctor.precision;
324
+ rm = Ctor.rounding;
325
+ xsd = x.sd();
326
+ if (Math.max(xsd, pr) < 2 * -x.e - 1) return finalise(new Ctor(x), pr, rm, true);
327
+ Ctor.precision = wpr = xsd - x.e;
328
+ x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
329
+ Ctor.precision = pr + 4;
330
+ Ctor.rounding = 1;
331
+ x = x.ln();
332
+ Ctor.precision = pr;
333
+ Ctor.rounding = rm;
334
+ return x.times(0.5);
335
+ };
336
+ P.inverseSine = P.asin = function() {
337
+ var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
338
+ if (x.isZero()) return new Ctor(x);
339
+ k = x.abs().cmp(1);
340
+ pr = Ctor.precision;
341
+ rm = Ctor.rounding;
342
+ if (k !== -1) {
343
+ if (k === 0) {
344
+ halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
345
+ halfPi.s = x.s;
346
+ return halfPi;
347
+ }
348
+ return new Ctor(NaN);
349
+ }
350
+ Ctor.precision = pr + 6;
351
+ Ctor.rounding = 1;
352
+ x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
353
+ Ctor.precision = pr;
354
+ Ctor.rounding = rm;
355
+ return x.times(2);
356
+ };
357
+ P.inverseTangent = P.atan = function() {
358
+ var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
359
+ if (!x.isFinite()) {
360
+ if (!x.s) return new Ctor(NaN);
361
+ if (pr + 4 <= PI_PRECISION) {
362
+ r = getPi(Ctor, pr + 4, rm).times(0.5);
363
+ r.s = x.s;
364
+ return r;
365
+ }
366
+ } else if (x.isZero()) {
367
+ return new Ctor(x);
368
+ } else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
369
+ r = getPi(Ctor, pr + 4, rm).times(0.25);
370
+ r.s = x.s;
371
+ return r;
372
+ }
373
+ Ctor.precision = wpr = pr + 10;
374
+ Ctor.rounding = 1;
375
+ k = Math.min(28, wpr / LOG_BASE + 2 | 0);
376
+ for (i = k; i; --i) x = x.div(x.times(x).plus(1).sqrt().plus(1));
377
+ external = false;
378
+ j = Math.ceil(wpr / LOG_BASE);
379
+ n = 1;
380
+ x2 = x.times(x);
381
+ r = new Ctor(x);
382
+ px = x;
383
+ for (; i !== -1; ) {
384
+ px = px.times(x2);
385
+ t = r.minus(px.div(n += 2));
386
+ px = px.times(x2);
387
+ r = t.plus(px.div(n += 2));
388
+ if (r.d[j] !== void 0) for (i = j; r.d[i] === t.d[i] && i--; ) ;
389
+ }
390
+ if (k) r = r.times(2 << k - 1);
391
+ external = true;
392
+ return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
393
+ };
394
+ P.isFinite = function() {
395
+ return !!this.d;
396
+ };
397
+ P.isInteger = P.isInt = function() {
398
+ return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
399
+ };
400
+ P.isNaN = function() {
401
+ return !this.s;
402
+ };
403
+ P.isNegative = P.isNeg = function() {
404
+ return this.s < 0;
405
+ };
406
+ P.isPositive = P.isPos = function() {
407
+ return this.s > 0;
408
+ };
409
+ P.isZero = function() {
410
+ return !!this.d && this.d[0] === 0;
411
+ };
412
+ P.lessThan = P.lt = function(y) {
413
+ return this.cmp(y) < 0;
414
+ };
415
+ P.lessThanOrEqualTo = P.lte = function(y) {
416
+ return this.cmp(y) < 1;
417
+ };
418
+ P.logarithm = P.log = function(base) {
419
+ var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
420
+ if (base == null) {
421
+ base = new Ctor(10);
422
+ isBase10 = true;
423
+ } else {
424
+ base = new Ctor(base);
425
+ d = base.d;
426
+ if (base.s < 0 || !d || !d[0] || base.eq(1)) return new Ctor(NaN);
427
+ isBase10 = base.eq(10);
428
+ }
429
+ d = arg.d;
430
+ if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
431
+ return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
432
+ }
433
+ if (isBase10) {
434
+ if (d.length > 1) {
435
+ inf = true;
436
+ } else {
437
+ for (k = d[0]; k % 10 === 0; ) k /= 10;
438
+ inf = k !== 1;
439
+ }
440
+ }
441
+ external = false;
442
+ sd = pr + guard;
443
+ num = naturalLogarithm(arg, sd);
444
+ denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
445
+ r = divide(num, denominator, sd, 1);
446
+ if (checkRoundingDigits(r.d, k = pr, rm)) {
447
+ do {
448
+ sd += 10;
449
+ num = naturalLogarithm(arg, sd);
450
+ denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
451
+ r = divide(num, denominator, sd, 1);
452
+ if (!inf) {
453
+ if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
454
+ r = finalise(r, pr + 1, 0);
455
+ }
456
+ break;
457
+ }
458
+ } while (checkRoundingDigits(r.d, k += 10, rm));
459
+ }
460
+ external = true;
461
+ return finalise(r, pr, rm);
462
+ };
463
+ P.minus = P.sub = function(y) {
464
+ var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
465
+ y = new Ctor(y);
466
+ if (!x.d || !y.d) {
467
+ if (!x.s || !y.s) y = new Ctor(NaN);
468
+ else if (x.d) y.s = -y.s;
469
+ else y = new Ctor(y.d || x.s !== y.s ? x : NaN);
470
+ return y;
471
+ }
472
+ if (x.s != y.s) {
473
+ y.s = -y.s;
474
+ return x.plus(y);
475
+ }
476
+ xd = x.d;
477
+ yd = y.d;
478
+ pr = Ctor.precision;
479
+ rm = Ctor.rounding;
480
+ if (!xd[0] || !yd[0]) {
481
+ if (yd[0]) y.s = -y.s;
482
+ else if (xd[0]) y = new Ctor(x);
483
+ else return new Ctor(rm === 3 ? -0 : 0);
484
+ return external ? finalise(y, pr, rm) : y;
485
+ }
486
+ e = mathfloor(y.e / LOG_BASE);
487
+ xe = mathfloor(x.e / LOG_BASE);
488
+ xd = xd.slice();
489
+ k = xe - e;
490
+ if (k) {
491
+ xLTy = k < 0;
492
+ if (xLTy) {
493
+ d = xd;
494
+ k = -k;
495
+ len = yd.length;
496
+ } else {
497
+ d = yd;
498
+ e = xe;
499
+ len = xd.length;
500
+ }
501
+ i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
502
+ if (k > i) {
503
+ k = i;
504
+ d.length = 1;
505
+ }
506
+ d.reverse();
507
+ for (i = k; i--; ) d.push(0);
508
+ d.reverse();
509
+ } else {
510
+ i = xd.length;
511
+ len = yd.length;
512
+ xLTy = i < len;
513
+ if (xLTy) len = i;
514
+ for (i = 0; i < len; i++) {
515
+ if (xd[i] != yd[i]) {
516
+ xLTy = xd[i] < yd[i];
517
+ break;
518
+ }
519
+ }
520
+ k = 0;
521
+ }
522
+ if (xLTy) {
523
+ d = xd;
524
+ xd = yd;
525
+ yd = d;
526
+ y.s = -y.s;
527
+ }
528
+ len = xd.length;
529
+ for (i = yd.length - len; i > 0; --i) xd[len++] = 0;
530
+ for (i = yd.length; i > k; ) {
531
+ if (xd[--i] < yd[i]) {
532
+ for (j = i; j && xd[--j] === 0; ) xd[j] = BASE - 1;
533
+ --xd[j];
534
+ xd[i] += BASE;
535
+ }
536
+ xd[i] -= yd[i];
537
+ }
538
+ for (; xd[--len] === 0; ) xd.pop();
539
+ for (; xd[0] === 0; xd.shift()) --e;
540
+ if (!xd[0]) return new Ctor(rm === 3 ? -0 : 0);
541
+ y.d = xd;
542
+ y.e = getBase10Exponent(xd, e);
543
+ return external ? finalise(y, pr, rm) : y;
544
+ };
545
+ P.modulo = P.mod = function(y) {
546
+ var q, x = this, Ctor = x.constructor;
547
+ y = new Ctor(y);
548
+ if (!x.d || !y.s || y.d && !y.d[0]) return new Ctor(NaN);
549
+ if (!y.d || x.d && !x.d[0]) {
550
+ return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
551
+ }
552
+ external = false;
553
+ if (Ctor.modulo == 9) {
554
+ q = divide(x, y.abs(), 0, 3, 1);
555
+ q.s *= y.s;
556
+ } else {
557
+ q = divide(x, y, 0, Ctor.modulo, 1);
558
+ }
559
+ q = q.times(y);
560
+ external = true;
561
+ return x.minus(q);
562
+ };
563
+ P.naturalExponential = P.exp = function() {
564
+ return naturalExponential(this);
565
+ };
566
+ P.naturalLogarithm = P.ln = function() {
567
+ return naturalLogarithm(this);
568
+ };
569
+ P.negated = P.neg = function() {
570
+ var x = new this.constructor(this);
571
+ x.s = -x.s;
572
+ return finalise(x);
573
+ };
574
+ P.plus = P.add = function(y) {
575
+ var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
576
+ y = new Ctor(y);
577
+ if (!x.d || !y.d) {
578
+ if (!x.s || !y.s) y = new Ctor(NaN);
579
+ else if (!x.d) y = new Ctor(y.d || x.s === y.s ? x : NaN);
580
+ return y;
581
+ }
582
+ if (x.s != y.s) {
583
+ y.s = -y.s;
584
+ return x.minus(y);
585
+ }
586
+ xd = x.d;
587
+ yd = y.d;
588
+ pr = Ctor.precision;
589
+ rm = Ctor.rounding;
590
+ if (!xd[0] || !yd[0]) {
591
+ if (!yd[0]) y = new Ctor(x);
592
+ return external ? finalise(y, pr, rm) : y;
593
+ }
594
+ k = mathfloor(x.e / LOG_BASE);
595
+ e = mathfloor(y.e / LOG_BASE);
596
+ xd = xd.slice();
597
+ i = k - e;
598
+ if (i) {
599
+ if (i < 0) {
600
+ d = xd;
601
+ i = -i;
602
+ len = yd.length;
603
+ } else {
604
+ d = yd;
605
+ e = k;
606
+ len = xd.length;
607
+ }
608
+ k = Math.ceil(pr / LOG_BASE);
609
+ len = k > len ? k + 1 : len + 1;
610
+ if (i > len) {
611
+ i = len;
612
+ d.length = 1;
613
+ }
614
+ d.reverse();
615
+ for (; i--; ) d.push(0);
616
+ d.reverse();
617
+ }
618
+ len = xd.length;
619
+ i = yd.length;
620
+ if (len - i < 0) {
621
+ i = len;
622
+ d = yd;
623
+ yd = xd;
624
+ xd = d;
625
+ }
626
+ for (carry = 0; i; ) {
627
+ carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
628
+ xd[i] %= BASE;
629
+ }
630
+ if (carry) {
631
+ xd.unshift(carry);
632
+ ++e;
633
+ }
634
+ for (len = xd.length; xd[--len] == 0; ) xd.pop();
635
+ y.d = xd;
636
+ y.e = getBase10Exponent(xd, e);
637
+ return external ? finalise(y, pr, rm) : y;
638
+ };
639
+ P.precision = P.sd = function(z) {
640
+ var k, x = this;
641
+ if (z !== void 0 && z !== !!z && z !== 1 && z !== 0) throw Error(invalidArgument + z);
642
+ if (x.d) {
643
+ k = getPrecision(x.d);
644
+ if (z && x.e + 1 > k) k = x.e + 1;
645
+ } else {
646
+ k = NaN;
647
+ }
648
+ return k;
649
+ };
650
+ P.round = function() {
651
+ var x = this, Ctor = x.constructor;
652
+ return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
653
+ };
654
+ P.sine = P.sin = function() {
655
+ var pr, rm, x = this, Ctor = x.constructor;
656
+ if (!x.isFinite()) return new Ctor(NaN);
657
+ if (x.isZero()) return new Ctor(x);
658
+ pr = Ctor.precision;
659
+ rm = Ctor.rounding;
660
+ Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
661
+ Ctor.rounding = 1;
662
+ x = sine(Ctor, toLessThanHalfPi(Ctor, x));
663
+ Ctor.precision = pr;
664
+ Ctor.rounding = rm;
665
+ return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
666
+ };
667
+ P.squareRoot = P.sqrt = function() {
668
+ var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
669
+ if (s !== 1 || !d || !d[0]) {
670
+ return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
671
+ }
672
+ external = false;
673
+ s = Math.sqrt(+x);
674
+ if (s == 0 || s == 1 / 0) {
675
+ n = digitsToString(d);
676
+ if ((n.length + e) % 2 == 0) n += "0";
677
+ s = Math.sqrt(n);
678
+ e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
679
+ if (s == 1 / 0) {
680
+ n = "5e" + e;
681
+ } else {
682
+ n = s.toExponential();
683
+ n = n.slice(0, n.indexOf("e") + 1) + e;
684
+ }
685
+ r = new Ctor(n);
686
+ } else {
687
+ r = new Ctor(s.toString());
688
+ }
689
+ sd = (e = Ctor.precision) + 3;
690
+ for (; ; ) {
691
+ t = r;
692
+ r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
693
+ if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
694
+ n = n.slice(sd - 3, sd + 1);
695
+ if (n == "9999" || !rep && n == "4999") {
696
+ if (!rep) {
697
+ finalise(t, e + 1, 0);
698
+ if (t.times(t).eq(x)) {
699
+ r = t;
700
+ break;
701
+ }
702
+ }
703
+ sd += 4;
704
+ rep = 1;
705
+ } else {
706
+ if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
707
+ finalise(r, e + 1, 1);
708
+ m = !r.times(r).eq(x);
709
+ }
710
+ break;
711
+ }
712
+ }
713
+ }
714
+ external = true;
715
+ return finalise(r, e, Ctor.rounding, m);
716
+ };
717
+ P.tangent = P.tan = function() {
718
+ var pr, rm, x = this, Ctor = x.constructor;
719
+ if (!x.isFinite()) return new Ctor(NaN);
720
+ if (x.isZero()) return new Ctor(x);
721
+ pr = Ctor.precision;
722
+ rm = Ctor.rounding;
723
+ Ctor.precision = pr + 10;
724
+ Ctor.rounding = 1;
725
+ x = x.sin();
726
+ x.s = 1;
727
+ x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
728
+ Ctor.precision = pr;
729
+ Ctor.rounding = rm;
730
+ return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
731
+ };
732
+ P.times = P.mul = function(y) {
733
+ var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
734
+ y.s *= x.s;
735
+ if (!xd || !xd[0] || !yd || !yd[0]) {
736
+ return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
737
+ }
738
+ e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
739
+ xdL = xd.length;
740
+ ydL = yd.length;
741
+ if (xdL < ydL) {
742
+ r = xd;
743
+ xd = yd;
744
+ yd = r;
745
+ rL = xdL;
746
+ xdL = ydL;
747
+ ydL = rL;
748
+ }
749
+ r = [];
750
+ rL = xdL + ydL;
751
+ for (i = rL; i--; ) r.push(0);
752
+ for (i = ydL; --i >= 0; ) {
753
+ carry = 0;
754
+ for (k = xdL + i; k > i; ) {
755
+ t = r[k] + yd[i] * xd[k - i - 1] + carry;
756
+ r[k--] = t % BASE | 0;
757
+ carry = t / BASE | 0;
758
+ }
759
+ r[k] = (r[k] + carry) % BASE | 0;
760
+ }
761
+ for (; !r[--rL]; ) r.pop();
762
+ if (carry) ++e;
763
+ else r.shift();
764
+ y.d = r;
765
+ y.e = getBase10Exponent(r, e);
766
+ return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
767
+ };
768
+ P.toBinary = function(sd, rm) {
769
+ return toStringBinary(this, 2, sd, rm);
770
+ };
771
+ P.toDecimalPlaces = P.toDP = function(dp, rm) {
772
+ var x = this, Ctor = x.constructor;
773
+ x = new Ctor(x);
774
+ if (dp === void 0) return x;
775
+ checkInt32(dp, 0, MAX_DIGITS);
776
+ if (rm === void 0) rm = Ctor.rounding;
777
+ else checkInt32(rm, 0, 8);
778
+ return finalise(x, dp + x.e + 1, rm);
779
+ };
780
+ P.toExponential = function(dp, rm) {
781
+ var str, x = this, Ctor = x.constructor;
782
+ if (dp === void 0) {
783
+ str = finiteToString(x, true);
784
+ } else {
785
+ checkInt32(dp, 0, MAX_DIGITS);
786
+ if (rm === void 0) rm = Ctor.rounding;
787
+ else checkInt32(rm, 0, 8);
788
+ x = finalise(new Ctor(x), dp + 1, rm);
789
+ str = finiteToString(x, true, dp + 1);
790
+ }
791
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
792
+ };
793
+ P.toFixed = function(dp, rm) {
794
+ var str, y, x = this, Ctor = x.constructor;
795
+ if (dp === void 0) {
796
+ str = finiteToString(x);
797
+ } else {
798
+ checkInt32(dp, 0, MAX_DIGITS);
799
+ if (rm === void 0) rm = Ctor.rounding;
800
+ else checkInt32(rm, 0, 8);
801
+ y = finalise(new Ctor(x), dp + x.e + 1, rm);
802
+ str = finiteToString(y, false, dp + y.e + 1);
803
+ }
804
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
805
+ };
806
+ P.toFraction = function(maxD) {
807
+ var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
808
+ if (!xd) return new Ctor(x);
809
+ n1 = d0 = new Ctor(1);
810
+ d1 = n0 = new Ctor(0);
811
+ d = new Ctor(d1);
812
+ e = d.e = getPrecision(xd) - x.e - 1;
813
+ k = e % LOG_BASE;
814
+ d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
815
+ if (maxD == null) {
816
+ maxD = e > 0 ? d : n1;
817
+ } else {
818
+ n = new Ctor(maxD);
819
+ if (!n.isInt() || n.lt(n1)) throw Error(invalidArgument + n);
820
+ maxD = n.gt(d) ? e > 0 ? d : n1 : n;
821
+ }
822
+ external = false;
823
+ n = new Ctor(digitsToString(xd));
824
+ pr = Ctor.precision;
825
+ Ctor.precision = e = xd.length * LOG_BASE * 2;
826
+ for (; ; ) {
827
+ q = divide(n, d, 0, 1, 1);
828
+ d2 = d0.plus(q.times(d1));
829
+ if (d2.cmp(maxD) == 1) break;
830
+ d0 = d1;
831
+ d1 = d2;
832
+ d2 = n1;
833
+ n1 = n0.plus(q.times(d2));
834
+ n0 = d2;
835
+ d2 = d;
836
+ d = n.minus(q.times(d2));
837
+ n = d2;
838
+ }
839
+ d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
840
+ n0 = n0.plus(d2.times(n1));
841
+ d0 = d0.plus(d2.times(d1));
842
+ n0.s = n1.s = x.s;
843
+ r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
844
+ Ctor.precision = pr;
845
+ external = true;
846
+ return r;
847
+ };
848
+ P.toHexadecimal = P.toHex = function(sd, rm) {
849
+ return toStringBinary(this, 16, sd, rm);
850
+ };
851
+ P.toNearest = function(y, rm) {
852
+ var x = this, Ctor = x.constructor;
853
+ x = new Ctor(x);
854
+ if (y == null) {
855
+ if (!x.d) return x;
856
+ y = new Ctor(1);
857
+ rm = Ctor.rounding;
858
+ } else {
859
+ y = new Ctor(y);
860
+ if (rm === void 0) {
861
+ rm = Ctor.rounding;
862
+ } else {
863
+ checkInt32(rm, 0, 8);
864
+ }
865
+ if (!x.d) return y.s ? x : y;
866
+ if (!y.d) {
867
+ if (y.s) y.s = x.s;
868
+ return y;
869
+ }
870
+ }
871
+ if (y.d[0]) {
872
+ external = false;
873
+ x = divide(x, y, 0, rm, 1).times(y);
874
+ external = true;
875
+ finalise(x);
876
+ } else {
877
+ y.s = x.s;
878
+ x = y;
879
+ }
880
+ return x;
881
+ };
882
+ P.toNumber = function() {
883
+ return +this;
884
+ };
885
+ P.toOctal = function(sd, rm) {
886
+ return toStringBinary(this, 8, sd, rm);
887
+ };
888
+ P.toPower = P.pow = function(y) {
889
+ var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
890
+ if (!x.d || !y.d || !x.d[0] || !y.d[0]) return new Ctor(mathpow(+x, yn));
891
+ x = new Ctor(x);
892
+ if (x.eq(1)) return x;
893
+ pr = Ctor.precision;
894
+ rm = Ctor.rounding;
895
+ if (y.eq(1)) return finalise(x, pr, rm);
896
+ e = mathfloor(y.e / LOG_BASE);
897
+ if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
898
+ r = intPow(Ctor, x, k, pr);
899
+ return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
900
+ }
901
+ s = x.s;
902
+ if (s < 0) {
903
+ if (e < y.d.length - 1) return new Ctor(NaN);
904
+ if ((y.d[e] & 1) == 0) s = 1;
905
+ if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
906
+ x.s = s;
907
+ return x;
908
+ }
909
+ }
910
+ k = mathpow(+x, yn);
911
+ e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
912
+ if (e > Ctor.maxE + 1 || e < Ctor.minE - 1) return new Ctor(e > 0 ? s / 0 : 0);
913
+ external = false;
914
+ Ctor.rounding = x.s = 1;
915
+ k = Math.min(12, (e + "").length);
916
+ r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
917
+ if (r.d) {
918
+ r = finalise(r, pr + 5, 1);
919
+ if (checkRoundingDigits(r.d, pr, rm)) {
920
+ e = pr + 10;
921
+ r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
922
+ if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
923
+ r = finalise(r, pr + 1, 0);
924
+ }
925
+ }
926
+ }
927
+ r.s = s;
928
+ external = true;
929
+ Ctor.rounding = rm;
930
+ return finalise(r, pr, rm);
931
+ };
932
+ P.toPrecision = function(sd, rm) {
933
+ var str, x = this, Ctor = x.constructor;
934
+ if (sd === void 0) {
935
+ str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
936
+ } else {
937
+ checkInt32(sd, 1, MAX_DIGITS);
938
+ if (rm === void 0) rm = Ctor.rounding;
939
+ else checkInt32(rm, 0, 8);
940
+ x = finalise(new Ctor(x), sd, rm);
941
+ str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
942
+ }
943
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
944
+ };
945
+ P.toSignificantDigits = P.toSD = function(sd, rm) {
946
+ var x = this, Ctor = x.constructor;
947
+ if (sd === void 0) {
948
+ sd = Ctor.precision;
949
+ rm = Ctor.rounding;
950
+ } else {
951
+ checkInt32(sd, 1, MAX_DIGITS);
952
+ if (rm === void 0) rm = Ctor.rounding;
953
+ else checkInt32(rm, 0, 8);
954
+ }
955
+ return finalise(new Ctor(x), sd, rm);
956
+ };
957
+ P.toString = function() {
958
+ var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
959
+ return x.isNeg() && !x.isZero() ? "-" + str : str;
960
+ };
961
+ P.truncated = P.trunc = function() {
962
+ return finalise(new this.constructor(this), this.e + 1, 1);
963
+ };
964
+ P.valueOf = P.toJSON = function() {
965
+ var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
966
+ return x.isNeg() ? "-" + str : str;
967
+ };
968
+ function digitsToString(d) {
969
+ var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
970
+ if (indexOfLastWord > 0) {
971
+ str += w;
972
+ for (i = 1; i < indexOfLastWord; i++) {
973
+ ws = d[i] + "";
974
+ k = LOG_BASE - ws.length;
975
+ if (k) str += getZeroString(k);
976
+ str += ws;
977
+ }
978
+ w = d[i];
979
+ ws = w + "";
980
+ k = LOG_BASE - ws.length;
981
+ if (k) str += getZeroString(k);
982
+ } else if (w === 0) {
983
+ return "0";
984
+ }
985
+ for (; w % 10 === 0; ) w /= 10;
986
+ return str + w;
987
+ }
988
+ function checkInt32(i, min2, max2) {
989
+ if (i !== ~~i || i < min2 || i > max2) {
990
+ throw Error(invalidArgument + i);
991
+ }
992
+ }
993
+ function checkRoundingDigits(d, i, rm, repeating) {
994
+ var di, k, r, rd;
995
+ for (k = d[0]; k >= 10; k /= 10) --i;
996
+ if (--i < 0) {
997
+ i += LOG_BASE;
998
+ di = 0;
999
+ } else {
1000
+ di = Math.ceil((i + 1) / LOG_BASE);
1001
+ i %= LOG_BASE;
1002
+ }
1003
+ k = mathpow(10, LOG_BASE - i);
1004
+ rd = d[di] % k | 0;
1005
+ if (repeating == null) {
1006
+ if (i < 3) {
1007
+ if (i == 0) rd = rd / 100 | 0;
1008
+ else if (i == 1) rd = rd / 10 | 0;
1009
+ r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
1010
+ } else {
1011
+ r = (rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 100 | 0) == mathpow(10, i - 2) - 1 || (rd == k / 2 || rd == 0) && (d[di + 1] / k / 100 | 0) == 0;
1012
+ }
1013
+ } else {
1014
+ if (i < 4) {
1015
+ if (i == 0) rd = rd / 1e3 | 0;
1016
+ else if (i == 1) rd = rd / 100 | 0;
1017
+ else if (i == 2) rd = rd / 10 | 0;
1018
+ r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
1019
+ } else {
1020
+ r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1e3 | 0) == mathpow(10, i - 3) - 1;
1021
+ }
1022
+ }
1023
+ return r;
1024
+ }
1025
+ function convertBase(str, baseIn, baseOut) {
1026
+ var j, arr = [0], arrL, i = 0, strL = str.length;
1027
+ for (; i < strL; ) {
1028
+ for (arrL = arr.length; arrL--; ) arr[arrL] *= baseIn;
1029
+ arr[0] += NUMERALS.indexOf(str.charAt(i++));
1030
+ for (j = 0; j < arr.length; j++) {
1031
+ if (arr[j] > baseOut - 1) {
1032
+ if (arr[j + 1] === void 0) arr[j + 1] = 0;
1033
+ arr[j + 1] += arr[j] / baseOut | 0;
1034
+ arr[j] %= baseOut;
1035
+ }
1036
+ }
1037
+ }
1038
+ return arr.reverse();
1039
+ }
1040
+ function cosine(Ctor, x) {
1041
+ var k, len, y;
1042
+ if (x.isZero()) return x;
1043
+ len = x.d.length;
1044
+ if (len < 32) {
1045
+ k = Math.ceil(len / 3);
1046
+ y = (1 / tinyPow(4, k)).toString();
1047
+ } else {
1048
+ k = 16;
1049
+ y = "2.3283064365386962890625e-10";
1050
+ }
1051
+ Ctor.precision += k;
1052
+ x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
1053
+ for (var i = k; i--; ) {
1054
+ var cos2x = x.times(x);
1055
+ x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
1056
+ }
1057
+ Ctor.precision -= k;
1058
+ return x;
1059
+ }
1060
+ var divide = /* @__PURE__ */ (function() {
1061
+ function multiplyInteger(x, k, base) {
1062
+ var temp, carry = 0, i = x.length;
1063
+ for (x = x.slice(); i--; ) {
1064
+ temp = x[i] * k + carry;
1065
+ x[i] = temp % base | 0;
1066
+ carry = temp / base | 0;
1067
+ }
1068
+ if (carry) x.unshift(carry);
1069
+ return x;
1070
+ }
1071
+ function compare(a, b, aL, bL) {
1072
+ var i, r;
1073
+ if (aL != bL) {
1074
+ r = aL > bL ? 1 : -1;
1075
+ } else {
1076
+ for (i = r = 0; i < aL; i++) {
1077
+ if (a[i] != b[i]) {
1078
+ r = a[i] > b[i] ? 1 : -1;
1079
+ break;
1080
+ }
1081
+ }
1082
+ }
1083
+ return r;
1084
+ }
1085
+ function subtract(a, b, aL, base) {
1086
+ var i = 0;
1087
+ for (; aL--; ) {
1088
+ a[aL] -= i;
1089
+ i = a[aL] < b[aL] ? 1 : 0;
1090
+ a[aL] = i * base + a[aL] - b[aL];
1091
+ }
1092
+ for (; !a[0] && a.length > 1; ) a.shift();
1093
+ }
1094
+ return function(x, y, pr, rm, dp, base) {
1095
+ var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign2 = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
1096
+ if (!xd || !xd[0] || !yd || !yd[0]) {
1097
+ return new Ctor(
1098
+ // Return NaN if either NaN, or both Infinity or 0.
1099
+ !x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : (
1100
+ // Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
1101
+ xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
1102
+ )
1103
+ );
1104
+ }
1105
+ if (base) {
1106
+ logBase = 1;
1107
+ e = x.e - y.e;
1108
+ } else {
1109
+ base = BASE;
1110
+ logBase = LOG_BASE;
1111
+ e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
1112
+ }
1113
+ yL = yd.length;
1114
+ xL = xd.length;
1115
+ q = new Ctor(sign2);
1116
+ qd = q.d = [];
1117
+ for (i = 0; yd[i] == (xd[i] || 0); i++) ;
1118
+ if (yd[i] > (xd[i] || 0)) e--;
1119
+ if (pr == null) {
1120
+ sd = pr = Ctor.precision;
1121
+ rm = Ctor.rounding;
1122
+ } else if (dp) {
1123
+ sd = pr + (x.e - y.e) + 1;
1124
+ } else {
1125
+ sd = pr;
1126
+ }
1127
+ if (sd < 0) {
1128
+ qd.push(1);
1129
+ more = true;
1130
+ } else {
1131
+ sd = sd / logBase + 2 | 0;
1132
+ i = 0;
1133
+ if (yL == 1) {
1134
+ k = 0;
1135
+ yd = yd[0];
1136
+ sd++;
1137
+ for (; (i < xL || k) && sd--; i++) {
1138
+ t = k * base + (xd[i] || 0);
1139
+ qd[i] = t / yd | 0;
1140
+ k = t % yd | 0;
1141
+ }
1142
+ more = k || i < xL;
1143
+ } else {
1144
+ k = base / (yd[0] + 1) | 0;
1145
+ if (k > 1) {
1146
+ yd = multiplyInteger(yd, k, base);
1147
+ xd = multiplyInteger(xd, k, base);
1148
+ yL = yd.length;
1149
+ xL = xd.length;
1150
+ }
1151
+ xi = yL;
1152
+ rem = xd.slice(0, yL);
1153
+ remL = rem.length;
1154
+ for (; remL < yL; ) rem[remL++] = 0;
1155
+ yz = yd.slice();
1156
+ yz.unshift(0);
1157
+ yd0 = yd[0];
1158
+ if (yd[1] >= base / 2) ++yd0;
1159
+ do {
1160
+ k = 0;
1161
+ cmp = compare(yd, rem, yL, remL);
1162
+ if (cmp < 0) {
1163
+ rem0 = rem[0];
1164
+ if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
1165
+ k = rem0 / yd0 | 0;
1166
+ if (k > 1) {
1167
+ if (k >= base) k = base - 1;
1168
+ prod = multiplyInteger(yd, k, base);
1169
+ prodL = prod.length;
1170
+ remL = rem.length;
1171
+ cmp = compare(prod, rem, prodL, remL);
1172
+ if (cmp == 1) {
1173
+ k--;
1174
+ subtract(prod, yL < prodL ? yz : yd, prodL, base);
1175
+ }
1176
+ } else {
1177
+ if (k == 0) cmp = k = 1;
1178
+ prod = yd.slice();
1179
+ }
1180
+ prodL = prod.length;
1181
+ if (prodL < remL) prod.unshift(0);
1182
+ subtract(rem, prod, remL, base);
1183
+ if (cmp == -1) {
1184
+ remL = rem.length;
1185
+ cmp = compare(yd, rem, yL, remL);
1186
+ if (cmp < 1) {
1187
+ k++;
1188
+ subtract(rem, yL < remL ? yz : yd, remL, base);
1189
+ }
1190
+ }
1191
+ remL = rem.length;
1192
+ } else if (cmp === 0) {
1193
+ k++;
1194
+ rem = [0];
1195
+ }
1196
+ qd[i++] = k;
1197
+ if (cmp && rem[0]) {
1198
+ rem[remL++] = xd[xi] || 0;
1199
+ } else {
1200
+ rem = [xd[xi]];
1201
+ remL = 1;
1202
+ }
1203
+ } while ((xi++ < xL || rem[0] !== void 0) && sd--);
1204
+ more = rem[0] !== void 0;
1205
+ }
1206
+ if (!qd[0]) qd.shift();
1207
+ }
1208
+ if (logBase == 1) {
1209
+ q.e = e;
1210
+ inexact = more;
1211
+ } else {
1212
+ for (i = 1, k = qd[0]; k >= 10; k /= 10) i++;
1213
+ q.e = i + e * logBase - 1;
1214
+ finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
1215
+ }
1216
+ return q;
1217
+ };
1218
+ })();
1219
+ function finalise(x, sd, rm, isTruncated) {
1220
+ var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
1221
+ out: if (sd != null) {
1222
+ xd = x.d;
1223
+ if (!xd) return x;
1224
+ for (digits = 1, k = xd[0]; k >= 10; k /= 10) digits++;
1225
+ i = sd - digits;
1226
+ if (i < 0) {
1227
+ i += LOG_BASE;
1228
+ j = sd;
1229
+ w = xd[xdi = 0];
1230
+ rd = w / mathpow(10, digits - j - 1) % 10 | 0;
1231
+ } else {
1232
+ xdi = Math.ceil((i + 1) / LOG_BASE);
1233
+ k = xd.length;
1234
+ if (xdi >= k) {
1235
+ if (isTruncated) {
1236
+ for (; k++ <= xdi; ) xd.push(0);
1237
+ w = rd = 0;
1238
+ digits = 1;
1239
+ i %= LOG_BASE;
1240
+ j = i - LOG_BASE + 1;
1241
+ } else {
1242
+ break out;
1243
+ }
1244
+ } else {
1245
+ w = k = xd[xdi];
1246
+ for (digits = 1; k >= 10; k /= 10) digits++;
1247
+ i %= LOG_BASE;
1248
+ j = i - LOG_BASE + digits;
1249
+ rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
1250
+ }
1251
+ }
1252
+ isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
1253
+ roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
1254
+ (i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
1255
+ if (sd < 1 || !xd[0]) {
1256
+ xd.length = 0;
1257
+ if (roundUp) {
1258
+ sd -= x.e + 1;
1259
+ xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
1260
+ x.e = -sd || 0;
1261
+ } else {
1262
+ xd[0] = x.e = 0;
1263
+ }
1264
+ return x;
1265
+ }
1266
+ if (i == 0) {
1267
+ xd.length = xdi;
1268
+ k = 1;
1269
+ xdi--;
1270
+ } else {
1271
+ xd.length = xdi + 1;
1272
+ k = mathpow(10, LOG_BASE - i);
1273
+ xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
1274
+ }
1275
+ if (roundUp) {
1276
+ for (; ; ) {
1277
+ if (xdi == 0) {
1278
+ for (i = 1, j = xd[0]; j >= 10; j /= 10) i++;
1279
+ j = xd[0] += k;
1280
+ for (k = 1; j >= 10; j /= 10) k++;
1281
+ if (i != k) {
1282
+ x.e++;
1283
+ if (xd[0] == BASE) xd[0] = 1;
1284
+ }
1285
+ break;
1286
+ } else {
1287
+ xd[xdi] += k;
1288
+ if (xd[xdi] != BASE) break;
1289
+ xd[xdi--] = 0;
1290
+ k = 1;
1291
+ }
1292
+ }
1293
+ }
1294
+ for (i = xd.length; xd[--i] === 0; ) xd.pop();
1295
+ }
1296
+ if (external) {
1297
+ if (x.e > Ctor.maxE) {
1298
+ x.d = null;
1299
+ x.e = NaN;
1300
+ } else if (x.e < Ctor.minE) {
1301
+ x.e = 0;
1302
+ x.d = [0];
1303
+ }
1304
+ }
1305
+ return x;
1306
+ }
1307
+ function finiteToString(x, isExp, sd) {
1308
+ if (!x.isFinite()) return nonFiniteToString(x);
1309
+ var k, e = x.e, str = digitsToString(x.d), len = str.length;
1310
+ if (isExp) {
1311
+ if (sd && (k = sd - len) > 0) {
1312
+ str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
1313
+ } else if (len > 1) {
1314
+ str = str.charAt(0) + "." + str.slice(1);
1315
+ }
1316
+ str = str + (x.e < 0 ? "e" : "e+") + x.e;
1317
+ } else if (e < 0) {
1318
+ str = "0." + getZeroString(-e - 1) + str;
1319
+ if (sd && (k = sd - len) > 0) str += getZeroString(k);
1320
+ } else if (e >= len) {
1321
+ str += getZeroString(e + 1 - len);
1322
+ if (sd && (k = sd - e - 1) > 0) str = str + "." + getZeroString(k);
1323
+ } else {
1324
+ if ((k = e + 1) < len) str = str.slice(0, k) + "." + str.slice(k);
1325
+ if (sd && (k = sd - len) > 0) {
1326
+ if (e + 1 === len) str += ".";
1327
+ str += getZeroString(k);
1328
+ }
1329
+ }
1330
+ return str;
1331
+ }
1332
+ function getBase10Exponent(digits, e) {
1333
+ var w = digits[0];
1334
+ for (e *= LOG_BASE; w >= 10; w /= 10) e++;
1335
+ return e;
1336
+ }
1337
+ function getLn10(Ctor, sd, pr) {
1338
+ if (sd > LN10_PRECISION) {
1339
+ external = true;
1340
+ if (pr) Ctor.precision = pr;
1341
+ throw Error(precisionLimitExceeded);
1342
+ }
1343
+ return finalise(new Ctor(LN10), sd, 1, true);
1344
+ }
1345
+ function getPi(Ctor, sd, rm) {
1346
+ if (sd > PI_PRECISION) throw Error(precisionLimitExceeded);
1347
+ return finalise(new Ctor(PI), sd, rm, true);
1348
+ }
1349
+ function getPrecision(digits) {
1350
+ var w = digits.length - 1, len = w * LOG_BASE + 1;
1351
+ w = digits[w];
1352
+ if (w) {
1353
+ for (; w % 10 == 0; w /= 10) len--;
1354
+ for (w = digits[0]; w >= 10; w /= 10) len++;
1355
+ }
1356
+ return len;
1357
+ }
1358
+ function getZeroString(k) {
1359
+ var zs = "";
1360
+ for (; k--; ) zs += "0";
1361
+ return zs;
1362
+ }
1363
+ function intPow(Ctor, x, n, pr) {
1364
+ var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
1365
+ external = false;
1366
+ for (; ; ) {
1367
+ if (n % 2) {
1368
+ r = r.times(x);
1369
+ if (truncate(r.d, k)) isTruncated = true;
1370
+ }
1371
+ n = mathfloor(n / 2);
1372
+ if (n === 0) {
1373
+ n = r.d.length - 1;
1374
+ if (isTruncated && r.d[n] === 0) ++r.d[n];
1375
+ break;
1376
+ }
1377
+ x = x.times(x);
1378
+ truncate(x.d, k);
1379
+ }
1380
+ external = true;
1381
+ return r;
1382
+ }
1383
+ function isOdd(n) {
1384
+ return n.d[n.d.length - 1] & 1;
1385
+ }
1386
+ function maxOrMin(Ctor, args, n) {
1387
+ var k, y, x = new Ctor(args[0]), i = 0;
1388
+ for (; ++i < args.length; ) {
1389
+ y = new Ctor(args[i]);
1390
+ if (!y.s) {
1391
+ x = y;
1392
+ break;
1393
+ }
1394
+ k = x.cmp(y);
1395
+ if (k === n || k === 0 && x.s === n) {
1396
+ x = y;
1397
+ }
1398
+ }
1399
+ return x;
1400
+ }
1401
+ function naturalExponential(x, sd) {
1402
+ var denominator, guard, j, pow2, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1403
+ if (!x.d || !x.d[0] || x.e > 17) {
1404
+ return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
1405
+ }
1406
+ if (sd == null) {
1407
+ external = false;
1408
+ wpr = pr;
1409
+ } else {
1410
+ wpr = sd;
1411
+ }
1412
+ t = new Ctor(0.03125);
1413
+ while (x.e > -2) {
1414
+ x = x.times(t);
1415
+ k += 5;
1416
+ }
1417
+ guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
1418
+ wpr += guard;
1419
+ denominator = pow2 = sum2 = new Ctor(1);
1420
+ Ctor.precision = wpr;
1421
+ for (; ; ) {
1422
+ pow2 = finalise(pow2.times(x), wpr, 1);
1423
+ denominator = denominator.times(++i);
1424
+ t = sum2.plus(divide(pow2, denominator, wpr, 1));
1425
+ if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
1426
+ j = k;
1427
+ while (j--) sum2 = finalise(sum2.times(sum2), wpr, 1);
1428
+ if (sd == null) {
1429
+ if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
1430
+ Ctor.precision = wpr += 10;
1431
+ denominator = pow2 = t = new Ctor(1);
1432
+ i = 0;
1433
+ rep++;
1434
+ } else {
1435
+ return finalise(sum2, Ctor.precision = pr, rm, external = true);
1436
+ }
1437
+ } else {
1438
+ Ctor.precision = pr;
1439
+ return sum2;
1440
+ }
1441
+ }
1442
+ sum2 = t;
1443
+ }
1444
+ }
1445
+ function naturalLogarithm(y, sd) {
1446
+ var c, c0, denominator, e, numerator, rep, sum2, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1447
+ if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
1448
+ return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
1449
+ }
1450
+ if (sd == null) {
1451
+ external = false;
1452
+ wpr = pr;
1453
+ } else {
1454
+ wpr = sd;
1455
+ }
1456
+ Ctor.precision = wpr += guard;
1457
+ c = digitsToString(xd);
1458
+ c0 = c.charAt(0);
1459
+ if (Math.abs(e = x.e) < 15e14) {
1460
+ while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
1461
+ x = x.times(y);
1462
+ c = digitsToString(x.d);
1463
+ c0 = c.charAt(0);
1464
+ n++;
1465
+ }
1466
+ e = x.e;
1467
+ if (c0 > 1) {
1468
+ x = new Ctor("0." + c);
1469
+ e++;
1470
+ } else {
1471
+ x = new Ctor(c0 + "." + c.slice(1));
1472
+ }
1473
+ } else {
1474
+ t = getLn10(Ctor, wpr + 2, pr).times(e + "");
1475
+ x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
1476
+ Ctor.precision = pr;
1477
+ return sd == null ? finalise(x, pr, rm, external = true) : x;
1478
+ }
1479
+ x1 = x;
1480
+ sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
1481
+ x2 = finalise(x.times(x), wpr, 1);
1482
+ denominator = 3;
1483
+ for (; ; ) {
1484
+ numerator = finalise(numerator.times(x2), wpr, 1);
1485
+ t = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1));
1486
+ if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
1487
+ sum2 = sum2.times(2);
1488
+ if (e !== 0) sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
1489
+ sum2 = divide(sum2, new Ctor(n), wpr, 1);
1490
+ if (sd == null) {
1491
+ if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
1492
+ Ctor.precision = wpr += guard;
1493
+ t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
1494
+ x2 = finalise(x.times(x), wpr, 1);
1495
+ denominator = rep = 1;
1496
+ } else {
1497
+ return finalise(sum2, Ctor.precision = pr, rm, external = true);
1498
+ }
1499
+ } else {
1500
+ Ctor.precision = pr;
1501
+ return sum2;
1502
+ }
1503
+ }
1504
+ sum2 = t;
1505
+ denominator += 2;
1506
+ }
1507
+ }
1508
+ function nonFiniteToString(x) {
1509
+ return String(x.s * x.s / 0);
1510
+ }
1511
+ function parseDecimal(x, str) {
1512
+ var e, i, len;
1513
+ if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
1514
+ if ((i = str.search(/e/i)) > 0) {
1515
+ if (e < 0) e = i;
1516
+ e += +str.slice(i + 1);
1517
+ str = str.substring(0, i);
1518
+ } else if (e < 0) {
1519
+ e = str.length;
1520
+ }
1521
+ for (i = 0; str.charCodeAt(i) === 48; i++) ;
1522
+ for (len = str.length; str.charCodeAt(len - 1) === 48; --len) ;
1523
+ str = str.slice(i, len);
1524
+ if (str) {
1525
+ len -= i;
1526
+ x.e = e = e - i - 1;
1527
+ x.d = [];
1528
+ i = (e + 1) % LOG_BASE;
1529
+ if (e < 0) i += LOG_BASE;
1530
+ if (i < len) {
1531
+ if (i) x.d.push(+str.slice(0, i));
1532
+ for (len -= LOG_BASE; i < len; ) x.d.push(+str.slice(i, i += LOG_BASE));
1533
+ str = str.slice(i);
1534
+ i = LOG_BASE - str.length;
1535
+ } else {
1536
+ i -= len;
1537
+ }
1538
+ for (; i--; ) str += "0";
1539
+ x.d.push(+str);
1540
+ if (external) {
1541
+ if (x.e > x.constructor.maxE) {
1542
+ x.d = null;
1543
+ x.e = NaN;
1544
+ } else if (x.e < x.constructor.minE) {
1545
+ x.e = 0;
1546
+ x.d = [0];
1547
+ }
1548
+ }
1549
+ } else {
1550
+ x.e = 0;
1551
+ x.d = [0];
1552
+ }
1553
+ return x;
1554
+ }
1555
+ function parseOther(x, str) {
1556
+ var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
1557
+ if (str.indexOf("_") > -1) {
1558
+ str = str.replace(/(\d)_(?=\d)/g, "$1");
1559
+ if (isDecimal.test(str)) return parseDecimal(x, str);
1560
+ } else if (str === "Infinity" || str === "NaN") {
1561
+ if (!+str) x.s = NaN;
1562
+ x.e = NaN;
1563
+ x.d = null;
1564
+ return x;
1565
+ }
1566
+ if (isHex.test(str)) {
1567
+ base = 16;
1568
+ str = str.toLowerCase();
1569
+ } else if (isBinary.test(str)) {
1570
+ base = 2;
1571
+ } else if (isOctal.test(str)) {
1572
+ base = 8;
1573
+ } else {
1574
+ throw Error(invalidArgument + str);
1575
+ }
1576
+ i = str.search(/p/i);
1577
+ if (i > 0) {
1578
+ p = +str.slice(i + 1);
1579
+ str = str.substring(2, i);
1580
+ } else {
1581
+ str = str.slice(2);
1582
+ }
1583
+ i = str.indexOf(".");
1584
+ isFloat = i >= 0;
1585
+ Ctor = x.constructor;
1586
+ if (isFloat) {
1587
+ str = str.replace(".", "");
1588
+ len = str.length;
1589
+ i = len - i;
1590
+ divisor = intPow(Ctor, new Ctor(base), i, i * 2);
1591
+ }
1592
+ xd = convertBase(str, base, BASE);
1593
+ xe = xd.length - 1;
1594
+ for (i = xe; xd[i] === 0; --i) xd.pop();
1595
+ if (i < 0) return new Ctor(x.s * 0);
1596
+ x.e = getBase10Exponent(xd, xe);
1597
+ x.d = xd;
1598
+ external = false;
1599
+ if (isFloat) x = divide(x, divisor, len * 4);
1600
+ if (p) x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
1601
+ external = true;
1602
+ return x;
1603
+ }
1604
+ function sine(Ctor, x) {
1605
+ var k, len = x.d.length;
1606
+ if (len < 3) {
1607
+ return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
1608
+ }
1609
+ k = 1.4 * Math.sqrt(len);
1610
+ k = k > 16 ? 16 : k | 0;
1611
+ x = x.times(1 / tinyPow(5, k));
1612
+ x = taylorSeries(Ctor, 2, x, x);
1613
+ var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
1614
+ for (; k--; ) {
1615
+ sin2_x = x.times(x);
1616
+ x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
1617
+ }
1618
+ return x;
1619
+ }
1620
+ function taylorSeries(Ctor, n, x, y, isHyperbolic) {
1621
+ var j, t, u, x2, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
1622
+ external = false;
1623
+ x2 = x.times(x);
1624
+ u = new Ctor(y);
1625
+ for (; ; ) {
1626
+ t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
1627
+ u = isHyperbolic ? y.plus(t) : y.minus(t);
1628
+ y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
1629
+ t = u.plus(y);
1630
+ if (t.d[k] !== void 0) {
1631
+ for (j = k; t.d[j] === u.d[j] && j--; ) ;
1632
+ if (j == -1) break;
1633
+ }
1634
+ j = u;
1635
+ u = y;
1636
+ y = t;
1637
+ t = j;
1638
+ }
1639
+ external = true;
1640
+ t.d.length = k + 1;
1641
+ return t;
1642
+ }
1643
+ function tinyPow(b, e) {
1644
+ var n = b;
1645
+ while (--e) n *= b;
1646
+ return n;
1647
+ }
1648
+ function toLessThanHalfPi(Ctor, x) {
1649
+ var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
1650
+ x = x.abs();
1651
+ if (x.lte(halfPi)) {
1652
+ quadrant = isNeg ? 4 : 1;
1653
+ return x;
1654
+ }
1655
+ t = x.divToInt(pi);
1656
+ if (t.isZero()) {
1657
+ quadrant = isNeg ? 3 : 2;
1658
+ } else {
1659
+ x = x.minus(t.times(pi));
1660
+ if (x.lte(halfPi)) {
1661
+ quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
1662
+ return x;
1663
+ }
1664
+ quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
1665
+ }
1666
+ return x.minus(pi).abs();
1667
+ }
1668
+ function toStringBinary(x, baseOut, sd, rm) {
1669
+ var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== void 0;
1670
+ if (isExp) {
1671
+ checkInt32(sd, 1, MAX_DIGITS);
1672
+ if (rm === void 0) rm = Ctor.rounding;
1673
+ else checkInt32(rm, 0, 8);
1674
+ } else {
1675
+ sd = Ctor.precision;
1676
+ rm = Ctor.rounding;
1677
+ }
1678
+ if (!x.isFinite()) {
1679
+ str = nonFiniteToString(x);
1680
+ } else {
1681
+ str = finiteToString(x);
1682
+ i = str.indexOf(".");
1683
+ if (isExp) {
1684
+ base = 2;
1685
+ if (baseOut == 16) {
1686
+ sd = sd * 4 - 3;
1687
+ } else if (baseOut == 8) {
1688
+ sd = sd * 3 - 2;
1689
+ }
1690
+ } else {
1691
+ base = baseOut;
1692
+ }
1693
+ if (i >= 0) {
1694
+ str = str.replace(".", "");
1695
+ y = new Ctor(1);
1696
+ y.e = str.length - i;
1697
+ y.d = convertBase(finiteToString(y), 10, base);
1698
+ y.e = y.d.length;
1699
+ }
1700
+ xd = convertBase(str, 10, base);
1701
+ e = len = xd.length;
1702
+ for (; xd[--len] == 0; ) xd.pop();
1703
+ if (!xd[0]) {
1704
+ str = isExp ? "0p+0" : "0";
1705
+ } else {
1706
+ if (i < 0) {
1707
+ e--;
1708
+ } else {
1709
+ x = new Ctor(x);
1710
+ x.d = xd;
1711
+ x.e = e;
1712
+ x = divide(x, y, sd, rm, 0, base);
1713
+ xd = x.d;
1714
+ e = x.e;
1715
+ roundUp = inexact;
1716
+ }
1717
+ i = xd[sd];
1718
+ k = base / 2;
1719
+ roundUp = roundUp || xd[sd + 1] !== void 0;
1720
+ roundUp = rm < 4 ? (i !== void 0 || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2)) : i > k || i === k && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 || rm === (x.s < 0 ? 8 : 7));
1721
+ xd.length = sd;
1722
+ if (roundUp) {
1723
+ for (; ++xd[--sd] > base - 1; ) {
1724
+ xd[sd] = 0;
1725
+ if (!sd) {
1726
+ ++e;
1727
+ xd.unshift(1);
1728
+ }
1729
+ }
1730
+ }
1731
+ for (len = xd.length; !xd[len - 1]; --len) ;
1732
+ for (i = 0, str = ""; i < len; i++) str += NUMERALS.charAt(xd[i]);
1733
+ if (isExp) {
1734
+ if (len > 1) {
1735
+ if (baseOut == 16 || baseOut == 8) {
1736
+ i = baseOut == 16 ? 4 : 3;
1737
+ for (--len; len % i; len++) str += "0";
1738
+ xd = convertBase(str, base, baseOut);
1739
+ for (len = xd.length; !xd[len - 1]; --len) ;
1740
+ for (i = 1, str = "1."; i < len; i++) str += NUMERALS.charAt(xd[i]);
1741
+ } else {
1742
+ str = str.charAt(0) + "." + str.slice(1);
1743
+ }
1744
+ }
1745
+ str = str + (e < 0 ? "p" : "p+") + e;
1746
+ } else if (e < 0) {
1747
+ for (; ++e; ) str = "0" + str;
1748
+ str = "0." + str;
1749
+ } else {
1750
+ if (++e > len) for (e -= len; e--; ) str += "0";
1751
+ else if (e < len) str = str.slice(0, e) + "." + str.slice(e);
1752
+ }
1753
+ }
1754
+ str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
1755
+ }
1756
+ return x.s < 0 ? "-" + str : str;
1757
+ }
1758
+ function truncate(arr, len) {
1759
+ if (arr.length > len) {
1760
+ arr.length = len;
1761
+ return true;
1762
+ }
1763
+ }
1764
+ function abs(x) {
1765
+ return new this(x).abs();
1766
+ }
1767
+ function acos(x) {
1768
+ return new this(x).acos();
1769
+ }
1770
+ function acosh(x) {
1771
+ return new this(x).acosh();
1772
+ }
1773
+ function add(x, y) {
1774
+ return new this(x).plus(y);
1775
+ }
1776
+ function asin(x) {
1777
+ return new this(x).asin();
1778
+ }
1779
+ function asinh(x) {
1780
+ return new this(x).asinh();
1781
+ }
1782
+ function atan(x) {
1783
+ return new this(x).atan();
1784
+ }
1785
+ function atanh(x) {
1786
+ return new this(x).atanh();
1787
+ }
1788
+ function atan2(y, x) {
1789
+ y = new this(y);
1790
+ x = new this(x);
1791
+ var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
1792
+ if (!y.s || !x.s) {
1793
+ r = new this(NaN);
1794
+ } else if (!y.d && !x.d) {
1795
+ r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
1796
+ r.s = y.s;
1797
+ } else if (!x.d || y.isZero()) {
1798
+ r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
1799
+ r.s = y.s;
1800
+ } else if (!y.d || x.isZero()) {
1801
+ r = getPi(this, wpr, 1).times(0.5);
1802
+ r.s = y.s;
1803
+ } else if (x.s < 0) {
1804
+ this.precision = wpr;
1805
+ this.rounding = 1;
1806
+ r = this.atan(divide(y, x, wpr, 1));
1807
+ x = getPi(this, wpr, 1);
1808
+ this.precision = pr;
1809
+ this.rounding = rm;
1810
+ r = y.s < 0 ? r.minus(x) : r.plus(x);
1811
+ } else {
1812
+ r = this.atan(divide(y, x, wpr, 1));
1813
+ }
1814
+ return r;
1815
+ }
1816
+ function cbrt(x) {
1817
+ return new this(x).cbrt();
1818
+ }
1819
+ function ceil(x) {
1820
+ return finalise(x = new this(x), x.e + 1, 2);
1821
+ }
1822
+ function clamp(x, min2, max2) {
1823
+ return new this(x).clamp(min2, max2);
1824
+ }
1825
+ function config(obj) {
1826
+ if (!obj || typeof obj !== "object") throw Error(decimalError + "Object expected");
1827
+ var i, p, v, useDefaults = obj.defaults === true, ps = [
1828
+ "precision",
1829
+ 1,
1830
+ MAX_DIGITS,
1831
+ "rounding",
1832
+ 0,
1833
+ 8,
1834
+ "toExpNeg",
1835
+ -EXP_LIMIT,
1836
+ 0,
1837
+ "toExpPos",
1838
+ 0,
1839
+ EXP_LIMIT,
1840
+ "maxE",
1841
+ 0,
1842
+ EXP_LIMIT,
1843
+ "minE",
1844
+ -EXP_LIMIT,
1845
+ 0,
1846
+ "modulo",
1847
+ 0,
1848
+ 9
1849
+ ];
1850
+ for (i = 0; i < ps.length; i += 3) {
1851
+ if (p = ps[i], useDefaults) this[p] = DEFAULTS[p];
1852
+ if ((v = obj[p]) !== void 0) {
1853
+ if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2]) this[p] = v;
1854
+ else throw Error(invalidArgument + p + ": " + v);
1855
+ }
1856
+ }
1857
+ if (p = "crypto", useDefaults) this[p] = DEFAULTS[p];
1858
+ if ((v = obj[p]) !== void 0) {
1859
+ if (v === true || v === false || v === 0 || v === 1) {
1860
+ if (v) {
1861
+ if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
1862
+ this[p] = true;
1863
+ } else {
1864
+ throw Error(cryptoUnavailable);
1865
+ }
1866
+ } else {
1867
+ this[p] = false;
1868
+ }
1869
+ } else {
1870
+ throw Error(invalidArgument + p + ": " + v);
1871
+ }
1872
+ }
1873
+ return this;
1874
+ }
1875
+ function cos(x) {
1876
+ return new this(x).cos();
1877
+ }
1878
+ function cosh(x) {
1879
+ return new this(x).cosh();
1880
+ }
1881
+ function clone(obj) {
1882
+ var i, p, ps;
1883
+ function Decimal2(v) {
1884
+ var e, i2, t, x = this;
1885
+ if (!(x instanceof Decimal2)) return new Decimal2(v);
1886
+ x.constructor = Decimal2;
1887
+ if (isDecimalInstance(v)) {
1888
+ x.s = v.s;
1889
+ if (external) {
1890
+ if (!v.d || v.e > Decimal2.maxE) {
1891
+ x.e = NaN;
1892
+ x.d = null;
1893
+ } else if (v.e < Decimal2.minE) {
1894
+ x.e = 0;
1895
+ x.d = [0];
1896
+ } else {
1897
+ x.e = v.e;
1898
+ x.d = v.d.slice();
1899
+ }
1900
+ } else {
1901
+ x.e = v.e;
1902
+ x.d = v.d ? v.d.slice() : v.d;
1903
+ }
1904
+ return;
1905
+ }
1906
+ t = typeof v;
1907
+ if (t === "number") {
1908
+ if (v === 0) {
1909
+ x.s = 1 / v < 0 ? -1 : 1;
1910
+ x.e = 0;
1911
+ x.d = [0];
1912
+ return;
1913
+ }
1914
+ if (v < 0) {
1915
+ v = -v;
1916
+ x.s = -1;
1917
+ } else {
1918
+ x.s = 1;
1919
+ }
1920
+ if (v === ~~v && v < 1e7) {
1921
+ for (e = 0, i2 = v; i2 >= 10; i2 /= 10) e++;
1922
+ if (external) {
1923
+ if (e > Decimal2.maxE) {
1924
+ x.e = NaN;
1925
+ x.d = null;
1926
+ } else if (e < Decimal2.minE) {
1927
+ x.e = 0;
1928
+ x.d = [0];
1929
+ } else {
1930
+ x.e = e;
1931
+ x.d = [v];
1932
+ }
1933
+ } else {
1934
+ x.e = e;
1935
+ x.d = [v];
1936
+ }
1937
+ return;
1938
+ }
1939
+ if (v * 0 !== 0) {
1940
+ if (!v) x.s = NaN;
1941
+ x.e = NaN;
1942
+ x.d = null;
1943
+ return;
1944
+ }
1945
+ return parseDecimal(x, v.toString());
1946
+ }
1947
+ if (t === "string") {
1948
+ if ((i2 = v.charCodeAt(0)) === 45) {
1949
+ v = v.slice(1);
1950
+ x.s = -1;
1951
+ } else {
1952
+ if (i2 === 43) v = v.slice(1);
1953
+ x.s = 1;
1954
+ }
1955
+ return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
1956
+ }
1957
+ if (t === "bigint") {
1958
+ if (v < 0) {
1959
+ v = -v;
1960
+ x.s = -1;
1961
+ } else {
1962
+ x.s = 1;
1963
+ }
1964
+ return parseDecimal(x, v.toString());
1965
+ }
1966
+ throw Error(invalidArgument + v);
1967
+ }
1968
+ Decimal2.prototype = P;
1969
+ Decimal2.ROUND_UP = 0;
1970
+ Decimal2.ROUND_DOWN = 1;
1971
+ Decimal2.ROUND_CEIL = 2;
1972
+ Decimal2.ROUND_FLOOR = 3;
1973
+ Decimal2.ROUND_HALF_UP = 4;
1974
+ Decimal2.ROUND_HALF_DOWN = 5;
1975
+ Decimal2.ROUND_HALF_EVEN = 6;
1976
+ Decimal2.ROUND_HALF_CEIL = 7;
1977
+ Decimal2.ROUND_HALF_FLOOR = 8;
1978
+ Decimal2.EUCLID = 9;
1979
+ Decimal2.config = Decimal2.set = config;
1980
+ Decimal2.clone = clone;
1981
+ Decimal2.isDecimal = isDecimalInstance;
1982
+ Decimal2.abs = abs;
1983
+ Decimal2.acos = acos;
1984
+ Decimal2.acosh = acosh;
1985
+ Decimal2.add = add;
1986
+ Decimal2.asin = asin;
1987
+ Decimal2.asinh = asinh;
1988
+ Decimal2.atan = atan;
1989
+ Decimal2.atanh = atanh;
1990
+ Decimal2.atan2 = atan2;
1991
+ Decimal2.cbrt = cbrt;
1992
+ Decimal2.ceil = ceil;
1993
+ Decimal2.clamp = clamp;
1994
+ Decimal2.cos = cos;
1995
+ Decimal2.cosh = cosh;
1996
+ Decimal2.div = div;
1997
+ Decimal2.exp = exp;
1998
+ Decimal2.floor = floor;
1999
+ Decimal2.hypot = hypot;
2000
+ Decimal2.ln = ln;
2001
+ Decimal2.log = log;
2002
+ Decimal2.log10 = log10;
2003
+ Decimal2.log2 = log2;
2004
+ Decimal2.max = max;
2005
+ Decimal2.min = min;
2006
+ Decimal2.mod = mod;
2007
+ Decimal2.mul = mul;
2008
+ Decimal2.pow = pow;
2009
+ Decimal2.random = random;
2010
+ Decimal2.round = round;
2011
+ Decimal2.sign = sign;
2012
+ Decimal2.sin = sin;
2013
+ Decimal2.sinh = sinh;
2014
+ Decimal2.sqrt = sqrt;
2015
+ Decimal2.sub = sub;
2016
+ Decimal2.sum = sum;
2017
+ Decimal2.tan = tan;
2018
+ Decimal2.tanh = tanh;
2019
+ Decimal2.trunc = trunc;
2020
+ if (obj === void 0) obj = {};
2021
+ if (obj) {
2022
+ if (obj.defaults !== true) {
2023
+ ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
2024
+ for (i = 0; i < ps.length; ) if (!obj.hasOwnProperty(p = ps[i++])) obj[p] = this[p];
2025
+ }
2026
+ }
2027
+ Decimal2.config(obj);
2028
+ return Decimal2;
2029
+ }
2030
+ function div(x, y) {
2031
+ return new this(x).div(y);
2032
+ }
2033
+ function exp(x) {
2034
+ return new this(x).exp();
2035
+ }
2036
+ function floor(x) {
2037
+ return finalise(x = new this(x), x.e + 1, 3);
2038
+ }
2039
+ function hypot() {
2040
+ var i, n, t = new this(0);
2041
+ external = false;
2042
+ for (i = 0; i < arguments.length; ) {
2043
+ n = new this(arguments[i++]);
2044
+ if (!n.d) {
2045
+ if (n.s) {
2046
+ external = true;
2047
+ return new this(1 / 0);
2048
+ }
2049
+ t = n;
2050
+ } else if (t.d) {
2051
+ t = t.plus(n.times(n));
2052
+ }
2053
+ }
2054
+ external = true;
2055
+ return t.sqrt();
2056
+ }
2057
+ function isDecimalInstance(obj) {
2058
+ return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
2059
+ }
2060
+ function ln(x) {
2061
+ return new this(x).ln();
2062
+ }
2063
+ function log(x, y) {
2064
+ return new this(x).log(y);
2065
+ }
2066
+ function log2(x) {
2067
+ return new this(x).log(2);
2068
+ }
2069
+ function log10(x) {
2070
+ return new this(x).log(10);
2071
+ }
2072
+ function max() {
2073
+ return maxOrMin(this, arguments, -1);
2074
+ }
2075
+ function min() {
2076
+ return maxOrMin(this, arguments, 1);
2077
+ }
2078
+ function mod(x, y) {
2079
+ return new this(x).mod(y);
2080
+ }
2081
+ function mul(x, y) {
2082
+ return new this(x).mul(y);
2083
+ }
2084
+ function pow(x, y) {
2085
+ return new this(x).pow(y);
2086
+ }
2087
+ function random(sd) {
2088
+ var d, e, k, n, i = 0, r = new this(1), rd = [];
2089
+ if (sd === void 0) sd = this.precision;
2090
+ else checkInt32(sd, 1, MAX_DIGITS);
2091
+ k = Math.ceil(sd / LOG_BASE);
2092
+ if (!this.crypto) {
2093
+ for (; i < k; ) rd[i++] = Math.random() * 1e7 | 0;
2094
+ } else if (crypto.getRandomValues) {
2095
+ d = crypto.getRandomValues(new Uint32Array(k));
2096
+ for (; i < k; ) {
2097
+ n = d[i];
2098
+ if (n >= 429e7) {
2099
+ d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
2100
+ } else {
2101
+ rd[i++] = n % 1e7;
2102
+ }
2103
+ }
2104
+ } else if (crypto.randomBytes) {
2105
+ d = crypto.randomBytes(k *= 4);
2106
+ for (; i < k; ) {
2107
+ n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
2108
+ if (n >= 214e7) {
2109
+ crypto.randomBytes(4).copy(d, i);
2110
+ } else {
2111
+ rd.push(n % 1e7);
2112
+ i += 4;
2113
+ }
2114
+ }
2115
+ i = k / 4;
2116
+ } else {
2117
+ throw Error(cryptoUnavailable);
2118
+ }
2119
+ k = rd[--i];
2120
+ sd %= LOG_BASE;
2121
+ if (k && sd) {
2122
+ n = mathpow(10, LOG_BASE - sd);
2123
+ rd[i] = (k / n | 0) * n;
2124
+ }
2125
+ for (; rd[i] === 0; i--) rd.pop();
2126
+ if (i < 0) {
2127
+ e = 0;
2128
+ rd = [0];
2129
+ } else {
2130
+ e = -1;
2131
+ for (; rd[0] === 0; e -= LOG_BASE) rd.shift();
2132
+ for (k = 1, n = rd[0]; n >= 10; n /= 10) k++;
2133
+ if (k < LOG_BASE) e -= LOG_BASE - k;
2134
+ }
2135
+ r.e = e;
2136
+ r.d = rd;
2137
+ return r;
2138
+ }
2139
+ function round(x) {
2140
+ return finalise(x = new this(x), x.e + 1, this.rounding);
2141
+ }
2142
+ function sign(x) {
2143
+ x = new this(x);
2144
+ return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
2145
+ }
2146
+ function sin(x) {
2147
+ return new this(x).sin();
2148
+ }
2149
+ function sinh(x) {
2150
+ return new this(x).sinh();
2151
+ }
2152
+ function sqrt(x) {
2153
+ return new this(x).sqrt();
2154
+ }
2155
+ function sub(x, y) {
2156
+ return new this(x).sub(y);
2157
+ }
2158
+ function sum() {
2159
+ var i = 0, args = arguments, x = new this(args[i]);
2160
+ external = false;
2161
+ for (; x.s && ++i < args.length; ) x = x.plus(args[i]);
2162
+ external = true;
2163
+ return finalise(x, this.precision, this.rounding);
2164
+ }
2165
+ function tan(x) {
2166
+ return new this(x).tan();
2167
+ }
2168
+ function tanh(x) {
2169
+ return new this(x).tanh();
2170
+ }
2171
+ function trunc(x) {
2172
+ return finalise(x = new this(x), x.e + 1, 1);
2173
+ }
2174
+ P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
2175
+ P[Symbol.toStringTag] = "Decimal";
2176
+ var Decimal = P.constructor = clone(DEFAULTS);
2177
+ LN10 = new Decimal(LN10);
2178
+ PI = new Decimal(PI);
2179
+ var decimal_default = Decimal;
2180
+ function getTransactionAccountEncoder() {
2181
+ return getStructEncoder([
2182
+ ["pubkey", getAddressEncoder()],
2183
+ ["isSigner", getBooleanEncoder()],
2184
+ ["isWritable", getBooleanEncoder()]
2185
+ ]);
2186
+ }
2187
+ function getTransactionAccountDecoder() {
2188
+ return getStructDecoder([
2189
+ ["pubkey", getAddressDecoder()],
2190
+ ["isSigner", getBooleanDecoder()],
2191
+ ["isWritable", getBooleanDecoder()]
2192
+ ]);
2193
+ }
2194
+ function getTransactionAccountCodec() {
2195
+ return combineCodec(
2196
+ getTransactionAccountEncoder(),
2197
+ getTransactionAccountDecoder()
2198
+ );
2199
+ }
2200
+ var FeeCollectionFrequency = /* @__PURE__ */ ((FeeCollectionFrequency2) => {
2201
+ FeeCollectionFrequency2[FeeCollectionFrequency2["Monthly"] = 0] = "Monthly";
2202
+ FeeCollectionFrequency2[FeeCollectionFrequency2["Quarterly"] = 1] = "Quarterly";
2203
+ FeeCollectionFrequency2[FeeCollectionFrequency2["Annually"] = 2] = "Annually";
2204
+ FeeCollectionFrequency2[FeeCollectionFrequency2["OnWithdrawal"] = 3] = "OnWithdrawal";
2205
+ return FeeCollectionFrequency2;
2206
+ })(FeeCollectionFrequency || {});
2207
+ function getFeeCollectionFrequencyEncoder() {
2208
+ return getEnumEncoder(FeeCollectionFrequency);
2209
+ }
2210
+ function getFeeCollectionFrequencyDecoder() {
2211
+ return getEnumDecoder(FeeCollectionFrequency);
2212
+ }
2213
+ function getFeeCollectionFrequencyCodec() {
2214
+ return combineCodec(
2215
+ getFeeCollectionFrequencyEncoder(),
2216
+ getFeeCollectionFrequencyDecoder()
2217
+ );
2218
+ }
2219
+
2220
+ // src/types/managerFeeStructure.ts
2221
+ function getManagerFeeStructureEncoder() {
2222
+ return getStructEncoder([
2223
+ ["performanceFeeRate", getU16Encoder()],
2224
+ ["managementFeeRate", getU16Encoder()],
2225
+ ["collectionFrequency", getFeeCollectionFrequencyEncoder()],
2226
+ ["highWaterMark", getU64Encoder()],
2227
+ ["feeRecipient", getAddressEncoder()]
2228
+ ]);
2229
+ }
2230
+ function getManagerFeeStructureDecoder() {
2231
+ return getStructDecoder([
2232
+ ["performanceFeeRate", getU16Decoder()],
2233
+ ["managementFeeRate", getU16Decoder()],
2234
+ ["collectionFrequency", getFeeCollectionFrequencyDecoder()],
2235
+ ["highWaterMark", getU64Decoder()],
2236
+ ["feeRecipient", getAddressDecoder()]
2237
+ ]);
2238
+ }
2239
+ function getManagerFeeStructureCodec() {
2240
+ return combineCodec(
2241
+ getManagerFeeStructureEncoder(),
2242
+ getManagerFeeStructureDecoder()
2243
+ );
2244
+ }
2245
+
2246
+ // src/types/policy.ts
2247
+ var Policy = /* @__PURE__ */ ((Policy2) => {
2248
+ Policy2["AllowAny"] = "AllowAny";
2249
+ Policy2["DenyAll"] = "DenyAll";
2250
+ Policy2["LimitTransfer"] = "LimitTransfer";
2251
+ Policy2["Owners"] = "Owners";
2252
+ Policy2["Multisig"] = "Multisig";
2253
+ return Policy2;
2254
+ })(Policy || {});
2255
+ function getVaultDecoder() {
2256
+ return getStructDecoder([
2257
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
2258
+ ["policyProgram", getAddressDecoder()],
2259
+ ["seed", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
2260
+ ["authority", getAddressDecoder()],
2261
+ ["shareMint", getAddressDecoder()],
2262
+ ["underlyingMint", getAddressDecoder()],
2263
+ ["manager", getOptionDecoder(getAddressDecoder())],
2264
+ ["parentVault", getOptionDecoder(getAddressDecoder())],
2265
+ ["allocation", getU64Decoder()],
2266
+ ["onchainBalance", getU64Decoder()],
2267
+ ["offchainBalance", getU64Decoder()],
2268
+ ["totalBalance", getU64Decoder()],
2269
+ ["lastBalanceUpdate", getU64Decoder()],
2270
+ ["highWaterMark", getU64Decoder()],
2271
+ ["totalFeesPaid", getU64Decoder()],
2272
+ ["managerFees", getOptionDecoder(getManagerFeeStructureDecoder())],
2273
+ ["createdAt", getU64Decoder()],
2274
+ ["lastFeeCollection", getU64Decoder()]
2275
+ ]);
2276
+ }
2277
+ function decodeVault(encodedAccount) {
2278
+ return decodeAccount(
2279
+ encodedAccount,
2280
+ getVaultDecoder()
2281
+ );
2282
+ }
2283
+ async function fetchVault(rpc, address, config2) {
2284
+ const maybeAccount = await fetchMaybeVault(rpc, address, config2);
2285
+ assertAccountExists(maybeAccount);
2286
+ return maybeAccount;
2287
+ }
2288
+ async function fetchMaybeVault(rpc, address, config2) {
2289
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config2);
2290
+ return decodeVault(maybeAccount);
2291
+ }
2292
+ function getTransactionDecoder() {
2293
+ return getStructDecoder([
2294
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
2295
+ ["nonce", getU64Decoder()],
2296
+ ["didExecute", getBooleanDecoder()],
2297
+ ["vault", getAddressDecoder()],
2298
+ ["programId", getAddressDecoder()],
2299
+ ["data", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder())],
2300
+ ["accounts", getArrayDecoder(getTransactionAccountDecoder())]
2301
+ ]);
2302
+ }
2303
+ function decodeTransaction(encodedAccount) {
2304
+ return decodeAccount(
2305
+ encodedAccount,
2306
+ getTransactionDecoder()
2307
+ );
2308
+ }
2309
+ async function fetchTransaction(rpc, address, config2) {
2310
+ const maybeAccount = await fetchMaybeTransaction(rpc, address, config2);
2311
+ assertAccountExists(maybeAccount);
2312
+ return maybeAccount;
2313
+ }
2314
+ async function fetchMaybeTransaction(rpc, address, config2) {
2315
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config2);
2316
+ return decodeTransaction(maybeAccount);
2317
+ }
2318
+
2319
+ // src/programs/hyroProtocol.ts
2320
+ var HYRO_PROTOCOL_PROGRAM_ADDRESS = "EGfondqUWdztf79joC5CBDi9HQEhgUtSsVmbPK838At4";
2321
+
2322
+ // src/programs/dropper.ts
2323
+ var DROPPER_PROGRAM_ADDRESS = "5Lk3HERSPsH82FQH9xGnp6YXjoTczQs6jpJoyG7M5kiC";
2324
+
2325
+ // src/programs/policyPrograms.ts
2326
+ var POLICY_ALLOW_ANY_PROGRAM_ADDRESS = "8PahHajSVz2QZn3cCTVH5Ldq2CJzD1GiPrqAiVmuB91Q";
2327
+ var POLICY_DENY_ALL_PROGRAM_ADDRESS = "FK8qiE3SoLfvtoQUXSdTwKEwmcBWjGBteh5m1VrD91zu";
2328
+ var POLICY_LIMIT_TRANSFER_PROGRAM_ADDRESS = "BhX5NffdrXhv7sPPBkobYNDQbBLsTQhrcTsTbTYGj389";
2329
+ var POLICY_OWNERS_PROGRAM_ADDRESS = "AgcQY5x8iB3vf2oQwR1V78ZczTkCy5EUP6pZAdrmHbLX";
2330
+ var POLICY_MULTISIG_PROGRAM_ADDRESS = "CaiBHtLhiBJJCdzUksjjXWEQfcXpFnCvLDLU6QhstAwE";
2331
+ var POLICY_CHALLENGES_PROGRAM_ADDRESS = "8Vewok54U1fwpbytBX7JDfv2nNTKCEqu93DcFPCRdgWM";
2332
+ function expectSome(value) {
2333
+ if (value === null || value === void 0) {
2334
+ throw new Error("Expected a value but received null or undefined.");
2335
+ }
2336
+ return value;
2337
+ }
2338
+ function expectAddress(value) {
2339
+ if (!value) {
2340
+ throw new Error("Expected a Address.");
2341
+ }
2342
+ if (typeof value === "object" && "address" in value) {
2343
+ return value.address;
2344
+ }
2345
+ if (Array.isArray(value)) {
2346
+ return value[0];
2347
+ }
2348
+ return value;
2349
+ }
2350
+ function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
2351
+ return (account) => {
2352
+ if (!account.value) {
2353
+ return Object.freeze({
2354
+ address: programAddress,
2355
+ role: AccountRole.READONLY
2356
+ });
2357
+ }
2358
+ const writableRole = account.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;
2359
+ return Object.freeze({
2360
+ address: expectAddress(account.value),
2361
+ role: isTransactionSigner(account.value) ? upgradeRoleToSigner(writableRole) : writableRole,
2362
+ ...isTransactionSigner(account.value) ? { signer: account.value } : {}
2363
+ });
2364
+ };
2365
+ }
2366
+ function isTransactionSigner(value) {
2367
+ return !!value && typeof value === "object" && "address" in value && isTransactionSigner$1(value);
2368
+ }
2369
+
2370
+ // src/instructions/dropper/transferLamports.ts
2371
+ var TRANSFER_LAMPORTS_DISCRIMINATOR = new Uint8Array([
2372
+ 62,
2373
+ 53,
2374
+ 201,
2375
+ 68,
2376
+ 102,
2377
+ 134,
2378
+ 83,
2379
+ 103
2380
+ ]);
2381
+ function getTransferLamportsDiscriminatorBytes() {
2382
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
2383
+ TRANSFER_LAMPORTS_DISCRIMINATOR
2384
+ );
2385
+ }
2386
+ function getTransferLamportsInstructionDataEncoder() {
2387
+ return transformEncoder(
2388
+ getStructEncoder([
2389
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
2390
+ ["amount", getU64Encoder()]
2391
+ ]),
2392
+ (value) => ({ ...value, discriminator: TRANSFER_LAMPORTS_DISCRIMINATOR })
2393
+ );
2394
+ }
2395
+ function getTransferLamportsInstructionDataDecoder() {
2396
+ return getStructDecoder([
2397
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
2398
+ ["amount", getU64Decoder()]
2399
+ ]);
2400
+ }
2401
+ function getTransferLamportsInstructionDataCodec() {
2402
+ return combineCodec(
2403
+ getTransferLamportsInstructionDataEncoder(),
2404
+ getTransferLamportsInstructionDataDecoder()
2405
+ );
2406
+ }
2407
+ function getTransferLamportsInstruction(input, config2) {
2408
+ const programAddress = config2?.programAddress ?? DROPPER_PROGRAM_ADDRESS;
2409
+ const originalAccounts = {
2410
+ from: { value: input.from ?? null, isWritable: true },
2411
+ to: { value: input.to ?? null, isWritable: true },
2412
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false }
2413
+ };
2414
+ const accounts = originalAccounts;
2415
+ const args = { ...input };
2416
+ if (!accounts.systemProgram.value) {
2417
+ accounts.systemProgram.value = "11111111111111111111111111111111";
2418
+ }
2419
+ const getAccountMeta = getAccountMetaFactory(programAddress);
2420
+ const instruction = {
2421
+ accounts: [
2422
+ getAccountMeta(accounts.from),
2423
+ getAccountMeta(accounts.to),
2424
+ getAccountMeta(accounts.systemProgram)
2425
+ ],
2426
+ programAddress,
2427
+ data: getTransferLamportsInstructionDataEncoder().encode(
2428
+ args
2429
+ )
2430
+ };
2431
+ return instruction;
2432
+ }
2433
+ function parseTransferLamportsInstruction(instruction) {
2434
+ if (instruction.accounts.length < 3) {
2435
+ throw new Error("Not enough accounts");
2436
+ }
2437
+ let accountIndex = 0;
2438
+ const getNextAccount = () => {
2439
+ const accountMeta = instruction.accounts[accountIndex];
2440
+ accountIndex += 1;
2441
+ return accountMeta;
2442
+ };
2443
+ return {
2444
+ programAddress: instruction.programAddress,
2445
+ accounts: {
2446
+ from: getNextAccount(),
2447
+ to: getNextAccount(),
2448
+ systemProgram: getNextAccount()
2449
+ },
2450
+ data: getTransferLamportsInstructionDataDecoder().decode(instruction.data)
2451
+ };
2452
+ }
2453
+ var CREATE_TX_DISCRIMINATOR = new Uint8Array([
2454
+ 97,
2455
+ 223,
2456
+ 80,
2457
+ 153,
2458
+ 55,
2459
+ 13,
2460
+ 155,
2461
+ 12
2462
+ ]);
2463
+ function getCreateTxDiscriminatorBytes() {
2464
+ return fixEncoderSize(getBytesEncoder(), 8).encode(CREATE_TX_DISCRIMINATOR);
2465
+ }
2466
+ function getCreateTxInstructionDataEncoder() {
2467
+ return transformEncoder(
2468
+ getStructEncoder([
2469
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
2470
+ ["nonce", getU64Encoder()],
2471
+ ["pid", getAddressEncoder()],
2472
+ ["accs", getArrayEncoder(getTransactionAccountEncoder())],
2473
+ ["data", addEncoderSizePrefix(getBytesEncoder(), getU32Encoder())]
2474
+ ]),
2475
+ (value) => ({ ...value, discriminator: CREATE_TX_DISCRIMINATOR })
2476
+ );
2477
+ }
2478
+ function getCreateTxInstructionDataDecoder() {
2479
+ return getStructDecoder([
2480
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
2481
+ ["nonce", getU64Decoder()],
2482
+ ["pid", getAddressDecoder()],
2483
+ ["accs", getArrayDecoder(getTransactionAccountDecoder())],
2484
+ ["data", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder())]
2485
+ ]);
2486
+ }
2487
+ function getCreateTxInstructionDataCodec() {
2488
+ return combineCodec(
2489
+ getCreateTxInstructionDataEncoder(),
2490
+ getCreateTxInstructionDataDecoder()
2491
+ );
2492
+ }
2493
+ async function getCreateTxInstructionAsync(input, config2) {
2494
+ const programAddress = config2?.programAddress ?? HYRO_PROTOCOL_PROGRAM_ADDRESS;
2495
+ const originalAccounts = {
2496
+ vault: { value: input.vault ?? null, isWritable: false },
2497
+ transaction: { value: input.transaction ?? null, isWritable: true },
2498
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
2499
+ policyProgram: { value: input.policyProgram ?? null, isWritable: false },
2500
+ vaultSigner: { value: input.vaultSigner ?? null, isWritable: false },
2501
+ signer: { value: input.signer ?? null, isWritable: true },
2502
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false }
2503
+ };
2504
+ const accounts = originalAccounts;
2505
+ const args = { ...input };
2506
+ if (!accounts.transaction.value) {
2507
+ accounts.transaction.value = await getProgramDerivedAddress({
2508
+ programAddress,
2509
+ seeds: [
2510
+ getAddressEncoder().encode(expectAddress(accounts.vault.value)),
2511
+ getU64Encoder().encode(expectSome(args.nonce))
2512
+ ]
2513
+ });
2514
+ }
2515
+ if (!accounts.vaultSigner.value) {
2516
+ accounts.vaultSigner.value = await getProgramDerivedAddress({
2517
+ programAddress,
2518
+ seeds: [getAddressEncoder().encode(expectAddress(accounts.vault.value))]
2519
+ });
2520
+ }
2521
+ if (!accounts.systemProgram.value) {
2522
+ accounts.systemProgram.value = "11111111111111111111111111111111";
2523
+ }
2524
+ const getAccountMeta = getAccountMetaFactory(programAddress);
2525
+ const instruction = {
2526
+ accounts: [
2527
+ getAccountMeta(accounts.vault),
2528
+ getAccountMeta(accounts.transaction),
2529
+ getAccountMeta(accounts.policyAccount),
2530
+ getAccountMeta(accounts.policyProgram),
2531
+ getAccountMeta(accounts.vaultSigner),
2532
+ getAccountMeta(accounts.signer),
2533
+ getAccountMeta(accounts.systemProgram)
2534
+ ],
2535
+ programAddress,
2536
+ data: getCreateTxInstructionDataEncoder().encode(
2537
+ args
2538
+ )
2539
+ };
2540
+ return instruction;
2541
+ }
2542
+ function getCreateTxInstruction(input, config2) {
2543
+ const programAddress = config2?.programAddress ?? HYRO_PROTOCOL_PROGRAM_ADDRESS;
2544
+ const originalAccounts = {
2545
+ vault: { value: input.vault ?? null, isWritable: false },
2546
+ transaction: { value: input.transaction ?? null, isWritable: true },
2547
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
2548
+ policyProgram: { value: input.policyProgram ?? null, isWritable: false },
2549
+ vaultSigner: { value: input.vaultSigner ?? null, isWritable: false },
2550
+ signer: { value: input.signer ?? null, isWritable: true },
2551
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false }
2552
+ };
2553
+ const accounts = originalAccounts;
2554
+ const args = { ...input };
2555
+ if (!accounts.systemProgram.value) {
2556
+ accounts.systemProgram.value = "11111111111111111111111111111111";
2557
+ }
2558
+ const getAccountMeta = getAccountMetaFactory(programAddress);
2559
+ const instruction = {
2560
+ accounts: [
2561
+ getAccountMeta(accounts.vault),
2562
+ getAccountMeta(accounts.transaction),
2563
+ getAccountMeta(accounts.policyAccount),
2564
+ getAccountMeta(accounts.policyProgram),
2565
+ getAccountMeta(accounts.vaultSigner),
2566
+ getAccountMeta(accounts.signer),
2567
+ getAccountMeta(accounts.systemProgram)
2568
+ ],
2569
+ programAddress,
2570
+ data: getCreateTxInstructionDataEncoder().encode(
2571
+ args
2572
+ )
2573
+ };
2574
+ return instruction;
2575
+ }
2576
+ function parseCreateTxInstruction(instruction) {
2577
+ if (instruction.accounts.length < 7) {
2578
+ throw new Error("Not enough accounts");
2579
+ }
2580
+ let accountIndex = 0;
2581
+ const getNextAccount = () => {
2582
+ const accountMeta = instruction.accounts[accountIndex];
2583
+ accountIndex += 1;
2584
+ return accountMeta;
2585
+ };
2586
+ return {
2587
+ programAddress: instruction.programAddress,
2588
+ accounts: {
2589
+ vault: getNextAccount(),
2590
+ transaction: getNextAccount(),
2591
+ policyAccount: getNextAccount(),
2592
+ policyProgram: getNextAccount(),
2593
+ vaultSigner: getNextAccount(),
2594
+ signer: getNextAccount(),
2595
+ systemProgram: getNextAccount()
2596
+ },
2597
+ data: getCreateTxInstructionDataDecoder().decode(instruction.data)
2598
+ };
2599
+ }
2600
+ var EXECUTE_TX_DISCRIMINATOR = new Uint8Array([
2601
+ 249,
2602
+ 17,
2603
+ 145,
2604
+ 23,
2605
+ 12,
2606
+ 252,
2607
+ 17,
2608
+ 41
2609
+ ]);
2610
+ function getExecuteTxDiscriminatorBytes() {
2611
+ return fixEncoderSize(getBytesEncoder(), 8).encode(EXECUTE_TX_DISCRIMINATOR);
2612
+ }
2613
+ function getExecuteTxInstructionDataEncoder() {
2614
+ return transformEncoder(
2615
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
2616
+ (value) => ({ ...value, discriminator: EXECUTE_TX_DISCRIMINATOR })
2617
+ );
2618
+ }
2619
+ function getExecuteTxInstructionDataDecoder() {
2620
+ return getStructDecoder([
2621
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)]
2622
+ ]);
2623
+ }
2624
+ function getExecuteTxInstructionDataCodec() {
2625
+ return combineCodec(
2626
+ getExecuteTxInstructionDataEncoder(),
2627
+ getExecuteTxInstructionDataDecoder()
2628
+ );
2629
+ }
2630
+ async function getExecuteTxInstructionAsync(input, config2) {
2631
+ const programAddress = config2?.programAddress ?? HYRO_PROTOCOL_PROGRAM_ADDRESS;
2632
+ const originalAccounts = {
2633
+ vault: { value: input.vault ?? null, isWritable: false },
2634
+ transaction: { value: input.transaction ?? null, isWritable: false },
2635
+ vaultSigner: { value: input.vaultSigner ?? null, isWritable: false },
2636
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
2637
+ policyProgram: { value: input.policyProgram ?? null, isWritable: false },
2638
+ signer: { value: input.signer ?? null, isWritable: true }
2639
+ };
2640
+ const accounts = originalAccounts;
2641
+ if (!accounts.vaultSigner.value) {
2642
+ accounts.vaultSigner.value = await getProgramDerivedAddress({
2643
+ programAddress,
2644
+ seeds: [getAddressEncoder().encode(expectAddress(accounts.vault.value))]
2645
+ });
2646
+ }
2647
+ const getAccountMeta = getAccountMetaFactory(programAddress);
2648
+ const instruction = {
2649
+ accounts: [
2650
+ getAccountMeta(accounts.vault),
2651
+ getAccountMeta(accounts.transaction),
2652
+ getAccountMeta(accounts.vaultSigner),
2653
+ getAccountMeta(accounts.policyAccount),
2654
+ getAccountMeta(accounts.policyProgram),
2655
+ getAccountMeta(accounts.signer)
2656
+ ],
2657
+ programAddress,
2658
+ data: getExecuteTxInstructionDataEncoder().encode({})
2659
+ };
2660
+ return instruction;
2661
+ }
2662
+ function getExecuteTxInstruction(input, config2) {
2663
+ const programAddress = config2?.programAddress ?? HYRO_PROTOCOL_PROGRAM_ADDRESS;
2664
+ const originalAccounts = {
2665
+ vault: { value: input.vault ?? null, isWritable: false },
2666
+ transaction: { value: input.transaction ?? null, isWritable: false },
2667
+ vaultSigner: { value: input.vaultSigner ?? null, isWritable: false },
2668
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
2669
+ policyProgram: { value: input.policyProgram ?? null, isWritable: false },
2670
+ signer: { value: input.signer ?? null, isWritable: true }
2671
+ };
2672
+ const accounts = originalAccounts;
2673
+ const getAccountMeta = getAccountMetaFactory(programAddress);
2674
+ const instruction = {
2675
+ accounts: [
2676
+ getAccountMeta(accounts.vault),
2677
+ getAccountMeta(accounts.transaction),
2678
+ getAccountMeta(accounts.vaultSigner),
2679
+ getAccountMeta(accounts.policyAccount),
2680
+ getAccountMeta(accounts.policyProgram),
2681
+ getAccountMeta(accounts.signer)
2682
+ ],
2683
+ programAddress,
2684
+ data: getExecuteTxInstructionDataEncoder().encode({})
2685
+ };
2686
+ return instruction;
2687
+ }
2688
+ function parseExecuteTxInstruction(instruction) {
2689
+ if (instruction.accounts.length < 6) {
2690
+ throw new Error("Not enough accounts");
2691
+ }
2692
+ let accountIndex = 0;
2693
+ const getNextAccount = () => {
2694
+ const accountMeta = instruction.accounts[accountIndex];
2695
+ accountIndex += 1;
2696
+ return accountMeta;
2697
+ };
2698
+ return {
2699
+ programAddress: instruction.programAddress,
2700
+ accounts: {
2701
+ vault: getNextAccount(),
2702
+ transaction: getNextAccount(),
2703
+ vaultSigner: getNextAccount(),
2704
+ policyAccount: getNextAccount(),
2705
+ policyProgram: getNextAccount(),
2706
+ signer: getNextAccount()
2707
+ },
2708
+ data: getExecuteTxInstructionDataDecoder().decode(instruction.data)
2709
+ };
2710
+ }
2711
+ var INITIALIZE_VAULT_DISCRIMINATOR = new Uint8Array([
2712
+ 48,
2713
+ 191,
2714
+ 163,
2715
+ 44,
2716
+ 71,
2717
+ 129,
2718
+ 63,
2719
+ 164
2720
+ ]);
2721
+ function getInitializeVaultDiscriminatorBytes() {
2722
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
2723
+ INITIALIZE_VAULT_DISCRIMINATOR
2724
+ );
2725
+ }
2726
+ function getInitializeVaultInstructionDataEncoder() {
2727
+ return transformEncoder(
2728
+ getStructEncoder([
2729
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
2730
+ ["seed", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
2731
+ ["policyProgram", getAddressEncoder()]
2732
+ ]),
2733
+ (value) => ({ ...value, discriminator: INITIALIZE_VAULT_DISCRIMINATOR })
2734
+ );
2735
+ }
2736
+ function getInitializeVaultInstructionDataDecoder() {
2737
+ return getStructDecoder([
2738
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
2739
+ ["seed", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
2740
+ ["policyProgram", getAddressDecoder()]
2741
+ ]);
2742
+ }
2743
+ function getInitializeVaultInstructionDataCodec() {
2744
+ return combineCodec(
2745
+ getInitializeVaultInstructionDataEncoder(),
2746
+ getInitializeVaultInstructionDataDecoder()
2747
+ );
2748
+ }
2749
+ async function getInitializeVaultInstructionAsync(input, config2) {
2750
+ const programAddress = config2?.programAddress ?? HYRO_PROTOCOL_PROGRAM_ADDRESS;
2751
+ const originalAccounts = {
2752
+ vault: { value: input.vault ?? null, isWritable: true },
2753
+ authority: { value: input.authority ?? null, isWritable: false },
2754
+ signer: { value: input.signer ?? null, isWritable: true },
2755
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
2756
+ shareSignerPda: { value: input.shareSignerPda ?? null, isWritable: false },
2757
+ shareMint: { value: input.shareMint ?? null, isWritable: true },
2758
+ vaultTokenAccount: {
2759
+ value: input.vaultTokenAccount ?? null,
2760
+ isWritable: true
2761
+ },
2762
+ authorityTokenAccount: {
2763
+ value: input.authorityTokenAccount ?? null,
2764
+ isWritable: true
2765
+ },
2766
+ underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
2767
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
2768
+ rent: { value: input.rent ?? null, isWritable: false }
2769
+ };
2770
+ const accounts = originalAccounts;
2771
+ const args = { ...input };
2772
+ if (!accounts.vault.value) {
2773
+ accounts.vault.value = await getProgramDerivedAddress({
2774
+ programAddress,
2775
+ seeds: [
2776
+ addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()).encode(
2777
+ expectSome(args.seed)
2778
+ )
2779
+ ]
2780
+ });
2781
+ }
2782
+ if (!accounts.authority.value) {
2783
+ accounts.authority.value = await getProgramDerivedAddress({
2784
+ programAddress,
2785
+ seeds: [getAddressEncoder().encode(expectAddress(accounts.vault.value))]
2786
+ });
2787
+ }
2788
+ if (!accounts.systemProgram.value) {
2789
+ accounts.systemProgram.value = "11111111111111111111111111111111";
2790
+ }
2791
+ if (!accounts.shareSignerPda.value) {
2792
+ accounts.shareSignerPda.value = await getProgramDerivedAddress({
2793
+ programAddress,
2794
+ seeds: [
2795
+ getBytesEncoder().encode(
2796
+ new Uint8Array([
2797
+ 118,
2798
+ 97,
2799
+ 117,
2800
+ 108,
2801
+ 116,
2802
+ 95,
2803
+ 115,
2804
+ 104,
2805
+ 97,
2806
+ 114,
2807
+ 101,
2808
+ 95,
2809
+ 115,
2810
+ 105,
2811
+ 103,
2812
+ 110,
2813
+ 101,
2814
+ 114
2815
+ ])
2816
+ ),
2817
+ getAddressEncoder().encode(expectAddress(accounts.vault.value))
2818
+ ]
2819
+ });
2820
+ }
2821
+ if (!accounts.shareMint.value) {
2822
+ accounts.shareMint.value = await getProgramDerivedAddress({
2823
+ programAddress,
2824
+ seeds: [
2825
+ getBytesEncoder().encode(
2826
+ new Uint8Array([
2827
+ 118,
2828
+ 97,
2829
+ 117,
2830
+ 108,
2831
+ 116,
2832
+ 95,
2833
+ 115,
2834
+ 104,
2835
+ 97,
2836
+ 114,
2837
+ 101,
2838
+ 95,
2839
+ 109,
2840
+ 105,
2841
+ 110,
2842
+ 116
2843
+ ])
2844
+ ),
2845
+ getAddressEncoder().encode(expectAddress(accounts.vault.value))
2846
+ ]
2847
+ });
2848
+ }
2849
+ if (!accounts.vaultTokenAccount.value) {
2850
+ accounts.vaultTokenAccount.value = await getProgramDerivedAddress({
2851
+ programAddress,
2852
+ seeds: [
2853
+ getBytesEncoder().encode(
2854
+ new Uint8Array([
2855
+ 118,
2856
+ 97,
2857
+ 117,
2858
+ 108,
2859
+ 116,
2860
+ 95,
2861
+ 116,
2862
+ 111,
2863
+ 107,
2864
+ 101,
2865
+ 110,
2866
+ 95,
2867
+ 97,
2868
+ 99,
2869
+ 99,
2870
+ 111,
2871
+ 117,
2872
+ 110,
2873
+ 116
2874
+ ])
2875
+ ),
2876
+ getAddressEncoder().encode(expectAddress(accounts.vault.value)),
2877
+ getAddressEncoder().encode(
2878
+ expectAddress(accounts.underlyingMint.value)
2879
+ )
2880
+ ]
2881
+ });
2882
+ }
2883
+ if (!accounts.authorityTokenAccount.value) {
2884
+ accounts.authorityTokenAccount.value = await getProgramDerivedAddress({
2885
+ programAddress,
2886
+ seeds: [
2887
+ getBytesEncoder().encode(
2888
+ new Uint8Array([
2889
+ 97,
2890
+ 117,
2891
+ 116,
2892
+ 104,
2893
+ 111,
2894
+ 114,
2895
+ 105,
2896
+ 116,
2897
+ 121,
2898
+ 95,
2899
+ 116,
2900
+ 111,
2901
+ 107,
2902
+ 101,
2903
+ 110,
2904
+ 95,
2905
+ 97,
2906
+ 99,
2907
+ 99,
2908
+ 111,
2909
+ 117,
2910
+ 110,
2911
+ 116
2912
+ ])
2913
+ ),
2914
+ getAddressEncoder().encode(expectAddress(accounts.authority.value)),
2915
+ getAddressEncoder().encode(
2916
+ expectAddress(accounts.underlyingMint.value)
2917
+ )
2918
+ ]
2919
+ });
2920
+ }
2921
+ if (!accounts.tokenProgram.value) {
2922
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
2923
+ }
2924
+ if (!accounts.rent.value) {
2925
+ accounts.rent.value = "SysvarRent111111111111111111111111111111111";
2926
+ }
2927
+ const getAccountMeta = getAccountMetaFactory(programAddress);
2928
+ const instruction = {
2929
+ accounts: [
2930
+ getAccountMeta(accounts.vault),
2931
+ getAccountMeta(accounts.authority),
2932
+ getAccountMeta(accounts.signer),
2933
+ getAccountMeta(accounts.systemProgram),
2934
+ getAccountMeta(accounts.shareSignerPda),
2935
+ getAccountMeta(accounts.shareMint),
2936
+ getAccountMeta(accounts.vaultTokenAccount),
2937
+ getAccountMeta(accounts.authorityTokenAccount),
2938
+ getAccountMeta(accounts.underlyingMint),
2939
+ getAccountMeta(accounts.tokenProgram),
2940
+ getAccountMeta(accounts.rent)
2941
+ ],
2942
+ programAddress,
2943
+ data: getInitializeVaultInstructionDataEncoder().encode(
2944
+ args
2945
+ )
2946
+ };
2947
+ return instruction;
2948
+ }
2949
+ function getInitializeVaultInstruction(input, config2) {
2950
+ const programAddress = config2?.programAddress ?? HYRO_PROTOCOL_PROGRAM_ADDRESS;
2951
+ const originalAccounts = {
2952
+ vault: { value: input.vault ?? null, isWritable: true },
2953
+ authority: { value: input.authority ?? null, isWritable: false },
2954
+ signer: { value: input.signer ?? null, isWritable: true },
2955
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
2956
+ shareSignerPda: { value: input.shareSignerPda ?? null, isWritable: false },
2957
+ shareMint: { value: input.shareMint ?? null, isWritable: true },
2958
+ vaultTokenAccount: {
2959
+ value: input.vaultTokenAccount ?? null,
2960
+ isWritable: true
2961
+ },
2962
+ authorityTokenAccount: {
2963
+ value: input.authorityTokenAccount ?? null,
2964
+ isWritable: true
2965
+ },
2966
+ underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
2967
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
2968
+ rent: { value: input.rent ?? null, isWritable: false }
2969
+ };
2970
+ const accounts = originalAccounts;
2971
+ const args = { ...input };
2972
+ if (!accounts.systemProgram.value) {
2973
+ accounts.systemProgram.value = "11111111111111111111111111111111";
2974
+ }
2975
+ if (!accounts.tokenProgram.value) {
2976
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
2977
+ }
2978
+ if (!accounts.rent.value) {
2979
+ accounts.rent.value = "SysvarRent111111111111111111111111111111111";
2980
+ }
2981
+ const getAccountMeta = getAccountMetaFactory(programAddress);
2982
+ const instruction = {
2983
+ accounts: [
2984
+ getAccountMeta(accounts.vault),
2985
+ getAccountMeta(accounts.authority),
2986
+ getAccountMeta(accounts.signer),
2987
+ getAccountMeta(accounts.systemProgram),
2988
+ getAccountMeta(accounts.shareSignerPda),
2989
+ getAccountMeta(accounts.shareMint),
2990
+ getAccountMeta(accounts.vaultTokenAccount),
2991
+ getAccountMeta(accounts.authorityTokenAccount),
2992
+ getAccountMeta(accounts.underlyingMint),
2993
+ getAccountMeta(accounts.tokenProgram),
2994
+ getAccountMeta(accounts.rent)
2995
+ ],
2996
+ programAddress,
2997
+ data: getInitializeVaultInstructionDataEncoder().encode(
2998
+ args
2999
+ )
3000
+ };
3001
+ return instruction;
3002
+ }
3003
+ function parseInitializeVaultInstruction(instruction) {
3004
+ if (instruction.accounts.length < 11) {
3005
+ throw new Error("Not enough accounts");
3006
+ }
3007
+ let accountIndex = 0;
3008
+ const getNextAccount = () => {
3009
+ const accountMeta = instruction.accounts[accountIndex];
3010
+ accountIndex += 1;
3011
+ return accountMeta;
3012
+ };
3013
+ return {
3014
+ programAddress: instruction.programAddress,
3015
+ accounts: {
3016
+ vault: getNextAccount(),
3017
+ authority: getNextAccount(),
3018
+ signer: getNextAccount(),
3019
+ systemProgram: getNextAccount(),
3020
+ shareSignerPda: getNextAccount(),
3021
+ shareMint: getNextAccount(),
3022
+ vaultTokenAccount: getNextAccount(),
3023
+ authorityTokenAccount: getNextAccount(),
3024
+ underlyingMint: getNextAccount(),
3025
+ tokenProgram: getNextAccount(),
3026
+ rent: getNextAccount()
3027
+ },
3028
+ data: getInitializeVaultInstructionDataDecoder().decode(instruction.data)
3029
+ };
3030
+ }
3031
+ var INITIALIZE_LIMIT_TRANSFER_DISCRIMINATOR = new Uint8Array([
3032
+ 231,
3033
+ 140,
3034
+ 57,
3035
+ 76,
3036
+ 17,
3037
+ 243,
3038
+ 161,
3039
+ 149
3040
+ ]);
3041
+ function getInitializeLimitTransferDiscriminatorBytes() {
3042
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
3043
+ INITIALIZE_LIMIT_TRANSFER_DISCRIMINATOR
3044
+ );
3045
+ }
3046
+ function getInitializeLimitTransferInstructionDataEncoder() {
3047
+ return transformEncoder(
3048
+ getStructEncoder([
3049
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
3050
+ ["min", getU64Encoder()],
3051
+ ["max", getU64Encoder()]
3052
+ ]),
3053
+ (value) => ({
3054
+ ...value,
3055
+ discriminator: INITIALIZE_LIMIT_TRANSFER_DISCRIMINATOR
3056
+ })
3057
+ );
3058
+ }
3059
+ function getInitializeLimitTransferInstructionDataDecoder() {
3060
+ return getStructDecoder([
3061
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
3062
+ ["min", getU64Decoder()],
3063
+ ["max", getU64Decoder()]
3064
+ ]);
3065
+ }
3066
+ function getInitializeLimitTransferInstructionDataCodec() {
3067
+ return combineCodec(
3068
+ getInitializeLimitTransferInstructionDataEncoder(),
3069
+ getInitializeLimitTransferInstructionDataDecoder()
3070
+ );
3071
+ }
3072
+ async function getInitializeLimitTransferInstructionAsync(input, config2) {
3073
+ const programAddress = config2?.programAddress ?? POLICY_LIMIT_TRANSFER_PROGRAM_ADDRESS;
3074
+ const originalAccounts = {
3075
+ vault: { value: input.vault ?? null, isWritable: false },
3076
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
3077
+ signer: { value: input.signer ?? null, isWritable: true },
3078
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false }
3079
+ };
3080
+ const accounts = originalAccounts;
3081
+ const args = { ...input };
3082
+ if (!accounts.policyAccount.value) {
3083
+ accounts.policyAccount.value = await getProgramDerivedAddress({
3084
+ programAddress,
3085
+ seeds: [getAddressEncoder().encode(expectAddress(accounts.vault.value))]
3086
+ });
3087
+ }
3088
+ if (!accounts.systemProgram.value) {
3089
+ accounts.systemProgram.value = "11111111111111111111111111111111";
3090
+ }
3091
+ const getAccountMeta = getAccountMetaFactory(programAddress);
3092
+ const instruction = {
3093
+ accounts: [
3094
+ getAccountMeta(accounts.vault),
3095
+ getAccountMeta(accounts.policyAccount),
3096
+ getAccountMeta(accounts.signer),
3097
+ getAccountMeta(accounts.systemProgram)
3098
+ ],
3099
+ programAddress,
3100
+ data: getInitializeLimitTransferInstructionDataEncoder().encode(
3101
+ args
3102
+ )
3103
+ };
3104
+ return instruction;
3105
+ }
3106
+ function getInitializeLimitTransferInstruction(input, config2) {
3107
+ const programAddress = config2?.programAddress ?? POLICY_LIMIT_TRANSFER_PROGRAM_ADDRESS;
3108
+ const originalAccounts = {
3109
+ vault: { value: input.vault ?? null, isWritable: false },
3110
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
3111
+ signer: { value: input.signer ?? null, isWritable: true },
3112
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false }
3113
+ };
3114
+ const accounts = originalAccounts;
3115
+ const args = { ...input };
3116
+ if (!accounts.systemProgram.value) {
3117
+ accounts.systemProgram.value = "11111111111111111111111111111111";
3118
+ }
3119
+ const getAccountMeta = getAccountMetaFactory(programAddress);
3120
+ const instruction = {
3121
+ accounts: [
3122
+ getAccountMeta(accounts.vault),
3123
+ getAccountMeta(accounts.policyAccount),
3124
+ getAccountMeta(accounts.signer),
3125
+ getAccountMeta(accounts.systemProgram)
3126
+ ],
3127
+ programAddress,
3128
+ data: getInitializeLimitTransferInstructionDataEncoder().encode(
3129
+ args
3130
+ )
3131
+ };
3132
+ return instruction;
3133
+ }
3134
+ function parseInitializeLimitTransferInstruction(instruction) {
3135
+ if (instruction.accounts.length < 4) {
3136
+ throw new Error("Not enough accounts");
3137
+ }
3138
+ let accountIndex = 0;
3139
+ const getNextAccount = () => {
3140
+ const accountMeta = instruction.accounts[accountIndex];
3141
+ accountIndex += 1;
3142
+ return accountMeta;
3143
+ };
3144
+ return {
3145
+ programAddress: instruction.programAddress,
3146
+ accounts: {
3147
+ vault: getNextAccount(),
3148
+ policyAccount: getNextAccount(),
3149
+ signer: getNextAccount(),
3150
+ systemProgram: getNextAccount()
3151
+ },
3152
+ data: getInitializeLimitTransferInstructionDataDecoder().decode(
3153
+ instruction.data
3154
+ )
3155
+ };
3156
+ }
3157
+ var APPROVE_DISCRIMINATOR = new Uint8Array([
3158
+ 69,
3159
+ 74,
3160
+ 217,
3161
+ 36,
3162
+ 115,
3163
+ 117,
3164
+ 97,
3165
+ 76
3166
+ ]);
3167
+ function getApproveDiscriminatorBytes() {
3168
+ return fixEncoderSize(getBytesEncoder(), 8).encode(APPROVE_DISCRIMINATOR);
3169
+ }
3170
+ function getApproveInstructionDataEncoder() {
3171
+ return transformEncoder(
3172
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
3173
+ (value) => ({ ...value, discriminator: APPROVE_DISCRIMINATOR })
3174
+ );
3175
+ }
3176
+ function getApproveInstructionDataDecoder() {
3177
+ return getStructDecoder([
3178
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)]
3179
+ ]);
3180
+ }
3181
+ function getApproveInstructionDataCodec() {
3182
+ return combineCodec(
3183
+ getApproveInstructionDataEncoder(),
3184
+ getApproveInstructionDataDecoder()
3185
+ );
3186
+ }
3187
+ function getApproveInstruction(input, config2) {
3188
+ const programAddress = config2?.programAddress ?? POLICY_MULTISIG_PROGRAM_ADDRESS;
3189
+ const originalAccounts = {
3190
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
3191
+ owner: { value: input.owner ?? null, isWritable: false }
3192
+ };
3193
+ const accounts = originalAccounts;
3194
+ const getAccountMeta = getAccountMetaFactory(programAddress);
3195
+ const instruction = {
3196
+ accounts: [
3197
+ getAccountMeta(accounts.policyAccount),
3198
+ getAccountMeta(accounts.owner)
3199
+ ],
3200
+ programAddress,
3201
+ data: getApproveInstructionDataEncoder().encode({})
3202
+ };
3203
+ return instruction;
3204
+ }
3205
+ function parseApproveInstruction(instruction) {
3206
+ if (instruction.accounts.length < 2) {
3207
+ throw new Error("Not enough accounts");
3208
+ }
3209
+ let accountIndex = 0;
3210
+ const getNextAccount = () => {
3211
+ const accountMeta = instruction.accounts[accountIndex];
3212
+ accountIndex += 1;
3213
+ return accountMeta;
3214
+ };
3215
+ return {
3216
+ programAddress: instruction.programAddress,
3217
+ accounts: {
3218
+ policyAccount: getNextAccount(),
3219
+ owner: getNextAccount()
3220
+ },
3221
+ data: getApproveInstructionDataDecoder().decode(instruction.data)
3222
+ };
3223
+ }
3224
+ var INITIALIZE_MULTISIG_DISCRIMINATOR = new Uint8Array([
3225
+ 220,
3226
+ 130,
3227
+ 117,
3228
+ 21,
3229
+ 27,
3230
+ 227,
3231
+ 78,
3232
+ 213
3233
+ ]);
3234
+ function getInitializeMultisigDiscriminatorBytes() {
3235
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
3236
+ INITIALIZE_MULTISIG_DISCRIMINATOR
3237
+ );
3238
+ }
3239
+ function getInitializeMultisigInstructionDataEncoder() {
3240
+ return transformEncoder(
3241
+ getStructEncoder([
3242
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
3243
+ ["owners", getArrayEncoder(getAddressEncoder())],
3244
+ ["threshold", getU64Encoder()]
3245
+ ]),
3246
+ (value) => ({ ...value, discriminator: INITIALIZE_MULTISIG_DISCRIMINATOR })
3247
+ );
3248
+ }
3249
+ function getInitializeMultisigInstructionDataDecoder() {
3250
+ return getStructDecoder([
3251
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
3252
+ ["owners", getArrayDecoder(getAddressDecoder())],
3253
+ ["threshold", getU64Decoder()]
3254
+ ]);
3255
+ }
3256
+ function getInitializeMultisigInstructionDataCodec() {
3257
+ return combineCodec(
3258
+ getInitializeMultisigInstructionDataEncoder(),
3259
+ getInitializeMultisigInstructionDataDecoder()
3260
+ );
3261
+ }
3262
+ async function getInitializeMultisigInstructionAsync(input, config2) {
3263
+ const programAddress = config2?.programAddress ?? POLICY_MULTISIG_PROGRAM_ADDRESS;
3264
+ const originalAccounts = {
3265
+ vault: { value: input.vault ?? null, isWritable: false },
3266
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
3267
+ signer: { value: input.signer ?? null, isWritable: true },
3268
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false }
3269
+ };
3270
+ const accounts = originalAccounts;
3271
+ const args = { ...input };
3272
+ if (!accounts.policyAccount.value) {
3273
+ accounts.policyAccount.value = await getProgramDerivedAddress({
3274
+ programAddress,
3275
+ seeds: [getAddressEncoder().encode(expectAddress(accounts.vault.value))]
3276
+ });
3277
+ }
3278
+ if (!accounts.systemProgram.value) {
3279
+ accounts.systemProgram.value = "11111111111111111111111111111111";
3280
+ }
3281
+ const getAccountMeta = getAccountMetaFactory(programAddress);
3282
+ const instruction = {
3283
+ accounts: [
3284
+ getAccountMeta(accounts.vault),
3285
+ getAccountMeta(accounts.policyAccount),
3286
+ getAccountMeta(accounts.signer),
3287
+ getAccountMeta(accounts.systemProgram)
3288
+ ],
3289
+ programAddress,
3290
+ data: getInitializeMultisigInstructionDataEncoder().encode(
3291
+ args
3292
+ )
3293
+ };
3294
+ return instruction;
3295
+ }
3296
+ function getInitializeMultisigInstruction(input, config2) {
3297
+ const programAddress = config2?.programAddress ?? POLICY_MULTISIG_PROGRAM_ADDRESS;
3298
+ const originalAccounts = {
3299
+ vault: { value: input.vault ?? null, isWritable: false },
3300
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
3301
+ signer: { value: input.signer ?? null, isWritable: true },
3302
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false }
3303
+ };
3304
+ const accounts = originalAccounts;
3305
+ const args = { ...input };
3306
+ if (!accounts.systemProgram.value) {
3307
+ accounts.systemProgram.value = "11111111111111111111111111111111";
3308
+ }
3309
+ const getAccountMeta = getAccountMetaFactory(programAddress);
3310
+ const instruction = {
3311
+ accounts: [
3312
+ getAccountMeta(accounts.vault),
3313
+ getAccountMeta(accounts.policyAccount),
3314
+ getAccountMeta(accounts.signer),
3315
+ getAccountMeta(accounts.systemProgram)
3316
+ ],
3317
+ programAddress,
3318
+ data: getInitializeMultisigInstructionDataEncoder().encode(
3319
+ args
3320
+ )
3321
+ };
3322
+ return instruction;
3323
+ }
3324
+ function parseInitializeMultisigInstruction(instruction) {
3325
+ if (instruction.accounts.length < 4) {
3326
+ throw new Error("Not enough accounts");
3327
+ }
3328
+ let accountIndex = 0;
3329
+ const getNextAccount = () => {
3330
+ const accountMeta = instruction.accounts[accountIndex];
3331
+ accountIndex += 1;
3332
+ return accountMeta;
3333
+ };
3334
+ return {
3335
+ programAddress: instruction.programAddress,
3336
+ accounts: {
3337
+ vault: getNextAccount(),
3338
+ policyAccount: getNextAccount(),
3339
+ signer: getNextAccount(),
3340
+ systemProgram: getNextAccount()
3341
+ },
3342
+ data: getInitializeMultisigInstructionDataDecoder().decode(
3343
+ instruction.data
3344
+ )
3345
+ };
3346
+ }
3347
+ var INITIALIZE_OWNERS_DISCRIMINATOR = new Uint8Array([
3348
+ 145,
3349
+ 41,
3350
+ 103,
3351
+ 101,
3352
+ 229,
3353
+ 205,
3354
+ 135,
3355
+ 157
3356
+ ]);
3357
+ function getInitializeOwnersDiscriminatorBytes() {
3358
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
3359
+ INITIALIZE_OWNERS_DISCRIMINATOR
3360
+ );
3361
+ }
3362
+ function getInitializeOwnersInstructionDataEncoder() {
3363
+ return transformEncoder(
3364
+ getStructEncoder([
3365
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
3366
+ ["owners", getArrayEncoder(getAddressEncoder())]
3367
+ ]),
3368
+ (value) => ({ ...value, discriminator: INITIALIZE_OWNERS_DISCRIMINATOR })
3369
+ );
3370
+ }
3371
+ function getInitializeOwnersInstructionDataDecoder() {
3372
+ return getStructDecoder([
3373
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
3374
+ ["owners", getArrayDecoder(getAddressDecoder())]
3375
+ ]);
3376
+ }
3377
+ function getInitializeOwnersInstructionDataCodec() {
3378
+ return combineCodec(
3379
+ getInitializeOwnersInstructionDataEncoder(),
3380
+ getInitializeOwnersInstructionDataDecoder()
3381
+ );
3382
+ }
3383
+ async function getInitializeOwnersInstructionAsync(input, config2) {
3384
+ const programAddress = config2?.programAddress ?? POLICY_OWNERS_PROGRAM_ADDRESS;
3385
+ const originalAccounts = {
3386
+ vault: { value: input.vault ?? null, isWritable: false },
3387
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
3388
+ signer: { value: input.signer ?? null, isWritable: true },
3389
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false }
3390
+ };
3391
+ const accounts = originalAccounts;
3392
+ const args = { ...input };
3393
+ if (!accounts.policyAccount.value) {
3394
+ accounts.policyAccount.value = await getProgramDerivedAddress({
3395
+ programAddress,
3396
+ seeds: [getAddressEncoder().encode(expectAddress(accounts.vault.value))]
3397
+ });
3398
+ }
3399
+ if (!accounts.systemProgram.value) {
3400
+ accounts.systemProgram.value = "11111111111111111111111111111111";
3401
+ }
3402
+ const getAccountMeta = getAccountMetaFactory(programAddress);
3403
+ const instruction = {
3404
+ accounts: [
3405
+ getAccountMeta(accounts.vault),
3406
+ getAccountMeta(accounts.policyAccount),
3407
+ getAccountMeta(accounts.signer),
3408
+ getAccountMeta(accounts.systemProgram)
3409
+ ],
3410
+ programAddress,
3411
+ data: getInitializeOwnersInstructionDataEncoder().encode(
3412
+ args
3413
+ )
3414
+ };
3415
+ return instruction;
3416
+ }
3417
+ function getInitializeOwnersInstruction(input, config2) {
3418
+ const programAddress = config2?.programAddress ?? POLICY_OWNERS_PROGRAM_ADDRESS;
3419
+ const originalAccounts = {
3420
+ vault: { value: input.vault ?? null, isWritable: false },
3421
+ policyAccount: { value: input.policyAccount ?? null, isWritable: true },
3422
+ signer: { value: input.signer ?? null, isWritable: true },
3423
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false }
3424
+ };
3425
+ const accounts = originalAccounts;
3426
+ const args = { ...input };
3427
+ if (!accounts.systemProgram.value) {
3428
+ accounts.systemProgram.value = "11111111111111111111111111111111";
3429
+ }
3430
+ const getAccountMeta = getAccountMetaFactory(programAddress);
3431
+ const instruction = {
3432
+ accounts: [
3433
+ getAccountMeta(accounts.vault),
3434
+ getAccountMeta(accounts.policyAccount),
3435
+ getAccountMeta(accounts.signer),
3436
+ getAccountMeta(accounts.systemProgram)
3437
+ ],
3438
+ programAddress,
3439
+ data: getInitializeOwnersInstructionDataEncoder().encode(
3440
+ args
3441
+ )
3442
+ };
3443
+ return instruction;
3444
+ }
3445
+ function parseInitializeOwnersInstruction(instruction) {
3446
+ if (instruction.accounts.length < 4) {
3447
+ throw new Error("Not enough accounts");
3448
+ }
3449
+ let accountIndex = 0;
3450
+ const getNextAccount = () => {
3451
+ const accountMeta = instruction.accounts[accountIndex];
3452
+ accountIndex += 1;
3453
+ return accountMeta;
3454
+ };
3455
+ return {
3456
+ programAddress: instruction.programAddress,
3457
+ accounts: {
3458
+ vault: getNextAccount(),
3459
+ policyAccount: getNextAccount(),
3460
+ signer: getNextAccount(),
3461
+ systemProgram: getNextAccount()
3462
+ },
3463
+ data: getInitializeOwnersInstructionDataDecoder().decode(instruction.data)
3464
+ };
3465
+ }
3466
+ function bigIntToSeed(value, byteLength = 8) {
3467
+ const buf = Buffer.alloc(byteLength);
3468
+ buf.writeBigUInt64LE(BigInt(value));
3469
+ return buf;
3470
+ }
3471
+ async function getPda(programAddress, seeds) {
3472
+ const addressEncoder = getAddressEncoder();
3473
+ const seedsUint8Array = seeds.map((seed) => {
3474
+ if (typeof seed === "bigint" || typeof seed === "number") {
3475
+ return bigIntToSeed(BigInt(seed), 8);
3476
+ }
3477
+ try {
3478
+ const encoded = addressEncoder.encode(seed);
3479
+ return encoded;
3480
+ } catch {
3481
+ return new TextEncoder().encode(seed);
3482
+ }
3483
+ });
3484
+ return getProgramDerivedAddress({
3485
+ seeds: seedsUint8Array,
3486
+ programAddress
3487
+ });
3488
+ }
3489
+ async function getVaultPda(seed) {
3490
+ const vault = await getPda(HYRO_PROTOCOL_PROGRAM_ADDRESS, [seed]);
3491
+ const authority = await getPda(HYRO_PROTOCOL_PROGRAM_ADDRESS, [vault[0]]);
3492
+ return [vault, authority];
3493
+ }
3494
+ async function getTransactionPda(vault, nonce) {
3495
+ return getPda(HYRO_PROTOCOL_PROGRAM_ADDRESS, [vault[0], nonce]);
3496
+ }
3497
+ async function getShareSignerPda(vault) {
3498
+ const addressEncoder = getAddressEncoder();
3499
+ return getProgramDerivedAddress({
3500
+ programAddress: HYRO_PROTOCOL_PROGRAM_ADDRESS,
3501
+ seeds: [
3502
+ new Uint8Array([
3503
+ 118,
3504
+ 97,
3505
+ 117,
3506
+ 108,
3507
+ 116,
3508
+ 95,
3509
+ 115,
3510
+ 104,
3511
+ 97,
3512
+ 114,
3513
+ 101,
3514
+ 95,
3515
+ 115,
3516
+ 105,
3517
+ 103,
3518
+ 110,
3519
+ 101,
3520
+ 114
3521
+ ]),
3522
+ addressEncoder.encode(vault[0])
3523
+ ]
3524
+ });
3525
+ }
3526
+ async function getShareMintPda(vault) {
3527
+ const addressEncoder = getAddressEncoder();
3528
+ return getProgramDerivedAddress({
3529
+ programAddress: HYRO_PROTOCOL_PROGRAM_ADDRESS,
3530
+ seeds: [
3531
+ new Uint8Array([
3532
+ 118,
3533
+ 97,
3534
+ 117,
3535
+ 108,
3536
+ 116,
3537
+ 95,
3538
+ 115,
3539
+ 104,
3540
+ 97,
3541
+ 114,
3542
+ 101,
3543
+ 95,
3544
+ 109,
3545
+ 105,
3546
+ 110,
3547
+ 116
3548
+ ]),
3549
+ addressEncoder.encode(vault[0])
3550
+ ]
3551
+ });
3552
+ }
3553
+ async function getVaultTokenAccountPda(vault, underlyingMint) {
3554
+ const addressEncoder = getAddressEncoder();
3555
+ return getProgramDerivedAddress({
3556
+ programAddress: HYRO_PROTOCOL_PROGRAM_ADDRESS,
3557
+ seeds: [
3558
+ new Uint8Array([
3559
+ 118,
3560
+ 97,
3561
+ 117,
3562
+ 108,
3563
+ 116,
3564
+ 95,
3565
+ 116,
3566
+ 111,
3567
+ 107,
3568
+ 101,
3569
+ 110,
3570
+ 95,
3571
+ 97,
3572
+ 99,
3573
+ 99,
3574
+ 111,
3575
+ 117,
3576
+ 110,
3577
+ 116
3578
+ ]),
3579
+ addressEncoder.encode(vault[0]),
3580
+ addressEncoder.encode(underlyingMint)
3581
+ ]
3582
+ });
3583
+ }
3584
+ async function getPolicyAccountPda(vault, policyprogram) {
3585
+ const pda = await getPda(policyprogram, [vault[0]]);
3586
+ return pda[0];
3587
+ }
3588
+
3589
+ // src/sdk/vault.ts
3590
+ var Vault = class {
3591
+ /**
3592
+ * Create a new Vault instance
3593
+ * @param seed - The seed string for the vault
3594
+ * @param signer - The transaction signer
3595
+ * @param policy - The policy type to use for the vault
3596
+ */
3597
+ constructor(seed, signer, policy, params) {
3598
+ this._seed = seed;
3599
+ this._signer = signer;
3600
+ this._policy = policy;
3601
+ this._policyProgram = this.getPolicyProgramAddress(policy);
3602
+ this._params = params;
3603
+ }
3604
+ getPolicyProgramAddress(policy) {
3605
+ switch (policy) {
3606
+ case "AllowAny" /* AllowAny */:
3607
+ return POLICY_ALLOW_ANY_PROGRAM_ADDRESS;
3608
+ case "DenyAll" /* DenyAll */:
3609
+ return POLICY_DENY_ALL_PROGRAM_ADDRESS;
3610
+ case "LimitTransfer" /* LimitTransfer */:
3611
+ return POLICY_LIMIT_TRANSFER_PROGRAM_ADDRESS;
3612
+ case "Owners" /* Owners */:
3613
+ return POLICY_OWNERS_PROGRAM_ADDRESS;
3614
+ case "Multisig" /* Multisig */:
3615
+ return POLICY_MULTISIG_PROGRAM_ADDRESS;
3616
+ }
3617
+ }
3618
+ /**
3619
+ * Initialize the vault (lazy loads PDAs)
3620
+ */
3621
+ async initialize() {
3622
+ if (!this._vaultPda || !this._authorityPda || !this._policyAccount) {
3623
+ [this._vaultPda, this._authorityPda] = await getVaultPda(
3624
+ this._seed
3625
+ );
3626
+ this._policyAccount = await this.getPolicyAccountAddress();
3627
+ }
3628
+ }
3629
+ /**
3630
+ * Get the vault PDA
3631
+ */
3632
+ async getVaultPda() {
3633
+ await this.initialize();
3634
+ return this._vaultPda;
3635
+ }
3636
+ /**
3637
+ * Get the authority PDA
3638
+ */
3639
+ async getAuthorityPda() {
3640
+ await this.initialize();
3641
+ return this._authorityPda;
3642
+ }
3643
+ /**
3644
+ * Get the vault address
3645
+ */
3646
+ async getAddress() {
3647
+ const pda = await this.getVaultPda();
3648
+ return pda[0];
3649
+ }
3650
+ /**
3651
+ * Get the authority address
3652
+ */
3653
+ async getAuthorityAddress() {
3654
+ const pda = await this.getAuthorityPda();
3655
+ return pda[0];
3656
+ }
3657
+ /**
3658
+ * Get share signer PDA
3659
+ */
3660
+ async getShareSignerPda() {
3661
+ const vaultPda = await this.getVaultPda();
3662
+ return getShareSignerPda(vaultPda);
3663
+ }
3664
+ /**
3665
+ * Get share mint PDA
3666
+ */
3667
+ async getShareMintPda() {
3668
+ const vaultPda = await this.getVaultPda();
3669
+ return getShareMintPda(vaultPda);
3670
+ }
3671
+ /**
3672
+ * Get vault token account PDA
3673
+ */
3674
+ async getVaultTokenAccountPda(underlyingMint) {
3675
+ const vaultPda = await this.getVaultPda();
3676
+ return getVaultTokenAccountPda(vaultPda, underlyingMint);
3677
+ }
3678
+ /**
3679
+ * Get transaction PDA for a given nonce
3680
+ */
3681
+ async getTransactionPda(nonce) {
3682
+ const vaultPda = await this.getVaultPda();
3683
+ return getTransactionPda(vaultPda, nonce);
3684
+ }
3685
+ /**
3686
+ * Get policy account address
3687
+ */
3688
+ async getPolicyAccountAddress() {
3689
+ switch (this._policy) {
3690
+ case "AllowAny" /* AllowAny */:
3691
+ return POLICY_ALLOW_ANY_PROGRAM_ADDRESS;
3692
+ case "DenyAll" /* DenyAll */:
3693
+ return POLICY_DENY_ALL_PROGRAM_ADDRESS;
3694
+ case "LimitTransfer" /* LimitTransfer */:
3695
+ return await getPolicyAccountPda(this._vaultPda, POLICY_LIMIT_TRANSFER_PROGRAM_ADDRESS);
3696
+ case "Owners" /* Owners */:
3697
+ return await getPolicyAccountPda(this._vaultPda, POLICY_OWNERS_PROGRAM_ADDRESS);
3698
+ case "Multisig" /* Multisig */:
3699
+ return await getPolicyAccountPda(this._vaultPda, POLICY_MULTISIG_PROGRAM_ADDRESS);
3700
+ default:
3701
+ return POLICY_ALLOW_ANY_PROGRAM_ADDRESS;
3702
+ }
3703
+ }
3704
+ /**
3705
+ * Build initialize vault instruction
3706
+ */
3707
+ async buildInitializeVaultInstruction(params) {
3708
+ await this.initialize();
3709
+ const ixs = [];
3710
+ const shareSignerPda = await this.getShareSignerPda();
3711
+ const shareMintPda = await this.getShareMintPda();
3712
+ const vaultTokenAccountPda = await this.getVaultTokenAccountPda(params.underlyingMint);
3713
+ if (this._policy === "LimitTransfer" /* LimitTransfer */) {
3714
+ ixs.push(await getInitializeLimitTransferInstructionAsync({
3715
+ signer: this._signer,
3716
+ vault: this._vaultPda[0],
3717
+ min: decimal_default(this._params?.min).mul(10 ** 9).floor().toNumber(),
3718
+ max: decimal_default(this._params?.max).mul(10 ** 9).floor().toNumber(),
3719
+ policyAccount: this._policyAccount
3720
+ }));
3721
+ }
3722
+ if (this._policy === "Owners" /* Owners */) {
3723
+ ixs.push(await getInitializeOwnersInstructionAsync({
3724
+ vault: this._vaultPda[0],
3725
+ owners: this._params?.owners,
3726
+ policyAccount: this._policyAccount,
3727
+ signer: this._signer
3728
+ }));
3729
+ }
3730
+ if (this._policy === "Multisig" /* Multisig */) {
3731
+ ixs.push(await getInitializeMultisigInstructionAsync({
3732
+ vault: this._vaultPda[0],
3733
+ owners: this._params?.owners,
3734
+ threshold: this._params?.threshold,
3735
+ policyAccount: this._policyAccount,
3736
+ signer: this._signer
3737
+ }));
3738
+ }
3739
+ ixs.push(await getInitializeVaultInstructionAsync({
3740
+ seed: this._seed,
3741
+ policyProgram: this._policyProgram,
3742
+ underlyingMint: params.underlyingMint,
3743
+ signer: this._signer,
3744
+ vault: this._vaultPda[0],
3745
+ authority: this._authorityPda[0],
3746
+ shareSignerPda: shareSignerPda[0],
3747
+ shareMint: shareMintPda[0],
3748
+ vaultTokenAccount: vaultTokenAccountPda[0]
3749
+ }));
3750
+ return ixs;
3751
+ }
3752
+ /**
3753
+ * Create a transaction from an instruction (high-level method)
3754
+ * Automatically maps accounts and adds required program account
3755
+ */
3756
+ async createTx(instruction) {
3757
+ await this.initialize();
3758
+ const nonce = Math.floor(Math.random() * 1e4) + 1;
3759
+ const vaultPda = this._vaultPda;
3760
+ const authorityPda = this._authorityPda;
3761
+ const transactionPda = await this.getTransactionPda(nonce);
3762
+ if (!instruction.accounts || !instruction.data) {
3763
+ throw new Error("Instruction must have accounts and data");
3764
+ }
3765
+ const accounts = [
3766
+ ...instruction.accounts.map((account) => ({
3767
+ pubkey: account.address,
3768
+ // always false since it is meta tx
3769
+ isSigner: false,
3770
+ isWritable: account.role === AccountRole.WRITABLE || account.role === AccountRole.WRITABLE_SIGNER
3771
+ })),
3772
+ {
3773
+ pubkey: DROPPER_PROGRAM_ADDRESS,
3774
+ isSigner: false,
3775
+ isWritable: false
3776
+ }
3777
+ ];
3778
+ const remainingAccounts = [
3779
+ {
3780
+ address: transactionPda[0],
3781
+ role: AccountRole.READONLY
3782
+ },
3783
+ {
3784
+ address: this._policyAccount,
3785
+ role: AccountRole.READONLY
3786
+ },
3787
+ {
3788
+ address: this._signer.address,
3789
+ role: AccountRole.READONLY
3790
+ },
3791
+ {
3792
+ address: authorityPda[0],
3793
+ role: AccountRole.READONLY
3794
+ }
3795
+ ];
3796
+ const createTxInstruction = await getCreateTxInstructionAsync({
3797
+ vault: vaultPda[0],
3798
+ nonce,
3799
+ pid: DROPPER_PROGRAM_ADDRESS,
3800
+ accs: accounts,
3801
+ data: instruction.data,
3802
+ policyAccount: this._policyAccount || this._policyProgram,
3803
+ policyProgram: this._policyProgram,
3804
+ signer: this._signer,
3805
+ transaction: transactionPda[0],
3806
+ vaultSigner: authorityPda[0]
3807
+ });
3808
+ createTxInstruction.accounts.push(...remainingAccounts);
3809
+ return {
3810
+ ix: createTxInstruction,
3811
+ nonce: typeof nonce === "bigint" ? Number(nonce) : nonce,
3812
+ transferInstruction: instruction
3813
+ };
3814
+ }
3815
+ /**
3816
+ * Execute a transaction (high-level method)
3817
+ * Automatically resolves all required accounts
3818
+ */
3819
+ async executeTx(createOp) {
3820
+ await this.initialize();
3821
+ const vaultPda = this._vaultPda;
3822
+ const authorityPda = this._authorityPda;
3823
+ const transactionPda = await this.getTransactionPda(createOp.nonce);
3824
+ if (!createOp.transferInstruction.accounts) {
3825
+ throw new Error("Original instruction must have accounts");
3826
+ }
3827
+ const remainingAccounts = [
3828
+ {
3829
+ address: transactionPda[0],
3830
+ role: AccountRole.READONLY
3831
+ },
3832
+ {
3833
+ address: this._policyAccount,
3834
+ role: AccountRole.READONLY
3835
+ },
3836
+ {
3837
+ address: this._signer.address,
3838
+ role: AccountRole.READONLY
3839
+ },
3840
+ {
3841
+ address: authorityPda[0],
3842
+ role: AccountRole.READONLY
3843
+ },
3844
+ ...createOp.transferInstruction.accounts.map((account) => ({
3845
+ address: account.address,
3846
+ role: account.role === AccountRole.WRITABLE_SIGNER || account.role === AccountRole.READONLY_SIGNER ? AccountRole.READONLY : account.role
3847
+ })),
3848
+ {
3849
+ address: DROPPER_PROGRAM_ADDRESS,
3850
+ role: AccountRole.READONLY
3851
+ }
3852
+ ];
3853
+ const executeTxInstruction = await getExecuteTxInstructionAsync({
3854
+ vault: vaultPda[0],
3855
+ transaction: transactionPda[0],
3856
+ policyAccount: this._policyAccount || this._policyProgram,
3857
+ policyProgram: this._policyProgram,
3858
+ signer: this._signer,
3859
+ vaultSigner: authorityPda[0]
3860
+ });
3861
+ executeTxInstruction.accounts.push(...remainingAccounts);
3862
+ return {
3863
+ ix: executeTxInstruction,
3864
+ nonce: createOp.nonce
3865
+ };
3866
+ }
3867
+ /**
3868
+ * Fetch vault account data
3869
+ */
3870
+ async fetch(rpc) {
3871
+ const address = await this.getAddress();
3872
+ return fetchVault(rpc, address);
3873
+ }
3874
+ /**
3875
+ * Fetch transaction account data
3876
+ */
3877
+ async fetchTransaction(rpc, nonce) {
3878
+ const transactionPda = await this.getTransactionPda(nonce);
3879
+ return fetchTransaction(rpc, transactionPda[0]);
3880
+ }
3881
+ };
3882
+ /*! Bundled license information:
3883
+
3884
+ decimal.js/decimal.mjs:
3885
+ (*!
3886
+ * decimal.js v10.6.0
3887
+ * An arbitrary-precision Decimal type for JavaScript.
3888
+ * https://github.com/MikeMcl/decimal.js
3889
+ * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
3890
+ * MIT Licence
3891
+ *)
3892
+ */
3893
+
3894
+ export { APPROVE_DISCRIMINATOR, CREATE_TX_DISCRIMINATOR, DROPPER_PROGRAM_ADDRESS, EXECUTE_TX_DISCRIMINATOR, FeeCollectionFrequency, HYRO_PROTOCOL_PROGRAM_ADDRESS, INITIALIZE_LIMIT_TRANSFER_DISCRIMINATOR, INITIALIZE_MULTISIG_DISCRIMINATOR, INITIALIZE_OWNERS_DISCRIMINATOR, INITIALIZE_VAULT_DISCRIMINATOR, POLICY_ALLOW_ANY_PROGRAM_ADDRESS, POLICY_CHALLENGES_PROGRAM_ADDRESS, POLICY_DENY_ALL_PROGRAM_ADDRESS, POLICY_LIMIT_TRANSFER_PROGRAM_ADDRESS, POLICY_MULTISIG_PROGRAM_ADDRESS, POLICY_OWNERS_PROGRAM_ADDRESS, Policy, TRANSFER_LAMPORTS_DISCRIMINATOR, Vault, getApproveDiscriminatorBytes, getApproveInstruction, getApproveInstructionDataCodec, getApproveInstructionDataDecoder, getApproveInstructionDataEncoder, getCreateTxDiscriminatorBytes, getCreateTxInstruction, getCreateTxInstructionAsync, getCreateTxInstructionDataCodec, getCreateTxInstructionDataDecoder, getCreateTxInstructionDataEncoder, getExecuteTxDiscriminatorBytes, getExecuteTxInstruction, getExecuteTxInstructionAsync, getExecuteTxInstructionDataCodec, getExecuteTxInstructionDataDecoder, getExecuteTxInstructionDataEncoder, getFeeCollectionFrequencyCodec, getFeeCollectionFrequencyDecoder, getFeeCollectionFrequencyEncoder, getInitializeLimitTransferDiscriminatorBytes, getInitializeLimitTransferInstruction, getInitializeLimitTransferInstructionAsync, getInitializeLimitTransferInstructionDataCodec, getInitializeLimitTransferInstructionDataDecoder, getInitializeLimitTransferInstructionDataEncoder, getInitializeMultisigDiscriminatorBytes, getInitializeMultisigInstruction, getInitializeMultisigInstructionAsync, getInitializeMultisigInstructionDataCodec, getInitializeMultisigInstructionDataDecoder, getInitializeMultisigInstructionDataEncoder, getInitializeOwnersDiscriminatorBytes, getInitializeOwnersInstruction, getInitializeOwnersInstructionAsync, getInitializeOwnersInstructionDataCodec, getInitializeOwnersInstructionDataDecoder, getInitializeOwnersInstructionDataEncoder, getInitializeVaultDiscriminatorBytes, getInitializeVaultInstruction, getInitializeVaultInstructionAsync, getInitializeVaultInstructionDataCodec, getInitializeVaultInstructionDataDecoder, getInitializeVaultInstructionDataEncoder, getManagerFeeStructureCodec, getManagerFeeStructureDecoder, getManagerFeeStructureEncoder, getPolicyAccountPda, getShareMintPda, getShareSignerPda, getTransactionAccountCodec, getTransactionAccountDecoder, getTransactionAccountEncoder, getTransactionPda, getTransferLamportsDiscriminatorBytes, getTransferLamportsInstruction, getTransferLamportsInstructionDataCodec, getTransferLamportsInstructionDataDecoder, getTransferLamportsInstructionDataEncoder, getVaultPda, getVaultTokenAccountPda, parseApproveInstruction, parseCreateTxInstruction, parseExecuteTxInstruction, parseInitializeLimitTransferInstruction, parseInitializeMultisigInstruction, parseInitializeOwnersInstruction, parseInitializeVaultInstruction, parseTransferLamportsInstruction };
3895
+ //# sourceMappingURL=index.mjs.map
3896
+ //# sourceMappingURL=index.mjs.map