@chainflip/utils 0.4.0 → 0.4.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.
Files changed (44) hide show
  1. package/dist/assertion.js +2 -2
  2. package/dist/async.cjs +1 -1
  3. package/dist/async.d.cts +1 -1
  4. package/dist/async.d.ts +1 -1
  5. package/dist/async.js +1 -1
  6. package/dist/base58.js +4 -4
  7. package/dist/bytes.js +3 -3
  8. package/dist/chainflip.cjs +147 -0
  9. package/dist/chainflip.d.cts +99 -0
  10. package/dist/chainflip.d.ts +99 -0
  11. package/dist/chainflip.js +22 -0
  12. package/dist/{chunk-D7RIA7SA.js → chunk-2KA626OL.js} +1 -1
  13. package/dist/{chunk-UPA7KLTI.js → chunk-CGMSQQDO.js} +1 -1
  14. package/dist/{chunk-CZNX6EUV.js → chunk-HBIFE4XN.js} +7 -1
  15. package/dist/chunk-WGS2RGVR.js +1348 -0
  16. package/dist/chunk-XFHVSV76.js +115 -0
  17. package/dist/{chunk-MYP3UYWE.js → chunk-ZHIKNZLU.js} +1 -1
  18. package/dist/consts.cjs +146 -0
  19. package/dist/consts.d.cts +148 -0
  20. package/dist/consts.d.ts +148 -0
  21. package/dist/consts.js +113 -0
  22. package/dist/date.cjs +497 -0
  23. package/dist/date.d.cts +16 -0
  24. package/dist/date.d.ts +16 -0
  25. package/dist/date.js +455 -0
  26. package/dist/guard.cjs +9 -0
  27. package/dist/guard.d.cts +11 -8
  28. package/dist/guard.d.ts +11 -8
  29. package/dist/guard.js +7 -1
  30. package/dist/number.cjs +1386 -0
  31. package/dist/number.d.cts +6 -1
  32. package/dist/number.d.ts +6 -1
  33. package/dist/number.js +33 -0
  34. package/dist/ss58.cjs +23 -23
  35. package/dist/ss58.js +10 -10
  36. package/dist/string.cjs +21 -0
  37. package/dist/string.d.cts +7 -2
  38. package/dist/string.d.ts +7 -2
  39. package/dist/string.js +18 -0
  40. package/dist/tickMath.cjs +1502 -0
  41. package/dist/tickMath.d.cts +15 -0
  42. package/dist/tickMath.d.ts +15 -0
  43. package/dist/tickMath.js +35 -0
  44. package/package.json +9 -2
