@paraspell/sdk 0.0.8 → 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,18 +2,53 @@
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
-
9
- function transferParaToRelay(api, origin, currency, amount, to) {
10
- if (origin == "Karura" || origin == "Bifrost") {
11
- return api.tx.xTokens.transfer(
12
- {
13
- Token: currency
14
- },
15
- amount,
16
- {
11
+ function selectLimit(limit, isLimited) {
12
+ if (isLimited) {
13
+ return {
14
+ Limited: limit
15
+ };
16
+ } else {
17
+ return "Unlimited";
18
+ }
19
+ }
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 {
17
52
  V1: {
18
53
  parents: 1,
19
54
  interior: {
@@ -25,30 +60,188 @@ function transferParaToRelay(api, origin, currency, amount, to) {
25
60
  }
26
61
  }
27
62
  }
28
- },
29
- 46e8
30
- );
31
- } else if (origin == "Pichiu") {
32
- return api.tx.ormlXTokens.transfer(
33
- currency,
34
- amount,
35
- {
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 {
36
89
  V1: {
37
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,
38
129
  interior: {
39
130
  X1: {
40
131
  AccountId32: {
41
- network: "any",
132
+ network: "Any",
42
133
  id: createAccID(api, to)
43
134
  }
44
135
  }
45
136
  }
46
137
  }
47
- },
48
- 46e8
49
- );
138
+ };
139
+ }
50
140
  }
51
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);
231
+ }
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
+ }
52
245
  function transferRelayToPara(api, destination, amount, to) {
53
246
  return api.tx.xcmPallet.reserveTransferAssets(
54
247
  {
@@ -61,19 +254,38 @@ function transferRelayToPara(api, destination, amount, to) {
61
254
  }
62
255
  }
63
256
  },
257
+ buildCall("RelayToPara", api, to, destination),
258
+ {
259
+ V1: [
260
+ {
261
+ id: {
262
+ Concrete: {
263
+ parents: 0,
264
+ interior: "Here"
265
+ }
266
+ },
267
+ fun: {
268
+ Fungible: amount
269
+ }
270
+ }
271
+ ]
272
+ },
273
+ getFees("RelayToPara")
274
+ );
275
+ }
276
+ function limitedTransferRelayToPara(api, destination, amount, to, limit, isLimited) {
277
+ return api.tx.xcmPallet.limitedReserveTransferAssets(
64
278
  {
65
279
  V1: {
66
280
  parents: 0,
67
281
  interior: {
68
282
  X1: {
69
- AccountId32: {
70
- network: "Any",
71
- id: createAccID(api, to)
72
- }
283
+ Parachain: destination
73
284
  }
74
285
  }
75
286
  }
76
287
  },
288
+ buildCall("RelayToPara", api, to, destination),
77
289
  {
78
290
  V1: [
79
291
  {
@@ -89,77 +301,44 @@ function transferRelayToPara(api, destination, amount, to) {
89
301
  }
90
302
  ]
91
303
  },
92
- 0
304
+ getFees("RelayToPara"),
305
+ selectLimit(limit, isLimited)
93
306
  );
94
307
  }
95
- function transferParaToPara(api, origin, destination, currency, amount, to) {
96
- if (origin == "Karura" || origin == "Bifrost") {
97
- return api.tx.xTokens.transfer(
98
- {
99
- Token: currency
100
- },
101
- amount,
102
- {
103
- V1: {
104
- parents: 1,
105
- interior: {
106
- X2: [
107
- {
108
- Parachain: destination
109
- },
110
- {
111
- AccountId32: {
112
- network: "Any",
113
- id: createAccID(api, to)
114
- }
115
- }
116
- ]
117
- }
118
- }
119
- },
120
- 3996e8
121
- );
122
- } else if (origin == "Pichiu") {
123
- return api.tx.ormlXTokens.transfer(
124
- currency,
125
- amount,
126
- {
127
- V1: {
128
- parents: 1,
129
- interior: {
130
- X2: [
131
- {
132
- Parachain: destination
133
- },
134
- {
135
- AccountId32: {
136
- network: "Any",
137
- id: createAccID(api, to)
138
- }
139
- }
140
- ]
141
- }
142
- }
143
- },
144
- 3996e8
145
- );
146
- }
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
+ );
147
318
  }
