From 39b9fcff6b2c1c9a2ea4dee19c0f6c81cfd70a0c Mon Sep 17 00:00:00 2001 From: anilhelvaci Date: Tue, 8 Oct 2024 22:46:19 +0300 Subject: [PATCH] chore: add a method for getting latest round if for a given price feed https://github.com/Agoric/agoric-3-proposals/issues/182 --- .../synthetic-chain/src/lib/econHelpers.js | 18 +++++++++++++++++- .../test/snapshots/test-exports.ts.md | 1 + .../test/snapshots/test-exports.ts.snap | Bin 2276 -> 2300 bytes 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/synthetic-chain/src/lib/econHelpers.js b/packages/synthetic-chain/src/lib/econHelpers.js index 231e011f..3fc7a7d5 100644 --- a/packages/synthetic-chain/src/lib/econHelpers.js +++ b/packages/synthetic-chain/src/lib/econHelpers.js @@ -1,6 +1,12 @@ import { executeOffer, waitForBlock } from './commonUpgradeHelpers.js'; import { ATOM_DENOM, CHAINID, VALIDATORADDR } from './constants.js'; -import { agd, agops, executeCommand, agopsLocation } from './cliHelper.js'; +import { + agd, + agops, + executeCommand, + agopsLocation, + agoric as agoricAmbient, +} from './cliHelper.js'; import { GOV1ADDR, GOV2ADDR, GOV3ADDR } from './constants.js'; import { queryVstorage, getQuoteBody, getInstanceBoardId } from './vstorage.js'; @@ -198,6 +204,16 @@ export const pushPrices = async (price, brandIn, oraclesByBrand, round) => { } }; +export const getRoundId = async (price, io = {}) => { + const { + agoric = { follow: agoricAmbient.follow }, + prefix = 'published.', + } = io; + const path = `:${prefix}priceFeed.${price}-USD_price_feed.latestRound`; + const round = await agoric.follow('-lF', path); + return parseInt(round.roundId); +}; + export const getPriceQuote = async price => { const path = `published.priceFeed.${price}-USD_price_feed`; const body = await getQuoteBody(path); diff --git a/packages/synthetic-chain/test/snapshots/test-exports.ts.md b/packages/synthetic-chain/test/snapshots/test-exports.ts.md index 44e233da..34e950d0 100644 --- a/packages/synthetic-chain/test/snapshots/test-exports.ts.md +++ b/packages/synthetic-chain/test/snapshots/test-exports.ts.md @@ -68,6 +68,7 @@ Generated by [AVA](https://avajs.dev). getPriceQuote: AsyncFunction {}, getProvisionPoolMetrics: AsyncFunction [], getQuoteBody: AsyncFunction {}, + getRoundId: AsyncFunction {}, getUser: AsyncFunction {}, getVatDetails: AsyncFunction {}, getVaultPrices: AsyncFunction {}, diff --git a/packages/synthetic-chain/test/snapshots/test-exports.ts.snap b/packages/synthetic-chain/test/snapshots/test-exports.ts.snap index 17997e702afe700f95505e977d08f00078056eb4..d4255a46c6b04ffa5e807cea73ed95968572fc13 100644 GIT binary patch literal 2300 zcmVKMZ zT!9xyUmuGI00000000A(nO$rgR~5(qWAC@^wH-TIrzxaB+Y}OK{rv%jvi@o|iDP3s zP6|TF^~~MbSNNR$upgb+gF zffk8Ugka~++SlW?@%YJe{=akYx#ym_K6CwYVasIdw)5O8lpEZnI;~fj%^kzBNX02K z?mYLhrV&n_Ik(=4IGR67Lb-NT0ag{Dt^i+EfY%h@Ob4KK0N?EZ{?GyRcLH}if$wz! zzwHFx>IC{Cz+(~M$p~;e0(?6H{5S&qE&{w00Wwjb76rZ%1%40(-i!ioM}h7bFd74H z!~iP>ybuFkjRCL!@A+>rU@#6$#(_`AfoJ2uy*TirIPk|f@SiwvAptBV0FnT96Tp`e z!1oitZxX;e3E)%`xSRy8CV^rS_-qommjqr-0&gUNzb1kH6fl+oZl?gA0$xf1_fx=| zDd61{aJCD`b^$A0fZheX*ah700tS>=T2cCy*fP^xllJxXLFs{V6-qA#l#W5A6H2sS zN#!URr>Hx&J3djFs*vLJ&d5Zm=x$jUT0@%qBG zJ8LT|8!f{?)^+TxW2;#a!LXxk2Yiw@*B95?X4079NC^Nm$#?fovCtpYInlb zY<*_C;WnxTXSWm_u4glMJ-?9KSXpbkISzMdjZc+!oci>1rKZ-mtw~ZGDedU)j9t_V zX04!^P|}L>>n@<>ewt|7s!eI#aJXUVD>hM0>Ufyay^qC-rrmU??Fqw@&_%S8>+ntD zn%oobN@Ay1g=s~3Nis%>&MIPtpGoGFXU=%3X?TIa7ZLd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