ox 0.14.31 → 0.14.32

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,18 @@
1
1
  # ox
2
2
 
3
+ ## 0.14.32
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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.
8
+
9
+ ```ts
10
+ import { EarnShares } from "ox/tempo";
11
+
12
+ const tokens = EarnShares.toTokens({ engineShares: 3n, supply: 2n }, 7n);
13
+ const minimumShares = EarnShares.minimumOutput(1_000_000n, 50n);
14
+ ```
15
+
3
16
  ## 0.14.31
4
17
 
5
18
  ### 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,S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,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,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;AAqBnD,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.32';
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,GAA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;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;IAG9D,YAAY,OAA2C;QACrD,KAAK,CACH,qBAAqB,OAAO,CAAC,cAAc,+BAA+B,CAC3E,CAAA;QALe;;;;mBAAO,uCAAuC;WAAA;IAMhE,CAAC;CACF;AAQD;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,SAAS;IAGxD,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;QAPc;;;;mBAAO,iCAAiC;WAAA;IAQ1D,CAAC;CACF"}
@@ -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
  *
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAC3D;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAC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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,qBAAqB,MAAM,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.32';
3
3
  //# sourceMappingURL=version.js.map
@@ -0,0 +1,176 @@
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(1_000_000n, 50)
139
+ * // @log: 995_000n
140
+ * ```
141
+ *
142
+ * @param expectedAmount - Expected output in base units.
143
+ * @param slippageBps - Allowed slippage in basis points from `0` through `9_999`.
144
+ * @returns The minimum accepted output, floored to `1n`.
145
+ * @throws `InvalidExpectedOutputError` when `expectedAmount` is not positive.
146
+ * @throws `InvalidSlippageError` when `slippageBps` is outside its valid range.
147
+ */
148
+ export declare function minimumOutput(expectedAmount: bigint, slippageBps: number): bigint;
149
+ export declare namespace minimumOutput {
150
+ type ErrorType = InvalidExpectedOutputError | InvalidSlippageError | Errors.GlobalErrorType;
151
+ }
152
+ /**
153
+ * Error thrown when an expected output is not positive.
154
+ */
155
+ export declare class InvalidExpectedOutputError extends Errors.BaseError {
156
+ readonly name = "EarnShares.InvalidExpectedOutputError";
157
+ constructor(options: InvalidExpectedOutputError.Options);
158
+ }
159
+ export declare namespace InvalidExpectedOutputError {
160
+ type Options = {
161
+ expectedAmount: bigint;
162
+ };
163
+ }
164
+ /**
165
+ * Error thrown when a slippage tolerance is not an integer from `0` through `9_999`.
166
+ */
167
+ export declare class InvalidSlippageError extends Errors.BaseError {
168
+ readonly name = "EarnShares.InvalidSlippageError";
169
+ constructor(options: InvalidSlippageError.Options);
170
+ }
171
+ export declare namespace InvalidSlippageError {
172
+ type Options = {
173
+ slippageBps: number;
174
+ };
175
+ }
176
+ //# sourceMappingURL=EarnShares.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EarnShares.d.ts","sourceRoot":"","sources":["../../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,QAAQ,CAAC;IAChC,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAG3E;AAED,MAAM,CAAC,OAAO,WAAW,UAAU,CAAC;IAClC,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAA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AW,EAAE,MAAM,CAAA;KACpB,CAAA;CACF"}
@@ -60,6 +60,28 @@ export * as AuthorizationTempo from './AuthorizationTempo.js';
60
60
  * @category Reference
61
61
  */
62
62
  export * as Channel from './Channel.js';
63
+ /**
64
+ * Tempo Earn `VaultAdapter` share math: raw vault-share and venue-share conversions
65
+ * at the anchor rate, the dilution-correct fee-share formula, and the
66
+ * `minimumOutput` slippage floor.
67
+ *
68
+ * Conversions are fee-blind mirrors of the adapter's anchor arithmetic; use the
69
+ * adapter's `previewRedeem` for user-facing value.
70
+ *
71
+ * @example
72
+ * ```ts twoslash
73
+ * import { EarnShares } from 'ox/tempo'
74
+ *
75
+ * const shareAmount = EarnShares.toAmount(
76
+ * { engineShares: 3n, shareSupply: 2n },
77
+ * 7n,
78
+ * )
79
+ * // @log: 4n
80
+ * ```
81
+ *
82
+ * @category Reference
83
+ */
84
+ export * as EarnShares from './EarnShares.js';
63
85
  /**
64
86
  * Tempo key authorization utilities for provisioning and signing access keys.
65
87
  *
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;A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MAAM,cAAc,CAAA;AACvC;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;GAkBG;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.31";
2
+ export declare const version = "0.14.32";
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.31",
4
+ "version": "0.14.32",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -508,6 +508,11 @@
508
508
  "import": "./_esm/tempo/Channel.js",
509
509
  "default": "./_cjs/tempo/Channel.js"
510
510
  },
511
+ "./tempo/EarnShares": {
512
+ "types": "./_types/tempo/EarnShares.d.ts",
513
+ "import": "./_esm/tempo/EarnShares.js",
514
+ "default": "./_cjs/tempo/EarnShares.js"
515
+ },
511
516
  "./tempo/KeyAuthorization.test-d": {
512
517
  "types": "./_types/tempo/KeyAuthorization.test-d.d.ts",
513
518
  "import": "./_esm/tempo/KeyAuthorization.test-d.js",
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/tempo/EarnShares.d.ts",
4
+ "main": "../../_cjs/tempo/EarnShares.js",
5
+ "module": "../../_esm/tempo/EarnShares.js"
6
+ }
@@ -0,0 +1,122 @@
1
+ import { EarnShares } from 'ox/tempo'
2
+ import { describe, expect, test } from 'vitest'
3
+
4
+ const anchor = { engineShares: 3n, shareSupply: 2n } as const
5
+
6
+ describe('toAmount', () => {
7
+ test('default', () => {
8
+ expect(EarnShares.toAmount(anchor, 7n)).toBe(4n)
9
+ })
10
+
11
+ test('behavior: rounds down', () => {
12
+ expect(EarnShares.toAmount({ engineShares: 3n, shareSupply: 1n }, 2n)).toBe(
13
+ 0n,
14
+ )
15
+ })
16
+ })
17
+
18
+ describe('toAmountUp', () => {
19
+ test('default', () => {
20
+ expect(EarnShares.toAmountUp(anchor, 7n)).toBe(5n)
21
+ })
22
+
23
+ test('behavior: exact conversions do not round up', () => {
24
+ expect(EarnShares.toAmountUp(anchor, 3n)).toBe(2n)
25
+ })
26
+ })
27
+
28
+ describe('toVenueAmount', () => {
29
+ test('default', () => {
30
+ expect(EarnShares.toVenueAmount(anchor, 7n)).toBe(10n)
31
+ })
32
+
33
+ test('behavior: identity at the initial 1:1 anchor', () => {
34
+ expect(
35
+ EarnShares.toVenueAmount({ engineShares: 1n, shareSupply: 1n }, 12_345n),
36
+ ).toBe(12_345n)
37
+ })
38
+ })
39
+
40
+ describe('feeShares', () => {
41
+ test('default', () => {
42
+ expect(
43
+ EarnShares.feeShares({
44
+ activeAssets: 1_100n,
45
+ shareSupply: 1_000n,
46
+ totalFeeAssets: 100n,
47
+ }),
48
+ ).toBe(100n)
49
+ })
50
+
51
+ test('behavior: zero fee mints nothing', () => {
52
+ expect(
53
+ EarnShares.feeShares({
54
+ activeAssets: 1_100n,
55
+ shareSupply: 1_000n,
56
+ totalFeeAssets: 0n,
57
+ }),
58
+ ).toBe(0n)
59
+ })
60
+
61
+ test('behavior: fee at or above active assets mints nothing', () => {
62
+ expect(
63
+ EarnShares.feeShares({
64
+ activeAssets: 100n,
65
+ shareSupply: 1_000n,
66
+ totalFeeAssets: 100n,
67
+ }),
68
+ ).toBe(0n)
69
+ })
70
+
71
+ test('behavior: rounds down', () => {
72
+ expect(
73
+ EarnShares.feeShares({
74
+ activeAssets: 1_000n,
75
+ shareSupply: 999n,
76
+ totalFeeAssets: 100n,
77
+ }),
78
+ ).toBe(111n)
79
+ })
80
+ })
81
+
82
+ describe('minimumOutput', () => {
83
+ test('default', () => {
84
+ expect(EarnShares.minimumOutput(1_000_000n, 50)).toBe(995_000n)
85
+ })
86
+
87
+ test('behavior: zero slippage returns the expected output', () => {
88
+ expect(EarnShares.minimumOutput(1_000_000n, 0)).toBe(1_000_000n)
89
+ })
90
+
91
+ test('behavior: floors to 1n', () => {
92
+ expect(EarnShares.minimumOutput(1n, 9_999)).toBe(1n)
93
+ })
94
+
95
+ test('error: non-positive expected output', () => {
96
+ expect(() =>
97
+ EarnShares.minimumOutput(0n, 50),
98
+ ).toThrowErrorMatchingInlineSnapshot(
99
+ `[EarnShares.InvalidExpectedOutputError: Expected output \`0\` must be greater than zero.]`,
100
+ )
101
+ })
102
+
103
+ test('error: out-of-range slippage', () => {
104
+ expect(() =>
105
+ EarnShares.minimumOutput(1_000_000n, 10_000),
106
+ ).toThrowErrorMatchingInlineSnapshot(`
107
+ [EarnShares.InvalidSlippageError: Slippage tolerance \`10000\` is invalid.
108
+
109
+ Slippage must be a whole number from 0 through 9999 basis points.]
110
+ `)
111
+ })
112
+
113
+ test('error: non-integer slippage', () => {
114
+ expect(() =>
115
+ EarnShares.minimumOutput(1_000_000n, 0.5),
116
+ ).toThrowErrorMatchingInlineSnapshot(`
117
+ [EarnShares.InvalidSlippageError: Slippage tolerance \`0.5\` is invalid.
118
+
119
+ Slippage must be a whole number from 0 through 9999 basis points.]
120
+ `)
121
+ })
122
+ })
@@ -0,0 +1,232 @@
1
+ import * as Errors from '../core/Errors.js'
2
+
3
+ /** Basis-point denominator used by slippage bounds. */
4
+ export const basisPointScale = 10_000
5
+
6
+ /**
7
+ * Tempo Earn `VaultAdapter` conversion anchor.
8
+ *
9
+ * The adapter prices vault shares against venue shares through this pair:
10
+ * `engineShares` venue shares are worth `shareSupply` vault shares. It is initialised
11
+ * 1:1 and restated on `contribute` and `migrateEngine`.
12
+ *
13
+ * These conversions are raw and fee-blind; they ignore pending fee dilution
14
+ * and are unsuitable for user-facing value (use the adapter's `previewRedeem`).
15
+ */
16
+ export type Anchor = {
17
+ /** Venue shares held by the engine at the anchor point. */
18
+ engineShares: bigint
19
+ /** Vault share supply at the anchor point. */
20
+ shareSupply: bigint
21
+ }
22
+
23
+ /**
24
+ * Converts venue shares to a vault share amount at the anchor rate, rounding down.
25
+ *
26
+ * Mirrors `VaultAdapter.sharesToTokens`.
27
+ *
28
+ * @example
29
+ * ```ts twoslash
30
+ * import { EarnShares } from 'ox/tempo'
31
+ *
32
+ * const shareAmount = EarnShares.toAmount(
33
+ * { engineShares: 3n, shareSupply: 2n },
34
+ * 7n,
35
+ * )
36
+ * // @log: 4n
37
+ * ```
38
+ *
39
+ * @param anchor - The conversion anchor.
40
+ * @param venueShareAmount - Venue share amount, base units.
41
+ * @returns Vault share amount, rounded down.
42
+ */
43
+ export function toAmount(anchor: Anchor, venueShareAmount: bigint): bigint {
44
+ return (venueShareAmount * anchor.shareSupply) / anchor.engineShares
45
+ }
46
+
47
+ export declare namespace toAmount {
48
+ type ErrorType = Errors.GlobalErrorType
49
+ }
50
+
51
+ /**
52
+ * Converts venue shares to a vault share amount at the anchor rate, rounding up.
53
+ *
54
+ * Mirrors the adapter's ceiling conversion used by exact-asset exits.
55
+ *
56
+ * @example
57
+ * ```ts twoslash
58
+ * import { EarnShares } from 'ox/tempo'
59
+ *
60
+ * const shareAmount = EarnShares.toAmountUp(
61
+ * { engineShares: 3n, shareSupply: 2n },
62
+ * 7n,
63
+ * )
64
+ * // @log: 5n
65
+ * ```
66
+ *
67
+ * @param anchor - The conversion anchor.
68
+ * @param venueShareAmount - Venue share amount, base units.
69
+ * @returns Vault share amount, rounded up.
70
+ */
71
+ export function toAmountUp(anchor: Anchor, venueShareAmount: bigint): bigint {
72
+ const { engineShares, shareSupply } = anchor
73
+ return (venueShareAmount * shareSupply + engineShares - 1n) / engineShares
74
+ }
75
+
76
+ export declare namespace toAmountUp {
77
+ type ErrorType = Errors.GlobalErrorType
78
+ }
79
+
80
+ /**
81
+ * Converts a vault share amount to venue shares at the anchor rate, rounding down.
82
+ *
83
+ * Mirrors `VaultAdapter.tokensToShares`.
84
+ *
85
+ * @example
86
+ * ```ts twoslash
87
+ * import { EarnShares } from 'ox/tempo'
88
+ *
89
+ * const venueShareAmount = EarnShares.toVenueAmount(
90
+ * { engineShares: 3n, shareSupply: 2n },
91
+ * 7n,
92
+ * )
93
+ * // @log: 10n
94
+ * ```
95
+ *
96
+ * @param anchor - The conversion anchor.
97
+ * @param shareAmount - Vault share amount, base units.
98
+ * @returns Venue share amount, rounded down.
99
+ */
100
+ export function toVenueAmount(anchor: Anchor, shareAmount: bigint): bigint {
101
+ return (shareAmount * anchor.engineShares) / anchor.shareSupply
102
+ }
103
+
104
+ export declare namespace toVenueAmount {
105
+ type ErrorType = Errors.GlobalErrorType
106
+ }
107
+
108
+ /**
109
+ * Computes the dilution-correct vault shares minted for an asset-denominated fee.
110
+ *
111
+ * Mirrors `FeeMath`:
112
+ * `feeShares = floor(fee * shareSupply / (activeAssets - fee))`, zero when the
113
+ * fee is zero or not smaller than the active assets. Minting this amount to the
114
+ * fee ledger prices the fee at post-mint value per share.
115
+ *
116
+ * @example
117
+ * ```ts twoslash
118
+ * import { EarnShares } from 'ox/tempo'
119
+ *
120
+ * const shares = EarnShares.feeShares({
121
+ * activeAssets: 1_100n,
122
+ * shareSupply: 1_000n,
123
+ * totalFeeAssets: 100n,
124
+ * })
125
+ * // @log: 100n
126
+ * ```
127
+ *
128
+ * @param options - Fee accrual inputs.
129
+ * @returns Vault shares to mint for the fee, rounded down.
130
+ */
131
+ export function feeShares(options: feeShares.Options): bigint {
132
+ const { activeAssets, shareSupply, totalFeeAssets } = options
133
+ if (totalFeeAssets === 0n || totalFeeAssets >= activeAssets) return 0n
134
+ return (totalFeeAssets * shareSupply) / (activeAssets - totalFeeAssets)
135
+ }
136
+
137
+ export declare namespace feeShares {
138
+ export type Options = {
139
+ /** Assets backing the active (non-queued) supply, base units. */
140
+ activeAssets: bigint
141
+ /** Active vault share supply, base units. */
142
+ shareSupply: bigint
143
+ /** Total fee liability in asset units. */
144
+ totalFeeAssets: bigint
145
+ }
146
+ export type ErrorType = Errors.GlobalErrorType
147
+ }
148
+
149
+ /**
150
+ * Lowers an expected output by a basis-point slippage tolerance, flooring to `1n`.
151
+ *
152
+ * Suitable for lower bounds such as a deposit's minimum shares or a redeem's
153
+ * minimum assets; not for upper bounds such as an exact withdrawal's maximum
154
+ * shares.
155
+ *
156
+ * @example
157
+ * ```ts twoslash
158
+ * import { EarnShares } from 'ox/tempo'
159
+ *
160
+ * const minimumShares = EarnShares.minimumOutput(1_000_000n, 50)
161
+ * // @log: 995_000n
162
+ * ```
163
+ *
164
+ * @param expectedAmount - Expected output in base units.
165
+ * @param slippageBps - Allowed slippage in basis points from `0` through `9_999`.
166
+ * @returns The minimum accepted output, floored to `1n`.
167
+ * @throws `InvalidExpectedOutputError` when `expectedAmount` is not positive.
168
+ * @throws `InvalidSlippageError` when `slippageBps` is outside its valid range.
169
+ */
170
+ export function minimumOutput(
171
+ expectedAmount: bigint,
172
+ slippageBps: number,
173
+ ): bigint {
174
+ if (expectedAmount <= 0n)
175
+ throw new InvalidExpectedOutputError({ expectedAmount })
176
+ if (
177
+ !Number.isInteger(slippageBps) ||
178
+ slippageBps < 0 ||
179
+ slippageBps >= basisPointScale
180
+ )
181
+ throw new InvalidSlippageError({ slippageBps })
182
+ const scale = BigInt(basisPointScale)
183
+ const bounded = (expectedAmount * (scale - BigInt(slippageBps))) / scale
184
+ return bounded === 0n ? 1n : bounded
185
+ }
186
+
187
+ export declare namespace minimumOutput {
188
+ type ErrorType =
189
+ | InvalidExpectedOutputError
190
+ | InvalidSlippageError
191
+ | Errors.GlobalErrorType
192
+ }
193
+
194
+ /**
195
+ * Error thrown when an expected output is not positive.
196
+ */
197
+ export class InvalidExpectedOutputError extends Errors.BaseError {
198
+ override readonly name = 'EarnShares.InvalidExpectedOutputError'
199
+
200
+ constructor(options: InvalidExpectedOutputError.Options) {
201
+ super(
202
+ `Expected output \`${options.expectedAmount}\` must be greater than zero.`,
203
+ )
204
+ }
205
+ }
206
+
207
+ export declare namespace InvalidExpectedOutputError {
208
+ export type Options = {
209
+ expectedAmount: bigint
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Error thrown when a slippage tolerance is not an integer from `0` through `9_999`.
215
+ */
216
+ export class InvalidSlippageError extends Errors.BaseError {
217
+ override readonly name = 'EarnShares.InvalidSlippageError'
218
+
219
+ constructor(options: InvalidSlippageError.Options) {
220
+ super(`Slippage tolerance \`${options.slippageBps}\` is invalid.`, {
221
+ metaMessages: [
222
+ `Slippage must be a whole number from 0 through ${basisPointScale - 1} basis points.`,
223
+ ],
224
+ })
225
+ }
226
+ }
227
+
228
+ export declare namespace InvalidSlippageError {
229
+ export type Options = {
230
+ slippageBps: number
231
+ }
232
+ }
package/tempo/index.ts CHANGED
@@ -62,6 +62,28 @@ export * as AuthorizationTempo from './AuthorizationTempo.js'
62
62
  * @category Reference
63
63
  */
64
64
  export * as Channel from './Channel.js'
65
+ /**
66
+ * Tempo Earn `VaultAdapter` share math: raw vault-share and venue-share conversions
67
+ * at the anchor rate, the dilution-correct fee-share formula, and the
68
+ * `minimumOutput` slippage floor.
69
+ *
70
+ * Conversions are fee-blind mirrors of the adapter's anchor arithmetic; use the
71
+ * adapter's `previewRedeem` for user-facing value.
72
+ *
73
+ * @example
74
+ * ```ts twoslash
75
+ * import { EarnShares } from 'ox/tempo'
76
+ *
77
+ * const shareAmount = EarnShares.toAmount(
78
+ * { engineShares: 3n, shareSupply: 2n },
79
+ * 7n,
80
+ * )
81
+ * // @log: 4n
82
+ * ```
83
+ *
84
+ * @category Reference
85
+ */
86
+ export * as EarnShares from './EarnShares.js'
65
87
  /**
66
88
  * Tempo key authorization utilities for provisioning and signing access keys.
67
89
  *
package/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '0.14.31'
2
+ export const version = '0.14.32'