Skip to content

Commit

Permalink
chore: integrate with changes to paramManager
Browse files Browse the repository at this point in the history
extracted params to a separate file
  • Loading branch information
Chris-Hibbert committed Jun 22, 2021
1 parent 8bd0d3e commit e478297
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 224 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"timeout": "30m"
},
"dependencies": {
"@endo/eslint-config": "^0.3.9",
"@endo/eslint-config": "^0.3.10",
"@endo/eslint-plugin": "^0.3.6",
"patch-package": "^6.2.2"
}
}
102 changes: 0 additions & 102 deletions packages/governance/src/param-manager.js

This file was deleted.

7 changes: 6 additions & 1 deletion packages/governance/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
* @property {ParamType} type
*/

/**
* @callback GetParams
* @returns {Record<Keyword,ParamDescription>}
*/

/**
* @typedef {Object} ParamManagerBase
* @property {() => Record<Keyword,ParamDescription>} getParams
* @property {GetParams} getParams
*
* @typedef {{ [updater: string]: (arg: ParamValue) => void }} ParamManagerUpdaters
* @typedef {ParamManagerBase & ParamManagerUpdaters} ParamManagerFull
Expand Down
2 changes: 1 addition & 1 deletion packages/treasury/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
"eslintConfig": {
"extends": [
"@endo"
"@agoric"
]
},
"eslintIgnore": [
Expand Down
13 changes: 0 additions & 13 deletions packages/treasury/src/paramKeys.js

This file was deleted.

81 changes: 81 additions & 0 deletions packages/treasury/src/params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// @ts-check

import { buildParamManager, ParamType } from '@agoric/governance';

export const POOL_FEE_KEY = 'PoolFee';
export const PROTOCOL_FEE_KEY = 'ProtocolFee';

export const CHARGING_PERIOD_KEY = 'ChargingPeriod';
export const RECORDING_PERIOD_KEY = 'RecordingPeriod';

export const INITIAL_MARGIN_KEY = 'InitialMargin';
export const LIQUIDATION_MARGIN_KEY = 'LiquidationMargin';
export const INTEREST_RATE_KEY = 'InterestRate';
export const LOAN_FEE_KEY = 'LoanFee';

export const governedParameterTerms = () => ({
loanParams: {
POOL_FEE_KEY,
PROTOCOL_FEE_KEY,
},
poolParams: {
CHARGING_PERIOD_KEY,
RECORDING_PERIOD_KEY,
INITIAL_MARGIN_KEY,
LIQUIDATION_MARGIN_KEY,
INTEREST_RATE_KEY,
LOAN_FEE_KEY,
},
});

export const makeFeeGovernor = loanParams => {
/** @type {FeeGovernor} */
return buildParamManager([
{
name: POOL_FEE_KEY,
value: loanParams.poolFee,
type: ParamType.NAT,
},
{
name: PROTOCOL_FEE_KEY,
value: loanParams.protocolFee,
type: ParamType.NAT,
},
]);
};

export const makePoolGovernor = (loanParams, rates) => {
/** @type {PoolGovernor} */
return buildParamManager([
{
name: CHARGING_PERIOD_KEY,
value: loanParams.chargingPeriod,
type: ParamType.NAT,
},
{
name: RECORDING_PERIOD_KEY,
value: loanParams.recordingPeriod,
type: ParamType.NAT,
},
{
name: INITIAL_MARGIN_KEY,
value: rates.initialMargin,
type: ParamType.RATIO,
},
{
name: LIQUIDATION_MARGIN_KEY,
value: rates.liquidationMargin,
type: ParamType.RATIO,
},
{
name: INTEREST_RATE_KEY,
value: rates.interestRate,
type: ParamType.RATIO,
},
{
name: LOAN_FEE_KEY,
value: rates.loanFee,
type: ParamType.RATIO,
},
]);
};
95 changes: 16 additions & 79 deletions packages/treasury/src/stablecoinMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,17 @@ import {
makeRatioFromAmounts,
} from '@agoric/zoe/src/contractSupport/ratio';
import { AmountMath } from '@agoric/ertp';
import {
buildParamManager,
ParamType,
} from '@agoric/governance/src/param-manager';

import { makeTracer } from './makeTracer';
import { makeVaultManager } from './vaultManager';
import { makeLiquidationStrategy } from './liquidateMinimum';
import { makeMakeCollectFeesInvitation } from './collectRewardFees';
import {
makePoolGovernor,
makeFeeGovernor,
PROTOCOL_FEE_KEY,
POOL_FEE_KEY,
RECORDING_PERIOD_KEY,
CHARGING_PERIOD_KEY,
INITIAL_MARGIN_KEY,
LIQUIDATION_MARGIN_KEY,
INITIAL_PRICE_KEY,
INTEREST_RATE_KEY,
LOAN_FEE_KEY,
} from './paramKeys';
} from './params';

const trace = makeTracer('ST');

