@moonbeam-network/xcm-sdk 1.0.0-dev.30 → 1.0.0-dev.300

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/build/index.d.ts CHANGED
@@ -1,227 +1,236 @@
1
- import {
2
- SubstrateQueryConfig,
3
- ExtrinsicConfig,
4
- ContractConfig,
5
- } from '@moonbeam-network/xcm-builder';
6
- import {
7
- IConfigService,
8
- TransferConfig,
9
- FeeAssetConfig,
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 { AssetRoute, FeeConfig, ConfigService } from '@moonbeam-network/xcm-config';
2
+ import * as _moonbeam_network_xcm_types from '@moonbeam-network/xcm-types';
3
+ import { AssetAmount, AnyChain, AnyParachain, ChainAsset, EvmChain, EvmParachain, Asset, Ecosystem, AnyAsset } from '@moonbeam-network/xcm-types';
4
+ import { Signer, SubmittableExtrinsic } from '@polkadot/api/types';
5
+ import { IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
6
+ import { WalletClient, PublicClient, HttpTransport, StateOverride, Hash, Address } from 'viem';
7
+ import { ContractConfig, ExtrinsicConfig, BalanceConfigBuilder, FeeConfigBuilder, AssetMinConfigBuilder, EvmQueryConfig, SubstrateQueryConfig, EventMonitoringConfig } from '@moonbeam-network/xcm-builder';
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, EventRecord } 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
- readonly configService: IConfigService;
30
- constructor(
31
- api: ApiPromise,
32
- chain: AnyParachain,
33
- configService: IConfigService,
34
- );
35
- static create(
36
- chain: AnyParachain,
37
- configService: IConfigService,
38
- ): Promise<PolkadotService>;
39
- static createMulti(
40
- chains: AnyParachain[],
41
- configService: IConfigService,
42
- ): Promise<PolkadotService[]>;
43
- get decimals(): number;
44
- get asset(): Asset;
45
- get existentialDeposit(): AssetAmount;
46
- getAssetMeta(asset: ChainAssetId): Promise<
47
- | {
48
- symbol: string;
49
- decimals: number;
50
- }
51
- | undefined
52
- >;
53
- getAssetDecimalsFromQuery(asset: ChainAssetId): Promise<number | undefined>;
54
- getAssetDecimals(asset: Asset): Promise<number>;
55
- query(config: SubstrateQueryConfig): Promise<bigint>;
56
- getFee(account: string, config: ExtrinsicConfig): Promise<bigint>;
57
- transfer(
58
- account: string,
59
- config: ExtrinsicConfig,
60
- signer: Signer | IKeyringPair,
61
- ): Promise<string>;
62
- }
63
-
64
- type EvmSigner = Signer$1 | WalletClient;
12
+ type EvmSigner = WalletClient;
65
13
  interface Signers {
66
- /**
67
- * @deprecated ethersSigner - is deprecated and will be removed in v2, use evmSigner instead
68
- */
69
- ethersSigner?: Signer$1;
70
- evmSigner?: EvmSigner;
71
- polkadotSigner: Signer | IKeyringPair;
14
+ evmSigner?: EvmSigner;
15
+ polkadotSigner?: Signer | IKeyringPair;
72
16
  }
73
17
  interface TransferData {
74
- destination: DestinationChainTransferData;
75
- getEstimate(amount: number | string): AssetAmount;
76
- isSwapPossible: boolean;
77
- max: AssetAmount;
78
- min: AssetAmount;
79
- source: SourceChainTransferData;
80
- swap(): Promise<TransferData | undefined>;
81
- 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(params: TransferParams): Promise<string>;
24
+ }
25
+ interface TransferParams {
26
+ amount: number | string;
27
+ signers: Partial<Signers>;
28
+ statusCallback?: (status: ISubmittableResult) => void;
29
+ onSourceFinalized?: () => void;
30
+ onSourceError?: (error: Error) => void;
31
+ onDestinationFinalized?: () => void;
32
+ onDestinationError?: (error: Error) => void;
82
33
  }
