Skip to content

Commit

Permalink
refactor: new package for run-protocol; rename Treasury/stablecoin
Browse files Browse the repository at this point in the history
rename treasury package to run-protocol.
rename stablecoinMachine (and stablecoin) to vaultFactory

changes to documentation will be done separately
The Dapps will be updated in linked PRs as necessary.
  • Loading branch information
Chris-Hibbert committed Dec 27, 2021
1 parent fea822e commit bde898d
Show file tree
Hide file tree
Showing 56 changed files with 218 additions and 200 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/misc-tools/measure-metering/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/misc-tools/vat-map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
# 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
vats = {} # vatID -> { name, managerType, cranks }
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 = "([^"]+)"')
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,7 +169,7 @@ export async function installOnChain({
const nameBundles = [
['liquidate', liquidateBundle],
['amm', ammBundle],
['stablecoin', stablecoinBundle],
['vaultFactory', vaultFactoryBundle],
['contractGovernor', contractGovernorBundle],
['noActionElectorate', noActionElectorateBundle],
['binaryCounter', binaryVoteCounterBundle],
Expand All @@ -178,7 +178,7 @@ export async function installOnChain({
const [
liquidationInstall,
ammInstall,
stablecoinMachineInstall,
vaultFactoryInstall,
contractGovernorInstall,
noActionElectorateInstall,
binaryCounterInstall,
Expand All @@ -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,
Expand Down Expand Up @@ -228,15 +228,15 @@ 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),
interestRate: makeRatio(250n, centralBrand, BASIS_POINTS),
loanFee: makeRatio(200n, centralBrand, BASIS_POINTS),
}

const treasuryTerms = makeGovernedTerms(
const vaultFactoryTerms = makeGovernedTerms(
priceAuthority,
loanParams,
liquidationInstall,
Expand All @@ -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 }),
},
Expand All @@ -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,
Expand All @@ -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],
Expand All @@ -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],
];
Expand All @@ -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 };
}
1 change: 1 addition & 0 deletions packages/run-protocol/exported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './src/vaultFactory/types.js';
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
],
[
Expand Down
2 changes: 2 additions & 0 deletions packages/run-protocol/src/exported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './vpool-xyk-amm/types.js';
import './vaultFactory/types.js';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/

/**
* @typedef {Object} StablecoinMachine - the creator facet
* @typedef {Object} VaultFactory - the creator facet
* @property {AddVaultType} addVaultType
* @property {() => Promise<Array<Collateral>>} getCollaterals
* @property {() => Allocation} getRewardAllocation,
Expand All @@ -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.
*
Expand Down Expand Up @@ -268,7 +268,7 @@
*/

/**
* @callback TreasuryLiquidate
* @callback VaultFactoryLiquidate
* @param {ContractFacet} zcf
* @param {VaultKit} vaultKit
* @param {(losses: AmountKeywordRecord,
Expand All @@ -292,7 +292,7 @@
*/

/**
* @typedef {Object} GovernedTreasuryTerms
* @typedef {Object} GovernedVaultFactoryTerms
* @property {XYKAMMPublicFacet} ammPublicFacet
* @property {ERef<PriceAuthority>} priceAuthority
* @property {Record<Keyword,ParamShortDescription>} loanParams
Expand All @@ -312,5 +312,5 @@
* @param {Rates} rates
* @param {XYKAMMPublicFacet} ammPublicFacet
* @param {bigint=} bootstrapPaymentValue
* @returns {GovernedTreasuryTerms}
* @returns {GovernedVaultFactoryTerms}
*/
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
File renamed without changes.
Loading

0 comments on commit bde898d

Please sign in to comment.