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.
@@ -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,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,MAAM,CAAC,OAAO,WAAW,aAAa,CAAC;IACrC,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO,GAAG,MAAM,CAI5D;AAED,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,KAAY,OAAO,GAAG;QACpB,iEAAiE;QACjE,YAAY,EAAE,MAAM,CAAA;QACpB,6CAA6C;QAC7C,WAAW,EAAE,MAAM,CAAA;QACnB,0CAA0C;QAC1C,cAAc,EAAE,MAAM,CAAA;KACvB,CAAA;IACD,KAAY,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CAC/C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAC3B,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,GAClB,MAAM,CAYR;AAED,MAAM,CAAC,OAAO,WAAW,aAAa,CAAC;IACrC,KAAK,SAAS,GACV,0BAA0B,GAC1B,oBAAoB,GACpB,MAAM,CAAC,eAAe,CAAA;CAC3B;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,MAAM,CAAC,SAAS;IAC9D,SAAkB,IAAI,2CAA0C;gBAEpD,OAAO,EAAE,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"}
@@ -1,50 +1,68 @@
1
- import type * as Errors from '../core/Errors.js';
1
+ import * as Errors from '../core/Errors.js';
2
+ declare const chainIdConfig: {
3
+ readonly 4217: {
4
+ readonly base: 421700000;
5
+ readonly range: 1002610000;
6
+ };
7
+ readonly 42431: {
8
+ readonly base: 1424310000;
9
+ readonly range: 723173648;
10
+ };
11
+ };
2
12
  /**
3
- * Base offset for deriving zone chain IDs.
4
- *
5
- * Zone chain IDs are computed as `chainIdBase + zoneId`.
13
+ * Base offset for deriving Presto zone chain IDs.
6
14
  */
7
- export declare const chainIdBase: 4217000000;
15
+ export declare const chainIdBase: 421700000;
16
+ /** Tempo source chain ID. */
17
+ export type SourceId = keyof typeof chainIdConfig;
8
18
  /**
9
19
  * Derives a zone ID from a zone chain ID.
10
20
  *
11
- * Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so a chain ID
12
- * of `4217000006` corresponds to zone ID `6`.
21
+ * Zone chain IDs use the base assigned to their Tempo source chain.
13
22
  *
14
23
  * @example
15
24
  * ```ts twoslash
16
25
  * import { ZoneId } from 'ox/tempo'
17
26
  *
18
- * const zoneId = ZoneId.fromChainId(4_217_000_006)
19
- * // @log: 6
27
+ * const zoneId = ZoneId.fromChainId(421_700_001)
28
+ * // @log: 1
20
29
  * ```
21
30
  *
22
31
  * @param chainId - The zone chain ID.
32
+ * @param sourceId - The Tempo source chain ID. Defaults to `4217` (Presto).
23
33
  * @returns The zone ID.
24
34
  */
25
- export declare function fromChainId(chainId: number): number;
35
+ export declare function fromChainId(chainId: number, sourceId?: SourceId): number;
26
36
  export declare namespace fromChainId {
27
- type ErrorType = Errors.GlobalErrorType;
37
+ type ErrorType = typeof UnsupportedSourceIdError | Errors.GlobalErrorType;
28
38
  }
29
39
  /**
30
40
  * Derives a zone chain ID from a zone ID.
31
41
  *
32
- * Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so zone ID
33
- * `6` corresponds to chain ID `4217000006`.
42
+ * Zone chain IDs use the base and range assigned to their Tempo source chain.
34
43
  *
35
44
  * @example
36
45
  * ```ts twoslash
37
46
  * import { ZoneId } from 'ox/tempo'
38
47
  *
39
- * const chainId = ZoneId.toChainId(6)
40
- * // @log: 4217000006
48
+ * const chainId = ZoneId.toChainId(1)
49
+ * // @log: 421700001
41
50
  * ```
42
51
  *
43
52
  * @param zoneId - The zone ID.
53
+ * @param sourceId - The Tempo source chain ID. Defaults to `4217` (Presto).
44
54
  * @returns The zone chain ID.
45
55
  */
