Skip to content

Commit

Permalink
Merge pull request #7147 from Agoric/ta/BoardRemote
Browse files Browse the repository at this point in the history
board remote as remotable
  • Loading branch information
mergify[bot] authored Mar 10, 2023
2 parents 65f9122 + a298823 commit f2ebdb5
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 66 deletions.
2 changes: 0 additions & 2 deletions packages/agoric-cli/src/commands/ec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const makeEconomicCommiteeCommand = async _logger => {
id: opts.offerId,
invitationSpec: {
source: 'purse',
// @ts-expect-error xxx RpcRemote
instance: economicCommittee,
description: 'Voter0', // XXX it may not always be
},
Expand All @@ -56,7 +55,6 @@ export const makeEconomicCommiteeCommand = async _logger => {
id: opts.offerId,
invitationSpec: {
source: 'purse',
// @ts-expect-error xxx RpcRemote
instance: econCommitteeCharter,
description: 'charter member invitation',
},
Expand Down
1 change: 0 additions & 1 deletion packages/agoric-cli/src/commands/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const makeOracleCommand = async logger => {
id: Number(opts.offerId),
invitationSpec: {
source: 'purse',
// @ts-expect-error xxx RpcRemote
instance,
description: 'oracle invitation',
},
Expand Down
3 changes: 2 additions & 1 deletion packages/agoric-cli/src/commands/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ export const makePsmCommand = async logger => {
.action(async function (opts) {
console.warn('running with options', opts);
const instance = await lookupPsmInstance(opts.pair);
// @ts-expect-error xxx RpcRemote
const offer = Offers.psm.swap(instance, agoricNames.brand, {
offerId: opts.offerId,
feePct: opts.feePct,
giveMinted: opts.giveMinted,
wantMinted: opts.wantMinted,
});
outputExecuteOfferAction(offer);
});
Expand Down
17 changes: 14 additions & 3 deletions packages/agoric-cli/src/commands/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,20 @@ export const makeWalletCommand = async () => {
} catch (e) {
console.error('CAUGHT HERE', e);
}
execFileSync('agd', [`query`, 'bank', 'balances', opts.from], {
stdio: 'inherit',
});
execFileSync(
'agd',
[
'query',
'--node',
networkConfig.rpcAddrs[0],
'bank',
'balances',
opts.from,
],
{
stdio: 'inherit',
},
);
});

wallet
Expand Down
36 changes: 14 additions & 22 deletions packages/agoric-cli/src/lib/format.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
/* eslint-disable @typescript-eslint/prefer-ts-expect-error -- https://github.com/Agoric/agoric-sdk/issues/4620 */
import { makeBoardRemote } from '@agoric/vats/tools/board-utils.js';
// eslint-disable-next-line no-unused-vars -- typeof below
import { makeAgoricNames } from './rpc.js';

Expand All @@ -20,39 +20,40 @@ export const Natural = str => {
return b;
};

/** @type {import('@agoric/vats/tools/board-utils.js').VBankAssetDetail} */
// eslint-disable-next-line no-unused-vars
const exampleAsset = {
brand: { boardId: 'board0425', iface: 'Alleged: BLD brand' },
// @ts-expect-error cast
brand: makeBoardRemote({ boardId: 'board0425', iface: 'Alleged: BLD brand' }),
displayInfo: { assetKind: 'nat', decimalPlaces: 6 },
issuer: { boardId: null, iface: undefined },
// @ts-expect-error cast
issuer: makeBoardRemote({ boardId: null, iface: undefined }),
petname: 'Agoric staking token',
};
/** @typedef {import('@agoric/smart-wallet/src/smartWallet').BrandDescriptor & {brand: import('./rpc').RpcRemote}} AssetDescriptor */
/** @typedef {import('@agoric/vats/tools/board-utils.js').VBankAssetDetail & { brand: import('@agoric/vats/tools/board-utils.js').BoardRemote }} AssetDescriptor */

/** @param {AssetDescriptor[]} assets */
export const makeAmountFormatter = assets => amt => {
const {
brand: { boardId },
value,
} = amt;
const asset = assets.find(a => a.brand.boardId === boardId);
const asset = assets.find(a => a.brand.getBoardId() === boardId);
if (!asset) return [NaN, boardId];
const {
petname,
displayInfo: { assetKind, decimalPlaces = 0 },
issuerName,
} = asset;
const name = Array.isArray(petname) ? petname.join('.') : petname;
switch (assetKind) {
case 'nat':
/** @type {[petname: string, qty: number]} */
return [name, Number(value) / 10 ** decimalPlaces];
return [issuerName, Number(value) / 10 ** decimalPlaces];
case 'set':
if (value[0]?.handle?.iface?.includes('InvitationHandle')) {
return [name, value.map(v => v.description)];
return [issuerName, value.map(v => v.description)];
}
return [name, value];
return [issuerName, value];
default:
return [name, ['?']];
return [issuerName, ['?']];
}
};

Expand Down Expand Up @@ -97,11 +98,7 @@ export const fmtRecordOfLines = record => {
*/
export const offerStatusTuples = (state, agoricNames) => {
const { offerStatuses } = state;
const fmt = makeAmountFormatter(
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error -- https://github.com/Agoric/agoric-sdk/issues/4620 */
// @ts-ignore xxx RpcRemote
Object.values(agoricNames.vbankAsset),
);
const fmt = makeAmountFormatter(Object.values(agoricNames.vbankAsset));
const fmtRecord = r =>
r
? Object.fromEntries(
Expand Down Expand Up @@ -132,7 +129,6 @@ export const offerStatusTuples = (state, agoricNames) => {
} = 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,
);
const instanceName = entry ? entry[0] : '???';
Expand Down Expand Up @@ -161,11 +157,7 @@ export const summarize = (current, coalesced, agoricNames) => {
return {
lastOfferId: [current.lastOfferId],
purses: purseBalanceTuples(
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error -- https://github.com/Agoric/agoric-sdk/issues/4620 */
// @ts-ignore xxx RpcRemote
[...current.purses.values()],
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error -- https://github.com/Agoric/agoric-sdk/issues/4620 */
// @ts-ignore xxx RpcRemote
Object.values(agoricNames.vbankAsset),
),
usedInvitations: Object.entries(current.offerToUsedInvitation).map(
Expand Down
26 changes: 14 additions & 12 deletions packages/agoric-cli/src/lib/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
/* global Buffer, fetch, process */

import { NonNullish } from '@agoric/assert';
import { boardSlottingMarshaller } from '@agoric/vats/tools/board-utils.js';
import {
boardSlottingMarshaller,
makeBoardRemote,
} from '@agoric/vats/tools/board-utils.js';

export { boardSlottingMarshaller };

/**
* @typedef {{boardId: string, iface: string}} RpcRemote
*/

export const networkConfigUrl = agoricNetSubdomain =>
`https://${agoricNetSubdomain}.agoric.net/network-config`;
export const rpcUrl = agoricNetSubdomain =>
Expand Down Expand Up @@ -125,14 +124,14 @@ export const makeVStorage = powers => {
};
/** @typedef {ReturnType<typeof makeVStorage>} VStorage */

export const makeFromBoard = (slotKey = 'boardId') => {
export const makeFromBoard = () => {
const cache = new Map();
const convertSlotToVal = (slot, iface) => {
if (cache.has(slot)) {
return cache.get(slot);
const convertSlotToVal = (boardId, iface) => {
if (cache.has(boardId)) {
return cache.get(boardId);
}
const val = harden({ [slotKey]: slot, iface });
cache.set(slot, val);
const val = makeBoardRemote({ boardId, iface });
cache.set(boardId, val);
return val;
};
return harden({ convertSlotToVal });
Expand Down Expand Up @@ -189,9 +188,12 @@ export const makeAgoricNames = async (ctx, vstorage) => {
const content = await vstorage.readLatest(
`published.agoricNames.${kind}`,
);
/** @type {Array<[string, import('@agoric/vats/tools/board-utils.js').BoardRemote]>} */
const parts = storageHelper.unserializeTxt(content, ctx).at(-1);
for (const [name, remote] of parts) {
reverse[remote.boardId] = name;
if ('getBoardId' in remote) {
reverse[remote.getBoardId()] = name;
}
}
return [kind, Object.fromEntries(parts)];
}),
Expand Down
14 changes: 6 additions & 8 deletions packages/inter-protocol/src/clientSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const COSMOS_UNIT = 1_000_000n;
/**
* Give/want
*
* @param {Record<string, import('@agoric/vats/tools/board-utils').BoardRemote>} brands
* @param {Record<string, Brand>} brands
* @param {{ giveMinted?: number, wantMinted?: number } | { collateralBrandKey: string, giveCollateral?: number, wantCollateral?: number }} opts
* @returns {Proposal}
*/
Expand Down Expand Up @@ -54,7 +54,7 @@ const makeVaultProposal = (brands, opts) => {
// Then these can be used in tests as arguments to `executeOffer()` without a bridge.

/**
* @param {Record<string, import('@agoric/vats/tools/board-utils').BoardRemote>} brands
* @param {Record<string, Brand>} brands
* @param {{ offerId: string, wantMinted: number, giveCollateral: number, collateralBrandKey: string }} opts
* @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
*/
Expand Down Expand Up @@ -85,7 +85,7 @@ const makeOpenOffer = (brands, opts) => {
};

/**
* @param {Record<string, import('@agoric/vats/tools/board-utils').BoardRemote>} brands
* @param {Record<string, Brand>} brands
* @param {{ offerId: string, collateralBrandKey?: string, giveCollateral?: number, wantCollateral?: number, giveMinted?: number, wantMinted?: number }} opts
* @param {string} previousOffer
* @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
Expand All @@ -108,7 +108,7 @@ const makeAdjustOffer = (brands, opts, previousOffer) => {
};

/**
* @param {Record<string, import('@agoric/vats/tools/board-utils').BoardRemote>} brands
* @param {Record<string, Brand>} brands
* @param {{ offerId: string, collateralBrandKey?: string, giveMinted: number }} opts
* @param {string} previousOffer
* @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
Expand Down Expand Up @@ -147,7 +147,7 @@ export const lookupOfferIdForVault = async (vaultId, currentP) => {
};

/**
* @param {Record<string, import('@agoric/vats/tools/board-utils').BoardRemote>} brands
* @param {Record<string, Brand>} brands
* @param {({ wantMinted: number | undefined, giveMinted: number | undefined })} opts
* @param {number} [fee=0]
* @param {string} [anchor]
Expand All @@ -168,19 +168,17 @@ const makePsmProposal = (brands, opts, fee = 0, anchor = 'AUSD') => {
};
return {
give: {
// @ts-expect-error XXX BoardRemote not real remote
In: { brand: brand.in, value: adjusted.in },
},
want: {
// @ts-expect-error XXX BoardRemote not real remote
Out: { brand: brand.out, value: adjusted.out },
},
};
};

/**
* @param {Instance} instance
* @param {Record<string, import('@agoric/vats/tools/board-utils').BoardRemote>} brands
* @param {Record<string, Brand>} brands
* @param {{ offerId: number, feePct?: number } &
* ({ wantMinted: number | undefined, giveMinted: number | undefined })} opts
* @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
Expand Down
2 changes: 1 addition & 1 deletion packages/smart-wallet/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const makeWalletStateCoalescer = (invitationBrand = undefined) => {
/**
* keyed by description; xxx assumes unique
*
* @type {Map<import('./offers').OfferId, { acceptedIn: import('./offers').OfferId, description: string, instance: { boardId: string } }>}
* @type {Map<import('./offers').OfferId, { acceptedIn: import('./offers').OfferId, description: string, instance: Instance }>}
*/
const invitationsReceived = new Map();

Expand Down
2 changes: 1 addition & 1 deletion packages/vats/test/bootstrapTests/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const makeWalletFactoryDriver = async (
return EV(walletPresence).handleBridgeAction(offerCapData, true);
},
/**
* @template {(brands: Record<string, import('../../tools/board-utils.js').BoardRemote>, ...rest: any) => import('@agoric/smart-wallet/src/offers.js').OfferSpec} M offer maker function
* @template {(brands: Record<string, Brand>, ...rest: any) => import('@agoric/smart-wallet/src/offers.js').OfferSpec} M offer maker function
* @param {M} makeOffer
* @param {Parameters<M>[1]} firstArg
* @param {Parameters<M>[2]} [secondArg]
Expand Down
8 changes: 4 additions & 4 deletions packages/vats/test/test-board-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f2ebdb5

Please sign in to comment.