@paraspell/assets 8.9.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.
@@ -0,0 +1,262 @@
1
+ import { TRelayChainSymbol, TMultiLocation, TNodeWithRelayChains } from '@paraspell/sdk-common';
2
+
3
+ type AtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
4
+ [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
5
+ }[Keys];
6
+ type TBaseAsset = {
7
+ symbol: string;
8
+ decimals?: number;
9
+ manuallyAdded?: boolean;
10
+ alias?: string;
11
+ existentialDeposit?: string;
12
+ };
13
+ type TNativeAsset = TBaseAsset & {
14
+ isNative: true;
15
+ multiLocation?: TMultiLocation;
16
+ };
17
+ type TForeignAsset = TBaseAsset & AtLeastOne<{
18
+ assetId?: string;
19
+ multiLocation?: TMultiLocation;
20
+ }>;
21
+ type TAsset = TNativeAsset | TForeignAsset;
22
+ type TNodeAssets = {
23
+ relayChainAssetSymbol: TRelayChainSymbol;
24
+ nativeAssetSymbol: string;
25
+ isEVM: boolean;
26
+ supportsDryRunApi: boolean;
27
+ nativeAssets: TNativeAsset[];
28
+ otherAssets: TForeignAsset[];
29
+ };
30
+ type TAssetJsonMap = Record<TNodeWithRelayChains, TNodeAssets>;
31
+
32
+ type TMultiAsset = TMultiAssetV3 | TMultiAssetV4;
33
+ interface TMultiAssetV3 {
34
+ id: {
35
+ Concrete: TMultiLocation;
36
+ };
37
+ fun: {
38
+ Fungible: TAmount;
39
+ };
40
+ }
41
+ interface TMultiAssetV4 {
42
+ id: TMultiLocation;
43
+ fun: {
44
+ Fungible: TAmount;
45
+ };
46
+ }
47
+
48
+ type TAmount = string | number | bigint;
49
+ type TCurrency = string | number | bigint;
50
+ type TSymbolSpecifier = {
51
+ type: 'Native' | 'Foreign' | 'ForeignAbstract';
52
+ value: string;
53
+ };
54
+ type TOverrideMultiLocationSpecifier = {
55
+ type: 'Override';
56
+ value: TMultiLocation;
57
+ };
58
+ type TCurrencySymbolValue = string | TSymbolSpecifier;
59
+ type TCurrencySymbol = {
60
+ symbol: TCurrencySymbolValue;
61
+ };
62
+ type TCurrencyCore = TCurrencySymbol | {
63
+ id: TCurrency;
64
+ } | {
65
+ multilocation: TMultiLocationValue;
66
+ };
67
+ type TMultiAssetWithFee = TMultiAsset & {
68
+ isFeeAsset?: boolean;
69
+ };
70
+ type TMultiLocationValue = string | TMultiLocation;
71
+ type TMultiLocationValueWithOverride = TMultiLocationValue | TOverrideMultiLocationSpecifier;
72
+ type TCurrencyInputWithAmount = WithAmount<TCurrencySymbol | {
73
+ id: TCurrency;
74
+ } | {
75
+ multilocation: TMultiLocationValueWithOverride;
76
+ }> | {
77
+ multiasset: TMultiAsset[] | WithAmount<TCurrencyCore>[];
78
+ };
79
+ type TCurrencyInput = TCurrencySymbol | {
80
+ id: TCurrency;
81
+ } | {
82
+ multilocation: TMultiLocationValueWithOverride;
83
+ } | {
84
+ multiasset: TMultiAsset[] | WithAmount<TCurrencyCore>[];
85
+ };
86
+ type WithAmount<TBase> = TBase & {
87
+ amount: TAmount;
88
+ };
89
+
90
+ /**
91
+ * Retrieves the existential deposit value for a given node.
92
+ *
93
+ * @param node - The node for which to get the existential deposit.
94
+ * @returns The existential deposit as a string if available; otherwise, null.
95
+ */
96
+ declare const getExistentialDeposit: (node: TNodeWithRelayChains, currency?: TCurrencyCore) => string | null;
97
+
98
+ /**
99
+ * Retrieves the assets object for a given node containing the native and foreign assets.
100
+ *
101
+ * @param node - The node for which to retrieve the assets object.
102
+ * @returns The assets object associated with the given node.
103
+ */
104
+ declare const getAssetsObject: (node: TNodeWithRelayChains) => TNodeAssets;
105
+ declare const isNodeEvm: (node: TNodeWithRelayChains) => boolean;
106
+ /**
107
+ * Retrieves the asset ID for a given symbol on a specified node.
108
+ *
109
+ * @param node - The node to search for the asset.
110
+ * @param symbol - The symbol of the asset.
111
+ * @returns The asset ID if found; otherwise, null.
112
+ */
113
+ declare const getAssetId: (node: TNodeWithRelayChains, symbol: string) => string | null;
114
+ /**
115
+ * Retrieves the relay chain asset symbol for a specified node.
116
+ *
117
+ * @param node - The node for which to get the relay chain symbol.
118
+ * @returns The relay chain asset symbol.
119
+ */
120
+ declare const getRelayChainSymbol: (node: TNodeWithRelayChains) => TRelayChainSymbol;
121
+ /**
122
+ * Retrieves the list of native assets for a specified node.
123
+ *
124
+ * @param node - The node for which to get native assets.
125
+ * @returns An array of native asset details.
126
+ */
127
+ declare const getNativeAssets: (node: TNodeWithRelayChains) => TNativeAsset[];
128
+ /**
129
+ * Retrieves the list of other (non-native) assets for a specified node.
130
+ *
131
+ * @param node - The node for which to get other assets.
132
+ * @returns An array of other asset details.
133
+ */
134
+ declare const getOtherAssets: (node: TNodeWithRelayChains) => TForeignAsset[];
135
+ /**
136
+ * Retrieves the complete list of assets for a specified node, including relay chain asset, native, and other assets.
137
+ *
138
+ * @param node - The node for which to get the assets.
139
+ * @returns An array of objects of all assets associated with the node.
140
+ */
141
+ declare const getAssets: (node: TNodeWithRelayChains) => TAsset[];
142
+ /**
143
+ * Retrieves the symbols of all assets (relay chain, native, and other assets) for a specified node.
144
+ *
145
+ * @param node - The node for which to get asset symbols.
146
+ * @returns An array of asset symbols.
147
+ */
148
+ declare const getAllAssetsSymbols: (node: TNodeWithRelayChains) => string[];
149
+ /**
150
+ * Retrieves the symbol of the native asset for a specified node.
151
+ *
152
+ * @param node - The node for which to get the native asset symbol.
153
+ * @returns The symbol of the native asset.
154
+ */
155
+ declare const getNativeAssetSymbol: (node: TNodeWithRelayChains) => string;
156
+ /**
157
+ * Determines whether a specified node supports an asset with the given symbol.
158
+ *
159
+ * @param node - The node to check for asset support.
160
+ * @param symbol - The symbol of the asset to check.
161
+ * @returns True if the asset is supported; otherwise, false.
162
+ */
163
+ declare const hasSupportForAsset: (node: TNodeWithRelayChains, symbol: string) => boolean;
164
+ /**
165
+ * Retrieves the number of decimals for an asset with the given symbol on a specified node.
166
+ *
167
+ * @param node - The node where the asset is located.
168
+ * @param symbol - The symbol of the asset.
169
+ * @returns The number of decimals if the asset is found; otherwise, null.
170
+ */
171
+ declare const getAssetDecimals: (node: TNodeWithRelayChains, symbol: string) => number | null;
172
+ declare const hasDryRunSupport: (node: TNodeWithRelayChains) => boolean;
173
+
174
+ declare const Native: (symbol: string) => TSymbolSpecifier;
175
+ declare const Foreign: (symbol: string) => TSymbolSpecifier;
176
+ declare const ForeignAbstract: (symbol: string) => TSymbolSpecifier;
177
+ declare const Override: (multiLocation: TMultiLocation) => TOverrideMultiLocationSpecifier;
178
+
179
+ declare const filterEthCompatibleAssets: (assets: TForeignAsset[]) => TForeignAsset[];
180
+
181
+ /**
182
+ * Normalizes an asset symbol by stripping the 'xc' prefix (if present) and converting it to lowercase.
183
+ *
184
+ * @param symbol - The symbol to normalize.
185
+ * @returns The normalized symbol.
186
+ */
187
+ declare const normalizeSymbol: (symbol: string | undefined) => string;
188
+ /**
189
+ * Retrieves the list of assets that are supported for transfers between two specified nodes.
190
+ *
191
+ * @param origin - The origin node.
192
+ * @param destination - The destination node.
193
+ * @returns An array of assets supported between the origin and destination nodes.
194
+ */
195
+ declare const getSupportedAssets: (origin: TNodeWithRelayChains, destination: TNodeWithRelayChains) => TAsset[];
196
+
197
+ declare const isAssetEqual: (asset1: TAsset, asset2: TAsset) => boolean;
198
+
199
+ declare const findAsset: (node: TNodeWithRelayChains, currency: TCurrencyInput, destination: TNodeWithRelayChains | null) => TAsset | null;
200
+
201
+ declare const findAssetById: (assets: TForeignAsset[], assetId: TCurrency) => TForeignAsset | undefined;
202
+
203
+ declare const findAssetByMultiLocation: (foreignAssets: TForeignAsset[], multiLocation: string | TMultiLocation) => TForeignAsset | undefined;
204
+
205
+ declare const findAssetBySymbol: (node: TNodeWithRelayChains, destination: TNodeWithRelayChains | null, otherAssets: TForeignAsset[], nativeAssets: TNativeAsset[], symbol: TCurrencySymbolValue) => TAsset | undefined;
206
+
207
+ declare const findBestMatches: <T extends {
208
+ symbol: string;
209
+ alias?: string;
210
+ }>(assets: T[], value: string, property?: "symbol" | "alias") => T[];
211
+
212
+ /**
213
+ * Error thrown when multiple assets with the same symbol are found.
214
+ */
215
+ declare class DuplicateAssetError extends Error {
216
+ /**
217
+ * Constructs a new DuplicateAssetError.
218
+ *
219
+ * @param symbol - The symbol of the asset causing the duplication error.
220
+ */
221
+ constructor(msg: string);
222
+ }
223
+
224
+ /**
225
+ * Error thrown when multiple assets with the same symbol are found.
226
+ */
227
+ declare class DuplicateAssetIdError extends Error {
228
+ /**
229
+ * Constructs a new DuplicateAssetError.
230
+ *
231
+ * @param symbol - The symbol of the asset causing the duplication error.
232
+ */
233
+ constructor(id: string);
234
+ }
235
+
236
+ /**
237
+ * Used to inform user, that currency they wish to use is not registered on either origin or destination Parachain
238
+ */
239
+ declare class InvalidCurrencyError extends Error {
240
+ /**
241
+ * Constructs a new InvalidCurrencyError.
242
+ *
243
+ * @param message - The error message.
244
+ */
245
+ constructor(message: string);
246
+ }
247
+
248
+ declare const isForeignAsset: (asset: TAsset) => asset is TForeignAsset;
249
+
250
+ declare const isOverrideMultiLocationSpecifier: (multiLocationSpecifier: TMultiLocationValueWithOverride) => multiLocationSpecifier is TOverrideMultiLocationSpecifier;
251
+
252
+ declare const isSymbolSpecifier: (currencySymbolValue: TCurrencySymbolValue) => currencySymbolValue is TSymbolSpecifier;
253
+
254
+ declare const isTMultiAsset: (value: unknown) => value is TMultiAsset;
255
+
256
+ declare const compareMultiLocations: (input: string, asset: TForeignAsset) => boolean;
257
+
258
+ declare const extractMultiAssetLoc: (multiAsset: TMultiAsset) => TMultiLocation;
259
+
260
+ declare const getAssetMultiLocation: (node: TNodeWithRelayChains, currency: TCurrencyInput) => TMultiLocation | null;
261
+
262
+ export { DuplicateAssetError, DuplicateAssetIdError, Foreign, ForeignAbstract, InvalidCurrencyError, Native, Override, type TAmount, type TAsset, type TAssetJsonMap, type TCurrency, type TCurrencyCore, type TCurrencyInput, type TCurrencyInputWithAmount, type TCurrencySymbol, type TCurrencySymbolValue, type TForeignAsset, type TMultiAsset, type TMultiAssetV3, type TMultiAssetV4, type TMultiAssetWithFee, type TMultiLocationValue, type TMultiLocationValueWithOverride, type TNativeAsset, type TNodeAssets, type TOverrideMultiLocationSpecifier, type TSymbolSpecifier, type WithAmount, compareMultiLocations, extractMultiAssetLoc, filterEthCompatibleAssets, findAsset, findAssetById, findAssetByMultiLocation, findAssetBySymbol, findBestMatches, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssetMultiLocation, getAssets, getAssetsObject, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, hasDryRunSupport, hasSupportForAsset, isAssetEqual, isForeignAsset, isNodeEvm, isOverrideMultiLocationSpecifier, isSymbolSpecifier, isTMultiAsset, normalizeSymbol };