Skip to content

Commit

Permalink
fix: review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Mar 19, 2023
1 parent 22dd70c commit 2b38651
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 78 deletions.
35 changes: 33 additions & 2 deletions packages/inter-protocol/src/stakeFactory/stakeFactory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @jessie-check
import { AmountMath } from '@agoric/ertp';
import { handleParamGovernance, ParamTypes } from '@agoric/governance';
import { M } from '@agoric/store';
import { atomicRearrange } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
import { E, Far } from '@endo/far';
import { makeMakeCollectFeesInvitation } from '../collectFees.js';
Expand Down Expand Up @@ -100,9 +101,11 @@ export const start = async (
/** @type {ZCFMint<'nat'>} */
const debtMint = await zcf.registerFeeMint(KW.Debt, feeMintAccess);
const { brand: debtBrand } = debtMint.getIssuerRecord();
const debtAmountShape = debtBrand.getAmountShape();

const att = await makeAttestationFacets(zcf, stakeBrand, lienBridge);
const attestBrand = await E(att.publicFacet).getBrand();
const attestAmountShape = attestBrand.getAmountShape();

const { augmentPublicFacet, makeGovernorFacet, params } =
await handleParamGovernance(
Expand Down Expand Up @@ -173,6 +176,15 @@ export const start = async (
{ timerService, chargingPeriod, recordingPeriod, startTimeStamp },
);

const StakeFactoryCloseProposalShape = M.splitRecord({
give: {
[KW.Debt]: debtAmountShape,
},
want: {
[KW.Attestation]: attestAmountShape,
},
});

/**
* @param {ZCFSeat} seat
*/
Expand All @@ -190,16 +202,35 @@ export const start = async (
'AdjustBalances',
),
CloseVault: () =>
zcf.makeInvitation(seatx => helper.closeHook(seatx), 'CloseVault'),
zcf.makeInvitation(
seatx => helper.closeHook(seatx),
'CloseVault',
undefined,
StakeFactoryCloseProposalShape,
),
}),
vault: pot,
});
};

const MakeStakeFactoryProposalShape = M.splitRecord({
give: {
[KW.Attestation]: attestAmountShape,
},
want: {
[KW.Debt]: debtAmountShape,
},
});

