Skip to content

Commit

Permalink
fix(zoe,pegasus): a few more invitation proposal shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Aug 29, 2023
1 parent d5a33e9 commit 1163e9a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
22 changes: 12 additions & 10 deletions packages/pegasus/src/pegasus.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// @ts-check

import { assert, details as X, Fail } from '@agoric/assert';
import { makeLegacyWeakMap, makeLegacyMap } from '@agoric/store';
import { makeLegacyWeakMap, makeLegacyMap, M } from '@agoric/store';
import { E, Far } from '@endo/far';
import {
assertProposalShape,
atomicTransfer,
} from '@agoric/zoe/src/contractSupport/index.js';
import { atomicTransfer } from '@agoric/zoe/src/contractSupport/index.js';
import { makeSubscriptionKit } from '@agoric/notifier';
import { AmountShape } from '@agoric/ertp';

import '@agoric/network/exported.js';
import '@agoric/zoe/exported.js';
Expand All @@ -20,11 +18,11 @@ import { makeCourierMaker, getCourierPK } from './courier.js';
const DEFAULT_DENOM_TRANSFORMER = IBCSourceTraceDenomTransformer;
const DEFAULT_TRANSFER_PROTOCOL = ICS20TransferProtocol;

const TRANSFER_PROPOSAL_SHAPE = {
const TransferProposalShape = M.splitRecord({
give: {
Transfer: null,
Transfer: AmountShape, // TODO get amount shape from brand
},
};
});

/**
* Make a Pegasus public API.
Expand Down Expand Up @@ -481,11 +479,15 @@ const makePegasus = (zcf, board, namesByAddress) => {
* @type {OfferHandler}
*/
const offerHandler = zcfSeat => {
assertProposalShape(zcfSeat, TRANSFER_PROPOSAL_SHAPE);
send(zcfSeat, depositAddress, memo);
};

return zcf.makeInvitation(offerHandler, `pegasus ${sendDenom} transfer`);
return zcf.makeInvitation(
offerHandler,
`pegasus ${sendDenom} transfer`,
undefined,
TransferProposalShape,
);
},
});
};
Expand Down
7 changes: 7 additions & 0 deletions packages/zoe/src/contractSupport/zoeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AssetKind } from '@agoric/ertp';
import { fromUniqueEntries } from '@agoric/internal';
import { satisfiesWant } from '../contractFacet/offerSafety.js';
import { atomicTransfer, fromOnly, toOnly } from './atomicTransfer.js';
import { AmountKeywordRecordShape } from '../typeGuards.js';

export const defaultAcceptanceMsg = `The offer has been accepted. Once the contract has been completed, please check your payout`;

Expand Down Expand Up @@ -199,6 +200,12 @@ export const depositToSeat = async (zcf, recipientSeat, amounts, payments) => {
const invitation = zcf.makeInvitation(
reallocateAfterDeposit,
'temporary seat for deposit',
undefined,
harden({
give: AmountKeywordRecordShape,
want: {},
exit: { onDemand: null },
}),
);
const proposal = harden({ give: amounts });
harden(payments);
Expand Down
52 changes: 37 additions & 15 deletions packages/zoe/src/contracts/auction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { E } from '@endo/eventual-send';
import { mustMatch } from '@endo/patterns';
import { Far } from '@endo/marshal';
import { TimeMath, RelativeTimeShape } from '@agoric/time';
import { M } from '@agoric/store';
import { AmountShape } from '@agoric/ertp';

// Eventually will be importable from '@agoric/zoe-contract-support'
import {
defaultAcceptanceMsg,
assertIssuerKeywords,
assertProposalShape,
} from '../../contractSupport/index.js';
import * as secondPriceLogic from './secondPriceLogic.js';
import * as firstPriceLogic from './firstPriceLogic.js';
Expand Down Expand Up @@ -116,15 +117,33 @@ const start = zcf => {
});
};

const BidProposalShape = M.splitRecord({
give: {
Bid: AmountShape, // TODO get amount shape from brand
},
want: {
Asset: AmountShape, // TODO get amount shape from brand
},
});

const SellProposalShape = M.splitRecord({
give: {
Asset: AmountShape, // TODO get amount shape from brand
},
want: {
Ask: AmountShape, // TODO get amount shape from brand
},
exit: {
// The auction is not over until the deadline according to the
// provided timer. The seller cannot exit beforehand.
waived: null,
},
});

const makeBidInvitation = () => {
/** @type {OfferHandler} */
const performBid = seat => {
assert(!isClosed, 'Auction session is closed, no more bidding');

assertProposalShape(seat, {
give: { Bid: null },
want: { Asset: null },
});
assertBidSeat(zcf, sellSeat, seat);

// XXX await make function hanging
Expand All @@ -135,17 +154,15 @@ const start = zcf => {
};

const customDetails = getSessionDetails();
return zcf.makeInvitation(performBid, 'bid', customDetails);
return zcf.makeInvitation(
performBid,
'bid',
customDetails,
BidProposalShape,
);
};

const sell = seat => {
assertProposalShape(seat, {
give: { Asset: null },
want: { Ask: null },
// The auction is not over until the deadline according to the
// provided timer. The seller cannot exit beforehand.
exit: { waived: null },
});
// Save the seat for when the auction closes.
sellSeat = seat;

Expand All @@ -159,7 +176,12 @@ const start = zcf => {
getSessionDetails,
});

const creatorInvitation = zcf.makeInvitation(sell, 'sellAssets');
const creatorInvitation = zcf.makeInvitation(
sell,
'sellAssets',
undefined,
SellProposalShape,
);

return harden({ creatorInvitation, publicFacet });
};
Expand Down
6 changes: 6 additions & 0 deletions packages/zoe/src/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export const FullProposalShape = harden({
/** @see {Proposal} type */
export const ProposalShape = M.splitRecord({}, FullProposalShape, {});

export const EmptyProposalShape = M.splitRecord({
give: {},
want: {},
exit: { onDemand: null },
});

export const isOnDemandExitRule = exit => {
const [exitKey] = Object.keys(exit);
return exitKey === 'onDemand';
Expand Down

0 comments on commit 1163e9a

Please sign in to comment.