Skip to content

Commit

Permalink
#40 Made paramManagers work again, removed copy-paste code and used i…
Browse files Browse the repository at this point in the history
…mported ones instead, should update timer.tick() and test numbers
  • Loading branch information
anilhelvaci committed Oct 25, 2022
1 parent b6aed7e commit 208577e
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 53 deletions.
8 changes: 5 additions & 3 deletions contract/src/lendingPool/lendingPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const trace = makeTracer('LendingPool');
* since we might add a DAO later.
*
* @param {ZCF} zcf
* @param {{initialPoserInvitation: Invitation}} privateArgs
* @param {{initialPoserInvitation: Invitation, storageNode: ERef<StorageNode>, marshaller: ERef<Marshaller>}} privateArgs
*/
export const start = async (zcf, privateArgs) => {
/** @type {LendingPoolTerms}*/
Expand All @@ -88,9 +88,11 @@ export const start = async (zcf, privateArgs) => {
compareCurrencyBrand,
} = terms;

const { initialPoserInvitation } = privateArgs;
const { initialPoserInvitation, storageNode, marshaller } = privateArgs;
const electorateParamManager = await makeElectorateParamManager(
E(zcf).getZoeService(),
storageNode,
marshaller,
initialPoserInvitation,
);

Expand Down Expand Up @@ -169,7 +171,7 @@ export const start = async (zcf, privateArgs) => {
initialExchangeRate,
});

const poolParamManager = makePoolParamManager(ratesUpdated);
const poolParamManager = makePoolParamManager(storageNode, marshaller, ratesUpdated);
poolParamManagers.init(underlyingBrand, poolParamManager);

