@xchainjs/xchain-thorchain 0.28.8 → 0.28.9
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/client.d.ts +13 -1
- package/lib/index.esm.js +207 -171
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +207 -171
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -4382,56 +4382,64 @@ var indexMinimal = {};
|
|
|
4382
4382
|
|
|
4383
4383
|
var minimal$1 = {};
|
|
4384
4384
|
|
|
4385
|
-
var aspromise
|
|
4385
|
+
var aspromise;
|
|
4386
|
+
var hasRequiredAspromise;
|
|
4387
|
+
|
|
4388
|
+
function requireAspromise () {
|
|
4389
|
+
if (hasRequiredAspromise) return aspromise;
|
|
4390
|
+
hasRequiredAspromise = 1;
|
|
4391
|
+
aspromise = asPromise;
|
|
4386
4392
|
|
|
4387
|
-
/**
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4393
|
+
/**
|
|
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}
|
|
4400
|
+
*/
|
|
4395
4401
|
|
|
4396
|
-
/**
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
function asPromise(fn, ctx/*, varargs */) {
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4402
|
+
/**
|
|
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
|
|
4409
|
+
*/
|
|
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
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
});
|
|
4441
|
+
}
|
|
4442
|
+
return aspromise;
|
|
4435
4443
|
}
|
|
4436
4444
|
|
|
4437
4445
|
var base64$1 = {};
|
|
@@ -4577,81 +4585,89 @@ var base64$1 = {};
|
|
|
4577
4585
|
};
|
|
4578
4586
|
} (base64$1));
|
|
4579
4587
|
|
|
4580
|
-
var eventemitter
|
|
4588
|
+
var eventemitter;
|
|
4589
|
+
var hasRequiredEventemitter;
|
|
4590
|
+
|
|
4591
|
+
function requireEventemitter () {
|
|
4592
|
+
if (hasRequiredEventemitter) return eventemitter;
|
|
4593
|
+
hasRequiredEventemitter = 1;
|
|
4594
|
+
eventemitter = EventEmitter;
|
|
4581
4595
|
|
|
4582
|
-
/**
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
function EventEmitter() {
|
|
4596
|
+
/**
|
|
4597
|
+
* Constructs a new event emitter instance.
|
|
4598
|
+
* @classdesc A minimal event emitter.
|
|
4599
|
+
* @memberof util
|
|
4600
|
+
* @constructor
|
|
4601
|
+
*/
|
|
4602
|
+
function EventEmitter() {
|
|
4589
4603
|
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
}
|
|
4604
|
+
/**
|
|
4605
|
+
* Registered listeners.
|
|
4606
|
+
* @type {Object.<string,*>}
|
|
4607
|
+
* @private
|
|
4608
|
+
*/
|
|
4609
|
+
this._listeners = {};
|
|
4610
|
+
}
|
|
4597
4611
|
|
|
4598
|
-
/**
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
EventEmitter.prototype.on = function on(evt, fn, ctx) {
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
};
|
|
4612
|
+
/**
|
|
4613
|
+
* Registers an event listener.
|
|
4614
|
+
* @param {string} evt Event name
|
|
4615
|
+
* @param {function} fn Listener
|
|
4616
|
+
* @param {*} [ctx] Listener context
|
|
4617
|
+
* @returns {util.EventEmitter} `this`
|
|
4618
|
+
*/
|
|
4619
|
+
EventEmitter.prototype.on = function on(evt, fn, ctx) {
|
|
4620
|
+
(this._listeners[evt] || (this._listeners[evt] = [])).push({
|
|
4621
|
+
fn : fn,
|
|
4622
|
+
ctx : ctx || this
|
|
4623
|
+
});
|
|
4624
|
+
return this;
|
|
4625
|
+
};
|
|
4612
4626
|
|
|
4613
|
-
/**
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
EventEmitter.prototype.off = function off(evt, fn) {
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
};
|
|
4627
|
+
/**
|
|
4628
|
+
* Removes an event listener or any matching listeners if arguments are omitted.
|
|
4629
|
+
* @param {string} [evt] Event name. Removes all listeners if omitted.
|
|
4630
|
+
* @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
|
|
4631
|
+
* @returns {util.EventEmitter} `this`
|
|
4632
|
+
*/
|
|
4633
|
+
EventEmitter.prototype.off = function off(evt, fn) {
|
|
4634
|
+
if (evt === undefined)
|
|
4635
|
+
this._listeners = {};
|
|
4636
|
+
else {
|
|
4637
|
+
if (fn === undefined)
|
|
4638
|
+
this._listeners[evt] = [];
|
|
4639
|
+
else {
|
|
4640
|
+
var listeners = this._listeners[evt];
|
|
4641
|
+
for (var i = 0; i < listeners.length;)
|
|
4642
|
+
if (listeners[i].fn === fn)
|
|
4643
|
+
listeners.splice(i, 1);
|
|
4644
|
+
else
|
|
4645
|
+
++i;
|
|
4646
|
+
}
|
|
4647
|
+
}
|
|
4648
|
+
return this;
|
|
4649
|
+
};
|
|
4636
4650
|
|
|
4637
|
-
/**
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
EventEmitter.prototype.emit = function emit(evt) {
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
};
|
|
4651
|
+
/**
|
|
4652
|
+
* Emits an event by calling its listeners with the specified arguments.
|
|
4653
|
+
* @param {string} evt Event name
|
|
4654
|
+
* @param {...*} args Arguments
|
|
4655
|
+
* @returns {util.EventEmitter} `this`
|
|
4656
|
+
*/
|
|
4657
|
+
EventEmitter.prototype.emit = function emit(evt) {
|
|
4658
|
+
var listeners = this._listeners[evt];
|
|
4659
|
+
if (listeners) {
|
|
4660
|
+
var args = [],
|
|
4661
|
+
i = 1;
|
|
4662
|
+
for (; i < arguments.length;)
|
|
4663
|
+
args.push(arguments[i++]);
|
|
4664
|
+
for (i = 0; i < listeners.length;)
|
|
4665
|
+
listeners[i].fn.apply(listeners[i++].ctx, args);
|
|
4666
|
+
}
|
|
4667
|
+
return this;
|
|
4668
|
+
};
|
|
4669
|
+
return eventemitter;
|
|
4670
|
+
}
|
|
4655
4671
|
|
|
4656
4672
|
var float = factory(factory);
|
|
4657
4673
|
|
|
@@ -4987,29 +5003,21 @@ function readUintBE(buf, pos) {
|
|
|
4987
5003
|
| buf[pos + 3]) >>> 0;
|
|
4988
5004
|
}
|
|
4989
5005
|
|
|
4990
|
-
var inquire_1;
|
|
4991
|
-
var hasRequiredInquire;
|
|
4992
|
-
|
|
4993
|
-
function requireInquire () {
|
|
4994
|
-
if (hasRequiredInquire) return inquire_1;
|
|
4995
|
-
hasRequiredInquire = 1;
|
|
4996
|
-
inquire_1 = inquire;
|
|
5006
|
+
var inquire_1 = inquire;
|
|
4997
5007
|
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
}
|
|
5012
|
-
return inquire_1;
|
|
5008
|
+
/**
|
|
5009
|
+
* Requires a module only if available.
|
|
5010
|
+
* @memberof util
|
|
5011
|
+
* @param {string} moduleName Module to require
|
|
5012
|
+
* @returns {?Object} Required module if available and not empty, otherwise `null`
|
|
5013
|
+
*/
|
|
5014
|
+
function inquire(moduleName) {
|
|
5015
|
+
try {
|
|
5016
|
+
var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
|
|
5017
|
+
if (mod && (mod.length || Object.keys(mod).length))
|
|
5018
|
+
return mod;
|
|
5019
|
+
} catch (e) {} // eslint-disable-line no-empty
|
|
5020
|
+
return null;
|
|
5013
5021
|
}
|
|
5014
5022
|
|
|
5015
5023
|
var utf8$2 = {};
|
|
@@ -5401,19 +5409,19 @@ function requireMinimal () {
|
|
|
5401
5409
|
var util = exports;
|
|
5402
5410
|
|
|
5403
5411
|
// used to return a Promise where callback is omitted
|
|
5404
|
-
util.asPromise =
|
|
5412
|
+
util.asPromise = requireAspromise();
|
|
5405
5413
|
|
|
5406
5414
|
// converts to / from base64 encoded strings
|
|
5407
5415
|
util.base64 = base64$1;
|
|
5408
5416
|
|
|
5409
5417
|
// base class of rpc.Service
|
|
5410
|
-
util.EventEmitter =
|
|
5418
|
+
util.EventEmitter = requireEventemitter();
|
|
5411
5419
|
|
|
5412
5420
|
// float handling accross browsers
|
|
5413
5421
|
util.float = float;
|
|
5414
5422
|
|
|
5415
5423
|
// requires modules optionally and hides the call from bundlers
|
|
5416
|
-
util.inquire =
|
|
5424
|
+
util.inquire = inquire_1;
|
|
5417
5425
|
|
|
5418
5426
|
// converts to / from utf8 encoded strings
|
|
5419
5427
|
util.utf8 = requireUtf8();
|
|
@@ -10701,7 +10709,8 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10701
10709
|
transfer({ walletIndex = 0, asset = AssetRuneNative, amount, recipient, memo, gasLimit = new BigNumber(DEFAULT_GAS_LIMIT_VALUE), sequence, }) {
|
|
10702
10710
|
var _a, _b, _c, _d;
|
|
10703
10711
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10704
|
-
const
|
|
10712
|
+
const sender = this.getAddress(walletIndex);
|
|
10713
|
+
const balances = yield this.getBalance(sender);
|
|
10705
10714
|
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);
|
|
10706
10715
|
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);
|
|
10707
10716
|
const fee = (yield this.getFees()).average;
|
|
@@ -10717,35 +10726,25 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10717
10726
|
throw new Error('insufficient funds');
|
|
10718
10727
|
}
|
|
10719
10728
|
}
|
|
10720
|
-
const
|
|
10721
|
-
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
memo: memo,
|
|
10729
|
-
assetAmount: amount,
|
|
10730
|
-
assetDenom: denom,
|
|
10731
|
-
chainId: this.getChainId(),
|
|
10732
|
-
nodeUrl: this.getClientUrl().node,
|
|
10729
|
+
const unsignedTxData = yield this.prepareTx({
|
|
10730
|
+
sender,
|
|
10731
|
+
asset,
|
|
10732
|
+
amount,
|
|
10733
|
+
recipient,
|
|
10734
|
+
memo,
|
|
10735
|
+
gasLimit,
|
|
10736
|
+
sequence,
|
|
10733
10737
|
});
|
|
10734
|
-
const
|
|
10735
|
-
const
|
|
10738
|
+
const decodedTx = cosmosclient__default["default"].proto.cosmos.tx.v1beta1.TxRaw.decode(Buffer.from(unsignedTxData.rawUnsignedTx, 'base64'));
|
|
10739
|
+
const txBuilder = new cosmosclient__default["default"].TxBuilder(this.getCosmosClient().sdk, cosmosclient__default["default"].proto.cosmos.tx.v1beta1.TxBody.decode(decodedTx.body_bytes), cosmosclient__default["default"].proto.cosmos.tx.v1beta1.AuthInfo.decode(decodedTx.auth_info_bytes));
|
|
10740
|
+
const { account_number: accountNumber } = yield this.getCosmosClient().getAccount(cosmosclient__default["default"].AccAddress.fromString(sender));
|
|
10736
10741
|
if (!accountNumber)
|
|
10737
|
-
throw Error(`
|
|
10738
|
-
const
|
|
10739
|
-
|
|
10740
|
-
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
sequence: sequence ? Long$1.fromNumber(sequence) : account.sequence || Long$1.ZERO,
|
|
10744
|
-
});
|
|
10745
|
-
const txHash = yield this.cosmosClient.signAndBroadcast(txBuilder, privKey, accountNumber);
|
|
10746
|
-
if (!txHash)
|
|
10747
|
-
throw Error(`Invalid transaction hash: ${txHash}`);
|
|
10748
|
-
return txHash;
|
|
10742
|
+
throw Error(`Transfer failed - missing account number`);
|
|
10743
|
+
const privKey = this.getCosmosClient().getPrivKeyFromMnemonic(this.phrase, this.getFullDerivationPath(walletIndex));
|
|
10744
|
+
const signDocBytes = txBuilder.signDocBytes(accountNumber);
|
|
10745
|
+
txBuilder.addSignature(privKey.sign(signDocBytes));
|
|
10746
|
+
const signedTx = txBuilder.txBytes();
|
|
10747
|
+
return this.broadcastTx(signedTx);
|
|
10749
10748
|
});
|
|
10750
10749
|
}
|
|
10751
10750
|
broadcastTx(txHex) {
|
|
@@ -10756,6 +10755,7 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10756
10755
|
/**
|
|
10757
10756
|
* Transfer without broadcast balances with MsgSend
|
|
10758
10757
|
*
|
|
10758
|
+
* @deprecated use instead prepareTx
|
|
10759
10759
|
* @param {TxOfflineParams} params The transfer offline options.
|
|
10760
10760
|
* @returns {string} The signed transaction bytes.
|
|
10761
10761
|
*/
|
|
@@ -10815,6 +10815,42 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10815
10815
|
}
|
|
10816
10816
|
});
|
|
10817
10817
|
}
|
|
10818
|
+
/**
|
|
10819
|
+
* Prepare transfer.
|
|
10820
|
+
*
|
|
10821
|
+
* @param {TxParams&Address&BigNumber} params The transfer options.
|
|
10822
|
+
* @returns {PreparedTx} The raw unsigned transaction.
|
|
10823
|
+
*/
|
|
10824
|
+
prepareTx({ sender, recipient, amount, memo, asset = AssetRuneNative, gasLimit = new BigNumber(DEFAULT_GAS_LIMIT_VALUE), sequence, }) {
|
|
10825
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10826
|
+
if (!this.validateAddress(sender))
|
|
10827
|
+
throw Error('Invalid sender address');
|
|
10828
|
+
if (!this.validateAddress(recipient))
|
|
10829
|
+
throw Error('Invalid recipient address');
|
|
10830
|
+
const denom = getDenom(asset);
|
|
10831
|
+
const txBody = yield buildTransferTx({
|
|
10832
|
+
fromAddress: sender,
|
|
10833
|
+
toAddress: recipient,
|
|
10834
|
+
memo,
|
|
10835
|
+
assetAmount: amount,
|
|
10836
|
+
assetDenom: denom,
|
|
10837
|
+
chainId: this.getChainId(),
|
|
10838
|
+
nodeUrl: this.getClientUrl().node,
|
|
10839
|
+
});
|
|
10840
|
+
const account = yield this.getCosmosClient().getAccount(cosmosclient__default["default"].AccAddress.fromString(sender));
|
|
10841
|
+
const { pub_key: pubkey } = account;
|
|
10842
|
+
if (!pubkey)
|
|
10843
|
+
throw Error(`Transfer failed - missing pub key`);
|
|
10844
|
+
const txBuilder = buildUnsignedTx({
|
|
10845
|
+
cosmosSdk: this.getCosmosClient().sdk,
|
|
10846
|
+
txBody,
|
|
10847
|
+
gasLimit: Long$1.fromString(gasLimit.toString()),
|
|
10848
|
+
signerPubkey: pubkey,
|
|
10849
|
+
sequence: sequence ? Long$1.fromNumber(sequence) : account.sequence || Long$1.ZERO,
|
|
10850
|
+
});
|
|
10851
|
+
return { rawUnsignedTx: txBuilder.txBytes() };
|
|
10852
|
+
});
|
|
10853
|
+
}
|
|
10818
10854
|
}
|
|
10819
10855
|
|
|
10820
10856
|
class MsgNativeTx {
|