@paraspell/sdk 11.14.9 → 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 -33
- package/dist/index.d.ts +5 -39
- package/dist/index.mjs +11 -43
- package/package.json +4 -4
- package/dist/index.cjs +0 -2006
package/dist/index.cjs
DELETED
|
@@ -1,2006 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var sdkCore = require('@paraspell/sdk-core');
|
|
4
|
-
var blake2 = require('@noble/hashes/blake2');
|
|
5
|
-
var utils = require('@noble/hashes/utils');
|
|
6
|
-
var legacyProvider = require('@polkadot-api/legacy-provider');
|
|
7
|
-
var polkadotApi = require('polkadot-api');
|
|
8
|
-
var polkadotSdkCompat = require('polkadot-api/polkadot-sdk-compat');
|
|
9
|
-
var wsProvider = require('polkadot-api/ws-provider');
|
|
10
|
-
var viem = require('viem');
|
|
11
|
-
|
|
12
|
-
function _arrayLikeToArray(r, a) {
|
|
13
|
-
(null == a || a > r.length) && (a = r.length);
|
|
14
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
15
|
-
return n;
|
|
16
|
-
}
|
|
17
|
-
function _arrayWithHoles(r) {
|
|
18
|
-
if (Array.isArray(r)) return r;
|
|
19
|
-
}
|
|
20
|
-
function _arrayWithoutHoles(r) {
|
|
21
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
22
|
-
}
|
|
23
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
24
|
-
try {
|
|
25
|
-
var i = n[a](c),
|
|
26
|
-
u = i.value;
|
|
27
|
-
} catch (n) {
|
|
28
|
-
return void e(n);
|
|
29
|
-
}
|
|
30
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
31
|
-
}
|
|
32
|
-
function _asyncToGenerator(n) {
|
|
33
|
-
return function () {
|
|
34
|
-
var t = this,
|
|
35
|
-
e = arguments;
|
|
36
|
-
return new Promise(function (r, o) {
|
|
37
|
-
var a = n.apply(t, e);
|
|
38
|
-
function _next(n) {
|
|
39
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
40
|
-
}
|
|
41
|
-
function _throw(n) {
|
|
42
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
43
|
-
}
|
|
44
|
-
_next(void 0);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function _classCallCheck(a, n) {
|
|
49
|
-
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
50
|
-
}
|
|
51
|
-
function _defineProperties(e, r) {
|
|
52
|
-
for (var t = 0; t < r.length; t++) {
|
|
53
|
-
var o = r[t];
|
|
54
|
-
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function _createClass(e, r, t) {
|
|
58
|
-
return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
|
|
59
|
-
writable: false
|
|
60
|
-
}), e;
|
|
61
|
-
}
|
|
62
|
-
function _createForOfIteratorHelper(r, e) {
|
|
63
|
-
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
64
|
-
if (!t) {
|
|
65
|
-
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
|
66
|
-
t && (r = t);
|
|
67
|
-
var n = 0,
|
|
68
|
-
F = function () {};
|
|
69
|
-
return {
|
|
70
|
-
s: F,
|
|
71
|
-
n: function () {
|
|
72
|
-
return n >= r.length ? {
|
|
73
|
-
done: true
|
|
74
|
-
} : {
|
|
75
|
-
done: false,
|
|
76
|
-
value: r[n++]
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
e: function (r) {
|
|
80
|
-
throw r;
|
|
81
|
-
},
|
|
82
|
-
f: F
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
86
|
-
}
|
|
87
|
-
var o,
|
|
88
|
-
a = true,
|
|
89
|
-
u = false;
|
|
90
|
-
return {
|
|
91
|
-
s: function () {
|
|
92
|
-
t = t.call(r);
|
|
93
|
-
},
|
|
94
|
-
n: function () {
|
|
95
|
-
var r = t.next();
|
|
96
|
-
return a = r.done, r;
|
|
97
|
-
},
|
|
98
|
-
e: function (r) {
|
|
99
|
-
u = true, o = r;
|
|
100
|
-
},
|
|
101
|
-
f: function () {
|
|
102
|
-
try {
|
|
103
|
-
a || null == t.return || t.return();
|
|
104
|
-
} finally {
|
|
105
|
-
if (u) throw o;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function _defineProperty(e, r, t) {
|
|
111
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
112
|
-
value: t,
|
|
113
|
-
enumerable: true,
|
|
114
|
-
configurable: true,
|
|
115
|
-
writable: true
|
|
116
|
-
}) : e[r] = t, e;
|
|
117
|
-
}
|
|
118
|
-
function _iterableToArray(r) {
|
|
119
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
120
|
-
}
|
|
121
|
-
function _iterableToArrayLimit(r, l) {
|
|
122
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
123
|
-
if (null != t) {
|
|
124
|
-
var e,
|
|
125
|
-
n,
|
|
126
|
-
i,
|
|
127
|
-
u,
|
|
128
|
-
a = [],
|
|
129
|
-
f = true,
|
|
130
|
-
o = false;
|
|
131
|
-
try {
|
|
132
|
-
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);
|
|
133
|
-
} catch (r) {
|
|
134
|
-
o = true, n = r;
|
|
135
|
-
} finally {
|
|
136
|
-
try {
|
|
137
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
138
|
-
} finally {
|
|
139
|
-
if (o) throw n;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return a;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function _nonIterableRest() {
|
|
146
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
147
|
-
}
|
|
148
|
-
function _nonIterableSpread() {
|
|
149
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
150
|
-
}
|
|
151
|
-
function ownKeys(e, r) {
|
|
152
|
-
var t = Object.keys(e);
|
|
153
|
-
if (Object.getOwnPropertySymbols) {
|
|
154
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
155
|
-
r && (o = o.filter(function (r) {
|
|
156
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
157
|
-
})), t.push.apply(t, o);
|
|
158
|
-
}
|
|
159
|
-
return t;
|
|
160
|
-
}
|
|
161
|
-
function _objectSpread2(e) {
|
|
162
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
163
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
164
|
-
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
165
|
-
_defineProperty(e, r, t[r]);
|
|
166
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
167
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
return e;
|
|
171
|
-
}
|
|
172
|
-
function _regenerator() {
|
|
173
|
-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
174
|
-
var e,
|
|
175
|
-
t,
|
|
176
|
-
r = "function" == typeof Symbol ? Symbol : {},
|
|
177
|
-
n = r.iterator || "@@iterator",
|
|
178
|
-
o = r.toStringTag || "@@toStringTag";
|
|
179
|
-
function i(r, n, o, i) {
|
|
180
|
-
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
181
|
-
u = Object.create(c.prototype);
|
|
182
|
-
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
183
|
-
var i,
|
|
184
|
-
c,
|
|
185
|
-
u,
|
|
186
|
-
f = 0,
|
|
187
|
-
p = o || [],
|
|
188
|
-
y = false,
|
|
189
|
-
G = {
|
|
190
|
-
p: 0,
|
|
191
|
-
n: 0,
|
|
192
|
-
v: e,
|
|
193
|
-
a: d,
|
|
194
|
-
f: d.bind(e, 4),
|
|
195
|
-
d: function (t, r) {
|
|
196
|
-
return i = t, c = 0, u = e, G.n = r, a;
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
function d(r, n) {
|
|
200
|
-
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
201
|
-
var o,
|
|
202
|
-
i = p[t],
|
|
203
|
-
d = G.p,
|
|
204
|
-
l = i[2];
|
|
205
|
-
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));
|
|
206
|
-
}
|
|
207
|
-
if (o || r > 1) return a;
|
|
208
|
-
throw y = true, n;
|
|
209
|
-
}
|
|
210
|
-
return function (o, p, l) {
|
|
211
|
-
if (f > 1) throw TypeError("Generator is already running");
|
|
212
|
-
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
213
|
-
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
214
|
-
try {
|
|
215
|
-
if (f = 2, i) {
|
|
216
|
-
if (c || (o = "next"), t = i[o]) {
|
|
217
|
-
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
218
|
-
if (!t.done) return t;
|
|
219
|
-
u = t.value, c < 2 && (c = 0);
|
|
220
|
-
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
221
|
-
i = e;
|
|
222
|
-
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
223
|
-
} catch (t) {
|
|
224
|
-
i = e, c = 1, u = t;
|
|
225
|
-
} finally {
|
|
226
|
-
f = 1;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return {
|
|
230
|
-
value: t,
|
|
231
|
-
done: y
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
}(r, o, i), true), u;
|
|
235
|
-
}
|
|
236
|
-
var a = {};
|
|
237
|
-
function Generator() {}
|
|
238
|
-
function GeneratorFunction() {}
|
|
239
|
-
function GeneratorFunctionPrototype() {}
|
|
240
|
-
t = Object.getPrototypeOf;
|
|
241
|
-
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
242
|
-
return this;
|
|
243
|
-
}), t),
|
|
244
|
-
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
245
|
-
function f(e) {
|
|
246
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
247
|
-
}
|
|
248
|
-
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 () {
|
|
249
|
-
return this;
|
|
250
|
-
}), _regeneratorDefine(u, "toString", function () {
|
|
251
|
-
return "[object Generator]";
|
|
252
|
-
}), (_regenerator = function () {
|
|
253
|
-
return {
|
|
254
|
-
w: i,
|
|
255
|
-
m: f
|
|
256
|
-
};
|
|
257
|
-
})();
|
|
258
|
-
}
|
|
259
|
-
function _regeneratorDefine(e, r, n, t) {
|
|
260
|
-
var i = Object.defineProperty;
|
|
261
|
-
try {
|
|
262
|
-
i({}, "", {});
|
|
263
|
-
} catch (e) {
|
|
264
|
-
i = 0;
|
|
265
|
-
}
|
|
266
|
-
_regeneratorDefine = function (e, r, n, t) {
|
|
267
|
-
function o(r, n) {
|
|
268
|
-
_regeneratorDefine(e, r, function (e) {
|
|
269
|
-
return this._invoke(r, n, e);
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
r ? i ? i(e, r, {
|
|
273
|
-
value: n,
|
|
274
|
-
enumerable: !t,
|
|
275
|
-
configurable: !t,
|
|
276
|
-
writable: !t
|
|
277
|
-
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
278
|
-
}, _regeneratorDefine(e, r, n, t);
|
|
279
|
-
}
|
|
280
|
-
function _slicedToArray(r, e) {
|
|
281
|
-
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
282
|
-
}
|
|
283
|
-
function _toConsumableArray(r) {
|
|
284
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
285
|
-
}
|
|
286
|
-
function _toPrimitive(t, r) {
|
|
287
|
-
if ("object" != typeof t || !t) return t;
|
|
288
|
-
var e = t[Symbol.toPrimitive];
|
|
289
|
-
if (void 0 !== e) {
|
|
290
|
-
var i = e.call(t, r);
|
|
291
|
-
if ("object" != typeof i) return i;
|
|
292
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
293
|
-
}
|
|
294
|
-
return ("string" === r ? String : Number)(t);
|
|
295
|
-
}
|
|
296
|
-
function _toPropertyKey(t) {
|
|
297
|
-
var i = _toPrimitive(t, "string");
|
|
298
|
-
return "symbol" == typeof i ? i : i + "";
|
|
299
|
-
}
|
|
300
|
-
function _typeof(o) {
|
|
301
|
-
"@babel/helpers - typeof";
|
|
302
|
-
|
|
303
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
304
|
-
return typeof o;
|
|
305
|
-
} : function (o) {
|
|
306
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
307
|
-
}, _typeof(o);
|
|
308
|
-
}
|
|
309
|
-
function _unsupportedIterableToArray(r, a) {
|
|
310
|
-
if (r) {
|
|
311
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
312
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
313
|
-
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;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
var LEGACY_CHAINS = ['Interlay', 'CrustShadow', 'Kintsugi', 'RobonomicsKusama', 'RobonomicsPolkadot', 'Pendulum'];
|
|
318
|
-
// Cache settings
|
|
319
|
-
var DEFAULT_TTL_MS = 60000; // 1 minute
|
|
320
|
-
var MAX_CLIENTS = 100;
|
|
321
|
-
var EXTENSION_MS = 5 * 60000; // 5 minutes
|
|
322
|
-
|
|
323
|
-
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
324
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
325
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
326
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
327
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
328
|
-
var processAssetsDepositedEvents = function processAssetsDepositedEvents(events, amount, pallet, method) {
|
|
329
|
-
var returnOnOneEvent = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
330
|
-
var assetsDepositedEvents = events.filter(function (event) {
|
|
331
|
-
return event.type === pallet && event.value.type === method;
|
|
332
|
-
});
|
|
333
|
-
if (assetsDepositedEvents.length === 0) {
|
|
334
|
-
return undefined;
|
|
335
|
-
}
|
|
336
|
-
if (assetsDepositedEvents.length === 1 && returnOnOneEvent) {
|
|
337
|
-
return BigInt(assetsDepositedEvents[0].value.value.amount);
|
|
338
|
-
}
|
|
339
|
-
// Start with all events
|
|
340
|
-
var currentEvents = _toConsumableArray(assetsDepositedEvents);
|
|
341
|
-
var threshold = amount * BigInt(90) / BigInt(100); // 90% of amount
|
|
342
|
-
while (currentEvents.length > 0) {
|
|
343
|
-
// 1. Make a sum of all amounts in events
|
|
344
|
-
var sum = currentEvents.reduce(function (total, event) {
|
|
345
|
-
return total + BigInt(event.value.value.amount);
|
|
346
|
-
}, BigInt(0));
|
|
347
|
-
// 2. If that sum is bigger than 90% of amount, remove the biggest event
|
|
348
|
-
if (sum > threshold) {
|
|
349
|
-
// Sort events by amount (descending) and remove the biggest
|
|
350
|
-
currentEvents.sort(function (a, b) {
|
|
351
|
-
return Number(BigInt(b.value.value.amount) - BigInt(a.value.value.amount));
|
|
352
|
-
});
|
|
353
|
-
currentEvents = currentEvents.slice(1); // Remove the biggest event
|
|
354
|
-
} else {
|
|
355
|
-
// If not, return the summed value
|
|
356
|
-
return sum;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
// If we've removed all events, return undefined
|
|
360
|
-
return undefined;
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
var checkAndConvertToNumberOrBigInt = function checkAndConvertToNumberOrBigInt(input) {
|
|
364
|
-
if (!/^-?\d+$/.test(input)) {
|
|
365
|
-
throw new sdkCore.InvalidParameterError('Invalid integer string');
|
|
366
|
-
}
|
|
367
|
-
var bigIntValue = BigInt(input);
|
|
368
|
-
if (bigIntValue >= Number.MIN_SAFE_INTEGER && bigIntValue <= Number.MAX_SAFE_INTEGER) {
|
|
369
|
-
return Number(bigIntValue);
|
|
370
|
-
}
|
|
371
|
-
return bigIntValue;
|
|
372
|
-
};
|
|
373
|
-
var _transform = function transform(obj) {
|
|
374
|
-
if (Array.isArray(obj)) {
|
|
375
|
-
return obj.map(_transform);
|
|
376
|
-
} else if (_typeof(obj) === 'object' && obj !== null) {
|
|
377
|
-
var keys = Object.keys(obj);
|
|
378
|
-
if (keys.length === 1) {
|
|
379
|
-
var key = keys[0];
|
|
380
|
-
var value = obj[key];
|
|
381
|
-
if (key === 'items' && Array.isArray(value)) {
|
|
382
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
|
383
|
-
return {
|
|
384
|
-
items: value.map(function (item) {
|
|
385
|
-
return item.map(function (i) {
|
|
386
|
-
return polkadotApi.Binary.fromHex(i);
|
|
387
|
-
});
|
|
388
|
-
})
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
if (key === 'AccountId32') {
|
|
392
|
-
return {
|
|
393
|
-
type: key,
|
|
394
|
-
value: {
|
|
395
|
-
network: value.network === 'any' ? {
|
|
396
|
-
type: 'Any'
|
|
397
|
-
} : undefined,
|
|
398
|
-
id: polkadotApi.FixedSizeBinary.fromHex(value.id)
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
} else if (key === 'Id') {
|
|
402
|
-
return {
|
|
403
|
-
type: key,
|
|
404
|
-
value: value
|
|
405
|
-
};
|
|
406
|
-
} else if (key === 'Substrate') {
|
|
407
|
-
return {
|
|
408
|
-
type: key,
|
|
409
|
-
value: value
|
|
410
|
-
};
|
|
411
|
-
} else if (key === 'OtherReserve') {
|
|
412
|
-
return {
|
|
413
|
-
type: key,
|
|
414
|
-
value: checkAndConvertToNumberOrBigInt(value)
|
|
415
|
-
};
|
|
416
|
-
} else if (key === 'GlobalConsensus' && _typeof(value) === 'object' && ('polkadot' in value || 'kusama' in value)) {
|
|
417
|
-
return {
|
|
418
|
-
type: key,
|
|
419
|
-
value: {
|
|
420
|
-
type: 'polkadot' in value ? 'Polkadot' : 'Kusama'
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
} else if (key === 'PalletInstance') {
|
|
424
|
-
return {
|
|
425
|
-
type: key,
|
|
426
|
-
value: value
|
|
427
|
-
};
|
|
428
|
-
} else if (key === 'GeneralIndex') {
|
|
429
|
-
return {
|
|
430
|
-
type: key,
|
|
431
|
-
value: BigInt(value)
|
|
432
|
-
};
|
|
433
|
-
} else if (key === 'Ethereum') {
|
|
434
|
-
return {
|
|
435
|
-
type: key,
|
|
436
|
-
value: {
|
|
437
|
-
chain_id: BigInt('chainId' in value ? value.chainId : value.chain_id)
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
} else if (key === 'AccountKey20') {
|
|
441
|
-
return {
|
|
442
|
-
type: key,
|
|
443
|
-
value: {
|
|
444
|
-
network: value.network === 'any' ? {
|
|
445
|
-
type: 'Any'
|
|
446
|
-
} : undefined,
|
|
447
|
-
key: polkadotApi.FixedSizeBinary.fromHex(value.key)
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
} else if (key === 'SetTopic') {
|
|
451
|
-
return {
|
|
452
|
-
type: key,
|
|
453
|
-
value: polkadotApi.FixedSizeBinary.fromHex(value)
|
|
454
|
-
};
|
|
455
|
-
} else if (key === 'SetFeesMode') {
|
|
456
|
-
var _value$jit_withdraw;
|
|
457
|
-
return {
|
|
458
|
-
type: key,
|
|
459
|
-
value: {
|
|
460
|
-
jit_withdraw: (_value$jit_withdraw = value.jit_withdraw) !== null && _value$jit_withdraw !== void 0 ? _value$jit_withdraw : false
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
} else if (key === 'X1' && Array.isArray(value)) {
|
|
464
|
-
return {
|
|
465
|
-
type: key,
|
|
466
|
-
value: value.length === 1 ? _transform(value[0]) : value.map(_transform)
|
|
467
|
-
};
|
|
468
|
-
} else if (key === 'Fungible') {
|
|
469
|
-
return {
|
|
470
|
-
type: key,
|
|
471
|
-
value: value
|
|
472
|
-
};
|
|
473
|
-
} else if (typeof value === 'string') {
|
|
474
|
-
return {
|
|
475
|
-
type: key,
|
|
476
|
-
value: {
|
|
477
|
-
type: value
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
} else if (typeof value === 'number') {
|
|
481
|
-
return {
|
|
482
|
-
type: key,
|
|
483
|
-
value: value
|
|
484
|
-
};
|
|
485
|
-
} else {
|
|
486
|
-
return {
|
|
487
|
-
type: key,
|
|
488
|
-
value: _transform(value)
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
} else {
|
|
492
|
-
var newObj = {};
|
|
493
|
-
var _iterator = _createForOfIteratorHelper(keys),
|
|
494
|
-
_step;
|
|
495
|
-
try {
|
|
496
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
497
|
-
var k = _step.value;
|
|
498
|
-
var v = obj[k];
|
|
499
|
-
if (k === 'fee_item') {
|
|
500
|
-
newObj[k] = Number(v);
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
if (k === 'currency_id' && typeof v === 'string') {
|
|
504
|
-
try {
|
|
505
|
-
newObj[k] = checkAndConvertToNumberOrBigInt(v);
|
|
506
|
-
} catch (_e) {
|
|
507
|
-
newObj[k] = {
|
|
508
|
-
type: v
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
if (k === 'amount' && typeof v === 'string') {
|
|
513
|
-
try {
|
|
514
|
-
newObj[k] = BigInt(v);
|
|
515
|
-
} catch (_e) {
|
|
516
|
-
newObj[k] = {
|
|
517
|
-
type: v
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
continue;
|
|
521
|
-
}
|
|
522
|
-
if (k === 'dest_weight' && v === null) {
|
|
523
|
-
newObj[k] = undefined;
|
|
524
|
-
continue;
|
|
525
|
-
}
|
|
526
|
-
if (typeof v === 'string' && polkadotApi.getSs58AddressInfo(v).isValid) {
|
|
527
|
-
newObj[k] = v;
|
|
528
|
-
continue;
|
|
529
|
-
}
|
|
530
|
-
if (typeof v === 'string' && viem.isAddress(v)) {
|
|
531
|
-
newObj[k] = v;
|
|
532
|
-
} else if (typeof v === 'string' && v.startsWith('0x')) {
|
|
533
|
-
newObj[k] = polkadotApi.FixedSizeBinary.fromHex(v);
|
|
534
|
-
} else if (typeof v === 'string') {
|
|
535
|
-
newObj[k] = {
|
|
536
|
-
type: v
|
|
537
|
-
};
|
|
538
|
-
} else {
|
|
539
|
-
newObj[k] = _transform(v);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
} catch (err) {
|
|
543
|
-
_iterator.e(err);
|
|
544
|
-
} finally {
|
|
545
|
-
_iterator.f();
|
|
546
|
-
}
|
|
547
|
-
return newObj;
|
|
548
|
-
}
|
|
549
|
-
} else {
|
|
550
|
-
// For primitive values
|
|
551
|
-
return obj;
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
function createClientCache(maxSize, onEviction) {
|
|
556
|
-
var extensionMs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 5 * 60000;
|
|
557
|
-
var data = new Map();
|
|
558
|
-
var timers = new Map();
|
|
559
|
-
var now = function now() {
|
|
560
|
-
return Date.now();
|
|
561
|
-
};
|
|
562
|
-
var timeLeft = function timeLeft(w) {
|
|
563
|
-
return Math.max(w.expireAt - now(), 0);
|
|
564
|
-
};
|
|
565
|
-
var schedule = function schedule(k, delay) {
|
|
566
|
-
if (timers.has(k)) clearTimeout(timers.get(k));
|
|
567
|
-
timers.set(k, setTimeout(function () {
|
|
568
|
-
return handleTimeout(k);
|
|
569
|
-
}, delay));
|
|
570
|
-
};
|
|
571
|
-
var handleTimeout = function handleTimeout(k) {
|
|
572
|
-
var w = data.get(k);
|
|
573
|
-
if (!w) return;
|
|
574
|
-
if (!w.extended && w.value.refs > 0) {
|
|
575
|
-
// first expiry while still in use - Extend grace period
|
|
576
|
-
// Call rpc.properties to keep the connection alive
|
|
577
|
-
void _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
578
|
-
return _regenerator().w(function (_context) {
|
|
579
|
-
while (1) switch (_context.p = _context.n) {
|
|
580
|
-
case 0:
|
|
581
|
-
_context.p = 0;
|
|
582
|
-
_context.n = 1;
|
|
583
|
-
return w.value.client.getChainSpecData();
|
|
584
|
-
case 1:
|
|
585
|
-
_context.n = 3;
|
|
586
|
-
break;
|
|
587
|
-
case 2:
|
|
588
|
-
_context.p = 2;
|
|
589
|
-
_context.v;
|
|
590
|
-
case 3:
|
|
591
|
-
return _context.a(2);
|
|
592
|
-
}
|
|
593
|
-
}, _callee, null, [[0, 2]]);
|
|
594
|
-
}))();
|
|
595
|
-
w.value.destroyWanted = true;
|
|
596
|
-
w.extended = true;
|
|
597
|
-
w.expireAt = now() + extensionMs;
|
|
598
|
-
schedule(k, extensionMs);
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
evict(k); // second expiry or unused - real eviction
|
|
602
|
-
};
|
|
603
|
-
var evict = function evict(k) {
|
|
604
|
-
var w = data.get(k);
|
|
605
|
-
if (!w) return;
|
|
606
|
-
clearTimeout(timers.get(k));
|
|
607
|
-
timers["delete"](k);
|
|
608
|
-
data["delete"](k);
|
|
609
|
-
onEviction === null || onEviction === void 0 || onEviction(k, w.value);
|
|
610
|
-
};
|
|
611
|
-
var evictIfNeeded = function evictIfNeeded() {
|
|
612
|
-
if (data.size <= maxSize) return;
|
|
613
|
-
var victimKey;
|
|
614
|
-
var victim;
|
|
615
|
-
var _iterator = _createForOfIteratorHelper(data),
|
|
616
|
-
_step;
|
|
617
|
-
try {
|
|
618
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
619
|
-
var _step$value = _slicedToArray(_step.value, 2),
|
|
620
|
-
k = _step$value[0],
|
|
621
|
-
w = _step$value[1];
|
|
622
|
-
if (!victim) {
|
|
623
|
-
victimKey = k;
|
|
624
|
-
victim = w;
|
|
625
|
-
continue;
|
|
626
|
-
}
|
|
627
|
-
var better = w.extended && !victim.extended ||
|
|
628
|
-
// Prefer extended over normal
|
|
629
|
-
w.extended === victim.extended && w.value.destroyWanted && !victim.value.destroyWanted || w.extended === victim.extended && w.value.destroyWanted === victim.value.destroyWanted && timeLeft(w) < timeLeft(victim) || w.extended === victim.extended && w.value.destroyWanted === victim.value.destroyWanted && timeLeft(w) === timeLeft(victim) && w.value.refs < victim.value.refs; // Prefer with less refs
|
|
630
|
-
if (better) {
|
|
631
|
-
victimKey = k;
|
|
632
|
-
victim = w;
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
} catch (err) {
|
|
636
|
-
_iterator.e(err);
|
|
637
|
-
} finally {
|
|
638
|
-
_iterator.f();
|
|
639
|
-
}
|
|
640
|
-
if (victimKey !== undefined) evict(victimKey);
|
|
641
|
-
};
|
|
642
|
-
var set = function set(k, v, ttl) {
|
|
643
|
-
var existing = data.get(k);
|
|
644
|
-
if (existing) {
|
|
645
|
-
existing.value = v;
|
|
646
|
-
existing.ttl = ttl;
|
|
647
|
-
existing.extended = false;
|
|
648
|
-
existing.expireAt = now() + ttl;
|
|
649
|
-
schedule(k, ttl);
|
|
650
|
-
} else {
|
|
651
|
-
data.set(k, {
|
|
652
|
-
value: v,
|
|
653
|
-
ttl: ttl,
|
|
654
|
-
extended: false,
|
|
655
|
-
expireAt: now() + ttl
|
|
656
|
-
});
|
|
657
|
-
schedule(k, ttl);
|
|
658
|
-
}
|
|
659
|
-
evictIfNeeded();
|
|
660
|
-
};
|
|
661
|
-
var get = function get(k) {
|
|
662
|
-
var w = data.get(k);
|
|
663
|
-
if (!w) return undefined;
|
|
664
|
-
if (!w.extended && timeLeft(w) < w.ttl) {
|
|
665
|
-
w.expireAt = now() + w.ttl; // refresh normal life
|
|
666
|
-
schedule(k, w.ttl);
|
|
667
|
-
}
|
|
668
|
-
return w.value;
|
|
669
|
-
};
|
|
670
|
-
var revive = function revive(k, ttl) {
|
|
671
|
-
var w = data.get(k);
|
|
672
|
-
if (!w) return;
|
|
673
|
-
var remaining = timeLeft(w);
|
|
674
|
-
w.extended = false;
|
|
675
|
-
if (ttl < remaining) {
|
|
676
|
-
w.ttl = ttl;
|
|
677
|
-
w.expireAt = now() + ttl;
|
|
678
|
-
schedule(k, ttl);
|
|
679
|
-
}
|
|
680
|
-
// if ttl ≥ remaining - keep current timer
|
|
681
|
-
};
|
|
682
|
-
var del = function del(k) {
|
|
683
|
-
if (!data.has(k)) return false;
|
|
684
|
-
evict(k);
|
|
685
|
-
return true;
|
|
686
|
-
};
|
|
687
|
-
var clear = function clear() {
|
|
688
|
-
var _iterator2 = _createForOfIteratorHelper(timers.values()),
|
|
689
|
-
_step2;
|
|
690
|
-
try {
|
|
691
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
692
|
-
var t = _step2.value;
|
|
693
|
-
clearTimeout(t);
|
|
694
|
-
}
|
|
695
|
-
} catch (err) {
|
|
696
|
-
_iterator2.e(err);
|
|
697
|
-
} finally {
|
|
698
|
-
_iterator2.f();
|
|
699
|
-
}
|
|
700
|
-
timers.clear();
|
|
701
|
-
data.clear();
|
|
702
|
-
};
|
|
703
|
-
return {
|
|
704
|
-
set: set,
|
|
705
|
-
get: get,
|
|
706
|
-
"delete": del,
|
|
707
|
-
has: function has(k) {
|
|
708
|
-
return data.has(k);
|
|
709
|
-
},
|
|
710
|
-
clear: clear,
|
|
711
|
-
peek: function peek(k) {
|
|
712
|
-
var _data$get;
|
|
713
|
-
return (_data$get = data.get(k)) === null || _data$get === void 0 ? void 0 : _data$get.value;
|
|
714
|
-
},
|
|
715
|
-
remainingTtl: function remainingTtl(k) {
|
|
716
|
-
var w = data.get(k);
|
|
717
|
-
return w ? timeLeft(w) : undefined;
|
|
718
|
-
},
|
|
719
|
-
revive: revive
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
var clientPool = createClientCache(MAX_CLIENTS, function (_key, entry) {
|
|
724
|
-
entry.client.destroy();
|
|
725
|
-
}, EXTENSION_MS);
|
|
726
|
-
var keyFromWs = function keyFromWs(ws) {
|
|
727
|
-
return Array.isArray(ws) ? JSON.stringify(ws) : ws;
|
|
728
|
-
};
|
|
729
|
-
var createPolkadotClient = function createPolkadotClient(ws, useLegacy) {
|
|
730
|
-
var options = useLegacy ? {
|
|
731
|
-
innerEnhancer: legacyProvider.withLegacy()
|
|
732
|
-
} : {};
|
|
733
|
-
var provider = wsProvider.getWsProvider(ws, options);
|
|
734
|
-
return polkadotApi.createClient(useLegacy ? provider : polkadotSdkCompat.withPolkadotSdkCompat(provider));
|
|
735
|
-
};
|
|
736
|
-
var leasePolkadotClient = function leasePolkadotClient(ws, ttlMs, useLegacy) {
|
|
737
|
-
var key = keyFromWs(ws);
|
|
738
|
-
var entry = clientPool.peek(key);
|
|
739
|
-
if (!entry) {
|
|
740
|
-
entry = {
|
|
741
|
-
client: createPolkadotClient(ws, useLegacy),
|
|
742
|
-
refs: 0,
|
|
743
|
-
destroyWanted: false
|
|
744
|
-
};
|
|
745
|
-
clientPool.set(key, entry, ttlMs);
|
|
746
|
-
}
|
|
747
|
-
entry.refs += 1;
|
|
748
|
-
clientPool.revive(key, ttlMs);
|
|
749
|
-
entry.destroyWanted = false;
|
|
750
|
-
return entry.client;
|
|
751
|
-
};
|
|
752
|
-
var releasePolkadotClient = function releasePolkadotClient(ws) {
|
|
753
|
-
var key = keyFromWs(ws);
|
|
754
|
-
var entry = clientPool.peek(key);
|
|
755
|
-
if (!entry) {
|
|
756
|
-
return;
|
|
757
|
-
}
|
|
758
|
-
entry.refs -= 1;
|
|
759
|
-
if (entry.refs === 0 && entry.destroyWanted) {
|
|
760
|
-
clientPool["delete"](key);
|
|
761
|
-
}
|
|
762
|
-
};
|
|
763
|
-
var isHex = function isHex(str) {
|
|
764
|
-
return typeof str === 'string' && /^0x[0-9a-fA-F]+$/.test(str);
|
|
765
|
-
};
|
|
766
|
-
var extractDryRunXcmFailureReason = function extractDryRunXcmFailureReason(result) {
|
|
767
|
-
var _result$value, _executionResult$valu, _ref, _ref2, _ref3, _error$error$type, _error$error, _error$value, _error$value2, _error$value3, _ref4, _result$value2;
|
|
768
|
-
var executionResult = result === null || result === void 0 || (_result$value = result.value) === null || _result$value === void 0 ? void 0 : _result$value.execution_result;
|
|
769
|
-
var error = executionResult === null || executionResult === void 0 || (_executionResult$valu = executionResult.value) === null || _executionResult$valu === void 0 ? void 0 : _executionResult$valu.error;
|
|
770
|
-
var failureType = (_ref = (_ref2 = (_ref3 = (_error$error$type = error === null || error === void 0 || (_error$error = error.error) === null || _error$error === void 0 ? void 0 : _error$error.type) !== null && _error$error$type !== void 0 ? _error$error$type : error === null || error === void 0 || (_error$value = error.value) === null || _error$value === void 0 || (_error$value = _error$value.error) === null || _error$value === void 0 ? void 0 : _error$value.type) !== null && _ref3 !== void 0 ? _ref3 : error === null || error === void 0 || (_error$value2 = error.value) === null || _error$value2 === void 0 || (_error$value2 = _error$value2.value) === null || _error$value2 === void 0 ? void 0 : _error$value2.type) !== null && _ref2 !== void 0 ? _ref2 : error === null || error === void 0 || (_error$value3 = error.value) === null || _error$value3 === void 0 ? void 0 : _error$value3.type) !== null && _ref !== void 0 ? _ref : error === null || error === void 0 ? void 0 : error.type;
|
|
771
|
-
if (typeof failureType === 'string') {
|
|
772
|
-
return failureType;
|
|
773
|
-
}
|
|
774
|
-
if (typeof (executionResult === null || executionResult === void 0 ? void 0 : executionResult.type) === 'string') {
|
|
775
|
-
return executionResult.type;
|
|
776
|
-
}
|
|
777
|
-
return JSON.stringify((_ref4 = (_result$value2 = result === null || result === void 0 ? void 0 : result.value) !== null && _result$value2 !== void 0 ? _result$value2 : result) !== null && _ref4 !== void 0 ? _ref4 : 'Unknown error structure', sdkCore.replaceBigInt);
|
|
778
|
-
};
|
|
779
|
-
var PapiApi = /*#__PURE__*/function () {
|
|
780
|
-
function PapiApi(config) {
|
|
781
|
-
_classCallCheck(this, PapiApi);
|
|
782
|
-
this._ttlMs = DEFAULT_TTL_MS;
|
|
783
|
-
this.initialized = false;
|
|
784
|
-
this.disconnectAllowed = true;
|
|
785
|
-
this._config = config;
|
|
786
|
-
}
|
|
787
|
-
return _createClass(PapiApi, [{
|
|
788
|
-
key: "getConfig",
|
|
789
|
-
value: function getConfig() {
|
|
790
|
-
return this._config;
|
|
791
|
-
}
|
|
792
|
-
}, {
|
|
793
|
-
key: "getApi",
|
|
794
|
-
value: function getApi() {
|
|
795
|
-
return this.api;
|
|
796
|
-
}
|
|
797
|
-
}, {
|
|
798
|
-
key: "init",
|
|
799
|
-
value: function () {
|
|
800
|
-
var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain) {
|
|
801
|
-
var clientTtlMs,
|
|
802
|
-
apiConfig,
|
|
803
|
-
_args = arguments;
|
|
804
|
-
return _regenerator().w(function (_context) {
|
|
805
|
-
while (1) switch (_context.n) {
|
|
806
|
-
case 0:
|
|
807
|
-
clientTtlMs = _args.length > 1 && _args[1] !== undefined ? _args[1] : DEFAULT_TTL_MS;
|
|
808
|
-
if (!(this.initialized || chain === 'Ethereum')) {
|
|
809
|
-
_context.n = 1;
|
|
810
|
-
break;
|
|
811
|
-
}
|
|
812
|
-
return _context.a(2);
|
|
813
|
-
case 1:
|
|
814
|
-
this._ttlMs = clientTtlMs;
|
|
815
|
-
this._chain = chain;
|
|
816
|
-
apiConfig = this.getApiConfigForChain(chain); // For development mode, api for each used chain must be provided
|
|
817
|
-
if (!(sdkCore.isConfig(this._config) && this._config.development && !apiConfig)) {
|
|
818
|
-
_context.n = 2;
|
|
819
|
-
break;
|
|
820
|
-
}
|
|
821
|
-
throw new sdkCore.MissingChainApiError(chain);
|
|
822
|
-
case 2:
|
|
823
|
-
_context.n = 3;
|
|
824
|
-
return this.resolveApi(apiConfig, chain);
|
|
825
|
-
case 3:
|
|
826
|
-
this.api = _context.v;
|
|
827
|
-
this.initialized = true;
|
|
828
|
-
case 4:
|
|
829
|
-
return _context.a(2);
|
|
830
|
-
}
|
|
831
|
-
}, _callee, this);
|
|
832
|
-
}));
|
|
833
|
-
function init(_x) {
|
|
834
|
-
return _init.apply(this, arguments);
|
|
835
|
-
}
|
|
836
|
-
return init;
|
|
837
|
-
}()
|
|
838
|
-
}, {
|
|
839
|
-
key: "getApiConfigForChain",
|
|
840
|
-
value: function getApiConfigForChain(chain) {
|
|
841
|
-
if (sdkCore.isConfig(this._config)) {
|
|
842
|
-
var _this$_config$apiOver;
|
|
843
|
-
return (_this$_config$apiOver = this._config.apiOverrides) === null || _this$_config$apiOver === void 0 ? void 0 : _this$_config$apiOver[chain];
|
|
844
|
-
}
|
|
845
|
-
return this._config;
|
|
846
|
-
}
|
|
847
|
-
}, {
|
|
848
|
-
key: "resolveApi",
|
|
849
|
-
value: function () {
|
|
850
|
-
var _resolveApi = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(apiConfig, chain) {
|
|
851
|
-
var wsUrl;
|
|
852
|
-
return _regenerator().w(function (_context2) {
|
|
853
|
-
while (1) switch (_context2.n) {
|
|
854
|
-
case 0:
|
|
855
|
-
if (apiConfig) {
|
|
856
|
-
_context2.n = 1;
|
|
857
|
-
break;
|
|
858
|
-
}
|
|
859
|
-
wsUrl = sdkCore.getChainProviders(chain);
|
|
860
|
-
return _context2.a(2, this.createApiInstance(wsUrl, chain));
|
|
861
|
-
case 1:
|
|
862
|
-
if (!(typeof apiConfig === 'string' || apiConfig instanceof Array)) {
|
|
863
|
-
_context2.n = 2;
|
|
864
|
-
break;
|
|
865
|
-
}
|
|
866
|
-
return _context2.a(2, this.createApiInstance(apiConfig, chain));
|
|
867
|
-
case 2:
|
|
868
|
-
return _context2.a(2, apiConfig);
|
|
869
|
-
}
|
|
870
|
-
}, _callee2, this);
|
|
871
|
-
}));
|
|
872
|
-
function resolveApi(_x2, _x3) {
|
|
873
|
-
return _resolveApi.apply(this, arguments);
|
|
874
|
-
}
|
|
875
|
-
return resolveApi;
|
|
876
|
-
}()
|
|
877
|
-
}, {
|
|
878
|
-
key: "createApiInstance",
|
|
879
|
-
value: function createApiInstance(wsUrl, chain) {
|
|
880
|
-
var useLegacy = LEGACY_CHAINS.includes(chain);
|
|
881
|
-
return Promise.resolve(leasePolkadotClient(wsUrl, this._ttlMs, useLegacy));
|
|
882
|
-
}
|
|
883
|
-
}, {
|
|
884
|
-
key: "accountToHex",
|
|
885
|
-
value: function accountToHex(address) {
|
|
886
|
-
var isPrefixed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
887
|
-
if (isHex(address)) return address;
|
|
888
|
-
var hex = polkadotApi.FixedSizeBinary.fromAccountId32(address).asHex();
|
|
889
|
-
return isPrefixed ? hex : hex.slice(2);
|
|
890
|
-
}
|
|
891
|
-
}, {
|
|
892
|
-
key: "accountToUint8a",
|
|
893
|
-
value: function accountToUint8a(address) {
|
|
894
|
-
var result = polkadotApi.getSs58AddressInfo(address);
|
|
895
|
-
if (!result.isValid) {
|
|
896
|
-
throw new sdkCore.InvalidAddressError("Invalid address: ".concat(address));
|
|
897
|
-
}
|
|
898
|
-
return result.publicKey;
|
|
899
|
-
}
|
|
900
|
-
}, {
|
|
901
|
-
key: "validateSubstrateAddress",
|
|
902
|
-
value: function validateSubstrateAddress(address) {
|
|
903
|
-
var result = polkadotApi.getSs58AddressInfo(address);
|
|
904
|
-
return result.isValid;
|
|
905
|
-
}
|
|
906
|
-
}, {
|
|
907
|
-
key: "deserializeExtrinsics",
|
|
908
|
-
value: function deserializeExtrinsics(_ref5) {
|
|
909
|
-
var module = _ref5.module,
|
|
910
|
-
method = _ref5.method,
|
|
911
|
-
params = _ref5.params;
|
|
912
|
-
var transformedParams = _transform(params);
|
|
913
|
-
return this.api.getUnsafeApi().tx[module][method](transformedParams);
|
|
914
|
-
}
|
|
915
|
-
}, {
|
|
916
|
-
key: "queryState",
|
|
917
|
-
value: function queryState(_ref6) {
|
|
918
|
-
var _this$api$getUnsafeAp;
|
|
919
|
-
var module = _ref6.module,
|
|
920
|
-
method = _ref6.method,
|
|
921
|
-
params = _ref6.params;
|
|
922
|
-
return (_this$api$getUnsafeAp = this.api.getUnsafeApi().query[module][method]).getValue.apply(_this$api$getUnsafeAp, _toConsumableArray(params.map(_transform)));
|
|
923
|
-
}
|
|
924
|
-
}, {
|
|
925
|
-
key: "queryRuntimeApi",
|
|
926
|
-
value: function queryRuntimeApi(_ref7) {
|
|
927
|
-
var _this$api$getUnsafeAp2;
|
|
928
|
-
var module = _ref7.module,
|
|
929
|
-
method = _ref7.method,
|
|
930
|
-
params = _ref7.params;
|
|
931
|
-
return (_this$api$getUnsafeAp2 = this.api.getUnsafeApi().apis[module])[method].apply(_this$api$getUnsafeAp2, _toConsumableArray(params.map(_transform)));
|
|
932
|
-
}
|
|
933
|
-
}, {
|
|
934
|
-
key: "callBatchMethod",
|
|
935
|
-
value: function callBatchMethod(calls, mode) {
|
|
936
|
-
var method = mode === sdkCore.BatchMode.BATCH_ALL ? 'batch_all' : 'batch';
|
|
937
|
-
return this.api.getUnsafeApi().tx.Utility[method]({
|
|
938
|
-
calls: calls.map(function (call) {
|
|
939
|
-
return call.decodedCall;
|
|
940
|
-
})
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
}, {
|
|
944
|
-
key: "callDispatchAsMethod",
|
|
945
|
-
value: function callDispatchAsMethod(call, address) {
|
|
946
|
-
var origin = {
|
|
947
|
-
type: 'system',
|
|
948
|
-
value: {
|
|
949
|
-
type: 'Signed',
|
|
950
|
-
value: address
|
|
951
|
-
}
|
|
952
|
-
};
|
|
953
|
-
return this.api.getUnsafeApi().tx.Utility.dispatch_as({
|
|
954
|
-
as_origin: origin,
|
|
955
|
-
call: call.decodedCall
|
|
956
|
-
});
|
|
957
|
-
}
|
|
958
|
-
}, {
|
|
959
|
-
key: "objectToHex",
|
|
960
|
-
value: function () {
|
|
961
|
-
var _objectToHex = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(obj) {
|
|
962
|
-
var transformedObj, tx, removeFirst5Bytes, encodedData;
|
|
963
|
-
return _regenerator().w(function (_context3) {
|
|
964
|
-
while (1) switch (_context3.n) {
|
|
965
|
-
case 0:
|
|
966
|
-
transformedObj = _transform(obj);
|
|
967
|
-
tx = this.api.getUnsafeApi().tx.PolkadotXcm.send({
|
|
968
|
-
dest: {
|
|
969
|
-
type: sdkCore.Version.V4,
|
|
970
|
-
value: {
|
|
971
|
-
parents: sdkCore.Parents.ZERO,
|
|
972
|
-
interior: {
|
|
973
|
-
type: 'Here'
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
},
|
|
977
|
-
message: transformedObj
|
|
978
|
-
});
|
|
979
|
-
removeFirst5Bytes = function removeFirst5Bytes(hexString) {
|
|
980
|
-
return '0x' + hexString.slice(12);
|
|
981
|
-
};
|
|
982
|
-
_context3.n = 1;
|
|
983
|
-
return tx.getEncodedData();
|
|
984
|
-
case 1:
|
|
985
|
-
encodedData = _context3.v;
|
|
986
|
-
return _context3.a(2, removeFirst5Bytes(encodedData.asHex()));
|
|
987
|
-
}
|
|
988
|
-
}, _callee3, this);
|
|
989
|
-
}));
|
|
990
|
-
function objectToHex(_x4) {
|
|
991
|
-
return _objectToHex.apply(this, arguments);
|
|
992
|
-
}
|
|
993
|
-
return objectToHex;
|
|
994
|
-
}()
|
|
995
|
-
}, {
|
|
996
|
-
key: "hexToUint8a",
|
|
997
|
-
value: function hexToUint8a(hex) {
|
|
998
|
-
return polkadotApi.Binary.fromHex(hex).asBytes();
|
|
999
|
-
}
|
|
1000
|
-
}, {
|
|
1001
|
-
key: "stringToUint8a",
|
|
1002
|
-
value: function stringToUint8a(str) {
|
|
1003
|
-
return polkadotApi.Binary.fromText(str).asBytes();
|
|
1004
|
-
}
|
|
1005
|
-
}, {
|
|
1006
|
-
key: "blake2AsHex",
|
|
1007
|
-
value: function blake2AsHex(data) {
|
|
1008
|
-
return "0x".concat(utils.bytesToHex(blake2.blake2b(data, {
|
|
1009
|
-
dkLen: 32
|
|
1010
|
-
})));
|
|
1011
|
-
}
|
|
1012
|
-
}, {
|
|
1013
|
-
key: "hasMethod",
|
|
1014
|
-
value: function () {
|
|
1015
|
-
var _hasMethod = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(pallet, method) {
|
|
1016
|
-
var _t;
|
|
1017
|
-
return _regenerator().w(function (_context4) {
|
|
1018
|
-
while (1) switch (_context4.p = _context4.n) {
|
|
1019
|
-
case 0:
|
|
1020
|
-
_context4.p = 0;
|
|
1021
|
-
_context4.n = 1;
|
|
1022
|
-
return this.api.getUnsafeApi().tx[pallet][method]().getEncodedData();
|
|
1023
|
-
case 1:
|
|
1024
|
-
return _context4.a(2, true);
|
|
1025
|
-
case 2:
|
|
1026
|
-
_context4.p = 2;
|
|
1027
|
-
_t = _context4.v;
|
|
1028
|
-
if (!(_t instanceof Error && _t.message.includes("Runtime entry Tx(".concat(pallet, ".").concat(method, ") not found")))) {
|
|
1029
|
-
_context4.n = 3;
|
|
1030
|
-
break;
|
|
1031
|
-
}
|
|
1032
|
-
return _context4.a(2, false);
|
|
1033
|
-
case 3:
|
|
1034
|
-
return _context4.a(2, true);
|
|
1035
|
-
}
|
|
1036
|
-
}, _callee4, this, [[0, 2]]);
|
|
1037
|
-
}));
|
|
1038
|
-
function hasMethod(_x5, _x6) {
|
|
1039
|
-
return _hasMethod.apply(this, arguments);
|
|
1040
|
-
}
|
|
1041
|
-
return hasMethod;
|
|
1042
|
-
}()
|
|
1043
|
-
}, {
|
|
1044
|
-
key: "getMethod",
|
|
1045
|
-
value: function getMethod(tx) {
|
|
1046
|
-
return tx.decodedCall.value.type;
|
|
1047
|
-
}
|
|
1048
|
-
}, {
|
|
1049
|
-
key: "getTypeThenAssetCount",
|
|
1050
|
-
value: function getTypeThenAssetCount(tx) {
|
|
1051
|
-
if (this.getMethod(tx) !== 'transfer_assets_using_type_and_then') return undefined;
|
|
1052
|
-
return tx.decodedCall.value.value.assets.value.length;
|
|
1053
|
-
}
|
|
1054
|
-
}, {
|
|
1055
|
-
key: "calculateTransactionFee",
|
|
1056
|
-
value: function () {
|
|
1057
|
-
var _calculateTransactionFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(tx, address) {
|
|
1058
|
-
return _regenerator().w(function (_context5) {
|
|
1059
|
-
while (1) switch (_context5.n) {
|
|
1060
|
-
case 0:
|
|
1061
|
-
return _context5.a(2, tx.getEstimatedFees(address));
|
|
1062
|
-
}
|
|
1063
|
-
}, _callee5);
|
|
1064
|
-
}));
|
|
1065
|
-
function calculateTransactionFee(_x7, _x8) {
|
|
1066
|
-
return _calculateTransactionFee.apply(this, arguments);
|
|
1067
|
-
}
|
|
1068
|
-
return calculateTransactionFee;
|
|
1069
|
-
}()
|
|
1070
|
-
}, {
|
|
1071
|
-
key: "quoteAhPrice",
|
|
1072
|
-
value: function () {
|
|
1073
|
-
var _quoteAhPrice = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(fromMl, toMl, amountIn) {
|
|
1074
|
-
var includeFee,
|
|
1075
|
-
transformedFromMl,
|
|
1076
|
-
transformedToMl,
|
|
1077
|
-
response,
|
|
1078
|
-
_args6 = arguments;
|
|
1079
|
-
return _regenerator().w(function (_context6) {
|
|
1080
|
-
while (1) switch (_context6.n) {
|
|
1081
|
-
case 0:
|
|
1082
|
-
includeFee = _args6.length > 3 && _args6[3] !== undefined ? _args6[3] : true;
|
|
1083
|
-
transformedFromMl = _transform(fromMl);
|
|
1084
|
-
transformedToMl = _transform(toMl);
|
|
1085
|
-
_context6.n = 1;
|
|
1086
|
-
return this.api.getUnsafeApi().apis.AssetConversionApi.quote_price_exact_tokens_for_tokens(transformedFromMl, transformedToMl, amountIn, includeFee);
|
|
1087
|
-
case 1:
|
|
1088
|
-
response = _context6.v;
|
|
1089
|
-
return _context6.a(2, response ? BigInt(response) : undefined);
|
|
1090
|
-
}
|
|
1091
|
-
}, _callee6, this);
|
|
1092
|
-
}));
|
|
1093
|
-
function quoteAhPrice(_x9, _x0, _x1) {
|
|
1094
|
-
return _quoteAhPrice.apply(this, arguments);
|
|
1095
|
-
}
|
|
1096
|
-
return quoteAhPrice;
|
|
1097
|
-
}()
|
|
1098
|
-
}, {
|
|
1099
|
-
key: "getEvmStorage",
|
|
1100
|
-
value: function getEvmStorage(contract, slot) {
|
|
1101
|
-
return this.api.getUnsafeApi().query.EVM.AccountStorages.getKey(polkadotApi.FixedSizeBinary.fromHex(contract), polkadotApi.FixedSizeBinary.fromHex(slot));
|
|
1102
|
-
}
|
|
1103
|
-
}, {
|
|
1104
|
-
key: "getFromRpc",
|
|
1105
|
-
value: function () {
|
|
1106
|
-
var _getFromRpc = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(module, method, key) {
|
|
1107
|
-
var toSS58, value;
|
|
1108
|
-
return _regenerator().w(function (_context7) {
|
|
1109
|
-
while (1) switch (_context7.n) {
|
|
1110
|
-
case 0:
|
|
1111
|
-
toSS58 = polkadotApi.AccountId().dec;
|
|
1112
|
-
_context7.n = 1;
|
|
1113
|
-
return this.api._request("".concat(module, "_").concat(method), [module === 'system' && isHex(key) && !viem.isAddress(key) ? toSS58(key) : key]);
|
|
1114
|
-
case 1:
|
|
1115
|
-
value = _context7.v;
|
|
1116
|
-
return _context7.a(2, isHex(value) ? value : '0x' + value.toString(16).padStart(8, '0'));
|
|
1117
|
-
}
|
|
1118
|
-
}, _callee7, this);
|
|
1119
|
-
}));
|
|
1120
|
-
function getFromRpc(_x10, _x11, _x12) {
|
|
1121
|
-
return _getFromRpc.apply(this, arguments);
|
|
1122
|
-
}
|
|
1123
|
-
return getFromRpc;
|
|
1124
|
-
}()
|
|
1125
|
-
}, {
|
|
1126
|
-
key: "clone",
|
|
1127
|
-
value: function clone() {
|
|
1128
|
-
return new PapiApi(sdkCore.isConfig(this._config) ? this._config : undefined);
|
|
1129
|
-
}
|
|
1130
|
-
}, {
|
|
1131
|
-
key: "createApiForChain",
|
|
1132
|
-
value: function () {
|
|
1133
|
-
var _createApiForChain = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(chain) {
|
|
1134
|
-
var api;
|
|
1135
|
-
return _regenerator().w(function (_context8) {
|
|
1136
|
-
while (1) switch (_context8.n) {
|
|
1137
|
-
case 0:
|
|
1138
|
-
api = new PapiApi();
|
|
1139
|
-
_context8.n = 1;
|
|
1140
|
-
return api.init(chain);
|
|
1141
|
-
case 1:
|
|
1142
|
-
return _context8.a(2, api);
|
|
1143
|
-
}
|
|
1144
|
-
}, _callee8);
|
|
1145
|
-
}));
|
|
1146
|
-
function createApiForChain(_x13) {
|
|
1147
|
-
return _createApiForChain.apply(this, arguments);
|
|
1148
|
-
}
|
|
1149
|
-
return createApiForChain;
|
|
1150
|
-
}()
|
|
1151
|
-
}, {
|
|
1152
|
-
key: "getDryRunCall",
|
|
1153
|
-
value: function () {
|
|
1154
|
-
var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(options) {
|
|
1155
|
-
var _this = this;
|
|
1156
|
-
var tx, chain, destination, address, feeAsset, bypassOptions, _options$useRootOrigi, useRootOrigin, supportsDryRunApi, DEFAULT_XCM_VERSION, basePayload, resolvedTx, performDryRunCall, getExecutionSuccessFromResult, findFailureObjectFromResult, extractFailureReasonFromResult, result, isSuccess, failureOutputReason, initialFailureReason, usedAsset, usedSymbol, actualWeight, weight, forwardedXcms, destParaId, nativeAsset, hasLocation, xcmFee, executionFee, fee, _t2;
|
|
1157
|
-
return _regenerator().w(function (_context0) {
|
|
1158
|
-
while (1) switch (_context0.n) {
|
|
1159
|
-
case 0:
|
|
1160
|
-
tx = options.tx, chain = options.chain, destination = options.destination, address = options.address, feeAsset = options.feeAsset, bypassOptions = options.bypassOptions, _options$useRootOrigi = options.useRootOrigin, useRootOrigin = _options$useRootOrigi === void 0 ? false : _options$useRootOrigi;
|
|
1161
|
-
supportsDryRunApi = sdkCore.getAssetsObject(chain).supportsDryRunApi;
|
|
1162
|
-
if (supportsDryRunApi) {
|
|
1163
|
-
_context0.n = 1;
|
|
1164
|
-
break;
|
|
1165
|
-
}
|
|
1166
|
-
throw new sdkCore.ChainNotSupportedError("DryRunApi is not available on chain ".concat(chain));
|
|
1167
|
-
case 1:
|
|
1168
|
-
DEFAULT_XCM_VERSION = 3;
|
|
1169
|
-
basePayload = {
|
|
1170
|
-
type: 'system',
|
|
1171
|
-
value: useRootOrigin ? {
|
|
1172
|
-
type: 'Root'
|
|
1173
|
-
} : {
|
|
1174
|
-
type: 'Signed',
|
|
1175
|
-
value: address
|
|
1176
|
-
}
|
|
1177
|
-
};
|
|
1178
|
-
if (!useRootOrigin) {
|
|
1179
|
-
_context0.n = 3;
|
|
1180
|
-
break;
|
|
1181
|
-
}
|
|
1182
|
-
_context0.n = 2;
|
|
1183
|
-
return sdkCore.wrapTxBypass(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
1184
|
-
api: this
|
|
1185
|
-
}), bypassOptions);
|
|
1186
|
-
case 2:
|
|
1187
|
-
_t2 = _context0.v;
|
|
1188
|
-
_context0.n = 4;
|
|
1189
|
-
break;
|
|
1190
|
-
case 3:
|
|
1191
|
-
_t2 = tx;
|
|
1192
|
-
case 4:
|
|
1193
|
-
resolvedTx = _t2;
|
|
1194
|
-
performDryRunCall = /*#__PURE__*/function () {
|
|
1195
|
-
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(includeVersion) {
|
|
1196
|
-
var _this$api$getUnsafeAp3;
|
|
1197
|
-
var callArgs;
|
|
1198
|
-
return _regenerator().w(function (_context9) {
|
|
1199
|
-
while (1) switch (_context9.n) {
|
|
1200
|
-
case 0:
|
|
1201
|
-
callArgs = [basePayload, resolvedTx.decodedCall];
|
|
1202
|
-
if (includeVersion) {
|
|
1203
|
-
callArgs.push(DEFAULT_XCM_VERSION);
|
|
1204
|
-
}
|
|
1205
|
-
return _context9.a(2, (_this$api$getUnsafeAp3 = _this.api.getUnsafeApi().apis.DryRunApi).dry_run_call.apply(_this$api$getUnsafeAp3, callArgs));
|
|
1206
|
-
}
|
|
1207
|
-
}, _callee9);
|
|
1208
|
-
}));
|
|
1209
|
-
return function performDryRunCall(_x15) {
|
|
1210
|
-
return _ref8.apply(this, arguments);
|
|
1211
|
-
};
|
|
1212
|
-
}();
|
|
1213
|
-
getExecutionSuccessFromResult = function getExecutionSuccessFromResult(result) {
|
|
1214
|
-
var _result$value3;
|
|
1215
|
-
var errorInEvents = findFailingEvent(result);
|
|
1216
|
-
return (result === null || result === void 0 ? void 0 : result.success) && ((_result$value3 = result.value) === null || _result$value3 === void 0 || (_result$value3 = _result$value3.execution_result) === null || _result$value3 === void 0 ? void 0 : _result$value3.success) && !errorInEvents;
|
|
1217
|
-
};
|
|
1218
|
-
findFailureObjectFromResult = function findFailureObjectFromResult(result) {
|
|
1219
|
-
var _result$value4, _executionResultValue, _executionResultValue2, _result$value5;
|
|
1220
|
-
var executionResultValue = result === null || result === void 0 || (_result$value4 = result.value) === null || _result$value4 === void 0 || (_result$value4 = _result$value4.execution_result) === null || _result$value4 === void 0 ? void 0 : _result$value4.value;
|
|
1221
|
-
if (executionResultValue !== null && executionResultValue !== void 0 && (_executionResultValue = executionResultValue.error) !== null && _executionResultValue !== void 0 && (_executionResultValue = _executionResultValue.value) !== null && _executionResultValue !== void 0 && (_executionResultValue = _executionResultValue.value) !== null && _executionResultValue !== void 0 && _executionResultValue.type) {
|
|
1222
|
-
return executionResultValue.error.value.value;
|
|
1223
|
-
}
|
|
1224
|
-
if (executionResultValue !== null && executionResultValue !== void 0 && (_executionResultValue2 = executionResultValue.error) !== null && _executionResultValue2 !== void 0 && (_executionResultValue2 = _executionResultValue2.value) !== null && _executionResultValue2 !== void 0 && _executionResultValue2.type) {
|
|
1225
|
-
return executionResultValue.error.value;
|
|
1226
|
-
}
|
|
1227
|
-
if (result !== null && result !== void 0 && (_result$value5 = result.value) !== null && _result$value5 !== void 0 && _result$value5.type) {
|
|
1228
|
-
return result.value;
|
|
1229
|
-
}
|
|
1230
|
-
var erroredEvent = findFailingEvent(result);
|
|
1231
|
-
if (erroredEvent) {
|
|
1232
|
-
var _result$value$value$v;
|
|
1233
|
-
var _result = erroredEvent.value.value.result;
|
|
1234
|
-
return (_result$value$value$v = _result.value.value.value) !== null && _result$value$value$v !== void 0 ? _result$value$value$v : _result.value.value;
|
|
1235
|
-
}
|
|
1236
|
-
return result;
|
|
1237
|
-
};
|
|
1238
|
-
extractFailureReasonFromResult = function extractFailureReasonFromResult(result) {
|
|
1239
|
-
var _obj$value, _ref9, _result$value6;
|
|
1240
|
-
var obj = findFailureObjectFromResult(result);
|
|
1241
|
-
if (obj !== null && obj !== void 0 && obj.type && obj !== null && obj !== void 0 && (_obj$value = obj.value) !== null && _obj$value !== void 0 && (_obj$value = _obj$value.error) !== null && _obj$value !== void 0 && _obj$value.type) {
|
|
1242
|
-
return {
|
|
1243
|
-
failureReason: obj.type,
|
|
1244
|
-
failureSubReason: obj.value.error.type
|
|
1245
|
-
};
|
|
1246
|
-
}
|
|
1247
|
-
if (obj !== null && obj !== void 0 && obj.type) {
|
|
1248
|
-
return {
|
|
1249
|
-
failureReason: obj.type
|
|
1250
|
-
};
|
|
1251
|
-
}
|
|
1252
|
-
return {
|
|
1253
|
-
failureReason: JSON.stringify((_ref9 = (_result$value6 = result === null || result === void 0 ? void 0 : result.value) !== null && _result$value6 !== void 0 ? _result$value6 : result) !== null && _ref9 !== void 0 ? _ref9 : 'Unknown error structure', sdkCore.replaceBigInt)
|
|
1254
|
-
};
|
|
1255
|
-
};
|
|
1256
|
-
failureOutputReason = {
|
|
1257
|
-
failureReason: ''
|
|
1258
|
-
};
|
|
1259
|
-
_context0.n = 5;
|
|
1260
|
-
return performDryRunCall(false);
|
|
1261
|
-
case 5:
|
|
1262
|
-
result = _context0.v;
|
|
1263
|
-
isSuccess = getExecutionSuccessFromResult(result);
|
|
1264
|
-
if (isSuccess) {
|
|
1265
|
-
_context0.n = 7;
|
|
1266
|
-
break;
|
|
1267
|
-
}
|
|
1268
|
-
initialFailureReason = extractFailureReasonFromResult(result);
|
|
1269
|
-
failureOutputReason = initialFailureReason;
|
|
1270
|
-
if (!(initialFailureReason.failureReason === 'VersionedConversionFailed')) {
|
|
1271
|
-
_context0.n = 7;
|
|
1272
|
-
break;
|
|
1273
|
-
}
|
|
1274
|
-
_context0.n = 6;
|
|
1275
|
-
return performDryRunCall(true);
|
|
1276
|
-
case 6:
|
|
1277
|
-
result = _context0.v;
|
|
1278
|
-
isSuccess = getExecutionSuccessFromResult(result);
|
|
1279
|
-
if (!isSuccess) {
|
|
1280
|
-
failureOutputReason = extractFailureReasonFromResult(result);
|
|
1281
|
-
} else {
|
|
1282
|
-
failureOutputReason = {
|
|
1283
|
-
failureReason: '',
|
|
1284
|
-
failureSubReason: undefined
|
|
1285
|
-
};
|
|
1286
|
-
}
|
|
1287
|
-
case 7:
|
|
1288
|
-
usedAsset = feeAsset !== null && feeAsset !== void 0 ? feeAsset : sdkCore.findNativeAssetInfoOrThrow(chain);
|
|
1289
|
-
usedSymbol = usedAsset.symbol;
|
|
1290
|
-
if (isSuccess) {
|
|
1291
|
-
_context0.n = 8;
|
|
1292
|
-
break;
|
|
1293
|
-
}
|
|
1294
|
-
return _context0.a(2, Promise.resolve({
|
|
1295
|
-
success: false,
|
|
1296
|
-
failureReason: failureOutputReason.failureReason,
|
|
1297
|
-
failureSubReason: failureOutputReason.failureSubReason,
|
|
1298
|
-
currency: usedSymbol,
|
|
1299
|
-
asset: usedAsset
|
|
1300
|
-
}));
|
|
1301
|
-
case 8:
|
|
1302
|
-
actualWeight = result.value.execution_result.value.actual_weight;
|
|
1303
|
-
weight = actualWeight ? {
|
|
1304
|
-
refTime: actualWeight.ref_time,
|
|
1305
|
-
proofSize: actualWeight.proof_size
|
|
1306
|
-
} : undefined;
|
|
1307
|
-
forwardedXcms = result.value.forwarded_xcms.length > 0 ? result.value.forwarded_xcms[0] : [];
|
|
1308
|
-
destParaId = forwardedXcms.length === 0 ? undefined : forwardedXcms[0].value.interior.type === 'Here' ? 0 : forwardedXcms[0].value.interior.value.value;
|
|
1309
|
-
nativeAsset = sdkCore.findNativeAssetInfoOrThrow(chain);
|
|
1310
|
-
hasLocation = feeAsset ? Boolean(feeAsset.location) : Boolean(nativeAsset === null || nativeAsset === void 0 ? void 0 : nativeAsset.location);
|
|
1311
|
-
if (!(sdkCore.hasXcmPaymentApiSupport(chain) && result.value.local_xcm && hasLocation && (feeAsset || chain.startsWith('AssetHub') && destination === 'Ethereum'))) {
|
|
1312
|
-
_context0.n = 10;
|
|
1313
|
-
break;
|
|
1314
|
-
}
|
|
1315
|
-
_context0.n = 9;
|
|
1316
|
-
return this.getXcmPaymentApiFee(chain, result.value.local_xcm, forwardedXcms, feeAsset !== null && feeAsset !== void 0 ? feeAsset : nativeAsset);
|
|
1317
|
-
case 9:
|
|
1318
|
-
xcmFee = _context0.v;
|
|
1319
|
-
if (!(typeof xcmFee === 'bigint')) {
|
|
1320
|
-
_context0.n = 10;
|
|
1321
|
-
break;
|
|
1322
|
-
}
|
|
1323
|
-
return _context0.a(2, Promise.resolve({
|
|
1324
|
-
success: true,
|
|
1325
|
-
fee: xcmFee,
|
|
1326
|
-
currency: usedSymbol,
|
|
1327
|
-
asset: usedAsset,
|
|
1328
|
-
weight: weight,
|
|
1329
|
-
forwardedXcms: forwardedXcms,
|
|
1330
|
-
destParaId: destParaId
|
|
1331
|
-
}));
|
|
1332
|
-
case 10:
|
|
1333
|
-
_context0.n = 11;
|
|
1334
|
-
return this.calculateTransactionFee(tx, address);
|
|
1335
|
-
case 11:
|
|
1336
|
-
executionFee = _context0.v;
|
|
1337
|
-
fee = sdkCore.computeFeeFromDryRun(result, chain, executionFee, !!feeAsset);
|
|
1338
|
-
return _context0.a(2, Promise.resolve({
|
|
1339
|
-
success: true,
|
|
1340
|
-
fee: fee,
|
|
1341
|
-
currency: usedSymbol,
|
|
1342
|
-
asset: usedAsset,
|
|
1343
|
-
weight: weight,
|
|
1344
|
-
forwardedXcms: forwardedXcms,
|
|
1345
|
-
destParaId: destParaId
|
|
1346
|
-
}));
|
|
1347
|
-
}
|
|
1348
|
-
}, _callee0, this);
|
|
1349
|
-
}));
|
|
1350
|
-
function getDryRunCall(_x14) {
|
|
1351
|
-
return _getDryRunCall.apply(this, arguments);
|
|
1352
|
-
}
|
|
1353
|
-
return getDryRunCall;
|
|
1354
|
-
}()
|
|
1355
|
-
}, {
|
|
1356
|
-
key: "getXcmWeight",
|
|
1357
|
-
value: function () {
|
|
1358
|
-
var _getXcmWeight = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(xcm) {
|
|
1359
|
-
var weightResult, _weightResult$value, ref_time, proof_size;
|
|
1360
|
-
return _regenerator().w(function (_context1) {
|
|
1361
|
-
while (1) switch (_context1.n) {
|
|
1362
|
-
case 0:
|
|
1363
|
-
_context1.n = 1;
|
|
1364
|
-
return this.api.getUnsafeApi().apis.XcmPaymentApi.query_xcm_weight(!xcm.type ? _transform(xcm) : xcm);
|
|
1365
|
-
case 1:
|
|
1366
|
-
weightResult = _context1.v;
|
|
1367
|
-
_weightResult$value = weightResult.value, ref_time = _weightResult$value.ref_time, proof_size = _weightResult$value.proof_size;
|
|
1368
|
-
return _context1.a(2, {
|
|
1369
|
-
refTime: ref_time,
|
|
1370
|
-
proofSize: proof_size
|
|
1371
|
-
});
|
|
1372
|
-
}
|
|
1373
|
-
}, _callee1, this);
|
|
1374
|
-
}));
|
|
1375
|
-
function getXcmWeight(_x16) {
|
|
1376
|
-
return _getXcmWeight.apply(this, arguments);
|
|
1377
|
-
}
|
|
1378
|
-
return getXcmWeight;
|
|
1379
|
-
}()
|
|
1380
|
-
}, {
|
|
1381
|
-
key: "getXcmPaymentApiFee",
|
|
1382
|
-
value: function () {
|
|
1383
|
-
var _getXcmPaymentApiFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(chain, localXcm, forwardedXcm, asset) {
|
|
1384
|
-
var _deliveryFeeRes$value, _deliveryFeeRes$value2;
|
|
1385
|
-
var transformXcm,
|
|
1386
|
-
transformedXcm,
|
|
1387
|
-
weight,
|
|
1388
|
-
assetLocalizedLoc,
|
|
1389
|
-
transformedAssetLoc,
|
|
1390
|
-
execFeeRes,
|
|
1391
|
-
deliveryFeeRes,
|
|
1392
|
-
deliveryFeeResolved,
|
|
1393
|
-
nativeAsset,
|
|
1394
|
-
deliveryFee,
|
|
1395
|
-
res,
|
|
1396
|
-
_args10 = arguments,
|
|
1397
|
-
_t3,
|
|
1398
|
-
_t4;
|
|
1399
|
-
return _regenerator().w(function (_context10) {
|
|
1400
|
-
while (1) switch (_context10.p = _context10.n) {
|
|
1401
|
-
case 0:
|
|
1402
|
-
transformXcm = _args10.length > 4 && _args10[4] !== undefined ? _args10[4] : false;
|
|
1403
|
-
transformedXcm = transformXcm ? _transform(localXcm) : localXcm;
|
|
1404
|
-
_context10.n = 1;
|
|
1405
|
-
return this.api.getUnsafeApi().apis.XcmPaymentApi.query_xcm_weight(transformedXcm);
|
|
1406
|
-
case 1:
|
|
1407
|
-
weight = _context10.v;
|
|
1408
|
-
sdkCore.assertHasLocation(asset);
|
|
1409
|
-
assetLocalizedLoc = sdkCore.localizeLocation(chain, asset.location);
|
|
1410
|
-
transformedAssetLoc = _transform(assetLocalizedLoc);
|
|
1411
|
-
_context10.n = 2;
|
|
1412
|
-
return this.api.getUnsafeApi().apis.XcmPaymentApi.query_weight_to_asset_fee(weight.value, {
|
|
1413
|
-
type: sdkCore.Version.V4,
|
|
1414
|
-
value: transformedAssetLoc
|
|
1415
|
-
});
|
|
1416
|
-
case 2:
|
|
1417
|
-
execFeeRes = _context10.v;
|
|
1418
|
-
if (!(forwardedXcm.length > 0)) {
|
|
1419
|
-
_context10.n = 4;
|
|
1420
|
-
break;
|
|
1421
|
-
}
|
|
1422
|
-
_context10.n = 3;
|
|
1423
|
-
return this.api.getUnsafeApi().apis.XcmPaymentApi.query_delivery_fees(forwardedXcm[0], forwardedXcm[1][0]);
|
|
1424
|
-
case 3:
|
|
1425
|
-
_t3 = _context10.v;
|
|
1426
|
-
_context10.n = 5;
|
|
1427
|
-
break;
|
|
1428
|
-
case 4:
|
|
1429
|
-
_t3 = undefined;
|
|
1430
|
-
case 5:
|
|
1431
|
-
deliveryFeeRes = _t3;
|
|
1432
|
-
deliveryFeeResolved = (deliveryFeeRes === null || deliveryFeeRes === void 0 || (_deliveryFeeRes$value = deliveryFeeRes.value) === null || _deliveryFeeRes$value === void 0 ? void 0 : _deliveryFeeRes$value.value.length) > 0 ? deliveryFeeRes === null || deliveryFeeRes === void 0 || (_deliveryFeeRes$value2 = deliveryFeeRes.value) === null || _deliveryFeeRes$value2 === void 0 ? void 0 : _deliveryFeeRes$value2.value[0].fun.value : 0n;
|
|
1433
|
-
nativeAsset = sdkCore.findNativeAssetInfoOrThrow(chain);
|
|
1434
|
-
if (!sdkCore.isAssetXcEqual(asset, nativeAsset)) {
|
|
1435
|
-
_context10.n = 6;
|
|
1436
|
-
break;
|
|
1437
|
-
}
|
|
1438
|
-
deliveryFee = deliveryFeeResolved;
|
|
1439
|
-
_context10.n = 9;
|
|
1440
|
-
break;
|
|
1441
|
-
case 6:
|
|
1442
|
-
_context10.p = 6;
|
|
1443
|
-
sdkCore.assertHasLocation(nativeAsset);
|
|
1444
|
-
_context10.n = 7;
|
|
1445
|
-
return this.quoteAhPrice(sdkCore.localizeLocation(chain, nativeAsset.location), assetLocalizedLoc, deliveryFeeResolved, false);
|
|
1446
|
-
case 7:
|
|
1447
|
-
res = _context10.v;
|
|
1448
|
-
deliveryFee = res !== null && res !== void 0 ? res : 0n;
|
|
1449
|
-
_context10.n = 9;
|
|
1450
|
-
break;
|
|
1451
|
-
case 8:
|
|
1452
|
-
_context10.p = 8;
|
|
1453
|
-
_t4 = _context10.v;
|
|
1454
|
-
if (_t4 instanceof Error && /Runtime entry RuntimeCall\(.+\) not found/.test(_t4.message)) {
|
|
1455
|
-
deliveryFee = 0n;
|
|
1456
|
-
} else {
|
|
1457
|
-
deliveryFee = 0n;
|
|
1458
|
-
}
|
|
1459
|
-
case 9:
|
|
1460
|
-
return _context10.a(2, execFeeRes.value + deliveryFee);
|
|
1461
|
-
}
|
|
1462
|
-
}, _callee10, this, [[6, 8]]);
|
|
1463
|
-
}));
|
|
1464
|
-
function getXcmPaymentApiFee(_x17, _x18, _x19, _x20) {
|
|
1465
|
-
return _getXcmPaymentApiFee.apply(this, arguments);
|
|
1466
|
-
}
|
|
1467
|
-
return getXcmPaymentApiFee;
|
|
1468
|
-
}()
|
|
1469
|
-
}, {
|
|
1470
|
-
key: "getDryRunXcm",
|
|
1471
|
-
value: function () {
|
|
1472
|
-
var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(_ref0) {
|
|
1473
|
-
var _ref1, _processAssetsDeposit, _ref10, _ref11, _ref12, _ref13, _ref14;
|
|
1474
|
-
var originLocation, xcm, chain, origin, asset, feeAsset, originFee, amount, supportsDryRunApi, transformedOriginLocation, result, symbol, isSuccess, failureReason, actualWeight, weight, forwardedXcms, destParaId, _fee, emitted, reversedEvents, palletsWithIssued, isFeeAsset, feeAssetFeeEvent, processedAssetsAmount, feeEvent, fee, processedFee;
|
|
1475
|
-
return _regenerator().w(function (_context11) {
|
|
1476
|
-
while (1) switch (_context11.n) {
|
|
1477
|
-
case 0:
|
|
1478
|
-
originLocation = _ref0.originLocation, xcm = _ref0.xcm, chain = _ref0.chain, origin = _ref0.origin, asset = _ref0.asset, feeAsset = _ref0.feeAsset, originFee = _ref0.originFee, amount = _ref0.amount;
|
|
1479
|
-
supportsDryRunApi = sdkCore.getAssetsObject(chain).supportsDryRunApi;
|
|
1480
|
-
if (supportsDryRunApi) {
|
|
1481
|
-
_context11.n = 1;
|
|
1482
|
-
break;
|
|
1483
|
-
}
|
|
1484
|
-
throw new sdkCore.ChainNotSupportedError("DryRunApi is not available on chain ".concat(chain));
|
|
1485
|
-
case 1:
|
|
1486
|
-
transformedOriginLocation = _transform(originLocation);
|
|
1487
|
-
_context11.n = 2;
|
|
1488
|
-
return this.api.getUnsafeApi().apis.DryRunApi.dry_run_xcm(transformedOriginLocation, xcm);
|
|
1489
|
-
case 2:
|
|
1490
|
-
result = _context11.v;
|
|
1491
|
-
symbol = asset.symbol;
|
|
1492
|
-
isSuccess = result.success && result.value.execution_result.type === 'Complete';
|
|
1493
|
-
if (isSuccess) {
|
|
1494
|
-
_context11.n = 3;
|
|
1495
|
-
break;
|
|
1496
|
-
}
|
|
1497
|
-
failureReason = extractDryRunXcmFailureReason(result);
|
|
1498
|
-
return _context11.a(2, {
|
|
1499
|
-
success: false,
|
|
1500
|
-
failureReason: failureReason,
|
|
1501
|
-
currency: symbol,
|
|
1502
|
-
asset: asset
|
|
1503
|
-
});
|
|
1504
|
-
case 3:
|
|
1505
|
-
actualWeight = result.value.execution_result.value.used;
|
|
1506
|
-
weight = actualWeight ? {
|
|
1507
|
-
refTime: actualWeight.ref_time,
|
|
1508
|
-
proofSize: actualWeight.proof_size
|
|
1509
|
-
} : undefined;
|
|
1510
|
-
forwardedXcms = result.value.forwarded_xcms.length > 0 ? result.value.forwarded_xcms[0] : [];
|
|
1511
|
-
destParaId = forwardedXcms.length === 0 ? undefined : forwardedXcms[0].value.interior.type === 'Here' ? 0 : forwardedXcms[0].value.interior.value.value;
|
|
1512
|
-
if (!(sdkCore.hasXcmPaymentApiSupport(chain) && asset)) {
|
|
1513
|
-
_context11.n = 5;
|
|
1514
|
-
break;
|
|
1515
|
-
}
|
|
1516
|
-
_context11.n = 4;
|
|
1517
|
-
return this.getXcmPaymentApiFee(chain, xcm, forwardedXcms, asset);
|
|
1518
|
-
case 4:
|
|
1519
|
-
_fee = _context11.v;
|
|
1520
|
-
if (!(typeof _fee === 'bigint')) {
|
|
1521
|
-
_context11.n = 5;
|
|
1522
|
-
break;
|
|
1523
|
-
}
|
|
1524
|
-
return _context11.a(2, {
|
|
1525
|
-
success: true,
|
|
1526
|
-
fee: _fee,
|
|
1527
|
-
currency: symbol,
|
|
1528
|
-
asset: asset,
|
|
1529
|
-
weight: weight,
|
|
1530
|
-
forwardedXcms: forwardedXcms,
|
|
1531
|
-
destParaId: destParaId
|
|
1532
|
-
});
|
|
1533
|
-
case 5:
|
|
1534
|
-
emitted = result.value.emitted_events; // We want to look for the last event
|
|
1535
|
-
reversedEvents = _toConsumableArray(emitted).reverse();
|
|
1536
|
-
palletsWithIssued = ['Balances', 'ForeignAssets', 'Assets'];
|
|
1537
|
-
isFeeAsset = origin === 'AssetHubPolkadot' && feeAsset && asset && sdkCore.isAssetEqual(feeAsset, asset);
|
|
1538
|
-
feeAssetFeeEvent = (_ref1 = isFeeAsset ? _toConsumableArray(emitted).find(function (event) {
|
|
1539
|
-
return (event.type === 'ForeignAssets' || event.type === 'Assets') && event.value.type === 'Issued';
|
|
1540
|
-
}) : undefined) !== null && _ref1 !== void 0 ? _ref1 : isFeeAsset ? _toConsumableArray(emitted).find(function (event) {
|
|
1541
|
-
return event.type === 'Tokens' && event.value.type === 'Deposited';
|
|
1542
|
-
}) : undefined;
|
|
1543
|
-
processedAssetsAmount = chain === 'AssetHubPolkadot' && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== 'DOT' ? processAssetsDepositedEvents(emitted, amount, 'Assets', 'Deposited', true) : (_processAssetsDeposit = processAssetsDepositedEvents(emitted, amount, 'Balances', 'Minted', false)) !== null && _processAssetsDeposit !== void 0 ? _processAssetsDeposit : processAssetsDepositedEvents(emitted, amount, 'Balances', 'Issued', false);
|
|
1544
|
-
feeEvent = (_ref10 = (_ref11 = (_ref12 = (_ref13 = (_ref14 = feeAssetFeeEvent !== null && feeAssetFeeEvent !== void 0 ? feeAssetFeeEvent :
|
|
1545
|
-
//
|
|
1546
|
-
processedAssetsAmount !== undefined ? {
|
|
1547
|
-
type: 'Assets',
|
|
1548
|
-
value: {
|
|
1549
|
-
type: 'Deposited',
|
|
1550
|
-
value: {
|
|
1551
|
-
amount: processedAssetsAmount
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
} : undefined) !== null && _ref14 !== void 0 ? _ref14 :
|
|
1555
|
-
//
|
|
1556
|
-
chain === 'Mythos' ? reversedEvents.find(function (event) {
|
|
1557
|
-
return event.type === 'Balances' && event.value.type === 'Issued';
|
|
1558
|
-
}) : undefined) !== null && _ref13 !== void 0 ? _ref13 :
|
|
1559
|
-
//
|
|
1560
|
-
origin === 'Mythos' || chain === 'AssetHubPolkadot' && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== 'DOT' ? reversedEvents.find(function (event) {
|
|
1561
|
-
return event.type === 'AssetConversion' && event.value.type === 'SwapCreditExecuted';
|
|
1562
|
-
}) : undefined) !== null && _ref12 !== void 0 ? _ref12 :
|
|
1563
|
-
// Prefer to Minted event
|
|
1564
|
-
reversedEvents.find(function (event) {
|
|
1565
|
-
return ['Balances', 'ForeignAssets'].includes(event.type) && event.value.type === 'Minted';
|
|
1566
|
-
})) !== null && _ref11 !== void 0 ? _ref11 :
|
|
1567
|
-
// Fallback an Issued event
|
|
1568
|
-
reversedEvents.find(function (event) {
|
|
1569
|
-
return palletsWithIssued.includes(event.type) && event.value.type === 'Issued';
|
|
1570
|
-
})) !== null && _ref10 !== void 0 ? _ref10 : reversedEvents.find(function (event) {
|
|
1571
|
-
return ['Currencies', 'Tokens'].includes(event.type) && event.value.type === 'Deposited';
|
|
1572
|
-
});
|
|
1573
|
-
if (feeEvent) {
|
|
1574
|
-
_context11.n = 6;
|
|
1575
|
-
break;
|
|
1576
|
-
}
|
|
1577
|
-
return _context11.a(2, Promise.resolve({
|
|
1578
|
-
success: false,
|
|
1579
|
-
failureReason: 'Cannot determine destination fee. No fee event found',
|
|
1580
|
-
currency: symbol,
|
|
1581
|
-
asset: asset
|
|
1582
|
-
}));
|
|
1583
|
-
case 6:
|
|
1584
|
-
fee = feeEvent.type === 'AssetConversion' ? feeEvent.value.value.amount_in : feeEvent.value.value.amount;
|
|
1585
|
-
if (feeAssetFeeEvent) {
|
|
1586
|
-
fee = amount - originFee - feeEvent.value.value.amount;
|
|
1587
|
-
}
|
|
1588
|
-
processedFee = (sdkCore.isRelayChain(chain) || chain.includes('AssetHub')) && (asset === null || asset === void 0 ? void 0 : asset.symbol) === 'DOT' ? sdkCore.padValueBy(fee, 30) : fee;
|
|
1589
|
-
return _context11.a(2, Promise.resolve({
|
|
1590
|
-
success: true,
|
|
1591
|
-
fee: processedFee,
|
|
1592
|
-
currency: symbol,
|
|
1593
|
-
asset: asset,
|
|
1594
|
-
weight: weight,
|
|
1595
|
-
forwardedXcms: forwardedXcms,
|
|
1596
|
-
destParaId: destParaId
|
|
1597
|
-
}));
|
|
1598
|
-
}
|
|
1599
|
-
}, _callee11, this);
|
|
1600
|
-
}));
|
|
1601
|
-
function getDryRunXcm(_x21) {
|
|
1602
|
-
return _getDryRunXcm.apply(this, arguments);
|
|
1603
|
-
}
|
|
1604
|
-
return getDryRunXcm;
|
|
1605
|
-
}()
|
|
1606
|
-
}, {
|
|
1607
|
-
key: "getBridgeStatus",
|
|
1608
|
-
value: function () {
|
|
1609
|
-
var _getBridgeStatus = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
|
|
1610
|
-
var outboundOperatingMode;
|
|
1611
|
-
return _regenerator().w(function (_context12) {
|
|
1612
|
-
while (1) switch (_context12.n) {
|
|
1613
|
-
case 0:
|
|
1614
|
-
_context12.n = 1;
|
|
1615
|
-
return this.api.getUnsafeApi().query.EthereumOutboundQueue.OperatingMode.getValue();
|
|
1616
|
-
case 1:
|
|
1617
|
-
outboundOperatingMode = _context12.v;
|
|
1618
|
-
return _context12.a(2, outboundOperatingMode.type);
|
|
1619
|
-
}
|
|
1620
|
-
}, _callee12, this);
|
|
1621
|
-
}));
|
|
1622
|
-
function getBridgeStatus() {
|
|
1623
|
-
return _getBridgeStatus.apply(this, arguments);
|
|
1624
|
-
}
|
|
1625
|
-
return getBridgeStatus;
|
|
1626
|
-
}()
|
|
1627
|
-
}, {
|
|
1628
|
-
key: "setDisconnectAllowed",
|
|
1629
|
-
value: function setDisconnectAllowed(allowed) {
|
|
1630
|
-
this.disconnectAllowed = allowed;
|
|
1631
|
-
}
|
|
1632
|
-
}, {
|
|
1633
|
-
key: "getDisconnectAllowed",
|
|
1634
|
-
value: function getDisconnectAllowed() {
|
|
1635
|
-
return this.disconnectAllowed;
|
|
1636
|
-
}
|
|
1637
|
-
}, {
|
|
1638
|
-
key: "disconnect",
|
|
1639
|
-
value: function disconnect() {
|
|
1640
|
-
var _this$_config$apiOver2;
|
|
1641
|
-
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1642
|
-
if (!this.initialized) return Promise.resolve();
|
|
1643
|
-
if (!force && !this.disconnectAllowed) return Promise.resolve();
|
|
1644
|
-
var 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;
|
|
1645
|
-
// Own client provided, destroy only if force true
|
|
1646
|
-
if (force && _typeof(api) === 'object') {
|
|
1647
|
-
this.api.destroy();
|
|
1648
|
-
}
|
|
1649
|
-
// Client created automatically
|
|
1650
|
-
if (typeof api === 'string' || Array.isArray(api) || api === undefined) {
|
|
1651
|
-
if (force) {
|
|
1652
|
-
this.api.destroy();
|
|
1653
|
-
} else {
|
|
1654
|
-
var key = api === undefined ? sdkCore.getChainProviders(this._chain) : api;
|
|
1655
|
-
releasePolkadotClient(key);
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
return Promise.resolve();
|
|
1659
|
-
}
|
|
1660
|
-
}]);
|
|
1661
|
-
}();
|
|
1662
|
-
|
|
1663
|
-
var createChainClient = function createChainClient(chain, api) {
|
|
1664
|
-
var papiApi = new PapiApi(api);
|
|
1665
|
-
return sdkCore.createChainClient(papiApi, chain);
|
|
1666
|
-
};
|
|
1667
|
-
var createPapiApiCall = function createPapiApiCall(apiCall) {
|
|
1668
|
-
return /*#__PURE__*/function () {
|
|
1669
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
1670
|
-
var papiApi, optionsWithApi;
|
|
1671
|
-
return _regenerator().w(function (_context) {
|
|
1672
|
-
while (1) switch (_context.n) {
|
|
1673
|
-
case 0:
|
|
1674
|
-
papiApi = new PapiApi(options.api);
|
|
1675
|
-
optionsWithApi = _objectSpread2(_objectSpread2({}, options), {}, {
|
|
1676
|
-
api: papiApi
|
|
1677
|
-
});
|
|
1678
|
-
return _context.a(2, apiCall(optionsWithApi));
|
|
1679
|
-
}
|
|
1680
|
-
}, _callee);
|
|
1681
|
-
}));
|
|
1682
|
-
return function (_x) {
|
|
1683
|
-
return _ref.apply(this, arguments);
|
|
1684
|
-
};
|
|
1685
|
-
}();
|
|
1686
|
-
};
|
|
1687
|
-
var findFailingEvent = function findFailingEvent(result) {
|
|
1688
|
-
var _result$value;
|
|
1689
|
-
return (_result$value = result.value) === null || _result$value === void 0 || (_result$value = _result$value.emitted_events) === null || _result$value === void 0 ? void 0 : _result$value.find(function (event) {
|
|
1690
|
-
return event.type === 'Utility' && event.value.type === 'DispatchedAs' && event.value.value.result.success === false;
|
|
1691
|
-
});
|
|
1692
|
-
};
|
|
1693
|
-
|
|
1694
|
-
/**
|
|
1695
|
-
* Retrieves the native balance for a given account on a specified chain.
|
|
1696
|
-
*
|
|
1697
|
-
* @returns The native balance as a bigint.
|
|
1698
|
-
*/
|
|
1699
|
-
var getBalanceNative = createPapiApiCall(sdkCore.getBalanceNative);
|
|
1700
|
-
/**
|
|
1701
|
-
* Retrieves the balance of a foreign asset for a given account on a specified chain.
|
|
1702
|
-
*
|
|
1703
|
-
* @returns The balance of the foreign asset as a bigint, or null if not found.
|
|
1704
|
-
*/
|
|
1705
|
-
var getBalanceForeign = createPapiApiCall(sdkCore.getBalance);
|
|
1706
|
-
/**
|
|
1707
|
-
* Retrieves the asset balance for a given account on a specified chain.
|
|
1708
|
-
*
|
|
1709
|
-
* @returns The asset balance as a bigint.
|
|
1710
|
-
*/
|
|
1711
|
-
var getAssetBalance = createPapiApiCall(sdkCore.getBalance);
|
|
1712
|
-
/**
|
|
1713
|
-
* Claims assets from a parachain.
|
|
1714
|
-
*
|
|
1715
|
-
* @returns An extrinsic representing the claim transaction.
|
|
1716
|
-
*/
|
|
1717
|
-
var claimAssets = createPapiApiCall(sdkCore.claimAssets);
|
|
1718
|
-
/**
|
|
1719
|
-
* @deprecated This function is deprecated and will be removed in a future version.
|
|
1720
|
-
* Please use `builder.getOriginXcmFee()` or `builder.getOriginXcmFeeEstimate()` instead,
|
|
1721
|
-
* where `builder` is an instance of `Builder()`. Will be removed in v12
|
|
1722
|
-
* For more details, please refer to the documentation:
|
|
1723
|
-
* {@link https://paraspell.github.io/docs/sdk/xcmPallet.html#xcm-fee-origin-and-dest}
|
|
1724
|
-
*/
|
|
1725
|
-
var getOriginFeeDetails = createPapiApiCall(sdkCore.getOriginFeeDetails);
|
|
1726
|
-
|
|
1727
|
-
var assets = /*#__PURE__*/Object.freeze({
|
|
1728
|
-
__proto__: null,
|
|
1729
|
-
Foreign: sdkCore.Foreign,
|
|
1730
|
-
ForeignAbstract: sdkCore.ForeignAbstract,
|
|
1731
|
-
Native: sdkCore.Native,
|
|
1732
|
-
Override: sdkCore.Override,
|
|
1733
|
-
claimAssets: claimAssets,
|
|
1734
|
-
findAssetInfo: sdkCore.findAssetInfo,
|
|
1735
|
-
getAllAssetsSymbols: sdkCore.getAllAssetsSymbols,
|
|
1736
|
-
getAssetBalance: getAssetBalance,
|
|
1737
|
-
getAssetDecimals: sdkCore.getAssetDecimals,
|
|
1738
|
-
getAssetId: sdkCore.getAssetId,
|
|
1739
|
-
getAssets: sdkCore.getAssets,
|
|
1740
|
-
getAssetsObject: sdkCore.getAssetsObject,
|
|
1741
|
-
getBalanceForeign: getBalanceForeign,
|
|
1742
|
-
getBalanceNative: getBalanceNative,
|
|
1743
|
-
getExistentialDeposit: sdkCore.getExistentialDeposit,
|
|
1744
|
-
getNativeAssetSymbol: sdkCore.getNativeAssetSymbol,
|
|
1745
|
-
getNativeAssets: sdkCore.getNativeAssets,
|
|
1746
|
-
getOriginFeeDetails: getOriginFeeDetails,
|
|
1747
|
-
getOtherAssets: sdkCore.getOtherAssets,
|
|
1748
|
-
getRelayChainSymbol: sdkCore.getRelayChainSymbol,
|
|
1749
|
-
getSupportedAssets: sdkCore.getSupportedAssets,
|
|
1750
|
-
getTChain: sdkCore.getTChain,
|
|
1751
|
-
hasSupportForAsset: sdkCore.hasSupportForAsset,
|
|
1752
|
-
isChainEvm: sdkCore.isChainEvm
|
|
1753
|
-
});
|
|
1754
|
-
|
|
1755
|
-
var convertSs58 = function convertSs58(address, chain) {
|
|
1756
|
-
var papiApi = new PapiApi();
|
|
1757
|
-
return sdkCore.convertSs58(papiApi, address, chain);
|
|
1758
|
-
};
|
|
1759
|
-
|
|
1760
|
-
/**
|
|
1761
|
-
* Builder class for constructing transfers from Ethereum to Polkadot.
|
|
1762
|
-
*/
|
|
1763
|
-
var EvmBuilderCore = /*#__PURE__*/function () {
|
|
1764
|
-
function EvmBuilderCore(options) {
|
|
1765
|
-
_classCallCheck(this, EvmBuilderCore);
|
|
1766
|
-
this._options = options;
|
|
1767
|
-
}
|
|
1768
|
-
return _createClass(EvmBuilderCore, [{
|
|
1769
|
-
key: "from",
|
|
1770
|
-
value: function from(chain) {
|
|
1771
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1772
|
-
from: chain
|
|
1773
|
-
}));
|
|
1774
|
-
}
|
|
1775
|
-
/**
|
|
1776
|
-
* Specifies the destination chain on Polkadot.
|
|
1777
|
-
*
|
|
1778
|
-
* @param chain - The Polkadot chain to which the transfer will be made.
|
|
1779
|
-
* @returns An instance of EvmBuilder
|
|
1780
|
-
*/
|
|
1781
|
-
}, {
|
|
1782
|
-
key: "to",
|
|
1783
|
-
value: function to(chain) {
|
|
1784
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1785
|
-
to: chain
|
|
1786
|
-
}));
|
|
1787
|
-
}
|
|
1788
|
-
/**
|
|
1789
|
-
* Specifies the currency to transfer.
|
|
1790
|
-
*
|
|
1791
|
-
* @param currency - The currency to be transferred.
|
|
1792
|
-
* @returns An instance of EvmBuilder
|
|
1793
|
-
*/
|
|
1794
|
-
}, {
|
|
1795
|
-
key: "currency",
|
|
1796
|
-
value: function currency(_currency) {
|
|
1797
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1798
|
-
currency: _currency
|
|
1799
|
-
}));
|
|
1800
|
-
}
|
|
1801
|
-
/**
|
|
1802
|
-
* Specifies the recipient address on Polkadot.
|
|
1803
|
-
*
|
|
1804
|
-
* @param address - The Polkadot address to receive the transfer.
|
|
1805
|
-
* @returns An instance of EvmBuilder
|
|
1806
|
-
*/
|
|
1807
|
-
}, {
|
|
1808
|
-
key: "address",
|
|
1809
|
-
value: function address(_address) {
|
|
1810
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1811
|
-
address: _address
|
|
1812
|
-
}));
|
|
1813
|
-
}
|
|
1814
|
-
/**
|
|
1815
|
-
* Sets the asset hub address. This is used for transfers that go through the Asset Hub.
|
|
1816
|
-
*
|
|
1817
|
-
* @param address - The address to be used.
|
|
1818
|
-
* @returns An instance of EvmBuilder
|
|
1819
|
-
*/
|
|
1820
|
-
}, {
|
|
1821
|
-
key: "ahAddress",
|
|
1822
|
-
value: function ahAddress(address) {
|
|
1823
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1824
|
-
ahAddress: address
|
|
1825
|
-
}));
|
|
1826
|
-
}
|
|
1827
|
-
/**
|
|
1828
|
-
* Specifies the signer for the Ethereum transaction.
|
|
1829
|
-
*
|
|
1830
|
-
* @param signer - The Ethereum signer to authorize the transfer.
|
|
1831
|
-
* @returns An instance of EvmBuilder
|
|
1832
|
-
*/
|
|
1833
|
-
}, {
|
|
1834
|
-
key: "signer",
|
|
1835
|
-
value: function signer(_signer) {
|
|
1836
|
-
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1837
|
-
signer: _signer
|
|
1838
|
-
}));
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
* Builds and executes the transfer from Ethereum to Polkadot.
|
|
1842
|
-
*
|
|
1843
|
-
* @throws Error if any required parameters are missing.
|
|
1844
|
-
*/
|
|
1845
|
-
}, {
|
|
1846
|
-
key: "build",
|
|
1847
|
-
value: (function () {
|
|
1848
|
-
var _build = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1849
|
-
var _this$_options, from, to, address, api;
|
|
1850
|
-
return _regenerator().w(function (_context) {
|
|
1851
|
-
while (1) switch (_context.n) {
|
|
1852
|
-
case 0:
|
|
1853
|
-
_this$_options = this._options, from = _this$_options.from, to = _this$_options.to, address = _this$_options.address, api = _this$_options.api;
|
|
1854
|
-
sdkCore.validateAddress(api, address, to);
|
|
1855
|
-
if (!(from === 'Moonbeam' && to === 'Ethereum')) {
|
|
1856
|
-
_context.n = 1;
|
|
1857
|
-
break;
|
|
1858
|
-
}
|
|
1859
|
-
return _context.a(2, sdkCore.transferMoonbeamToEth(this._options));
|
|
1860
|
-
case 1:
|
|
1861
|
-
return _context.a(2, sdkCore.transferMoonbeamEvm(this._options));
|
|
1862
|
-
}
|
|
1863
|
-
}, _callee, this);
|
|
1864
|
-
}));
|
|
1865
|
-
function build() {
|
|
1866
|
-
return _build.apply(this, arguments);
|
|
1867
|
-
}
|
|
1868
|
-
return build;
|
|
1869
|
-
}())
|
|
1870
|
-
}]);
|
|
1871
|
-
}();
|
|
1872
|
-
/**
|
|
1873
|
-
* Creates a new EvmBuilder instance for constructing Ethereum to Polkadot transfers.
|
|
1874
|
-
*
|
|
1875
|
-
* @param provider - The Ethereum provider to use for the transfer.
|
|
1876
|
-
* @returns An instance of EvmBuilder class
|
|
1877
|
-
*/
|
|
1878
|
-
var EvmBuilder$1 = function EvmBuilder(api) {
|
|
1879
|
-
return new EvmBuilderCore({
|
|
1880
|
-
api: api
|
|
1881
|
-
});
|
|
1882
|
-
};
|
|
1883
|
-
|
|
1884
|
-
/**
|
|
1885
|
-
* Creates a new Builder instance.
|
|
1886
|
-
*
|
|
1887
|
-
* @param api - The API instance to use for building transactions. If not provided, a new instance will be created.
|
|
1888
|
-
* @returns A new Builder instance.
|
|
1889
|
-
*/
|
|
1890
|
-
var Builder = function Builder(api) {
|
|
1891
|
-
var papiApi = new PapiApi(api);
|
|
1892
|
-
return sdkCore.Builder(papiApi);
|
|
1893
|
-
};
|
|
1894
|
-
var EvmBuilder = function EvmBuilder(api) {
|
|
1895
|
-
var papiApi = new PapiApi(api);
|
|
1896
|
-
return EvmBuilder$1(papiApi);
|
|
1897
|
-
};
|
|
1898
|
-
|
|
1899
|
-
/**
|
|
1900
|
-
* Transfers assets from parachain to another parachain or from/to relay chain.
|
|
1901
|
-
* @param options - The transfer options.
|
|
1902
|
-
* @returns An extrinsic to be signed and sent.
|
|
1903
|
-
*/
|
|
1904
|
-
var send = createPapiApiCall(sdkCore.send);
|
|
1905
|
-
var dryRun = createPapiApiCall(sdkCore.dryRun);
|
|
1906
|
-
var dryRunOrigin = createPapiApiCall(sdkCore.dryRunOrigin);
|
|
1907
|
-
var getParaEthTransferFees = /*#__PURE__*/function () {
|
|
1908
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ahApi) {
|
|
1909
|
-
var papiApi;
|
|
1910
|
-
return _regenerator().w(function (_context) {
|
|
1911
|
-
while (1) switch (_context.n) {
|
|
1912
|
-
case 0:
|
|
1913
|
-
papiApi = new PapiApi(ahApi);
|
|
1914
|
-
_context.n = 1;
|
|
1915
|
-
return papiApi.init('AssetHubPolkadot');
|
|
1916
|
-
case 1:
|
|
1917
|
-
return _context.a(2, sdkCore.getParaEthTransferFees(papiApi));
|
|
1918
|
-
}
|
|
1919
|
-
}, _callee);
|
|
1920
|
-
}));
|
|
1921
|
-
return function getParaEthTransferFees(_x) {
|
|
1922
|
-
return _ref.apply(this, arguments);
|
|
1923
|
-
};
|
|
1924
|
-
}();
|
|
1925
|
-
/**
|
|
1926
|
-
* Gets the Ethereum bridge status.
|
|
1927
|
-
*/
|
|
1928
|
-
var getBridgeStatus = /*#__PURE__*/function () {
|
|
1929
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(ahApi) {
|
|
1930
|
-
var papiApi;
|
|
1931
|
-
return _regenerator().w(function (_context2) {
|
|
1932
|
-
while (1) switch (_context2.n) {
|
|
1933
|
-
case 0:
|
|
1934
|
-
papiApi = new PapiApi(ahApi);
|
|
1935
|
-
return _context2.a(2, sdkCore.getBridgeStatus(papiApi));
|
|
1936
|
-
}
|
|
1937
|
-
}, _callee2);
|
|
1938
|
-
}));
|
|
1939
|
-
return function getBridgeStatus(_x2) {
|
|
1940
|
-
return _ref2.apply(this, arguments);
|
|
1941
|
-
};
|
|
1942
|
-
}();
|
|
1943
|
-
var getOriginXcmFee = createPapiApiCall(sdkCore.getOriginXcmFee);
|
|
1944
|
-
var getXcmFee = /*#__PURE__*/function () {
|
|
1945
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options, builderOptions) {
|
|
1946
|
-
var api;
|
|
1947
|
-
return _regenerator().w(function (_context3) {
|
|
1948
|
-
while (1) switch (_context3.n) {
|
|
1949
|
-
case 0:
|
|
1950
|
-
api = new PapiApi(builderOptions);
|
|
1951
|
-
return _context3.a(2, sdkCore.getXcmFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
1952
|
-
api: api
|
|
1953
|
-
})));
|
|
1954
|
-
}
|
|
1955
|
-
}, _callee3);
|
|
1956
|
-
}));
|
|
1957
|
-
return function getXcmFee(_x3, _x4) {
|
|
1958
|
-
return _ref3.apply(this, arguments);
|
|
1959
|
-
};
|
|
1960
|
-
}();
|
|
1961
|
-
var handleSwapExecuteTransfer = function handleSwapExecuteTransfer(options, builderOptions) {
|
|
1962
|
-
var api = new PapiApi(builderOptions);
|
|
1963
|
-
return sdkCore.handleSwapExecuteTransfer(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
1964
|
-
api: api
|
|
1965
|
-
}));
|
|
1966
|
-
};
|
|
1967
|
-
|
|
1968
|
-
var transfer = /*#__PURE__*/Object.freeze({
|
|
1969
|
-
__proto__: null,
|
|
1970
|
-
dryRun: dryRun,
|
|
1971
|
-
dryRunOrigin: dryRunOrigin,
|
|
1972
|
-
getBridgeStatus: getBridgeStatus,
|
|
1973
|
-
getOriginXcmFee: getOriginXcmFee,
|
|
1974
|
-
getParaEthTransferFees: getParaEthTransferFees,
|
|
1975
|
-
getXcmFee: getXcmFee,
|
|
1976
|
-
handleSwapExecuteTransfer: handleSwapExecuteTransfer,
|
|
1977
|
-
send: send
|
|
1978
|
-
});
|
|
1979
|
-
|
|
1980
|
-
exports.Builder = Builder;
|
|
1981
|
-
exports.EvmBuilder = EvmBuilder;
|
|
1982
|
-
exports.assets = assets;
|
|
1983
|
-
exports.checkAndConvertToNumberOrBigInt = checkAndConvertToNumberOrBigInt;
|
|
1984
|
-
exports.claimAssets = claimAssets;
|
|
1985
|
-
exports.convertSs58 = convertSs58;
|
|
1986
|
-
exports.createChainClient = createChainClient;
|
|
1987
|
-
exports.dryRun = dryRun;
|
|
1988
|
-
exports.dryRunOrigin = dryRunOrigin;
|
|
1989
|
-
exports.getAssetBalance = getAssetBalance;
|
|
1990
|
-
exports.getBalanceForeign = getBalanceForeign;
|
|
1991
|
-
exports.getBalanceNative = getBalanceNative;
|
|
1992
|
-
exports.getBridgeStatus = getBridgeStatus;
|
|
1993
|
-
exports.getOriginFeeDetails = getOriginFeeDetails;
|
|
1994
|
-
exports.getOriginXcmFee = getOriginXcmFee;
|
|
1995
|
-
exports.getParaEthTransferFees = getParaEthTransferFees;
|
|
1996
|
-
exports.getXcmFee = getXcmFee;
|
|
1997
|
-
exports.handleSwapExecuteTransfer = handleSwapExecuteTransfer;
|
|
1998
|
-
exports.send = send;
|
|
1999
|
-
exports.transform = _transform;
|
|
2000
|
-
exports.xcmPallet = transfer;
|
|
2001
|
-
Object.keys(sdkCore).forEach(function (k) {
|
|
2002
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
2003
|
-
enumerable: true,
|
|
2004
|
-
get: function () { return sdkCore[k]; }
|
|
2005
|
-
});
|
|
2006
|
-
});
|