diff --git a/.github/workflows/test-all-packages.yml b/.github/workflows/test-all-packages.yml index 7f807674141c..ef62c05876df 100644 --- a/.github/workflows/test-all-packages.yml +++ b/.github/workflows/test-all-packages.yml @@ -242,8 +242,8 @@ jobs: # END-TEST-BOILERPLATE - name: yarn test (cosmos) run: cd golang/cosmos && yarn test - - name: yarn test (treasury) - run: cd packages/treasury && yarn test + - name: yarn test (run-protocol) + run: cd packages/run-protocol && yarn test - name: yarn test (pegasus) run: cd packages/pegasus && yarn test - name: yarn test (vats) diff --git a/package.json b/package.json index 7e2dc4cc041b..d1963ce8615d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "packages/wallet", "packages/wallet/api", "packages/wallet/ui", - "packages/treasury", + "packages/run-protocol", "packages/pegasus", "packages/cosmic-swingset", "packages/agoric-cli", diff --git a/packages/SwingSet/misc-tools/measure-metering/measure.js b/packages/SwingSet/misc-tools/measure-metering/measure.js index 628eded34bf2..c6c6369bfed2 100644 --- a/packages/SwingSet/misc-tools/measure-metering/measure.js +++ b/packages/SwingSet/misc-tools/measure-metering/measure.js @@ -47,7 +47,7 @@ async function run() { const bootFn = new URL('measurement-bootstrap.js', import.meta.url).pathname; const targetFn = new URL('measurement-target.js', import.meta.url).pathname; const zoeFn = new URL('measurement-zoe.js', import.meta.url).pathname; - // const treasuryFn = new URL('measurement-zoe.js', import.meta.url).pathname; + // const vaultFactoryFn = new URL('measurement-zoe.js', import.meta.url).pathname; const autoswapFn = new URL( '../../../zoe/src/contracts/vpool-xyk-amm/multipoolMarketMaker.js', import.meta.url, @@ -134,8 +134,8 @@ async function run() { const counted = p.counted(); return Number(counted); } - const zoeInstallTreasury = await doCounted('zoeInstallTreasury'); - console.log(`zoe install (treasury): ${zoeInstallTreasury}`); + const zoeInstallVaultFactory = await doCounted('zoeInstallVaultFactory'); + console.log(`zoe install (vaultFactory): ${zoeInstallVaultFactory}`); const zoeInstallAMM = await doCounted('zoeInstallBundle', [autoswapBundle]); console.log(`zoe install (AMM): ${zoeInstallAMM}`); diff --git a/packages/SwingSet/misc-tools/measure-metering/measurement-bootstrap.js b/packages/SwingSet/misc-tools/measure-metering/measurement-bootstrap.js index 1c1d70141970..f1b2e6c80f7d 100644 --- a/packages/SwingSet/misc-tools/measure-metering/measurement-bootstrap.js +++ b/packages/SwingSet/misc-tools/measure-metering/measurement-bootstrap.js @@ -1,7 +1,7 @@ /* eslint-disable import/no-extraneous-dependencies,no-unused-vars,no-empty-function */ import { E } from '@agoric/eventual-send'; import { Far } from '@agoric/marshal'; -import stablecoinBundle from '@agoric/treasury/bundles/bundle-stablecoinMachine.js'; +import vaultFactoryBundle from '@agoric/run-protocol/bundles/bundle-vaultFactory.js'; import { makeIssuerKit, AmountMath } from '@agoric/ertp'; export function buildRootObject() { @@ -30,8 +30,8 @@ export function buildRootObject() { return Number(start.remaining - finish.remaining); }, - async zoeInstallTreasury() { - installation = await E(zoe).install(stablecoinBundle); + async zoeInstallVaultFactory() { + installation = await E(zoe).install(vaultFactoryBundle); }, async zoeInstallBundle(bundle) { installation = await E(zoe).install(bundle); diff --git a/packages/SwingSet/misc-tools/vat-map.py b/packages/SwingSet/misc-tools/vat-map.py index 8cec3edfa3bf..070a80c89832 100644 --- a/packages/SwingSet/misc-tools/vat-map.py +++ b/packages/SwingSet/misc-tools/vat-map.py @@ -9,7 +9,7 @@ # description on each vat. Static vats get a name from their bundle, e.g. # "bank" or "mints" or "zoe". Dynamic contract vats find the agoric-sdk # -relative filename of the entry point of the contract, e.g. -# "packages/treasury/src/stablecointMachine.js", and emit an abbreviation +# "packages/run-protocol/src/vaultFactory.js", and emit an abbreviation # (for known contracts) or the full string. unknown_vats = set() # vatID @@ -17,10 +17,10 @@ unnamed_zcf_vats = set() abbreviations = { - "packages/treasury/src/stablecoinMachine.js": "treasury", + "packages/run-protocol/src/vaultFactory.js": "vaultFactory", "packages/pegasus/src/pegasus.js": "pegasus", "packages/zoe/src/contracts/multipoolAutoswap/multipoolAutoswap.js": "amm", - "packages/treasury/src/liquidateMinimum.js": "liquidate", + "packages/run-protocol/src/liquidateMinimum.js": "liquidate", } EPRE = re.compile(r'const entrypoint = "([^"]+)"') diff --git a/packages/treasury/CHANGELOG.md b/packages/run-protocol/CHANGELOG.md similarity index 100% rename from packages/treasury/CHANGELOG.md rename to packages/run-protocol/CHANGELOG.md diff --git a/packages/treasury/NEWS.md b/packages/run-protocol/NEWS.md similarity index 100% rename from packages/treasury/NEWS.md rename to packages/run-protocol/NEWS.md diff --git a/packages/treasury/bundles/install-on-chain.js b/packages/run-protocol/bundles/install-on-chain.js similarity index 87% rename from packages/treasury/bundles/install-on-chain.js rename to packages/run-protocol/bundles/install-on-chain.js index 37f1a511aef1..764e125708b1 100644 --- a/packages/treasury/bundles/install-on-chain.js +++ b/packages/run-protocol/bundles/install-on-chain.js @@ -14,11 +14,11 @@ import { makeRatio } from '@agoric/zoe/src/contractSupport'; import liquidateBundle from './bundle-liquidateMinimum.js'; import ammBundle from './bundle-amm.js'; -import stablecoinBundle from './bundle-stablecoinMachine.js'; +import vaultFactoryBundle from './bundle-vaultFactory.js'; import contractGovernorBundle from './bundle-contractGovernor.js'; import noActionElectorateBundle from './bundle-noActionElectorate.js'; import binaryVoteCounterBundle from './bundle-binaryVoteCounter.js'; -import { makeGovernedTerms } from '../src/params.js'; +import { makeGovernedTerms } from '../src/vaultFactory/params.js'; const SECONDS_PER_HOUR = 60n * 60n; const SECONDS_PER_DAY = 24n * SECONDS_PER_HOUR; @@ -169,7 +169,7 @@ export async function installOnChain({ const nameBundles = [ ['liquidate', liquidateBundle], ['amm', ammBundle], - ['stablecoin', stablecoinBundle], + ['vaultFactory', vaultFactoryBundle], ['contractGovernor', contractGovernorBundle], ['noActionElectorate', noActionElectorateBundle], ['binaryCounter', binaryVoteCounterBundle], @@ -178,7 +178,7 @@ export async function installOnChain({ const [ liquidationInstall, ammInstall, - stablecoinMachineInstall, + vaultFactoryInstall, contractGovernorInstall, noActionElectorateInstall, binaryCounterInstall, @@ -194,7 +194,7 @@ export async function installOnChain({ ); // The Electorate is a no-action electorate, so the testNet runs without - // anyone having the ability to change the treasury's parameters. + // anyone having the ability to change the vaultFactory's parameters. const { creatorFacet: electorateCreatorFacet, instance: electorateInstance, @@ -228,7 +228,7 @@ export async function installOnChain({ E(centralIssuerP).getBrand(), ]); - // declare governed params for the treasury; addVaultType() sets actual rates + // declare governed params for the vaultFactory; addVaultType() sets actual rates const rates = { initialMargin: makeRatio(120n, centralBrand), liquidationMargin: makeRatio(105n, centralBrand), @@ -236,7 +236,7 @@ export async function installOnChain({ loanFee: makeRatio(200n, centralBrand, BASIS_POINTS), } - const treasuryTerms = makeGovernedTerms( + const vaultFactoryTerms = makeGovernedTerms( priceAuthority, loanParams, liquidationInstall, @@ -249,9 +249,9 @@ export async function installOnChain({ const governorTerms = harden({ timer: chainTimerService, electorateInstance, - governedContractInstallation: stablecoinMachineInstall, + governedContractInstallation: vaultFactoryInstall, governed: { - terms: treasuryTerms, + terms: vaultFactoryTerms, issuerKeywordRecord: {}, privateArgs: harden({ feeMintAccess, initialPoserInvitation }), }, @@ -266,22 +266,22 @@ export async function installOnChain({ harden({ electorateCreatorFacet }), ); - const treasuryInstance = await E(governorCreatorFacet).getInstance(); + const vaultFactoryInstance = await E(governorCreatorFacet).getInstance(); const [ invitationIssuer, { issuers: { Governance: govIssuer }, brands: { Governance: govBrand }, }, - treasuryCreator, + vaultFactoryCreator, ] = await Promise.all([ E(zoeWPurse).getInvitationIssuer(), - E(zoeWPurse).getTerms(treasuryInstance), + E(zoeWPurse).getTerms(vaultFactoryInstance), E(governorCreatorFacet).getCreatorFacet() ]); - const treasuryUiDefaults = { - CONTRACT_NAME: 'Treasury', + const vaultFactoryUiDefaults = { + CONTRACT_NAME: 'VaultFactory', AMM_NAME: 'amm', BRIDGE_URL: 'http://127.0.0.1:8000', // Avoid setting API_URL, so that the UI uses the same origin it came from, @@ -291,8 +291,8 @@ export async function installOnChain({ // Look up all the board IDs. const boardIdValue = [ - ['INSTANCE_BOARD_ID', treasuryInstance], - ['INSTALLATION_BOARD_ID', stablecoinMachineInstall], + ['INSTANCE_BOARD_ID', vaultFactoryInstance], + ['INSTALLATION_BOARD_ID', vaultFactoryInstall], ['RUN_ISSUER_BOARD_ID', centralIssuer], ['RUN_BRAND_BOARD_ID', centralBrand], ['AMM_INSTALLATION_BOARD_ID', ammInstall], @@ -307,18 +307,18 @@ export async function installOnChain({ boardIdValue.map(async ([key, valP]) => { const val = await valP; const boardId = await E(board).getId(val); - treasuryUiDefaults[key] = boardId; + vaultFactoryUiDefaults[key] = boardId; }), ); // Stash the defaults where the UI can find them. - harden(treasuryUiDefaults); + harden(vaultFactoryUiDefaults); // Install the names in agoricNames. const nameAdminUpdates = [ - [uiConfigAdmin, treasuryUiDefaults.CONTRACT_NAME, treasuryUiDefaults], - [instanceAdmin, treasuryUiDefaults.CONTRACT_NAME, treasuryInstance], - [instanceAdmin, treasuryUiDefaults.AMM_NAME, amm.governedInstance], + [uiConfigAdmin, vaultFactoryUiDefaults.CONTRACT_NAME, vaultFactoryUiDefaults], + [instanceAdmin, vaultFactoryUiDefaults.CONTRACT_NAME, vaultFactoryInstance], + [instanceAdmin, vaultFactoryUiDefaults.AMM_NAME, amm.governedInstance], [brandAdmin, centralName, centralBrand], [issuerAdmin, centralName, centralIssuer], ]; @@ -328,9 +328,9 @@ export async function installOnChain({ ), ); - const voteCreator = Far('treasury vote creator', { + const voteCreator = Far('vaultFactory vote creator', { voteOnParamChange: E(governorCreatorFacet).voteOnParamChange, }); - return { treasuryCreator, voteCreator, ammFacets: amm }; + return { vaultFactoryCreator, voteCreator, ammFacets: amm }; } diff --git a/packages/run-protocol/exported.js b/packages/run-protocol/exported.js new file mode 100644 index 000000000000..db353234f386 --- /dev/null +++ b/packages/run-protocol/exported.js @@ -0,0 +1 @@ +import './src/vaultFactory/types.js'; diff --git a/packages/treasury/globals.d.ts b/packages/run-protocol/globals.d.ts similarity index 100% rename from packages/treasury/globals.d.ts rename to packages/run-protocol/globals.d.ts diff --git a/packages/treasury/jsconfig.json b/packages/run-protocol/jsconfig.json similarity index 100% rename from packages/treasury/jsconfig.json rename to packages/run-protocol/jsconfig.json diff --git a/packages/treasury/package.json b/packages/run-protocol/package.json similarity index 96% rename from packages/treasury/package.json rename to packages/run-protocol/package.json index 6faf15c82ef8..c00756e46b56 100644 --- a/packages/treasury/package.json +++ b/packages/run-protocol/package.json @@ -1,9 +1,9 @@ { - "name": "@agoric/treasury", + "name": "@agoric/run-protocol", "version": "0.7.0", "description": "Core cryptoeconomy contracts", "type": "module", - "main": "src/stablecoinMachine.js", + "main": "src/vaultFactory/vaultFactory.js", "engines": { "node": ">=11.0" }, diff --git a/packages/treasury/scripts/build-bundles.js b/packages/run-protocol/scripts/build-bundles.js similarity index 93% rename from packages/treasury/scripts/build-bundles.js rename to packages/run-protocol/scripts/build-bundles.js index 3ffa35f1b057..63638e492157 100644 --- a/packages/treasury/scripts/build-bundles.js +++ b/packages/run-protocol/scripts/build-bundles.js @@ -31,11 +31,11 @@ async function writeSourceBundle(contractFilename, outputPath) { async function main() { const contractOutputs = [ [ - `${srcDir}/stablecoinMachine.js`, - `${bundlesDir}/bundle-stablecoinMachine.js`, + `${srcDir}/vaultFactory/vaultFactory.js`, + `${bundlesDir}/bundle-vaultFactory.js`, ], [ - `${srcDir}/liquidateMinimum.js`, + `${srcDir}/vaultFactory/liquidateMinimum.js`, `${bundlesDir}/bundle-liquidateMinimum.js`, ], [ diff --git a/packages/run-protocol/src/exported.js b/packages/run-protocol/src/exported.js new file mode 100644 index 000000000000..f5811b591624 --- /dev/null +++ b/packages/run-protocol/src/exported.js @@ -0,0 +1,2 @@ +import './vpool-xyk-amm/types.js'; +import './vaultFactory/types.js'; diff --git a/packages/treasury/src/makeTracer.js b/packages/run-protocol/src/makeTracer.js similarity index 100% rename from packages/treasury/src/makeTracer.js rename to packages/run-protocol/src/makeTracer.js diff --git a/packages/treasury/src/burn.js b/packages/run-protocol/src/vaultFactory/burn.js similarity index 100% rename from packages/treasury/src/burn.js rename to packages/run-protocol/src/vaultFactory/burn.js diff --git a/packages/treasury/src/collectRewardFees.js b/packages/run-protocol/src/vaultFactory/collectRewardFees.js similarity index 100% rename from packages/treasury/src/collectRewardFees.js rename to packages/run-protocol/src/vaultFactory/collectRewardFees.js diff --git a/packages/treasury/src/interest.js b/packages/run-protocol/src/vaultFactory/interest.js similarity index 100% rename from packages/treasury/src/interest.js rename to packages/run-protocol/src/vaultFactory/interest.js diff --git a/packages/treasury/src/liquidateMinimum.js b/packages/run-protocol/src/vaultFactory/liquidateMinimum.js similarity index 98% rename from packages/treasury/src/liquidateMinimum.js rename to packages/run-protocol/src/vaultFactory/liquidateMinimum.js index 82c614719d16..7b942a5fb4cb 100644 --- a/packages/treasury/src/liquidateMinimum.js +++ b/packages/run-protocol/src/vaultFactory/liquidateMinimum.js @@ -6,7 +6,7 @@ import { AmountMath } from '@agoric/ertp'; import { Far } from '@agoric/marshal'; import { makeDefaultLiquidationStrategy } from './liquidation.js'; -import { makeTracer } from './makeTracer.js'; +import { makeTracer } from '../makeTracer.js'; const trace = makeTracer('LM'); diff --git a/packages/treasury/src/liquidation.js b/packages/run-protocol/src/vaultFactory/liquidation.js similarity index 97% rename from packages/treasury/src/liquidation.js rename to packages/run-protocol/src/vaultFactory/liquidation.js index c9cca4b67609..48bebef894bd 100644 --- a/packages/treasury/src/liquidation.js +++ b/packages/run-protocol/src/vaultFactory/liquidation.js @@ -3,7 +3,7 @@ import { E } from '@agoric/eventual-send'; import { AmountMath } from '@agoric/ertp'; import { offerTo } from '@agoric/zoe/src/contractSupport/index.js'; -import { makeTracer } from './makeTracer.js'; +import { makeTracer } from '../makeTracer.js'; const trace = makeTracer('LIQ'); @@ -15,7 +15,7 @@ const trace = makeTracer('LIQ'); * Once collateral has been sold using the contract, we burn the amount * necessary to cover the debt and return the remainder. * - * @type {TreasuryLiquidate} + * @type {VaultFactoryLiquidate} */ const liquidate = async ( zcf, diff --git a/packages/treasury/src/params.js b/packages/run-protocol/src/vaultFactory/params.js similarity index 100% rename from packages/treasury/src/params.js rename to packages/run-protocol/src/vaultFactory/params.js diff --git a/packages/treasury/src/prioritizedVaults.js b/packages/run-protocol/src/vaultFactory/prioritizedVaults.js similarity index 100% rename from packages/treasury/src/prioritizedVaults.js rename to packages/run-protocol/src/vaultFactory/prioritizedVaults.js diff --git a/packages/treasury/src/type-imports.js b/packages/run-protocol/src/vaultFactory/type-imports.js similarity index 100% rename from packages/treasury/src/type-imports.js rename to packages/run-protocol/src/vaultFactory/type-imports.js diff --git a/packages/treasury/src/types.js b/packages/run-protocol/src/vaultFactory/types.js similarity index 97% rename from packages/treasury/src/types.js rename to packages/run-protocol/src/vaultFactory/types.js index 021f1a335208..2498278cbd36 100644 --- a/packages/treasury/src/types.js +++ b/packages/run-protocol/src/vaultFactory/types.js @@ -47,7 +47,7 @@ */ /** - * @typedef {Object} StablecoinMachine - the creator facet + * @typedef {Object} VaultFactory - the creator facet * @property {AddVaultType} addVaultType * @property {() => Promise>} getCollaterals * @property {() => Allocation} getRewardAllocation, @@ -69,7 +69,7 @@ /** * @callback ReallocateReward * - * Transfer the indicated amount to the stablecoin machine's reward + * Transfer the indicated amount to the vaultFactory's reward * pool, taken from the `fromSeat`. Then reallocate over all the seat * arguments and the rewardPoolSeat. * @@ -268,7 +268,7 @@ */ /** - * @callback TreasuryLiquidate + * @callback VaultFactoryLiquidate * @param {ContractFacet} zcf * @param {VaultKit} vaultKit * @param {(losses: AmountKeywordRecord, @@ -292,7 +292,7 @@ */ /** - * @typedef {Object} GovernedTreasuryTerms + * @typedef {Object} GovernedVaultFactoryTerms * @property {XYKAMMPublicFacet} ammPublicFacet * @property {ERef} priceAuthority * @property {Record} loanParams @@ -312,5 +312,5 @@ * @param {Rates} rates * @param {XYKAMMPublicFacet} ammPublicFacet * @param {bigint=} bootstrapPaymentValue - * @returns {GovernedTreasuryTerms} + * @returns {GovernedVaultFactoryTerms} */ diff --git a/packages/treasury/src/vault.js b/packages/run-protocol/src/vaultFactory/vault.js similarity index 100% rename from packages/treasury/src/vault.js rename to packages/run-protocol/src/vaultFactory/vault.js diff --git a/packages/treasury/src/stablecoinMachine.js b/packages/run-protocol/src/vaultFactory/vaultFactory.js similarity index 95% rename from packages/treasury/src/stablecoinMachine.js rename to packages/run-protocol/src/vaultFactory/vaultFactory.js index e4deefc93977..eecd28d794b8 100644 --- a/packages/treasury/src/stablecoinMachine.js +++ b/packages/run-protocol/src/vaultFactory/vaultFactory.js @@ -3,8 +3,7 @@ import '@agoric/zoe/exported.js'; import '@agoric/zoe/src/contracts/exported.js'; -// The StableCoinMachine owns a number of VaultManagers, and a mint for the -// "RUN" stablecoin. +// The vaultFactory owns a number of VaultManagers and a mint for RUN. // // addVaultType is a closely held method that adds a brand new collateral type. // It specifies the initial exchange rate for that type. It depends on a @@ -259,7 +258,7 @@ export const start = async (zcf, privateArgs) => { }; /** @type {StablecoinPublicFacet} */ - const publicFacet = Far('stablecoin public facet', { + const publicFacet = Far('vaultFactory public facet', { makeLoanInvitation, getCollaterals, getRunIssuer: () => runIssuer, @@ -287,8 +286,8 @@ export const start = async (zcf, privateArgs) => { }, }); - /** @type {StablecoinMachine} */ - const stablecoinMachine = Far('stablecoin machine', { + /** @type {VaultFactory} */ + const vaultFactory = Far('vaultFactory machine', { addVaultType, getCollaterals, getRewardAllocation, @@ -297,14 +296,14 @@ export const start = async (zcf, privateArgs) => { getContractGovernor: () => electionManager, }); - const stablecoinMachineWrapper = Far('powerful stablecoinMachine wrapper', { + const vaultFactoryWrapper = Far('powerful vaultFactory wrapper', { getParamMgrRetriever, getInvitation: electorateParamManager.getInternalParamValue, - getLimitedCreatorFacet: () => stablecoinMachine, + getLimitedCreatorFacet: () => vaultFactory, }); return harden({ - creatorFacet: stablecoinMachineWrapper, + creatorFacet: vaultFactoryWrapper, publicFacet, }); }; diff --git a/packages/treasury/src/vaultManager.js b/packages/run-protocol/src/vaultFactory/vaultManager.js similarity index 99% rename from packages/treasury/src/vaultManager.js rename to packages/run-protocol/src/vaultFactory/vaultManager.js index 526228a471c4..39285cf1af61 100644 --- a/packages/treasury/src/vaultManager.js +++ b/packages/run-protocol/src/vaultFactory/vaultManager.js @@ -18,7 +18,7 @@ import { Far } from '@agoric/marshal'; import { makeVaultKit } from './vault.js'; import { makePrioritizedVaults } from './prioritizedVaults.js'; import { liquidate } from './liquidation.js'; -import { makeTracer } from './makeTracer.js'; +import { makeTracer } from '../makeTracer.js'; import { RECORDING_PERIOD_KEY, LIQUIDATION_MARGIN_KEY, diff --git a/packages/treasury/test/faucet.js b/packages/run-protocol/test/faucet.js similarity index 96% rename from packages/treasury/test/faucet.js rename to packages/run-protocol/test/faucet.js index 2397c3f79679..f88af2b202e7 100644 --- a/packages/treasury/test/faucet.js +++ b/packages/run-protocol/test/faucet.js @@ -5,7 +5,7 @@ import { assertProposalShape } from '@agoric/zoe/src/contractSupport'; import { LOW_FEE, SHORT_EXP } from '@agoric/zoe/src/constants'; // A Faucet providing RUN so we can provide initial liquidity to the AMM so the -// Treasury can reliably liquidate. +// VaultFactory can reliably liquidate. /** @type {ContractStartFn} */ export async function start(zcf, privateArgs) { diff --git a/packages/treasury/test/mockAmm.js b/packages/run-protocol/test/mockAmm.js similarity index 100% rename from packages/treasury/test/mockAmm.js rename to packages/run-protocol/test/mockAmm.js diff --git a/packages/treasury/test/swingsetTests/governance/bootstrap.js b/packages/run-protocol/test/swingsetTests/governance/bootstrap.js similarity index 86% rename from packages/treasury/test/swingsetTests/governance/bootstrap.js rename to packages/run-protocol/test/swingsetTests/governance/bootstrap.js index 6f579170b531..66e622cff513 100644 --- a/packages/treasury/test/swingsetTests/governance/bootstrap.js +++ b/packages/run-protocol/test/swingsetTests/governance/bootstrap.js @@ -4,7 +4,7 @@ import { E } from '@agoric/eventual-send'; import { Far } from '@agoric/marshal'; import { makeRatio } from '@agoric/zoe/src/contractSupport'; -import { INTEREST_RATE_KEY } from '../../../src/params'; +import { INTEREST_RATE_KEY } from '../../../src/vaultFactory/params'; import { ONE_DAY, createCommittee, installContracts, makeVats } from '../setup'; const { quote: q } = assert; @@ -56,17 +56,22 @@ const setUpVote = async ( paramDesc, contracts, ) => { - const { treasury, installations, electorateInstance, governor } = contracts; + const { + vaultFactory, + installations, + electorateInstance, + governor, + } = contracts; const { details: feeDetails } = await E( - treasury.voteCreator, + vaultFactory.voteCreator, ).voteOnParamChange(paramDesc, newValue, installations.counter, deadline); await votersVote(feeDetails, votersP, votes); await oneVoterValidate( votersP, feeDetails, - treasury.instance, + vaultFactory.instance, electorateInstance, governor.instance, installations, @@ -89,7 +94,7 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => { const { aliceP, governor, - treasury, + vaultFactory, runBrand, timer, electorateCreatorFacet, @@ -107,12 +112,19 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => { const votersP = createCommittee(electorateCreatorFacet, voterCreator); log(`=> voter and electorate vats are set up`); - const feeParamsStateAnte = await E(treasury.publicFacet).getGovernedParams({ + const feeParamsStateAnte = await E( + vaultFactory.publicFacet, + ).getGovernedParams({ collateralBrand, }); log(`param values before ${q(feeParamsStateAnte)}`); - const contracts = { treasury, installations, electorateInstance, governor }; + const contracts = { + vaultFactory, + installations, + electorateInstance, + governor, + }; const votes = [0, 1, 1, 0, 0]; const interestRateParam = { @@ -132,7 +144,7 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => { .getOutcome() .then(async outcome => { const feeParamsStatePost = await E( - treasury.publicFacet, + vaultFactory.publicFacet, ).getGovernedParams(interestRateParam); log( `param values after vote on (${outcome.changeParam.parameterName}) ${q( @@ -146,7 +158,7 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => { await E(timer).tick(); await E(timer).tick(); - await E(aliceP).startTest(testName, treasury.publicFacet); + await E(aliceP).startTest(testName, vaultFactory.publicFacet); }; export function buildRootObject(vatPowers, vatParameters) { diff --git a/packages/treasury/test/swingsetTests/governance/test-governance.js b/packages/run-protocol/test/swingsetTests/governance/test-governance.js similarity index 94% rename from packages/treasury/test/swingsetTests/governance/test-governance.js rename to packages/run-protocol/test/swingsetTests/governance/test-governance.js index d48e5bd68694..8b7c2a5b8c9e 100644 --- a/packages/treasury/test/swingsetTests/governance/test-governance.js +++ b/packages/run-protocol/test/swingsetTests/governance/test-governance.js @@ -14,7 +14,7 @@ import path from 'path'; import liquidateBundle from '../../../bundles/bundle-liquidateMinimum.js'; import ammBundle from '../../../bundles/bundle-amm.js'; -import stablecoinBundle from '../../../bundles/bundle-stablecoinMachine.js'; +import vaultFactoryBundle from '../../../bundles/bundle-vaultFactory.js'; import contractGovernorBundle from '../../../bundles/bundle-contractGovernor.js'; import committeeBundle from '../../../bundles/bundle-committee.js'; import binaryVoteCounterBundle from '../../../bundles/bundle-binaryVoteCounter.js'; @@ -31,7 +31,7 @@ test.before(async t => { const nameToBundle = [ ['liquidateMinimum', liquidateBundle], ['amm', ammBundle], - ['treasury', stablecoinBundle], + ['vaultFactory', vaultFactoryBundle], ['committee', committeeBundle], ['contractGovernor', contractGovernorBundle], ['binaryVoteCounter', binaryVoteCounterBundle], @@ -72,8 +72,8 @@ async function main(t, argv) { return E(controller).dump(); } -const expectedTreasuryLog = [ - '=> alice and the treasury are set up', +const expectedVaultFactoryLog = [ + '=> alice and the vaultFactory are set up', '=> voter and electorate vats are set up', 'param values before {"ChargingPeriod":{"type":"nat","value":"[86400n]"},"InitialMargin":{"type":"ratio","value":{"denominator":{"brand":"[Alleged: RUN brand]","value":"[100n]"},"numerator":{"brand":"[Seen]","value":"[120n]"}}},"InterestRate":{"type":"ratio","value":{"denominator":{"brand":"[Seen]","value":"[10000n]"},"numerator":{"brand":"[Seen]","value":"[250n]"}}},"LiquidationMargin":{"type":"ratio","value":{"denominator":{"brand":"[Seen]","value":"[100n]"},"numerator":{"brand":"[Seen]","value":"[105n]"}}},"LoanFee":{"type":"ratio","value":{"denominator":{"brand":"[Seen]","value":"[10000n]"},"numerator":{"brand":"[Seen]","value":"[200n]"}}},"RecordingPeriod":{"type":"nat","value":"[86400n]"}}', 'Voter Bob cast a ballot for {"changeParam":{"collateralBrand":"[Alleged: moola brand]","parameterName":"InterestRate"},"proposedValue":{"denominator":{"brand":"[Alleged: RUN brand]","value":"[10000n]"},"numerator":{"brand":"[Seen]","value":"[500n]"}}}', @@ -89,8 +89,8 @@ const expectedTreasuryLog = [ 'Alice owes {"brand":"[Alleged: RUN brand]","value":"[510069n]"} after interest', ]; -test.serial('treasury', async t => { +test.serial('vaultFactory', async t => { const startingValues = [[100], [1000]]; const dump = await main(t, ['oneLoanWithInterest', startingValues]); - t.deepEqual(dump.log, expectedTreasuryLog); + t.deepEqual(dump.log, expectedVaultFactoryLog); }); diff --git a/packages/treasury/test/swingsetTests/governance/vat-alice.js b/packages/run-protocol/test/swingsetTests/governance/vat-alice.js similarity index 82% rename from packages/treasury/test/swingsetTests/governance/vat-alice.js rename to packages/run-protocol/test/swingsetTests/governance/vat-alice.js index 4b42b2d464bc..2625b965b259 100644 --- a/packages/treasury/test/swingsetTests/governance/vat-alice.js +++ b/packages/run-protocol/test/swingsetTests/governance/vat-alice.js @@ -10,14 +10,14 @@ const build = async (log, zoe, brands, payments, timer) => { const [moolaBrand] = brands; const [moolaPayment] = payments; - const oneLoanWithInterest = async treasury => { + const oneLoanWithInterest = async vaultFactory => { log(`=> alice.oneLoanWithInterest called`); - const runIssuer = await E(treasury).getRunIssuer(); + const runIssuer = await E(vaultFactory).getRunIssuer(); const runBrand = await E(runIssuer).getBrand(); const loanSeat = await E(zoe).offer( - E(treasury).makeLoanInvitation(), + E(vaultFactory).makeLoanInvitation(), harden({ give: { Collateral: AmountMath.make(moolaBrand, 100n) }, want: { RUN: AmountMath.make(runBrand, 500000n) }, @@ -34,10 +34,10 @@ const build = async (log, zoe, brands, payments, timer) => { }; return Far('build', { - startTest: async (testName, treasury) => { + startTest: async (testName, vaultFactory) => { switch (testName) { case 'oneLoanWithInterest': { - return oneLoanWithInterest(treasury); + return oneLoanWithInterest(vaultFactory); } default: { assert.fail(X`testName ${testName} not recognized`); diff --git a/packages/treasury/test/swingsetTests/governance/vat-owner.js b/packages/run-protocol/test/swingsetTests/governance/vat-owner.js similarity index 91% rename from packages/treasury/test/swingsetTests/governance/vat-owner.js rename to packages/run-protocol/test/swingsetTests/governance/vat-owner.js index 7484d8a40c8a..ae8637396768 100644 --- a/packages/treasury/test/swingsetTests/governance/vat-owner.js +++ b/packages/run-protocol/test/swingsetTests/governance/vat-owner.js @@ -3,7 +3,7 @@ import { Far } from '@agoric/marshal'; import { buildOwner } from '../setup.js'; -// Treasury owner +// VaultFactory owner export function buildRootObject(vatPowers) { return Far('root', { diff --git a/packages/treasury/test/swingsetTests/governance/vat-priceAuthority.js b/packages/run-protocol/test/swingsetTests/governance/vat-priceAuthority.js similarity index 100% rename from packages/treasury/test/swingsetTests/governance/vat-priceAuthority.js rename to packages/run-protocol/test/swingsetTests/governance/vat-priceAuthority.js diff --git a/packages/treasury/test/swingsetTests/governance/vat-voter.js b/packages/run-protocol/test/swingsetTests/governance/vat-voter.js similarity index 96% rename from packages/treasury/test/swingsetTests/governance/vat-voter.js rename to packages/run-protocol/test/swingsetTests/governance/vat-voter.js index 6446517958b0..0dbc4e2381c2 100644 --- a/packages/treasury/test/swingsetTests/governance/vat-voter.js +++ b/packages/run-protocol/test/swingsetTests/governance/vat-voter.js @@ -100,8 +100,8 @@ const build = async (log, zoe) => { X`electorate Installation should match`, ); assert( - governedInstallation === installations.treasury, - X`treasury Installation should match`, + governedInstallation === installations.vaultFactory, + X`vaultFactory Installation should match`, ); }, }); diff --git a/packages/treasury/test/swingsetTests/governance/vat-zoe.js b/packages/run-protocol/test/swingsetTests/governance/vat-zoe.js similarity index 100% rename from packages/treasury/test/swingsetTests/governance/vat-zoe.js rename to packages/run-protocol/test/swingsetTests/governance/vat-zoe.js diff --git a/packages/treasury/test/swingsetTests/setup.js b/packages/run-protocol/test/swingsetTests/setup.js similarity index 91% rename from packages/treasury/test/swingsetTests/setup.js rename to packages/run-protocol/test/swingsetTests/setup.js index 8f6cf64990a2..73eb0a66887e 100644 --- a/packages/treasury/test/swingsetTests/setup.js +++ b/packages/run-protocol/test/swingsetTests/setup.js @@ -6,7 +6,7 @@ import { makeRatio } from '@agoric/zoe/src/contractSupport'; import { Far } from '@agoric/marshal'; import buildManualTimer from '@agoric/zoe/tools/manualTimer'; -import { makeGovernedTerms } from '../../src/params'; +import { makeGovernedTerms } from '../../src/vaultFactory/params'; import { ammMock } from '../mockAmm'; const ONE_DAY = 24n * 60n * 60n; @@ -30,13 +30,13 @@ const setupBasicMints = () => { const installContracts = async (zoe, cb) => { const [ liquidateMinimum, - treasury, + vaultFactory, electorate, counter, governor, ] = await Promise.all([ E(zoe).install(cb.liquidateMinimum), - E(zoe).install(cb.treasury), + E(zoe).install(cb.vaultFactory), E(zoe).install(cb.committee), E(zoe).install(cb.binaryVoteCounter), E(zoe).install(cb.contractGovernor), @@ -44,7 +44,7 @@ const installContracts = async (zoe, cb) => { const installations = { liquidateMinimum, - treasury, + vaultFactory, electorate, counter, governor, @@ -118,7 +118,9 @@ const makeVats = async ( ); // Setup Owner - const { governor, governed: treasury, runBrand } = await E(vats.owner).build( + const { governor, governed: vaultFactory, runBrand } = await E( + vats.owner, + ).build( zoe, issuers, brands, @@ -131,11 +133,11 @@ const makeVats = async ( electorateCreatorFacet, ); - log(`=> alice and the treasury are set up`); + log(`=> alice and the vaultFactory are set up`); return { aliceP, governor, - treasury, + vaultFactory, runBrand, timer, electorateCreatorFacet, @@ -187,7 +189,7 @@ const buildOwner = async ( ammMock, ); - const privateTreasuryArgs = { feeMintAccess, initialPoserInvitation }; + const privateVaultFactoryArgs = { feeMintAccess, initialPoserInvitation }; const governorFacets = await E(zoe).startInstance( installations.governor, @@ -195,11 +197,11 @@ const buildOwner = async ( harden({ timer, electorateInstance, - governedContractInstallation: installations.treasury, + governedContractInstallation: installations.vaultFactory, governed: { terms, issuerKeywordRecord: {}, - privateArgs: privateTreasuryArgs, + privateArgs: privateVaultFactoryArgs, }, }), ); @@ -236,7 +238,7 @@ const buildOwner = async ( runBrand, ); - const voteCreator = Far('treasury vote creator', { + const voteCreator = Far('vaultFactory vote creator', { voteOnParamChange: E(governorFacets.creatorFacet).voteOnParamChange, }); diff --git a/packages/treasury/test/swingsetTests/treasury/bootstrap.js b/packages/run-protocol/test/swingsetTests/treasury/bootstrap.js similarity index 87% rename from packages/treasury/test/swingsetTests/treasury/bootstrap.js rename to packages/run-protocol/test/swingsetTests/treasury/bootstrap.js index 3fe432f60fd0..fbb38f8db88d 100644 --- a/packages/treasury/test/swingsetTests/treasury/bootstrap.js +++ b/packages/run-protocol/test/swingsetTests/treasury/bootstrap.js @@ -14,7 +14,7 @@ function makeBootstrap(argv, cb, vatPowers) { const installations = await installContracts(zoe, cb); const [testName, startingValues] = argv; - const { aliceP, treasury } = await makeVats( + const { aliceP, vaultFactory } = await makeVats( vatPowers.testLog, vats, zoe, @@ -23,7 +23,7 @@ function makeBootstrap(argv, cb, vatPowers) { feeMintAccess, ); - await E(aliceP).startTest(testName, treasury.publicFacet); + await E(aliceP).startTest(testName, vaultFactory.publicFacet); }; } diff --git a/packages/treasury/test/swingsetTests/treasury/test-treasury.js b/packages/run-protocol/test/swingsetTests/treasury/test-treasury.js similarity index 90% rename from packages/treasury/test/swingsetTests/treasury/test-treasury.js rename to packages/run-protocol/test/swingsetTests/treasury/test-treasury.js index 3bf1a55021b8..8f5b0b4b67cc 100644 --- a/packages/treasury/test/swingsetTests/treasury/test-treasury.js +++ b/packages/run-protocol/test/swingsetTests/treasury/test-treasury.js @@ -14,7 +14,7 @@ import { E } from '@agoric/eventual-send'; import liquidateBundle from '../../../bundles/bundle-liquidateMinimum.js'; import ammBundle from '../../../bundles/bundle-amm.js'; -import stablecoinBundle from '../../../bundles/bundle-stablecoinMachine.js'; +import vaultFactoryBundle from '../../../bundles/bundle-vaultFactory.js'; import committeeBundle from '../../../bundles/bundle-committee.js'; import contractGovernorBundle from '../../../bundles/bundle-contractGovernor.js'; import binaryVoteCounterBundle from '../../../bundles/bundle-binaryVoteCounter.js'; @@ -31,7 +31,7 @@ test.before(async t => { const nameToBundle = [ ['liquidateMinimum', liquidateBundle], ['amm', ammBundle], - ['treasury', stablecoinBundle], + ['vaultFactory', vaultFactoryBundle], ['committee', committeeBundle], ['contractGovernor', contractGovernorBundle], ['binaryVoteCounter', binaryVoteCounterBundle], @@ -72,15 +72,15 @@ async function main(t, argv) { return E(controller).dump(); } -const expectedTreasuryLog = [ - '=> alice and the treasury are set up', +const expectedVaultFactoryLog = [ + '=> alice and the vaultFactory are set up', '=> alice.oneLoanWithInterest called', 'Alice owes {"brand":"[Alleged: RUN brand]","value":"[510000n]"} after borrowing', 'Alice owes {"brand":"[Alleged: RUN brand]","value":"[510035n]"} after interest', ]; -test.serial('treasury', async t => { +test.serial('vaultFactory', async t => { const startingValues = [[100], [1000]]; const dump = await main(t, ['oneLoanWithInterest', startingValues]); - t.deepEqual(dump.log, expectedTreasuryLog); + t.deepEqual(dump.log, expectedVaultFactoryLog); }); diff --git a/packages/treasury/test/swingsetTests/treasury/vat-alice.js b/packages/run-protocol/test/swingsetTests/treasury/vat-alice.js similarity index 83% rename from packages/treasury/test/swingsetTests/treasury/vat-alice.js rename to packages/run-protocol/test/swingsetTests/treasury/vat-alice.js index 12d642a80ceb..c07893af9b44 100644 --- a/packages/treasury/test/swingsetTests/treasury/vat-alice.js +++ b/packages/run-protocol/test/swingsetTests/treasury/vat-alice.js @@ -9,14 +9,14 @@ const build = async (log, zoe, brands, payments, timer) => { const [moolaBrand] = brands; const [moolaPayment] = payments; - const oneLoanWithInterest = async treasury => { + const oneLoanWithInterest = async vaultFactory => { log(`=> alice.oneLoanWithInterest called`); - const runIssuer = await E(treasury).getRunIssuer(); + const runIssuer = await E(vaultFactory).getRunIssuer(); const runBrand = await E(runIssuer).getBrand(); const loanSeat = await E(zoe).offer( - E(treasury).makeLoanInvitation(), + E(vaultFactory).makeLoanInvitation(), harden({ give: { Collateral: AmountMath.make(moolaBrand, 100n) }, want: { RUN: AmountMath.make(runBrand, 500000n) }, @@ -33,10 +33,10 @@ const build = async (log, zoe, brands, payments, timer) => { }; return Far('build', { - startTest: async (testName, treasury) => { + startTest: async (testName, vaultFactory) => { switch (testName) { case 'oneLoanWithInterest': { - return oneLoanWithInterest(treasury); + return oneLoanWithInterest(vaultFactory); } default: { assert.fail(X`testName ${testName} not recognized`); diff --git a/packages/treasury/test/swingsetTests/treasury/vat-owner.js b/packages/run-protocol/test/swingsetTests/treasury/vat-owner.js similarity index 91% rename from packages/treasury/test/swingsetTests/treasury/vat-owner.js rename to packages/run-protocol/test/swingsetTests/treasury/vat-owner.js index 7484d8a40c8a..ae8637396768 100644 --- a/packages/treasury/test/swingsetTests/treasury/vat-owner.js +++ b/packages/run-protocol/test/swingsetTests/treasury/vat-owner.js @@ -3,7 +3,7 @@ import { Far } from '@agoric/marshal'; import { buildOwner } from '../setup.js'; -// Treasury owner +// VaultFactory owner export function buildRootObject(vatPowers) { return Far('root', { diff --git a/packages/treasury/test/swingsetTests/treasury/vat-priceAuthority.js b/packages/run-protocol/test/swingsetTests/treasury/vat-priceAuthority.js similarity index 100% rename from packages/treasury/test/swingsetTests/treasury/vat-priceAuthority.js rename to packages/run-protocol/test/swingsetTests/treasury/vat-priceAuthority.js diff --git a/packages/treasury/test/swingsetTests/treasury/vat-zoe.js b/packages/run-protocol/test/swingsetTests/treasury/vat-zoe.js similarity index 100% rename from packages/treasury/test/swingsetTests/treasury/vat-zoe.js rename to packages/run-protocol/test/swingsetTests/treasury/vat-zoe.js diff --git a/packages/treasury/test/test-bootstrapPayment.js b/packages/run-protocol/test/test-bootstrapPayment.js similarity index 99% rename from packages/treasury/test/test-bootstrapPayment.js rename to packages/run-protocol/test/test-bootstrapPayment.js index 29a53809d83b..a7ed2d316603 100644 --- a/packages/treasury/test/test-bootstrapPayment.js +++ b/packages/run-protocol/test/test-bootstrapPayment.js @@ -3,7 +3,7 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import '@agoric/zoe/exported.js'; -import '../src/types.js'; +import '../src/vaultFactory/types.js'; import path from 'path'; import { E } from '@agoric/eventual-send'; diff --git a/packages/treasury/test/test-interest.js b/packages/run-protocol/test/test-interest.js similarity index 99% rename from packages/treasury/test/test-interest.js rename to packages/run-protocol/test/test-interest.js index 7e48cdc44d36..ab88e65f54a1 100644 --- a/packages/treasury/test/test-interest.js +++ b/packages/run-protocol/test/test-interest.js @@ -5,7 +5,10 @@ import '@agoric/zoe/exported.js'; import { makeIssuerKit, AmountMath } from '@agoric/ertp'; import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js'; -import { makeInterestCalculator, SECONDS_PER_YEAR } from '../src/interest.js'; +import { + makeInterestCalculator, + SECONDS_PER_YEAR, +} from '../src/vaultFactory/interest.js'; const ONE_DAY = 60n * 60n * 24n; const ONE_MONTH = ONE_DAY * 30n; diff --git a/packages/treasury/test/test-prioritizedVaults.js b/packages/run-protocol/test/test-prioritizedVaults.js similarity index 99% rename from packages/treasury/test/test-prioritizedVaults.js rename to packages/run-protocol/test/test-prioritizedVaults.js index 8e75cedc0be0..c34a8f37abc5 100644 --- a/packages/treasury/test/test-prioritizedVaults.js +++ b/packages/run-protocol/test/test-prioritizedVaults.js @@ -11,7 +11,7 @@ import { Far } from '@agoric/marshal'; import { makePromiseKit } from '@agoric/promise-kit'; import { makeRatioFromAmounts } from '@agoric/zoe/src/contractSupport/index.js'; -import { makePrioritizedVaults } from '../src/prioritizedVaults.js'; +import { makePrioritizedVaults } from '../src/vaultFactory/prioritizedVaults.js'; // Some notifier updates aren't propogating sufficiently quickly for the tests. // This invocation (thanks to Warner) waits for all promises that can fire to diff --git a/packages/treasury/test/test-stablecoin.js b/packages/run-protocol/test/test-stablecoin.js similarity index 95% rename from packages/treasury/test/test-stablecoin.js rename to packages/run-protocol/test/test-stablecoin.js index 3420965af1d2..698c01986362 100644 --- a/packages/treasury/test/test-stablecoin.js +++ b/packages/run-protocol/test/test-stablecoin.js @@ -25,18 +25,18 @@ import { import { makeParamManagerBuilder } from '@agoric/governance'; import { makeTracer } from '../src/makeTracer.js'; -import { SECONDS_PER_YEAR } from '../src/interest.js'; -import { VaultState } from '../src/vault.js'; +import { SECONDS_PER_YEAR } from '../src/vaultFactory/interest.js'; +import { VaultState } from '../src/vaultFactory/vault.js'; import { makeGovernedTerms, CHARGING_PERIOD_KEY, RECORDING_PERIOD_KEY, -} from '../src/params.js'; +} from '../src/vaultFactory/params.js'; const ammRoot = '@agoric/zoe/src/contracts/vpool-xyk-amm/multipoolMarketMaker.js'; -const stablecoinRoot = '../src/stablecoinMachine.js'; +const vaultFactoryRoot = '../src/vaultFactory.js'; const liquidationRoot = '../src/liquidateMinimum.js'; const faucetRoot = './faucet.js'; @@ -58,7 +58,7 @@ async function makeBundle(sourceRoot) { } // makeBundle is a slow step, so we do it once for all the tests. -const stablecoinBundleP = makeBundle(stablecoinRoot); +const vaultFactoryBundleP = makeBundle(vaultFactoryRoot); const liquidationBundleP = makeBundle(liquidationRoot); const contractGovernorBundleP = makeBundle(contractGovernorRoot); const committeeBundleP = makeBundle(committeeRoot); @@ -181,7 +181,12 @@ async function setupAmmAndElectorate( }; } -async function setupTreasury(governorTerms, installs, zoe, committeeCreator) { +async function setupVaultFactory( + governorTerms, + installs, + zoe, + committeeCreator, +) { const { instance: governorInstance, publicFacet: governorPublicFacet, @@ -190,23 +195,20 @@ async function setupTreasury(governorTerms, installs, zoe, committeeCreator) { electorateCreatorFacet: committeeCreator, }); - const stablecoinMachineP = E(governorCreatorFacet).getCreatorFacet(); + const vaultFactoryP = E(governorCreatorFacet).getCreatorFacet(); const lenderP = E(governorCreatorFacet).getPublicFacet(); - const [stablecoinMachine, lender] = await Promise.all([ - stablecoinMachineP, - lenderP, - ]); + const [vaultFactory, lender] = await Promise.all([vaultFactoryP, lenderP]); const g = { governorInstance, governorPublicFacet, governorCreatorFacet }; - const s = { stablecoinMachine, lender }; - return { g, s }; + const v = { vaultFactory, lender }; + return { g, v }; } async function bundleInstalls(zoe) { const [ - stablecoinBundle, + vaultFactoryBundle, liquidationBundle, contractGovernorBundle, committeeBundle, @@ -214,7 +216,7 @@ async function bundleInstalls(zoe) { ammBundle, faucetBundle, ] = await Promise.all([ - stablecoinBundleP, + vaultFactoryBundleP, liquidationBundleP, contractGovernorBundleP, committeeBundleP, @@ -224,7 +226,7 @@ async function bundleInstalls(zoe) { ]); const [ - stablecoin, + vaultFactory, liquidation, governor, electorate, @@ -232,7 +234,7 @@ async function bundleInstalls(zoe) { amm, faucet, ] = await Promise.all([ - installBundle(zoe, stablecoinBundle), + installBundle(zoe, vaultFactoryBundle), installBundle(zoe, liquidationBundle), installBundle(zoe, contractGovernorBundle), installBundle(zoe, committeeBundle), @@ -242,7 +244,7 @@ async function bundleInstalls(zoe) { ]); const installs = { - stablecoin, + vaultFactory, liquidation, governor, electorate, @@ -337,7 +339,7 @@ async function setupServices( E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP), ]); - const treasuryTerms = makeGovernedTerms( + const vaultFactoryTerms = makeGovernedTerms( priceAuthorityPromise, loanParams, installs.liquidation, @@ -350,15 +352,15 @@ async function setupServices( const governorTerms = harden({ timer, electorateInstance, - governedContractInstallation: installs.stablecoin, + governedContractInstallation: installs.vaultFactory, governed: { - terms: treasuryTerms, + terms: vaultFactoryTerms, issuerKeywordRecord: {}, privateArgs: { feeMintAccess, initialPoserInvitation }, }, }); - const { g, s } = await setupTreasury( + const { g, v } = await setupVaultFactory( governorTerms, installs, zoe, @@ -368,7 +370,7 @@ async function setupServices( const quoteMint = makeIssuerKit('quote', AssetKind.SET).mint; // priceAuthority needs the RUN brand, which isn't available until the - // stablecoinMachine has been built, so resolve priceAuthorityPromiseKit here + // vaultFactory has been built, so resolve priceAuthorityPromiseKit here const priceAuthority = makePriceAuthority( aethBrand, runBrand, @@ -384,7 +386,7 @@ async function setupServices( zoe, installs, governor: g, - stablecoin: s, + vaultFactory: v, ammFacets, runKit: { issuer: runIssuer, brand: runBrand }, priceAuthority, @@ -422,12 +424,12 @@ test('first', async t => { zoe, runKit: { issuer: runIssuer, brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; // Add a vault that will lend on aeth collateral const rates = makeRates(runBrand); /** @type {VaultManager} */ - const aethVaultManager = await E(stablecoinMachine).addVaultType( + const aethVaultManager = await E(vaultFactory).addVaultType( aethIssuer, 'AEth', rates, @@ -529,7 +531,7 @@ test('first', async t => { t.deepEqual(liquidations.Collateral, AmountMath.make(aethBrand, 566n)); t.deepEqual(liquidations.RUN, AmountMath.makeEmpty(runBrand)); - t.deepEqual(await E(stablecoinMachine).getRewardAllocation(), { + t.deepEqual(await E(vaultFactory).getRewardAllocation(), { RUN: AmountMath.make(runBrand, 24n), }); }); @@ -570,11 +572,11 @@ test('price drop', async t => { zoe, runKit: { brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; // Add a vault that will lend on aeth collateral const rates = makeRates(runBrand); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); // Create a loan for 270 RUN with 400 aeth collateral const collateralAmount = AmountMath.make(aethBrand, 400n); @@ -643,7 +645,7 @@ test('price drop', async t => { ); t.truthy(AmountMath.isEmpty(debtAmountAfter)); - t.deepEqual(await E(stablecoinMachine).getRewardAllocation(), { + t.deepEqual(await E(vaultFactory).getRewardAllocation(), { RUN: AmountMath.make(runBrand, 14n), }); @@ -694,11 +696,11 @@ test('price falls precipitously', async t => { zoe, runKit: { brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; // Add a vault that will lend on aeth collateral const rates = makeRates(runBrand); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); // Create a loan for 370 RUN with 400 aeth collateral const collateralAmount = AmountMath.make(aethBrand, 400n); @@ -763,7 +765,7 @@ test('price falls precipitously', async t => { t.truthy(AmountMath.isGTE(AmountMath.make(runBrand, 70n), newDebtAmount)); - t.deepEqual(await E(stablecoinMachine).getRewardAllocation(), { + t.deepEqual(await E(vaultFactory).getRewardAllocation(), { RUN: AmountMath.make(runBrand, 19n), }); @@ -774,7 +776,7 @@ test('price falls precipitously', async t => { t.deepEqual(liquidations.RUN, AmountMath.makeEmpty(runBrand)); }); -test('stablecoin display collateral', async t => { +test('vaultFactory display collateral', async t => { const loanParams = { chargingPeriod: 2n, recordingPeriod: 6n, @@ -804,7 +806,7 @@ test('stablecoin display collateral', async t => { const { runKit: { brand: runBrand }, } = services; - const { stablecoinMachine } = services.stablecoin; + const { vaultFactory } = services.vaultFactory; const rates = harden({ initialMargin: makeRatio(120n, runBrand), @@ -813,9 +815,9 @@ test('stablecoin display collateral', async t => { loanFee: makeRatio(530n, runBrand, BASIS_POINTS), }); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); - const collaterals = await E(stablecoinMachine).getCollaterals(); + const collaterals = await E(vaultFactory).getCollaterals(); t.deepEqual(collaterals[0], { brand: aethBrand, @@ -862,7 +864,7 @@ test('interest on multiple vaults', async t => { zoe, runKit: { issuer: runIssuer, brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; const interestRate = makeRatio(5n, runBrand); const rates = harden({ @@ -871,7 +873,7 @@ test('interest on multiple vaults', async t => { interestRate, loanFee: makeRatio(500n, runBrand, BASIS_POINTS), }); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); // Create a loan for Alice for 4700 RUN with 1100 aeth collateral const collateralAmount = AmountMath.make(aethBrand, 1100n); @@ -987,7 +989,7 @@ test('interest on multiple vaults', async t => { aliceCollateralization.denominator.value, ); - const rewardAllocation = await E(stablecoinMachine).getRewardAllocation(); + const rewardAllocation = await E(vaultFactory).getRewardAllocation(); t.truthy( AmountMath.isEqual( rewardAllocation.RUN, @@ -1029,11 +1031,11 @@ test('adjust balances', async t => { zoe, runKit: { issuer: runIssuer, brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; const priceConversion = makeRatio(15n, runBrand, 1n, aethBrand); const rates = makeRates(runBrand); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); // initial loan ///////////////////////////////////// @@ -1297,10 +1299,10 @@ test('overdeposit', async t => { zoe, runKit: { issuer: runIssuer, brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; const rates = makeRates(runBrand); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); // Alice's loan ///////////////////////////////////// @@ -1409,7 +1411,7 @@ test('overdeposit', async t => { ); const collectFeesSeat = await E(zoe).offer( - E(stablecoinMachine).makeCollectFeesInvitation(), + E(vaultFactory).makeCollectFeesInvitation(), ); await E(collectFeesSeat).getOfferResult(); assertAmountsEqual( @@ -1461,7 +1463,7 @@ test('mutable liquidity triggers and interest', async t => { zoe, runKit: { issuer: runIssuer, brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; // Add a vaultManager with 10000 aeth collateral at a 200 aeth/RUN rate const rates = harden({ @@ -1472,7 +1474,7 @@ test('mutable liquidity triggers and interest', async t => { loanFee: makeRatio(500n, runBrand, BASIS_POINTS), }); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); // initial loans ///////////////////////////////////// @@ -1676,12 +1678,12 @@ test('collect fees from loan and AMM', async t => { zoe, runKit: { brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; // Add a pool with 900 aeth collateral at a 201 aeth/RUN rate const rates = makeRates(runBrand); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); // Create a loan for 470 RUN with 1100 aeth collateral const collateralAmount = AmountMath.make(aethBrand, 1100n); @@ -1713,7 +1715,7 @@ test('collect fees from loan and AMM', async t => { 'vault holds 1100 Collateral', ); - t.deepEqual(await E(stablecoinMachine).getRewardAllocation(), { + t.deepEqual(await E(vaultFactory).getRewardAllocation(), { RUN: AmountMath.make(runBrand, 24n), }); @@ -1735,7 +1737,7 @@ test('collect fees from loan and AMM', async t => { const feePoolBalance = await E(amm).getProtocolPoolBalance(); const collectFeesSeat = await E(zoe).offer( - E(stablecoinMachine).makeCollectFeesInvitation(), + E(vaultFactory).makeCollectFeesInvitation(), ); await E(collectFeesSeat).getOfferResult(); const feePayoutAmount = await E.get(E(collectFeesSeat).getCurrentAllocation()) @@ -1775,10 +1777,10 @@ test('close loan', async t => { zoe, runKit: { issuer: runIssuer, brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; const rates = makeRates(runBrand); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); // initial loan ///////////////////////////////////// @@ -1916,10 +1918,10 @@ test('excessive loan', async t => { zoe, runKit: { brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; const rates = makeRates(runBrand); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); // Try to Create a loan for Alice for 5000 RUN with 100 aeth collateral const collateralAmount = AmountMath.make(aethBrand, 100n); @@ -1983,7 +1985,7 @@ test('mutable liquidity triggers and interest sensitivity', async t => { zoe, runKit: { issuer: runIssuer, brand: runBrand }, } = services; - const { stablecoinMachine, lender } = services.stablecoin; + const { vaultFactory, lender } = services.vaultFactory; // Add a vaultManager with 10000 aeth collateral at a 200 aeth/RUN rate const rates = harden({ @@ -1994,7 +1996,7 @@ test('mutable liquidity triggers and interest sensitivity', async t => { loanFee: makeRatio(500n, runBrand, BASIS_POINTS), }); - await E(stablecoinMachine).addVaultType(aethIssuer, 'AEth', rates); + await E(vaultFactory).addVaultType(aethIssuer, 'AEth', rates); // initial loans ///////////////////////////////////// diff --git a/packages/treasury/test/test-vault-interest.js b/packages/run-protocol/test/test-vault-interest.js similarity index 100% rename from packages/treasury/test/test-vault-interest.js rename to packages/run-protocol/test/test-vault-interest.js diff --git a/packages/treasury/test/test-vault.js b/packages/run-protocol/test/test-vault.js similarity index 100% rename from packages/treasury/test/test-vault.js rename to packages/run-protocol/test/test-vault.js diff --git a/packages/treasury/test/vault-contract-wrapper.js b/packages/run-protocol/test/vault-contract-wrapper.js similarity index 96% rename from packages/treasury/test/vault-contract-wrapper.js rename to packages/run-protocol/test/vault-contract-wrapper.js index c64d2a51b3ab..fb32c95a5792 100644 --- a/packages/treasury/test/vault-contract-wrapper.js +++ b/packages/run-protocol/test/vault-contract-wrapper.js @@ -10,8 +10,8 @@ import { makeFakePriceAuthority } from '@agoric/zoe/tools/fakePriceAuthority.js' import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js'; import { Far } from '@agoric/marshal'; -import { makeVaultKit } from '../src/vault.js'; -import { paymentFromZCFMint } from '../src/burn.js'; +import { makeVaultKit } from '../src/vaultFactory/vault.js'; +import { paymentFromZCFMint } from '../src/vaultFactory/burn.js'; const BASIS_POINTS = 10000n; const SECONDS_PER_HOUR = 60n * 60n; diff --git a/packages/treasury/exported.js b/packages/treasury/exported.js deleted file mode 100644 index 54086a2c4013..000000000000 --- a/packages/treasury/exported.js +++ /dev/null @@ -1,5 +0,0 @@ -import './src/types.js'; -import '@agoric/notifier/exported.js'; -import '@agoric/ertp/exported.js'; -import '@agoric/store/exported.js'; -import '@agoric/swingset-vat/exported.js'; diff --git a/packages/vats/package.json b/packages/vats/package.json index 0d9d00736d2b..80c0b14e158b 100644 --- a/packages/vats/package.json +++ b/packages/vats/package.json @@ -36,7 +36,7 @@ "@agoric/sparse-ints": "^0.1.24", "@agoric/store": "^0.6.7", "@agoric/swingset-vat": "^0.24.0", - "@agoric/treasury": "^0.7.0", + "@agoric/run-protocol": "^0.7.0", "@agoric/wallet-backend": "^0.10.6", "@agoric/zoe": "^0.21.0" }, diff --git a/packages/vats/src/bootstrap.js b/packages/vats/src/bootstrap.js index 43d492623e30..877870c32848 100644 --- a/packages/vats/src/bootstrap.js +++ b/packages/vats/src/bootstrap.js @@ -7,7 +7,7 @@ import { } from '@agoric/swingset-vat/src/vats/network/index.js'; import { E, Far } from '@agoric/far'; import { makeStore } from '@agoric/store'; -import { installOnChain as installTreasuryOnChain } from '@agoric/treasury/bundles/install-on-chain.js'; +import { installOnChain as installVaultFactoryOnChain } from '@agoric/run-protocol/bundles/install-on-chain.js'; import { installOnChain as installPegasusOnChain } from '@agoric/pegasus/bundles/install-on-chain.js'; import { makePluginManager } from '@agoric/swingset-vat/src/vats/plugin-manager.js'; @@ -155,15 +155,15 @@ export function buildRootObject(vatPowers, vatParameters) { nameAdmins.init(nameHub, nameAdmin); if (nm === 'uiConfig') { // Reserve the Treasury's config until we've populated it. - nameAdmin.reserve('Treasury'); + nameAdmin.reserve('vaultFactory'); } }, ), ); // Install the economy, giving the components access to the name admins we made. - const [treasuryInstallResults] = await Promise.all([ - installTreasuryOnChain({ + const [vaultFactoryInstallResults] = await Promise.all([ + installVaultFactoryOnChain({ agoricNames, board, centralName: CENTRAL_ISSUER_NAME, @@ -182,7 +182,7 @@ export function buildRootObject(vatPowers, vatParameters) { zoeWPurse: zoeWUnlimitedPurse, }), ]); - return treasuryInstallResults; + return vaultFactoryInstallResults; } const demoIssuers = demoIssuerEntries(noFakeCurrencies); @@ -252,13 +252,15 @@ export function buildRootObject(vatPowers, vatParameters) { // Now we can bootstrap the economy! const bankBootstrapSupply = Nat(BigInt(centralBootstrapSupply.amount)); - // Ask the treasury for enough RUN to fund both AMM and bank. + // Ask the vaultFactory for enough RUN to fund both AMM and bank. const bootstrapPaymentValue = bankBootstrapSupply + ammDepositValue; // NOTE: no use of the voteCreator. We'll need it to initiate votes on - // changing Treasury parameters. - const { treasuryCreator, _voteCreator, ammFacets } = await installEconomy( - bootstrapPaymentValue, - ); + // changing VaultFactory parameters. + const { + vaultFactoryCreator, + _voteCreator, + ammFacets, + } = await installEconomy(bootstrapPaymentValue); const [ centralIssuer, @@ -291,7 +293,7 @@ export function buildRootObject(vatPowers, vatParameters) { E(vats.distributeFees) .buildDistributor( E(vats.distributeFees).makeFeeCollector(zoeWUnlimitedPurse, [ - treasuryCreator, + vaultFactoryCreator, ammFacets.ammCreatorFacet, ]), feeCollectorDepositFacet, @@ -309,7 +311,7 @@ export function buildRootObject(vatPowers, vatParameters) { /* Prime the bank vat with our bootstrap payment. */ const centralBootstrapPayment = await E( - treasuryCreator, + vaultFactoryCreator, ).getBootstrapPayment(AmountMath.make(centralBrand, bootstrapPaymentValue)); const [ammBootstrapPayment, bankBootstrapPayment] = await E( @@ -483,7 +485,7 @@ export function buildRootObject(vatPowers, vatParameters) { }), ); - return E(treasuryCreator).addVaultType( + return E(vaultFactoryCreator).addVaultType( record.issuer, config.keyword, rates, @@ -777,7 +779,7 @@ export function buildRootObject(vatPowers, vatParameters) { ['chainWallet', () => makeChainWallet()], ['pegasusConnections', pegasusConnections], ['priceAuthorityAdmin', priceAuthorityAdmin], - ['treasuryCreator', treasuryCreator], + ['vaultFactoryCreator', vaultFactoryCreator], ['vattp', () => makeVattpFrom(vats)], ]; await Promise.all( diff --git a/packages/vats/src/distributeFees.js b/packages/vats/src/distributeFees.js index 797708e24d65..8632bb83ad2b 100644 --- a/packages/vats/src/distributeFees.js +++ b/packages/vats/src/distributeFees.js @@ -3,7 +3,7 @@ import { observeNotifier } from '@agoric/notifier'; import { E, Far } from '@agoric/far'; -// wrapper to take the treasury or AMM's creatorFacet, and make a function that +// wrapper to take the vaultFactory or AMM's creatorFacet, and make a function that // will request an invitation and return a promise for a payment. export function makeFeeCollector(zoe, creatorFacet) { /** @type {FeeCollector} */ @@ -17,7 +17,7 @@ export function makeFeeCollector(zoe, creatorFacet) { } /** - * A distributor of fees from treasury or AMM to the Bank module. Each time the + * A distributor of fees from vaultFactory or AMM to the Bank module. Each time the * epochTimer signals the end of an Epoch, it will ask the contracts for fees * that have been collected to date and send that payment to the depositFacet. * @@ -49,10 +49,10 @@ export async function buildDistributor( throw e; }), fail: reason => { - throw Error(`Treasury epoch timer failed: ${reason}`); + throw Error(`VaultFactory epoch timer failed: ${reason}`); }, finish: done => { - throw Error(`Treasury epoch timer died: ${done}`); + throw Error(`VaultFactory epoch timer died: ${done}`); }, }; diff --git a/packages/vats/test/test-distributeFees.js b/packages/vats/test/test-distributeFees.js index b1d0b8d16e69..2e84c966e5c9 100644 --- a/packages/vats/test/test-distributeFees.js +++ b/packages/vats/test/test-distributeFees.js @@ -62,14 +62,14 @@ test('fee distribution', async t => { const { brands, moolaIssuer: issuer, moolaMint: runMint } = setup(); const brand = brands.get('moola'); const { feeDepositFacet, getPayments } = makeFakeFeeDepositFacet(issuer); - const treasury = makeFakeFeeProducer(); + const vaultFactory = makeFakeFeeProducer(); const amm = makeFakeFeeProducer(); const epochTimer = buildManualTimer(console.log); const distributorParams = { epochInterval: 1n, }; buildDistributor( - [treasury, amm], + [vaultFactory, amm], feeDepositFacet, epochTimer, distributorParams, @@ -77,7 +77,7 @@ test('fee distribution', async t => { t.fail(e.stack); }); - treasury.pushFees(runMint.mintPayment(AmountMath.make(brand, 500n))); + vaultFactory.pushFees(runMint.mintPayment(AmountMath.make(brand, 500n))); amm.pushFees(runMint.mintPayment(AmountMath.make(brand, 270n))); t.deepEqual(getPayments(), []); @@ -92,20 +92,20 @@ test('fee distribution, leftovers', async t => { const { brands, moolaIssuer: issuer, moolaMint: runMint } = setup(); const brand = brands.get('moola'); const { feeDepositFacet, getPayments } = makeFakeFeeDepositFacet(issuer); - const treasury = makeFakeFeeProducer(); + const vaultFactory = makeFakeFeeProducer(); const amm = makeFakeFeeProducer(); const epochTimer = buildManualTimer(console.log); const distributorParams = { epochInterval: 1n, }; buildDistributor( - [treasury, amm], + [vaultFactory, amm], feeDepositFacet, epochTimer, distributorParams, ); - treasury.pushFees(runMint.mintPayment(AmountMath.make(brand, 12n))); + vaultFactory.pushFees(runMint.mintPayment(AmountMath.make(brand, 12n))); amm.pushFees(runMint.mintPayment(AmountMath.make(brand, 8n))); t.deepEqual(getPayments(), []); @@ -116,7 +116,7 @@ test('fee distribution, leftovers', async t => { assertPaymentArray(t, getPayments(), 2, [12n, 8n], issuer, brand); // Pay them again - treasury.pushFees(runMint.mintPayment(AmountMath.make(brand, 13n))); + vaultFactory.pushFees(runMint.mintPayment(AmountMath.make(brand, 13n))); amm.pushFees(runMint.mintPayment(AmountMath.make(brand, 7n))); await epochTimer.tick(); diff --git a/packages/zoe/src/zoeService/zoe.js b/packages/zoe/src/zoeService/zoe.js index 1149716d2a4d..376d267b3bb4 100644 --- a/packages/zoe/src/zoeService/zoe.js +++ b/packages/zoe/src/zoeService/zoe.js @@ -73,7 +73,7 @@ const makeZoeKit = ( }, meteringConfig = { incrementBy: 25_000_000n, - initial: 75_000_000n, // executeContract for treasury is 13.5M + initial: 75_000_000n, // executeContract for vaultFactory is 13.5M threshold: 25_000_000n, price: { feeNumerator: 1n,