-
Notifications
You must be signed in to change notification settings - Fork 254
feat(zoe): zoe part of minimal want patterns using M.containerHas(el,n)
#10952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: markm-want-patterns-only-ertp
Are you sure you want to change the base?
Conversation
ffd5cdd to
b2b30dc
Compare
a2c8801 to
b8ebc19
Compare
c1fbfcf to
3698a77
Compare
a04ee47 to
20b287d
Compare
Closes: #XXXX Refs: #2002 #2008 #2113 #1739 Agoric/agoric-sdk#10952 ## Description This PR adds a new `M.containerHas(elementPatt, positiveBigint)` matcher, and exported `containerHasSplit` function. This is motivated to support Agoric/agoric-sdk#10952 , which introduces a minimal form of want pattern in terms of `M.containerHas`. - [x] Actually merging this must happen only after we've decided either to move forward with #2008 or to give up on it. Once a decision is made, and even before it is acted on, then this PR can move forward. (Any decision to move forward or not with #2008 should also consider changing the default of the feature flag introduced by #2002 .) ### Security Considerations none ### Scaling Considerations Might help due to early termination of the split operations, which Agoric/agoric-sdk#10952 uses for `AmountMath.isGTE`. ### Documentation Considerations Already doc-documents `M.containerHas` in the types.js file for `M`. That's probably good enough for this PR. The interesting documentation will be explaining want patterns in Agoric/agoric-sdk#10952 ### Testing Considerations Added tests for `M.containerHas` ### Compatibility Considerations The reason to postpone merging this PR until decisions are made on #2008 is that this PR will further expose `rankOrder` in the API, amplifying the danger that changing the string order will cause surprising observable changes. ### Upgrade Considerations This PR itself does not introduce any BREAKING changes or Upgrade issues. - [x] Update `NEWS.md` for user-facing changes.
1efc171 to
27b3006
Compare
bc8b038 to
bbd4873
Compare
|
Base branch is changed to master. Please re-run the integration tests by adding 'force:integration' label. |
a91d27c to
28f79dd
Compare
# `ses` v1.12.0 - The `evalTaming:` option values are renamed: - from `'safeEval'`, `'unsafeEval'`, and `'noEval'` - to `'safe-eval'`, `'unsafe-eval'`, and `'no-eval'` in order to follow the convention that lockdown option values use kebob-case rather than camelCase. To avoid breaking old programs during the transition, the old names are deprecated, but continue to work for now. - The value of expressions like `typeof unlikelyGlobal` is now `undefined` instead of producing a `ReferenceError` because it proves impossible to do so without revealing what properties exist on the host `globalThis` to compartmentalized code. # `@endo/patterns` v1.5.0 - New pattern: `M.containerHas(elementPatt, bound = 1n)` motivated to support want patterns in Zoe, to pull out only `bound` number of elements that match `elementPatt`. `bound` must be a positive bigint. - Closely related, `@endo/patterns` now exports `containerHasSplit` to support ERTP's use of `M.containerHas` on non-fungible (`set`, `copySet`) and semifungible (`copyBag`) assets, respectively. See Agoric/agoric-sdk#10952 . # `@endo/import-bundle` v1.4.0 - Adds support for `test` format bundles, which simply return a promise for an object that resembles a module exports namespace with the objects specified on the symbol-named property @exports, which is deliberately not JSON serializable or passable. - Adds a `typedImportBundle<ExpectedExportsNamespace>` function with a proper type signature, to provide a narrower signature than `any` without disrupting existing usage. # `@endo/bundle-source` v4.0.0 - Replaces the implementation for the `nestedEvaluate` and `getExport` formats with one based on Endo's Compartment Mapper instead of Rollup, in order to obviate the need to reconcile source map transforms between Rollup and the underlying Babel generator. As a consequence, we no longer generate a source map for the bundle, but Babel ensures that we preserve line and column numbers between the original source and the bundled source. # `@endo/compartment-mapper` v1.6.0 - Accommodates CommonJS modules that use `defineProperty` on `exports`. - Divides the role of `makeBundle` into `makeScript` and `makeFunctor`. The new `makeScript` replaces `makeBundle` without breaking changes, producing a JavaScript string that is suitable as a `<script>` tag in a web page. - The new `makeFunctor` produces a JavaScript string that, when evaluated, produces a partially applied function, so the caller can provide runtime options. - Both `makeScript` and `makeFunctor` now accept `format`, `useEvaluate` and `sourceUrlPrefix` options. - The functor produced by `makeFunctor` now accepts `evaluate`, `require`, and `sourceUrlPrefix` runtime options. - Both `makeScript` and `makeFunctor` now accept a `format` option. Specifiying the `"cjs"` format allows the bundle to exit to the host's CommonJS `require` for host modules. - Adds `sourceDirname` to compartment descriptors in the compartment maps generated by `mapNodeModules` and uses these to provide better source URL comments for bundles generated by `makeScript` and `makeFunctor`, by default. These changes collectively allow us to replace the implementation of `nestedEvaluate` and `getExports` formats in `@endo/bundle-source`, including the preservation of useful line numbers and file names in stack traces. - `mapNodeModules`, `importLocation` and `loadLocation` now accept a `log` option for users to define a custom logging function. As of this writing, _only `mapNodeModules`_ will potentially call this function if provided. Expansion of log messaging and support for the `log` option in more APIs is expected _in the future_. # `@endo/evasive-transform` v1.4.0 - Adds a `sourceMap` option so that the generated sourcemap can project back to the original source code without `unmapLoc`. - Removes support for sourcemap `unmapLoc` because it is not used by contemporary Endo packages. The option is now ignored.
5260960 to
43794cc
Compare
7e865f7 to
113653c
Compare
a1ed11d to
6f54123
Compare
6f54123 to
67b544c
Compare
M.containerHas(el,n)
M.containerHas(el,n)M.containerHas(el,n)
ae6b40c to
2e4d932
Compare
67b544c to
89b0caa
Compare
2e4d932 to
979da2a
Compare
89b0caa to
e13d700
Compare
979da2a to
b01e796
Compare
e13d700 to
9b970c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements minimal want patterns support in Zoe, allowing the use of M.containerHas(el,n) patterns in proposal wants. The implementation focuses on the Zoe-side infrastructure needed to handle amount bounds (patterns) rather than just exact amounts in proposal wants.
Key changes:
- Updates type definitions to distinguish between
AmountandAmountBoundtypes - Modifies proposal processing to support patterns in want clauses while maintaining backwards compatibility
- Adds infrastructure for pattern validation and conversion
Reviewed Changes
Copilot reviewed 20 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/zoe/tools/setup-zoe.js | Updates import organization for Installation type |
| packages/zoe/test/unitTests/zoe/escrowStorage.test.js | Adds mock getAssetKindByBrand function parameter to test calls |
| packages/zoe/test/unitTests/setupBasicMints.js | Replaces AmountMath.make with direct amount construction and updates type annotations |
| packages/zoe/test/unitTests/cleanProposal.test.js | Updates tests to use M.containerHas patterns instead of M.any() |
| packages/zoe/test/types.test-d.ts | Reorganizes type imports for Installation |
| packages/zoe/src/zoeService/zoeStorageManager.js | Passes getAssetKindByBrand function to provideEscrowStorage |
| packages/zoe/src/zoeService/types.ts | Major type reorganization introducing AmountBound types and consolidating imports |
| packages/zoe/src/zoeService/internal-types.js | Updates type imports and references |
| packages/zoe/src/zoeService/escrowStorage.js | Adds getAssetKindByAmount helper and updates empty amount creation |
| packages/zoe/src/types.ts | Minor import reorganization |
| packages/zoe/src/typeGuards.js | Replaces AmountPatternKeywordRecordShape with AmountBoundKeywordRecordShape |
| packages/zoe/src/contracts/loan/borrow.js | Adds type assertions and pattern validation for amounts |
| packages/zoe/src/contracts/auction/secondPriceLogic.js | Adds type assertion for brand |
| packages/zoe/src/contracts/auction/firstPriceLogic.js | Adds type assertion for brand |
| packages/zoe/src/contractSupport/zoeHelpers.js | Adds mustBeKey helper and updates swapExact to handle amount bounds |
| packages/zoe/src/contractSupport/atomicTransfer.js | Updates to support AmountBound types in transfer operations |
| packages/zoe/src/contractFacet/types.ts | Updates TransferPart type to use AmountBoundKeywordRecord |
| packages/zoe/src/contractFacet/reallocate.js | Adds pattern validation for transfer amounts |
| packages/zoe/src/contractFacet/offerSafety.js | Updates to work with AmountBound types |
| packages/zoe/src/cleanProposal.js | Major refactoring to support AmountBound validation and M.containerHas patterns |
| resultingAllocations.push([seat, newAlloc]); | ||
| } | ||
| return resultingAllocations; | ||
| return harden(resultingAllocations); |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from returning resultingAllocations to harden(resultingAllocations) suggests the original array wasn't hardened. This should be verified against the function's return type expectations and existing callers to ensure compatibility.
| * @param {AmountBoundKeywordRecord} want | ||
| * @param {string} complaint | ||
| * @returns {AmountKeywordRecord} | ||
| */ | ||
| export const mustBeKey = (want, complaint) => { | ||
| if (isKey(want)) { | ||
| return want; | ||
| } | ||
| if (isPattern(want)) { | ||
| throw Fail`${b(complaint)}: ${want}`; | ||
| } | ||
| throw Fail`Must be key: ${want}`; |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The function parameter is named want but the function is generic and could be used for other purposes. Consider renaming to value or input for better clarity.
| * @param {AmountBoundKeywordRecord} want | |
| * @param {string} complaint | |
| * @returns {AmountKeywordRecord} | |
| */ | |
| export const mustBeKey = (want, complaint) => { | |
| if (isKey(want)) { | |
| return want; | |
| } | |
| if (isPattern(want)) { | |
| throw Fail`${b(complaint)}: ${want}`; | |
| } | |
| throw Fail`Must be key: ${want}`; | |
| * @param {AmountBoundKeywordRecord} value | |
| * @param {string} complaint | |
| * @returns {AmountKeywordRecord} | |
| */ | |
| export const mustBeKey = (value, complaint) => { | |
| if (isKey(value)) { | |
| return value; | |
| } | |
| if (isPattern(value)) { | |
| throw Fail`${b(complaint)}: ${value}`; | |
| } | |
| throw Fail`Must be key: ${value}`; |
| } | ||
| const fromAmounts = mustBeKey( | ||
| fromAmountBounds, | ||
| 'TODO: atomicRearange does not yet support AmountBounds', |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"atomicRearange" should be "atomicRearrange" (missing 'r').
| 'TODO: atomicRearange does not yet support AmountBounds', | |
| 'TODO: atomicRearrange does not yet support AmountBounds', |
Staged on #11235 , which provides the E part
closes: #XXXX
refs: endojs/endo#2710 #1905 #1913 #1915 #2155 #2156 #2230 #4212 #4217 #10951 #11235
Description
Implements minimal want patterns, where the only supported pattern is
M.containerHasSecurity Considerations
none
Scaling Considerations
By allowing want patterns, might this make the processing of wants more expensive?
Documentation Considerations
Need to update the Zoe API docs to explain want-patterns
Testing Considerations
Upgrade Considerations
None