83
34
  interface SourceChainTransferData extends ChainTransferData {
84
- destinationFeeBalance: AssetAmount;
85
- feeBalance: AssetAmount;
86
- max: AssetAmount;
35
+ destinationFee: AssetAmount;
36
+ destinationFeeBalance: AssetAmount;
37
+ feeBalance: AssetAmount;
38
+ max: AssetAmount;
39
+ }
40
+ interface SovereignAccountBalance {
41
+ feeAssetBalance: bigint | undefined;
42
+ transferAssetBalance: bigint;
43
+ }
44
+ interface DestinationChainTransferData extends ChainTransferData {
45
+ sovereignAccountBalances?: SovereignAccountBalance;
87
46
  }
88
- interface DestinationChainTransferData extends ChainTransferData {}
89
47
  interface ChainTransferData {
90
- balance: AssetAmount;
91
- chain: AnyChain;
92
- existentialDeposit: AssetAmount;
93
- fee: AssetAmount;
94
- min: AssetAmount;
48
+ balance: AssetAmount;
49
+ chain: AnyChain;
50
+ existentialDeposit?: AssetAmount;
51
+ fee: AssetAmount;
52
+ min: AssetAmount;
53
+ }
54
+
55
+ interface GetDestinationDataParams {
56
+ route: AssetRoute;
57
+ destinationAddress: string;
95
58
  }
59
+ declare function getDestinationData({ route, destinationAddress, }: GetDestinationDataParams): Promise<DestinationChainTransferData>;
96
60
 
