Skip to content

Commit

Permalink
fix! vault factory takes auctioneerPublicFacet from private args inst…
Browse files Browse the repository at this point in the history
…ead of terms
  • Loading branch information
iomekam authored and Chris-Hibbert committed Jan 16, 2024
1 parent df3d0a7 commit a289edc
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

. ./upgrade-test-scripts/env_setup.sh

set -euo pipefail
# set -x

here='upgrade-test-scripts/agoric-upgrade-11'

bundle_auctioneer_filepath='/tmp/bundle-auctioneer.json'
bundle_vault_filepath='/tmp/bundle-vaultFactory.json'

alias bundle-source="yarn run --silent bundle-source"
# TODO: for now, we're bundling vaultFactory outside the container. but before we finish:
# bundle-source --cache-json /tmp packages/inter-protocol/src/vaultFactory/vaultFactory.js vaultFactory
VAULT_HASH=`jq -r .endoZipBase64Sha512 ${bundle_vault_filepath}`

echo checking that hashes match ${here}/gov-switch-auctioneer.js
echo ${VAULT_HASH}
grep ${VAULT_HASH} ${here}/gov-switch-auctioneer.js || exit 1

bundle-source --cache-json /tmp packages/inter-protocol/src/auction/auctioneer.js auctioneer
AUCTIONEER_HASH=`jq -r .endoZipBase64Sha512 ${bundle_auctioneer_filepath}`
grep ${AUCTIONEER_HASH} ${here}/gov-switch-auctioneer.js || exit 1

# TODO: make sure this consistently works
agd tx swingset install-bundle @${bundle_vault_filepath} \
--from gov1 --keyring-backend=test --gas=auto \
--chain-id=agoriclocal -b block --yes
agoric follow -lF :bundles

agd tx swingset install-bundle @${bundle_auctioneer_filepath} \
--from gov1 --keyring-backend=test --gas=auto \
--chain-id=agoriclocal -b block --yes
agoric follow -lF :bundles

agd --chain-id=agoriclocal \
tx gov submit-proposal swingset-core-eval \
${here}/gov-switch-auctioneer-permit.json ${here}/gov-switch-auctioneer.js \
--title="Auctioneer Upgrade" --description="auctioneer upgrade test" \
--deposit=10000000ubld \
--gas=auto --gas-adjustment=1.2 \
--yes -o json --from=validator --keyring-backend=test -b block

agd --chain-id=agoriclocal query gov proposals --output json | \
jq -c '.proposals[] | [.proposal_id,.voting_end_time,.status]';

voteLatestProposalAndWait

