Skip to content

Commit 96c9ff5

Browse files
authored
chore: Sync Endo versions (2024-05-07) (#9334)
This brings Agoric in sync with Endo versions endojs/endo#2272 which covers a new `Passable` type and improvements to `pass-style`, `patterns`, and `exo`. This subsumes changes from #8774 necessary for integration.
2 parents aa68d8f + f83c530 commit 96c9ff5

203 files changed

Lines changed: 1468 additions & 1183 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MAINTAINERS.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ From `origin/master`, begin a branch for syncing Endo.
264264

265265
```sh
266266
NOW=`date -u +%Y-%m-%d-%H-%M-%S`
267-
git checkout -b "$USER-sync-endo-$NOW" origin/endo-integration-master
268-
git rebase origin/master
267+
git checkout -b "$USER-sync-endo-$NOW"
268+
git rebase origin/integration-endo-master
269269
```
270270

271271
Use a helper script from the Endo repository to update the dependency versions
@@ -308,8 +308,6 @@ Increment the meter type in `packages/xsnap/api.js`:
308308
export const METER_TYPE = 'xs-meter-0';
309309
```
310310

311-
Be sure to also update `test/test-xs-perf.js` with the new meter version.
312-
313311
```sh
314312
cd packages/xsnap
315313
git add api.js

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type": "module",
1111
"packageManager": "yarn@1.22.19",
1212
"devDependencies": {
13-
"@endo/eslint-plugin": "^2.1.2",
13+
"@endo/eslint-plugin": "^2.1.3",
1414
"@jessie.js/eslint-plugin": "^0.4.1",
1515
"@types/express": "^4.17.17",
1616
"@types/node": "^18.19.24",

packages/ERTP/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@
4444
"@agoric/store": "^0.9.2",
4545
"@agoric/vat-data": "^0.5.2",
4646
"@agoric/zone": "^0.2.2",
47-
"@endo/eventual-send": "^1.2.1",
48-
"@endo/far": "^1.1.1",
49-
"@endo/marshal": "^1.4.1",
50-
"@endo/nat": "^5.0.6",
51-
"@endo/patterns": "^1.3.1",
52-
"@endo/promise-kit": "^1.1.1"
47+
"@endo/eventual-send": "^1.2.2",
48+
"@endo/far": "^1.1.2",
49+
"@endo/marshal": "^1.5.0",
50+
"@endo/nat": "^5.0.7",
51+
"@endo/patterns": "^1.4.0",
52+
"@endo/promise-kit": "^1.1.2"
5353
},
5454
"devDependencies": {
5555
"@agoric/swingset-vat": "^0.32.2",
56-
"@endo/bundle-source": "^3.2.2",
56+
"@endo/bundle-source": "^3.2.3",
5757
"@fast-check/ava": "^1.1.5",
5858
"ava": "^5.3.0",
5959
"tsd": "^0.30.7"
@@ -86,6 +86,6 @@
8686
"access": "public"
8787
},
8888
"typeCoverage": {
89-
"atLeast": 90.62
89+
"atLeast": 91.21
9090
}
9191
}

packages/ERTP/src/amountMath.js

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { setMathHelpers } from './mathHelpers/setMathHelpers.js';
66
import { copySetMathHelpers } from './mathHelpers/copySetMathHelpers.js';
77
import { copyBagMathHelpers } from './mathHelpers/copyBagMathHelpers.js';
88

9-
/** @import {Amount, AssetKind, AmountValue, AssetKindForValue, AssetValueForKind, Brand, MathHelpers} from './types.js' */
9+
/**
10+
* @import {CopyBag, CopySet} from '@endo/patterns';
11+
* @import {Amount, AssetKind, AmountValue, AssetKindForValue, AssetValueForKind, Brand, CopyBagAmount, CopySetAmount, MathHelpers, NatAmount, NatValue, SetAmount, SetValue} from './types.js';
12+
*/
1013