const publicFacet = augmentPublicFacet(
harden({
makeLoanInvitation: () =>
zcf.makeInvitation(offerHandler, 'make stakeFactory'),
zcf.makeInvitation(
offerHandler,
'make stakeFactory',
undefined,
MakeStakeFactoryProposalShape,
),
makeReturnAttInvitation: att.publicFacet.makeReturnAttInvitation,
}),
);
Expand Down
50 changes: 20 additions & 30 deletions packages/inter-protocol/src/stakeFactory/stakeFactoryKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { bindAllMethods, makeTracer } from '@agoric/internal';
import { makePublishKit } from '@agoric/notifier';
import { M, matches } from '@agoric/store';
import { defineKindMulti } from '@agoric/vat-data';
import {
assertProposalShape,
atomicRearrange,
} from '@agoric/zoe/src/contractSupport/index.js';
import { atomicRearrange } from '@agoric/zoe/src/contractSupport/index.js';
import { ceilMultiplyBy } from '@agoric/zoe/src/contractSupport/ratio.js';
import { addSubtract } from '../contractSupport.js';
import { calculateCurrentDebt, reverseInterest } from '../interest-math.js';
Expand Down Expand Up @@ -74,12 +71,6 @@ const initState = (zcf, startSeat, manager) => {
const emptyDebt = AmountMath.makeEmpty(debtBrand);

const initialDebt = (() => {
// What `makeInvitation` call does this correspond to?
// TODO use a proposalShape there and kill the `assertProposalShape` here.
assertProposalShape(startSeat, {
give: { [KW.Attestation]: null },
want: { [KW.Debt]: null },
});
const {
give: { [KW.Attestation]: attestationGiven },
want: { [KW.Debt]: runWanted },
Expand Down Expand Up @@ -374,26 +365,25 @@ const potBehavior = {
const { helper } = facets;
assert(state.open);

// Or should this be more like the AdjustBalancesProposalShape in
// vaultFactory, that allows both records to have both properties?
const AdjustBalancesProposalShape = M.or(
M.splitRecord({
give: {
Attestation: AmountShape, // TODO brand specific AmountShape
},
want: {
Debt: AmountShape, // TODO brand specific AmountShape
},
}),
M.splitRecord({
give: {
Debt: AmountShape, // TODO brand specific AmountShape
// Adjustments must be able to specify just the 'give' or the 'want'.
const AdjustBalancesProposalShape = M.splitRecord({
give: M.splitRecord(
{},
{
Attestation: AmountShape, // TODO get amount shape from brand
Debt: AmountShape, // TODO get amount shape from brand
},
want: {
Attestation: AmountShape, // TODO brand specific AmountShape
{},
),
want: M.splitRecord(
{},
{
Attestation: AmountShape, // TODO get amount shape from brand
Debt: AmountShape, // TODO get amount shape from brand
},
}),
);
{},
),
});

return zcf.makeInvitation(
seat => helper.adjustBalancesHook(seat),
Expand All @@ -410,10 +400,10 @@ const potBehavior = {

const CloseProposalShape = M.splitRecord({
give: {
[KW.Debt]: AmountShape, // TODO brand specific AmountShape
[KW.Debt]: AmountShape, // TODO get amount shape from brand
},
want: {
[KW.Attestation]: AmountShape, // TODO brand specific AmountShape
[KW.Attestation]: AmountShape, // TODO get amount shape from brand
},
});

Expand Down
36 changes: 0 additions & 36 deletions packages/inter-protocol/src/vaultFactory/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,42 +182,6 @@ export const VaultI = M.interface('Vault', {
export const prepareVault = (baggage, marshaller, zcf) => {
const makeVaultKit = prepareVaultKit(baggage, marshaller);

const AdjustBalancesProposalShape = M.splitRecord({
give: M.splitRecord(
{},
{
Collateral: AmountShape, // TODO brand specific AmountShape
Minted: AmountShape, // TODO brand specific AmountShape
},
{},
),
want: M.splitRecord(
{},
{
Collateral: AmountShape, // TODO brand specific AmountShape
Minted: AmountShape, // TODO brand specific AmountShape
},
{},
),
});

const CloseProposalShape = M.splitRecord({
give: M.splitRecord(
{},
{
Minted: AmountShape, // TODO brand specific AmountShape
},
{},
),
want: M.splitRecord(
{},
{
Collateral: AmountShape, // TODO brand specific AmountShape
},
{},
),
});

const maker = prepareExoClassKit(
baggage,
'Vault',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ test('extra offer keywords are rejected', async t => {
harden({ [KW.Attestation]: attPmt }),
);
await t.throwsAsync(E(seat).getOfferResult(), {
message: /Pony.*did not match/,
message:
/^"make stakeFactory" proposal: want: .* - Must not have unexpected properties: \["Pony"\]$/,
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/pegasus/src/pegasus.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { makeCourierMaker, getCourierPK } from './courier.js';
const DEFAULT_DENOM_TRANSFORMER = IBCSourceTraceDenomTransformer;
const DEFAULT_TRANSFER_PROTOCOL = ICS20TransferProtocol;

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

Expand Down Expand Up @@ -486,7 +486,7 @@ const makePegasus = (zcf, board, namesByAddress) => {
offerHandler,
`pegasus ${sendDenom} transfer`,
undefined,
TRANSFER_PROPOSAL_SHAPE,
TransferProposalShape,
);
},
});
Expand Down
5 changes: 3 additions & 2 deletions packages/zoe/src/contractSupport/zoeHelpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mustMatch, keyEQ, M } from '@agoric/store';
import { mustMatch, keyEQ } from '@agoric/store';
import { E } from '@endo/eventual-send';
import { makePromiseKit } from '@endo/promise-kit';
import { AssetKind } from '@agoric/ertp';
Expand All @@ -10,6 +10,7 @@ import {
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 @@ -207,7 +208,7 @@ export const depositToSeat = async (zcf, recipientSeat, amounts, payments) => {
'temporary seat for deposit',
undefined,
harden({
give: M.any(),
give: AmountKeywordRecordShape,
want: {},
exit: { onDemand: null },
}),
Expand Down
8 changes: 4 additions & 4 deletions packages/zoe/src/contracts/auction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ const start = zcf => {

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

const SellProposalShape = M.splitRecord({
give: {
Asset: AmountShape, // TODO brand specific AmountShape
Asset: AmountShape, // TODO get amount shape from brand
},
want: {
Ask: AmountShape, // TODO brand specific AmountShape
Ask: AmountShape, // TODO get amount shape from brand
},
exit: {
// The auction is not over until the deadline according to the
Expand Down

0 comments on commit 2b38651

Please sign in to comment.