@chainflip/utils 0.8.0 → 0.8.1
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/dist/chainflip.cjs +60 -0
- package/dist/chainflip.d.cts +32 -1
- package/dist/chainflip.d.ts +32 -1
- package/dist/chainflip.js +7 -1
- package/dist/{chunk-SAV2D2GE.js → chunk-LY7K57IN.js} +58 -1
- package/dist/tickMath.js +1 -1
- package/package.json +1 -1
package/dist/chainflip.cjs
CHANGED
|
@@ -30,7 +30,10 @@ __export(chainflip_exports, {
|
|
|
30
30
|
chainflipChains: () => chainflipChains,
|
|
31
31
|
chainflipEvmChains: () => chainflipEvmChains,
|
|
32
32
|
chainflipNetworks: () => chainflipNetworks,
|
|
33
|
+
getInternalAsset: () => getInternalAsset,
|
|
34
|
+
getInternalAssets: () => getInternalAssets,
|
|
33
35
|
internalAssetToRpcAsset: () => internalAssetToRpcAsset,
|
|
36
|
+
isValidAssetAndChain: () => isValidAssetAndChain,
|
|
34
37
|
readAssetValue: () => readAssetValue,
|
|
35
38
|
rpcAssets: () => rpcAssets
|
|
36
39
|
});
|
|
@@ -217,6 +220,60 @@ var assetContractId = {
|
|
|
217
220
|
HubUsdt: 12,
|
|
218
221
|
HubUsdc: 13
|
|
219
222
|
};
|
|
223
|
+
function isValidAssetAndChain(assetAndChain) {
|
|
224
|
+
const { asset, chain } = assetAndChain;
|
|
225
|
+
if (!(chain in chainConstants)) return false;
|
|
226
|
+
const validAssets = chainConstants[chain].assets;
|
|
227
|
+
return validAssets.includes(asset);
|
|
228
|
+
}
|
|
229
|
+
function getInternalAsset(asset, assert = true) {
|
|
230
|
+
if (!isValidAssetAndChain(asset)) {
|
|
231
|
+
if (assert) {
|
|
232
|
+
throw new Error(`invalid asset and chain combination: ${JSON.stringify(asset)}`);
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
const map = {
|
|
237
|
+
Ethereum: {
|
|
238
|
+
USDC: "Usdc",
|
|
239
|
+
FLIP: "Flip",
|
|
240
|
+
ETH: "Eth",
|
|
241
|
+
USDT: "Usdt"
|
|
242
|
+
},
|
|
243
|
+
Bitcoin: {
|
|
244
|
+
BTC: "Btc"
|
|
245
|
+
},
|
|
246
|
+
Polkadot: {
|
|
247
|
+
DOT: "Dot"
|
|
248
|
+
},
|
|
249
|
+
Arbitrum: {
|
|
250
|
+
USDC: "ArbUsdc",
|
|
251
|
+
ETH: "ArbEth"
|
|
252
|
+
},
|
|
253
|
+
Solana: {
|
|
254
|
+
SOL: "Sol",
|
|
255
|
+
USDC: "SolUsdc"
|
|
256
|
+
},
|
|
257
|
+
Assethub: {
|
|
258
|
+
USDC: "HubUsdc",
|
|
259
|
+
USDT: "HubUsdt",
|
|
260
|
+
DOT: "HubDot"
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const chain = map[asset.chain];
|
|
264
|
+
return chain[asset.asset];
|
|
265
|
+
}
|
|
266
|
+
function getInternalAssets({
|
|
267
|
+
srcAsset,
|
|
268
|
+
srcChain,
|
|
269
|
+
destAsset,
|
|
270
|
+
destChain
|
|
271
|
+
}, assert = true) {
|
|
272
|
+
return {
|
|
273
|
+
srcAsset: getInternalAsset({ asset: srcAsset, chain: srcChain }, assert),
|
|
274
|
+
destAsset: getInternalAsset({ asset: destAsset, chain: destChain }, assert)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
220
277
|
// Annotate the CommonJS export names for ESM import in node:
|
|
221
278
|
0 && (module.exports = {
|
|
222
279
|
addressTypes,
|
|
@@ -229,7 +286,10 @@ var assetContractId = {
|
|
|
229
286
|
chainflipChains,
|
|
230
287
|
chainflipEvmChains,
|
|
231
288
|
chainflipNetworks,
|
|
289
|
+
getInternalAsset,
|
|
290
|
+
getInternalAssets,
|
|
232
291
|
internalAssetToRpcAsset,
|
|
292
|
+
isValidAssetAndChain,
|
|
233
293
|
readAssetValue,
|
|
234
294
|
rpcAssets
|
|
235
295
|
});
|
package/dist/chainflip.d.cts
CHANGED
|
@@ -144,5 +144,36 @@ declare const chainConstants: {
|
|
|
144
144
|
declare const internalAssetToRpcAsset: Record<ChainflipAsset, AssetAndChain>;
|
|
145
145
|
declare const chainContractId: Record<ChainflipChain, number>;
|
|
146
146
|
declare const assetContractId: Record<ChainflipAsset, number>;
|
|
147
|
+
declare function isValidAssetAndChain(assetAndChain: UncheckedAssetAndChain): assetAndChain is AssetAndChain;
|
|
148
|
+
declare function getInternalAsset(asset: UncheckedAssetAndChain): ChainflipAsset;
|
|
149
|
+
declare function getInternalAsset(asset: UncheckedAssetAndChain, assert: true): ChainflipAsset;
|
|
150
|
+
declare function getInternalAsset(asset: UncheckedAssetAndChain, assert: boolean): ChainflipAsset | null;
|
|
151
|
+
declare function getInternalAssets(data: {
|
|
152
|
+
srcAsset: RpcAsset;
|
|
153
|
+
srcChain: ChainflipChain;
|
|
154
|
+
destAsset: RpcAsset;
|
|
155
|
+
destChain: ChainflipChain;
|
|
156
|
+
}): {
|
|
157
|
+
srcAsset: ChainflipAsset;
|
|
158
|
+
destAsset: ChainflipAsset;
|
|
159
|
+
};
|
|
160
|
+
declare function getInternalAssets(data: {
|
|
161
|
+
srcAsset: RpcAsset;
|
|
162
|
+
srcChain: ChainflipChain;
|
|
163
|
+
destAsset: RpcAsset;
|
|
164
|
+
destChain: ChainflipChain;
|
|
165
|
+
}, assert: true): {
|
|
166
|
+
srcAsset: ChainflipAsset;
|
|
167
|
+
destAsset: ChainflipAsset;
|
|
168
|
+
};
|
|
169
|
+
declare function getInternalAssets(data: {
|
|
170
|
+
srcAsset: RpcAsset;
|
|
171
|
+
srcChain: ChainflipChain;
|
|
172
|
+
destAsset: RpcAsset;
|
|
173
|
+
destChain: ChainflipChain;
|
|
174
|
+
}, assert: boolean): {
|
|
175
|
+
srcAsset: ChainflipAsset | null;
|
|
176
|
+
destAsset: ChainflipAsset | null;
|
|
177
|
+
};
|
|
147
178
|
|
|
148
|
-
export { type AddressType, type AssetAndChain, type AssetOfChain, type BaseChainAssetMap, type BaseChainflipAsset, type ChainAssetMap, type ChainflipAsset, type ChainflipChain, type ChainflipEvmChain, type ChainflipNetwork, type UncheckedAssetAndChain, addressTypes, assetConstants, assetContractId, baseChainflipAssets, chainConstants, chainContractId, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, internalAssetToRpcAsset, readAssetValue, rpcAssets };
|
|
179
|
+
export { type AddressType, type AssetAndChain, type AssetOfChain, type BaseChainAssetMap, type BaseChainflipAsset, type ChainAssetMap, type ChainflipAsset, type ChainflipChain, type ChainflipEvmChain, type ChainflipNetwork, type UncheckedAssetAndChain, addressTypes, assetConstants, assetContractId, baseChainflipAssets, chainConstants, chainContractId, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, getInternalAsset, getInternalAssets, internalAssetToRpcAsset, isValidAssetAndChain, readAssetValue, rpcAssets };
|
package/dist/chainflip.d.ts
CHANGED
|
@@ -144,5 +144,36 @@ declare const chainConstants: {
|
|
|
144
144
|
declare const internalAssetToRpcAsset: Record<ChainflipAsset, AssetAndChain>;
|
|
145
145
|
declare const chainContractId: Record<ChainflipChain, number>;
|
|
146
146
|
declare const assetContractId: Record<ChainflipAsset, number>;
|
|
147
|
+
declare function isValidAssetAndChain(assetAndChain: UncheckedAssetAndChain): assetAndChain is AssetAndChain;
|
|
148
|
+
declare function getInternalAsset(asset: UncheckedAssetAndChain): ChainflipAsset;
|
|
149
|
+
declare function getInternalAsset(asset: UncheckedAssetAndChain, assert: true): ChainflipAsset;
|
|
150
|
+
declare function getInternalAsset(asset: UncheckedAssetAndChain, assert: boolean): ChainflipAsset | null;
|
|
151
|
+
declare function getInternalAssets(data: {
|
|
152
|
+
srcAsset: RpcAsset;
|
|
153
|
+
srcChain: ChainflipChain;
|
|
154
|
+
destAsset: RpcAsset;
|
|
155
|
+
destChain: ChainflipChain;
|
|
156
|
+
}): {
|
|
157
|
+
srcAsset: ChainflipAsset;
|
|
158
|
+
destAsset: ChainflipAsset;
|
|
159
|
+
};
|
|
160
|
+
declare function getInternalAssets(data: {
|
|
161
|
+
srcAsset: RpcAsset;
|
|
162
|
+
srcChain: ChainflipChain;
|
|
163
|
+
destAsset: RpcAsset;
|
|
164
|
+
destChain: ChainflipChain;
|
|
165
|
+
}, assert: true): {
|
|
166
|
+
srcAsset: ChainflipAsset;
|
|
167
|
+
destAsset: ChainflipAsset;
|
|
168
|
+
};
|
|
169
|
+
declare function getInternalAssets(data: {
|
|
170
|
+
srcAsset: RpcAsset;
|
|
171
|
+
srcChain: ChainflipChain;
|
|
172
|
+
destAsset: RpcAsset;
|
|
173
|
+
destChain: ChainflipChain;
|
|
174
|
+
}, assert: boolean): {
|
|
175
|
+
srcAsset: ChainflipAsset | null;
|
|
176
|
+
destAsset: ChainflipAsset | null;
|
|
177
|
+
};
|
|
147
178
|
|
|
148
|
-
export { type AddressType, type AssetAndChain, type AssetOfChain, type BaseChainAssetMap, type BaseChainflipAsset, type ChainAssetMap, type ChainflipAsset, type ChainflipChain, type ChainflipEvmChain, type ChainflipNetwork, type UncheckedAssetAndChain, addressTypes, assetConstants, assetContractId, baseChainflipAssets, chainConstants, chainContractId, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, internalAssetToRpcAsset, readAssetValue, rpcAssets };
|
|
179
|
+
export { type AddressType, type AssetAndChain, type AssetOfChain, type BaseChainAssetMap, type BaseChainflipAsset, type ChainAssetMap, type ChainflipAsset, type ChainflipChain, type ChainflipEvmChain, type ChainflipNetwork, type UncheckedAssetAndChain, addressTypes, assetConstants, assetContractId, baseChainflipAssets, chainConstants, chainContractId, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, getInternalAsset, getInternalAssets, internalAssetToRpcAsset, isValidAssetAndChain, readAssetValue, rpcAssets };
|
package/dist/chainflip.js
CHANGED
|
@@ -9,10 +9,13 @@ import {
|
|
|
9
9
|
chainflipChains,
|
|
10
10
|
chainflipEvmChains,
|
|
11
11
|
chainflipNetworks,
|
|
12
|
+
getInternalAsset,
|
|
13
|
+
getInternalAssets,
|
|
12
14
|
internalAssetToRpcAsset,
|
|
15
|
+
isValidAssetAndChain,
|
|
13
16
|
readAssetValue,
|
|
14
17
|
rpcAssets
|
|
15
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-LY7K57IN.js";
|
|
16
19
|
export {
|
|
17
20
|
addressTypes,
|
|
18
21
|
assetConstants,
|
|
@@ -24,7 +27,10 @@ export {
|
|
|
24
27
|
chainflipChains,
|
|
25
28
|
chainflipEvmChains,
|
|
26
29
|
chainflipNetworks,
|
|
30
|
+
getInternalAsset,
|
|
31
|
+
getInternalAssets,
|
|
27
32
|
internalAssetToRpcAsset,
|
|
33
|
+
isValidAssetAndChain,
|
|
28
34
|
readAssetValue,
|
|
29
35
|
rpcAssets
|
|
30
36
|
};
|
|
@@ -181,6 +181,60 @@ var assetContractId = {
|
|
|
181
181
|
HubUsdt: 12,
|
|
182
182
|
HubUsdc: 13
|
|
183
183
|
};
|
|
184
|
+
function isValidAssetAndChain(assetAndChain) {
|
|
185
|
+
const { asset, chain } = assetAndChain;
|
|
186
|
+
if (!(chain in chainConstants)) return false;
|
|
187
|
+
const validAssets = chainConstants[chain].assets;
|
|
188
|
+
return validAssets.includes(asset);
|
|
189
|
+
}
|
|
190
|
+
function getInternalAsset(asset, assert = true) {
|
|
191
|
+
if (!isValidAssetAndChain(asset)) {
|
|
192
|
+
if (assert) {
|
|
193
|
+
throw new Error(`invalid asset and chain combination: ${JSON.stringify(asset)}`);
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
const map = {
|
|
198
|
+
Ethereum: {
|
|
199
|
+
USDC: "Usdc",
|
|
200
|
+
FLIP: "Flip",
|
|
201
|
+
ETH: "Eth",
|
|
202
|
+
USDT: "Usdt"
|
|
203
|
+
},
|
|
204
|
+
Bitcoin: {
|
|
205
|
+
BTC: "Btc"
|
|
206
|
+
},
|
|
207
|
+
Polkadot: {
|
|
208
|
+
DOT: "Dot"
|
|
209
|
+
},
|
|
210
|
+
Arbitrum: {
|
|
211
|
+
USDC: "ArbUsdc",
|
|
212
|
+
ETH: "ArbEth"
|
|
213
|
+
},
|
|
214
|
+
Solana: {
|
|
215
|
+
SOL: "Sol",
|
|
216
|
+
USDC: "SolUsdc"
|
|
217
|
+
},
|
|
218
|
+
Assethub: {
|
|
219
|
+
USDC: "HubUsdc",
|
|
220
|
+
USDT: "HubUsdt",
|
|
221
|
+
DOT: "HubDot"
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const chain = map[asset.chain];
|
|
225
|
+
return chain[asset.asset];
|
|
226
|
+
}
|
|
227
|
+
function getInternalAssets({
|
|
228
|
+
srcAsset,
|
|
229
|
+
srcChain,
|
|
230
|
+
destAsset,
|
|
231
|
+
destChain
|
|
232
|
+
}, assert = true) {
|
|
233
|
+
return {
|
|
234
|
+
srcAsset: getInternalAsset({ asset: srcAsset, chain: srcChain }, assert),
|
|
235
|
+
destAsset: getInternalAsset({ asset: destAsset, chain: destChain }, assert)
|
|
236
|
+
};
|
|
237
|
+
}
|
|
184
238
|
|
|
185
239
|
export {
|
|
186
240
|
chainflipAssets,
|
|
@@ -195,5 +249,8 @@ export {
|
|
|
195
249
|
chainConstants,
|
|
196
250
|
internalAssetToRpcAsset,
|
|
197
251
|
chainContractId,
|
|
198
|
-
assetContractId
|
|
252
|
+
assetContractId,
|
|
253
|
+
isValidAssetAndChain,
|
|
254
|
+
getInternalAsset,
|
|
255
|
+
getInternalAssets
|
|
199
256
|
};
|
package/dist/tickMath.js
CHANGED