@moonbeam-network/xcm-sdk 3.0.0 → 3.0.2

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.
Files changed (3) hide show
  1. package/README.md +19 -31
  2. package/package.json +17 -15
  3. package/build/index.d.mts +0 -195
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The Moonbeam XCM SDK enables developers to easily transfer assets between chains, either between parachains or between a parachain and the relay chain, within the Polkadot/Kusama ecosystem. With the SDK, you don't need to worry about determining the multilocation of the origin or destination assets or which extrinsics are used on which networks to send XCM transfers.
2
2
 
3
- The XCM SDK offers helper functions, that provide a very simple interface to execute XCM transfers between chains in the Polkadot/Kusama ecosystem. In addition, the XCM config package allows any parachain project to add their information in a standard way, so they can be immediately supported by the XCM SDK.
3
+ The XCM SDK offers helper functions that provide a very simple interface to execute XCM transfers between chains in the Polkadot/Kusama ecosystem. In addition, the XCM config package allows any parachain project to add their information in a standard way, so they can be immediately supported by the XCM SDK.
4
4
 
5
5
  # Documentation
6
6
 
@@ -15,40 +15,30 @@ npm i @moonbeam-network/xcm-sdk
15
15
  :warning: You need to have peer dependencies of SDK installed as well.
16
16
 
17
17
  ```bash
18
- npm i @polkadot/api @polkadot/api-augment @polkadot/types @polkadot/util @polkadot/util-crypto @polkadot/apps-config ethers
18
+ npm i @polkadot/api @polkadot/util-crypto
19
19
  ```
20
20
 
21
21
  # Usage
22
22
 
