graz 0.0.45-alpha.1 → 0.0.45

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.js CHANGED
@@ -1,3046 +1 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
-
33
- // ../../node_modules/.pnpm/long@4.0.0/node_modules/long/src/long.js
34
- var require_long = __commonJS({
35
- "../../node_modules/.pnpm/long@4.0.0/node_modules/long/src/long.js"(exports, module2) {
36
- "use strict";
37
- module2.exports = Long2;
38
- var wasm = null;
39
- try {
40
- wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
41
- 0,
42
- 97,
43
- 115,
44
- 109,
45
- 1,
46
- 0,
47
- 0,
48
- 0,
49
- 1,
50
- 13,
51
- 2,
52
- 96,
53
- 0,
54
- 1,
55
- 127,
56
- 96,
57
- 4,
58
- 127,
59
- 127,
60
- 127,
61
- 127,
62
- 1,
63
- 127,
64
- 3,
65
- 7,
66
- 6,
67
- 0,
68
- 1,
69
- 1,
70
- 1,
71
- 1,
72
- 1,
73
- 6,
74
- 6,
75
- 1,
76
- 127,
77
- 1,
78
- 65,
79
- 0,
80
- 11,
81
- 7,
82
- 50,
83
- 6,
84
- 3,
85
- 109,
86
- 117,
87
- 108,
88
- 0,
89
- 1,
90
- 5,
91
- 100,
92
- 105,
93
- 118,
94
- 95,
95
- 115,
96
- 0,
97
- 2,
98
- 5,
99
- 100,
100
- 105,
101
- 118,
102
- 95,
103
- 117,
104
- 0,
105
- 3,
106
- 5,
107
- 114,
108
- 101,
109
- 109,
110
- 95,
111
- 115,
112
- 0,
113
- 4,
114
- 5,
115
- 114,
116
- 101,
117
- 109,
118
- 95,
119
- 117,
120
- 0,
121
- 5,
122
- 8,
123
- 103,
124
- 101,
125
- 116,
126
- 95,
127
- 104,
128
- 105,
129
- 103,
130
- 104,
131
- 0,
132
- 0,
133
- 10,
134
- 191,
135
- 1,
136
- 6,
137
- 4,
138
- 0,
139
- 35,
140
- 0,
141
- 11,
142
- 36,
143
- 1,
144
- 1,
145
- 126,
146
- 32,
147
- 0,
148
- 173,
149
- 32,
150
- 1,
151
- 173,
152
- 66,
153
- 32,
154
- 134,
155
- 132,
156
- 32,
157
- 2,
158
- 173,
159
- 32,
160
- 3,
161
- 173,
162
- 66,
163
- 32,
164
- 134,
165
- 132,
166
- 126,
167
- 34,
168
- 4,
169
- 66,
170
- 32,
171
- 135,
172
- 167,
173
- 36,
174
- 0,
175
- 32,
176
- 4,
177
- 167,
178
- 11,
179
- 36,
180
- 1,
181
- 1,
182
- 126,
183
- 32,
184
- 0,
185
- 173,
186
- 32,
187
- 1,
188
- 173,
189
- 66,
190
- 32,
191
- 134,
192
- 132,
193
- 32,
194
- 2,
195
- 173,
196
- 32,
197
- 3,
198
- 173,
199
- 66,
200
- 32,
201
- 134,
202
- 132,
203
- 127,
204
- 34,
205
- 4,
206
- 66,
207
- 32,
208
- 135,
209
- 167,
210
- 36,
211
- 0,
212
- 32,
213
- 4,
214
- 167,
215
- 11,
216
- 36,
217
- 1,
218
- 1,
219
- 126,
220
- 32,
221
- 0,
222
- 173,
223
- 32,
224
- 1,
225
- 173,
226
- 66,
227
- 32,
228
- 134,
229
- 132,
230
- 32,
231
- 2,
232
- 173,
233
- 32,
234
- 3,
235
- 173,
236
- 66,
237
- 32,
238
- 134,
239
- 132,
240
- 128,
241
- 34,
242
- 4,
243
- 66,
244
- 32,
245
- 135,
246
- 167,
247
- 36,
248
- 0,
249
- 32,
250
- 4,
251
- 167,
252
- 11,
253
- 36,
254
- 1,
255
- 1,
256
- 126,
257
- 32,
258
- 0,
259
- 173,
260
- 32,
261
- 1,
262
- 173,
263
- 66,
264
- 32,
265
- 134,
266
- 132,
267
- 32,
268
- 2,
269
- 173,
270
- 32,
271
- 3,
272
- 173,
273
- 66,
274
- 32,
275
- 134,
276
- 132,
277
- 129,
278
- 34,
279
- 4,
280
- 66,
281
- 32,
282
- 135,
283
- 167,
284
- 36,
285
- 0,
286
- 32,
287
- 4,
288
- 167,
289
- 11,
290
- 36,
291
- 1,
292
- 1,
293
- 126,
294
- 32,
295
- 0,
296
- 173,
297
- 32,
298
- 1,
299
- 173,
300
- 66,
301
- 32,
302
- 134,
303
- 132,
304
- 32,
305
- 2,
306
- 173,
307
- 32,
308
- 3,
309
- 173,
310
- 66,
311
- 32,
312
- 134,
313
- 132,
314
- 130,
315
- 34,
316
- 4,
317
- 66,
318
- 32,
319
- 135,
320
- 167,
321
- 36,
322
- 0,
323
- 32,
324
- 4,
325
- 167,
326
- 11
327
- ])), {}).exports;
328
- } catch (e) {
329
- }
330
- function Long2(low, high, unsigned) {
331
- this.low = low | 0;
332
- this.high = high | 0;
333
- this.unsigned = !!unsigned;
334
- }
335
- Long2.prototype.__isLong__;
336
- Object.defineProperty(Long2.prototype, "__isLong__", { value: true });
337
- function isLong(obj) {
338
- return (obj && obj["__isLong__"]) === true;
339
- }
340
- Long2.isLong = isLong;
341
- var INT_CACHE = {};
342
- var UINT_CACHE = {};
343
- function fromInt(value, unsigned) {
344
- var obj, cachedObj, cache;
345
- if (unsigned) {
346
- value >>>= 0;
347
- if (cache = 0 <= value && value < 256) {
348
- cachedObj = UINT_CACHE[value];
349
- if (cachedObj)
350
- return cachedObj;
351
- }
352
- obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true);
353
- if (cache)
354
- UINT_CACHE[value] = obj;
355
- return obj;
356
- } else {
357
- value |= 0;
358
- if (cache = -128 <= value && value < 128) {
359
- cachedObj = INT_CACHE[value];
360
- if (cachedObj)
361
- return cachedObj;
362
- }
363
- obj = fromBits(value, value < 0 ? -1 : 0, false);
364
- if (cache)
365
- INT_CACHE[value] = obj;
366
- return obj;
367
- }
368
- }
369
- Long2.fromInt = fromInt;
370
- function fromNumber(value, unsigned) {
371
- if (isNaN(value))
372
- return unsigned ? UZERO : ZERO;
373
- if (unsigned) {
374
- if (value < 0)
375
- return UZERO;
376
- if (value >= TWO_PWR_64_DBL)
377
- return MAX_UNSIGNED_VALUE;
378
- } else {
379
- if (value <= -TWO_PWR_63_DBL)
380
- return MIN_VALUE;
381
- if (value + 1 >= TWO_PWR_63_DBL)
382
- return MAX_VALUE;
383
- }
384
- if (value < 0)
385
- return fromNumber(-value, unsigned).neg();
386
- return fromBits(value % TWO_PWR_32_DBL | 0, value / TWO_PWR_32_DBL | 0, unsigned);
387
- }
388
- Long2.fromNumber = fromNumber;
389
- function fromBits(lowBits, highBits, unsigned) {
390
- return new Long2(lowBits, highBits, unsigned);
391
- }
392
- Long2.fromBits = fromBits;
393
- var pow_dbl = Math.pow;
394
- function fromString(str, unsigned, radix) {
395
- if (str.length === 0)
396
- throw Error("empty string");
397
- if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
398
- return ZERO;
399
- if (typeof unsigned === "number") {
400
- radix = unsigned, unsigned = false;
401
- } else {
402
- unsigned = !!unsigned;
403
- }
404
- radix = radix || 10;
405
- if (radix < 2 || 36 < radix)
406
- throw RangeError("radix");
407
- var p;
408
- if ((p = str.indexOf("-")) > 0)
409
- throw Error("interior hyphen");
410
- else if (p === 0) {
411
- return fromString(str.substring(1), unsigned, radix).neg();
412
- }
413
- var radixToPower = fromNumber(pow_dbl(radix, 8));
414
- var result = ZERO;
415
- for (var i = 0; i < str.length; i += 8) {
416
- var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
417
- if (size < 8) {
418
- var power = fromNumber(pow_dbl(radix, size));
419
- result = result.mul(power).add(fromNumber(value));
420
- } else {
421
- result = result.mul(radixToPower);
422
- result = result.add(fromNumber(value));
423
- }
424
- }
425
- result.unsigned = unsigned;
426
- return result;
427
- }
428
- Long2.fromString = fromString;
429
- function fromValue(val, unsigned) {
430
- if (typeof val === "number")
431
- return fromNumber(val, unsigned);
432
- if (typeof val === "string")
433
- return fromString(val, unsigned);
434
- return fromBits(val.low, val.high, typeof unsigned === "boolean" ? unsigned : val.unsigned);
435
- }
436
- Long2.fromValue = fromValue;
437
- var TWO_PWR_16_DBL = 1 << 16;
438
- var TWO_PWR_24_DBL = 1 << 24;
439
- var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
440
- var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
441
- var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
442
- var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
443
- var ZERO = fromInt(0);
444
- Long2.ZERO = ZERO;
445
- var UZERO = fromInt(0, true);
446
- Long2.UZERO = UZERO;
447
- var ONE = fromInt(1);
448
- Long2.ONE = ONE;
449
- var UONE = fromInt(1, true);
450
- Long2.UONE = UONE;
451
- var NEG_ONE = fromInt(-1);
452
- Long2.NEG_ONE = NEG_ONE;
453
- var MAX_VALUE = fromBits(4294967295 | 0, 2147483647 | 0, false);
454
- Long2.MAX_VALUE = MAX_VALUE;
455
- var MAX_UNSIGNED_VALUE = fromBits(4294967295 | 0, 4294967295 | 0, true);
456
- Long2.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
457
- var MIN_VALUE = fromBits(0, 2147483648 | 0, false);
458
- Long2.MIN_VALUE = MIN_VALUE;
459
- var LongPrototype = Long2.prototype;
460
- LongPrototype.toInt = function toInt() {
461
- return this.unsigned ? this.low >>> 0 : this.low;
462
- };
463
- LongPrototype.toNumber = function toNumber() {
464
- if (this.unsigned)
465
- return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
466
- return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
467
- };
468
- LongPrototype.toString = function toString(radix) {
469
- radix = radix || 10;
470
- if (radix < 2 || 36 < radix)
471
- throw RangeError("radix");
472
- if (this.isZero())
473
- return "0";
474
- if (this.isNegative()) {
475
- if (this.eq(MIN_VALUE)) {
476
- var radixLong = fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
477
- return div.toString(radix) + rem1.toInt().toString(radix);
478
- } else
479
- return "-" + this.neg().toString(radix);
480
- }
481
- var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), rem = this;
482
- var result = "";
483
- while (true) {
484
- var remDiv = rem.div(radixToPower), intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, digits = intval.toString(radix);
485
- rem = remDiv;
486
- if (rem.isZero())
487
- return digits + result;
488
- else {
489
- while (digits.length < 6)
490
- digits = "0" + digits;
491
- result = "" + digits + result;
492
- }
493
- }
494
- };
495
- LongPrototype.getHighBits = function getHighBits() {
496
- return this.high;
497
- };
498
- LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
499
- return this.high >>> 0;
500
- };
501
- LongPrototype.getLowBits = function getLowBits() {
502
- return this.low;
503
- };
504
- LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
505
- return this.low >>> 0;
506
- };
507
- LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
508
- if (this.isNegative())
509
- return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
510
- var val = this.high != 0 ? this.high : this.low;
511
- for (var bit = 31; bit > 0; bit--)
512
- if ((val & 1 << bit) != 0)
513
- break;
514
- return this.high != 0 ? bit + 33 : bit + 1;
515
- };
516
- LongPrototype.isZero = function isZero() {
517
- return this.high === 0 && this.low === 0;
518
- };
519
- LongPrototype.eqz = LongPrototype.isZero;
520
- LongPrototype.isNegative = function isNegative() {
521
- return !this.unsigned && this.high < 0;
522
- };
523
- LongPrototype.isPositive = function isPositive() {
524
- return this.unsigned || this.high >= 0;
525
- };
526
- LongPrototype.isOdd = function isOdd() {
527
- return (this.low & 1) === 1;
528
- };
529
- LongPrototype.isEven = function isEven() {
530
- return (this.low & 1) === 0;
531
- };
532
- LongPrototype.equals = function equals(other) {
533
- if (!isLong(other))
534
- other = fromValue(other);
535
- if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
536
- return false;
537
- return this.high === other.high && this.low === other.low;
538
- };
539
- LongPrototype.eq = LongPrototype.equals;
540
- LongPrototype.notEquals = function notEquals(other) {
541
- return !this.eq(
542
- /* validates */
543
- other
544
- );
545
- };
546
- LongPrototype.neq = LongPrototype.notEquals;
547
- LongPrototype.ne = LongPrototype.notEquals;
548
- LongPrototype.lessThan = function lessThan(other) {
549
- return this.comp(
550
- /* validates */
551
- other
552
- ) < 0;
553
- };
554
- LongPrototype.lt = LongPrototype.lessThan;
555
- LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
556
- return this.comp(
557
- /* validates */
558
- other
559
- ) <= 0;
560
- };
561
- LongPrototype.lte = LongPrototype.lessThanOrEqual;
562
- LongPrototype.le = LongPrototype.lessThanOrEqual;
563
- LongPrototype.greaterThan = function greaterThan(other) {
564
- return this.comp(
565
- /* validates */
566
- other
567
- ) > 0;
568
- };
569
- LongPrototype.gt = LongPrototype.greaterThan;
570
- LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
571
- return this.comp(
572
- /* validates */
573
- other
574
- ) >= 0;
575
- };
576
- LongPrototype.gte = LongPrototype.greaterThanOrEqual;
577
- LongPrototype.ge = LongPrototype.greaterThanOrEqual;
578
- LongPrototype.compare = function compare(other) {
579
- if (!isLong(other))
580
- other = fromValue(other);
581
- if (this.eq(other))
582
- return 0;
583
- var thisNeg = this.isNegative(), otherNeg = other.isNegative();
584
- if (thisNeg && !otherNeg)
585
- return -1;
586
- if (!thisNeg && otherNeg)
587
- return 1;
588
- if (!this.unsigned)
589
- return this.sub(other).isNegative() ? -1 : 1;
590
- return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
591
- };
592
- LongPrototype.comp = LongPrototype.compare;
593
- LongPrototype.negate = function negate() {
594
- if (!this.unsigned && this.eq(MIN_VALUE))
595
- return MIN_VALUE;
596
- return this.not().add(ONE);
597
- };
598
- LongPrototype.neg = LongPrototype.negate;
599
- LongPrototype.add = function add(addend) {
600
- if (!isLong(addend))
601
- addend = fromValue(addend);
602
- var a48 = this.high >>> 16;
603
- var a32 = this.high & 65535;
604
- var a16 = this.low >>> 16;
605
- var a00 = this.low & 65535;
606
- var b48 = addend.high >>> 16;
607
- var b32 = addend.high & 65535;
608
- var b16 = addend.low >>> 16;
609
- var b00 = addend.low & 65535;
610
- var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
611
- c00 += a00 + b00;
612
- c16 += c00 >>> 16;
613
- c00 &= 65535;
614
- c16 += a16 + b16;
615
- c32 += c16 >>> 16;
616
- c16 &= 65535;
617
- c32 += a32 + b32;
618
- c48 += c32 >>> 16;
619
- c32 &= 65535;
620
- c48 += a48 + b48;
621
- c48 &= 65535;
622
- return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
623
- };
624
- LongPrototype.subtract = function subtract(subtrahend) {
625
- if (!isLong(subtrahend))
626
- subtrahend = fromValue(subtrahend);
627
- return this.add(subtrahend.neg());
628
- };
629
- LongPrototype.sub = LongPrototype.subtract;
630
- LongPrototype.multiply = function multiply(multiplier) {
631
- if (this.isZero())
632
- return ZERO;
633
- if (!isLong(multiplier))
634
- multiplier = fromValue(multiplier);
635
- if (wasm) {
636
- var low = wasm.mul(
637
- this.low,
638
- this.high,
639
- multiplier.low,
640
- multiplier.high
641
- );
642
- return fromBits(low, wasm.get_high(), this.unsigned);
643
- }
644
- if (multiplier.isZero())
645
- return ZERO;
646
- if (this.eq(MIN_VALUE))
647
- return multiplier.isOdd() ? MIN_VALUE : ZERO;
648
- if (multiplier.eq(MIN_VALUE))
649
- return this.isOdd() ? MIN_VALUE : ZERO;
650
- if (this.isNegative()) {
651
- if (multiplier.isNegative())
652
- return this.neg().mul(multiplier.neg());
653
- else
654
- return this.neg().mul(multiplier).neg();
655
- } else if (multiplier.isNegative())
656
- return this.mul(multiplier.neg()).neg();
657
- if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
658
- return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
659
- var a48 = this.high >>> 16;
660
- var a32 = this.high & 65535;
661
- var a16 = this.low >>> 16;
662
- var a00 = this.low & 65535;
663
- var b48 = multiplier.high >>> 16;
664
- var b32 = multiplier.high & 65535;
665
- var b16 = multiplier.low >>> 16;
666
- var b00 = multiplier.low & 65535;
667
- var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
668
- c00 += a00 * b00;
669
- c16 += c00 >>> 16;
670
- c00 &= 65535;
671
- c16 += a16 * b00;
672
- c32 += c16 >>> 16;
673
- c16 &= 65535;
674
- c16 += a00 * b16;
675
- c32 += c16 >>> 16;
676
- c16 &= 65535;
677
- c32 += a32 * b00;
678
- c48 += c32 >>> 16;
679
- c32 &= 65535;
680
- c32 += a16 * b16;
681
- c48 += c32 >>> 16;
682
- c32 &= 65535;
683
- c32 += a00 * b32;
684
- c48 += c32 >>> 16;
685
- c32 &= 65535;
686
- c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
687
- c48 &= 65535;
688
- return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
689
- };
690
- LongPrototype.mul = LongPrototype.multiply;
691
- LongPrototype.divide = function divide(divisor) {
692
- if (!isLong(divisor))
693
- divisor = fromValue(divisor);
694
- if (divisor.isZero())
695
- throw Error("division by zero");
696
- if (wasm) {
697
- if (!this.unsigned && this.high === -2147483648 && divisor.low === -1 && divisor.high === -1) {
698
- return this;
699
- }
700
- var low = (this.unsigned ? wasm.div_u : wasm.div_s)(
701
- this.low,
702
- this.high,
703
- divisor.low,
704
- divisor.high
705
- );
706
- return fromBits(low, wasm.get_high(), this.unsigned);
707
- }
708
- if (this.isZero())
709
- return this.unsigned ? UZERO : ZERO;
710
- var approx, rem, res;
711
- if (!this.unsigned) {
712
- if (this.eq(MIN_VALUE)) {
713
- if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
714
- return MIN_VALUE;
715
- else if (divisor.eq(MIN_VALUE))
716
- return ONE;
717
- else {
718
- var halfThis = this.shr(1);
719
- approx = halfThis.div(divisor).shl(1);
720
- if (approx.eq(ZERO)) {
721
- return divisor.isNegative() ? ONE : NEG_ONE;
722
- } else {
723
- rem = this.sub(divisor.mul(approx));
724
- res = approx.add(rem.div(divisor));
725
- return res;
726
- }
727
- }
728
- } else if (divisor.eq(MIN_VALUE))
729
- return this.unsigned ? UZERO : ZERO;
730
- if (this.isNegative()) {
731
- if (divisor.isNegative())
732
- return this.neg().div(divisor.neg());
733
- return this.neg().div(divisor).neg();
734
- } else if (divisor.isNegative())
735
- return this.div(divisor.neg()).neg();
736
- res = ZERO;
737
- } else {
738
- if (!divisor.unsigned)
739
- divisor = divisor.toUnsigned();
740
- if (divisor.gt(this))
741
- return UZERO;
742
- if (divisor.gt(this.shru(1)))
743
- return UONE;
744
- res = UZERO;
745
- }
746
- rem = this;
747
- while (rem.gte(divisor)) {
748
- approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
749
- var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = log2 <= 48 ? 1 : pow_dbl(2, log2 - 48), approxRes = fromNumber(approx), approxRem = approxRes.mul(divisor);
750
- while (approxRem.isNegative() || approxRem.gt(rem)) {
751
- approx -= delta;
752
- approxRes = fromNumber(approx, this.unsigned);
753
- approxRem = approxRes.mul(divisor);
754
- }
755
- if (approxRes.isZero())
756
- approxRes = ONE;
757
- res = res.add(approxRes);
758
- rem = rem.sub(approxRem);
759
- }
760
- return res;
761
- };
762
- LongPrototype.div = LongPrototype.divide;
763
- LongPrototype.modulo = function modulo(divisor) {
764
- if (!isLong(divisor))
765
- divisor = fromValue(divisor);
766
- if (wasm) {
767
- var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(
768
- this.low,
769
- this.high,
770
- divisor.low,
771
- divisor.high
772
- );
773
- return fromBits(low, wasm.get_high(), this.unsigned);
774
- }
775
- return this.sub(this.div(divisor).mul(divisor));
776
- };
777
- LongPrototype.mod = LongPrototype.modulo;
778
- LongPrototype.rem = LongPrototype.modulo;
779
- LongPrototype.not = function not() {
780
- return fromBits(~this.low, ~this.high, this.unsigned);
781
- };
782
- LongPrototype.and = function and(other) {
783
- if (!isLong(other))
784
- other = fromValue(other);
785
- return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
786
- };
787
- LongPrototype.or = function or(other) {
788
- if (!isLong(other))
789
- other = fromValue(other);
790
- return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
791
- };
792
- LongPrototype.xor = function xor(other) {
793
- if (!isLong(other))
794
- other = fromValue(other);
795
- return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
796
- };
797
- LongPrototype.shiftLeft = function shiftLeft(numBits) {
798
- if (isLong(numBits))
799
- numBits = numBits.toInt();
800
- if ((numBits &= 63) === 0)
801
- return this;
802
- else if (numBits < 32)
803
- return fromBits(this.low << numBits, this.high << numBits | this.low >>> 32 - numBits, this.unsigned);
804
- else
805
- return fromBits(0, this.low << numBits - 32, this.unsigned);
806
- };
807
- LongPrototype.shl = LongPrototype.shiftLeft;
808
- LongPrototype.shiftRight = function shiftRight(numBits) {
809
- if (isLong(numBits))
810
- numBits = numBits.toInt();
811
- if ((numBits &= 63) === 0)
812
- return this;
813
- else if (numBits < 32)
814
- return fromBits(this.low >>> numBits | this.high << 32 - numBits, this.high >> numBits, this.unsigned);
815
- else
816
- return fromBits(this.high >> numBits - 32, this.high >= 0 ? 0 : -1, this.unsigned);
817
- };
818
- LongPrototype.shr = LongPrototype.shiftRight;
819
- LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
820
- if (isLong(numBits))
821
- numBits = numBits.toInt();
822
- numBits &= 63;
823
- if (numBits === 0)
824
- return this;
825
- else {
826
- var high = this.high;
827
- if (numBits < 32) {
828
- var low = this.low;
829
- return fromBits(low >>> numBits | high << 32 - numBits, high >>> numBits, this.unsigned);
830
- } else if (numBits === 32)
831
- return fromBits(high, 0, this.unsigned);
832
- else
833
- return fromBits(high >>> numBits - 32, 0, this.unsigned);
834
- }
835
- };
836
- LongPrototype.shru = LongPrototype.shiftRightUnsigned;
837
- LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
838
- LongPrototype.toSigned = function toSigned() {
839
- if (!this.unsigned)
840
- return this;
841
- return fromBits(this.low, this.high, false);
842
- };
843
- LongPrototype.toUnsigned = function toUnsigned() {
844
- if (this.unsigned)
845
- return this;
846
- return fromBits(this.low, this.high, true);
847
- };
848
- LongPrototype.toBytes = function toBytes(le) {
849
- return le ? this.toBytesLE() : this.toBytesBE();
850
- };
851
- LongPrototype.toBytesLE = function toBytesLE() {
852
- var hi = this.high, lo = this.low;
853
- return [
854
- lo & 255,
855
- lo >>> 8 & 255,
856
- lo >>> 16 & 255,
857
- lo >>> 24,
858
- hi & 255,
859
- hi >>> 8 & 255,
860
- hi >>> 16 & 255,
861
- hi >>> 24
862
- ];
863
- };
864
- LongPrototype.toBytesBE = function toBytesBE() {
865
- var hi = this.high, lo = this.low;
866
- return [
867
- hi >>> 24,
868
- hi >>> 16 & 255,
869
- hi >>> 8 & 255,
870
- hi & 255,
871
- lo >>> 24,
872
- lo >>> 16 & 255,
873
- lo >>> 8 & 255,
874
- lo & 255
875
- ];
876
- };
877
- Long2.fromBytes = function fromBytes(bytes, unsigned, le) {
878
- return le ? Long2.fromBytesLE(bytes, unsigned) : Long2.fromBytesBE(bytes, unsigned);
879
- };
880
- Long2.fromBytesLE = function fromBytesLE(bytes, unsigned) {
881
- return new Long2(
882
- bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24,
883
- bytes[4] | bytes[5] << 8 | bytes[6] << 16 | bytes[7] << 24,
884
- unsigned
885
- );
886
- };
887
- Long2.fromBytesBE = function fromBytesBE(bytes, unsigned) {
888
- return new Long2(
889
- bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7],
890
- bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3],
891
- unsigned
892
- );
893
- };
894
- }
895
- });
896
-
897
- // src/index.ts
898
- var src_exports = {};
899
- __export(src_exports, {
900
- GrazEvents: () => GrazEvents,
901
- GrazProvider: () => GrazProvider,
902
- WALLET_TYPES: () => WALLET_TYPES,
903
- WalletType: () => WalletType,
904
- checkWallet: () => checkWallet,
905
- clearRecentChain: () => clearRecentChain,
906
- configureGraz: () => configureGraz,
907
- connect: () => connect,
908
- connectClient: () => connectClient,
909
- connectSigningClient: () => connectSigningClient,
910
- defineChain: () => defineChain,
911
- defineChainInfo: () => defineChainInfo,
912
- defineChains: () => defineChains,
913
- disconnect: () => disconnect,
914
- executeContract: () => executeContract,
915
- getAvailableWallets: () => getAvailableWallets,
916
- getBalanceStaked: () => getBalanceStaked,
917
- getBalances: () => getBalances,
918
- getCosmostation: () => getCosmostation,
919
- getKeplr: () => getKeplr,
920
- getLeap: () => getLeap,
921
- getOfflineSigners: () => getOfflineSigners,
922
- getQueryRaw: () => getQueryRaw,
923
- getQuerySmart: () => getQuerySmart,
924
- getRecentChains: () => getRecentChains,
925
- getVectis: () => getVectis,
926
- getWCCosmostation: () => getWCCosmostation,
927
- getWCKeplr: () => getWCKeplr,
928
- getWCLeap: () => getWCLeap,
929
- getWallet: () => getWallet,
930
- getWalletConnect: () => getWalletConnect,
931
- instantiateContract: () => instantiateContract,
932
- mainnetChains: () => mainnetChains,
933
- mainnetChainsArray: () => mainnetChainsArray,
934
- reconnect: () => reconnect,
935
- sendIbcTokens: () => sendIbcTokens,
936
- sendTokens: () => sendTokens,
937
- suggestChain: () => suggestChain,
938
- suggestChainAndConnect: () => suggestChainAndConnect,
939
- testnetChains: () => testnetChains,
940
- testnetChainsArray: () => testnetChainsArray,
941
- useAccount: () => useAccount,
942
- useActiveChainValidators: () => useActiveChainValidators,
943
- useActiveWalletType: () => useActiveWalletType,
944
- useBalanceStaked: () => useBalanceStaked,
945
- useBalances: () => useBalances,
946
- useCheckWallet: () => useCheckWallet,
947
- useConnect: () => useConnect,
948
- useConnectClient: () => useConnectClient,
949
- useConnectSigningClient: () => useConnectSigningClient,
950
- useDisconnect: () => useDisconnect,
951
- useGrazEvents: () => useGrazEvents,
952
- useOfflineSigners: () => useOfflineSigners,
953
- useRecentChain: () => useRecentChain,
954
- useSendTokens: () => useSendTokens,
955
- useSuggestChain: () => useSuggestChain,
956
- useSuggestChainAndConnect: () => useSuggestChainAndConnect
957
- });
958
- module.exports = __toCommonJS(src_exports);
959
-
960
- // src/constant.ts
961
- var RECONNECT_SESSION_KEY = "graz-reconnect-session";
962
-
963
- // src/store/index.ts
964
- var import_zustand = require("zustand");
965
- var import_middleware = require("zustand/middleware");
966
- var import_middleware2 = require("zustand/middleware");
967
-
968
- // src/types/wallet.ts
969
- var WalletType = /* @__PURE__ */ ((WalletType2) => {
970
- WalletType2["KEPLR"] = "keplr";
971
- WalletType2["LEAP"] = "leap";
972
- WalletType2["VECTIS"] = "vectis";
973
- WalletType2["COSMOSTATION"] = "cosmostation";
974
- WalletType2["WALLETCONNECT"] = "walletconnect";
975
- WalletType2["WC_KEPLR_MOBILE"] = "wc_keplr_mobile";
976
- WalletType2["WC_LEAP_MOBILE"] = "wc_leap_mobile";
977
- WalletType2["WC_COSMOSTATION_MOBILE"] = "wc_cosmostation_mobile";
978
- return WalletType2;
979
- })(WalletType || {});
980
- var WALLET_TYPES = [
981
- "keplr" /* KEPLR */,
982
- "leap" /* LEAP */,
983
- "vectis" /* VECTIS */,
984
- "cosmostation" /* COSMOSTATION */,
985
- "walletconnect" /* WALLETCONNECT */,
986
- "wc_keplr_mobile" /* WC_KEPLR_MOBILE */,
987
- "wc_leap_mobile" /* WC_LEAP_MOBILE */,
988
- "wc_cosmostation_mobile" /* WC_COSMOSTATION_MOBILE */
989
- ];
990
-
991
- // src/store/index.ts
992
- var grazInternalDefaultValues = {
993
- chains: null,
994
- recentChains: null,
995
- defaultClient: "stargate",
996
- defaultSigningClient: "stargate",
997
- walletType: "keplr" /* KEPLR */,
998
- walletConnect: {
999
- options: null,
1000
- web3Modal: null
1001
- },
1002
- _notFoundFn: () => null,
1003
- _onReconnectFailed: () => null,
1004
- _reconnect: false,
1005
- _reconnectConnector: null
1006
- };
1007
- var grazSessionDefaultValues = {
1008
- sessions: null,
1009
- wcSignClient: null
1010
- };
1011
- var sessionOptions = {
1012
- name: "graz-session",
1013
- version: 2,
1014
- partialize: (x) => ({
1015
- sessions: x.sessions
1016
- }),
1017
- storage: (0, import_middleware.createJSONStorage)(() => sessionStorage)
1018
- };
1019
- var persistOptions = {
1020
- name: "graz-internal",
1021
- partialize: (x) => ({
1022
- recentChains: x.recentChains,
1023
- _reconnect: x._reconnect,
1024
- _reconnectConnector: x._reconnectConnector
1025
- }),
1026
- version: 2
1027
- };
1028
- var useGrazSessionStore = (0, import_zustand.create)(
1029
- (0, import_middleware2.subscribeWithSelector)((0, import_middleware2.persist)(() => grazSessionDefaultValues, sessionOptions))
1030
- );
1031
- var useGrazInternalStore = (0, import_zustand.create)(
1032
- (0, import_middleware2.subscribeWithSelector)((0, import_middleware2.persist)(() => grazInternalDefaultValues, persistOptions))
1033
- );
1034
-
1035
- // src/utils/mergeSessions.ts
1036
- var mergeSessions = ({ prev, next }) => {
1037
- if (!prev)
1038
- return next;
1039
- const prevKeys = prev.map((v) => v.chainId);
1040
- const nextKeys = next.map((v) => v.chainId);
1041
- const keys = [...prevKeys, ...nextKeys].filter((item, i, ar) => ar.indexOf(item) === i);
1042
- const result = keys.map((key) => {
1043
- const prevValue = prev.find((v) => v.chainId === key);
1044
- const nextValue = next.find((v) => v.chainId === key);
1045
- const value = nextValue || prevValue;
1046
- return {
1047
- ...value,
1048
- chainId: key
1049
- };
1050
- });
1051
- return result;
1052
- };
1053
-
1054
- // src/actions/wallet.ts
1055
- var import_encoding = require("@cosmjs/encoding");
1056
- var import_sign_client = require("@walletconnect/sign-client");
1057
- var import_utils = require("@walletconnect/utils");
1058
- var import_long = __toESM(require_long());
1059
-
1060
- // src/utils/os.ts
1061
- var isMobile = () => {
1062
- if (typeof window !== "undefined") {
1063
- return Boolean(
1064
- window.matchMedia("(pointer:coarse)").matches || /Android|webOS|iPhone|iPad|iPod|BlackBerry|Opera Mini/u.test(navigator.userAgent)
1065
- );
1066
- }
1067
- return false;
1068
- };
1069
- var isAndroid = () => {
1070
- return isMobile() && navigator.userAgent.toLowerCase().includes("android");
1071
- };
1072
- var isIos = () => {
1073
- return isMobile() && (navigator.userAgent.toLowerCase().includes("iphone") || navigator.userAgent.toLowerCase().includes("ipad"));
1074
- };
1075
-
1076
- // src/utils/timeout.ts
1077
- var promiseWithTimeout = (promise, ms, timeoutError = new Error("Promise timed out")) => {
1078
- const timeout = new Promise((_, reject) => {
1079
- setTimeout(() => {
1080
- reject(timeoutError);
1081
- }, ms);
1082
- });
1083
- return Promise.race([promise, timeout]);
1084
- };
1085
-
1086
- // src/actions/wallet.ts
1087
- var checkWallet = (type = useGrazInternalStore.getState().walletType) => {
1088
- try {
1089
- getWallet(type);
1090
- return true;
1091
- } catch (error) {
1092
- return false;
1093
- }
1094
- };
1095
- var clearSession = () => {
1096
- window.sessionStorage.removeItem(RECONNECT_SESSION_KEY);
1097
- useGrazSessionStore.setState(grazSessionDefaultValues);
1098
- };
1099
- var getKeplr = () => {
1100
- if (typeof window.keplr !== "undefined") {
1101
- const keplr = window.keplr;
1102
- const subscription = (reconnect2) => {
1103
- window.addEventListener("keplr_keystorechange", () => {
1104
- clearSession();
1105
- reconnect2();
1106
- });
1107
- return () => {
1108
- window.removeEventListener("keplr_keystorechange", () => {
1109
- clearSession();
1110
- reconnect2();
1111
- });
1112
- };
1113
- };
1114
- const res = Object.assign(keplr, {
1115
- subscription
1116
- });
1117
- return res;
1118
- }
1119
- useGrazInternalStore.getState()._notFoundFn();
1120
- throw new Error("window.keplr is not defined");
1121
- };
1122
- var getLeap = () => {
1123
- if (typeof window.leap !== "undefined") {
1124
- const leap = window.leap;
1125
- const subscription = (reconnect2) => {
1126
- window.addEventListener("leap_keystorechange", () => {
1127
- clearSession();
1128
- reconnect2();
1129
- });
1130
- return () => {
1131
- window.removeEventListener("leap_keystorechange", () => {
1132
- clearSession();
1133
- reconnect2();
1134
- });
1135
- };
1136
- };
1137
- const res = Object.assign(leap, {
1138
- subscription
1139
- });
1140
- return res;
1141
- }
1142
- useGrazInternalStore.getState()._notFoundFn();
1143
- throw new Error("window.leap is not defined");
1144
- };
1145
- var getCosmostation = () => {
1146
- if (typeof window.cosmostation.providers.keplr !== "undefined") {
1147
- const cosmostation = window.cosmostation.providers.keplr;
1148
- const subscription = (reconnect2) => {
1149
- window.cosmostation.cosmos.on("accountChanged", () => {
1150
- clearSession();
1151
- reconnect2();
1152
- });
1153
- return () => {
1154
- window.cosmostation.cosmos.off("accountChanged", () => {
1155
- clearSession();
1156
- reconnect2();
1157
- });
1158
- };
1159
- };
1160
- const res = Object.assign(cosmostation, {
1161
- subscription
1162
- });
1163
- return res;
1164
- }
1165
- useGrazInternalStore.getState()._notFoundFn();
1166
- throw new Error("window.cosmostation.providers.keplr is not defined");
1167
- };
1168
- var getVectis = () => {
1169
- if (typeof window.vectis !== "undefined") {
1170
- const vectis = window.vectis.cosmos;
1171
- const subscription = (reconnect2) => {
1172
- window.addEventListener("vectis_accountChanged", () => {
1173
- clearSession();
1174
- reconnect2();
1175
- });
1176
- return () => {
1177
- window.removeEventListener("vectis_accountChanged", () => {
1178
- clearSession();
1179
- reconnect2();
1180
- });
1181
- };
1182
- };
1183
- const getOfflineSignerOnlyAmino = (...args) => {
1184
- return vectis.getOfflineSignerAmino(...args);
1185
- };
1186
- const experimentalSuggestChain = async (...args) => {
1187
- const [chainInfo] = args;
1188
- const adaptChainInfo = {
1189
- ...chainInfo,
1190
- rpcUrl: chainInfo.rpc,
1191
- restUrl: chainInfo.rest,
1192
- prettyName: chainInfo.chainName.replace(" ", ""),
1193
- bech32Prefix: chainInfo.bech32Config.bech32PrefixAccAddr
1194
- };
1195
- return vectis.suggestChains([adaptChainInfo]);
1196
- };
1197
- const getKey = async (chainId) => {
1198
- const key = await vectis.getKey(chainId);
1199
- return {
1200
- address: (0, import_encoding.fromBech32)(key.address).data,
1201
- algo: key.algo,
1202
- bech32Address: key.address,
1203
- name: key.name,
1204
- pubKey: key.pubKey,
1205
- isKeystone: false,
1206
- isNanoLedger: key.isNanoLedger
1207
- };
1208
- };
1209
- const signDirect = async (...args) => {
1210
- var _a;
1211
- const { 1: signer, 2: signDoc } = args;
1212
- return vectis.signDirect(signer, {
1213
- bodyBytes: signDoc.bodyBytes || Uint8Array.from([]),
1214
- authInfoBytes: signDoc.authInfoBytes || Uint8Array.from([]),
1215
- accountNumber: import_long.default.fromString(((_a = signDoc.accountNumber) == null ? void 0 : _a.toString()) || "", false),
1216
- chainId: signDoc.chainId || ""
1217
- });
1218
- };
1219
- const signAmino = async (...args) => {
1220
- const { 1: signer, 2: signDoc } = args;
1221
- return vectis.signAmino(signer, signDoc);
1222
- };
1223
- return {
1224
- enable: (chainId) => vectis.enable(chainId),
1225
- getOfflineSigner: (chainId) => vectis.getOfflineSigner(chainId),
1226
- getOfflineSignerAuto: (chainId) => vectis.getOfflineSignerAuto(chainId),
1227
- getKey,
1228
- subscription,
1229
- getOfflineSignerOnlyAmino,
1230
- experimentalSuggestChain,
1231
- signDirect,
1232
- signAmino
1233
- };
1234
- }
1235
- useGrazInternalStore.getState()._notFoundFn();
1236
- throw new Error("window.vectis is not defined");
1237
- };
1238
- var getWalletConnect = (params) => {
1239
- var _a, _b, _c;
1240
- if (!((_c = (_b = (_a = useGrazInternalStore.getState().walletConnect) == null ? void 0 : _a.options) == null ? void 0 : _b.projectId) == null ? void 0 : _c.trim())) {
1241
- throw new Error("walletConnect.options.projectId is not defined");
1242
- }
1243
- const encoding = (params == null ? void 0 : params.encoding) || "base64";
1244
- const redirectToApp = (wcUri) => {
1245
- if (!params)
1246
- return;
1247
- const { appUrl, formatNativeUrl } = params;
1248
- if (!isMobile())
1249
- return;
1250
- if (isAndroid()) {
1251
- if (!wcUri) {
1252
- window.open(appUrl.mobile.android, "_self", "noreferrer noopener");
1253
- } else {
1254
- const href = formatNativeUrl(appUrl.mobile.android, wcUri, "android");
1255
- window.open(href, "_self", "noreferrer noopener");
1256
- }
1257
- }
1258
- if (isIos()) {
1259
- if (!wcUri) {
1260
- window.open(appUrl.mobile.ios, "_self", "noreferrer noopener");
1261
- } else {
1262
- const href = formatNativeUrl(appUrl.mobile.ios, wcUri, "ios");
1263
- window.open(href, "_self", "noreferrer noopener");
1264
- }
1265
- }
1266
- };
1267
- const _disconnect = () => {
1268
- const { wcSignClient } = useGrazSessionStore.getState();
1269
- if (!wcSignClient)
1270
- throw new Error("walletConnect.signClient is not defined");
1271
- clearSession();
1272
- useGrazInternalStore.setState({
1273
- _reconnect: false,
1274
- _reconnectConnector: null,
1275
- recentChains: null
1276
- });
1277
- };
1278
- const wcDisconnect = async (topic) => {
1279
- const { wcSignClient } = useGrazSessionStore.getState();
1280
- if (!wcSignClient)
1281
- throw new Error("walletConnect.signClient is not defined");
1282
- if (!topic)
1283
- throw new Error("No wallet connect session");
1284
- await wcSignClient.disconnect({
1285
- topic,
1286
- reason: (0, import_utils.getSdkError)("USER_DISCONNECTED")
1287
- });
1288
- await deleteInactivePairings(wcSignClient);
1289
- _disconnect();
1290
- };
1291
- const getSession = (chainId) => {
1292
- try {
1293
- const { wcSignClient } = useGrazSessionStore.getState();
1294
- if (!wcSignClient)
1295
- throw new Error("walletConnect.signClient is not defined");
1296
- const lastSession = wcSignClient.session.getAll().at(-1);
1297
- if (!lastSession)
1298
- return;
1299
- const isValid = lastSession.expiry * 1e3 > Date.now() + 1e3;
1300
- if (!isValid) {
1301
- void wcDisconnect(lastSession.topic);
1302
- throw new Error("invalid session");
1303
- }
1304
- try {
1305
- const chainSession = wcSignClient.find({
1306
- requiredNamespaces: {
1307
- cosmos: {
1308
- methods: ["cosmos_getAccounts", "cosmos_signAmino", "cosmos_signDirect"],
1309
- chains: chainId.map((i) => `cosmos:${i}`),
1310
- events: ["chainChanged", "accountsChanged"]
1311
- }
1312
- }
1313
- });
1314
- if (!chainSession.length) {
1315
- throw new Error("no session");
1316
- }
1317
- return chainSession.at(-1);
1318
- } catch (error) {
1319
- if (!error.message.toLowerCase().includes("no matching key"))
1320
- throw error;
1321
- }
1322
- return lastSession;
1323
- } catch (error) {
1324
- if (!error.message.toLowerCase().includes("no matching key"))
1325
- throw error;
1326
- }
1327
- };
1328
- const checkSession = (chainId) => {
1329
- try {
1330
- const lastSession = getSession(chainId);
1331
- return lastSession;
1332
- } catch (error) {
1333
- return void 0;
1334
- }
1335
- };
1336
- const deleteInactivePairings = async (signClient) => {
1337
- try {
1338
- const pairings = signClient.core.pairing.pairings.getAll({ active: false });
1339
- if (!pairings.length)
1340
- return;
1341
- await Promise.all(
1342
- pairings.map(async (pairing) => {
1343
- await signClient.core.pairing.pairings.delete(pairing.topic, {
1344
- code: 7001,
1345
- message: "clear pairing"
1346
- });
1347
- })
1348
- );
1349
- } catch (error) {
1350
- if (!error.message.toLowerCase().includes("no matching key"))
1351
- throw error;
1352
- }
1353
- };
1354
- const init = async () => {
1355
- const { walletConnect } = useGrazInternalStore.getState();
1356
- if (!(walletConnect == null ? void 0 : walletConnect.options))
1357
- throw new Error("walletConnect.options is not defined");
1358
- const { wcSignClient } = useGrazSessionStore.getState();
1359
- if (wcSignClient) {
1360
- useGrazSessionStore.setState({ wcSignClient });
1361
- return wcSignClient;
1362
- }
1363
- const signClient = await import_sign_client.SignClient.init(walletConnect.options);
1364
- useGrazSessionStore.setState({ wcSignClient: signClient });
1365
- return signClient;
1366
- };
1367
- const subscription = (reconnect2) => {
1368
- const { wcSignClient } = useGrazSessionStore.getState();
1369
- if (!wcSignClient)
1370
- return;
1371
- wcSignClient.events.on("session_delete", (_) => {
1372
- _disconnect();
1373
- });
1374
- wcSignClient.events.on("session_expire", (_) => {
1375
- _disconnect();
1376
- });
1377
- wcSignClient.events.on("session_event", (args) => {
1378
- var _a2, _b2;
1379
- if (args.params.event.name === "accountsChanged" && !((_b2 = useGrazSessionStore.getState().sessions) == null ? void 0 : _b2.map((i) => {
1380
- var _a3;
1381
- return (_a3 = i.account) == null ? void 0 : _a3.bech32Address;
1382
- }).includes((_a2 = args.params.event.data) == null ? void 0 : _a2[0]))) {
1383
- const chainId = args.params.chainId.split(":")[1];
1384
- chainId && void enable([chainId]);
1385
- } else {
1386
- reconnect2();
1387
- }
1388
- });
1389
- return () => {
1390
- wcSignClient.events.off("session_delete", (_) => {
1391
- _disconnect();
1392
- });
1393
- wcSignClient.events.off("session_expire", (_) => {
1394
- _disconnect();
1395
- });
1396
- wcSignClient.events.off("session_event", (args) => {
1397
- var _a2, _b2;
1398
- if (args.params.event.name === "accountsChanged" && !((_b2 = useGrazSessionStore.getState().sessions) == null ? void 0 : _b2.map((i) => {
1399
- var _a3;
1400
- return (_a3 = i.account) == null ? void 0 : _a3.bech32Address;
1401
- }).includes((_a2 = args.params.event.data) == null ? void 0 : _a2[0]))) {
1402
- const chainId = args.params.chainId.split(":")[1];
1403
- chainId && void enable([chainId]);
1404
- } else {
1405
- reconnect2();
1406
- }
1407
- });
1408
- };
1409
- };
1410
- const enable = async (chainId) => {
1411
- var _a2;
1412
- const { wcSignClient: signClient } = useGrazSessionStore.getState();
1413
- if (!signClient)
1414
- throw new Error("enable walletConnect.signClient is not defined");
1415
- const { walletConnect } = useGrazInternalStore.getState();
1416
- if (!((_a2 = walletConnect == null ? void 0 : walletConnect.options) == null ? void 0 : _a2.projectId))
1417
- throw new Error("walletConnect.options.projectId is not defined");
1418
- const { Web3Modal } = await import("@web3modal/standalone");
1419
- const web3Modal = new Web3Modal({
1420
- projectId: walletConnect.options.projectId,
1421
- walletConnectVersion: 2,
1422
- enableExplorer: false,
1423
- explorerRecommendedWalletIds: "NONE",
1424
- ...walletConnect.web3Modal
1425
- // explorerRecommendedWalletIds: [
1426
- // https://walletconnect.com/explorer?type=wallet&version=2&chains=cosmos%3Acosmoshub-4
1427
- // keplr doesn't have complete app object better hide it for now and use getKeplr
1428
- // "6adb6082c909901b9e7189af3a4a0223102cd6f8d5c39e39f3d49acb92b578bb",
1429
- // "3ed8cc046c6211a798dc5ec70f1302b43e07db9639fd287de44a9aa115a21ed6",
1430
- // "feb6ff1fb426db18110f5a80c7adbde846d0a7e96b2bc53af4b73aaf32552bea",
1431
- // "afbd95522f4041c71dd4f1a065f971fd32372865b416f95a0b1db759ae33f2a7",
1432
- // "85db431492aa2e8672e93f4ea7acf10c88b97b867b0d373107af63dc4880f041",
1433
- // "7674bb4e353bf52886768a3ddc2a4562ce2f4191c80831291218ebd90f5f5e26",
1434
- // "0b415a746fb9ee99cce155c2ceca0c6f6061b1dbca2d722b3ba16381d0562150",
1435
- // "022e8ff84519e427bff394b3a58308bc9838196a8efb45158da0ab7c3228abfb",
1436
- // "f896cbca30cd6dc414712d3d6fcc2f8f7d35d5bd30e3b1fc5d60cf6c8926f98f",
1437
- // ],
1438
- });
1439
- const lastSession = checkSession(chainId);
1440
- if (!lastSession) {
1441
- const { uri, approval } = await signClient.connect({
1442
- requiredNamespaces: {
1443
- cosmos: {
1444
- methods: ["cosmos_getAccounts", "cosmos_signAmino", "cosmos_signDirect"],
1445
- chains: chainId.map((i) => `cosmos:${i}`),
1446
- events: ["chainChanged", "accountsChanged"]
1447
- }
1448
- }
1449
- });
1450
- if (!uri)
1451
- throw new Error("No wallet connect uri");
1452
- if (!params) {
1453
- await web3Modal.openModal({ uri });
1454
- } else {
1455
- redirectToApp(uri);
1456
- }
1457
- try {
1458
- await promiseWithTimeout(
1459
- (async () => {
1460
- await approval();
1461
- })(),
1462
- 4e4,
1463
- new Error("Modal approval timeout")
1464
- );
1465
- } catch (error) {
1466
- web3Modal.closeModal();
1467
- if (!error.message.toLowerCase().includes("no matching key"))
1468
- return Promise.reject(error);
1469
- }
1470
- if (!params) {
1471
- web3Modal.closeModal();
1472
- }
1473
- return Promise.resolve();
1474
- }
1475
- try {
1476
- await promiseWithTimeout(
1477
- (async () => {
1478
- const sessions = await Promise.all(
1479
- chainId.map(async (i) => {
1480
- const wcAccount = await getKey(i);
1481
- return { account: wcAccount, chainId: i, status: "connected" };
1482
- })
1483
- );
1484
- useGrazSessionStore.setState((prev) => ({
1485
- sessions: mergeSessions({ prev: prev.sessions, next: sessions })
1486
- }));
1487
- })(),
1488
- 1e4 * chainId.length,
1489
- new Error("Connection timeout")
1490
- );
1491
- } catch (error) {
1492
- void wcDisconnect(lastSession.topic);
1493
- if (!error.message.toLowerCase().includes("no matching key"))
1494
- throw error;
1495
- }
1496
- };
1497
- const getAccount = async (chainId) => {
1498
- var _a2;
1499
- const { wcSignClient } = useGrazSessionStore.getState();
1500
- if (!wcSignClient)
1501
- throw new Error("walletConnect.signClient is not defined");
1502
- const topic = (_a2 = getSession([chainId])) == null ? void 0 : _a2.topic;
1503
- if (!topic)
1504
- throw new Error("No wallet connect session");
1505
- redirectToApp();
1506
- const result = await wcSignClient.request({
1507
- topic,
1508
- chainId: `cosmos:${chainId}`,
1509
- request: {
1510
- method: "cosmos_getAccounts",
1511
- params: {}
1512
- }
1513
- });
1514
- if (!result[0])
1515
- throw new Error("No wallet connect account");
1516
- return {
1517
- address: result[0].address,
1518
- algo: result[0].algo,
1519
- pubkey: new Uint8Array(Buffer.from(result[0].pubkey, encoding))
1520
- };
1521
- };
1522
- const getKey = async (chainId) => {
1523
- const { address, algo, pubkey } = await getAccount(chainId);
1524
- return {
1525
- address: (0, import_encoding.fromBech32)(address).data,
1526
- algo,
1527
- bech32Address: address,
1528
- name: "",
1529
- pubKey: pubkey,
1530
- isKeystone: false,
1531
- isNanoLedger: false
1532
- };
1533
- };
1534
- const wcSignDirect = async (...args) => {
1535
- var _a2, _b2;
1536
- const [chainId, signer, signDoc] = args;
1537
- const { wcSignClient } = useGrazSessionStore.getState();
1538
- if (!wcSignClient)
1539
- throw new Error("walletConnect.signClient is not defined");
1540
- const topic = (_a2 = getSession([chainId])) == null ? void 0 : _a2.topic;
1541
- if (!topic)
1542
- throw new Error("No wallet connect session");
1543
- if (!signDoc.bodyBytes)
1544
- throw new Error("No bodyBytes");
1545
- if (!signDoc.authInfoBytes)
1546
- throw new Error("No authInfoBytes");
1547
- const req = {
1548
- topic,
1549
- chainId: `cosmos:${chainId}`,
1550
- request: {
1551
- method: "cosmos_signDirect",
1552
- params: {
1553
- signerAddress: signer,
1554
- signDoc: {
1555
- ...signDoc,
1556
- bodyBytes: Buffer.from(signDoc.bodyBytes).toString(encoding),
1557
- authInfoBytes: Buffer.from(signDoc.authInfoBytes).toString(encoding),
1558
- accountNumber: (_b2 = signDoc.accountNumber) == null ? void 0 : _b2.toString()
1559
- }
1560
- }
1561
- }
1562
- };
1563
- redirectToApp();
1564
- const result = await wcSignClient.request(req);
1565
- return result;
1566
- };
1567
- const signDirect = async (...args) => {
1568
- const [chainId, signer, signDoc] = args;
1569
- const { signature, signed } = await wcSignDirect(chainId, signer, signDoc);
1570
- return {
1571
- signed: {
1572
- chainId: signed.chainId,
1573
- accountNumber: import_long.default.fromString(signed.accountNumber, false),
1574
- authInfoBytes: new Uint8Array(Buffer.from(signed.authInfoBytes, encoding)),
1575
- bodyBytes: new Uint8Array(Buffer.from(signed.bodyBytes, encoding))
1576
- },
1577
- signature
1578
- };
1579
- };
1580
- const wcSignAmino = async (...args) => {
1581
- var _a2;
1582
- const [chainId, signer, signDoc, _signOptions] = args;
1583
- const { wcSignClient } = useGrazSessionStore.getState();
1584
- if (!wcSignClient)
1585
- throw new Error("walletConnect.signClient is not defined");
1586
- const topic = (_a2 = getSession([chainId])) == null ? void 0 : _a2.topic;
1587
- if (!topic)
1588
- throw new Error("No wallet connect session");
1589
- redirectToApp();
1590
- const result = await wcSignClient.request({
1591
- topic,
1592
- chainId: `cosmos:${chainId}`,
1593
- request: {
1594
- method: "cosmos_signDirect",
1595
- params: {
1596
- signerAddress: signer,
1597
- signDoc
1598
- }
1599
- }
1600
- });
1601
- return result;
1602
- };
1603
- const signAmino = async (...args) => {
1604
- const [chainId, signer, signDoc, _signOptions] = args;
1605
- const result = await wcSignAmino(chainId, signer, signDoc);
1606
- return result;
1607
- };
1608
- const getOfflineSignerDirect = (chainId) => {
1609
- return {
1610
- getAccounts: async () => [await getAccount(chainId)],
1611
- signDirect: (signerAddress, signDoc) => signDirect(chainId, signerAddress, signDoc)
1612
- };
1613
- };
1614
- const getOfflineSignerOnlyAmino = (chainId) => {
1615
- return {
1616
- getAccounts: async () => [await getAccount(chainId)],
1617
- signAmino: (signerAddress, signDoc) => signAmino(chainId, signerAddress, signDoc)
1618
- };
1619
- };
1620
- const getOfflineSigner = (chainId) => {
1621
- return {
1622
- getAccounts: async () => [await getAccount(chainId)],
1623
- signDirect: (signerAddress, signDoc) => signDirect(chainId, signerAddress, signDoc),
1624
- signAmino: (signerAddress, signDoc) => signAmino(chainId, signerAddress, signDoc)
1625
- };
1626
- };
1627
- const getOfflineSignerAuto = async (chainId) => {
1628
- const key = await getKey(chainId);
1629
- if (key.isNanoLedger)
1630
- return getOfflineSignerOnlyAmino(chainId);
1631
- return getOfflineSignerDirect(chainId);
1632
- };
1633
- const experimentalSuggestChain = async (..._args) => {
1634
- await Promise.reject(new Error("WalletConnect does not support experimentalSuggestChain"));
1635
- };
1636
- return {
1637
- enable,
1638
- experimentalSuggestChain,
1639
- getKey,
1640
- getOfflineSigner,
1641
- getOfflineSignerAuto,
1642
- getOfflineSignerOnlyAmino,
1643
- signAmino,
1644
- signDirect,
1645
- subscription,
1646
- init
1647
- };
1648
- };
1649
- var getWCKeplr = () => {
1650
- var _a, _b, _c;
1651
- if (!((_c = (_b = (_a = useGrazInternalStore.getState().walletConnect) == null ? void 0 : _a.options) == null ? void 0 : _b.projectId) == null ? void 0 : _c.trim())) {
1652
- throw new Error("walletConnect.options.projectId is not defined");
1653
- }
1654
- if (!isMobile())
1655
- throw new Error("WalletConnect Keplr mobile is only supported in mobile");
1656
- const params = {
1657
- encoding: "base64",
1658
- appUrl: {
1659
- mobile: {
1660
- ios: "keplrwallet://",
1661
- android: "intent://"
1662
- }
1663
- },
1664
- walletType: "wc_keplr_mobile" /* WC_KEPLR_MOBILE */,
1665
- formatNativeUrl: (appUrl, wcUri, os) => {
1666
- const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
1667
- const encoded = encodeURIComponent(wcUri);
1668
- switch (os) {
1669
- case "ios":
1670
- return `${plainAppUrl}://wcV2?${encoded}`;
1671
- case "android":
1672
- return `${plainAppUrl}://wcV2?${encoded}#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;`;
1673
- default:
1674
- return `${plainAppUrl}://wc?uri=${encoded}`;
1675
- }
1676
- }
1677
- };
1678
- return getWalletConnect(params);
1679
- };
1680
- var getWCLeap = () => {
1681
- var _a, _b, _c;
1682
- if (!((_c = (_b = (_a = useGrazInternalStore.getState().walletConnect) == null ? void 0 : _a.options) == null ? void 0 : _b.projectId) == null ? void 0 : _c.trim())) {
1683
- throw new Error("walletConnect.options.projectId is not defined");
1684
- }
1685
- if (!isMobile())
1686
- throw new Error("WalletConnect Leap mobile is only supported in mobile");
1687
- const params = {
1688
- encoding: "base64",
1689
- appUrl: {
1690
- mobile: {
1691
- ios: "leapcosmos://",
1692
- android: "intent://"
1693
- }
1694
- },
1695
- walletType: "wc_leap_mobile" /* WC_LEAP_MOBILE */,
1696
- formatNativeUrl: (appUrl, wcUri, os) => {
1697
- const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
1698
- const encoded = encodeURIComponent(wcUri);
1699
- switch (os) {
1700
- case "ios":
1701
- return `${plainAppUrl}://wcV2?${encoded}`;
1702
- case "android":
1703
- return `${plainAppUrl}://wcV2?${encoded}#Intent;package=io.leapwallet.cosmos;scheme=leapwallet;end;`;
1704
- default:
1705
- return `${plainAppUrl}://wc?uri=${encoded}`;
1706
- }
1707
- }
1708
- };
1709
- return getWalletConnect(params);
1710
- };
1711
- var getWCCosmostation = () => {
1712
- var _a, _b, _c;
1713
- if (!((_c = (_b = (_a = useGrazInternalStore.getState().walletConnect) == null ? void 0 : _a.options) == null ? void 0 : _b.projectId) == null ? void 0 : _c.trim())) {
1714
- throw new Error("walletConnect.options.projectId is not defined");
1715
- }
1716
- if (!isMobile())
1717
- throw new Error("WalletConnect Leap mobile is only supported in mobile");
1718
- const params = {
1719
- encoding: "hex",
1720
- appUrl: {
1721
- mobile: {
1722
- ios: "cosmostation://",
1723
- android: "cosmostation://"
1724
- }
1725
- },
1726
- walletType: "wc_leap_mobile" /* WC_LEAP_MOBILE */,
1727
- formatNativeUrl: (appUrl, wcUri, _os) => {
1728
- const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
1729
- return `${plainAppUrl}://wc?${wcUri}`;
1730
- }
1731
- };
1732
- return getWalletConnect(params);
1733
- };
1734
- var getWallet = (type = useGrazInternalStore.getState().walletType) => {
1735
- switch (type) {
1736
- case "keplr" /* KEPLR */: {
1737
- return getKeplr();
1738
- }
1739
- case "leap" /* LEAP */: {
1740
- return getLeap();
1741
- }
1742
- case "cosmostation" /* COSMOSTATION */: {
1743
- return getCosmostation();
1744
- }
1745
- case "vectis" /* VECTIS */: {
1746
- return getVectis();
1747
- }
1748
- case "walletconnect" /* WALLETCONNECT */: {
1749
- return getWalletConnect();
1750
- }
1751
- case "wc_keplr_mobile" /* WC_KEPLR_MOBILE */: {
1752
- return getWCKeplr();
1753
- }
1754
- case "wc_leap_mobile" /* WC_LEAP_MOBILE */: {
1755
- return getWCLeap();
1756
- }
1757
- case "wc_cosmostation_mobile" /* WC_COSMOSTATION_MOBILE */: {
1758
- return getWCCosmostation();
1759
- }
1760
- default: {
1761
- throw new Error("Unknown wallet type");
1762
- }
1763
- }
1764
- };
1765
- var getAvailableWallets = () => {
1766
- return Object.fromEntries(WALLET_TYPES.map((type) => [type, checkWallet(type)]));
1767
- };
1768
-
1769
- // src/actions/account.ts
1770
- var connect = async (args) => {
1771
- var _a, _b;
1772
- try {
1773
- const { recentChains, walletType } = useGrazInternalStore.getState();
1774
- if ((args == null ? void 0 : args.walletType) && args.walletType !== walletType) {
1775
- await disconnect();
1776
- }
1777
- const currentWalletType = (args == null ? void 0 : args.walletType) || walletType;
1778
- const isWalletAvailable = checkWallet(currentWalletType);
1779
- if (!isWalletAvailable) {
1780
- throw new Error(`${currentWalletType} is not available`);
1781
- }
1782
- const wallet = getWallet(currentWalletType);
1783
- const chainId = (args == null ? void 0 : args.chainId) || recentChains;
1784
- if (!chainId) {
1785
- throw new Error("No last known connected chain, connect action requires chain id");
1786
- }
1787
- await ((_a = wallet.init) == null ? void 0 : _a.call(wallet));
1788
- await wallet.enable(chainId);
1789
- const { sessions: _sessions } = useGrazSessionStore.getState();
1790
- const sessions = await Promise.all(
1791
- chainId.map(async (i) => {
1792
- const account = await wallet.getKey(i);
1793
- return { account, chainId: i, status: "connected" };
1794
- })
1795
- );
1796
- useGrazSessionStore.setState((prev) => ({ sessions: mergeSessions({ prev: prev.sessions, next: sessions }) }));
1797
- useGrazInternalStore.setState({
1798
- recentChains: (_b = useGrazSessionStore.getState().sessions) == null ? void 0 : _b.map((session) => session.chainId),
1799
- walletType: currentWalletType,
1800
- _reconnect: Boolean(args == null ? void 0 : args.autoReconnect),
1801
- _reconnectConnector: currentWalletType
1802
- });
1803
- typeof window !== "undefined" && window.sessionStorage.setItem(RECONNECT_SESSION_KEY, "Active");
1804
- return { walletType: currentWalletType, sessions };
1805
- } catch (error) {
1806
- console.error("connect ", error);
1807
- useGrazSessionStore.setState((prev) => {
1808
- var _a2;
1809
- return {
1810
- sessions: (_a2 = prev.sessions) == null ? void 0 : _a2.map(
1811
- (item) => item.account ? { ...item, status: "connected" } : {
1812
- ...item,
1813
- status: "disconnected"
1814
- }
1815
- )
1816
- };
1817
- });
1818
- throw error;
1819
- }
1820
- };
1821
- var getOfflineSigners = async (args) => {
1822
- if (!(args == null ? void 0 : args.chainId))
1823
- throw new Error("chainId is required");
1824
- const { walletType } = useGrazInternalStore.getState();
1825
- const currentWalletType = args.walletType || walletType;
1826
- const isWalletAvailable = checkWallet(currentWalletType);
1827
- if (!isWalletAvailable) {
1828
- throw new Error(`${currentWalletType} is not available`);
1829
- }
1830
- const wallet = getWallet(currentWalletType);
1831
- const offlineSigner = wallet.getOfflineSigner(args.chainId);
1832
- const offlineSignerAmino = wallet.getOfflineSignerOnlyAmino(args.chainId);
1833
- const offlineSignerAuto = await wallet.getOfflineSignerAuto(args.chainId);
1834
- return { offlineSigner, offlineSignerAmino, offlineSignerAuto };
1835
- };
1836
- var disconnect = async (args) => {
1837
- typeof window !== "undefined" && window.sessionStorage.removeItem(RECONNECT_SESSION_KEY);
1838
- if (args == null ? void 0 : args.chainId) {
1839
- useGrazSessionStore.setState((x) => {
1840
- var _a;
1841
- return {
1842
- sessions: (_a = x.sessions) == null ? void 0 : _a.filter((item) => {
1843
- var _a2;
1844
- return !((_a2 = args.chainId) == null ? void 0 : _a2.includes(item.chainId));
1845
- })
1846
- };
1847
- });
1848
- useGrazInternalStore.setState((x) => {
1849
- var _a;
1850
- return {
1851
- _reconnect: false,
1852
- _reconnectConnector: null,
1853
- recentChains: (_a = x.recentChains) == null ? void 0 : _a.filter((item) => {
1854
- var _a2;
1855
- return !((_a2 = args.chainId) == null ? void 0 : _a2.includes(item));
1856
- })
1857
- };
1858
- });
1859
- } else {
1860
- useGrazSessionStore.setState(grazSessionDefaultValues);
1861
- useGrazInternalStore.setState({
1862
- _reconnect: false,
1863
- _reconnectConnector: null,
1864
- recentChains: null
1865
- });
1866
- }
1867
- return Promise.resolve();
1868
- };
1869
- var reconnect = async (args) => {
1870
- var _a;
1871
- const { recentChains, _reconnectConnector, _reconnect } = useGrazInternalStore.getState();
1872
- try {
1873
- const isWalletReady = checkWallet(_reconnectConnector || void 0);
1874
- if (recentChains && isWalletReady && _reconnectConnector) {
1875
- const key = await connect({
1876
- chainId: recentChains,
1877
- walletType: _reconnectConnector,
1878
- autoReconnect: _reconnect
1879
- });
1880
- return key;
1881
- }
1882
- } catch (error) {
1883
- (_a = args == null ? void 0 : args.onError) == null ? void 0 : _a.call(args, error);
1884
- void disconnect();
1885
- }
1886
- };
1887
-
1888
- // src/actions/chains.ts
1889
- var clearRecentChain = () => {
1890
- useGrazInternalStore.setState({ recentChains: null });
1891
- };
1892
- var getRecentChains = () => {
1893
- return useGrazInternalStore.getState().recentChains;
1894
- };
1895
- var suggestChain = async (chainInfo) => {
1896
- const wallet = getWallet();
1897
- await wallet.experimentalSuggestChain(chainInfo);
1898
- return chainInfo;
1899
- };
1900
- var suggestChainAndConnect = async (args) => {
1901
- await suggestChain(args.chainInfo);
1902
- const result = await connect({
1903
- chainId: [args.chainInfo.chainId],
1904
- autoReconnect: args.autoReconnect,
1905
- walletType: args.walletType
1906
- });
1907
- return result;
1908
- };
1909
-
1910
- // src/actions/clients.ts
1911
- var import_cosmwasm_stargate = require("@cosmjs/cosmwasm-stargate");
1912
- var import_stargate = require("@cosmjs/stargate");
1913
- var import_tendermint_rpc = require("@cosmjs/tendermint-rpc");
1914
- var connectClient = async ({ rpc, rpcHeaders, client }) => {
1915
- const endpoint = { url: rpc, headers: { ...rpcHeaders || {} } };
1916
- const result = await (async () => {
1917
- switch (client) {
1918
- case "cosmWasm":
1919
- return import_cosmwasm_stargate.CosmWasmClient.connect(endpoint);
1920
- case "stargate":
1921
- return import_stargate.StargateClient.connect(endpoint);
1922
- case "tendermint":
1923
- return import_tendermint_rpc.Tendermint34Client.connect(rpc);
1924
- default:
1925
- throw new Error(`Unknown client: ${client}`);
1926
- }
1927
- })();
1928
- return result;
1929
- };
1930
- var connectSigningClient = async (args) => {
1931
- const { rpc, rpcHeaders, offlineSignerAuto, client, options = {} } = args;
1932
- const endpoint = { url: rpc, headers: { ...rpcHeaders || {} } };
1933
- const result = await (async () => {
1934
- switch (client) {
1935
- case "cosmWasm":
1936
- return import_cosmwasm_stargate.SigningCosmWasmClient.connectWithSigner(
1937
- endpoint,
1938
- offlineSignerAuto,
1939
- options
1940
- );
1941
- case "stargate":
1942
- return import_stargate.SigningStargateClient.connectWithSigner(endpoint, offlineSignerAuto, options);
1943
- default:
1944
- throw new Error(`Unknown client: ${client}`);
1945
- }
1946
- })();
1947
- return result;
1948
- };
1949
-
1950
- // src/actions/configure.ts
1951
- var configureGraz = (args) => {
1952
- useGrazInternalStore.setState((prev) => ({
1953
- chains: args.chains || prev.chains,
1954
- defaultClient: args.defaultClient || prev.defaultClient,
1955
- defaultSigningClient: args.defaultSigningClient || prev.defaultSigningClient,
1956
- walletConnect: args.walletConnect || prev.walletConnect,
1957
- walletType: args.defaultWallet || prev.walletType,
1958
- _notFoundFn: args.onNotFound || prev._notFoundFn,
1959
- _onReconnectFailed: args.onReconnectFailed || prev._onReconnectFailed,
1960
- _reconnect: args.autoReconnect === void 0 ? true : args.autoReconnect || prev._reconnect
1961
- }));
1962
- return args;
1963
- };
1964
-
1965
- // src/actions/methods.ts
1966
- var getBalances = async ({
1967
- bech32Address,
1968
- client,
1969
- currencies: currencies9
1970
- }) => {
1971
- const balances = await Promise.all(
1972
- currencies9.filter((i) => !i.coinMinimalDenom.startsWith("cw20:")).map(async (item) => {
1973
- return client.getBalance(bech32Address, item.coinMinimalDenom);
1974
- })
1975
- );
1976
- return balances;
1977
- };
1978
- var getBalanceStaked = async ({
1979
- bech32Address,
1980
- client
1981
- }) => {
1982
- return client.getBalanceStaked(bech32Address);
1983
- };
1984
- var sendTokens = async ({
1985
- senderAddress,
1986
- recipientAddress,
1987
- amount,
1988
- fee,
1989
- memo,
1990
- signingClient
1991
- }) => {
1992
- return signingClient.sendTokens(senderAddress, recipientAddress, amount, fee, memo);
1993
- };
1994
- var sendIbcTokens = async ({
1995
- signingClient,
1996
- senderAddress,
1997
- recipientAddress,
1998
- transferAmount,
1999
- sourcePort,
2000
- sourceChannel,
2001
- timeoutHeight,
2002
- timeoutTimestamp,
2003
- fee,
2004
- memo
2005
- }) => {
2006
- return signingClient.sendIbcTokens(
2007
- senderAddress,
2008
- recipientAddress,
2009
- transferAmount,
2010
- sourcePort,
2011
- sourceChannel,
2012
- timeoutHeight,
2013
- timeoutTimestamp,
2014
- fee,
2015
- memo
2016
- );
2017
- };
2018
- var instantiateContract = async ({
2019
- signingClient,
2020
- senderAddress,
2021
- msg,
2022
- fee,
2023
- options,
2024
- label,
2025
- codeId
2026
- }) => {
2027
- return signingClient.instantiate(senderAddress, codeId, msg, label, fee, options);
2028
- };
2029
- var executeContract = async ({
2030
- signingClient,
2031
- senderAddress,
2032
- msg,
2033
- fee,
2034
- contractAddress,
2035
- funds,
2036
- memo
2037
- }) => {
2038
- return signingClient.execute(senderAddress, contractAddress, msg, fee, memo, funds);
2039
- };
2040
- var getQuerySmart = async ({
2041
- client,
2042
- address,
2043
- queryMsg
2044
- }) => {
2045
- const result = await client.queryContractSmart(address, queryMsg);
2046
- return result;
2047
- };
2048
- var getQueryRaw = ({
2049
- client,
2050
- address,
2051
- keyStr
2052
- }) => {
2053
- const key = new TextEncoder().encode(keyStr);
2054
- return client.queryContractRaw(address, key);
2055
- };
2056
-
2057
- // src/chains/mainnet/axelar.ts
2058
- var import_cosmos = require("@keplr-wallet/cosmos");
2059
- var AXL = {
2060
- coinDenom: "axl",
2061
- coinMinimalDenom: "uaxl",
2062
- coinDecimals: 6,
2063
- coinGeckoId: "axelar-network",
2064
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axl.png"
2065
- };
2066
- var USDC = {
2067
- coinDenom: "usdc",
2068
- coinMinimalDenom: "uusdc",
2069
- coinDecimals: 6,
2070
- coinGeckoId: "usd-coin",
2071
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/usdc.png"
2072
- };
2073
- var FRAX = {
2074
- coinDenom: "dai",
2075
- coinMinimalDenom: "dai-wei",
2076
- coinDecimals: 18,
2077
- coinGeckoId: "dai",
2078
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/dai.png"
2079
- };
2080
- var USDT = {
2081
- coinDenom: "usdt",
2082
- coinMinimalDenom: "uusdt",
2083
- coinDecimals: 6,
2084
- coinGeckoId: "tether",
2085
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/usdt.png"
2086
- };
2087
- var WETH = {
2088
- coinDenom: "weth-wei",
2089
- coinMinimalDenom: "weth",
2090
- coinDecimals: 18,
2091
- coinGeckoId: "weth",
2092
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/weth.png"
2093
- };
2094
- var WBTC = {
2095
- coinDenom: "wbtc-satoshi",
2096
- coinMinimalDenom: "wbtc",
2097
- coinDecimals: 8,
2098
- coinGeckoId: "wrapped-bitcoin",
2099
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/wbtc.png"
2100
- };
2101
- var currencies = [AXL, USDC, FRAX, USDT, WETH, WBTC];
2102
- var axelar = {
2103
- rpc: "https://rpc.axelar.strange.love",
2104
- rest: "https://api.axelar.strange.love",
2105
- chainId: "axelar-dojo-1",
2106
- chainName: "Axelar",
2107
- stakeCurrency: AXL,
2108
- bip44: {
2109
- coinType: 118
2110
- },
2111
- bech32Config: import_cosmos.Bech32Address.defaultBech32Config("axelar"),
2112
- currencies,
2113
- feeCurrencies: currencies
2114
- };
2115
-
2116
- // src/chains/mainnet/cosmoshub.ts
2117
- var import_cosmos2 = require("@keplr-wallet/cosmos");
2118
- var ATOM = {
2119
- coinDenom: "atom",
2120
- coinMinimalDenom: "uatom",
2121
- coinDecimals: 6,
2122
- coinGeckoId: "cosmos",
2123
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"
2124
- };
2125
- var currencies2 = [ATOM];
2126
- var cosmoshub = {
2127
- rpc: "https://rpc.cosmoshub.strange.love",
2128
- rest: "https://api.cosmoshub.strange.love",
2129
- chainId: "cosmoshub-4",
2130
- chainName: "Cosmos Hub",
2131
- stakeCurrency: ATOM,
2132
- bip44: {
2133
- coinType: 118
2134
- },
2135
- bech32Config: import_cosmos2.Bech32Address.defaultBech32Config("cosmos"),
2136
- currencies: currencies2,
2137
- feeCurrencies: currencies2
2138
- };
2139
-
2140
- // src/chains/mainnet/juno.ts
2141
- var import_cosmos3 = require("@keplr-wallet/cosmos");
2142
- var JUNO = {
2143
- coinDenom: "juno",
2144
- coinMinimalDenom: "ujuno",
2145
- coinDecimals: 6,
2146
- coinGeckoId: "juno-network",
2147
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"
2148
- };
2149
- var NETA = {
2150
- coinDenom: "neta",
2151
- coinMinimalDenom: "cw20:juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr",
2152
- coinDecimals: 6,
2153
- coinGeckoId: "neta",
2154
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/neta.png"
2155
- };
2156
- var MARBLE = {
2157
- coinDenom: "marble",
2158
- coinMinimalDenom: "cw20:juno1g2g7ucurum66d42g8k5twk34yegdq8c82858gz0tq2fc75zy7khssgnhjl",
2159
- coinDecimals: 3,
2160
- coinGeckoId: "marble",
2161
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/marble.png"
2162
- };
2163
- var HOPE = {
2164
- coinDenom: "hope",
2165
- coinMinimalDenom: "cw20:juno1re3x67ppxap48ygndmrc7har2cnc7tcxtm9nplcas4v0gc3wnmvs3s807z",
2166
- coinDecimals: 6,
2167
- coinGeckoId: "hope-galaxy",
2168
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hope.png"
2169
- };
2170
- var RAC = {
2171
- coinDenom: "rac",
2172
- coinMinimalDenom: "cw20:juno1r4pzw8f9z0sypct5l9j906d47z998ulwvhvqe5xdwgy8wf84583sxwh0pa",
2173
- coinDecimals: 6,
2174
- coinGeckoId: "racoon",
2175
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/rac.png"
2176
- };
2177
- var BLOCK = {
2178
- coinDenom: "block",
2179
- coinMinimalDenom: "cw20:juno1y9rf7ql6ffwkv02hsgd4yruz23pn4w97p75e2slsnkm0mnamhzysvqnxaq",
2180
- coinDecimals: 6,
2181
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/block.png"
2182
- };
2183
- var DHK = {
2184
- coinDenom: "dhk",
2185
- coinMinimalDenom: "cw20:juno1tdjwrqmnztn2j3sj2ln9xnyps5hs48q3ddwjrz7jpv6mskappjys5czd49",
2186
- coinDecimals: 0,
2187
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/dhk.png"
2188
- };
2189
- var RAW = {
2190
- coinDenom: "raw",
2191
- coinMinimalDenom: "cw20:juno15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hes5sn38g",
2192
- coinDecimals: 6,
2193
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/raw.png",
2194
- coinGeckoId: "junoswap-raw-dao"
2195
- };
2196
- var ASVT = {
2197
- coinDenom: "asvt",
2198
- coinMinimalDenom: "cw20:juno17wzaxtfdw5em7lc94yed4ylgjme63eh73lm3lutp2rhcxttyvpwsypjm4w",
2199
- coinDecimals: 6,
2200
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/asvt.png"
2201
- };
2202
- var HNS = {
2203
- coinDenom: "hns",
2204
- coinMinimalDenom: "cw20:juno1ur4jx0sxchdevahep7fwq28yk4tqsrhshdtylz46yka3uf6kky5qllqp4k",
2205
- coinDecimals: 6,
2206
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hns.svg"
2207
- };
2208
- var JOE = {
2209
- coinDenom: "joe",
2210
- coinMinimalDenom: "cw20:juno1n7n7d5088qlzlj37e9mgmkhx6dfgtvt02hqxq66lcap4dxnzdhwqfmgng3",
2211
- coinDecimals: 6,
2212
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/joe.png"
2213
- };
2214
- var currencies3 = [JUNO, NETA, MARBLE, HOPE, RAC, BLOCK, DHK, RAW, ASVT, HNS, JOE];
2215
- var juno = {
2216
- rpc: "https://rpc.juno.strange.love",
2217
- rest: "https://api.juno.strange.love",
2218
- chainId: "juno-1",
2219
- chainName: "Juno",
2220
- stakeCurrency: JUNO,
2221
- bip44: {
2222
- coinType: 118
2223
- },
2224
- bech32Config: import_cosmos3.Bech32Address.defaultBech32Config("juno"),
2225
- currencies: currencies3,
2226
- feeCurrencies: currencies3
2227
- };
2228
-
2229
- // src/chains/mainnet/osmosis.ts
2230
- var import_cosmos4 = require("@keplr-wallet/cosmos");
2231
- var OSMO = {
2232
- coinDenom: "osmo",
2233
- coinMinimalDenom: "uosmo",
2234
- coinDecimals: 6,
2235
- coinGeckoId: "osmosis",
2236
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"
2237
- };
2238
- var ION = {
2239
- coinDenom: "ion",
2240
- coinMinimalDenom: "uion",
2241
- coinDecimals: 6,
2242
- coinGeckoId: "ion",
2243
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/ion.png"
2244
- };
2245
- var currencies4 = [OSMO, ION];
2246
- var osmosis = {
2247
- rpc: "https://rpc.osmosis.strange.love",
2248
- rest: "https://api.osmosis.strange.love",
2249
- chainId: "osmosis-1",
2250
- chainName: "Osmosis",
2251
- stakeCurrency: OSMO,
2252
- bip44: {
2253
- coinType: 118
2254
- },
2255
- bech32Config: import_cosmos4.Bech32Address.defaultBech32Config("osmo"),
2256
- currencies: currencies4,
2257
- feeCurrencies: currencies4
2258
- };
2259
-
2260
- // src/chains/mainnet/sommelier.ts
2261
- var import_cosmos5 = require("@keplr-wallet/cosmos");
2262
- var SOMM = {
2263
- coinDenom: "somm",
2264
- coinMinimalDenom: "usomm",
2265
- coinDecimals: 6,
2266
- coinGeckoId: "sommelier",
2267
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/sommelier/images/somm.png"
2268
- };
2269
- var currencies5 = [SOMM];
2270
- var sommelier = {
2271
- rpc: "https://rpc.sommelier.strange.love",
2272
- rest: "https://api.sommelier.strange.love",
2273
- chainId: "sommelier-3",
2274
- chainName: "Sommelier",
2275
- stakeCurrency: SOMM,
2276
- bip44: {
2277
- coinType: 118
2278
- },
2279
- bech32Config: import_cosmos5.Bech32Address.defaultBech32Config("somm"),
2280
- currencies: currencies5,
2281
- feeCurrencies: currencies5
2282
- };
2283
-
2284
- // src/chains/testnet/crescent.ts
2285
- var import_cosmos6 = require("@keplr-wallet/cosmos");
2286
- var CRE = {
2287
- coinDenom: "CRE",
2288
- coinMinimalDenom: "ucre",
2289
- coinDecimals: 6,
2290
- coinGeckoId: "crescent",
2291
- coinImageUrl: "https://raw.githubusercontent.com/crescent-network/asset/main/images/coin/CRE.png"
2292
- };
2293
- var currencies6 = [CRE];
2294
- var crescentTestnet = {
2295
- rpc: "https://testnet-endpoint.crescent.network/rpc/crescent",
2296
- rest: "https://testnet-endpoint.crescent.network/api/crescent",
2297
- chainId: "mooncat-1-1",
2298
- chainName: "Crescent Testnet",
2299
- bip44: {
2300
- coinType: 118
2301
- },
2302
- bech32Config: import_cosmos6.Bech32Address.defaultBech32Config("CRE"),
2303
- currencies: currencies6,
2304
- feeCurrencies: currencies6,
2305
- stakeCurrency: CRE,
2306
- coinType: 118
2307
- };
2308
-
2309
- // src/chains/testnet/juno.ts
2310
- var import_cosmos7 = require("@keplr-wallet/cosmos");
2311
- var JUNO2 = {
2312
- coinDenom: "junox",
2313
- coinMinimalDenom: "ujunox",
2314
- coinDecimals: 6,
2315
- coinGeckoId: "juno-network",
2316
- coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"
2317
- };
2318
- var currencies7 = [JUNO2];
2319
- var junoTestnet = {
2320
- rpc: "https://rpc.uni.junonetwork.io",
2321
- rest: "https://api.uni.junonetwork.io",
2322
- chainId: "uni-5",
2323
- chainName: "Juno Testnet",
2324
- stakeCurrency: JUNO2,
2325
- bip44: {
2326
- coinType: 118
2327
- },
2328
- bech32Config: import_cosmos7.Bech32Address.defaultBech32Config("juno"),
2329
- currencies: currencies7,
2330
- feeCurrencies: [JUNO2],
2331
- coinType: 118
2332
- };
2333
-
2334
- // src/chains/testnet/osmosis.ts
2335
- var import_cosmos8 = require("@keplr-wallet/cosmos");
2336
- var OSMO2 = {
2337
- coinDenom: "osmo",
2338
- coinMinimalDenom: "uosmo",
2339
- coinDecimals: 6,
2340
- coinGeckoId: "osmosis",
2341
- coinImageUrl: "https://dhj8dql1kzq2v.cloudfront.net/white/osmo.png"
2342
- };
2343
- var currencies8 = [OSMO2];
2344
- var osmosisTestnet = {
2345
- rpc: "https://testnet-rpc.osmosis.zone",
2346
- rest: "https://testnet-rest.osmosis.zone",
2347
- chainId: "osmo-test-4",
2348
- chainName: "Osmosis Testnet",
2349
- stakeCurrency: OSMO2,
2350
- bip44: {
2351
- coinType: 118
2352
- },
2353
- bech32Config: import_cosmos8.Bech32Address.defaultBech32Config("osmo"),
2354
- currencies: currencies8,
2355
- feeCurrencies: [OSMO2],
2356
- coinType: 118
2357
- };
2358
-
2359
- // src/chains/index.ts
2360
- var defineChains = (chains) => {
2361
- return chains;
2362
- };
2363
- var defineChain = (chain) => {
2364
- return chain;
2365
- };
2366
- var defineChainInfo = (chain) => {
2367
- return chain;
2368
- };
2369
- var mainnetChains = defineChains({
2370
- axelar,
2371
- cosmoshub,
2372
- juno,
2373
- osmosis,
2374
- sommelier
2375
- });
2376
- var mainnetChainsArray = [axelar, cosmoshub, juno, osmosis, sommelier];
2377
- var testnetChains = defineChains({
2378
- crescent: crescentTestnet,
2379
- juno: junoTestnet,
2380
- osmosis: osmosisTestnet
2381
- });
2382
- var testnetChainsArray = [crescentTestnet, junoTestnet, osmosisTestnet];
2383
-
2384
- // src/hooks/account.ts
2385
- var import_react_query2 = require("@tanstack/react-query");
2386
- var import_react = require("react");
2387
-
2388
- // src/hooks/wallet.ts
2389
- var import_react_query = require("@tanstack/react-query");
2390
- var import_shallow = require("zustand/shallow");
2391
- var useActiveWalletType = () => {
2392
- return useGrazInternalStore(
2393
- (x) => ({
2394
- walletType: x.walletType,
2395
- isCosmostation: x.walletType === "cosmostation" /* COSMOSTATION */,
2396
- isCosmostationMobile: x.walletType === "wc_cosmostation_mobile" /* WC_COSMOSTATION_MOBILE */,
2397
- isKeplr: x.walletType === "keplr" /* KEPLR */,
2398
- isKeplrMobile: x.walletType === "wc_keplr_mobile" /* WC_KEPLR_MOBILE */,
2399
- isLeap: x.walletType === "leap" /* LEAP */,
2400
- isLeapMobile: x.walletType === "wc_leap_mobile" /* WC_LEAP_MOBILE */,
2401
- isVectis: x.walletType === "vectis" /* VECTIS */,
2402
- isWalletConnect: x.walletType === "walletconnect" /* WALLETCONNECT */
2403
- }),
2404
- import_shallow.shallow
2405
- );
2406
- };
2407
- var useCheckWallet = (type) => {
2408
- const walletType = useGrazInternalStore((x) => type || x.walletType);
2409
- const queryKey = ["USE_CHECK_WALLET", walletType];
2410
- const query = (0, import_react_query.useQuery)(queryKey, ({ queryKey: [, _type] }) => checkWallet(_type));
2411
- return query;
2412
- };
2413
-
2414
- // src/hooks/account.ts
2415
- var useAccount = (args) => {
2416
- const sessions = useGrazSessionStore((x) => x.sessions);
2417
- (0, import_react.useEffect)(() => {
2418
- return useGrazSessionStore.subscribe(
2419
- (x) => x.sessions,
2420
- (stat, prevStat) => {
2421
- stat == null ? void 0 : stat.forEach((i) => {
2422
- var _a, _b, _c, _d;
2423
- if (((_a = prevStat == null ? void 0 : prevStat.find((y) => y.chainId === i.chainId)) == null ? void 0 : _a.status) !== "connected" && i.status === "connected") {
2424
- (_c = args == null ? void 0 : args.onConnect) == null ? void 0 : _c.call(args, {
2425
- account: i.account,
2426
- chainId: i.chainId,
2427
- status: i.status,
2428
- isReconnect: ((_b = prevStat == null ? void 0 : prevStat.find((j) => j.chainId === i.chainId)) == null ? void 0 : _b.status) === "reconnecting"
2429
- });
2430
- }
2431
- if (i.status === "disconnected") {
2432
- (_d = args == null ? void 0 : args.onDisconnect) == null ? void 0 : _d.call(args);
2433
- }
2434
- });
2435
- }
2436
- );
2437
- }, [args, args == null ? void 0 : args.onConnect, args == null ? void 0 : args.onDisconnect]);
2438
- const res = (0, import_react.useMemo)(() => {
2439
- if (args == null ? void 0 : args.chainId) {
2440
- const singleChainRes = sessions == null ? void 0 : sessions.find((i) => i.chainId === args.chainId);
2441
- return {
2442
- data: singleChainRes,
2443
- isConnected: Boolean(singleChainRes == null ? void 0 : singleChainRes.account),
2444
- isConnecting: (singleChainRes == null ? void 0 : singleChainRes.status) === "connecting",
2445
- isDisconnected: (singleChainRes == null ? void 0 : singleChainRes.status) === "disconnected",
2446
- isReconnecting: (singleChainRes == null ? void 0 : singleChainRes.status) === "reconnecting",
2447
- isLoading: (singleChainRes == null ? void 0 : singleChainRes.status) === "connecting" || status === "reconnecting",
2448
- status: singleChainRes == null ? void 0 : singleChainRes.status
2449
- };
2450
- }
2451
- if (!sessions)
2452
- return void 0;
2453
- const multiChainRes = {};
2454
- sessions.forEach((i) => {
2455
- multiChainRes[i.chainId] = {
2456
- data: i,
2457
- isConnected: Boolean(i.account),
2458
- isConnecting: i.status === "connecting",
2459
- isDisconnected: i.status === "disconnected",
2460
- isReconnecting: i.status === "reconnecting",
2461
- isLoading: i.status === "connecting" || status === "reconnecting",
2462
- status: i.status
2463
- };
2464
- });
2465
- return multiChainRes;
2466
- }, [args == null ? void 0 : args.chainId, sessions]);
2467
- return res;
2468
- };
2469
- var useConnect = ({ onError, onLoading, onSuccess } = {}) => {
2470
- const queryKey = ["USE_CONNECT", onError, onLoading, onSuccess];
2471
- const mutation = (0, import_react_query2.useMutation)(queryKey, connect, {
2472
- onError: (err, args) => Promise.resolve(onError == null ? void 0 : onError(err, args)),
2473
- onMutate: onLoading,
2474
- onSuccess: (connectResult) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(connectResult))
2475
- });
2476
- const { data: isSupported } = useCheckWallet();
2477
- return {
2478
- connect: (args) => mutation.mutate(args),
2479
- connectAsync: (args) => mutation.mutateAsync(args),
2480
- error: mutation.error,
2481
- isLoading: mutation.isLoading,
2482
- isSuccess: mutation.isSuccess,
2483
- isSupported: Boolean(isSupported),
2484
- status: mutation.status
2485
- };
2486
- };
2487
- var useDisconnect = ({ onError, onLoading, onSuccess } = {}) => {
2488
- const queryKey = ["USE_DISCONNECT", onError, onLoading, onSuccess];
2489
- const mutation = (0, import_react_query2.useMutation)(queryKey, disconnect, {
2490
- onError: (err) => Promise.resolve(onError == null ? void 0 : onError(err, void 0)),
2491
- onMutate: onLoading,
2492
- onSuccess: () => Promise.resolve(onSuccess == null ? void 0 : onSuccess(void 0))
2493
- });
2494
- return {
2495
- disconnect: (args) => mutation.mutate({
2496
- chainId: args == null ? void 0 : args.chainid
2497
- }),
2498
- disconnectAsync: (args) => mutation.mutateAsync({ chainId: args == null ? void 0 : args.chainid }),
2499
- error: mutation.error,
2500
- isLoading: mutation.isLoading,
2501
- isSuccess: mutation.isSuccess,
2502
- status: mutation.status
2503
- };
2504
- };
2505
- var useOfflineSigners = (args) => {
2506
- const accounts = useAccount();
2507
- const { data } = (0, import_react_query2.useQuery)(
2508
- ["OFFLINE_SIGNERS", { accounts }],
2509
- async () => {
2510
- if (!accounts)
2511
- return void 0;
2512
- const connectedChainIds = Object.values(accounts).map((i) => {
2513
- var _a;
2514
- return (_a = i.data) == null ? void 0 : _a.chainId;
2515
- }).filter((i) => i);
2516
- const res = {};
2517
- await Promise.all(
2518
- connectedChainIds.map(async (_chainId) => {
2519
- const signers = await getOfflineSigners({
2520
- chainId: _chainId
2521
- });
2522
- res[_chainId] = signers;
2523
- })
2524
- );
2525
- return res;
2526
- },
2527
- {
2528
- enabled: Boolean(accounts)
2529
- }
2530
- );
2531
- const query = (0, import_react_query2.useQuery)(
2532
- [
2533
- "USE_OFFLINE_SIGNERS",
2534
- {
2535
- args,
2536
- offlineSigners: data
2537
- }
2538
- ],
2539
- async () => {
2540
- if (!data)
2541
- return void 0;
2542
- const connectedChainIds = Object.keys(data).map(([chainId]) => chainId).filter((i) => i);
2543
- if (args == null ? void 0 : args.chainId) {
2544
- const offlineSigners = await getOfflineSigners({
2545
- chainId: args.chainId
2546
- });
2547
- return offlineSigners;
2548
- }
2549
- const res = {};
2550
- await Promise.all(
2551
- connectedChainIds.map(async (_chainId) => {
2552
- const signers = await getOfflineSigners({
2553
- chainId: _chainId
2554
- });
2555
- res[_chainId] = signers;
2556
- })
2557
- );
2558
- return res;
2559
- },
2560
- { enabled: Boolean(data), refetchOnMount: false, refetchOnWindowFocus: false }
2561
- );
2562
- return query;
2563
- };
2564
-
2565
- // src/hooks/chains.ts
2566
- var import_react_query3 = require("@tanstack/react-query");
2567
- var useActiveChainValidators = (queryClient2, status2 = "BOND_STATUS_BONDED") => {
2568
- const queryKey = ["USE_ACTIVE_CHAIN_VALIDATORS", queryClient2, status2];
2569
- const query = (0, import_react_query3.useQuery)(
2570
- queryKey,
2571
- ({ queryKey: [, _queryClient, _status] }) => {
2572
- return _queryClient.staking.validators(_status);
2573
- },
2574
- {
2575
- enabled: typeof queryClient2 !== "undefined"
2576
- }
2577
- );
2578
- return query;
2579
- };
2580
- var useRecentChain = () => {
2581
- const recentChains = useGrazInternalStore((x) => x.recentChains);
2582
- return { data: recentChains, clear: clearRecentChain };
2583
- };
2584
- var useSuggestChain = ({ onError, onLoading, onSuccess } = {}) => {
2585
- const queryKey = ["USE_SUGGEST_CHAIN", onError, onLoading, onSuccess];
2586
- const mutation = (0, import_react_query3.useMutation)(queryKey, suggestChain, {
2587
- onError: (err, chainInfo) => Promise.resolve(onError == null ? void 0 : onError(err, chainInfo)),
2588
- onMutate: onLoading,
2589
- onSuccess: (chainInfo) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(chainInfo))
2590
- });
2591
- return {
2592
- error: mutation.error,
2593
- isLoading: mutation.isLoading,
2594
- isSuccess: mutation.isSuccess,
2595
- suggest: mutation.mutate,
2596
- suggestAsync: mutation.mutateAsync,
2597
- status: mutation.status
2598
- };
2599
- };
2600
- var useSuggestChainAndConnect = ({ onError, onLoading, onSuccess } = {}) => {
2601
- const queryKey = ["USE_SUGGEST_CHAIN_AND_CONNECT", onError, onLoading, onSuccess];
2602
- const mutation = (0, import_react_query3.useMutation)(queryKey, suggestChainAndConnect, {
2603
- onError: (err, args) => Promise.resolve(onError == null ? void 0 : onError(err, args)),
2604
- onMutate: (args) => onLoading == null ? void 0 : onLoading(args),
2605
- onSuccess: (res) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(res))
2606
- });
2607
- const { data: isSupported } = useCheckWallet();
2608
- return {
2609
- error: mutation.error,
2610
- isLoading: mutation.isLoading,
2611
- isSuccess: mutation.isSuccess,
2612
- isSupported: Boolean(isSupported),
2613
- status: mutation.status,
2614
- suggestAndConnect: mutation.mutate,
2615
- suggestAndConnectAsync: mutation.mutateAsync
2616
- };
2617
- };
2618
-
2619
- // src/hooks/clients.ts
2620
- var import_stargate2 = require("@cosmjs/stargate");
2621
- var import_react_query4 = require("@tanstack/react-query");
2622
- var useConnectClient = (args) => {
2623
- var _a;
2624
- const _client = (args == null ? void 0 : args.client) ?? useGrazInternalStore.getState().defaultClient;
2625
- const _chains = useGrazInternalStore.getState().chains;
2626
- const sessionChainIds = (_a = useGrazSessionStore.getState().sessions) == null ? void 0 : _a.map((i) => i.chainId);
2627
- const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === (args == null ? void 0 : args.chainId));
2628
- const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
2629
- const chains = (args == null ? void 0 : args.onlyConnectedChains) ? sessionChains : _chains;
2630
- const query = (0, import_react_query4.useQuery)(
2631
- [
2632
- "USE_CLIENTS",
2633
- {
2634
- client: _client,
2635
- chainId: args == null ? void 0 : args.chainId,
2636
- onlyConnectedChains: args == null ? void 0 : args.onlyConnectedChains
2637
- }
2638
- ],
2639
- async () => {
2640
- if (singleChain) {
2641
- const client = await connectClient({
2642
- client: _client,
2643
- rpc: singleChain.rpc,
2644
- rpcHeaders: singleChain.rpcHeaders
2645
- });
2646
- return client;
2647
- }
2648
- const res = {};
2649
- if (!chains)
2650
- return void 0;
2651
- await Promise.all(
2652
- chains.map(async (chain) => {
2653
- const client = await connectClient({
2654
- client: _client,
2655
- rpc: chain.rpc,
2656
- rpcHeaders: chain.rpcHeaders
2657
- });
2658
- res[chain.chainId] = client;
2659
- })
2660
- );
2661
- return res;
2662
- },
2663
- {
2664
- enabled: (args == null ? void 0 : args.enabled) !== void 0 ? args.enabled && Boolean(_chains) : Boolean(_chains),
2665
- refetchOnMount: false,
2666
- refetchOnWindowFocus: false
2667
- }
2668
- );
2669
- return query;
2670
- };
2671
- var useConnectSigningClient = (args) => {
2672
- var _a;
2673
- const _client = (args == null ? void 0 : args.client) ?? useGrazInternalStore.getState().defaultClient;
2674
- const _chains = useGrazInternalStore.getState().chains;
2675
- const sessionChainIds = (_a = useGrazSessionStore.getState().sessions) == null ? void 0 : _a.map((i) => i.chainId);
2676
- const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === (args == null ? void 0 : args.chainId));
2677
- const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
2678
- const queryKey = [
2679
- "USE_SIGNING_CLIENTS",
2680
- { client: _client, chainId: args == null ? void 0 : args.chainId, options: args == null ? void 0 : args.options }
2681
- ];
2682
- const query = (0, import_react_query4.useQuery)(
2683
- queryKey,
2684
- async () => {
2685
- if (singleChain) {
2686
- const { offlineSignerAuto } = await getOfflineSigners({
2687
- chainId: singleChain.chainId
2688
- });
2689
- const gasPrice = singleChain.gas ? import_stargate2.GasPrice.fromString(`${singleChain.gas.price}${singleChain.gas.denom}`) : void 0;
2690
- const options = _client === "cosmWasm" ? { gasPrice, ...(args == null ? void 0 : args.options) || {} } : args == null ? void 0 : args.options;
2691
- const client = await connectSigningClient({
2692
- client: _client,
2693
- rpc: singleChain.rpc,
2694
- rpcHeaders: singleChain.rpcHeaders,
2695
- offlineSignerAuto,
2696
- options
2697
- });
2698
- return client;
2699
- }
2700
- const res = {};
2701
- if (!sessionChains)
2702
- return void 0;
2703
- await Promise.all(
2704
- sessionChains.map(async (chain) => {
2705
- var _a2, _b;
2706
- const { offlineSignerAuto } = await getOfflineSigners({ chainId: chain.chainId });
2707
- const gasPrice = chain.gas ? import_stargate2.GasPrice.fromString(`${chain.gas.price}${chain.gas.denom}`) : void 0;
2708
- const options = _client === "cosmWasm" ? (
2709
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2710
- // @ts-expect-error
2711
- { gasPrice, ...((_a2 = args == null ? void 0 : args.options) == null ? void 0 : _a2[chain.chainId]) || {} }
2712
- ) : (
2713
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2714
- // @ts-expect-error
2715
- (_b = args == null ? void 0 : args.options) == null ? void 0 : _b[chain.chainId]
2716
- );
2717
- const client = await connectSigningClient({
2718
- client: _client,
2719
- rpc: chain.rpc,
2720
- rpcHeaders: chain.rpcHeaders,
2721
- offlineSignerAuto,
2722
- options
2723
- });
2724
- res[chain.chainId] = client;
2725
- })
2726
- );
2727
- return res;
2728
- },
2729
- {
2730
- enabled: Boolean(_chains),
2731
- refetchOnMount: false,
2732
- refetchOnWindowFocus: false
2733
- }
2734
- );
2735
- return query;
2736
- };
2737
-
2738
- // src/hooks/methods.ts
2739
- var import_encoding2 = require("@cosmjs/encoding");
2740
- var import_react_query5 = require("@tanstack/react-query");
2741
- var useBalances = (args) => {
2742
- const _client = args.client ?? useGrazInternalStore.getState().defaultClient;
2743
- const _chains = useGrazInternalStore.getState().chains;
2744
- const { data: singleClient } = useConnectClient({
2745
- client: _client,
2746
- chainId: args.chainId,
2747
- enabled: Boolean(args.chainId)
2748
- });
2749
- const { data: multiClient } = useConnectClient({
2750
- client: _client,
2751
- enabled: !args.chainId
2752
- });
2753
- const query = (0, import_react_query5.useQuery)(
2754
- [
2755
- "USE_BALANCES",
2756
- {
2757
- singleClient,
2758
- multiClient,
2759
- ...args,
2760
- _chains
2761
- }
2762
- ],
2763
- async () => {
2764
- if (args.chainId && singleClient) {
2765
- const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
2766
- const res = await getBalances({
2767
- client: singleClient,
2768
- bech32Address: (0, import_encoding2.toBech32)(singleChain.bech32Config.bech32PrefixAccAddr, (0, import_encoding2.fromBech32)(args.bech32Address).data),
2769
- currencies: singleChain.currencies
2770
- });
2771
- return res;
2772
- }
2773
- if (!args.chainId && multiClient) {
2774
- const multiChain = Object.entries(multiClient);
2775
- const res = {};
2776
- await Promise.all(
2777
- multiChain.map(async ([chainId, client]) => {
2778
- const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
2779
- if (!chain)
2780
- return;
2781
- const _res = await getBalances({
2782
- client,
2783
- bech32Address: (0, import_encoding2.toBech32)(chain.bech32Config.bech32PrefixAccAddr, (0, import_encoding2.fromBech32)(args.bech32Address).data),
2784
- currencies: chain.currencies
2785
- });
2786
- res[chainId] = _res;
2787
- })
2788
- );
2789
- return res;
2790
- }
2791
- return void 0;
2792
- },
2793
- {
2794
- enabled: Boolean(args.bech32Address) && Boolean(_chains) && (Boolean(singleClient) || Boolean(multiClient)),
2795
- refetchOnMount: false,
2796
- refetchOnReconnect: true,
2797
- refetchOnWindowFocus: false
2798
- }
2799
- );
2800
- return query;
2801
- };
2802
- var useBalanceStaked = (args) => {
2803
- const _chains = useGrazInternalStore.getState().chains;
2804
- const { data: singleClient } = useConnectClient({
2805
- client: "stargate",
2806
- chainId: args.chainId,
2807
- enabled: Boolean(args.chainId)
2808
- });
2809
- const { data: multiClient } = useConnectClient({
2810
- client: "stargate",
2811
- enabled: !args.chainId
2812
- });
2813
- const query = (0, import_react_query5.useQuery)(
2814
- [
2815
- "USE_BALANCE_STAKED",
2816
- {
2817
- singleClient,
2818
- multiClient,
2819
- ...args,
2820
- _chains
2821
- }
2822
- ],
2823
- async () => {
2824
- if (args.chainId && singleClient) {
2825
- const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
2826
- if (!singleChain)
2827
- throw new Error(`${args.chainId} Chain not found`);
2828
- const res = await getBalanceStaked({
2829
- client: singleClient,
2830
- bech32Address: (0, import_encoding2.toBech32)(singleChain.bech32Config.bech32PrefixAccAddr, (0, import_encoding2.fromBech32)(args.bech32Address).data)
2831
- });
2832
- return res;
2833
- }
2834
- if (!args.chainId && multiClient) {
2835
- const multiChain = Object.entries(multiClient);
2836
- const res = {};
2837
- await Promise.all(
2838
- multiChain.map(async ([chainId, client]) => {
2839
- const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
2840
- if (!chain)
2841
- return;
2842
- const _res = await getBalanceStaked({
2843
- client,
2844
- bech32Address: (0, import_encoding2.toBech32)(chain.bech32Config.bech32PrefixAccAddr, (0, import_encoding2.fromBech32)(args.bech32Address).data)
2845
- });
2846
- res[chainId] = _res;
2847
- })
2848
- );
2849
- return res;
2850
- }
2851
- return void 0;
2852
- },
2853
- {
2854
- enabled: Boolean(args.bech32Address) && Boolean(_chains) && (Boolean(singleClient) || Boolean(multiClient)),
2855
- refetchOnMount: false,
2856
- refetchOnReconnect: true,
2857
- refetchOnWindowFocus: false
2858
- }
2859
- );
2860
- return query;
2861
- };
2862
- var useSendTokens = ({
2863
- signingClient,
2864
- signingClientOptions,
2865
- chainId,
2866
- onError,
2867
- onLoading,
2868
- onSuccess
2869
- }) => {
2870
- const _client = signingClient ?? useGrazInternalStore.getState().defaultSigningClient;
2871
- const { data: _signingClient } = useConnectSigningClient({
2872
- chainId,
2873
- client: _client,
2874
- options: signingClientOptions
2875
- });
2876
- const queryKey = ["USE_SEND_TOKENS", { onError, onLoading, onSuccess, chainId }];
2877
- const mutation = (0, import_react_query5.useMutation)(
2878
- queryKey,
2879
- async (args) => {
2880
- if (!_signingClient)
2881
- throw new Error("Signing client is not available");
2882
- const res = await sendTokens({ signingClient: _signingClient, ...args });
2883
- return res;
2884
- },
2885
- {
2886
- onError: (err, data) => Promise.resolve(onError == null ? void 0 : onError(err, data)),
2887
- onMutate: onLoading,
2888
- onSuccess: (txResponse) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(txResponse))
2889
- }
2890
- );
2891
- return {
2892
- error: mutation.error,
2893
- isLoading: mutation.isLoading,
2894
- isSuccess: mutation.isSuccess,
2895
- sendTokens: mutation.mutate,
2896
- sendTokensAsync: mutation.mutateAsync,
2897
- status: mutation.status
2898
- };
2899
- };
2900
-
2901
- // src/provider/events.tsx
2902
- var import_react2 = require("react");
2903
- var useGrazEvents = () => {
2904
- const isSessionActive = typeof window !== "undefined" && window.sessionStorage.getItem(RECONNECT_SESSION_KEY) === "Active";
2905
- const { _reconnect, _onReconnectFailed, _reconnectConnector } = useGrazInternalStore();
2906
- const { sessions, wcSignClient } = useGrazSessionStore();
2907
- (0, import_react2.useEffect)(() => {
2908
- if (_reconnectConnector) {
2909
- if (isSessionActive && Boolean(sessions)) {
2910
- void reconnect({
2911
- onError: _onReconnectFailed
2912
- });
2913
- } else if (!isSessionActive && _reconnect) {
2914
- void reconnect({
2915
- onError: _onReconnectFailed
2916
- });
2917
- }
2918
- }
2919
- }, []);
2920
- (0, import_react2.useEffect)(() => {
2921
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2922
- if (_reconnectConnector) {
2923
- if (_reconnectConnector === "keplr" /* KEPLR */) {
2924
- (_b = (_a = getKeplr()).subscription) == null ? void 0 : _b.call(_a, () => {
2925
- void reconnect({ onError: _onReconnectFailed });
2926
- });
2927
- }
2928
- if (_reconnectConnector === "cosmostation" /* COSMOSTATION */) {
2929
- (_d = (_c = getCosmostation()).subscription) == null ? void 0 : _d.call(_c, () => {
2930
- void reconnect({
2931
- onError: _onReconnectFailed
2932
- });
2933
- });
2934
- }
2935
- if (_reconnectConnector === "leap" /* LEAP */) {
2936
- (_f = (_e = getLeap()).subscription) == null ? void 0 : _f.call(_e, () => {
2937
- void reconnect({ onError: _onReconnectFailed });
2938
- });
2939
- }
2940
- if (_reconnectConnector === "vectis" /* VECTIS */) {
2941
- (_h = (_g = getVectis()).subscription) == null ? void 0 : _h.call(_g, () => {
2942
- void reconnect({ onError: _onReconnectFailed });
2943
- });
2944
- }
2945
- if (_reconnectConnector === "walletconnect" /* WALLETCONNECT */) {
2946
- if (wcSignClient) {
2947
- (_j = (_i = getWalletConnect()).subscription) == null ? void 0 : _j.call(_i, () => {
2948
- void reconnect({ onError: _onReconnectFailed });
2949
- });
2950
- }
2951
- }
2952
- }
2953
- }, [_reconnectConnector, wcSignClient]);
2954
- return null;
2955
- };
2956
- var GrazEvents = () => {
2957
- useGrazEvents();
2958
- return null;
2959
- };
2960
-
2961
- // src/provider/index.tsx
2962
- var import_react_query6 = require("@tanstack/react-query");
2963
-
2964
- // src/provider/client-only.tsx
2965
- var import_react3 = require("react");
2966
- var import_jsx_runtime = require("react/jsx-runtime");
2967
- var ClientOnly = ({ children }) => {
2968
- const [isHydrated, setIsHydrated] = (0, import_react3.useState)(false);
2969
- (0, import_react3.useEffect)(() => {
2970
- setIsHydrated(true);
2971
- }, []);
2972
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: isHydrated ? children : null });
2973
- };
2974
-
2975
- // src/provider/index.tsx
2976
- var import_jsx_runtime2 = require("react/jsx-runtime");
2977
- var queryClient = new import_react_query6.QueryClient({
2978
- //
2979
- });
2980
- var GrazProvider = ({ children, grazConfig, ...props }) => {
2981
- configureGraz(grazConfig);
2982
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_query6.QueryClientProvider, { client: queryClient, ...props, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(ClientOnly, { children: [
2983
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GrazEvents, {}),
2984
- children
2985
- ] }) }, "graz-provider");
2986
- };
2987
- // Annotate the CommonJS export names for ESM import in node:
2988
- 0 && (module.exports = {
2989
- GrazEvents,
2990
- GrazProvider,
2991
- WALLET_TYPES,
2992
- WalletType,
2993
- checkWallet,
2994
- clearRecentChain,
2995
- configureGraz,
2996
- connect,
2997
- connectClient,
2998
- connectSigningClient,
2999
- defineChain,
3000
- defineChainInfo,
3001
- defineChains,
3002
- disconnect,
3003
- executeContract,
3004
- getAvailableWallets,
3005
- getBalanceStaked,
3006
- getBalances,
3007
- getCosmostation,
3008
- getKeplr,
3009
- getLeap,
3010
- getOfflineSigners,
3011
- getQueryRaw,
3012
- getQuerySmart,
3013
- getRecentChains,
3014
- getVectis,
3015
- getWCCosmostation,
3016
- getWCKeplr,
3017
- getWCLeap,
3018
- getWallet,
3019
- getWalletConnect,
3020
- instantiateContract,
3021
- mainnetChains,
3022
- mainnetChainsArray,
3023
- reconnect,
3024
- sendIbcTokens,
3025
- sendTokens,
3026
- suggestChain,
3027
- suggestChainAndConnect,
3028
- testnetChains,
3029
- testnetChainsArray,
3030
- useAccount,
3031
- useActiveChainValidators,
3032
- useActiveWalletType,
3033
- useBalanceStaked,
3034
- useBalances,
3035
- useCheckWallet,
3036
- useConnect,
3037
- useConnectClient,
3038
- useConnectSigningClient,
3039
- useDisconnect,
3040
- useGrazEvents,
3041
- useOfflineSigners,
3042
- useRecentChain,
3043
- useSendTokens,
3044
- useSuggestChain,
3045
- useSuggestChainAndConnect
3046
- });
1
+ "use strict";var an=Object.create;var ae=Object.defineProperty;var cn=Object.getOwnPropertyDescriptor;var ln=Object.getOwnPropertyNames;var un=Object.getPrototypeOf,mn=Object.prototype.hasOwnProperty;var pn=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),gn=(t,e)=>{for(var n in e)ae(t,n,{get:e[n],enumerable:!0})},ut=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ln(e))!mn.call(t,o)&&o!==n&&ae(t,o,{get:()=>e[o],enumerable:!(r=cn(e,o))||r.enumerable});return t};var mt=(t,e,n)=>(n=t!=null?an(un(t)):{},ut(e||!t||!t.__esModule?ae(n,"default",{value:t,enumerable:!0}):n,t)),fn=t=>ut(ae({},"__esModule",{value:!0}),t);var It=pn((To,Et)=>{"use strict";Et.exports=w;var W=null;try{W=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}function w(t,e,n){this.low=t|0,this.high=e|0,this.unsigned=!!n}w.prototype.__isLong__;Object.defineProperty(w.prototype,"__isLong__",{value:!0});function _(t){return(t&&t.__isLong__)===!0}w.isLong=_;var gt={},ft={};function z(t,e){var n,r,o;return e?(t>>>=0,(o=0<=t&&t<256)&&(r=ft[t],r)?r:(n=S(t,(t|0)<0?-1:0,!0),o&&(ft[t]=n),n)):(t|=0,(o=-128<=t&&t<128)&&(r=gt[t],r)?r:(n=S(t,t<0?-1:0,!1),o&&(gt[t]=n),n))}w.fromInt=z;function k(t,e){if(isNaN(t))return e?j:F;if(e){if(t<0)return j;if(t>=Ct)return At}else{if(t<=-dt)return O;if(t+1>=dt)return St}return t<0?k(-t,e).neg():S(t%$|0,t/$|0,e)}w.fromNumber=k;function S(t,e,n){return new w(t,e,n)}w.fromBits=S;var ce=Math.pow;function _e(t,e,n){if(t.length===0)throw Error("empty string");if(t==="NaN"||t==="Infinity"||t==="+Infinity"||t==="-Infinity")return F;if(typeof e=="number"?(n=e,e=!1):e=!!e,n=n||10,n<2||36<n)throw RangeError("radix");var r;if((r=t.indexOf("-"))>0)throw Error("interior hyphen");if(r===0)return _e(t.substring(1),e,n).neg();for(var o=k(ce(n,8)),i=F,s=0;s<t.length;s+=8){var a=Math.min(8,t.length-s),c=parseInt(t.substring(s,s+a),n);if(a<8){var p=k(ce(n,a));i=i.mul(p).add(k(c))}else i=i.mul(o),i=i.add(k(c))}return i.unsigned=e,i}w.fromString=_e;function D(t,e){return typeof t=="number"?k(t,e):typeof t=="string"?_e(t,e):S(t.low,t.high,typeof e=="boolean"?e:t.unsigned)}w.fromValue=D;var ht=65536,Cn=1<<24,$=ht*ht,Ct=$*$,dt=Ct/2,yt=z(Cn),F=z(0);w.ZERO=F;var j=z(0,!0);w.UZERO=j;var V=z(1);w.ONE=V;var wt=z(1,!0);w.UONE=wt;var Oe=z(-1);w.NEG_ONE=Oe;var St=S(-1,2147483647,!1);w.MAX_VALUE=St;var At=S(-1,-1,!0);w.MAX_UNSIGNED_VALUE=At;var O=S(0,-2147483648,!1);w.MIN_VALUE=O;var l=w.prototype;l.toInt=function(){return this.unsigned?this.low>>>0:this.low};l.toNumber=function(){return this.unsigned?(this.high>>>0)*$+(this.low>>>0):this.high*$+(this.low>>>0)};l.toString=function(e){if(e=e||10,e<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative())if(this.eq(O)){var n=k(e),r=this.div(n),o=r.mul(n).sub(this);return r.toString(e)+o.toInt().toString(e)}else return"-"+this.neg().toString(e);for(var i=k(ce(e,6),this.unsigned),s=this,a="";;){var c=s.div(i),p=s.sub(c.mul(i)).toInt()>>>0,d=p.toString(e);if(s=c,s.isZero())return d+a;for(;d.length<6;)d="0"+d;a=""+d+a}};l.getHighBits=function(){return this.high};l.getHighBitsUnsigned=function(){return this.high>>>0};l.getLowBits=function(){return this.low};l.getLowBitsUnsigned=function(){return this.low>>>0};l.getNumBitsAbs=function(){if(this.isNegative())return this.eq(O)?64:this.neg().getNumBitsAbs();for(var e=this.high!=0?this.high:this.low,n=31;n>0&&!(e&1<<n);n--);return this.high!=0?n+33:n+1};l.isZero=function(){return this.high===0&&this.low===0};l.eqz=l.isZero;l.isNegative=function(){return!this.unsigned&&this.high<0};l.isPositive=function(){return this.unsigned||this.high>=0};l.isOdd=function(){return(this.low&1)===1};l.isEven=function(){return(this.low&1)===0};l.equals=function(e){return _(e)||(e=D(e)),this.unsigned!==e.unsigned&&this.high>>>31===1&&e.high>>>31===1?!1:this.high===e.high&&this.low===e.low};l.eq=l.equals;l.notEquals=function(e){return!this.eq(e)};l.neq=l.notEquals;l.ne=l.notEquals;l.lessThan=function(e){return this.comp(e)<0};l.lt=l.lessThan;l.lessThanOrEqual=function(e){return this.comp(e)<=0};l.lte=l.lessThanOrEqual;l.le=l.lessThanOrEqual;l.greaterThan=function(e){return this.comp(e)>0};l.gt=l.greaterThan;l.greaterThanOrEqual=function(e){return this.comp(e)>=0};l.gte=l.greaterThanOrEqual;l.ge=l.greaterThanOrEqual;l.compare=function(e){if(_(e)||(e=D(e)),this.eq(e))return 0;var n=this.isNegative(),r=e.isNegative();return n&&!r?-1:!n&&r?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1};l.comp=l.compare;l.negate=function(){return!this.unsigned&&this.eq(O)?O:this.not().add(V)};l.neg=l.negate;l.add=function(e){_(e)||(e=D(e));var n=this.high>>>16,r=this.high&65535,o=this.low>>>16,i=this.low&65535,s=e.high>>>16,a=e.high&65535,c=e.low>>>16,p=e.low&65535,d=0,E=0,C=0,T=0;return T+=i+p,C+=T>>>16,T&=65535,C+=o+c,E+=C>>>16,C&=65535,E+=r+a,d+=E>>>16,E&=65535,d+=n+s,d&=65535,S(C<<16|T,d<<16|E,this.unsigned)};l.subtract=function(e){return _(e)||(e=D(e)),this.add(e.neg())};l.sub=l.subtract;l.multiply=function(e){if(this.isZero())return F;if(_(e)||(e=D(e)),W){var n=W.mul(this.low,this.high,e.low,e.high);return S(n,W.get_high(),this.unsigned)}if(e.isZero())return F;if(this.eq(O))return e.isOdd()?O:F;if(e.eq(O))return this.isOdd()?O:F;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(yt)&&e.lt(yt))return k(this.toNumber()*e.toNumber(),this.unsigned);var r=this.high>>>16,o=this.high&65535,i=this.low>>>16,s=this.low&65535,a=e.high>>>16,c=e.high&65535,p=e.low>>>16,d=e.low&65535,E=0,C=0,T=0,N=0;return N+=s*d,T+=N>>>16,N&=65535,T+=i*d,C+=T>>>16,T&=65535,T+=s*p,C+=T>>>16,T&=65535,C+=o*d,E+=C>>>16,C&=65535,C+=i*p,E+=C>>>16,C&=65535,C+=s*c,E+=C>>>16,C&=65535,E+=r*d+o*p+i*c+s*a,E&=65535,S(T<<16|N,E<<16|C,this.unsigned)};l.mul=l.multiply;l.divide=function(e){if(_(e)||(e=D(e)),e.isZero())throw Error("division by zero");if(W){if(!this.unsigned&&this.high===-2147483648&&e.low===-1&&e.high===-1)return this;var n=(this.unsigned?W.div_u:W.div_s)(this.low,this.high,e.low,e.high);return S(n,W.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?j:F;var r,o,i;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return j;if(e.gt(this.shru(1)))return wt;i=j}else{if(this.eq(O)){if(e.eq(V)||e.eq(Oe))return O;if(e.eq(O))return V;var s=this.shr(1);return r=s.div(e).shl(1),r.eq(F)?e.isNegative()?V:Oe:(o=this.sub(e.mul(r)),i=r.add(o.div(e)),i)}else if(e.eq(O))return this.unsigned?j:F;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();i=F}for(o=this;o.gte(e);){r=Math.max(1,Math.floor(o.toNumber()/e.toNumber()));for(var a=Math.ceil(Math.log(r)/Math.LN2),c=a<=48?1:ce(2,a-48),p=k(r),d=p.mul(e);d.isNegative()||d.gt(o);)r-=c,p=k(r,this.unsigned),d=p.mul(e);p.isZero()&&(p=V),i=i.add(p),o=o.sub(d)}return i};l.div=l.divide;l.modulo=function(e){if(_(e)||(e=D(e)),W){var n=(this.unsigned?W.rem_u:W.rem_s)(this.low,this.high,e.low,e.high);return S(n,W.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))};l.mod=l.modulo;l.rem=l.modulo;l.not=function(){return S(~this.low,~this.high,this.unsigned)};l.and=function(e){return _(e)||(e=D(e)),S(this.low&e.low,this.high&e.high,this.unsigned)};l.or=function(e){return _(e)||(e=D(e)),S(this.low|e.low,this.high|e.high,this.unsigned)};l.xor=function(e){return _(e)||(e=D(e)),S(this.low^e.low,this.high^e.high,this.unsigned)};l.shiftLeft=function(e){return _(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?S(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):S(0,this.low<<e-32,this.unsigned)};l.shl=l.shiftLeft;l.shiftRight=function(e){return _(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?S(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):S(this.high>>e-32,this.high>=0?0:-1,this.unsigned)};l.shr=l.shiftRight;l.shiftRightUnsigned=function(e){if(_(e)&&(e=e.toInt()),e&=63,e===0)return this;var n=this.high;if(e<32){var r=this.low;return S(r>>>e|n<<32-e,n>>>e,this.unsigned)}else return e===32?S(n,0,this.unsigned):S(n>>>e-32,0,this.unsigned)};l.shru=l.shiftRightUnsigned;l.shr_u=l.shiftRightUnsigned;l.toSigned=function(){return this.unsigned?S(this.low,this.high,!1):this};l.toUnsigned=function(){return this.unsigned?this:S(this.low,this.high,!0)};l.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()};l.toBytesLE=function(){var e=this.high,n=this.low;return[n&255,n>>>8&255,n>>>16&255,n>>>24,e&255,e>>>8&255,e>>>16&255,e>>>24]};l.toBytesBE=function(){var e=this.high,n=this.low;return[e>>>24,e>>>16&255,e>>>8&255,e&255,n>>>24,n>>>16&255,n>>>8&255,n&255]};w.fromBytes=function(e,n,r){return r?w.fromBytesLE(e,n):w.fromBytesBE(e,n)};w.fromBytesLE=function(e,n){return new w(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,n)};w.fromBytesBE=function(e,n){return new w(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],n)}});var ho={};gn(ho,{GrazEvents:()=>rt,GrazProvider:()=>fo,WALLET_TYPES:()=>xe,WalletType:()=>be,checkWallet:()=>x,clearRecentChain:()=>Me,configureGraz:()=>Ue,connect:()=>Z,defineChain:()=>Ln,defineChainInfo:()=>Pn,defineChains:()=>et,disconnect:()=>ge,executeContract:()=>Be,getActiveChainCurrency:()=>De,getAvailableWallets:()=>wn,getCosmostation:()=>me,getKeplr:()=>le,getLeap:()=>ue,getOfflineSigners:()=>Fe,getQueryRaw:()=>je,getQuerySmart:()=>Ge,getRecentChain:()=>Sn,getVectis:()=>pe,getWCCosmostation:()=>Nt,getWCKeplr:()=>Ot,getWCLeap:()=>_t,getWallet:()=>M,getWalletConnect:()=>Q,instantiateContract:()=>Pe,mainnetChains:()=>Bn,mainnetChainsArray:()=>Gn,reconnect:()=>R,sendIbcTokens:()=>Le,sendTokens:()=>qe,suggestChain:()=>fe,suggestChainAndConnect:()=>Re,testnetChains:()=>jn,testnetChainsArray:()=>zn,useAccount:()=>P,useActiveChain:()=>Yn,useActiveChainCurrency:()=>Xn,useActiveChainValidators:()=>Jn,useActiveWalletType:()=>Kn,useBalance:()=>Qn,useBalanceStaked:()=>Zn,useBalances:()=>tn,useCheckWallet:()=>te,useConnect:()=>Hn,useCosmWasmClient:()=>we,useCosmWasmSigningClient:()=>uo,useCosmWasmTmSigningClient:()=>po,useDisconnect:()=>Vn,useExecuteContract:()=>so,useGrazEvents:()=>on,useInstantiateContract:()=>io,useOfflineSigners:()=>$n,useQueryRaw:()=>co,useQuerySmart:()=>ao,useRecentChain:()=>eo,useSendIbcTokens:()=>ro,useSendTokens:()=>oo,useStargateClient:()=>Ce,useStargateSigningClient:()=>lo,useStargateTmSigningClient:()=>mo,useSuggestChain:()=>to,useSuggestChainAndConnect:()=>no,useTendermintClient:()=>Se});module.exports=fn(ho);var G="graz-reconnect-session";var ve=require("zustand"),pt=require("zustand/middleware"),H=require("zustand/middleware");var be=(c=>(c.KEPLR="keplr",c.LEAP="leap",c.VECTIS="vectis",c.COSMOSTATION="cosmostation",c.WALLETCONNECT="walletconnect",c.WC_KEPLR_MOBILE="wc_keplr_mobile",c.WC_LEAP_MOBILE="wc_leap_mobile",c.WC_COSMOSTATION_MOBILE="wc_cosmostation_mobile",c))(be||{}),xe=["keplr","leap","vectis","cosmostation","walletconnect","wc_keplr_mobile","wc_leap_mobile","wc_cosmostation_mobile"];var hn={recentChain:null,defaultChain:null,defaultSigningClient:"stargate",walletType:"keplr",walletConnect:{options:null,web3Modal:null},_notFoundFn:()=>null,_onReconnectFailed:()=>null,_reconnect:!1,_reconnectConnector:null},ee={account:null,activeChain:null,balances:null,status:"disconnected",wcSignClient:null},dn={name:"graz-session",version:1,partialize:t=>({account:t.account,activeChain:t.activeChain}),storage:(0,pt.createJSONStorage)(()=>sessionStorage)},yn={name:"graz-internal",partialize:t=>({recentChain:t.recentChain,_reconnect:t._reconnect,_reconnectConnector:t._reconnectConnector}),version:1},g=(0,ve.create)((0,H.subscribeWithSelector)((0,H.persist)(()=>ee,dn))),h=(0,ve.create)((0,H.subscribeWithSelector)((0,H.persist)(()=>hn,yn)));var We=require("@cosmjs/encoding"),xt=require("@walletconnect/sign-client"),vt=require("@walletconnect/utils"),ke=mt(It());var K=()=>typeof window<"u"?!!(window.matchMedia("(pointer:coarse)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|Opera Mini/u.test(navigator.userAgent)):!1,Tt=()=>K()&&navigator.userAgent.toLowerCase().includes("android"),bt=()=>K()&&(navigator.userAgent.toLowerCase().includes("iphone")||navigator.userAgent.toLowerCase().includes("ipad"));var Ne=(t,e,n=new Error("Promise timed out"))=>{let r=new Promise((o,i)=>{setTimeout(()=>{i(n)},e)});return Promise.race([t,r])};var x=(t=h.getState().walletType)=>{try{return M(t),!0}catch{return!1}},q=()=>{window.sessionStorage.removeItem(G),g.setState(ee)},le=()=>{if(typeof window.keplr<"u"){let t=window.keplr;return Object.assign(t,{subscription:r=>(window.addEventListener("keplr_keystorechange",()=>{q(),r()}),()=>{window.removeEventListener("keplr_keystorechange",()=>{q(),r()})})})}throw h.getState()._notFoundFn(),new Error("window.keplr is not defined")},ue=()=>{if(typeof window.leap<"u"){let t=window.leap;return Object.assign(t,{subscription:r=>(window.addEventListener("leap_keystorechange",()=>{q(),r()}),()=>{window.removeEventListener("leap_keystorechange",()=>{q(),r()})})})}throw h.getState()._notFoundFn(),new Error("window.leap is not defined")},me=()=>{if(typeof window.cosmostation.providers.keplr<"u"){let t=window.cosmostation.providers.keplr;return Object.assign(t,{subscription:r=>(window.cosmostation.cosmos.on("accountChanged",()=>{q(),r()}),()=>{window.cosmostation.cosmos.off("accountChanged",()=>{q(),r()})})})}throw h.getState()._notFoundFn(),new Error("window.cosmostation.providers.keplr is not defined")},pe=()=>{if(typeof window.vectis<"u"){let t=window.vectis.cosmos;return{enable:a=>t.enable(a),getOfflineSigner:a=>t.getOfflineSigner(a),getOfflineSignerAuto:a=>t.getOfflineSignerAuto(a),getKey:async a=>{let c=await t.getKey(a);return{address:(0,We.fromBech32)(c.address).data,algo:c.algo,bech32Address:c.address,name:c.name,pubKey:c.pubKey,isKeystone:!1,isNanoLedger:c.isNanoLedger}},subscription:a=>(window.addEventListener("vectis_accountChanged",()=>{q(),a()}),()=>{window.removeEventListener("vectis_accountChanged",()=>{q(),a()})}),getOfflineSignerOnlyAmino:(...a)=>t.getOfflineSignerAmino(...a),experimentalSuggestChain:async(...a)=>{let[c]=a,p={...c,rpcUrl:c.rpc,restUrl:c.rest,prettyName:c.chainName.replace(" ",""),bech32Prefix:c.bech32Config.bech32PrefixAccAddr};return t.suggestChains([p])},signDirect:async(...a)=>{var d;let{1:c,2:p}=a;return t.signDirect(c,{bodyBytes:p.bodyBytes||Uint8Array.from([]),authInfoBytes:p.authInfoBytes||Uint8Array.from([]),accountNumber:ke.default.fromString(((d=p.accountNumber)==null?void 0:d.toString())||"",!1),chainId:p.chainId||""})},signAmino:async(...a)=>{let{1:c,2:p}=a;return t.signAmino(c,p)}}}throw h.getState()._notFoundFn(),new Error("window.vectis is not defined")},Q=t=>{var st,at,ct;if(!((ct=(at=(st=h.getState().walletConnect)==null?void 0:st.options)==null?void 0:at.projectId)!=null&&ct.trim()))throw new Error("walletConnect.options.projectId is not defined");let e=(t==null?void 0:t.encoding)||"base64",n=m=>{if(!t)return;let{appUrl:u,formatNativeUrl:f}=t;if(K()){if(Tt())if(!m)window.open(u.mobile.android,"_self","noreferrer noopener");else{let y=f(u.mobile.android,m,"android");window.open(y,"_self","noreferrer noopener")}if(bt())if(!m)window.open(u.mobile.ios,"_self","noreferrer noopener");else{let y=f(u.mobile.ios,m,"ios");window.open(y,"_self","noreferrer noopener")}}},r=()=>{let{wcSignClient:m}=g.getState();if(!m)throw new Error("walletConnect.signClient is not defined");q(),h.setState({_reconnect:!1,_reconnectConnector:null,recentChain:null})},o=async m=>{let{wcSignClient:u}=g.getState();if(!u)throw new Error("walletConnect.signClient is not defined");if(!m)throw new Error("No wallet connect session");await u.disconnect({topic:m,reason:(0,vt.getSdkError)("USER_DISCONNECTED")}),await a(u),r()},i=m=>{var u,f;try{let{wcSignClient:y}=g.getState();if(!y)throw new Error("walletConnect.signClient is not defined");let A=y.session.getAll().at(-1);if(!A)return;let I=(f=(u=y.session.getAll().at(-1))==null?void 0:u.namespaces.cosmos)==null?void 0:f.accounts.find(b=>b.startsWith(`cosmos:${m}`));if(!(A.expiry*1e3>Date.now()+1e3))throw o(A.topic),new Error("invalid session");if(!I)try{let b=y.find({requiredNamespaces:{cosmos:{methods:["cosmos_getAccounts","cosmos_signAmino","cosmos_signDirect"],chains:[`cosmos:${m}`],events:["chainChanged","accountsChanged"]}}});if(!b.length)throw new Error("no session");return b.at(-1)}catch(b){if(!b.message.toLowerCase().includes("no matching key"))throw b}return A}catch(y){if(!y.message.toLowerCase().includes("no matching key"))throw y}},s=m=>{try{return i(m)}catch{return}},a=async m=>{try{let u=m.core.pairing.pairings.getAll({active:!1});if(!u.length)return;await Promise.all(u.map(async f=>{await m.core.pairing.pairings.delete(f.topic,{code:7001,message:"clear pairing"})}))}catch(u){if(!u.message.toLowerCase().includes("no matching key"))throw u}},c=async()=>{let{walletConnect:m}=h.getState();if(!(m!=null&&m.options))throw new Error("walletConnect.options is not defined");let{wcSignClient:u}=g.getState();if(u)return g.setState({wcSignClient:u}),u;let f=await xt.SignClient.init(m.options);return g.setState({wcSignClient:f}),f},p=m=>{let{wcSignClient:u}=g.getState();if(u)return u.events.on("session_delete",f=>{r()}),u.events.on("session_expire",f=>{r()}),u.events.on("session_event",f=>{var y,A;if(f.params.event.name==="accountsChanged"&&((y=f.params.event.data)==null?void 0:y[0])!==((A=g.getState().account)==null?void 0:A.bech32Address)){let I=f.params.chainId.split(":")[1];I&&d(I)}else m()}),()=>{u.events.off("session_delete",f=>{r()}),u.events.off("session_expire",f=>{r()}),u.events.off("session_event",f=>{var y,A;if(f.params.event.name==="accountsChanged"&&((y=f.params.event.data)==null?void 0:y[0])!==((A=g.getState().account)==null?void 0:A.bech32Address)){let I=f.params.chainId.split(":")[1];I&&d(I)}else m()})}},d=async m=>{var ie;let{wcSignClient:u}=g.getState();if(!u)throw new Error("enable walletConnect.signClient is not defined");let{walletConnect:f}=h.getState();if(!((ie=f==null?void 0:f.options)!=null&&ie.projectId))throw new Error("walletConnect.options.projectId is not defined");let{Web3Modal:y}=await import("@web3modal/standalone"),A=new y({projectId:f.options.projectId,walletConnectVersion:2,enableExplorer:!1,explorerRecommendedWalletIds:"NONE",...f.web3Modal}),{account:I,activeChain:U}=g.getState(),b=s(m);if((U==null?void 0:U.chainId)!==m&&!b||!I){let{uri:v,approval:se}=await u.connect({requiredNamespaces:{cosmos:{methods:["cosmos_getAccounts","cosmos_signAmino","cosmos_signDirect"],chains:[`cosmos:${m}`],events:["chainChanged","accountsChanged"]}}});if(!v)throw new Error("No wallet connect uri");t?n(v):await A.openModal({uri:v});try{await Ne((async()=>{await se()})(),4e4,new Error("Modal approval timeout"))}catch(lt){if(A.closeModal(),!lt.message.toLowerCase().includes("no matching key"))return Promise.reject(lt)}return t||A.closeModal(),Promise.resolve()}try{await Ne((async()=>{let v=await C(m);g.setState({account:v})})(),1e4,new Error("Connection timeout"))}catch(v){if(o(b==null?void 0:b.topic),!v.message.toLowerCase().includes("no matching key"))throw v}},E=async m=>{var A;let{wcSignClient:u}=g.getState();if(!u)throw new Error("walletConnect.signClient is not defined");let f=(A=i(m))==null?void 0:A.topic;if(!f)throw new Error("No wallet connect session");n();let y=await u.request({topic:f,chainId:`cosmos:${m}`,request:{method:"cosmos_getAccounts",params:{}}});if(!y[0])throw new Error("No wallet connect account");return{address:y[0].address,algo:y[0].algo,pubkey:new Uint8Array(Buffer.from(y[0].pubkey,e))}},C=async m=>{let{address:u,algo:f,pubkey:y}=await E(m);return{address:(0,We.fromBech32)(u).data,algo:f,bech32Address:u,name:"",pubKey:y,isKeystone:!1,isNanoLedger:!1}},T=async(...m)=>{var v,se;let[u,f,y]=m,{account:A,wcSignClient:I}=g.getState();if(!I)throw new Error("walletConnect.signClient is not defined");if(!A)throw new Error("account is not defined");let U=(v=i(u))==null?void 0:v.topic;if(!U)throw new Error("No wallet connect session");if(!y.bodyBytes)throw new Error("No bodyBytes");if(!y.authInfoBytes)throw new Error("No authInfoBytes");let b={topic:U,chainId:`cosmos:${u}`,request:{method:"cosmos_signDirect",params:{signerAddress:f,signDoc:{...y,bodyBytes:Buffer.from(y.bodyBytes).toString(e),authInfoBytes:Buffer.from(y.authInfoBytes).toString(e),accountNumber:(se=y.accountNumber)==null?void 0:se.toString()}}}};return n(),await I.request(b)},N=async(...m)=>{let[u,f,y]=m,{signature:A,signed:I}=await T(u,f,y);return{signed:{chainId:I.chainId,accountNumber:ke.default.fromString(I.accountNumber,!1),authInfoBytes:new Uint8Array(Buffer.from(I.authInfoBytes,e)),bodyBytes:new Uint8Array(Buffer.from(I.bodyBytes,e))},signature:A}},re=async(...m)=>{var v;let[u,f,y,A]=m,{wcSignClient:I}=g.getState(),{account:U}=g.getState();if(!I)throw new Error("walletConnect.signClient is not defined");if(!U)throw new Error("account is not defined");let b=(v=i(u))==null?void 0:v.topic;if(!b)throw new Error("No wallet connect session");return n(),await I.request({topic:b,chainId:`cosmos:${u}`,request:{method:"cosmos_signDirect",params:{signerAddress:f,signDoc:y}}})},Te=async(...m)=>{let[u,f,y,A]=m;return await re(u,f,y)},sn=m=>({getAccounts:async()=>[await E(m)],signDirect:(u,f)=>N(m,u,f)}),it=m=>({getAccounts:async()=>[await E(m)],signAmino:(u,f)=>Te(m,u,f)});return{enable:d,experimentalSuggestChain:async(...m)=>{await Promise.reject(new Error("WalletConnect does not support experimentalSuggestChain"))},getKey:C,getOfflineSigner:m=>({getAccounts:async()=>[await E(m)],signDirect:(u,f)=>N(m,u,f),signAmino:(u,f)=>Te(m,u,f)}),getOfflineSignerAuto:async m=>(await C(m)).isNanoLedger?it(m):sn(m),getOfflineSignerOnlyAmino:it,signAmino:Te,signDirect:N,subscription:p,init:c}},Ot=()=>{var e,n,r;if(!((r=(n=(e=h.getState().walletConnect)==null?void 0:e.options)==null?void 0:n.projectId)!=null&&r.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!K())throw new Error("WalletConnect Keplr mobile is only supported in mobile");let t={encoding:"base64",appUrl:{mobile:{ios:"keplrwallet://",android:"intent://"}},walletType:"wc_keplr_mobile",formatNativeUrl:(o,i,s)=>{let a=o.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(i);switch(s){case"ios":return`${a}://wcV2?${c}`;case"android":return`${a}://wcV2?${c}#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;`;default:return`${a}://wc?uri=${c}`}}};return Q(t)},_t=()=>{var e,n,r;if(!((r=(n=(e=h.getState().walletConnect)==null?void 0:e.options)==null?void 0:n.projectId)!=null&&r.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!K())throw new Error("WalletConnect Leap mobile is only supported in mobile");let t={encoding:"base64",appUrl:{mobile:{ios:"leapcosmos://",android:"intent://"}},walletType:"wc_leap_mobile",formatNativeUrl:(o,i,s)=>{let a=o.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(i);switch(s){case"ios":return`${a}://wcV2?${c}`;case"android":return`${a}://wcV2?${c}#Intent;package=io.leapwallet.cosmos;scheme=leapwallet;end;`;default:return`${a}://wc?uri=${c}`}}};return Q(t)},Nt=()=>{var e,n,r;if(!((r=(n=(e=h.getState().walletConnect)==null?void 0:e.options)==null?void 0:n.projectId)!=null&&r.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!K())throw new Error("WalletConnect Leap mobile is only supported in mobile");let t={encoding:"hex",appUrl:{mobile:{ios:"cosmostation://",android:"cosmostation://"}},walletType:"wc_leap_mobile",formatNativeUrl:(o,i,s)=>`${o.replaceAll("/","").replaceAll(":","")}://wc?${i}`};return Q(t)},M=(t=h.getState().walletType)=>{switch(t){case"keplr":return le();case"leap":return ue();case"cosmostation":return me();case"vectis":return pe();case"walletconnect":return Q();case"wc_keplr_mobile":return Ot();case"wc_leap_mobile":return _t();case"wc_cosmostation_mobile":return Nt();default:throw new Error("Unknown wallet type")}},wn=()=>Object.fromEntries(xe.map(t=>[t,x(t)]));var Z=async t=>{var e;try{let{defaultChain:n,recentChain:r,walletType:o}=h.getState(),i=(t==null?void 0:t.walletType)||o;if(!x(i))throw new Error(`${i} is not available`);let a=M(i),c=(t==null?void 0:t.chain)||r||n;if(!c)throw new Error("No last known connected chain, connect action requires chain info");g.setState(C=>{let T=h.getState()._reconnect||!!h.getState()._reconnectConnector||!!c;return C.activeChain&&C.activeChain.chainId!==c.chainId?{status:"connecting"}:T?{status:"reconnecting"}:{status:"connecting"}});let{account:p,activeChain:d}=g.getState();if(await((e=a.init)==null?void 0:e.call(a)),!p||(d==null?void 0:d.chainId)!==c.chainId){await a.enable(c.chainId);let C=await a.getKey(c.chainId);g.setState({account:C})}h.setState({recentChain:c,walletType:i,_reconnect:!!(t!=null&&t.autoReconnect),_reconnectConnector:i}),g.setState({activeChain:c,status:"connected"}),typeof window<"u"&&window.sessionStorage.setItem(G,"Active");let{account:E}=g.getState();return{account:E,walletType:i,chain:c}}catch(n){throw console.error("connect ",n),g.getState().account===null&&g.setState({status:"disconnected"}),g.getState().account&&g.getState().activeChain&&g.setState({status:"connected"}),n}},ge=async(t=!1)=>(typeof window<"u"&&window.sessionStorage.removeItem(G),g.setState(ee),h.setState(e=>({_reconnect:!1,_reconnectConnector:null,recentChain:t?null:e.recentChain})),Promise.resolve()),R=async t=>{var o;let{recentChain:e,_reconnectConnector:n,_reconnect:r}=h.getState();try{let i=x(n||void 0);if(e&&i&&n)return await Z({chain:e,walletType:n,autoReconnect:r})}catch(i){(o=t==null?void 0:t.onError)==null||o.call(t,i),ge()}},Fe=async t=>{if(!(t!=null&&t.chainId))throw new Error("chainId is required");let{walletType:e}=h.getState(),n=t.walletType||e;if(!x(n))throw new Error(`${n} is not available`);let o=M(n),i=o.getOfflineSigner(t.chainId),s=o.getOfflineSignerOnlyAmino(t.chainId),a=await o.getOfflineSignerAuto(t.chainId);return{offlineSigner:i,offlineSignerAmino:s,offlineSignerAuto:a}};var Me=()=>{h.setState({recentChain:null})},De=t=>{let{activeChain:e}=g.getState();return e==null?void 0:e.currencies.find(n=>n.coinMinimalDenom===t)},Sn=()=>h.getState().recentChain,fe=async t=>(await M().experimentalSuggestChain(t),t),Re=async({chainInfo:t,rpcHeaders:e,gas:n,path:r,...o})=>{let i=await fe(t);return{...await Z({chain:{chainId:t.chainId,currencies:t.currencies,rest:t.rest,rpc:t.rpc,rpcHeaders:e,gas:n,path:r},...o}),chain:i}};var Ue=(t={})=>(h.setState(e=>({defaultChain:t.defaultChain||e.defaultChain,defaultSigningClient:t.defaultSigningClient||e.defaultSigningClient,walletConnect:t.walletConnect||e.walletConnect,walletType:t.defaultWallet||e.walletType,_notFoundFn:t.onNotFound||e._notFoundFn,_onReconnectFailed:t.onReconnectFailed||e._onReconnectFailed,_reconnect:t.autoReconnect===void 0?!0:t.autoReconnect||e._reconnect})),t);var qe=async({signingClient:t,senderAddress:e,recipientAddress:n,amount:r,fee:o,memo:i})=>{if(!t)throw new Error("No connected account detected");if(!e)throw new Error("senderAddress is not defined");return t.sendTokens(e,n,r,o,i)},Le=async({signingClient:t,senderAddress:e,recipientAddress:n,transferAmount:r,sourcePort:o,sourceChannel:i,timeoutHeight:s,timeoutTimestamp:a,fee:c,memo:p})=>{if(!t)throw new Error("Stargate signing client is not ready");if(!e)throw new Error("senderAddress is not defined");return t.sendIbcTokens(e,n,r,o,i,s,a,c,p)},Pe=async({signingClient:t,senderAddress:e,msg:n,fee:r,options:o,label:i,codeId:s})=>{if(!t)throw new Error("CosmWasm signing client is not ready");return t.instantiate(e,s,n,i,r,o)},Be=async({signingClient:t,senderAddress:e,msg:n,fee:r,contractAddress:o,funds:i,memo:s})=>{if(!t)throw new Error("CosmWasm signing client is not ready");return t.execute(e,o,n,r,s,i)},Ge=async(t,e,n)=>{if(!n)throw new Error("CosmWasm client is not ready");return await n.queryContractSmart(t,e)},je=(t,e,n)=>{if(!n)throw new Error("CosmWasm client is not ready");let r=new TextEncoder().encode(e);return n.queryContractRaw(t,r)};var kt=require("@keplr-wallet/cosmos"),Ft={coinDenom:"axl",coinMinimalDenom:"uaxl",coinDecimals:6,coinGeckoId:"axelar-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axl.png"},An={coinDenom:"usdc",coinMinimalDenom:"uusdc",coinDecimals:6,coinGeckoId:"usd-coin",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/usdc.png"},En={coinDenom:"dai",coinMinimalDenom:"dai-wei",coinDecimals:18,coinGeckoId:"dai",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/dai.png"},In={coinDenom:"usdt",coinMinimalDenom:"uusdt",coinDecimals:6,coinGeckoId:"tether",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/usdt.png"},Tn={coinDenom:"weth-wei",coinMinimalDenom:"weth",coinDecimals:18,coinGeckoId:"weth",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/weth.png"},bn={coinDenom:"wbtc-satoshi",coinMinimalDenom:"wbtc",coinDecimals:8,coinGeckoId:"wrapped-bitcoin",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/wbtc.png"},Wt=[Ft,An,En,In,Tn,bn],ze={rpc:"https://rpc.axelar.strange.love",rest:"https://api.axelar.strange.love",chainId:"axelar-dojo-1",chainName:"Axelar",stakeCurrency:Ft,bip44:{coinType:118},bech32Config:kt.Bech32Address.defaultBech32Config("axelar"),currencies:Wt,feeCurrencies:Wt};var Dt=require("@keplr-wallet/cosmos"),Rt={coinDenom:"atom",coinMinimalDenom:"uatom",coinDecimals:6,coinGeckoId:"cosmos",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},Mt=[Rt],Ke={rpc:"https://rpc.cosmoshub.strange.love",rest:"https://api.cosmoshub.strange.love",chainId:"cosmoshub-4",chainName:"Cosmos Hub",stakeCurrency:Rt,bip44:{coinType:118},bech32Config:Dt.Bech32Address.defaultBech32Config("cosmos"),currencies:Mt,feeCurrencies:Mt};var qt=require("@keplr-wallet/cosmos"),Lt={coinDenom:"juno",coinMinimalDenom:"ujuno",coinDecimals:6,coinGeckoId:"juno-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"},xn={coinDenom:"neta",coinMinimalDenom:"cw20:juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr",coinDecimals:6,coinGeckoId:"neta",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/neta.png"},vn={coinDenom:"marble",coinMinimalDenom:"cw20:juno1g2g7ucurum66d42g8k5twk34yegdq8c82858gz0tq2fc75zy7khssgnhjl",coinDecimals:3,coinGeckoId:"marble",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/marble.png"},On={coinDenom:"hope",coinMinimalDenom:"cw20:juno1re3x67ppxap48ygndmrc7har2cnc7tcxtm9nplcas4v0gc3wnmvs3s807z",coinDecimals:6,coinGeckoId:"hope-galaxy",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hope.png"},_n={coinDenom:"rac",coinMinimalDenom:"cw20:juno1r4pzw8f9z0sypct5l9j906d47z998ulwvhvqe5xdwgy8wf84583sxwh0pa",coinDecimals:6,coinGeckoId:"racoon",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/rac.png"},Nn={coinDenom:"block",coinMinimalDenom:"cw20:juno1y9rf7ql6ffwkv02hsgd4yruz23pn4w97p75e2slsnkm0mnamhzysvqnxaq",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/block.png"},Wn={coinDenom:"dhk",coinMinimalDenom:"cw20:juno1tdjwrqmnztn2j3sj2ln9xnyps5hs48q3ddwjrz7jpv6mskappjys5czd49",coinDecimals:0,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/dhk.png"},kn={coinDenom:"raw",coinMinimalDenom:"cw20:juno15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hes5sn38g",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/raw.png",coinGeckoId:"junoswap-raw-dao"},Fn={coinDenom:"asvt",coinMinimalDenom:"cw20:juno17wzaxtfdw5em7lc94yed4ylgjme63eh73lm3lutp2rhcxttyvpwsypjm4w",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/asvt.png"},Mn={coinDenom:"hns",coinMinimalDenom:"cw20:juno1ur4jx0sxchdevahep7fwq28yk4tqsrhshdtylz46yka3uf6kky5qllqp4k",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hns.svg"},Dn={coinDenom:"joe",coinMinimalDenom:"cw20:juno1n7n7d5088qlzlj37e9mgmkhx6dfgtvt02hqxq66lcap4dxnzdhwqfmgng3",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/joe.png"},Ut=[Lt,xn,vn,On,_n,Nn,Wn,kn,Fn,Mn,Dn],Qe={rpc:"https://rpc.juno.strange.love",rest:"https://api.juno.strange.love",chainId:"juno-1",chainName:"Juno",stakeCurrency:Lt,bip44:{coinType:118},bech32Config:qt.Bech32Address.defaultBech32Config("juno"),currencies:Ut,feeCurrencies:Ut};var Bt=require("@keplr-wallet/cosmos"),Gt={coinDenom:"osmo",coinMinimalDenom:"uosmo",coinDecimals:6,coinGeckoId:"osmosis",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},Rn={coinDenom:"ion",coinMinimalDenom:"uion",coinDecimals:6,coinGeckoId:"ion",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/ion.png"},Pt=[Gt,Rn],He={rpc:"https://rpc.osmosis.strange.love",rest:"https://api.osmosis.strange.love",chainId:"osmosis-1",chainName:"Osmosis",stakeCurrency:Gt,bip44:{coinType:118},bech32Config:Bt.Bech32Address.defaultBech32Config("osmo"),currencies:Pt,feeCurrencies:Pt};var zt=require("@keplr-wallet/cosmos"),Kt={coinDenom:"somm",coinMinimalDenom:"usomm",coinDecimals:6,coinGeckoId:"sommelier",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/sommelier/images/somm.png"},jt=[Kt],Ve={rpc:"https://rpc.sommelier.strange.love",rest:"https://api.sommelier.strange.love",chainId:"sommelier-3",chainName:"Sommelier",stakeCurrency:Kt,bip44:{coinType:118},bech32Config:zt.Bech32Address.defaultBech32Config("somm"),currencies:jt,feeCurrencies:jt};var Ht=require("@keplr-wallet/cosmos"),Vt={coinDenom:"CRE",coinMinimalDenom:"ucre",coinDecimals:6,coinGeckoId:"crescent",coinImageUrl:"https://raw.githubusercontent.com/crescent-network/asset/main/images/coin/CRE.png"},Qt=[Vt],$e={rpc:"https://testnet-endpoint.crescent.network/rpc/crescent",rest:"https://testnet-endpoint.crescent.network/api/crescent",chainId:"mooncat-1-1",chainName:"Crescent Testnet",bip44:{coinType:118},bech32Config:Ht.Bech32Address.defaultBech32Config("CRE"),currencies:Qt,feeCurrencies:Qt,stakeCurrency:Vt,coinType:118};var $t=require("@keplr-wallet/cosmos"),Ze={coinDenom:"junox",coinMinimalDenom:"ujunox",coinDecimals:6,coinGeckoId:"juno-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"},Un=[Ze],Ye={rpc:"https://rpc.uni.junonetwork.io",rest:"https://api.uni.junonetwork.io",chainId:"uni-5",chainName:"Juno Testnet",stakeCurrency:Ze,bip44:{coinType:118},bech32Config:$t.Bech32Address.defaultBech32Config("juno"),currencies:Un,feeCurrencies:[Ze],coinType:118};var Zt=require("@keplr-wallet/cosmos"),Xe={coinDenom:"osmo",coinMinimalDenom:"uosmo",coinDecimals:6,coinGeckoId:"osmosis",coinImageUrl:"https://dhj8dql1kzq2v.cloudfront.net/white/osmo.png"},qn=[Xe],Je={rpc:"https://testnet-rpc.osmosis.zone",rest:"https://testnet-rest.osmosis.zone",chainId:"osmo-test-4",chainName:"Osmosis Testnet",stakeCurrency:Xe,bip44:{coinType:118},bech32Config:Zt.Bech32Address.defaultBech32Config("osmo"),currencies:qn,feeCurrencies:[Xe],coinType:118};var et=t=>t,Ln=t=>t,Pn=t=>t,Bn=et({axelar:ze,cosmoshub:Ke,juno:Qe,osmosis:He,sommelier:Ve}),Gn=[ze,Ke,Qe,He,Ve],jn=et({crescent:$e,juno:Ye,osmosis:Je}),zn=[$e,Ye,Je];var L=require("@tanstack/react-query"),Y=require("react");var Yt=require("@cosmjs/cosmwasm-stargate"),Xt=require("@cosmjs/stargate"),he=require("@cosmjs/tendermint-rpc"),de=require("@tanstack/react-query"),ye=require("react");var Ce=()=>{let t=g(n=>n.activeChain),e=(0,ye.useMemo)(()=>["USE_STARGATE_CLIENT",t],[t]);return(0,de.useQuery)({queryKey:e,queryFn:async({queryKey:[,n]})=>{if(!n)throw new Error("No chain found");let r={url:n.rpc,headers:{...n.rpcHeaders||{}}};return await Xt.StargateClient.connect(r)},enabled:!!t,refetchOnWindowFocus:!1})},we=()=>{let t=g(n=>n.activeChain),e=(0,ye.useMemo)(()=>["USE_COSMWASM_CLIENT",t],[t]);return(0,de.useQuery)({queryKey:e,queryFn:async({queryKey:[,n]})=>{if(!n)throw new Error("No chain found");let r={url:n.rpc,headers:{...n.rpcHeaders||{}}};return await Yt.CosmWasmClient.connect(r)},enabled:!!t,refetchOnWindowFocus:!1})},Se=t=>{let e=g(r=>r.activeChain),n=(0,ye.useMemo)(()=>["USE_TENDERMINT_CLIENT",t,e],[t,e]);return(0,de.useQuery)({queryKey:n,queryFn:async({queryKey:[,r,o]})=>{if(!o)throw new Error("No chain found");let i={url:o.rpc,headers:{...o.rpcHeaders||{}}};return await(r==="tm37"?he.Tendermint37Client:he.Tendermint34Client).connect(i)},enabled:!!e,refetchOnWindowFocus:!1})};var Jt=require("@tanstack/react-query"),en=require("zustand/shallow");var Kn=()=>h(t=>({walletType:t.walletType,isCosmostation:t.walletType==="cosmostation",isCosmostationMobile:t.walletType==="wc_cosmostation_mobile",isKeplr:t.walletType==="keplr",isKeplrMobile:t.walletType==="wc_keplr_mobile",isLeap:t.walletType==="leap",isLeapMobile:t.walletType==="wc_leap_mobile",isVectis:t.walletType==="vectis",isWalletConnect:t.walletType==="walletconnect"}),en.shallow),te=t=>{let n=["USE_CHECK_WALLET",h(o=>t||o.walletType)];return(0,Jt.useQuery)(n,({queryKey:[,o]})=>x(o))};var P=({onConnect:t,onDisconnect:e}={})=>{let n=g(o=>o.account),r=g(o=>o.status);return(0,Y.useEffect)(()=>g.subscribe(o=>o.status,(o,i)=>{if(o==="connected"){let{account:s,activeChain:a}=g.getState(),{walletType:c}=h.getState();t==null||t({account:s,chain:a,walletType:c,isReconnect:i==="reconnecting"})}o==="disconnected"&&(e==null||e())}),[t,e]),{data:n,isConnected:!!n,isConnecting:r==="connecting",isDisconnected:r==="disconnected",isReconnecting:r==="reconnecting",isLoading:r==="connecting"||r==="reconnecting",reconnect:R,status:r}},tn=t=>{let{data:e}=P(),{data:n}=Ce(),{activeChain:r}=g.getState(),o=t||(e==null?void 0:e.bech32Address),i=(0,Y.useMemo)(()=>["USE_ALL_BALANCES",n,r,o],[r,o,n]);return(0,L.useQuery)(i,async({queryKey:[,a,c,p]})=>{if(!c||!a)throw new Error("No connected account detected");if(!p)throw new Error("address is not defined");return await a.getAllBalances(p)},{enabled:!!o&&!!r&&!!n,refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})},Qn=(t,e)=>{let{data:n}=tn(e);return(0,L.useQuery)(["USE_BALANCE",n,t,e],({queryKey:[,i]})=>i==null?void 0:i.find(s=>s.denom===t),{enabled:!!n})},Hn=({onError:t,onLoading:e,onSuccess:n}={})=>{let o=(0,L.useMutation)(["USE_CONNECT",t,e,n],Z,{onError:(s,a)=>Promise.resolve(t==null?void 0:t(s,a)),onMutate:e,onSuccess:s=>Promise.resolve(n==null?void 0:n(s))}),{data:i}=te();return{connect:s=>o.mutate(s),connectAsync:s=>o.mutateAsync(s),error:o.error,isLoading:o.isLoading,isSuccess:o.isSuccess,isSupported:!!i,status:o.status}},Vn=({onError:t,onLoading:e,onSuccess:n}={})=>{let o=(0,L.useMutation)(["USE_DISCONNECT",t,e,n],ge,{onError:i=>Promise.resolve(t==null?void 0:t(i,void 0)),onMutate:e,onSuccess:()=>Promise.resolve(n==null?void 0:n(void 0))});return{disconnect:i=>o.mutate(i),disconnectAsync:i=>o.mutateAsync(i),error:o.error,isLoading:o.isLoading,isSuccess:o.isSuccess,status:o.status}},$n=()=>{let t=g(r=>r.activeChain),e=h(r=>r.walletType),n=(0,Y.useMemo)(()=>["USE_OFFLINE_SIGNERS",t,e],[t,e]);return(0,L.useQuery)({queryKey:n,queryFn:async({queryKey:[,r,o]})=>{if(!r)throw new Error("No chain found");if(!x(o))throw new Error(`${o} is not available`);return await Fe({chainId:r.chainId,walletType:o})},enabled:!!t&&!!e,refetchOnWindowFocus:!1})},Zn=t=>{let{data:e}=P(),{data:n}=Ce(),{activeChain:r}=g.getState(),o=t||(e==null?void 0:e.bech32Address),i=(0,Y.useMemo)(()=>["USE_BALANCE_STAKED",n,r,o],[r,o,n]);return(0,L.useQuery)(i,async({queryKey:[,a,c,p]})=>{if(!c||!a)throw new Error("No connected account detected");if(!p)throw new Error("address is not defined");return await a.getBalanceStaked(p)},{enabled:!!o&&!!r&&!!n,refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})};var X=require("@tanstack/react-query");var Yn=()=>g(t=>t.activeChain),Xn=t=>(0,X.useQuery)(["USE_ACTIVE_CHAIN_CURRENCY",t],({queryKey:[,r]})=>De(r)),Jn=(t,e="BOND_STATUS_BONDED")=>(0,X.useQuery)(["USE_ACTIVE_CHAIN_VALIDATORS",t,e],({queryKey:[,o,i]})=>o.staking.validators(i),{enabled:typeof t<"u"}),eo=()=>({data:h(e=>e.recentChain),clear:Me}),to=({onError:t,onLoading:e,onSuccess:n}={})=>{let o=(0,X.useMutation)(["USE_SUGGEST_CHAIN",t,e,n],fe,{onError:(i,s)=>Promise.resolve(t==null?void 0:t(i,s)),onMutate:e,onSuccess:i=>Promise.resolve(n==null?void 0:n(i))});return{error:o.error,isLoading:o.isLoading,isSuccess:o.isSuccess,suggest:o.mutate,suggestAsync:o.mutateAsync,status:o.status}},no=({onError:t,onLoading:e,onSuccess:n}={})=>{let o=(0,X.useMutation)(["USE_SUGGEST_CHAIN_AND_CONNECT",t,e,n],Re,{onError:(s,a)=>Promise.resolve(t==null?void 0:t(s,a)),onMutate:s=>e==null?void 0:e(s),onSuccess:s=>Promise.resolve(n==null?void 0:n(s))}),{data:i}=te();return{error:o.error,isLoading:o.isLoading,isSuccess:o.isSuccess,isSupported:!!i,status:o.status,suggestAndConnect:o.mutate,suggestAndConnectAsync:o.mutateAsync}};var B=require("@tanstack/react-query");var oo=({onError:t,onLoading:e,onSuccess:n}={})=>{let{data:r}=P(),o=r==null?void 0:r.bech32Address,i=(0,B.useMutation)(["USE_SEND_TOKENS",t,e,n,o],s=>qe({senderAddress:o,...s}),{onError:(s,a)=>Promise.resolve(t==null?void 0:t(s,a)),onMutate:e,onSuccess:s=>Promise.resolve(n==null?void 0:n(s))});return{error:i.error,isLoading:i.isLoading,isSuccess:i.isSuccess,sendTokens:i.mutate,sendTokensAsync:i.mutateAsync,status:i.status}},ro=({onError:t,onLoading:e,onSuccess:n}={})=>{let{data:r}=P(),o=r==null?void 0:r.bech32Address,i=(0,B.useMutation)(["USE_SEND_IBC_TOKENS",t,e,n,o],s=>Le({senderAddress:o,...s}),{onError:(s,a)=>Promise.resolve(t==null?void 0:t(s,a)),onMutate:e,onSuccess:s=>Promise.resolve(n==null?void 0:n(s))});return{error:i.error,isLoading:i.isLoading,isSuccess:i.isSuccess,sendIbcTokens:i.mutate,sendIbcTokensAsync:i.mutateAsync,status:i.status}},io=({codeId:t,onError:e,onLoading:n,onSuccess:r})=>{let{data:o}=P(),i=o==null?void 0:o.bech32Address,a=(0,B.useMutation)(["USE_INSTANTIATE_CONTRACT",e,n,r,t,i],c=>{if(!i)throw new Error("senderAddress is undefined");let p={...c,fee:c.fee??"auto",senderAddress:i,codeId:t};return Pe(p)},{onError:(c,p)=>Promise.resolve(e==null?void 0:e(c,p)),onMutate:n,onSuccess:c=>Promise.resolve(r==null?void 0:r(c))});return{error:a.error,isLoading:a.isLoading,isSuccess:a.isSuccess,instantiateContract:a.mutate,instantiateContractAsync:a.mutateAsync,status:a.status}},so=({contractAddress:t,onError:e,onLoading:n,onSuccess:r})=>{let{data:o}=P(),i=o==null?void 0:o.bech32Address,a=(0,B.useMutation)(["USE_EXECUTE_CONTRACT",e,n,r,t,i],c=>{if(!i)throw new Error("senderAddress is undefined");let p={...c,fee:c.fee??"auto",senderAddress:i,contractAddress:t,memo:c.memo??"",funds:c.funds??[]};return Be(p)},{onError:(c,p)=>Promise.resolve(e==null?void 0:e(c,p)),onMutate:n,onSuccess:c=>Promise.resolve(r==null?void 0:r(c))});return{error:a.error,isLoading:a.isLoading,isSuccess:a.isSuccess,executeContract:a.mutate,executeContractAsync:a.mutateAsync,status:a.status}},ao=(t,e)=>{let{data:n}=we();return(0,B.useQuery)(["USE_QUERY_SMART",t,e,n],({queryKey:[,o]})=>{if(!t||!e)throw new Error("address or queryMsg undefined");return Ge(t,e,n)},{enabled:!!t&&!!e&&!!n})},co=(t,e)=>{let{data:n}=we();return(0,B.useQuery)(["USE_QUERY_RAW",e,t,n],({queryKey:[,i]})=>{if(!t||!e)throw new Error("address or key undefined");return je(t,e,n)},{enabled:!!t&&!!e&&!!n})};var tt=require("@cosmjs/cosmwasm-stargate"),nt=require("@cosmjs/stargate"),ne=require("@tanstack/react-query"),oe=require("react");var lo=t=>{let e=g(o=>o.activeChain),n=h(o=>o.walletType),r=(0,oe.useMemo)(()=>["USE_STARGATE_SIGNING_CLIENT",e,n,t],[t,e,n]);return(0,ne.useQuery)({queryKey:r,queryFn:async({queryKey:[,o,i,s]})=>{if(!o)throw new Error("No chain found");if(!x(i))throw new Error(`${i} is not available`);let c=M(i).getOfflineSigner(o.chainId),p={url:o.rpc,headers:{...o.rpcHeaders||{}}};return await nt.SigningStargateClient.connectWithSigner(p,c,s==null?void 0:s.opts)},enabled:!!e&&!!n,refetchOnWindowFocus:!1})},uo=t=>{let e=g(o=>o.activeChain),n=h(o=>o.walletType),r=(0,oe.useMemo)(()=>["USE_COSMWASM_SIGNING_CLIENT",e,n,t],[t,e,n]);return(0,ne.useQuery)({queryKey:r,queryFn:async({queryKey:[,o,i,s]})=>{if(!o)throw new Error("No chain found");if(!x(i))throw new Error(`${i} is not available`);let c=M(i).getOfflineSigner(o.chainId),p={url:o.rpc,headers:{...o.rpcHeaders||{}}};return await tt.SigningCosmWasmClient.connectWithSigner(p,c,s==null?void 0:s.opts)},enabled:!!e&&!!n,refetchOnWindowFocus:!1})},mo=t=>{let e=g(i=>i.activeChain),n=h(i=>i.walletType),r=(0,oe.useMemo)(()=>["USE_STARGATE_TM_SIGNING_CLIENT",e,n,t],[t,e,n]),{data:o}=Se(t.type);return(0,ne.useQuery)({queryKey:r,queryFn:({queryKey:[,i,s,a]})=>{if(!i)throw new Error("No chain found");if(!x(s))throw new Error(`${s} is not available`);if(!o)throw new Error("No tendermint client found");let p=M(s).getOfflineSigner(i.chainId);return nt.SigningStargateClient.createWithSigner(o,p,a.opts)},enabled:!!e&&!!n&&!!o,refetchOnWindowFocus:!1})},po=t=>{let e=g(i=>i.activeChain),n=h(i=>i.walletType),r=(0,oe.useMemo)(()=>["USE_COSMWASM_TM_SIGNING_CLIENT",e,n,t],[t,e,n]),{data:o}=Se(t.type);return(0,ne.useQuery)({queryKey:r,queryFn:({queryKey:[,i,s,a]})=>{if(!i)throw new Error("No chain found");if(!x(s))throw new Error(`${s} is not available`);if(!o)throw new Error("No tendermint client found");let p=M(s).getOfflineSigner(i.chainId);return tt.SigningCosmWasmClient.createWithSigner(o,p,a.opts)},enabled:!!e&&!!n&&!!o,refetchOnWindowFocus:!1})};var Ie=require("@tanstack/react-query"),rn=require("@tanstack/react-query-devtools");var Ae=require("react"),Ee=require("react/jsx-runtime"),nn=({children:t})=>{let[e,n]=(0,Ae.useState)(!1);return(0,Ae.useEffect)(()=>{n(!0)},[]),(0,Ee.jsx)(Ee.Fragment,{children:e?t:null})};var ot=require("react");var on=()=>{let t=typeof window<"u"&&window.sessionStorage.getItem(G)==="Active",{_reconnect:e,_onReconnectFailed:n,_reconnectConnector:r}=h(),{activeChain:o,wcSignClient:i}=g();return(0,ot.useEffect)(()=>{r&&(t&&o?R({onError:n}):!t&&e&&R({onError:n}))},[]),(0,ot.useEffect)(()=>{var s,a,c,p,d,E,C,T,N,re;r&&(r==="cosmostation"&&((a=(s=me()).subscription)==null||a.call(s,()=>{R({onError:n})})),r==="keplr"&&((p=(c=le()).subscription)==null||p.call(c,()=>{R({onError:n})})),r==="leap"&&((E=(d=ue()).subscription)==null||E.call(d,()=>{R({onError:n})})),r==="vectis"&&((T=(C=pe()).subscription)==null||T.call(C,()=>{R({onError:n})})),r==="walletconnect"&&i&&((re=(N=Q()).subscription)==null||re.call(N,()=>{R({onError:n})})))},[r,i]),null},rt=()=>(on(),null);var J=require("react/jsx-runtime"),go=new Ie.QueryClient({}),fo=({children:t,grazOptions:e,debug:n,...r})=>(e&&Ue(e),(0,J.jsxs)(Ie.QueryClientProvider,{client:go,...r,children:[(0,J.jsxs)(nn,{children:[(0,J.jsx)(rt,{}),t]}),n?(0,J.jsx)(rn.ReactQueryDevtools,{initialIsOpen:!1,position:"bottom-right"}):null]},"graz-provider"));0&&(module.exports={GrazEvents,GrazProvider,WALLET_TYPES,WalletType,checkWallet,clearRecentChain,configureGraz,connect,defineChain,defineChainInfo,defineChains,disconnect,executeContract,getActiveChainCurrency,getAvailableWallets,getCosmostation,getKeplr,getLeap,getOfflineSigners,getQueryRaw,getQuerySmart,getRecentChain,getVectis,getWCCosmostation,getWCKeplr,getWCLeap,getWallet,getWalletConnect,instantiateContract,mainnetChains,mainnetChainsArray,reconnect,sendIbcTokens,sendTokens,suggestChain,suggestChainAndConnect,testnetChains,testnetChainsArray,useAccount,useActiveChain,useActiveChainCurrency,useActiveChainValidators,useActiveWalletType,useBalance,useBalanceStaked,useBalances,useCheckWallet,useConnect,useCosmWasmClient,useCosmWasmSigningClient,useCosmWasmTmSigningClient,useDisconnect,useExecuteContract,useGrazEvents,useInstantiateContract,useOfflineSigners,useQueryRaw,useQuerySmart,useRecentChain,useSendIbcTokens,useSendTokens,useStargateClient,useStargateSigningClient,useStargateTmSigningClient,useSuggestChain,useSuggestChainAndConnect,useTendermintClient});