ox 0.14.32 → 0.14.33

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # ox
2
2
 
3
+ ## 0.14.33
4
+
5
+ ### Patch Changes
6
+
7
+ - [#315](https://github.com/wevm/ox/pull/315) [`2298f7b`](https://github.com/wevm/ox/commit/2298f7b2181bda4954291a0e9e9e3a10c3cb089a) Thanks [@jxom](https://github.com/jxom)! - Corrected Zone chain ID conversion for Presto and Moderato source chains.
8
+
9
+ ```ts
10
+ import { ZoneId } from "ox/tempo";
11
+
12
+ ZoneId.toChainId(1, 42_431);
13
+ ```
14
+
3
15
  ## 0.14.32
4
16
 
5
17
  ### Patch Changes
@@ -1,13 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.chainIdBase = void 0;
3
+ exports.UnsupportedSourceIdError = exports.chainIdBase = void 0;
4
4
  exports.fromChainId = fromChainId;
5
5
  exports.toChainId = toChainId;
6
- exports.chainIdBase = 4_217_000_000;
7
- function fromChainId(chainId) {
8
- return chainId - exports.chainIdBase;
6
+ const Errors = require("../core/Errors.js");
7
+ const chainIdConfig = {
8
+ 4217: {
9
+ base: 421_700_000,
10
+ range: 1_002_610_000,
11
+ },
12
+ 42431: {
13
+ base: 1_424_310_000,
14
+ range: 723_173_648,
15
+ },
16
+ };
17
+ const defaultSourceId = 4_217;
18
+ exports.chainIdBase = chainIdConfig[defaultSourceId].base;
19
+ function fromChainId(chainId, sourceId = defaultSourceId) {
20
+ return chainId - getChainIdConfig(sourceId).base;
9
21
  }
10
- function toChainId(zoneId) {
11
- return exports.chainIdBase + zoneId;
22
+ function toChainId(zoneId, sourceId = defaultSourceId) {
23
+ const { base, range } = getChainIdConfig(sourceId);
24
+ return base + (zoneId % range);
25
+ }
26
+ class UnsupportedSourceIdError extends Errors.BaseError {
27
+ constructor({ sourceId }) {
28
+ super(`Source chain ID "${sourceId}" is not supported.`, {
29
+ metaMessages: ['Supported source chain IDs: 4217, 42431.'],
30
+ });
31
+ Object.defineProperty(this, "name", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: 'ZoneId.UnsupportedSourceIdError'
36
+ });
37
+ }
38
+ }
39
+ exports.UnsupportedSourceIdError = UnsupportedSourceIdError;
40
+ function getChainIdConfig(sourceId) {
41
+ if (sourceId === 4_217 || sourceId === 42_431)
42
+ return chainIdConfig[sourceId];
43
+ throw new UnsupportedSourceIdError({ sourceId });
12
44
  }
13
45
  //# sourceMappingURL=ZoneId.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ZoneId.js","sourceRoot":"","sources":["../../tempo/ZoneId.ts"],"names":[],"mappings":";;;AA0BA,kCAEC;AAuBD,8BAEC;AA9CY,QAAA,WAAW,GAAG,aAAsB,CAAA;AAmBjD,SAAgB,WAAW,CAAC,OAAe;IACzC,OAAO,OAAO,GAAG,mBAAW,CAAA;AAC9B,CAAC;AAuBD,SAAgB,SAAS,CAAC,MAAc;IACtC,OAAO,mBAAW,GAAG,MAAM,CAAA;AAC7B,CAAC"}
1
+ {"version":3,"file":"ZoneId.js","sourceRoot":"","sources":["../../tempo/ZoneId.ts"],"names":[],"mappings":";;;AAwCA,kCAKC;AAuBD,8BAMC;AA1ED,4CAA2C;AAE3C,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE;QACJ,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,aAAa;KACrB;IACD,KAAK,EAAE;QACL,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,WAAW;KACnB;CACO,CAAA;AAEV,MAAM,eAAe,GAAG,KAAK,CAAA;AAKhB,QAAA,WAAW,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC,IAAI,CAAA;AAsB9D,SAAgB,WAAW,CACzB,OAAe,EACf,WAAqB,eAAe;IAEpC,OAAO,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAA;AAClD,CAAC;AAuBD,SAAgB,SAAS,CACvB,MAAc,EACd,WAAqB,eAAe;IAEpC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAClD,OAAO,IAAI,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,CAAA;AAChC,CAAC;AAOD,MAAa,wBAAyB,SAAQ,MAAM,CAAC,SAAS;IAE5D,YAAY,EAAE,QAAQ,EAAwB;QAC5C,KAAK,CAAC,oBAAoB,QAAQ,qBAAqB,EAAE;YACvD,YAAY,EAAE,CAAC,0CAA0C,CAAC;SAC3D,CAAC,CAAA;QAJc;;;;mBAAO,iCAAiC;WAAA;IAK1D,CAAC;CACF;AAPD,4DAOC;AAED,SAAS,gBAAgB,CAAC,QAAgB;IACxC,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,MAAM;QAAE,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC7E,MAAM,IAAI,wBAAwB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;AAClD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":";;;AAoCA,gEAA6D;AA2B7D,0CAAuC;AAsBvC,gDAA6C;AAwC7C,4DAAyD;AA0BzD,wDAAqD;AA6BrD,wCAAqC;AAsBrC,wCAAqC;AAsBrC,oEAAiE;AAoBjE,wDAAqD;AAuBrD,8DAA2D;AAmB3D,oDAAiD;AAoBjD,oCAAiC;AAqBjC,0CAAuC;AAkBvC,8CAA2C;AAkD3C,kDAA+C;AAuB/C,gEAA6D;AAqB7D,gEAA6D;AA6B7D,0DAAuD;AA4BvD,wDAAqD;AAyBrD,sDAAmD;AAqBnD,wCAAqC;AAmCrC,sEAAmE"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":";;;AAoCA,gEAA6D;AA2B7D,0CAAuC;AAsBvC,gDAA6C;AAwC7C,4DAAyD;AA0BzD,wDAAqD;AA6BrD,wCAAqC;AAsBrC,wCAAqC;AAsBrC,oEAAiE;AAoBjE,wDAAqD;AAuBrD,8DAA2D;AAmB3D,oDAAiD;AAoBjD,oCAAiC;AAqBjC,0CAAuC;AAkBvC,8CAA2C;AAkD3C,kDAA+C;AAuB/C,gEAA6D;AAqB7D,gEAA6D;AA6B7D,0DAAuD;AA4BvD,wDAAqD;AAyBrD,sDAAmD;AAoBnD,wCAAqC;AAmCrC,sEAAmE"}
package/_cjs/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = '0.14.32';
4
+ exports.version = '0.14.33';
5
5
  //# sourceMappingURL=version.js.map
@@ -1,47 +1,77 @@
1
+ import * as Errors from '../core/Errors.js';
2
+ const chainIdConfig = {
3
+ 4217: {
4
+ base: 421_700_000,
5
+ range: 1_002_610_000,
6
+ },
7
+ 42431: {
8
+ base: 1_424_310_000,
9
+ range: 723_173_648,
10
+ },
11
+ };
12
+ const defaultSourceId = 4_217;
1
13
  /**
2
- * Base offset for deriving zone chain IDs.
3
- *
4
- * Zone chain IDs are computed as `chainIdBase + zoneId`.
14
+ * Base offset for deriving Presto zone chain IDs.
5
15
  */
6
- export const chainIdBase = 4_217_000_000;
16
+ export const chainIdBase = chainIdConfig[defaultSourceId].base;
7
17
  /**
8
18
  * Derives a zone ID from a zone chain ID.
9
19
  *
10
- * Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so a chain ID
11
- * of `4217000006` corresponds to zone ID `6`.
20
+ * Zone chain IDs use the base assigned to their Tempo source chain.
12
21
  *
13
22
  * @example
14
23
  * ```ts twoslash
15
24
  * import { ZoneId } from 'ox/tempo'
16
25
  *
17
- * const zoneId = ZoneId.fromChainId(4_217_000_006)
18
- * // @log: 6
26
+ * const zoneId = ZoneId.fromChainId(421_700_001)
27
+ * // @log: 1
19
28
  * ```
20
29
  *
21
30
  * @param chainId - The zone chain ID.
31
+ * @param sourceId - The Tempo source chain ID. Defaults to `4217` (Presto).
22
32
  * @returns The zone ID.
23
33
  */
24
- export function fromChainId(chainId) {
25
- return chainId - chainIdBase;
34
+ export function fromChainId(chainId, sourceId = defaultSourceId) {
35
+ return chainId - getChainIdConfig(sourceId).base;
26
36
  }
27
37
  /**
28
38
  * Derives a zone chain ID from a zone ID.
29
39
  *
30
- * Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so zone ID
31
- * `6` corresponds to chain ID `4217000006`.
40
+ * Zone chain IDs use the base and range assigned to their Tempo source chain.
32
41
  *
33
42
  * @example
34
43
  * ```ts twoslash
35
44
  * import { ZoneId } from 'ox/tempo'
36
45
  *
37
- * const chainId = ZoneId.toChainId(6)
38
- * // @log: 4217000006
46
+ * const chainId = ZoneId.toChainId(1)
47
+ * // @log: 421700001
39
48
  * ```
40
49
  *
41
50
  * @param zoneId - The zone ID.
51
+ * @param sourceId - The Tempo source chain ID. Defaults to `4217` (Presto).
42
52
  * @returns The zone chain ID.
43
53
  */
44
- export function toChainId(zoneId) {
45
- return chainIdBase + zoneId;
54
+ export function toChainId(zoneId, sourceId = defaultSourceId) {
55
+ const { base, range } = getChainIdConfig(sourceId);
56
+ return base + (zoneId % range);
57
+ }
58
+ /** Thrown when a Tempo source chain ID is unsupported. */
59
+ export class UnsupportedSourceIdError extends Errors.BaseError {
60
+ constructor({ sourceId }) {
61
+ super(`Source chain ID "${sourceId}" is not supported.`, {
62
+ metaMessages: ['Supported source chain IDs: 4217, 42431.'],
63
+ });
64
+ Object.defineProperty(this, "name", {
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true,
68
+ value: 'ZoneId.UnsupportedSourceIdError'
69
+ });
70
+ }
71
+ }
72
+ function getChainIdConfig(sourceId) {
73
+ if (sourceId === 4_217 || sourceId === 42_431)
74
+ return chainIdConfig[sourceId];
75
+ throw new UnsupportedSourceIdError({ sourceId });
46
76
  }
47
77
  //# sourceMappingURL=ZoneId.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ZoneId.js","sourceRoot":"","sources":["../../tempo/ZoneId.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAsB,CAAA;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,OAAO,GAAG,WAAW,CAAA;AAC9B,CAAC;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,OAAO,WAAW,GAAG,MAAM,CAAA;AAC7B,CAAC"}
1
+ {"version":3,"file":"ZoneId.js","sourceRoot":"","sources":["../../tempo/ZoneId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAE3C,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE;QACJ,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,aAAa;KACrB;IACD,KAAK,EAAE;QACL,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,WAAW;KACnB;CACO,CAAA;AAEV,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC,IAAI,CAAA;AAK9D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CACzB,OAAe,EACf,WAAqB,eAAe;IAEpC,OAAO,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAA;AAClD,CAAC;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,SAAS,CACvB,MAAc,EACd,WAAqB,eAAe;IAEpC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAClD,OAAO,IAAI,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,CAAA;AAChC,CAAC;AAMD,0DAA0D;AAC1D,MAAM,OAAO,wBAAyB,SAAQ,MAAM,CAAC,SAAS;IAE5D,YAAY,EAAE,QAAQ,EAAwB;QAC5C,KAAK,CAAC,oBAAoB,QAAQ,qBAAqB,EAAE;YACvD,YAAY,EAAE,CAAC,0CAA0C,CAAC;SAC3D,CAAC,CAAA;QAJc;;;;mBAAO,iCAAiC;WAAA;IAK1D,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,QAAgB;IACxC,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,MAAM;QAAE,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC7E,MAAM,IAAI,wBAAwB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;AAClD,CAAC"}
@@ -517,18 +517,17 @@ export * as VirtualMaster from './VirtualMaster.js';
517
517
  /**
518
518
  * Zone ID utilities for converting between zone IDs and zone chain IDs.
519
519
  *
520
- * Zone chain IDs are deterministically derived from zone IDs using the formula
521
- * `421_700_000 + zoneId`. This module provides helpers to convert between them.
520
+ * Zone chain IDs use the base and range assigned to their Tempo source chain.
522
521
  *
523
522
  * @example
524
523
  * ```ts twoslash
525
524
  * import { ZoneId } from 'ox/tempo'
526
525
  *
527
- * const zoneId = ZoneId.fromChainId(421_700_026)
528
- * // @log: 26
526
+ * const zoneId = ZoneId.fromChainId(421_700_001)
527
+ * // @log: 1
529
528
  *
530
- * const chainId = ZoneId.toChainId(26)
531
- * // @log: 421700026
529
+ * const chainId = ZoneId.toChainId(1)
530
+ * // @log: 421700001
532
531
  * ```
533
532
  *
534
533
  * @category Reference
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;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3 +1,3 @@
1
1
  /** @internal */
2
- export const version = '0.14.32';
2
+ export const version = '0.14.33';
3
3
  //# sourceMappingURL=version.js.map
@@ -1,50 +1,68 @@
1
- import type * as Errors from '../core/Errors.js';
1
+ import * as Errors from '../core/Errors.js';
2
+ declare const chainIdConfig: {
3
+ readonly 4217: {
4
+ readonly base: 421700000;
5
+ readonly range: 1002610000;
6
+ };
7
+ readonly 42431: {
8
+ readonly base: 1424310000;
9
+ readonly range: 723173648;
10
+ };
11
+ };
2
12
  /**
3
- * Base offset for deriving zone chain IDs.
4
- *
5
- * Zone chain IDs are computed as `chainIdBase + zoneId`.
13
+ * Base offset for deriving Presto zone chain IDs.
6
14
  */
7
- export declare const chainIdBase: 4217000000;
15
+ export declare const chainIdBase: 421700000;
16
+ /** Tempo source chain ID. */
17
+ export type SourceId = keyof typeof chainIdConfig;
8
18
  /**
9
19
  * Derives a zone ID from a zone chain ID.
10
20
  *
11
- * Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so a chain ID
12
- * of `4217000006` corresponds to zone ID `6`.
21
+ * Zone chain IDs use the base assigned to their Tempo source chain.
13
22
  *
14
23
  * @example
15
24
  * ```ts twoslash
16
25
  * import { ZoneId } from 'ox/tempo'
17
26
  *
18
- * const zoneId = ZoneId.fromChainId(4_217_000_006)
19
- * // @log: 6
27
+ * const zoneId = ZoneId.fromChainId(421_700_001)
28
+ * // @log: 1
20
29
  * ```
21
30
  *
22
31
  * @param chainId - The zone chain ID.
32
+ * @param sourceId - The Tempo source chain ID. Defaults to `4217` (Presto).
23
33
  * @returns The zone ID.
24
34
  */
25
- export declare function fromChainId(chainId: number): number;
35
+ export declare function fromChainId(chainId: number, sourceId?: SourceId): number;
26
36
  export declare namespace fromChainId {
27
- type ErrorType = Errors.GlobalErrorType;
37
+ type ErrorType = typeof UnsupportedSourceIdError | Errors.GlobalErrorType;
28
38
  }
29
39
  /**
30
40
  * Derives a zone chain ID from a zone ID.
31
41
  *
32
- * Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so zone ID
33
- * `6` corresponds to chain ID `4217000006`.
42
+ * Zone chain IDs use the base and range assigned to their Tempo source chain.
34
43
  *
35
44
  * @example
36
45
  * ```ts twoslash
37
46
  * import { ZoneId } from 'ox/tempo'
38
47
  *
39
- * const chainId = ZoneId.toChainId(6)
40
- * // @log: 4217000006
48
+ * const chainId = ZoneId.toChainId(1)
49
+ * // @log: 421700001
41
50
  * ```
42
51
  *
43
52
  * @param zoneId - The zone ID.
53
+ * @param sourceId - The Tempo source chain ID. Defaults to `4217` (Presto).
44
54
  * @returns The zone chain ID.
45
55
  */
46
- export declare function toChainId(zoneId: number): number;
56
+ export declare function toChainId(zoneId: number, sourceId?: SourceId): number;
47
57
  export declare namespace toChainId {
48
- type ErrorType = Errors.GlobalErrorType;
58
+ type ErrorType = typeof UnsupportedSourceIdError | Errors.GlobalErrorType;
59
+ }
60
+ /** Thrown when a Tempo source chain ID is unsupported. */
61
+ export declare class UnsupportedSourceIdError extends Errors.BaseError {
62
+ readonly name = "ZoneId.UnsupportedSourceIdError";
63
+ constructor({ sourceId }: {
64
+ sourceId: number;
65
+ });
49
66
  }
67
+ export {};
50
68
  //# sourceMappingURL=ZoneId.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ZoneId.d.ts","sourceRoot":"","sources":["../../tempo/ZoneId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD;;;;GAIG;AACH,eAAO,MAAM,WAAW,YAAyB,CAAA;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,MAAM,CAAC,OAAO,WAAW,WAAW,CAAC;IACnC,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC"}
1
+ {"version":3,"file":"ZoneId.d.ts","sourceRoot":"","sources":["../../tempo/ZoneId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAE3C,QAAA,MAAM,aAAa;;;;;;;;;CAST,CAAA;AAIV;;GAEG;AACH,eAAO,MAAM,WAAW,WAAsC,CAAA;AAE9D,6BAA6B;AAC7B,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,aAAa,CAAA;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,QAA0B,GACnC,MAAM,CAER;AAED,MAAM,CAAC,OAAO,WAAW,WAAW,CAAC;IACnC,KAAK,SAAS,GAAG,OAAO,wBAAwB,GAAG,MAAM,CAAC,eAAe,CAAA;CAC1E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,QAA0B,GACnC,MAAM,CAGR;AAED,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,KAAK,SAAS,GAAG,OAAO,wBAAwB,GAAG,MAAM,CAAC,eAAe,CAAA;CAC1E;AAED,0DAA0D;AAC1D,qBAAa,wBAAyB,SAAQ,MAAM,CAAC,SAAS;IAC5D,SAAkB,IAAI,qCAAoC;gBAC9C,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE;CAK/C"}
@@ -519,18 +519,17 @@ export * as VirtualMaster from './VirtualMaster.js';
519
519
  /**
520
520
  * Zone ID utilities for converting between zone IDs and zone chain IDs.
521
521
  *
522
- * Zone chain IDs are deterministically derived from zone IDs using the formula
523
- * `421_700_000 + zoneId`. This module provides helpers to convert between them.
522
+ * Zone chain IDs use the base and range assigned to their Tempo source chain.
524
523
  *
525
524
  * @example
526
525
  * ```ts twoslash
527
526
  * import { ZoneId } from 'ox/tempo'
528
527
  *
529
- * const zoneId = ZoneId.fromChainId(421_700_026)
530
- * // @log: 26
528
+ * const zoneId = ZoneId.fromChainId(421_700_001)
529
+ * // @log: 1
531
530
  *
532
- * const chainId = ZoneId.toChainId(26)
533
- * // @log: 421700026
531
+ * const chainId = ZoneId.toChainId(1)
532
+ * // @log: 421700001
534
533
  * ```
535
534
  *
536
535
  * @category Reference
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,YAAY,EAAE,CAAA;AAEd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AACzD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,oBAAoB,MAAM,2BAA2B,CAAA;AACjE;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAA"}
@@ -1,3 +1,3 @@
1
1
  /** @internal */
2
- export declare const version = "0.14.32";
2
+ export declare const version = "0.14.33";
3
3
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ox",
3
3
  "description": "Ethereum Standard Library",
4
- "version": "0.14.32",
4
+ "version": "0.14.33",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -608,6 +608,11 @@
608
608
  "import": "./_esm/tempo/VirtualMaster.js",
609
609
  "default": "./_cjs/tempo/VirtualMaster.js"
610
610
  },
611
+ "./tempo/ZoneId.test-d": {
612
+ "types": "./_types/tempo/ZoneId.test-d.d.ts",
613
+ "import": "./_esm/tempo/ZoneId.test-d.js",
614
+ "default": "./_cjs/tempo/ZoneId.test-d.js"
615
+ },
611
616
  "./tempo/ZoneId": {
612
617
  "types": "./_types/tempo/ZoneId.d.ts",
613
618
  "import": "./_esm/tempo/ZoneId.js",
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/tempo/ZoneId.test-d.d.ts",
4
+ "main": "../../_cjs/tempo/ZoneId.test-d.js",
5
+ "module": "../../_esm/tempo/ZoneId.test-d.js"
6
+ }
@@ -0,0 +1,16 @@
1
+ import { expectTypeOf, test } from 'vitest'
2
+ import * as ZoneId from './ZoneId.js'
3
+
4
+ test('accepts supported source IDs', () => {
5
+ expectTypeOf(ZoneId.fromChainId(421_700_001)).toEqualTypeOf<number>()
6
+ expectTypeOf(
7
+ ZoneId.fromChainId(1_424_310_001, 42_431),
8
+ ).toEqualTypeOf<number>()
9
+ expectTypeOf(ZoneId.toChainId(1)).toEqualTypeOf<number>()
10
+ expectTypeOf(ZoneId.toChainId(1, 42_431)).toEqualTypeOf<number>()
11
+
12
+ // @ts-expect-error Unsupported source ID.
13
+ ZoneId.fromChainId(421_700_001, 1)
14
+ // @ts-expect-error Unsupported source ID.
15
+ ZoneId.toChainId(1, 1)
16
+ })
@@ -3,40 +3,75 @@ import * as ZoneId from './ZoneId.js'
3
3
 
4
4
  describe('fromChainId', () => {
5
5
  test('default', () => {
6
- expect(ZoneId.fromChainId(4_217_000_006)).toBe(6)
6
+ expect(ZoneId.chainIdBase).toMatchInlineSnapshot(`421700000`)
7
+ expect(ZoneId.fromChainId(421_700_001)).toMatchInlineSnapshot(`1`)
7
8
  })
8
9
 
9
- test('zone 1', () => {
10
- expect(ZoneId.fromChainId(4_217_000_001)).toBe(1)
10
+ test('Moderato', () => {
11
+ expect(ZoneId.fromChainId(1_424_310_028, 42_431)).toMatchInlineSnapshot(
12
+ `28`,
13
+ )
11
14
  })
12
15
 
13
- test('zone 28', () => {
14
- expect(ZoneId.fromChainId(4_217_000_028)).toBe(28)
16
+ test('unsupported source id', () => {
17
+ expect(() =>
18
+ // @ts-expect-error Unsupported source ID.
19
+ ZoneId.fromChainId(421_700_001, 1),
20
+ ).toThrowErrorMatchingInlineSnapshot(`
21
+ [ZoneId.UnsupportedSourceIdError: Source chain ID "1" is not supported.
22
+
23
+ Supported source chain IDs: 4217, 42431.]
24
+ `)
15
25
  })
16
26
  })
17
27
 
18
28
  describe('toChainId', () => {
19
29
  test('default', () => {
20
- expect(ZoneId.toChainId(6)).toBe(4_217_000_006)
30
+ expect(ZoneId.toChainId(1)).toMatchInlineSnapshot(`421700001`)
31
+ })
32
+
33
+ test('Moderato', () => {
34
+ expect(ZoneId.toChainId(28, 42_431)).toMatchInlineSnapshot(`1424310028`)
21
35
  })
22
36
 
23
- test('zone 1', () => {
24
- expect(ZoneId.toChainId(1)).toBe(4_217_000_001)
37
+ test('wraps within the source chain range', () => {
38
+ expect(ZoneId.toChainId(1_002_610_001)).toMatchInlineSnapshot(`421700001`)
39
+ expect(ZoneId.toChainId(723_173_649, 42_431)).toMatchInlineSnapshot(
40
+ `1424310001`,
41
+ )
25
42
  })
26
43
 
27
- test('zone 28', () => {
28
- expect(ZoneId.toChainId(28)).toBe(4_217_000_028)
44
+ test('unsupported source id', () => {
45
+ expect(() =>
46
+ // @ts-expect-error Unsupported source ID.
47
+ ZoneId.toChainId(1, 1),
48
+ ).toThrowErrorMatchingInlineSnapshot(`
49
+ [ZoneId.UnsupportedSourceIdError: Source chain ID "1" is not supported.
50
+
51
+ Supported source chain IDs: 4217, 42431.]
52
+ `)
29
53
  })
30
54
  })
31
55
 
32
56
  describe('roundtrip', () => {
33
57
  test('fromChainId → toChainId', () => {
34
- const chainId = 4_217_000_006
35
- expect(ZoneId.toChainId(ZoneId.fromChainId(chainId))).toBe(chainId)
58
+ const chainId = 421_700_006
59
+ expect(ZoneId.toChainId(ZoneId.fromChainId(chainId))).toMatchInlineSnapshot(
60
+ `421700006`,
61
+ )
36
62
  })
37
63
 
38
64
  test('toChainId → fromChainId', () => {
39
65
  const zoneId = 42
40
- expect(ZoneId.fromChainId(ZoneId.toChainId(zoneId))).toBe(zoneId)
66
+ expect(ZoneId.fromChainId(ZoneId.toChainId(zoneId))).toMatchInlineSnapshot(
67
+ `42`,
68
+ )
69
+ })
70
+
71
+ test('Moderato', () => {
72
+ const zoneId = 42
73
+ const sourceId = 42_431
74
+ const chainId = ZoneId.toChainId(zoneId, sourceId)
75
+ expect(ZoneId.fromChainId(chainId, sourceId)).toMatchInlineSnapshot(`42`)
41
76
  })
42
77
  })
package/tempo/ZoneId.ts CHANGED
@@ -1,58 +1,94 @@
1
- import type * as Errors from '../core/Errors.js'
1
+ import * as Errors from '../core/Errors.js'
2
+
3
+ const chainIdConfig = {
4
+ 4217: {
5
+ base: 421_700_000,
6
+ range: 1_002_610_000,
7
+ },
8
+ 42431: {
9
+ base: 1_424_310_000,
10
+ range: 723_173_648,
11
+ },
12
+ } as const
13
+
14
+ const defaultSourceId = 4_217
2
15
 
3
16
  /**
4
- * Base offset for deriving zone chain IDs.
5
- *
6
- * Zone chain IDs are computed as `chainIdBase + zoneId`.
17
+ * Base offset for deriving Presto zone chain IDs.
7
18
  */
8
- export const chainIdBase = 4_217_000_000 as const
19
+ export const chainIdBase = chainIdConfig[defaultSourceId].base
20
+
21
+ /** Tempo source chain ID. */
22
+ export type SourceId = keyof typeof chainIdConfig
9
23
 
10
24
  /**
11
25
  * Derives a zone ID from a zone chain ID.
12
26
  *
13
- * Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so a chain ID
14
- * of `4217000006` corresponds to zone ID `6`.
27
+ * Zone chain IDs use the base assigned to their Tempo source chain.
15
28
  *
16
29
  * @example
17
30
  * ```ts twoslash
18
31
  * import { ZoneId } from 'ox/tempo'
19
32
  *
20
- * const zoneId = ZoneId.fromChainId(4_217_000_006)
21
- * // @log: 6
33
+ * const zoneId = ZoneId.fromChainId(421_700_001)
34
+ * // @log: 1
22
35
  * ```
23
36
  *
24
37
  * @param chainId - The zone chain ID.
38
+ * @param sourceId - The Tempo source chain ID. Defaults to `4217` (Presto).
25
39
  * @returns The zone ID.
26
40
  */
27
- export function fromChainId(chainId: number): number {
28
- return chainId - chainIdBase
41
+ export function fromChainId(
42
+ chainId: number,
43
+ sourceId: SourceId = defaultSourceId,
44
+ ): number {
45
+ return chainId - getChainIdConfig(sourceId).base
29
46
  }
30
47
 
31
48
  export declare namespace fromChainId {
32
- type ErrorType = Errors.GlobalErrorType
49
+ type ErrorType = typeof UnsupportedSourceIdError | Errors.GlobalErrorType
33
50
  }
34
51
 
35
52
  /**
36
53
  * Derives a zone chain ID from a zone ID.
37
54
  *
38
- * Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so zone ID
39
- * `6` corresponds to chain ID `4217000006`.
55
+ * Zone chain IDs use the base and range assigned to their Tempo source chain.
40
56
  *
41
57
  * @example
42
58
  * ```ts twoslash
43
59
  * import { ZoneId } from 'ox/tempo'
44
60
  *
45
- * const chainId = ZoneId.toChainId(6)
46
- * // @log: 4217000006
61
+ * const chainId = ZoneId.toChainId(1)
62
+ * // @log: 421700001
47
63
  * ```
48
64
  *
49
65
  * @param zoneId - The zone ID.
66
+ * @param sourceId - The Tempo source chain ID. Defaults to `4217` (Presto).
50
67
  * @returns The zone chain ID.
51
68
  */
52
- export function toChainId(zoneId: number): number {
53
- return chainIdBase + zoneId
69
+ export function toChainId(
70
+ zoneId: number,
71
+ sourceId: SourceId = defaultSourceId,
72
+ ): number {
73
+ const { base, range } = getChainIdConfig(sourceId)
74
+ return base + (zoneId % range)
54
75
  }
55
76
 
56
77
  export declare namespace toChainId {
57
- type ErrorType = Errors.GlobalErrorType
78
+ type ErrorType = typeof UnsupportedSourceIdError | Errors.GlobalErrorType
79
+ }
80
+
81
+ /** Thrown when a Tempo source chain ID is unsupported. */
82
+ export class UnsupportedSourceIdError extends Errors.BaseError {
83
+ override readonly name = 'ZoneId.UnsupportedSourceIdError'
84
+ constructor({ sourceId }: { sourceId: number }) {
85
+ super(`Source chain ID "${sourceId}" is not supported.`, {
86
+ metaMessages: ['Supported source chain IDs: 4217, 42431.'],
87
+ })
88
+ }
89
+ }
90
+
91
+ function getChainIdConfig(sourceId: number) {
92
+ if (sourceId === 4_217 || sourceId === 42_431) return chainIdConfig[sourceId]
93
+ throw new UnsupportedSourceIdError({ sourceId })
58
94
  }
package/tempo/index.ts CHANGED
@@ -524,18 +524,17 @@ export * as VirtualMaster from './VirtualMaster.js'
524
524
  /**
525
525
  * Zone ID utilities for converting between zone IDs and zone chain IDs.
526
526
  *
527
- * Zone chain IDs are deterministically derived from zone IDs using the formula
528
- * `421_700_000 + zoneId`. This module provides helpers to convert between them.
527
+ * Zone chain IDs use the base and range assigned to their Tempo source chain.
529
528
  *
530
529
  * @example
531
530
  * ```ts twoslash
532
531
  * import { ZoneId } from 'ox/tempo'
533
532
  *
534
- * const zoneId = ZoneId.fromChainId(421_700_026)
535
- * // @log: 26
533
+ * const zoneId = ZoneId.fromChainId(421_700_001)
534
+ * // @log: 1
536
535
  *
537
- * const chainId = ZoneId.toChainId(26)
538
- * // @log: 421700026
536
+ * const chainId = ZoneId.toChainId(1)
537
+ * // @log: 421700001
539
538
  * ```
540
539
  *
541
540
  * @category Reference
package/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '0.14.32'
2
+ export const version = '0.14.33'