ox 1.0.3 → 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 CHANGED
@@ -1,5 +1,23 @@
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
+
15
+ ## 1.0.4
16
+
17
+ ### Patch Changes
18
+
19
+ - [#312](https://github.com/wevm/ox/pull/312) [`d7721a1`](https://github.com/wevm/ox/commit/d7721a16276e584080a3a0bde23ce2b28aff5a42) Thanks [@jxom](https://github.com/jxom)! - Added `EarnShares` utilities for Tempo vault share conversions, fee share calculation, and slippage bounds.
20
+
3
21
  ## 1.0.3
4
22
 
5
23
  ### Patch Changes
@@ -0,0 +1,179 @@
1
+ import * as Errors from '../core/Errors.js';
2
+ /** Basis-point denominator used by slippage bounds. */
3
+ export declare const basisPointScale = 10000;
4
+ /**
5
+ * Tempo Earn `VaultAdapter` conversion anchor.
6
+ *
7
+ * The adapter prices vault shares against venue shares through this pair:
8
+ * `engineShares` venue shares are worth `shareSupply` vault shares. It is initialised
9
+ * 1:1 and restated on `contribute` and `migrateEngine`.
10
+ *
11
+ * These conversions are raw and fee-blind; they ignore pending fee dilution
12
+ * and are unsuitable for user-facing value (use the adapter's `previewRedeem`).
13
+ */
14
+ export type Anchor = {
15
+ /** Venue shares held by the engine at the anchor point. */
16
+ engineShares: bigint;
17
+ /** Vault share supply at the anchor point. */
18
+ shareSupply: bigint;
19
+ };
20
+ /**
21
+ * Converts venue shares to a vault share amount at the anchor rate, rounding down.
22
+ *
23
+ * Mirrors `VaultAdapter.sharesToTokens`.
24
+ *
25
+ * @example
26
+ * ```ts twoslash
27
+ * import { EarnShares } from 'ox/tempo'
28
+ *
29
+ * const shareAmount = EarnShares.toAmount(
30
+ * { engineShares: 3n, shareSupply: 2n },
31
+ * 7n
32
+ * )
33
+ * // @log: 4n
34
+ * ```
35
+ *
36
+ * @param anchor - The conversion anchor.
37
+ * @param venueShareAmount - Venue share amount, base units.
38
+ * @returns Vault share amount, rounded down.
39
+ */
40
+ export declare function toAmount(anchor: Anchor, venueShareAmount: bigint): bigint;
41
+ export declare namespace toAmount {
42
+ type ErrorType = Errors.GlobalErrorType;
43
+ }
44
+ /**
45
+ * Converts venue shares to a vault share amount at the anchor rate, rounding up.
46
+ *
47
+ * Mirrors the adapter's ceiling conversion used by exact-asset exits.
48
+ *
49
+ * @example
50
+ * ```ts twoslash
51
+ * import { EarnShares } from 'ox/tempo'
52
+ *
53
+ * const shareAmount = EarnShares.toAmountUp(
54
+ * { engineShares: 3n, shareSupply: 2n },
55
+ * 7n
56
+ * )
57
+ * // @log: 5n
58
+ * ```
59
+ *
60
+ * @param anchor - The conversion anchor.
61
+ * @param venueShareAmount - Venue share amount, base units.
62
+ * @returns Vault share amount, rounded up.
63
+ */
64
+ export declare function toAmountUp(anchor: Anchor, venueShareAmount: bigint): bigint;
65
+ export declare namespace toAmountUp {
66
+ type ErrorType = Errors.GlobalErrorType;
67
+ }
68
+ /**
69
+ * Converts a vault share amount to venue shares at the anchor rate, rounding down.
70
+ *
71
+ * Mirrors `VaultAdapter.tokensToShares`.
72
+ *
73
+ * @example
74
+ * ```ts twoslash
75
+ * import { EarnShares } from 'ox/tempo'
76
+ *
77
+ * const venueShareAmount = EarnShares.toVenueAmount(
78
+ * { engineShares: 3n, shareSupply: 2n },
79
+ * 7n
80
+ * )
81
+ * // @log: 10n
82
+ * ```
83
+ *
84
+ * @param anchor - The conversion anchor.
85
+ * @param shareAmount - Vault share amount, base units.
86
+ * @returns Venue share amount, rounded down.
87
+ */
88
+ export declare function toVenueAmount(anchor: Anchor, shareAmount: bigint): bigint;
89
+ export declare namespace toVenueAmount {
90
+ type ErrorType = Errors.GlobalErrorType;
91
+ }
92
+ /**
93
+ * Computes the dilution-correct vault shares minted for an asset-denominated fee.
94
+ *
95
+ * Mirrors `FeeMath`:
96
+ * `feeShares = floor(fee * shareSupply / (activeAssets - fee))`, zero when the
97
+ * fee is zero or not smaller than the active assets. Minting this amount to the
98
+ * fee ledger prices the fee at post-mint value per share.
99
+ *
100
+ * @example
101
+ * ```ts twoslash
102
+ * import { EarnShares } from 'ox/tempo'
103
+ *
104
+ * const shares = EarnShares.feeShares({
105
+ * activeAssets: 1_100n,
106
+ * shareSupply: 1_000n,
107
+ * totalFeeAssets: 100n
108
+ * })
109
+ * // @log: 100n
110
+ * ```
111
+ *
112
+ * @param options - Fee accrual inputs.
113
+ * @returns Vault shares to mint for the fee, rounded down.
114
+ */
115
+ export declare function feeShares(options: feeShares.Options): bigint;
116
+ export declare namespace feeShares {
117
+ type Options = {
118
+ /** Assets backing the active (non-queued) supply, base units. */
119
+ activeAssets: bigint;
120
+ /** Active vault share supply, base units. */
121
+ shareSupply: bigint;
122
+ /** Total fee liability in asset units. */
123
+ totalFeeAssets: bigint;
124
+ };
125
+ type ErrorType = Errors.GlobalErrorType;
126
+ }
127
+ /**
128
+ * Lowers an expected output by a basis-point slippage tolerance, flooring to `1n`.
129
+ *
130
+ * Suitable for lower bounds such as a deposit's minimum shares or a redeem's
131
+ * minimum assets; not for upper bounds such as an exact withdrawal's maximum
132
+ * shares.
133
+ *
134
+ * @example
135
+ * ```ts twoslash
136
+ * import { EarnShares } from 'ox/tempo'
137
+ *
138
+ * const minimumShares = EarnShares.minimumOutput(
139
+ * 1_000_000n,
140
+ * 50
141
+ * )
142
+ * // @log: 995_000n
143
+ * ```
144
+ *
145
+ * @param expectedAmount - Expected output in base units.
146
+ * @param slippageBps - Allowed slippage in basis points from `0` through `9_999`.
147
+ * @returns The minimum accepted output, floored to `1n`.
148
+ * @throws `InvalidExpectedOutputError` when `expectedAmount` is not positive.
149
+ * @throws `InvalidSlippageError` when `slippageBps` is outside its valid range.
150
+ */
151
+ export declare function minimumOutput(expectedAmount: bigint, slippageBps: number): bigint;
152
+ export declare namespace minimumOutput {
153
+ type ErrorType = InvalidExpectedOutputError | InvalidSlippageError | Errors.GlobalErrorType;
154
+ }
155
+ /**
156
+ * Error thrown when an expected output is not positive.
157
+ */
158
+ export declare class InvalidExpectedOutputError extends Errors.BaseError {
159
+ readonly name = "EarnShares.InvalidExpectedOutputError";
160
+ constructor(options: InvalidExpectedOutputError.Options);
161
+ }
162
+ export declare namespace InvalidExpectedOutputError {
163
+ type Options = {
164
+ expectedAmount: bigint;
165
+ };
166
+ }
167
+ /**
168
+ * Error thrown when a slippage tolerance is not an integer from `0` through `9_999`.
169
+ */
170
+ export declare class InvalidSlippageError extends Errors.BaseError {
171
+ readonly name = "EarnShares.InvalidSlippageError";
172
+ constructor(options: InvalidSlippageError.Options);
173
+ }
174
+ export declare namespace InvalidSlippageError {
175
+ type Options = {
176
+ slippageBps: number;
177
+ };
178
+ }
179
+ //# sourceMappingURL=EarnShares.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EarnShares.d.ts","sourceRoot":"","sources":["../../src/tempo/EarnShares.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAE3C,uDAAuD;AACvD,eAAO,MAAM,eAAe,QAAS,CAAA;AAErC;;;;;;;;;GASG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAA;IACpB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,MAAM,CAAC,OAAO,WAAW,QAA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,0BAA0B,CAAC,OAAO;CAKxD;AAED,MAAM,CAAC,OAAO,WAAW,0BAA0B,CAAC;IAClD,KAAY,OAAO,GAAG;QACpB,cAAc,EAAE,MAAM,CAAA;KACvB,CAAA;CACF;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,MAAM,CAAC,SAAS;IACxD,SAAkB,IAAI,qCAAoC;gBAE9C,OAAO,EAAE,oBAAoB,CAAC,OAAO;CAOlD;AAED,MAAM,CAAC,OAAO,WAAW,oBAAoB,CAAC;IAC5C,KAAY,OAAO,GAAG;QACpB,WAAW,EAAE,MAAM,CAAA;KACpB,CAAA;CACF"}
@@ -0,0 +1,160 @@
1
+ import * as Errors from '../core/Errors.js';
2
+ /** Basis-point denominator used by slippage bounds. */
3
+ export const basisPointScale = 10_000;
4
+ /**
5
+ * Converts venue shares to a vault share amount at the anchor rate, rounding down.
6
+ *
7
+ * Mirrors `VaultAdapter.sharesToTokens`.
8
+ *
9
+ * @example
10
+ * ```ts twoslash
11
+ * import { EarnShares } from 'ox/tempo'
12
+ *
13
+ * const shareAmount = EarnShares.toAmount(
14
+ * { engineShares: 3n, shareSupply: 2n },
15
+ * 7n
16
+ * )
17
+ * // @log: 4n
18
+ * ```
19
+ *
20
+ * @param anchor - The conversion anchor.
21
+ * @param venueShareAmount - Venue share amount, base units.
22
+ * @returns Vault share amount, rounded down.
23
+ */
24
+ export function toAmount(anchor, venueShareAmount) {
25
+ return (venueShareAmount * anchor.shareSupply) / anchor.engineShares;
26
+ }
27
+ /**
28
+ * Converts venue shares to a vault share amount at the anchor rate, rounding up.
29
+ *
30
+ * Mirrors the adapter's ceiling conversion used by exact-asset exits.
31
+ *
32
+ * @example
33
+ * ```ts twoslash
34
+ * import { EarnShares } from 'ox/tempo'
35
+ *
36
+ * const shareAmount = EarnShares.toAmountUp(
37
+ * { engineShares: 3n, shareSupply: 2n },
38
+ * 7n
39
+ * )
40
+ * // @log: 5n
41
+ * ```
42
+ *
43
+ * @param anchor - The conversion anchor.
44
+ * @param venueShareAmount - Venue share amount, base units.
45
+ * @returns Vault share amount, rounded up.
46
+ */
47
+ export function toAmountUp(anchor, venueShareAmount) {
48
+ const { engineShares, shareSupply } = anchor;
49
+ return (venueShareAmount * shareSupply + engineShares - 1n) / engineShares;
50
+ }
51
+ /**
52
+ * Converts a vault share amount to venue shares at the anchor rate, rounding down.
53
+ *
54
+ * Mirrors `VaultAdapter.tokensToShares`.
55
+ *
56
+ * @example
57
+ * ```ts twoslash
58
+ * import { EarnShares } from 'ox/tempo'
59
+ *
60
+ * const venueShareAmount = EarnShares.toVenueAmount(
61
+ * { engineShares: 3n, shareSupply: 2n },
62
+ * 7n
63
+ * )
64
+ * // @log: 10n
65
+ * ```
66
+ *
67
+ * @param anchor - The conversion anchor.
68
+ * @param shareAmount - Vault share amount, base units.
69
+ * @returns Venue share amount, rounded down.
70
+ */
71
+ export function toVenueAmount(anchor, shareAmount) {
72
+ return (shareAmount * anchor.engineShares) / anchor.shareSupply;
73
+ }
74
+ /**
75
+ * Computes the dilution-correct vault shares minted for an asset-denominated fee.
76
+ *
77
+ * Mirrors `FeeMath`:
78
+ * `feeShares = floor(fee * shareSupply / (activeAssets - fee))`, zero when the
79
+ * fee is zero or not smaller than the active assets. Minting this amount to the
80
+ * fee ledger prices the fee at post-mint value per share.
81
+ *
82
+ * @example
83
+ * ```ts twoslash
84
+ * import { EarnShares } from 'ox/tempo'
85
+ *
86
+ * const shares = EarnShares.feeShares({
87
+ * activeAssets: 1_100n,
88
+ * shareSupply: 1_000n,
89
+ * totalFeeAssets: 100n
90
+ * })
91
+ * // @log: 100n
92
+ * ```
93
+ *
94
+ * @param options - Fee accrual inputs.
95
+ * @returns Vault shares to mint for the fee, rounded down.
96
+ */
97
+ export function feeShares(options) {
98
+ const { activeAssets, shareSupply, totalFeeAssets } = options;
99
+ if (totalFeeAssets === 0n || totalFeeAssets >= activeAssets)
100
+ return 0n;
101
+ return (totalFeeAssets * shareSupply) / (activeAssets - totalFeeAssets);
102
+ }
103
+ /**
104
+ * Lowers an expected output by a basis-point slippage tolerance, flooring to `1n`.
105
+ *
106
+ * Suitable for lower bounds such as a deposit's minimum shares or a redeem's
107
+ * minimum assets; not for upper bounds such as an exact withdrawal's maximum
108
+ * shares.
109
+ *
110
+ * @example
111
+ * ```ts twoslash
112
+ * import { EarnShares } from 'ox/tempo'
113
+ *
114
+ * const minimumShares = EarnShares.minimumOutput(
115
+ * 1_000_000n,
116
+ * 50
117
+ * )
118
+ * // @log: 995_000n
119
+ * ```
120
+ *
121
+ * @param expectedAmount - Expected output in base units.
122
+ * @param slippageBps - Allowed slippage in basis points from `0` through `9_999`.
123
+ * @returns The minimum accepted output, floored to `1n`.
124
+ * @throws `InvalidExpectedOutputError` when `expectedAmount` is not positive.
125
+ * @throws `InvalidSlippageError` when `slippageBps` is outside its valid range.
126
+ */
127
+ export function minimumOutput(expectedAmount, slippageBps) {
128
+ if (expectedAmount <= 0n)
129
+ throw new InvalidExpectedOutputError({ expectedAmount });
130
+ if (!Number.isInteger(slippageBps) ||
131
+ slippageBps < 0 ||
132
+ slippageBps >= basisPointScale)
133
+ throw new InvalidSlippageError({ slippageBps });
134
+ const scale = BigInt(basisPointScale);
135
+ const bounded = (expectedAmount * (scale - BigInt(slippageBps))) / scale;
136
+ return bounded === 0n ? 1n : bounded;
137
+ }
138
+ /**
139
+ * Error thrown when an expected output is not positive.
140
+ */
141
+ export class InvalidExpectedOutputError extends Errors.BaseError {
142
+ name = 'EarnShares.InvalidExpectedOutputError';
143
+ constructor(options) {
144
+ super(`Expected output \`${options.expectedAmount}\` must be greater than zero.`);
145
+ }
146
+ }
147
+ /**
148
+ * Error thrown when a slippage tolerance is not an integer from `0` through `9_999`.
149
+ */
150
+ export class InvalidSlippageError extends Errors.BaseError {
151
+ name = 'EarnShares.InvalidSlippageError';
152
+ constructor(options) {
153
+ super(`Slippage tolerance \`${options.slippageBps}\` is invalid.`, {
154
+ metaMessages: [
155
+ `Slippage must be a whole number from 0 through ${basisPointScale - 1} basis points.`,
156
+ ],
157
+ });
158
+ }
159
+ }
160
+ //# sourceMappingURL=EarnShares.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EarnShares.js","sourceRoot":"","sources":["../../src/tempo/EarnShares.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAE3C,uDAAuD;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAA;AAmBrC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,gBAAwB;IAC/D,OAAO,CAAC,gBAAgB,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,YAAY,CAAA;AACtE,CAAC;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,gBAAwB;IACjE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CAAA;IAC5C,OAAO,CAAC,gBAAgB,GAAG,WAAW,GAAG,YAAY,GAAG,EAAE,CAAC,GAAG,YAAY,CAAA;AAC5E,CAAC;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,WAAmB;IAC/D,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,WAAW,CAAA;AACjE,CAAC;AAMD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,SAAS,CAAC,OAA0B;IAClD,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,OAAO,CAAA;IAC7D,IAAI,cAAc,KAAK,EAAE,IAAI,cAAc,IAAI,YAAY;QAAE,OAAO,EAAE,CAAA;IACtE,OAAO,CAAC,cAAc,GAAG,WAAW,CAAC,GAAG,CAAC,YAAY,GAAG,cAAc,CAAC,CAAA;AACzE,CAAC;AAcD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,aAAa,CAC3B,cAAsB,EACtB,WAAmB;IAEnB,IAAI,cAAc,IAAI,EAAE;QACtB,MAAM,IAAI,0BAA0B,CAAC,EAAE,cAAc,EAAE,CAAC,CAAA;IAC1D,IACE,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC;QAC9B,WAAW,GAAG,CAAC;QACf,WAAW,IAAI,eAAe;QAE9B,MAAM,IAAI,oBAAoB,CAAC,EAAE,WAAW,EAAE,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,MAAM,CAAC,eAAe,CAAC,CAAA;IACrC,MAAM,OAAO,GAAG,CAAC,cAAc,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;IACxE,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAA;AACtC,CAAC;AASD;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,MAAM,CAAC,SAAS;IAC5C,IAAI,GAAG,uCAAuC,CAAA;IAEhE,YAAY,OAA2C;QACrD,KAAK,CACH,qBAAqB,OAAO,CAAC,cAAc,+BAA+B,CAC3E,CAAA;IACH,CAAC;CACF;AAQD;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,SAAS;IACtC,IAAI,GAAG,iCAAiC,CAAA;IAE1D,YAAY,OAAqC;QAC/C,KAAK,CAAC,wBAAwB,OAAO,CAAC,WAAW,gBAAgB,EAAE;YACjE,YAAY,EAAE;gBACZ,kDAAkD,eAAe,GAAG,CAAC,gBAAgB;aACtF;SACF,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -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":["../../src/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":["../../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"}
@@ -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 = 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
+ 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
@@ -1 +1 @@
1
- {"version":3,"file":"ZoneId.js","sourceRoot":"","sources":["../../src/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":["../../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"}
@@ -66,6 +66,28 @@ export * as AuthorizationTempo from './AuthorizationTempo.js';
66
66
  * @category Reference
67
67
  */
68
68
  export * as Channel from './Channel.js';
69
+ /**
70
+ * Tempo Earn `VaultAdapter` share math: raw vault-share and venue-share conversions
71
+ * at the anchor rate, the dilution-correct fee-share formula, and the
72
+ * `minimumOutput` slippage floor.
73
+ *
74
+ * Conversions are fee-blind mirrors of the adapter's anchor arithmetic; use the
75
+ * adapter's `previewRedeem` for user-facing value.
76
+ *
77
+ * @example
78
+ * ```ts twoslash
79
+ * import { EarnShares } from 'ox/tempo'
80
+ *
81
+ * const shareAmount = EarnShares.toAmount(
82
+ * { engineShares: 3n, shareSupply: 2n },
83
+ * 7n
84
+ * )
85
+ * // @log: 4n
86
+ * ```
87
+ *
88
+ * @category Reference
89
+ */
90
+ export * as EarnShares from './EarnShares.js';
69
91
  /**
70
92
  * Tempo key authorization utilities for provisioning and signing access keys.
71
93
  *
@@ -505,18 +527,17 @@ export * as VirtualMaster from './VirtualMaster.js';
505
527
  /**
506
528
  * Zone ID utilities for converting between zone IDs and zone chain IDs.
507
529
  *
508
- * Zone chain IDs are deterministically derived from zone IDs using the formula
509
- * `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.
510
531
  *
511
532
  * @example
512
533
  * ```ts twoslash
513
534
  * import { ZoneId } from 'ox/tempo'
514
535
  *
515
- * const zoneId = ZoneId.fromChainId(421_700_026)
516
- * // @log: 26
536
+ * const zoneId = ZoneId.fromChainId(421_700_001)
537
+ * // @log: 1
517
538
  *
518
- * const chainId = ZoneId.toChainId(26)
519
- * // @log: 421700026
539
+ * const chainId = ZoneId.toChainId(1)
540
+ * // @log: 421700001
520
541
  * ```
521
542
  *
522
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAA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