ox 0.14.31 → 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,30 @@
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
+
15
+ ## 0.14.32
16
+
17
+ ### Patch Changes
18
+
19
+ - [#310](https://github.com/wevm/ox/pull/310) [`d882d95`](https://github.com/wevm/ox/commit/d882d95788b06669427ced3a44484a32221617c7) Thanks [@jxom](https://github.com/jxom)! - Added `EarnShares` to `ox/tempo`: raw EarnToken/venue-share conversions at the vault anchor rate, the dilution-correct fee-share formula, and a `minimumOutput` slippage floor.
20
+
21
+ ```ts
22
+ import { EarnShares } from "ox/tempo";
23
+
24
+ const tokens = EarnShares.toTokens({ engineShares: 3n, supply: 2n }, 7n);
25
+ const minimumShares = EarnShares.minimumOutput(1_000_000n, 50n);
26
+ ```
27
+
3
28
  ## 0.14.31
4
29
 
5
30
  ### Patch Changes
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidSlippageError = exports.InvalidExpectedOutputError = exports.basisPointScale = void 0;
4
+ exports.toAmount = toAmount;
5
+ exports.toAmountUp = toAmountUp;
6
+ exports.toVenueAmount = toVenueAmount;
7
+ exports.feeShares = feeShares;
8
+ exports.minimumOutput = minimumOutput;
9
+ const Errors = require("../core/Errors.js");
10
+ exports.basisPointScale = 10_000;
11
+ function toAmount(anchor, venueShareAmount) {
12
+ return (venueShareAmount * anchor.shareSupply) / anchor.engineShares;
13
+ }
14
+ function toAmountUp(anchor, venueShareAmount) {
15
+ const { engineShares, shareSupply } = anchor;
16
+ return (venueShareAmount * shareSupply + engineShares - 1n) / engineShares;
17
+ }
18
+ function toVenueAmount(anchor, shareAmount) {
19
+ return (shareAmount * anchor.engineShares) / anchor.shareSupply;
20
+ }
21
+ function feeShares(options) {
22
+ const { activeAssets, shareSupply, totalFeeAssets } = options;
23
+ if (totalFeeAssets === 0n || totalFeeAssets >= activeAssets)
24
+ return 0n;
25
+ return (totalFeeAssets * shareSupply) / (activeAssets - totalFeeAssets);
26
+ }
27
+ function minimumOutput(expectedAmount, slippageBps) {
28
+ if (expectedAmount <= 0n)
29
+ throw new InvalidExpectedOutputError({ expectedAmount });
30
+ if (!Number.isInteger(slippageBps) ||
31
+ slippageBps < 0 ||
32
+ slippageBps >= exports.basisPointScale)
33
+ throw new InvalidSlippageError({ slippageBps });
34
+ const scale = BigInt(exports.basisPointScale);
35
+ const bounded = (expectedAmount * (scale - BigInt(slippageBps))) / scale;
36
+ return bounded === 0n ? 1n : bounded;
37
+ }
38
+ class InvalidExpectedOutputError extends Errors.BaseError {
39
+ constructor(options) {
40
+ super(`Expected output \`${options.expectedAmount}\` must be greater than zero.`);
41
+ Object.defineProperty(this, "name", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: 'EarnShares.InvalidExpectedOutputError'
46
+ });
47
+ }
48
+ }
49
+ exports.InvalidExpectedOutputError = InvalidExpectedOutputError;
50
+ class InvalidSlippageError extends Errors.BaseError {
51
+ constructor(options) {
52
+ super(`Slippage tolerance \`${options.slippageBps}\` is invalid.`, {
53
+ metaMessages: [
54
+ `Slippage must be a whole number from 0 through ${exports.basisPointScale - 1} basis points.`,
55
+ ],
56
+ });
57
+ Object.defineProperty(this, "name", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: 'EarnShares.InvalidSlippageError'
62
+ });
63
+ }
64
+ }
65
+ exports.InvalidSlippageError = InvalidSlippageError;
66
+ //# sourceMappingURL=EarnShares.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EarnShares.js","sourceRoot":"","sources":["../../tempo/EarnShares.ts"],"names":[],"mappings":";;;AA0CA,4BAEC;AA0BD,gCAGC;AA0BD,sCAEC;AA6BD,8BAIC;AAmCD,sCAeC;AAxLD,4CAA2C;AAG9B,QAAA,eAAe,GAAG,MAAM,CAAA;AAuCrC,SAAgB,QAAQ,CAAC,MAAc,EAAE,gBAAwB;IAC/D,OAAO,CAAC,gBAAgB,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,YAAY,CAAA;AACtE,CAAC;AA0BD,SAAgB,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;AA0BD,SAAgB,aAAa,CAAC,MAAc,EAAE,WAAmB;IAC/D,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,WAAW,CAAA;AACjE,CAAC;AA6BD,SAAgB,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;AAmCD,SAAgB,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,uBAAe;QAE9B,MAAM,IAAI,oBAAoB,CAAC,EAAE,WAAW,EAAE,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,MAAM,CAAC,uBAAe,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;AAYD,MAAa,0BAA2B,SAAQ,MAAM,CAAC,SAAS;IAG9D,YAAY,OAA2C;QACrD,KAAK,CACH,qBAAqB,OAAO,CAAC,cAAc,+BAA+B,CAC3E,CAAA;QALe;;;;mBAAO,uCAAuC;WAAA;IAMhE,CAAC;CACF;AARD,gEAQC;AAWD,MAAa,oBAAqB,SAAQ,MAAM,CAAC,SAAS;IAGxD,YAAY,OAAqC;QAC/C,KAAK,CAAC,wBAAwB,OAAO,CAAC,WAAW,gBAAgB,EAAE;YACjE,YAAY,EAAE;gBACZ,kDAAkD,uBAAe,GAAG,CAAC,gBAAgB;aACtF;SACF,CAAC,CAAA;QAPc;;;;mBAAO,iCAAiC;WAAA;IAQ1D,CAAC;CACF;AAVD,oDAUC"}
@@ -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,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZoneRpcAuthentication = exports.ZoneId = exports.VirtualMaster = exports.VirtualAddress = exports.TxEnvelopeTempo = exports.TransactionRequest = exports.TransactionReceipt = exports.Transaction = exports.TokenRole = exports.TokenId = exports.Tick = exports.TempoAddress = exports.SignatureEnvelope = exports.RpcSchemaTempo = exports.ReceivePolicyReceipt = exports.PoolId = exports.Period = exports.MultisigConfig = exports.KeyAuthorization = exports.Channel = exports.AuthorizationTempo = void 0;
3
+ exports.ZoneRpcAuthentication = exports.ZoneId = exports.VirtualMaster = exports.VirtualAddress = exports.TxEnvelopeTempo = exports.TransactionRequest = exports.TransactionReceipt = exports.Transaction = exports.TokenRole = exports.TokenId = exports.Tick = exports.TempoAddress = exports.SignatureEnvelope = exports.RpcSchemaTempo = exports.ReceivePolicyReceipt = exports.PoolId = exports.Period = exports.MultisigConfig = exports.KeyAuthorization = exports.EarnShares = exports.Channel = exports.AuthorizationTempo = void 0;
4
4
  exports.AuthorizationTempo = require("./AuthorizationTempo.js");
5
5
  exports.Channel = require("./Channel.js");
6
+ exports.EarnShares = require("./EarnShares.js");
6
7
  exports.KeyAuthorization = require("./KeyAuthorization.js");
7
8
  exports.MultisigConfig = require("./MultisigConfig.js");
8
9
  exports.Period = require("./Period.js");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":";;;AAoCA,gEAA6D;AA2B7D,0CAAuC;AAwCvC,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.31';
4
+ exports.version = '0.14.33';
5
5
  //# sourceMappingURL=version.js.map
@@ -0,0 +1,167 @@
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(1_000_000n, 50)
115
+ * // @log: 995_000n
116
+ * ```
117
+ *
118
+ * @param expectedAmount - Expected output in base units.
119
+ * @param slippageBps - Allowed slippage in basis points from `0` through `9_999`.
120
+ * @returns The minimum accepted output, floored to `1n`.
121
+ * @throws `InvalidExpectedOutputError` when `expectedAmount` is not positive.
122
+ * @throws `InvalidSlippageError` when `slippageBps` is outside its valid range.
123
+ */
124
+ export function minimumOutput(expectedAmount, slippageBps) {
125
+ if (expectedAmount <= 0n)
126
+ throw new InvalidExpectedOutputError({ expectedAmount });
127
+ if (!Number.isInteger(slippageBps) ||
128
+ slippageBps < 0 ||
129
+ slippageBps >= basisPointScale)
130
+ throw new InvalidSlippageError({ slippageBps });
131
+ const scale = BigInt(basisPointScale);
132
+ const bounded = (expectedAmount * (scale - BigInt(slippageBps))) / scale;
133
+ return bounded === 0n ? 1n : bounded;
134
+ }
135
+ /**
136
+ * Error thrown when an expected output is not positive.
137
+ */
138
+ export class InvalidExpectedOutputError extends Errors.BaseError {
139
+ constructor(options) {
140
+ super(`Expected output \`${options.expectedAmount}\` must be greater than zero.`);
141
+ Object.defineProperty(this, "name", {
142
+ enumerable: true,
143
+ configurable: true,
144
+ writable: true,
145
+ value: 'EarnShares.InvalidExpectedOutputError'
146
+ });
147
+ }
148
+ }
149
+ /**
150
+ * Error thrown when a slippage tolerance is not an integer from `0` through `9_999`.
151
+ */
152
+ export class InvalidSlippageError extends Errors.BaseError {
153
+ constructor(options) {
154
+ super(`Slippage tolerance \`${options.slippageBps}\` is invalid.`, {
155
+ metaMessages: [
156
+ `Slippage must be a whole number from 0 through ${basisPointScale - 1} basis points.`,
157
+ ],
158
+ });
159
+ Object.defineProperty(this, "name", {
160
+ enumerable: true,
161
+ configurable: true,
162
+ writable: true,
163
+ value: 'EarnShares.InvalidSlippageError'
164
+ });
165
+ }
166
+ }
167
+ //# sourceMappingURL=EarnShares.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EarnShares.js","sourceRoot":"","sources":["../../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,E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,CAAC,CAAA;QAPc;;;;mBAAO,iCAAiC;WAAA;IAQ1D,CAAC;CACF"}
@@ -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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,EAAE,QAAQ,EAAE,CAAC,CAAA;AAClD,CAAC"}
@@ -58,6 +58,28 @@ export * as AuthorizationTempo from './AuthorizationTempo.js';
58
58
  * @category Reference
