Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(agops): fix continuing id lookup in oracle setPrice #8457

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading