ox 1.0.4 → 1.0.5
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 +12 -0
- package/dist/tempo/ZoneId.d.ts +35 -17
- package/dist/tempo/ZoneId.d.ts.map +1 -1
- package/dist/tempo/ZoneId.js +41 -16
- package/dist/tempo/ZoneId.js.map +1 -1
- package/dist/tempo/index.d.ts +5 -6
- package/dist/tempo/index.d.ts.map +1 -1
- package/dist/tempo/index.js +5 -6
- package/dist/tempo/index.js.map +1 -1
- package/package.json +1 -1
- package/src/tempo/ZoneId.test-d.ts +16 -0
- package/src/tempo/ZoneId.test.ts +48 -13
- package/src/tempo/ZoneId.ts +55 -19
- package/src/tempo/index.ts +5 -6
- package/src/version.ts +1 -1
- package/src/zod/tempo/_test/ZoneId.test.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# ox
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#314](https://github.com/wevm/ox/pull/314) [`b179677`](https://github.com/wevm/ox/commit/b17967709e4f88a1925e865e3a86fa1040e9ff15) 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
|
## 1.0.4
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/tempo/ZoneId.d.ts
CHANGED
|
@@ -1,50 +1,68 @@
|
|
|
1
|
-
import
|
|
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:
|
|
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
|
|
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(
|
|
19
|
-
* // @log:
|
|
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
|
|
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(
|
|
40
|
-
* // @log:
|
|
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":["../../src/tempo/ZoneId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ZoneId.d.ts","sourceRoot":"","sources":["../../src/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"}
|
package/dist/tempo/ZoneId.js
CHANGED
|
@@ -1,47 +1,72 @@
|
|
|
1
|
+
import * as Errors from '../core/Errors.js';
|
|
2
|
+
const chainIdConfig = {
|
|
3
|
+
4_217: {
|
|
4
|
+
base: 421_700_000,
|
|
5
|
+
range: 1_002_610_000,
|
|
6
|
+
},
|
|
7
|
+
42_431: {
|
|
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 =
|
|
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
|
|
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(
|
|
18
|
-
* // @log:
|
|
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 -
|
|
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
|
|
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(
|
|
38
|
-
* // @log:
|
|
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
|
-
|
|
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
|
+
name = 'ZoneId.UnsupportedSourceIdError';
|
|
61
|
+
constructor({ sourceId }) {
|
|
62
|
+
super(`Source chain ID "${sourceId}" is not supported.`, {
|
|
63
|
+
metaMessages: ['Supported source chain IDs: 4217, 42431.'],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function getChainIdConfig(sourceId) {
|
|
68
|
+
if (sourceId === 4_217 || sourceId === 42_431)
|
|
69
|
+
return chainIdConfig[sourceId];
|
|
70
|
+
throw new UnsupportedSourceIdError({ sourceId });
|
|
46
71
|
}
|
|
47
72
|
//# sourceMappingURL=ZoneId.js.map
|
package/dist/tempo/ZoneId.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZoneId.js","sourceRoot":"","sources":["../../src/tempo/ZoneId.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ZoneId.js","sourceRoot":"","sources":["../../src/tempo/ZoneId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAE3C,MAAM,aAAa,GAAG;IACpB,KAAK,EAAE;QACL,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,aAAa;KACrB;IACD,MAAM,EAAE;QACN,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;IAC1C,IAAI,GAAG,iCAAiC,CAAA;IAC1D,YAAY,EAAE,QAAQ,EAAwB;QAC5C,KAAK,CAAC,oBAAoB,QAAQ,qBAAqB,EAAE;YACvD,YAAY,EAAE,CAAC,0CAA0C,CAAC;SAC3D,CAAC,CAAA;IACJ,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"}
|
package/dist/tempo/index.d.ts
CHANGED
|
@@ -527,18 +527,17 @@ export * as VirtualMaster from './VirtualMaster.js';
|
|
|
527
527
|
/**
|
|
528
528
|
* Zone ID utilities for converting between zone IDs and zone chain IDs.
|
|
529
529
|
*
|
|
530
|
-
* Zone chain IDs
|
|
531
|
-
* `421_700_000 + zoneId`. This module provides helpers to convert between them.
|
|
530
|
+
* Zone chain IDs use the base and range assigned to their Tempo source chain.
|
|
532
531
|
*
|
|
533
532
|
* @example
|
|
534
533
|
* ```ts twoslash
|
|
535
534
|
* import { ZoneId } from 'ox/tempo'
|
|
536
535
|
*
|
|
537
|
-
* const zoneId = ZoneId.fromChainId(
|
|
538
|
-
* // @log:
|
|
536
|
+
* const zoneId = ZoneId.fromChainId(421_700_001)
|
|
537
|
+
* // @log: 1
|
|
539
538
|
*
|
|
540
|
-
* const chainId = ZoneId.toChainId(
|
|
541
|
-
* // @log:
|
|
539
|
+
* const chainId = ZoneId.toChainId(1)
|
|
540
|
+
* // @log: 421700001
|
|
542
541
|
* ```
|
|
543
542
|
*
|
|
544
543
|
* @category Reference
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tempo/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAGhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACr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sBAAsB,CAAA;AACvD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAA"}
|
package/dist/tempo/index.js
CHANGED
|
@@ -528,18 +528,17 @@ export * as VirtualMaster from './VirtualMaster.js';
|
|
|
528
528
|
/**
|
|
529
529
|
* Zone ID utilities for converting between zone IDs and zone chain IDs.
|
|
530
530
|
*
|
|
531
|
-
* Zone chain IDs
|
|
532
|
-
* `421_700_000 + zoneId`. This module provides helpers to convert between them.
|
|
531
|
+
* Zone chain IDs use the base and range assigned to their Tempo source chain.
|
|
533
532
|
*
|
|
534
533
|
* @example
|
|
535
534
|
* ```ts twoslash
|
|
536
535
|
* import { ZoneId } from 'ox/tempo'
|
|
537
536
|
*
|
|
538
|
-
* const zoneId = ZoneId.fromChainId(
|
|
539
|
-
* // @log:
|
|
537
|
+
* const zoneId = ZoneId.fromChainId(421_700_001)
|
|
538
|
+
* // @log: 1
|
|
540
539
|
*
|
|
541
|
-
* const chainId = ZoneId.toChainId(
|
|
542
|
-
* // @log:
|
|
540
|
+
* const chainId = ZoneId.toChainId(1)
|
|
541
|
+
* // @log: 421700001
|
|
543
542
|
* ```
|
|
544
543
|
*
|
|
545
544
|
* @category Reference
|
package/dist/tempo/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tempo/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,2DAA2D;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAC3D;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAA"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { expectTypeOf, test } from 'vp/test'
|
|
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
|
+
})
|
package/src/tempo/ZoneId.test.ts
CHANGED
|
@@ -3,40 +3,75 @@ import * as ZoneId from './ZoneId.js'
|
|
|
3
3
|
|
|
4
4
|
describe('fromChainId', () => {
|
|
5
5
|
test('default', () => {
|
|
6
|
-
expect(ZoneId.
|
|
6
|
+
expect(ZoneId.chainIdBase).toMatchInlineSnapshot(`421700000`)
|
|
7
|
+
expect(ZoneId.fromChainId(421_700_001)).toMatchInlineSnapshot(`1`)
|
|
7
8
|
})
|
|
8
9
|
|
|
9
|
-
test('
|
|
10
|
-
expect(ZoneId.fromChainId(
|
|
10
|
+
test('Moderato', () => {
|
|
11
|
+
expect(ZoneId.fromChainId(1_424_310_028, 42_431)).toMatchInlineSnapshot(
|
|
12
|
+
`28`,
|
|
13
|
+
)
|
|
11
14
|
})
|
|
12
15
|
|
|
13
|
-
test('
|
|
14
|
-
expect(
|
|
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(
|
|
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('
|
|
24
|
-
expect(ZoneId.toChainId(
|
|
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('
|
|
28
|
-
expect(
|
|
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 =
|
|
35
|
-
expect(ZoneId.toChainId(ZoneId.fromChainId(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))).
|
|
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/src/tempo/ZoneId.ts
CHANGED
|
@@ -1,58 +1,94 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Errors from '../core/Errors.js'
|
|
2
|
+
|
|
3
|
+
const chainIdConfig = {
|
|
4
|
+
4_217: {
|
|
5
|
+
base: 421_700_000,
|
|
6
|
+
range: 1_002_610_000,
|
|
7
|
+
},
|
|
8
|
+
42_431: {
|
|
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 =
|
|
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
|
|
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(
|
|
21
|
-
* // @log:
|
|
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(
|
|
28
|
-
|
|
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
|
|
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(
|
|
46
|
-
* // @log:
|
|
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(
|
|
53
|
-
|
|
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/src/tempo/index.ts
CHANGED
|
@@ -532,18 +532,17 @@ export * as VirtualMaster from './VirtualMaster.js'
|
|
|
532
532
|
/**
|
|
533
533
|
* Zone ID utilities for converting between zone IDs and zone chain IDs.
|
|
534
534
|
*
|
|
535
|
-
* Zone chain IDs
|
|
536
|
-
* `421_700_000 + zoneId`. This module provides helpers to convert between them.
|
|
535
|
+
* Zone chain IDs use the base and range assigned to their Tempo source chain.
|
|
537
536
|
*
|
|
538
537
|
* @example
|
|
539
538
|
* ```ts twoslash
|
|
540
539
|
* import { ZoneId } from 'ox/tempo'
|
|
541
540
|
*
|
|
542
|
-
* const zoneId = ZoneId.fromChainId(
|
|
543
|
-
* // @log:
|
|
541
|
+
* const zoneId = ZoneId.fromChainId(421_700_001)
|
|
542
|
+
* // @log: 1
|
|
544
543
|
*
|
|
545
|
-
* const chainId = ZoneId.toChainId(
|
|
546
|
-
* // @log:
|
|
544
|
+
* const chainId = ZoneId.toChainId(1)
|
|
545
|
+
* // @log: 421700001
|
|
547
546
|
* ```
|
|
548
547
|
*
|
|
549
548
|
* @category Reference
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '1.0.
|
|
2
|
+
export const version = '1.0.5'
|
|
@@ -11,7 +11,7 @@ describe('ZoneId', () => {
|
|
|
11
11
|
})
|
|
12
12
|
|
|
13
13
|
test('decodes and encodes chain ids', () => {
|
|
14
|
-
expect(z.decode(z_ZoneId.chainId,
|
|
15
|
-
expect(z.encode(z_ZoneId.chainId,
|
|
14
|
+
expect(z.decode(z_ZoneId.chainId, 421_700_001)).toMatchInlineSnapshot(`1`)
|
|
15
|
+
expect(z.encode(z_ZoneId.chainId, 1)).toMatchInlineSnapshot(`421700001`)
|
|
16
16
|
})
|
|
17
17
|
})
|