Skip to content

Commit

Permalink
feat: upgrade vaults and add a new auction
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Apr 24, 2024
1 parent 3f2b479 commit eae60be
Show file tree
Hide file tree
Showing 6 changed files with 416 additions and 1 deletion.
3 changes: 2 additions & 1 deletion a3p-integration/scripts/generate-a3p-submissions.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
set -ueo pipefail

SCRIPT_DIR=$( cd ${0%/*} && pwd -P )
# cd prints its target on some platforms. Without the redirect, we get 2 copies
SCRIPT_DIR=$( cd ${0%/*} > /dev/null && pwd -P )

IFS=$'\n'

Expand Down
4 changes: 4 additions & 0 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,10 @@ func unreleasedUpgradeHandler(app *GaiaApp, targetUpgrade string) func(sdk.Conte
"@agoric/builders/scripts/vats/updateStOsmoPriceFeed.js",
"@agoric/builders/scripts/vats/updateStTiaPriceFeed.js",
),
// Add new auction contract. The old one will be retired shortly.
vm.CoreProposalStepForModules( "@agoric/builders/scripts/vats/add-auction.js"),
// upgrade vaultFactory.
vm.CoreProposalStepForModules( "@agoric/builders/scripts/vats/upgradeVaults.js"),
}
}

Expand Down
14 changes: 14 additions & 0 deletions packages/builders/scripts/vats/add-auction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { makeHelpers } from '@agoric/deploy-script-support';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const defaultProposalBuilder = async () => {
return harden({
sourceSpec: '@agoric/inter-protocol/src/proposals/add-auction.js',
getManifestCall: ['getManifestForAddAuction'],
});
};

export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('add-auction', defaultProposalBuilder);
};
23 changes: 23 additions & 0 deletions packages/builders/scripts/vats/upgradeVaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { makeHelpers } from '@agoric/deploy-script-support';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const defaultProposalBuilder = async ({ publishRef, install }) =>
harden({
sourceSpec: '@agoric/inter-protocol/src/proposals/upgrade-vaults.js',
getManifestCall: [
'getManifestForUpgradeVaults',
{
vaultsRef: publishRef(
install(
'@agoric/inter-protocol/src/vaultFactory/vaultFactory.js',
'../bundles/bundle-vaultFactory.js',
),
),
},
],
});

export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('upgrade-vaults', defaultProposalBuilder);
};
177 changes: 177 additions & 0 deletions packages/inter-protocol/src/proposals/add-auction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import { deeplyFulfilledObject, makeTracer } from '@agoric/internal';
import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
import { E } from '@endo/far';
import { Stable } from '@agoric/internal/src/tokens.js';
import { makeGovernedTerms as makeGovernedATerms } from '../auction/params.js';

const trace = makeTracer('NewAuction', true);

/** @param {import('./econ-behaviors.js').EconomyBootstrapPowers} powers */
export const addAuction = async ({
consume: {
zoe,
board,
chainTimerService,
priceAuthority,
chainStorage,
economicCommitteeCreatorFacet: electorateCreatorFacet,
auctioneerKit: legacyKitP,
},
produce: { newAuctioneerKit },
instance: {
consume: { reserve: reserveInstance },
},
installation: {
consume: {
auctioneer: auctionInstallation,
contractGovernor: contractGovernorInstallation,
},
},
issuer: {
consume: { [Stable.symbol]: stableIssuerP },
},
}) => {
trace('addAuction start');
const STORAGE_PATH = 'auction';

const poserInvitationP = E(electorateCreatorFacet).getPoserInvitation();

const [
initialPoserInvitation,
electorateInvitationAmount,
stableIssuer,
legacyKit,
] = await Promise.all([
poserInvitationP,
E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
stableIssuerP,
legacyKitP,
]);

// Each field has an extra layer of type + value:
// AuctionStartDelay: { type: 'relativeTime', value: { relValue: 2n, timerBrand: Object [Alleged: timerBrand] {} } }
/** @type {any} */
const paramValues = await E(legacyKit.publicFacet).getGovernedParams();
const params = harden({
StartFrequency: paramValues.StartFrequency.value,
ClockStep: paramValues.ClockStep.value,
StartingRate: paramValues.StartingRate.value,
LowestRate: paramValues.LowestRate.value,
DiscountStep: paramValues.DiscountStep.value,
AuctionStartDelay: paramValues.AuctionStartDelay.value,
PriceLockPeriod: paramValues.PriceLockPeriod.value,
});
const timerBrand = await E(chainTimerService).getTimerBrand();

const storageNode = await makeStorageNodeChild(chainStorage, STORAGE_PATH);
const marshaller = await E(board).getReadonlyMarshaller();

const reservePublicFacet = await E(zoe).getPublicFacet(reserveInstance);

const auctionTerms = makeGovernedATerms(
{ storageNode, marshaller },
chainTimerService,
priceAuthority,
reservePublicFacet,
{
...params,
ElectorateInvitationAmount: electorateInvitationAmount,
TimerBrand: timerBrand,
},
);

const governorTerms = await deeplyFulfilledObject(
harden({
timer: chainTimerService,
governedContractInstallation: auctionInstallation,
governed: {
terms: auctionTerms,
issuerKeywordRecord: { Bid: stableIssuer },
storageNode,
marshaller,
label: 'auctioneer',
},
}),
);

/** @type {GovernorStartedInstallationKit<typeof auctionInstallation>} */
const governorStartResult = await E(zoe).startInstance(
contractGovernorInstallation,
undefined,
governorTerms,
harden({
electorateCreatorFacet,
governed: {
initialPoserInvitation,
storageNode,
marshaller,
},
}),
'auctioneer.governor',
);

const [governedInstance, governedCreatorFacet, governedPublicFacet] =
await Promise.all([
E(governorStartResult.creatorFacet).getInstance(),
E(governorStartResult.creatorFacet).getCreatorFacet(),
E(governorStartResult.creatorFacet).getPublicFacet(),
]);

const allIssuers = await E(zoe).getIssuers(legacyKit.instance);
const { Bid: _istIssuer, ...auctionIssuers } = allIssuers;
await Promise.all(
Object.keys(auctionIssuers).map(kwd =>
E(governedCreatorFacet).addBrand(auctionIssuers[kwd], kwd),
),
);

newAuctioneerKit.resolve(
harden({
label: 'auctioneer',
creatorFacet: governedCreatorFacet,
adminFacet: governorStartResult.adminFacet,
publicFacet: governedPublicFacet,
instance: governedInstance,

governor: governorStartResult.instance,
governorCreatorFacet: governorStartResult.creatorFacet,
governorAdminFacet: governorStartResult.adminFacet,
}),
);
// don't overwrite auctioneerKit or auction instance yet. Wait until
// upgrade-vault.js
};

export const ADD_AUCTION_MANIFEST = harden({
[addAuction.name]: {
consume: {
zoe: true,
board: true,
chainTimerService: true,
priceAuthority: true,
chainStorage: true,
economicCommitteeCreatorFacet: true,
auctioneerKit: true,
},
produce: {
newAuctioneerKit: true,
},
instance: {
consume: { reserve: true },
},
installation: {
consume: {
auctioneer: true,
contractGovernor: true,
},
},
issuer: {
consume: { [Stable.symbol]: true },
},
},
});

/* Add a new auction to a chain that already has one. */
export const getManifestForAddAuction = async () => {
return { manifest: ADD_AUCTION_MANIFEST };
};
Loading

0 comments on commit eae60be

Please sign in to comment.