@xchainjs/xchain-thorchain 0.28.0 → 0.28.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -4283,7 +4283,7 @@ const DEFAULT_EXPLORER_URL = 'https://viewblock.io/thorchain';
4283
4283
  const txUrl = `${DEFAULT_EXPLORER_URL}/tx`;
4284
4284
  const addressUrl = `${DEFAULT_EXPLORER_URL}/address`;
4285
4285
  const RUNE_TICKER = 'RUNE';
4286
- const DECIMAL = 8;
4286
+ const RUNE_DECIMAL = 8;
4287
4287
  const DEFAULT_GAS_ADJUSTMENT = 2;
4288
4288
  const DEFAULT_GAS_LIMIT_VALUE = '4000000';
4289
4289
  const DEPOSIT_GAS_LIMIT_VALUE = '600000000';
@@ -4358,205 +4358,239 @@ const AssetRuneERC20Testnet = {
4358
4358
  ticker: RUNE_TICKER,
4359
4359
  synth: false,
4360
4360
  };
4361
+ /**
4362
+ * Fall back node's and rpc's
4363
+ */
4364
+ const FallBackUrls = [
4365
+ {
4366
+ [lib.Network.Testnet]: {
4367
+ node: ['deprecated'],
4368
+ rpc: ['deprecated'],
4369
+ },
4370
+ [lib.Network.Stagenet]: {
4371
+ node: ['https://stagenet-thornode.ninerealms.com'],
4372
+ rpc: ['https://stagenet-rpc.ninerealms.com'],
4373
+ },
4374
+ [lib.Network.Mainnet]: {
4375
+ node: ['https://thornode-v1.ninerealms.com', 'https://thornode.thorswap.net/'],
4376
+ rpc: ['https://rpc-v1.ninerealms.com', 'https://rpc.thorswap.net'],
4377
+ },
4378
+ },
4379
+ ];
4361
4380
 
4362
4381
  var indexMinimal = {};
4363
4382
 
4364
4383
  var minimal$1 = {};
4365
4384
 
4366
- var aspromise = asPromise;
4367
-
4368
- /**
4369
- * Callback as used by {@link util.asPromise}.
4370
- * @typedef asPromiseCallback
4371
- * @type {function}
4372
- * @param {Error|null} error Error, if any
4373
- * @param {...*} params Additional arguments
4374
- * @returns {undefined}
4375
- */
4376
-
4377
- /**
4378
- * Returns a promise from a node-style callback function.
4379
- * @memberof util
4380
- * @param {asPromiseCallback} fn Function to call
4381
- * @param {*} ctx Function context
4382
- * @param {...*} params Function arguments
4383
- * @returns {Promise<*>} Promisified function
4384
- */
4385
- function asPromise(fn, ctx/*, varargs */) {
4386
- var params = new Array(arguments.length - 1),
4387
- offset = 0,
4388
- index = 2,
4389
- pending = true;
4390
- while (index < arguments.length)
4391
- params[offset++] = arguments[index++];
4392
- return new Promise(function executor(resolve, reject) {
4393
- params[offset] = function callback(err/*, varargs */) {
4394
- if (pending) {
4395
- pending = false;
4396
- if (err)
4397
- reject(err);
4398
- else {
4399
- var params = new Array(arguments.length - 1),
4400
- offset = 0;
4401
- while (offset < params.length)
4402
- params[offset++] = arguments[offset];
4403
- resolve.apply(null, params);
4404
- }
4405
- }
4406
- };
4407
- try {
4408
- fn.apply(ctx || null, params);
4409
- } catch (err) {
4410
- if (pending) {
4411
- pending = false;
4412
- reject(err);
4413
- }
4414
- }
4415
- });
4416
- }
4385
+ var aspromise;
4386
+ var hasRequiredAspromise;
4417
4387
 