97
61
  interface GetSourceDataParams {
98
- transferConfig: TransferConfig;
99
- destinationAddress: string;
100
- destinationFee: AssetAmount;
101
- evmSigner?: EvmSigner;
102
- polkadot: PolkadotService;
103
- sourceAddress: string;
104
- }
105
- declare function getSourceData({
106
- transferConfig,
107
- destinationAddress,
108
- destinationFee,
109
- evmSigner,
110
- polkadot,
111
- sourceAddress,
112
- }: GetSourceDataParams): Promise<SourceChainTransferData>;
113
- interface GetBalancesParams {
114
- address: string;
115
- balance: bigint;
116
- feeConfig: FeeAssetConfig | undefined;
117
- polkadot: PolkadotService;
118
- }
119
- declare function getFeeBalances({
120
- address,
121
- balance,
122
- feeConfig,
123
- polkadot,
124
- }: GetBalancesParams): Promise<bigint>;
62
+ route: AssetRoute;
63
+ destinationAddress: string;
64
+ destinationFee: AssetAmount;
65
+ sourceAddress: string;
66
+ }
67
+ declare function getSourceData({ route, destinationAddress, destinationFee, sourceAddress, }: GetSourceDataParams): Promise<SourceChainTransferData>;
125
68
  interface GetFeeParams {
126
- balance: bigint;
127
- contract?: ContractConfig;
128
- decimals: number;
129
- evmSigner?: EvmSigner;
130
- extrinsic?: ExtrinsicConfig;
131
- polkadot: PolkadotService;
132
- sourceAddress: string;
133
- }
134
- declare function getFee({
135
- balance,
136
- contract,
137
- decimals,
138
- evmSigner,
139
- extrinsic,
140
- polkadot,
141
- sourceAddress,
142
- }: GetFeeParams): Promise<bigint>;
143
- declare function getContractFee(
144
- balance: bigint,
145
- config: ContractConfig,
146
- decimals: number,
147
- evmSigner: EvmSigner,
148
- ): Promise<bigint>;
149
- declare function getExtrinsicFee(
150
- balance: bigint,
151
- extrinsic: ExtrinsicConfig,
152
- polkadot: PolkadotService,
153
- sourceAddress: string,
154
- ): Promise<bigint>;
69
+ balance: AssetAmount;
70
+ feeBalance: AssetAmount;
71
+ contract?: ContractConfig;
72
+ chain: AnyParachain;
73
+ destinationFee: AssetAmount;
74
+ extrinsic?: ExtrinsicConfig;
75
+ feeConfig?: FeeConfig;
76
+ sourceAddress: string;
77
+ }
78
+ declare function getFee({ balance, feeBalance, chain, contract, destinationFee, extrinsic, feeConfig, sourceAddress, }: GetFeeParams): Promise<AssetAmount>;
79
+ interface GetAssetsBalancesParams {
80
+ address: string;
81
+ chain: AnyParachain;
82
+ routes: AssetRoute[];
83
+ evmSigner?: EvmSigner;
84
+ }
85
+ declare function getAssetsBalances({ address, chain, routes, }: GetAssetsBalancesParams): Promise<AssetAmount[]>;
86
+
87
+ interface GetBalancesParams {
88
+ address: string;
89
+ asset: ChainAsset;
90
+ builder: BalanceConfigBuilder;
91
+ chain: AnyChain;
92
+ }
93
+ declare function getBalance({ address, asset, builder, chain, }: GetBalancesParams): Promise<AssetAmount>;
94
+ interface GetMinParams {
95
+ asset: Asset;
96
+ builder?: AssetMinConfigBuilder;
97
+ chain: AnyChain;
98
+ }
99
+ declare function getAssetMin({ asset, builder, chain, }: GetMinParams): Promise<AssetAmount>;
100
+ declare function getMin({ balance, existentialDeposit, fee, min, }: DestinationChainTransferData): AssetAmount;
155
101
  interface GetMaxParams {
156
- balanceAmount: AssetAmount;
157
- existentialDeposit: AssetAmount;
158
- feeAmount: AssetAmount;
159
- minAmount: AssetAmount;
160
- }
161
- declare function getMax({
162
- balanceAmount,
163
- existentialDeposit,
164
- feeAmount,
165
- minAmount,
166
- }: GetMaxParams): AssetAmount;
102
+ balance: AssetAmount;
103
+ existentialDeposit?: AssetAmount;
104
+ fee: AssetAmount;
105
+ min: AssetAmount;
106
+ }
107
+ declare function getMax({ balance, existentialDeposit, fee, min, }: GetMaxParams): AssetAmount;
108
+ interface GetDestinationFeeParams {
109
+ address: string;
110
+ asset: Asset;
111
+ feeAsset: Asset;
112
+ destination: AnyChain;
113
+ fee: number | FeeConfigBuilder;
114
+ source: AnyChain;
115
+ }
116
+ declare function getDestinationFee({ address, asset, destination, fee, feeAsset, source, }: GetDestinationFeeParams): Promise<AssetAmount>;
117
+ interface ConvertToChainDecimalsParams {
118
+ asset: AssetAmount;
119
+ target: ChainAsset;
120
+ }
121
+ declare function convertToChainDecimals({ asset, target, }: ConvertToChainDecimalsParams): AssetAmount;
122
+ declare function getExistentialDeposit(chain: AnyChain): Promise<AssetAmount | undefined>;
123
+ interface GetDestinationFeeBalanceParams {
124
+ balance: AssetAmount;
125
+ feeBalance: AssetAmount;
126
+ route: AssetRoute;
127
+ sourceAddress: string;
128
+ }
129
+ declare function getDestinationFeeBalance({ balance, feeBalance, route, sourceAddress, }: GetDestinationFeeBalanceParams): Promise<AssetAmount>;
130
+ interface GetExtrinsicFeeParams {
131
+ address: string;
132
+ balance: AssetAmount;
133
+ chain: AnyParachain;
134
+ extrinsic: ExtrinsicConfig;
135
+ feeBalance: AssetAmount;
136
+ feeConfig?: FeeConfig;
137
+ }
138
+ declare function getExtrinsicFee({ address, balance, chain, extrinsic, feeBalance, feeConfig, }: GetExtrinsicFeeParams): Promise<AssetAmount>;
139
+ interface GetContractFeeParams {
140
+ address: string;
141
+ balance: AssetAmount;
142
+ chain: EvmChain | EvmParachain;
143
+ contract: ContractConfig;
144
+ destinationFee: AssetAmount;
145
+ feeBalance: AssetAmount;
146
+ feeConfig?: FeeConfig;
147
+ }
148
+ declare function getContractFee({ address, balance, chain, contract, destinationFee, feeBalance, feeConfig, }: GetContractFeeParams): Promise<AssetAmount>;
149
+ interface ValidateSovereignAccountBalancesProps {
150
+ amount: bigint;
151
+ destinationData: DestinationChainTransferData;
152
+ sourceData: SourceChainTransferData;
153
+ }
154
+ declare function validateSovereignAccountBalances({ amount, sourceData, destinationData, }: ValidateSovereignAccountBalancesProps): void;
167
155
 
