Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(run-protocol): @jessie-check for runStake #5148

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/run-protocol/src/runStake/attestation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
// @jessie-check

import { AmountMath, AssetKind } from '@agoric/ertp';
import { E, Far } from '@endo/far';
Expand Down
1 change: 1 addition & 0 deletions packages/run-protocol/src/runStake/params.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
// @jessie-check

import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';

Expand Down
1 change: 1 addition & 0 deletions packages/run-protocol/src/runStake/runStake.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
// @jessie-check
import { AmountMath } from '@agoric/ertp';
import { handleParamGovernance, ParamTypes } from '@agoric/governance';
import { E, Far } from '@endo/far';
Expand Down
9 changes: 5 additions & 4 deletions packages/run-protocol/src/runStake/runStakeKit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
// @jessie-check
import { Far } from '@endo/far';
import { AmountMath, AssetKind } from '@agoric/ertp';
import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';
Expand Down Expand Up @@ -212,17 +213,17 @@ export const makeRunStakeKit = (zcf, startSeat, manager) => {
const debt = getCurrentDebt();
const collateral = getCollateralAllocated(vaultSeat);

const giveColl = proposal.give[KW.Attestation] || emptyCollateral;
const wantColl = proposal.want[KW.Attestation] || emptyCollateral;
const giveColl = proposal.give.Attestation || emptyCollateral;
const wantColl = proposal.want.Attestation || emptyCollateral;

// new = after the transaction gets applied
const newCollateral = addSubtract(collateral, giveColl, wantColl);
// max debt supported by current Collateral as modified by proposal
const { amountLiened, maxDebt: newMaxDebt } =
manager.maxDebtForLien(newCollateral);

const giveRUN = AmountMath.min(proposal.give[KW.Debt] || emptyDebt, debt);
const wantRUN = proposal.want[KW.Debt] || emptyDebt;
const giveRUN = AmountMath.min(proposal.give.Debt || emptyDebt, debt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

proposal.give.Attestation looks nicer, but it's a use that is not checked against any defining occurrence.

So now someone could type proposal.give.Debt and get no error, whereas proposal.give[KW.Debte] would have said KW doesn't have that key. But in both cases give doesn't constrain the keys.

I think where we want to get to is that you can validate the proposal with pattern matching so that the type system has a guarantee from some runtime validation as to what's in give. So imo let's work towards that and not invest in the stop-gap.

const wantRUN = proposal.want.Debt || emptyDebt;
const giveRUNonly = matches(
proposal,
harden({ give: { [KW.Debt]: M.record() }, want: {}, exit: M.any() }),
Expand Down
1 change: 1 addition & 0 deletions packages/run-protocol/src/runStake/runStakeManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
// @jessie-check
import { AmountMath } from '@agoric/ertp';
import { floorMultiplyBy } from '@agoric/zoe/src/contractSupport/index.js';
import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
Expand Down