@moonbeam-network/xcm-sdk 2.7.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +19 -11
- package/build/index.d.mts +195 -0
- package/build/index.d.ts +168 -301
- package/build/index.mjs +767 -1
- package/build/index.mjs.map +1 -1
- package/package.json +21 -31
- package/build/index.cjs +0 -2
- package/build/index.cjs.map +0 -1
- package/build/index.d.cts +0 -177
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
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
|
@@ -66,20 +66,26 @@ const hash = await dataViaGetTransferDataMethod.transfer('INSERT_TRANSFER_AMOUNT
|
|
|
66
66
|
```bash
|
|
67
67
|
git clone git@github.com:moonbeam-foundation/xcm-sdk.git
|
|
68
68
|
cd xcm-sdk
|
|
69
|
-
|
|
69
|
+
pnpm install
|
|
70
70
|
cd examples/sdk-simple
|
|
71
71
|
|
|
72
72
|
# edit index.ts by adding your accounts
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
pnpm run start
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
# Contributing
|
|
78
78
|
|
|
79
79
|
```bash
|
|
80
80
|
git clone git@github.com:moonbeam-foundation/xcm-sdk.git
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
83
89
|
```
|
|
84
90
|
|
|
85
91
|
# Tests
|
|
@@ -87,7 +93,7 @@ npm run dev
|
|
|
87
93
|
## Unit tests
|
|
88
94
|
|
|
89
95
|
```bash
|
|
90
|
-
|
|
96
|
+
pnpm run test
|
|
91
97
|
```
|
|
92
98
|
|
|
93
99
|
## Acceptance tests
|
|
@@ -96,7 +102,7 @@ npm run test
|
|
|
96
102
|
cp .env.example .env
|
|
97
103
|
# add private key and suri to .env file
|
|
98
104
|
|
|
99
|
-
|
|
105
|
+
pnpm run test:acc
|
|
100
106
|
```
|
|
101
107
|
|
|
102
108
|
# Release
|
|
@@ -106,7 +112,7 @@ To create a dev version go to GitHub actions and run `publish dev versions` work
|
|
|
106
112
|
To create a release version run:
|
|
107
113
|
|
|
108
114
|
```bash
|
|
109
|
-
|
|
115
|
+
pnpm run changeset
|
|
110
116
|
```
|
|
111
117
|
|
|
112
118
|
# Testing the change in the SDK locally
|
|
@@ -114,17 +120,19 @@ npm run changeset
|
|
|
114
120
|
Build the project:
|
|
115
121
|
|
|
116
122
|
```bash
|
|
117
|
-
|
|
123
|
+
pnpm run build
|
|
118
124
|
```
|
|
119
125
|
|
|
126
|
+
Link the SDK:
|
|
127
|
+
|
|
120
128
|
```bash
|
|
121
|
-
|
|
129
|
+
pnpm run clean && pnpm run build && pnpm run link
|
|
122
130
|
```
|
|
123
131
|
|
|
124
132
|
In your project where you would like to test the changes:
|
|
125
133
|
|
|
126
134
|
```bash
|
|
127
|
-
|
|
135
|
+
pnpm link @moonbeam-network/xcm-types @moonbeam-network/xcm-utils @moonbeam-network/xcm-builder @moonbeam-network/xcm-config @moonbeam-network/xcm-sdk
|
|
128
136
|
```
|
|
129
137
|
|
|
130
138
|
If you need you can link other packages too.
|
|
@@ -132,5 +140,5 @@ If you need you can link other packages too.
|
|
|
132
140
|
After testing is done, unlink the SDK:
|
|
133
141
|
|
|
134
142
|
```bash
|
|
135
|
-
|
|
143
|
+
pnpm unlink @moonbeam-network/xcm-types @moonbeam-network/xcm-utils @moonbeam-network/xcm-builder @moonbeam-network/xcm-config @moonbeam-network/xcm-sdk
|
|
136
144
|
```
|
|
@@ -0,0 +1,195 @@
|
|
|
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 };
|