package/dist/assertion.js CHANGED
@@ -8,8 +8,8 @@ import {
8
8
  assertSymbol,
9
9
  assertUndefined,
10
10
  unreachable
11
- } from "./chunk-MYP3UYWE.js";
12
- import "./chunk-CZNX6EUV.js";
11
+ } from "./chunk-ZHIKNZLU.js";
12
+ import "./chunk-HBIFE4XN.js";
13
13
  export {
14
14
  assert,
15
15
  assertBigInt,
package/dist/async.cjs CHANGED
@@ -94,7 +94,7 @@ var once = async (target, event, opts) => {
94
94
  target.addEventListener(event, onSuccess, { once: true, signal: opts?.signal });
95
95
  target.addEventListener("error", onError, { once: true, signal: opts?.signal });
96
96
  if (opts?.signal) {
97
- const signal = opts.signal;
97
+ const { signal } = opts;
98
98
  const abort = () => {
99
99
  deferred.reject(new Error("aborted"));
100
100
  };
package/dist/async.d.cts CHANGED
@@ -25,7 +25,7 @@ declare class RateLimiter<T, Args extends unknown[]> {
25
25
  });
26
26
  request(...args: Args): Promise<T>;
27
27
  }
28
- declare const once: <T extends EventTarget, K extends string>(target: T, event: K, opts?: {
28
+ declare const once: (target: EventTarget, event: string, opts?: {
29
29
  signal?: AbortSignal;
30
30
  timeout?: number;
31
31
  }) => Promise<void>;
package/dist/async.d.ts CHANGED
@@ -25,7 +25,7 @@ declare class RateLimiter<T, Args extends unknown[]> {
25
25
  });
26
26
  request(...args: Args): Promise<T>;
27
27
  }
28
- declare const once: <T extends EventTarget, K extends string>(target: T, event: K, opts?: {
28
+ declare const once: (target: EventTarget, event: string, opts?: {
29
29
  signal?: AbortSignal;
30
30
  timeout?: number;
31
31
  }) => Promise<void>;
package/dist/async.js CHANGED
@@ -66,7 +66,7 @@ var once = async (target, event, opts) => {
66
66
  target.addEventListener(event, onSuccess, { once: true, signal: opts?.signal });
67
67
  target.addEventListener("error", onError, { once: true, signal: opts?.signal });
68
68
  if (opts?.signal) {
69
- const signal = opts.signal;
69
+ const { signal } = opts;
70
70
  const abort = () => {
71
71
  deferred.reject(new Error("aborted"));
72
72
  };
package/dist/base58.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  decode,
3
3
  encode
4
- } from "./chunk-UPA7KLTI.js";
5
- import "./chunk-D7RIA7SA.js";
6
- import "./chunk-MYP3UYWE.js";
7
- import "./chunk-CZNX6EUV.js";
4
+ } from "./chunk-CGMSQQDO.js";
5
+ import "./chunk-2KA626OL.js";
6
+ import "./chunk-ZHIKNZLU.js";
7
+ import "./chunk-HBIFE4XN.js";
8
8
  export {
9
9
  decode,
10
10
  encode
package/dist/bytes.js CHANGED
@@ -4,9 +4,9 @@ import {
4
4
  encodeBytesWithCharset,
5
5
  hexToBytes,
6
6
  reverseBytes
7
- } from "./chunk-D7RIA7SA.js";
8
- import "./chunk-MYP3UYWE.js";
9
- import "./chunk-CZNX6EUV.js";
7
+ } from "./chunk-2KA626OL.js";
8
+ import "./chunk-ZHIKNZLU.js";
9
+ import "./chunk-HBIFE4XN.js";
10
10
  export {
11
11
  bytesToHex,
12
12
  decodeBytesWithCharset,
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/chainflip.ts
21
+ var chainflip_exports = {};
22
+ __export(chainflip_exports, {
23
+ assetConstants: () => assetConstants,
24
+ baseChainflipAssets: () => baseChainflipAssets,
25
+ chainConstants: () => chainConstants,
26
+ chainflipAssets: () => chainflipAssets,
27
+ chainflipChains: () => chainflipChains,
28
+ chainflipEvmChains: () => chainflipEvmChains,
29
+ chainflipNetworks: () => chainflipNetworks,
30
+ readAssetValue: () => readAssetValue,
31
+ rpcAssets: () => rpcAssets
32
+ });
33
+ module.exports = __toCommonJS(chainflip_exports);
34
+ var chainflipAssets = [
35
+ "Usdc",
36
+ "Usdt",
37
+ "Flip",
38
+ "Dot",
39
+ "Eth",
40
+ "Btc",
41
+ "ArbUsdc",
42
+ "ArbEth",
43
+ "Sol",
44
+ "SolUsdc"
45
+ ];
46
+ var rpcAssets = ["USDC", "USDT", "FLIP", "DOT", "ETH", "BTC", "SOL"];
47
+ var baseChainflipAssets = chainflipAssets.filter(
48
+ (asset) => asset !== "Usdc"
49
+ );
50
+ var chainflipEvmChains = ["Ethereum", "Arbitrum"];
51
+ var chainflipChains = [...chainflipEvmChains, "Bitcoin", "Polkadot", "Solana"];
52
+ var chainflipNetworks = ["backspin", "sisyphos", "perseverance", "mainnet"];
53
+ var readAssetValue = (value, asset) => {
54
+ const chainValues = value[assetConstants[asset].chain];
55
+ return chainValues[assetConstants[asset].rpcAsset];
56
+ };
57
+ var assetConstants = {
58
+ Eth: {
59
+ chain: "Ethereum",
60
+ rpcAsset: "ETH",
61
+ decimals: 18
62
+ },
63
+ Flip: {
64
+ chain: "Ethereum",
65
+ rpcAsset: "FLIP",
66
+ decimals: 18
67
+ },
68
+ Usdc: {
69
+ chain: "Ethereum",
70
+ rpcAsset: "USDC",
71
+ decimals: 6
72
+ },
73
+ Usdt: {
74
+ chain: "Ethereum",
75
+ rpcAsset: "USDT",
76
+ decimals: 6
77
+ },
78
+ Dot: {
79
+ chain: "Polkadot",
80
+ rpcAsset: "DOT",
81
+ decimals: 10
82
+ },
83
+ Btc: {
84
+ chain: "Bitcoin",
85
+ rpcAsset: "BTC",
86
+ decimals: 8
87
+ },
88
+ ArbUsdc: {
89
+ chain: "Arbitrum",
90
+ rpcAsset: "USDC",
91
+ decimals: 6
92
+ },
93
+ ArbEth: {
94
+ chain: "Arbitrum",
95
+ rpcAsset: "ETH",
96
+ decimals: 18
97
+ },
98
+ Sol: {
99
+ chain: "Solana",
100
+ rpcAsset: "SOL",
101
+ decimals: 9
102
+ },
103
+ SolUsdc: {
104
+ chain: "Solana",
105
+ rpcAsset: "USDC",
106
+ decimals: 6
107
+ }
108
+ };
109
+ var chainConstants = {
110
+ Ethereum: {
111
+ assets: ["Eth", "Flip", "Usdc", "Usdt"],
112
+ gasAsset: "Eth",
113
+ blockTimeSeconds: 12
114
+ },
115
+ Polkadot: {
116
+ assets: ["Dot"],
117
+ gasAsset: "Dot",
118
+ blockTimeSeconds: 6
119
+ },
120
+ Bitcoin: {
121
+ assets: ["Btc"],
122
+ gasAsset: "Btc",
123
+ blockTimeSeconds: 10 * 60
124
+ },
125
+ Arbitrum: {
126
+ assets: ["ArbUsdc", "ArbEth"],
127
+ gasAsset: "ArbEth",
128
+ blockTimeSeconds: 0.26
129
+ },
130
+ Solana: {
131
+ assets: ["Sol", "SolUsdc"],
132
+ gasAsset: "Sol",
133
+ blockTimeSeconds: 0.8
134
+ }
135
+ };
136
+ // Annotate the CommonJS export names for ESM import in node:
137
+ 0 && (module.exports = {
138
+ assetConstants,
139
+ baseChainflipAssets,
140
+ chainConstants,
141
+ chainflipAssets,
142
+ chainflipChains,
143
+ chainflipEvmChains,
144
+ chainflipNetworks,
145
+ readAssetValue,
146
+ rpcAssets
147
+ });
@@ -0,0 +1,99 @@
1
+ declare const chainflipAssets: readonly ["Usdc", "Usdt", "Flip", "Dot", "Eth", "Btc", "ArbUsdc", "ArbEth", "Sol", "SolUsdc"];
2
+ type ChainflipAsset = (typeof chainflipAssets)[number];
3
+ declare const rpcAssets: readonly ["USDC", "USDT", "FLIP", "DOT", "ETH", "BTC", "SOL"];
4
+ type BaseChainflipAsset = Exclude<ChainflipAsset, 'Usdc'>;
5
+ declare const baseChainflipAssets: BaseChainflipAsset[];
6
+ declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum"];
7
+ type ChainflipEvmChain = (typeof chainflipEvmChains)[number];
8
+ declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Bitcoin", "Polkadot", "Solana"];
9
+ type ChainflipChain = (typeof chainflipChains)[number];
10
+ declare const chainflipNetworks: readonly ["backspin", "sisyphos", "perseverance", "mainnet"];
11
+ type ChainflipNetwork = (typeof chainflipNetworks)[number];
12
+ type AssetOfChain<C extends ChainflipChain> = (typeof chainConstants)[C]['assets'][number];
13
+ type ChainAssetMap<T> = {
14
+ [C in ChainflipChain]: {
15
+ [A in (typeof assetConstants)[AssetOfChain<C>]['rpcAsset']]: T;
16
+ };
17
+ };
18
+ declare const readAssetValue: <T>(value: ChainAssetMap<T>, asset: ChainflipAsset) => T;
19
+ declare const assetConstants: {
20
+ readonly Eth: {
21
+ readonly chain: "Ethereum";
22
+ readonly rpcAsset: "ETH";
23
+ readonly decimals: 18;
24
+ };
25
+ readonly Flip: {
26
+ readonly chain: "Ethereum";
27
+ readonly rpcAsset: "FLIP";
28
+ readonly decimals: 18;
29
+ };
30
+ readonly Usdc: {
31
+ readonly chain: "Ethereum";
32
+ readonly rpcAsset: "USDC";
33
+ readonly decimals: 6;
34
+ };
35
+ readonly Usdt: {
36
+ readonly chain: "Ethereum";
37
+ readonly rpcAsset: "USDT";
38
+ readonly decimals: 6;
39
+ };
40
+ readonly Dot: {
41
+ readonly chain: "Polkadot";
42
+ readonly rpcAsset: "DOT";
43
+ readonly decimals: 10;
44
+ };
45
+ readonly Btc: {
46
+ readonly chain: "Bitcoin";
47
+ readonly rpcAsset: "BTC";
48
+ readonly decimals: 8;
49
+ };
50
+ readonly ArbUsdc: {
51
+ readonly chain: "Arbitrum";
52
+ readonly rpcAsset: "USDC";
53
+ readonly decimals: 6;
54
+ };
55
+ readonly ArbEth: {
56
+ readonly chain: "Arbitrum";
57
+ readonly rpcAsset: "ETH";
58
+ readonly decimals: 18;
59
+ };
60
+ readonly Sol: {
61
+ readonly chain: "Solana";
62
+ readonly rpcAsset: "SOL";
63
+ readonly decimals: 9;
64
+ };
65
+ readonly SolUsdc: {
66
+ readonly chain: "Solana";
67
+ readonly rpcAsset: "USDC";
68
+ readonly decimals: 6;
69
+ };
70
+ };
71
+ declare const chainConstants: {
72
+ readonly Ethereum: {
73
+ readonly assets: ["Eth", "Flip", "Usdc", "Usdt"];
74
+ readonly gasAsset: "Eth";
75
+ readonly blockTimeSeconds: 12;
76
+ };
77
+ readonly Polkadot: {
78
+ readonly assets: ["Dot"];
79
+ readonly gasAsset: "Dot";
80
+ readonly blockTimeSeconds: 6;
81
+ };
82
+ readonly Bitcoin: {
83
+ readonly assets: ["Btc"];
84
+ readonly gasAsset: "Btc";
85
+ readonly blockTimeSeconds: number;
86
+ };
87
+ readonly Arbitrum: {
88
+ readonly assets: ["ArbUsdc", "ArbEth"];
89
+ readonly gasAsset: "ArbEth";
90
+ readonly blockTimeSeconds: 0.26;
91
+ };
92
+ readonly Solana: {
93
+ readonly assets: ["Sol", "SolUsdc"];
94
+ readonly gasAsset: "Sol";
95
+ readonly blockTimeSeconds: 0.8;
96
+ };
97
+ };
98
+
99
+ export { type AssetOfChain, type BaseChainflipAsset, type ChainAssetMap, type ChainflipAsset, type ChainflipChain, type ChainflipEvmChain, type ChainflipNetwork, assetConstants, baseChainflipAssets, chainConstants, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, readAssetValue, rpcAssets };
@@ -0,0 +1,99 @@
1
+ declare const chainflipAssets: readonly ["Usdc", "Usdt", "Flip", "Dot", "Eth", "Btc", "ArbUsdc", "ArbEth", "Sol", "SolUsdc"];
2
+ type ChainflipAsset = (typeof chainflipAssets)[number];
3
+ declare const rpcAssets: readonly ["USDC", "USDT", "FLIP", "DOT", "ETH", "BTC", "SOL"];
4
+ type BaseChainflipAsset = Exclude<ChainflipAsset, 'Usdc'>;
5
+ declare const baseChainflipAssets: BaseChainflipAsset[];
6
+ declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum"];
7
+ type ChainflipEvmChain = (typeof chainflipEvmChains)[number];
8
+ declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Bitcoin", "Polkadot", "Solana"];
9
+ type ChainflipChain = (typeof chainflipChains)[number];
10
+ declare const chainflipNetworks: readonly ["backspin", "sisyphos", "perseverance", "mainnet"];
11
+ type ChainflipNetwork = (typeof chainflipNetworks)[number];
12
+ type AssetOfChain<C extends ChainflipChain> = (typeof chainConstants)[C]['assets'][number];
13
+ type ChainAssetMap<T> = {
14
+ [C in ChainflipChain]: {
15
+ [A in (typeof assetConstants)[AssetOfChain<C>]['rpcAsset']]: T;
16
+ };
17
+ };
18
+ declare const readAssetValue: <T>(value: ChainAssetMap<T>, asset: ChainflipAsset) => T;
19
+ declare const assetConstants: {
20
+ readonly Eth: {
21
+ readonly chain: "Ethereum";
22
+ readonly rpcAsset: "ETH";
23
+ readonly decimals: 18;
24
+ };
25
+ readonly Flip: {
26
+ readonly chain: "Ethereum";
27
+ readonly rpcAsset: "FLIP";
28
+ readonly decimals: 18;
29
+ };
30
+ readonly Usdc: {
31
+ readonly chain: "Ethereum";
32
+ readonly rpcAsset: "USDC";
33
+ readonly decimals: 6;
34
+ };
35
+ readonly Usdt: {
36
+ readonly chain: "Ethereum";
37
+ readonly rpcAsset: "USDT";
38
+ readonly decimals: 6;
39
+ };
40
+ readonly Dot: {
41
+ readonly chain: "Polkadot";
42
+ readonly rpcAsset: "DOT";
43
+ readonly decimals: 10;
44
+ };
45
+ readonly Btc: {
46
+ readonly chain: "Bitcoin";
47
+ readonly rpcAsset: "BTC";
48
+ readonly decimals: 8;
49
+ };
50
+ readonly ArbUsdc: {
51
+ readonly chain: "Arbitrum";
52
+ readonly rpcAsset: "USDC";
53
+ readonly decimals: 6;
54
+ };
55
+ readonly ArbEth: {
56
+ readonly chain: "Arbitrum";
57
+ readonly rpcAsset: "ETH";
58
+ readonly decimals: 18;
59
+ };
60
+ readonly Sol: {
61
+ readonly chain: "Solana";
62
+ readonly rpcAsset: "SOL";
63
+ readonly decimals: 9;
64
+ };
65
+ readonly SolUsdc: {
66
+ readonly chain: "Solana";
67
+ readonly rpcAsset: "USDC";
68
+ readonly decimals: 6;
69
+ };
70
+ };
71
+ declare const chainConstants: {
72
+ readonly Ethereum: {
73
+ readonly assets: ["Eth", "Flip", "Usdc", "Usdt"];
74
+ readonly gasAsset: "Eth";
75
+ readonly blockTimeSeconds: 12;
76
+ };
77
+ readonly Polkadot: {
78
+ readonly assets: ["Dot"];
79
+ readonly gasAsset: "Dot";
80
+ readonly blockTimeSeconds: 6;
81
+ };
82
+ readonly Bitcoin: {
83
+ readonly assets: ["Btc"];
84
+ readonly gasAsset: "Btc";
85
+ readonly blockTimeSeconds: number;
86
+ };
87
+ readonly Arbitrum: {
88
+ readonly assets: ["ArbUsdc", "ArbEth"];
89
+ readonly gasAsset: "ArbEth";
90
+ readonly blockTimeSeconds: 0.26;
91
+ };
92
+ readonly Solana: {
93
+ readonly assets: ["Sol", "SolUsdc"];
94
+ readonly gasAsset: "Sol";
95
+ readonly blockTimeSeconds: 0.8;
96
+ };
97
+ };
98
+
99
+ export { type AssetOfChain, type BaseChainflipAsset, type ChainAssetMap, type ChainflipAsset, type ChainflipChain, type ChainflipEvmChain, type ChainflipNetwork, assetConstants, baseChainflipAssets, chainConstants, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, readAssetValue, rpcAssets };
@@ -0,0 +1,22 @@
1
+ import {
2
+ assetConstants,
3
+ baseChainflipAssets,
4
+ chainConstants,
5
+ chainflipAssets,
6
+ chainflipChains,
7
+ chainflipEvmChains,
8
+ chainflipNetworks,
9
+ readAssetValue,
10
+ rpcAssets
11
+ } from "./chunk-XFHVSV76.js";
12
+ export {
13
+ assetConstants,
14
+ baseChainflipAssets,
15
+ chainConstants,
16
+ chainflipAssets,
17
+ chainflipChains,
18
+ chainflipEvmChains,
19
+ chainflipNetworks,
20
+ readAssetValue,
21
+ rpcAssets
22
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  assert
3
- } from "./chunk-MYP3UYWE.js";
3
+ } from "./chunk-ZHIKNZLU.js";
4
4
 
5
5
  // src/bytes.ts
6
6
  var bytesToHex = (input) => {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  decodeBytesWithCharset,
3
3
  encodeBytesWithCharset
4
- } from "./chunk-D7RIA7SA.js";
4
+ } from "./chunk-2KA626OL.js";
5
5
 
6
6
  // src/base58.ts
7
7
  var charset = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
@@ -9,6 +9,9 @@ var isObject = createIsGuard("object");
9
9
  var isUndefined = createIsGuard("undefined");
10
10
  var isNotNullish = (value) => value != null;
11
11
  var isNullish = (value) => value == null;
12
+ var isTruthy = (value) => Boolean(value);
13
+ var isFullfilled = (value) => value.status === "fulfilled";
14
+ var isRejected = (value) => value.status === "rejected";
12
15
 
13
16
  export {
14
17
  isString,
@@ -19,5 +22,8 @@ export {
19
22
  isObject,
20
23
  isUndefined,
21
24
  isNotNullish,
22
- isNullish
25
+ isNullish,
26
+ isTruthy,
27
+ isFullfilled,
28
+ isRejected
23
29
  };