@moonbeam-network/xcm-sdk 1.0.0-dev.3 → 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,200 +1,236 @@
1
- import {
2
- SubstrateQueryConfig,
3
- ExtrinsicConfig,
4
- ContractConfig,
5
- } from '@moonbeam-network/xcm-builder';
6
- import { TransferConfig, AssetConfig } from '@moonbeam-network/xcm-config';
7
- import {
8
- AnyParachain,
9
- Asset,
10
- AssetAmount,
11
- ChainAssetId,
12
- AnyChain,
13
- Ecosystem,
14
- } from '@moonbeam-network/xcm-types';
15
- import { Signer as Signer$1 } from 'ethers';
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';
16
8
  import { ApiPromise } from '@polkadot/api';
17
- import { Signer } from '@polkadot/api/types';
18
- import { IKeyringPair } from '@polkadot/types/types';
19
-
20
- declare class PolkadotService {
21
- #private;
22
- readonly api: ApiPromise;
23
- readonly chain: AnyParachain;
24
- constructor(api: ApiPromise, chain: AnyParachain);
25
- static create(chain: AnyParachain): Promise<PolkadotService>;
26
- static createMulti(chains: AnyParachain[]): Promise<PolkadotService[]>;
27
- get decimals(): number;
28
- get asset(): Asset;
29
- get existentialDeposit(): AssetAmount;
30
- getAssetMeta(asset: ChainAssetId): Promise<
31
- | {
32
- symbol: string;
33
- decimals: number;
34
- }
35
- | undefined
36
- >;
37
- getAssetDecimals(asset: Asset): Promise<number>;
38
- query(config: SubstrateQueryConfig): Promise<bigint>;
39
- getFee(account: string, config: ExtrinsicConfig): Promise<bigint>;
40
- transfer(
41
- account: string,
42
- config: ExtrinsicConfig,
43
- signer: Signer | IKeyringPair,
44
- ): Promise<string>;
45
- }
9
+ import { RuntimeDispatchInfo, EventRecord } from '@polkadot/types/interfaces';
10
+ import { HexString } from '@polkadot/util/types';
46
11
 
12
+ type EvmSigner = WalletClient;
47
13
  interface Signers {
48
- ethersSigner: Signer$1;
49
- polkadotSigner: Signer | IKeyringPair;
14
+ evmSigner?: EvmSigner;
15
+ polkadotSigner?: Signer | IKeyringPair;
50
16
  }
51
17
  interface TransferData {
52
- destination: DestinationChainTransferData;
53
- getEstimate(amount: number | string): AssetAmount;
54
- isSwapPossible: boolean;
55
- max: AssetAmount;
56
- min: AssetAmount;
57
- source: SourceChainTransferData;
58
- swap(): Promise<TransferData | undefined>;
59
- 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;
60
33
  }
61
34
  interface SourceChainTransferData extends ChainTransferData {
62
- feeBalance: AssetAmount;
63
- 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;
64
46
  }
65
- interface DestinationChainTransferData extends ChainTransferData {}
66
47
  interface ChainTransferData {
67
- balance: AssetAmount;
68
- chain: AnyChain;
69
- existentialDeposit: AssetAmount;
70
- fee: AssetAmount;
71
- 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;
72
58
  }
59
+ declare function getDestinationData({ route, destinationAddress, }: GetDestinationDataParams): Promise<DestinationChainTransferData>;
73
60
 
74
61
  interface GetSourceDataParams {
75
- transferConfig: TransferConfig;
76
- destinationAddress: string;
77
- destinationFee: AssetAmount;
78
- ethersSigner: Signer$1;
79
- polkadot: PolkadotService;
80
- sourceAddress: string;
81
- }
82
- declare function getSourceData({
83
- transferConfig,
84
- destinationAddress,
85
- destinationFee,
86
- ethersSigner,
87
- polkadot,
88
- sourceAddress,
89
- }: GetSourceDataParams): Promise<SourceChainTransferData>;
90
- interface GetBalancesParams {
91
- address: string;
92
- balance: bigint;
93
- config: AssetConfig;
94
- polkadot: PolkadotService;
95
- }
96
- declare function getFeeBalances({
97
- address,
98
- balance,
99
- config,
100
- polkadot,
101
- }: 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>;
102
68
  interface GetFeeParams {
103
- balance: bigint;
104
- contract?: ContractConfig;
105
- decimals: number;
106
- ethersSigner?: Signer$1;
107
- extrinsic?: ExtrinsicConfig;
108
- polkadot: PolkadotService;
109
- sourceAddress: string;
110
- }
111
- declare function getFee({
112
- balance,
113
- contract,
114
- decimals,
115
- ethersSigner,
116
- extrinsic,
117
- polkadot,
118
- sourceAddress,
119
- }: GetFeeParams): Promise<bigint>;
120
- declare function getContractFee(
121
- balance: bigint,
122
- config: ContractConfig,
123
- decimals: number,
124
- ethersSigner: Signer$1,
125
- ): Promise<bigint>;
126
- declare function getExtrinsicFee(
127
- balance: bigint,
128
- extrinsic: ExtrinsicConfig,
129
- polkadot: PolkadotService,
130
- sourceAddress: string,
131
- ): 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;
132
101
  interface GetMaxParams {
133
- balanceAmount: AssetAmount;
134
- existentialDeposit: AssetAmount;
135
- feeAmount: AssetAmount;
136
- minAmount: AssetAmount;
137
- }
138
- declare function getMax({
139
- balanceAmount,
140
- existentialDeposit,
141
- feeAmount,
142
- minAmount,
143
- }: 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;
144
155
 
145
- interface SdkOptions extends Partial<Signers> {}
146
- declare function Sdk(options?: SdkOptions): {
147
- assets(ecosystem?: Ecosystem): {
148
- assets: Asset[];
149
- asset(keyOrAsset: string | Asset): {
150
- sourceChains: AnyChain[];
151
- source(keyOrChain: string | AnyChain): {
152
- destinationChains: AnyChain[];
153
- destination(destKeyOrChain: string | AnyChain): {
154
- accounts(
155
- sourceAddress: string,
156
- destinationAddress: string,
157
- signers?: Partial<Signers>,
158
- ): 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
+ };
159
172
  };
160
- };
161
173
  };
162
- };
163
- getTransferData({
164
- destinationAddress,
165
- destinationKeyOrChain,
166
- ethersSigner,
167
- keyOrAsset,
168
- polkadotSigner,
169
- sourceAddress,
170
- sourceKeyOrChain,
171
- }: SdkTransferParams): Promise<TransferData>;
172
174
  };
173
- interface SdkTransferParams extends Partial<Signers> {
174
- destinationAddress: string;
175
- destinationKeyOrChain: string | AnyChain;
176
- keyOrAsset: string | Asset;
177
- sourceAddress: string;
178
- 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>;
179
187
  }
180
188
 
181
- export {
182
- ChainTransferData,
183
- DestinationChainTransferData,
184
- GetBalancesParams,
185
- GetFeeParams,
186
- GetMaxParams,
187
- GetSourceDataParams,
188
- Sdk,
189
- SdkOptions,
190
- SdkTransferParams,
191
- Signers,
192
- SourceChainTransferData,
193
- TransferData,
194
- getContractFee,
195
- getExtrinsicFee,
196
- getFee,
197
- getFeeBalances,
198
- getMax,
199
- getSourceData,
200
- };
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 };