@paraspell/sdk-pjs 8.0.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/dist/index.cjs ADDED
@@ -0,0 +1,1408 @@
1
+ 'use strict';
2
+
3
+ var sdkCore = require('@paraspell/sdk-core');
4
+ var api = require('@snowbridge/api');
5
+ var api$1 = require('@polkadot/api');
6
+ var types = require('@polkadot/types');
7
+ var utilCrypto = require('@polkadot/util-crypto');
8
+ var util = require('@polkadot/util');
9
+
10
+ function _arrayLikeToArray(r, a) {
11
+ (null == a || a > r.length) && (a = r.length);
12
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
13
+ return n;
14
+ }
15
+ function _arrayWithHoles(r) {
16
+ if (Array.isArray(r)) return r;
17
+ }
18
+ function _arrayWithoutHoles(r) {
19
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
20
+ }
21
+ function _classCallCheck(a, n) {
22
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
23
+ }
24
+ function _defineProperties(e, r) {
25
+ for (var t = 0; t < r.length; t++) {
26
+ var o = r[t];
27
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
28
+ }
29
+ }
30
+ function _createClass(e, r, t) {
31
+ return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
32
+ writable: !1
33
+ }), e;
34
+ }
35
+ function _iterableToArray(r) {
36
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
37
+ }
38
+ function _iterableToArrayLimit(r, l) {
39
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
40
+ if (null != t) {
41
+ var e,
42
+ n,
43
+ i,
44
+ u,
45
+ a = [],
46
+ f = !0,
47
+ o = !1;
48
+ try {
49
+ if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
50
+ } catch (r) {
51
+ o = !0, n = r;
52
+ } finally {
53
+ try {
54
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
55
+ } finally {
56
+ if (o) throw n;
57
+ }
58
+ }
59
+ return a;
60
+ }
61
+ }
62
+ function _nonIterableRest() {
63
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
64
+ }
65
+ function _nonIterableSpread() {
66
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
67
+ }
68
+ function _regeneratorRuntime() {
69
+ _regeneratorRuntime = function () {
70
+ return e;
71
+ };
72
+ var t,
73
+ e = {},
74
+ r = Object.prototype,
75
+ n = r.hasOwnProperty,
76
+ o = Object.defineProperty || function (t, e, r) {
77
+ t[e] = r.value;
78
+ },
79
+ i = "function" == typeof Symbol ? Symbol : {},
80
+ a = i.iterator || "@@iterator",
81
+ c = i.asyncIterator || "@@asyncIterator",
82
+ u = i.toStringTag || "@@toStringTag";
83
+ function define(t, e, r) {
84
+ return Object.defineProperty(t, e, {
85
+ value: r,
86
+ enumerable: !0,
87
+ configurable: !0,
88
+ writable: !0
89
+ }), t[e];
90
+ }
91
+ try {
92
+ define({}, "");
93
+ } catch (t) {
94
+ define = function (t, e, r) {
95
+ return t[e] = r;
96
+ };
97
+ }
98
+ function wrap(t, e, r, n) {
99
+ var i = e && e.prototype instanceof Generator ? e : Generator,
100
+ a = Object.create(i.prototype),
101
+ c = new Context(n || []);
102
+ return o(a, "_invoke", {
103
+ value: makeInvokeMethod(t, r, c)
104
+ }), a;
105
+ }
106
+ function tryCatch(t, e, r) {
107
+ try {
108
+ return {
109
+ type: "normal",
110
+ arg: t.call(e, r)
111
+ };
112
+ } catch (t) {
113
+ return {
114
+ type: "throw",
115
+ arg: t
116
+ };
117
+ }
118
+ }
119
+ e.wrap = wrap;
120
+ var h = "suspendedStart",
121
+ l = "suspendedYield",
122
+ f = "executing",
123
+ s = "completed",
124
+ y = {};
125
+ function Generator() {}
126
+ function GeneratorFunction() {}
127
+ function GeneratorFunctionPrototype() {}
128
+ var p = {};
129
+ define(p, a, function () {
130
+ return this;
131
+ });
132
+ var d = Object.getPrototypeOf,
133
+ v = d && d(d(values([])));
134
+ v && v !== r && n.call(v, a) && (p = v);
135
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
136
+ function defineIteratorMethods(t) {
137
+ ["next", "throw", "return"].forEach(function (e) {
138
+ define(t, e, function (t) {
139
+ return this._invoke(e, t);
140
+ });
141
+ });
142
+ }
143
+ function AsyncIterator(t, e) {
144
+ function invoke(r, o, i, a) {
145
+ var c = tryCatch(t[r], t, o);
146
+ if ("throw" !== c.type) {
147
+ var u = c.arg,
148
+ h = u.value;
149
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
150
+ invoke("next", t, i, a);
151
+ }, function (t) {
152
+ invoke("throw", t, i, a);
153
+ }) : e.resolve(h).then(function (t) {
154
+ u.value = t, i(u);
155
+ }, function (t) {
156
+ return invoke("throw", t, i, a);
157
+ });
158
+ }
159
+ a(c.arg);
160
+ }
161
+ var r;
162
+ o(this, "_invoke", {
163
+ value: function (t, n) {
164
+ function callInvokeWithMethodAndArg() {
165
+ return new e(function (e, r) {
166
+ invoke(t, n, e, r);
167
+ });
168
+ }
169
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
170
+ }
171
+ });
172
+ }
173
+ function makeInvokeMethod(e, r, n) {
174
+ var o = h;
175
+ return function (i, a) {
176
+ if (o === f) throw Error("Generator is already running");
177
+ if (o === s) {
178
+ if ("throw" === i) throw a;
179
+ return {
180
+ value: t,
181
+ done: !0
182
+ };
183
+ }
184
+ for (n.method = i, n.arg = a;;) {
185
+ var c = n.delegate;
186
+ if (c) {
187
+ var u = maybeInvokeDelegate(c, n);
188
+ if (u) {
189
+ if (u === y) continue;
190
+ return u;
191
+ }
192
+ }
193
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
194
+ if (o === h) throw o = s, n.arg;
195
+ n.dispatchException(n.arg);
196
+ } else "return" === n.method && n.abrupt("return", n.arg);
197
+ o = f;
198
+ var p = tryCatch(e, r, n);
199
+ if ("normal" === p.type) {
200
+ if (o = n.done ? s : l, p.arg === y) continue;
201
+ return {
202
+ value: p.arg,
203
+ done: n.done
204
+ };
205
+ }
206
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
207
+ }
208
+ };
209
+ }
210
+ function maybeInvokeDelegate(e, r) {
211
+ var n = r.method,
212
+ o = e.iterator[n];
213
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
214
+ var i = tryCatch(o, e.iterator, r.arg);
215
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
216
+ var a = i.arg;
217
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
218
+ }
219
+ function pushTryEntry(t) {
220
+ var e = {
221
+ tryLoc: t[0]
222
+ };
223
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
224
+ }
225
+ function resetTryEntry(t) {
226
+ var e = t.completion || {};
227
+ e.type = "normal", delete e.arg, t.completion = e;
228
+ }
229
+ function Context(t) {
230
+ this.tryEntries = [{
231
+ tryLoc: "root"
232
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
233
+ }
234
+ function values(e) {
235
+ if (e || "" === e) {
236
+ var r = e[a];
237
+ if (r) return r.call(e);
238
+ if ("function" == typeof e.next) return e;
239
+ if (!isNaN(e.length)) {
240
+ var o = -1,
241
+ i = function next() {
242
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
243
+ return next.value = t, next.done = !0, next;
244
+ };
245
+ return i.next = i;
246
+ }
247
+ }
248
+ throw new TypeError(typeof e + " is not iterable");
249
+ }
250
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
251
+ value: GeneratorFunctionPrototype,
252
+ configurable: !0
253
+ }), o(GeneratorFunctionPrototype, "constructor", {
254
+ value: GeneratorFunction,
255
+ configurable: !0
256
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
257
+ var e = "function" == typeof t && t.constructor;
258
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
259
+ }, e.mark = function (t) {
260
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
261
+ }, e.awrap = function (t) {
262
+ return {
263
+ __await: t
264
+ };
265
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
266
+ return this;
267
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
268
+ void 0 === i && (i = Promise);
269
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
270
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
271
+ return t.done ? t.value : a.next();
272
+ });
273
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
274
+ return this;
275
+ }), define(g, "toString", function () {
276
+ return "[object Generator]";
277
+ }), e.keys = function (t) {
278
+ var e = Object(t),
279
+ r = [];
280
+ for (var n in e) r.push(n);
281
+ return r.reverse(), function next() {
282
+ for (; r.length;) {
283
+ var t = r.pop();
284
+ if (t in e) return next.value = t, next.done = !1, next;
285
+ }
286
+ return next.done = !0, next;
287
+ };
288
+ }, e.values = values, Context.prototype = {
289
+ constructor: Context,
290
+ reset: function (e) {
291
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
292
+ },
293
+ stop: function () {
294
+ this.done = !0;
295
+ var t = this.tryEntries[0].completion;
296
+ if ("throw" === t.type) throw t.arg;
297
+ return this.rval;
298
+ },
299
+ dispatchException: function (e) {
300
+ if (this.done) throw e;
301
+ var r = this;
302
+ function handle(n, o) {
303
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
304
+ }
305
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
306
+ var i = this.tryEntries[o],
307
+ a = i.completion;
308
+ if ("root" === i.tryLoc) return handle("end");
309
+ if (i.tryLoc <= this.prev) {
310
+ var c = n.call(i, "catchLoc"),
311
+ u = n.call(i, "finallyLoc");
312
+ if (c && u) {
313
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
314
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
315
+ } else if (c) {
316
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
317
+ } else {
318
+ if (!u) throw Error("try statement without catch or finally");
319
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
320
+ }
321
+ }
322
+ }
323
+ },
324
+ abrupt: function (t, e) {
325
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
326
+ var o = this.tryEntries[r];
327
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
328
+ var i = o;
329
+ break;
330
+ }
331
+ }
332
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
333
+ var a = i ? i.completion : {};
334
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
335
+ },
336
+ complete: function (t, e) {
337
+ if ("throw" === t.type) throw t.arg;
338
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
339
+ },
340
+ finish: function (t) {
341
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
342
+ var r = this.tryEntries[e];
343
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
344
+ }
345
+ },
346
+ catch: function (t) {
347
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
348
+ var r = this.tryEntries[e];
349
+ if (r.tryLoc === t) {
350
+ var n = r.completion;
351
+ if ("throw" === n.type) {
352
+ var o = n.arg;
353
+ resetTryEntry(r);
354
+ }
355
+ return o;
356
+ }
357
+ }
358
+ throw Error("illegal catch attempt");
359
+ },
360
+ delegateYield: function (e, r, n) {
361
+ return this.delegate = {
362
+ iterator: values(e),
363
+ resultName: r,
364
+ nextLoc: n
365
+ }, "next" === this.method && (this.arg = t), y;
366
+ }
367
+ }, e;
368
+ }
369
+ function _slicedToArray(r, e) {
370
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
371
+ }
372
+ function _toConsumableArray(r) {
373
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
374
+ }
375
+ function _toPrimitive(t, r) {
376
+ if ("object" != typeof t || !t) return t;
377
+ var e = t[Symbol.toPrimitive];
378
+ if (void 0 !== e) {
379
+ var i = e.call(t, r);
380
+ if ("object" != typeof i) return i;
381
+ throw new TypeError("@@toPrimitive must return a primitive value.");
382
+ }
383
+ return (String )(t);
384
+ }
385
+ function _toPropertyKey(t) {
386
+ var i = _toPrimitive(t, "string");
387
+ return "symbol" == typeof i ? i : i + "";
388
+ }
389
+ function _typeof(o) {
390
+ "@babel/helpers - typeof";
391
+
392
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
393
+ return typeof o;
394
+ } : function (o) {
395
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
396
+ }, _typeof(o);
397
+ }
398
+ function _unsupportedIterableToArray(r, a) {
399
+ if (r) {
400
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
401
+ var t = {}.toString.call(r).slice(8, -1);
402
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
403
+ }
404
+ }
405
+
406
+ /******************************************************************************
407
+ Copyright (c) Microsoft Corporation.
408
+
409
+ Permission to use, copy, modify, and/or distribute this software for any
410
+ purpose with or without fee is hereby granted.
411
+
412
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
413
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
414
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
415
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
416
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
417
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
418
+ PERFORMANCE OF THIS SOFTWARE.
419
+ ***************************************************************************** */
420
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
421
+
422
+
423
+ function __awaiter(thisArg, _arguments, P, generator) {
424
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
425
+ return new (P || (P = Promise))(function (resolve, reject) {
426
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
427
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
428
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
429
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
430
+ });
431
+ }
432
+
433
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
434
+ var e = new Error(message);
435
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
436
+ };
437
+
438
+ var findEthAsset = function findEthAsset(currency) {
439
+ var ethAssets = sdkCore.getOtherAssets('Ethereum');
440
+ var ethAsset = 'symbol' in currency ? ethAssets.find(function (asset) {
441
+ return asset.symbol === currency.symbol;
442
+ }) : ethAssets.find(function (asset) {
443
+ return asset.assetId === currency.id;
444
+ });
445
+ if (!ethAsset) {
446
+ throw new sdkCore.InvalidCurrencyError("Currency ".concat(JSON.stringify(currency), " is not supported for Ethereum transfers"));
447
+ }
448
+ return ethAsset;
449
+ };
450
+
451
+ var createContext = function createContext(executionUrl, config) {
452
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
453
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
454
+ while (1) switch (_context.prev = _context.next) {
455
+ case 0:
456
+ return _context.abrupt("return", api.contextFactory({
457
+ ethereum: {
458
+ execution_url: executionUrl,
459
+ beacon_url: config.BEACON_HTTP_API
460
+ },
461
+ polkadot: {
462
+ url: {
463
+ bridgeHub: config.BRIDGE_HUB_URL,
464
+ assetHub: config.ASSET_HUB_URL,
465
+ relaychain: config.RELAY_CHAIN_URL,
466
+ parachains: config.PARACHAINS
467
+ }
468
+ },
469
+ appContracts: {
470
+ gateway: config.GATEWAY_CONTRACT,
471
+ beefy: config.BEEFY_CONTRACT
472
+ }
473
+ }));
474
+ case 1:
475
+ case "end":
476
+ return _context.stop();
477
+ }
478
+ }, _callee);
479
+ }));
480
+ };
481
+
482
+ var checkPlanFailure = function checkPlanFailure(plan) {
483
+ if (plan.failure) {
484
+ throw new Error("Failed to validate send: ".concat(plan.failure.errors.map(function (e) {
485
+ return e.message;
486
+ }).join('\n\n')));
487
+ }
488
+ };
489
+
490
+ var isEthersSigner = function isEthersSigner(signer) {
491
+ return _typeof(signer) === 'object' && signer !== null && 'provider' in signer;
492
+ };
493
+
494
+ /**
495
+ * Transfers an Ethereum asset to a Polkadot account.
496
+ *
497
+ * @param provider - The Ethereum provider instance to interact with the Ethereum network.
498
+ * @param options - The options for the transfer.
499
+ *
500
+ * @returns A Promise that resolves to an object containing the result and the plan of the transfer.
501
+ *
502
+ * @throws Will throw an error if the transfer validation fails or if the transfer cannot be completed.
503
+ */
504
+ var transferEthToPolkadot$1 = function transferEthToPolkadot(_a) {
505
+ return __awaiter(void 0, [_a], void 0, function (_ref) {
506
+ var provider = _ref.provider,
507
+ signer = _ref.signer,
508
+ address = _ref.address,
509
+ to = _ref.to,
510
+ currency = _ref.currency;
511
+ return /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
512
+ var _b, ethAsset, env, context, destParaId, plan, result;
513
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
514
+ while (1) switch (_context.prev = _context.next) {
515
+ case 0:
516
+ if (provider) {
517
+ _context.next = 2;
518
+ break;
519
+ }
520
+ throw new Error('provider parameter is required for Snowbridge transfers.');
521
+ case 2:
522
+ if (isEthersSigner(signer)) {
523
+ _context.next = 4;
524
+ break;
525
+ }
526
+ throw new Error('Snowbridge does not support Viem provider yet.');
527
+ case 4:
528
+ ethAsset = findEthAsset(currency);
529
+ env = api.environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
530
+ _context.next = 8;
531
+ return createContext(provider, env.config);
532
+ case 8:
533
+ context = _context.sent;
534
+ destParaId = sdkCore.getParaId(to);
535
+ _context.next = 12;
536
+ return api.toPolkadot.validateSend(context, signer, address, (_b = ethAsset.assetId) !== null && _b !== void 0 ? _b : '', destParaId, BigInt(currency.amount), BigInt(0));
537
+ case 12:
538
+ plan = _context.sent;
539
+ checkPlanFailure(plan);
540
+ _context.next = 16;
541
+ return api.toPolkadot.send(context, signer, plan);
542
+ case 16:
543
+ result = _context.sent;
544
+ return _context.abrupt("return", {
545
+ result: result,
546
+ plan: plan
547
+ });
548
+ case 18:
549
+ case "end":
550
+ return _context.stop();
551
+ }
552
+ }, _callee);
553
+ })();
554
+ });
555
+ };
556
+
557
+ var buildEthTransferOptions = function buildEthTransferOptions(_a) {
558
+ return __awaiter(void 0, [_a], void 0, function (_ref) {
559
+ var currency = _ref.currency,
560
+ to = _ref.to,
561
+ address = _ref.address,
562
+ destAddress = _ref.destAddress;
563
+ return /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
564
+ var _b, ethAsset, env, EXECUTION_URL, context, destParaId, signer, plan;
565
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
566
+ while (1) switch (_context.prev = _context.next) {
567
+ case 0:
568
+ ethAsset = findEthAsset(currency);
569
+ env = api.environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
570
+ EXECUTION_URL = 'https://eth.llamarpc.com';
571
+ _context.next = 5;
572
+ return createContext(EXECUTION_URL, env.config);
573
+ case 5:
574
+ context = _context.sent;
575
+ destParaId = sdkCore.getParaId(to);
576
+ signer = {
577
+ getAddress: function getAddress() {
578
+ return Promise.resolve(address);
579
+ }
580
+ };
581
+ _context.next = 10;
582
+ return api.toPolkadot.validateSend(context, signer, destAddress, (_b = ethAsset.assetId) !== null && _b !== void 0 ? _b : '', destParaId, BigInt(currency.amount), BigInt(0));
583
+ case 10:
584
+ plan = _context.sent;
585
+ checkPlanFailure(plan);
586
+ if (plan.success) {
587
+ _context.next = 14;
588
+ break;
589
+ }
590
+ throw new Error('Failed to validate send');
591
+ case 14:
592
+ return _context.abrupt("return", {
593
+ token: plan.success.token,
594
+ destinationParaId: plan.success.destinationParaId,
595
+ destinationFee: plan.success.destinationFee,
596
+ amount: plan.success.amount,
597
+ fee: plan.success.fee
598
+ });
599
+ case 15:
600
+ case "end":
601
+ return _context.stop();
602
+ }
603
+ }, _callee);
604
+ })();
605
+ });
606
+ };
607
+
608
+ var lowercaseFirstLetter = function lowercaseFirstLetter(value) {
609
+ return value.charAt(0).toLowerCase() + value.slice(1);
610
+ };
611
+ var snakeToCamel = function snakeToCamel(str) {
612
+ return str.toLowerCase().replace(/([-_][a-z])/g, function (group) {
613
+ return group.toUpperCase().replace('-', '').replace('_', '');
614
+ });
615
+ };
616
+ var PolkadotJsApi = /*#__PURE__*/function () {
617
+ function PolkadotJsApi() {
618
+ _classCallCheck(this, PolkadotJsApi);
619
+ this.initialized = false;
620
+ this.disconnectAllowed = true;
621
+ }
622
+ return _createClass(PolkadotJsApi, [{
623
+ key: "setApi",
624
+ value: function setApi(api) {
625
+ this._api = api;
626
+ }
627
+ }, {
628
+ key: "getApiOrUrl",
629
+ value: function getApiOrUrl() {
630
+ return this._api;
631
+ }
632
+ }, {
633
+ key: "getApi",
634
+ value: function getApi() {
635
+ return this.api;
636
+ }
637
+ }, {
638
+ key: "init",
639
+ value: function init(node) {
640
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
641
+ var _a;
642
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
643
+ while (1) switch (_context.prev = _context.next) {
644
+ case 0:
645
+ if (!this.initialized) {
646
+ _context.next = 2;
647
+ break;
648
+ }
649
+ return _context.abrupt("return");
650
+ case 2:
651
+ if (!(typeof this._api === 'string' || this._api instanceof Array)) {
652
+ _context.next = 8;
653
+ break;
654
+ }
655
+ _context.next = 5;
656
+ return this.createApiInstance(this._api);
657
+ case 5:
658
+ this.api = _context.sent;
659
+ _context.next = 16;
660
+ break;
661
+ case 8:
662
+ if (!((_a = this._api) !== null && _a !== void 0)) {
663
+ _context.next = 12;
664
+ break;
665
+ }
666
+ _context.t0 = _a;
667
+ _context.next = 15;
668
+ break;
669
+ case 12:
670
+ _context.next = 14;
671
+ return sdkCore.createApiInstanceForNode(this, node);
672
+ case 14:
673
+ _context.t0 = _context.sent;
674
+ case 15:
675
+ this.api = _context.t0;
676
+ case 16:
677
+ this.initialized = true;
678
+ case 17:
679
+ case "end":
680
+ return _context.stop();
681
+ }
682
+ }, _callee, this);
683
+ }));
684
+ }
685
+ }, {
686
+ key: "createApiInstance",
687
+ value: function createApiInstance(wsUrl) {
688
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
689
+ var wsProvider;
690
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
691
+ while (1) switch (_context2.prev = _context2.next) {
692
+ case 0:
693
+ wsProvider = new api$1.WsProvider(wsUrl);
694
+ return _context2.abrupt("return", api$1.ApiPromise.create({
695
+ provider: wsProvider
696
+ }));
697
+ case 2:
698
+ case "end":
699
+ return _context2.stop();
700
+ }
701
+ }, _callee2);
702
+ }));
703
+ }
704
+ }, {
705
+ key: "createAccountId",
706
+ value: function createAccountId(address) {
707
+ return this.api.createType('AccountId32', address).toHex();
708
+ }
709
+ }, {
710
+ key: "accountToHex",
711
+ value: function accountToHex(address) {
712
+ var isPrefixed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
713
+ var uint8Array = utilCrypto.decodeAddress(address);
714
+ return util.u8aToHex(uint8Array, -1, isPrefixed);
715
+ }
716
+ }, {
717
+ key: "callTxMethod",
718
+ value: function callTxMethod(_ref) {
719
+ var _this$api$tx$moduleLo2;
720
+ var module = _ref.module,
721
+ section = _ref.section,
722
+ parameters = _ref.parameters;
723
+ var values = Object.values(parameters);
724
+ var moduleLowerCase = lowercaseFirstLetter(module);
725
+ var sectionCamelCase = snakeToCamel(section);
726
+ if (module === 'Utility') {
727
+ var _this$api$tx$moduleLo;
728
+ return (_this$api$tx$moduleLo = this.api.tx[moduleLowerCase])[sectionCamelCase].apply(_this$api$tx$moduleLo, _toConsumableArray(values[0]));
729
+ }
730
+ return (_this$api$tx$moduleLo2 = this.api.tx[moduleLowerCase])[sectionCamelCase].apply(_this$api$tx$moduleLo2, values);
731
+ }
732
+ }, {
733
+ key: "calculateTransactionFee",
734
+ value: function calculateTransactionFee(tx, address) {
735
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
736
+ var _yield$tx$paymentInfo, partialFee;
737
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
738
+ while (1) switch (_context3.prev = _context3.next) {
739
+ case 0:
740
+ _context3.next = 2;
741
+ return tx.paymentInfo(address);
742
+ case 2:
743
+ _yield$tx$paymentInfo = _context3.sent;
744
+ partialFee = _yield$tx$paymentInfo.partialFee;
745
+ return _context3.abrupt("return", partialFee.toBigInt());
746
+ case 5:
747
+ case "end":
748
+ return _context3.stop();
749
+ }
750
+ }, _callee3);
751
+ }));
752
+ }
753
+ }, {
754
+ key: "getBalanceNative",
755
+ value: function getBalanceNative(address) {
756
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
757
+ var response;
758
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
759
+ while (1) switch (_context4.prev = _context4.next) {
760
+ case 0:
761
+ _context4.next = 2;
762
+ return this.api.query.system.account(address);
763
+ case 2:
764
+ response = _context4.sent;
765
+ return _context4.abrupt("return", response.data.free.toBigInt());
766
+ case 4:
767
+ case "end":
768
+ return _context4.stop();
769
+ }
770
+ }, _callee4, this);
771
+ }));
772
+ }
773
+ }, {
774
+ key: "getBalanceForeignPolkadotXcm",
775
+ value: function getBalanceForeignPolkadotXcm(address, id) {
776
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
777
+ var parsedId, response, obj;
778
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
779
+ while (1) switch (_context5.prev = _context5.next) {
780
+ case 0:
781
+ parsedId = new types.u32(this.api.registry, id);
782
+ _context5.next = 3;
783
+ return this.api.query.assets.account(parsedId, address);
784
+ case 3:
785
+ response = _context5.sent;
786
+ obj = response.toJSON();
787
+ return _context5.abrupt("return", obj.balance ? BigInt(obj.balance) : BigInt(0));
788
+ case 6:
789
+ case "end":
790
+ return _context5.stop();
791
+ }
792
+ }, _callee5, this);
793
+ }));
794
+ }
795
+ }, {
796
+ key: "getMythosForeignBalance",
797
+ value: function getMythosForeignBalance(address) {
798
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
799
+ var response, obj;
800
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
801
+ while (1) switch (_context6.prev = _context6.next) {
802
+ case 0:
803
+ _context6.next = 2;
804
+ return this.api.query.balances.account(address);
805
+ case 2:
806
+ response = _context6.sent;
807
+ obj = response.toJSON();
808
+ return _context6.abrupt("return", obj.free ? BigInt(obj.free) : BigInt(0));
809
+ case 5:
810
+ case "end":
811
+ return _context6.stop();
812
+ }
813
+ }, _callee6, this);
814
+ }));
815
+ }
816
+ }, {
817
+ key: "getAssetHubForeignBalance",
818
+ value: function getAssetHubForeignBalance(address, multiLocation) {
819
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
820
+ var response, obj;
821
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
822
+ while (1) switch (_context7.prev = _context7.next) {
823
+ case 0:
824
+ _context7.next = 2;
825
+ return this.api.query.foreignAssets.account(multiLocation, address);
826
+ case 2:
827
+ response = _context7.sent;
828
+ obj = response.toJSON();
829
+ return _context7.abrupt("return", BigInt(obj === null || !obj.balance ? 0 : obj.balance));
830
+ case 5:
831
+ case "end":
832
+ return _context7.stop();
833
+ }
834
+ }, _callee7, this);
835
+ }));
836
+ }
837
+ }, {
838
+ key: "getForeignAssetsByIdBalance",
839
+ value: function getForeignAssetsByIdBalance(address, assetId) {
840
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
841
+ var response, obj;
842
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
843
+ while (1) switch (_context8.prev = _context8.next) {
844
+ case 0:
845
+ _context8.next = 2;
846
+ return this.api.query.foreignAssets.account(assetId, address);
847
+ case 2:
848
+ response = _context8.sent;
849
+ obj = response.toJSON();
850
+ return _context8.abrupt("return", BigInt(obj === null || !obj.balance ? 0 : obj.balance));
851
+ case 5:
852
+ case "end":
853
+ return _context8.stop();
854
+ }
855
+ }, _callee8, this);
856
+ }));
857
+ }
858
+ }, {
859
+ key: "getBalanceForeignBifrost",
860
+ value: function getBalanceForeignBifrost(address, asset) {
861
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
862
+ var currencySelection, response, accountData;
863
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
864
+ while (1) switch (_context9.prev = _context9.next) {
865
+ case 0:
866
+ currencySelection = sdkCore.getNode('BifrostPolkadot').getCurrencySelection(asset);
867
+ _context9.next = 3;
868
+ return this.api.query.tokens.accounts(address, currencySelection);
869
+ case 3:
870
+ response = _context9.sent;
871
+ accountData = response ? response : null;
872
+ return _context9.abrupt("return", accountData ? BigInt(accountData.free.toString()) : BigInt(0));
873
+ case 6:
874
+ case "end":
875
+ return _context9.stop();
876
+ }
877
+ }, _callee9, this);
878
+ }));
879
+ }
880
+ }, {
881
+ key: "getBalanceNativeAcala",
882
+ value: function getBalanceNativeAcala(address, symbol) {
883
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
884
+ var response, accountData;
885
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
886
+ while (1) switch (_context10.prev = _context10.next) {
887
+ case 0:
888
+ _context10.next = 2;
889
+ return this.api.query.tokens.accounts(address, {
890
+ Token: symbol
891
+ });
892
+ case 2:
893
+ response = _context10.sent;
894
+ accountData = response ? response : null;
895
+ return _context10.abrupt("return", accountData ? BigInt(accountData.free.toString()) : BigInt(0));
896
+ case 5:
897
+ case "end":
898
+ return _context10.stop();
899
+ }
900
+ }, _callee10, this);
901
+ }));
902
+ }
903
+ }, {
904
+ key: "getBalanceForeignXTokens",
905
+ value: function getBalanceForeignXTokens(node, address, asset) {
906
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
907
+ var pallet, response, entry, accountData;
908
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
909
+ while (1) switch (_context11.prev = _context11.next) {
910
+ case 0:
911
+ pallet = 'tokens';
912
+ if (node === 'Centrifuge' || node === 'Altair') {
913
+ pallet = 'ormlTokens';
914
+ }
915
+ _context11.next = 4;
916
+ return this.api.query[pallet].accounts.entries(address);
917
+ case 4:
918
+ response = _context11.sent;
919
+ entry = response.find(function (_ref2) {
920
+ var _ref3 = _slicedToArray(_ref2, 2),
921
+ _ref3$0$args = _slicedToArray(_ref3[0].args, 2);
922
+ _ref3$0$args[0];
923
+ var assetItem = _ref3$0$args[1];
924
+ _ref3[1];
925
+ var _a, _b, _c, _d, _e, _f;
926
+ var assetSymbol = assetItem.toString().toLowerCase();
927
+ return assetSymbol === ((_a = asset.symbol) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || sdkCore.isForeignAsset(asset) && assetSymbol === ((_b = asset.assetId) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || Object.values((_c = assetItem.toHuman()) !== null && _c !== void 0 ? _c : {}).toString().toLowerCase() === ((_d = asset.symbol) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || sdkCore.isForeignAsset(asset) && Object.values((_e = assetItem.toHuman()) !== null && _e !== void 0 ? _e : {}).toString().toLowerCase() === ((_f = asset.assetId) === null || _f === void 0 ? void 0 : _f.toLowerCase());
928
+ });
929
+ accountData = entry ? entry[1] : null;
930
+ return _context11.abrupt("return", accountData ? BigInt(accountData.free.toString()) : BigInt(0));
931
+ case 8:
932
+ case "end":
933
+ return _context11.stop();
934
+ }
935
+ }, _callee11, this);
936
+ }));
937
+ }
938
+ }, {
939
+ key: "getBalanceForeignAssetsAccount",
940
+ value: function getBalanceForeignAssetsAccount(address, assetId) {
941
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
942
+ var response, obj;
943
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
944
+ while (1) switch (_context12.prev = _context12.next) {
945
+ case 0:
946
+ _context12.next = 2;
947
+ return this.api.query.assets.account(assetId, address);
948
+ case 2:
949
+ response = _context12.sent;
950
+ obj = response.toJSON();
951
+ return _context12.abrupt("return", BigInt(obj === null || !obj.balance ? 0 : obj.balance));
952
+ case 5:
953
+ case "end":
954
+ return _context12.stop();
955
+ }
956
+ }, _callee12, this);
957
+ }));
958
+ }
959
+ }, {
960
+ key: "getFromStorage",
961
+ value: function getFromStorage(key) {
962
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
963
+ var response;
964
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
965
+ while (1) switch (_context13.prev = _context13.next) {
966
+ case 0:
967
+ _context13.next = 2;
968
+ return this.api.rpc.state.getStorage(key);
969
+ case 2:
970
+ response = _context13.sent;
971
+ return _context13.abrupt("return", response.toHex());
972
+ case 4:
973
+ case "end":
974
+ return _context13.stop();
975
+ }
976
+ }, _callee13, this);
977
+ }));
978
+ }
979
+ }, {
980
+ key: "clone",
981
+ value: function clone() {
982
+ return new PolkadotJsApi();
983
+ }
984
+ }, {
985
+ key: "createApiForNode",
986
+ value: function createApiForNode(node) {
987
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
988
+ var api;
989
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
990
+ while (1) switch (_context14.prev = _context14.next) {
991
+ case 0:
992
+ api = new PolkadotJsApi();
993
+ _context14.next = 3;
994
+ return api.init(node);
995
+ case 3:
996
+ return _context14.abrupt("return", api);
997
+ case 4:
998
+ case "end":
999
+ return _context14.stop();
1000
+ }
1001
+ }, _callee14);
1002
+ }));
1003
+ }
1004
+ }, {
1005
+ key: "getDryRun",
1006
+ value: function getDryRun(_a) {
1007
+ return __awaiter(this, arguments, void 0, function (_ref4) {
1008
+ var _this = this;
1009
+ var tx = _ref4.tx,
1010
+ address = _ref4.address,
1011
+ node = _ref4.node;
1012
+ return /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1013
+ var supportsDryRunApi, result, isSuccess, moduleError, failureReason, executionFee, fee;
1014
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1015
+ while (1) switch (_context15.prev = _context15.next) {
1016
+ case 0:
1017
+ supportsDryRunApi = sdkCore.getAssetsObject(node).supportsDryRunApi;
1018
+ if (supportsDryRunApi) {
1019
+ _context15.next = 3;
1020
+ break;
1021
+ }
1022
+ throw new Error("DryRunApi is not available on node ".concat(node));
1023
+ case 3:
1024
+ _context15.next = 5;
1025
+ return _this.api.call.dryRunApi.dryRunCall({
1026
+ system: {
1027
+ Signed: address
1028
+ }
1029
+ }, tx);
1030
+ case 5:
1031
+ result = _context15.sent.toHuman();
1032
+ isSuccess = result.Ok && result.Ok.executionResult.Ok;
1033
+ if (isSuccess) {
1034
+ _context15.next = 11;
1035
+ break;
1036
+ }
1037
+ moduleError = result.Ok.executionResult.Err.error.Module;
1038
+ failureReason = sdkCore.resolveModuleError(node, moduleError);
1039
+ return _context15.abrupt("return", {
1040
+ success: false,
1041
+ failureReason: failureReason
1042
+ });
1043
+ case 11:
1044
+ _context15.next = 13;
1045
+ return _this.calculateTransactionFee(tx, address);
1046
+ case 13:
1047
+ executionFee = _context15.sent;
1048
+ fee = sdkCore.computeFeeFromDryRunPjs(result, node, executionFee);
1049
+ return _context15.abrupt("return", {
1050
+ success: true,
1051
+ fee: fee
1052
+ });
1053
+ case 16:
1054
+ case "end":
1055
+ return _context15.stop();
1056
+ }
1057
+ }, _callee15);
1058
+ })();
1059
+ });
1060
+ }
1061
+ }, {
1062
+ key: "setDisconnectAllowed",
1063
+ value: function setDisconnectAllowed(allowed) {
1064
+ this.disconnectAllowed = allowed;
1065
+ }
1066
+ }, {
1067
+ key: "getDisconnectAllowed",
1068
+ value: function getDisconnectAllowed() {
1069
+ return this.disconnectAllowed;
1070
+ }
1071
+ }, {
1072
+ key: "disconnect",
1073
+ value: function disconnect() {
1074
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1075
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1076
+ while (1) switch (_context16.prev = _context16.next) {
1077
+ case 0:
1078
+ if (this.disconnectAllowed) {
1079
+ _context16.next = 2;
1080
+ break;
1081
+ }
1082
+ return _context16.abrupt("return");
1083
+ case 2:
1084
+ if (!(typeof this._api === 'string' || this._api === undefined)) {
1085
+ _context16.next = 5;
1086
+ break;
1087
+ }
1088
+ _context16.next = 5;
1089
+ return this.api.disconnect();
1090
+ case 5:
1091
+ case "end":
1092
+ return _context16.stop();
1093
+ }
1094
+ }, _callee16, this);
1095
+ }));
1096
+ }
1097
+ }]);
1098
+ }();
1099
+
1100
+ var createApiInstanceForNode = function createApiInstanceForNode(node) {
1101
+ var pjsApi = new PolkadotJsApi();
1102
+ return sdkCore.createApiInstanceForNode(pjsApi, node);
1103
+ };
1104
+ var createPolkadotJsApiCall = function createPolkadotJsApiCall(apiCall) {
1105
+ return function (options) {
1106
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1107
+ var pjsApi, optionsWithApi;
1108
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1109
+ while (1) switch (_context.prev = _context.next) {
1110
+ case 0:
1111
+ pjsApi = new PolkadotJsApi();
1112
+ pjsApi.setApi(options.api);
1113
+ optionsWithApi = Object.assign(Object.assign({}, options), {
1114
+ api: pjsApi
1115
+ });
1116
+ return _context.abrupt("return", apiCall(optionsWithApi));
1117
+ case 4:
1118
+ case "end":
1119
+ return _context.stop();
1120
+ }
1121
+ }, _callee);
1122
+ }));
1123
+ };
1124
+ };
1125
+
1126
+ /**
1127
+ * Transfers assets from parachain to another parachain or from/to relay chain.
1128
+ * @param options - The transfer options.
1129
+ * @returns An extrinsic to be signed and sent.
1130
+ */
1131
+ var send = function send(options) {
1132
+ var pjsApi = new PolkadotJsApi();
1133
+ pjsApi.setApi(options.api);
1134
+ var destPjsApi = new PolkadotJsApi();
1135
+ destPjsApi.setApi(options.destApiForKeepAlive);
1136
+ return sdkCore.send(Object.assign(Object.assign({}, options), {
1137
+ api: pjsApi,
1138
+ destApiForKeepAlive: destPjsApi
1139
+ }));
1140
+ };
1141
+ var getDryRun = createPolkadotJsApiCall(sdkCore.getDryRun);
1142
+ var transferEthToPolkadot = function transferEthToPolkadot(options) {
1143
+ return transferEthToPolkadot$1(Object.assign(Object.assign({}, options), {
1144
+ api: new PolkadotJsApi()
1145
+ }));
1146
+ };
1147
+
1148
+ var transfer = /*#__PURE__*/Object.freeze({
1149
+ __proto__: null,
1150
+ buildEthTransferOptions: buildEthTransferOptions,
1151
+ getDryRun: getDryRun,
1152
+ send: send,
1153
+ transferEthToPolkadot: transferEthToPolkadot
1154
+ });
1155
+
1156
+ /**
1157
+ * Retrieves the native balance for a given account on a specified node.
1158
+ *
1159
+ * @returns The native balance as a bigint.
1160
+ */
1161
+ var getBalanceNative = createPolkadotJsApiCall(sdkCore.getBalanceNative);
1162
+ /**
1163
+ * Retrieves the balance of a foreign asset for a given account on a specified node.
1164
+ *
1165
+ * @returns The balance of the foreign asset as a bigint, or null if not found.
1166
+ */
1167
+ var getBalanceForeign = createPolkadotJsApiCall(sdkCore.getBalanceForeign);
1168
+ /**
1169
+ * Retrieves detailed transfer information for a cross-chain transfer.
1170
+ *
1171
+ * @returns A Promise that resolves to the transfer information.
1172
+ */
1173
+ var getTransferInfo = createPolkadotJsApiCall(sdkCore.getTransferInfo);
1174
+ /**
1175
+ * Retrieves the asset balance for a given account on a specified node.
1176
+ *
1177
+ * @returns The asset balance as a bigint.
1178
+ */
1179
+ var getAssetBalance = createPolkadotJsApiCall(sdkCore.getAssetBalance);
1180
+ /**
1181
+ * Claims assets from a parachain.
1182
+ *
1183
+ * @returns An extrinsic representing the claim transaction.
1184
+ */
1185
+ var claimAssets = createPolkadotJsApiCall(sdkCore.claimAssets);
1186
+ var getOriginFeeDetails = createPolkadotJsApiCall(sdkCore.getOriginFeeDetails);
1187
+ var getMaxNativeTransferableAmount = createPolkadotJsApiCall(sdkCore.getMaxNativeTransferableAmount);
1188
+ var getMaxForeignTransferableAmount = createPolkadotJsApiCall(sdkCore.getMaxForeignTransferableAmount);
1189
+ var getTransferableAmount = createPolkadotJsApiCall(sdkCore.getTransferableAmount);
1190
+
1191
+ var assets = /*#__PURE__*/Object.freeze({
1192
+ __proto__: null,
1193
+ claimAssets: claimAssets,
1194
+ getAssetBalance: getAssetBalance,
1195
+ getBalanceForeign: getBalanceForeign,
1196
+ getBalanceNative: getBalanceNative,
1197
+ getMaxForeignTransferableAmount: getMaxForeignTransferableAmount,
1198
+ getMaxNativeTransferableAmount: getMaxNativeTransferableAmount,
1199
+ getOriginFeeDetails: getOriginFeeDetails,
1200
+ getTransferInfo: getTransferInfo,
1201
+ getTransferableAmount: getTransferableAmount
1202
+ });
1203
+
1204
+ /**
1205
+ * Builder class for constructing transfers from Ethereum to Polkadot.
1206
+ */
1207
+ var EvmBuilderClass = /*#__PURE__*/function () {
1208
+ function EvmBuilderClass(api, provider) {
1209
+ _classCallCheck(this, EvmBuilderClass);
1210
+ this._options = {};
1211
+ this._options.api = api;
1212
+ this._options.provider = provider;
1213
+ }
1214
+ return _createClass(EvmBuilderClass, [{
1215
+ key: "from",
1216
+ value: function from(node) {
1217
+ this._options.from = node;
1218
+ return this;
1219
+ }
1220
+ /**
1221
+ * Specifies the destination node on Polkadot.
1222
+ *
1223
+ * @param node - The Polkadot node to which the transfer will be made.
1224
+ * @returns An instance of EvmBuilder
1225
+ */
1226
+ }, {
1227
+ key: "to",
1228
+ value: function to(node) {
1229
+ this._options.to = node;
1230
+ return this;
1231
+ }
1232
+ /**
1233
+ * Specifies the currency to transfer.
1234
+ *
1235
+ * @param currency - The currency to be transferred.
1236
+ * @returns An instance of EvmBuilder
1237
+ */
1238
+ }, {
1239
+ key: "currency",
1240
+ value: function currency(_currency) {
1241
+ this._options.currency = _currency;
1242
+ return this;
1243
+ }
1244
+ /**
1245
+ * Specifies the recipient address on Polkadot.
1246
+ *
1247
+ * @param address - The Polkadot address to receive the transfer.
1248
+ * @returns An instance of EvmBuilder
1249
+ */
1250
+ }, {
1251
+ key: "address",
1252
+ value: function address(_address) {
1253
+ this._options.address = _address;
1254
+ return this;
1255
+ }
1256
+ /**
1257
+ * Specifies the signer for the Ethereum transaction.
1258
+ *
1259
+ * @param signer - The Ethereum signer to authorize the transfer.
1260
+ * @returns An instance of EvmBuilder
1261
+ */
1262
+ }, {
1263
+ key: "signer",
1264
+ value: function signer(_signer) {
1265
+ this._options.signer = _signer;
1266
+ return this;
1267
+ }
1268
+ /**
1269
+ * Builds and executes the transfer from Ethereum to Polkadot.
1270
+ *
1271
+ * @throws Error if any required parameters are missing.
1272
+ */
1273
+ }, {
1274
+ key: "build",
1275
+ value: function build() {
1276
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1277
+ var _a, _b, requiredParams, _i, _requiredParams, param;
1278
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1279
+ while (1) switch (_context.prev = _context.next) {
1280
+ case 0:
1281
+ requiredParams = ['from', 'to', 'currency', 'address', 'signer'];
1282
+ _i = 0, _requiredParams = requiredParams;
1283
+ case 2:
1284
+ if (!(_i < _requiredParams.length)) {
1285
+ _context.next = 9;
1286
+ break;
1287
+ }
1288
+ param = _requiredParams[_i];
1289
+ if (!(this._options[param] === undefined)) {
1290
+ _context.next = 6;
1291
+ break;
1292
+ }
1293
+ throw new Error("Builder object is missing parameter: ".concat(param));
1294
+ case 6:
1295
+ _i++;
1296
+ _context.next = 2;
1297
+ break;
1298
+ case 9:
1299
+ if (!(this._options.from === 'Moonbeam' || this._options.from === 'Moonriver')) {
1300
+ _context.next = 13;
1301
+ break;
1302
+ }
1303
+ _context.next = 12;
1304
+ return sdkCore.transferMoonbeamEvm(this._options);
1305
+ case 12:
1306
+ return _context.abrupt("return", _context.sent);
1307
+ case 13:
1308
+ _context.next = 15;
1309
+ return transferEthToPolkadot$1(this._options);
1310
+ case 15:
1311
+ _context.t2 = _a = _context.sent.result.success;
1312
+ _context.t1 = _context.t2 === null;
1313
+ if (_context.t1) {
1314
+ _context.next = 19;
1315
+ break;
1316
+ }
1317
+ _context.t1 = _a === void 0;
1318
+ case 19:
1319
+ if (!_context.t1) {
1320
+ _context.next = 23;
1321
+ break;
1322
+ }
1323
+ _context.t3 = void 0;
1324
+ _context.next = 24;
1325
+ break;
1326
+ case 23:
1327
+ _context.t3 = _a.ethereum.blockHash;
1328
+ case 24:
1329
+ _context.t4 = _b = _context.t3;
1330
+ _context.t0 = _context.t4 !== null;
1331
+ if (!_context.t0) {
1332
+ _context.next = 28;
1333
+ break;
1334
+ }
1335
+ _context.t0 = _b !== void 0;
1336
+ case 28:
1337
+ if (!_context.t0) {
1338
+ _context.next = 32;
1339
+ break;
1340
+ }
1341
+ _context.t5 = _b;
1342
+ _context.next = 33;
1343
+ break;
1344
+ case 32:
1345
+ _context.t5 = '';
1346
+ case 33:
1347
+ return _context.abrupt("return", _context.t5);
1348
+ case 34:
1349
+ case "end":
1350
+ return _context.stop();
1351
+ }
1352
+ }, _callee, this);
1353
+ }));
1354
+ }
1355
+ }]);
1356
+ }();
1357
+ /**
1358
+ * Creates a new EvmBuilder instance for constructing Ethereum to Polkadot transfers.
1359
+ *
1360
+ * @param provider - The Ethereum provider to use for the transfer.
1361
+ * @returns An instance of EvmBuilder class
1362
+ */
1363
+ var EvmBuilder$1 = function EvmBuilder(api, provider) {
1364
+ return new EvmBuilderClass(api, provider);
1365
+ };
1366
+
1367
+ /**
1368
+ * Creates a new Builder instance.
1369
+ *
1370
+ * @param api - The API instance to use for building transactions. If not provided, a new instance will be created.
1371
+ * @returns A new Builder instance.
1372
+ */
1373
+ var Builder = function Builder(api) {
1374
+ var pjsApi = new PolkadotJsApi();
1375
+ pjsApi.setApi(api);
1376
+ return sdkCore.Builder(pjsApi);
1377
+ };
1378
+ var GeneralBuilder = sdkCore.GeneralBuilder;
1379
+ var EvmBuilder = function EvmBuilder(provider) {
1380
+ var pjsApi = new PolkadotJsApi();
1381
+ return EvmBuilder$1(pjsApi, provider);
1382
+ };
1383
+
1384
+ exports.Builder = Builder;
1385
+ exports.EvmBuilder = EvmBuilder;
1386
+ exports.GeneralBuilder = GeneralBuilder;
1387
+ exports.assets = assets;
1388
+ exports.buildEthTransferOptions = buildEthTransferOptions;
1389
+ exports.claimAssets = claimAssets;
1390
+ exports.createApiInstanceForNode = createApiInstanceForNode;
1391
+ exports.getAssetBalance = getAssetBalance;
1392
+ exports.getBalanceForeign = getBalanceForeign;
1393
+ exports.getBalanceNative = getBalanceNative;
1394
+ exports.getDryRun = getDryRun;
1395
+ exports.getMaxForeignTransferableAmount = getMaxForeignTransferableAmount;
1396
+ exports.getMaxNativeTransferableAmount = getMaxNativeTransferableAmount;
1397
+ exports.getOriginFeeDetails = getOriginFeeDetails;
1398
+ exports.getTransferInfo = getTransferInfo;
1399
+ exports.getTransferableAmount = getTransferableAmount;
1400
+ exports.send = send;
1401
+ exports.transferEthToPolkadot = transferEthToPolkadot;
1402
+ exports.xcmPallet = transfer;
1403
+ Object.keys(sdkCore).forEach(function (k) {
1404
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1405
+ enumerable: true,
1406
+ get: function () { return sdkCore[k]; }
1407
+ });
1408
+ });