148
319
 
149
320
  const index$2 = {
150
- __proto__: null,
151
- transferParaToPara: transferParaToPara,
152
- transferParaToRelay: transferParaToRelay,
153
- transferRelayToPara: transferRelayToPara
321
+ __proto__: null,
322
+ transferParaToRelay: transferParaToRelay,
323
+ transferRelayToPara: transferRelayToPara,
324
+ limitedTransferRelayToPara: limitedTransferRelayToPara,
325
+ transferParaToPara: transferParaToPara
154
326
  };
155
327
 
156
328
  function openChannel(api, origin, destination, maxSize, maxMessageSize) {
157
- 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
+ );
158
337
  }
159
338
 
160
339
  const index$1 = {
161
- __proto__: null,
162
- openChannel: openChannel
340
+ __proto__: null,
341
+ openChannel: openChannel
163
342
  };
164
343
 
165
344
  function closeChannel(api, origin, inbound, outbound) {
@@ -167,8 +346,8 @@ function closeChannel(api, origin, inbound, outbound) {
167
346
  }
168
347
 
169
348
  const index = {
170
- __proto__: null,
171
- closeChannel: closeChannel
349
+ __proto__: null,
350
+ closeChannel: closeChannel
172
351
  };
173
352
 
174
353
  exports.closeChannels = index;
package/dist/index.d.ts CHANGED
@@ -3,18 +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
- declare function transferParaToPara(api: ApiPromise, origin: string, destination: number, currency: string, amount: any, to: string): Extrinsic;
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, currencyID: number, amount: any, to: string): Extrinsic;
9
10
 
10
- declare const index$2_transferParaToPara: typeof transferParaToPara;
11
11
  declare const index$2_transferParaToRelay: typeof transferParaToRelay;
12
12
  declare const index$2_transferRelayToPara: typeof transferRelayToPara;
13
+ declare const index$2_limitedTransferRelayToPara: typeof limitedTransferRelayToPara;
14
+ declare const index$2_transferParaToPara: typeof transferParaToPara;
13
15
  declare namespace index$2 {
14
16
  export {
15
- index$2_transferParaToPara as transferParaToPara,
16
17
  index$2_transferParaToRelay as transferParaToRelay,
17
18
  index$2_transferRelayToPara as transferRelayToPara,
19
+ index$2_limitedTransferRelayToPara as limitedTransferRelayToPara,
20
+ index$2_transferParaToPara as transferParaToPara,
18
21
  };
19
22
  }
20
23
 