# then tes some stuff???
# 3129800000uist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"consume": {
"auctioneerKit": true,
"chainTimerService": true,
"priceAuthority": true,
"startGovernedUpgradable": true,
"vaultFactoryKit": true,
"zoe": true,
"chainStorage": true,
"board": true,
"reserveKit": true
},
"produce": {
"auctioneerKit": true
},
"instance": {
"produce": {
"auctioneer": true
},
"consume": {
"reserve": true
}
},
"issuer": {
"consume": {
"IST": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// @ts-nocheck
// xxport { E } from '@endo/far';
/* global E */

console.log('started switch-auctioneer script');

// TODO: set these bundle-ids to the revised code
const bundleIDs = {
vaultFactory:
'b1-4755fb5c079fc2a17e6ea5a887d27787cd6d48df179e046466c4dbf4b9e78ac7dceee183a395de3d6a09c5f162415e12f42685269b84c64b58c5f65eab6b0de1',
auctioneer:
'b1-e85289898e66e0423d7ec1c402ac2ced21573f93cf599d593a0533a1e2355ace624cc95c8c8c18c66d44a921511642e87837accd0e728427c269936b040bb886',
};

const STORAGE_PATH = 'auction';

const { fromEntries, keys, values } = Object;

/** @type {<X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
const zip = (xs, ys) => harden(xs.map((x, i) => [x, ys[+i]]));

/**
* @type {<T extends Record<string, ERef<any>>>(
* obj: T,
* ) => Promise<{ [K in keyof T]: Awaited<T[K]> }>}
*/
const allValues = async obj => {
const resolved = await Promise.all(values(obj));
// @ts-expect-error cast
return harden(fromEntries(zip(keys(obj), resolved)));
};

// /** @param {xxport('../../src/proposals/econ-behaviors').EconomyBootstrapPowers} permittedPowers */
const switchAuctioneer = async permittedPowers => {
console.log('switchAuctioneer: extracting permitted powers...');
// see gov-switch-auctioneer-permit.json
const {
consume: {
auctioneerKit: auctioneerKitP,
chainTimerService: timerService,
priceAuthority,
startGovernedUpgradable,
vaultFactoryKit,
zoe,
chainStorage,
board,
reserveKit,
},
produce: { auctioneerKit },
instance: {
produce: { auctioneer: auctionInstance },
consume: { reserve: reserveInstance },
},
issuer: {
consume: { IST: stableIssuerP },
},
} = permittedPowers;

/** install, start governed instance, publish results */
const startNewAuctioneer = async () => {
console.log('startNewAuctioneer: installBundleID etc.');
const {
// @ts-expect-error cast XXX missing from type
// auctioneerKit: { privateArgs }, // TODO, this doesn't work. Find a way to pass in valid private args
governedParamsOrig,
installation,
reservePublicFacet,
stableIssuer,
storageNode,
marshaller,
} = await allValues({
auctioneerKit: auctioneerKitP,
installation: E(zoe).installBundleID(bundleIDs.auctioneer, 'auctioneer'),
reservePublicFacet: E(zoe).getPublicFacet(reserveInstance),
stableIssuer: stableIssuerP,
governedParamsOrig: E(
E.get(auctioneerKitP).publicFacet,
).getGovernedParams(),
storageNode: E(chainStorage).makeChildNode(STORAGE_PATH),
marshaller: E(board).getReadonlyMarshaller(),
});

const privateArgs = {
storageNode,
marshaller,
};

const { Electorate: _, ...governedParams } = governedParamsOrig;

const terms = {
priceAuthority,
reservePublicFacet,
timerService,
governedParams: governedParamsOrig,
};

console.log('startNewAuctioneer: startGovernedUpgradable');
const kit = await E(startGovernedUpgradable)({
label: 'auctioneer',
installation,
issuerKeywordRecord: { Bid: stableIssuer },
terms,
governedParams,
privateArgs,
});

auctioneerKit.reset();
auctioneerKit.resolve(kit);
// TODO: test that auctioneer in agoricNames.instance gets updated
auctionInstance.reset();
auctionInstance.resolve(kit.instance);

return kit;
};

const newAuctionKit = await startNewAuctioneer();

// TODO: shut down old auctioneer?

// upgrade the vaultFactory
const upgradeVaultFactory = async () => {
console.log('upgradeVaultFactory...');
const kit = await vaultFactoryKit;
// @ts-expect-error cast XXX privateArgs missing from type
const { privateArgs } = kit;

/** @type {xxport('../../src/vaultFactory/vaultFactory').VaultFactoryContract['privateArgs']} */
const newPrivateArgs = harden({
...privateArgs,
auctioneerPublicFacet: newAuctionKit.publicFacet,
});
const upgradeResult = await E(kit.adminFacet).upgradeContract(
bundleIDs.vaultFactory,
newPrivateArgs,
);

const shortfallInvitation = await E(
E.get(reserveKit).creatorFacet,
).makeShortfallReportingInvitation();

await E(kit.creatorFacet).updateShortfallReporter(shortfallInvitation);

console.log('upgraded vaultVactory.', upgradeResult);
};
await upgradeVaultFactory();
};

switchAuctioneer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
agd tx bank send validator $GOV1ADDR 20123000000ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA --keyring-backend=test --chain-id=agoriclocal --yes -bblock
agops vaults open --giveCollateral 5000 --wantMinted 20000 > /tmp/offer.json
agops perf satisfaction --executeOffer /tmp/offer.json --from gov1 --keyring-backend=test


# ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/proposals/econ-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ export const setupVaultFactoryArguments = async (

const vaultFactoryTerms = makeGovernedVFTerms({
priceAuthority,
auctioneerPublicFacet,
reservePublicFacet,
interestTiming,
timer: chainTimerService,
Expand All @@ -264,6 +263,7 @@ export const setupVaultFactoryArguments = async (
});

const vaultFactoryPrivateArgs = {
auctioneerPublicFacet,
feeMintAccess,
initialPoserInvitation,
initialShortfallInvitation,
Expand Down
8 changes: 4 additions & 4 deletions packages/inter-protocol/src/vaultFactory/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export const vaultParamPattern = M.splitRecord(

/**
* @param {{
* auctioneerPublicFacet: ERef<AuctioneerPublicFacet>;
* electorateInvitationAmount: Amount<'set'>;
* minInitialDebt: Amount<'nat'>;
* bootstrapPaymentValue: bigint;
Expand All @@ -139,7 +138,6 @@ export const vaultParamPattern = M.splitRecord(
* }} opts
*/
export const makeGovernedTerms = ({
auctioneerPublicFacet,
bootstrapPaymentValue,
electorateInvitationAmount,
interestTiming,
Expand All @@ -151,7 +149,6 @@ export const makeGovernedTerms = ({
referencedUi = 'NO REFERENCE',
}) => {
return harden({
auctioneerPublicFacet,
priceAuthority,
reservePublicFacet,
timerService: timer,
Expand Down Expand Up @@ -201,7 +198,10 @@ export const provideVaultParamManagers = (baggage, marshaller) => {
};

// restore from baggage
[...managerArgs.entries()].map(([brand, args]) => makeManager(brand, args));
// [...managerArgs.entries()].map(([brand, args]) => makeManager(brand, args));
for (const [brand, args] of managerArgs.entries()) {
makeManager(brand, args);
}

return {
/**
Expand Down
15 changes: 14 additions & 1 deletion packages/inter-protocol/src/vaultFactory/vaultDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import '@agoric/zoe/src/contracts/exported.js';
import '@agoric/governance/exported.js';

import { AmountMath, AmountShape, BrandShape, IssuerShape } from '@agoric/ertp';
import { GovernorFacetShape } from '@agoric/governance/src/typeGuards.js';
import {
GovernorFacetShape,
InvitationShape,
} from '@agoric/governance/src/typeGuards.js';
import { makeTracer } from '@agoric/internal';
import { M, mustMatch } from '@agoric/store';
import {
Expand Down Expand Up @@ -143,9 +146,12 @@ const prepareVaultDirector = (
const oldInvitation = baggage.has(shortfallInvitationKey)
? baggage.get(shortfallInvitationKey)
: undefined;
console.log('@@@@@ Old Invitation', oldInvitation);

const newInvitation = await directorParamManager.getInternalParamValue(
SHORTFALL_INVITATION_KEY,
);
console.log('@@@@@ New Invitation', newInvitation);

if (newInvitation === oldInvitation) {
shortfallReporter ||
Expand Down Expand Up @@ -294,6 +300,7 @@ const prepareVaultDirector = (
makePriceLockWaker: M.call().returns(M.remotable('TimerWaker')),
makeLiquidationWaker: M.call().returns(M.remotable('TimerWaker')),
makeReschedulerWaker: M.call().returns(M.remotable('TimerWaker')),
updateShortfallReporter: M.call(InvitationShape).returns(M.promise()),
}),
public: M.interface('public', {
getCollateralManager: M.call(BrandShape).returns(M.remotable()),
Expand Down Expand Up @@ -437,6 +444,12 @@ const prepareVaultDirector = (
allManagersDo(vm => vm.lockOraclePrices());
});
},
async updateShortfallReporter(newInvitation) {
const zoe = zcf.getZoeService();
shortfallReporter = await E(
E(zoe).offer(newInvitation),
).getOfferResult();
},
},
public: {
/** @param {Brand} brandIn */
Expand Down
7 changes: 4 additions & 3 deletions packages/inter-protocol/src/vaultFactory/vaultFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const trace = makeTracer('VF', true);

/**
* @typedef {ZCF<
* GovernanceTerms<import('./params.js').VaultDirectorParams> & {
* auctioneerPublicFacet: import('../auction/auctioneer.js').AuctioneerPublicFacet;
* GovernanceTerms<import('./params').VaultDirectorParams> & {
* priceAuthority: ERef<PriceAuthority>;
* reservePublicFacet: AssetReservePublicFacet;
* timerService: import('@agoric/time').TimerService;
Expand Down Expand Up @@ -70,6 +69,7 @@ harden(meta);
* initialShortfallInvitation: Invitation;
* storageNode: ERef<StorageNode>;
* marshaller: ERef<Marshaller>;
* auctioneerPublicFacet: import('../auction/auctioneer.js').AuctioneerPublicFacet;
* }} privateArgs
* @param {import('@agoric/ertp').Baggage} baggage
*/
Expand All @@ -80,6 +80,7 @@ export const start = async (zcf, privateArgs, baggage) => {
initialShortfallInvitation,
marshaller,
storageNode,
auctioneerPublicFacet,
} = privateArgs;

trace('awaiting debtMint');
Expand All @@ -91,7 +92,7 @@ export const start = async (zcf, privateArgs, baggage) => {
mintedIssuerRecord: debtMint.getIssuerRecord(),
}));

const { timerService, auctioneerPublicFacet } = zcf.getTerms();
const { timerService } = zcf.getTerms();

const { makeRecorderKit, makeERecorderKit } = prepareRecorderKitMakers(
baggage,
Expand Down

0 comments on commit a289edc

Please sign in to comment.