Skip to content

Commit

Permalink
feat(builders): non-ambient strictPriceFeedProposalBuilder in `pric…
Browse files Browse the repository at this point in the history
…eFeedSupport.js`
  • Loading branch information
michaelfig authored and mhofman committed Jun 26, 2024
1 parent 8376991 commit 95174a2
Showing 1 changed file with 47 additions and 19 deletions.
66 changes: 47 additions & 19 deletions packages/builders/scripts/vats/priceFeedSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,33 @@

import { DEFAULT_CONTRACT_TERMS } from '../inter-protocol/price-feed-core.js';

const ORACLE_ADDRESSES = [
// XXX These are the oracle addresses. They must be provided before the chain
// is running, which means they must be known ahead of time.
// see https://github.com/Agoric/agoric-3-proposals/issues/5
'agoric1lu9hh5vgx05hmlpfu47hukershgdxctk6l5s05',
'agoric15lpnq2mjsdhtztf6khp7mrsq66hyrssspy92pd',
'agoric1mwm224epc4l3pjcz7qsxnudcuktpynwkmnfqfp',
];
const { Fail } = assert;

/**
* modified copy of ../inter-protocol/price-feed-core.js
*
* @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder}
*/
export const priceFeedProposalBuilder = async (
export const strictPriceFeedProposalBuilder = async (
{ publishRef, install },
options = {},
options,
) => {
const {
AGORIC_INSTANCE_NAME,
IN_BRAND_LOOKUP,
IN_BRAND_NAME = IN_BRAND_LOOKUP[IN_BRAND_LOOKUP.length - 1],
ORACLE_ADDRESSES,
} = options;

const { GOV1ADDR, GOV2ADDR, GOV3ADDR } = process.env;
const oracleAddresses =
GOV1ADDR || GOV2ADDR || GOV3ADDR
? [GOV1ADDR, GOV2ADDR, GOV3ADDR].filter(x => x)
: ORACLE_ADDRESSES;
assert(Array.isArray(oracleAddresses), 'oracleAddresses array is required');
const oracleAddresses = ORACLE_ADDRESSES;
Array.isArray(oracleAddresses) ||
Fail`ORACLE_ADDRESSES array is required; got ${oracleAddresses}`;

assert(AGORIC_INSTANCE_NAME, 'AGORIC_INSTANCE_NAME is required');
AGORIC_INSTANCE_NAME ||
Fail`AGORIC_INSTANCE_NAME is required; got ${AGORIC_INSTANCE_NAME}`;

assert.equal(IN_BRAND_LOOKUP[0], 'agoricNames');
assert(IN_BRAND_NAME, 'brandIn is required');
Array.isArray(IN_BRAND_LOOKUP) ||
Fail`IN_BRAND_NAME array is required; got ${IN_BRAND_LOOKUP}`;

return harden({
sourceSpec: '@agoric/inter-protocol/src/proposals/price-feed-proposal.js',
Expand All @@ -60,3 +52,39 @@ export const priceFeedProposalBuilder = async (
],
});
};

/**
* @deprecated use `strictPriceFeedProposalBuilder` and specify arguments instead
* @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder}
*/
export const deprecatedPriceFeedProposalBuilder = async (powers, options) => {
console.warn(
'deprecated ambient `priceFeedProposalBuilder`; use `strictPriceFeedProposalBuilder` instead',
);

const DEFAULT_ORACLE_ADDRESSES = [
// XXX These are the oracle addresses. They must be provided before the chain
// is running, which means they must be known ahead of time.
// see https://github.com/Agoric/agoric-3-proposals/issues/5
'agoric1lu9hh5vgx05hmlpfu47hukershgdxctk6l5s05',
'agoric15lpnq2mjsdhtztf6khp7mrsq66hyrssspy92pd',
'agoric1mwm224epc4l3pjcz7qsxnudcuktpynwkmnfqfp',
];

const { GOV1ADDR, GOV2ADDR, GOV3ADDR } = process.env;
const governanceAddressEnv = [GOV1ADDR, GOV2ADDR, GOV3ADDR].filter(x => x);
const ORACLE_ADDRESSES = governanceAddressEnv.length
? governanceAddressEnv
: DEFAULT_ORACLE_ADDRESSES;

return strictPriceFeedProposalBuilder(powers, {
...options,
ORACLE_ADDRESSES,
});
};

/**
* @deprecated use `strictPriceFeedProposalBuilder` and specify arguments instead
* @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder}
*/
export const priceFeedProposalBuilder = deprecatedPriceFeedProposalBuilder;

0 comments on commit 95174a2

Please sign in to comment.