Skip to content

Commit

Permalink
chore(run-protocol): type documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 25, 2022
1 parent 80f0076 commit 402c3aa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/run-protocol/src/vaultFactory/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/

/**
* @typedef {Object} vaultFactoryPublicFacet - the public facet
* @typedef {Object} VaultFactoryPublicFacet - the public facet
* @property {() => Promise<Invitation>} makeLoanInvitation
* @property {() => Promise<Array<Collateral>>} getCollaterals
* @property {() => Issuer} getRunIssuer
Expand Down
15 changes: 11 additions & 4 deletions packages/run-protocol/src/vaultFactory/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ export const makeVaultKit = (
}
};

/**
* @param {Amount} newDebt
*/
const liquidated = newDebt => {
runDebt = newDebt;
vaultState = VaultState.CLOSED;
Expand Down Expand Up @@ -464,8 +467,12 @@ export const makeVaultKit = (
return { notifier };
};

/**
* @param {bigint} currentTime
* @returns {Amount} rate of interest used for accrual period
*/
const accrueInterestAndAddToPool = currentTime => {
const interestKit = interestCalculator.calculateReportingPeriod(
const debtStatus = interestCalculator.calculateReportingPeriod(
{
latestInterestUpdate,
newDebt: runDebt,
Expand All @@ -474,13 +481,13 @@ export const makeVaultKit = (
currentTime,
);

if (interestKit.latestInterestUpdate === latestInterestUpdate) {
if (debtStatus.latestInterestUpdate === latestInterestUpdate) {
return AmountMath.makeEmpty(runBrand);
}

({ latestInterestUpdate, newDebt: runDebt } = interestKit);
({ latestInterestUpdate, newDebt: runDebt } = debtStatus);
updateUiState();
return interestKit.interest;
return debtStatus.interest;
};

const getDebtAmount = () => runDebt;
Expand Down
2 changes: 1 addition & 1 deletion packages/run-protocol/src/vaultFactory/vaultFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export const start = async (zcf, privateArgs) => {
return vaultParamManagers.get(paramDesc.collateralBrand).getParams();
};

/** @type {vaultFactoryPublicFacet} */
/** @type {VaultFactoryPublicFacet} */
const publicFacet = Far('vaultFactory public facet', {
makeLoanInvitation,
getCollaterals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ import { AmountMath } from '@agoric/ertp';

const { details: X, quote: q } = assert;

/**
*
* @param {(msg: any)=> void} log
* @param {ZoeService} zoe
* @param {Brand[]} brands
* @param {Payment[]} payments
* @param {ManualTimer} timer
* @returns {Promise<{startTest: Function}>}
*/
const build = async (log, zoe, brands, payments, timer) => {
const [moolaBrand] = brands;
const [moolaPayment] = payments;

/**
* @param {VaultFactoryPublicFacet} vaultFactory
*/
const oneLoanWithInterest = async vaultFactory => {
log(`=> alice.oneLoanWithInterest called`);

Expand All @@ -34,6 +46,11 @@ const build = async (log, zoe, brands, payments, timer) => {
};

return Far('build', {
/**
* @param {string} testName
* @param {VaultFactoryPublicFacet} vaultFactory
* @returns {Promise<void>}
*/
startTest: async (testName, vaultFactory) => {
switch (testName) {
case 'oneLoanWithInterest': {
Expand All @@ -47,8 +64,12 @@ const build = async (log, zoe, brands, payments, timer) => {
});
};

/**
* @param {VatPowers & {testLog: *}} vatPowers
*/
export function buildRootObject(vatPowers) {
return Far('root', {
build: (...args) => build(vatPowers.testLog, ...args),
build: (zoe, brands, payments, timer) =>
build(vatPowers.testLog, zoe, brands, payments, timer),
});
}

0 comments on commit 402c3aa

Please sign in to comment.