@paraspell/sdk-pjs 8.6.0 → 8.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +998 -1020
- package/dist/index.d.ts +72 -75
- package/dist/index.mjs +802 -823
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BatchMode, createApiInstanceForNode as createApiInstanceForNode$1, getNode, isForeignAsset, computeFeeFromDryRunPjs, resolveModuleError, 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, getAllAssetsSymbols, getAssetBySymbolOrId, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTNode, hasSupportForAsset, isNodeEvm, getParaId, InvalidCurrencyError, isEthersSigner, isOverrideMultiLocationSpecifier, validateAddress, transferMoonbeamToEth, transferMoonbeamEvm, Builder as Builder$1, getParaEthTransferFees as getParaEthTransferFees$1, send as send$1, getDryRun as getDryRun$1 } from '@paraspell/sdk-core';
|
|
2
2
|
export * from '@paraspell/sdk-core';
|
|
3
|
-
import { Context, toPolkadotV2, assetsV2, environment } from '@snowbridge/api';
|
|
4
|
-
import { WETH9__factory } from '@snowbridge/contract-types';
|
|
5
3
|
import { WsProvider, ApiPromise } from '@polkadot/api';
|
|
6
4
|
import { u32 } from '@polkadot/types';
|
|
7
|
-
import { decodeAddress, blake2AsHex } from '@polkadot/util-crypto';
|
|
8
5
|
import { isHex, u8aToHex, hexToU8a, stringToU8a } from '@polkadot/util';
|
|
6
|
+
import { decodeAddress, blake2AsHex } from '@polkadot/util-crypto';
|
|
7
|
+
import { environment, Context, toPolkadotV2, assetsV2 } from '@snowbridge/api';
|
|
8
|
+
import { WETH9__factory } from '@snowbridge/contract-types';
|
|
9
9
|
|
|
10
10
|
function _arrayLikeToArray(r, a) {
|
|
11
11
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -436,669 +436,344 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
-
var
|
|
440
|
-
return
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
polkadot: {
|
|
446
|
-
assetHubParaId: config.ASSET_HUB_PARAID,
|
|
447
|
-
bridgeHubParaId: config.BRIDGE_HUB_PARAID,
|
|
448
|
-
parachains: config.PARACHAINS,
|
|
449
|
-
relaychain: config.RELAY_CHAIN_URL
|
|
450
|
-
},
|
|
451
|
-
appContracts: {
|
|
452
|
-
gateway: config.GATEWAY_CONTRACT,
|
|
453
|
-
beefy: config.BEEFY_CONTRACT
|
|
454
|
-
}
|
|
439
|
+
var lowercaseFirstLetter = function lowercaseFirstLetter(value) {
|
|
440
|
+
return value.charAt(0).toLowerCase() + value.slice(1);
|
|
441
|
+
};
|
|
442
|
+
var snakeToCamel = function snakeToCamel(str) {
|
|
443
|
+
return str.toLowerCase().replace(/([-_][a-z])/g, function (group) {
|
|
444
|
+
return group.toUpperCase().replace('-', '').replace('_', '');
|
|
455
445
|
});
|
|
456
446
|
};
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
447
|
+
var PolkadotJsApi = /*#__PURE__*/function () {
|
|
448
|
+
function PolkadotJsApi() {
|
|
449
|
+
_classCallCheck(this, PolkadotJsApi);
|
|
450
|
+
this.initialized = false;
|
|
451
|
+
this.disconnectAllowed = true;
|
|
452
|
+
}
|
|
453
|
+
return _createClass(PolkadotJsApi, [{
|
|
454
|
+
key: "setApi",
|
|
455
|
+
value: function setApi(api) {
|
|
456
|
+
this._api = api;
|
|
457
|
+
}
|
|
458
|
+
}, {
|
|
459
|
+
key: "getApiOrUrl",
|
|
460
|
+
value: function getApiOrUrl() {
|
|
461
|
+
return this._api;
|
|
462
|
+
}
|
|
463
|
+
}, {
|
|
464
|
+
key: "getApi",
|
|
465
|
+
value: function getApi() {
|
|
466
|
+
return this.api;
|
|
467
|
+
}
|
|
468
|
+
}, {
|
|
469
|
+
key: "init",
|
|
470
|
+
value: function () {
|
|
471
|
+
var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(node) {
|
|
472
|
+
var _this$_api;
|
|
473
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
474
|
+
while (1) switch (_context.prev = _context.next) {
|
|
475
|
+
case 0:
|
|
476
|
+
if (!this.initialized) {
|
|
477
|
+
_context.next = 2;
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
return _context.abrupt("return");
|
|
481
|
+
case 2:
|
|
482
|
+
if (!(typeof this._api === 'string' || this._api instanceof Array)) {
|
|
483
|
+
_context.next = 8;
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
_context.next = 5;
|
|
487
|
+
return this.createApiInstance(this._api);
|
|
488
|
+
case 5:
|
|
489
|
+
this.api = _context.sent;
|
|
490
|
+
_context.next = 16;
|
|
491
|
+
break;
|
|
492
|
+
case 8:
|
|
493
|
+
if (!((_this$_api = this._api) !== null && _this$_api !== void 0)) {
|
|
494
|
+
_context.next = 12;
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
_context.t0 = _this$_api;
|
|
498
|
+
_context.next = 15;
|
|
499
|
+
break;
|
|
500
|
+
case 12:
|
|
501
|
+
_context.next = 14;
|
|
502
|
+
return createApiInstanceForNode$1(this, node);
|
|
503
|
+
case 14:
|
|
504
|
+
_context.t0 = _context.sent;
|
|
505
|
+
case 15:
|
|
506
|
+
this.api = _context.t0;
|
|
507
|
+
case 16:
|
|
508
|
+
this.initialized = true;
|
|
509
|
+
case 17:
|
|
510
|
+
case "end":
|
|
511
|
+
return _context.stop();
|
|
490
512
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
513
|
+
}, _callee, this);
|
|
514
|
+
}));
|
|
515
|
+
function init(_x) {
|
|
516
|
+
return _init.apply(this, arguments);
|
|
517
|
+
}
|
|
518
|
+
return init;
|
|
519
|
+
}()
|
|
520
|
+
}, {
|
|
521
|
+
key: "createApiInstance",
|
|
522
|
+
value: function () {
|
|
523
|
+
var _createApiInstance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(wsUrl) {
|
|
524
|
+
var wsProvider;
|
|
525
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
526
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
527
|
+
case 0:
|
|
528
|
+
wsProvider = new WsProvider(wsUrl);
|
|
529
|
+
return _context2.abrupt("return", ApiPromise.create({
|
|
530
|
+
provider: wsProvider
|
|
531
|
+
}));
|
|
532
|
+
case 2:
|
|
533
|
+
case "end":
|
|
534
|
+
return _context2.stop();
|
|
496
535
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
536
|
+
}, _callee2);
|
|
537
|
+
}));
|
|
538
|
+
function createApiInstance(_x2) {
|
|
539
|
+
return _createApiInstance.apply(this, arguments);
|
|
540
|
+
}
|
|
541
|
+
return createApiInstance;
|
|
542
|
+
}()
|
|
543
|
+
}, {
|
|
544
|
+
key: "accountToHex",
|
|
545
|
+
value: function accountToHex(address) {
|
|
546
|
+
var isPrefixed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
547
|
+
if (isHex(address)) return address;
|
|
548
|
+
var uint8Array = decodeAddress(address);
|
|
549
|
+
return u8aToHex(uint8Array, -1, isPrefixed);
|
|
550
|
+
}
|
|
551
|
+
}, {
|
|
552
|
+
key: "callTxMethod",
|
|
553
|
+
value: function callTxMethod(_ref) {
|
|
554
|
+
var _this$api$tx$moduleLo;
|
|
555
|
+
var module = _ref.module,
|
|
556
|
+
section = _ref.section,
|
|
557
|
+
parameters = _ref.parameters;
|
|
558
|
+
var values = Object.values(parameters);
|
|
559
|
+
var moduleLowerCase = lowercaseFirstLetter(module);
|
|
560
|
+
var sectionCamelCase = snakeToCamel(section);
|
|
561
|
+
return (_this$api$tx$moduleLo = this.api.tx[moduleLowerCase])[sectionCamelCase].apply(_this$api$tx$moduleLo, values);
|
|
562
|
+
}
|
|
563
|
+
}, {
|
|
564
|
+
key: "callBatchMethod",
|
|
565
|
+
value: function callBatchMethod(calls, mode) {
|
|
566
|
+
var section = mode === BatchMode.BATCH_ALL ? 'batchAll' : 'batch';
|
|
567
|
+
return this.api.tx.utility[section](calls);
|
|
568
|
+
}
|
|
569
|
+
}, {
|
|
570
|
+
key: "objectToHex",
|
|
571
|
+
value: function objectToHex(obj, typeName) {
|
|
572
|
+
return Promise.resolve(this.api.createType(typeName, obj).toHex());
|
|
573
|
+
}
|
|
574
|
+
}, {
|
|
575
|
+
key: "hexToUint8a",
|
|
576
|
+
value: function hexToUint8a(hex) {
|
|
577
|
+
return hexToU8a(hex);
|
|
578
|
+
}
|
|
579
|
+
}, {
|
|
580
|
+
key: "stringToUint8a",
|
|
581
|
+
value: function stringToUint8a(str) {
|
|
582
|
+
return stringToU8a(str);
|
|
583
|
+
}
|
|
584
|
+
}, {
|
|
585
|
+
key: "calculateTransactionFee",
|
|
586
|
+
value: function () {
|
|
587
|
+
var _calculateTransactionFee = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(tx, address) {
|
|
588
|
+
var _yield$tx$paymentInfo, partialFee;
|
|
589
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
590
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
591
|
+
case 0:
|
|
592
|
+
_context3.next = 2;
|
|
593
|
+
return tx.paymentInfo(address);
|
|
594
|
+
case 2:
|
|
595
|
+
_yield$tx$paymentInfo = _context3.sent;
|
|
596
|
+
partialFee = _yield$tx$paymentInfo.partialFee;
|
|
597
|
+
return _context3.abrupt("return", partialFee.toBigInt());
|
|
598
|
+
case 5:
|
|
599
|
+
case "end":
|
|
600
|
+
return _context3.stop();
|
|
503
601
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
602
|
+
}, _callee3);
|
|
603
|
+
}));
|
|
604
|
+
function calculateTransactionFee(_x3, _x4) {
|
|
605
|
+
return _calculateTransactionFee.apply(this, arguments);
|
|
606
|
+
}
|
|
607
|
+
return calculateTransactionFee;
|
|
608
|
+
}()
|
|
609
|
+
}, {
|
|
610
|
+
key: "getBalanceNative",
|
|
611
|
+
value: function () {
|
|
612
|
+
var _getBalanceNative = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(address) {
|
|
613
|
+
var response;
|
|
614
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
615
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
616
|
+
case 0:
|
|
617
|
+
_context4.next = 2;
|
|
618
|
+
return this.api.query.system.account(address);
|
|
619
|
+
case 2:
|
|
620
|
+
response = _context4.sent;
|
|
621
|
+
return _context4.abrupt("return", response.data.free.toBigInt());
|
|
622
|
+
case 4:
|
|
623
|
+
case "end":
|
|
624
|
+
return _context4.stop();
|
|
512
625
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
'2004': '0x000000000000000000000000000000000000081A'
|
|
518
|
-
},
|
|
519
|
-
destinationFeeOverrides: {
|
|
520
|
-
'3369': 500000000n
|
|
521
|
-
},
|
|
522
|
-
assetOverrides: {
|
|
523
|
-
'3369': [{
|
|
524
|
-
token: '0xba41ddf06b7ffd89d1267b5a93bfef2424eb2003'.toLowerCase(),
|
|
525
|
-
name: 'Mythos',
|
|
526
|
-
minimumBalance: 10000000000000000n,
|
|
527
|
-
symbol: 'MYTH',
|
|
528
|
-
decimals: 18,
|
|
529
|
-
isSufficient: true
|
|
530
|
-
}]
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
_context.t0 = assetsV2;
|
|
534
|
-
_context.t1 = _objectSpread2;
|
|
535
|
-
_context.t2 = _objectSpread2;
|
|
536
|
-
_context.t3 = {};
|
|
537
|
-
_context.next = 24;
|
|
538
|
-
return assetsV2.fromContext(context);
|
|
539
|
-
case 24:
|
|
540
|
-
_context.t4 = _context.sent;
|
|
541
|
-
_context.t5 = (0, _context.t2)(_context.t3, _context.t4);
|
|
542
|
-
_context.t6 = overrides;
|
|
543
|
-
_context.t7 = (0, _context.t1)(_context.t5, _context.t6);
|
|
544
|
-
_context.next = 30;
|
|
545
|
-
return _context.t0.buildRegistry.call(_context.t0, _context.t7);
|
|
546
|
-
case 30:
|
|
547
|
-
registry = _context.sent;
|
|
548
|
-
_context.next = 33;
|
|
549
|
-
return toPolkadotV2.getDeliveryFee(context.gateway(), registry, ethAsset.assetId, destParaId);
|
|
550
|
-
case 33:
|
|
551
|
-
fee = _context.sent;
|
|
552
|
-
_context.next = 36;
|
|
553
|
-
return signer.getAddress();
|
|
554
|
-
case 36:
|
|
555
|
-
sourceAddress = _context.sent;
|
|
556
|
-
_context.next = 39;
|
|
557
|
-
return toPolkadotV2.createTransfer(registry, sourceAddress, address, ethAsset.assetId, destParaId, BigInt(currency.amount), fee);
|
|
558
|
-
case 39:
|
|
559
|
-
transfer = _context.sent;
|
|
560
|
-
_context.t8 = toPolkadotV2;
|
|
561
|
-
_context.t9 = context.ethereum();
|
|
562
|
-
_context.t10 = context.gateway();
|
|
563
|
-
_context.next = 45;
|
|
564
|
-
return context.bridgeHub();
|
|
565
|
-
case 45:
|
|
566
|
-
_context.t11 = _context.sent;
|
|
567
|
-
_context.next = 48;
|
|
568
|
-
return context.assetHub();
|
|
569
|
-
case 48:
|
|
570
|
-
_context.t12 = _context.sent;
|
|
571
|
-
if (!(destParaId !== getParaId('AssetHubPolkadot'))) {
|
|
572
|
-
_context.next = 55;
|
|
573
|
-
break;
|
|
574
|
-
}
|
|
575
|
-
_context.next = 52;
|
|
576
|
-
return context.parachain(destParaId);
|
|
577
|
-
case 52:
|
|
578
|
-
_context.t13 = _context.sent;
|
|
579
|
-
_context.next = 56;
|
|
580
|
-
break;
|
|
581
|
-
case 55:
|
|
582
|
-
_context.t13 = undefined;
|
|
583
|
-
case 56:
|
|
584
|
-
_context.t14 = _context.t13;
|
|
585
|
-
_context.t15 = {
|
|
586
|
-
ethereum: _context.t9,
|
|
587
|
-
gateway: _context.t10,
|
|
588
|
-
bridgeHub: _context.t11,
|
|
589
|
-
assetHub: _context.t12,
|
|
590
|
-
destParachain: _context.t14
|
|
591
|
-
};
|
|
592
|
-
_context.t16 = transfer;
|
|
593
|
-
_context.next = 61;
|
|
594
|
-
return _context.t8.validateTransfer.call(_context.t8, _context.t15, _context.t16);
|
|
595
|
-
case 61:
|
|
596
|
-
validation = _context.sent;
|
|
597
|
-
if (!validation.logs.find(function (l) {
|
|
598
|
-
return l.kind == toPolkadotV2.ValidationKind.Error;
|
|
599
|
-
})) {
|
|
600
|
-
_context.next = 64;
|
|
601
|
-
break;
|
|
602
|
-
}
|
|
603
|
-
throw Error("Validation failed with following errors: \n\n ".concat(validation.logs.filter(function (l) {
|
|
604
|
-
return l.kind == toPolkadotV2.ValidationKind.Error;
|
|
605
|
-
}).map(function (l) {
|
|
606
|
-
return l.message;
|
|
607
|
-
}).join('\n\n')));
|
|
608
|
-
case 64:
|
|
609
|
-
tx = transfer.tx;
|
|
610
|
-
_context.next = 67;
|
|
611
|
-
return signer.sendTransaction(tx);
|
|
612
|
-
case 67:
|
|
613
|
-
response = _context.sent;
|
|
614
|
-
_context.next = 70;
|
|
615
|
-
return response.wait(1);
|
|
616
|
-
case 70:
|
|
617
|
-
receipt = _context.sent;
|
|
618
|
-
if (receipt) {
|
|
619
|
-
_context.next = 73;
|
|
620
|
-
break;
|
|
621
|
-
}
|
|
622
|
-
throw Error("Transaction ".concat(response.hash, " not included."));
|
|
623
|
-
case 73:
|
|
624
|
-
_context.next = 75;
|
|
625
|
-
return toPolkadotV2.getMessageReceipt(receipt);
|
|
626
|
-
case 75:
|
|
627
|
-
messageReceipt = _context.sent;
|
|
628
|
-
if (messageReceipt) {
|
|
629
|
-
_context.next = 78;
|
|
630
|
-
break;
|
|
631
|
-
}
|
|
632
|
-
throw Error("Transaction ".concat(receipt.hash, " did not emit a message."));
|
|
633
|
-
case 78:
|
|
634
|
-
return _context.abrupt("return", {
|
|
635
|
-
response: response,
|
|
636
|
-
messageReceipt: messageReceipt
|
|
637
|
-
});
|
|
638
|
-
case 79:
|
|
639
|
-
case "end":
|
|
640
|
-
return _context.stop();
|
|
626
|
+
}, _callee4, this);
|
|
627
|
+
}));
|
|
628
|
+
function getBalanceNative(_x5) {
|
|
629
|
+
return _getBalanceNative.apply(this, arguments);
|
|
641
630
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
631
|
+
return getBalanceNative;
|
|
632
|
+
}()
|
|
633
|
+
}, {
|
|
634
|
+
key: "getBalanceForeignPolkadotXcm",
|
|
635
|
+
value: function () {
|
|
636
|
+
var _getBalanceForeignPolkadotXcm = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(address, id) {
|
|
637
|
+
var parsedId, response, obj;
|
|
638
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
639
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
640
|
+
case 0:
|
|
641
|
+
parsedId = new u32(this.api.registry, id);
|
|
642
|
+
_context5.next = 3;
|
|
643
|
+
return this.api.query.assets.account(parsedId, address);
|
|
644
|
+
case 3:
|
|
645
|
+
response = _context5.sent;
|
|
646
|
+
obj = response.toJSON();
|
|
647
|
+
return _context5.abrupt("return", obj.balance ? BigInt(obj.balance) : 0n);
|
|
648
|
+
case 6:
|
|
649
|
+
case "end":
|
|
650
|
+
return _context5.stop();
|
|
662
651
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
return weth9.deposit({
|
|
668
|
-
value: amount
|
|
669
|
-
});
|
|
670
|
-
case 7:
|
|
671
|
-
result = _context.sent;
|
|
672
|
-
_context.next = 10;
|
|
673
|
-
return result.wait();
|
|
674
|
-
case 10:
|
|
675
|
-
receipt = _context.sent;
|
|
676
|
-
return _context.abrupt("return", {
|
|
677
|
-
result: result,
|
|
678
|
-
receipt: receipt
|
|
679
|
-
});
|
|
680
|
-
case 12:
|
|
681
|
-
case "end":
|
|
682
|
-
return _context.stop();
|
|
652
|
+
}, _callee5, this);
|
|
653
|
+
}));
|
|
654
|
+
function getBalanceForeignPolkadotXcm(_x6, _x7) {
|
|
655
|
+
return _getBalanceForeignPolkadotXcm.apply(this, arguments);
|
|
683
656
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
break;
|
|
657
|
+
return getBalanceForeignPolkadotXcm;
|
|
658
|
+
}()
|
|
659
|
+
}, {
|
|
660
|
+
key: "getMythosForeignBalance",
|
|
661
|
+
value: function () {
|
|
662
|
+
var _getMythosForeignBalance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(address) {
|
|
663
|
+
var response, obj;
|
|
664
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
665
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
666
|
+
case 0:
|
|
667
|
+
_context6.next = 2;
|
|
668
|
+
return this.api.query.balances.account(address);
|
|
669
|
+
case 2:
|
|
670
|
+
response = _context6.sent;
|
|
671
|
+
obj = response.toJSON();
|
|
672
|
+
return _context6.abrupt("return", obj.free ? BigInt(obj.free) : 0n);
|
|
673
|
+
case 5:
|
|
674
|
+
case "end":
|
|
675
|
+
return _context6.stop();
|
|
704
676
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
return weth9.approve(env.config.GATEWAY_CONTRACT, amount);
|
|
710
|
-
case 7:
|
|
711
|
-
result = _context.sent;
|
|
712
|
-
_context.next = 10;
|
|
713
|
-
return result.wait();
|
|
714
|
-
case 10:
|
|
715
|
-
receipt = _context.sent;
|
|
716
|
-
return _context.abrupt("return", {
|
|
717
|
-
result: result,
|
|
718
|
-
receipt: receipt
|
|
719
|
-
});
|
|
720
|
-
case 12:
|
|
721
|
-
case "end":
|
|
722
|
-
return _context.stop();
|
|
677
|
+
}, _callee6, this);
|
|
678
|
+
}));
|
|
679
|
+
function getMythosForeignBalance(_x8) {
|
|
680
|
+
return _getMythosForeignBalance.apply(this, arguments);
|
|
723
681
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
return function approveToken(_x, _x2, _x3) {
|
|
727
|
-
return _ref.apply(this, arguments);
|
|
728
|
-
};
|
|
729
|
-
}();
|
|
730
|
-
|
|
731
|
-
var getTokenBalance = /*#__PURE__*/function () {
|
|
732
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(signer, symbol) {
|
|
733
|
-
var env, contract, weth9, address;
|
|
734
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
735
|
-
while (1) switch (_context.prev = _context.next) {
|
|
736
|
-
case 0:
|
|
737
|
-
env = environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
|
|
738
|
-
contract = env.locations[0].erc20tokensReceivable.find(function (t) {
|
|
739
|
-
return t.id === symbol;
|
|
740
|
-
});
|
|
741
|
-
if (contract) {
|
|
742
|
-
_context.next = 4;
|
|
743
|
-
break;
|
|
744
|
-
}
|
|
745
|
-
throw new Error("Token ".concat(symbol, " not supported"));
|
|
746
|
-
case 4:
|
|
747
|
-
weth9 = WETH9__factory.connect(contract.address, signer);
|
|
748
|
-
_context.next = 7;
|
|
749
|
-
return signer.getAddress();
|
|
750
|
-
case 7:
|
|
751
|
-
address = _context.sent;
|
|
752
|
-
return _context.abrupt("return", weth9.balanceOf(address));
|
|
753
|
-
case 9:
|
|
754
|
-
case "end":
|
|
755
|
-
return _context.stop();
|
|
756
|
-
}
|
|
757
|
-
}, _callee);
|
|
758
|
-
}));
|
|
759
|
-
return function getTokenBalance(_x, _x2) {
|
|
760
|
-
return _ref.apply(this, arguments);
|
|
761
|
-
};
|
|
762
|
-
}();
|
|
763
|
-
|
|
764
|
-
var lowercaseFirstLetter = function lowercaseFirstLetter(value) {
|
|
765
|
-
return value.charAt(0).toLowerCase() + value.slice(1);
|
|
766
|
-
};
|
|
767
|
-
var snakeToCamel = function snakeToCamel(str) {
|
|
768
|
-
return str.toLowerCase().replace(/([-_][a-z])/g, function (group) {
|
|
769
|
-
return group.toUpperCase().replace('-', '').replace('_', '');
|
|
770
|
-
});
|
|
771
|
-
};
|
|
772
|
-
var PolkadotJsApi = /*#__PURE__*/function () {
|
|
773
|
-
function PolkadotJsApi() {
|
|
774
|
-
_classCallCheck(this, PolkadotJsApi);
|
|
775
|
-
this.initialized = false;
|
|
776
|
-
this.disconnectAllowed = true;
|
|
777
|
-
}
|
|
778
|
-
return _createClass(PolkadotJsApi, [{
|
|
779
|
-
key: "setApi",
|
|
780
|
-
value: function setApi(api) {
|
|
781
|
-
this._api = api;
|
|
782
|
-
}
|
|
783
|
-
}, {
|
|
784
|
-
key: "getApiOrUrl",
|
|
785
|
-
value: function getApiOrUrl() {
|
|
786
|
-
return this._api;
|
|
787
|
-
}
|
|
788
|
-
}, {
|
|
789
|
-
key: "getApi",
|
|
790
|
-
value: function getApi() {
|
|
791
|
-
return this.api;
|
|
792
|
-
}
|
|
682
|
+
return getMythosForeignBalance;
|
|
683
|
+
}()
|
|
793
684
|
}, {
|
|
794
|
-
key: "
|
|
685
|
+
key: "getAssetHubForeignBalance",
|
|
795
686
|
value: function () {
|
|
796
|
-
var
|
|
797
|
-
var
|
|
798
|
-
return _regeneratorRuntime().wrap(function
|
|
799
|
-
while (1) switch (
|
|
687
|
+
var _getAssetHubForeignBalance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(address, multiLocation) {
|
|
688
|
+
var response, obj;
|
|
689
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
690
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
800
691
|
case 0:
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
break;
|
|
804
|
-
}
|
|
805
|
-
return _context.abrupt("return");
|
|
692
|
+
_context7.next = 2;
|
|
693
|
+
return this.api.query.foreignAssets.account(multiLocation, address);
|
|
806
694
|
case 2:
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
}
|
|
811
|
-
_context.next = 5;
|
|
812
|
-
return this.createApiInstance(this._api);
|
|
695
|
+
response = _context7.sent;
|
|
696
|
+
obj = response.toJSON();
|
|
697
|
+
return _context7.abrupt("return", BigInt(obj === null || !obj.balance ? 0 : obj.balance));
|
|
813
698
|
case 5:
|
|
814
|
-
this.api = _context.sent;
|
|
815
|
-
_context.next = 16;
|
|
816
|
-
break;
|
|
817
|
-
case 8:
|
|
818
|
-
if (!((_this$_api = this._api) !== null && _this$_api !== void 0)) {
|
|
819
|
-
_context.next = 12;
|
|
820
|
-
break;
|
|
821
|
-
}
|
|
822
|
-
_context.t0 = _this$_api;
|
|
823
|
-
_context.next = 15;
|
|
824
|
-
break;
|
|
825
|
-
case 12:
|
|
826
|
-
_context.next = 14;
|
|
827
|
-
return createApiInstanceForNode$1(this, node);
|
|
828
|
-
case 14:
|
|
829
|
-
_context.t0 = _context.sent;
|
|
830
|
-
case 15:
|
|
831
|
-
this.api = _context.t0;
|
|
832
|
-
case 16:
|
|
833
|
-
this.initialized = true;
|
|
834
|
-
case 17:
|
|
835
699
|
case "end":
|
|
836
|
-
return
|
|
700
|
+
return _context7.stop();
|
|
837
701
|
}
|
|
838
|
-
},
|
|
702
|
+
}, _callee7, this);
|
|
839
703
|
}));
|
|
840
|
-
function
|
|
841
|
-
return
|
|
704
|
+
function getAssetHubForeignBalance(_x9, _x10) {
|
|
705
|
+
return _getAssetHubForeignBalance.apply(this, arguments);
|
|
842
706
|
}
|
|
843
|
-
return
|
|
707
|
+
return getAssetHubForeignBalance;
|
|
844
708
|
}()
|
|
845
709
|
}, {
|
|
846
|
-
key: "
|
|
710
|
+
key: "getForeignAssetsByIdBalance",
|
|
847
711
|
value: function () {
|
|
848
|
-
var
|
|
849
|
-
var
|
|
850
|
-
return _regeneratorRuntime().wrap(function
|
|
851
|
-
while (1) switch (
|
|
712
|
+
var _getForeignAssetsByIdBalance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(address, assetId) {
|
|
713
|
+
var response, obj;
|
|
714
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
715
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
852
716
|
case 0:
|
|
853
|
-
|
|
854
|
-
return
|
|
855
|
-
provider: wsProvider
|
|
856
|
-
}));
|
|
717
|
+
_context8.next = 2;
|
|
718
|
+
return this.api.query.foreignAssets.account(assetId, address);
|
|
857
719
|
case 2:
|
|
720
|
+
response = _context8.sent;
|
|
721
|
+
obj = response.toJSON();
|
|
722
|
+
return _context8.abrupt("return", BigInt(obj === null || !obj.balance ? 0 : obj.balance));
|
|
723
|
+
case 5:
|
|
858
724
|
case "end":
|
|
859
|
-
return
|
|
725
|
+
return _context8.stop();
|
|
860
726
|
}
|
|
861
|
-
},
|
|
727
|
+
}, _callee8, this);
|
|
862
728
|
}));
|
|
863
|
-
function
|
|
864
|
-
return
|
|
729
|
+
function getForeignAssetsByIdBalance(_x11, _x12) {
|
|
730
|
+
return _getForeignAssetsByIdBalance.apply(this, arguments);
|
|
865
731
|
}
|
|
866
|
-
return
|
|
732
|
+
return getForeignAssetsByIdBalance;
|
|
867
733
|
}()
|
|
868
734
|
}, {
|
|
869
|
-
key: "
|
|
870
|
-
value: function accountToHex(address) {
|
|
871
|
-
var isPrefixed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
872
|
-
if (isHex(address)) return address;
|
|
873
|
-
var uint8Array = decodeAddress(address);
|
|
874
|
-
return u8aToHex(uint8Array, -1, isPrefixed);
|
|
875
|
-
}
|
|
876
|
-
}, {
|
|
877
|
-
key: "callTxMethod",
|
|
878
|
-
value: function callTxMethod(_ref) {
|
|
879
|
-
var _this$api$tx$moduleLo;
|
|
880
|
-
var module = _ref.module,
|
|
881
|
-
section = _ref.section,
|
|
882
|
-
parameters = _ref.parameters;
|
|
883
|
-
var values = Object.values(parameters);
|
|
884
|
-
var moduleLowerCase = lowercaseFirstLetter(module);
|
|
885
|
-
var sectionCamelCase = snakeToCamel(section);
|
|
886
|
-
return (_this$api$tx$moduleLo = this.api.tx[moduleLowerCase])[sectionCamelCase].apply(_this$api$tx$moduleLo, values);
|
|
887
|
-
}
|
|
888
|
-
}, {
|
|
889
|
-
key: "callBatchMethod",
|
|
890
|
-
value: function callBatchMethod(calls, mode) {
|
|
891
|
-
var section = mode === BatchMode.BATCH_ALL ? 'batchAll' : 'batch';
|
|
892
|
-
return this.api.tx.utility[section](calls);
|
|
893
|
-
}
|
|
894
|
-
}, {
|
|
895
|
-
key: "objectToHex",
|
|
896
|
-
value: function objectToHex(obj, typeName) {
|
|
897
|
-
return Promise.resolve(this.api.createType(typeName, obj).toHex());
|
|
898
|
-
}
|
|
899
|
-
}, {
|
|
900
|
-
key: "hexToUint8a",
|
|
901
|
-
value: function hexToUint8a(hex) {
|
|
902
|
-
return hexToU8a(hex);
|
|
903
|
-
}
|
|
904
|
-
}, {
|
|
905
|
-
key: "stringToUint8a",
|
|
906
|
-
value: function stringToUint8a(str) {
|
|
907
|
-
return stringToU8a(str);
|
|
908
|
-
}
|
|
909
|
-
}, {
|
|
910
|
-
key: "calculateTransactionFee",
|
|
735
|
+
key: "getBalanceForeignBifrost",
|
|
911
736
|
value: function () {
|
|
912
|
-
var
|
|
913
|
-
var
|
|
914
|
-
return _regeneratorRuntime().wrap(function
|
|
915
|
-
while (1) switch (
|
|
737
|
+
var _getBalanceForeignBifrost = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(address, asset) {
|
|
738
|
+
var currencySelection, response, accountData;
|
|
739
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
740
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
916
741
|
case 0:
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
742
|
+
currencySelection = getNode('BifrostPolkadot').getCurrencySelection(asset);
|
|
743
|
+
_context9.next = 3;
|
|
744
|
+
return this.api.query.tokens.accounts(address, currencySelection);
|
|
745
|
+
case 3:
|
|
746
|
+
response = _context9.sent;
|
|
747
|
+
accountData = response ? response : null;
|
|
748
|
+
return _context9.abrupt("return", accountData ? BigInt(accountData.free.toString()) : 0n);
|
|
749
|
+
case 6:
|
|
924
750
|
case "end":
|
|
925
|
-
return
|
|
751
|
+
return _context9.stop();
|
|
926
752
|
}
|
|
927
|
-
},
|
|
753
|
+
}, _callee9, this);
|
|
928
754
|
}));
|
|
929
|
-
function
|
|
930
|
-
return
|
|
755
|
+
function getBalanceForeignBifrost(_x13, _x14) {
|
|
756
|
+
return _getBalanceForeignBifrost.apply(this, arguments);
|
|
931
757
|
}
|
|
932
|
-
return
|
|
758
|
+
return getBalanceForeignBifrost;
|
|
933
759
|
}()
|
|
934
760
|
}, {
|
|
935
|
-
key: "
|
|
761
|
+
key: "getBalanceNativeAcala",
|
|
936
762
|
value: function () {
|
|
937
|
-
var
|
|
938
|
-
var response;
|
|
939
|
-
return _regeneratorRuntime().wrap(function
|
|
940
|
-
while (1) switch (
|
|
763
|
+
var _getBalanceNativeAcala = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(address, symbol) {
|
|
764
|
+
var response, accountData;
|
|
765
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
766
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
941
767
|
case 0:
|
|
942
|
-
|
|
943
|
-
return this.api.query.
|
|
768
|
+
_context10.next = 2;
|
|
769
|
+
return this.api.query.tokens.accounts(address, {
|
|
770
|
+
Token: symbol
|
|
771
|
+
});
|
|
944
772
|
case 2:
|
|
945
|
-
response =
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
case
|
|
949
|
-
return _context4.stop();
|
|
950
|
-
}
|
|
951
|
-
}, _callee4, this);
|
|
952
|
-
}));
|
|
953
|
-
function getBalanceNative(_x5) {
|
|
954
|
-
return _getBalanceNative.apply(this, arguments);
|
|
955
|
-
}
|
|
956
|
-
return getBalanceNative;
|
|
957
|
-
}()
|
|
958
|
-
}, {
|
|
959
|
-
key: "getBalanceForeignPolkadotXcm",
|
|
960
|
-
value: function () {
|
|
961
|
-
var _getBalanceForeignPolkadotXcm = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(address, id) {
|
|
962
|
-
var parsedId, response, obj;
|
|
963
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
964
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
965
|
-
case 0:
|
|
966
|
-
parsedId = new u32(this.api.registry, id);
|
|
967
|
-
_context5.next = 3;
|
|
968
|
-
return this.api.query.assets.account(parsedId, address);
|
|
969
|
-
case 3:
|
|
970
|
-
response = _context5.sent;
|
|
971
|
-
obj = response.toJSON();
|
|
972
|
-
return _context5.abrupt("return", obj.balance ? BigInt(obj.balance) : 0n);
|
|
973
|
-
case 6:
|
|
974
|
-
case "end":
|
|
975
|
-
return _context5.stop();
|
|
976
|
-
}
|
|
977
|
-
}, _callee5, this);
|
|
978
|
-
}));
|
|
979
|
-
function getBalanceForeignPolkadotXcm(_x6, _x7) {
|
|
980
|
-
return _getBalanceForeignPolkadotXcm.apply(this, arguments);
|
|
981
|
-
}
|
|
982
|
-
return getBalanceForeignPolkadotXcm;
|
|
983
|
-
}()
|
|
984
|
-
}, {
|
|
985
|
-
key: "getMythosForeignBalance",
|
|
986
|
-
value: function () {
|
|
987
|
-
var _getMythosForeignBalance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(address) {
|
|
988
|
-
var response, obj;
|
|
989
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
990
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
991
|
-
case 0:
|
|
992
|
-
_context6.next = 2;
|
|
993
|
-
return this.api.query.balances.account(address);
|
|
994
|
-
case 2:
|
|
995
|
-
response = _context6.sent;
|
|
996
|
-
obj = response.toJSON();
|
|
997
|
-
return _context6.abrupt("return", obj.free ? BigInt(obj.free) : 0n);
|
|
998
|
-
case 5:
|
|
999
|
-
case "end":
|
|
1000
|
-
return _context6.stop();
|
|
1001
|
-
}
|
|
1002
|
-
}, _callee6, this);
|
|
1003
|
-
}));
|
|
1004
|
-
function getMythosForeignBalance(_x8) {
|
|
1005
|
-
return _getMythosForeignBalance.apply(this, arguments);
|
|
1006
|
-
}
|
|
1007
|
-
return getMythosForeignBalance;
|
|
1008
|
-
}()
|
|
1009
|
-
}, {
|
|
1010
|
-
key: "getAssetHubForeignBalance",
|
|
1011
|
-
value: function () {
|
|
1012
|
-
var _getAssetHubForeignBalance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(address, multiLocation) {
|
|
1013
|
-
var response, obj;
|
|
1014
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
1015
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
1016
|
-
case 0:
|
|
1017
|
-
_context7.next = 2;
|
|
1018
|
-
return this.api.query.foreignAssets.account(multiLocation, address);
|
|
1019
|
-
case 2:
|
|
1020
|
-
response = _context7.sent;
|
|
1021
|
-
obj = response.toJSON();
|
|
1022
|
-
return _context7.abrupt("return", BigInt(obj === null || !obj.balance ? 0 : obj.balance));
|
|
1023
|
-
case 5:
|
|
1024
|
-
case "end":
|
|
1025
|
-
return _context7.stop();
|
|
1026
|
-
}
|
|
1027
|
-
}, _callee7, this);
|
|
1028
|
-
}));
|
|
1029
|
-
function getAssetHubForeignBalance(_x9, _x10) {
|
|
1030
|
-
return _getAssetHubForeignBalance.apply(this, arguments);
|
|
1031
|
-
}
|
|
1032
|
-
return getAssetHubForeignBalance;
|
|
1033
|
-
}()
|
|
1034
|
-
}, {
|
|
1035
|
-
key: "getForeignAssetsByIdBalance",
|
|
1036
|
-
value: function () {
|
|
1037
|
-
var _getForeignAssetsByIdBalance = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(address, assetId) {
|
|
1038
|
-
var response, obj;
|
|
1039
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1040
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
1041
|
-
case 0:
|
|
1042
|
-
_context8.next = 2;
|
|
1043
|
-
return this.api.query.foreignAssets.account(assetId, address);
|
|
1044
|
-
case 2:
|
|
1045
|
-
response = _context8.sent;
|
|
1046
|
-
obj = response.toJSON();
|
|
1047
|
-
return _context8.abrupt("return", BigInt(obj === null || !obj.balance ? 0 : obj.balance));
|
|
1048
|
-
case 5:
|
|
1049
|
-
case "end":
|
|
1050
|
-
return _context8.stop();
|
|
1051
|
-
}
|
|
1052
|
-
}, _callee8, this);
|
|
1053
|
-
}));
|
|
1054
|
-
function getForeignAssetsByIdBalance(_x11, _x12) {
|
|
1055
|
-
return _getForeignAssetsByIdBalance.apply(this, arguments);
|
|
1056
|
-
}
|
|
1057
|
-
return getForeignAssetsByIdBalance;
|
|
1058
|
-
}()
|
|
1059
|
-
}, {
|
|
1060
|
-
key: "getBalanceForeignBifrost",
|
|
1061
|
-
value: function () {
|
|
1062
|
-
var _getBalanceForeignBifrost = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(address, asset) {
|
|
1063
|
-
var currencySelection, response, accountData;
|
|
1064
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1065
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
1066
|
-
case 0:
|
|
1067
|
-
currencySelection = getNode('BifrostPolkadot').getCurrencySelection(asset);
|
|
1068
|
-
_context9.next = 3;
|
|
1069
|
-
return this.api.query.tokens.accounts(address, currencySelection);
|
|
1070
|
-
case 3:
|
|
1071
|
-
response = _context9.sent;
|
|
1072
|
-
accountData = response ? response : null;
|
|
1073
|
-
return _context9.abrupt("return", accountData ? BigInt(accountData.free.toString()) : 0n);
|
|
1074
|
-
case 6:
|
|
1075
|
-
case "end":
|
|
1076
|
-
return _context9.stop();
|
|
1077
|
-
}
|
|
1078
|
-
}, _callee9, this);
|
|
1079
|
-
}));
|
|
1080
|
-
function getBalanceForeignBifrost(_x13, _x14) {
|
|
1081
|
-
return _getBalanceForeignBifrost.apply(this, arguments);
|
|
1082
|
-
}
|
|
1083
|
-
return getBalanceForeignBifrost;
|
|
1084
|
-
}()
|
|
1085
|
-
}, {
|
|
1086
|
-
key: "getBalanceNativeAcala",
|
|
1087
|
-
value: function () {
|
|
1088
|
-
var _getBalanceNativeAcala = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(address, symbol) {
|
|
1089
|
-
var response, accountData;
|
|
1090
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1091
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
1092
|
-
case 0:
|
|
1093
|
-
_context10.next = 2;
|
|
1094
|
-
return this.api.query.tokens.accounts(address, {
|
|
1095
|
-
Token: symbol
|
|
1096
|
-
});
|
|
1097
|
-
case 2:
|
|
1098
|
-
response = _context10.sent;
|
|
1099
|
-
accountData = response ? response : null;
|
|
1100
|
-
return _context10.abrupt("return", accountData ? BigInt(accountData.free.toString()) : 0n);
|
|
1101
|
-
case 5:
|
|
773
|
+
response = _context10.sent;
|
|
774
|
+
accountData = response ? response : null;
|
|
775
|
+
return _context10.abrupt("return", accountData ? BigInt(accountData.free.toString()) : 0n);
|
|
776
|
+
case 5:
|
|
1102
777
|
case "end":
|
|
1103
778
|
return _context10.stop();
|
|
1104
779
|
}
|
|
@@ -1336,175 +1011,453 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
1336
1011
|
case "end":
|
|
1337
1012
|
return _context16.stop();
|
|
1338
1013
|
}
|
|
1339
|
-
}, _callee16, this);
|
|
1340
|
-
}));
|
|
1341
|
-
function disconnect() {
|
|
1342
|
-
return _disconnect.apply(this, arguments);
|
|
1014
|
+
}, _callee16, this);
|
|
1015
|
+
}));
|
|
1016
|
+
function disconnect() {
|
|
1017
|
+
return _disconnect.apply(this, arguments);
|
|
1018
|
+
}
|
|
1019
|
+
return disconnect;
|
|
1020
|
+
}()
|
|
1021
|
+
}]);
|
|
1022
|
+
}();
|
|
1023
|
+
|
|
1024
|
+
var createApiInstanceForNode = function createApiInstanceForNode(node) {
|
|
1025
|
+
var pjsApi = new PolkadotJsApi();
|
|
1026
|
+
return createApiInstanceForNode$1(pjsApi, node);
|
|
1027
|
+
};
|
|
1028
|
+
var createPolkadotJsApiCall = function createPolkadotJsApiCall(apiCall) {
|
|
1029
|
+
return /*#__PURE__*/function () {
|
|
1030
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
1031
|
+
var pjsApi, optionsWithApi;
|
|
1032
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1033
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1034
|
+
case 0:
|
|
1035
|
+
pjsApi = new PolkadotJsApi();
|
|
1036
|
+
pjsApi.setApi(options.api);
|
|
1037
|
+
optionsWithApi = _objectSpread2(_objectSpread2({}, options), {}, {
|
|
1038
|
+
api: pjsApi
|
|
1039
|
+
});
|
|
1040
|
+
return _context.abrupt("return", apiCall(optionsWithApi));
|
|
1041
|
+
case 4:
|
|
1042
|
+
case "end":
|
|
1043
|
+
return _context.stop();
|
|
1044
|
+
}
|
|
1045
|
+
}, _callee);
|
|
1046
|
+
}));
|
|
1047
|
+
return function (_x) {
|
|
1048
|
+
return _ref.apply(this, arguments);
|
|
1049
|
+
};
|
|
1050
|
+
}();
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Retrieves the native balance for a given account on a specified node.
|
|
1055
|
+
*
|
|
1056
|
+
* @returns The native balance as a bigint.
|
|
1057
|
+
*/
|
|
1058
|
+
var getBalanceNative = createPolkadotJsApiCall(getBalanceNative$1);
|
|
1059
|
+
/**
|
|
1060
|
+
* Retrieves the balance of a foreign asset for a given account on a specified node.
|
|
1061
|
+
*
|
|
1062
|
+
* @returns The balance of the foreign asset as a bigint, or null if not found.
|
|
1063
|
+
*/
|
|
1064
|
+
var getBalanceForeign = createPolkadotJsApiCall(getBalanceForeign$1);
|
|
1065
|
+
/**
|
|
1066
|
+
* Retrieves detailed transfer information for a cross-chain transfer.
|
|
1067
|
+
*
|
|
1068
|
+
* @returns A Promise that resolves to the transfer information.
|
|
1069
|
+
*/
|
|
1070
|
+
var getTransferInfo = createPolkadotJsApiCall(getTransferInfo$1);
|
|
1071
|
+
/**
|
|
1072
|
+
* Retrieves the asset balance for a given account on a specified node.
|
|
1073
|
+
*
|
|
1074
|
+
* @returns The asset balance as a bigint.
|
|
1075
|
+
*/
|
|
1076
|
+
var getAssetBalance = createPolkadotJsApiCall(getAssetBalance$1);
|
|
1077
|
+
/**
|
|
1078
|
+
* Claims assets from a parachain.
|
|
1079
|
+
*
|
|
1080
|
+
* @returns An extrinsic representing the claim transaction.
|
|
1081
|
+
*/
|
|
1082
|
+
var claimAssets = createPolkadotJsApiCall(claimAssets$1);
|
|
1083
|
+
var getOriginFeeDetails = createPolkadotJsApiCall(getOriginFeeDetails$1);
|
|
1084
|
+
var getMaxNativeTransferableAmount = createPolkadotJsApiCall(getMaxNativeTransferableAmount$1);
|
|
1085
|
+
var getMaxForeignTransferableAmount = createPolkadotJsApiCall(getMaxForeignTransferableAmount$1);
|
|
1086
|
+
var getTransferableAmount = createPolkadotJsApiCall(getTransferableAmount$1);
|
|
1087
|
+
var verifyEdOnDestination = createPolkadotJsApiCall(verifyEdOnDestination$1);
|
|
1088
|
+
|
|
1089
|
+
var assets = /*#__PURE__*/Object.freeze({
|
|
1090
|
+
__proto__: null,
|
|
1091
|
+
Foreign: Foreign,
|
|
1092
|
+
ForeignAbstract: ForeignAbstract,
|
|
1093
|
+
Native: Native,
|
|
1094
|
+
Override: Override,
|
|
1095
|
+
claimAssets: claimAssets,
|
|
1096
|
+
getAllAssetsSymbols: getAllAssetsSymbols,
|
|
1097
|
+
getAssetBalance: getAssetBalance,
|
|
1098
|
+
getAssetBySymbolOrId: getAssetBySymbolOrId,
|
|
1099
|
+
getAssetDecimals: getAssetDecimals,
|
|
1100
|
+
getAssetId: getAssetId,
|
|
1101
|
+
getAssets: getAssets,
|
|
1102
|
+
getAssetsObject: getAssetsObject,
|
|
1103
|
+
getBalanceForeign: getBalanceForeign,
|
|
1104
|
+
getBalanceNative: getBalanceNative,
|
|
1105
|
+
getExistentialDeposit: getExistentialDeposit,
|
|
1106
|
+
getMaxForeignTransferableAmount: getMaxForeignTransferableAmount,
|
|
1107
|
+
getMaxNativeTransferableAmount: getMaxNativeTransferableAmount,
|
|
1108
|
+
getNativeAssetSymbol: getNativeAssetSymbol,
|
|
1109
|
+
getNativeAssets: getNativeAssets,
|
|
1110
|
+
getOriginFeeDetails: getOriginFeeDetails,
|
|
1111
|
+
getOtherAssets: getOtherAssets,
|
|
1112
|
+
getRelayChainSymbol: getRelayChainSymbol,
|
|
1113
|
+
getSupportedAssets: getSupportedAssets,
|
|
1114
|
+
getTNode: getTNode,
|
|
1115
|
+
getTransferInfo: getTransferInfo,
|
|
1116
|
+
getTransferableAmount: getTransferableAmount,
|
|
1117
|
+
hasSupportForAsset: hasSupportForAsset,
|
|
1118
|
+
isNodeEvm: isNodeEvm,
|
|
1119
|
+
verifyEdOnDestination: verifyEdOnDestination
|
|
1120
|
+
});
|
|
1121
|
+
|
|
1122
|
+
var approveToken = /*#__PURE__*/function () {
|
|
1123
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(signer, amount, symbol) {
|
|
1124
|
+
var env, contract, weth9, result, receipt;
|
|
1125
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1126
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1127
|
+
case 0:
|
|
1128
|
+
env = environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
|
|
1129
|
+
contract = env.locations[0].erc20tokensReceivable.find(function (t) {
|
|
1130
|
+
return t.id === symbol;
|
|
1131
|
+
});
|
|
1132
|
+
if (contract) {
|
|
1133
|
+
_context.next = 4;
|
|
1134
|
+
break;
|
|
1135
|
+
}
|
|
1136
|
+
throw new Error("Token ".concat(symbol, " not supported"));
|
|
1137
|
+
case 4:
|
|
1138
|
+
weth9 = WETH9__factory.connect(contract.address, signer);
|
|
1139
|
+
_context.next = 7;
|
|
1140
|
+
return weth9.approve(env.config.GATEWAY_CONTRACT, amount);
|
|
1141
|
+
case 7:
|
|
1142
|
+
result = _context.sent;
|
|
1143
|
+
_context.next = 10;
|
|
1144
|
+
return result.wait();
|
|
1145
|
+
case 10:
|
|
1146
|
+
receipt = _context.sent;
|
|
1147
|
+
return _context.abrupt("return", {
|
|
1148
|
+
result: result,
|
|
1149
|
+
receipt: receipt
|
|
1150
|
+
});
|
|
1151
|
+
case 12:
|
|
1152
|
+
case "end":
|
|
1153
|
+
return _context.stop();
|
|
1154
|
+
}
|
|
1155
|
+
}, _callee);
|
|
1156
|
+
}));
|
|
1157
|
+
return function approveToken(_x, _x2, _x3) {
|
|
1158
|
+
return _ref.apply(this, arguments);
|
|
1159
|
+
};
|
|
1160
|
+
}();
|
|
1161
|
+
|
|
1162
|
+
var depositToken = /*#__PURE__*/function () {
|
|
1163
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(signer, amount, symbol) {
|
|
1164
|
+
var env, contract, weth9, result, receipt;
|
|
1165
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1166
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1167
|
+
case 0:
|
|
1168
|
+
env = environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
|
|
1169
|
+
contract = env.locations[0].erc20tokensReceivable.find(function (t) {
|
|
1170
|
+
return t.id === symbol;
|
|
1171
|
+
});
|
|
1172
|
+
if (contract) {
|
|
1173
|
+
_context.next = 4;
|
|
1174
|
+
break;
|
|
1175
|
+
}
|
|
1176
|
+
throw new Error("Token ".concat(symbol, " not supported"));
|
|
1177
|
+
case 4:
|
|
1178
|
+
weth9 = WETH9__factory.connect(contract.address, signer);
|
|
1179
|
+
_context.next = 7;
|
|
1180
|
+
return weth9.deposit({
|
|
1181
|
+
value: amount
|
|
1182
|
+
});
|
|
1183
|
+
case 7:
|
|
1184
|
+
result = _context.sent;
|
|
1185
|
+
_context.next = 10;
|
|
1186
|
+
return result.wait();
|
|
1187
|
+
case 10:
|
|
1188
|
+
receipt = _context.sent;
|
|
1189
|
+
return _context.abrupt("return", {
|
|
1190
|
+
result: result,
|
|
1191
|
+
receipt: receipt
|
|
1192
|
+
});
|
|
1193
|
+
case 12:
|
|
1194
|
+
case "end":
|
|
1195
|
+
return _context.stop();
|
|
1196
|
+
}
|
|
1197
|
+
}, _callee);
|
|
1198
|
+
}));
|
|
1199
|
+
return function depositToken(_x, _x2, _x3) {
|
|
1200
|
+
return _ref.apply(this, arguments);
|
|
1201
|
+
};
|
|
1202
|
+
}();
|
|
1203
|
+
|
|
1204
|
+
var createContext = function createContext(executionUrl, config) {
|
|
1205
|
+
return new Context({
|
|
1206
|
+
ethereum: {
|
|
1207
|
+
execution_url: executionUrl,
|
|
1208
|
+
beacon_url: config.BEACON_HTTP_API
|
|
1209
|
+
},
|
|
1210
|
+
polkadot: {
|
|
1211
|
+
assetHubParaId: config.ASSET_HUB_PARAID,
|
|
1212
|
+
bridgeHubParaId: config.BRIDGE_HUB_PARAID,
|
|
1213
|
+
parachains: config.PARACHAINS,
|
|
1214
|
+
relaychain: config.RELAY_CHAIN_URL
|
|
1215
|
+
},
|
|
1216
|
+
appContracts: {
|
|
1217
|
+
gateway: config.GATEWAY_CONTRACT,
|
|
1218
|
+
beefy: config.BEEFY_CONTRACT
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* Transfers an Ethereum asset to a Polkadot account.
|
|
1225
|
+
*
|
|
1226
|
+
* @param provider - The Ethereum provider instance to interact with the Ethereum network.
|
|
1227
|
+
* @param options - The options for the transfer.
|
|
1228
|
+
*
|
|
1229
|
+
* @returns A Promise that resolves to an object containing the result and the plan of the transfer.
|
|
1230
|
+
*
|
|
1231
|
+
* @throws Will throw an error if the transfer validation fails or if the transfer cannot be completed.
|
|
1232
|
+
*/
|
|
1233
|
+
var transferEthToPolkadot$1 = /*#__PURE__*/function () {
|
|
1234
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
1235
|
+
var provider, signer, address, to, currency, ethAsset, env, context, destParaId, overrides, registry, fee, sourceAddress, transfer, validation, tx, response, receipt, messageReceipt;
|
|
1236
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1237
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1238
|
+
case 0:
|
|
1239
|
+
provider = _ref.provider, signer = _ref.signer, address = _ref.address, to = _ref.to, currency = _ref.currency;
|
|
1240
|
+
if (!('multiasset' in currency)) {
|
|
1241
|
+
_context.next = 3;
|
|
1242
|
+
break;
|
|
1243
|
+
}
|
|
1244
|
+
throw new Error('Multiassets syntax is not supported for Evm transfers');
|
|
1245
|
+
case 3:
|
|
1246
|
+
if (!('multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation))) {
|
|
1247
|
+
_context.next = 5;
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1250
|
+
throw new Error('Override multilocation is not supported for Evm transfers');
|
|
1251
|
+
case 5:
|
|
1252
|
+
if (provider) {
|
|
1253
|
+
_context.next = 7;
|
|
1254
|
+
break;
|
|
1255
|
+
}
|
|
1256
|
+
throw new Error('provider parameter is required for Snowbridge transfers.');
|
|
1257
|
+
case 7:
|
|
1258
|
+
if (isEthersSigner(signer)) {
|
|
1259
|
+
_context.next = 9;
|
|
1260
|
+
break;
|
|
1261
|
+
}
|
|
1262
|
+
throw new Error('Snowbridge does not support Viem provider yet.');
|
|
1263
|
+
case 9:
|
|
1264
|
+
ethAsset = getAssetBySymbolOrId('Ethereum', currency, to);
|
|
1265
|
+
if (!(ethAsset === null)) {
|
|
1266
|
+
_context.next = 12;
|
|
1267
|
+
break;
|
|
1268
|
+
}
|
|
1269
|
+
throw new InvalidCurrencyError("Origin node Ethereum does not support currency ".concat(JSON.stringify(currency), "."));
|
|
1270
|
+
case 12:
|
|
1271
|
+
env = environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
|
|
1272
|
+
context = createContext(provider, env.config);
|
|
1273
|
+
destParaId = getParaId(to);
|
|
1274
|
+
if (!(!isForeignAsset(ethAsset) || ethAsset.assetId === undefined)) {
|
|
1275
|
+
_context.next = 17;
|
|
1276
|
+
break;
|
|
1277
|
+
}
|
|
1278
|
+
throw new InvalidCurrencyError('Selected asset has no asset id');
|
|
1279
|
+
case 17:
|
|
1280
|
+
overrides = {
|
|
1281
|
+
precompiles: {
|
|
1282
|
+
'2004': '0x000000000000000000000000000000000000081A'
|
|
1283
|
+
},
|
|
1284
|
+
destinationFeeOverrides: {
|
|
1285
|
+
'3369': 500000000n
|
|
1286
|
+
},
|
|
1287
|
+
assetOverrides: {
|
|
1288
|
+
'3369': [{
|
|
1289
|
+
token: '0xba41ddf06b7ffd89d1267b5a93bfef2424eb2003'.toLowerCase(),
|
|
1290
|
+
name: 'Mythos',
|
|
1291
|
+
minimumBalance: 10000000000000000n,
|
|
1292
|
+
symbol: 'MYTH',
|
|
1293
|
+
decimals: 18,
|
|
1294
|
+
isSufficient: true
|
|
1295
|
+
}]
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
_context.t0 = assetsV2;
|
|
1299
|
+
_context.t1 = _objectSpread2;
|
|
1300
|
+
_context.t2 = _objectSpread2;
|
|
1301
|
+
_context.t3 = {};
|
|
1302
|
+
_context.next = 24;
|
|
1303
|
+
return assetsV2.fromContext(context);
|
|
1304
|
+
case 24:
|
|
1305
|
+
_context.t4 = _context.sent;
|
|
1306
|
+
_context.t5 = (0, _context.t2)(_context.t3, _context.t4);
|
|
1307
|
+
_context.t6 = overrides;
|
|
1308
|
+
_context.t7 = (0, _context.t1)(_context.t5, _context.t6);
|
|
1309
|
+
_context.next = 30;
|
|
1310
|
+
return _context.t0.buildRegistry.call(_context.t0, _context.t7);
|
|
1311
|
+
case 30:
|
|
1312
|
+
registry = _context.sent;
|
|
1313
|
+
_context.next = 33;
|
|
1314
|
+
return toPolkadotV2.getDeliveryFee(context.gateway(), registry, ethAsset.assetId, destParaId);
|
|
1315
|
+
case 33:
|
|
1316
|
+
fee = _context.sent;
|
|
1317
|
+
_context.next = 36;
|
|
1318
|
+
return signer.getAddress();
|
|
1319
|
+
case 36:
|
|
1320
|
+
sourceAddress = _context.sent;
|
|
1321
|
+
_context.next = 39;
|
|
1322
|
+
return toPolkadotV2.createTransfer(registry, sourceAddress, address, ethAsset.assetId, destParaId, BigInt(currency.amount), fee);
|
|
1323
|
+
case 39:
|
|
1324
|
+
transfer = _context.sent;
|
|
1325
|
+
_context.t8 = toPolkadotV2;
|
|
1326
|
+
_context.t9 = context.ethereum();
|
|
1327
|
+
_context.t10 = context.gateway();
|
|
1328
|
+
_context.next = 45;
|
|
1329
|
+
return context.bridgeHub();
|
|
1330
|
+
case 45:
|
|
1331
|
+
_context.t11 = _context.sent;
|
|
1332
|
+
_context.next = 48;
|
|
1333
|
+
return context.assetHub();
|
|
1334
|
+
case 48:
|
|
1335
|
+
_context.t12 = _context.sent;
|
|
1336
|
+
if (!(destParaId !== getParaId('AssetHubPolkadot'))) {
|
|
1337
|
+
_context.next = 55;
|
|
1338
|
+
break;
|
|
1339
|
+
}
|
|
1340
|
+
_context.next = 52;
|
|
1341
|
+
return context.parachain(destParaId);
|
|
1342
|
+
case 52:
|
|
1343
|
+
_context.t13 = _context.sent;
|
|
1344
|
+
_context.next = 56;
|
|
1345
|
+
break;
|
|
1346
|
+
case 55:
|
|
1347
|
+
_context.t13 = undefined;
|
|
1348
|
+
case 56:
|
|
1349
|
+
_context.t14 = _context.t13;
|
|
1350
|
+
_context.t15 = {
|
|
1351
|
+
ethereum: _context.t9,
|
|
1352
|
+
gateway: _context.t10,
|
|
1353
|
+
bridgeHub: _context.t11,
|
|
1354
|
+
assetHub: _context.t12,
|
|
1355
|
+
destParachain: _context.t14
|
|
1356
|
+
};
|
|
1357
|
+
_context.t16 = transfer;
|
|
1358
|
+
_context.next = 61;
|
|
1359
|
+
return _context.t8.validateTransfer.call(_context.t8, _context.t15, _context.t16);
|
|
1360
|
+
case 61:
|
|
1361
|
+
validation = _context.sent;
|
|
1362
|
+
if (!validation.logs.find(function (l) {
|
|
1363
|
+
return l.kind == toPolkadotV2.ValidationKind.Error;
|
|
1364
|
+
})) {
|
|
1365
|
+
_context.next = 64;
|
|
1366
|
+
break;
|
|
1367
|
+
}
|
|
1368
|
+
throw Error("Validation failed with following errors: \n\n ".concat(validation.logs.filter(function (l) {
|
|
1369
|
+
return l.kind == toPolkadotV2.ValidationKind.Error;
|
|
1370
|
+
}).map(function (l) {
|
|
1371
|
+
return l.message;
|
|
1372
|
+
}).join('\n\n')));
|
|
1373
|
+
case 64:
|
|
1374
|
+
tx = transfer.tx;
|
|
1375
|
+
_context.next = 67;
|
|
1376
|
+
return signer.sendTransaction(tx);
|
|
1377
|
+
case 67:
|
|
1378
|
+
response = _context.sent;
|
|
1379
|
+
_context.next = 70;
|
|
1380
|
+
return response.wait(1);
|
|
1381
|
+
case 70:
|
|
1382
|
+
receipt = _context.sent;
|
|
1383
|
+
if (receipt) {
|
|
1384
|
+
_context.next = 73;
|
|
1385
|
+
break;
|
|
1386
|
+
}
|
|
1387
|
+
throw Error("Transaction ".concat(response.hash, " not included."));
|
|
1388
|
+
case 73:
|
|
1389
|
+
_context.next = 75;
|
|
1390
|
+
return toPolkadotV2.getMessageReceipt(receipt);
|
|
1391
|
+
case 75:
|
|
1392
|
+
messageReceipt = _context.sent;
|
|
1393
|
+
if (messageReceipt) {
|
|
1394
|
+
_context.next = 78;
|
|
1395
|
+
break;
|
|
1396
|
+
}
|
|
1397
|
+
throw Error("Transaction ".concat(receipt.hash, " did not emit a message."));
|
|
1398
|
+
case 78:
|
|
1399
|
+
return _context.abrupt("return", {
|
|
1400
|
+
response: response,
|
|
1401
|
+
messageReceipt: messageReceipt
|
|
1402
|
+
});
|
|
1403
|
+
case 79:
|
|
1404
|
+
case "end":
|
|
1405
|
+
return _context.stop();
|
|
1343
1406
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1407
|
+
}, _callee);
|
|
1408
|
+
}));
|
|
1409
|
+
return function transferEthToPolkadot(_x) {
|
|
1410
|
+
return _ref2.apply(this, arguments);
|
|
1411
|
+
};
|
|
1347
1412
|
}();
|
|
1348
1413
|
|
|
1349
|
-
var
|
|
1350
|
-
var
|
|
1351
|
-
|
|
1352
|
-
};
|
|
1353
|
-
var createPolkadotJsApiCall = function createPolkadotJsApiCall(apiCall) {
|
|
1354
|
-
return /*#__PURE__*/function () {
|
|
1355
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
1356
|
-
var pjsApi, optionsWithApi;
|
|
1357
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1358
|
-
while (1) switch (_context.prev = _context.next) {
|
|
1359
|
-
case 0:
|
|
1360
|
-
pjsApi = new PolkadotJsApi();
|
|
1361
|
-
pjsApi.setApi(options.api);
|
|
1362
|
-
optionsWithApi = _objectSpread2(_objectSpread2({}, options), {}, {
|
|
1363
|
-
api: pjsApi
|
|
1364
|
-
});
|
|
1365
|
-
return _context.abrupt("return", apiCall(optionsWithApi));
|
|
1366
|
-
case 4:
|
|
1367
|
-
case "end":
|
|
1368
|
-
return _context.stop();
|
|
1369
|
-
}
|
|
1370
|
-
}, _callee);
|
|
1371
|
-
}));
|
|
1372
|
-
return function (_x) {
|
|
1373
|
-
return _ref.apply(this, arguments);
|
|
1374
|
-
};
|
|
1375
|
-
}();
|
|
1376
|
-
};
|
|
1377
|
-
|
|
1378
|
-
/**
|
|
1379
|
-
* Transfers assets from parachain to another parachain or from/to relay chain.
|
|
1380
|
-
* @param options - The transfer options.
|
|
1381
|
-
* @returns An extrinsic to be signed and sent.
|
|
1382
|
-
*/
|
|
1383
|
-
var send = createPolkadotJsApiCall(send$1);
|
|
1384
|
-
var getDryRun = createPolkadotJsApiCall(getDryRun$1);
|
|
1385
|
-
var transferEthToPolkadot = function transferEthToPolkadot(options) {
|
|
1386
|
-
return transferEthToPolkadot$1(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
1387
|
-
api: new PolkadotJsApi()
|
|
1388
|
-
}));
|
|
1389
|
-
};
|
|
1390
|
-
var getParaEthTransferFees = /*#__PURE__*/function () {
|
|
1391
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api) {
|
|
1392
|
-
var pjsApi;
|
|
1414
|
+
var getTokenBalance = /*#__PURE__*/function () {
|
|
1415
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(signer, symbol) {
|
|
1416
|
+
var env, contract, weth9, address;
|
|
1393
1417
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1394
1418
|
while (1) switch (_context.prev = _context.next) {
|
|
1395
1419
|
case 0:
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1420
|
+
env = environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
|
|
1421
|
+
contract = env.locations[0].erc20tokensReceivable.find(function (t) {
|
|
1422
|
+
return t.id === symbol;
|
|
1423
|
+
});
|
|
1424
|
+
if (contract) {
|
|
1425
|
+
_context.next = 4;
|
|
1426
|
+
break;
|
|
1427
|
+
}
|
|
1428
|
+
throw new Error("Token ".concat(symbol, " not supported"));
|
|
1400
1429
|
case 4:
|
|
1401
|
-
|
|
1402
|
-
|
|
1430
|
+
weth9 = WETH9__factory.connect(contract.address, signer);
|
|
1431
|
+
_context.next = 7;
|
|
1432
|
+
return signer.getAddress();
|
|
1433
|
+
case 7:
|
|
1434
|
+
address = _context.sent;
|
|
1435
|
+
return _context.abrupt("return", weth9.balanceOf(address));
|
|
1436
|
+
case 9:
|
|
1403
1437
|
case "end":
|
|
1404
1438
|
return _context.stop();
|
|
1405
1439
|
}
|
|
1406
1440
|
}, _callee);
|
|
1407
1441
|
}));
|
|
1408
|
-
return function
|
|
1442
|
+
return function getTokenBalance(_x, _x2) {
|
|
1409
1443
|
return _ref.apply(this, arguments);
|
|
1410
1444
|
};
|
|
1411
1445
|
}();
|
|
1412
1446
|
|
|
1413
|
-
var transfer = /*#__PURE__*/Object.freeze({
|
|
1414
|
-
__proto__: null,
|
|
1415
|
-
approveToken: approveToken,
|
|
1416
|
-
depositToken: depositToken,
|
|
1417
|
-
getDryRun: getDryRun,
|
|
1418
|
-
getParaEthTransferFees: getParaEthTransferFees,
|
|
1419
|
-
getTokenBalance: getTokenBalance,
|
|
1420
|
-
send: send,
|
|
1421
|
-
transferEthToPolkadot: transferEthToPolkadot
|
|
1422
|
-
});
|
|
1423
|
-
|
|
1424
|
-
/**
|
|
1425
|
-
* Retrieves the native balance for a given account on a specified node.
|
|
1426
|
-
*
|
|
1427
|
-
* @returns The native balance as a bigint.
|
|
1428
|
-
*/
|
|
1429
|
-
var getBalanceNative = createPolkadotJsApiCall(getBalanceNative$1);
|
|
1430
|
-
/**
|
|
1431
|
-
* Retrieves the balance of a foreign asset for a given account on a specified node.
|
|
1432
|
-
*
|
|
1433
|
-
* @returns The balance of the foreign asset as a bigint, or null if not found.
|
|
1434
|
-
*/
|
|
1435
|
-
var getBalanceForeign = createPolkadotJsApiCall(getBalanceForeign$1);
|
|
1436
|
-
/**
|
|
1437
|
-
* Retrieves detailed transfer information for a cross-chain transfer.
|
|
1438
|
-
*
|
|
1439
|
-
* @returns A Promise that resolves to the transfer information.
|
|
1440
|
-
*/
|
|
1441
|
-
var getTransferInfo = createPolkadotJsApiCall(getTransferInfo$1);
|
|
1442
|
-
/**
|
|
1443
|
-
* Retrieves the asset balance for a given account on a specified node.
|
|
1444
|
-
*
|
|
1445
|
-
* @returns The asset balance as a bigint.
|
|
1446
|
-
*/
|
|
1447
|
-
var getAssetBalance = createPolkadotJsApiCall(getAssetBalance$1);
|
|
1448
|
-
/**
|
|
1449
|
-
* Claims assets from a parachain.
|
|
1450
|
-
*
|
|
1451
|
-
* @returns An extrinsic representing the claim transaction.
|
|
1452
|
-
*/
|
|
1453
|
-
var claimAssets = createPolkadotJsApiCall(claimAssets$1);
|
|
1454
|
-
var getOriginFeeDetails = createPolkadotJsApiCall(getOriginFeeDetails$1);
|
|
1455
|
-
var getMaxNativeTransferableAmount = createPolkadotJsApiCall(getMaxNativeTransferableAmount$1);
|
|
1456
|
-
var getMaxForeignTransferableAmount = createPolkadotJsApiCall(getMaxForeignTransferableAmount$1);
|
|
1457
|
-
var getTransferableAmount = createPolkadotJsApiCall(getTransferableAmount$1);
|
|
1458
|
-
var verifyEdOnDestination = createPolkadotJsApiCall(verifyEdOnDestination$1);
|
|
1459
|
-
|
|
1460
|
-
var assets = /*#__PURE__*/Object.freeze({
|
|
1461
|
-
__proto__: null,
|
|
1462
|
-
Foreign: Foreign,
|
|
1463
|
-
ForeignAbstract: ForeignAbstract,
|
|
1464
|
-
Native: Native,
|
|
1465
|
-
Override: Override,
|
|
1466
|
-
claimAssets: claimAssets,
|
|
1467
|
-
getAllAssetsSymbols: getAllAssetsSymbols,
|
|
1468
|
-
getAssetBalance: getAssetBalance,
|
|
1469
|
-
getAssetBySymbolOrId: getAssetBySymbolOrId,
|
|
1470
|
-
getAssetDecimals: getAssetDecimals,
|
|
1471
|
-
getAssetId: getAssetId,
|
|
1472
|
-
getAssets: getAssets,
|
|
1473
|
-
getAssetsObject: getAssetsObject,
|
|
1474
|
-
getBalanceForeign: getBalanceForeign,
|
|
1475
|
-
getBalanceNative: getBalanceNative,
|
|
1476
|
-
getExistentialDeposit: getExistentialDeposit,
|
|
1477
|
-
getMaxForeignTransferableAmount: getMaxForeignTransferableAmount,
|
|
1478
|
-
getMaxNativeTransferableAmount: getMaxNativeTransferableAmount,
|
|
1479
|
-
getNativeAssetSymbol: getNativeAssetSymbol,
|
|
1480
|
-
getNativeAssets: getNativeAssets,
|
|
1481
|
-
getOriginFeeDetails: getOriginFeeDetails,
|
|
1482
|
-
getOtherAssets: getOtherAssets,
|
|
1483
|
-
getRelayChainSymbol: getRelayChainSymbol,
|
|
1484
|
-
getSupportedAssets: getSupportedAssets,
|
|
1485
|
-
getTNode: getTNode,
|
|
1486
|
-
getTransferInfo: getTransferInfo,
|
|
1487
|
-
getTransferableAmount: getTransferableAmount,
|
|
1488
|
-
hasSupportForAsset: hasSupportForAsset,
|
|
1489
|
-
isNodeEvm: isNodeEvm,
|
|
1490
|
-
verifyEdOnDestination: verifyEdOnDestination
|
|
1491
|
-
});
|
|
1492
|
-
|
|
1493
1447
|
/**
|
|
1494
1448
|
* Builder class for constructing transfers from Ethereum to Polkadot.
|
|
1495
1449
|
*/
|
|
1496
|
-
var
|
|
1497
|
-
function
|
|
1498
|
-
_classCallCheck(this,
|
|
1499
|
-
this._options =
|
|
1500
|
-
this._options.api = api;
|
|
1501
|
-
this._options.provider = provider;
|
|
1450
|
+
var EvmBuilderCore = /*#__PURE__*/function () {
|
|
1451
|
+
function EvmBuilderCore(options) {
|
|
1452
|
+
_classCallCheck(this, EvmBuilderCore);
|
|
1453
|
+
this._options = options;
|
|
1502
1454
|
}
|
|
1503
|
-
return _createClass(
|
|
1455
|
+
return _createClass(EvmBuilderCore, [{
|
|
1504
1456
|
key: "from",
|
|
1505
1457
|
value: function from(node) {
|
|
1506
|
-
this._options
|
|
1507
|
-
|
|
1458
|
+
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1459
|
+
from: node
|
|
1460
|
+
}));
|
|
1508
1461
|
}
|
|
1509
1462
|
/**
|
|
1510
1463
|
* Specifies the destination node on Polkadot.
|
|
@@ -1515,8 +1468,9 @@ var EvmBuilderClass = /*#__PURE__*/function () {
|
|
|
1515
1468
|
}, {
|
|
1516
1469
|
key: "to",
|
|
1517
1470
|
value: function to(node) {
|
|
1518
|
-
this._options
|
|
1519
|
-
|
|
1471
|
+
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1472
|
+
to: node
|
|
1473
|
+
}));
|
|
1520
1474
|
}
|
|
1521
1475
|
/**
|
|
1522
1476
|
* Specifies the currency to transfer.
|
|
@@ -1527,8 +1481,9 @@ var EvmBuilderClass = /*#__PURE__*/function () {
|
|
|
1527
1481
|
}, {
|
|
1528
1482
|
key: "currency",
|
|
1529
1483
|
value: function currency(_currency) {
|
|
1530
|
-
this._options
|
|
1531
|
-
|
|
1484
|
+
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1485
|
+
currency: _currency
|
|
1486
|
+
}));
|
|
1532
1487
|
}
|
|
1533
1488
|
/**
|
|
1534
1489
|
* Specifies the recipient address on Polkadot.
|
|
@@ -1539,9 +1494,10 @@ var EvmBuilderClass = /*#__PURE__*/function () {
|
|
|
1539
1494
|
}, {
|
|
1540
1495
|
key: "address",
|
|
1541
1496
|
value: function address(_address, ahAddress) {
|
|
1542
|
-
this._options
|
|
1543
|
-
|
|
1544
|
-
|
|
1497
|
+
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1498
|
+
address: _address,
|
|
1499
|
+
ahAddress: ahAddress
|
|
1500
|
+
}));
|
|
1545
1501
|
}
|
|
1546
1502
|
/**
|
|
1547
1503
|
* Specifies the signer for the Ethereum transaction.
|
|
@@ -1552,8 +1508,9 @@ var EvmBuilderClass = /*#__PURE__*/function () {
|
|
|
1552
1508
|
}, {
|
|
1553
1509
|
key: "signer",
|
|
1554
1510
|
value: function signer(_signer) {
|
|
1555
|
-
this._options
|
|
1556
|
-
|
|
1511
|
+
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1512
|
+
signer: _signer
|
|
1513
|
+
}));
|
|
1557
1514
|
}
|
|
1558
1515
|
/**
|
|
1559
1516
|
* Builds and executes the transfer from Ethereum to Polkadot.
|
|
@@ -1564,57 +1521,31 @@ var EvmBuilderClass = /*#__PURE__*/function () {
|
|
|
1564
1521
|
key: "build",
|
|
1565
1522
|
value: (function () {
|
|
1566
1523
|
var _build = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1567
|
-
var
|
|
1524
|
+
var _this$_options, from, to, address, _yield$transferEthToP, response;
|
|
1568
1525
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1569
1526
|
while (1) switch (_context.prev = _context.next) {
|
|
1570
1527
|
case 0:
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
_context.next = 9;
|
|
1576
|
-
break;
|
|
1577
|
-
}
|
|
1578
|
-
param = _requiredParams[_i];
|
|
1579
|
-
if (!(this._options[param] === undefined)) {
|
|
1580
|
-
_context.next = 6;
|
|
1581
|
-
break;
|
|
1582
|
-
}
|
|
1583
|
-
throw new Error("Builder object is missing parameter: ".concat(param));
|
|
1584
|
-
case 6:
|
|
1585
|
-
_i++;
|
|
1586
|
-
_context.next = 2;
|
|
1587
|
-
break;
|
|
1588
|
-
case 9:
|
|
1589
|
-
validateAddress(this._options.address, this._options.to);
|
|
1590
|
-
if (!(this._options.from === 'Moonbeam' && this._options.to === 'Ethereum')) {
|
|
1591
|
-
_context.next = 12;
|
|
1528
|
+
_this$_options = this._options, from = _this$_options.from, to = _this$_options.to, address = _this$_options.address;
|
|
1529
|
+
validateAddress(address, to);
|
|
1530
|
+
if (!(from === 'Moonbeam' && to === 'Ethereum')) {
|
|
1531
|
+
_context.next = 4;
|
|
1592
1532
|
break;
|
|
1593
1533
|
}
|
|
1594
1534
|
return _context.abrupt("return", transferMoonbeamToEth(this._options));
|
|
1595
|
-
case
|
|
1596
|
-
if (!(
|
|
1597
|
-
_context.next =
|
|
1598
|
-
break;
|
|
1599
|
-
}
|
|
1600
|
-
_context.next = 15;
|
|
1601
|
-
return transferMoonbeamEvm(this._options);
|
|
1602
|
-
case 15:
|
|
1603
|
-
return _context.abrupt("return", _context.sent);
|
|
1604
|
-
case 16:
|
|
1605
|
-
if (!(this._options.from === 'Ethereum')) {
|
|
1606
|
-
_context.next = 22;
|
|
1535
|
+
case 4:
|
|
1536
|
+
if (!(from === 'Moonbeam' || from === 'Moonriver' || from === 'Darwinia')) {
|
|
1537
|
+
_context.next = 8;
|
|
1607
1538
|
break;
|
|
1608
1539
|
}
|
|
1609
|
-
_context.
|
|
1540
|
+
return _context.abrupt("return", transferMoonbeamEvm(this._options));
|
|
1541
|
+
case 8:
|
|
1542
|
+
_context.next = 10;
|
|
1610
1543
|
return transferEthToPolkadot$1(this._options);
|
|
1611
|
-
case
|
|
1544
|
+
case 10:
|
|
1612
1545
|
_yield$transferEthToP = _context.sent;
|
|
1613
1546
|
response = _yield$transferEthToP.response;
|
|
1614
1547
|
return _context.abrupt("return", response.hash);
|
|
1615
|
-
case
|
|
1616
|
-
throw new Error('Scenario not supported');
|
|
1617
|
-
case 23:
|
|
1548
|
+
case 13:
|
|
1618
1549
|
case "end":
|
|
1619
1550
|
return _context.stop();
|
|
1620
1551
|
}
|
|
@@ -1634,7 +1565,10 @@ var EvmBuilderClass = /*#__PURE__*/function () {
|
|
|
1634
1565
|
* @returns An instance of EvmBuilder class
|
|
1635
1566
|
*/
|
|
1636
1567
|
var EvmBuilder$1 = function EvmBuilder(api, provider) {
|
|
1637
|
-
return new
|
|
1568
|
+
return new EvmBuilderCore({
|
|
1569
|
+
api: api,
|
|
1570
|
+
provider: provider
|
|
1571
|
+
});
|
|
1638
1572
|
};
|
|
1639
1573
|
|
|
1640
1574
|
/**
|
|
@@ -1648,10 +1582,55 @@ var Builder = function Builder(api) {
|
|
|
1648
1582
|
pjsApi.setApi(api);
|
|
1649
1583
|
return Builder$1(pjsApi);
|
|
1650
1584
|
};
|
|
1651
|
-
var GeneralBuilder = GeneralBuilder$1;
|
|
1652
1585
|
var EvmBuilder = function EvmBuilder(provider) {
|
|
1653
1586
|
var pjsApi = new PolkadotJsApi();
|
|
1654
1587
|
return EvmBuilder$1(pjsApi, provider);
|
|
1655
1588
|
};
|
|
1656
1589
|
|
|
1657
|
-
|
|
1590
|
+
/**
|
|
1591
|
+
* Transfers assets from parachain to another parachain or from/to relay chain.
|
|
1592
|
+
* @param options - The transfer options.
|
|
1593
|
+
* @returns An extrinsic to be signed and sent.
|
|
1594
|
+
*/
|
|
1595
|
+
var send = createPolkadotJsApiCall(send$1);
|
|
1596
|
+
var getDryRun = createPolkadotJsApiCall(getDryRun$1);
|
|
1597
|
+
var transferEthToPolkadot = function transferEthToPolkadot(options) {
|
|
1598
|
+
return transferEthToPolkadot$1(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
1599
|
+
api: new PolkadotJsApi()
|
|
1600
|
+
}));
|
|
1601
|
+
};
|
|
1602
|
+
var getParaEthTransferFees = /*#__PURE__*/function () {
|
|
1603
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(api) {
|
|
1604
|
+
var pjsApi;
|
|
1605
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1606
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1607
|
+
case 0:
|
|
1608
|
+
pjsApi = new PolkadotJsApi();
|
|
1609
|
+
pjsApi.setApi(api);
|
|
1610
|
+
_context.next = 4;
|
|
1611
|
+
return pjsApi.init('AssetHubPolkadot');
|
|
1612
|
+
case 4:
|
|
1613
|
+
return _context.abrupt("return", getParaEthTransferFees$1(pjsApi));
|
|
1614
|
+
case 5:
|
|
1615
|
+
case "end":
|
|
1616
|
+
return _context.stop();
|
|
1617
|
+
}
|
|
1618
|
+
}, _callee);
|
|
1619
|
+
}));
|
|
1620
|
+
return function getParaEthTransferFees(_x) {
|
|
1621
|
+
return _ref.apply(this, arguments);
|
|
1622
|
+
};
|
|
1623
|
+
}();
|
|
1624
|
+
|
|
1625
|
+
var transfer = /*#__PURE__*/Object.freeze({
|
|
1626
|
+
__proto__: null,
|
|
1627
|
+
approveToken: approveToken,
|
|
1628
|
+
depositToken: depositToken,
|
|
1629
|
+
getDryRun: getDryRun,
|
|
1630
|
+
getParaEthTransferFees: getParaEthTransferFees,
|
|
1631
|
+
getTokenBalance: getTokenBalance,
|
|
1632
|
+
send: send,
|
|
1633
|
+
transferEthToPolkadot: transferEthToPolkadot
|
|
1634
|
+
});
|
|
1635
|
+
|
|
1636
|
+
export { Builder, EvmBuilder, approveToken, assets, claimAssets, createApiInstanceForNode, depositToken, getAssetBalance, getBalanceForeign, getBalanceNative, getDryRun, getMaxForeignTransferableAmount, getMaxNativeTransferableAmount, getOriginFeeDetails, getParaEthTransferFees, getTokenBalance, getTransferInfo, getTransferableAmount, send, transferEthToPolkadot, verifyEdOnDestination, transfer as xcmPallet };
|