ox 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/tempo/EarnShares.d.ts +179 -0
- package/dist/tempo/EarnShares.d.ts.map +1 -0
- package/dist/tempo/EarnShares.js +160 -0
- package/dist/tempo/EarnShares.js.map +1 -0
- package/dist/tempo/KeyAuthorization.d.ts +22 -16
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +31 -7
- package/dist/tempo/KeyAuthorization.js.map +1 -1
- package/dist/tempo/MultisigConfig.d.ts +8 -4
- package/dist/tempo/MultisigConfig.d.ts.map +1 -1
- package/dist/tempo/MultisigConfig.js +16 -4
- package/dist/tempo/MultisigConfig.js.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts +31 -13
- package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/tempo/SignatureEnvelope.js +172 -55
- package/dist/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/tempo/index.d.ts +22 -0
- package/dist/tempo/index.d.ts.map +1 -1
- package/dist/tempo/index.js +22 -0
- package/dist/tempo/index.js.map +1 -1
- package/dist/zod/tempo/AuthorizationTempo.d.ts +70 -60
- package/dist/zod/tempo/AuthorizationTempo.d.ts.map +1 -1
- package/dist/zod/tempo/KeyAuthorization.d.ts +0 -306
- package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/zod/tempo/KeyAuthorization.js +2 -2
- package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
- package/dist/zod/tempo/MultisigConfig.d.ts.map +1 -1
- package/dist/zod/tempo/MultisigConfig.js +5 -2
- package/dist/zod/tempo/MultisigConfig.js.map +1 -1
- package/dist/zod/tempo/RpcSchemaTempo.d.ts +28 -132
- package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.d.ts +79 -18
- package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.js +39 -11
- package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/zod/tempo/Transaction.d.ts +84 -396
- package/dist/zod/tempo/Transaction.d.ts.map +1 -1
- package/dist/zod/tempo/TransactionRequest.d.ts +42 -234
- package/dist/zod/tempo/TransactionRequest.d.ts.map +1 -1
- package/dist/zod/tempo/TxEnvelopeTempo.d.ts +0 -108
- package/dist/zod/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/tempo/EarnShares.test.ts +120 -0
- package/src/tempo/EarnShares.ts +235 -0
- package/src/tempo/KeyAuthorization.test-d.ts +62 -0
- package/src/tempo/KeyAuthorization.test.ts +53 -0
- package/src/tempo/KeyAuthorization.ts +69 -27
- package/src/tempo/MultisigConfig.test.ts +34 -2
- package/src/tempo/MultisigConfig.ts +18 -4
- package/src/tempo/SignatureEnvelope.test-d.ts +97 -0
- package/src/tempo/SignatureEnvelope.test.ts +247 -36
- package/src/tempo/SignatureEnvelope.ts +271 -85
- package/src/tempo/e2e.test.ts +0 -416
- package/src/tempo/index.ts +22 -0
- package/src/tempo/multisig.e2e.test.ts +582 -0
- package/src/version.ts +1 -1
- package/src/zod/tempo/KeyAuthorization.ts +2 -2
- package/src/zod/tempo/MultisigConfig.ts +13 -5
- package/src/zod/tempo/SignatureEnvelope.ts +81 -18
- package/src/zod/tempo/_test/KeyAuthorization.test.ts +25 -0
- package/src/zod/tempo/_test/MultisigConfig.test.ts +44 -0
- package/src/zod/tempo/_test/SignatureEnvelope.test-d.ts +9 -0
- package/src/zod/tempo/_test/SignatureEnvelope.test.ts +142 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# ox
|
|
2
2
|
|
|
3
|
+
## 1.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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.
|
|
8
|
+
|
|
9
|
+
## 1.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#305](https://github.com/wevm/ox/pull/305) [`7355d1d`](https://github.com/wevm/ox/commit/7355d1d5758df61949563d6d46f3f8b41324331c) Thanks [@jxom](https://github.com/jxom)! - `viem/tempo`: Updated multisig implementation.
|
|
14
|
+
|
|
3
15
|
## 1.0.2
|
|
4
16
|
|
|
5
17
|
### 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,QAAQ,CAAC;IAChC,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,M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AAa,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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,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"}
|
|
@@ -2,7 +2,7 @@ import type * as Address from '../core/Address.js';
|
|
|
2
2
|
import type * as Errors from '../core/Errors.js';
|
|
3
3
|
import * as Hash from '../core/Hash.js';
|
|
4
4
|
import * as Hex from '../core/Hex.js';
|
|
5
|
-
import type { Compute, OneOf } from '../core/internal/types.js';
|
|
5
|
+
import type { Compute, OneOf, UnionPartialBy } from '../core/internal/types.js';
|
|
6
6
|
import * as Rlp from '../core/Rlp.js';
|
|
7
7
|
import * as SignatureEnvelope from './SignatureEnvelope.js';
|
|
8
8
|
/**
|
|
@@ -61,9 +61,9 @@ export type KeyAuthorization<signed extends boolean = boolean, bigintType = bigi
|
|
|
61
61
|
/** Whether this authorization provisions an admin access key. */
|
|
62
62
|
isAdmin: boolean;
|
|
63
63
|
} | {}> & (signed extends true ? {
|
|
64
|
-
signature: SignatureEnvelope.
|
|
64
|
+
signature: SignatureEnvelope.Primitive<numberType>;
|
|
65
65
|
} : {
|
|
66
|
-
signature?: SignatureEnvelope.
|
|
66
|
+
signature?: SignatureEnvelope.Primitive<numberType> | undefined;
|
|
67
67
|
});
|
|
68
68
|
/** Input type for a Key Authorization. */
|
|
69
69
|
export type Input = KeyAuthorization<false, bigint, number>;
|
|
@@ -85,8 +85,8 @@ export type Rpc = {
|
|
|
85
85
|
keyType: SignatureEnvelope.Type;
|
|
86
86
|
/** Token spending limits. */
|
|
87
87
|
limits?: readonly RpcTokenLimit[] | null | undefined;
|
|
88
|
-
/**
|
|
89
|
-
signature: SignatureEnvelope.
|
|
88
|
+
/** Primitive signature authorizing this key. */
|
|
89
|
+
signature: SignatureEnvelope.PrimitiveRpc;
|
|
90
90
|
/** Optional 32-byte witness (hex). */
|
|
91
91
|
witness?: Hex.Hex | null | undefined;
|
|
92
92
|
};
|
|
@@ -108,6 +108,7 @@ export type RpcSelectorRule = {
|
|
|
108
108
|
};
|
|
109
109
|
/** Signed representation of a Key Authorization. */
|
|
110
110
|
export type Signed<bigintType = bigint, numberType = number> = KeyAuthorization<true, bigintType, numberType>;
|
|
111
|
+
type PrimitiveSignatureValue = UnionPartialBy<SignatureEnvelope.Primitive, 'prehash' | 'type'> | SignatureEnvelope.Secp256k1Flat | SignatureEnvelope.Serialized;
|
|
111
112
|
type BaseTuple = readonly [
|
|
112
113
|
chainId: Hex.Hex,
|
|
113
114
|
keyType: Hex.Hex,
|
|
@@ -366,16 +367,16 @@ export type TokenLimit<bigintType = bigint, numberType = number> = {
|
|
|
366
367
|
* @param options - Key Authorization options.
|
|
367
368
|
* @returns The {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
368
369
|
*/
|
|
369
|
-
export declare function from<const authorization extends Input | Rpc, const signature extends
|
|
370
|
+
export declare function from<const authorization extends Input | Rpc, const signature extends PrimitiveSignatureValue | undefined = undefined>(authorization: authorization | KeyAuthorization, options?: from.Options<signature>): from.ReturnType<authorization, signature>;
|
|
370
371
|
export declare namespace from {
|
|
371
|
-
type Options<signature extends
|
|
372
|
-
/** The
|
|
373
|
-
signature?: signature | SignatureEnvelope.
|
|
372
|
+
type Options<signature extends PrimitiveSignatureValue | undefined = PrimitiveSignatureValue | undefined> = {
|
|
373
|
+
/** The primitive signature to attach to the Key Authorization. */
|
|
374
|
+
signature?: signature | SignatureEnvelope.Primitive | undefined;
|
|
374
375
|
};
|
|
375
|
-
type ReturnType<authorization extends KeyAuthorization | Input | Rpc = KeyAuthorization, signature extends
|
|
376
|
-
signature: SignatureEnvelope.from.ReturnValue<signature>;
|
|
376
|
+
type ReturnType<authorization extends KeyAuthorization | Input | Rpc = KeyAuthorization, signature extends PrimitiveSignatureValue | undefined = PrimitiveSignatureValue | undefined> = Compute<authorization extends Rpc ? Signed : authorization & (signature extends PrimitiveSignatureValue ? {
|
|
377
|
+
signature: Extract<SignatureEnvelope.from.ReturnValue<signature>, SignatureEnvelope.Primitive>;
|
|
377
378
|
} : {})>;
|
|
378
|
-
type ErrorType = Errors.GlobalErrorType;
|
|
379
|
+
type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType;
|
|
379
380
|
}
|
|
380
381
|
/**
|
|
381
382
|
* Converts an {@link ox#AuthorizationTempo.Rpc} to an {@link ox#AuthorizationTempo.AuthorizationTempo}.
|
|
@@ -409,7 +410,7 @@ export declare namespace from {
|
|
|
409
410
|
*/
|
|
410
411
|
export declare function fromRpc(authorization: Rpc): Signed;
|
|
411
412
|
export declare namespace fromRpc {
|
|
412
|
-
type ErrorType = Errors.GlobalErrorType;
|
|
413
|
+
type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType;
|
|
413
414
|
}
|
|
414
415
|
/**
|
|
415
416
|
* Converts an {@link ox#KeyAuthorization.Tuple} to an {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
@@ -463,7 +464,7 @@ export declare namespace fromRpc {
|
|
|
463
464
|
export declare function fromTuple<const tuple extends Tuple>(tuple: tuple): fromTuple.ReturnType<tuple>;
|
|
464
465
|
export declare namespace fromTuple {
|
|
465
466
|
type ReturnType<authorization extends Tuple = Tuple> = Compute<KeyAuthorization<authorization extends Tuple<true> ? true : false>>;
|
|
466
|
-
type ErrorType = Errors.GlobalErrorType;
|
|
467
|
+
type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType;
|
|
467
468
|
}
|
|
468
469
|
/**
|
|
469
470
|
* Computes the sign payload for an {@link ox#KeyAuthorization.KeyAuthorization}.
|
|
@@ -640,7 +641,7 @@ export declare function toRpc(authorization: toRpc.Input): Rpc;
|
|
|
640
641
|
export declare namespace toRpc {
|
|
641
642
|
/** Numberish input accepted by {@link ox#KeyAuthorization.(toRpc:function)}. */
|
|
642
643
|
type Input = Signed<Hex.Hex | bigint | number, Hex.Hex | number>;
|
|
643
|
-
type ErrorType = Errors.GlobalErrorType;
|
|
644
|
+
type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType;
|
|
644
645
|
}
|
|
645
646
|
/**
|
|
646
647
|
* Converts an {@link ox#KeyAuthorization.KeyAuthorization} to an {@link ox#KeyAuthorization.Tuple}.
|
|
@@ -678,7 +679,7 @@ export declare namespace toRpc {
|
|
|
678
679
|
export declare function toTuple<const authorization extends KeyAuthorization>(authorization: authorization): toTuple.ReturnType<authorization>;
|
|
679
680
|
export declare namespace toTuple {
|
|
680
681
|
type ReturnType<authorization extends KeyAuthorization = KeyAuthorization> = Compute<Tuple<authorization extends KeyAuthorization<true> ? true : false>>;
|
|
681
|
-
type ErrorType = Errors.GlobalErrorType;
|
|
682
|
+
type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType;
|
|
682
683
|
}
|
|
683
684
|
/** Thrown when a `witness` field is not exactly 32 bytes. */
|
|
684
685
|
export declare class InvalidWitnessSizeError extends Error {
|
|
@@ -690,5 +691,10 @@ export declare class InvalidAdminMarkerError extends Error {
|
|
|
690
691
|
readonly name = "KeyAuthorization.InvalidAdminMarkerError";
|
|
691
692
|
constructor(marker: Hex.Hex);
|
|
692
693
|
}
|
|
694
|
+
/** Thrown when a key authorization contains a non-primitive signature. */
|
|
695
|
+
export declare class InvalidSignatureTypeError extends Error {
|
|
696
|
+
readonly name = "KeyAuthorization.InvalidSignatureTypeError";
|
|
697
|
+
constructor(type: SignatureEnvelope.SignatureEnvelope['type']);
|
|
698
|
+
}
|
|
693
699
|
export {};
|
|
694
700
|
//# sourceMappingURL=KeyAuthorization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyAuthorization.d.ts","sourceRoot":"","sources":["../../src/tempo/KeyAuthorization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AACvC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAErC,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AAC/
|
|
1
|
+
{"version":3,"file":"KeyAuthorization.d.ts","sourceRoot":"","sources":["../../src/tempo/KeyAuthorization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AACvC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAErC,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/E,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AAC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B,GAAG,MAAM,CAAC,eAAe,CAAA;CACpE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,OAAO,CAAC,KAAK,CAAC,aAAa,SAAS,gBAAgB,EAClE,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CA0GnC;AAED,MAAM,CAAC,OAAO,WAAW,OAAO,CAAC;IAC/B,KAAK,UAAU,CAAC,aAAa,SAAS,gBAAgB,GAAG,gBAAgB,IACvE,OAAO,CAAC,KAAK,CAAC,aAAa,SAAS,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,CAAC,CAAA;IAE7E,KAAK,SAAS,GAAG,yBAAyB,GAAG,MAAM,CAAC,eAAe,CAAA;CACpE;AAgDD,6DAA6D;AAC7D,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,SAAkB,IAAI,8CAA6C;gBACvD,OAAO,EAAE,GAAG,CAAC,GAAG;CAK7B;AAED,2EAA2E;AAC3E,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,SAAkB,IAAI,8CAA6C;gBACvD,MAAM,EAAE,GAAG,CAAC,GAAG;CAK5B;AAED,0EAA0E;AAC1E,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,SAAkB,IAAI,gDAA+C;gBACzD,IAAI,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,MAAM,CAAC;CAK9D"}
|
|
@@ -172,6 +172,8 @@ export function from(authorization, options = {}) {
|
|
|
172
172
|
const auth = authorization;
|
|
173
173
|
if (auth.witness !== undefined)
|
|
174
174
|
assertWitness(auth.witness);
|
|
175
|
+
if (auth.signature)
|
|
176
|
+
assertSignature(auth.signature);
|
|
175
177
|
const resolved = {
|
|
176
178
|
...auth,
|
|
177
179
|
...(auth.scopes
|
|
@@ -183,11 +185,14 @@ export function from(authorization, options = {}) {
|
|
|
183
185
|
}
|
|
184
186
|
: {}),
|
|
185
187
|
};
|
|
186
|
-
if (options.signature)
|
|
188
|
+
if (options.signature) {
|
|
189
|
+
const signature = SignatureEnvelope.from(options.signature);
|
|
190
|
+
assertSignature(signature);
|
|
187
191
|
return {
|
|
188
192
|
...resolved,
|
|
189
|
-
signature
|
|
193
|
+
signature,
|
|
190
194
|
};
|
|
195
|
+
}
|
|
191
196
|
return resolved;
|
|
192
197
|
}
|
|
193
198
|
/**
|
|
@@ -226,6 +231,7 @@ export function fromRpc(authorization) {
|
|
|
226
231
|
const isAdmin = authorization.isAdmin ?? undefined;
|
|
227
232
|
const account = authorization.account ?? undefined;
|
|
228
233
|
const signature = SignatureEnvelope.fromRpc(authorization.signature);
|
|
234
|
+
assertSignature(signature);
|
|
229
235
|
if (witness !== undefined)
|
|
230
236
|
assertWitness(witness);
|
|
231
237
|
// Unflatten nested allowedCalls into flat scopes
|
|
@@ -394,8 +400,11 @@ export function fromTuple(tuple) {
|
|
|
394
400
|
...(witness !== undefined ? { witness } : {}),
|
|
395
401
|
...adminPair,
|
|
396
402
|
};
|
|
397
|
-
if (signatureSerialized)
|
|
398
|
-
|
|
403
|
+
if (signatureSerialized) {
|
|
404
|
+
const signature = SignatureEnvelope.deserialize(signatureSerialized);
|
|
405
|
+
assertSignature(signature);
|
|
406
|
+
args.signature = signature;
|
|
407
|
+
}
|
|
399
408
|
return from(args);
|
|
400
409
|
}
|
|
401
410
|
/**
|
|
@@ -571,6 +580,7 @@ export function serialize(authorization) {
|
|
|
571
580
|
*/
|
|
572
581
|
export function toRpc(authorization) {
|
|
573
582
|
const { address, scopes, chainId, expiry, limits, type, signature, witness, isAdmin, account, } = authorization;
|
|
583
|
+
assertSignature(signature);
|
|
574
584
|
if (witness !== undefined)
|
|
575
585
|
assertWitness(witness);
|
|
576
586
|
// Group flat scopes by address into nested allowedCalls wire format
|
|
@@ -651,9 +661,12 @@ export function toTuple(authorization) {
|
|
|
651
661
|
const { address, chainId, scopes, expiry, limits, witness, isAdmin, account, } = authorization;
|
|
652
662
|
if (witness !== undefined)
|
|
653
663
|
assertWitness(witness);
|
|
654
|
-
const signature =
|
|
655
|
-
|
|
656
|
-
|
|
664
|
+
const signature = (() => {
|
|
665
|
+
if (!authorization.signature)
|
|
666
|
+
return undefined;
|
|
667
|
+
assertSignature(authorization.signature);
|
|
668
|
+
return SignatureEnvelope.serialize(authorization.signature);
|
|
669
|
+
})();
|
|
657
670
|
const type = (() => {
|
|
658
671
|
switch (authorization.type) {
|
|
659
672
|
case 'secp256k1':
|
|
@@ -772,6 +785,10 @@ function assertWitness(witness) {
|
|
|
772
785
|
if (Hex.size(witness) !== 32)
|
|
773
786
|
throw new InvalidWitnessSizeError(witness);
|
|
774
787
|
}
|
|
788
|
+
function assertSignature(signature) {
|
|
789
|
+
if (signature.type === 'keychain' || signature.type === 'multisig')
|
|
790
|
+
throw new InvalidSignatureTypeError(signature.type);
|
|
791
|
+
}
|
|
775
792
|
function isAbsent(value) {
|
|
776
793
|
return value === undefined || value === '0x';
|
|
777
794
|
}
|
|
@@ -789,4 +806,11 @@ export class InvalidAdminMarkerError extends Error {
|
|
|
789
806
|
super(`Admin marker \`${marker}\` is invalid; expected \`0x01\` (TIP-1049).`);
|
|
790
807
|
}
|
|
791
808
|
}
|
|
809
|
+
/** Thrown when a key authorization contains a non-primitive signature. */
|
|
810
|
+
export class InvalidSignatureTypeError extends Error {
|
|
811
|
+
name = 'KeyAuthorization.InvalidSignatureTypeError';
|
|
812
|
+
constructor(type) {
|
|
813
|
+
super(`Signature type \`${type}\` is invalid for key authorizations; expected \`secp256k1\`, \`p256\`, or \`webAuthn\`.`);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
792
816
|
//# sourceMappingURL=KeyAuthorization.js.map
|