package/dist/index.mjs CHANGED
@@ -1,15 +1,50 @@
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
-
5
- function transferParaToRelay(api, origin, currency, amount, to) {
6
- if (origin == "Karura" || origin == "Bifrost") {
7
- return api.tx.xTokens.transfer(
8
- {
9
- Token: currency
10
- },
11
- amount,
12
- {
7
+ function selectLimit(limit, isLimited) {
8
+ if (isLimited) {
9
+ return {
10
+ Limited: limit
11
+ };
12
+ } else {
13
+ return "Unlimited";
14
+ }
15
+ }
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 {
13
48
  V1: {
14
49
  parents: 1,
15
50
  interior: {
@@ -21,30 +56,188 @@ function transferParaToRelay(api, origin, currency, amount, to) {
21
56
  }
22
57
  }
23
58
  }
24
- },
25
- 46e8
26
- );
27
- } else if (origin == "Pichiu") {
28
- return api.tx.ormlXTokens.transfer(
29
- currency,
30
- amount,
31
- {
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 {
32
85
  V1: {
33
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,
34
125
  interior: {
35
126
  X1: {
36
127
  AccountId32: {
37
- network: "any",
128
+ network: "Any",
38
129
  id: createAccID(api, to)
39
130
  }
40
131
  }
41
132
  }
42
133
  }
43
- },
44
- 46e8
45
- );
134
+ };
135
+ }
46
136
  }
47
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);
227
+ }
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
+ }
48
241
  function transferRelayToPara(api, destination, amount, to) {
49
242
  return api.tx.xcmPallet.reserveTransferAssets(
50
243
  {
@@ -57,19 +250,38 @@ function transferRelayToPara(api, destination, amount, to) {
57
250
  }
58
251
  }
59
252
  },
253
+ buildCall("RelayToPara", api, to, destination),
254
+ {
255
+ V1: [
256
+ {
257
+ id: {
258
+ Concrete: {
259
+ parents: 0,
260
+ interior: "Here"
261
+ }
262
+ },
263
+ fun: {
264
+ Fungible: amount
265
+ }
266
+ }
267
+ ]
268
+ },
269
+ getFees("RelayToPara")
270
+ );
271
+ }
272
+ function limitedTransferRelayToPara(api, destination, amount, to, limit, isLimited) {
273
+ return api.tx.xcmPallet.limitedReserveTransferAssets(
60
274
  {
61
275
  V1: {
62
276
  parents: 0,
63
277
  interior: {
64
278
  X1: {
65
- AccountId32: {
66
- network: "Any",
67
- id: createAccID(api, to)
68
- }
279
+ Parachain: destination
69
280
  }
70
281
  }
71
282
  }
72
283
  },
284
+ buildCall("RelayToPara", api, to, destination),
73
285
  {
74
286
  V1: [
75
287
  {
@@ -85,77 +297,44 @@ function transferRelayToPara(api, destination, amount, to) {
85
297
  }
86
298
  ]
87
299
  },
88
- 0
300
+ getFees("RelayToPara"),
301
+ selectLimit(limit, isLimited)
89
302
  );
90
303
  }
91
- function transferParaToPara(api, origin, destination, currency, amount, to) {
92
- if (origin == "Karura" || origin == "Bifrost") {
93
- return api.tx.xTokens.transfer(
94
- {
95
- Token: currency
96
- },
97
- amount,
98
- {
99
- V1: {
100
- parents: 1,
101
- interior: {
102
- X2: [
103
- {
104
- Parachain: destination
105
- },
106
- {
107
- AccountId32: {
108
- network: "Any",
109
- id: createAccID(api, to)
110
- }
111
- }
112
- ]
113
- }
114
- }
115
- },
116
- 3996e8
117
- );
118
- } else if (origin == "Pichiu") {
119
- return api.tx.ormlXTokens.transfer(
120
- currency,
121
- amount,
122
- {
123
- V1: {
124
- parents: 1,
125
- interior: {
126
- X2: [
127
- {
128
- Parachain: destination
129
- },
130
- {
131
- AccountId32: {
132
- network: "Any",
133
- id: createAccID(api, to)
134
- }
135
- }
136
- ]
137
- }
138
- }
139
- },
140
- 3996e8
141
- );
142
- }
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
+ );
143
314
  }
144
315
 
145
316
  const index$2 = {
146
- __proto__: null,
147
- transferParaToPara: transferParaToPara,
148
- transferParaToRelay: transferParaToRelay,
149
- transferRelayToPara: transferRelayToPara
317
+ __proto__: null,
318
+ transferParaToRelay: transferParaToRelay,
319
+ transferRelayToPara: transferRelayToPara,
320
+ limitedTransferRelayToPara: limitedTransferRelayToPara,
321
+ transferParaToPara: transferParaToPara
150
322
  };
151
323
 
152
324
  function openChannel(api, origin, destination, maxSize, maxMessageSize) {
153
- 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
+ );
154
333
  }
155
334
 
156
335
  const index$1 = {
157
- __proto__: null,
158
- openChannel: openChannel
336
+ __proto__: null,
337
+ openChannel: openChannel
159
338
  };
160
339
 
161
340
  function closeChannel(api, origin, inbound, outbound) {
@@ -163,8 +342,8 @@ function closeChannel(api, origin, inbound, outbound) {
163
342
  }
164
343
 
165
344
  const index = {
166
- __proto__: null,
167
- closeChannel: closeChannel
345
+ __proto__: null,
346
+ closeChannel: closeChannel
168
347
  };
169
348
 
170
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.8",
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,8 +36,8 @@
35
36
  "scripts": {
36
37
  "build": "unbuild",
37
38
  "dev": "vitest dev",
38
- "lint": "eslint --ext .ts,.js,.mjs,.cjs .",
39
- "release": "pnpm test && standard-version && git push --follow-tags && pnpm publish --access=public",
39
+ "lint": "eslint --fix --ext .ts,.js,.mjs,.cjs .",
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
  }
42
43
  }