1114
const { quote: q, Fail } = assert;
1215

@@ -76,26 +79,19 @@ const helpers = {
7679
copyBag: copyBagMathHelpers,
7780
};
7881

79-
/**
80-
* @template {AmountValue} V
81-
* @type {(value: V) => AssetKindForValue<V>}
82-
*/
82+
/** @type {(value: unknown) => 'nat' | 'set' | 'copySet' | 'copyBag'} } */
8383
const assertValueGetAssetKind = value => {
8484
const passStyle = passStyleOf(value);
8585
if (passStyle === 'bigint') {
86-
// @ts-expect-error cast
8786
return 'nat';
8887
}
8988
if (passStyle === 'copyArray') {
90-
// @ts-expect-error cast
9189
return 'set';
9290
}
9391
if (matches(value, M.set())) {
94-
// @ts-expect-error cast
9592
return 'copySet';
9693
}
9794
if (matches(value, M.bag())) {
98-
// @ts-expect-error cast
9995
return 'copyBag';
10096
}
10197
// TODO This isn't quite the right error message, in case valuePassStyle
@@ -113,7 +109,7 @@ const assertValueGetAssetKind = value => {
113109
*
114110
* Made available only for testing, but it is harmless for other uses.
115111
*
116-
* @template {AmountValue} V
112+
* @template V
117113
* @param {V} value
118114
* @returns {MathHelpers<V>}
119115
*/
@@ -198,29 +194,44 @@ const isGTE = (leftAmount, rightAmount, brand = undefined) => {
198194
* the abstract right to participate in a particular exchange.
199195
*/
200196
const AmountMath = {
197+
// TODO use overloading to handle when Brand has an AssetKind and when it doesn't.
198+
// a AmountForValue utility could help DRY those cases.
201199
/**
202200
* Make an amount from a value by adding the brand.
203201
*
204-
* @template {AssetKind} K
205-
* @param {Brand<K>} brand
206-
* @param {AssetValueForKind<K>} allegedValue
207-
* @returns {Amount<K>}
202+
* Does not verify that the Brand's AssetKind matches the value's.
203+
*
204+
* @template {Brand} B
205+
* @template {NatValue | CopySet | CopyBag | SetValue} V
206+
* @param {B} brand
207+
* @param {V} allegedValue
208+
* @returns {B extends Brand<'nat'>
209+
* ? NatAmount
210+
* : V extends NatValue
211+
* ? NatAmount
212+
* : V extends CopySet
213+
* ? CopySetAmount<V['payload'][0]>
214+
* : V extends CopyBag
215+
* ? CopyBagAmount<V['payload'][0][0]>
216+
* : V extends SetValue
217+
* ? SetAmount<V[0]>
218+
* : never}
208219
*/
209-
// allegedValue has a conditional expression for type widening, to prevent V being bound to a a literal like 1n
210220
make: (brand, allegedValue) => {
211221
assertRemotable(brand, 'brand');
212222
const h = assertValueGetHelpers(allegedValue);
213223
const value = h.doCoerce(allegedValue);
224+
// @ts-expect-error cast
214225
return harden({ brand, value });
215226
},
216227
/**
217228
* Make sure this amount is valid enough, and return a corresponding valid
218229
* amount if so.
219230
*
220-
* @template {AssetKind} K
221-
* @param {Brand<K>} brand
222-
* @param {Amount<K>} allegedAmount
223-
* @returns {Amount<K>}
231+
* @template {Amount} A
232+
* @param {Brand} brand
233+
* @param {A} allegedAmount
234+
* @returns {A}
224235
*/
225236
coerce: (brand, allegedAmount) => {
226237
assertRemotable(brand, 'brand');
@@ -229,15 +240,16 @@ const AmountMath = {
229240
brand === allegedBrand ||
230241
Fail`The brand in the allegedAmount ${allegedAmount} in 'coerce' didn't match the specified brand ${brand}.`;
231242
// Will throw on inappropriate value
243+
// @ts-expect-error cast
232244
return AmountMath.make(brand, allegedValue);
233245
},
234246
/**
235247
* Extract and return the value.
236248
*
237-
* @template {AssetKind} K
238-
* @param {Brand<K>} brand
239-
* @param {Amount<K>} amount
240-
* @returns {AssetValueForKind<K>}
249+
* @template {Amount} A
250+
* @param {Brand} brand
251+
* @param {A} amount
252+
* @returns {A['value']}
241253
*/
242254
getValue: (brand, amount) => AmountMath.coerce(brand, amount).value,
243255
/**
@@ -246,29 +258,29 @@ const AmountMath = {
246258
*
247259
* @type {{
248260
* (brand: Brand): Amount<'nat'>;
249-
* <K extends AssetKind>(brand: Brand, assetKind: K): Amount<K>;
261+
* <K extends AssetKind>(brand: Brand<K>, assetKind: K): Amount<K>;
250262
* }}
251263
*/
252264
makeEmpty: (brand, assetKind = /** @type {const} */ ('nat')) => {
253265
assertRemotable(brand, 'brand');
254266
assertAssetKind(assetKind);
255267
const value = helpers[assetKind].doMakeEmpty();
268+
// @ts-expect-error XXX narrowing from function overload
256269
return harden({ brand, value });
257270
},
258271
/**
259272
* Return the amount representing an empty amount, using another amount as the
260273
* template for the brand and assetKind.
261274
*
262-
* @template {AssetKind} K
263-
* @param {Amount<K>} amount
264-
* @returns {Amount<K>}
275+
* @template {Amount} A
276+
* @param {A} amount
277+
* @returns {A}
265278
*/
266279
makeEmptyFromAmount: amount => {
267280
assertRecord(amount, 'amount');
268281
const { brand, value } = amount;
269-
// @ts-expect-error cast
270282
const assetKind = assertValueGetAssetKind(value);
271-
// @ts-expect-error cast (ignore b/c erroring in CI but not my IDE)
283+
// @ts-expect-error different subtype
272284
return AmountMath.makeEmpty(brand, assetKind);
273285
},
274286
/**
@@ -291,10 +303,10 @@ const AmountMath = {
291303
* Returns true if the leftAmount equals the rightAmount. We assume that if
292304
* isGTE is true in both directions, isEqual is also true
293305
*
294-
* @template {AssetKind} K
295-
* @param {Amount<K>} leftAmount
296-
* @param {Amount<K>} rightAmount
297-
* @param {Brand<K>} [brand]
306+
* @template {Amount} A
307+
* @param {A} leftAmount
308+
* @param {A} rightAmount
309+
* @param {Brand} [brand]
298310
* @returns {boolean}
299311
*/
300312
isEqual: (leftAmount, rightAmount, brand = undefined) => {
@@ -308,15 +320,16 @@ const AmountMath = {
308320
* amount, it usually means including all of the elements from both left and
309321
* right.
310322
*
311-
* @template {AssetKind} K
312-
* @param {Amount<K>} leftAmount
313-
* @param {Amount<K>} rightAmount
314-
* @param {Brand<K>} [brand]
315-
* @returns {Amount<K>}
323+
* @template {Amount} A
324+
* @param {A} leftAmount
325+
* @param {A} rightAmount
326+
* @param {Brand} [brand]
327+
* @returns {A}
316328
*/
317329
add: (leftAmount, rightAmount, brand = undefined) => {
318330
const h = checkLRAndGetHelpers(leftAmount, rightAmount, brand);
319331
const value = h.doAdd(...coerceLR(h, leftAmount, rightAmount));
332+
// @ts-expect-error different subtype
320333
return harden({ brand: leftAmount.brand, value });
321334
},
322335
/**
@@ -326,25 +339,27 @@ const AmountMath = {
326339
* error. Because the left amount must include the right amount, this is NOT
327340
* equivalent to set subtraction.
328341
*
329-
* @template {AssetKind} K
330-
* @param {Amount<K>} leftAmount
331-
* @param {Amount<K>} rightAmount
332-
* @param {Brand<K>} [brand]
333-
* @returns {Amount<K>}
342+
* @template {Amount} L
343+
* @template {Amount} R
344+
* @param {L} leftAmount
345+
* @param {R} rightAmount
346+
* @param {Brand} [brand]
347+
* @returns {L extends R ? L : never}
334348
*/
335349
subtract: (leftAmount, rightAmount, brand = undefined) => {
336350
const h = checkLRAndGetHelpers(leftAmount, rightAmount, brand);
337351
const value = h.doSubtract(...coerceLR(h, leftAmount, rightAmount));
352+
// @ts-expect-error different subtype
338353
return harden({ brand: leftAmount.brand, value });
339354
},
340355
/**
341356
* Returns the min value between x and y using isGTE
342357
*
343-
* @template {AssetKind} K
344-
* @param {Amount<K>} x
345-
* @param {Amount<K>} y
346-
* @param {Brand<K>} [brand]
347-
* @returns {Amount<K>}
358+
* @template {Amount} A
359+
* @param {A} x
360+
* @param {A} y
361+
* @param {Brand} [brand]
362+
* @returns {A}
348363
*/
349364
min: (x, y, brand = undefined) =>
350365
// eslint-disable-next-line no-nested-ternary
@@ -356,11 +371,11 @@ const AmountMath = {
356371
/**
357372
* Returns the max value between x and y using isGTE
358373
*
359-
* @template {AssetKind} K
360-
* @param {Amount<K>} x
361-
* @param {Amount<K>} y
362-
* @param {Brand<K>} [brand]
363-
* @returns {Amount<K>}
374+
* @template {Amount} A
375+
* @param {A} x
376+
* @param {A} y
377+
* @param {Brand} [brand]
378+
* @returns {A}
364379
*/
365380
max: (x, y, brand = undefined) =>
366381
// eslint-disable-next-line no-nested-ternary
@@ -376,7 +391,6 @@ harden(AmountMath);
376391
const getAssetKind = amount => {
377392
assertRecord(amount, 'amount');
378393
const { value } = amount;
379-
// @ts-expect-error cast (ignore b/c erroring in CI but not my IDE)
380394
return assertValueGetAssetKind(value);
381395
};
382396
harden(getAssetKind);

packages/ERTP/src/issuerKit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ harden(prepareIssuerKit);
325325
* anything else is corrupted by that corrupted state. See
326326
* https://github.com/Agoric/agoric-sdk/issues/3434
327327
* @param {IssuerOptionsRecord} [options]
328-
* @returns {IssuerKit<K>}
328+
* @returns {IssuerKit<K, any>}
329329
*/
330330
export const makeIssuerKit = (
331331
name,

packages/ERTP/src/legacy-payment-helpers.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ const { Fail } = assert;
2626
*/
2727

2828
/**
29-
* @template {AssetKind} K
30-
* @param {ERef<Purse<K>>} recoveryPurse
31-
* @param {ERef<Payment<K>>} srcPaymentP
29+
* @template {Payment} P
30+
* @param {ERef<Purse>} recoveryPurse
31+
* @param {ERef<P>} srcPaymentP
3232
* @param {Pattern} [optAmountShape]
33-
* @returns {Promise<Payment<K>>}
33+
* @returns {Promise<P>}
3434
*/
3535
export const claim = async (
3636
recoveryPurse,
3737
srcPaymentP,
3838
optAmountShape = undefined,
3939
) => {
4040
const srcPayment = await srcPaymentP;
41+
// @ts-expect-error XXX could be instantiated with a different subtype
4142
return E.when(E(recoveryPurse).deposit(srcPayment, optAmountShape), amount =>
4243
E(recoveryPurse).withdraw(amount),
4344
);

0 commit comments

Comments
 (0)