@chainflip/utils 0.8.0 → 0.8.2

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.
@@ -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
  });
@@ -144,36 +147,42 @@ var assetConstants = {
144
147
  var chainConstants = {
145
148
  Ethereum: {
146
149
  assets: ["Eth", "Flip", "Usdc", "Usdt"],
150
+ rpcAssets: ["ETH", "FLIP", "USDC", "USDT"],
147
151
  gasAsset: "Eth",
148
152
  addressType: "Eth",
149
153
  blockTimeSeconds: 12
150
154
  },
151
155
  Polkadot: {
152
156
  assets: ["Dot"],
157
+ rpcAssets: ["DOT"],
153
158
  gasAsset: "Dot",
154
159
  addressType: "Dot",
155
160
  blockTimeSeconds: 6
156
161
  },
157
162
  Bitcoin: {
158
163
  assets: ["Btc"],
164
+ rpcAssets: ["BTC"],
159
165
  gasAsset: "Btc",
160
166
  addressType: "Btc",
161
167
  blockTimeSeconds: 10 * 60
162
168
  },
163
169
  Arbitrum: {
164
170
  assets: ["ArbUsdc", "ArbEth"],
171
+ rpcAssets: ["USDC", "ETH"],
165
172
  gasAsset: "ArbEth",
166
173
  addressType: "Arb",
167
174
  blockTimeSeconds: 0.26
168
175
  },
169
176
  Solana: {
170
177
  assets: ["Sol", "SolUsdc"],
178
+ rpcAssets: ["SOL", "USDC"],
171
179
  gasAsset: "Sol",
172
180
  addressType: "Sol",
173
181
  blockTimeSeconds: 0.8
174
182
  },
175
183
  Assethub: {
176
184
  assets: ["HubDot", "HubUsdt", "HubUsdc"],
185
+ rpcAssets: ["DOT", "USDT", "USDC"],
177
186
  gasAsset: "HubDot",
178
187
  addressType: "Hub",
179
188
  blockTimeSeconds: 12
@@ -217,6 +226,60 @@ var assetContractId = {
217
226
  HubUsdt: 12,
218
227
  HubUsdc: 13
219
228
  };
229
+ function isValidAssetAndChain(assetAndChain) {
230
+ const { asset, chain } = assetAndChain;
231
+ if (!(chain in chainConstants)) return false;
232
+ const validAssets = chainConstants[chain].rpcAssets;
233
+ return validAssets.includes(asset);
234
+ }
235
+ function getInternalAsset(asset, assert = true) {
236
+ if (!isValidAssetAndChain(asset)) {
237
+ if (assert) {
238
+ throw new Error(`invalid asset and chain combination: ${JSON.stringify(asset)}`);
239
+ }
240
+ return null;
241
+ }
242
+ const map = {
243
+ Ethereum: {
244
+ USDC: "Usdc",
245
+ FLIP: "Flip",
246
+ ETH: "Eth",
247
+ USDT: "Usdt"
248
+ },
249
+ Bitcoin: {
250
+ BTC: "Btc"
251
+ },
252
+ Polkadot: {
253
+ DOT: "Dot"
254
+ },
255
+ Arbitrum: {
256
+ USDC: "ArbUsdc",
257
+ ETH: "ArbEth"
258
+ },
259
+ Solana: {
260
+ SOL: "Sol",
261
+ USDC: "SolUsdc"
262
+ },
263
+ Assethub: {
264
+ USDC: "HubUsdc",
265
+ USDT: "HubUsdt",
266
+ DOT: "HubDot"
267
+ }
268
+ };
269
+ const chain = map[asset.chain];
270
+ return chain[asset.asset];
271
+ }
272
+ function getInternalAssets({
273
+ srcAsset,
274
+ srcChain,
275
+ destAsset,
276
+ destChain
277
+ }, assert = true) {
278
+ return {
279
+ srcAsset: getInternalAsset({ asset: srcAsset, chain: srcChain }, assert),
280
+ destAsset: getInternalAsset({ asset: destAsset, chain: destChain }, assert)
281
+ };
282
+ }
220
283
  // Annotate the CommonJS export names for ESM import in node:
221
284
  0 && (module.exports = {
222
285
  addressTypes,
@@ -229,7 +292,10 @@ var assetContractId = {
229
292
  chainflipChains,
230
293
  chainflipEvmChains,
231
294
  chainflipNetworks,
295
+ getInternalAsset,
296
+ getInternalAssets,
232
297
  internalAssetToRpcAsset,
298
+ isValidAssetAndChain,
233
299
  readAssetValue,
234
300
  rpcAssets
235
301
  });
@@ -106,36 +106,42 @@ declare const assetConstants: {
106
106
  declare const chainConstants: {
107
107
  readonly Ethereum: {
108
108
  readonly assets: ["Eth", "Flip", "Usdc", "Usdt"];
109
+ readonly rpcAssets: ["ETH", "FLIP", "USDC", "USDT"];
109
110
  readonly gasAsset: "Eth";
110
111
  readonly addressType: "Eth";
111
112
  readonly blockTimeSeconds: 12;
112
113
  };
113
114
  readonly Polkadot: {
114
115
  readonly assets: ["Dot"];
116
+ readonly rpcAssets: ["DOT"];
115
117
  readonly gasAsset: "Dot";
116
118
  readonly addressType: "Dot";
117
119
  readonly blockTimeSeconds: 6;
118
120
  };
119
121
  readonly Bitcoin: {
120
122
  readonly assets: ["Btc"];
123
+ readonly rpcAssets: ["BTC"];
121
124
  readonly gasAsset: "Btc";
122
125
  readonly addressType: "Btc";
123
126
  readonly blockTimeSeconds: number;
124
127
  };
125
128
  readonly Arbitrum: {
126
129
  readonly assets: ["ArbUsdc", "ArbEth"];
130
+ readonly rpcAssets: ["USDC", "ETH"];
127
131
  readonly gasAsset: "ArbEth";
128
132
  readonly addressType: "Arb";
129
133
  readonly blockTimeSeconds: 0.26;
130
134
  };
131
135
  readonly Solana: {
132
136
  readonly assets: ["Sol", "SolUsdc"];
137
+ readonly rpcAssets: ["SOL", "USDC"];
133
138
  readonly gasAsset: "Sol";
134
139
  readonly addressType: "Sol";
135
140
  readonly blockTimeSeconds: 0.8;
136
141
  };
137
142
  readonly Assethub: {
138
143
  readonly assets: ["HubDot", "HubUsdt", "HubUsdc"];
144
+ readonly rpcAssets: ["DOT", "USDT", "USDC"];
139
145
  readonly gasAsset: "HubDot";
140
146
  readonly addressType: "Hub";
141
147
  readonly blockTimeSeconds: 12;
@@ -144,5 +150,36 @@ declare const chainConstants: {
144
150
  declare const internalAssetToRpcAsset: Record<ChainflipAsset, AssetAndChain>;
145
151
  declare const chainContractId: Record<ChainflipChain, number>;
146
152
  declare const assetContractId: Record<ChainflipAsset, number>;
153
+ declare function isValidAssetAndChain(assetAndChain: UncheckedAssetAndChain): assetAndChain is AssetAndChain;
154
+ declare function getInternalAsset(asset: UncheckedAssetAndChain): ChainflipAsset;
155
+ declare function getInternalAsset(asset: UncheckedAssetAndChain, assert: true): ChainflipAsset;
156
+ declare function getInternalAsset(asset: UncheckedAssetAndChain, assert: boolean): ChainflipAsset | null;
157
+ declare function getInternalAssets(data: {
158
+ srcAsset: RpcAsset;
159
+ srcChain: ChainflipChain;
160
+ destAsset: RpcAsset;
161
+ destChain: ChainflipChain;
162
+ }): {
163
+ srcAsset: ChainflipAsset;
164
+ destAsset: ChainflipAsset;
165
+ };
166
+ declare function getInternalAssets(data: {
167
+ srcAsset: RpcAsset;
168
+ srcChain: ChainflipChain;
169
+ destAsset: RpcAsset;
170
+ destChain: ChainflipChain;
171
+ }, assert: true): {
172
+ srcAsset: ChainflipAsset;
173
+ destAsset: ChainflipAsset;
174
+ };
175
+ declare function getInternalAssets(data: {
176
+ srcAsset: RpcAsset;
177
+ srcChain: ChainflipChain;
178
+ destAsset: RpcAsset;
179
+ destChain: ChainflipChain;
180
+ }, assert: boolean): {
181
+ srcAsset: ChainflipAsset | null;
182
+ destAsset: ChainflipAsset | null;
183
+ };
147
184
 
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 };
185
+ 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 };
@@ -106,36 +106,42 @@ declare const assetConstants: {
106
106
  declare const chainConstants: {
107
107
  readonly Ethereum: {
108
108
  readonly assets: ["Eth", "Flip", "Usdc", "Usdt"];
109
+ readonly rpcAssets: ["ETH", "FLIP", "USDC", "USDT"];
109
110
  readonly gasAsset: "Eth";
110
111
  readonly addressType: "Eth";
111
112
  readonly blockTimeSeconds: 12;
112
113
  };
113
114
  readonly Polkadot: {
114
115
  readonly assets: ["Dot"];
116
+ readonly rpcAssets: ["DOT"];
115
117
  readonly gasAsset: "Dot";
116
118
  readonly addressType: "Dot";
117
119
  readonly blockTimeSeconds: 6;
118
120
  };
119
121
  readonly Bitcoin: {
120
122
  readonly assets: ["Btc"];
123
+ readonly rpcAssets: ["BTC"];
121
124
  readonly gasAsset: "Btc";
122
125
  readonly addressType: "Btc";
123
126
  readonly blockTimeSeconds: number;
124
127
  };
125
128
  readonly Arbitrum: {
126
129
  readonly assets: ["ArbUsdc", "ArbEth"];
130
+ readonly rpcAssets: ["USDC", "ETH"];
127
131
  readonly gasAsset: "ArbEth";
128
132
  readonly addressType: "Arb";
129
133
  readonly blockTimeSeconds: 0.26;
130
134
  };
131
135
  readonly Solana: {
132
136
  readonly assets: ["Sol", "SolUsdc"];
137
+ readonly rpcAssets: ["SOL", "USDC"];
133
138
  readonly gasAsset: "Sol";
134
139
  readonly addressType: "Sol";
135
140
  readonly blockTimeSeconds: 0.8;
136
141
  };
137
142
  readonly Assethub: {
138
143
  readonly assets: ["HubDot", "HubUsdt", "HubUsdc"];
144
+ readonly rpcAssets: ["DOT", "USDT", "USDC"];
139
145
  readonly gasAsset: "HubDot";
140
146
  readonly addressType: "Hub";
141
147
  readonly blockTimeSeconds: 12;
@@ -144,5 +150,36 @@ declare const chainConstants: {
144
150
  declare const internalAssetToRpcAsset: Record<ChainflipAsset, AssetAndChain>;
145
151
  declare const chainContractId: Record<ChainflipChain, number>;
146
152
  declare const assetContractId: Record<ChainflipAsset, number>;
153
+ declare function isValidAssetAndChain(assetAndChain: UncheckedAssetAndChain): assetAndChain is AssetAndChain;
154
+ declare function getInternalAsset(asset: UncheckedAssetAndChain): ChainflipAsset;
155
+ declare function getInternalAsset(asset: UncheckedAssetAndChain, assert: true): ChainflipAsset;
156
+ declare function getInternalAsset(asset: UncheckedAssetAndChain, assert: boolean): ChainflipAsset | null;
157
+ declare function getInternalAssets(data: {
158
+ srcAsset: RpcAsset;
159
+ srcChain: ChainflipChain;
160
+ destAsset: RpcAsset;
161
+ destChain: ChainflipChain;
162
+ }): {
163
+ srcAsset: ChainflipAsset;
164
+ destAsset: ChainflipAsset;
165
+ };
166
+ declare function getInternalAssets(data: {
167
+ srcAsset: RpcAsset;
168
+ srcChain: ChainflipChain;
169
+ destAsset: RpcAsset;
170
+ destChain: ChainflipChain;
171
+ }, assert: true): {
172
+ srcAsset: ChainflipAsset;
173
+ destAsset: ChainflipAsset;
174
+ };
175
+ declare function getInternalAssets(data: {
176
+ srcAsset: RpcAsset;
177
+ srcChain: ChainflipChain;
178
+ destAsset: RpcAsset;
179
+ destChain: ChainflipChain;
180
+ }, assert: boolean): {
181
+ srcAsset: ChainflipAsset | null;
182
+ destAsset: ChainflipAsset | null;
183
+ };
147
184
 
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 };
185
+ 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-SAV2D2GE.js";
18
+ } from "./chunk-3IZHLINB.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
  };
@@ -108,36 +108,42 @@ var assetConstants = {
108
108
  var chainConstants = {
109
109
  Ethereum: {
110
110
  assets: ["Eth", "Flip", "Usdc", "Usdt"],
111
+ rpcAssets: ["ETH", "FLIP", "USDC", "USDT"],
111
112
  gasAsset: "Eth",
112
113
  addressType: "Eth",
113
114
  blockTimeSeconds: 12
114
115
  },
115
116
  Polkadot: {
116
117
  assets: ["Dot"],
118
+ rpcAssets: ["DOT"],
117
119
  gasAsset: "Dot",
118
120
  addressType: "Dot",
119
121
  blockTimeSeconds: 6
120
122
  },
121
123
  Bitcoin: {
122
124
  assets: ["Btc"],
125
+ rpcAssets: ["BTC"],
123
126
  gasAsset: "Btc",
124
127
  addressType: "Btc",
125
128
  blockTimeSeconds: 10 * 60
126
129
  },
127
130
  Arbitrum: {
128
131
  assets: ["ArbUsdc", "ArbEth"],
132
+ rpcAssets: ["USDC", "ETH"],
129
133
  gasAsset: "ArbEth",
130
134
  addressType: "Arb",
131
135
  blockTimeSeconds: 0.26
132
136
  },
133
137
  Solana: {
134
138
  assets: ["Sol", "SolUsdc"],
139
+ rpcAssets: ["SOL", "USDC"],
135
140
  gasAsset: "Sol",
136
141
  addressType: "Sol",
137
142
  blockTimeSeconds: 0.8
138
143
  },
139
144
  Assethub: {
140
145
  assets: ["HubDot", "HubUsdt", "HubUsdc"],
146
+ rpcAssets: ["DOT", "USDT", "USDC"],
141
147
  gasAsset: "HubDot",
142
148
  addressType: "Hub",
143
149
  blockTimeSeconds: 12
@@ -181,6 +187,60 @@ var assetContractId = {
181
187
  HubUsdt: 12,
182
188
  HubUsdc: 13
183
189
  };
190
+ function isValidAssetAndChain(assetAndChain) {
191
+ const { asset, chain } = assetAndChain;
192
+ if (!(chain in chainConstants)) return false;
193
+ const validAssets = chainConstants[chain].rpcAssets;
194
+ return validAssets.includes(asset);
195
+ }
196
+ function getInternalAsset(asset, assert = true) {
197
+ if (!isValidAssetAndChain(asset)) {
198
+ if (assert) {
199
+ throw new Error(`invalid asset and chain combination: ${JSON.stringify(asset)}`);
200
+ }
201
+ return null;
202
+ }
203
+ const map = {
204
+ Ethereum: {
205
+ USDC: "Usdc",
206
+ FLIP: "Flip",
207
+ ETH: "Eth",
208
+ USDT: "Usdt"
209
+ },
210
+ Bitcoin: {
211
+ BTC: "Btc"
212
+ },
213
+ Polkadot: {
214
+ DOT: "Dot"
215
+ },
216
+ Arbitrum: {
217
+ USDC: "ArbUsdc",
218
+ ETH: "ArbEth"
219
+ },
220
+ Solana: {
221
+ SOL: "Sol",
222
+ USDC: "SolUsdc"
223
+ },
224
+ Assethub: {
225
+ USDC: "HubUsdc",
226
+ USDT: "HubUsdt",
227
+ DOT: "HubDot"
228
+ }
229
+ };
230
+ const chain = map[asset.chain];
231
+ return chain[asset.asset];
232
+ }
233
+ function getInternalAssets({
234
+ srcAsset,
235
+ srcChain,
236
+ destAsset,
237
+ destChain
238
+ }, assert = true) {
239
+ return {
240
+ srcAsset: getInternalAsset({ asset: srcAsset, chain: srcChain }, assert),
241
+ destAsset: getInternalAsset({ asset: destAsset, chain: destChain }, assert)
242
+ };
243
+ }
184
244
 
185
245
  export {
186
246
  chainflipAssets,
@@ -195,5 +255,8 @@ export {
195
255
  chainConstants,
196
256
  internalAssetToRpcAsset,
197
257
  chainContractId,
198
- assetContractId
258
+ assetContractId,
259
+ isValidAssetAndChain,
260
+ getInternalAsset,
261
+ getInternalAssets
199
262
  };
package/dist/tickMath.cjs CHANGED
@@ -134,36 +134,42 @@ var assetConstants = {
134
134
  var chainConstants = {
135
135
  Ethereum: {
136
136
  assets: ["Eth", "Flip", "Usdc", "Usdt"],
137
+ rpcAssets: ["ETH", "FLIP", "USDC", "USDT"],
137
138
  gasAsset: "Eth",
138
139
  addressType: "Eth",
139
140
  blockTimeSeconds: 12
140
141
  },
141
142
  Polkadot: {
142
143
  assets: ["Dot"],
144
+ rpcAssets: ["DOT"],
143
145
  gasAsset: "Dot",
144
146
  addressType: "Dot",
145
147
  blockTimeSeconds: 6
146
148
  },
147
149
  Bitcoin: {
148
150
  assets: ["Btc"],
151
+ rpcAssets: ["BTC"],
149
152
  gasAsset: "Btc",
150
153
  addressType: "Btc",
151
154
  blockTimeSeconds: 10 * 60
152
155
  },
153
156
  Arbitrum: {
154
157
  assets: ["ArbUsdc", "ArbEth"],
158
+ rpcAssets: ["USDC", "ETH"],
155
159
  gasAsset: "ArbEth",
156
160
  addressType: "Arb",
157
161
  blockTimeSeconds: 0.26
158
162
  },
159
163
  Solana: {
160
164
  assets: ["Sol", "SolUsdc"],
165
+ rpcAssets: ["SOL", "USDC"],
161
166
  gasAsset: "Sol",
162
167
  addressType: "Sol",
163
168
  blockTimeSeconds: 0.8
164
169
  },
165
170
  Assethub: {
166
171
  assets: ["HubDot", "HubUsdt", "HubUsdc"],
172
+ rpcAssets: ["DOT", "USDT", "USDC"],
167
173
  gasAsset: "HubDot",
168
174
  addressType: "Hub",
169
175
  blockTimeSeconds: 12
package/dist/tickMath.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  assetConstants
3
- } from "./chunk-SAV2D2GE.js";
3
+ } from "./chunk-3IZHLINB.js";
4
4
 
5
5
  // src/tickMath.ts
6
6
  import { BigNumber } from "bignumber.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/utils",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",