4418
- var base64$1 = {};
4419
-
4420
- (function (exports) {
4388
+ function requireAspromise () {
4389
+ if (hasRequiredAspromise) return aspromise;
4390
+ hasRequiredAspromise = 1;
4391
+ aspromise = asPromise;
4421
4392
 
4422
4393
  /**
4423
- * A minimal base64 implementation for number arrays.
4424
- * @memberof util
4425
- * @namespace
4426
- */
4427
- var base64 = exports;
4428
-
4429
- /**
4430
- * Calculates the byte length of a base64 encoded string.
4431
- * @param {string} string Base64 encoded string
4432
- * @returns {number} Byte length
4433
- */
4434
- base64.length = function length(string) {
4435
- var p = string.length;
4436
- if (!p)
4437
- return 0;
4438
- var n = 0;
4439
- while (--p % 4 > 1 && string.charAt(p) === "=")
4440
- ++n;
4441
- return Math.ceil(string.length * 3) / 4 - n;
4442
- };
4443
-
4444
- // Base64 encoding table
4445
- var b64 = new Array(64);
4446
-
4447
- // Base64 decoding table
4448
- var s64 = new Array(123);
4449
-
4450
- // 65..90, 97..122, 48..57, 43, 47
4451
- for (var i = 0; i < 64;)
4452
- s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
4453
-
4454
- /**
4455
- * Encodes a buffer to a base64 encoded string.
4456
- * @param {Uint8Array} buffer Source buffer
4457
- * @param {number} start Source start
4458
- * @param {number} end Source end
4459
- * @returns {string} Base64 encoded string
4394
+ * Callback as used by {@link util.asPromise}.
4395
+ * @typedef asPromiseCallback
4396
+ * @type {function}
4397
+ * @param {Error|null} error Error, if any
4398
+ * @param {...*} params Additional arguments
4399
+ * @returns {undefined}
4460
4400
  */
4461
- base64.encode = function encode(buffer, start, end) {
4462
- var parts = null,
4463
- chunk = [];
4464
- var i = 0, // output index
4465
- j = 0, // goto index
4466
- t; // temporary
4467
- while (start < end) {
4468
- var b = buffer[start++];
4469
- switch (j) {
4470
- case 0:
4471
- chunk[i++] = b64[b >> 2];
4472
- t = (b & 3) << 4;
4473
- j = 1;
4474
- break;
4475
- case 1:
4476
- chunk[i++] = b64[t | b >> 4];
4477
- t = (b & 15) << 2;
4478
- j = 2;
4479
- break;
4480
- case 2:
4481
- chunk[i++] = b64[t | b >> 6];
4482
- chunk[i++] = b64[b & 63];
4483
- j = 0;
4484
- break;
4485
- }
4486
- if (i > 8191) {
4487
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
4488
- i = 0;
4489
- }
4490
- }
4491
- if (j) {
4492
- chunk[i++] = b64[t];
4493
- chunk[i++] = 61;
4494
- if (j === 1)
4495
- chunk[i++] = 61;
4496
- }
4497
- if (parts) {
4498
- if (i)
4499
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
4500
- return parts.join("");
4501
- }
4502
- return String.fromCharCode.apply(String, chunk.slice(0, i));
4503
- };
4504
-
4505
- var invalidEncoding = "invalid encoding";
4506
4401
 
4507
4402
  /**
4508
- * Decodes a base64 encoded string to a buffer.
4509
- * @param {string} string Source string
4510
- * @param {Uint8Array} buffer Destination buffer
4511
- * @param {number} offset Destination offset
4512
- * @returns {number} Number of bytes written
4513
- * @throws {Error} If encoding is invalid
4403
+ * Returns a promise from a node-style callback function.
4404
+ * @memberof util
4405
+ * @param {asPromiseCallback} fn Function to call
4406
+ * @param {*} ctx Function context
4407
+ * @param {...*} params Function arguments
4408
+ * @returns {Promise<*>} Promisified function
4514
4409
  */
4515
- base64.decode = function decode(string, buffer, offset) {
4516
- var start = offset;
4517
- var j = 0, // goto index
4518
- t; // temporary
4519
- for (var i = 0; i < string.length;) {
4520
- var c = string.charCodeAt(i++);
4521
- if (c === 61 && j > 1)
4522
- break;
4523
- if ((c = s64[c]) === undefined)
4524
- throw Error(invalidEncoding);
4525
- switch (j) {
4526
- case 0:
4527
- t = c;
4528
- j = 1;
4529
- break;
4530
- case 1:
4531
- buffer[offset++] = t << 2 | (c & 48) >> 4;
4532
- t = c;
4533
- j = 2;
4534
- break;
4535
- case 2:
4536
- buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
4537
- t = c;
4538
- j = 3;
4539
- break;
4540
- case 3:
4541
- buffer[offset++] = (t & 3) << 6 | c;
4542
- j = 0;
4543
- break;
4410
+ function asPromise(fn, ctx/*, varargs */) {
4411
+ var params = new Array(arguments.length - 1),
4412
+ offset = 0,
4413
+ index = 2,
4414
+ pending = true;
4415
+ while (index < arguments.length)
4416
+ params[offset++] = arguments[index++];
4417
+ return new Promise(function executor(resolve, reject) {
4418
+ params[offset] = function callback(err/*, varargs */) {
4419
+ if (pending) {
4420
+ pending = false;
4421
+ if (err)
4422
+ reject(err);
4423
+ else {
4424
+ var params = new Array(arguments.length - 1),
4425
+ offset = 0;
4426
+ while (offset < params.length)
4427
+ params[offset++] = arguments[offset];
4428
+ resolve.apply(null, params);
4429
+ }
4430
+ }
4431
+ };
4432
+ try {
4433
+ fn.apply(ctx || null, params);
4434
+ } catch (err) {
4435
+ if (pending) {
4436
+ pending = false;
4437
+ reject(err);
4438
+ }
4544
4439
  }
4545
- }
4546
- if (j === 1)
4547
- throw Error(invalidEncoding);
4548
- return offset - start;
4549
- };
4440
+ });
4441
+ }
4442
+ return aspromise;
4443
+ }
4444
+
4445
+ var base64$1 = {};
4446
+
4447
+ var hasRequiredBase64;
4448
+
4449
+ function requireBase64 () {
4450
+ if (hasRequiredBase64) return base64$1;
4451
+ hasRequiredBase64 = 1;
4452
+ (function (exports) {
4550
4453
 
4551
- /**
4552
- * Tests if the specified string appears to be base64 encoded.
4553
- * @param {string} string String to test
4554
- * @returns {boolean} `true` if probably base64 encoded, otherwise false
4555
- */
4556
- base64.test = function test(string) {
4557
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
4558
- };
4559
- } (base64$1));
4454
+ /**
4455
+ * A minimal base64 implementation for number arrays.
4456
+ * @memberof util
4457
+ * @namespace
4458
+ */
4459
+ var base64 = exports;
4460
+
4461
+ /**
4462
+ * Calculates the byte length of a base64 encoded string.
4463
+ * @param {string} string Base64 encoded string
4464
+ * @returns {number} Byte length
4465
+ */
4466
+ base64.length = function length(string) {
4467
+ var p = string.length;
4468
+ if (!p)
4469
+ return 0;
4470
+ var n = 0;
4471
+ while (--p % 4 > 1 && string.charAt(p) === "=")
4472
+ ++n;
4473
+ return Math.ceil(string.length * 3) / 4 - n;
4474
+ };
4475
+
4476
+ // Base64 encoding table
4477
+ var b64 = new Array(64);
4478
+
4479
+ // Base64 decoding table
4480
+ var s64 = new Array(123);
4481
+
4482
+ // 65..90, 97..122, 48..57, 43, 47
4483
+ for (var i = 0; i < 64;)
4484
+ s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
4485
+
4486
+ /**
4487
+ * Encodes a buffer to a base64 encoded string.
4488
+ * @param {Uint8Array} buffer Source buffer
4489
+ * @param {number} start Source start
4490
+ * @param {number} end Source end
4491
+ * @returns {string} Base64 encoded string
4492
+ */
4493
+ base64.encode = function encode(buffer, start, end) {
4494
+ var parts = null,
4495
+ chunk = [];
4496
+ var i = 0, // output index
4497
+ j = 0, // goto index
4498
+ t; // temporary
4499
+ while (start < end) {
4500
+ var b = buffer[start++];
4501
+ switch (j) {
4502
+ case 0:
4503
+ chunk[i++] = b64[b >> 2];
4504
+ t = (b & 3) << 4;
4505
+ j = 1;
4506
+ break;
4507
+ case 1:
4508
+ chunk[i++] = b64[t | b >> 4];
4509
+ t = (b & 15) << 2;
4510
+ j = 2;
4511
+ break;
4512
+ case 2:
4513
+ chunk[i++] = b64[t | b >> 6];
4514
+ chunk[i++] = b64[b & 63];
4515
+ j = 0;
4516
+ break;
4517
+ }
4518
+ if (i > 8191) {
4519
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
4520
+ i = 0;
4521
+ }
4522
+ }
4523
+ if (j) {
4524
+ chunk[i++] = b64[t];
4525
+ chunk[i++] = 61;
4526
+ if (j === 1)
4527
+ chunk[i++] = 61;
4528
+ }
4529
+ if (parts) {
4530
+ if (i)
4531
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
4532
+ return parts.join("");
4533
+ }
4534
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
4535
+ };
4536
+
4537
+ var invalidEncoding = "invalid encoding";
4538
+
4539
+ /**
4540
+ * Decodes a base64 encoded string to a buffer.
4541
+ * @param {string} string Source string
4542
+ * @param {Uint8Array} buffer Destination buffer
4543
+ * @param {number} offset Destination offset
4544
+ * @returns {number} Number of bytes written
4545
+ * @throws {Error} If encoding is invalid
4546
+ */
4547
+ base64.decode = function decode(string, buffer, offset) {
4548
+ var start = offset;
4549
+ var j = 0, // goto index
4550
+ t; // temporary
4551
+ for (var i = 0; i < string.length;) {
4552
+ var c = string.charCodeAt(i++);
4553
+ if (c === 61 && j > 1)
4554
+ break;
4555
+ if ((c = s64[c]) === undefined)
4556
+ throw Error(invalidEncoding);
4557
+ switch (j) {
4558
+ case 0:
4559
+ t = c;
4560
+ j = 1;
4561
+ break;
4562
+ case 1:
4563
+ buffer[offset++] = t << 2 | (c & 48) >> 4;
4564
+ t = c;
4565
+ j = 2;
4566
+ break;
4567
+ case 2:
4568
+ buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
4569
+ t = c;
4570
+ j = 3;
4571
+ break;
4572
+ case 3:
4573
+ buffer[offset++] = (t & 3) << 6 | c;
4574
+ j = 0;
4575
+ break;
4576
+ }
4577
+ }
4578
+ if (j === 1)
4579
+ throw Error(invalidEncoding);
4580
+ return offset - start;
4581
+ };
4582
+
4583
+ /**
4584
+ * Tests if the specified string appears to be base64 encoded.
4585
+ * @param {string} string String to test
4586
+ * @returns {boolean} `true` if probably base64 encoded, otherwise false
4587
+ */
4588
+ base64.test = function test(string) {
4589
+ return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
4590
+ };
4591
+ } (base64$1));
4592
+ return base64$1;
4593
+ }
4560
4594
 
4561
4595
  var eventemitter = EventEmitter;
4562
4596
 
@@ -4995,159 +5029,174 @@ function requireInquire () {
4995
5029
 
4996
5030
  var utf8$2 = {};
4997
5031
 
4998
- (function (exports) {
5032
+ var hasRequiredUtf8;
5033
+
5034
+ function requireUtf8 () {
5035
+ if (hasRequiredUtf8) return utf8$2;
5036
+ hasRequiredUtf8 = 1;
5037
+ (function (exports) {
4999
5038
 
5000
- /**
5001
- * A minimal UTF8 implementation for number arrays.
5002
- * @memberof util
5003
- * @namespace
5004
- */
5005
- var utf8 = exports;
5039
+ /**
5040
+ * A minimal UTF8 implementation for number arrays.
5041
+ * @memberof util
5042
+ * @namespace
5043
+ */
5044
+ var utf8 = exports;
5045
+
5046
+ /**
5047
+ * Calculates the UTF8 byte length of a string.
5048
+ * @param {string} string String
5049
+ * @returns {number} Byte length
5050
+ */
5051
+ utf8.length = function utf8_length(string) {
5052
+ var len = 0,
5053
+ c = 0;
5054
+ for (var i = 0; i < string.length; ++i) {
5055
+ c = string.charCodeAt(i);
5056
+ if (c < 128)
5057
+ len += 1;
5058
+ else if (c < 2048)
5059
+ len += 2;
5060
+ else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
5061
+ ++i;
5062
+ len += 4;
5063
+ } else
5064
+ len += 3;
5065
+ }
5066
+ return len;
5067
+ };
5068
+
5069
+ /**
5070
+ * Reads UTF8 bytes as a string.
5071
+ * @param {Uint8Array} buffer Source buffer
5072
+ * @param {number} start Source start
5073
+ * @param {number} end Source end
5074
+ * @returns {string} String read
5075
+ */
5076
+ utf8.read = function utf8_read(buffer, start, end) {
5077
+ var len = end - start;
5078
+ if (len < 1)
5079
+ return "";
5080
+ var parts = null,
5081
+ chunk = [],
5082
+ i = 0, // char offset
5083
+ t; // temporary
5084
+ while (start < end) {
5085
+ t = buffer[start++];
5086
+ if (t < 128)
5087
+ chunk[i++] = t;
5088
+ else if (t > 191 && t < 224)
5089
+ chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
5090
+ else if (t > 239 && t < 365) {
5091
+ t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
5092
+ chunk[i++] = 0xD800 + (t >> 10);
5093
+ chunk[i++] = 0xDC00 + (t & 1023);
5094
+ } else
5095
+ chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
5096
+ if (i > 8191) {
5097
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
5098
+ i = 0;
5099
+ }
5100
+ }
5101
+ if (parts) {
5102
+ if (i)
5103
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
5104
+ return parts.join("");
5105
+ }
5106
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
5107
+ };
5108
+
5109
+ /**
5110
+ * Writes a string as UTF8 bytes.
5111
+ * @param {string} string Source string
5112
+ * @param {Uint8Array} buffer Destination buffer
5113
+ * @param {number} offset Destination offset
5114
+ * @returns {number} Bytes written
5115
+ */
5116
+ utf8.write = function utf8_write(string, buffer, offset) {
5117
+ var start = offset,
5118
+ c1, // character 1
5119
+ c2; // character 2
5120
+ for (var i = 0; i < string.length; ++i) {
5121
+ c1 = string.charCodeAt(i);
5122
+ if (c1 < 128) {
5123
+ buffer[offset++] = c1;
5124
+ } else if (c1 < 2048) {
5125
+ buffer[offset++] = c1 >> 6 | 192;
5126
+ buffer[offset++] = c1 & 63 | 128;
5127
+ } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
5128
+ c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
5129
+ ++i;
5130
+ buffer[offset++] = c1 >> 18 | 240;
5131
+ buffer[offset++] = c1 >> 12 & 63 | 128;
5132
+ buffer[offset++] = c1 >> 6 & 63 | 128;
5133
+ buffer[offset++] = c1 & 63 | 128;
5134
+ } else {
5135
+ buffer[offset++] = c1 >> 12 | 224;
5136
+ buffer[offset++] = c1 >> 6 & 63 | 128;
5137
+ buffer[offset++] = c1 & 63 | 128;
5138
+ }
5139
+ }
5140
+ return offset - start;
5141
+ };
5142
+ } (utf8$2));
5143
+ return utf8$2;
5144
+ }
5145
+
5146
+ var pool_1;
5147
+ var hasRequiredPool;
5148
+
5149
+ function requirePool () {
5150
+ if (hasRequiredPool) return pool_1;
5151
+ hasRequiredPool = 1;
5152
+ pool_1 = pool;
5006
5153
 
5007
5154
  /**
5008
- * Calculates the UTF8 byte length of a string.
5009
- * @param {string} string String
5010
- * @returns {number} Byte length
5155
+ * An allocator as used by {@link util.pool}.
5156
+ * @typedef PoolAllocator
5157
+ * @type {function}
5158
+ * @param {number} size Buffer size
5159
+ * @returns {Uint8Array} Buffer
5011
5160
  */
5012
- utf8.length = function utf8_length(string) {
5013
- var len = 0,
5014
- c = 0;
5015
- for (var i = 0; i < string.length; ++i) {
5016
- c = string.charCodeAt(i);
5017
- if (c < 128)
5018
- len += 1;
5019
- else if (c < 2048)
5020
- len += 2;
5021
- else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
5022
- ++i;
5023
- len += 4;
5024
- } else
5025
- len += 3;
5026
- }
5027
- return len;
5028
- };
5029
5161
 
5030
5162
  /**
5031
- * Reads UTF8 bytes as a string.
5032
- * @param {Uint8Array} buffer Source buffer
5033
- * @param {number} start Source start
5034
- * @param {number} end Source end
5035
- * @returns {string} String read
5163
+ * A slicer as used by {@link util.pool}.
5164
+ * @typedef PoolSlicer
5165
+ * @type {function}
5166
+ * @param {number} start Start offset
5167
+ * @param {number} end End offset
5168
+ * @returns {Uint8Array} Buffer slice
5169
+ * @this {Uint8Array}
5036
5170
  */
5037
- utf8.read = function utf8_read(buffer, start, end) {
5038
- var len = end - start;
5039
- if (len < 1)
5040
- return "";
5041
- var parts = null,
5042
- chunk = [],
5043
- i = 0, // char offset
5044
- t; // temporary
5045
- while (start < end) {
5046
- t = buffer[start++];
5047
- if (t < 128)
5048
- chunk[i++] = t;
5049
- else if (t > 191 && t < 224)
5050
- chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
5051
- else if (t > 239 && t < 365) {
5052
- t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
5053
- chunk[i++] = 0xD800 + (t >> 10);
5054
- chunk[i++] = 0xDC00 + (t & 1023);
5055
- } else
5056
- chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
5057
- if (i > 8191) {
5058
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
5059
- i = 0;
5060
- }
5061
- }
5062
- if (parts) {
5063
- if (i)
5064
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
5065
- return parts.join("");
5066
- }
5067
- return String.fromCharCode.apply(String, chunk.slice(0, i));
5068
- };
5069
5171
 
5070
5172
  /**
5071
- * Writes a string as UTF8 bytes.
5072
- * @param {string} string Source string
5073
- * @param {Uint8Array} buffer Destination buffer
5074
- * @param {number} offset Destination offset
5075
- * @returns {number} Bytes written
5173
+ * A general purpose buffer pool.
5174
+ * @memberof util
5175
+ * @function
5176
+ * @param {PoolAllocator} alloc Allocator
5177
+ * @param {PoolSlicer} slice Slicer
5178
+ * @param {number} [size=8192] Slab size
5179
+ * @returns {PoolAllocator} Pooled allocator
5076
5180
  */
5077
- utf8.write = function utf8_write(string, buffer, offset) {
5078
- var start = offset,
5079
- c1, // character 1
5080
- c2; // character 2
5081
- for (var i = 0; i < string.length; ++i) {
5082
- c1 = string.charCodeAt(i);
5083
- if (c1 < 128) {
5084
- buffer[offset++] = c1;
5085
- } else if (c1 < 2048) {
5086
- buffer[offset++] = c1 >> 6 | 192;
5087
- buffer[offset++] = c1 & 63 | 128;
5088
- } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
5089
- c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
5090
- ++i;
5091
- buffer[offset++] = c1 >> 18 | 240;
5092
- buffer[offset++] = c1 >> 12 & 63 | 128;
5093
- buffer[offset++] = c1 >> 6 & 63 | 128;
5094
- buffer[offset++] = c1 & 63 | 128;
5095
- } else {
5096
- buffer[offset++] = c1 >> 12 | 224;
5097
- buffer[offset++] = c1 >> 6 & 63 | 128;
5098
- buffer[offset++] = c1 & 63 | 128;
5181
+ function pool(alloc, slice, size) {
5182
+ var SIZE = size || 8192;
5183
+ var MAX = SIZE >>> 1;
5184
+ var slab = null;
5185
+ var offset = SIZE;
5186
+ return function pool_alloc(size) {
5187
+ if (size < 1 || size > MAX)
5188
+ return alloc(size);
5189
+ if (offset + size > SIZE) {
5190
+ slab = alloc(SIZE);
5191
+ offset = 0;
5099
5192
  }
5100
- }
5101
- return offset - start;
5102
- };
5103
- } (utf8$2));
5104
-
5105
- var pool_1 = pool;
5106
-
5107
- /**
5108
- * An allocator as used by {@link util.pool}.
5109
- * @typedef PoolAllocator
5110
- * @type {function}
5111
- * @param {number} size Buffer size
5112
- * @returns {Uint8Array} Buffer
5113
- */
5114
-
5115
- /**
5116
- * A slicer as used by {@link util.pool}.
5117
- * @typedef PoolSlicer
5118
- * @type {function}
5119
- * @param {number} start Start offset
5120
- * @param {number} end End offset
5121
- * @returns {Uint8Array} Buffer slice
5122
- * @this {Uint8Array}
5123
- */
5124
-
5125
- /**
5126
- * A general purpose buffer pool.
5127
- * @memberof util
5128
- * @function
5129
- * @param {PoolAllocator} alloc Allocator
5130
- * @param {PoolSlicer} slice Slicer
5131
- * @param {number} [size=8192] Slab size
5132
- * @returns {PoolAllocator} Pooled allocator
5133
- */
5134
- function pool(alloc, slice, size) {
5135
- var SIZE = size || 8192;
5136
- var MAX = SIZE >>> 1;
5137
- var slab = null;
5138
- var offset = SIZE;
5139
- return function pool_alloc(size) {
5140
- if (size < 1 || size > MAX)
5141
- return alloc(size);
5142
- if (offset + size > SIZE) {
5143
- slab = alloc(SIZE);
5144
- offset = 0;
5145
- }
5146
- var buf = slice.call(slab, offset, offset += size);
5147
- if (offset & 7) // align to 32 bit
5148
- offset = (offset | 7) + 1;
5149
- return buf;
5150
- };
5193
+ var buf = slice.call(slab, offset, offset += size);
5194
+ if (offset & 7) // align to 32 bit
5195
+ offset = (offset | 7) + 1;
5196
+ return buf;
5197
+ };
5198
+ }
5199
+ return pool_1;
5151
5200
  }