168
- interface SdkOptions extends Partial<Signers> {
169
- configService?: IConfigService;
170
- }
171
- declare function Sdk(options?: SdkOptions): {
172
- assets(ecosystem?: Ecosystem): {
173
- assets: Asset[];
174
- asset(keyOrAsset: string | Asset): {
175
- sourceChains: AnyChain[];
176
- source(keyOrChain: string | AnyChain): {
177
- destinationChains: AnyChain[];
178
- destination(destKeyOrChain: string | AnyChain): {
179
- accounts(
180
- sourceAddress: string,
181
- destinationAddress: string,
182
- signers?: Partial<Signers>,
183
- ): Promise<TransferData>;
156
+ interface SdkOptions {
157
+ configService?: ConfigService;
158
+ ecosystem?: Ecosystem;
159
+ }
160
+ declare function Sdk({ configService, ecosystem }?: SdkOptions): {
161
+ assets: _moonbeam_network_xcm_types.Asset[];
162
+ setAsset(asset: string | AnyAsset): {
163
+ sources: AnyChain[];
164
+ setSource(source: string | AnyChain): {
165
+ destinations: AnyChain[];
166
+ setDestination(destination: string | AnyChain): {
167
+ setAddresses({ sourceAddress, destinationAddress, }: {
168
+ sourceAddress: string;
169
+ destinationAddress: string;
170
+ }): Promise<TransferData>;
171
+ };
184
172
  };
185
- };
186
173
  };
187
- };
188
- getTransferData({
189
- destinationAddress,
190
- destinationKeyOrChain,
191
- ethersSigner,
192
- evmSigner,
193
- keyOrAsset,
194
- polkadotSigner,
195
- sourceAddress,
196
- sourceKeyOrChain,
197
- }: SdkTransferParams): Promise<TransferData>;
198
174
  };
199
- interface SdkTransferParams extends Partial<Signers> {
200
- destinationAddress: string;
201
- destinationKeyOrChain: string | AnyChain;
202
- keyOrAsset: string | Asset;
203
- sourceAddress: string;
204
- sourceKeyOrChain: string | AnyChain;
175
+ declare function getParachainBalances(chain: AnyParachain, address: string, service?: ConfigService): Promise<AssetAmount[]>;
176
+
177
+ declare class EvmService {
178
+ readonly chain: EvmChain | EvmParachain;
179
+ readonly client: PublicClient<HttpTransport>;
180
+ static create(chain: EvmChain | EvmParachain): EvmService;
181
+ constructor(chain: EvmChain | EvmParachain);
182
+ query(query: EvmQueryConfig): Promise<bigint>;
183
+ read(config: ContractConfig): Promise<unknown>;
184
+ getFee(address: string, contract: ContractConfig, stateOverride?: StateOverride): Promise<bigint>;
185
+ getBalance(address: string, contract: ContractConfig): Promise<bigint>;
186
+ transfer(signer: EvmSigner, contract: ContractConfig): Promise<Hash>;
205
187
  }
206
188
 
207
- export {
208
- ChainTransferData,
209
- DestinationChainTransferData,
210
- EvmSigner,
211
- GetBalancesParams,
212
- GetFeeParams,
213
- GetMaxParams,
214
- GetSourceDataParams,
215
- Sdk,
216
- SdkOptions,
217
- SdkTransferParams,
218
- Signers,
219
- SourceChainTransferData,
220
- TransferData,
221
- getContractFee,
222
- getExtrinsicFee,
223
- getFee,
224
- getFeeBalances,
225
- getMax,
226
- getSourceData,
227
- };
189
+ declare class PolkadotService {
190
+ #private;
191
+ readonly api: ApiPromise;
192
+ readonly chain: AnyParachain;
193
+ constructor(api: ApiPromise, chain: AnyParachain);
194
+ static create(chain: AnyParachain): Promise<PolkadotService>;
195
+ static createMulti(chains: AnyParachain[]): Promise<PolkadotService[]>;
196
+ get decimals(): number;
197
+ get existentialDeposit(): AssetAmount;
198
+ query(config: SubstrateQueryConfig): Promise<bigint>;
199
+ getExtrinsic(config: ExtrinsicConfig): SubmittableExtrinsic<'promise', ISubmittableResult>;
200
+ getExtrinsicCallHash(config: ExtrinsicConfig): HexString;
201
+ getPaymentInfo(account: string, config: ExtrinsicConfig): Promise<RuntimeDispatchInfo>;
202
+ getFee(account: string, config: ExtrinsicConfig): Promise<bigint>;
203
+ transfer(account: string, config: ExtrinsicConfig, signer: Signer | IKeyringPair, statusCallback?: (params: ISubmittableResult) => void): Promise<string>;
204
+ }
205
+
206
+ declare function getAllowanceSlot(owner: string, spender: string, allowanceSlot: number): Address;
207
+ declare const MAX_ALLOWANCE_HEX: `0x${string}`;
208
+
209
+ interface ListenToDestinationEventsProps {
210
+ route: AssetRoute;
211
+ monitoringConfig: EventMonitoringConfig;
212
+ messageId?: string;
213
+ onDestinationFinalized?: () => void;
214
+ onDestinationError?: (error: Error) => void;
215
+ }
216
+ declare function listenToDestinationEvents({ route, monitoringConfig, messageId, onDestinationFinalized, onDestinationError, }: ListenToDestinationEventsProps): Promise<void>;
217
+ interface CreateMonitoringCallbackProps {
218
+ sourceAddress: string;
219
+ route: AssetRoute;
220
+ statusCallback?: (status: ISubmittableResult) => void;
221
+ onSourceFinalized?: () => void;
222
+ onSourceError?: (error: Error) => void;
223
+ onDestinationFinalized?: () => void;
224
+ onDestinationError?: (error: Error) => void;
225
+ }
226
+ interface ListenToSourceEventsProps extends CreateMonitoringCallbackProps {
227
+ }
228
+ interface ProcessSourceEventsProps extends ListenToSourceEventsProps {
229
+ events: EventRecord[];
230
+ unsubscribe?: () => void;
231
+ }
232
+ declare function processSourceEvents({ events, sourceAddress, route, onSourceFinalized, onSourceError, onDestinationFinalized, onDestinationError, unsubscribe, }: ProcessSourceEventsProps): void;
233
+ declare function createMonitoringCallback({ sourceAddress, route, statusCallback, onSourceFinalized, onSourceError, onDestinationFinalized, onDestinationError, }: CreateMonitoringCallbackProps): (status: ISubmittableResult) => void;
234
+ declare function listenToSourceEvents({ route, sourceAddress, onSourceFinalized, onSourceError, onDestinationFinalized, onDestinationError, }: ListenToSourceEventsProps): Promise<void>;
235
+
236
+ 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, MAX_ALLOWANCE_HEX, PolkadotService, Sdk, type SdkOptions, type Signers, type SourceChainTransferData, type SovereignAccountBalance, type TransferData, type TransferParams, convertToChainDecimals, createMonitoringCallback, getAllowanceSlot, getAssetMin, getAssetsBalances, getBalance, getContractFee, getDestinationData, getDestinationFee, getDestinationFeeBalance, getExistentialDeposit, getExtrinsicFee, getFee, getMax, getMin, getParachainBalances, getSourceData, listenToDestinationEvents, listenToSourceEvents, processSourceEvents, validateSovereignAccountBalances };