Skip to content

Commit

Permalink
refactor: extract price feed name helper
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 7, 2023
1 parent 10e19d7 commit daf56fc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
3 changes: 2 additions & 1 deletion packages/agoric-cli/src/commands/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Nat } from '@endo/nat';
import { Command } from 'commander';
import * as cp from 'child_process';
import { inspect } from 'util';
import { instanceNameFor } from '@agoric/inter-protocol/src/proposals/price-feed-proposal.js';
import { normalizeAddressWithOptions } from '../lib/chain.js';
import { getNetworkConfig, makeRpcUtils, storageHelper } from '../lib/rpc.js';
import {
Expand Down Expand Up @@ -75,7 +76,7 @@ export const makeOracleCommand = (logger, io = {}) => {
const utils = await makeRpcUtils({ fetch });

const lookupPriceAggregatorInstance = ([brandIn, brandOut]) => {
const name = `${brandIn}-${brandOut} price feed`;
const name = instanceNameFor(brandIn, brandOut);
const instance = utils.agoricNames.instance[name];
if (!instance) {
logger.debug('known instances:', utils.agoricNames.instance);
Expand Down
4 changes: 2 additions & 2 deletions packages/inter-protocol/src/proposals/addAssetToVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Stable } from '@agoric/vats/src/tokens.js';
import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
import { parseRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
import { E } from '@endo/far';
import { instanceNameFor } from './price-feed-proposal.js';
import { reserveThenGetNames } from './utils.js';

export * from './startPSM.js';
Expand Down Expand Up @@ -240,8 +241,7 @@ export const addAssetToVault = async (
[keyword],
);

// XXX copied from price-feed-proposal
const oracleInstanceName = `${oracleBrand}-USD price feed`;
const oracleInstanceName = instanceNameFor(oracleBrand, 'USD');
// don't add the collateral offering to vaultFactory until its price feed is available
// eslint-disable-next-line no-restricted-syntax -- allow this computed property
await consumeInstance[oracleInstanceName];
Expand Down
5 changes: 4 additions & 1 deletion packages/inter-protocol/src/proposals/price-feed-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const sanitizePathSegment = name => {
return candidate;
};

export const instanceNameFor = (inBrandName, outBrandName) =>
`${inBrandName}-${outBrandName} price feed`;

/**
* @typedef {{
* brandIn?: ERef<Brand<'nat'> | undefined>,
Expand Down Expand Up @@ -314,7 +317,7 @@ export const startPriceFeeds = async (
{
options: {
priceFeedOptions: {
AGORIC_INSTANCE_NAME: `${inBrandName}-${outBrandName} price feed`,
AGORIC_INSTANCE_NAME: instanceNameFor(inBrandName, outBrandName),
contractTerms: {
minSubmissionCount: 2,
minSubmissionValue: 1,
Expand Down
7 changes: 5 additions & 2 deletions packages/inter-protocol/test/smartWallet/contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
import { heapZone } from '@agoric/zone';
import { E } from '@endo/far';
import path from 'path';
import { createPriceFeed } from '../../src/proposals/price-feed-proposal.js';
import {
createPriceFeed,
instanceNameFor,
} from '../../src/proposals/price-feed-proposal.js';
import { withAmountUtils } from '../supports.js';

// referenced by TS
Expand Down Expand Up @@ -169,7 +172,7 @@ export const makeDefaultTestContext = async (t, makeSpace) => {
{
options: {
priceFeedOptions: {
AGORIC_INSTANCE_NAME: `${inBrandName}-${outBrandName} price feed`,
AGORIC_INSTANCE_NAME: instanceNameFor(inBrandName, outBrandName),
contractTerms: {
minSubmissionCount: 2,
minSubmissionValue: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import '@agoric/vats/src/core/types.js';
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { NonNullish } from '@agoric/assert';
import { coalesceUpdates } from '@agoric/smart-wallet/src/utils.js';
import { AssetKind, makeIssuerKit } from '@agoric/ertp';
import { zip } from '@agoric/internal';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { coalesceUpdates } from '@agoric/smart-wallet/src/utils.js';
import { TimeMath } from '@agoric/time';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { E } from '@endo/far';
import { zip } from '@agoric/internal';
import { AssetKind, makeIssuerKit } from '@agoric/ertp';
import { buildRootObject } from './boot-psm.js';
import { INVITATION_MAKERS_DESC as EC_INVITATION_MAKERS_DESC } from '../../src/econCommitteeCharter.js';
import { INVITATION_MAKERS_DESC as ORACLE_INVITATION_MAKERS_DESC } from '../../src/price/fluxAggregatorKit.js';
import { instanceNameFor } from '../../src/proposals/price-feed-proposal.js';
import { headValue } from '../supports.js';
import { buildRootObject } from './boot-psm.js';
import {
currentPurseBalance,
importBootTestUtils,
Expand Down Expand Up @@ -122,7 +123,7 @@ const setupFeedWithWallets = async (t, oracleAddresses) => {
/** @type {import('@agoric/zoe/src/zoeService/utils.js').Instance<import('@agoric/inter-protocol/src/price/fluxAggregatorContract.js').prepare>} */
const governedPriceAggregator = await E(agoricNames).lookup(
'instance',
'ATOM-USD price feed',
instanceNameFor('ATOM', 'USD'),
);

return { oracleWallets, governedPriceAggregator };
Expand Down Expand Up @@ -464,7 +465,10 @@ test.serial('govern oracles list', async t => {
t.is(usedInvitations.get('acceptVoterOID')?.value[0].description, 'Voter0');
}

const feed = await E(agoricNames).lookup('instance', 'ATOM-USD price feed');
const feed = await E(agoricNames).lookup(
'instance',
instanceNameFor('ATOM', 'USD'),
);
t.assert(feed);

// Call for a vote to addOracles ////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion packages/vats/test/bootstrapTests/drivers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import { SECONDS_PER_MINUTE } from '@agoric/inter-protocol/src/proposals/econ-behaviors.js';
import { unmarshalFromVstorage } from '@agoric/internal/src/lib-chainStorage.js';
import { slotToRemotable } from '@agoric/internal/src/storage-test-utils.js';
import { instanceNameFor } from '@agoric/inter-protocol/src/proposals/price-feed-proposal.js';
import { boardSlottingMarshaller } from '../../tools/board-utils.js';

/**
Expand Down Expand Up @@ -156,7 +157,7 @@ export const makePriceFeedDriver = async (
oracleAddresses,
) => {
// XXX assumes this one feed
const priceFeedName = 'ATOM-USD price feed';
const priceFeedName = instanceNameFor('ATOM', 'USD');

const oracleWallets = await Promise.all(
oracleAddresses.map(addr => walletFactoryDriver.provideSmartWallet(addr)),
Expand Down

0 comments on commit daf56fc

Please sign in to comment.