@paraspell/sdk-pjs 12.9.7 → 12.10.0-rc.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 +96 -51
- package/dist/index.d.ts +7 -17
- package/dist/index.mjs +150 -33
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -44,7 +44,33 @@ npm install | pnpm add | yarn add @polkadot/api @polkadot/types @polkadot/api-ba
|
|
|
44
44
|
npm install | pnpm add | yarn add @paraspell/sdk-pjs
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
###
|
|
47
|
+
### Install Swap extension
|
|
48
|
+
|
|
49
|
+
If you plan to [do Swap XCMs](https://paraspell.github.io/docs/sdk/xcmPallet.html#swap) you can install Swap package which allows you to do cross-chain swaps on popular Polkadot, Kusama, Paseo, Westend exchanges. Now available in all JS client versions of SDK.
|
|
50
|
+
|
|
51
|
+
> [!IMPORTANT]
|
|
52
|
+
> - ⚠️ **WebAssembly (Wasm) must be enabled in your project** because of the Hydration SDK (One of the exchanges implemented in XCM Router). Wasm can be enabled either through the web application configuration or through the appropriate plugin.
|
|
53
|
+
>
|
|
54
|
+
> - ⚠️ Additionally, Hydration requires the use of the **augment package** (see: https://github.com/galacticcouncil/sdk/issues/114).
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install | pnpm add | yarn add @paraspell/swap @galacticcouncil/api-augment
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Setup Swap extension
|
|
61
|
+
|
|
62
|
+
Add the `@paraspell/swap` import to your application's root component (Usually `App.tsx`). This ensures the extension is registered before using Builder.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// Import swap extension here
|
|
66
|
+
import '@paraspell/swap';
|
|
67
|
+
|
|
68
|
+
export default function App() {
|
|
69
|
+
return {/* Your app here */};
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Importing SDK functionality
|
|
48
74
|
|
|
49
75
|
Named import:
|
|
50
76
|
```ts
|
|
@@ -61,13 +87,14 @@ import * as paraspell from '@paraspell/sdk-pjs'
|
|
|
61
87
|
## Implementation
|
|
62
88
|
|
|
63
89
|
> [!NOTE]
|
|
64
|
-
> -
|
|
65
|
-
> - V11 > V12 Migration guide https://paraspell.github.io/docs/migration/v11-to-v12.html
|
|
66
|
-
>
|
|
67
|
-
> **Latest news:**
|
|
68
|
-
> - You can now pass signer directly into senderAddress parameter
|
|
90
|
+
> - You can now pass signer directly into sender parameter
|
|
69
91
|
> - The local transfers now have additional builder parameter called keepAlive
|
|
70
92
|
> - Transact is here! Find out more: https://paraspell.github.io/docs/sdk/xcmPallet.html#transact
|
|
93
|
+
>
|
|
94
|
+
> **Latest news:**
|
|
95
|
+
> - V12 > V13 Migration guide: https://paraspell.github.io/docs/migration/v12-to-v13.html
|
|
96
|
+
> - Swap package is now available on every XCM SDK version: https://paraspell.github.io/docs/sdk/getting-started.html#install-swap-extension
|
|
97
|
+
> - abstractDecimals is now turned on by default!
|
|
71
98
|
|
|
72
99
|
|
|
73
100
|
### Sending XCM
|
|
@@ -80,15 +107,15 @@ const builder = Builder(/*chain api/builder_config/ws_url_string/ws_url_array -
|
|
|
80
107
|
.from(TSubstrateChain)
|
|
81
108
|
.to(TChain /*,customParaId - optional*/ | Location object /*Only works for PolkadotXCM pallet*/)
|
|
82
109
|
.currency({id: currencyID, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: currencySymbol, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Native('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Foreign('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: ForeignAbstract('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {location: AssetLocationString, amount: amount /*Use "ALL" to transfer everything*/ | AssetLocationJson, amount: amount /*Use "ALL" to transfer everything*/} | {location: Override('Custom Location'), amount: amount /*Use "ALL" to transfer everything*/} | [{currencySelection /*for example symbol: symbol or id: id, or location: location*/, amount: amount /*Use "ALL" to transfer everything*/}, {currencySelection}, ..])
|
|
83
|
-
.
|
|
84
|
-
.
|
|
110
|
+
.recipient(address | Location object /*If you are sending through xTokens, you need to pass the destination and address Location in one object (x2)*/)
|
|
111
|
+
.sender(address | {address, PJS_Signer}) // - OPTIONAL but strongly recommended as it is automatically ignored when not needed - Used when origin is AssetHub with feeAsset or when sending to AssetHub to prevent asset traps by auto-swapping to DOT to have DOT ED.
|
|
85
112
|
/*.ahAddress(ahAddress) - OPTIONAL - used when origin is EVM chain and XCM goes through AssetHub (Multihop transfer where we are unable to convert Key20 to ID32 address eg. origin: Moonbeam & destination: Ethereum (Multihop goes from Moonbeam > AssetHub > BridgeHub > Ethereum)
|
|
86
113
|
.feeAsset({symbol: 'symbol'} || {id: 'id'} || {location: 'location'}) // Optional parameter used when multiasset is provided or when origin is AssetHub - so user can pay in fees different than DOT
|
|
87
114
|
.xcmVersion(Version.V3/V4/V5) //Optional parameter for manual override of XCM Version used in call
|
|
88
115
|
.customPallet('Pallet','pallet_function') //Optional parameter for manual override of XCM Pallet and function used in call (If they are named differently on some chain but syntax stays the same). Both pallet name and function required. Pallet name must be CamelCase, function name snake_case.*/
|
|
89
116
|
|
|
90
117
|
const tx = await builder.build()
|
|
91
|
-
// Or if you use signers in
|
|
118
|
+
// Or if you use signers in sender:
|
|
92
119
|
// await builder.signAndSubmit() - Signs and submits the transaction; returns TX hash for tracking
|
|
93
120
|
|
|
94
121
|
//Make sure to disconnect the API after it is no longer used (eg, after a transaction)
|
|
@@ -101,9 +128,9 @@ const builder = Builder()
|
|
|
101
128
|
.to('Polkadot')
|
|
102
129
|
.currency({
|
|
103
130
|
symbol: 'DOT',
|
|
104
|
-
amount: '
|
|
131
|
+
amount: '1'
|
|
105
132
|
})
|
|
106
|
-
.
|
|
133
|
+
.recipient(address)
|
|
107
134
|
|
|
108
135
|
const tx = await builder.build()
|
|
109
136
|
|
|
@@ -119,7 +146,7 @@ const builder = Builder(/*chain api/builder_config/ws_url_string/ws_url_array -
|
|
|
119
146
|
.from(TSubstrateChain)
|
|
120
147
|
.to(TChain) //Has to be the same as the origin (from)
|
|
121
148
|
.currency({id: currencyID, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: currencySymbol, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Native('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Foreign('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: ForeignAbstract('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {location: AssetLocationString, amount: amount /*Use "ALL" to transfer everything*/ | AssetLocationJson, amount: amount /*Use "ALL" to transfer everything*/} | {location: Override('Custom Location'), amount: amount /*Use "ALL" to transfer everything*/} | [{currencySelection /*for example symbol: symbol or id: id, or location: location*/, amount: amount /*Use "ALL" to transfer everything*/}, {currencySelection}, ..])
|
|
122
|
-
.
|
|
149
|
+
.recipient(address)
|
|
123
150
|
/* .keepAlive(bool) - Optional: Allows draining the account below the existential deposit. */
|
|
124
151
|
|
|
125
152
|
|
|
@@ -135,9 +162,9 @@ const builder = Builder()
|
|
|
135
162
|
.to('Hydration')
|
|
136
163
|
.currency({
|
|
137
164
|
symbol: 'DOT',
|
|
138
|
-
amount: '
|
|
165
|
+
amount: '1'
|
|
139
166
|
})
|
|
140
|
-
.
|
|
167
|
+
.recipient(address)
|
|
141
168
|
|
|
142
169
|
const tx = await builder.build()
|
|
143
170
|
|
|
@@ -153,18 +180,45 @@ const builder = Builder(/*client | builder_config | ws_url | [ws_url, ws_url,..]
|
|
|
153
180
|
.from(TSubstrateChain) // 'AssetHubPolkadot' | 'Hydration' | 'Moonbeam' | 'Polkadot' | ... https://paraspell.github.io/docs/sdk/AssetPallet.html#import-chains-as-types
|
|
154
181
|
.to(TChain) // Has to be same as origin (from)
|
|
155
182
|
.currency(CURRENCY_SPEC) // Refer to currency spec options below
|
|
156
|
-
.
|
|
157
|
-
.
|
|
183
|
+
.sender(sender | PAPI SIGNER)
|
|
184
|
+
.recipient(address)
|
|
158
185
|
.transact(hex, /* originType, TWeight - Optional */)
|
|
159
186
|
|
|
160
187
|
const tx = await builder.build()
|
|
161
|
-
// Or if you use signers in
|
|
188
|
+
// Or if you use signers in sender:
|
|
162
189
|
// await builder.signAndSubmit() - Signs and submits the transaction; returns TX hash for tracking
|
|
163
190
|
|
|
164
191
|
//Disconnect API after TX
|
|
165
192
|
await builder.disconnect()
|
|
166
193
|
```
|
|
167
194
|
|
|
195
|
+
#### Swap
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
const builder = Builder(/*client | builder_config |ws_url | [ws_url, ws_url,..] - Optional*/)
|
|
199
|
+
.from(TSubstrateChain) // 'AssetHubPolkadot' | 'Hydration' | 'Moonbeam' | 'Polkadot' | ... https://paraspell.github.io/docs/sdk/AssetPallet.html#import-chains-as-types
|
|
200
|
+
.to(TChain /*,customParaId - optional*/ | Location object /*Only works for PolkadotXCM pallet*/) //'AssetHubPolkadot' | 'Hydration' | 'Moonbeam' | 'Polkadot' | ... https://paraspell.github.io/docs/sdk/AssetPallet.html#import-chains-as-types
|
|
201
|
+
.currency({id: currencyID, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: currencySymbol, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Native('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Foreign('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: ForeignAbstract('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {location: AssetLocationString, amount: amount /*Use "ALL" to transfer everything*/ | AssetLocationJson, amount: amount /*Use "ALL" to transfer everything*/} | {location: Override('Custom Location'), amount: amount /*Use "ALL" to transfer everything*/})
|
|
202
|
+
.recipient(address | Location object /*If you are sending through xTokens, you need to pass the destination and address location in one object (x2)*/)
|
|
203
|
+
.sender(address | PAPI_SIGNER /*Only in PAPI SDK*/ | {address, PJS_SIGNER} /*Only in PJS SDK*/) // - OPTIONAL but strongly recommended as it is automatically ignored when not needed - Used when origin is AssetHub/Hydration with feeAsset or when sending to AssetHub to prevent asset traps by auto-swapping to DOT to have DOT ED.
|
|
204
|
+
.swap({
|
|
205
|
+
currencyTo: {id: currencyID, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: currencySymbol, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Native('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Foreign('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: ForeignAbstract('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {location: AssetLocationString, amount: amount /*Use "ALL" to transfer everything*/ | AssetLocationJson, amount: amount /*Use "ALL" to transfer everything*/} | {location: Override('Custom Location'), amount: amount /*Use "ALL" to transfer everything*/}
|
|
206
|
+
// exchange: ['AssetHubPolkadotDex'], - Optional parameter - 'HydrationDex' | 'AcalaDex' | 'AssetHubPolkadotDex' | ...
|
|
207
|
+
// slippage: 1, - Optional - 1 by default
|
|
208
|
+
// evmsender: '0x000', - Optional parameter when origin CHAIN is EVM based (Required with evmSigner)
|
|
209
|
+
// evmSigner: Signer, - Optional parameter when origin CHAIN is EVM based (Required with evmInjectorAddress)
|
|
210
|
+
// onStatusChange: (event) => void - Optional parameter for callback events when sender address is supplied as signer
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
const tx = await builder.buildAll()
|
|
214
|
+
// Or if you use signers in sender:
|
|
215
|
+
// await builder.signAndSubmit() - Signs and submits the transaction (only working in 1click scenarios); returns TX hash for tracking
|
|
216
|
+
// await builder.signAndSubmitAll() - Signs and submits transactions (required in 2click scenarios); returns array of TX hashes for tracking
|
|
217
|
+
|
|
218
|
+
// Make sure to disconnect API after it is no longer used (eg. after transaction)
|
|
219
|
+
await builder.disconnect()
|
|
220
|
+
```
|
|
221
|
+
|
|
168
222
|
#### Dry run your XCM Calls:
|
|
169
223
|
```ts
|
|
170
224
|
//Builder pattern
|
|
@@ -173,8 +227,8 @@ const result = await Builder(/*chain api/builder_config/ws_url_string/ws_url_arr
|
|
|
173
227
|
.to(TChain)
|
|
174
228
|
.currency({id: currencyID, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: currencySymbol, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Native('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Foreign('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: ForeignAbstract('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {location: AssetLocationString, amount: amount /*Use "ALL" to transfer everything*/ | AssetLocationJson, amount: amount /*Use "ALL" to transfer everything*/} | {location: Override('Custom Location'), amount: amount /*Use "ALL" to transfer everything*/} | {[{currencySelection, isFeeAsset?: true /* for example symbol: symbol or id: id, or Location: Location*/, amount: amount /*Use "ALL" to transfer everything*/}]})
|
|
175
229
|
/*.feeAsset(CURRENCY) - Optional parameter when origin === AssetHubPolkadot and TX is supposed to be paid in same fee asset as selected currency.*/
|
|
176
|
-
.
|
|
177
|
-
.
|
|
230
|
+
.recipient(ADDRESS)
|
|
231
|
+
.sender(address | {address, PJS_Signer})
|
|
178
232
|
.dryRun()
|
|
179
233
|
|
|
180
234
|
//Check Parachain for DryRun support - returns true/false
|
|
@@ -191,8 +245,8 @@ const result = await Builder(/*chain api/builder_config/ws_url_string/ws_url_arr
|
|
|
191
245
|
.to(TChain)
|
|
192
246
|
.currency({id: currencyID, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: currencySymbol, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Native('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Foreign('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: ForeignAbstract('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {location: AssetLocationString, amount: amount /*Use "ALL" to transfer everything*/ | AssetLocationJson, amount: amount /*Use "ALL" to transfer everything*/} | {location: Override('Custom Location'), amount: amount /*Use "ALL" to transfer everything*/} | {[{currencySelection, isFeeAsset?: true /* for example symbol: symbol or id: id, or Location: Location*/, amount: amount /*Use "ALL" to transfer everything*/}]})
|
|
193
247
|
/*.feeAsset(CURRENCY) - Optional parameter when origin === AssetHubPolkadot and TX is supposed to be paid in same fee asset as selected currency.*/
|
|
194
|
-
.
|
|
195
|
-
.
|
|
248
|
+
.recipient(ADDRESS)
|
|
249
|
+
.sender(address | {address, PJS_Signer})
|
|
196
250
|
.dryRunPreview(/*{ mintFeeAssets: true } - false by default - Mints fee assets also, if user does not have enough to cover fees on origin.*/)
|
|
197
251
|
```
|
|
198
252
|
|
|
@@ -203,13 +257,13 @@ const builder = Builder(/*chain api/builder_config/ws_url_string/ws_url_array -
|
|
|
203
257
|
.from(TSubstrateChain) //Ensure, that origin chain is the same in all batched XCM Calls.
|
|
204
258
|
.to(TChain2) //Any compatible Parachain
|
|
205
259
|
.currency({currencySelection, amount}) //Currency to transfer - options as in scenarios above
|
|
206
|
-
.
|
|
260
|
+
.recipient(address | Location object)
|
|
207
261
|
.addToBatch()
|
|
208
262
|
|
|
209
263
|
.from(TSubstrateChain) //Ensure, that origin chain is the same in all batched XCM Calls.
|
|
210
264
|
.to(TChain3) //Any compatible Parachain
|
|
211
265
|
.currency({currencySelection, amount}) //Currency to transfer - options as in scenarios above
|
|
212
|
-
.
|
|
266
|
+
.recipient(address | Location object)
|
|
213
267
|
.addToBatch()
|
|
214
268
|
|
|
215
269
|
const tx = await builder.buildBatch({
|
|
@@ -229,7 +283,7 @@ const builder = Builder(/*chain api/builder_config/ws_url_string/ws_url_array -
|
|
|
229
283
|
.claimfrom(TSubstrateChain)
|
|
230
284
|
.currency({id: currencyID, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: currencySymbol, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Native('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Foreign('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: ForeignAbstract('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {location: AssetLocationString, amount: amount /*Use "ALL" to transfer everything*/ | AssetLocationJson, amount: amount /*Use "ALL" to transfer everything*/} | [{currencySelection /*for example symbol: symbol or id: id, or location: location*/, amount: amount /*Use "ALL" to transfer everything*/}, {currencySelection}, ..]
|
|
231
285
|
)
|
|
232
|
-
.
|
|
286
|
+
.recipient(address | Location object)
|
|
233
287
|
/*.xcmVersion(Version.V3) Optional parameter, by default chain specific version. XCM Version ENUM if a different XCM version is needed (Supported V3 & V4 & V5). Requires importing Version enum.*/
|
|
234
288
|
|
|
235
289
|
const tx = await builder.build()
|
|
@@ -253,11 +307,11 @@ const builder = await Builder({
|
|
|
253
307
|
.from(TSubstrateChain)
|
|
254
308
|
.to(TChain)
|
|
255
309
|
.currency({id: currencyID, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: currencySymbol, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Native('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Foreign('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: ForeignAbstract('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {location: AssetLocationString, amount: amount /*Use "ALL" to transfer everything*/ | AssetLocationJson, amount: amount /*Use "ALL" to transfer everything*/} | {location: Override('Custom Location'), amount: amount /*Use "ALL" to transfer everything*/} | [{currencySelection, isFeeAsset?: true /* for example symbol: symbol or id: id, or Location: Location*/, amount: amount /*Use "ALL" to transfer everything*/}])
|
|
256
|
-
.
|
|
257
|
-
.
|
|
310
|
+
.recipient(address) //You can also use prederived accounts - //Alice, //Bob... //Alith, //Balthathar...
|
|
311
|
+
.sender(address | {address, PJS_Signer}) //You can also use prederived accounts //Alice, //Bob... //Alith, //Balthathar...
|
|
258
312
|
|
|
259
313
|
const tx = await builder.build()
|
|
260
|
-
//Or if you use prederived account as
|
|
314
|
+
//Or if you use prederived account as sender:
|
|
261
315
|
//await builder.signAndSubmit()
|
|
262
316
|
|
|
263
317
|
//Disconnect API after TX
|
|
@@ -276,8 +330,8 @@ const fee = await Builder(/*chain api/builder_config/ws_url_string/ws_url_array
|
|
|
276
330
|
.to(TChain)
|
|
277
331
|
.currency(CURRENCY_SPEC)
|
|
278
332
|
/*.feeAsset(CURRENCY) - Optional parameter when origin === AssetHubPolkadot and TX is supposed to be paid in the same fee asset as selected currency.*/
|
|
279
|
-
.
|
|
280
|
-
.
|
|
333
|
+
.recipient(RECIPIENT_ADDRESS)
|
|
334
|
+
.sender(address | {address, PJS_Signer})
|
|
281
335
|
.getXcmFee(/*{disableFallback: true / false}*/) //Fallback is optional. When fallback is disabled, you only get notified of a DryRun error, but no Payment info query fallback is performed. Payment info is still performed if Origin or Destination chain do not support DryRun out of the box.
|
|
282
336
|
```
|
|
283
337
|
|
|
@@ -289,8 +343,8 @@ const fee = await Builder(/*chain api/builder_config/ws_url_string/ws_url_array
|
|
|
289
343
|
.to(TChain)
|
|
290
344
|
.currency(CURRENCY_SPEC)
|
|
291
345
|
/*.feeAsset(CURRENCY) - Optional parameter when origin === AssetHubPolkadot and TX is supposed to be paid in the same fee asset as selected currency.*/
|
|
292
|
-
.
|
|
293
|
-
.
|
|
346
|
+
.recipient(RECIPIENT_ADDRESS)
|
|
347
|
+
.sender(address | {address, PJS_Signer})
|
|
294
348
|
.getOriginXcmFee(/*{disableFallback: true / false}*/) //Fallback is optional. When fallback is disabled, you only get notified of a DryRun error, but no Payment info query fallback is performed. Payment info is still performed if Origin do not support DryRun out of the box.
|
|
295
349
|
```
|
|
296
350
|
|
|
@@ -301,8 +355,8 @@ const info = await Builder(/*chain api/builder_config/ws_url_string/ws_url_array
|
|
|
301
355
|
.to(TChain)
|
|
302
356
|
.currency(CURRENCY_SPEC)
|
|
303
357
|
/*.feeAsset(CURRENCY) - Optional parameter when origin === AssetHubPolkadot and TX is supposed to be paid in the same fee asset as selected currency.*/
|
|
304
|
-
.
|
|
305
|
-
.
|
|
358
|
+
.recipient(RECIPIENT_ADDRESS)
|
|
359
|
+
.sender(address | {address, PJS_Signer})
|
|
306
360
|
.getTransferInfo()
|
|
307
361
|
```
|
|
308
362
|
|
|
@@ -313,8 +367,8 @@ const transferable = await Builder(/*chain api/builder_config/ws_url_string/ws_u
|
|
|
313
367
|
.to(TChain)
|
|
314
368
|
.currency(CURRENCY_SPEC)
|
|
315
369
|
/*.feeAsset(CURRENCY) - Optional parameter when origin === AssetHubPolkadot and TX is supposed to be paid in the same fee asset as selected currency.*/
|
|
316
|
-
.
|
|
317
|
-
.
|
|
370
|
+
.recipient(RECIPIENT_ADDRESS)
|
|
371
|
+
.sender(address | {address, PJS_Signer})
|
|
318
372
|
.getTransferableAmount()
|
|
319
373
|
```
|
|
320
374
|
|
|
@@ -325,8 +379,8 @@ const transferable = await Builder(/*chain api/builder_config/ws_url_string/ws_u
|
|
|
325
379
|
.to(TChain)
|
|
326
380
|
.currency(CURRENCY_SPEC)
|
|
327
381
|
/*.feeAsset(CURRENCY) - Optional parameter when origin === AssetHubPolkadot and TX is supposed to be paid in the same fee asset as selected currency.*/
|
|
328
|
-
.
|
|
329
|
-
.
|
|
382
|
+
.recipient(RECIPIENT_ADDRESS)
|
|
383
|
+
.sender(address | {address, PJS_Signer})
|
|
330
384
|
.getMinTransferableAmount()
|
|
331
385
|
```
|
|
332
386
|
|
|
@@ -337,8 +391,8 @@ const receivable = await Builder(/*chain api/builder_config/ws_url_string/ws_url
|
|
|
337
391
|
.to(TChain)
|
|
338
392
|
.currency(CURRENCY_SPEC)
|
|
339
393
|
/*.feeAsset(CURRENCY) - Optional parameter when origin === AssetHubPolkadot and TX is supposed to be paid in the same fee asset as selected currency.*/
|
|
340
|
-
.
|
|
341
|
-
.
|
|
394
|
+
.recipient(RECIPIENT_ADDRESS)
|
|
395
|
+
.sender(address | {address, PJS_Signer})
|
|
342
396
|
.getReceivableAmount()
|
|
343
397
|
```
|
|
344
398
|
|
|
@@ -349,8 +403,8 @@ const ed = await Builder(/*chain api/builder_config/ws_url_string/ws_url_array -
|
|
|
349
403
|
.to(TChain)
|
|
350
404
|
.currency(CURRENCY_SPEC)
|
|
351
405
|
/*.feeAsset(CURRENCY) - Optional parameter when origin === AssetHubPolkadot and TX is supposed to be paid in the same fee asset as selected currency.*/
|
|
352
|
-
.
|
|
353
|
-
.
|
|
406
|
+
.recipient(RECIPIENT_ADDRESS)
|
|
407
|
+
.sender(address | {address, PJS_Signer})
|
|
354
408
|
.verifyEdOnDestination()
|
|
355
409
|
```
|
|
356
410
|
|
|
@@ -390,7 +444,7 @@ let result = convertSs58(ADDRESS, TChain) // returns converted address in string
|
|
|
390
444
|
For full documentation with output examples of asset queries, head over to [official documentation](https://paraspell.github.io/docs/sdk/AssetPallet.html).
|
|
391
445
|
|
|
392
446
|
```ts
|
|
393
|
-
import { getSupportedDestinations, getFeeAssets, getAssetsObject,
|
|
447
|
+
import { getSupportedDestinations, getFeeAssets, getAssetsObject, getRelayChainSymbol, getNativeAssets, getNativeAssets, getOtherAssets, getAllAssetsSymbols, getParaId, getTChain, getAssetLocation, CHAINS, findAssetInfo, findAssetInfoOrThrow } from '@paraspell/sdk-pjs'
|
|
394
448
|
|
|
395
449
|
//Get chains that support the specific asset related to origin
|
|
396
450
|
getSupportedDestinations(TChain, CURRENCY)
|
|
@@ -413,9 +467,6 @@ getAssetLocation(TChain, { symbol: symbol } | { id: assetId })
|
|
|
413
467
|
// Retrieve assets object from assets.json for a particular chain, including information about native and foreign assets
|
|
414
468
|
getAssetsObject(TChain)
|
|
415
469
|
|
|
416
|
-
// Retrieve foreign assetId for a particular chain and asset symbol
|
|
417
|
-
getAssetId(TChain, ASSET_SYMBOL)
|
|
418
|
-
|
|
419
470
|
// Retrieve the symbol of the relay chain for a particular chain. Either "DOT" or "KSM"
|
|
420
471
|
getRelayChainSymbol(TChain)
|
|
421
472
|
|
|
@@ -428,12 +479,6 @@ getOtherAssets(TChain)
|
|
|
428
479
|
// Retrieve string array of all asset symbols. (native and foreign assets are merged into a single array)
|
|
429
480
|
getAllAssetsSymbols(TChain)
|
|
430
481
|
|
|
431
|
-
// Check if a chain supports a particular asset. (Both native and foreign assets are searched). Returns boolean
|
|
432
|
-
hasSupportForAsset(TChain, ASSET_SYMBOL)
|
|
433
|
-
|
|
434
|
-
// Get decimals for specific asset
|
|
435
|
-
getAssetDecimals(TChain, ASSET_SYMBOL)
|
|
436
|
-
|
|
437
482
|
// Get specific chain id
|
|
438
483
|
getParaId(TChain)
|
|
439
484
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _paraspell_sdk_core from '@paraspell/sdk-core';
|
|
2
|
-
import { TApiOrUrl, WithApi, TEvmChainFrom, TChain, TCurrencyInputWithAmount, Foreign, ForeignAbstract, Native, Override, findAssetInfo, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getAssetsObject, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTChain, hasSupportForAsset, isChainEvm, TSubstrateChain, TBuilderOptions, GeneralBuilder as GeneralBuilder$1,
|
|
2
|
+
import { TApiOrUrl, WithApi, TEvmChainFrom, TChain, TCurrencyInputWithAmount, Foreign, ForeignAbstract, Native, Override, findAssetInfo, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getAssetsObject, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTChain, hasSupportForAsset, isChainEvm, TSubstrateChain, TBuilderOptions, GeneralBuilder as GeneralBuilder$1, TTransferBaseOptions } from '@paraspell/sdk-core';
|
|
3
3
|
export * from '@paraspell/sdk-core';
|
|
4
4
|
import * as _polkadot_api from '@polkadot/api';
|
|
5
5
|
import { ApiPromise } from '@polkadot/api';
|
|
@@ -32,7 +32,7 @@ type TEvmBuilderOptionsBase = {
|
|
|
32
32
|
/**
|
|
33
33
|
* The Polkadot destination address.
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
recipient: string;
|
|
36
36
|
/**
|
|
37
37
|
* The AssetHub address
|
|
38
38
|
*/
|
|
@@ -56,20 +56,11 @@ declare const getBalance: (options: _paraspell_sdk_core.TGetBalanceCommonOptions
|
|
|
56
56
|
} & {
|
|
57
57
|
api?: TPjsApiOrUrl;
|
|
58
58
|
}) => Promise<bigint>;
|
|
59
|
-
/**
|
|
60
|
-
* Claims assets from a parachain.
|
|
61
|
-
*
|
|
62
|
-
* @returns An extrinsic representing the claim transaction.
|
|
63
|
-
*/
|
|
64
|
-
declare const claimAssets: (options: _paraspell_sdk_core.TAssetClaimOptionsBase & {
|
|
65
|
-
api?: TPjsApiOrUrl;
|
|
66
|
-
}) => Promise<Extrinsic>;
|
|
67
59
|
|
|
68
60
|
declare const assets_Foreign: typeof Foreign;
|
|
69
61
|
declare const assets_ForeignAbstract: typeof ForeignAbstract;
|
|
70
62
|
declare const assets_Native: typeof Native;
|
|
71
63
|
declare const assets_Override: typeof Override;
|
|
72
|
-
declare const assets_claimAssets: typeof claimAssets;
|
|
73
64
|
declare const assets_findAssetInfo: typeof findAssetInfo;
|
|
74
65
|
declare const assets_getAllAssetsSymbols: typeof getAllAssetsSymbols;
|
|
75
66
|
declare const assets_getAssetDecimals: typeof getAssetDecimals;
|
|
@@ -92,7 +83,6 @@ declare namespace assets {
|
|
|
92
83
|
assets_ForeignAbstract as ForeignAbstract,
|
|
93
84
|
assets_Native as Native,
|
|
94
85
|
assets_Override as Override,
|
|
95
|
-
assets_claimAssets as claimAssets,
|
|
96
86
|
assets_findAssetInfo as findAssetInfo,
|
|
97
87
|
assets_getAllAssetsSymbols as getAllAssetsSymbols,
|
|
98
88
|
assets_getAssetDecimals as getAssetDecimals,
|
|
@@ -147,8 +137,8 @@ declare class EvmBuilderCore<TApi, TRes, TSigner, T extends Partial<TPjsEvmBuild
|
|
|
147
137
|
* @param address - The Polkadot address to receive the transfer.
|
|
148
138
|
* @returns An instance of EvmBuilder
|
|
149
139
|
*/
|
|
150
|
-
|
|
151
|
-
|
|
140
|
+
recipient(address: string): EvmBuilderCore<TApi, TRes, TSigner, T & {
|
|
141
|
+
recipient: string;
|
|
152
142
|
}>;
|
|
153
143
|
/**
|
|
154
144
|
* Sets the asset hub address. This is used for transfers that go through the Asset Hub.
|
|
@@ -183,7 +173,7 @@ declare class EvmBuilderCore<TApi, TRes, TSigner, T extends Partial<TPjsEvmBuild
|
|
|
183
173
|
* @returns A new Builder instance.
|
|
184
174
|
*/
|
|
185
175
|
declare const Builder: (api?: TBuilderOptions<TPjsApiOrUrl>) => GeneralBuilder$1<_polkadot_api.ApiPromise, Extrinsic, TPjsSigner, object>;
|
|
186
|
-
type GeneralBuilder<T extends Partial<
|
|
176
|
+
type GeneralBuilder<T extends Partial<TTransferBaseOptions<TPjsApi, Extrinsic, TPjsSigner>> = object> = GeneralBuilder$1<TPjsApi, Extrinsic, TPjsSigner, T>;
|
|
187
177
|
declare const EvmBuilder: (provider?: AbstractProvider, api?: TBuilderOptions<TPjsApiOrUrl>) => EvmBuilderCore<unknown, unknown, unknown, {
|
|
188
178
|
api: _paraspell_sdk_core.IPolkadotApi<_polkadot_api.ApiPromise, Extrinsic, TPjsSigner>;
|
|
189
179
|
provider: AbstractProvider | undefined;
|
|
@@ -209,7 +199,7 @@ declare const depositToken: (signer: Signer$1, amount: bigint, symbol: string) =
|
|
|
209
199
|
*
|
|
210
200
|
* @throws Will throw an error if the transfer validation fails or if the transfer cannot be completed.
|
|
211
201
|
*/
|
|
212
|
-
declare const transferEthToPolkadot$1: <TApi, TRes, TSigner>({ api, provider, signer,
|
|
202
|
+
declare const transferEthToPolkadot$1: <TApi, TRes, TSigner>({ api, provider, signer, recipient, to, currency }: TPjsEvmBuilderOptions<TApi, TRes, TSigner>) => Promise<{
|
|
213
203
|
response: ethers.TransactionResponse;
|
|
214
204
|
messageReceipt: toPolkadotV2.MessageReceipt;
|
|
215
205
|
}>;
|
|
@@ -252,5 +242,5 @@ declare namespace transfer {
|
|
|
252
242
|
|
|
253
243
|
declare const createChainClient: (chain: TSubstrateChain, builderOptions?: TBuilderOptions<TPjsApiOrUrl>) => Promise<_polkadot_api.ApiPromise>;
|
|
254
244
|
|
|
255
|
-
export { Builder, EvmBuilder, approveToken, assets,
|
|
245
|
+
export { Builder, EvmBuilder, approveToken, assets, convertSs58, createChainClient, depositToken, dryRun, dryRunOrigin, getBalance, getBridgeStatus, getParaEthTransferFees, getTokenBalance, transferEthToPolkadot, transfer as xcmPallet };
|
|
256
246
|
export type { Extrinsic, GeneralBuilder, TPjsApi, TPjsApiOrUrl, TPjsEvmBuilderOptions, TPjsSigner };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getNativeAssetSymbol, getOtherAssets, hasJunction, getJunctionValue, getEvmPrivateKeyHex, createClientCache, MAX_CLIENTS, EXTENSION_MS, createClientPoolHelpers, BatchMode, isConfig, findNativeAssetInfoOrThrow, getChainProviders, isSenderSigner, DEFAULT_TTL_MS, resolveChainApi, isExternalChain,
|
|
1
|
+
import { getNativeAssetSymbol, getOtherAssets, hasJunction, getJunctionValue, getEvmPrivateKeyHex, UnsupportedOperationError, createClientCache, MAX_CLIENTS, EXTENSION_MS, createClientPoolHelpers, BatchMode, isConfig, findNativeAssetInfoOrThrow, getChainProviders, isSenderSigner, DEFAULT_TTL_MS, resolveChainApi, isExternalChain, findAssetInfoOrThrow, hasXcmPaymentApiSupport, resolveModuleError, getAssetsObject, RuntimeApiUnavailableError, wrapTxBypass, localizeLocation, addXcmVersionHeader, isAssetXcEqual, RELAY_LOCATION, getRelayChainOf, SubmitTransactionError, createChainClient as createChainClient$1, getBalance as getBalance$1, Foreign, ForeignAbstract, Native, Override, findAssetInfo, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssets, getRelayChainSymbol, getSupportedAssets, getTChain, hasSupportForAsset, isChainEvm, convertSs58 as convertSs58$1, assertHasId, getParaId, RoutingResolutionError, abstractDecimals, MissingParameterError, isOverrideLocationSpecifier, transferMoonbeamEvm, transferMoonbeamToEth, validateAddress as validateAddress$1, Builder as Builder$1, getBridgeStatus as getBridgeStatus$1, getParaEthTransferFees as getParaEthTransferFees$1, DRY_RUN_CLIENT_TIMEOUT_MS, dryRun as dryRun$1, dryRunOrigin as dryRunOrigin$1 } from '@paraspell/sdk-core';
|
|
2
2
|
export * from '@paraspell/sdk-core';
|
|
3
3
|
import { Keyring, WsProvider, ApiPromise } from '@polkadot/api';
|
|
4
|
-
import { isHex, u8aToHex, hexToU8a, stringToU8a } from '@polkadot/util';
|
|
4
|
+
import { u8aConcat, compactToU8a, u8aEq, isHex, u8aToHex, hexToU8a, stringToU8a } from '@polkadot/util';
|
|
5
5
|
import { decodeAddress, blake2AsHex, validateAddress } from '@polkadot/util-crypto';
|
|
6
6
|
import { WETH9__factory } from '@snowbridge/contract-types';
|
|
7
7
|
import { bridgeInfoFor } from '@snowbridge/registry';
|
|
@@ -359,6 +359,54 @@ var snakeToCamel = function snakeToCamel(str) {
|
|
|
359
359
|
});
|
|
360
360
|
};
|
|
361
361
|
|
|
362
|
+
var txFromHex = function txFromHex(api, hex) {
|
|
363
|
+
var _api$tx$section;
|
|
364
|
+
// Try as full extrinsic
|
|
365
|
+
try {
|
|
366
|
+
var tx = api.tx(hex);
|
|
367
|
+
if (tx.toHex() === hex) return tx;
|
|
368
|
+
} catch (_unused) {
|
|
369
|
+
// Not a valid extrinsic, try other formats
|
|
370
|
+
}
|
|
371
|
+
// Try as Call
|
|
372
|
+
try {
|
|
373
|
+
var _call = api.createType('Call', hex);
|
|
374
|
+
var callHex = _call.toHex();
|
|
375
|
+
if (callHex === hex) {
|
|
376
|
+
var _api$tx$_section;
|
|
377
|
+
var _api$registry$findMet = api.registry.findMetaCall(_call.callIndex),
|
|
378
|
+
_method = _api$registry$findMet.method,
|
|
379
|
+
_section = _api$registry$findMet.section;
|
|
380
|
+
return (_api$tx$_section = api.tx[_section])[_method].apply(_api$tx$_section, _toConsumableArray(_call.args));
|
|
381
|
+
}
|
|
382
|
+
if (hex.startsWith(callHex)) {
|
|
383
|
+
// Try as un-prefixed ExtrinsicPayload
|
|
384
|
+
var prefixed = u8aConcat(compactToU8a(_call.encodedLength), hex);
|
|
385
|
+
var _payload = api.createType('ExtrinsicPayload', prefixed);
|
|
386
|
+
if (u8aEq(_payload.toU8a(), prefixed)) {
|
|
387
|
+
var _api$tx$_section2;
|
|
388
|
+
var payloadCall = api.createType('Call', _payload.method.toHex());
|
|
389
|
+
var _api$registry$findMet2 = api.registry.findMetaCall(payloadCall.callIndex),
|
|
390
|
+
_method2 = _api$registry$findMet2.method,
|
|
391
|
+
_section2 = _api$registry$findMet2.section;
|
|
392
|
+
return (_api$tx$_section2 = api.tx[_section2])[_method2].apply(_api$tx$_section2, _toConsumableArray(payloadCall.args));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
} catch (_unused2) {
|
|
396
|
+
// Not a valid call, try as payload
|
|
397
|
+
}
|
|
398
|
+
// Final attempt: try as prefixed ExtrinsicPayload
|
|
399
|
+
var payload = api.createType('ExtrinsicPayload', hex);
|
|
400
|
+
if (payload.toHex() !== hex) {
|
|
401
|
+
throw new UnsupportedOperationError('Unable to decode hex as Extrinsic, Call, or ExtrinsicPayload');
|
|
402
|
+
}
|
|
403
|
+
var call = api.createType('Call', payload.method.toHex());
|
|
404
|
+
var _api$registry$findMet3 = api.registry.findMetaCall(call.callIndex),
|
|
405
|
+
method = _api$registry$findMet3.method,
|
|
406
|
+
section = _api$registry$findMet3.section;
|
|
407
|
+
return (_api$tx$section = api.tx[section])[method].apply(_api$tx$section, _toConsumableArray(call.args));
|
|
408
|
+
};
|
|
409
|
+
|
|
362
410
|
var clientPool = createClientCache(MAX_CLIENTS, /*#__PURE__*/function () {
|
|
363
411
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(client) {
|
|
364
412
|
return _regenerator().w(function (_context) {
|
|
@@ -497,8 +545,8 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
497
545
|
}
|
|
498
546
|
}, {
|
|
499
547
|
key: "txFromHex",
|
|
500
|
-
value: function txFromHex(hex) {
|
|
501
|
-
return Promise.resolve(this.api
|
|
548
|
+
value: function txFromHex$1(hex) {
|
|
549
|
+
return Promise.resolve(txFromHex(this.api, hex));
|
|
502
550
|
}
|
|
503
551
|
}, {
|
|
504
552
|
key: "queryState",
|
|
@@ -691,13 +739,13 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
691
739
|
return _regenerator().w(function (_context8) {
|
|
692
740
|
while (1) switch (_context8.n) {
|
|
693
741
|
case 0:
|
|
694
|
-
api = new PolkadotJsApi();
|
|
742
|
+
api = new PolkadotJsApi(isConfig(this._config) ? this._config : undefined);
|
|
695
743
|
_context8.n = 1;
|
|
696
744
|
return api.init(chain);
|
|
697
745
|
case 1:
|
|
698
746
|
return _context8.a(2, api);
|
|
699
747
|
}
|
|
700
|
-
}, _callee8);
|
|
748
|
+
}, _callee8, this);
|
|
701
749
|
}));
|
|
702
750
|
function createApiForChain(_x11) {
|
|
703
751
|
return _createApiForChain.apply(this, arguments);
|
|
@@ -747,7 +795,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
747
795
|
isCustomAsset: true,
|
|
748
796
|
asset: findAssetInfoOrThrow(chain, {
|
|
749
797
|
id: assetId
|
|
750
|
-
}
|
|
798
|
+
})
|
|
751
799
|
});
|
|
752
800
|
}
|
|
753
801
|
}, _callee9, this);
|
|
@@ -762,7 +810,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
762
810
|
value: function () {
|
|
763
811
|
var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(options) {
|
|
764
812
|
var _this2 = this;
|
|
765
|
-
var tx, address, feeAsset, chain, destination, version, _options$useRootOrigi, useRootOrigin, bypassOptions, supportsDryRunApi, basePayload, resolvedTx, resolvedFeeAsset, performDryRunCall, getExecutionSuccessFromResult, extractFailureReasonFromResult, response, resultHuman, resultJson, isSuccess, failureErr, shouldRetryWithVersion, msg, _msg, forwardedXcms, actualWeight, weight, destParaId, overriddenWeight, xcmFee, _yield$this$getPaymen, executionFee, fee, _t, _t2, _t3, _t4;
|
|
813
|
+
var tx, address, feeAsset, chain, destination, version, _options$useRootOrigi, useRootOrigin, bypassOptions, supportsDryRunApi, basePayload, resolvedTx, resolvedFeeAsset, performDryRunCall, findFailingEventInResult, getExecutionSuccessFromResult, extractFailureReasonFromResult, response, resultHuman, resultJson, isSuccess, failureErr, shouldRetryWithVersion, msg, _msg, forwardedXcms, actualWeight, weight, destParaId, overriddenWeight, xcmFee, _yield$this$getPaymen, executionFee, fee, _t, _t2, _t3, _t4;
|
|
766
814
|
return _regenerator().w(function (_context1) {
|
|
767
815
|
while (1) switch (_context1.p = _context1.n) {
|
|
768
816
|
case 0:
|
|
@@ -819,23 +867,31 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
819
867
|
return _ref5.apply(this, arguments);
|
|
820
868
|
};
|
|
821
869
|
}();
|
|
870
|
+
findFailingEventInResult = function findFailingEventInResult(resultHuman) {
|
|
871
|
+
var _resultHuman$Ok;
|
|
872
|
+
return resultHuman === null || resultHuman === void 0 || (_resultHuman$Ok = resultHuman.Ok) === null || _resultHuman$Ok === void 0 || (_resultHuman$Ok = _resultHuman$Ok.emittedEvents) === null || _resultHuman$Ok === void 0 ? void 0 : _resultHuman$Ok.find(function (event) {
|
|
873
|
+
var _event$data;
|
|
874
|
+
return (event.section === 'utility' || event.section === 'Utility') && event.method === 'DispatchedAs' && ((_event$data = event.data) === null || _event$data === void 0 || (_event$data = _event$data.result) === null || _event$data === void 0 ? void 0 : _event$data.Err);
|
|
875
|
+
});
|
|
876
|
+
};
|
|
822
877
|
getExecutionSuccessFromResult = function getExecutionSuccessFromResult(resultHuman) {
|
|
823
878
|
var _resultHuman$Ok$execu;
|
|
824
|
-
|
|
879
|
+
var errorInEvents = findFailingEventInResult(resultHuman);
|
|
880
|
+
return Boolean((resultHuman === null || resultHuman === void 0 ? void 0 : resultHuman.Ok) && ((_resultHuman$Ok$execu = resultHuman.Ok.executionResult) === null || _resultHuman$Ok$execu === void 0 ? void 0 : _resultHuman$Ok$execu.Ok) && !errorInEvents);
|
|
825
881
|
};
|
|
826
882
|
extractFailureReasonFromResult = function extractFailureReasonFromResult(resultHuman, resultJson) {
|
|
827
|
-
var _resultHuman$
|
|
828
|
-
var modErrHuman = resultHuman === null || resultHuman === void 0 || (_resultHuman$
|
|
883
|
+
var _resultHuman$Ok2, _resultHuman$Ok3, _resultHuman$Ok4, _resultJson$ok, _ref6;
|
|
884
|
+
var modErrHuman = resultHuman === null || resultHuman === void 0 || (_resultHuman$Ok2 = resultHuman.Ok) === null || _resultHuman$Ok2 === void 0 || (_resultHuman$Ok2 = _resultHuman$Ok2.executionResult) === null || _resultHuman$Ok2 === void 0 || (_resultHuman$Ok2 = _resultHuman$Ok2.Err) === null || _resultHuman$Ok2 === void 0 || (_resultHuman$Ok2 = _resultHuman$Ok2.error) === null || _resultHuman$Ok2 === void 0 ? void 0 : _resultHuman$Ok2.Module;
|
|
829
885
|
if (modErrHuman) {
|
|
830
886
|
return resolveModuleError(chain, modErrHuman);
|
|
831
887
|
}
|
|
832
|
-
var otherErrHuman = resultHuman === null || resultHuman === void 0 || (_resultHuman$
|
|
888
|
+
var otherErrHuman = resultHuman === null || resultHuman === void 0 || (_resultHuman$Ok3 = resultHuman.Ok) === null || _resultHuman$Ok3 === void 0 || (_resultHuman$Ok3 = _resultHuman$Ok3.executionResult) === null || _resultHuman$Ok3 === void 0 || (_resultHuman$Ok3 = _resultHuman$Ok3.Err) === null || _resultHuman$Ok3 === void 0 || (_resultHuman$Ok3 = _resultHuman$Ok3.error) === null || _resultHuman$Ok3 === void 0 ? void 0 : _resultHuman$Ok3.Other;
|
|
833
889
|
if (otherErrHuman) {
|
|
834
890
|
return {
|
|
835
891
|
failureReason: String(otherErrHuman)
|
|
836
892
|
};
|
|
837
893
|
}
|
|
838
|
-
var secondErrHuman = resultHuman === null || resultHuman === void 0 || (_resultHuman$
|
|
894
|
+
var secondErrHuman = resultHuman === null || resultHuman === void 0 || (_resultHuman$Ok4 = resultHuman.Ok) === null || _resultHuman$Ok4 === void 0 || (_resultHuman$Ok4 = _resultHuman$Ok4.executionResult) === null || _resultHuman$Ok4 === void 0 || (_resultHuman$Ok4 = _resultHuman$Ok4.Err) === null || _resultHuman$Ok4 === void 0 ? void 0 : _resultHuman$Ok4.error;
|
|
839
895
|
if (secondErrHuman) {
|
|
840
896
|
return {
|
|
841
897
|
failureReason: String(secondErrHuman)
|
|
@@ -850,6 +906,19 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
850
906
|
failureReason: String(execErrJson.other)
|
|
851
907
|
};
|
|
852
908
|
}
|
|
909
|
+
var erroredEvent = findFailingEventInResult(resultHuman);
|
|
910
|
+
if (erroredEvent) {
|
|
911
|
+
var _erroredEvent$data;
|
|
912
|
+
var err = (_erroredEvent$data = erroredEvent.data) === null || _erroredEvent$data === void 0 || (_erroredEvent$data = _erroredEvent$data.result) === null || _erroredEvent$data === void 0 ? void 0 : _erroredEvent$data.Err;
|
|
913
|
+
if (err !== null && err !== void 0 && err.Module) {
|
|
914
|
+
return resolveModuleError(chain, err.Module);
|
|
915
|
+
}
|
|
916
|
+
if (err) {
|
|
917
|
+
return {
|
|
918
|
+
failureReason: typeof err === 'string' ? err : JSON.stringify(err)
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
}
|
|
853
922
|
return {
|
|
854
923
|
failureReason: JSON.stringify((_ref6 = resultJson !== null && resultJson !== void 0 ? resultJson : resultHuman) !== null && _ref6 !== void 0 ? _ref6 : 'Unknown error')
|
|
855
924
|
};
|
|
@@ -1426,6 +1495,61 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
1426
1495
|
}
|
|
1427
1496
|
return signAndSubmit;
|
|
1428
1497
|
}()
|
|
1498
|
+
}, {
|
|
1499
|
+
key: "signAndSubmitFinalized",
|
|
1500
|
+
value: function () {
|
|
1501
|
+
var _signAndSubmitFinalized = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(tx, sender) {
|
|
1502
|
+
var _this3 = this;
|
|
1503
|
+
return _regenerator().w(function (_context17) {
|
|
1504
|
+
while (1) switch (_context17.n) {
|
|
1505
|
+
case 0:
|
|
1506
|
+
if (!isSenderSigner(sender)) {
|
|
1507
|
+
_context17.n = 2;
|
|
1508
|
+
break;
|
|
1509
|
+
}
|
|
1510
|
+
_context17.n = 1;
|
|
1511
|
+
return tx.signAsync(sender.address, {
|
|
1512
|
+
signer: sender.signer
|
|
1513
|
+
});
|
|
1514
|
+
case 1:
|
|
1515
|
+
_context17.n = 3;
|
|
1516
|
+
break;
|
|
1517
|
+
case 2:
|
|
1518
|
+
_context17.n = 3;
|
|
1519
|
+
return tx.signAsync(createKeyringPair(sender));
|
|
1520
|
+
case 3:
|
|
1521
|
+
return _context17.a(2, new Promise(function (resolve, reject) {
|
|
1522
|
+
tx.send(function (_ref13) {
|
|
1523
|
+
var status = _ref13.status,
|
|
1524
|
+
dispatchError = _ref13.dispatchError,
|
|
1525
|
+
txHash = _ref13.txHash;
|
|
1526
|
+
if (status.isFinalized) {
|
|
1527
|
+
if (dispatchError !== undefined) {
|
|
1528
|
+
if (dispatchError.isModule) {
|
|
1529
|
+
var decoded = _this3.api.registry.findMetaError(dispatchError.asModule);
|
|
1530
|
+
var docs = decoded.docs,
|
|
1531
|
+
name = decoded.name,
|
|
1532
|
+
section = decoded.section;
|
|
1533
|
+
reject(new SubmitTransactionError("".concat(section, ".").concat(name, ": ").concat(docs.join(' '))));
|
|
1534
|
+
} else {
|
|
1535
|
+
reject(new SubmitTransactionError(dispatchError.toString()));
|
|
1536
|
+
}
|
|
1537
|
+
} else {
|
|
1538
|
+
resolve(txHash.toString());
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
})["catch"](function (error) {
|
|
1542
|
+
reject(error instanceof Error ? error : new SubmitTransactionError(String(error)));
|
|
1543
|
+
});
|
|
1544
|
+
}));
|
|
1545
|
+
}
|
|
1546
|
+
}, _callee17);
|
|
1547
|
+
}));
|
|
1548
|
+
function signAndSubmitFinalized(_x33, _x34) {
|
|
1549
|
+
return _signAndSubmitFinalized.apply(this, arguments);
|
|
1550
|
+
}
|
|
1551
|
+
return signAndSubmitFinalized;
|
|
1552
|
+
}()
|
|
1429
1553
|
}]);
|
|
1430
1554
|
}();
|
|
1431
1555
|
|
|
@@ -1463,12 +1587,6 @@ var isEthersSigner = function isEthersSigner(signer) {
|
|
|
1463
1587
|
* @returns The asset balance as a bigint.
|
|
1464
1588
|
*/
|
|
1465
1589
|
var getBalance = createPolkadotJsApiCall(getBalance$1);
|
|
1466
|
-
/**
|
|
1467
|
-
* Claims assets from a parachain.
|
|
1468
|
-
*
|
|
1469
|
-
* @returns An extrinsic representing the claim transaction.
|
|
1470
|
-
*/
|
|
1471
|
-
var claimAssets = createPolkadotJsApiCall(claimAssets$1);
|
|
1472
1590
|
|
|
1473
1591
|
var assets = /*#__PURE__*/Object.freeze({
|
|
1474
1592
|
__proto__: null,
|
|
@@ -1476,7 +1594,6 @@ var assets = /*#__PURE__*/Object.freeze({
|
|
|
1476
1594
|
ForeignAbstract: ForeignAbstract,
|
|
1477
1595
|
Native: Native,
|
|
1478
1596
|
Override: Override,
|
|
1479
|
-
claimAssets: claimAssets,
|
|
1480
1597
|
findAssetInfo: findAssetInfo,
|
|
1481
1598
|
getAllAssetsSymbols: getAllAssetsSymbols,
|
|
1482
1599
|
getAssetDecimals: getAssetDecimals,
|
|
@@ -1509,7 +1626,7 @@ var approveToken = /*#__PURE__*/function () {
|
|
|
1509
1626
|
_bridgeInfoFor = bridgeInfoFor('polkadot_mainnet'), gatewayContract = _bridgeInfoFor.environment.gatewayContract;
|
|
1510
1627
|
asset = findAssetInfoOrThrow('Ethereum', {
|
|
1511
1628
|
symbol: symbol
|
|
1512
|
-
}
|
|
1629
|
+
});
|
|
1513
1630
|
assertHasId(asset);
|
|
1514
1631
|
weth9 = WETH9__factory.connect(asset.assetId, signer);
|
|
1515
1632
|
_context.n = 1;
|
|
@@ -1540,7 +1657,7 @@ var depositToken = /*#__PURE__*/function () {
|
|
|
1540
1657
|
case 0:
|
|
1541
1658
|
asset = findAssetInfoOrThrow('Ethereum', {
|
|
1542
1659
|
symbol: symbol
|
|
1543
|
-
}
|
|
1660
|
+
});
|
|
1544
1661
|
assertHasId(asset);
|
|
1545
1662
|
weth9 = WETH9__factory.connect(asset.assetId, signer);
|
|
1546
1663
|
_context.n = 1;
|
|
@@ -1599,11 +1716,11 @@ var createContext = function createContext(executionUrl, env) {
|
|
|
1599
1716
|
*/
|
|
1600
1717
|
var transferEthToPolkadot$1 = /*#__PURE__*/function () {
|
|
1601
1718
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
1602
|
-
var api, provider, signer,
|
|
1719
|
+
var api, provider, signer, recipient, to, currency, ethAsset, amount, _bridgeInfoFor, environment, registry, context, destParaId, fee, sourceAddress, transfer, validation, tx, response, receipt, messageReceipt, _t, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t0, _t1;
|
|
1603
1720
|
return _regenerator().w(function (_context) {
|
|
1604
1721
|
while (1) switch (_context.n) {
|
|
1605
1722
|
case 0:
|
|
1606
|
-
api = _ref.api, provider = _ref.provider, signer = _ref.signer,
|
|
1723
|
+
api = _ref.api, provider = _ref.provider, signer = _ref.signer, recipient = _ref.recipient, to = _ref.to, currency = _ref.currency;
|
|
1607
1724
|
if (!Array.isArray(currency)) {
|
|
1608
1725
|
_context.n = 1;
|
|
1609
1726
|
break;
|
|
@@ -1657,7 +1774,7 @@ var transferEthToPolkadot$1 = /*#__PURE__*/function () {
|
|
|
1657
1774
|
case 8:
|
|
1658
1775
|
sourceAddress = _context.v;
|
|
1659
1776
|
_context.n = 9;
|
|
1660
|
-
return toPolkadotV2.createTransfer(registry, sourceAddress,
|
|
1777
|
+
return toPolkadotV2.createTransfer(registry, sourceAddress, recipient, ethAsset.assetId, destParaId, amount, fee);
|
|
1661
1778
|
case 9:
|
|
1662
1779
|
transfer = _context.v;
|
|
1663
1780
|
_t5 = toPolkadotV2;
|
|
@@ -1752,7 +1869,7 @@ var getTokenBalance = /*#__PURE__*/function () {
|
|
|
1752
1869
|
case 0:
|
|
1753
1870
|
asset = findAssetInfoOrThrow('Ethereum', {
|
|
1754
1871
|
symbol: symbol
|
|
1755
|
-
}
|
|
1872
|
+
});
|
|
1756
1873
|
assertHasId(asset);
|
|
1757
1874
|
weth9 = WETH9__factory.connect(asset.assetId, signer);
|
|
1758
1875
|
_context.n = 1;
|
|
@@ -1816,10 +1933,10 @@ var EvmBuilderCore = /*#__PURE__*/function () {
|
|
|
1816
1933
|
* @returns An instance of EvmBuilder
|
|
1817
1934
|
*/
|
|
1818
1935
|
}, {
|
|
1819
|
-
key: "
|
|
1820
|
-
value: function address
|
|
1936
|
+
key: "recipient",
|
|
1937
|
+
value: function recipient(address) {
|
|
1821
1938
|
return new EvmBuilderCore(_objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
1822
|
-
|
|
1939
|
+
recipient: address
|
|
1823
1940
|
}));
|
|
1824
1941
|
}
|
|
1825
1942
|
/**
|
|
@@ -1857,12 +1974,12 @@ var EvmBuilderCore = /*#__PURE__*/function () {
|
|
|
1857
1974
|
key: "build",
|
|
1858
1975
|
value: (function () {
|
|
1859
1976
|
var _build = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1860
|
-
var _this$_options, from, to,
|
|
1977
|
+
var _this$_options, from, to, recipient, signer, api, _yield$transferEthToP, response;
|
|
1861
1978
|
return _regenerator().w(function (_context) {
|
|
1862
1979
|
while (1) switch (_context.n) {
|
|
1863
1980
|
case 0:
|
|
1864
|
-
_this$_options = this._options, from = _this$_options.from, to = _this$_options.to,
|
|
1865
|
-
validateAddress$1(api,
|
|
1981
|
+
_this$_options = this._options, from = _this$_options.from, to = _this$_options.to, recipient = _this$_options.recipient, signer = _this$_options.signer, api = _this$_options.api;
|
|
1982
|
+
validateAddress$1(api, recipient, to);
|
|
1866
1983
|
if (!(from === 'Moonbeam' && to === 'Ethereum')) {
|
|
1867
1984
|
_context.n = 2;
|
|
1868
1985
|
break;
|
|
@@ -1993,4 +2110,4 @@ var transfer = /*#__PURE__*/Object.freeze({
|
|
|
1993
2110
|
transferEthToPolkadot: transferEthToPolkadot
|
|
1994
2111
|
});
|
|
1995
2112
|
|
|
1996
|
-
export { Builder, EvmBuilder, approveToken, assets,
|
|
2113
|
+
export { Builder, EvmBuilder, approveToken, assets, convertSs58, createChainClient, depositToken, dryRun, dryRunOrigin, getBalance, getBridgeStatus, getParaEthTransferFees, getTokenBalance, transferEthToPolkadot, transfer as xcmPallet };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paraspell/sdk-pjs",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.10.0-rc.0",
|
|
4
4
|
"description": "Polkadot.js based SDK for ParaSpell XCM/XCMP tool for developers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@snowbridge/registry": "^0.4.4",
|
|
30
30
|
"ethers": "^6.16.0",
|
|
31
31
|
"viem": "2.47.1",
|
|
32
|
-
"@paraspell/sdk-core": "12.
|
|
32
|
+
"@paraspell/sdk-core": "12.10.0-rc.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@polkadot/api": ">= 16.0 < 17",
|