@moonbeam-network/xcm-sdk 1.0.0-dev.16 → 1.0.0-dev.161

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2022 PureStake
1
+ Copyright 2024 Moonbeam Foundation
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,22 +1,10 @@
1
- ![Moonbeam](https://docs.moonbeam.network/images/builders/interoperability/xcm/sdk/xcm-sdk-banner.png)
2
-
3
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.
4
2
 
5
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.
6
4
 
7
5
  # Documentation
8
6
 
9
- ## v1 (current)
10
-
11
- - [readme](https://github.com/PureStake/xcm-sdk/tree/main)
12
- - [usage](https://docs.moonbeam.network/builders/interoperability/xcm/xcm-sdk/v1/xcm-sdk/)
13
- - [reference](https://docs.moonbeam.network/builders/interoperability/xcm/xcm-sdk/v1/reference/)
14
-
15
- ## v0 (previous)
16
-
17
- - [readme](https://github.com/PureStake/xcm-sdk/tree/v0)
18
- - [usage](https://docs.moonbeam.network/builders/interoperability/xcm/xcm-sdk/v0/xcm-sdk/)
19
- - [reference](https://docs.moonbeam.network/builders/interoperability/xcm/xcm-sdk/v0/reference/)
7
+ You can find the documentation at [https://moonbeam-foundation.github.io/xcm-sdk/latest/](https://moonbeam-foundation.github.io/xcm-sdk/latest/).
20
8
 
21
9
  # Installation
22
10
 
@@ -32,7 +20,7 @@ npm i @polkadot/api @polkadot/api-augment @polkadot/types @polkadot/util @polkad
32
20
 
33
21
  # Usage
34
22
 
35
- 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 v1 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 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/).
36
24
 
37
25
  ## Build XCM Transfer Data
38
26
 
@@ -73,25 +61,31 @@ const hash = await dataViaGetTransferDataMethod.transfer('INSERT_TRANSFER_AMOUNT
73
61
 
74
62
  # Examples
75
63
 
76
- - [sdk](https://github.com/PureStake/xcm-sdk/blob/main/examples/sdk-simple)
64
+ - [sdk](https://github.com/moonbeam-foundation/xcm-sdk/blob/main/examples/sdk-simple)
77
65
 
78
66
  ```bash
79
- git clone git@github.com:PureStake/xcm-sdk.git
67
+ git clone git@github.com:moonbeam-foundation/xcm-sdk.git
80
68
  cd xcm-sdk
81
- npm i
69
+ pnpm install
82
70
  cd examples/sdk-simple
83
71
 
84
72
  # edit index.ts by adding your accounts
85
73
 
86
- npm start
74
+ pnpm run start
87
75
  ```
88
76
 
89
77
  # Contributing
90
78
 
91
79
  ```bash
92
- git clone git@github.com:PureStake/xcm-sdk.git
93
- npm i
94
- npm run dev
80
+ git clone git@github.com:moonbeam-foundation/xcm-sdk.git
81
+ pnpm install
82
+ pnpm run dev
83
+ ```
84
+
85
+ Optionally, you can install the `pre-commit` hook to run the linter and tests before committing:
86
+
87
+ ```bash
88
+ pnpm lefthook install
95
89
  ```
96
90
 
97
91
  # Tests
@@ -99,7 +93,7 @@ npm run dev
99
93
  ## Unit tests
100
94
 
101
95
  ```bash
102
- npm run test
96
+ pnpm run test
103
97
  ```
104
98
 
105
99
  ## Acceptance tests
@@ -108,5 +102,43 @@ npm run test
108
102
  cp .env.example .env
109
103
  # add private key and suri to .env file
110
104
 
111
- npm run test:acc
105
+ pnpm run test:acc
106
+ ```
107
+
108
+ # Release
109
+
110
+ To create a dev version go to GitHub actions and run `publish dev versions` workflow.
111
+
112
+ To create a release version run:
113
+
114
+ ```bash
115
+ pnpm run changeset
116
+ ```
117
+
118
+ # Testing the change in the SDK locally
119
+
120
+ Build the project:
121
+
122
+ ```bash
123
+ pnpm run build
124
+ ```
125
+
126
+ Link the SDK:
127
+
128
+ ```bash
129
+ pnpm run clean && pnpm run build && pnpm run link
130
+ ```
131
+
132
+ In your project where you would like to test the changes:
133
+
134
+ ```bash
135
+ pnpm link @moonbeam-network/xcm-types @moonbeam-network/xcm-utils @moonbeam-network/xcm-builder @moonbeam-network/xcm-config @moonbeam-network/xcm-sdk
136
+ ```
137
+
138
+ If you need you can link other packages too.
139
+
140
+ After testing is done, unlink the SDK:
141
+
142
+ ```bash
143
+ pnpm unlink @moonbeam-network/xcm-types @moonbeam-network/xcm-utils @moonbeam-network/xcm-builder @moonbeam-network/xcm-config @moonbeam-network/xcm-sdk
112
144
  ```
package/build/index.d.ts CHANGED
@@ -1,215 +1,194 @@
1
- import {
2
- SubstrateQueryConfig,
3
- ExtrinsicConfig,
4
- ContractConfig,
5
- } from '@moonbeam-network/xcm-builder';
6
- import {
7
- TransferConfig,
8
- FeeAssetConfig,
9
- IConfigService,
10
- } from '@moonbeam-network/xcm-config';
11
- import {
12
- AnyParachain,
13
- Asset,
14
- AssetAmount,
15
- ChainAssetId,
16
- AnyChain,
17
- Ecosystem,
18
- } from '@moonbeam-network/xcm-types';
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';
19
8
  import { ApiPromise } from '@polkadot/api';
20
- import { Signer } from '@polkadot/api/types';
21
- import { IKeyringPair } from '@polkadot/types/types';
22
- import { Signer as Signer$1 } from 'ethers';
23
- import { WalletClient } from 'viem';
9
+ import { RuntimeDispatchInfo } from '@polkadot/types/interfaces';
10
+ import { HexString } from '@polkadot/util/types';
24
11
 
25
- declare class PolkadotService {
26
- #private;
27
- readonly api: ApiPromise;
28
- readonly chain: AnyParachain;
29
- constructor(api: ApiPromise, chain: AnyParachain);
30
- static create(chain: AnyParachain): Promise<PolkadotService>;
31
- static createMulti(chains: AnyParachain[]): Promise<PolkadotService[]>;
32
- get decimals(): number;
33
- get asset(): Asset;
34
- get existentialDeposit(): AssetAmount;
35
- getAssetMeta(asset: ChainAssetId): Promise<
36
- | {
37
- symbol: string;
38
- decimals: number;
39
- }
40
- | undefined
41
- >;
42
- getAssetDecimals(asset: Asset): Promise<number>;
43
- query(config: SubstrateQueryConfig): Promise<bigint>;
44
- getFee(account: string, config: ExtrinsicConfig): Promise<bigint>;
45
- transfer(
46
- account: string,
47
- config: ExtrinsicConfig,
48
- signer: Signer | IKeyringPair,
49
- ): Promise<string>;
50
- }
51
-
52
- type EvmSigner = Signer$1 | WalletClient;
12
+ type EvmSigner = WalletClient;
53
13
  interface Signers {
54
- /**
55
- * @deprecated ethersSigner - is deprecated and will be removed in v2, use evmSigner instead
56
- */
57
- ethersSigner?: Signer$1;
58
- evmSigner?: EvmSigner;
59
- polkadotSigner: Signer | IKeyringPair;
14
+ evmSigner?: EvmSigner;
15
+ polkadotSigner?: Signer | IKeyringPair;
60
16
  }
61
17
  interface TransferData {
62
- destination: DestinationChainTransferData;
63
- getEstimate(amount: number | string): AssetAmount;
64
- isSwapPossible: boolean;
65
- max: AssetAmount;
66
- min: AssetAmount;
67
- source: SourceChainTransferData;
68
- swap(): Promise<TransferData | undefined>;
69
- transfer(amount: bigint | number | string): Promise<string>;
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>;
70
24
  }
71
25
  interface SourceChainTransferData extends ChainTransferData {
72
- destinationFeeBalance: AssetAmount;
73
- feeBalance: AssetAmount;
74
- max: AssetAmount;
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;
75
37
  }
76
- interface DestinationChainTransferData extends ChainTransferData {}
77
38
  interface ChainTransferData {
78
- balance: AssetAmount;
79
- chain: AnyChain;
80
- existentialDeposit: AssetAmount;
81
- fee: AssetAmount;
82
- min: AssetAmount;
39
+ balance: AssetAmount;
40
+ chain: AnyChain;
41
+ existentialDeposit?: AssetAmount;
42
+ fee: AssetAmount;
43
+ min: AssetAmount;
83
44
  }
84
45
 
85
46
  interface GetSourceDataParams {
86
- transferConfig: TransferConfig;
87
- destinationAddress: string;
88
- destinationFee: AssetAmount;
89
- evmSigner: EvmSigner;
90
- polkadot: PolkadotService;
91
- sourceAddress: string;
92
- }
93
- declare function getSourceData({
94
- transferConfig,
95
- destinationAddress,
96
- destinationFee,
97
- evmSigner,
98
- polkadot,
99
- sourceAddress,
100
- }: GetSourceDataParams): Promise<SourceChainTransferData>;
101
- interface GetBalancesParams {
102
- address: string;
103
- balance: bigint;
104
- feeConfig: FeeAssetConfig | undefined;
105
- polkadot: PolkadotService;
106
- }
107
- declare function getFeeBalances({
108
- address,
109
- balance,
110
- feeConfig,
111
- polkadot,
112
- }: GetBalancesParams): Promise<bigint>;
47
+ route: AssetRoute;
48
+ destinationAddress: string;
49
+ destinationFee: AssetAmount;
50
+ sourceAddress: string;
51
+ }
52
+ declare function getSourceData({ route, destinationAddress, destinationFee, sourceAddress, }: GetSourceDataParams): Promise<SourceChainTransferData>;
113
53
  interface GetFeeParams {
114
- balance: bigint;
115
- contract?: ContractConfig;
116
- decimals: number;
117
- evmSigner?: EvmSigner;
118
- extrinsic?: ExtrinsicConfig;
119
- polkadot: PolkadotService;
120
- sourceAddress: string;
121
- }
122
- declare function getFee({
123
- balance,
124
- contract,
125
- decimals,
126
- evmSigner,
127
- extrinsic,
128
- polkadot,
129
- sourceAddress,
130
- }: GetFeeParams): Promise<bigint>;
131
- declare function getContractFee(
132
- balance: bigint,
133
- config: ContractConfig,
134
- decimals: number,
135
- evmSigner: EvmSigner,
136
- ): Promise<bigint>;
137
- declare function getExtrinsicFee(
138
- balance: bigint,
139
- extrinsic: ExtrinsicConfig,
140
- polkadot: PolkadotService,
141
- sourceAddress: string,
142
- ): Promise<bigint>;
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;
143
92
  interface GetMaxParams {
144
- balanceAmount: AssetAmount;
145
- existentialDeposit: AssetAmount;
146
- feeAmount: AssetAmount;
147
- minAmount: AssetAmount;
148
- }
149
- declare function getMax({
150
- balanceAmount,
151
- existentialDeposit,
152
- feeAmount,
153
- minAmount,
154
- }: GetMaxParams): AssetAmount;
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
+ chain: EvmChain | EvmParachain;
132
+ contract: ContractConfig;
133
+ destinationFee: AssetAmount;
134
+ feeBalance: AssetAmount;
135
+ feeConfig?: FeeConfig;
136
+ }
137
+ declare function getContractFee({ address, chain, contract, destinationFee, feeBalance, feeConfig, }: GetContractFeeParams): Promise<AssetAmount>;
138
+ interface ValidateSovereignAccountBalancesProps {
139
+ amount: bigint;
140
+ destinationData: DestinationChainTransferData;
141
+ sourceData: SourceChainTransferData;
142
+ }
143
+ declare function validateSovereignAccountBalances({ amount, sourceData, destinationData, }: ValidateSovereignAccountBalancesProps): void;
155
144
 
156
- interface SdkOptions extends Partial<Signers> {
157
- configService?: IConfigService;
158
- }
159
- declare function Sdk(options?: SdkOptions): {
160
- assets(ecosystem?: Ecosystem): {
161
- assets: Asset[];
162
- asset(keyOrAsset: string | Asset): {
163
- sourceChains: AnyChain[];
164
- source(keyOrChain: string | AnyChain): {
165
- destinationChains: AnyChain[];
166
- destination(destKeyOrChain: string | AnyChain): {
167
- accounts(
168
- sourceAddress: string,
169
- destinationAddress: string,
170
- signers?: Partial<Signers>,
171
- ): Promise<TransferData>;
145
+ interface SdkOptions {
146
+ configService?: ConfigService;
147
+ ecosystem?: Ecosystem;
148
+ }
149
+ declare function Sdk({ configService, ecosystem }?: SdkOptions): {
150
+ assets: _moonbeam_network_xcm_types.Asset[];
151
+ setAsset(asset: string | AnyAsset): {
152
+ sources: AnyChain[];
153
+ setSource(source: string | AnyChain): {
154
+ destinations: AnyChain[];
155
+ setDestination(destination: string | AnyChain): {
156
+ setAddresses({ sourceAddress, destinationAddress, }: {
157
+ sourceAddress: string;
158
+ destinationAddress: string;
159
+ }): Promise<TransferData>;
160
+ };
172
161
  };
173
- };
174
162
  };
175
- };
176
- getTransferData({
177
- destinationAddress,
178
- destinationKeyOrChain,
179
- ethersSigner,
180
- evmSigner,
181
- keyOrAsset,
182
- polkadotSigner,
183
- sourceAddress,
184
- sourceKeyOrChain,
185
- }: SdkTransferParams): Promise<TransferData>;
186
163
  };
187
- interface SdkTransferParams extends Partial<Signers> {
188
- destinationAddress: string;
189
- destinationKeyOrChain: string | AnyChain;
190
- keyOrAsset: string | Asset;
191
- sourceAddress: string;
192
- sourceKeyOrChain: string | AnyChain;
164
+ declare function getParachainBalances(chain: AnyParachain, address: string, service?: ConfigService): Promise<AssetAmount[]>;
165
+
166
+ declare class PolkadotService {
167
+ #private;
168
+ readonly api: ApiPromise;
169
+ readonly chain: AnyParachain;
170
+ constructor(api: ApiPromise, chain: AnyParachain);
171
+ static create(chain: AnyParachain): Promise<PolkadotService>;
172
+ static createMulti(chains: AnyParachain[]): Promise<PolkadotService[]>;
173
+ get decimals(): number;
174
+ get existentialDeposit(): AssetAmount;
175
+ query(config: SubstrateQueryConfig): Promise<bigint>;
176
+ getExtrinsic(config: ExtrinsicConfig): SubmittableExtrinsic<'promise', ISubmittableResult>;
177
+ getExtrinsicCallHash(config: ExtrinsicConfig): HexString;
178
+ getPaymentInfo(account: string, config: ExtrinsicConfig): Promise<RuntimeDispatchInfo>;
179
+ getFee(account: string, config: ExtrinsicConfig): Promise<bigint>;
180
+ transfer(account: string, config: ExtrinsicConfig, signer: Signer | IKeyringPair, statusCallback?: (params: ISubmittableResult) => void): Promise<string>;
193
181
  }
194
182
 
195
- export {
196
- ChainTransferData,
197
- DestinationChainTransferData,
198
- EvmSigner,
199
- GetBalancesParams,
200
- GetFeeParams,
201
- GetMaxParams,
202
- GetSourceDataParams,
203
- Sdk,
204
- SdkOptions,
205
- SdkTransferParams,
206
- Signers,
207
- SourceChainTransferData,
208
- TransferData,
209
- getContractFee,
210
- getExtrinsicFee,
211
- getFee,
212
- getFeeBalances,
213
- getMax,
214
- getSourceData,
215
- };
183
+ declare class EvmService {
184
+ readonly chain: EvmChain | EvmParachain;
185
+ readonly client: PublicClient<HttpTransport>;
186
+ static create(chain: EvmChain | EvmParachain): EvmService;
187
+ constructor(chain: EvmChain | EvmParachain);
188
+ query(query: EvmQueryConfig): Promise<bigint>;
189
+ getFee(address: string, contract: ContractConfig): Promise<bigint>;
190
+ getBalance(address: string, contract: ContractConfig): Promise<bigint>;
191
+ transfer(signer: EvmSigner, contract: ContractConfig): Promise<Hash>;
192
+ }
193
+
194
+ 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 };