@paraspell/sdk 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/index.cjs +176 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.mjs +170 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 - UnJS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @paraspell/sdk
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![Github Actions][github-actions-src]][github-actions-href]
|
|
6
|
+
[![Codecov][codecov-src]][codecov-href]
|
|
7
|
+
|
|
8
|
+
> Package description
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
Install package:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
# npm
|
|
16
|
+
npm install @paraspell/sdk
|
|
17
|
+
|
|
18
|
+
# yarn
|
|
19
|
+
yarn install @paraspell/sdk
|
|
20
|
+
|
|
21
|
+
# pnpm
|
|
22
|
+
pnpm install @paraspell/sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Import:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
// ESM
|
|
29
|
+
import { } from '@paraspell/sdk'
|
|
30
|
+
|
|
31
|
+
// CommonJS
|
|
32
|
+
const { } = require('@paraspell/sdk')
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 💻 Development
|
|
36
|
+
|
|
37
|
+
- Clone this repository
|
|
38
|
+
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)
|
|
39
|
+
- Install dependencies using `pnpm install`
|
|
40
|
+
- Run interactive tests using `pnpm dev`
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
Made with 💛
|
|
45
|
+
|
|
46
|
+
Published under [MIT License](./LICENSE).
|
|
47
|
+
|
|
48
|
+
<!-- Badges -->
|
|
49
|
+
[npm-version-src]: https://img.shields.io/npm/v/@paraspell/sdk?style=flat-square
|
|
50
|
+
[npm-version-href]: https://npmjs.com/package/@paraspell/sdk
|
|
51
|
+
|
|
52
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@paraspell/sdk?style=flat-square
|
|
53
|
+
[npm-downloads-href]: https://npmjs.com/package/@paraspell/sdk
|
|
54
|
+
|
|
55
|
+
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/@paraspell/sdk/ci/main?style=flat-square
|
|
56
|
+
[github-actions-href]: https://github.com/unjs/@paraspell/sdk/actions?query=workflow%3Aci
|
|
57
|
+
|
|
58
|
+
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/@paraspell/sdk/main?style=flat-square
|
|
59
|
+
[codecov-href]: https://codecov.io/gh/unjs/@paraspell/sdk
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function createAccID(api, account) {
|
|
6
|
+
return api.createType("AccountId32", account).toHex();
|
|
7
|
+
}
|
|
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
|
+
{
|
|
17
|
+
V1: {
|
|
18
|
+
parents: 1,
|
|
19
|
+
interior: {
|
|
20
|
+
X1: {
|
|
21
|
+
AccountId32: {
|
|
22
|
+
network: "any",
|
|
23
|
+
id: createAccID(api, to)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
46e8
|
|
30
|
+
);
|
|
31
|
+
} else if (origin == "Pichiu") {
|
|
32
|
+
return api.tx.ormlXTokens.transfer(
|
|
33
|
+
currency,
|
|
34
|
+
amount,
|
|
35
|
+
{
|
|
36
|
+
V1: {
|
|
37
|
+
parents: 1,
|
|
38
|
+
interior: {
|
|
39
|
+
X1: {
|
|
40
|
+
AccountId32: {
|
|
41
|
+
network: "any",
|
|
42
|
+
id: createAccID(api, to)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
46e8
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function transferRelayToPara(api, destination, amount, to) {
|
|
53
|
+
return api.tx.xcmPallet.reserveTransferAssets(
|
|
54
|
+
{
|
|
55
|
+
V1: {
|
|
56
|
+
parents: 0,
|
|
57
|
+
interior: {
|
|
58
|
+
X1: {
|
|
59
|
+
Parachain: destination
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
V1: {
|
|
66
|
+
parents: 0,
|
|
67
|
+
interior: {
|
|
68
|
+
X1: {
|
|
69
|
+
AccountId32: {
|
|
70
|
+
network: "Any",
|
|
71
|
+
id: createAccID(api, to)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
V1: [
|
|
79
|
+
{
|
|
80
|
+
id: {
|
|
81
|
+
Concrete: {
|
|
82
|
+
parents: 0,
|
|
83
|
+
interior: "Here"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
fun: {
|
|
87
|
+
Fungible: amount
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
0
|
|
93
|
+
);
|
|
94
|
+
}
|
|
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
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const index$2 = {
|
|
150
|
+
__proto__: null,
|
|
151
|
+
transferParaToPara: transferParaToPara,
|
|
152
|
+
transferParaToRelay: transferParaToRelay,
|
|
153
|
+
transferRelayToPara: transferRelayToPara
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
function openChannel(api, origin, destination, maxSize, maxMessageSize) {
|
|
157
|
+
return api.tx.sudo.sudo(api.tx.parasSudoWrapper.sudoEstablishHrmpChannel(origin, destination, maxSize, maxMessageSize));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const index$1 = {
|
|
161
|
+
__proto__: null,
|
|
162
|
+
openChannel: openChannel
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
function closeChannel(api, origin, inbound, outbound) {
|
|
166
|
+
return api.tx.sudo.sudo(api.tx.hrmp.forceCleanHrmp(origin, inbound, outbound));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const index = {
|
|
170
|
+
__proto__: null,
|
|
171
|
+
closeChannel: closeChannel
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
exports.closeChannels = index;
|
|
175
|
+
exports.openChannels = index$1;
|
|
176
|
+
exports.xTokens = index$2;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ApiPromise } from '@polkadot/api';
|
|
2
|
+
import { SubmittableExtrinsic } from '@polkadot/api/types';
|
|
3
|
+
|
|
4
|
+
declare type Extrinsic = SubmittableExtrinsic<'promise'>;
|
|
5
|
+
|
|
6
|
+
declare function transferParaToRelay(api: ApiPromise, origin: string, currency: string, amount: any, to: string): Extrinsic;
|
|
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;
|
|
9
|
+
|
|
10
|
+
declare const index$2_transferParaToPara: typeof transferParaToPara;
|
|
11
|
+
declare const index$2_transferParaToRelay: typeof transferParaToRelay;
|
|
12
|
+
declare const index$2_transferRelayToPara: typeof transferRelayToPara;
|
|
13
|
+
declare namespace index$2 {
|
|
14
|
+
export {
|
|
15
|
+
index$2_transferParaToPara as transferParaToPara,
|
|
16
|
+
index$2_transferParaToRelay as transferParaToRelay,
|
|
17
|
+
index$2_transferRelayToPara as transferRelayToPara,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare function openChannel(api: ApiPromise, origin: number, destination: number, maxSize: number, maxMessageSize: number): Extrinsic;
|
|
22
|
+
|
|
23
|
+
declare const index$1_openChannel: typeof openChannel;
|
|
24
|
+
declare namespace index$1 {
|
|
25
|
+
export {
|
|
26
|
+
index$1_openChannel as openChannel,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare function closeChannel(api: ApiPromise, origin: number, inbound: number, outbound: number): Extrinsic;
|
|
31
|
+
|
|
32
|
+
declare const index_closeChannel: typeof closeChannel;
|
|
33
|
+
declare namespace index {
|
|
34
|
+
export {
|
|
35
|
+
index_closeChannel as closeChannel,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { index as closeChannels, index$1 as openChannels, index$2 as xTokens };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
function createAccID(api, account) {
|
|
2
|
+
return api.createType("AccountId32", account).toHex();
|
|
3
|
+
}
|
|
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
|
+
{
|
|
13
|
+
V1: {
|
|
14
|
+
parents: 1,
|
|
15
|
+
interior: {
|
|
16
|
+
X1: {
|
|
17
|
+
AccountId32: {
|
|
18
|
+
network: "any",
|
|
19
|
+
id: createAccID(api, to)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
46e8
|
|
26
|
+
);
|
|
27
|
+
} else if (origin == "Pichiu") {
|
|
28
|
+
return api.tx.ormlXTokens.transfer(
|
|
29
|
+
currency,
|
|
30
|
+
amount,
|
|
31
|
+
{
|
|
32
|
+
V1: {
|
|
33
|
+
parents: 1,
|
|
34
|
+
interior: {
|
|
35
|
+
X1: {
|
|
36
|
+
AccountId32: {
|
|
37
|
+
network: "any",
|
|
38
|
+
id: createAccID(api, to)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
46e8
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function transferRelayToPara(api, destination, amount, to) {
|
|
49
|
+
return api.tx.xcmPallet.reserveTransferAssets(
|
|
50
|
+
{
|
|
51
|
+
V1: {
|
|
52
|
+
parents: 0,
|
|
53
|
+
interior: {
|
|
54
|
+
X1: {
|
|
55
|
+
Parachain: destination
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
V1: {
|
|
62
|
+
parents: 0,
|
|
63
|
+
interior: {
|
|
64
|
+
X1: {
|
|
65
|
+
AccountId32: {
|
|
66
|
+
network: "Any",
|
|
67
|
+
id: createAccID(api, to)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
V1: [
|
|
75
|
+
{
|
|
76
|
+
id: {
|
|
77
|
+
Concrete: {
|
|
78
|
+
parents: 0,
|
|
79
|
+
interior: "Here"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
fun: {
|
|
83
|
+
Fungible: amount
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
0
|
|
89
|
+
);
|
|
90
|
+
}
|
|
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
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const index$2 = {
|
|
146
|
+
__proto__: null,
|
|
147
|
+
transferParaToPara: transferParaToPara,
|
|
148
|
+
transferParaToRelay: transferParaToRelay,
|
|
149
|
+
transferRelayToPara: transferRelayToPara
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
function openChannel(api, origin, destination, maxSize, maxMessageSize) {
|
|
153
|
+
return api.tx.sudo.sudo(api.tx.parasSudoWrapper.sudoEstablishHrmpChannel(origin, destination, maxSize, maxMessageSize));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const index$1 = {
|
|
157
|
+
__proto__: null,
|
|
158
|
+
openChannel: openChannel
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
function closeChannel(api, origin, inbound, outbound) {
|
|
162
|
+
return api.tx.sudo.sudo(api.tx.hrmp.forceCleanHrmp(origin, inbound, outbound));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const index = {
|
|
166
|
+
__proto__: null,
|
|
167
|
+
closeChannel: closeChannel
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export { index as closeChannels, index$1 as openChannels, index$2 as xTokens };
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@paraspell/sdk",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "SDK for ParaSpell XCM/XCMP tool for developers",
|
|
5
|
+
"repository": "@paraspell/sdk",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@polkadot/api": "^8.0.2",
|
|
23
|
+
"@polkadot/types": "^8.0.2"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@nuxtjs/eslint-config-typescript": "latest",
|
|
27
|
+
"@vitest/coverage-c8": "latest",
|
|
28
|
+
"eslint": "latest",
|
|
29
|
+
"standard-version": "latest",
|
|
30
|
+
"typescript": "latest",
|
|
31
|
+
"unbuild": "latest",
|
|
32
|
+
"vitest": "latest"
|
|
33
|
+
},
|
|
34
|
+
"packageManager": "pnpm@7.9.5",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "unbuild",
|
|
37
|
+
"dev": "vitest dev",
|
|
38
|
+
"lint": "eslint --ext .ts,.js,.mjs,.cjs .",
|
|
39
|
+
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish --no-git-checks --access=public",
|
|
40
|
+
"test": "pnpm lint && vitest run --coverage"
|
|
41
|
+
}
|
|
42
|
+
}
|