Expand Down Expand Up @@ -81,21 +72,7 @@ export async function start(zcf) {
)}) must be a BigInt`,
);

const {
publicFacet: paramManagerPublic,
manager: paramManager,
} = buildParamManager([
{
name: POOL_FEE_KEY,
value: loanParams.poolFee,
type: ParamType.BIGINT,
},
{
name: PROTOCOL_FEE_KEY,
value: loanParams.protocolFee,
type: ParamType.BIGINT,
},
]);
const feeGovernor = makeFeeGovernor(loanParams);

const [runMint, govMint] = await Promise.all([
zcf.makeZCFMint('RUN', undefined, harden({ decimalPlaces: 6 })),
Expand Down Expand Up @@ -149,12 +126,12 @@ export async function start(zcf) {
timer: timerService,
// TODO(hibbert): make the AMM use a paramManager. For now, the values
// are fixed after creation of an autoswap instance.
poolFee: paramManagerPublic.lookup(POOL_FEE_KEY),
protocolFee: paramManagerPublic.lookup(PROTOCOL_FEE_KEY),
poolFee: feeGovernor.getParams()[POOL_FEE_KEY].value,
protocolFee: feeGovernor.getParams()[PROTOCOL_FEE_KEY].value,
},
);

const rateManagers = makeStore('brand'); // Brand -> rateManager
const poolGovernors = makeStore('brand'); // Brand -> poolGovernor

// We process only one offer per collateralType. They must tell us the
// dollar value of their collateral, and we create that many RUN.
Expand All @@ -168,48 +145,9 @@ export async function start(zcf) {
const collateralBrand = zcf.getBrandForIssuer(collateralIssuer);
assert(!collateralTypes.has(collateralBrand));

const {
publicFacet: rateManagerPublic,
manager: rateManager,
} = buildParamManager([
{
name: CHARGING_PERIOD_KEY,
value: loanParams.chargingPeriod,
type: ParamType.BIGINT,
},
{
name: RECORDING_PERIOD_KEY,
value: loanParams.recordingPeriod,
type: ParamType.BIGINT,
},
{
name: INITIAL_MARGIN_KEY,
value: rates.initialMargin,
type: ParamType.RATIO,
},
{
name: LIQUIDATION_MARGIN_KEY,
value: rates.liquidationMargin,
type: ParamType.RATIO,
},
{
name: INITIAL_PRICE_KEY,
value: rates.initialPrice,
type: ParamType.RATIO,
},
{
name: INTEREST_RATE_KEY,
value: rates.interestRate,
type: ParamType.RATIO,
},
{
name: LOAN_FEE_KEY,
value: rates.loanFee,
type: ParamType.RATIO,
},
]);
assert(!rateManagers.has(collateralBrand));
rateManagers.init(collateralBrand, rateManager);
const poolGovernor = makePoolGovernor(loanParams, rates);
assert(!poolGovernors.has(collateralBrand));
poolGovernors.init(collateralBrand, poolGovernor);

const { creatorFacet: liquidationFacet } = await E(zoe).startInstance(
liquidationInstall,
Expand All @@ -227,8 +165,8 @@ export async function start(zcf) {
want: { Governance: _govOut }, // ownership of the whole stablecoin machine
} = seat.getProposal();
assert(!collateralTypes.has(collateralBrand));
const initialPrice = rateManagerPublic.lookup(INITIAL_PRICE_KEY);
const runAmount = multiplyBy(collateralIn, initialPrice);
// initialPrice is in rates, but only used at creation, so not in governor
const runAmount = multiplyBy(collateralIn, rates.initialPrice);
// arbitrarily, give governance tokens equal to RUN tokens
const govAmount = AmountMath.make(runAmount.value, govBrand);

Expand Down Expand Up @@ -304,10 +242,9 @@ export async function start(zcf) {
runMint,
collateralBrand,
priceAuthority,
rateManagerPublic,
poolGovernor.getParams,
reallocateReward,
timerService,
paramManagerPublic,
liquidationStrategy,
);
collateralTypes.init(collateralBrand, vm);
Expand Down Expand Up @@ -410,7 +347,7 @@ export async function start(zcf) {
getRunIssuer() {
return runIssuer;
},
getParamManager: () => paramManagerPublic,
getFeeParams: feeGovernor.getParams,
});

const { makeCollectFeesInvitation } = makeMakeCollectFeesInvitation(
Expand All @@ -430,8 +367,8 @@ export async function start(zcf) {
getRewardAllocation,
getBootstrapPayment: mintBootstrapPayment(),
makeCollectFeesInvitation,
getParamManager: () => paramManager,
getRateManager: rateManagers.get,
getFeeGovernor: () => feeGovernor,
getPoolGovernor: poolGovernors.get,
});

return harden({ creatorFacet: stablecoinMachine, publicFacet });
Expand Down
Loading

0 comments on commit e478297

Please sign in to comment.