diff --git a/packages/zoe/src/contracts/loan/index.js b/packages/zoe/src/contracts/loan/index.js index 9a138f645a8..777dd17a6c4 100644 --- a/packages/zoe/src/contracts/loan/index.js +++ b/packages/zoe/src/contracts/loan/index.js @@ -3,6 +3,7 @@ import '../../../exported'; import { assert } from '@agoric/assert'; +import { makeAsyncIterableFromNotifier } from '@agoric/notifier'; import { assertIssuerKeywords } from '../../contractSupport'; import { makeLendInvitation } from './lend'; @@ -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. * @@ -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, diff --git a/packages/zoe/test/unitTests/contracts/loan/test-borrow.js b/packages/zoe/test/unitTests/contracts/loan/test-borrow.js index 175920d5288..44e332bff53 100644 --- a/packages/zoe/test/unitTests/contracts/loan/test-borrow.js +++ b/packages/zoe/test/unitTests/contracts/loan/test-borrow.js @@ -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; @@ -78,7 +80,7 @@ const setupBorrow = async (maxLoanValue = 100) => { priceAuthority, makeCloseLoanInvitation, makeAddCollateralInvitation, - periodAsyncIterable: periodSubscription, + periodAsyncIterable, interestRate, }; // @ts-ignore @@ -89,7 +91,7 @@ const setupBorrow = async (maxLoanValue = 100) => { maxLoan, lenderUserSeat, periodUpdater, - periodAsyncIterable: periodSubscription, + periodAsyncIterable, timer, priceAuthority, }; diff --git a/packages/zoe/test/unitTests/contracts/loan/test-loan-e2e.js b/packages/zoe/test/unitTests/contracts/loan/test-loan-e2e.js index 92ec05abdf0..b1a72211f47 100644 --- a/packages/zoe/test/unitTests/contracts/loan/test-loan-e2e.js +++ b/packages/zoe/test/unitTests/contracts/loan/test-loan-e2e.js @@ -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'; @@ -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, };