5152
5201
 
5153
5202
  var longbits;
@@ -5367,10 +5416,10 @@ function requireMinimal () {
5367
5416
  var util = exports;
5368
5417
 
5369
5418
  // used to return a Promise where callback is omitted
5370
- util.asPromise = aspromise;
5419
+ util.asPromise = requireAspromise();
5371
5420
 
5372
5421
  // converts to / from base64 encoded strings
5373
- util.base64 = base64$1;
5422
+ util.base64 = requireBase64();
5374
5423
 
5375
5424
  // base class of rpc.Service
5376
5425
  util.EventEmitter = eventemitter;
@@ -5382,10 +5431,10 @@ function requireMinimal () {
5382
5431
  util.inquire = requireInquire();
5383
5432
 
5384
5433
  // converts to / from utf8 encoded strings
5385
- util.utf8 = utf8$2;
5434
+ util.utf8 = requireUtf8();
5386
5435
 
5387
5436
  // provides a node-like buffer pool in the browser
5388
- util.pool = pool_1;
5437
+ util.pool = requirePool();
5389
5438
 
5390
5439
  // utility to work with the low and high bits of a 64 bit value
5391
5440
  util.LongBits = requireLongbits();
@@ -9826,14 +9875,14 @@ const getDepositTxDataFromLogs = (logs, address, senderAsset, receiverAsset) =>
9826
9875
  if (type === 'transfer') {
9827
9876
  return attributes.reduce((acc2, { key, value }, index) => {
9828
9877
  if (index % 3 === 0)
9829
- acc2.push({ sender: '', recipient: '', amount: xchainUtil.baseAmount(0, DECIMAL) });
9878
+ acc2.push({ sender: '', recipient: '', amount: xchainUtil.baseAmount(0, RUNE_DECIMAL) });
9830
9879
  const newData = acc2[acc2.length - 1];
9831
9880
  if (key === 'sender')
9832
9881
  newData.sender = value;
9833
9882
  if (key === 'recipient')
9834
9883
  newData.recipient = value;
9835
9884
  if (key === 'amount')
9836
- newData.amount = xchainUtil.baseAmount(value.replace(/rune/, ''), DECIMAL);
9885
+ newData.amount = xchainUtil.baseAmount(value.replace(/rune/, ''), RUNE_DECIMAL);
9837
9886
  return acc2;
9838
9887
  }, acc);
9839
9888
  }
@@ -9852,7 +9901,7 @@ const getDepositTxDataFromLogs = (logs, address, senderAsset, receiverAsset) =>
9852
9901
  * @returns {Fees} The default fee.
9853
9902
  */
9854
9903
  const getDefaultFees = () => {
9855
- const fee = xchainUtil.assetToBase(xchainUtil.assetAmount(0.02 /* 0.02 RUNE */, DECIMAL));
9904
+ const fee = xchainUtil.assetToBase(xchainUtil.assetAmount(0.02 /* 0.02 RUNE */, RUNE_DECIMAL));
9856
9905
  return xchainClient.singleFee(xchainClient.FeeType.FlatFee, fee);
9857
9906
  };
9858
9907
  /**
@@ -10006,7 +10055,7 @@ const getBalance = ({ address, assets, cosmosClient, }) => __awaiter(void 0, voi
10006
10055
  return balances
10007
10056
  .map((balance) => ({
10008
10057
  asset: (balance.denom && assetFromDenom(balance.denom)) || AssetRuneNative,
10009
- amount: xchainUtil.baseAmount(balance.amount, DECIMAL),
10058
+ amount: xchainUtil.baseAmount(balance.amount, RUNE_DECIMAL),
10010
10059
  }))
10011
10060
  .filter((balance) => !assets || assets.filter((asset) => xchainUtil.assetToString(balance.asset) === xchainUtil.assetToString(asset)).length);
10012
10061
  });
@@ -10351,6 +10400,51 @@ class Client extends xchainClient.BaseXChainClient {
10351
10400
  return getBalance({ address, assets, cosmosClient: this.getCosmosClient() });
10352
10401
  });
10353
10402
  }
10403
+ /**
10404
+ *
10405
+ * @returns asset info
10406
+ */
10407
+ getAssetInfo() {
10408
+ const assetInfo = {
10409
+ asset: AssetRuneNative,
10410
+ decimal: RUNE_DECIMAL,
10411
+ };
10412
+ return assetInfo;
10413
+ }
10414
+ /**
10415
+ *
10416
+ * @param txId - tx hash
10417
+ * @returns txResponse
10418
+ */
10419
+ fetchTransaction(txId) {
10420
+ return __awaiter(this, void 0, void 0, function* () {
10421
+ try {
10422
+ const transaction = yield this.cosmosClient.txsHashGet(txId);
10423
+ return transaction;
10424
+ }
10425
+ catch (error) {
10426
+ for (const fallback of FallBackUrls) {
10427
+ for (const network of Object.keys(fallback)) {
10428
+ try {
10429
+ const networkObj = fallback[network];
10430
+ const clientUrl = networkObj.node;
10431
+ const cosmosClient = new xchainCosmos.CosmosSDKClient({
10432
+ server: Array.isArray(clientUrl) ? clientUrl[0] : clientUrl,
10433
+ chainId: this.getChainId(network),
10434
+ prefix: getPrefix(network),
10435
+ });
10436
+ const tx = yield cosmosClient.txsHashGet(txId);
10437
+ return tx;
10438
+ }
10439
+ catch (error) {
10440
+ // Handle specific error if needed
10441
+ }
10442
+ }
10443
+ }
10444
+ return null;
10445
+ }
10446
+ });
10447
+ }
10354
10448
  /**
10355
10449
  * Get the transaction details of a given transaction id.
10356
10450
  *
@@ -10360,8 +10454,9 @@ class Client extends xchainClient.BaseXChainClient {
10360
10454
  getTransactionData(txId, address) {
10361
10455
  var _a, _b, _c;
10362
10456
  return __awaiter(this, void 0, void 0, function* () {
10363
- try {
10364
- const txResult = yield this.cosmosClient.txsHashGet(txId);
10457
+ const response = yield this.fetchTransaction(txId);
10458
+ if (response) {
10459
+ const txResult = response;
10365
10460
  const bond = txResult.logs && txResult.logs[0].events.filter((i) => i.type === 'bond');
10366
10461
  const transfer = txResult.logs && txResult.logs[0].events.filter((i) => i.type === 'transfer');
10367
10462
  if (!transfer)
@@ -10381,10 +10476,10 @@ class Client extends xchainClient.BaseXChainClient {
10381
10476
  if (!bond)
10382
10477
  throw new Error(`Failed to get transaction logs (tx-hash: ${txId})`);
10383
10478
  // Rune only transactions
10384
- if (bond[0].type === 'bond' || action === 'send') {
10479
+ if (action === 'send' || bond[0].type === 'bond') {
10385
10480
  const assetTo = AssetRuneNative;
10386
10481
  const txData = txResult && txResult.logs
10387
- ? getDepositTxDataFromLogs(txResult.logs, senderAddress, senderAsset, assetTo)
10482
+ ? getDepositTxDataFromLogs(txResult.logs, `${senderAddress}`, senderAsset, assetTo)
10388
10483
  : null;
10389
10484
  //console.log(JSON.stringify(txData, null, 2))
10390
10485
  if (!txData)
@@ -10402,7 +10497,9 @@ class Client extends xchainClient.BaseXChainClient {
10402
10497
  // synths and other tx types
10403
10498
  const messageBody = JSON.stringify((_c = txResult.tx) === null || _c === void 0 ? void 0 : _c.body.messages).split(':');
10404
10499
  const assetTo = xchainUtil.assetFromStringEx(messageBody[7]);
10405
- const txData = txResult && txResult.logs ? getDepositTxDataFromLogs(txResult.logs, senderAddress, senderAsset, assetTo) : null;
10500
+ const txData = txResult && txResult.logs
10501
+ ? getDepositTxDataFromLogs(txResult.logs, `${senderAddress}`, senderAsset, assetTo)
10502
+ : null;
10406
10503
  if (!txData)
10407
10504
  throw new Error(`Failed to get transaction data (tx-hash: ${txId})`);
10408
10505
  const { from, to, type } = txData;
@@ -10415,8 +10512,9 @@ class Client extends xchainClient.BaseXChainClient {
10415
10512
  type,
10416
10513
  };
10417
10514
  }
10418
- catch (error) { }
10419
- return yield this.getTransactionDataThornode(txId);
10515
+ else {
10516
+ return yield this.getTransactionDataThornode(txId);
10517
+ }
10420
10518
  });
10421
10519
  }
10422
10520
  /** This function is used when in bound or outbound tx is not of thorchain
@@ -10445,7 +10543,7 @@ class Client extends xchainClient.BaseXChainClient {
10445
10543
  asset = xchainUtil.assetFromStringEx(getTx.observed_tx.tx.coins[0].asset);
10446
10544
  amount = getTx.observed_tx.tx.coins[0].amount;
10447
10545
  const addressTo = getTx.observed_tx.tx.to_address ? getTx.observed_tx.tx.to_address : 'undefined';
10448
- const to = [{ to: addressTo, amount: xchainUtil.baseAmount(amount, DECIMAL), asset: asset }];
10546
+ const to = [{ to: addressTo, amount: xchainUtil.baseAmount(amount, RUNE_DECIMAL), asset: asset }];
10449
10547
  const txData = {
10450
10548
  hash: txId,
10451
10549
  asset: senderAsset,
@@ -10461,7 +10559,7 @@ class Client extends xchainClient.BaseXChainClient {
10461
10559
  amount = splitMemo[3];
10462
10560
  const receiverAsset = asset;
10463
10561
  const recieverAmount = amount;
10464
- const to = [{ to: address, amount: xchainUtil.baseAmount(recieverAmount, DECIMAL), asset: receiverAsset }];
10562
+ const to = [{ to: address, amount: xchainUtil.baseAmount(recieverAmount, RUNE_DECIMAL), asset: receiverAsset }];
10465
10563
  const txData = {
10466
10564
  hash: txId,
10467
10565
  asset: senderAsset,
@@ -10492,11 +10590,11 @@ class Client extends xchainClient.BaseXChainClient {
10492
10590
  result.observed_tx.tx.coins.forEach((coin) => {
10493
10591
  from.push({
10494
10592
  from: result.observed_tx.tx.from_address,
10495
- amount: xchainUtil.baseAmount(coin.amount, DECIMAL),
10593
+ amount: xchainUtil.baseAmount(coin.amount, RUNE_DECIMAL),
10496
10594
  });
10497
10595
  to.push({
10498
10596
  to: result.observed_tx.tx.to_address,
10499
- amount: xchainUtil.baseAmount(coin.amount, DECIMAL),
10597
+ amount: xchainUtil.baseAmount(coin.amount, RUNE_DECIMAL),
10500
10598
  });
10501
10599
  asset = xchainUtil.assetFromString(coin.asset);
10502
10600
  });
@@ -10522,8 +10620,8 @@ class Client extends xchainClient.BaseXChainClient {
10522
10620
  var _a, _b, _c, _d;
10523
10621
  return __awaiter(this, void 0, void 0, function* () {
10524
10622
  const balances = yield this.getBalance(this.getAddress(walletIndex));
10525
- const runeBalance = (_b = (_a = balances.filter(({ asset }) => isAssetRuneNative(asset))[0]) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : xchainUtil.baseAmount(0, DECIMAL);
10526
- const assetBalance = (_d = (_c = balances.filter(({ asset: assetInList }) => xchainUtil.assetToString(assetInList) === xchainUtil.assetToString(asset))[0]) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : xchainUtil.baseAmount(0, DECIMAL);
10623
+ const runeBalance = (_b = (_a = balances.filter(({ asset }) => isAssetRuneNative(asset))[0]) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : xchainUtil.baseAmount(0, RUNE_DECIMAL);
10624
+ const assetBalance = (_d = (_c = balances.filter(({ asset: assetInList }) => xchainUtil.assetToString(assetInList) === xchainUtil.assetToString(asset))[0]) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : xchainUtil.baseAmount(0, RUNE_DECIMAL);
10527
10625
  const { average: fee } = yield this.getFees();
10528
10626
  if (isAssetRuneNative(asset)) {
10529
10627
  // amount + fee < runeBalance
@@ -10585,8 +10683,8 @@ class Client extends xchainClient.BaseXChainClient {
10585
10683
  var _a, _b, _c, _d;
10586
10684
  return __awaiter(this, void 0, void 0, function* () {
10587
10685
  const balances = yield this.getBalance(this.getAddress(walletIndex));
10588
- const runeBalance = (_b = (_a = balances.filter(({ asset }) => isAssetRuneNative(asset))[0]) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : xchainUtil.baseAmount(0, DECIMAL);
10589
- const assetBalance = (_d = (_c = balances.filter(({ asset: assetInList }) => xchainUtil.assetToString(assetInList) === xchainUtil.assetToString(asset))[0]) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : xchainUtil.baseAmount(0, DECIMAL);
10686
+ const runeBalance = (_b = (_a = balances.filter(({ asset }) => isAssetRuneNative(asset))[0]) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : xchainUtil.baseAmount(0, RUNE_DECIMAL);
10687
+ const assetBalance = (_d = (_c = balances.filter(({ asset: assetInList }) => xchainUtil.assetToString(assetInList) === xchainUtil.assetToString(asset))[0]) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : xchainUtil.baseAmount(0, RUNE_DECIMAL);
10590
10688
  const fee = (yield this.getFees()).average;
10591
10689
  if (isAssetRuneNative(asset)) {
10592
10690
  // amount + fee < runeBalance
@@ -10642,7 +10740,7 @@ class Client extends xchainClient.BaseXChainClient {
10642
10740
  * @param {TxOfflineParams} params The transfer offline options.
10643
10741
  * @returns {string} The signed transaction bytes.
10644
10742
  */
10645
- transferOffline({ walletIndex = 0, asset = AssetRuneNative, amount, recipient, memo, fromRuneBalance: from_rune_balance, fromAssetBalance: from_asset_balance = xchainUtil.baseAmount(0, DECIMAL), fromAccountNumber = Long$1.ZERO, fromSequence = Long$1.ZERO, gasLimit = new BigNumber(DEFAULT_GAS_LIMIT_VALUE), }) {
10743
+ transferOffline({ walletIndex = 0, asset = AssetRuneNative, amount, recipient, memo, fromRuneBalance: from_rune_balance, fromAssetBalance: from_asset_balance = xchainUtil.baseAmount(0, RUNE_DECIMAL), fromAccountNumber = Long$1.ZERO, fromSequence = Long$1.ZERO, gasLimit = new BigNumber(DEFAULT_GAS_LIMIT_VALUE), }) {
10646
10744
  return __awaiter(this, void 0, void 0, function* () {
10647
10745
  const fee = (yield this.getFees()).average;
10648
10746
  if (isAssetRuneNative(asset)) {
@@ -10723,14 +10821,15 @@ exports.AssetRuneERC20 = AssetRuneERC20;
10723
10821
  exports.AssetRuneERC20Testnet = AssetRuneERC20Testnet;
10724
10822
  exports.AssetRuneNative = AssetRuneNative;
10725
10823
  exports.Client = Client;
10726
- exports.DECIMAL = DECIMAL;
10727
10824
  exports.DEFAULT_GAS_ADJUSTMENT = DEFAULT_GAS_ADJUSTMENT;
10728
10825
  exports.DEFAULT_GAS_LIMIT_VALUE = DEFAULT_GAS_LIMIT_VALUE;
10729
10826
  exports.DEPOSIT_GAS_LIMIT_VALUE = DEPOSIT_GAS_LIMIT_VALUE;
10827
+ exports.FallBackUrls = FallBackUrls;
10730
10828
  exports.MAX_PAGES_PER_FUNCTION_CALL = MAX_PAGES_PER_FUNCTION_CALL;
10731
10829
  exports.MAX_TX_COUNT_PER_FUNCTION_CALL = MAX_TX_COUNT_PER_FUNCTION_CALL;
10732
10830
  exports.MAX_TX_COUNT_PER_PAGE = MAX_TX_COUNT_PER_PAGE;
10733
10831
  exports.MsgNativeTx = MsgNativeTx;
10832
+ exports.RUNE_DECIMAL = RUNE_DECIMAL;
10734
10833
  exports.RUNE_SYMBOL = RUNE_SYMBOL;
10735
10834
  exports.THORChain = THORChain;
10736
10835
  exports.assetFromDenom = assetFromDenom;