Skip to content

Commit

Permalink
test(bootstrap): liq after add-collateral
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 7, 2023
1 parent c711453 commit 247970e
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 87 deletions.
1 change: 1 addition & 0 deletions packages/inter-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts": {
"build": "yarn build:bundles",
"build:bundles": "node ./scripts/build-bundles.js",
"build:add-STARS-proposal": "agoric run scripts/add-STARS.js",
"test": "ava",
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
"test:xs": "exit 0",
Expand Down
43 changes: 43 additions & 0 deletions packages/inter-protocol/scripts/add-STARS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { makeHelpers } from '@agoric/deploy-script-support';
import { defaultProposalBuilder as vaultProposalBuilder } from './add-collateral-core.js';
import { defaultProposalBuilder as oraclesProposalBuilder } from './price-feed-core.js';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const starsVaultProposalBuilder = async powers => {
return vaultProposalBuilder(powers, {
interchainAssetOptions: {
// Values for the Stargaze token on Osmosis
denom:
'ibc/987C17B11ABC2B20019178ACE62929FE9840202CE79498E29FE8E5CB02B7C0A4',
decimalPlaces: 6,
keyword: 'STARS',
oracleBrand: 'STARS',
proposedName: 'STARS',
},
});
};

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const starsOraclesProposalBuilder = async powers => {
return oraclesProposalBuilder(powers, {
AGORIC_INSTANCE_NAME: `STARS-USD price feed`,
IN_BRAND_LOOKUP: ['agoricNames', 'oracleBrand', 'STARS'],
IN_BRAND_DECIMALS: 6,
OUT_BRAND_LOOKUP: ['agoricNames', 'oracleBrand', 'USD'],
OUT_BRAND_DECIMALS: 4,
oracleAddresses: [
// copied from decentral-main-vaults-config.json
'agoric1krunjcqfrf7la48zrvdfeeqtls5r00ep68mzkr',
'agoric19uscwxdac6cf6z7d5e26e0jm0lgwstc47cpll8',
'agoric144rrhh4m09mh7aaffhm6xy223ym76gve2x7y78',
'agoric19d6gnr9fyp6hev4tlrg87zjrzsd5gzr5qlfq2p',
'agoric1n4fcxsnkxe4gj6e24naec99hzmc4pjfdccy5nj',
],
});
};

export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('add-STARS', starsVaultProposalBuilder);
await writeCoreProposal('add-STARS-oracles', starsOraclesProposalBuilder);
};
1 change: 1 addition & 0 deletions packages/vats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build:boot-viz-sim": "node src/authorityViz.js --sim-chain >docs/boot-sim.dot && dot -Tsvg docs/boot-sim.dot >docs/boot-sim.dot.svg",
"build:boot-viz-sim-gov": "node src/authorityViz.js --sim-chain --gov >docs/boot-sim-gov.dot && dot -Tsvg docs/boot-sim-gov.dot >docs/boot-sim-gov.dot.svg",
"build:restart-vats-proposal": "agoric run scripts/restart-vats.js",
"build:add-STARS-proposal": "agoric run scripts/add-STARS.js",
"prepack": "tsc --build jsconfig.build.json",
"postpack": "git clean -f '*.d.ts*'",
"test": "ava",
Expand Down
12 changes: 6 additions & 6 deletions packages/vats/test/bootstrapTests/drivers.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,28 @@ export const makeWalletFactoryDriver = async (
};

/**
* @param {import('@agoric/internal/src/storage-test-utils.js').FakeStorageKit} storage
* @param {string} collateralBrandKey
* @param {import('../../tools/board-utils.js').AgoricNamesRemotes} agoricNamesRemotes
* @param {Awaited<ReturnType<typeof makeWalletFactoryDriver>>} walletFactoryDriver
* @param {string[]} oracleAddresses
*/
export const makePriceFeedDriver = async (
storage,
collateralBrandKey,
agoricNamesRemotes,
walletFactoryDriver,
oracleAddresses,
) => {
// XXX assumes this one feed
const priceFeedName = instanceNameFor('ATOM', 'USD');
const priceFeedName = instanceNameFor(collateralBrandKey, 'USD');

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

const priceFeedInstance = agoricNamesRemotes.instance[priceFeedName];
const adminOfferId = 'acceptOracleInvitation';
priceFeedInstance || Fail`no price feed ${priceFeedName}`;
const adminOfferId = `accept-${collateralBrandKey}-oracleInvitation`;

// accept invitations (TODO move into driver)
// accept invitations
await Promise.all(
oracleWallets.map(w =>
w.executeOffer({
Expand Down
71 changes: 48 additions & 23 deletions packages/vats/test/bootstrapTests/liquidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ export const makeLiquidationTestContext = async t => {
console.timeLog('DefaultTestContext', 'vaultFactoryKit');

// has to be late enough for agoricNames data to have been published
const agoricNamesRemotes = makeAgoricNamesRemotesFromFakeStorage(
swingsetTestKit.storage,
);
/** @type {import('../../tools/board-utils.js').AgoricNamesRemotes} */
const agoricNamesRemotes = {};
const refreshAgoricNamesRemotes = () => {
Object.assign(
agoricNamesRemotes,
makeAgoricNamesRemotesFromFakeStorage(swingsetTestKit.storage),
);
};
refreshAgoricNamesRemotes();
agoricNamesRemotes.brand.ATOM || Fail`ATOM missing from agoricNames`;
console.timeLog('DefaultTestContext', 'agoricNamesRemotes');

Expand All @@ -65,30 +71,43 @@ export const makeLiquidationTestContext = async t => {
);
console.timeLog('DefaultTestContext', 'governanceDriver');

const priceFeedDriver = await makePriceFeedDriver(
storage,
agoricNamesRemotes,
walletFactoryDriver,
// TODO read from the config file
[
'agoric1krunjcqfrf7la48zrvdfeeqtls5r00ep68mzkr',
'agoric19uscwxdac6cf6z7d5e26e0jm0lgwstc47cpll8',
'agoric144rrhh4m09mh7aaffhm6xy223ym76gve2x7y78',
'agoric19d6gnr9fyp6hev4tlrg87zjrzsd5gzr5qlfq2p',
'agoric1n4fcxsnkxe4gj6e24naec99hzmc4pjfdccy5nj',
],
);
/** @type {Record<string, Awaited<ReturnType<typeof makePriceFeedDriver>>>} */
const priceFeedDrivers = {};

console.timeLog('DefaultTestContext', 'priceFeedDriver');

console.timeEnd('DefaultTestContext');

const setupStartingState = async () => {
/**
*
* @param {object} opts
* @param {string} opts.collateralBrandKey
* @param {number} opts.managerIndex
*/
const setupStartingState = async ({ collateralBrandKey, managerIndex }) => {
const managerPath = `published.vaultFactory.managers.manager${managerIndex}`;
const { advanceTimeBy, readLatest } = swingsetTestKit;

!priceFeedDrivers[collateralBrandKey] ||
Fail`setup for ${collateralBrandKey} already ran`;
priceFeedDrivers[collateralBrandKey] = await makePriceFeedDriver(
collateralBrandKey,
agoricNamesRemotes,
walletFactoryDriver,
// TODO read from the config file
[
'agoric1krunjcqfrf7la48zrvdfeeqtls5r00ep68mzkr',
'agoric19uscwxdac6cf6z7d5e26e0jm0lgwstc47cpll8',
'agoric144rrhh4m09mh7aaffhm6xy223ym76gve2x7y78',
'agoric19d6gnr9fyp6hev4tlrg87zjrzsd5gzr5qlfq2p',
'agoric1n4fcxsnkxe4gj6e24naec99hzmc4pjfdccy5nj',
],
);

// price feed logic treats zero time as "unset" so advance to nonzero
await advanceTimeBy(1, 'seconds');

await priceFeedDriver.setPrice(12.34);
await priceFeedDrivers[collateralBrandKey].setPrice(12.34);

// raise the VaultFactory DebtLimit
await governanceDriver.changeParams(
Expand All @@ -102,7 +121,7 @@ export const makeLiquidationTestContext = async t => {
{
paramPath: {
key: {
collateralBrand: agoricNamesRemotes.brand.ATOM,
collateralBrand: agoricNamesRemotes.brand[collateralBrandKey],
},
},
},
Expand All @@ -120,7 +139,7 @@ export const makeLiquidationTestContext = async t => {
);

// confirm Relevant Governance Parameter Assumptions
t.like(readLatest('published.vaultFactory.managers.manager0.governance'), {
t.like(readLatest(`${managerPath}.governance`), {
current: {
DebtLimit: { value: { value: DebtLimitValue } },
InterestRate: {
Expand Down Expand Up @@ -168,11 +187,16 @@ export const makeLiquidationTestContext = async t => {
};

const check = {
vaultNotification(vaultIndex, partial) {
/**
* @param {number} managerIndex
* @param {number} vaultIndex
* @param {Record<string, any>} partial
*/
vaultNotification(managerIndex, vaultIndex, partial) {
const { readLatest } = swingsetTestKit;

const notification = readLatest(
`published.vaultFactory.managers.manager0.vaults.vault${vaultIndex}`,
`published.vaultFactory.managers.manager${managerIndex}.vaults.vault${vaultIndex}`,
);
t.like(notification, partial);
},
Expand All @@ -183,7 +207,8 @@ export const makeLiquidationTestContext = async t => {
agoricNamesRemotes,
check,
governanceDriver,
priceFeedDriver,
priceFeedDrivers,
refreshAgoricNamesRemotes,
setupStartingState,
walletFactoryDriver,
};
Expand Down
Loading

0 comments on commit 247970e

Please sign in to comment.