23
- The following sections contain basic examples of how to work with the XCM SDK to build transfer data to transfer an asset from one chain to another and how to submit the transfer. For a detailed overview on how to use each method, including a reference to the parameters and returned data of each method exposed by the SDK, please refer to the [XCM SDK docs](https://docs.moonbeam.network/builders/interoperability/xcm/xcm-sdk/v1/).
23
+ The following sections contain basic examples of how to work with the XCM SDK to build transfer data to transfer an asset from one chain to another and how to submit the transfer. For a detailed overview on how to use it, please refer to the [XCM SDK docs](https://moonbeam-foundation.github.io/xcm-sdk/latest/example-usage/xcm).
24
24
 
25
25
  ## Build XCM Transfer Data
26
26
 
27
27
  ```js
28
28
  import { Sdk } from '@moonbeam-network/xcm-sdk';
29
29
 
30
- const { assets, getTransferData } = Sdk();
31
-
32
- // You can build the XCM transfer data via the assets function
33
- const dataViaAssetsMethod = await assets()
34
- .asset('INSERT_ASSET')
35
- .source('INSERT_SOURCE_CHAIN')
36
- .destination('INSERT_DESTINATION_CHAIN')
37
- .accounts('INSERT_SOURCE_ADDRESS', 'INSERT_DESTINATION_ADDRESS', {
38
- evmSigner?: 'INSERT_EVM_SIGNER',
39
- polkadotSigner?: 'INSERT_POLKADOT_SIGNER',
40
- });
41
-
42
- // Or via the getTransferData function
43
- const dataViaGetTransferDataMethod = await getTransferData({
44
- destinationAddress: 'INSERT_DESTINATION_ADDRESS',
45
- destinationKeyOrChain: 'INSERT_DESTINATION_CHAIN',
46
- evmSigner?: 'INSERT_EVM_SIGNER',
47
- keyOrAsset: 'INSERT_ASSET',
48
- polkadotSigner?: 'INSERT_POLKADOT_SIGNER',
49
- sourceAddress: 'INSERT_SOURCE_ADDRESS',
50
- sourceKeyOrChain: 'INSERT_SOURCE_CHAIN',
51
- });
30
+ const transferData = async () => {
31
+ const transferData = await Sdk()
32
+ .setAsset(INSERT_ASSET)
33
+ .setSource(INSERT_SOURCE_CHAIN)
34
+ .setDestination(INSERT_DESTINATION_CHAIN)
35
+ .setAddresses({
36
+ sourceAddress: INSERT_SOURCE_ADDRESS,
37
+ destinationAddress: INSERT_DESTINATION_ADDRESS,
38
+ });
39
+ };
40
+
41
+ fromPolkadot();
52
42
  ```
53
43
 
54
44
  ## Transfer
@@ -56,7 +46,7 @@ const dataViaGetTransferDataMethod = await getTransferData({
56
46
  ```js
57
47
  ...
58
48
 
59
- const hash = await dataViaGetTransferDataMethod.transfer('INSERT_TRANSFER_AMOUNT');
49
+ const hash = await transferData.transfer(INSERT_TRANSFER_AMOUNT, { INSERT_SIGNERS });
60
50
  ```
61
51
 
62
52
  # Examples
@@ -76,10 +66,11 @@ pnpm run start
76
66
 
77
67
  # Contributing
78
68
 
69
+ First fork the repository and clone it.
70
+
79
71
  ```bash
80
- git clone git@github.com:moonbeam-foundation/xcm-sdk.git
72
+ git clone git@github.com:YOUR_GITHUB_USERNAME/xcm-sdk.git
81
73
  pnpm install
82
- pnpm run dev
83
74
  ```
84
75
 
85
76
  Optionally, you can install the `pre-commit` hook to run the linter and tests before committing:
@@ -99,9 +90,6 @@ pnpm run test
99
90
  ## Acceptance tests
100
91
 
101
92
  ```bash
102
- cp .env.example .env
103
- # add private key and suri to .env file
104
-
105
93
  pnpm run test:acc
106
94
  ```
107
95
 
package/package.json CHANGED
@@ -1,14 +1,7 @@
1
1
  {
2
2
  "name": "@moonbeam-network/xcm-sdk",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "The Moonbeam XCM SDK enables developers to easily deposit and withdraw assets to Moonbeam/Moonriver from the relay chain and other parachains in the Polkadot/Kusama ecosystem",
5
- "scripts": {
6
- "build": "tsup",
7
- "dev": "tsup --watch",
8
- "link": "pnpm ln --global",
9
- "typecheck": "tsc --noEmit",
10
- "test:acc": "vitest --run --testTimeout 300000 ./tests/acceptance"
11
- },
12
5
  "author": "moonbeam-foundation",
13
6
  "license": "MIT",
14
7
  "repository": {
@@ -29,7 +22,9 @@
29
22
  "url": "https://github.com/moonbeam-foundation/xcm-sdk/issues"
30
23
  },
31
24
  "homepage": "https://moonbeam-foundation.github.io/xcm-sdk/latest",
32
- "files": ["build"],
25
+ "files": [
26
+ "build"
27
+ ],
33
28
  "type": "module",
34
29
  "exports": {
35
30
  "import": "./build/index.mjs",
@@ -39,11 +34,11 @@
39
34
  "types": "./build/index.d.ts",
40
35
  "main": "./build/index.mjs",
41
36
  "dependencies": {
42
- "@moonbeam-network/xcm-builder": "3.0.0",
43
- "@moonbeam-network/xcm-config": "3.0.0",
44
- "@moonbeam-network/xcm-types": "3.0.0",
45
- "@moonbeam-network/xcm-utils": "3.0.0",
46
- "big.js": "^6.2.1"
37
+ "big.js": "^6.2.1",
38
+ "@moonbeam-network/xcm-config": "3.0.2",
39
+ "@moonbeam-network/xcm-types": "3.0.2",
40
+ "@moonbeam-network/xcm-utils": "3.0.2",
41
+ "@moonbeam-network/xcm-builder": "3.0.2"
47
42
  },
48
43
  "peerDependencies": {
49
44
  "@polkadot/api": "14.3.1",
@@ -54,5 +49,12 @@
54
49
  },
55
50
  "devDependencies": {
56
51
  "@types/big.js": "^6.2.2"
52
+ },
53
+ "scripts": {
54
+ "build": "tsup",
55
+ "dev": "tsup --watch",
56
+ "link": "pnpm ln --global",
57
+ "typecheck": "tsc --noEmit",
58
+ "test:acc": "vitest --run --testTimeout 300000 ./tests/acceptance"
57
59
  }
58
- }
60
+ }
package/build/index.d.mts DELETED
@@ -1,195 +0,0 @@
1
- import { ContractConfig, ExtrinsicConfig, BalanceConfigBuilder, AssetMinConfigBuilder, FeeConfigBuilder, SubstrateQueryConfig, EvmQueryConfig } from '@moonbeam-network/xcm-builder';
2
- import { AssetRoute, FeeConfig, ConfigService } from '@moonbeam-network/xcm-config';
3
- import * as _moonbeam_network_xcm_types from '@moonbeam-network/xcm-types';
4
- import { AssetAmount, AnyChain, AnyParachain, ChainAsset, Asset, EvmChain, EvmParachain, Ecosystem, AnyAsset } from '@moonbeam-network/xcm-types';
5
- import { Signer, SubmittableExtrinsic } from '@polkadot/api/types';
6
- import { IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
7
- import { WalletClient, PublicClient, HttpTransport, Hash } from 'viem';
8
- import { ApiPromise } from '@polkadot/api';
9
- import { RuntimeDispatchInfo } from '@polkadot/types/interfaces';
10
- import { HexString } from '@polkadot/util/types';
11
-
12
- type EvmSigner = WalletClient;
13
- interface Signers {
14
- evmSigner?: EvmSigner;
15
- polkadotSigner?: Signer | IKeyringPair;
16
- }
17
- interface TransferData {
18
- destination: DestinationChainTransferData;
19
- getEstimate(amount: number | string): AssetAmount;
20
- max: AssetAmount;
21
- min: AssetAmount;
22
- source: SourceChainTransferData;
23
- transfer(amount: bigint | number | string, signers: Signers): Promise<string>;
24
- }
25
- interface SourceChainTransferData extends ChainTransferData {
26
- destinationFee: AssetAmount;
27
- destinationFeeBalance: AssetAmount;
28
- feeBalance: AssetAmount;
29
- max: AssetAmount;
30
- }
31
- interface SovereignAccountBalance {
32
- feeAssetBalance: bigint | undefined;
33
- transferAssetBalance: bigint;
34
- }
35
- interface DestinationChainTransferData extends ChainTransferData {
36
- sovereignAccountBalances?: SovereignAccountBalance;
37
- }
38
- interface ChainTransferData {
39
- balance: AssetAmount;
40
- chain: AnyChain;
41
- existentialDeposit?: AssetAmount;
42
- fee: AssetAmount;
43
- min: AssetAmount;
44
- }
45
-
46
- interface GetSourceDataParams {
47
- route: AssetRoute;
48
- destinationAddress: string;
49
- destinationFee: AssetAmount;
50
- sourceAddress: string;
51
- }
52
- declare function getSourceData({ route, destinationAddress, destinationFee, sourceAddress, }: GetSourceDataParams): Promise<SourceChainTransferData>;
53
- interface GetFeeParams {
54
- balance: AssetAmount;
55
- feeBalance: AssetAmount;
56
- contract?: ContractConfig;
57
- chain: AnyParachain;
58
- destinationFee: AssetAmount;
59
- extrinsic?: ExtrinsicConfig;
60
- feeConfig?: FeeConfig;
61
- sourceAddress: string;
62
- }
63
- declare function getFee({ balance, feeBalance, chain, contract, destinationFee, extrinsic, feeConfig, sourceAddress, }: GetFeeParams): Promise<AssetAmount>;
64
- interface GetAssetsBalancesParams {
65
- address: string;
66
- chain: AnyParachain;
67
- routes: AssetRoute[];
68
- evmSigner?: EvmSigner;
69
- }
70
- declare function getAssetsBalances({ address, chain, routes, }: GetAssetsBalancesParams): Promise<AssetAmount[]>;
71
-
72
- interface GetDestinationDataParams {
73
- route: AssetRoute;
74
- destinationAddress: string;
75
- }
76
- declare function getDestinationData({ route, destinationAddress, }: GetDestinationDataParams): Promise<DestinationChainTransferData>;
77
-
78
- interface GetBalancesParams {
79
- address: string;
80
- asset: ChainAsset;
81
- builder: BalanceConfigBuilder;
82
- chain: AnyChain;
83
- }
84
- declare function getBalance({ address, asset, builder, chain, }: GetBalancesParams): Promise<AssetAmount>;
85
- interface GetMinParams {
86
- asset: Asset;
87
- builder?: AssetMinConfigBuilder;
88
- chain: AnyChain;
89
- }
90
- declare function getAssetMin({ asset, builder, chain, }: GetMinParams): Promise<AssetAmount>;
91
- declare function getMin({ balance, existentialDeposit, fee, min, }: DestinationChainTransferData): AssetAmount;
92
- interface GetMaxParams {
93
- balance: AssetAmount;
94
- existentialDeposit?: AssetAmount;
95
- fee: AssetAmount;
96
- min: AssetAmount;
97
- }
98
- declare function getMax({ balance, existentialDeposit, fee, min, }: GetMaxParams): AssetAmount;
99
- interface GetDestinationFeeParams {
100
- address: string;
101
- asset: Asset;
102
- feeAsset: Asset;
103
- destination: AnyChain;
104
- fee: number | FeeConfigBuilder;
105
- }
106
- declare function getDestinationFee({ address, asset, destination, fee, feeAsset, }: GetDestinationFeeParams): Promise<AssetAmount>;
107
- interface ConvertToChainDecimalsParams {
108
- asset: AssetAmount;
109
- target: ChainAsset;
110
- }
111
- declare function convertToChainDecimals({ asset, target, }: ConvertToChainDecimalsParams): AssetAmount;
112
- declare function getExistentialDeposit(chain: AnyChain): Promise<AssetAmount | undefined>;
113
- interface GetDestinationFeeBalanceParams {
114
- balance: AssetAmount;
115
- feeBalance: AssetAmount;
116
- route: AssetRoute;
117
- sourceAddress: string;
118
- }
119
- declare function getDestinationFeeBalance({ balance, feeBalance, route, sourceAddress, }: GetDestinationFeeBalanceParams): Promise<AssetAmount>;
120
- interface GetExtrinsicFeeParams {
121
- address: string;
122
- balance: AssetAmount;
123
- chain: AnyParachain;
124
- extrinsic: ExtrinsicConfig;
125
- feeBalance: AssetAmount;
126
- feeConfig?: FeeConfig;
127
- }
128
- declare function getExtrinsicFee({ address, balance, chain, extrinsic, feeBalance, feeConfig, }: GetExtrinsicFeeParams): Promise<AssetAmount>;
129
- interface GetContractFeeParams {
130
- address: string;
131
- balance: AssetAmount;
132
- chain: EvmChain | EvmParachain;
133
- contract: ContractConfig;
134
- destinationFee: AssetAmount;
135
- feeBalance: AssetAmount;
136
- feeConfig?: FeeConfig;
137
- }
138
- declare function getContractFee({ address, balance, chain, contract, destinationFee, feeBalance, feeConfig, }: GetContractFeeParams): Promise<AssetAmount>;
139
- interface ValidateSovereignAccountBalancesProps {
140
- amount: bigint;
141
- destinationData: DestinationChainTransferData;
142
- sourceData: SourceChainTransferData;
143
- }
144
- declare function validateSovereignAccountBalances({ amount, sourceData, destinationData, }: ValidateSovereignAccountBalancesProps): void;
145
-
146
- interface SdkOptions {
147
- configService?: ConfigService;
148
- ecosystem?: Ecosystem;
149
- }
150
- declare function Sdk({ configService, ecosystem }?: SdkOptions): {
151
- assets: _moonbeam_network_xcm_types.Asset[];
152
- setAsset(asset: string | AnyAsset): {
153
- sources: AnyChain[];
154
- setSource(source: string | AnyChain): {
155
- destinations: AnyChain[];
156
- setDestination(destination: string | AnyChain): {
157
- setAddresses({ sourceAddress, destinationAddress, }: {
158
- sourceAddress: string;
159
- destinationAddress: string;
160
- }): Promise<TransferData>;
161
- };
162
- };
163
- };
164
- };
165
- declare function getParachainBalances(chain: AnyParachain, address: string, service?: ConfigService): Promise<AssetAmount[]>;
166
-
167
- declare class PolkadotService {
168
- #private;
169
- readonly api: ApiPromise;
170
- readonly chain: AnyParachain;
171
- constructor(api: ApiPromise, chain: AnyParachain);
172
- static create(chain: AnyParachain): Promise<PolkadotService>;
173
- static createMulti(chains: AnyParachain[]): Promise<PolkadotService[]>;
174
- get decimals(): number;
175
- get existentialDeposit(): AssetAmount;
176
- query(config: SubstrateQueryConfig): Promise<bigint>;
177
- getExtrinsic(config: ExtrinsicConfig): SubmittableExtrinsic<'promise', ISubmittableResult>;
178
- getExtrinsicCallHash(config: ExtrinsicConfig): HexString;
179
- getPaymentInfo(account: string, config: ExtrinsicConfig): Promise<RuntimeDispatchInfo>;
180
- getFee(account: string, config: ExtrinsicConfig): Promise<bigint>;
181
- transfer(account: string, config: ExtrinsicConfig, signer: Signer | IKeyringPair, statusCallback?: (params: ISubmittableResult) => void): Promise<string>;
182
- }
183
-
184
- declare class EvmService {
185
- readonly chain: EvmChain | EvmParachain;
186
- readonly client: PublicClient<HttpTransport>;
187
- static create(chain: EvmChain | EvmParachain): EvmService;
188
- constructor(chain: EvmChain | EvmParachain);
189
- query(query: EvmQueryConfig): Promise<bigint>;
190
- getFee(address: string, contract: ContractConfig): Promise<bigint>;
191
- getBalance(address: string, contract: ContractConfig): Promise<bigint>;
192
- transfer(signer: EvmSigner, contract: ContractConfig): Promise<Hash>;
193
- }
194
-
195
- export { type ChainTransferData, type ConvertToChainDecimalsParams, type DestinationChainTransferData, EvmService, type EvmSigner, type GetAssetsBalancesParams, type GetBalancesParams, type GetContractFeeParams, type GetDestinationDataParams, type GetDestinationFeeBalanceParams, type GetDestinationFeeParams, type GetExtrinsicFeeParams, type GetFeeParams, type GetMaxParams, type GetMinParams, type GetSourceDataParams, PolkadotService, Sdk, type SdkOptions, type Signers, type SourceChainTransferData, type SovereignAccountBalance, type TransferData, convertToChainDecimals, getAssetMin, getAssetsBalances, getBalance, getContractFee, getDestinationData, getDestinationFee, getDestinationFeeBalance, getExistentialDeposit, getExtrinsicFee, getFee, getMax, getMin, getParachainBalances, getSourceData, validateSovereignAccountBalances };