@paraspell/sdk 7.2.9 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,34 +17,26 @@
17
17
  <img alt="snyk" src="https://snyk.io/test/github/paraspell/sdk/badge.svg" />
18
18
  </a>
19
19
  </p>
20
- <p>Currently supporting 58 Polkadot & Kusama nodes list <a href = "https://paraspell.github.io/docs/supported.html"\>[here]</p>
20
+ <p>Supporting every XCM Active Parachain <a href = "https://paraspell.github.io/docs/supported.html"\>[list]</p>
21
21
  <p>SDK documentation <a href = "https://paraspell.github.io/docs/" \>[here]</p>
22
22
  <p>SDK starter template project <a href = "https://github.com/paraspell/xcm-sdk-template" \>[here]</p>
23
23
  </div>
24
24
 
25
25
  <br /><br />
26
26
  <br /><br />
27
+
27
28
  ## Installation
28
29
 
29
30
  ### Install dependencies
30
31
 
31
- Install peer dependencies according to the choice of API package.
32
-
33
32
  ParaSpell XCM SDK is the 🥇 in the ecosystem to support both **PolkadotJS** and **PolkadotAPI**.
34
33
 
35
- ```
36
- NOTE: Make sure to set PeerDependencyInstall flag to false on your package manager (Because it will install both API packages instead of just one)
37
- For example on PNPM: `pnpm config set auto-install-peers false`
38
- ```
34
+ **This version of SDK uses PolkadotAPI** if you wish to use **PolkadotJS** version please reffer to [following package](https://github.com/paraspell/xcm-tools/tree/main/packages/sdk-pjs).
39
35
 
40
- ```bash
41
- #Choose a package and install its dependencies below (SDK is built in a way, that only one library has to be installed)
42
36
 
37
+ ```bash
43
38
  #Polkadot API peer dependencies
44
39
  pnpm | npm install || yarn add polkadot-api
45
-
46
- #PolkadotJS peer dependencies
47
- pnpm | npm install || yarn add @polkadot/api @polkadot/types @polkadot/api-base @polkadot/util
48
40
  ```
49
41
 
50
42
  ### Install SDK
@@ -58,30 +50,21 @@ pnpm | npm install || yarn add @paraspell/sdk
58
50
  Builder pattern:
59
51
  ```js
60
52
  // Polkadot API version
61
- import { Builder } from '@paraspell/sdk/papi'
62
-
63
- // Polkadot JS version
64
53
  import { Builder } from '@paraspell/sdk'
65
54
  ```
66
55
 
67
56
  Other patterns:
68
57
  ```js
69
- // ESM PAPI
70
- import * as paraspell from '@paraspell/sdk/papi'
71
- // ESM PJS
58
+ // ESM
72
59
  import * as paraspell from '@paraspell/sdk'
73
60
 
74
- // CommonJS PAPI
75
- const paraspell = require('@paraspell/sdk/papi')
76
-
77
- // CommonJS PJS
61
+ // CommonJS
78
62
  const paraspell = require('@paraspell/sdk')
79
63
  ```
80
64
 
81
65
  Interaction with further asset symbol abstraction:
82
66
  ```js
83
- import { Native, Foreign, ForeignAbstract } from '@paraspell/sdk'; //Only needed when advanced asset symbol selection is used. PJS version.
84
- import { Native, Foreign, ForeignAbstract } from '@paraspell/sdk/papi'; //Only needed when advanced asset symbol selection is used. PAPI version.
67
+ import { Native, Foreign, ForeignAbstract } from '@paraspell/sdk'; //Only needed when advanced asset symbol selection is used.
85
68
  ```
86
69
  ## Implementation
87
70
 
@@ -89,111 +72,108 @@ import { Native, Foreign, ForeignAbstract } from '@paraspell/sdk/papi'; //Only n
89
72
  NOTES:
90
73
  - If you wish to transfer from Parachain that uses long IDs for example Moonbeam you have to add the character 'n' to the end of currencyID. Eg: .currency({id: 42259045809535163221576417993425387648n}) will mean you transfer xcDOT.
91
74
  - You can now use custom ParachainIDs if you wish to test in TestNet. Just add parachainID as an additional parameter eg: .to('Basilisk', 2948).
92
- - You can now add an optional parameter useKeepAlive which will ensure, that you send more than the existential deposit.
93
- - Since v5 you can fully customize all multilocations (address, currency and destination). Instead of a string parameter simply pass an object with multilocation instead for more information refer to the following PR https://github.com/paraspell/xcm-tools/pull/199.
94
- - Fee asset is now a required builder parameter when you enter a multilocation array.
95
- - When using a multilocation array the amount parameter is overridden.
96
- - Multilocation arrays are now available. Customize your asset multilocations by .currency({multiasset: [{multilocation1},{multilocation2}..{multilocationN}]}) For more information refer to the official documentation or following PR https://github.com/paraspell/xcm-tools/pull/224.
97
75
  - POLKADOT <> KUSAMA Bridge is now available! Try sending DOT or KSM between AssetHubs - More information here: https://paraspell.github.io/docs/sdk/xcmPallet.html#ecosystem-bridges.
98
76
  - You can now customize XCM Version! Try using .xcmVersion parameter after address in builder.
99
77
  - POLKADOT <> ETHEREUM Bridge is now available! Try sending WETH between the ecosystems - More information here: https://paraspell.github.io/docs/sdk/xcmPallet.html#ecosystem-bridges.
78
+ - ParaSpell now offers advanced asset symbol selection {symbol: "symbol"} for non duplicate assets, {symbol: Native("symbol")} or {symbol: Foreign("symbol")} if the duplicates are between native and foreign assets and {symbol: ForeignAbstract("symbol")} if the duplicates are in foreign assets only. You will get an error that will guide you further if you simply start with {symbol: "symbol"}.
79
+ - You can now select assets by multilocation by simply using { multilocation: string | JSON }. The custom multilocation selection remains supported, but in order to use it you now have to use override - {multilocation: Override('Custom Multilocation')}.
80
+ - The balance queries also support multilocation asset selection
100
81
  ```
101
82
 
102
83
  ```
103
84
  Latest news:
104
- - ParaSpell now offers advanced asset symbol selection {symbol: "symbol"} for non duplicate assets, {symbol: Native("symbol")} or {symbol: Foreign("symbol")} if the duplicates are between native and foreign assets and {symbol: ForeignAbstract("symbol")} if the duplicates are in foreign assets only. You will get an error that will guide you further if you simply start with {symbol: "symbol"}.
105
- - You can now select assets by multilocation by simply using { multilocation: string | JSON }. The custom multilocation selection remains supported, but in order to use it you now have to use override - {multilocation: Override('Custom Multilocation')}.
106
- - The balance queries also support multilocation asset selection
107
85
  - PAPI version of SDK is now fully PJS-less (We removed apps/config as dependency entirely).
86
+ - You can now query foreign asset minimal deposits also.
87
+ - Since v8, amount moved closer to currency selection and specifying from and to parameters is no longer optional to save code.
88
+ - More information on v8 major breaking change: https://github.com/paraspell/xcm-tools/pull/554
89
+ - XCM SDK Now supports API Failsafe - If one endpoint doesn't work it automatically switches to the next one.
108
90
  ```
109
91
 
110
92
  ### Builder pattern:
111
93
 
112
94
  ##### Transfer assets from Parachain to Parachain
113
95
  ```ts
114
- await Builder(/*node api/ws_url_string - optional*/)
96
+ await Builder(/*node api/ws_url_string/ws_url_array - optional*/)
115
97
  .from(NODE)
116
98
  .to(NODE /*,customParaId - optional*/ | Multilocation object /*Only works for PolkadotXCM pallet*/)
117
- .currency({id: currencyID} | {symbol: currencySymbol} | {symbol: Native('currencySymbol')} | {symbol: Foreign('currencySymbol')} | {symbol: ForeignAbstract('currencySymbol')} | {multilocation: AssetMultilocationString | AssetMultilocationJson} | {multilocation: Override('Custom Multilocation')} | {multiasset: multilocationJsonArray})
118
- /*.feeAsset(feeAsset) - Parameter required when using MultilocationArray*/
119
- .amount(amount) // Overriden when using MultilocationArray
99
+ .currency({id: currencyID, amount: amount} | {symbol: currencySymbol, amount: amount} | {symbol: Native('currencySymbol'), amount: amount} | {symbol: Foreign('currencySymbol'), amount: amount} | {symbol: ForeignAbstract('currencySymbol'), amount: amount} | {multilocation: AssetMultilocationString, amount: amount | AssetMultilocationJson, amount: amount} | {multilocation: Override('Custom Multilocation'), amount: amount} | {multiasset: {currencySelection, isFeeAsset?: true /* for example symbol: symbol or id: id, or multilocation: multilocation*/, amount: amount}})
120
100
  .address(address | Multilocation object /*If you are sending through xTokens, you need to pass the destination and address multilocation in one object (x2)*/)
121
- /*.xcmVersion(Version.V1/V2/V3/V4) //Optional parameter for manual override of XCM Version used in call*/
101
+ /*.xcmVersion(Version.V1/V2/V3/V4) //Optional parameter for manual override of XCM Version used in call
102
+ .customPallet('Pallet','pallet_function') //Optional parameter for manual override of XCM Pallet and function used in call (If they are named differently on some node but syntax stays the same). Both pallet name and function required. Pallet name must be CamelCase, function name snake_case.*/
122
103
  .build()
123
104
  /*
124
105
  EXAMPLE:
125
- await Builder()
126
- .from('Hydration')
127
- .to('BifrostPolkadot')
128
- .currency({symbol:'BNC'})
129
- .amount(1000000000000)
130
- .address('4FCUYBMe2sbq5KosN22emsPUydS8XUwZhJ6VUZesmouGu6qd')
131
- .build()
106
+ const tx = await Builder()
107
+ .from('Acala')
108
+ .to('Astar')
109
+ .currency({
110
+ symbol: 'ACA',
111
+ amount: '1000000000'
112
+ })
113
+ .address(address)
114
+ .build();
132
115
  */
133
116
  ```
134
117
  ##### Transfer assets from the Relay chain to Parachain
135
118
  ```ts
136
- await Builder(/*node api/ws_url_string - optional*/)
119
+ await Builder(/*node api/ws_url_string/ws_url_array - optional*/)
120
+ .from(RELAY_NODE) //Kusama or Polkadot
137
121
  .to(NODE/*,customParaId - optional*/ | Multilocation object)
138
- .amount(amount)
122
+ .currency({symbol: 'DOT', amount: amount})
139
123
  .address(address | Multilocation object)
140
- /*.xcmVersion(Version.V1/V2/V3/V4) //Optional parameter for manual override of XCM Version used in call*/
124
+ /*.xcmVersion(Version.V1/V2/V3/V4) //Optional parameter for manual override of XCM Version used in call
125
+ .customPallet('Pallet','pallet_function') //Optional parameter for manual override of XCM Pallet and function used in call (If they are named differently on some node but syntax stays the same). Both pallet name and function required. Pallet name must be CamelCase, function name snake_case.*/
141
126
  .build()
142
127
  /*
143
128
  EXAMPLE:
144
- await Builder()
145
- .to('AssetHubPolkadot')
146
- .amount(1000000000000)
147
- .address('141NGS2jjZca5Ss2Nysth2stJ6rimcnufCNHnh5ExSsftn7U')
148
- .build()
129
+ const tx = await Builder()
130
+ .from('Polkadot')
131
+ .to('Astar')
132
+ .currency({
133
+ symbol: 'DOT',
134
+ amount: '1000000000'
135
+ })
136
+ .address(address)
137
+ .build();
149
138
  */
150
139
  ```
151
140
  ##### Transfer assets from Parachain to Relay chain
152
141
  ```ts
153
- await Builder(/*node api/ws_url_string - optional*/)
142
+ await Builder(/*node api/ws_url_string/ws_url_array - optional*/)
154
143
  .from(NODE)
155
- .amount(amount)
144
+ .to(RELAY_NODE) //Kusama or Polkadot
145
+ .currency({symbol: 'DOT', amount: amount})
156
146
  .address(address | Multilocation object)
157
- /*.xcmVersion(Version.V1/V2/V3/V4) //Optional parameter for manual override of XCM Version used in call*/
147
+ /*.xcmVersion(Version.V1/V2/V3/V4) //Optional parameter for manual override of XCM Version used in call
148
+ .customPallet('Pallet','pallet_function') //Optional parameter for manual override of XCM Pallet and function used in call (If they are named differently on some node but syntax stays the same). Both pallet name and function required. Pallet name must be CamelCase, function name snake_case.*/
158
149
  .build()
159
150
  /*
160
151
  EXAMPLE:
161
- await Builder()
162
- .from('AssetHubPolkadot')
163
- .amount(1000000000000)
164
- .address('141NGS2jjZca5Ss2Nysth2stJ6rimcnufCNHnh5ExSsftn7U')
165
- .build()
152
+ const tx = await Builder()
153
+ .from('Astar')
154
+ .to('Polkadot')
155
+ .currency({
156
+ symbol: 'DOT',
157
+ amount: '1000000000'
158
+ })
159
+ .address(address)
160
+ .build();
166
161
  */
167
162
  ```
168
- ##### Use keepAlive option
169
- ```
170
- NOTE: Custom multilocations are not available when keepALive check is used
171
- ```
172
- ```ts
173
- await Builder(/*node api/ws_url_string - optional*/)
174
- .from(NODE)
175
- .amount(amount)
176
- .address(address)
177
- .useKeepAlive(destinationParaAPI)
178
- /*.xcmVersion(Version.V1/V2/V3/V4) //Optional parameter for manual override of XCM Version used in call*/
179
- .build()
180
- ```
181
163
 
182
164
  ##### Batch calls
183
165
  You can batch XCM calls and execute multiple XCM calls within one call. All three scenarios (Para->Para, Para->Relay, Relay->Para) can be used and combined.
184
166
  ```js
185
- await Builder(/*node api/ws_url_string - optional*/)
167
+ await Builder(/*node api/ws_url_string/ws_url_array - optional*/)
186
168
  .from(NODE) //Ensure, that origin node is the same in all batched XCM Calls.
187
169
  .to(NODE_2) //Any compatible Parachain
188
- .currency(currency) //Currency to transfer (If Para->Para), otherwise you do not need to specify .currency()
189
- .amount(amount)
170
+ .currency({currencySelection, amount}) //Currency to transfer - options as in scenarios above
190
171
  .address(address | Multilocation object)
191
172
  .addToBatch()
192
173
 
193
174
  .from(NODE) //Ensure, that origin node is the same in all batched XCM Calls.
194
175
  .to(NODE_3) //Any compatible Parachain
195
- .currency(currency) //Currency to transfer (If Para->Para), otherwise you do not need to specify .currency()
196
- .amount(amount)
176
+ .currency({currencySelection, amount}) //Currency to transfer - options as in scenarios above
197
177
  .address(address | Multilocation object)
198
178
  .addToBatch()
199
179
  .buildBatch({
@@ -202,58 +182,24 @@ await Builder(/*node api/ws_url_string - optional*/)
202
182
  })
203
183
  ```
204
184
 
205
- ### Function pattern:
206
- ```
207
- NOTES:
208
- - Since version v5 there was a breaking change introduced. You now pass single object with properties instead of parameters
209
- - Since v5 you can fully customize all multilocations (address, currency and destination). Instead of string parameter simply pass object with multilocation instead for more information refer to the following PR https://github.com/paraspell/xcm-tools/pull/199.
210
- - Custom multilocations are not available when keepALive check is used
211
- ```
185
+ ### Dry run your XCM Calls:
212
186
  ```ts
213
- // Transfer assets from Parachain to Parachain
214
- await paraspell.xcmPallet.send(
215
- {
216
- api?: ApiPromise/Ws_url_string,
217
- origin: origin Parachain name string,
218
- currency: {id: currencyID} | {symbol: currencySymbol} | {symbol: Native('currencySymbol')} | {symbol: Foreign('currencySymbol')} | {symbol: ForeignAbstract('currencySymbol')} | {multilocation: AssetMultilocationString | AssetMultilocationJson} | {multilocation: Override('Custom Multilocation')} | {multiasset: multilocationJsonArray} ,
219
- feeAsset? - Fee asset select id
220
- amount: any,
221
- to: destination address string | Multilocation object,
222
- destination: destination Parachain ID | Multilocation object /*If you are sending through xTokens, you need to pass the destination and address multilocation in one object (x2)*/,
223
- paraIdTo?: number,
224
- destApiForKeepAlive?: ApiPromise
225
- }
226
- )
227
-
228
- // Transfer assets from Parachain to Relay chain
229
- await paraspell.xcmPallet.send(
230
- {
231
- api?: ApiPromise/Ws_url_string,
232
- origin: origin Parachain name string,
233
- amount: any,
234
- to: destination address string | Multilocation object,
235
- paraIdTo?: number,
236
- destApiForKeepAlive?: ApiPromise
237
- }
238
- )
239
-
240
- // Transfer assets from Relay chain to Parachain
241
- await paraspell.xcmPallet.transferRelayToPara(
242
- {
243
- api?: ApiPromise/Ws_url_string,
244
- destination: destination Parachain ID | Multilocation object,
245
- amount: any,
246
- to: destination address string | Multilocation object,
247
- paraIdTo?: number,
248
- destApiForKeepAlive?: ApiPromise
249
- }
250
- )
187
+ //Builder pattern
188
+ const result = await Builder(API /*optional*/)
189
+ .from(NODE)
190
+ .to(NODE_2)
191
+ .currency({id: currencyID, amount: amount} | {symbol: currencySymbol, amount: amount} | {symbol: Native('currencySymbol'), amount: amount} | {symbol: Foreign('currencySymbol'), amount: amount} | {symbol: ForeignAbstract('currencySymbol'), amount: amount} | {multilocation: AssetMultilocationString, amount: amount | AssetMultilocationJson, amount: amount} | {multilocation: Override('Custom Multilocation'), amount: amount} | {multiasset: {currencySelection, isFeeAsset?: true /* for example symbol: symbol or id: id, or multilocation: multilocation*/, amount: amount}})
192
+ .address(ADDRESS)
193
+ .dryRun()
194
+
195
+ //Function pattern
196
+ getDryRun({api /*optional*/, node, address, tx /* Extrinsic object */})
251
197
  ```
252
198
 
253
199
  ### Asset claim:
254
200
  ```ts
255
201
  //Claim XCM trapped assets from the selected chain
256
- await Builder(api/ws_url_string)
202
+ await Builder(/*node api/ws_url_string/ws_url_array - optional*/)
257
203
  .claimFrom(NODE)
258
204
  .fungible(MultilocationArray (Only one multilocation allowed) [{Multilocation}])
259
205
  .account(address | Multilocation object)
@@ -300,10 +246,7 @@ paraspell.NODE_NAMES
300
246
 
301
247
  ### Parachain XCM Pallet queries
302
248
  ```ts
303
- //PJS
304
- import { getDefaultPallet, getSupportedPallets, SUPPORTED_PALLETS } from '@paraspell/sdk'
305
- //PAPI
306
- import { getDefaultPallet, getSupportedPallets, SUPPORTED_PALLETS } from '@paraspell/sdk/papi'
249
+ import { getDefaultPallet, getSupportedPallets, SUPPORTED_PALLETS } from '@paraspell/sdk';
307
250
 
308
251
  //Retrieve default pallet for specific Parachain
309
252
  getDefaultPallet(node: TNode)
@@ -317,10 +260,7 @@ console.log(SUPPORTED_PALLETS)
317
260
 
318
261
  ### Existential deposit queries
319
262
  ```ts
320
- //PJS
321
263
  import { getExistentialDeposit } from "@paraspell/sdk";
322
- //PAPI
323
- import { getExistentialDeposit } from "@paraspell/sdk/papi";
324
264
 
325
265
  //Currency is an optional parameter. If you wish to query native asset, currency parameter is not necessary.
326
266
  //Currency can be either {symbol: assetSymbol}, {id: assetId}, {multilocation: assetMultilocation}.
@@ -329,10 +269,7 @@ const ed = getExistentialDeposit(node, currency?)
329
269
 
330
270
  ### XCM Transfer info
331
271
  ```ts
332
- //PJS
333
272
  import { getTransferInfo, getBalanceForeign, getBalanceNative, getOriginFeeDetails, getMaxNativeTransferableAmount, getMaxForeignTransferableAmount, getTransferableAmount } from "@paraspell/sdk";
334
- //PAPI
335
- import { getTransferInfo, getBalanceForeign, getBalanceNative, getOriginFeeDetails, getMaxNativeTransferableAmount, getMaxForeignTransferableAmount, getTransferableAmount } from "@paraspell/sdk/papi";
336
273
 
337
274
  //Get balance of foreign currency
338
275
  await getBalanceForeign({address, node, currency /*- {id: currencyID} | {symbol: currencySymbol} | {symbol: Native('currencySymbol')} | {symbol: Foreign('currencySymbol')} | {symbol: ForeignAbstract('currencySymbol')} | {multilocation: AssetMultilocationString | AssetMultilocationJson}*/, api /* api/ws_url_string optional */})
@@ -368,12 +305,6 @@ await getTransferInfo({from, to, address, destinationAddress, currency /*- {id:
368
305
 
369
306
  - Run end-to-end tests using `pnpm test:e2e`
370
307
 
371
- - Update Parachain registered assets in the map using script - `pnpm updateAssets`
372
-
373
- - Update XCM pallets in the map using script - `pnpm updatePallets`
374
-
375
- - Update existential deposits in the map using script - `pnpm updateEds`
376
-
377
308
  - Run all core tests and checks using `pnpm runAll`
378
309
 
379
310
  XCM SDK can be tested in [Playground](https://github.com/paraspell/xcm-tools/tree/main/apps/playground).
@@ -388,11 +319,7 @@ Published under [MIT License](https://github.com/paraspell/xcm-tools/blob/main/p
388
319
 
389
320
  <div align="center">
390
321
  <p align="center">
391
- <a href="https://github.com/w3f/Grants-Program/pull/1245">
392
322
  <img width="200" alt="version" src="https://user-images.githubusercontent.com/55763425/211145923-f7ee2a57-3e63-4b7d-9674-2da9db46b2ee.png" />
393
- </a>
394
- <a href="https://kusama.subsquare.io/referenda/417">
395
323
  <img width="200" alt="version" src="https://github.com/paraspell/xcm-sdk/assets/55763425/9ed74ebe-9b29-4efd-8e3e-7467ac4caed6" />
396
- </a>
397
324
  </p>
398
325
  </div>