Skip to content

Commit

Permalink
WIP: agops auction proposeParamChange command
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Apr 1, 2023
1 parent 5b41ec1 commit a05f324
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 15 deletions.
30 changes: 15 additions & 15 deletions packages/agoric-cli/src/bin-agops.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { makeReserveCommand } from './commands/reserve.js';
import { makeVaultsCommand } from './commands/vaults.js';
import { makePerfCommand } from './commands/perf.js';
import { makeInterCommand } from './commands/inter.js';
import { makeAuctionCommand } from './commands/auction.js';

const logger = anylogger('agops');
const progname = path.basename(process.argv[1]);
Expand All @@ -30,23 +31,22 @@ program.addCommand(await makeOracleCommand(logger));
program.addCommand(await makeEconomicCommiteeCommand(logger));
program.addCommand(await makePerfCommand(logger));
program.addCommand(await makePsmCommand(logger));
program.addCommand(await makeReserveCommand(logger));
program.addCommand(await makeVaultsCommand(logger));

program.addCommand(
await makeInterCommand(
{
env: { ...process.env },
stdout: process.stdout,
stderr: process.stderr,
createCommand,
execFileSync,
now: () => Date.now(),
setTimeout,
},
{ fetch },
),
);
const procIO = {
env: { ...process.env },
stdout: process.stdout,
stderr: process.stderr,
createCommand,
execFileSync,
now: () => Date.now(),
clock: () => Promise.resolve(Date.now()),
setTimeout,
};

program.addCommand(await makeReserveCommand(logger, procIO));
program.addCommand(makeAuctionCommand(logger, { ...procIO, fetch }));
program.addCommand(await makeInterCommand(procIO, { fetch }));

try {
await program.parseAsync(process.argv);
Expand Down
167 changes: 167 additions & 0 deletions packages/agoric-cli/src/commands/auction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/* eslint-disable @jessie.js/no-nested-await */
// @ts-check
/* eslint-disable func-names */
import { InvalidArgumentError } from 'commander';
import { makeRpcUtils } from '../lib/rpc.js';
import { outputActionAndHint } from '../lib/wallet.js';

const { Fail } = assert;

/** @typedef {import('@agoric/governance/src/contractGovernance/typedParamManager.js').ParamTypesMap} ParamTypesMap */
/** @template M @typedef {import('@agoric/governance/src/contractGovernance/typedParamManager.js').ParamTypesMapFromRecord<M>} ParamTypesMapFromRecord */

/**
* @template {ParamTypesMap} M
* @typedef {{
* [K in keyof M]: ParamValueForType<M[K]>
* }} ParamValues
*/

/** @typedef {ReturnType<import('@agoric/inter-protocol/src/auction/params.js').makeAuctioneerParams>} AuctionParamRecord */
/** @typedef {ParamValues<ParamTypesMapFromRecord<AuctionParamRecord>>} AuctionParams */

/**
* @param {import('anylogger').Logger} _logger
* @param {{
* createCommand: typeof import('commander').createCommand,
* fetch: typeof window.fetch,
* stdout: Pick<import('stream').Writable, 'write'>,
* stderr: Pick<import('stream').Writable, 'write'>,
* clock: () => Promise<number>,
* }} io
*/
export const makeAuctionCommand = (
_logger,
{ createCommand, stdout, stderr, fetch, clock },
) => {
const reserve = createCommand('auctioneer').description(
'Auctioneer commands',
);

reserve
.command('proposeParamChange')
.description('propose a change to start frequency')
.option(
'--start-frequency <seconds>',
'how often to start auctions',
BigInt,
)
.option('--clock-step <seconds>', 'descending clock frequency', BigInt)
.option(
'--starting-rate <basis-points>',
'relative to oracle: 999 = 1bp discount',
BigInt,
)
.option('--lowest-rate <basis-points>', 'lower limit for discount', BigInt)
.option(
'--discount-step <basis-points>',
'descending clock step size',
BigInt,
)
.option(
'--discount-step <integer>',
'proposed value (basis points)',
BigInt,
)
.requiredOption(
'--charterAcceptOfferId <string>',
'offer that had continuing invitation result',
)
.option('--offer-id <string>', 'Offer id', String, `propose-${Date.now()}`)
.option(
'--deadline [minutes]',
'minutes from now to close the vote',
Number,
1,
)
.action(
/**
*
* @param {{
* charterAcceptOfferId: string,
* startFrequency?: bigint,
* clockStep?: bigint,
* startingRate?: bigint,
* lowestRate?: bigint,
* discountStep?: bigint,
* offerId: string,
* deadline: number,
* }} opts
*/
async opts => {
const { agoricNames, readLatestHead } = await makeRpcUtils({ fetch });
const { brand } = agoricNames;

/** @type {{ current: AuctionParamRecord }} */
// @ts-expect-error XXX should runtime check?
const { current } = await readLatestHead(
`published.auction.governance`,
);

const {
AuctionStartDelay: {
// @ts-expect-error XXX RelativeTime includes raw bigint
value: { timerBrand },
},
} = current;
timerBrand || Fail`no timer brand?`;

/**
* typed param manager requires RelativeTimeRecord
* but TimeMath.toRel prodocues a RelativeTime (which may be a bare bigint).
*
* @param {bigint} relValue
* @returns {import('@agoric/time/src/types').RelativeTimeRecord}
*/
const toRel = relValue => relValue; // ({ timerBrand, relValue });

/** @type {Partial<AuctionParams>} */
const params = {
...(opts.startFrequency && {
StartFrequency: toRel(opts.startFrequency),
}),
...(opts.clockStep && { ClockStep: toRel(opts.clockStep) }),
...(opts.startingRate && { StartingRate: opts.startingRate }),
...(opts.lowestRate && { LowestRate: opts.lowestRate }),
...(opts.discountStep && { DiscountStep: opts.discountStep }),
};

if (Object.keys(params).length === 0) {
throw new InvalidArgumentError(`no parameters given`);
}

const instance = agoricNames.instance.auctioneer;
instance || Fail`missing auctioneer in names`;

const t0 = await clock();
const deadline = BigInt(Math.round(t0 / 1000) + 60 * opts.deadline);

/** @type {import('@agoric/inter-protocol/src/econCommitteeCharter.js').ParamChangesOfferArgs} */
const offerArgs = {
deadline,
params,
instance,
path: { paramPath: { key: 'governedParams' } },
};

/** @type {import('@agoric/smart-wallet/src/offers.js').OfferSpec} */
const offer = {
id: opts.offerId,
invitationSpec: {
source: 'continuing',
previousOffer: opts.charterAcceptOfferId,
invitationMakerName: 'VoteOnParamChange',
},
offerArgs,
proposal: {},
};

outputActionAndHint(
{ method: 'executeOffer', offer },
{ stdout, stderr },
);
},
);

return reserve;
};

0 comments on commit a05f324

Please sign in to comment.