From ec8357f493d05a316f9cbb5ff7493e8770282ab0 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Tue, 23 Jan 2024 19:50:21 -0600 Subject: [PATCH] fixup! fix: document contract; refactor for clarity; use defensive patterns --- contract/src/offer-up.contract.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/contract/src/offer-up.contract.js b/contract/src/offer-up.contract.js index 60509de..58e1b7c 100644 --- a/contract/src/offer-up.contract.js +++ b/contract/src/offer-up.contract.js @@ -13,7 +13,7 @@ import { Far } from '@endo/far'; import { M, getCopyBagEntries } from '@endo/patterns'; -import { AmountMath, AssetKind } from '@agoric/ertp/src/amountMath.js'; +import { AssetKind } from '@agoric/ertp/src/amountMath.js'; import { AmountShape } from '@agoric/ertp/src/typeGuards.js'; import { atomicRearrange } from '@agoric/zoe/src/contractSupport/atomicTransfer.js'; import '@agoric/zoe/exported.js'; @@ -85,11 +85,11 @@ export const start = async zcf => { /** * a pattern to constrain proposals given to {@link tradeHandler} * - * The `Price` amount must use the brand from the `price` term. + * The `Price` amount must be >= `tradePrice` term. * The `Items` amount must use the `Item` brand and a bag value. */ const proposalShape = harden({ - give: { Price: { brand: tradePrice.brand, value: M.any() } }, + give: { Price: M.gte(tradePrice) }, want: { Items: { brand: itemBrand, value: M.bag() } }, exit: M.any(), }); @@ -97,13 +97,10 @@ export const start = async zcf => { /** a seat for allocating proceeds of sales */ const proceeds = zcf.makeEmptySeatKit().zcfSeat; - /** @param {ZCFSeat} buyerSeat */ + /** @type {OfferHandler} */ const tradeHandler = buyerSeat => { // give and want are guaranteed by Zoe to match proposalShape - const { give, want } = buyerSeat.getProposal(); - - AmountMath.isGTE(give.Price, tradePrice) || - Fail`${q(give.Price)} below required ${q(tradePrice)}}`; + const { want } = buyerSeat.getProposal(); sum(bagCounts(want.Items.value)) <= maxItems || Fail`max ${q(maxItems)} items allowed: ${q(want.Items)}`;