Skip to content

Commit

Permalink
feat: start a new auction in a3p-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Mar 27, 2024
1 parent 247cc9b commit 8ccfd48
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 0 deletions.
9 changes: 9 additions & 0 deletions a3p-integration/proposals/a:upgrade-next/auction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import test from 'ava';
import { getVatDetails } from '@agoric/synthetic-chain';

test('new auction vat', async t => {
const auctionDetails = await getVatDetails('auction');
console.log(`AUC `, auctionDetails);

t.pass('new Auction');
});
2 changes: 2 additions & 0 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,8 @@ 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"),
}
}

Expand Down
28 changes: 28 additions & 0 deletions packages/builders/scripts/vats/add-auction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { makeHelpers } from '@agoric/deploy-script-support';
import {
SECONDS_PER_HOUR,
SECONDS_PER_MINUTE,
} from '@agoric/inter-protocol/src/proposals/econ-behaviors.js';

// Build proposal for sim-chain etc.
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const defaultProposalBuilder = async () => {
const auctionParams = harden({
StartFrequency: 1n * SECONDS_PER_HOUR,
ClockStep: 3n * SECONDS_PER_MINUTE,
StartingRate: 10500n,
LowestRate: 6500n,
DiscountStep: 500n,
AuctionStartDelay: 2n,
PriceLockPeriod: SECONDS_PER_HOUR / 2n,
});
return harden({
sourceSpec: '@agoric/inter-protocol/src/proposals/add-auction.js',
getManifestCall: ['getManifestForAddAuction', auctionParams],
});
};

export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('add-auction', defaultProposalBuilder);
};
167 changes: 167 additions & 0 deletions packages/inter-protocol/src/proposals/add-auction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
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';
import { SECONDS_PER_HOUR, SECONDS_PER_MINUTE } from './econ-behaviors.js';

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

/**
* @param {import('./econ-behaviors.js').EconomyBootstrapPowers} powers
* @param {object} config
* @param {any} [config.auctionParams]
*/
export const addAuction = async (
{
consume: {
zoe,
board,
chainTimerService,
priceAuthority,
chainStorage,
economicCommitteeCreatorFacet: electorateCreatorFacet,
},
produce: { newAuctioneerKit },
instance: {
consume: { reserve: reserveInstance },
},
installation: {
consume: {
auctioneer: auctionInstallation,
contractGovernor: contractGovernorInstallation,
},
},
issuer: {
consume: { [Stable.symbol]: stableIssuerP },
},
},
{
auctionParams = {
StartFrequency: 1n * SECONDS_PER_HOUR,
ClockStep: 3n * SECONDS_PER_MINUTE,
StartingRate: 10500n,
LowestRate: 6500n,
DiscountStep: 500n,
AuctionStartDelay: 2n,
PriceLockPeriod: SECONDS_PER_HOUR / 2n,
},
} = {},
) => {
trace('startAuctioneer');
const STORAGE_PATH = 'auction';

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

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

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,
{
...auctionParams,
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(),
]);

// don't overwrite auctioneerKit yet
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 replace auction instance yet.
};

export const ADD_AUCTION_MANIFEST = harden({
[addAuction.name]: {
consume: {
zoe: true,
board: true,
chainTimerService: true,
priceAuthority: true,
chainStorage: true,
economicCommitteeCreatorFacet: 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 };
};
1 change: 1 addition & 0 deletions packages/inter-protocol/src/proposals/econ-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const SECONDS_PER_WEEK = 7n * SECONDS_PER_DAY;
* import('../vaultFactory/vaultFactory.js')['start']
* >;
* auctioneerKit: AuctioneerKit;
* newAuctioneerKit: AuctioneerKit;
* minInitialDebt: NatValue;
* }>} EconomyBootstrapSpace
*/
Expand Down

0 comments on commit 8ccfd48

Please sign in to comment.