46
- export declare function toChainId(zoneId: number): number;
56
+ export declare function toChainId(zoneId: number, sourceId?: SourceId): number;
47
57
  export declare namespace toChainId {
48
- type ErrorType = Errors.GlobalErrorType;
58
+ type ErrorType = typeof UnsupportedSourceIdError | Errors.GlobalErrorType;
59
+ }
60
+ /** Thrown when a Tempo source chain ID is unsupported. */
61
+ export declare class UnsupportedSourceIdError extends Errors.BaseError {
62
+ readonly name = "ZoneId.UnsupportedSourceIdError";
63
+ constructor({ sourceId }: {
64
+ sourceId: number;
65
+ });
49
66
  }
67
+ export {};
50
68
  //# sourceMappingURL=ZoneId.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ZoneId.d.ts","sourceRoot":"","sources":["../../tempo/ZoneId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD;;;;GAIG;AACH,eAAO,MAAM,WAAW,YAAyB,CAAA;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,MAAM,CAAC,OAAO,WAAW,WAAW,CAAC;IACnC,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC"}
1
+ {"version":3,"file":"ZoneId.d.ts","sourceRoot":"","sources":["../../tempo/ZoneId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAE3C,QAAA,MAAM,aAAa;;;;;;;;;CAST,CAAA;AAIV;;GAEG;AACH,eAAO,MAAM,WAAW,WAAsC,CAAA;AAE9D,6BAA6B;AAC7B,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,aAAa,CAAA;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,QAA0B,GACnC,MAAM,CAER;AAED,MAAM,CAAC,OAAO,WAAW,WAAW,CAAC;IACnC,KAAK,SAAS,GAAG,OAAO,wBAAwB,GAAG,MAAM,CAAC,eAAe,CAAA;CAC1E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,QAA0B,GACnC,MAAM,CAGR;AAED,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,KAAK,SAAS,GAAG,OAAO,wBAAwB,GAAG,MAAM,CAAC,eAAe,CAAA;CAC1E;AAED,0DAA0D;AAC1D,qBAAa,wBAAyB,SAAQ,MAAM,CAAC,SAAS;IAC5D,SAAkB,IAAI,qCAAoC;gBAC9C,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE;CAK/C"}
@@ -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
  *
@@ -497,18 +519,17 @@ export * as VirtualMaster from './VirtualMaster.js';
497
519
  /**
498
520
  * Zone ID utilities for converting between zone IDs and zone chain IDs.
499
521
  *
500
- * Zone chain IDs are deterministically derived from zone IDs using the formula
501
- * `421_700_000 + zoneId`. This module provides helpers to convert between them.
522
+ * Zone chain IDs use the base and range assigned to their Tempo source chain.
502
523
  *
503
524
  * @example
504
525
  * ```ts twoslash
505
526
  * import { ZoneId } from 'ox/tempo'
506
527
  *
507
- * const zoneId = ZoneId.fromChainId(421_700_026)
508
- * // @log: 26
528
+ * const zoneId = ZoneId.fromChainId(421_700_001)
529
+ * // @log: 1
509
530
  *
510
- * const chainId = ZoneId.toChainId(26)
511
- * // @log: 421700026
531
+ * const chainId = ZoneId.toChainId(1)
532
+ * // @log: 421700001
512
533
  * ```
513
534
  *
514
535
  * @category Reference
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,YAAY,EAAE,CAAA;AAEd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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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;;;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;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAA"}
@@ -1,3 +1,3 @@
1
1
  /** @internal */
2
- export declare const version = "0.14.31";
2
+ export declare const version = "0.14.33";
3
3
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ox",
3
3
  "description": "Ethereum Standard Library",
4
- "version": "0.14.31",
4
+ "version": "0.14.33",
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",
@@ -603,6 +608,11 @@
603
608
  "import": "./_esm/tempo/VirtualMaster.js",
604
609
  "default": "./_cjs/tempo/VirtualMaster.js"
605
610
  },
611
+ "./tempo/ZoneId.test-d": {
612
+ "types": "./_types/tempo/ZoneId.test-d.d.ts",
613
+ "import": "./_esm/tempo/ZoneId.test-d.js",
614
+ "default": "./_cjs/tempo/ZoneId.test-d.js"
615
+ },
606
616
  "./tempo/ZoneId": {
607
617
  "types": "./_types/tempo/ZoneId.d.ts",
608
618
  "import": "./_esm/tempo/ZoneId.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
+ })