Skip to content

Commit

Permalink
fix: more invitations use proposal patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Feb 28, 2023
1 parent 0e039d9 commit ef35a91
Show file tree
Hide file tree
Showing 16 changed files with 305 additions and 117 deletions.
15 changes: 13 additions & 2 deletions packages/governance/src/committee.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { makeScalarMapStore, makeExo, M } from '@agoric/store';
import { natSafeMath } from '@agoric/zoe/src/contractSupport/index.js';
import { E } from '@endo/eventual-send';

import { EmptyProposalShape } from '@agoric/zoe/src/typeGuards.js';
import { makeHandle } from '@agoric/zoe/src/makeHandle.js';
import {
getOpenQuestions,
Expand Down Expand Up @@ -93,7 +94,12 @@ const start = (zcf, privateArgs) => {
return E(voteCap).submitVote(voterHandle, positions, 1n);
};

return zcf.makeInvitation(continuingVoteHandler, 'vote');
return zcf.makeInvitation(
continuingVoteHandler,
'vote',
undefined,
EmptyProposalShape,
);
},
}),
});
Expand All @@ -103,7 +109,12 @@ const start = (zcf, privateArgs) => {
// This will produce unique descriptions because
// makeCommitteeVoterInvitation() is only called within the following loop,
// which is only called once per Electorate.
return zcf.makeInvitation(offerHandler, `Voter${index}`);
return zcf.makeInvitation(
offerHandler,
`Voter${index}`,
undefined,
EmptyProposalShape,
);
};

const { committeeName, committeeSize } = zcf.getTerms();
Expand Down
8 changes: 7 additions & 1 deletion packages/governance/src/electorateTools.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EmptyProposalShape } from '@agoric/zoe/src/typeGuards.js';
import { E } from '@endo/eventual-send';
import { deeplyFulfilled, Far } from '@endo/marshal';

Expand Down Expand Up @@ -86,7 +87,12 @@ const getQuestion = (questionHandleP, questionStore) =>
*/
const getPoserInvitation = (zcf, addQuestion) => {
const questionPoserHandler = () => Far(`questionPoser`, { addQuestion });
return zcf.makeInvitation(questionPoserHandler, `questionPoser`);
return zcf.makeInvitation(
questionPoserHandler,
`questionPoser`,
undefined,
EmptyProposalShape,
);
};

harden(startCounter);
Expand Down
9 changes: 7 additions & 2 deletions packages/governance/src/noActionElectorate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { makePublishKit } from '@agoric/notifier';
import { makePromiseKit } from '@endo/promise-kit';
import { makeExo } from '@agoric/store';
import { EmptyProposalShape } from '@agoric/zoe/src/typeGuards.js';

import { ElectoratePublicI, ElectorateCreatorI } from './typeGuards.js';

