Skip to content

Commit

Permalink
agops setPrice ux improvements (#9984)
Browse files Browse the repository at this point in the history
_incidental_

## Description
Some new case handling and user feedback to reduce support costs

### Security Considerations
n/a
### Scaling Considerations
n/a

### Documentation Considerations
internal

### Testing Considerations
tested locally

### Upgrade Considerations
n/a
  • Loading branch information
mergify[bot] authored Aug 28, 2024
2 parents daff9eb + 1fcf43c commit 7ab749c
Showing 1 changed file with 52 additions and 33 deletions.
85 changes: 52 additions & 33 deletions packages/agoric-cli/src/commands/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const COSMOS_UNIT = 1_000_000n;
const scaleDecimals = num => BigInt(num * Number(COSMOS_UNIT));

/**
* Prints JSON output to stdout and diagnostic info (like logs) to stderr
*
* @param {import('anylogger').Logger} logger
* @param {{
* delay?: (ms: number) => Promise<void>,
Expand Down Expand Up @@ -271,14 +273,13 @@ export const makeOracleCommand = (logger, io = {}) => {
);
const unitPrice = scaleDecimals(price);

console.error(`${pair[0]}-${pair[1]}_price_feed: before setPrice`);
const feedPath = `published.priceFeed.${pair[0]}-${pair[1]}_price_feed`;

const readPrice = () =>
/** @type {Promise<PriceDescription>} */ (
readLatestHead(
`published.priceFeed.${pair[0]}-${pair[1]}_price_feed`,
).catch(err => {
console.warn(`cannot get ${pair[0]}-${pair[1]}_price_feed`, err);
readLatestHead(feedPath).catch(() => {
const viewer = `https://vstorage.agoric.net/#${networkConfig.rpcAddrs[0]}|published,published.priceFeed|${feedPath}`;
console.warn(`no existing price data; see ${viewer}`);
return undefined;
})
);
Expand All @@ -297,43 +298,61 @@ export const makeOracleCommand = (logger, io = {}) => {
show(fmtFeed(before));
}

console.error(
'Choose lead oracle operator order based on latestRound...',
);
const keyOrder = keys.map(normalizeAddress);
const latestRoundP = readLatestHead(
`published.priceFeed.${pair[0]}-${pair[1]}_price_feed.latestRound`,
);
await Promise.race([
delay(5000),
latestRoundP.then(round => {
// @ts-expect-error XXX get type from contract
const { roundId, startedAt, startedBy } = round;
show({
startedAt: fmtSecs(startedAt.absValue),
roundId,
startedBy,
});
if (startedBy === keyOrder[0]) {
keyOrder.reverse();
}
}),
]).catch(err => {
console.warn(err);
});
if (before) {
console.error(
'Choose lead oracle operator order based on latestRound...',
);

const instance = lookupPriceAggregatorInstance(pair);
const latestRoundP =
/** @type {Promise<{roundId: number, startedAt: import('@agoric/time').TimestampRecord, startedBy: string}>} */ (
readLatestHead(
`published.priceFeed.${pair[0]}-${pair[1]}_price_feed.latestRound`,
)
);
await Promise.race([
delay(5000),
latestRoundP.then(round => {
const { roundId, startedAt, startedBy } = round;
show({
startedAt: fmtSecs(startedAt.absValue),
roundId,
startedBy,
});
if (startedBy === keyOrder[0]) {
keyOrder.reverse();
}
}),
]).catch(err => {
console.warn(err);
});
}

console.error('pushPrice from each:', keyOrder);
const instance = lookupPriceAggregatorInstance(pair);
const adminOfferIds = {};
for await (const from of keyOrder) {
const oracleAdminAcceptOfferId = await findOracleCap(
adminOfferIds[from] = await findOracleCap(
instance,
from,
readLatestHead,
);
if (!oracleAdminAcceptOfferId) {
throw Error(`no oracle invitation found: ${from}`);
if (!adminOfferIds[from]) {
console.error(
`Failed to find an offer accepting oracle invitation for ${from}. Accept and try again:`,
);
console.error(
` agops oracle accept > accept.json; agoric wallet send --from ${from} --offer accept.json`,
);
}
}
assert(
Object.values(adminOfferIds).every(x => x),
'Missing oracle admin offer ids',
);

console.error('pushPrice from each:', keyOrder);
for await (const from of keyOrder) {
const oracleAdminAcceptOfferId = adminOfferIds[from];
show({ from, oracleAdminAcceptOfferId });
const offerId = `pushPrice-${Date.now()}`;
const offer = Offers.fluxAggregator.PushPrice(
Expand Down

0 comments on commit 7ab749c

Please sign in to comment.