Skip to content

Commit

Permalink
#40 Moved setup methods to setup.js, started using setup methods for …
Browse files Browse the repository at this point in the history
…amm from the econ-behaviors.js, started updating params.js
  • Loading branch information
anilhelvaci committed Oct 24, 2022
1 parent 807b814 commit b6aed7e
Show file tree
Hide file tree
Showing 3 changed files with 287 additions and 385 deletions.
34 changes: 24 additions & 10 deletions contract/src/lendingPool/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CONTRACT_ELECTORATE,
ParamTypes
} from '@agoric/governance';
import { makeStoredPublishKit } from '@agoric/notifier';

export const CHARGING_PERIOD_KEY = 'ChargingPeriod';
export const RECORDING_PERIOD_KEY = 'RecordingPeriod';
Expand Down Expand Up @@ -43,30 +44,36 @@ const makeLoanParams = (loanTiming, rates) => {
};

/**
* @param {ERef<StorageNode>} storageNode
* @param {ERef<Marshaller>} marshaller
* @param {LendingPoolTiming} initialValues
*/
const makeLoanTimingManager = initialValues => {
return makeParamManagerSync({
const makeLoanTimingManager = (storageNode, marshaller, initialValues) => {
return makeParamManagerSync(makeStoredPublishKit(storageNode, marshaller),{
[CHARGING_PERIOD_KEY]: [ParamTypes.NAT, initialValues.chargingPeriod],
[RECORDING_PERIOD_KEY]: [ParamTypes.NAT, initialValues.recordingPeriod],
[PRICE_CHECK_PERIOD_KEY]: [ParamTypes.NAT, initialValues.priceCheckPeriod] // TODO this now deprecated and not being used anywhere, should remove it
})
};

/**
* @param {ERef<StorageNode>} storageNode
* @param {ERef<Marshaller>} marshaller
* @param {Rates} rates
*/
const makeLoanParamManager = rates => {
return makeParamManagerSync({
const makeLoanParamManager = (storageNode, marshaller, rates) => {
return makeParamManagerSync(makeStoredPublishKit(storageNode, marshaller), {
[LIQUIDATION_MARGIN_KEY]: [ParamTypes.RATIO, rates.liquidationMargin],
})
};

/**
* @param {ERef<StorageNode>} storageNode
* @param {ERef<Marshaller>} marshaller
* @param {Rates} rates
*/
const makePoolParamManager = rates => {
return makeParamManagerSync({
const makePoolParamManager = (storageNode, marshaller, rates) => {
return makeParamManagerSync(makeStoredPublishKit(storageNode, marshaller), {
[LIQUIDATION_MARGIN_KEY]: [ParamTypes.RATIO, rates.liquidationMargin],
[INITIAL_EXCHANGE_RATE_KEY]: [ParamTypes.RATIO, rates.initialExchangeRate],
[BASE_RATE_KEY]: [ParamTypes.RATIO, rates.baseRate],
Expand All @@ -76,6 +83,8 @@ const makePoolParamManager = rates => {
};

/**
* @param {ERef<StorageNode>} storageNode
* @param {ERef<Marshaller>} marshaller
* @param {ERef<ZoeService>} zoe
* @param {Invitation} electorateInvitation
* @returns {Promise<{
Expand All @@ -85,14 +94,18 @@ const makePoolParamManager = rates => {
* updateElectorate: (invitation: Invitation) => void,
* }>}
*/
const makeElectorateParamManager = async (zoe, electorateInvitation) => {
return makeParamManager({
const makeElectorateParamManager = async (zoe, storageNode, marshaller, electorateInvitation) => {
return makeParamManager(makeStoredPublishKit(storageNode, marshaller), {
[CONTRACT_ELECTORATE]: [ParamTypes.INVITATION, electorateInvitation],
},
zoe);
};

/**
* @param {{
* storageNode,
* marshaller
* }} publishKitParams
* @param {ERef<PriceManager>} priceManager
* @param {LoanTiming} loanTiming
* @param {Installation} liquidationInstall
Expand All @@ -104,6 +117,7 @@ const makeElectorateParamManager = async (zoe, electorateInvitation) => {
* @param {bigint=} bootstrapPaymentValue
*/
const makeGovernedTerms = (
{ storageNode, marshaller },
priceManager,
loanTiming,
liquidationInstall,
Expand All @@ -114,9 +128,9 @@ const makeGovernedTerms = (
compareCurrencyBrand,
bootstrapPaymentValue = 0n,
) => {
const timingParamMgr = makeLoanTimingManager(loanTiming);
const timingParamMgr = makeLoanTimingManager(storageNode, marshaller, loanTiming);

const rateParamMgr = makeLoanParamManager(rates);
const rateParamMgr = makeLoanParamManager(storageNode, marshaller, rates);

return harden({
ammPublicFacet,
Expand Down
Loading

0 comments on commit b6aed7e

Please sign in to comment.