@chainflip/utils 2.1.8 → 2.2.0-alpha.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/async.cjs CHANGED
@@ -29,6 +29,7 @@ const sleep = (ms, { signal } = {}) => {
29
29
  return deferred.promise;
30
30
  };
31
31
  var Queue = class {
32
+ debounce;
32
33
  promise = Promise.resolve();
33
34
  constructor(debounce) {
34
35
  this.debounce = debounce;
package/dist/async.mjs CHANGED
@@ -27,6 +27,7 @@ const sleep = (ms, { signal } = {}) => {
27
27
  return deferred.promise;
28
28
  };
29
29
  var Queue = class {
30
+ debounce;
30
31
  promise = Promise.resolve();
31
32
  constructor(debounce) {
32
33
  this.debounce = debounce;
@@ -15,6 +15,8 @@ const chainflipAssets = [
15
15
  "Sol",
16
16
  "SolUsdc",
17
17
  "SolUsdt",
18
+ "Trx",
19
+ "TrxUsdt",
18
20
  "HubDot",
19
21
  "HubUsdt",
20
22
  "HubUsdc"
@@ -30,7 +32,11 @@ const priceAssets = [
30
32
  "Fine"
31
33
  ];
32
34
  const baseChainflipAssets = chainflipAssets.filter((asset) => asset !== "Usdc");
33
- const chainflipEvmChains = ["Ethereum", "Arbitrum"];
35
+ const chainflipEvmChains = [
36
+ "Ethereum",
37
+ "Arbitrum",
38
+ "Tron"
39
+ ];
34
40
  const chainflipChains = [
35
41
  ...chainflipEvmChains,
36
42
  "Bitcoin",
@@ -49,7 +55,8 @@ const addressTypes = [
49
55
  "Btc",
50
56
  "Arb",
51
57
  "Sol",
52
- "Hub"
58
+ "Hub",
59
+ "Tron"
53
60
  ];
54
61
  const legacyAddressTypes = ["Dot"];
55
62
  function readAssetValue(map, asset) {
@@ -130,6 +137,16 @@ const assetConstants = {
130
137
  chain: "Assethub",
131
138
  symbol: "USDT",
132
139
  decimals: 6
140
+ },
141
+ Trx: {
142
+ chain: "Tron",
143
+ symbol: "TRX",
144
+ decimals: 6
145
+ },
146
+ TrxUsdt: {
147
+ chain: "Tron",
148
+ symbol: "USDT",
149
+ decimals: 6
133
150
  }
134
151
  };
135
152
  const anyAssetConstants = {
@@ -148,7 +165,8 @@ const assetSymbols = [
148
165
  "SOL",
149
166
  "USDC",
150
167
  "USDT",
151
- "WBTC"
168
+ "WBTC",
169
+ "TRX"
152
170
  ];
153
171
  const chainConstants = {
154
172
  Ethereum: {
@@ -221,6 +239,13 @@ const chainConstants = {
221
239
  gasAsset: "HubDot",
222
240
  addressType: "Hub",
223
241
  blockTimeSeconds: 3
242
+ },
243
+ Tron: {
244
+ chainflipAssets: ["Trx", "TrxUsdt"],
245
+ assets: ["TRX", "USDT"],
246
+ gasAsset: "Trx",
247
+ addressType: "Tron",
248
+ blockTimeSeconds: 3
224
249
  }
225
250
  };
226
251
  const anyChainConstants = {
@@ -293,6 +318,14 @@ const internalAssetToRpcAsset = {
293
318
  HubUsdc: {
294
319
  chain: "Assethub",
295
320
  asset: "USDC"
321
+ },
322
+ Trx: {
323
+ chain: "Tron",
324
+ asset: "TRX"
325
+ },
326
+ TrxUsdt: {
327
+ chain: "Tron",
328
+ asset: "USDT"
296
329
  }
297
330
  };
298
331
  const anyInternalAssetToRpcAsset = {
@@ -307,7 +340,8 @@ const chainContractId = {
307
340
  Bitcoin: 3,
308
341
  Arbitrum: 4,
309
342
  Solana: 5,
310
- Assethub: 6
343
+ Assethub: 6,
344
+ Tron: 7
311
345
  };
312
346
  const assetContractId = {
313
347
  Eth: 1,
@@ -324,7 +358,9 @@ const assetContractId = {
324
358
  HubUsdc: 13,
325
359
  Wbtc: 14,
326
360
  ArbUsdt: 15,
327
- SolUsdt: 16
361
+ SolUsdt: 16,
362
+ Trx: 17,
363
+ TrxUsdt: 18
328
364
  };
329
365
  function getInternalAsset(asset, assert = true) {
330
366
  const internalAsset = {
@@ -350,6 +386,10 @@ function getInternalAsset(asset, assert = true) {
350
386
  USDC: "HubUsdc",
351
387
  USDT: "HubUsdt",
352
388
  DOT: "HubDot"
389
+ },
390
+ Tron: {
391
+ TRX: "Trx",
392
+ USDT: "TrxUsdt"
353
393
  }
354
394
  }[asset.chain]?.[asset.asset];
355
395
  if (internalAsset) return internalAsset;
@@ -392,7 +432,9 @@ const chainflipAssetToPriceAssetMap = {
392
432
  HubUsdt: "Usdt",
393
433
  Flip: null,
394
434
  HubDot: null,
395
- Wbtc: "Btc"
435
+ Wbtc: "Btc",
436
+ Trx: null,
437
+ TrxUsdt: "Usdt"
396
438
  };
397
439
  function isChainflipAsset(asset) {
398
440
  return chainflipAssets.includes(asset);
@@ -1,5 +1,5 @@
1
1
  //#region src/chainflip.d.ts
2
- declare const chainflipAssets: readonly ["Usdc", "Usdt", "Wbtc", "Flip", "Eth", "Btc", "ArbUsdc", "ArbUsdt", "ArbEth", "Sol", "SolUsdc", "SolUsdt", "HubDot", "HubUsdt", "HubUsdc"];
2
+ declare const chainflipAssets: readonly ["Usdc", "Usdt", "Wbtc", "Flip", "Eth", "Btc", "ArbUsdc", "ArbUsdt", "ArbEth", "Sol", "SolUsdc", "SolUsdt", "Trx", "TrxUsdt", "HubDot", "HubUsdt", "HubUsdc"];
3
3
  declare const legacyChainflipAssets: readonly ["Dot"];
4
4
  type ChainflipAsset = (typeof chainflipAssets)[number];
5
5
  type LegacyChainflipAsset = (typeof legacyChainflipAssets)[number];
@@ -9,16 +9,16 @@ type PriceAsset = (typeof priceAssets)[number];
9
9
  type BaseChainflipAsset = Exclude<ChainflipAsset, 'Usdc'>;
10
10
  type AnyBaseChainflipAsset = Exclude<AnyChainflipAsset, 'Usdc'>;
11
11
  declare const baseChainflipAssets: BaseChainflipAsset[];
12
- declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum"];
12
+ declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum", "Tron"];
13
13
  type ChainflipEvmChain = (typeof chainflipEvmChains)[number];
14
- declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Bitcoin", "Solana", "Assethub"];
14
+ declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Tron", "Bitcoin", "Solana", "Assethub"];
15
15
  type ChainflipChain = (typeof chainflipChains)[number];
16
16
  declare const legacyChainflipChains: readonly ["Polkadot"];
17
17
  type LegacyChainflipChain = (typeof legacyChainflipChains)[number];
18
18
  type AnyChainflipChain = ChainflipChain | LegacyChainflipChain;
19
19
  declare const chainflipNetworks: readonly ["backspin", "sisyphos", "perseverance", "mainnet"];
20
20
  type ChainflipNetwork = (typeof chainflipNetworks)[number];
21
- declare const addressTypes: readonly ["Eth", "Btc", "Arb", "Sol", "Hub"];
21
+ declare const addressTypes: readonly ["Eth", "Btc", "Arb", "Sol", "Hub", "Tron"];
22
22
  type AddressType = (typeof addressTypes)[number];
23
23
  declare const legacyAddressTypes: readonly ["Dot"];
24
24
  type LegacyAddressType = (typeof legacyAddressTypes)[number];
@@ -140,6 +140,16 @@ declare const assetConstants: {
140
140
  readonly symbol: "USDT";
141
141
  readonly decimals: 6;
142
142
  };
143
+ readonly Trx: {
144
+ readonly chain: "Tron";
145
+ readonly symbol: "TRX";
146
+ readonly decimals: 6;
147
+ };
148
+ readonly TrxUsdt: {
149
+ readonly chain: "Tron";
150
+ readonly symbol: "USDT";
151
+ readonly decimals: 6;
152
+ };
143
153
  };
144
154
  declare const anyAssetConstants: {
145
155
  readonly Dot: {
@@ -222,8 +232,18 @@ declare const anyAssetConstants: {
222
232
  readonly symbol: "USDT";
223
233
  readonly decimals: 6;
224
234
  };
235
+ readonly Trx: {
236
+ readonly chain: "Tron";
237
+ readonly symbol: "TRX";
238
+ readonly decimals: 6;
239
+ };
240
+ readonly TrxUsdt: {
241
+ readonly chain: "Tron";
242
+ readonly symbol: "USDT";
243
+ readonly decimals: 6;
244
+ };
225
245
  };
226
- declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC"];
246
+ declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC", "TRX"];
227
247
  type AssetSymbol = (typeof assetSymbols)[number];
228
248
  declare const chainConstants: {
229
249
  readonly Ethereum: {
@@ -261,6 +281,13 @@ declare const chainConstants: {
261
281
  readonly addressType: "Hub";
262
282
  readonly blockTimeSeconds: 3;
263
283
  };
284
+ readonly Tron: {
285
+ readonly chainflipAssets: ["Trx", "TrxUsdt"];
286
+ readonly assets: ["TRX", "USDT"];
287
+ readonly gasAsset: "Trx";
288
+ readonly addressType: "Tron";
289
+ readonly blockTimeSeconds: 3;
290
+ };
264
291
  };
265
292
  declare const anyChainConstants: {
266
293
  readonly Polkadot: {
@@ -305,6 +332,13 @@ declare const anyChainConstants: {
305
332
  readonly addressType: "Hub";
306
333
  readonly blockTimeSeconds: 3;
307
334
  };
335
+ readonly Tron: {
336
+ readonly chainflipAssets: ["Trx", "TrxUsdt"];
337
+ readonly assets: ["TRX", "USDT"];
338
+ readonly gasAsset: "Trx";
339
+ readonly addressType: "Tron";
340
+ readonly blockTimeSeconds: 3;
341
+ };
308
342
  };
309
343
  declare const internalAssetToRpcAsset: InternalAssetMap<AssetAndChain>;
310
344
  declare const anyInternalAssetToRpcAsset: AnyInternalAssetMap<AnyAssetAndChain>;
@@ -1,5 +1,5 @@
1
1
  //#region src/chainflip.d.ts
2
- declare const chainflipAssets: readonly ["Usdc", "Usdt", "Wbtc", "Flip", "Eth", "Btc", "ArbUsdc", "ArbUsdt", "ArbEth", "Sol", "SolUsdc", "SolUsdt", "HubDot", "HubUsdt", "HubUsdc"];
2
+ declare const chainflipAssets: readonly ["Usdc", "Usdt", "Wbtc", "Flip", "Eth", "Btc", "ArbUsdc", "ArbUsdt", "ArbEth", "Sol", "SolUsdc", "SolUsdt", "Trx", "TrxUsdt", "HubDot", "HubUsdt", "HubUsdc"];
3
3
  declare const legacyChainflipAssets: readonly ["Dot"];
4
4
  type ChainflipAsset = (typeof chainflipAssets)[number];
5
5
  type LegacyChainflipAsset = (typeof legacyChainflipAssets)[number];
@@ -9,16 +9,16 @@ type PriceAsset = (typeof priceAssets)[number];
9
9
  type BaseChainflipAsset = Exclude<ChainflipAsset, 'Usdc'>;
10
10
  type AnyBaseChainflipAsset = Exclude<AnyChainflipAsset, 'Usdc'>;
11
11
  declare const baseChainflipAssets: BaseChainflipAsset[];
12
- declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum"];
12
+ declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum", "Tron"];
13
13
  type ChainflipEvmChain = (typeof chainflipEvmChains)[number];
14
- declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Bitcoin", "Solana", "Assethub"];
14
+ declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Tron", "Bitcoin", "Solana", "Assethub"];
15
15
  type ChainflipChain = (typeof chainflipChains)[number];
16
16
  declare const legacyChainflipChains: readonly ["Polkadot"];
17
17
  type LegacyChainflipChain = (typeof legacyChainflipChains)[number];
18
18
  type AnyChainflipChain = ChainflipChain | LegacyChainflipChain;
19
19
  declare const chainflipNetworks: readonly ["backspin", "sisyphos", "perseverance", "mainnet"];
20
20
  type ChainflipNetwork = (typeof chainflipNetworks)[number];
21
- declare const addressTypes: readonly ["Eth", "Btc", "Arb", "Sol", "Hub"];
21
+ declare const addressTypes: readonly ["Eth", "Btc", "Arb", "Sol", "Hub", "Tron"];
22
22
  type AddressType = (typeof addressTypes)[number];
23
23
  declare const legacyAddressTypes: readonly ["Dot"];
24
24
  type LegacyAddressType = (typeof legacyAddressTypes)[number];
@@ -140,6 +140,16 @@ declare const assetConstants: {
140
140
  readonly symbol: "USDT";
141
141
  readonly decimals: 6;
142
142
  };
143
+ readonly Trx: {
144
+ readonly chain: "Tron";
145
+ readonly symbol: "TRX";
146
+ readonly decimals: 6;
147
+ };
148
+ readonly TrxUsdt: {
149
+ readonly chain: "Tron";
150
+ readonly symbol: "USDT";
151
+ readonly decimals: 6;
152
+ };
143
153
  };
144
154
  declare const anyAssetConstants: {
145
155
  readonly Dot: {
@@ -222,8 +232,18 @@ declare const anyAssetConstants: {
222
232
  readonly symbol: "USDT";
223
233
  readonly decimals: 6;
224
234
  };
235
+ readonly Trx: {
236
+ readonly chain: "Tron";
237
+ readonly symbol: "TRX";
238
+ readonly decimals: 6;
239
+ };
240
+ readonly TrxUsdt: {
241
+ readonly chain: "Tron";
242
+ readonly symbol: "USDT";
243
+ readonly decimals: 6;
244
+ };
225
245
  };
226
- declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC"];
246
+ declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC", "TRX"];
227
247
  type AssetSymbol = (typeof assetSymbols)[number];
228
248
  declare const chainConstants: {
229
249
  readonly Ethereum: {
@@ -261,6 +281,13 @@ declare const chainConstants: {
261
281
  readonly addressType: "Hub";
262
282
  readonly blockTimeSeconds: 3;
263
283
  };
284
+ readonly Tron: {
285
+ readonly chainflipAssets: ["Trx", "TrxUsdt"];
286
+ readonly assets: ["TRX", "USDT"];
287
+ readonly gasAsset: "Trx";
288
+ readonly addressType: "Tron";
289
+ readonly blockTimeSeconds: 3;
290
+ };
264
291
  };
265
292
  declare const anyChainConstants: {
266
293
  readonly Polkadot: {
@@ -305,6 +332,13 @@ declare const anyChainConstants: {
305
332
  readonly addressType: "Hub";
306
333
  readonly blockTimeSeconds: 3;
307
334
  };
335
+ readonly Tron: {
336
+ readonly chainflipAssets: ["Trx", "TrxUsdt"];
337
+ readonly assets: ["TRX", "USDT"];
338
+ readonly gasAsset: "Trx";
339
+ readonly addressType: "Tron";
340
+ readonly blockTimeSeconds: 3;
341
+ };
308
342
  };
309
343
  declare const internalAssetToRpcAsset: InternalAssetMap<AssetAndChain>;
310
344
  declare const anyInternalAssetToRpcAsset: AnyInternalAssetMap<AnyAssetAndChain>;
@@ -14,6 +14,8 @@ const chainflipAssets = [
14
14
  "Sol",
15
15
  "SolUsdc",
16
16
  "SolUsdt",
17
+ "Trx",
18
+ "TrxUsdt",
17
19
  "HubDot",
18
20
  "HubUsdt",
19
21
  "HubUsdc"
@@ -29,7 +31,11 @@ const priceAssets = [
29
31
  "Fine"
30
32
  ];
31
33
  const baseChainflipAssets = chainflipAssets.filter((asset) => asset !== "Usdc");
32
- const chainflipEvmChains = ["Ethereum", "Arbitrum"];
34
+ const chainflipEvmChains = [
35
+ "Ethereum",
36
+ "Arbitrum",
37
+ "Tron"
38
+ ];
33
39
  const chainflipChains = [
34
40
  ...chainflipEvmChains,
35
41
  "Bitcoin",
@@ -48,7 +54,8 @@ const addressTypes = [
48
54
  "Btc",
49
55
  "Arb",
50
56
  "Sol",
51
- "Hub"
57
+ "Hub",
58
+ "Tron"
52
59
  ];
53
60
  const legacyAddressTypes = ["Dot"];
54
61
  function readAssetValue(map, asset) {
@@ -129,6 +136,16 @@ const assetConstants = {
129
136
  chain: "Assethub",
130
137
  symbol: "USDT",
131
138
  decimals: 6
139
+ },
140
+ Trx: {
141
+ chain: "Tron",
142
+ symbol: "TRX",
143
+ decimals: 6
144
+ },
145
+ TrxUsdt: {
146
+ chain: "Tron",
147
+ symbol: "USDT",
148
+ decimals: 6
132
149
  }
133
150
  };
134
151
  const anyAssetConstants = {
@@ -147,7 +164,8 @@ const assetSymbols = [
147
164
  "SOL",
148
165
  "USDC",
149
166
  "USDT",
150
- "WBTC"
167
+ "WBTC",
168
+ "TRX"
151
169
  ];
152
170
  const chainConstants = {
153
171
  Ethereum: {
@@ -220,6 +238,13 @@ const chainConstants = {
220
238
  gasAsset: "HubDot",
221
239
  addressType: "Hub",
222
240
  blockTimeSeconds: 3
241
+ },
242
+ Tron: {
243
+ chainflipAssets: ["Trx", "TrxUsdt"],
244
+ assets: ["TRX", "USDT"],
245
+ gasAsset: "Trx",
246
+ addressType: "Tron",
247
+ blockTimeSeconds: 3
223
248
  }
224
249
  };
225
250
  const anyChainConstants = {
@@ -292,6 +317,14 @@ const internalAssetToRpcAsset = {
292
317
  HubUsdc: {
293
318
  chain: "Assethub",
294
319
  asset: "USDC"
320
+ },
321
+ Trx: {
322
+ chain: "Tron",
323
+ asset: "TRX"
324
+ },
325
+ TrxUsdt: {
326
+ chain: "Tron",
327
+ asset: "USDT"
295
328
  }
296
329
  };
297
330
  const anyInternalAssetToRpcAsset = {
@@ -306,7 +339,8 @@ const chainContractId = {
306
339
  Bitcoin: 3,
307
340
  Arbitrum: 4,
308
341
  Solana: 5,
309
- Assethub: 6
342
+ Assethub: 6,
343
+ Tron: 7
310
344
  };
311
345
  const assetContractId = {
312
346
  Eth: 1,
@@ -323,7 +357,9 @@ const assetContractId = {
323
357
  HubUsdc: 13,
324
358
  Wbtc: 14,
325
359
  ArbUsdt: 15,
326
- SolUsdt: 16
360
+ SolUsdt: 16,
361
+ Trx: 17,
362
+ TrxUsdt: 18
327
363
  };
328
364
  function getInternalAsset(asset, assert = true) {
329
365
  const internalAsset = {
@@ -349,6 +385,10 @@ function getInternalAsset(asset, assert = true) {
349
385
  USDC: "HubUsdc",
350
386
  USDT: "HubUsdt",
351
387
  DOT: "HubDot"
388
+ },
389
+ Tron: {
390
+ TRX: "Trx",
391
+ USDT: "TrxUsdt"
352
392
  }
353
393
  }[asset.chain]?.[asset.asset];
354
394
  if (internalAsset) return internalAsset;
@@ -391,7 +431,9 @@ const chainflipAssetToPriceAssetMap = {
391
431
  HubUsdt: "Usdt",
392
432
  Flip: null,
393
433
  HubDot: null,
394
- Wbtc: "Btc"
434
+ Wbtc: "Btc",
435
+ Trx: null,
436
+ TrxUsdt: "Usdt"
395
437
  };
396
438
  function isChainflipAsset(asset) {
397
439
  return chainflipAssets.includes(asset);
package/dist/tron.cjs ADDED
@@ -0,0 +1,15 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_base58 = require('./base58.cjs');
3
+
4
+ //#region src/tron.ts
5
+ const isValidTronAddress = (address) => {
6
+ try {
7
+ if (!address.startsWith("T")) return false;
8
+ return require_base58.decode(address).length === 25;
9
+ } catch {
10
+ return false;
11
+ }
12
+ };
13
+
14
+ //#endregion
15
+ exports.isValidTronAddress = isValidTronAddress;
@@ -0,0 +1,4 @@
1
+ //#region src/tron.d.ts
2
+ declare const isValidTronAddress: (address: string) => boolean;
3
+ //#endregion
4
+ export { isValidTronAddress };
@@ -0,0 +1,4 @@
1
+ //#region src/tron.d.ts
2
+ declare const isValidTronAddress: (address: string) => boolean;
3
+ //#endregion
4
+ export { isValidTronAddress };
package/dist/tron.mjs ADDED
@@ -0,0 +1,14 @@
1
+ import { decode } from "./base58.mjs";
2
+
3
+ //#region src/tron.ts
4
+ const isValidTronAddress = (address) => {
5
+ try {
6
+ if (!address.startsWith("T")) return false;
7
+ return decode(address).length === 25;
8
+ } catch {
9
+ return false;
10
+ }
11
+ };
12
+
13
+ //#endregion
14
+ export { isValidTronAddress };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/utils",
3
- "version": "2.1.8",
3
+ "version": "2.2.0-alpha.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@date-fns/utc": "^2.1.1",
26
26
  "@noble/hashes": "^2.2.0",
27
- "bignumber.js": "^10.0.2",
27
+ "bignumber.js": "^11.1.1",
28
28
  "date-fns": "4.1.0"
29
29
  },
30
30
  "repository": "https://github.com/chainflip-io/chainflip-product-toolkit.git",