@paraspell/sdk 0.0.10 → 0.0.11-alpha.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 CHANGED
@@ -1,72 +1,141 @@
1
+
1
2
  # @paraspell/sdk
2
3
 
4
+
5
+
3
6
  [![npm version][npm-version-src]][npm-version-href]
7
+
4
8
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
- [![Github Actions][github-actions-src]][github-actions-href]
6
- [![Codecov][codecov-src]][codecov-href]
7
9
 
8
- > Package description
10
+ [![Known Vulnerabilities](https://snyk.io/test/github/paraspell/sdk/badge.svg)](https://snyk.io/test/github/paraspell/sdk)
11
+
12
+
13
+ SDK For XCM & XCMP handling made with ❤️ by ParaSpell✨. It is no longer necessary to construct calls manually. @paraspell/sdk handles this for you. Feel free to become magician and try your paraSPELLS 🧙✨.
14
+
15
+ ##### Currently supporting 29 Polkadot & Kusama nodes list [here](https://github.com/paraspell/sdk/blob/beta-pre-release/docs/supportedNodes.md).
16
+
17
+
9
18
 
10
19
  ## Usage
11
20
 
21
+
22
+
12
23
  Install package:
13
24
 
14
- ```sh
15
- # npm
16
- npm install @paraspell/sdk
25
+
17
26
 
18
- # yarn
27
+ ##### Install via npm
28
+ ```
29
+ npm install @paraspell/sdk
30
+ ```
31
+ ##### Install via yarn
32
+ ```
19
33
  yarn install @paraspell/sdk
20
-
21
- # pnpm
34
+ ```
35
+ ##### Install via pnpm
36
+ ```
22
37
  pnpm install @paraspell/sdk
23
38
  ```
24
39
 
25
- Import:
40
+
26
41
 
42
+ ##### Importing package to your project:
43
+
44
+
27
45
  ```js
46
+
28
47
  // ESM
29
- import * as paraspell from '@paraspell/sdk'
48
+ import * as paraspell from '@paraspell/sdk'
30
49
 
31
50
  // CommonJS
32
- const { } = require('@paraspell/sdk')
51
+ const paraspell = require('@paraspell/sdk')
52
+
33
53
  ```
34
54
 
55
+
56
+
35
57
  ## Currently implemented pallets
58
+
36
59
  ```ts
60
+
37
61
  //xToken pallet:
38
- paraspell.xTokens.transferParaToPara(api: ApiPromise, origin: origin Parachain name string, destination: destination Parachain ID, currency: currency symbol string, amount: any, to: destination address string)
39
- paraspell.xTokens.transferParaToRelay(api: ApiPromise, origin: origin Parachain name string, currency: currency symbol string, amount: any, to: destination address string)
40
- paraspell.xTokens.transferRelayToPara(api: ApiPromise, destination: destination Parachain ID, amount: any, to: destination address string)
62
+
63
+ //Transfer tokens from Parachain to Parachain
64
+ paraspell.xTokens.transferParaToPara(api: ApiPromise, origin: origin Parachain name string, destination: destination Parachain ID, currency: currency symbol string, currencyID: number, amount: any, to: destination address string)
65
+
66
+ //Transfer tokens from Parachain to Relay chain
67
+ paraspell.xTokens.transferParaToRelay(api: ApiPromise, origin: origin Parachain name string, currency: currency symbol string, currencyID: number, amount: any, to: destination address string)
68
+
69
+ //Transfer tokens from Relay chain to Parachain
70
+ paraspell.xTokens.transferRelayToPara(api: ApiPromise, destination: destination Parachain ID, amount: any, to: destination address string)
71
+
72
+ //Transfer tokens from Relay chain to Parachain /w specific limit
73
+ xTokens.xTokens.limitedTransferRelayToPara(api,destParaID,amount,destinationAddress,yourWeight,true)
74
+
41
75
  //hrmp pallet:
42
- paraspell.closeChannels.closeChannel(api: ApiPromise, origin: origin Parachain ID, inbound: number, outbound: number)
76
+
77
+ //Close HRMP channels
78
+ paraspell.closeChannels.closeChannel(api: ApiPromise, origin: origin Parachain ID, inbound: number, outbound: number)
79
+
80
+
43
81
  //parasSudoWrapper pallet:
44
- paraspell.openChannels.openChannel(api: ApiPromise, origin: origin Parachain ID, destination: destination Parachain ID, maxSize: number, maxMessageSize: number)
82
+
83
+ //Open HRMP channels
84
+ paraspell.openChannels.openChannel(api: ApiPromise, origin: origin Parachain ID, destination: destination Parachain ID, maxSize: number, maxMessageSize: number)
85
+
86
+
45
87
 
46
88
  ```
47
- Example of usage can be found in the UI repository [here](https://github.com/paraspell/ui)
89
+
90
+ ##### Example of usage can be found in the UI repository [here](https://github.com/paraspell/ui)
91
+ ##### List of currently compatible nodes can be found [here](https://github.com/paraspell/sdk/blob/beta-pre-release/docs/supportedNodes.md)
92
+
93
+
48
94
 
49
95
  ## 💻 Development
50
96
 
97
+
98
+
51
99
  - Clone this repository
100
+
52
101
  - Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)
102
+
53
103
  - Install dependencies using `pnpm install`
104
+
54
105
  - Run interactive tests using `pnpm dev`
55
106
 
107
+
108
+
56
109
  ## License
57
- Made with 💛
58
110
 
59
- Published under [MIT License](./LICENSE).
111
+ Made with 💛 by [ParaSpell✨](https://github.com/paraspell)
112
+
113
+
114
+
115
+ Published under [MIT License](https://github.com/paraspell/sdk/blob/main/LICENSE).
116
+
117
+
60
118
 
61
119
  <!-- Badges -->
120
+
62
121
  [npm-version-src]: https://img.shields.io/npm/v/@paraspell/sdk?style=flat-square
122
+
63
123
  [npm-version-href]: https://npmjs.com/package/@paraspell/sdk
64
124
 
125
+
126
+
65
127
  [npm-downloads-src]: https://img.shields.io/npm/dm/@paraspell/sdk?style=flat-square
128
+
66
129
  [npm-downloads-href]: https://npmjs.com/package/@paraspell/sdk
67
130
 
131
+
132
+
68
133
  [github-actions-src]: https://img.shields.io/github/workflow/status/unjs/@paraspell/sdk/ci/main?style=flat-square
134
+
69
135
  [github-actions-href]: https://github.com/unjs/@paraspell/sdk/actions?query=workflow%3Aci
70
136
 
137
+
138
+
71
139
  [codecov-src]: https://img.shields.io/codecov/c/gh/unjs/@paraspell/sdk/main?style=flat-square
140
+
72
141
  [codecov-href]: https://codecov.io/gh/unjs/@paraspell/sdk
package/dist/index.cjs CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ const ethers = require('ethers');
6
+
5
7
  function createAccID(api, account) {
8
+ console.log("Generating AccountId32 address");
6
9
  return api.createType("AccountId32", account).toHex();
7
10
  }
8
11
  function selectLimit(limit, isLimited) {
@@ -14,15 +17,38 @@ function selectLimit(limit, isLimited) {
14
17
  return "Unlimited";
15
18
  }
16
19
  }
17
-
18
- function transferParaToRelay(api, origin, currency, amount, to) {
19
- if (origin == "Karura" || origin == "Bifrost") {
20
- return api.tx.xTokens.transfer(
21
- {
22
- Token: currency
23
- },
24
- amount,
25
- {
20
+ function getFees(scenario) {
21
+ if (scenario === "ParaToRelay") {
22
+ console.log("Asigning fees for transfer to Relay chain");
23
+ return 46e8;
24
+ } else if (scenario === "ParaToPara") {
25
+ console.log("Asigning fees for transfer to another Parachain chain");
26
+ return 3996e8;
27
+ } else {
28
+ console.log("Asigning fees for transfer from Relay chain");
29
+ return 0;
30
+ }
31
+ }
32
+ function buildCall(scenario, api, to, nodeId) {
33
+ if (scenario === "ParaToRelay") {
34
+ if (ethers.ethers.utils.isAddress(to)) {
35
+ console.log("AccountKey20 transfer");
36
+ return {
37
+ V1: {
38
+ parents: 1,
39
+ interior: {
40
+ X1: {
41
+ AccountKey20: {
42
+ network: "any",
43
+ key: to
44
+ }
45
+ }
46
+ }
47
+ }
48
+ };
49
+ } else {
50
+ console.log("AccountId32 transfer");
51
+ return {
26
52
  V1: {
27
53
  parents: 1,
28
54
  interior: {
@@ -34,30 +60,188 @@ function transferParaToRelay(api, origin, currency, amount, to) {
34
60
  }
35
61
  }
36
62
  }
37
- },
38
- 46e8
39
- );
40
- } else if (origin == "Pichiu") {
41
- return api.tx.ormlXTokens.transfer(
42
- currency,
43
- amount,
44
- {
63
+ };
64
+ }
65
+ } else if (scenario === "ParaToPara") {
66
+ if (ethers.ethers.utils.isAddress(to)) {
67
+ console.log("AccountKey20 transfer");
68
+ return {
69
+ V1: {
70
+ parents: 1,
71
+ interior: {
72
+ X2: [
73
+ {
74
+ Parachain: nodeId
75
+ },
76
+ {
77
+ AccountKey20: {
78
+ network: "Any",
79
+ key: to
80
+ }
81
+ }
82
+ ]
83
+ }
84
+ }
85
+ };
86
+ } else {
87
+ console.log("AccountId32 transfer");
88
+ return {
45
89
  V1: {
46
90
  parents: 1,
91
+ interior: {
92
+ X2: [
93
+ {
94
+ Parachain: nodeId
95
+ },
96
+ {
97
+ AccountId32: {
98
+ network: "Any",
99
+ id: createAccID(api, to)
100
+ }
101
+ }
102
+ ]
103
+ }
104
+ }
105
+ };
106
+ }
107
+ }
108
+ if (scenario === "RelayToPara") {
109
+ if (ethers.ethers.utils.isAddress(to)) {
110
+ console.log("AccountKey20 transfer");
111
+ return {
112
+ V1: {
113
+ parents: 0,
114
+ interior: {
115
+ X1: {
116
+ AccountKey20: {
117
+ network: "Any",
118
+ key: to
119
+ }
120
+ }
121
+ }
122
+ }
123
+ };
124
+ } else {
125
+ console.log("AccountId32 transfer");
126
+ return {
127
+ V1: {
128
+ parents: 0,
47
129
  interior: {
48
130
  X1: {
49
131
  AccountId32: {
50
- network: "any",
132
+ network: "Any",
51
133
  id: createAccID(api, to)
52
134
  }
53
135
  }
54
136
  }
55
137
  }
56
- },
57
- 46e8
58
- );
138
+ };
139
+ }
140
+ }
141
+ }
142
+ function selectPallet(api, origin, currencyID, currency, amount, call, fees) {
143
+ switch (origin) {
144
+ case "Acala":
145
+ console.log("Transferring tokens " + currency + " from Acala");
146
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
147
+ case "Bifrost_Polkadot":
148
+ console.log("Transferring " + currency + " tokens from Bifrost - Polkadot");
149
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
150
+ case "Centrifuge":
151
+ console.log("Transferring tokens from Centrifuge");
152
+ return api.tx.xTokens.transfer("Native", amount, call, fees);
153
+ case "Clover":
154
+ console.log("Transferring tokens from Clover");
155
+ return api.tx.xTokens.transfer("SelfReserve", amount, call, fees);
156
+ case "HydraDX":
157
+ console.log("Transferring " + currencyID + "tokens from HydraDX");
158
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
159
+ case "Interlay":
160
+ console.log("Transferring " + currency + "tokens from Interlay");
161
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
162
+ case "Moonbeam":
163
+ console.log("Transferring tokens from Moonbeam");
164
+ return api.tx.xTokens.transfer("SelfReserve", amount, call, fees);
165
+ case "Parallel":
166
+ console.log("Transferring " + currencyID + " tokens from Parallel");
167
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
168
+ case "Altair":
169
+ console.log("Transferring tokens from Altair");
170
+ return api.tx.xTokens.transfer("Native", amount, call, fees);
171
+ case "Basilisk":
172
+ console.log("Transferring " + currencyID + " tokens from Basilisk");
173
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
174
+ case "Bifrost_Kusama":
175
+ console.log("Transferring " + currency + " tokens from Bifrost - Kusama");
176
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
177
+ case "Pioneer":
178
+ console.log("Transferring tokens from Pioneer");
179
+ return api.tx.xTokens.transfer("NativeToken", amount, call, fees);
180
+ case "Calamari":
181
+ console.log("Transferring " + currencyID + " tokens from Calamari");
182
+ return api.tx.xTokens.transfer({ MantaCurrency: currencyID }, amount, call, fees);
183
+ case "Crust_Shadow":
184
+ console.log("Transferring tokens from Crust Shadow");
185
+ return api.tx.xTokens.transfer("SelfReserve", amount, call, fees);
186
+ case "Dorafactory":
187
+ console.log("Transferring " + currency + " tokens from DoraFactory");
188
+ return api.tx.xTokens.transfer(currency, amount, call, fees);
189
+ case "imbue":
190
+ console.log("Transferring " + currency + " tokens from imbue");
191
+ return api.tx.xTokens.transfer(currency, amount, call, fees);
192
+ case "Integritee":
193
+ console.log("Transferring " + currency + " tokens from Integritee");
194
+ return api.tx.xTokens.transfer(currency, amount, call, fees);
195
+ case "InvArch_Tinker":
196
+ console.log("Transferring " + currencyID + " tokens from InvArch Tinker");
197
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
198
+ case "Karura":
199
+ console.log("Transferring " + currency + " tokens from Karura");
200
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
201
+ case "KICO":
202
+ console.log("Transferring " + currencyID + " tokens from KICO");
203
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
204
+ case "kintsugi":
205
+ console.log("Transferring " + currency + " tokens from kintsugi");
206
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
207
+ case "Listen":
208
+ console.log("Transferring " + currencyID + " tokens from Listen");
209
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
210
+ case "Litmus":
211
+ console.log("Transferring tokens from Litmus");
212
+ return api.tx.xTokens.transfer("SelfReserve", amount, call, fees);
213
+ case "Mangata":
214
+ console.log("Transferring " + currencyID + " tokens from Mangata");
215
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
216
+ case "Moonriver":
217
+ console.log("Transferring tokens from Moonriver");
218
+ return api.tx.xTokens.transfer("SelfReserve", amount, call, fees);
219
+ case "Parallel_Heiko":
220
+ console.log("Transferring " + currencyID + " tokens from Parallel Heiko");
221
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
222
+ case "Picasso":
223
+ console.log("Transferring " + currencyID + " tokens from Picasso");
224
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
225
+ case "Pichiu":
226
+ console.log("Transferring " + currency + " tokens from Pichiu");
227
+ return api.tx.ormlXTokens.transfer(currency, amount, call, fees);
228
+ case "Turing":
229
+ console.log("Transferring " + currencyID + " tokens from Turing");
230
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
59
231
  }
60
232
  }
233
+
234
+ function transferParaToRelay(api, origin, currency, currencyID, amount, to) {
235
+ return selectPallet(
236
+ api,
237
+ origin,
238
+ currencyID,
239
+ currency,
240
+ amount,
241
+ buildCall("ParaToRelay", api, to, 0),
242
+ getFees("ParaToRelay")
243
+ );
244
+ }
61
245
  function transferRelayToPara(api, destination, amount, to) {
62
246
  return api.tx.xcmPallet.reserveTransferAssets(
63
247
  {
@@ -70,19 +254,7 @@ function transferRelayToPara(api, destination, amount, to) {
70
254
  }
71
255
  }
72
256
  },
73
- {
74
- V1: {
75
- parents: 0,
76
- interior: {
77
- X1: {
78
- AccountId32: {
79
- network: "Any",
80
- id: createAccID(api, to)
81
- }
82
- }
83
- }
84
- }
85
- },
257
+ buildCall("RelayToPara", api, to, destination),
86
258
  {
87
259
  V1: [
88
260
  {
@@ -98,7 +270,7 @@ function transferRelayToPara(api, destination, amount, to) {
98
270
  }
99
271
  ]
100
272
  },
101
- 0
273
+ getFees("RelayToPara")
102
274
  );
103
275
  }
104
276
  function limitedTransferRelayToPara(api, destination, amount, to, limit, isLimited) {
@@ -113,19 +285,7 @@ function limitedTransferRelayToPara(api, destination, amount, to, limit, isLimit
113
285
  }
114
286
  }
115
287
  },
116
- {
117
- V1: {
118
- parents: 0,
119
- interior: {
120
- X1: {
121
- AccountId32: {
122
- network: "Any",
123
- id: createAccID(api, to)
124
- }
125
- }
126
- }
127
- }
128
- },
288
+ buildCall("RelayToPara", api, to, destination),
129
289
  {
130
290
  V1: [
131
291
  {
@@ -141,79 +301,44 @@ function limitedTransferRelayToPara(api, destination, amount, to, limit, isLimit
141
301
  }
142
302
  ]
143
303
  },
144
- 0,
304
+ getFees("RelayToPara"),
145
305
  selectLimit(limit, isLimited)
146
306
  );
147
307
  }
148
- function transferParaToPara(api, origin, destination, currency, amount, to) {
149
- if (origin == "Karura" || origin == "Bifrost") {
150
- return api.tx.xTokens.transfer(
151
- {
152
- Token: currency
153
- },
154
- amount,
155
- {
156
- V1: {
157
- parents: 1,
158
- interior: {
159
- X2: [
160
- {
161
- Parachain: destination
162
- },
163
- {
164
- AccountId32: {
165
- network: "Any",
166
- id: createAccID(api, to)
167
- }
168
- }
169
- ]
170
- }
171
- }
172
- },
173
- 3996e8
174
- );
175
- } else if (origin == "Pichiu") {
176
- return api.tx.ormlXTokens.transfer(
177
- currency,
178
- amount,
179
- {
180
- V1: {
181
- parents: 1,
182
- interior: {
183
- X2: [
184
- {
185
- Parachain: destination
186
- },
187
- {
188
- AccountId32: {
189
- network: "Any",
190
- id: createAccID(api, to)
191
- }
192
- }
193
- ]
194
- }
195
- }
196
- },
197
- 3996e8
198
- );
199
- }
308
+ function transferParaToPara(api, origin, destination, currency, currencyID, amount, to) {
309
+ return selectPallet(
310
+ api,
311
+ origin,
312
+ currencyID,
313
+ currency,
314
+ amount,
315
+ buildCall("ParaToPara", api, to, destination),
316
+ getFees("ParaToPara")
317
+ );
200
318
  }
201
319
 
202
320
  const index$2 = {
203
- __proto__: null,
204
- transferParaToPara: transferParaToPara,
205
- transferParaToRelay: transferParaToRelay,
206
- transferRelayToPara: transferRelayToPara,
207
- limitedTransferRelayToPara: limitedTransferRelayToPara
321
+ __proto__: null,
322
+ transferParaToRelay: transferParaToRelay,
323
+ transferRelayToPara: transferRelayToPara,
324
+ limitedTransferRelayToPara: limitedTransferRelayToPara,
325
+ transferParaToPara: transferParaToPara
208
326
  };
209
327
 
210
328
  function openChannel(api, origin, destination, maxSize, maxMessageSize) {
211
- return api.tx.sudo.sudo(api.tx.parasSudoWrapper.sudoEstablishHrmpChannel(origin, destination, maxSize, maxMessageSize));
329
+ return api.tx.sudo.sudo(
330
+ api.tx.parasSudoWrapper.sudoEstablishHrmpChannel(
331
+ origin,
332
+ destination,
333
+ maxSize,
334
+ maxMessageSize
335
+ )
336
+ );
212
337
  }
213
338
 
214
339
  const index$1 = {
215
- __proto__: null,
216
- openChannel: openChannel
340
+ __proto__: null,
341
+ openChannel: openChannel
217
342
  };
218
343
 
219
344
  function closeChannel(api, origin, inbound, outbound) {
@@ -221,8 +346,8 @@ function closeChannel(api, origin, inbound, outbound) {
221
346
  }
222
347
 
223
348
  const index = {
224
- __proto__: null,
225
- closeChannel: closeChannel
349
+ __proto__: null,
350
+ closeChannel: closeChannel
226
351
  };
227
352
 
228
353
  exports.closeChannels = index;
package/dist/index.d.ts CHANGED
@@ -3,21 +3,21 @@ import { SubmittableExtrinsic } from '@polkadot/api/types';
3
3
 
4
4
  declare type Extrinsic = SubmittableExtrinsic<'promise'>;
5
5
 
6
- declare function transferParaToRelay(api: ApiPromise, origin: string, currency: string, amount: any, to: string): Extrinsic;
6
+ declare function transferParaToRelay(api: ApiPromise, origin: string, currency: string, currencyID: number, amount: any, to: string): Extrinsic;
7
7
  declare function transferRelayToPara(api: ApiPromise, destination: number, amount: any, to: string): Extrinsic;
8
8
  declare function limitedTransferRelayToPara(api: ApiPromise, destination: number, amount: any, to: string, limit: number, isLimited: boolean): Extrinsic;
9
- declare function transferParaToPara(api: ApiPromise, origin: string, destination: number, currency: string, amount: any, to: string): Extrinsic;
9
+ declare function transferParaToPara(api: ApiPromise, origin: string, destination: number, currency: string, currencyID: number, amount: any, to: string): Extrinsic;
10
10
 
11
- declare const index$2_transferParaToPara: typeof transferParaToPara;
12
11
  declare const index$2_transferParaToRelay: typeof transferParaToRelay;
13
12
  declare const index$2_transferRelayToPara: typeof transferRelayToPara;
14
13
  declare const index$2_limitedTransferRelayToPara: typeof limitedTransferRelayToPara;
14
+ declare const index$2_transferParaToPara: typeof transferParaToPara;
15
15
  declare namespace index$2 {
16
16
  export {
17
- index$2_transferParaToPara as transferParaToPara,
18
17
  index$2_transferParaToRelay as transferParaToRelay,
19
18
  index$2_transferRelayToPara as transferRelayToPara,
20
19
  index$2_limitedTransferRelayToPara as limitedTransferRelayToPara,
20
+ index$2_transferParaToPara as transferParaToPara,
21
21
  };
22
22
  }
23
23
 
package/dist/index.mjs CHANGED
@@ -1,4 +1,7 @@
1
+ import { ethers } from 'ethers';
2
+
1
3
  function createAccID(api, account) {
4
+ console.log("Generating AccountId32 address");
2
5
  return api.createType("AccountId32", account).toHex();
3
6
  }
4
7
  function selectLimit(limit, isLimited) {
@@ -10,15 +13,38 @@ function selectLimit(limit, isLimited) {
10
13
  return "Unlimited";
11
14
  }
12
15
  }
13
-
14
- function transferParaToRelay(api, origin, currency, amount, to) {
15
- if (origin == "Karura" || origin == "Bifrost") {
16
- return api.tx.xTokens.transfer(
17
- {
18
- Token: currency
19
- },
20
- amount,
21
- {
16
+ function getFees(scenario) {
17
+ if (scenario === "ParaToRelay") {
18
+ console.log("Asigning fees for transfer to Relay chain");
19
+ return 46e8;
20
+ } else if (scenario === "ParaToPara") {
21
+ console.log("Asigning fees for transfer to another Parachain chain");
22
+ return 3996e8;
23
+ } else {
24
+ console.log("Asigning fees for transfer from Relay chain");
25
+ return 0;
26
+ }
27
+ }
28
+ function buildCall(scenario, api, to, nodeId) {
29
+ if (scenario === "ParaToRelay") {
30
+ if (ethers.utils.isAddress(to)) {
31
+ console.log("AccountKey20 transfer");
32
+ return {
33
+ V1: {
34
+ parents: 1,
35
+ interior: {
36
+ X1: {
37
+ AccountKey20: {
38
+ network: "any",
39
+ key: to
40
+ }
41
+ }
42
+ }
43
+ }
44
+ };
45
+ } else {
46
+ console.log("AccountId32 transfer");
47
+ return {
22
48
  V1: {
23
49
  parents: 1,
24
50
  interior: {
@@ -30,30 +56,188 @@ function transferParaToRelay(api, origin, currency, amount, to) {
30
56
  }
31
57
  }
32
58
  }
33
- },
34
- 46e8
35
- );
36
- } else if (origin == "Pichiu") {
37
- return api.tx.ormlXTokens.transfer(
38
- currency,
39
- amount,
40
- {
59
+ };
60
+ }
61
+ } else if (scenario === "ParaToPara") {
62
+ if (ethers.utils.isAddress(to)) {
63
+ console.log("AccountKey20 transfer");
64
+ return {
65
+ V1: {
66
+ parents: 1,
67
+ interior: {
68
+ X2: [
69
+ {
70
+ Parachain: nodeId
71
+ },
72
+ {
73
+ AccountKey20: {
74
+ network: "Any",
75
+ key: to
76
+ }
77
+ }
78
+ ]
79
+ }
80
+ }
81
+ };
82
+ } else {
83
+ console.log("AccountId32 transfer");
84
+ return {
41
85
  V1: {
42
86
  parents: 1,
87
+ interior: {
88
+ X2: [
89
+ {
90
+ Parachain: nodeId
91
+ },
92
+ {
93
+ AccountId32: {
94
+ network: "Any",
95
+ id: createAccID(api, to)
96
+ }
97
+ }
98
+ ]
99
+ }
100
+ }
101
+ };
102
+ }
103
+ }
104
+ if (scenario === "RelayToPara") {
105
+ if (ethers.utils.isAddress(to)) {
106
+ console.log("AccountKey20 transfer");
107
+ return {
108
+ V1: {
109
+ parents: 0,
110
+ interior: {
111
+ X1: {
112
+ AccountKey20: {
113
+ network: "Any",
114
+ key: to
115
+ }
116
+ }
117
+ }
118
+ }
119
+ };
120
+ } else {
121
+ console.log("AccountId32 transfer");
122
+ return {
123
+ V1: {
124
+ parents: 0,
43
125
  interior: {
44
126
  X1: {
45
127
  AccountId32: {
46
- network: "any",
128
+ network: "Any",
47
129
  id: createAccID(api, to)
48
130
  }
49
131
  }
50
132
  }
51
133
  }
52
- },
53
- 46e8
54
- );
134
+ };
135
+ }
136
+ }
137
+ }
138
+ function selectPallet(api, origin, currencyID, currency, amount, call, fees) {
139
+ switch (origin) {
140
+ case "Acala":
141
+ console.log("Transferring tokens " + currency + " from Acala");
142
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
143
+ case "Bifrost_Polkadot":
144
+ console.log("Transferring " + currency + " tokens from Bifrost - Polkadot");
145
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
146
+ case "Centrifuge":
147
+ console.log("Transferring tokens from Centrifuge");
148
+ return api.tx.xTokens.transfer("Native", amount, call, fees);
149
+ case "Clover":
150
+ console.log("Transferring tokens from Clover");
151
+ return api.tx.xTokens.transfer("SelfReserve", amount, call, fees);
152
+ case "HydraDX":
153
+ console.log("Transferring " + currencyID + "tokens from HydraDX");
154
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
155
+ case "Interlay":
156
+ console.log("Transferring " + currency + "tokens from Interlay");
157
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
158
+ case "Moonbeam":
159
+ console.log("Transferring tokens from Moonbeam");
160
+ return api.tx.xTokens.transfer("SelfReserve", amount, call, fees);
161
+ case "Parallel":
162
+ console.log("Transferring " + currencyID + " tokens from Parallel");
163
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
164
+ case "Altair":
165
+ console.log("Transferring tokens from Altair");
166
+ return api.tx.xTokens.transfer("Native", amount, call, fees);
167
+ case "Basilisk":
168
+ console.log("Transferring " + currencyID + " tokens from Basilisk");
169
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
170
+ case "Bifrost_Kusama":
171
+ console.log("Transferring " + currency + " tokens from Bifrost - Kusama");
172
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
173
+ case "Pioneer":
174
+ console.log("Transferring tokens from Pioneer");
175
+ return api.tx.xTokens.transfer("NativeToken", amount, call, fees);
176
+ case "Calamari":
177
+ console.log("Transferring " + currencyID + " tokens from Calamari");
178
+ return api.tx.xTokens.transfer({ MantaCurrency: currencyID }, amount, call, fees);
179
+ case "Crust_Shadow":
180
+ console.log("Transferring tokens from Crust Shadow");
181
+ return api.tx.xTokens.transfer("SelfReserve", amount, call, fees);
182
+ case "Dorafactory":
183
+ console.log("Transferring " + currency + " tokens from DoraFactory");
184
+ return api.tx.xTokens.transfer(currency, amount, call, fees);
185
+ case "imbue":
186
+ console.log("Transferring " + currency + " tokens from imbue");
187
+ return api.tx.xTokens.transfer(currency, amount, call, fees);
188
+ case "Integritee":
189
+ console.log("Transferring " + currency + " tokens from Integritee");
190
+ return api.tx.xTokens.transfer(currency, amount, call, fees);
191
+ case "InvArch_Tinker":
192
+ console.log("Transferring " + currencyID + " tokens from InvArch Tinker");
193
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
194
+ case "Karura":
195
+ console.log("Transferring " + currency + " tokens from Karura");
196
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
197
+ case "KICO":
198
+ console.log("Transferring " + currencyID + " tokens from KICO");
199
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
200
+ case "kintsugi":
201
+ console.log("Transferring " + currency + " tokens from kintsugi");
202
+ return api.tx.xTokens.transfer({ Token: currency }, amount, call, fees);
203
+ case "Listen":
204
+ console.log("Transferring " + currencyID + " tokens from Listen");
205
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
206
+ case "Litmus":
207
+ console.log("Transferring tokens from Litmus");
208
+ return api.tx.xTokens.transfer("SelfReserve", amount, call, fees);
209
+ case "Mangata":
210
+ console.log("Transferring " + currencyID + " tokens from Mangata");
211
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
212
+ case "Moonriver":
213
+ console.log("Transferring tokens from Moonriver");
214
+ return api.tx.xTokens.transfer("SelfReserve", amount, call, fees);
215
+ case "Parallel_Heiko":
216
+ console.log("Transferring " + currencyID + " tokens from Parallel Heiko");
217
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
218
+ case "Picasso":
219
+ console.log("Transferring " + currencyID + " tokens from Picasso");
220
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
221
+ case "Pichiu":
222
+ console.log("Transferring " + currency + " tokens from Pichiu");
223
+ return api.tx.ormlXTokens.transfer(currency, amount, call, fees);
224
+ case "Turing":
225
+ console.log("Transferring " + currencyID + " tokens from Turing");
226
+ return api.tx.xTokens.transfer(currencyID, amount, call, fees);
55
227
  }
56
228
  }
229
+
230
+ function transferParaToRelay(api, origin, currency, currencyID, amount, to) {
231
+ return selectPallet(
232
+ api,
233
+ origin,
234
+ currencyID,
235
+ currency,
236
+ amount,
237
+ buildCall("ParaToRelay", api, to, 0),
238
+ getFees("ParaToRelay")
239
+ );
240
+ }
57
241
  function transferRelayToPara(api, destination, amount, to) {
58
242
  return api.tx.xcmPallet.reserveTransferAssets(
59
243
  {
@@ -66,19 +250,7 @@ function transferRelayToPara(api, destination, amount, to) {
66
250
  }
67
251
  }
68
252
  },
69
- {
70
- V1: {
71
- parents: 0,
72
- interior: {
73
- X1: {
74
- AccountId32: {
75
- network: "Any",
76
- id: createAccID(api, to)
77
- }
78
- }
79
- }
80
- }
81
- },
253
+ buildCall("RelayToPara", api, to, destination),
82
254
  {
83
255
  V1: [
84
256
  {
@@ -94,7 +266,7 @@ function transferRelayToPara(api, destination, amount, to) {
94
266
  }
95
267
  ]
96
268
  },
97
- 0
269
+ getFees("RelayToPara")
98
270
  );
99
271
  }
100
272
  function limitedTransferRelayToPara(api, destination, amount, to, limit, isLimited) {
@@ -109,19 +281,7 @@ function limitedTransferRelayToPara(api, destination, amount, to, limit, isLimit
109
281
  }
110
282
  }
111
283
  },
112
- {
113
- V1: {
114
- parents: 0,
115
- interior: {
116
- X1: {
117
- AccountId32: {
118
- network: "Any",
119
- id: createAccID(api, to)
120
- }
121
- }
122
- }
123
- }
124
- },
284
+ buildCall("RelayToPara", api, to, destination),
125
285
  {
126
286
  V1: [
127
287
  {
@@ -137,79 +297,44 @@ function limitedTransferRelayToPara(api, destination, amount, to, limit, isLimit
137
297
  }
138
298
  ]
139
299
  },
140
- 0,
300
+ getFees("RelayToPara"),
141
301
  selectLimit(limit, isLimited)
142
302
  );
143
303
  }
144
- function transferParaToPara(api, origin, destination, currency, amount, to) {
145
- if (origin == "Karura" || origin == "Bifrost") {
146
- return api.tx.xTokens.transfer(
147
- {
148
- Token: currency
149
- },
150
- amount,
151
- {
152
- V1: {
153
- parents: 1,
154
- interior: {
155
- X2: [
156
- {
157
- Parachain: destination
158
- },
159
- {
160
- AccountId32: {
161
- network: "Any",
162
- id: createAccID(api, to)
163
- }
164
- }
165
- ]
166
- }
167
- }
168
- },
169
- 3996e8
170
- );
171
- } else if (origin == "Pichiu") {
172
- return api.tx.ormlXTokens.transfer(
173
- currency,
174
- amount,
175
- {
176
- V1: {
177
- parents: 1,
178
- interior: {
179
- X2: [
180
- {
181
- Parachain: destination
182
- },
183
- {
184
- AccountId32: {
185
- network: "Any",
186
- id: createAccID(api, to)
187
- }
188
- }
189
- ]
190
- }
191
- }
192
- },
193
- 3996e8
194
- );
195
- }
304
+ function transferParaToPara(api, origin, destination, currency, currencyID, amount, to) {
305
+ return selectPallet(
306
+ api,
307
+ origin,
308
+ currencyID,
309
+ currency,
310
+ amount,
311
+ buildCall("ParaToPara", api, to, destination),
312
+ getFees("ParaToPara")
313
+ );
196
314
  }
197
315
 
198
316
  const index$2 = {
199
- __proto__: null,
200
- transferParaToPara: transferParaToPara,
201
- transferParaToRelay: transferParaToRelay,
202
- transferRelayToPara: transferRelayToPara,
203
- limitedTransferRelayToPara: limitedTransferRelayToPara
317
+ __proto__: null,
318
+ transferParaToRelay: transferParaToRelay,
319
+ transferRelayToPara: transferRelayToPara,
320
+ limitedTransferRelayToPara: limitedTransferRelayToPara,
321
+ transferParaToPara: transferParaToPara
204
322
  };
205
323
 
206
324
  function openChannel(api, origin, destination, maxSize, maxMessageSize) {
207
- return api.tx.sudo.sudo(api.tx.parasSudoWrapper.sudoEstablishHrmpChannel(origin, destination, maxSize, maxMessageSize));
325
+ return api.tx.sudo.sudo(
326
+ api.tx.parasSudoWrapper.sudoEstablishHrmpChannel(
327
+ origin,
328
+ destination,
329
+ maxSize,
330
+ maxMessageSize
331
+ )
332
+ );
208
333
  }
209
334
 
210
335
  const index$1 = {
211
- __proto__: null,
212
- openChannel: openChannel
336
+ __proto__: null,
337
+ openChannel: openChannel
213
338
  };
214
339
 
215
340
  function closeChannel(api, origin, inbound, outbound) {
@@ -217,8 +342,8 @@ function closeChannel(api, origin, inbound, outbound) {
217
342
  }
218
343
 
219
344
  const index = {
220
- __proto__: null,
221
- closeChannel: closeChannel
345
+ __proto__: null,
346
+ closeChannel: closeChannel
222
347
  };
223
348
 
224
349
  export { index as closeChannels, index$1 as openChannels, index$2 as xTokens };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk",
3
- "version": "0.0.10",
3
+ "version": "0.0.11-alpha.0",
4
4
  "description": "SDK for ParaSpell XCM/XCMP tool for developers",
5
5
  "repository": "@paraspell/sdk",
6
6
  "license": "MIT",
@@ -20,7 +20,8 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "@polkadot/api": "^8.0.2",
23
- "@polkadot/types": "^8.0.2"
23
+ "@polkadot/types": "^8.0.2",
24
+ "ethers": "^5.7.1"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@nuxtjs/eslint-config-typescript": "latest",
@@ -35,7 +36,7 @@
35
36
  "scripts": {
36
37
  "build": "unbuild",
37
38
  "dev": "vitest dev",
38
- "lint": "eslint --ext .ts,.js,.mjs,.cjs .",
39
+ "lint": "eslint --fix --ext .ts,.js,.mjs,.cjs .",
39
40
  "release": "pnpm test && standard-version && git push --follow-tags && pnpm publish --no-git-checks --access=public",
40
41
  "test": "pnpm lint && vitest run --coverage"
41
42
  }