-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(a3p): setup the oracle and push price for ATOM and stATOM at `u…
…se` phase of `f:replace-price-feeds` (#10296) closes: https://github.com/Agoric/BytePitchPartnerEng/issues/26 refs: https://github.com/Agoric/BytePitchPartnerEng/issues/22 ## Description This PR introduces a new script, `verifyPushedPrice`, which is executed during the `use` phase of the `n:upgrade-next` proposal. The purpose of this script is to set up the oracle and push an initial price for key brands such as Atom and stAtom. This functionality ensures that a price quote is available for the subsequent proposals and acceptance tests. ### Security Considerations ### Scaling Considerations ### Documentation Considerations ### Testing Considerations The existing test file, `priceFeedUpdate.test.js`, has been updated to account for the new price feed calls made during the use phase, as well as take advantage of the new helper functions built. ### Upgrade Considerations
- Loading branch information
Showing
6 changed files
with
177 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
a3p-integration/proposals/n:upgrade-next/test-lib/price-feed.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-env node */ | ||
|
||
import { | ||
agoric, | ||
getContractInfo, | ||
pushPrices, | ||
getPriceQuote, | ||
} from '@agoric/synthetic-chain'; | ||
import { retryUntilCondition } from './sync-tools.js'; | ||
|
||
export const scale6 = x => BigInt(x * 1_000_000); | ||
|
||
/** | ||
* | ||
* @param {number} price | ||
* @param {string} brand | ||
* @param {Map<any, any>} oraclesByBrand | ||
* @param {number} roundId | ||
* @returns {Promise<void>} | ||
*/ | ||
export const verifyPushedPrice = async ( | ||
price, | ||
brand, | ||
oraclesByBrand, | ||
roundId, | ||
) => { | ||
const pushPriceRetryOpts = { | ||
maxRetries: 5, // arbitrary | ||
retryIntervalMs: 5000, // in ms | ||
}; | ||
|
||
await pushPrices(price, brand, oraclesByBrand, roundId); | ||
console.log(`Pushing price ${price} for ${brand}`); | ||
|
||
await retryUntilCondition( | ||
() => getPriceQuote(brand), | ||
res => res === `+${scale6(price).toString()}`, | ||
'price not pushed yet', | ||
{ | ||
log: console.log, | ||
setTimeout: global.setTimeout, | ||
...pushPriceRetryOpts, | ||
}, | ||
); | ||
console.log(`Price ${price} pushed for ${brand}`); | ||
}; | ||
|
||
/** | ||
* | ||
* @param {string} brand | ||
* @returns {Promise<number>} | ||
*/ | ||
export const getPriceFeedRoundId = async brand => { | ||
const latestRoundPath = `published.priceFeed.${brand}-USD_price_feed.latestRound`; | ||
const latestRound = await getContractInfo(latestRoundPath, { | ||
agoric, | ||
prefix: '', | ||
}); | ||
|
||
console.log('latestRound: ', latestRound); | ||
return Number(latestRound.roundId); | ||
}; |
72 changes: 72 additions & 0 deletions
72
a3p-integration/proposals/n:upgrade-next/test-lib/sync-tools.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* eslint-env node */ | ||
|
||
/** | ||
* @file These tools mostly duplicate code that will be added in other PRs | ||
* and eventually migrated to synthetic-chain. Sorry for the duplication. | ||
*/ | ||
|
||
/** | ||
* @typedef {object} RetryOptions | ||
* @property {number} [maxRetries] | ||
* @property {number} [retryIntervalMs] | ||
* @property {(...arg0: string[]) => void} log | ||
* @property {(object) => void} [setTimeout] | ||
* @property {string} [errorMessage=Error] | ||
*/ | ||
|
||
const ambientSetTimeout = global.setTimeout; | ||
|
||
/** | ||
* From https://github.com/Agoric/agoric-sdk/blob/442f07c8f0af03281b52b90e90c27131eef6f331/multichain-testing/tools/sleep.ts#L10 | ||
* | ||
* @param {number} ms | ||
* @param {*} sleepOptions | ||
*/ | ||
const sleep = (ms, { log = () => {}, setTimeout = ambientSetTimeout }) => | ||
new Promise(resolve => { | ||
log(`Sleeping for ${ms}ms...`); | ||
setTimeout(resolve, ms); | ||
}); | ||
|
||
/** | ||
* From https://github.com/Agoric/agoric-sdk/blob/442f07c8f0af03281b52b90e90c27131eef6f331/multichain-testing/tools/sleep.ts#L24 | ||
* | ||
* @param {() => Promise} operation | ||
* @param {(result: any) => boolean} condition | ||
* @param {string} message | ||
* @param {RetryOptions} options | ||
*/ | ||
export const retryUntilCondition = async ( | ||
operation, | ||
condition, | ||
message, | ||
{ maxRetries = 6, retryIntervalMs = 3500, log, setTimeout }, | ||
) => { | ||
console.log({ maxRetries, retryIntervalMs, message }); | ||
let retries = 0; | ||
|
||
await null; | ||
while (retries < maxRetries) { | ||
try { | ||
const result = await operation(); | ||
log('RESULT', result); | ||
if (condition(result)) { | ||
return result; | ||
} | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
log(`Error: ${error.message}`); | ||
} else { | ||
log(`Unknown error: ${String(error)}`); | ||
} | ||
} | ||
|
||
retries += 1; | ||
console.log( | ||
`Retry ${retries}/${maxRetries} - Waiting for ${retryIntervalMs}ms for ${message}...`, | ||
); | ||
await sleep(retryIntervalMs, { log, setTimeout }); | ||
} | ||
|
||
throw Error(`${message} condition failed after ${maxRetries} retries.`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
a3p-integration/proposals/n:upgrade-next/verifyPushedPrice.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
|
||
import { | ||
registerOraclesForBrand, | ||
generateOracleMap, | ||
} from '@agoric/synthetic-chain'; | ||
import { argv } from 'node:process'; | ||
import { verifyPushedPrice } from './test-lib/price-feed.js'; | ||
|
||
const brand = argv[2]; | ||
const price = Number(argv[3]); | ||
|
||
const BASE_ID = 'n-upgrade'; | ||
const ROUND_ID = 1; | ||
|
||
const oraclesByBrand = generateOracleMap(BASE_ID, [brand]); | ||
await registerOraclesForBrand(brand, oraclesByBrand); | ||
console.log(`Registering Oracle for ${brand}`); | ||
|
||
await verifyPushedPrice(price, brand, oraclesByBrand, ROUND_ID); | ||
console.log(`Price pushed for ${brand}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters