Skip to content

Commit

Permalink
chore: fix errors in treasury, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
katelynsills committed Nov 15, 2021
1 parent e8aed1a commit 5857bef
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 63 deletions.
32 changes: 18 additions & 14 deletions packages/governance/test/unitTests/test-shareHolders.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ test('shareHolders attestation returned on simpleInvite', async t => {

const { publicFacet: electoratePub } = await E(zoe).startInstance(
electorateInstall,
{
harden({
Attestation: issuer,
},
}),
);

const attest1 = AmountMath.make(brand, attest('a', 37n, 5n));
Expand All @@ -159,9 +159,10 @@ test('shareHolders attestation returned on simpleInvite', async t => {
test('shareHolders attestation to vote', async t => {
const { issuer, brand, mint } = makeIssuerKit('attestations', AssetKind.SET);
const timer = buildManualTimer(console.log);
const { publicFacet, creatorFacet } = await E(
zoe,
).startInstance(electorateInstall, { Attestation: issuer });
const { publicFacet, creatorFacet } = await E(zoe).startInstance(
electorateInstall,
harden({ Attestation: issuer }),
);

const attest1 = AmountMath.make(brand, attest('a', 37n, 5n));
const voteSeat = voterFacet(mint, publicFacet, attest1);
Expand All @@ -185,9 +186,10 @@ test('shareHolders attestation to vote', async t => {
test('shareHolders reuse across questions', async t => {
const { issuer, brand, mint } = makeIssuerKit('attestations', AssetKind.SET);
const timer = buildManualTimer(console.log);
const { publicFacet, creatorFacet } = await E(
zoe,
).startInstance(electorateInstall, { Attestation: issuer });
const { publicFacet, creatorFacet } = await E(zoe).startInstance(
electorateInstall,
harden({ Attestation: issuer }),
);

const attest1 = AmountMath.make(brand, attest('a', 37n, 5n));
const voteFacet1 = voterFacet(mint, publicFacet, attest1);
Expand Down Expand Up @@ -247,9 +249,10 @@ test('shareHolders reuse across questions', async t => {
test('shareHolders expiring attestations', async t => {
const { issuer, brand, mint } = makeIssuerKit('attestations', AssetKind.SET);
const timer = buildManualTimer(console.log);
const { publicFacet, creatorFacet } = await E(
zoe,
).startInstance(electorateInstall, { Attestation: issuer });
const { publicFacet, creatorFacet } = await E(zoe).startInstance(
electorateInstall,
harden({ Attestation: issuer }),
);

// deadlines: depose: 2, dividends: 4
// voter 1 votes won't count; voter 2 can't vote on dividends.
Expand Down Expand Up @@ -335,9 +338,10 @@ test('shareHolders expiring attestations', async t => {
test('shareHolders bundle/split attestations', async t => {
const { issuer, brand, mint } = makeIssuerKit('attestations', AssetKind.SET);
const timer = buildManualTimer(console.log);
const { publicFacet, creatorFacet } = await E(
zoe,
).startInstance(electorateInstall, { Attestation: issuer });
const { publicFacet, creatorFacet } = await E(zoe).startInstance(
electorateInstall,
harden({ Attestation: issuer }),
);

// deadline: depose: 2
const handleShared = makeHandle('Attestation');
Expand Down
3 changes: 2 additions & 1 deletion packages/treasury/src/collectRewardFees.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const makeMakeCollectFeesInvitation = (
autoswapCreatorFacet,
).makeCollectFeesInvitation();
const { zcfSeat: transferSeat } = zcf.makeEmptySeatKit();
await E.get(offerTo(zcf, invitation, {}, {}, transferSeat)).deposited;
await E.get(offerTo(zcf, invitation, harden({}), harden({}), transferSeat))
.deposited;

seat.incrementBy(
feeSeat.decrementBy(
Expand Down
4 changes: 2 additions & 2 deletions packages/treasury/src/stablecoinMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ export async function start(zcf, privateArgs) {

const { creatorFacet: liquidationFacet } = await E(zoe).startInstance(
liquidationInstall,
{ RUN: runIssuer },
{ autoswap: autoswapAPI },
harden({ RUN: runIssuer, [collateralKeyword]: collateralIssuer }),
harden({ autoswap: autoswapAPI }),
);

async function addTypeHook(seat) {
Expand Down
10 changes: 7 additions & 3 deletions packages/treasury/test/swingsetTests/governance/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ const installContracts = async (zoe, cb) => {
};

const startElectorate = async (zoe, installations) => {
const electorateTerms = {
const electorateTerms = harden({
committeeName: 'TwentyCommittee',
committeeSize: 5,
};
});
const {
creatorFacet: electorateCreatorFacet,
instance: electorateInstance,
} = await E(zoe).startInstance(installations.electorate, {}, electorateTerms);
} = await E(zoe).startInstance(
installations.electorate,
harden({}),
electorateTerms,
);
return { electorateCreatorFacet, electorateInstance };
};

Expand Down
6 changes: 3 additions & 3 deletions packages/treasury/test/swingsetTests/governance/vat-owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const build = async (

const governorFacets = await E(zoe).startInstance(
installations.governor,
{},
{
harden({}),
harden({
timer,
electorateInstance,
governedContractInstallation: installations.treasury,
Expand All @@ -60,7 +60,7 @@ const build = async (
issuerKeywordRecord: {},
privateArgs: privateTreasuryArgs,
},
},
}),
privateArgs,
);

Expand Down
10 changes: 7 additions & 3 deletions packages/treasury/test/swingsetTests/treasury/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ const setupBasicMints = () => {
};

const startElectorate = async (zoe, installations) => {
const electorateTerms = {
const electorateTerms = harden({
committeeName: 'TwentyCommittee',
committeeSize: 5,
};
});
const {
creatorFacet: committeeCreator,
instance: electorateInstance,
} = await E(zoe).startInstance(installations.electorate, {}, electorateTerms);
} = await E(zoe).startInstance(
installations.electorate,
harden({}),
electorateTerms,
);
return { committeeCreator, electorateInstance };
};

Expand Down
4 changes: 2 additions & 2 deletions packages/treasury/test/swingsetTests/treasury/vat-owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const build = async (

const { creatorFacet: governor } = await E(zoe).startInstance(
installations.governor,
{},
harden({}),
{
timer,
electorateInstance,
Expand All @@ -60,7 +60,7 @@ const build = async (
privateArgs: privateTreasuryArgs,
},
},
{ electorateCreatorFacet: committeeCreator },
harden({ electorateCreatorFacet: committeeCreator }),
);

const governedInstance = await E(governor).getInstance();
Expand Down
8 changes: 6 additions & 2 deletions packages/treasury/test/test-bootstrapPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ const setupGovernor = async (
const {
instance: electorateInstance,
creatorFacet: electorateCreatorFacet,
} = await E(zoe).startInstance(electorateInstall, {}, electorateTerms);
} = await E(zoe).startInstance(
electorateInstall,
harden({}),
electorateTerms,
);

const governorTerms = {
electorateInstance,
Expand All @@ -74,7 +78,7 @@ const setupGovernor = async (
};
return E(zoe).startInstance(
governanceInstall,
{},
harden({}),
governorTerms,
harden({ electorateCreatorFacet }),
);
Expand Down
31 changes: 20 additions & 11 deletions packages/treasury/test/test-stablecoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ async function setupServices(
const {
creatorFacet: committeeCreator,
instance: electorateInstance,
} = await E(zoe).startInstance(installs.electorate, {}, electorateTerms);
} = await E(zoe).startInstance(
installs.electorate,
harden({}),
electorateTerms,
);

const priceAuthorityPromiseKit = makePromiseKit();
const priceAuthorityPromise = priceAuthorityPromiseKit.promise;
Expand All @@ -234,9 +238,14 @@ async function setupServices(
instance: governorInstance,
publicFacet: governorPublicFacet,
creatorFacet: governorCreatorFacet,
} = await E(zoe).startInstance(installs.governor, {}, governorTerms, {
electorateCreatorFacet: committeeCreator,
});
} = await E(zoe).startInstance(
installs.governor,
harden({}),
governorTerms,
harden({
electorateCreatorFacet: committeeCreator,
}),
);

const stablecoinMachineP = E(governorCreatorFacet).getCreatorFacet();
const lenderP = E(governorCreatorFacet).getPublicFacet();
Expand Down Expand Up @@ -617,10 +626,10 @@ test('price falls precipitously', async t => {

// Sell some Eth to drive the value down
const swapInvitation = E(services.autoswapAPI).makeSwapInvitation();
const proposal = {
const proposal = harden({
give: { In: AmountMath.make(aethBrand, 200n) },
want: { Out: AmountMath.makeEmpty(runBrand) },
};
});
await E(zoe).offer(
swapInvitation,
proposal,
Expand Down Expand Up @@ -1265,7 +1274,7 @@ test('overdeposit', async t => {

// overpay debt ///////////////////////////////////// (give RUN)

const combinedRun = await E(runIssuer).combine([borrowedRun, bobRun]);
const combinedRun = await E(runIssuer).combine(harden([borrowedRun, bobRun]));
const depositRun2 = AmountMath.make(runBrand, 6000n);

const aliceOverpaySeat = await E(zoe).offer(
Expand Down Expand Up @@ -1545,15 +1554,15 @@ test('bad chargingPeriod', async t => {
() =>
E(zoe).startInstance(
stablecoinInstall,
{},
{
harden({}),
harden({
autoswapInstall,
priceAuthority: priceAuthorityPromise,
loanParams,
timerService: manualTimer,
liquidationInstall,
governedParams: governedParameterTerms,
},
}),
harden({ feeMintAccess }),
),
{ message: 'chargingPeriod (2) must be a BigInt' },
Expand Down Expand Up @@ -1774,7 +1783,7 @@ test('close loan', async t => {

// close loan, using Bob's RUN /////////////////////////////////////

const runRepayment = await E(runIssuer).combine([bobRun, runLent]);
const runRepayment = await E(runIssuer).combine(harden([bobRun, runLent]));

const aliceCloseSeat = await E(zoe).offer(
E(aliceVault).makeCloseInvitation(),
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/src/contractSupport/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
* contractB. Note that the pathway to deposit the payout back to
* contractA reverses this mapping.
*
* @param {Proposal} proposal
* @param {Proposal | undefined} proposal
* The proposal for the offer to be made to contractB
*
* @param {ZCFSeat} fromSeat
Expand Down
34 changes: 19 additions & 15 deletions packages/zoe/src/contractSupport/zoeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,23 @@ export async function saveAllIssuers(zcf, issuerKeywordRecord = harden({})) {

/** @type {MapKeywords} */
export const mapKeywords = (keywordRecord = {}, keywordMapping) => {
return Object.fromEntries(
Object.entries(keywordRecord).map(([keyword, value]) => {
if (keywordMapping[keyword] === undefined) {
return [keyword, value];
}
return [keywordMapping[keyword], value];
}),
return harden(
Object.fromEntries(
Object.entries(keywordRecord).map(([keyword, value]) => {
if (keywordMapping[keyword] === undefined) {
return [keyword, value];
}
return [keywordMapping[keyword], value];
}),
),
);
};
/** @type {Reverse} */
const reverse = (keywordRecord = {}) => {
return Object.fromEntries(
Object.entries(keywordRecord).map(([key, value]) => [value, key]),
return harden(
Object.fromEntries(
Object.entries(keywordRecord).map(([key, value]) => [value, key]),
),
);
};

Expand All @@ -276,14 +280,14 @@ export const offerTo = async (
const zoe = zcf.getZoeService();
const mappingReversed = reverse(keywordMapping);

const newKeywords =
proposal !== undefined
? mapKeywords(proposal.give, mappingReversed)
: harden({});

// the proposal is in the other contract's keywords, but we want to
// use `proposal.give` to withdraw
const payments = await withdrawFromSeat(
zcf,
fromSeat,
// `proposal.give` may be undefined
mapKeywords(proposal.give, mappingReversed),
);
const payments = await withdrawFromSeat(zcf, fromSeat, newKeywords);

// Map to the other contract's keywords
const paymentsForOtherContract = mapKeywords(payments, keywordMapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,14 @@ const setupServices = async (
instance: governorInstance,
publicFacet: governorPublicFacet,
creatorFacet: governorCreatorFacet,
} = await E(zoe).startInstance(installs.governor, {}, governorTerms, {
electorateCreatorFacet: committeeCreator,
});
} = await E(zoe).startInstance(
installs.governor,
{},
governorTerms,
harden({
electorateCreatorFacet: committeeCreator,
}),
);

const ammCreatorFacetP = E(governorCreatorFacet).getInternalCreatorFacet();
const ammPublicP = E(governorCreatorFacet).getPublicFacet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,14 @@ const setupServices = async (
instance: governorInstance,
publicFacet: governorPublicFacet,
creatorFacet: governorCreatorFacet,
} = await E(zoe).startInstance(installs.governor, {}, governorTerms, {
electorateCreatorFacet: committeeCreator,
});
} = await E(zoe).startInstance(
installs.governor,
{},
governorTerms,
harden({
electorateCreatorFacet: committeeCreator,
}),
);

const ammCreatorFacetP = E(governorCreatorFacet).getInternalCreatorFacet();
const ammPublicP = E(governorCreatorFacet).getPublicFacet();
Expand Down

0 comments on commit 5857bef

Please sign in to comment.