Skip to content

Commit

Permalink
WIP WIP WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Aug 5, 2024
1 parent f02a654 commit 18f788e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
37 changes: 24 additions & 13 deletions packages/boot/test/bootstrapTests/price-feed-replace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ test.after.always(t => t.context.shutdown());
const collateralBrandKey = 'ATOM';
const managerIndex = 0;

// TODO: read from config file? sync with liquidation.ts
const ORACLE_ADDRESSES = [
'agoric1ldmtatp24qlllgxmrsjzcpe20fvlkp448zcuce',
'agoric140dmkrz2e42ergjj7gyvejhzmjzurvqeq82ang',
'agoric1w8wktaur4zf8qmmtn3n7x3r0jhsjkjntcm3u6h',
];

const setup: LiquidationSetup = {
vaults: [{ atom: 15, ist: 100, debt: 100.5 }],
bids: [{ give: '20IST', discount: 0.1 }],
Expand Down Expand Up @@ -63,24 +70,28 @@ test.serial('run replace-price-feeds proposals', async t => {
refreshAgoricNamesRemotes,
} = t.context;

const perFeedBuilders = [
// close enough to @agoric/builders/scripts/vats/priceFeedSupport.js"
'@agoric/builders/scripts/vats/updateAtomPriceFeed.js',
];
const instancePre = agoricNamesRemotes.instance['ATOM-USD price feed'];

const builders = [
...perFeedBuilders,
const perFeedBuilder = '@agoric/builders/scripts/vats/priceFeedSupport.js';
t.log('building', perFeedBuilder);
const brandName = collateralBrandKey;
const opts = {
AGORIC_INSTANCE_NAME: `${brandName}-USD price feed`,
ORACLE_ADDRESSES,
IN_BRAND_LOOKUP: ['agoricNames', 'oracleBrand', brandName],
IN_BRAND_DECIMALS: 6,
OUT_BRAND_LOOKUP: ['agoricNames', 'oracleBrand', 'USD'],
OUT_BRAND_DECIMALS: 4,
};
await evalProposal(buildProposal(perFeedBuilder, opts));

for (const builder of [
'@agoric/builders/scripts/vats/replaceScaledPriceAuthorities.js',
'@agoric/builders/scripts/vats/add-auction.js',
'@agoric/builders/scripts/vats/upgradeVaults.js',
];

const instancePre = agoricNamesRemotes.instance['ATOM-USD price feed'];
await null;
for (const builder of builders) {
]) {
t.log('building', builder);
const p = buildProposal(builder);
await evalProposal(p);
await evalProposal(buildProposal(builder));
}
refreshAgoricNamesRemotes();
const instancePost = agoricNamesRemotes.instance['ATOM-USD price feed'];
Expand Down
10 changes: 8 additions & 2 deletions packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export const makeProposalExtractor = ({ childProcess, fs }: Powers) => {
outputDir: string,
scriptPath: string,
env: NodeJS.ProcessEnv,
cliArgs: string[] = [],
) => {
console.info('running package script:', scriptPath);
const out = childProcess.execFileSync('yarn', ['bin', 'agoric'], {
Expand All @@ -160,7 +161,7 @@ export const makeProposalExtractor = ({ childProcess, fs }: Powers) => {
});
return childProcess.execFileSync(
out.toString().trim(),
['run', scriptPath],
['run', scriptPath, ...cliArgs],
{
cwd: outputDir,
env,
Expand Down Expand Up @@ -191,16 +192,21 @@ export const makeProposalExtractor = ({ childProcess, fs }: Powers) => {
return { evals, bundles };
};

const buildAndExtract = async (builderPath: string) => {
const buildAndExtract = async (
builderPath: string,
opts?: Record<string, unknown>,
) => {
const tmpDir = await fsAmbientPromises.mkdtemp(
join(getPkgPath('builders'), 'proposal-'),
);

const args = opts ? [JSON.stringify(opts)] : [];
const built = parseProposalParts(
runPackageScript(
tmpDir,
await importSpec(builderPath),
process.env,
args,
).toString(),
);

Expand Down
15 changes: 15 additions & 0 deletions packages/builders/scripts/vats/priceFeedSupport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global process */

import { makeHelpers } from '@agoric/deploy-script-support';
import { DEFAULT_CONTRACT_TERMS } from '../inter-protocol/price-feed-core.js';

const { Fail } = assert;
Expand Down Expand Up @@ -88,3 +89,17 @@ export const deprecatedPriceFeedProposalBuilder = async (powers, options) => {
* @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder}
*/
export const priceFeedProposalBuilder = deprecatedPriceFeedProposalBuilder;

export default async (homeP, endowments) => {
const { writeCoreEval } = await makeHelpers(homeP, endowments);

const { scriptArgs } = endowments;
if (scriptArgs.length !== 1) throw RangeError('arg 0 must be JSON opts');
console.log('@@@@', { scriptArgs });
const opts = JSON.parse(scriptArgs[0]);
console.log('@@@@', { scriptArgs, opts });

await writeCoreEval('atomPriceFeed', powers =>
strictPriceFeedProposalBuilder(powers, opts),
);
};

0 comments on commit 18f788e

Please sign in to comment.