@paraspell/evm 13.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ParaSpell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ <br /><br />
2
+
3
+ <div align="center">
4
+ <h1 align="center">@paraspell/evm</h1>
5
+ <h4 align="center"> An extension to @paraspell/sdk for smart contract XCMs (From Moonbeam, Moonriver and Darwinia). </h4>
6
+ <p align="center">
7
+ <a href="https://npmjs.com/package/@paraspell/evm">
8
+ <img alt="version" src="https://img.shields.io/npm/v/@paraspell/evm?style=flat-square" />
9
+ </a>
10
+ <a href="https://npmjs.com/package/@paraspell/evm">
11
+ <img alt="downloads" src="https://img.shields.io/npm/dm/@paraspell/evm?style=flat-square" />
12
+ </a>
13
+ <a href="https://github.com/paraspell/xcm-sdk/actions">
14
+ <img alt="build" src="https://github.com/paraspell/xcm-tools/actions/workflows/ci.yml/badge.svg" />
15
+ </a>
16
+ </p>
17
+ <p>How to interact <a href = "https://paraspell.github.io/docs/xcm-sdk/send-xcm.html#moonbeam-xtokens-smart-contract" \>[here]</p>
18
+ <p>XCM SDK starter template project <a href = "https://github.com/paraspell/xcm-sdk-template" \>[here]</p>
19
+ </div>
20
+
21
+ <br /><br />
22
+ <br /><br />
23
+
24
+ # Installation
25
+
26
+ Please reffer to [SDK documentation](https://paraspell.github.io/docs/xcm-sdk/send-xcm.html#moonbeam-xtokens-smart-contract)
27
+
28
+ ## 💻 Testing
29
+
30
+ - Run compilation using `pnpm compile`
31
+
32
+ - Run linting test using `pnpm lint`
33
+
34
+ - Run unit tests using `pnpm test`
35
+
36
+ > [!NOTE]
37
+ > EVM transfers can be tested in [Playground](https://playground.paraspell.xyz/https://playground.paraspell.xyz/xcm-sdk/xcm-transfer).
38
+
39
+ ## Contribute to XCM Tools and earn rewards 💰
40
+
41
+ We run an open Bug Bounty Program that rewards contributors for reporting and fixing bugs in the project. More information on bug bounty can be found in the [official documentation](https://paraspell.github.io/docs/contribution-guidelines.html).
42
+
43
+ ## Get Support 🚑
44
+
45
+ - Contact form on our [landing page](https://paraspell.xyz/#contact-us).
46
+ - Message us on our [X](https://x.com/paraspell).
47
+ - Support channel on [telegram](https://t.me/paraspell).
48
+
49
+ ## License
50
+
51
+ Made with 💛 by [ParaSpell✨](https://paraspell.xyz/)
52
+
53
+ Published under [MIT License](https://github.com/paraspell/xcm-tools/blob/main/packages/evm/LICENSE).
54
+
55
+ ## Supported by
56
+
57
+ <p align="center">
58
+ <picture>
59
+ <source media="(prefers-color-scheme: dark)" srcset="https://github.com/paraspell/presskit/blob/main/logos_supporters/polkadot_kusama_transparent.png">
60
+ <source media="(prefers-color-scheme: light)" srcset="https://github.com/paraspell/presskit/blob/main/logos_supporters/polkadot_kusama_w3f_standard.png">
61
+ <img width="750" alt="Shows a black logo in light color mode and a white one in dark color mode." src="https://github.com/paraspell/presskit/blob/main/logos_supporters/polkadot_kusama_w3f_standard.png">
62
+ </picture>
63
+ </p>
@@ -0,0 +1,7 @@
1
+ import { TEvmTransferOptions } from '@paraspell/sdk-core';
2
+
3
+ declare const executeEvmTransfer: <TApi, TRes, TSigner>(options: TEvmTransferOptions<TApi, TRes, TSigner>) => Promise<string>;
4
+
5
+ declare const EVM_ORIGIN_CHAINS: readonly ["Moonbeam", "Moonriver", "Darwinia"];
6
+
7
+ export { EVM_ORIGIN_CHAINS, executeEvmTransfer };
package/dist/index.mjs ADDED
@@ -0,0 +1,714 @@
1
+ import { getAssetsObject, getChainConfig, assertHasId, findAssetInfoOrThrow, formatAssetIdToERC20, InvalidCurrencyError, getNativeAssetSymbol, abstractDecimals, isOverrideLocationSpecifier, UnsupportedOperationError, getParaId, getParaEthTransferFees, Version, createCustomXcmOnDest, generateMessageId, assertSender, TX_CLIENT_TIMEOUT_MS, BridgeHaltedError, getBridgeStatus, MissingParameterError, NumberFormatError, validateAddress, registerEvmExtension } from '@paraspell/sdk-core';
2
+ import { getContract, createPublicClient, http } from 'viem';
3
+
4
+ function _arrayLikeToArray(r, a) {
5
+ (null == a || a > r.length) && (a = r.length);
6
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
7
+ return n;
8
+ }
9
+ function _arrayWithHoles(r) {
10
+ if (Array.isArray(r)) return r;
11
+ }
12
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
13
+ try {
14
+ var i = n[a](c),
15
+ u = i.value;
16
+ } catch (n) {
17
+ return void e(n);
18
+ }
19
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
20
+ }
21
+ function _asyncToGenerator(n) {
22
+ return function () {
23
+ var t = this,
24
+ e = arguments;
25
+ return new Promise(function (r, o) {
26
+ var a = n.apply(t, e);
27
+ function _next(n) {
28
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
29
+ }
30
+ function _throw(n) {
31
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
32
+ }
33
+ _next(void 0);
34
+ });
35
+ };
36
+ }
37
+ function _defineProperty(e, r, t) {
38
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
39
+ value: t,
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true
43
+ }) : e[r] = t, e;
44
+ }
45
+ function _iterableToArrayLimit(r, l) {
46
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
47
+ if (null != t) {
48
+ var e,
49
+ n,
50
+ i,
51
+ u,
52
+ a = [],
53
+ f = true,
54
+ o = false;
55
+ try {
56
+ 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);
57
+ } catch (r) {
58
+ o = true, n = r;
59
+ } finally {
60
+ try {
61
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
62
+ } finally {
63
+ if (o) throw n;
64
+ }
65
+ }
66
+ return a;
67
+ }
68
+ }
69
+ function _nonIterableRest() {
70
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
71
+ }
72
+ function ownKeys(e, r) {
73
+ var t = Object.keys(e);
74
+ if (Object.getOwnPropertySymbols) {
75
+ var o = Object.getOwnPropertySymbols(e);
76
+ r && (o = o.filter(function (r) {
77
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
78
+ })), t.push.apply(t, o);
79
+ }
80
+ return t;
81
+ }
82
+ function _objectSpread2(e) {
83
+ for (var r = 1; r < arguments.length; r++) {
84
+ var t = null != arguments[r] ? arguments[r] : {};
85
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
86
+ _defineProperty(e, r, t[r]);
87
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
88
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
89
+ });
90
+ }
91
+ return e;
92
+ }
93
+ function _regenerator() {
94
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
95
+ var e,
96
+ t,
97
+ r = "function" == typeof Symbol ? Symbol : {},
98
+ n = r.iterator || "@@iterator",
99
+ o = r.toStringTag || "@@toStringTag";
100
+ function i(r, n, o, i) {
101
+ var c = n && n.prototype instanceof Generator ? n : Generator,
102
+ u = Object.create(c.prototype);
103
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
104
+ var i,
105
+ c,
106
+ u,
107
+ f = 0,
108
+ p = o || [],
109
+ y = false,
110
+ G = {
111
+ p: 0,
112
+ n: 0,
113
+ v: e,
114
+ a: d,
115
+ f: d.bind(e, 4),
116
+ d: function (t, r) {
117
+ return i = t, c = 0, u = e, G.n = r, a;
118
+ }
119
+ };
120
+ function d(r, n) {
121
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
122
+ var o,
123
+ i = p[t],
124
+ d = G.p,
125
+ l = i[2];
126
+ 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));
127
+ }
128
+ if (o || r > 1) return a;
129
+ throw y = true, n;
130
+ }
131
+ return function (o, p, l) {
132
+ if (f > 1) throw TypeError("Generator is already running");
133
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
134
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
135
+ try {
136
+ if (f = 2, i) {
137
+ if (c || (o = "next"), t = i[o]) {
138
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
139
+ if (!t.done) return t;
140
+ u = t.value, c < 2 && (c = 0);
141
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
142
+ i = e;
143
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
144
+ } catch (t) {
145
+ i = e, c = 1, u = t;
146
+ } finally {
147
+ f = 1;
148
+ }
149
+ }
150
+ return {
151
+ value: t,
152
+ done: y
153
+ };
154
+ };
155
+ }(r, o, i), true), u;
156
+ }
157
+ var a = {};
158
+ function Generator() {}
159
+ function GeneratorFunction() {}
160
+ function GeneratorFunctionPrototype() {}
161
+ t = Object.getPrototypeOf;
162
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
163
+ return this;
164
+ }), t),
165
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
166
+ function f(e) {
167
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
168
+ }
169
+ 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 () {
170
+ return this;
171
+ }), _regeneratorDefine(u, "toString", function () {
172
+ return "[object Generator]";
173
+ }), (_regenerator = function () {
174
+ return {
175
+ w: i,
176
+ m: f
177
+ };
178
+ })();
179
+ }
180
+ function _regeneratorDefine(e, r, n, t) {
181
+ var i = Object.defineProperty;
182
+ try {
183
+ i({}, "", {});
184
+ } catch (e) {
185
+ i = 0;
186
+ }
187
+ _regeneratorDefine = function (e, r, n, t) {
188
+ function o(r, n) {
189
+ _regeneratorDefine(e, r, function (e) {
190
+ return this._invoke(r, n, e);
191
+ });
192
+ }
193
+ r ? i ? i(e, r, {
194
+ value: n,
195
+ enumerable: !t,
196
+ configurable: !t,
197
+ writable: !t
198
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
199
+ }, _regeneratorDefine(e, r, n, t);
200
+ }
201
+ function _slicedToArray(r, e) {
202
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
203
+ }
204
+ function _toPrimitive(t, r) {
205
+ if ("object" != typeof t || !t) return t;
206
+ var e = t[Symbol.toPrimitive];
207
+ if (void 0 !== e) {
208
+ var i = e.call(t, r);
209
+ if ("object" != typeof i) return i;
210
+ throw new TypeError("@@toPrimitive must return a primitive value.");
211
+ }
212
+ return ("string" === r ? String : Number)(t);
213
+ }
214
+ function _toPropertyKey(t) {
215
+ var i = _toPrimitive(t, "string");
216
+ return "symbol" == typeof i ? i : i + "";
217
+ }
218
+ function _unsupportedIterableToArray(r, a) {
219
+ if (r) {
220
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
221
+ var t = {}.toString.call(r).slice(8, -1);
222
+ 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;
223
+ }
224
+ }
225
+
226
+ var abi$2 = [
227
+ {
228
+ inputs: [
229
+ {
230
+ internalType: "address",
231
+ name: "currencyAddress",
232
+ type: "address"
233
+ },
234
+ {
235
+ internalType: "uint256",
236
+ name: "amount",
237
+ type: "uint256"
238
+ },
239
+ {
240
+ components: [
241
+ {
242
+ internalType: "uint8",
243
+ name: "parents",
244
+ type: "uint8"
245
+ },
246
+ {
247
+ internalType: "bytes[]",
248
+ name: "interior",
249
+ type: "bytes[]"
250
+ }
251
+ ],
252
+ internalType: "struct Xtokens.Multilocation",
253
+ name: "destination",
254
+ type: "tuple"
255
+ },
256
+ {
257
+ internalType: "uint64",
258
+ name: "weight",
259
+ type: "uint64"
260
+ }
261
+ ],
262
+ name: "transfer",
263
+ outputs: [
264
+ ],
265
+ stateMutability: "nonpayable",
266
+ type: "function"
267
+ },
268
+ {
269
+ inputs: [
270
+ {
271
+ components: [
272
+ {
273
+ internalType: "address",
274
+ name: "currencyAddress",
275
+ type: "address"
276
+ },
277
+ {
278
+ internalType: "uint256",
279
+ name: "amount",
280
+ type: "uint256"
281
+ }
282
+ ],
283
+ internalType: "struct Xtokens.Currency[]",
284
+ name: "currencies",
285
+ type: "tuple[]"
286
+ },
287
+ {
288
+ internalType: "uint32",
289
+ name: "feeItem",
290
+ type: "uint32"
291
+ },
292
+ {
293
+ components: [
294
+ {
295
+ internalType: "uint8",
296
+ name: "parents",
297
+ type: "uint8"
298
+ },
299
+ {
300
+ internalType: "bytes[]",
301
+ name: "interior",
302
+ type: "bytes[]"
303
+ }
304
+ ],
305
+ internalType: "struct Xtokens.Multilocation",
306
+ name: "destination",
307
+ type: "tuple"
308
+ },
309
+ {
310
+ internalType: "uint64",
311
+ name: "weight",
312
+ type: "uint64"
313
+ }
314
+ ],
315
+ name: "transferMultiCurrencies",
316
+ outputs: [
317
+ ],
318
+ stateMutability: "nonpayable",
319
+ type: "function"
320
+ }
321
+ ];
322
+
323
+ // Partially inspired by Moonbeam XCM-SDK
324
+ // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts#L126
325
+ var getDestinationLocation = function getDestinationLocation(api, address, destination) {
326
+ var _getAssetsObject = getAssetsObject(destination),
327
+ isEVM = _getAssetsObject.isEVM;
328
+ var accountType = isEVM ? '03' : '01';
329
+ var addressHex = api.accountToHex(address, false);
330
+ var acc = "0x".concat(accountType).concat(addressHex, "00");
331
+ var _getChainConfig = getChainConfig(destination),
332
+ paraId = _getChainConfig.paraId;
333
+ return [1, paraId ? ["0x0000000".concat(paraId.toString(16)), acc] : [acc]];
334
+ };
335
+
336
+ var abi$1 = [{
337
+ inputs: [{
338
+ internalType: 'address',
339
+ name: 'recipient_',
340
+ type: 'address'
341
+ }, {
342
+ internalType: 'uint256',
343
+ name: 'amount_',
344
+ type: 'uint256'
345
+ }],
346
+ name: 'transfer',
347
+ outputs: [{
348
+ internalType: 'bool',
349
+ name: '',
350
+ type: 'bool'
351
+ }],
352
+ stateMutability: 'nonpayable',
353
+ type: 'function'
354
+ }];
355
+ var transferMoonbeamLocal = /*#__PURE__*/function () {
356
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(client, assetInfo, _ref) {
357
+ var signer, recipient, contract;
358
+ return _regenerator().w(function (_context) {
359
+ while (1) switch (_context.n) {
360
+ case 0:
361
+ signer = _ref.signer, recipient = _ref.recipient;
362
+ assertHasId(assetInfo);
363
+ contract = getContract({
364
+ abi: abi$1,
365
+ address: assetInfo.assetId,
366
+ client: {
367
+ "public": client,
368
+ wallet: signer
369
+ }
370
+ });
371
+ return _context.a(2, contract.write.transfer([recipient, assetInfo.amount]));
372
+ }
373
+ }, _callee);
374
+ }));
375
+ return function transferMoonbeamLocal(_x, _x2, _x3) {
376
+ return _ref2.apply(this, arguments);
377
+ };
378
+ }();
379
+
380
+ var U_64_MAX = 18446744073709551615n;
381
+ var CONTRACT_ADDRESS = '0x0000000000000000000000000000000000000804';
382
+ var NATIVE_ASSET_ID = '0x0000000000000000000000000000000000000802';
383
+ // Partially inspired by Moonbeam XCM-SDK
384
+ var transferMoonbeamEvm = /*#__PURE__*/function () {
385
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
386
+ var _usdtAsset$assetId;
387
+ var api, from, to, signer, recipient, currency, foundAsset, amount, client, contract, asset, destLocation, weight, createTx, multiCurrencySymbols, useMultiAssets, usdtAsset, tx, _t;
388
+ return _regenerator().w(function (_context) {
389
+ while (1) switch (_context.n) {
390
+ case 0:
391
+ api = options.api, from = options.from, to = options.to, signer = options.signer, recipient = options.recipient, currency = options.currency;
392
+ if (!Array.isArray(currency)) {
393
+ _context.n = 1;
394
+ break;
395
+ }
396
+ throw new UnsupportedOperationError('Multi-assets are not yet supported for EVM transfers');
397
+ case 1:
398
+ if (!('location' in currency && isOverrideLocationSpecifier(currency.location))) {
399
+ _context.n = 2;
400
+ break;
401
+ }
402
+ throw new UnsupportedOperationError('Override location is not supported for EVM transfers');
403
+ case 2:
404
+ foundAsset = findAssetInfoOrThrow(from, currency, to);
405
+ amount = abstractDecimals(currency.amount, foundAsset.decimals, api);
406
+ client = createPublicClient({
407
+ chain: signer.chain,
408
+ transport: http()
409
+ });
410
+ if (!(from === to)) {
411
+ _context.n = 3;
412
+ break;
413
+ }
414
+ return _context.a(2, transferMoonbeamLocal(client, _objectSpread2(_objectSpread2({}, foundAsset), {}, {
415
+ amount: amount
416
+ }), options));
417
+ case 3:
418
+ contract = getContract({
419
+ abi: abi$2,
420
+ address: CONTRACT_ADDRESS,
421
+ client: {
422
+ "public": client,
423
+ wallet: signer
424
+ }
425
+ });
426
+ if (!(foundAsset.symbol === getNativeAssetSymbol(from))) {
427
+ _context.n = 4;
428
+ break;
429
+ }
430
+ asset = NATIVE_ASSET_ID;
431
+ _context.n = 6;
432
+ break;
433
+ case 4:
434
+ if (!(foundAsset.assetId === undefined)) {
435
+ _context.n = 5;
436
+ break;
437
+ }
438
+ throw new InvalidCurrencyError('Currency must be a foreign asset with valid assetId');
439
+ case 5:
440
+ asset = formatAssetIdToERC20(foundAsset.assetId);
441
+ case 6:
442
+ destLocation = getDestinationLocation(api, recipient, to);
443
+ weight = U_64_MAX; // Partially inspired by Moonbeam XCM-SDK
444
+ // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/sdk/src/contract/contracts/Xtokens/Xtokens.ts#L53
445
+ createTx = function createTx(func, args) {
446
+ return contract.write[func](args);
447
+ };
448
+ multiCurrencySymbols = ['xcPINK', 'xcDED', 'xcSTINK', 'xcWIFD', 'xcNCTR'];
449
+ useMultiAssets = from === 'Moonbeam' && to === 'AssetHubPolkadot' && multiCurrencySymbols.includes(foundAsset.symbol);
450
+ usdtAsset = findAssetInfoOrThrow(from, {
451
+ symbol: 'xcUSDT'
452
+ }, to);
453
+ assertHasId(usdtAsset);
454
+ if (!useMultiAssets) {
455
+ _context.n = 8;
456
+ break;
457
+ }
458
+ _context.n = 7;
459
+ return createTx('transferMultiCurrencies', [[[asset, amount.toString()], [formatAssetIdToERC20((_usdtAsset$assetId = usdtAsset.assetId) !== null && _usdtAsset$assetId !== void 0 ? _usdtAsset$assetId : ''), '200000']], 1,
460
+ // index of the fee asset
461
+ destLocation, weight]);
462
+ case 7:
463
+ _t = _context.v;
464
+ _context.n = 10;
465
+ break;
466
+ case 8:
467
+ _context.n = 9;
468
+ return createTx('transfer', [asset, amount.toString(), destLocation, weight]);
469
+ case 9:
470
+ _t = _context.v;
471
+ case 10:
472
+ tx = _t;
473
+ return _context.a(2, tx);
474
+ }
475
+ }, _callee);
476
+ }));
477
+ return function transferMoonbeamEvm(_x) {
478
+ return _ref.apply(this, arguments);
479
+ };
480
+ }();
481
+
482
+ var abi = [
483
+ {
484
+ inputs: [
485
+ {
486
+ components: [
487
+ {
488
+ internalType: "uint8",
489
+ name: "parents",
490
+ type: "uint8"
491
+ },
492
+ {
493
+ internalType: "bytes[]",
494
+ name: "interior",
495
+ type: "bytes[]"
496
+ }
497
+ ],
498
+ internalType: "struct XCM.Location",
499
+ name: "dest",
500
+ type: "tuple"
501
+ },
502
+ {
503
+ components: [
504
+ {
505
+ internalType: "address",
506
+ name: "asset",
507
+ type: "address"
508
+ },
509
+ {
510
+ internalType: "uint256",
511
+ name: "amount",
512
+ type: "uint256"
513
+ }
514
+ ],
515
+ internalType: "struct XCM.AssetAddressInfo[]",
516
+ name: "assets",
517
+ type: "tuple[]"
518
+ },
519
+ {
520
+ internalType: "enum XCM.TransferType",
521
+ name: "assetsTransferType",
522
+ type: "uint8"
523
+ },
524
+ {
525
+ internalType: "uint8",
526
+ name: "remoteFeesIdIndex",
527
+ type: "uint8"
528
+ },
529
+ {
530
+ internalType: "enum XCM.TransferType",
531
+ name: "feesTransferType",
532
+ type: "uint8"
533
+ },
534
+ {
535
+ internalType: "bytes",
536
+ name: "customXcmOnDest",
537
+ type: "bytes"
538
+ }
539
+ ],
540
+ name: "transferAssetsUsingTypeAndThenAddress",
541
+ outputs: [
542
+ ],
543
+ stateMutability: "nonpayable",
544
+ type: "function"
545
+ }
546
+ ];
547
+
548
+ // https://github.com/moonbeam-foundation/moonbeam/blob/b2b1bde7ced13aad4bd2928effc415c521fd48cb/runtime/moonbeam/src/precompiles.rs#L281
549
+ var xcmInterfacePrecompile = '0x000000000000000000000000000000000000081A';
550
+ var XCDOT = '0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080';
551
+ var transferMoonbeamToEth = /*#__PURE__*/function () {
552
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(from, _ref) {
553
+ var _signer$account;
554
+ var api, to, signer, recipient, ahAddress, currency, bridgeStatus, foundAsset, amount, ethAsset, contract, sender, messageId, version, customXcm, customXcmOnDest, assetHubApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, transferFee, createTx, numberToHex32, tx;
555
+ return _regenerator().w(function (_context) {
556
+ while (1) switch (_context.n) {
557
+ case 0:
558
+ api = _ref.api, to = _ref.to, signer = _ref.signer, recipient = _ref.recipient, ahAddress = _ref.ahAddress, currency = _ref.currency;
559
+ if (ahAddress) {
560
+ _context.n = 1;
561
+ break;
562
+ }
563
+ throw new MissingParameterError('ahAddress');
564
+ case 1:
565
+ _context.n = 2;
566
+ return getBridgeStatus(api.clone());
567
+ case 2:
568
+ bridgeStatus = _context.v;
569
+ if (!(bridgeStatus !== 'Normal')) {
570
+ _context.n = 3;
571
+ break;
572
+ }
573
+ throw new BridgeHaltedError();
574
+ case 3:
575
+ if (!Array.isArray(currency)) {
576
+ _context.n = 4;
577
+ break;
578
+ }
579
+ throw new UnsupportedOperationError('Multi-assets are not yet supported for EVM transfers');
580
+ case 4:
581
+ if (!('location' in currency && isOverrideLocationSpecifier(currency.location))) {
582
+ _context.n = 5;
583
+ break;
584
+ }
585
+ throw new UnsupportedOperationError('Override location is not supported for EVM transfers');
586
+ case 5:
587
+ foundAsset = findAssetInfoOrThrow(from, currency, to);
588
+ amount = abstractDecimals(currency.amount, foundAsset.decimals, api);
589
+ ethAsset = findAssetInfoOrThrow('Ethereum', {
590
+ symbol: foundAsset.symbol
591
+ });
592
+ contract = getContract({
593
+ abi: abi,
594
+ address: xcmInterfacePrecompile,
595
+ client: {
596
+ "public": createPublicClient({
597
+ chain: signer.chain,
598
+ transport: http()
599
+ }),
600
+ wallet: signer
601
+ }
602
+ });
603
+ sender = (_signer$account = signer.account) === null || _signer$account === void 0 ? void 0 : _signer$account.address;
604
+ assertSender(sender);
605
+ assertHasId(ethAsset);
606
+ _context.n = 6;
607
+ return api.init(from, TX_CLIENT_TIMEOUT_MS);
608
+ case 6:
609
+ _context.n = 7;
610
+ return generateMessageId(api, sender, getParaId(from), ethAsset.assetId, recipient, amount);
611
+ case 7:
612
+ messageId = _context.v;
613
+ version = Version.V4;
614
+ customXcm = createCustomXcmOnDest({
615
+ api: api,
616
+ chain: from,
617
+ destination: to,
618
+ recipient: recipient,
619
+ scenario: 'ParaToPara',
620
+ sender: sender,
621
+ ahAddress: ahAddress,
622
+ assetInfo: _objectSpread2(_objectSpread2({}, foundAsset), {}, {
623
+ amount: amount
624
+ }),
625
+ currency: currency,
626
+ asset: {},
627
+ beneficiaryLocation: {},
628
+ version: version
629
+ }, from, messageId, ethAsset);
630
+ _context.n = 8;
631
+ return api.objectToHex(customXcm, 'XcmVersionedXcm', version);
632
+ case 8:
633
+ customXcmOnDest = _context.v;
634
+ _context.n = 9;
635
+ return api.createApiForChain('AssetHubPolkadot');
636
+ case 9:
637
+ assetHubApi = _context.v;
638
+ _context.n = 10;
639
+ return getParaEthTransferFees(assetHubApi);
640
+ case 10:
641
+ _yield$getParaEthTran = _context.v;
642
+ _yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 2);
643
+ bridgeFee = _yield$getParaEthTran2[0];
644
+ executionFee = _yield$getParaEthTran2[1];
645
+ transferFee = (bridgeFee + executionFee).toString(); // Partially inspired by Moonbeam XCM-SDK
646
+ // https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/sdk/src/contract/contracts/Xtokens/Xtokens.ts#L53
647
+ createTx = function createTx(func, args) {
648
+ return contract.write[func](args);
649
+ };
650
+ numberToHex32 = function numberToHex32(num) {
651
+ return typeof num !== 'number' || isNaN(num) ? function () {
652
+ throw new NumberFormatError('Input must be a valid number');
653
+ }() : "0x".concat((num >>> 0).toString(16).padStart(8, '0'));
654
+ }; // Execute the custom XCM message with the precompile
655
+ _context.n = 11;
656
+ return createTx('transferAssetsUsingTypeAndThenAddress', [
657
+ // This represents (1,X1(Parachain(1000)))
658
+ [1, ['0x00' + numberToHex32(getParaId('AssetHubPolkadot')).slice(2)]],
659
+ // Assets including fee and the ERC20 asset, with fee be the first
660
+ [[XCDOT, transferFee], [ethAsset.assetId, amount.toString()]],
661
+ // The TransferType corresponding to asset being sent, 2 represents `DestinationReserve`
662
+ 2,
663
+ // index for the fee
664
+ 0,
665
+ // The TransferType corresponding to fee asset
666
+ 2, customXcmOnDest]);
667
+ case 11:
668
+ tx = _context.v;
669
+ return _context.a(2, tx);
670
+ }
671
+ }, _callee);
672
+ }));
673
+ return function transferMoonbeamToEth(_x, _x2) {
674
+ return _ref2.apply(this, arguments);
675
+ };
676
+ }();
677
+
678
+ var executeEvmTransfer = /*#__PURE__*/function () {
679
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
680
+ var api, from, to, recipient;
681
+ return _regenerator().w(function (_context) {
682
+ while (1) switch (_context.n) {
683
+ case 0:
684
+ api = options.api, from = options.from, to = options.to, recipient = options.recipient;
685
+ validateAddress(api, recipient, to);
686
+ if (!(from === 'Moonbeam' && to === 'Ethereum')) {
687
+ _context.n = 1;
688
+ break;
689
+ }
690
+ return _context.a(2, transferMoonbeamToEth(from, options));
691
+ case 1:
692
+ if (!(from === 'Moonbeam' || from === 'Moonriver' || from === 'Darwinia')) {
693
+ _context.n = 2;
694
+ break;
695
+ }
696
+ return _context.a(2, transferMoonbeamEvm(options));
697
+ case 2:
698
+ throw new UnsupportedOperationError("EVM transfer from '".concat(from, "' to '").concat(to, "' is not supported by @paraspell/evm."));
699
+ case 3:
700
+ return _context.a(2);
701
+ }
702
+ }, _callee);
703
+ }));
704
+ return function executeEvmTransfer(_x) {
705
+ return _ref.apply(this, arguments);
706
+ };
707
+ }();
708
+
709
+ registerEvmExtension({
710
+ executeEvmTransfer: executeEvmTransfer
711
+ });
712
+ var EVM_ORIGIN_CHAINS = ['Moonbeam', 'Moonriver', 'Darwinia'];
713
+
714
+ export { EVM_ORIGIN_CHAINS, executeEvmTransfer };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@paraspell/evm",
3
+ "version": "13.3.0",
4
+ "description": "Optional EVM extension for @paraspell/sdk enabling interaction with EVM-compatible chains.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/paraspell/xcm-tools.git",
8
+ "directory": "packages/evm"
9
+ },
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs"
16
+ }
17
+ },
18
+ "main": "dist/index.mjs",
19
+ "module": "./dist/index.mjs",
20
+ "types": "./dist/index.d.ts",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "keywords": [],
25
+ "author": "",
26
+ "dependencies": {
27
+ "viem": "^2.47.6",
28
+ "@paraspell/sdk-core": "13.3.0"
29
+ },
30
+ "devDependencies": {
31
+ "@babel/plugin-syntax-import-attributes": "^7.28.6",
32
+ "@babel/preset-env": "^7.29.2",
33
+ "@codecov/rollup-plugin": "^1.9.1",
34
+ "@rollup/plugin-babel": "^7.0.0",
35
+ "@rollup/plugin-json": "^6.1.0",
36
+ "@rollup/plugin-typescript": "^12.3.0",
37
+ "@vitest/coverage-v8": "^4.1.2",
38
+ "dotenv": "^17.3.1",
39
+ "rollup": "^4.60.1",
40
+ "rollup-plugin-dts": "^6.4.1",
41
+ "tslib": "^2.8.1"
42
+ },
43
+ "scripts": {
44
+ "compile": "tsc --noEmit",
45
+ "build": "rollup -c",
46
+ "lint:check": "eslint src",
47
+ "lint": "eslint --fix src",
48
+ "format:check": "prettier --check src",
49
+ "format:write": "prettier --write src",
50
+ "test": "vitest run",
51
+ "test:cov": "vitest run --coverage",
52
+ "test:watch": "vitest",
53
+ "runAll": "pnpm compile && pnpm format:write && pnpm lint && pnpm test"
54
+ }
55
+ }