const [startTimeStamp, priceAuthNotifier] = await Promise.all([
Expand Down
4 changes: 2 additions & 2 deletions contract/src/lendingPool/loanStoreUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { keyEQ, keyLT } from '@agoric/store';
import { keyEQ, keyLT, makeScalarMap } from '@agoric/store';
import { AmountMath } from '@agoric/ertp';
import { toVaultKey } from '@agoric/inter-protocol/src/vaultFactory/storeUtils.js';
import { makeOrderedVaultStore } from '@agoric/inter-protocol/src/vaultFactory/orderedVaultStore.js';
Expand Down Expand Up @@ -26,7 +26,7 @@ import { LoanPhase } from './loan.js'
* @return {LoanStore}
*/
export const makeLoanStoreUtils = () => {
const store = makeOrderedVaultStore('store');
const store = makeOrderedVaultStore(makeScalarMap('store'));
let firstKey;
let reschedule;

Expand Down
10 changes: 5 additions & 5 deletions contract/src/lendingPool/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CONTRACT_ELECTORATE,
ParamTypes
} from '@agoric/governance';
import { makeStoredPublishKit } from '@agoric/notifier';
import { makeStoredPublisherKit } from '@agoric/notifier';

export const CHARGING_PERIOD_KEY = 'ChargingPeriod';
export const RECORDING_PERIOD_KEY = 'RecordingPeriod';
Expand Down Expand Up @@ -49,7 +49,7 @@ const makeLoanParams = (loanTiming, rates) => {
* @param {LendingPoolTiming} initialValues
*/
const makeLoanTimingManager = (storageNode, marshaller, initialValues) => {
return makeParamManagerSync(makeStoredPublishKit(storageNode, marshaller),{
return makeParamManagerSync(makeStoredPublisherKit(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
Expand All @@ -62,7 +62,7 @@ const makeLoanTimingManager = (storageNode, marshaller, initialValues) => {
* @param {Rates} rates
*/
const makeLoanParamManager = (storageNode, marshaller, rates) => {
return makeParamManagerSync(makeStoredPublishKit(storageNode, marshaller), {
return makeParamManagerSync(makeStoredPublisherKit(storageNode, marshaller), {
[LIQUIDATION_MARGIN_KEY]: [ParamTypes.RATIO, rates.liquidationMargin],
})
};
Expand All @@ -73,7 +73,7 @@ const makeLoanParamManager = (storageNode, marshaller, rates) => {
* @param {Rates} rates
*/
const makePoolParamManager = (storageNode, marshaller, rates) => {
return makeParamManagerSync(makeStoredPublishKit(storageNode, marshaller), {
return makeParamManagerSync(makeStoredPublisherKit(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 @@ -95,7 +95,7 @@ const makePoolParamManager = (storageNode, marshaller, rates) => {
* }>}
*/
const makeElectorateParamManager = async (zoe, storageNode, marshaller, electorateInvitation) => {
return makeParamManager(makeStoredPublishKit(storageNode, marshaller), {
return makeParamManager(makeStoredPublisherKit(storageNode, marshaller), {
[CONTRACT_ELECTORATE]: [ParamTypes.INVITATION, electorateInvitation],
},
zoe);
Expand Down
3 changes: 2 additions & 1 deletion contract/src/lendingPool/poolManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ export const makePoolManager = (
},
};

observeNotifier(periodNotifier, timeObserver);
observeNotifier(periodNotifier, timeObserver)
.catch(error => console.log('Error building observer', error));

/** @type {ManagerFacet} */
const managerFacet = harden({
Expand Down
6 changes: 3 additions & 3 deletions contract/test/lendingPool/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { makeTracer } from '@agoric/run-protocol/src/makeTracer.js';
import * as Collect from '@agoric/run-protocol/src/collect.js';
import { floorDivideBy } from '@agoric/zoe/src/contractSupport/ratio.js';
import { makeManualPriceAuthority } from '@agoric/zoe/tools/manualPriceAuthority.js';
import { waitForPromisesToSettle } from './test-lendingPool.js';
import { eventLoopIteration } from '@agoric/zoe/tools/eventLoopIteration.js';

const trace = makeTracer('Helper');
const BASIS_POINTS = 10000n;
Expand Down Expand Up @@ -135,7 +135,7 @@ export const adjust = async (zoe, loan, collateralConfig = undefined, debtConfig
{ collateralUnderlyingBrand },
);

await waitForPromisesToSettle();
await eventLoopIteration();

return seat;
};
Expand Down Expand Up @@ -179,7 +179,7 @@ export const closeLoan = async (
proposal,
payment,
);
await waitForPromisesToSettle();
await eventLoopIteration();

return seat;
};
Expand Down
8 changes: 4 additions & 4 deletions contract/test/lendingPool/lendingPoolScenrioHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from './helpers.js';
import { AmountMath } from '@agoric/ertp';
import { Nat } from '@agoric/nat';
import { waitForPromisesToSettle } from './test-lendingPool.js';
import { eventLoopIteration } from '@agoric/zoe/tools/eventLoopIteration.js';
import { makeScalarMap } from '@agoric/store';
import { floorDivideBy, floorMultiplyBy, makeRatio, oneMinus } from '@agoric/zoe/src/contractSupport/index.js';

Expand Down Expand Up @@ -209,7 +209,7 @@ export const makeLendingPoolScenarioHelpers = (
{ collateralUnderlyingBrand },
);

await waitForPromisesToSettle();
await eventLoopIteration();

return seat;
};
Expand Down Expand Up @@ -243,7 +243,7 @@ export const makeLendingPoolScenarioHelpers = (
proposal,
payment,
);
await waitForPromisesToSettle();
await eventLoopIteration();

return seat;
};
Expand Down Expand Up @@ -282,7 +282,7 @@ export const makeLendingPoolScenarioHelpers = (
redeemPaymentRecord
);

await waitForPromisesToSettle();
await eventLoopIteration();
return redeemUserSeat
};

Expand Down
13 changes: 9 additions & 4 deletions contract/test/lendingPool/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const setupServices = async (
ammPoolsConfig = undefined,
) => {
const {
zoe,
farZoeKit: { zoe },
compareCurrencyKit: { brand: compCurrencyBrand },
vanKit: { mint: vanMint },
panKit: { mint: panMint },
Expand Down Expand Up @@ -228,7 +228,9 @@ export const startLendingPool = async (
instance.consume.economicCommittee,
contractGovernor,
]);

const ammPublicFacet = await E(zoe).getPublicFacet(ammInstance);
console.log('ammPublicFacet', ammPublicFacet)
const priceManager = await priceManagerP;
const timer = await chainTimerService;
const storageNode = await makeStorageNodeChild(chainStorage, STORAGE_PATH);
Expand All @@ -246,23 +248,26 @@ export const startLendingPool = async (
compareBrand,
undefined
);
// console.log("loanFactoryTerms", loanFactoryTerms)

const governorTerms = harden({
timer,
electorateInstance,
governedContractInstallation: installations.LendingPool,
governed: {
terms: loanFactoryTerms,
issuerKeywordRecord: {},
privateArgs: harden({ initialPoserInvitation }),
},
});
const { creatorFacet: governorCreatorFacet, instance: governorInstance } =
await E(zoe).startInstance(
contractGovernorInstall,
undefined,
governorTerms,
harden({ electorateCreatorFacet }),
harden({
electorateCreatorFacet, governed: {
initialPoserInvitation, storageNode, marshaller,
},
}),
);

const [lendingPoolInstance, lendingPoolCreator] = await Promise.all([
Expand Down
Loading

0 comments on commit 208577e

Please sign in to comment.