Skip to content

Commit

Permalink
Merge pull request #8457 from Agoric/dc-setPrice-mcs
Browse files Browse the repository at this point in the history
fix(agops): fix continuing id lookup in oracle setPrice
  • Loading branch information
mergify[bot] authored Nov 30, 2023
2 parents 76118c5 + 9bf2d72 commit 3238732
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions packages/agoric-cli/src/commands/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export const makeOracleCommand = (logger, io = {}) => {
env.AGORIC_KEYRING_BACKEND,
);

const normalizeAddress = literalOrName =>
normalizeAddressWithOptions(literalOrName, oracle.opts(), {
execFileSync,
});

const rpcTools = async () => {
// XXX pass fetch to getNetworkConfig() explicitly
const networkConfig = await getNetworkConfig(env);
Expand Down Expand Up @@ -161,16 +166,16 @@ export const makeOracleCommand = (logger, io = {}) => {
console.warn('Now execute the prepared offer');
});

const findOracleCap = async (from, readLatestHead) => {
const findOracleCap = async (instance, from, readLatestHead) => {
const current = await getCurrent(from, { readLatestHead });

const { offerToUsedInvitation: entries } = /** @type {any} */ (current);
Array.isArray(entries) || Fail`entries must be an array: ${entries}`;

for (const [offerId, { value }] of entries) {
/** @type {{ description: string, instance: unknown }[]} */
const [{ description }] = value;
if (description === 'oracle invitation') {
const [{ description, instance: candidate }] = value;
if (description === 'oracle invitation' && candidate === instance) {
return offerId;
}
}
Expand All @@ -179,11 +184,22 @@ export const makeOracleCommand = (logger, io = {}) => {
oracle
.command('find-continuing-id')
.description('print id of specified oracle continuing invitation')
.requiredOption('--from <address>', 'from address', String)
.requiredOption(
'--from <address>',
'wallet address literal or name',
normalizeAddress,
)
.requiredOption(
'--pair [brandIn.brandOut]',
'token pair (brandIn.brandOut)',
s => s.split('.'),
)
.action(async opts => {
const { readLatestHead } = await makeRpcUtils({ fetch });
const { readLatestHead, lookupPriceAggregatorInstance } =
await rpcTools();
const instance = lookupPriceAggregatorInstance(opts.pair);

const offerId = await findOracleCap(opts.from, readLatestHead);
const offerId = await findOracleCap(instance, opts.from, readLatestHead);
if (!offerId) {
console.error('No continuing ids found');
}
Expand Down Expand Up @@ -211,11 +227,6 @@ export const makeOracleCommand = (logger, io = {}) => {
console.log(inspect(capDatas[0], { depth: 10, colors: true }));
});

/** @param {string} literalOrName */
const normalizeAddress = literalOrName =>
normalizeAddressWithOptions(literalOrName, oracle.opts(), {
execFileSync,
});
const show = (info, indent = false) =>
stdout.write(
`${JSON.stringify(info, bigintReplacer, indent ? 2 : undefined)}\n`,
Expand Down Expand Up @@ -249,7 +260,8 @@ export const makeOracleCommand = (logger, io = {}) => {
* }}
*/ { pair, keys, price },
) => {
const { readLatestHead, networkConfig } = await rpcTools();
const { readLatestHead, networkConfig, lookupPriceAggregatorInstance } =
await rpcTools();
const wutil = await makeWalletUtils(
{ fetch, execFileSync, delay },
networkConfig,
Expand Down Expand Up @@ -307,9 +319,12 @@ export const makeOracleCommand = (logger, io = {}) => {
console.warn(err);
});

const instance = lookupPriceAggregatorInstance(pair);

console.error('pushPrice from each:', keyOrder);
for await (const from of keyOrder) {
const oracleAdminAcceptOfferId = await findOracleCap(
instance,
from,
readLatestHead,
);
Expand Down

0 comments on commit 3238732

Please sign in to comment.