@paraspell/sdk-pjs 11.14.8 → 12.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/README.md +5 -31
- package/dist/index.d.ts +5 -39
- package/dist/index.mjs +21 -55
- package/package.json +2 -2
- package/dist/index.cjs +0 -1763
package/dist/index.cjs
DELETED
|
@@ -1,1763 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var sdkCore = require('@paraspell/sdk-core');
|
|
4
|
-
var api = require('@polkadot/api');
|
|
5
|
-
var util = require('@polkadot/util');
|
|
6
|
-
var utilCrypto = require('@polkadot/util-crypto');
|
|
7
|
-
var api$1 = require('@snowbridge/api');
|
|
8
|
-
var contractTypes = require('@snowbridge/contract-types');
|
|
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 _arrayWithoutHoles(r) {
|
|
16
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
17
|
-
}
|
|
18
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
19
|
-
try {
|
|
20
|
-
var i = n[a](c),
|
|
21
|
-
u = i.value;
|
|
22
|
-
} catch (n) {
|
|
23
|
-
return void e(n);
|
|
24
|
-
}
|
|
25
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
26
|
-
}
|
|
27
|
-
function _asyncToGenerator(n) {
|
|
28
|
-
return function () {
|
|
29
|
-
var t = this,
|
|
30
|
-
e = arguments;
|
|
31
|
-
return new Promise(function (r, o) {
|
|
32
|
-
var a = n.apply(t, e);
|
|
33
|
-
function _next(n) {
|
|
34
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
35
|
-
}
|
|
36
|
-
function _throw(n) {
|
|
37
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
38
|
-
}
|
|
39
|
-
_next(void 0);
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function _classCallCheck(a, n) {
|
|
44
|
-
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
45
|
-
}
|
|
46
|
-
function _defineProperties(e, r) {
|
|
47
|
-
for (var t = 0; t < r.length; t++) {
|
|
48
|
-
var o = r[t];
|
|
49
|
-
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function _createClass(e, r, t) {
|
|
53
|
-
return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
|
|
54
|
-
writable: false
|
|
55
|
-
}), e;
|
|
56
|
-
}
|
|
57
|
-
function _defineProperty(e, r, t) {
|
|
58
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
59
|
-
value: t,
|
|
60
|
-
enumerable: true,
|
|
61
|
-
configurable: true,
|
|
62
|
-
writable: true
|
|
63
|
-
}) : e[r] = t, e;
|
|
64
|
-
}
|
|
65
|
-
function _iterableToArray(r) {
|
|
66
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
67
|
-
}
|
|
68
|
-
function _nonIterableSpread() {
|
|
69
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
70
|
-
}
|
|
71
|
-
function ownKeys(e, r) {
|
|
72
|
-
var t = Object.keys(e);
|
|
73
|
-
if (Object.getOwnPropertySymbols) {
|
|
74
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
75
|
-
r && (o = o.filter(function (r) {
|
|
76
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
77
|
-
})), t.push.apply(t, o);
|
|
78
|
-
}
|
|
79
|
-
return t;
|
|
80
|
-
}
|
|
81
|
-
function _objectSpread2(e) {
|
|
82
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
83
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
84
|
-
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
85
|
-
_defineProperty(e, r, t[r]);
|
|
86
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
87
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return e;
|
|
91
|
-
}
|
|
92
|
-
function _regenerator() {
|
|
93
|
-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
94
|
-
var e,
|
|
95
|
-
t,
|
|
96
|
-
r = "function" == typeof Symbol ? Symbol : {},
|
|
97
|
-
n = r.iterator || "@@iterator",
|
|
98
|
-
o = r.toStringTag || "@@toStringTag";
|
|
99
|
-
function i(r, n, o, i) {
|
|
100
|
-
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
101
|
-
u = Object.create(c.prototype);
|
|
102
|
-
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
103
|
-
var i,
|
|
104
|
-
c,
|
|
105
|
-
u,
|
|
106
|
-
f = 0,
|
|
107
|
-
p = o || [],
|
|
108
|
-
y = false,
|
|
109
|
-
G = {
|
|
110
|
-
p: 0,
|
|
111
|
-
n: 0,
|
|
112
|
-
v: e,
|
|
113
|
-
a: d,
|
|
114
|
-
f: d.bind(e, 4),
|
|
115
|
-
d: function (t, r) {
|
|
116
|
-
return i = t, c = 0, u = e, G.n = r, a;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
function d(r, n) {
|
|
120
|
-
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
121
|
-
var o,
|
|
122
|
-
i = p[t],
|
|
123
|
-
d = G.p,
|
|
124
|
-
l = i[2];
|
|
125
|
-
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
126
|
-
}
|
|
127
|
-
if (o || r > 1) return a;
|
|
128
|
-
throw y = true, n;
|
|
129
|
-
}
|
|
130
|
-
return function (o, p, l) {
|
|
131
|
-
if (f > 1) throw TypeError("Generator is already running");
|
|
132
|
-
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
133
|
-
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
134
|
-
try {
|
|
135
|
-
if (f = 2, i) {
|
|
136
|
-
if (c || (o = "next"), t = i[o]) {
|
|
137
|
-
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
138
|
-
if (!t.done) return t;
|
|
139
|
-
u = t.value, c < 2 && (c = 0);
|
|
140
|
-
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
141
|
-
i = e;
|
|
142
|
-
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
143
|
-
} catch (t) {
|
|
144
|
-
i = e, c = 1, u = t;
|
|
145
|
-
} finally {
|
|
146
|
-
f = 1;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
value: t,
|
|
151
|
-
done: y
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
}(r, o, i), true), u;
|
|
155
|
-
}
|
|
156
|
-
var a = {};
|
|
157
|
-
function Generator() {}
|
|
158
|
-
function GeneratorFunction() {}
|
|
159
|
-
function GeneratorFunctionPrototype() {}
|
|
160
|
-
t = Object.getPrototypeOf;
|
|
161
|
-
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
162
|
-
return this;
|
|
163
|
-
}), t),
|
|
164
|
-
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
165
|
-
function f(e) {
|
|
166
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
167
|
-
}
|
|
168
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
169
|
-
return this;
|
|
170
|
-
}), _regeneratorDefine(u, "toString", function () {
|
|
171
|
-
return "[object Generator]";
|
|
172
|
-
}), (_regenerator = function () {
|
|
173
|
-
return {
|
|
174
|
-
w: i,
|
|
175
|
-
m: f
|
|
176
|
-
};
|
|
177
|
-
})();
|
|
178
|
-
}
|
|
179
|
-
function _regeneratorDefine(e, r, n, t) {
|
|
180
|
-
var i = Object.defineProperty;
|
|
181
|
-
try {
|
|
182
|
-
i({}, "", {});
|
|
183
|
-
} catch (e) {
|
|
184
|
-
i = 0;
|
|
185
|
-
}
|
|
186
|
-
_regeneratorDefine = function (e, r, n, t) {
|
|
187
|
-
function o(r, n) {
|
|
188
|
-
_regeneratorDefine(e, r, function (e) {
|
|
189
|
-
return this._invoke(r, n, e);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
r ? i ? i(e, r, {
|
|
193
|
-
value: n,
|
|
194
|
-
enumerable: !t,
|
|
195
|
-
configurable: !t,
|
|
196
|
-
writable: !t
|
|
197
|
-
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
198
|
-
}, _regeneratorDefine(e, r, n, t);
|
|
199
|
-
}
|
|
200
|
-
function _toConsumableArray(r) {
|
|
201
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
202
|
-
}
|
|
203
|
-
function _toPrimitive(t, r) {
|
|
204
|
-
if ("object" != typeof t || !t) return t;
|
|
205
|
-
var e = t[Symbol.toPrimitive];
|
|
206
|
-
if (void 0 !== e) {
|
|
207
|
-
var i = e.call(t, r);
|
|
208
|
-
if ("object" != typeof i) return i;
|
|
209
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
210
|
-
}
|
|
211
|
-
return ("string" === r ? String : Number)(t);
|
|
212
|
-
}
|
|
213
|
-
function _toPropertyKey(t) {
|
|
214
|
-
var i = _toPrimitive(t, "string");
|
|
215
|
-
return "symbol" == typeof i ? i : i + "";
|
|
216
|
-
}
|
|
217
|
-
function _typeof(o) {
|
|
218
|
-
"@babel/helpers - typeof";
|
|
219
|
-
|
|
220
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
221
|
-
return typeof o;
|
|
222
|
-
} : function (o) {
|
|
223
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
224
|
-
}, _typeof(o);
|
|
225
|
-
}
|
|
226
|
-
function _unsupportedIterableToArray(r, a) {
|
|
227
|
-
if (r) {
|
|
228
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
229
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
230
|
-
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;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
var lowercaseFirstLetter = function lowercaseFirstLetter(value) {
|
|
235
|
-
return value.charAt(0).toLowerCase() + value.slice(1);
|
|
236
|
-
};
|
|
237
|
-
var snakeToCamel = function snakeToCamel(str) {
|
|
238
|
-
return str.toLowerCase().replace(/([-_][a-z])/g, function (group) {
|
|
239
|
-
return group.toUpperCase().replace('-', '').replace('_', '');
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
var PolkadotJsApi = /*#__PURE__*/function () {
|
|
243
|
-
function PolkadotJsApi(config) {
|
|
244
|
-
_classCallCheck(this, PolkadotJsApi);
|
|
245
|
-
this.initialized = false;
|
|
246
|
-
this.disconnectAllowed = true;
|
|
247
|
-
this._config = config;
|
|
248
|
-
}
|
|
249
|
-
return _createClass(PolkadotJsApi, [{
|
|
250
|
-
key: "getConfig",
|
|
251
|
-
value: function getConfig() {
|
|
252
|
-
return this._config;
|
|
253
|
-
}
|
|
254
|
-
}, {
|
|
255
|
-
key: "getApi",
|
|
256
|
-
value: function getApi() {
|
|
257
|
-
return this.api;
|
|
258
|
-
}
|
|
259
|
-
}, {
|
|
260
|
-
key: "init",
|
|
261
|
-
value: function () {
|
|
262
|
-
var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, _clientTtlMs) {
|
|
263
|
-
var apiConfig;
|
|
264
|
-
return _regenerator().w(function (_context) {
|
|
265
|
-
while (1) switch (_context.n) {
|
|
266
|
-
case 0:
|
|
267
|
-
if (!(this.initialized || chain === 'Ethereum')) {
|
|
268
|
-
_context.n = 1;
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
return _context.a(2);
|
|
272
|
-
case 1:
|
|
273
|
-
this._chain = chain;
|
|
274
|
-
apiConfig = this.getApiConfigForChain(chain);
|
|
275
|
-
if (!(sdkCore.isConfig(this._config) && this._config.development && !apiConfig)) {
|
|
276
|
-
_context.n = 2;
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
throw new sdkCore.MissingChainApiError(chain);
|
|
280
|
-
case 2:
|
|
281
|
-
_context.n = 3;
|
|
282
|
-
return this.resolveApi(apiConfig, chain);
|
|
283
|
-
case 3:
|
|
284
|
-
this.api = _context.v;
|
|
285
|
-
this.initialized = true;
|
|
286
|
-
case 4:
|
|
287
|
-
return _context.a(2);
|
|
288
|
-
}
|
|
289
|
-
}, _callee, this);
|
|
290
|
-
}));
|
|
291
|
-
function init(_x, _x2) {
|
|
292
|
-
return _init.apply(this, arguments);
|
|
293
|
-
}
|
|
294
|
-
return init;
|
|
295
|
-
}()
|
|
296
|
-
}, {
|
|
297
|
-
key: "getApiConfigForChain",
|
|
298
|
-
value: function getApiConfigForChain(chain) {
|
|
299
|
-
if (sdkCore.isConfig(this._config)) {
|
|
300
|
-
var _this$_config$apiOver;
|
|
301
|
-
return (_this$_config$apiOver = this._config.apiOverrides) === null || _this$_config$apiOver === void 0 ? void 0 : _this$_config$apiOver[chain];
|
|
302
|
-
}
|
|
303
|
-
return this._config;
|
|
304
|
-
}
|
|
305
|
-
}, {
|
|
306
|
-
key: "resolveApi",
|
|
307
|
-
value: function () {
|
|
308
|
-
var _resolveApi = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(apiConfig, chain) {
|
|
309
|
-
var wsUrl;
|
|
310
|
-
return _regenerator().w(function (_context2) {
|
|
311
|
-
while (1) switch (_context2.n) {
|
|
312
|
-
case 0:
|
|
313
|
-
if (apiConfig) {
|
|
314
|
-
_context2.n = 1;
|
|
315
|
-
break;
|
|
316
|
-
}
|
|
317
|
-
wsUrl = sdkCore.getChainProviders(chain);
|
|
318
|
-
return _context2.a(2, this.createApiInstance(wsUrl, chain));
|
|
319
|
-
case 1:
|
|
320
|
-
if (!(typeof apiConfig === 'string' || apiConfig instanceof Array)) {
|
|
321
|
-
_context2.n = 2;
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
return _context2.a(2, this.createApiInstance(apiConfig, chain));
|
|
325
|
-
case 2:
|
|
326
|
-
return _context2.a(2, apiConfig);
|
|
327
|
-
}
|
|
328
|
-
}, _callee2, this);
|
|
329
|
-
}));
|
|
330
|
-
function resolveApi(_x3, _x4) {
|
|
331
|
-
return _resolveApi.apply(this, arguments);
|
|
332
|
-
}
|
|
333
|
-
return resolveApi;
|
|
334
|
-
}()
|
|
335
|
-
}, {
|
|
336
|
-
key: "createApiInstance",
|
|
337
|
-
value: function () {
|
|
338
|
-
var _createApiInstance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(wsUrl, _chain) {
|
|
339
|
-
var wsProvider;
|
|
340
|
-
return _regenerator().w(function (_context3) {
|
|
341
|
-
while (1) switch (_context3.n) {
|
|
342
|
-
case 0:
|
|
343
|
-
wsProvider = new api.WsProvider(wsUrl);
|
|
344
|
-
return _context3.a(2, api.ApiPromise.create({
|
|
345
|
-
provider: wsProvider
|
|
346
|
-
}));
|
|
347
|
-
}
|
|
348
|
-
}, _callee3);
|
|
349
|
-
}));
|
|
350
|
-
function createApiInstance(_x5, _x6) {
|
|
351
|
-
return _createApiInstance.apply(this, arguments);
|
|
352
|
-
}
|
|
353
|
-
return createApiInstance;
|
|
354
|
-
}()
|
|
355
|
-
}, {
|
|
356
|
-
key: "accountToHex",
|
|
357
|
-
value: function accountToHex(address) {
|
|
358
|
-
var isPrefixed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
359
|
-
if (util.isHex(address)) return address;
|
|
360
|
-
var uint8Array = utilCrypto.decodeAddress(address);
|
|
361
|
-
return util.u8aToHex(uint8Array, -1, isPrefixed);
|
|
362
|
-
}
|
|
363
|
-
}, {
|
|
364
|
-
key: "accountToUint8a",
|
|
365
|
-
value: function accountToUint8a(address) {
|
|
366
|
-
return utilCrypto.decodeAddress(address);
|
|
367
|
-
}
|
|
368
|
-
}, {
|
|
369
|
-
key: "convertToPjsCall",
|
|
370
|
-
value: function convertToPjsCall(_ref) {
|
|
371
|
-
var module = _ref.module,
|
|
372
|
-
method = _ref.method;
|
|
373
|
-
return {
|
|
374
|
-
module: lowercaseFirstLetter(module),
|
|
375
|
-
method: snakeToCamel(method)
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
}, {
|
|
379
|
-
key: "deserializeExtrinsics",
|
|
380
|
-
value: function deserializeExtrinsics(serialized) {
|
|
381
|
-
var _this$api$tx$module;
|
|
382
|
-
var params = serialized.params;
|
|
383
|
-
var values = Object.values(params);
|
|
384
|
-
var _this$convertToPjsCal = this.convertToPjsCall(serialized),
|
|
385
|
-
module = _this$convertToPjsCal.module,
|
|
386
|
-
method = _this$convertToPjsCal.method;
|
|
387
|
-
return (_this$api$tx$module = this.api.tx[module])[method].apply(_this$api$tx$module, values);
|
|
388
|
-
}
|
|
389
|
-
}, {
|
|
390
|
-
key: "queryState",
|
|
391
|
-
value: function () {
|
|
392
|
-
var _queryState = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(serialized) {
|
|
393
|
-
var _this$api$query$modul;
|
|
394
|
-
var params, _this$convertToPjsCal2, module, method, res;
|
|
395
|
-
return _regenerator().w(function (_context4) {
|
|
396
|
-
while (1) switch (_context4.n) {
|
|
397
|
-
case 0:
|
|
398
|
-
params = serialized.params;
|
|
399
|
-
_this$convertToPjsCal2 = this.convertToPjsCall(serialized), module = _this$convertToPjsCal2.module, method = _this$convertToPjsCal2.method;
|
|
400
|
-
_context4.n = 1;
|
|
401
|
-
return (_this$api$query$modul = this.api.query[module])[method].apply(_this$api$query$modul, _toConsumableArray(params));
|
|
402
|
-
case 1:
|
|
403
|
-
res = _context4.v;
|
|
404
|
-
return _context4.a(2, res.toJSON());
|
|
405
|
-
}
|
|
406
|
-
}, _callee4, this);
|
|
407
|
-
}));
|
|
408
|
-
function queryState(_x7) {
|
|
409
|
-
return _queryState.apply(this, arguments);
|
|
410
|
-
}
|
|
411
|
-
return queryState;
|
|
412
|
-
}()
|
|
413
|
-
}, {
|
|
414
|
-
key: "queryRuntimeApi",
|
|
415
|
-
value: function queryRuntimeApi(serialized) {
|
|
416
|
-
var _this$api$call$module;
|
|
417
|
-
var params = serialized.params;
|
|
418
|
-
var _this$convertToPjsCal3 = this.convertToPjsCall(serialized),
|
|
419
|
-
module = _this$convertToPjsCal3.module,
|
|
420
|
-
method = _this$convertToPjsCal3.method;
|
|
421
|
-
return (_this$api$call$module = this.api.call[module])[method].apply(_this$api$call$module, _toConsumableArray(params));
|
|
422
|
-
}
|
|
423
|
-
}, {
|
|
424
|
-
key: "callBatchMethod",
|
|
425
|
-
value: function callBatchMethod(calls, mode) {
|
|
426
|
-
var method = mode === sdkCore.BatchMode.BATCH_ALL ? 'batchAll' : 'batch';
|
|
427
|
-
return this.api.tx.utility[method](calls);
|
|
428
|
-
}
|
|
429
|
-
}, {
|
|
430
|
-
key: "callDispatchAsMethod",
|
|
431
|
-
value: function callDispatchAsMethod(call, address) {
|
|
432
|
-
var origin = {
|
|
433
|
-
system: {
|
|
434
|
-
Signed: address
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
return this.api.tx.utility.dispatchAs(origin, call);
|
|
438
|
-
}
|
|
439
|
-
}, {
|
|
440
|
-
key: "objectToHex",
|
|
441
|
-
value: function objectToHex(obj, typeName) {
|
|
442
|
-
return Promise.resolve(this.api.createType(typeName, obj).toHex());
|
|
443
|
-
}
|
|
444
|
-
}, {
|
|
445
|
-
key: "hexToUint8a",
|
|
446
|
-
value: function hexToUint8a(hex) {
|
|
447
|
-
return util.hexToU8a(hex);
|
|
448
|
-
}
|
|
449
|
-
}, {
|
|
450
|
-
key: "stringToUint8a",
|
|
451
|
-
value: function stringToUint8a(str) {
|
|
452
|
-
return util.stringToU8a(str);
|
|
453
|
-
}
|
|
454
|
-
}, {
|
|
455
|
-
key: "calculateTransactionFee",
|
|
456
|
-
value: function () {
|
|
457
|
-
var _calculateTransactionFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(tx, address) {
|
|
458
|
-
var _yield$tx$paymentInfo, partialFee;
|
|
459
|
-
return _regenerator().w(function (_context5) {
|
|
460
|
-
while (1) switch (_context5.n) {
|
|
461
|
-
case 0:
|
|
462
|
-
_context5.n = 1;
|
|
463
|
-
return tx.paymentInfo(address);
|
|
464
|
-
case 1:
|
|
465
|
-
_yield$tx$paymentInfo = _context5.v;
|
|
466
|
-
partialFee = _yield$tx$paymentInfo.partialFee;
|
|
467
|
-
return _context5.a(2, partialFee.toBigInt());
|
|
468
|
-
}
|
|
469
|
-
}, _callee5);
|
|
470
|
-
}));
|
|
471
|
-
function calculateTransactionFee(_x8, _x9) {
|
|
472
|
-
return _calculateTransactionFee.apply(this, arguments);
|
|
473
|
-
}
|
|
474
|
-
return calculateTransactionFee;
|
|
475
|
-
}()
|
|
476
|
-
}, {
|
|
477
|
-
key: "quoteAhPrice",
|
|
478
|
-
value: function () {
|
|
479
|
-
var _quoteAhPrice = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(fromMl, toMl, amountIn) {
|
|
480
|
-
var includeFee,
|
|
481
|
-
quoted,
|
|
482
|
-
_args6 = arguments;
|
|
483
|
-
return _regenerator().w(function (_context6) {
|
|
484
|
-
while (1) switch (_context6.n) {
|
|
485
|
-
case 0:
|
|
486
|
-
includeFee = _args6.length > 3 && _args6[3] !== undefined ? _args6[3] : true;
|
|
487
|
-
_context6.n = 1;
|
|
488
|
-
return this.api.call.assetConversionApi.quotePriceExactTokensForTokens(fromMl, toMl, amountIn.toString(), includeFee);
|
|
489
|
-
case 1:
|
|
490
|
-
quoted = _context6.v;
|
|
491
|
-
return _context6.a(2, quoted.toJSON() !== null ? BigInt(quoted.toString()) : undefined);
|
|
492
|
-
}
|
|
493
|
-
}, _callee6, this);
|
|
494
|
-
}));
|
|
495
|
-
function quoteAhPrice(_x0, _x1, _x10) {
|
|
496
|
-
return _quoteAhPrice.apply(this, arguments);
|
|
497
|
-
}
|
|
498
|
-
return quoteAhPrice;
|
|
499
|
-
}()
|
|
500
|
-
}, {
|
|
501
|
-
key: "getEvmStorage",
|
|
502
|
-
value: function getEvmStorage(contract, slot) {
|
|
503
|
-
return Promise.resolve(this.api.query.evm.accountStorages.key(contract, slot));
|
|
504
|
-
}
|
|
505
|
-
}, {
|
|
506
|
-
key: "getMethod",
|
|
507
|
-
value: function getMethod(tx) {
|
|
508
|
-
return tx.method.method;
|
|
509
|
-
}
|
|
510
|
-
}, {
|
|
511
|
-
key: "getTypeThenAssetCount",
|
|
512
|
-
value: function getTypeThenAssetCount(tx) {
|
|
513
|
-
if (this.getMethod(tx) !== 'transferAssetsUsingTypeAndThen') return undefined;
|
|
514
|
-
var human = tx.toHuman();
|
|
515
|
-
return Object.values(human.method.args.assets)[0].length;
|
|
516
|
-
}
|
|
517
|
-
}, {
|
|
518
|
-
key: "hasMethod",
|
|
519
|
-
value: function hasMethod(pallet, method) {
|
|
520
|
-
var _this$api$tx$palletFo;
|
|
521
|
-
var palletFormatted = lowercaseFirstLetter(pallet);
|
|
522
|
-
var methodFormatted = snakeToCamel(method);
|
|
523
|
-
return Promise.resolve(((_this$api$tx$palletFo = this.api.tx[palletFormatted]) === null || _this$api$tx$palletFo === void 0 ? void 0 : _this$api$tx$palletFo[methodFormatted]) !== undefined);
|
|
524
|
-
}
|
|
525
|
-
}, {
|
|
526
|
-
key: "getFromRpc",
|
|
527
|
-
value: function () {
|
|
528
|
-
var _getFromRpc = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(module, method, key) {
|
|
529
|
-
var rpcModule, response;
|
|
530
|
-
return _regenerator().w(function (_context7) {
|
|
531
|
-
while (1) switch (_context7.n) {
|
|
532
|
-
case 0:
|
|
533
|
-
rpcModule = this.api.rpc[module];
|
|
534
|
-
if (!(!rpcModule || !rpcModule[method])) {
|
|
535
|
-
_context7.n = 1;
|
|
536
|
-
break;
|
|
537
|
-
}
|
|
538
|
-
throw new sdkCore.InvalidParameterError("RPC method ".concat(module, ".").concat(method, " not available"));
|
|
539
|
-
case 1:
|
|
540
|
-
_context7.n = 2;
|
|
541
|
-
return rpcModule[method](key);
|
|
542
|
-
case 2:
|
|
543
|
-
response = _context7.v;
|
|
544
|
-
return _context7.a(2, response.toHex());
|
|
545
|
-
}
|
|
546
|
-
}, _callee7, this);
|
|
547
|
-
}));
|
|
548
|
-
function getFromRpc(_x11, _x12, _x13) {
|
|
549
|
-
return _getFromRpc.apply(this, arguments);
|
|
550
|
-
}
|
|
551
|
-
return getFromRpc;
|
|
552
|
-
}()
|
|
553
|
-
}, {
|
|
554
|
-
key: "blake2AsHex",
|
|
555
|
-
value: function blake2AsHex(data) {
|
|
556
|
-
return utilCrypto.blake2AsHex(data);
|
|
557
|
-
}
|
|
558
|
-
}, {
|
|
559
|
-
key: "clone",
|
|
560
|
-
value: function clone() {
|
|
561
|
-
return new PolkadotJsApi(sdkCore.isConfig(this._config) ? this._config : undefined);
|
|
562
|
-
}
|
|
563
|
-
}, {
|
|
564
|
-
key: "createApiForChain",
|
|
565
|
-
value: function () {
|
|
566
|
-
var _createApiForChain = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(chain) {
|
|
567
|
-
var api;
|
|
568
|
-
return _regenerator().w(function (_context8) {
|
|
569
|
-
while (1) switch (_context8.n) {
|
|
570
|
-
case 0:
|
|
571
|
-
api = new PolkadotJsApi();
|
|
572
|
-
_context8.n = 1;
|
|
573
|
-
return api.init(chain);
|
|
574
|
-
case 1:
|
|
575
|
-
return _context8.a(2, api);
|
|
576
|
-
}
|
|
577
|
-
}, _callee8);
|
|
578
|
-
}));
|
|
579
|
-
function createApiForChain(_x14) {
|
|
580
|
-
return _createApiForChain.apply(this, arguments);
|
|
581
|
-
}
|
|
582
|
-
return createApiForChain;
|
|
583
|
-
}()
|
|
584
|
-
}, {
|
|
585
|
-
key: "getDryRunCall",
|
|
586
|
-
value: function () {
|
|
587
|
-
var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(options) {
|
|
588
|
-
var _this = this;
|
|
589
|
-
var tx, address, feeAsset, chain, destination, _options$useRootOrigi, useRootOrigin, bypassOptions, supportsDryRunApi, DEFAULT_XCM_VERSION, basePayload, resolvedTx, usedAsset, usedSymbol, performDryRunCall, getExecutionSuccessFromResult, extractFailureReasonFromResult, response, resultHuman, resultJson, isSuccess, failureErr, shouldRetryWithVersion, msg, _msg, forwardedXcms, actualWeight, weight, nativeAsset, hasLocation, destParaId, xcmFee, executionFee, fee, _t, _t2, _t3;
|
|
590
|
-
return _regenerator().w(function (_context0) {
|
|
591
|
-
while (1) switch (_context0.p = _context0.n) {
|
|
592
|
-
case 0:
|
|
593
|
-
tx = options.tx, address = options.address, feeAsset = options.feeAsset, chain = options.chain, destination = options.destination, _options$useRootOrigi = options.useRootOrigin, useRootOrigin = _options$useRootOrigi === void 0 ? false : _options$useRootOrigi, bypassOptions = options.bypassOptions;
|
|
594
|
-
supportsDryRunApi = sdkCore.getAssetsObject(chain).supportsDryRunApi;
|
|
595
|
-
if (supportsDryRunApi) {
|
|
596
|
-
_context0.n = 1;
|
|
597
|
-
break;
|
|
598
|
-
}
|
|
599
|
-
throw new sdkCore.ChainNotSupportedError("DryRunApi is not available on chain ".concat(chain));
|
|
600
|
-
case 1:
|
|
601
|
-
DEFAULT_XCM_VERSION = 3;
|
|
602
|
-
basePayload = useRootOrigin ? {
|
|
603
|
-
system: {
|
|
604
|
-
Root: null
|
|
605
|
-
}
|
|
606
|
-
} : {
|
|
607
|
-
system: {
|
|
608
|
-
Signed: address
|
|
609
|
-
}
|
|
610
|
-
};
|
|
611
|
-
if (!useRootOrigin) {
|
|
612
|
-
_context0.n = 3;
|
|
613
|
-
break;
|
|
614
|
-
}
|
|
615
|
-
_context0.n = 2;
|
|
616
|
-
return sdkCore.wrapTxBypass(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
617
|
-
api: this
|
|
618
|
-
}), bypassOptions);
|
|
619
|
-
case 2:
|
|
620
|
-
_t = _context0.v;
|
|
621
|
-
_context0.n = 4;
|
|
622
|
-
break;
|
|
623
|
-
case 3:
|
|
624
|
-
_t = tx;
|
|
625
|
-
case 4:
|
|
626
|
-
resolvedTx = _t;
|
|
627
|
-
usedAsset = feeAsset !== null && feeAsset !== void 0 ? feeAsset : sdkCore.findNativeAssetInfoOrThrow(chain);
|
|
628
|
-
usedSymbol = usedAsset.symbol;
|
|
629
|
-
performDryRunCall = /*#__PURE__*/function () {
|
|
630
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(includeVersion) {
|
|
631
|
-
var _this$api$call$dryRun;
|
|
632
|
-
return _regenerator().w(function (_context9) {
|
|
633
|
-
while (1) switch (_context9.n) {
|
|
634
|
-
case 0:
|
|
635
|
-
return _context9.a(2, (_this$api$call$dryRun = _this.api.call.dryRunApi).dryRunCall.apply(_this$api$call$dryRun, [basePayload, resolvedTx].concat(_toConsumableArray(includeVersion ? [DEFAULT_XCM_VERSION] : []))));
|
|
636
|
-
}
|
|
637
|
-
}, _callee9);
|
|
638
|
-
}));
|
|
639
|
-
return function performDryRunCall(_x16) {
|
|
640
|
-
return _ref2.apply(this, arguments);
|
|
641
|
-
};
|
|
642
|
-
}();
|
|
643
|
-
getExecutionSuccessFromResult = function getExecutionSuccessFromResult(resultHuman) {
|
|
644
|
-
var _resultHuman$Ok$execu;
|
|
645
|
-
return Boolean((resultHuman === null || resultHuman === void 0 ? void 0 : resultHuman.Ok) && ((_resultHuman$Ok$execu = resultHuman.Ok.executionResult) === null || _resultHuman$Ok$execu === void 0 ? void 0 : _resultHuman$Ok$execu.Ok));
|
|
646
|
-
};
|
|
647
|
-
extractFailureReasonFromResult = function extractFailureReasonFromResult(resultHuman, resultJson) {
|
|
648
|
-
var _resultHuman$Ok, _resultHuman$Ok2, _resultJson$ok, _ref3;
|
|
649
|
-
var modErrHuman = resultHuman === null || resultHuman === void 0 || (_resultHuman$Ok = resultHuman.Ok) === null || _resultHuman$Ok === void 0 || (_resultHuman$Ok = _resultHuman$Ok.executionResult) === null || _resultHuman$Ok === void 0 || (_resultHuman$Ok = _resultHuman$Ok.Err) === null || _resultHuman$Ok === void 0 || (_resultHuman$Ok = _resultHuman$Ok.error) === null || _resultHuman$Ok === void 0 ? void 0 : _resultHuman$Ok.Module;
|
|
650
|
-
if (modErrHuman) {
|
|
651
|
-
return sdkCore.resolveModuleError(chain, modErrHuman);
|
|
652
|
-
}
|
|
653
|
-
var otherErrHuman = resultHuman === null || resultHuman === void 0 || (_resultHuman$Ok2 = resultHuman.Ok) === null || _resultHuman$Ok2 === void 0 || (_resultHuman$Ok2 = _resultHuman$Ok2.executionResult) === null || _resultHuman$Ok2 === void 0 || (_resultHuman$Ok2 = _resultHuman$Ok2.Err) === null || _resultHuman$Ok2 === void 0 || (_resultHuman$Ok2 = _resultHuman$Ok2.error) === null || _resultHuman$Ok2 === void 0 ? void 0 : _resultHuman$Ok2.Other;
|
|
654
|
-
if (otherErrHuman) {
|
|
655
|
-
return {
|
|
656
|
-
failureReason: String(otherErrHuman)
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
var execErrJson = resultJson === null || resultJson === void 0 || (_resultJson$ok = resultJson.ok) === null || _resultJson$ok === void 0 || (_resultJson$ok = _resultJson$ok.executionResult) === null || _resultJson$ok === void 0 || (_resultJson$ok = _resultJson$ok.err) === null || _resultJson$ok === void 0 ? void 0 : _resultJson$ok.error;
|
|
660
|
-
if (execErrJson !== null && execErrJson !== void 0 && execErrJson.module) {
|
|
661
|
-
return sdkCore.resolveModuleError(chain, execErrJson.module);
|
|
662
|
-
}
|
|
663
|
-
if (execErrJson !== null && execErrJson !== void 0 && execErrJson.other) {
|
|
664
|
-
return {
|
|
665
|
-
failureReason: String(execErrJson.other)
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
return {
|
|
669
|
-
failureReason: JSON.stringify((_ref3 = resultJson !== null && resultJson !== void 0 ? resultJson : resultHuman) !== null && _ref3 !== void 0 ? _ref3 : 'Unknown error')
|
|
670
|
-
};
|
|
671
|
-
}; // Attempt 1: WITHOUT version
|
|
672
|
-
isSuccess = false;
|
|
673
|
-
failureErr = {
|
|
674
|
-
failureReason: ''
|
|
675
|
-
};
|
|
676
|
-
shouldRetryWithVersion = false;
|
|
677
|
-
_context0.p = 5;
|
|
678
|
-
_context0.n = 6;
|
|
679
|
-
return performDryRunCall(false);
|
|
680
|
-
case 6:
|
|
681
|
-
response = _context0.v;
|
|
682
|
-
resultHuman = response.toHuman();
|
|
683
|
-
resultJson = response.toJSON();
|
|
684
|
-
isSuccess = getExecutionSuccessFromResult(resultHuman);
|
|
685
|
-
if (!isSuccess) {
|
|
686
|
-
failureErr = extractFailureReasonFromResult(resultHuman, resultJson);
|
|
687
|
-
if (failureErr.failureReason === 'VersionedConversionFailed') {
|
|
688
|
-
shouldRetryWithVersion = true;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
_context0.n = 9;
|
|
692
|
-
break;
|
|
693
|
-
case 7:
|
|
694
|
-
_context0.p = 7;
|
|
695
|
-
_t2 = _context0.v;
|
|
696
|
-
msg = _t2 instanceof Error ? _t2.message : String(_t2);
|
|
697
|
-
if (!msg.includes('Expected 3 arguments')) {
|
|
698
|
-
_context0.n = 8;
|
|
699
|
-
break;
|
|
700
|
-
}
|
|
701
|
-
shouldRetryWithVersion = true;
|
|
702
|
-
_context0.n = 9;
|
|
703
|
-
break;
|
|
704
|
-
case 8:
|
|
705
|
-
return _context0.a(2, {
|
|
706
|
-
success: false,
|
|
707
|
-
failureReason: msg,
|
|
708
|
-
currency: usedSymbol,
|
|
709
|
-
asset: usedAsset
|
|
710
|
-
});
|
|
711
|
-
case 9:
|
|
712
|
-
if (!shouldRetryWithVersion) {
|
|
713
|
-
_context0.n = 13;
|
|
714
|
-
break;
|
|
715
|
-
}
|
|
716
|
-
_context0.p = 10;
|
|
717
|
-
_context0.n = 11;
|
|
718
|
-
return performDryRunCall(true);
|
|
719
|
-
case 11:
|
|
720
|
-
response = _context0.v;
|
|
721
|
-
resultHuman = response.toHuman();
|
|
722
|
-
resultJson = response.toJSON();
|
|
723
|
-
isSuccess = getExecutionSuccessFromResult(resultHuman);
|
|
724
|
-
if (!isSuccess) {
|
|
725
|
-
failureErr = extractFailureReasonFromResult(resultHuman, resultJson);
|
|
726
|
-
}
|
|
727
|
-
_context0.n = 13;
|
|
728
|
-
break;
|
|
729
|
-
case 12:
|
|
730
|
-
_context0.p = 12;
|
|
731
|
-
_t3 = _context0.v;
|
|
732
|
-
_msg = _t3 instanceof Error ? _t3.message : String(_t3);
|
|
733
|
-
failureErr = failureErr || _msg;
|
|
734
|
-
return _context0.a(2, {
|
|
735
|
-
success: false,
|
|
736
|
-
failureReason: failureErr.failureReason,
|
|
737
|
-
failureSubReason: failureErr.failureSubReason,
|
|
738
|
-
currency: usedSymbol,
|
|
739
|
-
asset: usedAsset
|
|
740
|
-
});
|
|
741
|
-
case 13:
|
|
742
|
-
if (isSuccess) {
|
|
743
|
-
_context0.n = 14;
|
|
744
|
-
break;
|
|
745
|
-
}
|
|
746
|
-
return _context0.a(2, {
|
|
747
|
-
success: false,
|
|
748
|
-
failureReason: failureErr.failureReason || 'Unknown error',
|
|
749
|
-
failureSubReason: failureErr.failureSubReason,
|
|
750
|
-
currency: usedSymbol,
|
|
751
|
-
asset: usedAsset
|
|
752
|
-
});
|
|
753
|
-
case 14:
|
|
754
|
-
forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
|
|
755
|
-
actualWeight = resultJson.ok.executionResult.ok.actualWeight;
|
|
756
|
-
weight = actualWeight ? {
|
|
757
|
-
refTime: BigInt(actualWeight.refTime),
|
|
758
|
-
proofSize: BigInt(actualWeight.proofSize)
|
|
759
|
-
} : undefined;
|
|
760
|
-
nativeAsset = sdkCore.findNativeAssetInfoOrThrow(chain);
|
|
761
|
-
hasLocation = feeAsset ? Boolean(feeAsset.location) : Boolean(nativeAsset === null || nativeAsset === void 0 ? void 0 : nativeAsset.location);
|
|
762
|
-
destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref4) {
|
|
763
|
-
return i.here === null ? 0 : (_ref4 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref4 === void 0 ? void 0 : _ref4.parachain;
|
|
764
|
-
}(Object.values(forwardedXcms[0])[0].interior);
|
|
765
|
-
if (!(sdkCore.hasXcmPaymentApiSupport(chain) && resultJson.ok.local_xcm && hasLocation && (feeAsset || chain.startsWith('AssetHub') && destination === 'Ethereum'))) {
|
|
766
|
-
_context0.n = 16;
|
|
767
|
-
break;
|
|
768
|
-
}
|
|
769
|
-
_context0.n = 15;
|
|
770
|
-
return this.getXcmPaymentApiFee(chain, resultJson.ok.local_xcm, forwardedXcms, feeAsset !== null && feeAsset !== void 0 ? feeAsset : nativeAsset);
|
|
771
|
-
case 15:
|
|
772
|
-
xcmFee = _context0.v;
|
|
773
|
-
if (!(typeof xcmFee === 'bigint')) {
|
|
774
|
-
_context0.n = 16;
|
|
775
|
-
break;
|
|
776
|
-
}
|
|
777
|
-
return _context0.a(2, Promise.resolve({
|
|
778
|
-
success: true,
|
|
779
|
-
fee: xcmFee,
|
|
780
|
-
currency: usedSymbol,
|
|
781
|
-
asset: usedAsset,
|
|
782
|
-
weight: weight,
|
|
783
|
-
forwardedXcms: forwardedXcms,
|
|
784
|
-
destParaId: destParaId
|
|
785
|
-
}));
|
|
786
|
-
case 16:
|
|
787
|
-
_context0.n = 17;
|
|
788
|
-
return this.calculateTransactionFee(tx, address);
|
|
789
|
-
case 17:
|
|
790
|
-
executionFee = _context0.v;
|
|
791
|
-
fee = sdkCore.computeFeeFromDryRunPjs(resultHuman, chain, executionFee);
|
|
792
|
-
return _context0.a(2, {
|
|
793
|
-
success: true,
|
|
794
|
-
fee: fee,
|
|
795
|
-
currency: usedSymbol,
|
|
796
|
-
asset: usedAsset,
|
|
797
|
-
weight: weight,
|
|
798
|
-
forwardedXcms: forwardedXcms,
|
|
799
|
-
destParaId: destParaId
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
}, _callee0, this, [[10, 12], [5, 7]]);
|
|
803
|
-
}));
|
|
804
|
-
function getDryRunCall(_x15) {
|
|
805
|
-
return _getDryRunCall.apply(this, arguments);
|
|
806
|
-
}
|
|
807
|
-
return getDryRunCall;
|
|
808
|
-
}()
|
|
809
|
-
}, {
|
|
810
|
-
key: "getXcmPaymentApiFee",
|
|
811
|
-
value: function () {
|
|
812
|
-
var _getXcmPaymentApiFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(chain, localXcm, forwardedXcm, asset) {
|
|
813
|
-
var _ref5, _deliveryFeeResJson$o, _deliveryFeeResJson$o2, _deliveryFeeResJson$o3, _ref6, _deliveryFeeResJson$o4, _deliveryFeeResJson$o5, _deliveryFeeResJson$o6;
|
|
814
|
-
var weight, assetLocalizedLoc, feeResult, execFeeRes, execFee, deliveryFeeRes, deliveryFeeResJson, deliveryFeeResolved, nativeAsset, deliveryFee, res, _t4;
|
|
815
|
-
return _regenerator().w(function (_context1) {
|
|
816
|
-
while (1) switch (_context1.p = _context1.n) {
|
|
817
|
-
case 0:
|
|
818
|
-
_context1.n = 1;
|
|
819
|
-
return this.getXcmWeight(localXcm);
|
|
820
|
-
case 1:
|
|
821
|
-
weight = _context1.v;
|
|
822
|
-
sdkCore.assertHasLocation(asset);
|
|
823
|
-
assetLocalizedLoc = sdkCore.localizeLocation(chain, asset.location);
|
|
824
|
-
_context1.n = 2;
|
|
825
|
-
return this.api.call.xcmPaymentApi.queryWeightToAssetFee(weight, sdkCore.addXcmVersionHeader(assetLocalizedLoc, sdkCore.Version.V4));
|
|
826
|
-
case 2:
|
|
827
|
-
feeResult = _context1.v;
|
|
828
|
-
execFeeRes = feeResult.toJSON();
|
|
829
|
-
execFee = BigInt(execFeeRes.ok);
|
|
830
|
-
if (!(forwardedXcm.length > 0)) {
|
|
831
|
-
_context1.n = 4;
|
|
832
|
-
break;
|
|
833
|
-
}
|
|
834
|
-
_context1.n = 3;
|
|
835
|
-
return this.api.call.xcmPaymentApi.queryDeliveryFees(forwardedXcm[0], forwardedXcm[1][0]);
|
|
836
|
-
case 3:
|
|
837
|
-
_t4 = _context1.v;
|
|
838
|
-
_context1.n = 5;
|
|
839
|
-
break;
|
|
840
|
-
case 4:
|
|
841
|
-
_t4 = undefined;
|
|
842
|
-
case 5:
|
|
843
|
-
deliveryFeeRes = _t4;
|
|
844
|
-
deliveryFeeResJson = deliveryFeeRes === null || deliveryFeeRes === void 0 ? void 0 : deliveryFeeRes.toJSON();
|
|
845
|
-
deliveryFeeResolved = deliveryFeeRes && ((_ref5 = (_deliveryFeeResJson$o = (_deliveryFeeResJson$o2 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o2 === void 0 ? void 0 : _deliveryFeeResJson$o2.v4) !== null && _deliveryFeeResJson$o !== void 0 ? _deliveryFeeResJson$o : (_deliveryFeeResJson$o3 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o3 === void 0 ? void 0 : _deliveryFeeResJson$o3.v3) === null || _ref5 === void 0 ? void 0 : _ref5.length) > 0 ? BigInt((_ref6 = (_deliveryFeeResJson$o4 = deliveryFeeResJson === null || deliveryFeeResJson === void 0 || (_deliveryFeeResJson$o5 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o5 === void 0 ? void 0 : _deliveryFeeResJson$o5.v4) !== null && _deliveryFeeResJson$o4 !== void 0 ? _deliveryFeeResJson$o4 : deliveryFeeResJson === null || deliveryFeeResJson === void 0 || (_deliveryFeeResJson$o6 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o6 === void 0 ? void 0 : _deliveryFeeResJson$o6.v3) === null || _ref6 === void 0 || (_ref6 = _ref6[0]) === null || _ref6 === void 0 || (_ref6 = _ref6.fun) === null || _ref6 === void 0 ? void 0 : _ref6.fungible) : 0n;
|
|
846
|
-
nativeAsset = sdkCore.findNativeAssetInfoOrThrow(chain);
|
|
847
|
-
if (!sdkCore.isAssetXcEqual(asset, nativeAsset)) {
|
|
848
|
-
_context1.n = 6;
|
|
849
|
-
break;
|
|
850
|
-
}
|
|
851
|
-
deliveryFee = deliveryFeeResolved;
|
|
852
|
-
_context1.n = 9;
|
|
853
|
-
break;
|
|
854
|
-
case 6:
|
|
855
|
-
_context1.p = 6;
|
|
856
|
-
sdkCore.assertHasLocation(nativeAsset);
|
|
857
|
-
_context1.n = 7;
|
|
858
|
-
return this.quoteAhPrice(sdkCore.localizeLocation(chain, nativeAsset.location), assetLocalizedLoc, deliveryFeeResolved, false);
|
|
859
|
-
case 7:
|
|
860
|
-
res = _context1.v;
|
|
861
|
-
deliveryFee = res !== null && res !== void 0 ? res : 0n;
|
|
862
|
-
_context1.n = 9;
|
|
863
|
-
break;
|
|
864
|
-
case 8:
|
|
865
|
-
_context1.p = 8;
|
|
866
|
-
_context1.v;
|
|
867
|
-
deliveryFee = 0n;
|
|
868
|
-
case 9:
|
|
869
|
-
return _context1.a(2, execFee + deliveryFee);
|
|
870
|
-
}
|
|
871
|
-
}, _callee1, this, [[6, 8]]);
|
|
872
|
-
}));
|
|
873
|
-
function getXcmPaymentApiFee(_x17, _x18, _x19, _x20) {
|
|
874
|
-
return _getXcmPaymentApiFee.apply(this, arguments);
|
|
875
|
-
}
|
|
876
|
-
return getXcmPaymentApiFee;
|
|
877
|
-
}()
|
|
878
|
-
}, {
|
|
879
|
-
key: "getXcmWeight",
|
|
880
|
-
value: function () {
|
|
881
|
-
var _getXcmWeight = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(xcm) {
|
|
882
|
-
var result, resultJson;
|
|
883
|
-
return _regenerator().w(function (_context10) {
|
|
884
|
-
while (1) switch (_context10.n) {
|
|
885
|
-
case 0:
|
|
886
|
-
_context10.n = 1;
|
|
887
|
-
return this.api.call.xcmPaymentApi.queryXcmWeight(xcm);
|
|
888
|
-
case 1:
|
|
889
|
-
result = _context10.v;
|
|
890
|
-
resultJson = result.toJSON();
|
|
891
|
-
return _context10.a(2, resultJson.ok);
|
|
892
|
-
}
|
|
893
|
-
}, _callee10, this);
|
|
894
|
-
}));
|
|
895
|
-
function getXcmWeight(_x21) {
|
|
896
|
-
return _getXcmWeight.apply(this, arguments);
|
|
897
|
-
}
|
|
898
|
-
return getXcmWeight;
|
|
899
|
-
}()
|
|
900
|
-
}, {
|
|
901
|
-
key: "getDryRunXcm",
|
|
902
|
-
value: function () {
|
|
903
|
-
var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(_ref7) {
|
|
904
|
-
var _ref9, _ref0, _ref1;
|
|
905
|
-
var originLocation, xcm, asset, chain, origin, supportsDryRunApi, response, result, resultJson, symbol, isSuccess, error, failureReason, forwardedXcms, actualWeight, weight, destParaId, _fee, emitted, reversedEvents, palletsWithIssued, feeEvent, feeAmount, fee;
|
|
906
|
-
return _regenerator().w(function (_context11) {
|
|
907
|
-
while (1) switch (_context11.n) {
|
|
908
|
-
case 0:
|
|
909
|
-
originLocation = _ref7.originLocation, xcm = _ref7.xcm, asset = _ref7.asset, chain = _ref7.chain, origin = _ref7.origin;
|
|
910
|
-
supportsDryRunApi = sdkCore.getAssetsObject(chain).supportsDryRunApi;
|
|
911
|
-
if (supportsDryRunApi) {
|
|
912
|
-
_context11.n = 1;
|
|
913
|
-
break;
|
|
914
|
-
}
|
|
915
|
-
throw new sdkCore.ChainNotSupportedError("DryRunApi is not available on chain ".concat(chain));
|
|
916
|
-
case 1:
|
|
917
|
-
_context11.n = 2;
|
|
918
|
-
return this.api.call.dryRunApi.dryRunXcm(originLocation, xcm);
|
|
919
|
-
case 2:
|
|
920
|
-
response = _context11.v;
|
|
921
|
-
result = response.toHuman();
|
|
922
|
-
resultJson = response.toJSON();
|
|
923
|
-
symbol = asset.symbol;
|
|
924
|
-
isSuccess = result.Ok && result.Ok.executionResult.Complete;
|
|
925
|
-
if (isSuccess) {
|
|
926
|
-
_context11.n = 3;
|
|
927
|
-
break;
|
|
928
|
-
}
|
|
929
|
-
error = result.Ok.executionResult.Incomplete.error;
|
|
930
|
-
failureReason = typeof error === 'string' ? error : error.error;
|
|
931
|
-
return _context11.a(2, {
|
|
932
|
-
success: false,
|
|
933
|
-
failureReason: failureReason,
|
|
934
|
-
currency: symbol,
|
|
935
|
-
asset: asset
|
|
936
|
-
});
|
|
937
|
-
case 3:
|
|
938
|
-
forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
|
|
939
|
-
actualWeight = resultJson.ok.executionResult.used;
|
|
940
|
-
weight = actualWeight ? {
|
|
941
|
-
refTime: BigInt(actualWeight.refTime),
|
|
942
|
-
proofSize: BigInt(actualWeight.proofSize)
|
|
943
|
-
} : undefined;
|
|
944
|
-
destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref8) {
|
|
945
|
-
return i.Here ? 0 : (_ref8 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref8 === void 0 ? void 0 : _ref8.parachain;
|
|
946
|
-
}(Object.values(forwardedXcms[0])[0].interior);
|
|
947
|
-
if (!(sdkCore.hasXcmPaymentApiSupport(chain) && asset)) {
|
|
948
|
-
_context11.n = 5;
|
|
949
|
-
break;
|
|
950
|
-
}
|
|
951
|
-
_context11.n = 4;
|
|
952
|
-
return this.getXcmPaymentApiFee(chain, xcm, forwardedXcms, asset);
|
|
953
|
-
case 4:
|
|
954
|
-
_fee = _context11.v;
|
|
955
|
-
if (!(typeof _fee === 'bigint')) {
|
|
956
|
-
_context11.n = 5;
|
|
957
|
-
break;
|
|
958
|
-
}
|
|
959
|
-
return _context11.a(2, {
|
|
960
|
-
success: true,
|
|
961
|
-
fee: _fee,
|
|
962
|
-
currency: symbol,
|
|
963
|
-
asset: asset,
|
|
964
|
-
weight: weight,
|
|
965
|
-
forwardedXcms: forwardedXcms,
|
|
966
|
-
destParaId: destParaId
|
|
967
|
-
});
|
|
968
|
-
case 5:
|
|
969
|
-
emitted = result.Ok.emittedEvents; // We want to look for the last event
|
|
970
|
-
reversedEvents = _toConsumableArray(emitted).reverse();
|
|
971
|
-
palletsWithIssued = ['balances', 'foreignAssets', 'assets'];
|
|
972
|
-
feeEvent = (_ref9 = (_ref0 = (_ref1 = origin === 'Mythos' ? reversedEvents.find(function (event) {
|
|
973
|
-
return event.section === 'assetConversion' && event.method === 'SwapCreditExecuted';
|
|
974
|
-
}) : undefined) !== null && _ref1 !== void 0 ? _ref1 :
|
|
975
|
-
// Prefer an Issued event
|
|
976
|
-
reversedEvents.find(function (event) {
|
|
977
|
-
return palletsWithIssued.includes(event.section) && event.method === 'Issued';
|
|
978
|
-
})) !== null && _ref0 !== void 0 ? _ref0 :
|
|
979
|
-
// Fallback to Minted event
|
|
980
|
-
reversedEvents.find(function (event) {
|
|
981
|
-
return ['balances', 'foreignAssets'].includes(event.section) && event.method === 'Minted';
|
|
982
|
-
})) !== null && _ref9 !== void 0 ? _ref9 : reversedEvents.find(function (event) {
|
|
983
|
-
return ['currencies', 'tokens'].includes(event.section) && event.method === 'Deposited';
|
|
984
|
-
});
|
|
985
|
-
if (feeEvent) {
|
|
986
|
-
_context11.n = 6;
|
|
987
|
-
break;
|
|
988
|
-
}
|
|
989
|
-
return _context11.a(2, Promise.resolve({
|
|
990
|
-
success: false,
|
|
991
|
-
failureReason: 'Cannot determine destination fee. No Issued event found',
|
|
992
|
-
currency: symbol,
|
|
993
|
-
asset: asset
|
|
994
|
-
}));
|
|
995
|
-
case 6:
|
|
996
|
-
feeAmount = feeEvent.section === 'assetConversion' ? feeEvent.data.amountIn : feeEvent.data.amount;
|
|
997
|
-
fee = BigInt(feeAmount.replace(/,/g, ''));
|
|
998
|
-
return _context11.a(2, {
|
|
999
|
-
success: true,
|
|
1000
|
-
fee: fee,
|
|
1001
|
-
currency: symbol,
|
|
1002
|
-
asset: asset,
|
|
1003
|
-
weight: weight,
|
|
1004
|
-
forwardedXcms: forwardedXcms,
|
|
1005
|
-
destParaId: destParaId
|
|
1006
|
-
});
|
|
1007
|
-
}
|
|
1008
|
-
}, _callee11, this);
|
|
1009
|
-
}));
|
|
1010
|
-
function getDryRunXcm(_x22) {
|
|
1011
|
-
return _getDryRunXcm.apply(this, arguments);
|
|
1012
|
-
}
|
|
1013
|
-
return getDryRunXcm;
|
|
1014
|
-
}()
|
|
1015
|
-
}, {
|
|
1016
|
-
key: "getBridgeStatus",
|
|
1017
|
-
value: function () {
|
|
1018
|
-
var _getBridgeStatus = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
|
|
1019
|
-
var outboundOperatingMode;
|
|
1020
|
-
return _regenerator().w(function (_context12) {
|
|
1021
|
-
while (1) switch (_context12.n) {
|
|
1022
|
-
case 0:
|
|
1023
|
-
_context12.n = 1;
|
|
1024
|
-
return this.api.query.ethereumOutboundQueue.operatingMode();
|
|
1025
|
-
case 1:
|
|
1026
|
-
outboundOperatingMode = _context12.v;
|
|
1027
|
-
return _context12.a(2, outboundOperatingMode.toPrimitive());
|
|
1028
|
-
}
|
|
1029
|
-
}, _callee12, this);
|
|
1030
|
-
}));
|
|
1031
|
-
function getBridgeStatus() {
|
|
1032
|
-
return _getBridgeStatus.apply(this, arguments);
|
|
1033
|
-
}
|
|
1034
|
-
return getBridgeStatus;
|
|
1035
|
-
}()
|
|
1036
|
-
}, {
|
|
1037
|
-
key: "setDisconnectAllowed",
|
|
1038
|
-
value: function setDisconnectAllowed(allowed) {
|
|
1039
|
-
this.disconnectAllowed = allowed;
|
|
1040
|
-
}
|
|
1041
|
-
}, {
|
|
1042
|
-
key: "getDisconnectAllowed",
|
|
1043
|
-
value: function getDisconnectAllowed() {
|
|
1044
|
-
return this.disconnectAllowed;
|
|
1045
|
-
}
|
|
1046
|
-
}, {
|
|
1047
|
-
key: "disconnect",
|
|
1048
|
-
value: function () {
|
|
1049
|
-
var _disconnect = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
|
|
1050
|
-
var _this$_config$apiOver2;
|
|
1051
|
-
var force,
|
|
1052
|
-
api,
|
|
1053
|
-
_args13 = arguments;
|
|
1054
|
-
return _regenerator().w(function (_context13) {
|
|
1055
|
-
while (1) switch (_context13.n) {
|
|
1056
|
-
case 0:
|
|
1057
|
-
force = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : false;
|
|
1058
|
-
if (this.initialized) {
|
|
1059
|
-
_context13.n = 1;
|
|
1060
|
-
break;
|
|
1061
|
-
}
|
|
1062
|
-
return _context13.a(2, Promise.resolve());
|
|
1063
|
-
case 1:
|
|
1064
|
-
if (!(!force && !this.disconnectAllowed)) {
|
|
1065
|
-
_context13.n = 2;
|
|
1066
|
-
break;
|
|
1067
|
-
}
|
|
1068
|
-
return _context13.a(2);
|
|
1069
|
-
case 2:
|
|
1070
|
-
api = sdkCore.isConfig(this._config) ? (_this$_config$apiOver2 = this._config.apiOverrides) === null || _this$_config$apiOver2 === void 0 ? void 0 : _this$_config$apiOver2[this._chain] : this._config; // Disconnect api only if it was created automatically
|
|
1071
|
-
if (!(force || typeof api === 'string' || api === undefined)) {
|
|
1072
|
-
_context13.n = 3;
|
|
1073
|
-
break;
|
|
1074
|
-
}
|
|
1075
|
-
_context13.n = 3;
|
|
1076
|
-
return this.api.disconnect();
|
|
1077
|
-
case 3:
|
|
1078
|
-
return _context13.a(2);
|
|
1079
|
-
}
|
|
1080
|
-
}, _callee13, this);
|
|
1081
|
-
}));
|
|
1082
|
-
function disconnect() {
|
|
1083
|
-
return _disconnect.apply(this, arguments);
|
|
1084
|
-
}
|
|
1085
|
-
return disconnect;
|
|
1086
|
-
}()
|
|
1087
|
-
}, {
|
|
1088
|
-
key: "validateSubstrateAddress",
|
|
1089
|
-
value: function validateSubstrateAddress(address) {
|
|
1090
|
-
try {
|
|
1091
|
-
utilCrypto.validateAddress(address);
|
|
1092
|
-
return true;
|
|
1093
|
-
} catch (_unused) {
|
|
1094
|
-
return false;
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
}]);
|
|
1098
|
-
}();
|
|
1099
|
-
|
|
1100
|
-
var createChainClient = function createChainClient(chain, builderOptions) {
|
|
1101
|
-
var pjsApi = new PolkadotJsApi(builderOptions);
|
|
1102
|
-
return sdkCore.createChainClient(pjsApi, chain);
|
|
1103
|
-
};
|
|
1104
|
-
var createPolkadotJsApiCall = function createPolkadotJsApiCall(apiCall) {
|
|
1105
|
-
return /*#__PURE__*/function () {
|
|
1106
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
1107
|
-
var pjsApi, optionsWithApi;
|
|
1108
|
-
return _regenerator().w(function (_context) {
|
|
1109
|
-
while (1) switch (_context.n) {
|
|
1110
|
-
case 0:
|
|
1111
|
-
pjsApi = new PolkadotJsApi(options.api);
|
|
1112
|
-
optionsWithApi = _objectSpread2(_objectSpread2({}, options), {}, {
|
|
1113
|
-
api: pjsApi
|
|
1114
|
-
});
|
|
1115
|
-
return _context.a(2, apiCall(optionsWithApi));
|
|
1116
|
-
}
|
|
1117
|
-
}, _callee);
|
|
1118
|
-
}));
|
|
1119
|
-
return function (_x) {
|
|
1120
|
-
return _ref.apply(this, arguments);
|
|
1121
|
-
};
|
|
1122
|
-
}();
|
|
1123
|
-
};
|
|
1124
|
-
var isEthersSigner = function isEthersSigner(signer) {
|
|
1125
|
-
return _typeof(signer) === 'object' && signer !== null && 'provider' in signer;
|
|
1126
|
-
};
|
|
1127
|
-
|
|
1128
|
-
/**
|
|
1129
|
-
* Retrieves the native balance for a given account on a specified chain.
|
|
1130
|
-
*
|
|
1131
|
-
* @returns The native balance as a bigint.
|
|
1132
|
-
*/
|
|
1133
|
-
var getBalanceNative = createPolkadotJsApiCall(sdkCore.getBalanceNative);
|
|
1134
|
-
/**
|
|
1135
|
-
* Retrieves the balance of a foreign asset for a given account on a specified chain.
|
|
1136
|
-
*
|
|
1137
|
-
* @returns The balance of the foreign asset as a bigint, or null if not found.
|
|
1138
|
-
*/
|
|
1139
|
-
var getBalanceForeign = createPolkadotJsApiCall(sdkCore.getBalance);
|
|
1140
|
-
/**
|
|
1141
|
-
* Retrieves the asset balance for a given account on a specified chain.
|
|
1142
|
-
*
|
|
1143
|
-
* @returns The asset balance as a bigint.
|
|
1144
|
-
*/
|
|
1145
|
-
var getAssetBalance = createPolkadotJsApiCall(sdkCore.getBalance);
|
|
1146
|
-
/**
|
|
1147
|
-
* Claims assets from a parachain.
|
|
1148
|
-
*
|
|
1149
|
-
* @returns An extrinsic representing the claim transaction.
|
|
1150
|
-
*/
|
|
1151
|
-
var claimAssets = createPolkadotJsApiCall(sdkCore.claimAssets);
|
|
1152
|
-
/**
|
|
1153
|
-
* @deprecated This function is deprecated and will be removed in a future version.
|
|
1154
|
-
* Please use `builder.getOriginXcmFee()` or `builder.getOriginXcmFeeEstimate()` instead,
|
|
1155
|
-
* where `builder` is an instance of `Builder()`. Will be removed in v12
|
|
1156
|
-
* For more details, please refer to the documentation:
|
|
1157
|
-
* {@link https://paraspell.github.io/docs/sdk/xcmPallet.html#xcm-fee-origin-and-dest}
|
|
1158
|
-
*/
|
|
1159
|
-
var getOriginFeeDetails = createPolkadotJsApiCall(sdkCore.getOriginFeeDetails);
|
|
1160
|
-
|
|
1161
|
-
var assets = /*#__PURE__*/Object.freeze({
|
|
1162
|
-
__proto__: null,
|
|
1163
|
-
Foreign: sdkCore.Foreign,
|
|
1164
|
-
ForeignAbstract: sdkCore.ForeignAbstract,
|
|
1165
|
-
Native: sdkCore.Native,
|
|
1166
|
-
Override: sdkCore.Override,
|
|
1167
|
-
claimAssets: claimAssets,
|
|
1168
|
-
findAssetInfo: sdkCore.findAssetInfo,
|
|
1169
|
-
getAllAssetsSymbols: sdkCore.getAllAssetsSymbols,
|
|
1170
|
-
getAssetBalance: getAssetBalance,
|
|
1171
|
-
getAssetDecimals: sdkCore.getAssetDecimals,
|
|
1172
|
-
getAssetId: sdkCore.getAssetId,
|
|
1173
|
-
getAssets: sdkCore.getAssets,
|
|
1174
|
-
getAssetsObject: sdkCore.getAssetsObject,
|
|
1175
|
-
getBalanceForeign: getBalanceForeign,
|
|
1176
|
-
getBalanceNative: getBalanceNative,
|
|
1177
|
-
getExistentialDeposit: sdkCore.getExistentialDeposit,
|
|
1178
|
-
getNativeAssetSymbol: sdkCore.getNativeAssetSymbol,
|
|
1179
|
-
getNativeAssets: sdkCore.getNativeAssets,
|
|
1180
|
-
getOriginFeeDetails: getOriginFeeDetails,
|
|
1181
|
-
getOtherAssets: sdkCore.getOtherAssets,
|
|
1182
|
-
getRelayChainSymbol: sdkCore.getRelayChainSymbol,
|
|
1183
|
-
getSupportedAssets: sdkCore.getSupportedAssets,
|
|
1184
|
-
getTChain: sdkCore.getTChain,
|
|
1185
|
-
hasSupportForAsset: sdkCore.hasSupportForAsset,
|
|
1186
|
-
isChainEvm: sdkCore.isChainEvm
|
|
1187
|
-
});
|
|
1188
|
-
|
|
1189
|
-
var convertSs58 = function convertSs58(address, chain) {
|
|
1190
|
-
var papiApi = new PolkadotJsApi();
|
|
1191
|
-
return sdkCore.convertSs58(papiApi, address, chain);
|
|
1192
|
-
};
|
|
1193
|
-
|
|
1194
|
-
var approveToken = /*#__PURE__*/function () {
|
|
1195
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(signer, amount, symbol) {
|
|
1196
|
-
var env, contract, weth9, result, receipt;
|
|
1197
|
-
return _regenerator().w(function (_context) {
|
|
1198
|
-
while (1) switch (_context.n) {
|
|
1199
|
-
case 0:
|
|
1200
|
-
env = api$1.environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
|
|
1201
|
-
contract = env.locations[0].erc20tokensReceivable.find(function (t) {
|
|
1202
|
-
return t.id === symbol;
|
|
1203
|
-
});
|
|
1204
|
-
if (contract) {
|
|
1205
|
-
_context.n = 1;
|
|
1206
|
-
break;
|
|
1207
|
-
}
|
|
1208
|
-
throw new sdkCore.InvalidParameterError("Token ".concat(symbol, " not supported"));
|
|
1209
|
-
case 1:
|
|
1210
|
-
weth9 = contractTypes.WETH9__factory.connect(contract.address, signer);
|
|
1211
|
-
_context.n = 2;
|
|
1212
|
-
return weth9.approve(env.config.GATEWAY_CONTRACT, amount);
|
|
1213
|
-
case 2:
|
|
1214
|
-
result = _context.v;
|
|
1215
|
-
_context.n = 3;
|
|
1216
|
-
return result.wait();
|
|
1217
|
-
case 3:
|
|
1218
|
-
receipt = _context.v;
|
|
1219
|
-
return _context.a(2, {
|
|
1220
|
-
result: result,
|
|
1221
|
-
receipt: receipt
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1224
|
-
}, _callee);
|
|
1225
|
-
}));
|
|
1226
|
-
return function approveToken(_x, _x2, _x3) {
|
|
1227
|
-
return _ref.apply(this, arguments);
|
|
1228
|
-
};
|
|
1229
|
-
}();
|
|
1230
|
-
|
|
1231
|
-
var depositToken = /*#__PURE__*/function () {
|
|
1232
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(signer, amount, symbol) {
|
|
1233
|
-
var env, contract, weth9, result, receipt;
|
|
1234
|
-
return _regenerator().w(function (_context) {
|
|
1235
|
-
while (1) switch (_context.n) {
|
|
1236
|
-
case 0:
|
|
1237
|
-
env = api$1.environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
|
|
1238
|
-
contract = env.locations[0].erc20tokensReceivable.find(function (t) {
|
|
1239
|
-
return t.id === symbol;
|
|
1240
|
-
});
|
|
1241
|
-
if (contract) {
|
|
1242
|
-
_context.n = 1;
|
|
1243
|
-
break;
|
|
1244
|
-
}
|
|
1245
|
-
throw new sdkCore.InvalidParameterError("Token ".concat(symbol, " not supported"));
|
|
1246
|
-
case 1:
|
|
1247
|
-
weth9 = contractTypes.WETH9__factory.connect(contract.address, signer);
|
|
1248
|
-
_context.n = 2;
|
|
1249
|
-
return weth9.deposit({
|
|
1250
|
-
value: amount
|
|
1251
|
-
});
|
|
1252
|
-
case 2:
|
|
1253
|
-
result = _context.v;
|
|
1254
|
-
_context.n = 3;
|
|
1255
|
-
return result.wait();
|
|
1256
|
-
case 3:
|
|
1257
|
-
receipt = _context.v;
|
|
1258
|
-
return _context.a(2, {
|
|
1259
|
-
result: result,
|
|
1260
|
-
receipt: receipt
|
|
1261
|
-
});
|
|
1262
|
-
}
|
|
1263
|
-
}, _callee);
|
|
1264
|
-
}));
|
|
1265
|
-
return function depositToken(_x, _x2, _x3) {
|
|
1266
|
-
return _ref.apply(this, arguments);
|
|
1267
|
-
};
|
|
1268
|
-
}();
|
|
1269
|
-
|
|
1270
|
-
var createContext = function createContext(executionUrl, env) {
|
|
1271
|
-
var config = env.config;
|
|
1272
|
-
return new api$1.Context({
|
|
1273
|
-
environment: env.name,
|
|
1274
|
-
graphqlApiUrl: config.GRAPHQL_API_URL,
|
|
1275
|
-
ethereum: {
|
|
1276
|
-
ethChainId: env.ethChainId,
|
|
1277
|
-
ethChains: _defineProperty(_defineProperty({}, sdkCore.ETH_CHAIN_ID.toString(), executionUrl), sdkCore.getParaId('Moonbeam'), 'https://rpc.api.moonbeam.network'),
|
|
1278
|
-
beacon_url: config.BEACON_HTTP_API
|
|
1279
|
-
},
|
|
1280
|
-
polkadot: {
|
|
1281
|
-
assetHubParaId: config.ASSET_HUB_PARAID,
|
|
1282
|
-
bridgeHubParaId: config.BRIDGE_HUB_PARAID,
|
|
1283
|
-
parachains: config.PARACHAINS,
|
|
1284
|
-
relaychain: config.RELAY_CHAIN_URL
|
|
1285
|
-
},
|
|
1286
|
-
appContracts: {
|
|
1287
|
-
gateway: config.GATEWAY_CONTRACT,
|
|
1288
|
-
beefy: config.BEEFY_CONTRACT
|
|
1289
|
-
}
|
|
1290
|
-
});
|
|
1291
|
-
};
|
|
1292
|
-
|
|
1293
|
-
/**
|
|
1294
|
-
* Transfers an Ethereum asset to a Polkadot account.
|
|
1295
|
-
*
|
|
1296
|
-
* @param provider - The Ethereum provider instance to interact with the Ethereum network.
|
|
1297
|
-
* @param options - The options for the transfer.
|
|
1298
|
-
*
|
|
1299
|
-
* @returns A Promise that resolves to an object containing the result and the plan of the transfer.
|
|
1300
|
-
*
|
|
1301
|
-
* @throws Will throw an error if the transfer validation fails or if the transfer cannot be completed.
|
|
1302
|
-
*/
|
|
1303
|
-
var transferEthToPolkadot$1 = /*#__PURE__*/function () {
|
|
1304
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
1305
|
-
var api, provider, signer, address, to, currency, ethAsset, amount, env, context, destParaId, overrides, registry, fee, sourceAddress, transfer, validation, tx, response, receipt, messageReceipt, _t, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t0, _t1, _t10, _t11, _t12, _t13;
|
|
1306
|
-
return _regenerator().w(function (_context) {
|
|
1307
|
-
while (1) switch (_context.n) {
|
|
1308
|
-
case 0:
|
|
1309
|
-
api = _ref.api, provider = _ref.provider, signer = _ref.signer, address = _ref.address, to = _ref.to, currency = _ref.currency;
|
|
1310
|
-
if (!Array.isArray(currency)) {
|
|
1311
|
-
_context.n = 1;
|
|
1312
|
-
break;
|
|
1313
|
-
}
|
|
1314
|
-
throw new sdkCore.InvalidParameterError('Multi-assets are not yet supported for EVM transfers');
|
|
1315
|
-
case 1:
|
|
1316
|
-
if (!('location' in currency && sdkCore.isOverrideLocationSpecifier(currency.location))) {
|
|
1317
|
-
_context.n = 2;
|
|
1318
|
-
break;
|
|
1319
|
-
}
|
|
1320
|
-
throw new sdkCore.InvalidParameterError('Override location is not supported for EVM transfers');
|
|
1321
|
-
case 2:
|
|
1322
|
-
if (provider) {
|
|
1323
|
-
_context.n = 3;
|
|
1324
|
-
break;
|
|
1325
|
-
}
|
|
1326
|
-
throw new sdkCore.InvalidParameterError('provider parameter is required for Snowbridge transfers.');
|
|
1327
|
-
case 3:
|
|
1328
|
-
if (isEthersSigner(signer)) {
|
|
1329
|
-
_context.n = 4;
|
|
1330
|
-
break;
|
|
1331
|
-
}
|
|
1332
|
-
throw new sdkCore.InvalidParameterError('Snowbridge does not support Viem provider yet.');
|
|
1333
|
-
case 4:
|
|
1334
|
-
ethAsset = sdkCore.findAssetInfoOrThrow('Ethereum', currency, to);
|
|
1335
|
-
amount = sdkCore.abstractDecimals(currency.amount, ethAsset.decimals, api);
|
|
1336
|
-
env = api$1.environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
|
|
1337
|
-
context = createContext(provider, env);
|
|
1338
|
-
destParaId = sdkCore.getParaId(to);
|
|
1339
|
-
sdkCore.assertHasId(ethAsset);
|
|
1340
|
-
overrides = {
|
|
1341
|
-
precompiles: {
|
|
1342
|
-
'2004': '0x000000000000000000000000000000000000081A'
|
|
1343
|
-
},
|
|
1344
|
-
assetOverrides: {
|
|
1345
|
-
'3369': [{
|
|
1346
|
-
token: '0xba41ddf06b7ffd89d1267b5a93bfef2424eb2003',
|
|
1347
|
-
name: 'Mythos',
|
|
1348
|
-
minimumBalance: 10000000000000000n,
|
|
1349
|
-
symbol: 'MYTH',
|
|
1350
|
-
decimals: 18,
|
|
1351
|
-
isSufficient: true
|
|
1352
|
-
}]
|
|
1353
|
-
}
|
|
1354
|
-
};
|
|
1355
|
-
_t = api$1.assetsV2;
|
|
1356
|
-
_t2 = _objectSpread2;
|
|
1357
|
-
_t3 = _objectSpread2;
|
|
1358
|
-
_t4 = {};
|
|
1359
|
-
_context.n = 5;
|
|
1360
|
-
return api$1.assetsV2.fromContext(context);
|
|
1361
|
-
case 5:
|
|
1362
|
-
_context.n = 6;
|
|
1363
|
-
return _t.buildRegistry.call(_t, _t2(_t3(_t4, _context.v), overrides));
|
|
1364
|
-
case 6:
|
|
1365
|
-
registry = _context.v;
|
|
1366
|
-
_t5 = api$1.toPolkadotV2;
|
|
1367
|
-
_t6 = context.gateway();
|
|
1368
|
-
_context.n = 7;
|
|
1369
|
-
return context.assetHub();
|
|
1370
|
-
case 7:
|
|
1371
|
-
_t7 = _context.v;
|
|
1372
|
-
_context.n = 8;
|
|
1373
|
-
return context.parachain(destParaId);
|
|
1374
|
-
case 8:
|
|
1375
|
-
_t8 = _context.v;
|
|
1376
|
-
_context.n = 9;
|
|
1377
|
-
return _t5.getDeliveryFee.call(_t5, {
|
|
1378
|
-
gateway: _t6,
|
|
1379
|
-
assetHub: _t7,
|
|
1380
|
-
destination: _t8
|
|
1381
|
-
}, registry, ethAsset.assetId, destParaId);
|
|
1382
|
-
case 9:
|
|
1383
|
-
fee = _context.v;
|
|
1384
|
-
_context.n = 10;
|
|
1385
|
-
return signer.getAddress();
|
|
1386
|
-
case 10:
|
|
1387
|
-
sourceAddress = _context.v;
|
|
1388
|
-
_context.n = 11;
|
|
1389
|
-
return api$1.toPolkadotV2.createTransfer(registry, sourceAddress, address, ethAsset.assetId, destParaId, amount, fee);
|
|
1390
|
-
case 11:
|
|
1391
|
-
transfer = _context.v;
|
|
1392
|
-
_t9 = api$1.toPolkadotV2;
|
|
1393
|
-
_t0 = context.ethereum();
|
|
1394
|
-
_t1 = context.gateway();
|
|
1395
|
-
_context.n = 12;
|
|
1396
|
-
return context.bridgeHub();
|
|
1397
|
-
case 12:
|
|
1398
|
-
_t10 = _context.v;
|
|
1399
|
-
_context.n = 13;
|
|
1400
|
-
return context.assetHub();
|
|
1401
|
-
case 13:
|
|
1402
|
-
_t11 = _context.v;
|
|
1403
|
-
if (!(destParaId !== sdkCore.getParaId('AssetHubPolkadot'))) {
|
|
1404
|
-
_context.n = 15;
|
|
1405
|
-
break;
|
|
1406
|
-
}
|
|
1407
|
-
_context.n = 14;
|
|
1408
|
-
return context.parachain(destParaId);
|
|
1409
|
-
case 14:
|
|
1410
|
-
_t12 = _context.v;
|
|
1411
|
-
_context.n = 16;
|
|
1412
|
-
break;
|
|
1413
|
-
case 15:
|
|
1414
|
-
_t12 = undefined;
|
|
1415
|
-
case 16:
|
|
1416
|
-
_t13 = _t12;
|
|
1417
|
-
_context.n = 17;
|
|
1418
|
-
return _t9.validateTransfer.call(_t9, {
|
|
1419
|
-
ethereum: _t0,
|
|
1420
|
-
gateway: _t1,
|
|
1421
|
-
bridgeHub: _t10,
|
|
1422
|
-
assetHub: _t11,
|
|
1423
|
-
destParachain: _t13
|
|
1424
|
-
}, transfer);
|
|
1425
|
-
case 17:
|
|
1426
|
-
validation = _context.v;
|
|
1427
|
-
if (!validation.logs.find(function (l) {
|
|
1428
|
-
return l.kind == api$1.toPolkadotV2.ValidationKind.Error;
|
|
1429
|
-
})) {
|
|
1430
|
-
_context.n = 18;
|
|
1431
|
-
break;
|
|
1432
|
-
}
|
|
1433
|
-
throw new sdkCore.InvalidParameterError("Validation failed with following errors: \n\n ".concat(validation.logs.filter(function (l) {
|
|
1434
|
-
return l.kind == api$1.toPolkadotV2.ValidationKind.Error;
|
|
1435
|
-
}).map(function (l) {
|
|
1436
|
-
return l.message;
|
|
1437
|
-
}).join('\n\n')));
|
|
1438
|
-
case 18:
|
|
1439
|
-
tx = transfer.tx;
|
|
1440
|
-
_context.n = 19;
|
|
1441
|
-
return signer.sendTransaction(tx);
|
|
1442
|
-
case 19:
|
|
1443
|
-
response = _context.v;
|
|
1444
|
-
_context.n = 20;
|
|
1445
|
-
return response.wait(1);
|
|
1446
|
-
case 20:
|
|
1447
|
-
receipt = _context.v;
|
|
1448
|
-
if (receipt) {
|
|
1449
|
-
_context.n = 21;
|
|
1450
|
-
break;
|
|
1451
|
-
}
|
|
1452
|
-
throw new sdkCore.InvalidParameterError("Transaction ".concat(response.hash, " not included."));
|
|
1453
|
-
case 21:
|
|
1454
|
-
_context.n = 22;
|
|
1455
|
-
return api$1.toPolkadotV2.getMessageReceipt(receipt);
|
|
1456
|
-
case 22:
|
|
1457
|
-
messageReceipt = _context.v;
|
|
1458
|
-
if (messageReceipt) {
|
|
1459
|
-
_context.n = 23;
|
|
1460
|
-
break;
|
|
1461
|
-
}
|
|
1462
|
-
throw new sdkCore.InvalidParameterError("Transaction ".concat(receipt.hash, " did not emit a message."));
|
|
1463
|
-
case 23:
|
|
1464
|
-
return _context.a(2, {
|
|
1465
|
-
response: response,
|
|
1466
|
-
messageReceipt: messageReceipt
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
}, _callee);
|
|
1470
|
-
}));
|
|
1471
|
-
return function transferEthToPolkadot(_x) {
|
|
1472
|
-
return _ref2.apply(this, arguments);
|
|
1473
|
-
};
|
|
1474
|
-
}();
|
|
1475
|
-
|
|
1476
|
-
var getTokenBalance = /*#__PURE__*/function () {
|
|
1477
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(signer, symbol) {
|
|
1478
|
-
var env, contract, weth9, address;
|
|
1479
|
-
return _regenerator().w(function (_context) {
|
|
1480
|
-
while (1) switch (_context.n) {
|
|
1481
|
-
case 0:
|
|
1482
|
-
env = api$1.environment.SNOWBRIDGE_ENV['polkadot_mainnet'];
|
|
1483
|
-
contract = env.locations[0].erc20tokensReceivable.find(function (t) {
|
|
1484
|
-
return t.id === symbol;
|
|
1485
|
-
});
|
|
1486
|
-
if (contract) {
|
|
1487
|
-
_context.n = 1;
|
|
1488
|
-
break;
|
|
1489
|
-
}
|
|
1490
|
-
throw new sdkCore.InvalidParameterError("Token ".concat(symbol, " not supported"));
|
|
1491
|
-
case 1:
|
|
1492
|
-
weth9 = contractTypes.WETH9__factory.connect(contract.address, signer);
|
|
1493
|
-
_context.n = 2;
|
|
1494
|
-
return signer.getAddress();
|
|
1495
|
-
case 2:
|
|
1496
|
-
address = _context.v;
|
|
1497
|
-
return _context.a(2, weth9.balanceOf(address));
|
|
1498
|
-
}
|
|
1499
|
-
}, _callee);
|
|
1500
|
-
}));
|
|
1501
|
-
return function getTokenBalance(_x, _x2) {
|
|
1502
|
-
return _ref.apply(this, arguments);
|
|
1503
|
-
};
|
|
1504
|
-
}();
|
|
1505
|
-
|
|
1506
|
-
/**
|
|
1507
|
-
* Builder class for constructing transfers from Ethereum to Polkadot.
|
|
1508
|
-
*/
|
|
1509
|
-
var EvmBuilderCore = /*#__PURE__*/function () {
|
|
1510
|
-
function EvmBuilderCore(options) {
|
|
1511
|
-
_classCallCheck(this, EvmBuilderCore);
|
|
1512
|
-
this._options = options;
|
|
1513
|
-
}
|
|
1514
|
-
return _createClass(EvmBuilderCore, [{
|
|
1515
|
-
key: "from",
|
|
1516
|
-
value: function from(chain) {
|
|
1517
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1518
|
-
from: chain
|
|
1519
|
-
}));
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
* Specifies the destination chain on Polkadot.
|
|
1523
|
-
*
|
|
1524
|
-
* @param chain - The Polkadot chain to which the transfer will be made.
|
|
1525
|
-
* @returns An instance of EvmBuilder
|
|
1526
|
-
*/
|
|
1527
|
-
}, {
|
|
1528
|
-
key: "to",
|
|
1529
|
-
value: function to(chain) {
|
|
1530
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1531
|
-
to: chain
|
|
1532
|
-
}));
|
|
1533
|
-
}
|
|
1534
|
-
/**
|
|
1535
|
-
* Specifies the currency to transfer.
|
|
1536
|
-
*
|
|
1537
|
-
* @param currency - The currency to be transferred.
|
|
1538
|
-
* @returns An instance of EvmBuilder
|
|
1539
|
-
*/
|
|
1540
|
-
}, {
|
|
1541
|
-
key: "currency",
|
|
1542
|
-
value: function currency(_currency) {
|
|
1543
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1544
|
-
currency: _currency
|
|
1545
|
-
}));
|
|
1546
|
-
}
|
|
1547
|
-
/**
|
|
1548
|
-
* Specifies the recipient address on Polkadot.
|
|
1549
|
-
*
|
|
1550
|
-
* @param address - The Polkadot address to receive the transfer.
|
|
1551
|
-
* @returns An instance of EvmBuilder
|
|
1552
|
-
*/
|
|
1553
|
-
}, {
|
|
1554
|
-
key: "address",
|
|
1555
|
-
value: function address(_address) {
|
|
1556
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1557
|
-
address: _address
|
|
1558
|
-
}));
|
|
1559
|
-
}
|
|
1560
|
-
/**
|
|
1561
|
-
* Sets the asset hub address. This is used for transfers that go through the Asset Hub.
|
|
1562
|
-
*
|
|
1563
|
-
* @param address - The address to be used.
|
|
1564
|
-
* @returns An instance of EvmBuilder
|
|
1565
|
-
*/
|
|
1566
|
-
}, {
|
|
1567
|
-
key: "ahAddress",
|
|
1568
|
-
value: function ahAddress(address) {
|
|
1569
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1570
|
-
ahAddress: address
|
|
1571
|
-
}));
|
|
1572
|
-
}
|
|
1573
|
-
/**
|
|
1574
|
-
* Specifies the signer for the Ethereum transaction.
|
|
1575
|
-
*
|
|
1576
|
-
* @param signer - The Ethereum signer to authorize the transfer.
|
|
1577
|
-
* @returns An instance of EvmBuilder
|
|
1578
|
-
*/
|
|
1579
|
-
}, {
|
|
1580
|
-
key: "signer",
|
|
1581
|
-
value: function signer(_signer) {
|
|
1582
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1583
|
-
signer: _signer
|
|
1584
|
-
}));
|
|
1585
|
-
}
|
|
1586
|
-
/**
|
|
1587
|
-
* Builds and executes the transfer from Ethereum to Polkadot.
|
|
1588
|
-
*
|
|
1589
|
-
* @throws Error if any required parameters are missing.
|
|
1590
|
-
*/
|
|
1591
|
-
}, {
|
|
1592
|
-
key: "build",
|
|
1593
|
-
value: (function () {
|
|
1594
|
-
var _build = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1595
|
-
var _this$_options, from, to, address, signer, api, _yield$transferEthToP, response;
|
|
1596
|
-
return _regenerator().w(function (_context) {
|
|
1597
|
-
while (1) switch (_context.n) {
|
|
1598
|
-
case 0:
|
|
1599
|
-
_this$_options = this._options, from = _this$_options.from, to = _this$_options.to, address = _this$_options.address, signer = _this$_options.signer, api = _this$_options.api;
|
|
1600
|
-
sdkCore.validateAddress(api, address, to);
|
|
1601
|
-
if (!(from === 'Moonbeam' && to === 'Ethereum')) {
|
|
1602
|
-
_context.n = 2;
|
|
1603
|
-
break;
|
|
1604
|
-
}
|
|
1605
|
-
if (!isEthersSigner(signer)) {
|
|
1606
|
-
_context.n = 1;
|
|
1607
|
-
break;
|
|
1608
|
-
}
|
|
1609
|
-
throw new sdkCore.InvalidParameterError('Ethers signer is not supported for Moonbeam to Ethereum transfers.');
|
|
1610
|
-
case 1:
|
|
1611
|
-
return _context.a(2, sdkCore.transferMoonbeamToEth(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1612
|
-
signer: signer
|
|
1613
|
-
})));
|
|
1614
|
-
case 2:
|
|
1615
|
-
if (!(from === 'Moonbeam' || from === 'Moonriver' || from === 'Darwinia')) {
|
|
1616
|
-
_context.n = 4;
|
|
1617
|
-
break;
|
|
1618
|
-
}
|
|
1619
|
-
if (!isEthersSigner(signer)) {
|
|
1620
|
-
_context.n = 3;
|
|
1621
|
-
break;
|
|
1622
|
-
}
|
|
1623
|
-
throw new sdkCore.InvalidParameterError('Ethers signer is not supported for Moonbeam to Ethereum transfers.');
|
|
1624
|
-
case 3:
|
|
1625
|
-
return _context.a(2, sdkCore.transferMoonbeamEvm(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1626
|
-
signer: signer
|
|
1627
|
-
})));
|
|
1628
|
-
case 4:
|
|
1629
|
-
_context.n = 5;
|
|
1630
|
-
return transferEthToPolkadot$1(this._options);
|
|
1631
|
-
case 5:
|
|
1632
|
-
_yield$transferEthToP = _context.v;
|
|
1633
|
-
response = _yield$transferEthToP.response;
|
|
1634
|
-
return _context.a(2, response.hash);
|
|
1635
|
-
case 6:
|
|
1636
|
-
return _context.a(2);
|
|
1637
|
-
}
|
|
1638
|
-
}, _callee, this);
|
|
1639
|
-
}));
|
|
1640
|
-
function build() {
|
|
1641
|
-
return _build.apply(this, arguments);
|
|
1642
|
-
}
|
|
1643
|
-
return build;
|
|
1644
|
-
}())
|
|
1645
|
-
}]);
|
|
1646
|
-
}();
|
|
1647
|
-
/**
|
|
1648
|
-
* Creates a new EvmBuilder instance for constructing Ethereum to Polkadot transfers.
|
|
1649
|
-
*
|
|
1650
|
-
* @param provider - The Ethereum provider to use for the transfer.
|
|
1651
|
-
* @returns An instance of EvmBuilder class
|
|
1652
|
-
*/
|
|
1653
|
-
var EvmBuilder$1 = function EvmBuilder(api, provider) {
|
|
1654
|
-
return new EvmBuilderCore({
|
|
1655
|
-
api: api,
|
|
1656
|
-
provider: provider
|
|
1657
|
-
});
|
|
1658
|
-
};
|
|
1659
|
-
|
|
1660
|
-
/**
|
|
1661
|
-
* Creates a new Builder instance.
|
|
1662
|
-
*
|
|
1663
|
-
* @param api - The API instance to use for building transactions. If not provided, a new instance will be created.
|
|
1664
|
-
* @returns A new Builder instance.
|
|
1665
|
-
*/
|
|
1666
|
-
var Builder = function Builder(api) {
|
|
1667
|
-
var pjsApi = new PolkadotJsApi(api);
|
|
1668
|
-
return sdkCore.Builder(pjsApi);
|
|
1669
|
-
};
|
|
1670
|
-
var EvmBuilder = function EvmBuilder(provider, api) {
|
|
1671
|
-
var pjsApi = new PolkadotJsApi(api);
|
|
1672
|
-
return EvmBuilder$1(pjsApi, provider);
|
|
1673
|
-
};
|
|
1674
|
-
|
|
1675
|
-
/**
|
|
1676
|
-
* Transfers assets from parachain to another parachain or from/to relay chain.
|
|
1677
|
-
* @param options - The transfer options.
|
|
1678
|
-
* @returns An extrinsic to be signed and sent.
|
|
1679
|
-
*/
|
|
1680
|
-
var send = createPolkadotJsApiCall(sdkCore.send);
|
|
1681
|
-
var dryRun = createPolkadotJsApiCall(sdkCore.dryRun);
|
|
1682
|
-
var dryRunOrigin = createPolkadotJsApiCall(sdkCore.dryRunOrigin);
|
|
1683
|
-
var transferEthToPolkadot = function transferEthToPolkadot(options) {
|
|
1684
|
-
return transferEthToPolkadot$1(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
1685
|
-
api: new PolkadotJsApi()
|
|
1686
|
-
}));
|
|
1687
|
-
};
|
|
1688
|
-
var getParaEthTransferFees = /*#__PURE__*/function () {
|
|
1689
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api) {
|
|
1690
|
-
var pjsApi;
|
|
1691
|
-
return _regenerator().w(function (_context) {
|
|
1692
|
-
while (1) switch (_context.n) {
|
|
1693
|
-
case 0:
|
|
1694
|
-
pjsApi = new PolkadotJsApi(api);
|
|
1695
|
-
_context.n = 1;
|
|
1696
|
-
return pjsApi.init('AssetHubPolkadot', sdkCore.DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
1697
|
-
case 1:
|
|
1698
|
-
return _context.a(2, sdkCore.getParaEthTransferFees(pjsApi));
|
|
1699
|
-
}
|
|
1700
|
-
}, _callee);
|
|
1701
|
-
}));
|
|
1702
|
-
return function getParaEthTransferFees(_x) {
|
|
1703
|
-
return _ref.apply(this, arguments);
|
|
1704
|
-
};
|
|
1705
|
-
}();
|
|
1706
|
-
/**
|
|
1707
|
-
* Gets the Ethereum bridge status.
|
|
1708
|
-
*/
|
|
1709
|
-
var getBridgeStatus = /*#__PURE__*/function () {
|
|
1710
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api) {
|
|
1711
|
-
var pjsApi;
|
|
1712
|
-
return _regenerator().w(function (_context2) {
|
|
1713
|
-
while (1) switch (_context2.n) {
|
|
1714
|
-
case 0:
|
|
1715
|
-
pjsApi = new PolkadotJsApi(api);
|
|
1716
|
-
return _context2.a(2, sdkCore.getBridgeStatus(pjsApi));
|
|
1717
|
-
}
|
|
1718
|
-
}, _callee2);
|
|
1719
|
-
}));
|
|
1720
|
-
return function getBridgeStatus(_x2) {
|
|
1721
|
-
return _ref2.apply(this, arguments);
|
|
1722
|
-
};
|
|
1723
|
-
}();
|
|
1724
|
-
|
|
1725
|
-
var transfer = /*#__PURE__*/Object.freeze({
|
|
1726
|
-
__proto__: null,
|
|
1727
|
-
approveToken: approveToken,
|
|
1728
|
-
depositToken: depositToken,
|
|
1729
|
-
dryRun: dryRun,
|
|
1730
|
-
dryRunOrigin: dryRunOrigin,
|
|
1731
|
-
getBridgeStatus: getBridgeStatus,
|
|
1732
|
-
getParaEthTransferFees: getParaEthTransferFees,
|
|
1733
|
-
getTokenBalance: getTokenBalance,
|
|
1734
|
-
send: send,
|
|
1735
|
-
transferEthToPolkadot: transferEthToPolkadot
|
|
1736
|
-
});
|
|
1737
|
-
|
|
1738
|
-
exports.Builder = Builder;
|
|
1739
|
-
exports.EvmBuilder = EvmBuilder;
|
|
1740
|
-
exports.approveToken = approveToken;
|
|
1741
|
-
exports.assets = assets;
|
|
1742
|
-
exports.claimAssets = claimAssets;
|
|
1743
|
-
exports.convertSs58 = convertSs58;
|
|
1744
|
-
exports.createChainClient = createChainClient;
|
|
1745
|
-
exports.depositToken = depositToken;
|
|
1746
|
-
exports.dryRun = dryRun;
|
|
1747
|
-
exports.dryRunOrigin = dryRunOrigin;
|
|
1748
|
-
exports.getAssetBalance = getAssetBalance;
|
|
1749
|
-
exports.getBalanceForeign = getBalanceForeign;
|
|
1750
|
-
exports.getBalanceNative = getBalanceNative;
|
|
1751
|
-
exports.getBridgeStatus = getBridgeStatus;
|
|
1752
|
-
exports.getOriginFeeDetails = getOriginFeeDetails;
|
|
1753
|
-
exports.getParaEthTransferFees = getParaEthTransferFees;
|
|
1754
|
-
exports.getTokenBalance = getTokenBalance;
|
|
1755
|
-
exports.send = send;
|
|
1756
|
-
exports.transferEthToPolkadot = transferEthToPolkadot;
|
|
1757
|
-
exports.xcmPallet = transfer;
|
|
1758
|
-
Object.keys(sdkCore).forEach(function (k) {
|
|
1759
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1760
|
-
enumerable: true,
|
|
1761
|
-
get: function () { return sdkCore[k]; }
|
|
1762
|
-
});
|
|
1763
|
-
});
|