Skip to content

Commit

Permalink
Merge pull request #6317 from Agoric/ta/gov-wallet-misc
Browse files Browse the repository at this point in the history
fix: wallet show coalesced updates
  • Loading branch information
mergify[bot] authored Sep 28, 2022
2 parents c9a1d68 + 8506e6d commit a27d71d
Show file tree
Hide file tree
Showing 20 changed files with 259 additions and 135 deletions.
4 changes: 2 additions & 2 deletions packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
"integration-test": "ava --config .ava-integration-test.config.js",
"lint-fix": "yarn lint:eslint --fix",
"lint": "run-s --continue-on-error lint:*",
"lint:types": "tsc --maxNodeModuleJsDepth 0 -p jsconfig.json",
"lint:types": "tsc -p jsconfig.json",
"lint:eslint": "eslint ."
},
"devDependencies": {
"@agoric/swingset-vat": "^0.29.0",
"ava": "^4.3.1",
"c8": "^7.11.0"
},
Expand All @@ -37,6 +36,7 @@
"@agoric/ertp": "^0.15.0",
"@agoric/nat": "^4.1.0",
"@agoric/smart-wallet": "^0.3.0",
"@agoric/swingset-vat": "^0.29.0",
"@agoric/zoe": "^0.25.0",
"@cosmjs/crypto": "0.28.13",
"@cosmjs/encoding": "0.28.13",
Expand Down
20 changes: 11 additions & 9 deletions packages/agoric-cli/src/commands/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ const { vstorage, fromBoard, agoricNames } = await makeRpcUtils({ fetch });
* @param {[Minted: string, Anchor: string]} pair
*/
const getGovernanceState = async ([Minted, Anchor]) => {
const govContent = await vstorage.read(
const govContent = await vstorage.readLatest(
`published.psm.${Minted}.${Anchor}.governance`,
);
assert(govContent, 'no gov content');
const { current: governance } = last(
storageHelper.unserialize(govContent, fromBoard),
storageHelper.unserializeTxt(govContent, fromBoard),
);
const { [`psm.${Minted}.${Anchor}`]: instance } = agoricNames.instance;

Expand Down Expand Up @@ -117,7 +117,7 @@ export const makePsmCommand = async logger => {

psm
.command('info')
.description('show governance info about the PSM (BROKEN)')
.description('show governance parameters of the PSM')
// TODO DRY with https://github.com/Agoric/agoric-sdk/issues/6181
.requiredOption(
'--pair [Minted.Anchor]',
Expand Down Expand Up @@ -162,6 +162,7 @@ export const makePsmCommand = async logger => {
const opts = this.opts();
console.warn('running with options', opts);
const instance = await lookupPsmInstance(opts.pair);
// @ts-expect-error xxx RpcRemote
const spendAction = makePSMSpendAction(instance, agoricNames.brand, opts);
outputAction(spendAction);
});
Expand All @@ -181,6 +182,7 @@ export const makePsmCommand = async logger => {
id: Number(opts.offerId),
invitationSpec: {
source: 'purse',
// @ts-expect-error xxx RpcRemote
instance: economicCommittee,
description: 'Voter0', // XXX it may not always be
},
Expand Down Expand Up @@ -210,6 +212,7 @@ export const makePsmCommand = async logger => {
id: Number(opts.offerId),
invitationSpec: {
source: 'purse',
// @ts-expect-error xxx RpcRemote
instance: psmCharter,
description: 'PSM charter member invitation',
},
Expand All @@ -235,7 +238,7 @@ export const makePsmCommand = async logger => {
['IST', 'AUSD'],
)
.requiredOption(
'--previousOfferId [number]',
'--psmCharterAcceptOfferId [number]',
'offer that had continuing invitation result',
Number,
)
Expand All @@ -261,7 +264,7 @@ export const makePsmCommand = async logger => {
id: Number(opts.offerId),
invitationSpec: {
source: 'continuing',
previousOffer: opts.previousOfferId,
previousOffer: opts.psmCharterAcceptOfferId,
invitationMakerName: 'VoteOnPauseOffers',
// ( instance, strings list, timer deadline seconds )
invitationArgs: harden([
Expand Down Expand Up @@ -313,7 +316,6 @@ export const makePsmCommand = async logger => {

const psmInstance = lookupPsmInstance(opts.pair);

/** @type {import('../types.js').Brand} */
const istBrand = agoricNames.brand.IST;
const scaledAmount = harden({
brand: istBrand,
Expand Down Expand Up @@ -348,7 +350,7 @@ export const makePsmCommand = async logger => {
.description('vote on a question (hard-coded for now))')
.option('--offerId [number]', 'Offer id', Number, Date.now())
.requiredOption(
'--previousOfferId [number]',
'--econCommAcceptOfferId [number]',
'offer that had continuing invitation result',
Number,
)
Expand All @@ -366,10 +368,10 @@ export const makePsmCommand = async logger => {
.action(async function () {
const opts = this.opts();

const questionHandleCapDataStr = await vstorage.read(
const questionHandleCapDataStr = await vstorage.readLatest(
'published.committees.Initial_Economic_Committee.latestQuestion',
);
const questionDescriptions = storageHelper.unserialize(
const questionDescriptions = storageHelper.unserializeTxt(
questionHandleCapDataStr,
fromBoard,
);
Expand Down
58 changes: 34 additions & 24 deletions packages/agoric-cli/src/commands/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import {
iterateLatest,
makeCastingSpec,
makeFollower,
makeLeader,
makeLeaderFromRpcAddresses,
} from '@agoric/casting';
import { coalesceWalletState } from '@agoric/smart-wallet/src/utils.js';
import { Command } from 'commander';
import util from 'util';
import { fmtRecordOfLines, summarize } from '../lib/format.js';
import {
fmtRecordOfLines,
offerStatusTuples,
purseBalanceTuples,
} from '../lib/format.js';
import { makeRpcUtils, networkConfig } from '../lib/rpc.js';
import { getWalletState } from '../lib/wallet.js';
boardSlottingMarshaller,
makeRpcUtils,
networkConfig,
} from '../lib/rpc.js';

import { makeLeaderOptions } from '../lib/casting.js';
import {
Expand Down Expand Up @@ -124,28 +126,35 @@ export const makeWalletCommand = async () => {
.description('show current state')
.requiredOption(
'--from <address>',
'address literal or name',
'wallet address literal or name',
normalizeAddress,
)
.action(async function () {
const opts = this.opts();
const { agoricNames, fromBoard, vstorage } = await makeRpcUtils({

const { agoricNames, fromBoard } = await makeRpcUtils({
fetch,
});
const state = await getWalletState(opts.from, fromBoard, {
vstorage,
});
console.warn('got state', state);
const { brands, balances } = state;
const summary = {
balances: purseBalanceTuples(
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error -- https://github.com/Agoric/agoric-sdk/issues/4620 */
// @ts-ignore xxx RpcRemote
[...balances.values()],
[...brands.values()],
),
offers: offerStatusTuples(state, agoricNames),
};

const unserializer = boardSlottingMarshaller(fromBoard.convertSlotToVal);

const leader = makeLeader(networkConfig.rpcAddrs[0]);
const follower = await makeFollower(
`:published.wallet.${opts.from}`,
leader,
{
// @ts-expect-error xxx
unserializer,
},
);

const state = await coalesceWalletState(follower);

console.warn(
'got state',
util.inspect(state, { depth: 10, colors: true }),
);
const summary = summarize(state, agoricNames);
process.stdout.write(fmtRecordOfLines(summary));
});

Expand Down Expand Up @@ -176,8 +185,9 @@ export const makeWalletCommand = async () => {
const castingSpec = makeCastingSpec(spec);
const follower = makeFollower(castingSpec, leader);
for await (const { value } of iterateLatest(follower)) {
process.stdout.write(value);
process.stdout.write('\n');
// xxx relying on console for app output
// worth it to get the nice formatting
console.log(value);
}
});

Expand Down
4 changes: 4 additions & 0 deletions packages/agoric-cli/src/init.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import chalk from 'chalk';
import { makePspawn } from './helpers.js';

// Ambient types. Needed only for dev but this does a runtime import.
import '@endo/captp/src/types.js';
import '@agoric/swingset-vat/exported.js';

// Use either an absolute template URL, or find it relative to DAPP_URL_BASE.
const gitURL = (relativeOrAbsoluteURL, base) => {
const url = new URL(relativeOrAbsoluteURL, base);
Expand Down
36 changes: 33 additions & 3 deletions packages/agoric-cli/src/lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,25 @@ export const asPercent = ratio => {
/**
* Summarize the balances array as user-facing informative tuples
* @param {Array<import('../types').Amount>} balances
* @param {Array<Amount>} balances
* @param {AssetDescriptor[]} assets
*/
export const purseBalanceTuples = (balances, assets) => {
const fmt = makeAmountFormatter(assets);
return balances.map(b => fmt(b));
};

/**
* @param {Record<string, Array<unknown>>} record
*/
export const fmtRecordOfLines = record => {
const { stringify } = JSON;
const groups = Object.entries(record).map(([key, items]) => [
key,
items.map(item => ` ${stringify(item)}`),
]);
const lineEntries = groups.map(
// @ts-expect-error ???
([key, lines]) => ` ${stringify(key)}: [\n${lines.join(',\n')}\n ]`,
);
return `{\n${lineEntries.join(',\n')}\n}`;
Expand Down Expand Up @@ -118,15 +122,16 @@ export const offerStatusTuples = (state, agoricNames) => {
payouts,
} = o;
const amounts = {
give: fmtRecord(give),
want: fmtRecord(want),
give: give ? fmtRecord(give) : undefined,
want: want ? fmtRecord(want) : undefined,
payouts: fmtRecord(payouts),
};
switch (o.invitationSpec.source) {
case 'contract': {
const {
invitationSpec: { instance, publicInvitationMaker },
} = o;
// xxx could be O(1)
const entry = Object.entries(agoricNames.instance).find(
// @ts-ignore minimarshal types are off by a bit
([_name, candidate]) => candidate === instance,
Expand All @@ -146,3 +151,28 @@ export const offerStatusTuples = (state, agoricNames) => {
}
});
};

/**
*
* @param {ReturnType<import('@agoric/smart-wallet/src/utils.js').makeWalletStateCoalescer>['state']} state
* @param {Awaited<ReturnType<typeof makeAgoricNames>>} agoricNames
*/
export const summarize = (state, agoricNames) => {
const { balances, brands, invitationsReceived } = state;
const invitations = Array.from(invitationsReceived.values()).map(v => [
agoricNames.reverse[v.instance.boardId],
v.description,
v.acceptedIn || 'not yet accepted',
]);
return {
invitations,
balances: purseBalanceTuples(
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error -- https://github.com/Agoric/agoric-sdk/issues/4620 */
// @ts-ignore xxx RpcRemote
[...balances.values()],
// @ts-expect-error xxx RpcRemote
[...brands.values()],
),
offers: offerStatusTuples(state, agoricNames),
};
};
8 changes: 4 additions & 4 deletions packages/agoric-cli/src/lib/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { COSMOS_UNIT } from './format.js';
/** @typedef {import('@agoric/smart-wallet/src/smartWallet').BridgeAction} BridgeAction */

/**
* @param {Record<string, import('../types').Brand>} brands
* @param {Record<string, Brand>} brands
* @param {({ wantMinted: number | undefined, giveMinted: number | undefined })} opts
* @param {number} [fee=0]
* @param {string} [anchor]
* @returns {import('../types').Proposal}
* @returns {Proposal}
*/
export const makePSMProposal = (brands, opts, fee = 0, anchor = 'AUSD') => {
const giving = opts.giveMinted ? 'minted' : 'anchor';
Expand All @@ -37,8 +37,8 @@ export const makePSMProposal = (brands, opts, fee = 0, anchor = 'AUSD') => {
};

/**
* @param {import('../types').Instance} instance
* @param {Record<string, import('../types').Brand>} brands
* @param {Instance} instance
* @param {Record<string, Brand>} brands
* @param {{ offerId: number, feePct?: number } &
* ({ wantMinted: number | undefined, giveMinted: number | undefined })} opts
* @returns {BridgeAction}
Expand Down
Loading

0 comments on commit a27d71d

Please sign in to comment.