Expand Down Expand Up @@ -37,8 +38,12 @@ const start = zcf => {

const creatorFacet = makeExo('creatorFacet', ElectorateCreatorI, {
getPoserInvitation() {
return zcf.makeInvitation(() => {},
`noActionElectorate doesn't allow posing questions`);
return zcf.makeInvitation(
() => {},
`noActionElectorate doesn't allow posing questions`,
undefined,
EmptyProposalShape,
);
},
addQuestion(_instance, _question) {
throw Error(`noActionElectorate doesn't add questions.`);
Expand Down
20 changes: 13 additions & 7 deletions packages/inter-protocol/src/stakeFactory/attestation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
makeScalarMapStore,
provideLazy,
} from '@agoric/store';
import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';
import { AttKW as KW } from './constants.js';
import { makeAttestationTool } from './attestationTool.js';

Expand Down Expand Up @@ -167,11 +166,6 @@ const makeAttestationIssuerKit = async (zcf, stakeBrand, lienBridge) => {

/** @param {ZCFSeat} seat */
const returnAttestation = async seat => {
assertProposalShape(seat, {
give: { [KW.Attestation]: null },
want: {},
});

const {
give: { [KW.Attestation]: attestationAmount },
} = seat.getProposal();
Expand Down Expand Up @@ -241,12 +235,24 @@ export const makeAttestationFacets = async (zcf, stakeBrand, lienBridge) => {
lienBridge,
);

const ReturnAttProposalShape = M.splitRecord({
give: {
[KW.Attestation]: brand.getAmountShape(),
},
want: {},
});

return harden({
publicFacet: Far('attestation publicFacet', {
getIssuer: () => issuer,
getBrand: () => brand,
makeReturnAttInvitation: () =>
zcf.makeInvitation(lienMint.returnAttestation, 'returnAttestation'),
zcf.makeInvitation(
lienMint.returnAttestation,
'returnAttestation',
undefined,
ReturnAttProposalShape,
),
}),
creatorFacet: Far('creator', {
/**
Expand Down
52 changes: 44 additions & 8 deletions packages/inter-protocol/src/stakeFactory/stakeFactoryKit.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @jessie-check
import { AmountMath, AssetKind } from '@agoric/ertp';
import { AmountMath, AmountShape, AssetKind } from '@agoric/ertp';
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 } from '@agoric/zoe/src/contractSupport/index.js';
import { ceilMultiplyBy } from '@agoric/zoe/src/contractSupport/ratio.js';
import { addSubtract, assertOnlyKeys } from '../contractSupport.js';
import { addSubtract } from '../contractSupport.js';
import { calculateCurrentDebt, reverseInterest } from '../interest-math.js';
import { ManagerKW as KW } from './constants.js';

Expand Down Expand Up @@ -71,6 +71,8 @@ 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 },
Expand Down Expand Up @@ -247,7 +249,6 @@ const helperBehavior = {
assert(state.open);

const proposal = clientSeat.getProposal();
assertOnlyKeys(proposal, [KW.Attestation, KW.Debt]);

const debt = pot.getCurrentDebt();
const collateral = helper.getCollateralAllocated(vaultSeat);
Expand Down Expand Up @@ -331,10 +332,6 @@ const helperBehavior = {
const { debtBrand, manager, vaultSeat, zcf } = state;
const { helper, pot } = facets;
assert(state.open);
assertProposalShape(seat, {
give: { [KW.Debt]: null },
want: { [KW.Attestation]: null },
});

const currentDebt = pot.getCurrentDebt();
const {
Expand Down Expand Up @@ -370,17 +367,56 @@ const potBehavior = {
const { zcf } = state;
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
},
want: {
Attestation: AmountShape, // TODO brand specific AmountShape
},
}),
);

return zcf.makeInvitation(
seat => helper.adjustBalancesHook(seat),
'AdjustBalances',
undefined,
AdjustBalancesProposalShape,
);
},
/** @param {MethodContext} context */
makeCloseInvitation: ({ state, facets }) => {
const { zcf } = state;
const { helper } = facets;
assert(state.open);
return zcf.makeInvitation(seat => helper.closeHook(seat), 'CloseVault');

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

return zcf.makeInvitation(
seat => helper.closeHook(seat),
'CloseVault',
undefined,
CloseProposalShape,
);
},
/**
* The actual current debt, including accrued interest.
Expand Down
23 changes: 17 additions & 6 deletions packages/inter-protocol/src/vaultFactory/liquidateIncrementally.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import { E } from '@endo/eventual-send';
import {
getAmountOut,
assertProposalShape,
offerTo,
natSafeMath as NatMath,
ceilMultiplyBy,
oneMinus,
atomicTransfer,
} from '@agoric/zoe/src/contractSupport/index.js';
import { AmountMath } from '@agoric/ertp';
import { AmountMath, AmountShape } from '@agoric/ertp';
import { Far } from '@endo/marshal';
import { forever, makeTracer } from '@agoric/internal';
import { M } from '@agoric/store';

const { Fail } = assert;
const trace = makeTracer('LiqI', false);
Expand Down Expand Up @@ -285,9 +285,6 @@ const start = async zcf => {
debtorSeat,
{ debt: originalDebt, penaltyRate },
) => {
assertProposalShape(debtorSeat, {
give: { In: null },
});
originalDebt.brand === debtBrand ||
Fail`Cannot liquidate to ${originalDebt.brand}`;
const penalty = ceilMultiplyBy(originalDebt, penaltyRate);
Expand Down Expand Up @@ -336,12 +333,26 @@ const start = async zcf => {
);
};

const LiquidateProposalShape = M.splitRecord({
give: {
In: AmountShape, // TODO brand-specific AmountShape
},
want: {
Out: AmountShape, // TODO brand-specific AmountShape
},
});

/**
* @type {ERef<Liquidator>}
*/
const creatorFacet = Far('debtorInvitationCreator (incrementally)', {
makeLiquidateInvitation: () =>
zcf.makeInvitation(handleLiquidateOffer, 'Liquidate'),
zcf.makeInvitation(
handleLiquidateOffer,
'Liquidate',
undefined,
LiquidateProposalShape,
),
});

return harden({ creatorFacet });
Expand Down
48 changes: 41 additions & 7 deletions packages/inter-protocol/src/vaultFactory/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { makeTracer } from '@agoric/internal';
import { StorageNodeShape } from '@agoric/notifier/src/typeGuards.js';
import { M, prepareExoClassKit } from '@agoric/vat-data';
import {
assertProposalShape,
atomicTransfer,
floorMultiplyBy,
makeRatioFromAmounts,
} from '@agoric/zoe/src/contractSupport/index.js';
import { SeatShape } from '@agoric/zoe/src/typeGuards.js';
import { addSubtract, allEmpty, assertOnlyKeys } from '../contractSupport.js';
import { addSubtract, allEmpty } from '../contractSupport.js';
import { calculateCurrentDebt, reverseInterest } from '../interest-math.js';
import { UnguardedHelperI } from '../typeGuards.js';
import { prepareVaultKit } from './vaultKit.js';
Expand Down Expand Up @@ -179,6 +178,42 @@ 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 Expand Up @@ -237,7 +272,6 @@ export const prepareVault = (baggage, marshaller, zcf) => {
* @returns {FullProposal}
*/
fullProposal(partial) {
assertOnlyKeys(partial, ['Collateral', 'Minted']);
return {
give: {
Collateral:
Expand Down Expand Up @@ -418,10 +452,6 @@ export const prepareVault = (baggage, marshaller, zcf) => {
const oldCollateral = self.getCollateralAmount();

if (phase === Phase.ACTIVE) {
assertProposalShape(seat, {
give: { Minted: null },
});

// you're paying off the debt, you get everything back.
const debt = self.getCurrentDebt();
const {
Expand Down Expand Up @@ -780,6 +810,8 @@ export const prepareVault = (baggage, marshaller, zcf) => {
return zcf.makeInvitation(
seat => helper.adjustBalancesHook(seat),
state.manager.scopeDescription('AdjustBalances'),
undefined,
AdjustBalancesProposalShape,
);
},

Expand All @@ -790,6 +822,8 @@ export const prepareVault = (baggage, marshaller, zcf) => {
return zcf.makeInvitation(
seat => helper.closeHook(seat),
state.manager.scopeDescription('CloseVault'),
undefined,
CloseProposalShape,
);
},

Expand Down
Loading

0 comments on commit ef35a91

Please sign in to comment.