Skip to content

Commit

Permalink
vote command
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Sep 11, 2022
1 parent afe1131 commit 8aaedcb
Showing 1 changed file with 50 additions and 9 deletions.
59 changes: 50 additions & 9 deletions packages/agoric-cli/src/commands/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,20 @@ export const makePsmCommand = async logger => {

const marshaller = miniMarshal();

function lookupInstance(instanceId) {
const instance = agoricNames.instance[instanceId];
const lookupInstance = name => {
const instance = agoricNames.instance[name];
if (!instance) {
throw new commander.InvalidArgumentError(
`Unknown instance ${instanceId}`,
);
logger.debug('known instances:', agoricNames.instance);
throw new Error(`Unknown instance ${name}`);
}
return instance;
}
};

/** @param {import('../lib/psm.js').BridgeAction} bridgeAction */
const outputAction = bridgeAction => {
const capData = marshaller.serialize(bridgeAction);
process.stdout.write(JSON.stringify(capData));
};

psm
.command('swap')
Expand All @@ -140,12 +145,48 @@ export const makePsmCommand = async logger => {
)
.option('--feePct [%]', 'Gas fee percentage', parseInt)
.option('--offerId [number]', 'Offer id', parseInt, Date.now())
.option('--instance [id]', 'Instance id', lookupInstance, 'psm-IST-AUSD')
.option(
'--instance [name]',
'Instance name',
lookupInstance,
lookupInstance('psm-IST-AUSD'),
)
.action(function () {
const opts = this.opts();
console.log({ opts });
const spendAction = makePSMSpendAction(agoricNames.brand, opts);
const capData = marshaller.serialize(spendAction);
process.stdout.write(JSON.stringify(capData));
outputAction(spendAction);
});

psm
.command('vote')
.description('prepare an offer to vote')
.option('--offerId [number]', 'Offer id', String(Date.now()))
.option(
'--instance [name]',
'Instance name',
lookupInstance,
// XXX PSM charter not yet on ollinet
lookupInstance('economicCommittee'),
)
.action(function () {
const opts = this.opts();

/** @type {import('../lib/psm.js').OfferSpec} */
const offer = {
id: opts.offerId,
invitationSpec: {
source: 'purse',
instance: opts.instance,
description: 'PSM charter member invitation',
},
proposal: {},
};

outputAction({
method: 'executeOffer',
offer,
});
});

return psm;
Expand Down

0 comments on commit 8aaedcb

Please sign in to comment.