59
59
  */
60
60
  export * as Channel from './Channel.js';
61
+ /**
62
+ * Tempo Earn `VaultAdapter` share math: raw vault-share and venue-share conversions
63
+ * at the anchor rate, the dilution-correct fee-share formula, and the
64
+ * `minimumOutput` slippage floor.
65
+ *
66
+ * Conversions are fee-blind mirrors of the adapter's anchor arithmetic; use the
67
+ * adapter's `previewRedeem` for user-facing value.
68
+ *
69
+ * @example
70
+ * ```ts twoslash
71
+ * import { EarnShares } from 'ox/tempo'
72
+ *
73
+ * const shareAmount = EarnShares.toAmount(
74
+ * { engineShares: 3n, shareSupply: 2n },
75
+ * 7n,
76
+ * )
77
+ * // @log: 4n
78
+ * ```
79
+ *
80
+ * @category Reference
81
+ */
82
+ export * as EarnShares from './EarnShares.js';
61
83
  /**
62
84
  * Tempo key authorization utilities for provisioning and signing access keys.
63
85
  *
@@ -495,18 +517,17 @@ export * as VirtualMaster from './VirtualMaster.js';
495
517
  /**
496
518
  * Zone ID utilities for converting between zone IDs and zone chain IDs.
497
519
  *
498
- * Zone chain IDs are deterministically derived from zone IDs using the formula
499
- * `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.
500
521
  *
501
522
  * @example
502
523
  * ```ts twoslash
503
524
  * import { ZoneId } from 'ox/tempo'
504
525
  *
505
- * const zoneId = ZoneId.fromChainId(421_700_026)
506
- * // @log: 26
526
+ * const zoneId = ZoneId.fromChainId(421_700_001)
527
+ * // @log: 1
507
528
  *
508
- * const chainId = ZoneId.toChainId(26)
509
- * // @log: 421700026
529
+ * const chainId = ZoneId.toChainId(1)
530
+ * // @log: 421700001
510
531
  * ```
511
532
  *
512
533
  * @category Reference
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":"AA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4BAA4B,CAAA"}
package/_esm/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /** @internal */
2
- export const version = '0.14.31';
2
+ export const version = '0.14.33';
3
3
  //# sourceMappingURL=version.js.map