@paraspell/sdk 8.13.2 → 8.15.0
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/README.md +16 -11
- package/dist/index.cjs +492 -233
- package/dist/index.mjs +493 -234
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { BatchMode, createApiInstanceForNode as createApiInstanceForNode$1, NodeNotSupportedError, Parents, Version, getNode, isForeignAsset, computeFeeFromDryRun, getAssetsObject, getBalanceNative as getBalanceNative$1, getBalanceForeign as getBalanceForeign$1, getTransferInfo as getTransferInfo$1, getAssetBalance as getAssetBalance$1, claimAssets as claimAssets$1, getOriginFeeDetails as getOriginFeeDetails$1, getMaxNativeTransferableAmount as getMaxNativeTransferableAmount$1, getMaxForeignTransferableAmount as getMaxForeignTransferableAmount$1, getTransferableAmount as getTransferableAmount$1, verifyEdOnDestination as verifyEdOnDestination$1, Foreign, ForeignAbstract, Native, Override, findAsset, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTNode, hasSupportForAsset, isNodeEvm, transferMoonbeamEvm, validateAddress, transferMoonbeamToEth, Builder as Builder$1, getParaEthTransferFees as getParaEthTransferFees$1, getBridgeStatus as getBridgeStatus$1, send as send$1, dryRun as dryRun$1, dryRunOrigin as dryRunOrigin$1 } from '@paraspell/sdk-core';
|
|
1
|
+
import { BatchMode, getNodeProviders, createApiInstanceForNode as createApiInstanceForNode$1, NodeNotSupportedError, Parents, Version, getNode, isForeignAsset, computeFeeFromDryRun, getAssetsObject, getBalanceNative as getBalanceNative$1, getBalanceForeign as getBalanceForeign$1, getTransferInfo as getTransferInfo$1, getAssetBalance as getAssetBalance$1, claimAssets as claimAssets$1, getOriginFeeDetails as getOriginFeeDetails$1, getMaxNativeTransferableAmount as getMaxNativeTransferableAmount$1, getMaxForeignTransferableAmount as getMaxForeignTransferableAmount$1, getTransferableAmount as getTransferableAmount$1, verifyEdOnDestination as verifyEdOnDestination$1, Foreign, ForeignAbstract, Native, Override, findAsset, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTNode, hasSupportForAsset, isNodeEvm, transferMoonbeamEvm, validateAddress, transferMoonbeamToEth, Builder as Builder$1, getParaEthTransferFees as getParaEthTransferFees$1, getBridgeStatus as getBridgeStatus$1, send as send$1, dryRun as dryRun$1, dryRunOrigin as dryRunOrigin$1 } from '@paraspell/sdk-core';
|
|
2
2
|
export * from '@paraspell/sdk-core';
|
|
3
|
-
import { blake2b } from '@noble/hashes/
|
|
3
|
+
import { blake2b } from '@noble/hashes/blake2';
|
|
4
4
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
5
5
|
import { ethers } from 'ethers';
|
|
6
|
-
import { FixedSizeBinary, Binary,
|
|
6
|
+
import { FixedSizeBinary, Binary, AccountId, createClient } from 'polkadot-api';
|
|
7
7
|
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat';
|
|
8
8
|
|
|
9
9
|
function _arrayLikeToArray(r, a) {
|
|
@@ -627,6 +627,269 @@ var _transform = function transform(obj) {
|
|
|
627
627
|
}
|
|
628
628
|
};
|
|
629
629
|
|
|
630
|
+
function createClientCache(maxSize, onEviction) {
|
|
631
|
+
var extensionMs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 5 * 60000;
|
|
632
|
+
var data = new Map();
|
|
633
|
+
var timers = new Map();
|
|
634
|
+
var now = function now() {
|
|
635
|
+
return Date.now();
|
|
636
|
+
};
|
|
637
|
+
var timeLeft = function timeLeft(w) {
|
|
638
|
+
return Math.max(w.expireAt - now(), 0);
|
|
639
|
+
};
|
|
640
|
+
var schedule = function schedule(k, delay) {
|
|
641
|
+
if (timers.has(k)) clearTimeout(timers.get(k));
|
|
642
|
+
timers.set(k, setTimeout(function () {
|
|
643
|
+
return handleTimeout(k);
|
|
644
|
+
}, delay));
|
|
645
|
+
};
|
|
646
|
+
var handleTimeout = function handleTimeout(k) {
|
|
647
|
+
var w = data.get(k);
|
|
648
|
+
if (!w) return;
|
|
649
|
+
if (!w.extended && w.value.refs > 0) {
|
|
650
|
+
// first expiry while still in use - Extend grace period
|
|
651
|
+
// Call rpc.properties to keep the connection alive
|
|
652
|
+
void _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
653
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
654
|
+
while (1) switch (_context.prev = _context.next) {
|
|
655
|
+
case 0:
|
|
656
|
+
_context.prev = 0;
|
|
657
|
+
_context.next = 3;
|
|
658
|
+
return w.value.client.getChainSpecData();
|
|
659
|
+
case 3:
|
|
660
|
+
_context.next = 7;
|
|
661
|
+
break;
|
|
662
|
+
case 5:
|
|
663
|
+
_context.prev = 5;
|
|
664
|
+
_context.t0 = _context["catch"](0);
|
|
665
|
+
case 7:
|
|
666
|
+
case "end":
|
|
667
|
+
return _context.stop();
|
|
668
|
+
}
|
|
669
|
+
}, _callee, null, [[0, 5]]);
|
|
670
|
+
}))();
|
|
671
|
+
w.value.destroyWanted = true;
|
|
672
|
+
w.extended = true;
|
|
673
|
+
w.expireAt = now() + extensionMs;
|
|
674
|
+
schedule(k, extensionMs);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
evict(k); // second expiry or unused - real eviction
|
|
678
|
+
};
|
|
679
|
+
var evict = function evict(k) {
|
|
680
|
+
var w = data.get(k);
|
|
681
|
+
if (!w) return;
|
|
682
|
+
clearTimeout(timers.get(k));
|
|
683
|
+
timers["delete"](k);
|
|
684
|
+
data["delete"](k);
|
|
685
|
+
onEviction === null || onEviction === void 0 || onEviction(k, w.value);
|
|
686
|
+
};
|
|
687
|
+
var evictIfNeeded = function evictIfNeeded() {
|
|
688
|
+
if (data.size <= maxSize) return;
|
|
689
|
+
var victimKey;
|
|
690
|
+
var victim;
|
|
691
|
+
var _iterator = _createForOfIteratorHelper(data),
|
|
692
|
+
_step;
|
|
693
|
+
try {
|
|
694
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
695
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
696
|
+
k = _step$value[0],
|
|
697
|
+
w = _step$value[1];
|
|
698
|
+
if (!victim) {
|
|
699
|
+
victimKey = k;
|
|
700
|
+
victim = w;
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
var better = w.extended && !victim.extended ||
|
|
704
|
+
// Prefer extended over normal
|
|
705
|
+
w.extended === victim.extended && w.value.destroyWanted && !victim.value.destroyWanted || w.extended === victim.extended && w.value.destroyWanted === victim.value.destroyWanted && timeLeft(w) < timeLeft(victim) || w.extended === victim.extended && w.value.destroyWanted === victim.value.destroyWanted && timeLeft(w) === timeLeft(victim) && w.value.refs < victim.value.refs; // Prefer with less refs
|
|
706
|
+
if (better) {
|
|
707
|
+
victimKey = k;
|
|
708
|
+
victim = w;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
} catch (err) {
|
|
712
|
+
_iterator.e(err);
|
|
713
|
+
} finally {
|
|
714
|
+
_iterator.f();
|
|
715
|
+
}
|
|
716
|
+
if (victimKey !== undefined) evict(victimKey);
|
|
717
|
+
};
|
|
718
|
+
var set = function set(k, v, ttl) {
|
|
719
|
+
var existing = data.get(k);
|
|
720
|
+
if (existing) {
|
|
721
|
+
existing.value = v;
|
|
722
|
+
existing.ttl = ttl;
|
|
723
|
+
existing.extended = false;
|
|
724
|
+
existing.expireAt = now() + ttl;
|
|
725
|
+
schedule(k, ttl);
|
|
726
|
+
} else {
|
|
727
|
+
data.set(k, {
|
|
728
|
+
value: v,
|
|
729
|
+
ttl: ttl,
|
|
730
|
+
extended: false,
|
|
731
|
+
expireAt: now() + ttl
|
|
732
|
+
});
|
|
733
|
+
schedule(k, ttl);
|
|
734
|
+
}
|
|
735
|
+
evictIfNeeded();
|
|
736
|
+
};
|
|
737
|
+
var get = function get(k) {
|
|
738
|
+
var w = data.get(k);
|
|
739
|
+
if (!w) return undefined;
|
|
740
|
+
if (!w.extended && timeLeft(w) < w.ttl) {
|
|
741
|
+
w.expireAt = now() + w.ttl; // refresh normal life
|
|
742
|
+
schedule(k, w.ttl);
|
|
743
|
+
}
|
|
744
|
+
return w.value;
|
|
745
|
+
};
|
|
746
|
+
var revive = function revive(k, ttl) {
|
|
747
|
+
var w = data.get(k);
|
|
748
|
+
if (!w) return;
|
|
749
|
+
var remaining = timeLeft(w);
|
|
750
|
+
w.extended = false;
|
|
751
|
+
if (ttl < remaining) {
|
|
752
|
+
w.ttl = ttl;
|
|
753
|
+
w.expireAt = now() + ttl;
|
|
754
|
+
schedule(k, ttl);
|
|
755
|
+
}
|
|
756
|
+
// if ttl ≥ remaining - keep current timer
|
|
757
|
+
};
|
|
758
|
+
var del = function del(k) {
|
|
759
|
+
if (!data.has(k)) return false;
|
|
760
|
+
evict(k);
|
|
761
|
+
return true;
|
|
762
|
+
};
|
|
763
|
+
var clear = function clear() {
|
|
764
|
+
var _iterator2 = _createForOfIteratorHelper(timers.values()),
|
|
765
|
+
_step2;
|
|
766
|
+
try {
|
|
767
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
768
|
+
var t = _step2.value;
|
|
769
|
+
clearTimeout(t);
|
|
770
|
+
}
|
|
771
|
+
} catch (err) {
|
|
772
|
+
_iterator2.e(err);
|
|
773
|
+
} finally {
|
|
774
|
+
_iterator2.f();
|
|
775
|
+
}
|
|
776
|
+
timers.clear();
|
|
777
|
+
data.clear();
|
|
778
|
+
};
|
|
779
|
+
return {
|
|
780
|
+
set: set,
|
|
781
|
+
get: get,
|
|
782
|
+
"delete": del,
|
|
783
|
+
has: function has(k) {
|
|
784
|
+
return data.has(k);
|
|
785
|
+
},
|
|
786
|
+
clear: clear,
|
|
787
|
+
peek: function peek(k) {
|
|
788
|
+
var _data$get;
|
|
789
|
+
return (_data$get = data.get(k)) === null || _data$get === void 0 ? void 0 : _data$get.value;
|
|
790
|
+
},
|
|
791
|
+
remainingTtl: function remainingTtl(k) {
|
|
792
|
+
var w = data.get(k);
|
|
793
|
+
return w ? timeLeft(w) : undefined;
|
|
794
|
+
},
|
|
795
|
+
revive: revive
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
var DEFAULT_TTL_MS = 60000; // 1 minute
|
|
800
|
+
var MAX_CLIENTS = 100;
|
|
801
|
+
var EXTENSION_MS = 5 * 60000; // 5 minutes
|
|
802
|
+
var clientPool = createClientCache(MAX_CLIENTS, function (_key, entry) {
|
|
803
|
+
entry.client.destroy();
|
|
804
|
+
}, EXTENSION_MS);
|
|
805
|
+
var keyFromWs = function keyFromWs(ws) {
|
|
806
|
+
return Array.isArray(ws) ? JSON.stringify(ws) : ws;
|
|
807
|
+
};
|
|
808
|
+
var createPolkadotClient = /*#__PURE__*/function () {
|
|
809
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(ws) {
|
|
810
|
+
var isNodeJs, _ref2, getWsProvider, provider;
|
|
811
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
812
|
+
while (1) switch (_context.prev = _context.next) {
|
|
813
|
+
case 0:
|
|
814
|
+
isNodeJs = typeof window === 'undefined';
|
|
815
|
+
if (!isNodeJs) {
|
|
816
|
+
_context.next = 7;
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
819
|
+
_context.next = 4;
|
|
820
|
+
return import('polkadot-api/ws-provider/node');
|
|
821
|
+
case 4:
|
|
822
|
+
_context.t0 = _context.sent;
|
|
823
|
+
_context.next = 10;
|
|
824
|
+
break;
|
|
825
|
+
case 7:
|
|
826
|
+
_context.next = 9;
|
|
827
|
+
return import('polkadot-api/ws-provider/web');
|
|
828
|
+
case 9:
|
|
829
|
+
_context.t0 = _context.sent;
|
|
830
|
+
case 10:
|
|
831
|
+
_ref2 = _context.t0;
|
|
832
|
+
getWsProvider = _ref2.getWsProvider;
|
|
833
|
+
provider = Array.isArray(ws) ? getWsProvider(ws) : getWsProvider(ws);
|
|
834
|
+
return _context.abrupt("return", createClient(withPolkadotSdkCompat(provider)));
|
|
835
|
+
case 14:
|
|
836
|
+
case "end":
|
|
837
|
+
return _context.stop();
|
|
838
|
+
}
|
|
839
|
+
}, _callee);
|
|
840
|
+
}));
|
|
841
|
+
return function createPolkadotClient(_x) {
|
|
842
|
+
return _ref.apply(this, arguments);
|
|
843
|
+
};
|
|
844
|
+
}();
|
|
845
|
+
var leasePolkadotClient = /*#__PURE__*/function () {
|
|
846
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ws, ttlMs) {
|
|
847
|
+
var key, entry;
|
|
848
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
849
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
850
|
+
case 0:
|
|
851
|
+
key = keyFromWs(ws);
|
|
852
|
+
entry = clientPool.peek(key);
|
|
853
|
+
if (entry) {
|
|
854
|
+
_context2.next = 8;
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
_context2.next = 5;
|
|
858
|
+
return createPolkadotClient(ws);
|
|
859
|
+
case 5:
|
|
860
|
+
_context2.t0 = _context2.sent;
|
|
861
|
+
entry = {
|
|
862
|
+
client: _context2.t0,
|
|
863
|
+
refs: 0,
|
|
864
|
+
destroyWanted: false
|
|
865
|
+
};
|
|
866
|
+
clientPool.set(key, entry, ttlMs);
|
|
867
|
+
case 8:
|
|
868
|
+
entry.refs += 1;
|
|
869
|
+
clientPool.revive(key, ttlMs);
|
|
870
|
+
entry.destroyWanted = false;
|
|
871
|
+
return _context2.abrupt("return", entry.client);
|
|
872
|
+
case 12:
|
|
873
|
+
case "end":
|
|
874
|
+
return _context2.stop();
|
|
875
|
+
}
|
|
876
|
+
}, _callee2);
|
|
877
|
+
}));
|
|
878
|
+
return function leasePolkadotClient(_x2, _x3) {
|
|
879
|
+
return _ref3.apply(this, arguments);
|
|
880
|
+
};
|
|
881
|
+
}();
|
|
882
|
+
var releasePolkadotClient = function releasePolkadotClient(ws) {
|
|
883
|
+
var key = keyFromWs(ws);
|
|
884
|
+
var entry = clientPool.peek(key);
|
|
885
|
+
if (!entry) {
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
entry.refs -= 1;
|
|
889
|
+
if (entry.refs === 0 && entry.destroyWanted) {
|
|
890
|
+
clientPool["delete"](key);
|
|
891
|
+
}
|
|
892
|
+
};
|
|
630
893
|
var unsupportedNodes = ['ComposableFinance', 'Interlay', 'CrustShadow', 'Kintsugi', 'RobonomicsKusama', 'Turing', 'Pendulum', 'Subsocial'];
|
|
631
894
|
var isHex = function isHex(str) {
|
|
632
895
|
return typeof str === 'string' && /^0x[0-9a-fA-F]+$/.test(str);
|
|
@@ -634,6 +897,7 @@ var isHex = function isHex(str) {
|
|
|
634
897
|
var PapiApi = /*#__PURE__*/function () {
|
|
635
898
|
function PapiApi() {
|
|
636
899
|
_classCallCheck(this, PapiApi);
|
|
900
|
+
this._ttlMs = DEFAULT_TTL_MS;
|
|
637
901
|
this.initialized = false;
|
|
638
902
|
this.disconnectAllowed = true;
|
|
639
903
|
}
|
|
@@ -655,57 +919,62 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
655
919
|
}, {
|
|
656
920
|
key: "init",
|
|
657
921
|
value: function () {
|
|
658
|
-
var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
659
|
-
var
|
|
660
|
-
|
|
661
|
-
|
|
922
|
+
var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(node) {
|
|
923
|
+
var clientTtlMs,
|
|
924
|
+
_this$_api,
|
|
925
|
+
_args3 = arguments;
|
|
926
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
927
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
662
928
|
case 0:
|
|
929
|
+
clientTtlMs = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : DEFAULT_TTL_MS;
|
|
663
930
|
if (!this.initialized) {
|
|
664
|
-
|
|
931
|
+
_context3.next = 3;
|
|
665
932
|
break;
|
|
666
933
|
}
|
|
667
|
-
return
|
|
668
|
-
case
|
|
934
|
+
return _context3.abrupt("return");
|
|
935
|
+
case 3:
|
|
669
936
|
if (!unsupportedNodes.includes(node)) {
|
|
670
|
-
|
|
937
|
+
_context3.next = 5;
|
|
671
938
|
break;
|
|
672
939
|
}
|
|
673
940
|
throw new NodeNotSupportedError("The node ".concat(node, " is not yet supported by the Polkadot API."));
|
|
674
|
-
case
|
|
941
|
+
case 5:
|
|
942
|
+
this._ttlMs = clientTtlMs;
|
|
675
943
|
if (!(typeof this._api === 'string' || this._api instanceof Array)) {
|
|
676
|
-
|
|
944
|
+
_context3.next = 12;
|
|
677
945
|
break;
|
|
678
946
|
}
|
|
679
|
-
|
|
947
|
+
_context3.next = 9;
|
|
680
948
|
return this.createApiInstance(this._api);
|
|
681
|
-
case
|
|
682
|
-
this.api =
|
|
683
|
-
|
|
949
|
+
case 9:
|
|
950
|
+
this.api = _context3.sent;
|
|
951
|
+
_context3.next = 20;
|
|
684
952
|
break;
|
|
685
|
-
case
|
|
953
|
+
case 12:
|
|
686
954
|
if (!((_this$_api = this._api) !== null && _this$_api !== void 0)) {
|
|
687
|
-
|
|
955
|
+
_context3.next = 16;
|
|
688
956
|
break;
|
|
689
957
|
}
|
|
690
|
-
|
|
691
|
-
|
|
958
|
+
_context3.t0 = _this$_api;
|
|
959
|
+
_context3.next = 19;
|
|
692
960
|
break;
|
|
693
|
-
case 14:
|
|
694
|
-
_context.next = 16;
|
|
695
|
-
return createApiInstanceForNode$1(this, node);
|
|
696
961
|
case 16:
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
this.api = _context.t0;
|
|
962
|
+
_context3.next = 18;
|
|
963
|
+
return createApiInstanceForNode$1(this, node);
|
|
700
964
|
case 18:
|
|
701
|
-
|
|
965
|
+
_context3.t0 = _context3.sent;
|
|
702
966
|
case 19:
|
|
967
|
+
this.api = _context3.t0;
|
|
968
|
+
case 20:
|
|
969
|
+
this._node = node;
|
|
970
|
+
this.initialized = true;
|
|
971
|
+
case 22:
|
|
703
972
|
case "end":
|
|
704
|
-
return
|
|
973
|
+
return _context3.stop();
|
|
705
974
|
}
|
|
706
|
-
},
|
|
975
|
+
}, _callee3, this);
|
|
707
976
|
}));
|
|
708
|
-
function init(
|
|
977
|
+
function init(_x4) {
|
|
709
978
|
return _init.apply(this, arguments);
|
|
710
979
|
}
|
|
711
980
|
return init;
|
|
@@ -713,37 +982,18 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
713
982
|
}, {
|
|
714
983
|
key: "createApiInstance",
|
|
715
984
|
value: function () {
|
|
716
|
-
var _createApiInstance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
985
|
+
var _createApiInstance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(wsUrl) {
|
|
986
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
987
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
720
988
|
case 0:
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
_context2.next = 7;
|
|
724
|
-
break;
|
|
725
|
-
}
|
|
726
|
-
_context2.next = 4;
|
|
727
|
-
return import('polkadot-api/ws-provider/node');
|
|
728
|
-
case 4:
|
|
729
|
-
getWsProvider = _context2.sent.getWsProvider;
|
|
730
|
-
_context2.next = 10;
|
|
731
|
-
break;
|
|
732
|
-
case 7:
|
|
733
|
-
_context2.next = 9;
|
|
734
|
-
return import('polkadot-api/ws-provider/web');
|
|
735
|
-
case 9:
|
|
736
|
-
getWsProvider = _context2.sent.getWsProvider;
|
|
737
|
-
case 10:
|
|
738
|
-
provider = wsUrl instanceof Array ? getWsProvider(wsUrl) : getWsProvider(wsUrl);
|
|
739
|
-
return _context2.abrupt("return", Promise.resolve(createClient(withPolkadotSdkCompat(provider))));
|
|
740
|
-
case 12:
|
|
989
|
+
return _context4.abrupt("return", leasePolkadotClient(wsUrl, this._ttlMs));
|
|
990
|
+
case 1:
|
|
741
991
|
case "end":
|
|
742
|
-
return
|
|
992
|
+
return _context4.stop();
|
|
743
993
|
}
|
|
744
|
-
},
|
|
994
|
+
}, _callee4, this);
|
|
745
995
|
}));
|
|
746
|
-
function createApiInstance(
|
|
996
|
+
function createApiInstance(_x5) {
|
|
747
997
|
return _createApiInstance.apply(this, arguments);
|
|
748
998
|
}
|
|
749
999
|
return createApiInstance;
|
|
@@ -758,10 +1008,10 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
758
1008
|
}
|
|
759
1009
|
}, {
|
|
760
1010
|
key: "callTxMethod",
|
|
761
|
-
value: function callTxMethod(
|
|
762
|
-
var module =
|
|
763
|
-
section =
|
|
764
|
-
parameters =
|
|
1011
|
+
value: function callTxMethod(_ref4) {
|
|
1012
|
+
var module = _ref4.module,
|
|
1013
|
+
section = _ref4.section,
|
|
1014
|
+
parameters = _ref4.parameters;
|
|
765
1015
|
var transformedParameters = _transform(parameters);
|
|
766
1016
|
return this.api.getUnsafeApi().tx[module][section](transformedParameters);
|
|
767
1017
|
}
|
|
@@ -778,10 +1028,10 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
778
1028
|
}, {
|
|
779
1029
|
key: "objectToHex",
|
|
780
1030
|
value: function () {
|
|
781
|
-
var _objectToHex = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1031
|
+
var _objectToHex = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(obj) {
|
|
782
1032
|
var transformedObj, tx, removeFirst5Bytes, encodedData;
|
|
783
|
-
return _regeneratorRuntime().wrap(function
|
|
784
|
-
while (1) switch (
|
|
1033
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
1034
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
785
1035
|
case 0:
|
|
786
1036
|
transformedObj = _transform(obj);
|
|
787
1037
|
tx = this.api.getUnsafeApi().tx.PolkadotXcm.send({
|
|
@@ -799,18 +1049,18 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
799
1049
|
removeFirst5Bytes = function removeFirst5Bytes(hexString) {
|
|
800
1050
|
return '0x' + hexString.slice(12);
|
|
801
1051
|
};
|
|
802
|
-
|
|
1052
|
+
_context5.next = 5;
|
|
803
1053
|
return tx.getEncodedData();
|
|
804
1054
|
case 5:
|
|
805
|
-
encodedData =
|
|
806
|
-
return
|
|
1055
|
+
encodedData = _context5.sent;
|
|
1056
|
+
return _context5.abrupt("return", removeFirst5Bytes(encodedData.asHex()));
|
|
807
1057
|
case 7:
|
|
808
1058
|
case "end":
|
|
809
|
-
return
|
|
1059
|
+
return _context5.stop();
|
|
810
1060
|
}
|
|
811
|
-
},
|
|
1061
|
+
}, _callee5, this);
|
|
812
1062
|
}));
|
|
813
|
-
function objectToHex(
|
|
1063
|
+
function objectToHex(_x6) {
|
|
814
1064
|
return _objectToHex.apply(this, arguments);
|
|
815
1065
|
}
|
|
816
1066
|
return objectToHex;
|
|
@@ -835,18 +1085,18 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
835
1085
|
}, {
|
|
836
1086
|
key: "calculateTransactionFee",
|
|
837
1087
|
value: function () {
|
|
838
|
-
var _calculateTransactionFee = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
839
|
-
return _regeneratorRuntime().wrap(function
|
|
840
|
-
while (1) switch (
|
|
1088
|
+
var _calculateTransactionFee = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(tx, address) {
|
|
1089
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
1090
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
841
1091
|
case 0:
|
|
842
|
-
return
|
|
1092
|
+
return _context6.abrupt("return", tx.getEstimatedFees(address));
|
|
843
1093
|
case 1:
|
|
844
1094
|
case "end":
|
|
845
|
-
return
|
|
1095
|
+
return _context6.stop();
|
|
846
1096
|
}
|
|
847
|
-
},
|
|
1097
|
+
}, _callee6);
|
|
848
1098
|
}));
|
|
849
|
-
function calculateTransactionFee(
|
|
1099
|
+
function calculateTransactionFee(_x7, _x8) {
|
|
850
1100
|
return _calculateTransactionFee.apply(this, arguments);
|
|
851
1101
|
}
|
|
852
1102
|
return calculateTransactionFee;
|
|
@@ -854,30 +1104,30 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
854
1104
|
}, {
|
|
855
1105
|
key: "quoteAhPrice",
|
|
856
1106
|
value: function () {
|
|
857
|
-
var _quoteAhPrice = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1107
|
+
var _quoteAhPrice = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(fromMl, toMl, amountIn) {
|
|
858
1108
|
var includeFee,
|
|
859
1109
|
transformedFromMl,
|
|
860
1110
|
transformedToMl,
|
|
861
1111
|
response,
|
|
862
|
-
|
|
863
|
-
return _regeneratorRuntime().wrap(function
|
|
864
|
-
while (1) switch (
|
|
1112
|
+
_args7 = arguments;
|
|
1113
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
1114
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
865
1115
|
case 0:
|
|
866
|
-
includeFee =
|
|
1116
|
+
includeFee = _args7.length > 3 && _args7[3] !== undefined ? _args7[3] : true;
|
|
867
1117
|
transformedFromMl = _transform(fromMl);
|
|
868
1118
|
transformedToMl = _transform(toMl);
|
|
869
|
-
|
|
1119
|
+
_context7.next = 5;
|
|
870
1120
|
return this.api.getUnsafeApi().apis.AssetConversionApi.quote_price_exact_tokens_for_tokens(transformedFromMl, transformedToMl, amountIn, includeFee);
|
|
871
1121
|
case 5:
|
|
872
|
-
response =
|
|
873
|
-
return
|
|
1122
|
+
response = _context7.sent;
|
|
1123
|
+
return _context7.abrupt("return", response ? BigInt(response) : undefined);
|
|
874
1124
|
case 7:
|
|
875
1125
|
case "end":
|
|
876
|
-
return
|
|
1126
|
+
return _context7.stop();
|
|
877
1127
|
}
|
|
878
|
-
},
|
|
1128
|
+
}, _callee7, this);
|
|
879
1129
|
}));
|
|
880
|
-
function quoteAhPrice(
|
|
1130
|
+
function quoteAhPrice(_x9, _x0, _x1) {
|
|
881
1131
|
return _quoteAhPrice.apply(this, arguments);
|
|
882
1132
|
}
|
|
883
1133
|
return quoteAhPrice;
|
|
@@ -885,23 +1135,23 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
885
1135
|
}, {
|
|
886
1136
|
key: "getBalanceNative",
|
|
887
1137
|
value: function () {
|
|
888
|
-
var _getBalanceNative = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1138
|
+
var _getBalanceNative = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(address) {
|
|
889
1139
|
var res;
|
|
890
|
-
return _regeneratorRuntime().wrap(function
|
|
891
|
-
while (1) switch (
|
|
1140
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1141
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
892
1142
|
case 0:
|
|
893
|
-
|
|
1143
|
+
_context8.next = 2;
|
|
894
1144
|
return this.api.getUnsafeApi().query.System.Account.getValue(address);
|
|
895
1145
|
case 2:
|
|
896
|
-
res =
|
|
897
|
-
return
|
|
1146
|
+
res = _context8.sent;
|
|
1147
|
+
return _context8.abrupt("return", res.data.free);
|
|
898
1148
|
case 4:
|
|
899
1149
|
case "end":
|
|
900
|
-
return
|
|
1150
|
+
return _context8.stop();
|
|
901
1151
|
}
|
|
902
|
-
},
|
|
1152
|
+
}, _callee8, this);
|
|
903
1153
|
}));
|
|
904
|
-
function getBalanceNative(
|
|
1154
|
+
function getBalanceNative(_x10) {
|
|
905
1155
|
return _getBalanceNative.apply(this, arguments);
|
|
906
1156
|
}
|
|
907
1157
|
return getBalanceNative;
|
|
@@ -909,23 +1159,23 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
909
1159
|
}, {
|
|
910
1160
|
key: "getBalanceForeignPolkadotXcm",
|
|
911
1161
|
value: function () {
|
|
912
|
-
var _getBalanceForeignPolkadotXcm = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1162
|
+
var _getBalanceForeignPolkadotXcm = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(address, id) {
|
|
913
1163
|
var res;
|
|
914
|
-
return _regeneratorRuntime().wrap(function
|
|
915
|
-
while (1) switch (
|
|
1164
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1165
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
916
1166
|
case 0:
|
|
917
|
-
|
|
1167
|
+
_context9.next = 2;
|
|
918
1168
|
return this.api.getUnsafeApi().query.Assets.Account.getValue(id, address);
|
|
919
1169
|
case 2:
|
|
920
|
-
res =
|
|
921
|
-
return
|
|
1170
|
+
res = _context9.sent;
|
|
1171
|
+
return _context9.abrupt("return", res && res.balance ? BigInt(res.balance) : 0n);
|
|
922
1172
|
case 4:
|
|
923
1173
|
case "end":
|
|
924
|
-
return
|
|
1174
|
+
return _context9.stop();
|
|
925
1175
|
}
|
|
926
|
-
},
|
|
1176
|
+
}, _callee9, this);
|
|
927
1177
|
}));
|
|
928
|
-
function getBalanceForeignPolkadotXcm(
|
|
1178
|
+
function getBalanceForeignPolkadotXcm(_x11, _x12) {
|
|
929
1179
|
return _getBalanceForeignPolkadotXcm.apply(this, arguments);
|
|
930
1180
|
}
|
|
931
1181
|
return getBalanceForeignPolkadotXcm;
|
|
@@ -933,23 +1183,23 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
933
1183
|
}, {
|
|
934
1184
|
key: "getMythosForeignBalance",
|
|
935
1185
|
value: function () {
|
|
936
|
-
var _getMythosForeignBalance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1186
|
+
var _getMythosForeignBalance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(address) {
|
|
937
1187
|
var res;
|
|
938
|
-
return _regeneratorRuntime().wrap(function
|
|
939
|
-
while (1) switch (
|
|
1188
|
+
return _regeneratorRuntime().wrap(function _callee0$(_context0) {
|
|
1189
|
+
while (1) switch (_context0.prev = _context0.next) {
|
|
940
1190
|
case 0:
|
|
941
|
-
|
|
1191
|
+
_context0.next = 2;
|
|
942
1192
|
return this.api.getUnsafeApi().query.Balances.Account.getValue(address);
|
|
943
1193
|
case 2:
|
|
944
|
-
res =
|
|
945
|
-
return
|
|
1194
|
+
res = _context0.sent;
|
|
1195
|
+
return _context0.abrupt("return", res && res.free ? BigInt(res.free) : 0n);
|
|
946
1196
|
case 4:
|
|
947
1197
|
case "end":
|
|
948
|
-
return
|
|
1198
|
+
return _context0.stop();
|
|
949
1199
|
}
|
|
950
|
-
},
|
|
1200
|
+
}, _callee0, this);
|
|
951
1201
|
}));
|
|
952
|
-
function getMythosForeignBalance(
|
|
1202
|
+
function getMythosForeignBalance(_x13) {
|
|
953
1203
|
return _getMythosForeignBalance.apply(this, arguments);
|
|
954
1204
|
}
|
|
955
1205
|
return getMythosForeignBalance;
|
|
@@ -957,24 +1207,24 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
957
1207
|
}, {
|
|
958
1208
|
key: "getBalanceForeignAssetsPallet",
|
|
959
1209
|
value: function () {
|
|
960
|
-
var _getBalanceForeignAssetsPallet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1210
|
+
var _getBalanceForeignAssetsPallet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee1(address, multiLocation) {
|
|
961
1211
|
var transformedMultiLocation, res;
|
|
962
|
-
return _regeneratorRuntime().wrap(function
|
|
963
|
-
while (1) switch (
|
|
1212
|
+
return _regeneratorRuntime().wrap(function _callee1$(_context1) {
|
|
1213
|
+
while (1) switch (_context1.prev = _context1.next) {
|
|
964
1214
|
case 0:
|
|
965
1215
|
transformedMultiLocation = _transform(multiLocation);
|
|
966
|
-
|
|
1216
|
+
_context1.next = 3;
|
|
967
1217
|
return this.api.getUnsafeApi().query.ForeignAssets.Account.getValue(transformedMultiLocation, address);
|
|
968
1218
|
case 3:
|
|
969
|
-
res =
|
|
970
|
-
return
|
|
1219
|
+
res = _context1.sent;
|
|
1220
|
+
return _context1.abrupt("return", BigInt(res === undefined ? 0 : res.balance));
|
|
971
1221
|
case 5:
|
|
972
1222
|
case "end":
|
|
973
|
-
return
|
|
1223
|
+
return _context1.stop();
|
|
974
1224
|
}
|
|
975
|
-
},
|
|
1225
|
+
}, _callee1, this);
|
|
976
1226
|
}));
|
|
977
|
-
function getBalanceForeignAssetsPallet(
|
|
1227
|
+
function getBalanceForeignAssetsPallet(_x14, _x15) {
|
|
978
1228
|
return _getBalanceForeignAssetsPallet.apply(this, arguments);
|
|
979
1229
|
}
|
|
980
1230
|
return getBalanceForeignAssetsPallet;
|
|
@@ -982,23 +1232,23 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
982
1232
|
}, {
|
|
983
1233
|
key: "getForeignAssetsByIdBalance",
|
|
984
1234
|
value: function () {
|
|
985
|
-
var _getForeignAssetsByIdBalance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1235
|
+
var _getForeignAssetsByIdBalance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(address, assetId) {
|
|
986
1236
|
var res;
|
|
987
|
-
return _regeneratorRuntime().wrap(function
|
|
988
|
-
while (1) switch (
|
|
1237
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1238
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
989
1239
|
case 0:
|
|
990
|
-
|
|
1240
|
+
_context10.next = 2;
|
|
991
1241
|
return this.api.getUnsafeApi().query.ForeignAssets.Account.getValue(assetId, address);
|
|
992
1242
|
case 2:
|
|
993
|
-
res =
|
|
994
|
-
return
|
|
1243
|
+
res = _context10.sent;
|
|
1244
|
+
return _context10.abrupt("return", BigInt(res === undefined ? 0 : res.balance));
|
|
995
1245
|
case 4:
|
|
996
1246
|
case "end":
|
|
997
|
-
return
|
|
1247
|
+
return _context10.stop();
|
|
998
1248
|
}
|
|
999
|
-
},
|
|
1249
|
+
}, _callee10, this);
|
|
1000
1250
|
}));
|
|
1001
|
-
function getForeignAssetsByIdBalance(
|
|
1251
|
+
function getForeignAssetsByIdBalance(_x16, _x17) {
|
|
1002
1252
|
return _getForeignAssetsByIdBalance.apply(this, arguments);
|
|
1003
1253
|
}
|
|
1004
1254
|
return getForeignAssetsByIdBalance;
|
|
@@ -1006,26 +1256,26 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1006
1256
|
}, {
|
|
1007
1257
|
key: "getBalanceForeignBifrost",
|
|
1008
1258
|
value: function () {
|
|
1009
|
-
var _getBalanceForeignBifrost = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1259
|
+
var _getBalanceForeignBifrost = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(address, asset) {
|
|
1010
1260
|
var currencySelection, transformedParameters, response, accountData;
|
|
1011
|
-
return _regeneratorRuntime().wrap(function
|
|
1012
|
-
while (1) switch (
|
|
1261
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
1262
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
1013
1263
|
case 0:
|
|
1014
1264
|
currencySelection = getNode('BifrostPolkadot').getCurrencySelection(asset);
|
|
1015
1265
|
transformedParameters = _transform(currencySelection);
|
|
1016
|
-
|
|
1266
|
+
_context11.next = 4;
|
|
1017
1267
|
return this.api.getUnsafeApi().query.Tokens.Accounts.getValue(address, transformedParameters);
|
|
1018
1268
|
case 4:
|
|
1019
|
-
response =
|
|
1269
|
+
response = _context11.sent;
|
|
1020
1270
|
accountData = response ? response : null;
|
|
1021
|
-
return
|
|
1271
|
+
return _context11.abrupt("return", accountData ? BigInt(accountData.free.toString()) : 0n);
|
|
1022
1272
|
case 7:
|
|
1023
1273
|
case "end":
|
|
1024
|
-
return
|
|
1274
|
+
return _context11.stop();
|
|
1025
1275
|
}
|
|
1026
|
-
},
|
|
1276
|
+
}, _callee11, this);
|
|
1027
1277
|
}));
|
|
1028
|
-
function getBalanceForeignBifrost(
|
|
1278
|
+
function getBalanceForeignBifrost(_x18, _x19) {
|
|
1029
1279
|
return _getBalanceForeignBifrost.apply(this, arguments);
|
|
1030
1280
|
}
|
|
1031
1281
|
return getBalanceForeignBifrost;
|
|
@@ -1033,27 +1283,27 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1033
1283
|
}, {
|
|
1034
1284
|
key: "getBalanceNativeAcala",
|
|
1035
1285
|
value: function () {
|
|
1036
|
-
var _getBalanceNativeAcala = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1286
|
+
var _getBalanceNativeAcala = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(address, symbol) {
|
|
1037
1287
|
var transformedParameters, response, accountData;
|
|
1038
|
-
return _regeneratorRuntime().wrap(function
|
|
1039
|
-
while (1) switch (
|
|
1288
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1289
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1040
1290
|
case 0:
|
|
1041
1291
|
transformedParameters = _transform({
|
|
1042
1292
|
Token: symbol
|
|
1043
1293
|
});
|
|
1044
|
-
|
|
1294
|
+
_context12.next = 3;
|
|
1045
1295
|
return this.api.getUnsafeApi().query.Tokens.Accounts.getValue(address, transformedParameters);
|
|
1046
1296
|
case 3:
|
|
1047
|
-
response =
|
|
1297
|
+
response = _context12.sent;
|
|
1048
1298
|
accountData = response ? response : null;
|
|
1049
|
-
return
|
|
1299
|
+
return _context12.abrupt("return", accountData ? BigInt(accountData.free.toString()) : 0n);
|
|
1050
1300
|
case 6:
|
|
1051
1301
|
case "end":
|
|
1052
|
-
return
|
|
1302
|
+
return _context12.stop();
|
|
1053
1303
|
}
|
|
1054
|
-
},
|
|
1304
|
+
}, _callee12, this);
|
|
1055
1305
|
}));
|
|
1056
|
-
function getBalanceNativeAcala(
|
|
1306
|
+
function getBalanceNativeAcala(_x20, _x21) {
|
|
1057
1307
|
return _getBalanceNativeAcala.apply(this, arguments);
|
|
1058
1308
|
}
|
|
1059
1309
|
return getBalanceNativeAcala;
|
|
@@ -1061,35 +1311,35 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1061
1311
|
}, {
|
|
1062
1312
|
key: "getBalanceForeignXTokens",
|
|
1063
1313
|
value: function () {
|
|
1064
|
-
var _getBalanceForeignXTokens = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1314
|
+
var _getBalanceForeignXTokens = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(node, address, asset) {
|
|
1065
1315
|
var pallet, response, entry;
|
|
1066
|
-
return _regeneratorRuntime().wrap(function
|
|
1067
|
-
while (1) switch (
|
|
1316
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1317
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1068
1318
|
case 0:
|
|
1069
1319
|
pallet = 'Tokens';
|
|
1070
1320
|
if (node === 'Centrifuge' || node === 'Altair') {
|
|
1071
1321
|
pallet = 'OrmlTokens';
|
|
1072
1322
|
}
|
|
1073
|
-
|
|
1323
|
+
_context13.next = 4;
|
|
1074
1324
|
return this.api.getUnsafeApi().query[pallet].Accounts.getEntries(address);
|
|
1075
1325
|
case 4:
|
|
1076
|
-
response =
|
|
1077
|
-
entry = response.find(function (
|
|
1326
|
+
response = _context13.sent;
|
|
1327
|
+
entry = response.find(function (_ref5) {
|
|
1078
1328
|
var _asset$symbol, _asset$assetId, _asset$symbol2, _asset$assetId2;
|
|
1079
|
-
var keyArgs =
|
|
1329
|
+
var keyArgs = _ref5.keyArgs;
|
|
1080
1330
|
var _keyArgs = _slicedToArray(keyArgs, 2);
|
|
1081
1331
|
_keyArgs[0];
|
|
1082
1332
|
var assetItem = _keyArgs[1];
|
|
1083
1333
|
return assetItem.toString().toLowerCase() === ((_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toLowerCase()) || isForeignAsset(asset) && assetItem.toString().toLowerCase() === ((_asset$assetId = asset.assetId) === null || _asset$assetId === void 0 ? void 0 : _asset$assetId.toLowerCase()) || _typeof(assetItem) === 'object' && 'value' in assetItem && assetItem.value.toString().toLowerCase() === ((_asset$symbol2 = asset.symbol) === null || _asset$symbol2 === void 0 ? void 0 : _asset$symbol2.toLowerCase()) || _typeof(assetItem) === 'object' && 'value' in assetItem && isForeignAsset(asset) && assetItem.value.toString().toLowerCase() === ((_asset$assetId2 = asset.assetId) === null || _asset$assetId2 === void 0 ? void 0 : _asset$assetId2.toLowerCase());
|
|
1084
1334
|
});
|
|
1085
|
-
return
|
|
1335
|
+
return _context13.abrupt("return", entry !== null && entry !== void 0 && entry.value ? BigInt(entry.value.free.toString()) : 0n);
|
|
1086
1336
|
case 7:
|
|
1087
1337
|
case "end":
|
|
1088
|
-
return
|
|
1338
|
+
return _context13.stop();
|
|
1089
1339
|
}
|
|
1090
|
-
},
|
|
1340
|
+
}, _callee13, this);
|
|
1091
1341
|
}));
|
|
1092
|
-
function getBalanceForeignXTokens(
|
|
1342
|
+
function getBalanceForeignXTokens(_x22, _x23, _x24) {
|
|
1093
1343
|
return _getBalanceForeignXTokens.apply(this, arguments);
|
|
1094
1344
|
}
|
|
1095
1345
|
return getBalanceForeignXTokens;
|
|
@@ -1097,23 +1347,23 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1097
1347
|
}, {
|
|
1098
1348
|
key: "getBalanceAssetsPallet",
|
|
1099
1349
|
value: function () {
|
|
1100
|
-
var _getBalanceAssetsPallet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1350
|
+
var _getBalanceAssetsPallet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(address, assetId) {
|
|
1101
1351
|
var response;
|
|
1102
|
-
return _regeneratorRuntime().wrap(function
|
|
1103
|
-
while (1) switch (
|
|
1352
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1353
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1104
1354
|
case 0:
|
|
1105
|
-
|
|
1355
|
+
_context14.next = 2;
|
|
1106
1356
|
return this.api.getUnsafeApi().query.Assets.Account.getValue(assetId, address);
|
|
1107
1357
|
case 2:
|
|
1108
|
-
response =
|
|
1109
|
-
return
|
|
1358
|
+
response = _context14.sent;
|
|
1359
|
+
return _context14.abrupt("return", BigInt(response === undefined ? 0 : response.balance));
|
|
1110
1360
|
case 4:
|
|
1111
1361
|
case "end":
|
|
1112
|
-
return
|
|
1362
|
+
return _context14.stop();
|
|
1113
1363
|
}
|
|
1114
|
-
},
|
|
1364
|
+
}, _callee14, this);
|
|
1115
1365
|
}));
|
|
1116
|
-
function getBalanceAssetsPallet(
|
|
1366
|
+
function getBalanceAssetsPallet(_x25, _x26) {
|
|
1117
1367
|
return _getBalanceAssetsPallet.apply(this, arguments);
|
|
1118
1368
|
}
|
|
1119
1369
|
return getBalanceAssetsPallet;
|
|
@@ -1121,24 +1371,24 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1121
1371
|
}, {
|
|
1122
1372
|
key: "getFromRpc",
|
|
1123
1373
|
value: function () {
|
|
1124
|
-
var _getFromRpc = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1374
|
+
var _getFromRpc = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15(module, method, key) {
|
|
1125
1375
|
var toSS58, value;
|
|
1126
|
-
return _regeneratorRuntime().wrap(function
|
|
1127
|
-
while (1) switch (
|
|
1376
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1377
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1128
1378
|
case 0:
|
|
1129
1379
|
toSS58 = AccountId().dec;
|
|
1130
|
-
|
|
1380
|
+
_context15.next = 3;
|
|
1131
1381
|
return this.api._request("".concat(module, "_").concat(method), [module === 'system' && isHex(key) && !ethers.isAddress(key) ? toSS58(key) : key]);
|
|
1132
1382
|
case 3:
|
|
1133
|
-
value =
|
|
1134
|
-
return
|
|
1383
|
+
value = _context15.sent;
|
|
1384
|
+
return _context15.abrupt("return", isHex(value) ? value : '0x' + value.toString(16).padStart(8, '0'));
|
|
1135
1385
|
case 5:
|
|
1136
1386
|
case "end":
|
|
1137
|
-
return
|
|
1387
|
+
return _context15.stop();
|
|
1138
1388
|
}
|
|
1139
|
-
},
|
|
1389
|
+
}, _callee15, this);
|
|
1140
1390
|
}));
|
|
1141
|
-
function getFromRpc(
|
|
1391
|
+
function getFromRpc(_x27, _x28, _x29) {
|
|
1142
1392
|
return _getFromRpc.apply(this, arguments);
|
|
1143
1393
|
}
|
|
1144
1394
|
return getFromRpc;
|
|
@@ -1151,23 +1401,23 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1151
1401
|
}, {
|
|
1152
1402
|
key: "createApiForNode",
|
|
1153
1403
|
value: function () {
|
|
1154
|
-
var _createApiForNode = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1404
|
+
var _createApiForNode = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee16(node) {
|
|
1155
1405
|
var api;
|
|
1156
|
-
return _regeneratorRuntime().wrap(function
|
|
1157
|
-
while (1) switch (
|
|
1406
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1407
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1158
1408
|
case 0:
|
|
1159
1409
|
api = new PapiApi();
|
|
1160
|
-
|
|
1410
|
+
_context16.next = 3;
|
|
1161
1411
|
return api.init(node);
|
|
1162
1412
|
case 3:
|
|
1163
|
-
return
|
|
1413
|
+
return _context16.abrupt("return", api);
|
|
1164
1414
|
case 4:
|
|
1165
1415
|
case "end":
|
|
1166
|
-
return
|
|
1416
|
+
return _context16.stop();
|
|
1167
1417
|
}
|
|
1168
|
-
},
|
|
1418
|
+
}, _callee16);
|
|
1169
1419
|
}));
|
|
1170
|
-
function createApiForNode(
|
|
1420
|
+
function createApiForNode(_x30) {
|
|
1171
1421
|
return _createApiForNode.apply(this, arguments);
|
|
1172
1422
|
}
|
|
1173
1423
|
return createApiForNode;
|
|
@@ -1175,16 +1425,16 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1175
1425
|
}, {
|
|
1176
1426
|
key: "getDryRunCall",
|
|
1177
1427
|
value: function () {
|
|
1178
|
-
var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1428
|
+
var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee17(_ref6) {
|
|
1179
1429
|
var _this$api$getUnsafeAp;
|
|
1180
1430
|
var tx, address, node, supportsDryRunApi, isBifrost, DEFAULT_XCM_VERSION, result, isSuccess, failureReason, executionFee, fee, actualWeight, weight, forwardedXcms, destParaId;
|
|
1181
|
-
return _regeneratorRuntime().wrap(function
|
|
1182
|
-
while (1) switch (
|
|
1431
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1432
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1183
1433
|
case 0:
|
|
1184
|
-
tx =
|
|
1434
|
+
tx = _ref6.tx, address = _ref6.address, node = _ref6.node;
|
|
1185
1435
|
supportsDryRunApi = getAssetsObject(node).supportsDryRunApi;
|
|
1186
1436
|
if (supportsDryRunApi) {
|
|
1187
|
-
|
|
1437
|
+
_context17.next = 4;
|
|
1188
1438
|
break;
|
|
1189
1439
|
}
|
|
1190
1440
|
throw new NodeNotSupportedError("DryRunApi is not available on node ".concat(node));
|
|
@@ -1192,7 +1442,7 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1192
1442
|
// These nodes require a third parameter XCM version
|
|
1193
1443
|
isBifrost = node === 'BifrostPolkadot' || node === 'BifrostKusama' || node === 'AssetHubKusama';
|
|
1194
1444
|
DEFAULT_XCM_VERSION = 3;
|
|
1195
|
-
|
|
1445
|
+
_context17.next = 8;
|
|
1196
1446
|
return (_this$api$getUnsafeAp = this.api.getUnsafeApi().apis.DryRunApi).dry_run_call.apply(_this$api$getUnsafeAp, [{
|
|
1197
1447
|
type: 'system',
|
|
1198
1448
|
value: {
|
|
@@ -1201,22 +1451,22 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1201
1451
|
}
|
|
1202
1452
|
}, tx.decodedCall].concat(_toConsumableArray(isBifrost ? [DEFAULT_XCM_VERSION] : [])));
|
|
1203
1453
|
case 8:
|
|
1204
|
-
result =
|
|
1454
|
+
result = _context17.sent;
|
|
1205
1455
|
isSuccess = result.success && result.value.execution_result.success;
|
|
1206
1456
|
if (isSuccess) {
|
|
1207
|
-
|
|
1457
|
+
_context17.next = 13;
|
|
1208
1458
|
break;
|
|
1209
1459
|
}
|
|
1210
1460
|
failureReason = result.value.execution_result.value.error.value.value.type;
|
|
1211
|
-
return
|
|
1461
|
+
return _context17.abrupt("return", Promise.resolve({
|
|
1212
1462
|
success: false,
|
|
1213
1463
|
failureReason: failureReason
|
|
1214
1464
|
}));
|
|
1215
1465
|
case 13:
|
|
1216
|
-
|
|
1466
|
+
_context17.next = 15;
|
|
1217
1467
|
return this.calculateTransactionFee(tx, address);
|
|
1218
1468
|
case 15:
|
|
1219
|
-
executionFee =
|
|
1469
|
+
executionFee = _context17.sent;
|
|
1220
1470
|
fee = computeFeeFromDryRun(result, node, executionFee);
|
|
1221
1471
|
actualWeight = result.value.execution_result.value.actual_weight;
|
|
1222
1472
|
weight = actualWeight ? {
|
|
@@ -1225,7 +1475,7 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1225
1475
|
} : undefined;
|
|
1226
1476
|
forwardedXcms = result.value.forwarded_xcms.length > 0 ? result.value.forwarded_xcms[0] : [];
|
|
1227
1477
|
destParaId = forwardedXcms.length === 0 ? undefined : forwardedXcms[0].value.interior.type === 'Here' ? 0 : forwardedXcms[0].value.interior.value.value;
|
|
1228
|
-
return
|
|
1478
|
+
return _context17.abrupt("return", Promise.resolve({
|
|
1229
1479
|
success: true,
|
|
1230
1480
|
fee: fee,
|
|
1231
1481
|
weight: weight,
|
|
@@ -1234,11 +1484,11 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1234
1484
|
}));
|
|
1235
1485
|
case 22:
|
|
1236
1486
|
case "end":
|
|
1237
|
-
return
|
|
1487
|
+
return _context17.stop();
|
|
1238
1488
|
}
|
|
1239
|
-
},
|
|
1489
|
+
}, _callee17, this);
|
|
1240
1490
|
}));
|
|
1241
|
-
function getDryRunCall(
|
|
1491
|
+
function getDryRunCall(_x31) {
|
|
1242
1492
|
return _getDryRunCall.apply(this, arguments);
|
|
1243
1493
|
}
|
|
1244
1494
|
return getDryRunCall;
|
|
@@ -1246,32 +1496,32 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1246
1496
|
}, {
|
|
1247
1497
|
key: "getDryRunXcm",
|
|
1248
1498
|
value: function () {
|
|
1249
|
-
var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1250
|
-
var
|
|
1499
|
+
var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee18(_ref7) {
|
|
1500
|
+
var _ref8, _ref9, _ref0;
|
|
1251
1501
|
var originLocation, xcm, node, origin, supportsDryRunApi, transformedOriginLocation, result, isSuccess, failureReason, emitted, reversedEvents, palletsWithIssued, feeEvent, fee, actualWeight, weight, forwardedXcms, destParaId;
|
|
1252
|
-
return _regeneratorRuntime().wrap(function
|
|
1253
|
-
while (1) switch (
|
|
1502
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1503
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1254
1504
|
case 0:
|
|
1255
|
-
originLocation =
|
|
1505
|
+
originLocation = _ref7.originLocation, xcm = _ref7.xcm, node = _ref7.node, origin = _ref7.origin;
|
|
1256
1506
|
supportsDryRunApi = getAssetsObject(node).supportsDryRunApi;
|
|
1257
1507
|
if (supportsDryRunApi) {
|
|
1258
|
-
|
|
1508
|
+
_context18.next = 4;
|
|
1259
1509
|
break;
|
|
1260
1510
|
}
|
|
1261
1511
|
throw new NodeNotSupportedError("DryRunApi is not available on node ".concat(node));
|
|
1262
1512
|
case 4:
|
|
1263
1513
|
transformedOriginLocation = _transform(originLocation);
|
|
1264
|
-
|
|
1514
|
+
_context18.next = 7;
|
|
1265
1515
|
return this.api.getUnsafeApi().apis.DryRunApi.dry_run_xcm(transformedOriginLocation, xcm);
|
|
1266
1516
|
case 7:
|
|
1267
|
-
result =
|
|
1517
|
+
result = _context18.sent;
|
|
1268
1518
|
isSuccess = result.success && result.value.execution_result.type === 'Complete';
|
|
1269
1519
|
if (isSuccess) {
|
|
1270
|
-
|
|
1520
|
+
_context18.next = 12;
|
|
1271
1521
|
break;
|
|
1272
1522
|
}
|
|
1273
1523
|
failureReason = result.value.execution_result.value.error.type;
|
|
1274
|
-
return
|
|
1524
|
+
return _context18.abrupt("return", Promise.resolve({
|
|
1275
1525
|
success: false,
|
|
1276
1526
|
failureReason: failureReason
|
|
1277
1527
|
}));
|
|
@@ -1279,24 +1529,24 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1279
1529
|
emitted = result.value.emitted_events; // We want to look for the last event
|
|
1280
1530
|
reversedEvents = _toConsumableArray(emitted).reverse();
|
|
1281
1531
|
palletsWithIssued = ['Balances', 'ForeignAssets', 'Assets'];
|
|
1282
|
-
feeEvent = (
|
|
1532
|
+
feeEvent = (_ref8 = (_ref9 = (_ref0 = origin === 'Mythos' ? reversedEvents.find(function (event) {
|
|
1283
1533
|
return event.type === 'AssetConversion' && event.value.type === 'SwapCreditExecuted';
|
|
1284
|
-
}) : undefined) !== null &&
|
|
1534
|
+
}) : undefined) !== null && _ref0 !== void 0 ? _ref0 :
|
|
1285
1535
|
// Prefer an Issued event
|
|
1286
1536
|
reversedEvents.find(function (event) {
|
|
1287
1537
|
return palletsWithIssued.includes(event.type) && event.value.type === 'Issued';
|
|
1288
|
-
})) !== null &&
|
|
1538
|
+
})) !== null && _ref9 !== void 0 ? _ref9 :
|
|
1289
1539
|
// Fallback to Minted event
|
|
1290
1540
|
reversedEvents.find(function (event) {
|
|
1291
1541
|
return ['Balances', 'ForeignAssets'].includes(event.type) && event.value.type === 'Minted';
|
|
1292
|
-
})) !== null &&
|
|
1542
|
+
})) !== null && _ref8 !== void 0 ? _ref8 : reversedEvents.find(function (event) {
|
|
1293
1543
|
return ['Currencies', 'Tokens'].includes(event.type) && event.value.type === 'Deposited';
|
|
1294
1544
|
});
|
|
1295
1545
|
if (feeEvent) {
|
|
1296
|
-
|
|
1546
|
+
_context18.next = 18;
|
|
1297
1547
|
break;
|
|
1298
1548
|
}
|
|
1299
|
-
return
|
|
1549
|
+
return _context18.abrupt("return", Promise.resolve({
|
|
1300
1550
|
success: false,
|
|
1301
1551
|
failureReason: 'Cannot determine destination fee. No Issued event found'
|
|
1302
1552
|
}));
|
|
@@ -1309,7 +1559,7 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1309
1559
|
} : undefined;
|
|
1310
1560
|
forwardedXcms = result.value.forwarded_xcms.length > 0 ? result.value.forwarded_xcms[0] : [];
|
|
1311
1561
|
destParaId = forwardedXcms.length === 0 ? undefined : forwardedXcms[0].value.interior.type === 'Here' ? 0 : forwardedXcms[0].value.interior.value.value;
|
|
1312
|
-
return
|
|
1562
|
+
return _context18.abrupt("return", Promise.resolve({
|
|
1313
1563
|
success: true,
|
|
1314
1564
|
fee: fee,
|
|
1315
1565
|
weight: weight,
|
|
@@ -1318,11 +1568,11 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1318
1568
|
}));
|
|
1319
1569
|
case 24:
|
|
1320
1570
|
case "end":
|
|
1321
|
-
return
|
|
1571
|
+
return _context18.stop();
|
|
1322
1572
|
}
|
|
1323
|
-
},
|
|
1573
|
+
}, _callee18, this);
|
|
1324
1574
|
}));
|
|
1325
|
-
function getDryRunXcm(
|
|
1575
|
+
function getDryRunXcm(_x32) {
|
|
1326
1576
|
return _getDryRunXcm.apply(this, arguments);
|
|
1327
1577
|
}
|
|
1328
1578
|
return getDryRunXcm;
|
|
@@ -1330,21 +1580,21 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1330
1580
|
}, {
|
|
1331
1581
|
key: "getBridgeStatus",
|
|
1332
1582
|
value: function () {
|
|
1333
|
-
var _getBridgeStatus = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1583
|
+
var _getBridgeStatus = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
1334
1584
|
var outboundOperatingMode;
|
|
1335
|
-
return _regeneratorRuntime().wrap(function
|
|
1336
|
-
while (1) switch (
|
|
1585
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1586
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1337
1587
|
case 0:
|
|
1338
|
-
|
|
1588
|
+
_context19.next = 2;
|
|
1339
1589
|
return this.api.getUnsafeApi().query.EthereumOutboundQueue.OperatingMode.getValue();
|
|
1340
1590
|
case 2:
|
|
1341
|
-
outboundOperatingMode =
|
|
1342
|
-
return
|
|
1591
|
+
outboundOperatingMode = _context19.sent;
|
|
1592
|
+
return _context19.abrupt("return", outboundOperatingMode.type);
|
|
1343
1593
|
case 4:
|
|
1344
1594
|
case "end":
|
|
1345
|
-
return
|
|
1595
|
+
return _context19.stop();
|
|
1346
1596
|
}
|
|
1347
|
-
},
|
|
1597
|
+
}, _callee19, this);
|
|
1348
1598
|
}));
|
|
1349
1599
|
function getBridgeStatus() {
|
|
1350
1600
|
return _getBridgeStatus.apply(this, arguments);
|
|
@@ -1367,10 +1617,19 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1367
1617
|
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1368
1618
|
if (!this.initialized) return Promise.resolve();
|
|
1369
1619
|
if (!force && !this.disconnectAllowed) return Promise.resolve();
|
|
1370
|
-
//
|
|
1371
|
-
if (force
|
|
1620
|
+
// Own client provided, destroy only if force true
|
|
1621
|
+
if (force && _typeof(this._api) === 'object') {
|
|
1372
1622
|
this.api.destroy();
|
|
1373
1623
|
}
|
|
1624
|
+
// Client created automatically
|
|
1625
|
+
if (typeof this._api === 'string' || Array.isArray(this._api) || this._api === undefined) {
|
|
1626
|
+
if (force) {
|
|
1627
|
+
this.api.destroy();
|
|
1628
|
+
} else {
|
|
1629
|
+
var key = this._api === undefined ? getNodeProviders(this._node) : this._api;
|
|
1630
|
+
releasePolkadotClient(key);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1374
1633
|
return Promise.resolve();
|
|
1375
1634
|
}
|
|
1376
1635
|
}]);
|