Skip to content

Commit

Permalink
fixup! fix: document contract; refactor for clarity; use defensive pa…
Browse files Browse the repository at this point in the history
…tterns
  • Loading branch information
dckc committed Jan 24, 2024
1 parent 739bfb5 commit ec8357f
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions contract/src/offer-up.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -85,25 +85,22 @@ 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(),
});

/** 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)}`;
Expand Down

0 comments on commit ec8357f

Please sign in to comment.