Skip to content

Commit

Permalink
chore: change the loan contract so it accepts a periodNotifier instea…
Browse files Browse the repository at this point in the history
…d of a periodAsyncIterable (Agoric#2115)
  • Loading branch information
katelynsills authored Dec 24, 2020
1 parent 604e3ef commit c25e71b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
14 changes: 10 additions & 4 deletions packages/zoe/src/contracts/loan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '../../../exported';

import { assert } from '@agoric/assert';

import { makeAsyncIterableFromNotifier } from '@agoric/notifier';
import { assertIssuerKeywords } from '../../contractSupport';
import { makeLendInvitation } from './lend';

Expand Down Expand Up @@ -35,9 +36,10 @@ import { makeLendInvitation } from './lend';
* or Multipool Autoswap installation. The publicFacet of the
* instance is used for producing an invitation to sell the
* collateral on liquidation.
* * periodAsyncIterable - the asyncIterable used for notifications
* * periodNotifier - the notifier used for notifications
* that a period has passed, on which compound interest will be
* calculated using the interestRate.
* calculated using the interestRate. Note that this is lossy, and
* therefore could be missing periods. There is a TODO to fix this (https://github.com/Agoric/agoric-sdk/issues/2108)
* * interestRate - the rate in basis points that will be multiplied
* with the debt on every period to compound interest.
*
Expand All @@ -59,15 +61,19 @@ const start = async zcf => {
mmr = 150, // Maintenance Margin Requirement
autoswapInstance,
priceAuthority,
periodAsyncIterable,
periodNotifier,
interestRate,
} = zcf.getTerms();

assert(autoswapInstance, `autoswapInstance must be provided`);
assert(priceAuthority, `priceAuthority must be provided`);
assert(periodAsyncIterable, `periodAsyncIterable must be provided`);
assert(periodNotifier, `periodNotifier must be provided`);
assert(interestRate, `interestRate must be provided`);

// TODO: make this non-lossy (notifier is lossy)
// https://github.com/Agoric/agoric-sdk/issues/2108
const periodAsyncIterable = makeAsyncIterableFromNotifier(periodNotifier);

/** @type {LoanTerms} */
const config = {
mmr,
Expand Down
8 changes: 5 additions & 3 deletions packages/zoe/test/unitTests/contracts/loan/test-borrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ const setupBorrow = async (maxLoanValue = 100) => {
initialLiquidityKeywordRecord,
);

// In the config that the borrow code sees, the periodNotifier has
// been adapted to a periodAsyncIterable
const {
publication: periodUpdater,
subscription: periodSubscription,
subscription: periodAsyncIterable,
} = makeSubscriptionKit();

const interestRate = 5;
Expand All @@ -78,7 +80,7 @@ const setupBorrow = async (maxLoanValue = 100) => {
priceAuthority,
makeCloseLoanInvitation,
makeAddCollateralInvitation,
periodAsyncIterable: periodSubscription,
periodAsyncIterable,
interestRate,
};
// @ts-ignore
Expand All @@ -89,7 +91,7 @@ const setupBorrow = async (maxLoanValue = 100) => {
maxLoan,
lenderUserSeat,
periodUpdater,
periodAsyncIterable: periodSubscription,
periodAsyncIterable,
timer,
priceAuthority,
};
Expand Down
6 changes: 3 additions & 3 deletions packages/zoe/test/unitTests/contracts/loan/test-loan-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import test from 'ava';
import { E } from '@agoric/eventual-send';

import bundleSource from '@agoric/bundle-source';
import { makeSubscriptionKit } from '@agoric/notifier';
import { makeNotifierKit } from '@agoric/notifier';

import { checkDetails, checkPayout } from './helpers';
import { setup } from '../../setupBasicMints';
Expand Down Expand Up @@ -56,13 +56,13 @@ test('loan - lend - exit before borrow', async t => {
timer,
});

const { subscription: periodAsyncIterable } = makeSubscriptionKit();
const { notifier: periodNotifier } = makeNotifierKit();

const terms = {
mmr: 150,
autoswapInstance,
priceAuthority,
periodAsyncIterable,
periodNotifier,
interestRate: 5,
};

Expand Down

0 comments on commit c25e71b

Please sign in to comment.