Skip to content

Commit cd7ebd8

Browse files
Chris-Hibbertmichaelfigkatelynsills
authored
feat: convert the fakePriceAuthority to a PlayerPiano model (#1985)
* feat: convert the fakePriceAuthority to a PlayerPiano model It repeatedly runs through the list of prices provided at setup. This will be used to create a price oracle for the test net. tests updated * fix(fakePriceAuthority): remove some assumptions * chore: fix typo * chore: remove premature inversePriceAuthority.js * feat: add getPriceNotifier, more parameters to fakePriceAuthority * fix: calculate priceOutQuote using priceInQuote * chore: revert bad commit * test: update test-callSpread for playerPiano fakePriceAuthority * chore: clean up unintentional changes * test: update for new fakePriceAuthority * chore: fix tests * chore: lint-fix Co-authored-by: Michael FIG <mfig@agoric.com> Co-authored-by: Kate Sills <kate@agoric.com>
1 parent c646bb6 commit cd7ebd8

17 files changed

+405
-347
lines changed

packages/ERTP/src/localAmountMath.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { E } from '@agoric/eventual-send';
22
import { makeAmountMath } from './amountMath';
33

44
/**
5-
* @param {Issuer} issuer
5+
* @param {ERef<Issuer>} issuer
66
* @returns {Promise<AmountMath>}
77
*/
88
const makeLocalAmountMath = async issuer => {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
import { makePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry';
2+
import { makeFakePriceAuthority } from '@agoric/zoe/tools/fakePriceAuthority';
3+
import { makeLocalAmountMath } from '@agoric/ertp';
24

35
export function buildRootObject(_vatPowers) {
46
return harden({
57
makePriceAuthority: makePriceAuthorityRegistry,
8+
async makeFakePriceAuthority(
9+
issuerIn,
10+
issuerOut,
11+
priceList,
12+
timer,
13+
quoteInterval = undefined,
14+
) {
15+
const [mathIn, mathOut] = await Promise.all([
16+
makeLocalAmountMath(issuerIn),
17+
makeLocalAmountMath(issuerOut),
18+
]);
19+
return makeFakePriceAuthority(
20+
mathIn,
21+
mathOut,
22+
priceList,
23+
timer,
24+
quoteInterval,
25+
);
26+
},
627
});
728
}

packages/zoe/src/contracts/loan/types.js

+15
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@
158158
* Used to tell the contract when a period has occurred
159159
*
160160
* @property {number} interestRate
161+
*
162+
* @property {ContractFacet} zcf
163+
* @property {ConfigMinusGetDebt} configMinusGetDebt
164+
*/
165+
166+
/**
167+
* @typedef {Object} ConfigMinusGetDebt
168+
* @property {ZCFSeat} collateralSeat
169+
* @property {PromiseRecord<any>} liquidationPromiseKit
170+
* @property {number} [mmr]
171+
* @property {InstanceHandle} autoswapInstance
172+
* @property {PriceAuthority} priceAuthority
173+
* @property {AsyncIterable<undefined>} periodAsyncIterable
174+
* @property {number} interestRate
175+
* @property {ZCFSeat} lenderSeat
161176
*/
162177

163178
/**

packages/zoe/test/fakePriceAuthority.js

-156
This file was deleted.

packages/zoe/test/unitTests/contracts/loan/test-addCollateral.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import '@agoric/install-ses';
88
import test from 'ava';
99

1010
import { makeAddCollateralInvitation } from '../../../../src/contracts/loan/addCollateral';
11-
import { makeFakePriceAuthority } from '../../../fakePriceAuthority';
11+
import { makeFakePriceAuthority } from '../../../../tools/fakePriceAuthority';
1212
import buildManualTimer from '../../../../tools/manualTimer';
1313

1414
import {
@@ -35,21 +35,14 @@ test('makeAddCollateralInvitation', async t => {
3535

3636
const { zcfSeat: lenderSeat } = await zcf.makeEmptySeatKit();
3737

38-
const amountMaths = new Map();
39-
amountMaths.set(
40-
collateralKit.brand.getAllegedName(),
41-
collateralKit.amountMath,
42-
);
43-
amountMaths.set(loanKit.brand.getAllegedName(), loanKit.amountMath);
44-
45-
const priceSchedule = {};
4638
const timer = buildManualTimer(console.log);
4739

48-
const priceAuthority = makeFakePriceAuthority(
49-
amountMaths,
50-
priceSchedule,
40+
const priceAuthority = makeFakePriceAuthority({
41+
mathIn: collateralKit.amountMath,
42+
mathOut: loanKit.amountMath,
43+
priceList: [],
5144
timer,
52-
);
45+
});
5346

5447
const autoswapInstance = {};
5548
const getDebt = () => loanKit.amountMath.make(100);

packages/zoe/test/unitTests/contracts/loan/test-borrow.js

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ts-check
1+
// @ts-check
22

33
import '../../../../exported';
44

@@ -22,7 +22,7 @@ import {
2222
makeAutoswapInstance,
2323
} from './helpers';
2424

25-
import { makeFakePriceAuthority } from '../../../fakePriceAuthority';
25+
import { makeFakePriceAuthority } from '../../../../tools/fakePriceAuthority';
2626
import buildManualTimer from '../../../../tools/manualTimer';
2727

2828
import { makeBorrowInvitation } from '../../../../src/contracts/loan/borrow';
@@ -41,24 +41,16 @@ const setupBorrow = async (maxLoanValue = 100) => {
4141
);
4242
const mmr = 150;
4343

44-
const amountMaths = new Map();
45-
amountMaths.set(
46-
collateralKit.brand.getAllegedName(),
47-
collateralKit.amountMath,
48-
);
49-
amountMaths.set(loanKit.brand.getAllegedName(), loanKit.amountMath);
50-
51-
const priceSchedule = [
52-
{ time: 0, price: 2 },
53-
{ time: 1, price: 1 },
54-
];
44+
const priceList = [2, 1, 1, 1];
5545
const timer = buildManualTimer(console.log);
5646

57-
const priceAuthority = makeFakePriceAuthority(
58-
amountMaths,
59-
priceSchedule,
47+
const priceAuthority = await makeFakePriceAuthority({
48+
mathIn: collateralKit.amountMath,
49+
mathOut: loanKit.amountMath,
50+
priceList,
6051
timer,
61-
);
52+
});
53+
await timer.tick();
6254

6355
const initialLiquidityKeywordRecord = {
6456
Central: loanKit.amountMath.make(10000),
@@ -192,7 +184,7 @@ test('borrow getLiquidationPromise', async t => {
192184

193185
const collateralGiven = collateralKit.amountMath.make(100);
194186

195-
const quoteIssuer = await E(priceAuthority).getQuoteIssuer(
187+
const quoteIssuer = E(priceAuthority).getQuoteIssuer(
196188
collateralKit.brand,
197189
loanKit.brand,
198190
);
@@ -214,7 +206,7 @@ test('borrow getLiquidationPromise', async t => {
214206
amountIn: collateralGiven,
215207
amountOut: loanKit.amountMath.make(100),
216208
timer,
217-
timestamp: 1,
209+
timestamp: 2,
218210
},
219211
]),
220212
),
@@ -274,7 +266,7 @@ test('borrow, then addCollateral, then getLiquidationPromise', async t => {
274266
amountIn: collateralGiven,
275267
amountOut: loanKit.amountMath.make(103),
276268
timer,
277-
timestamp: 2,
269+
timestamp: 3,
278270
},
279271
]),
280272
),

packages/zoe/test/unitTests/contracts/loan/test-loan-e2e.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { makeSubscriptionKit } from '@agoric/notifier';
1212

1313
import { checkDetails, checkPayout } from './helpers';
1414
import { setup } from '../../setupBasicMints';
15-
import { makeFakePriceAuthority } from '../../../fakePriceAuthority';
15+
import { makeFakePriceAuthority } from '../../../../tools/fakePriceAuthority';
1616
import buildManualTimer from '../../../../tools/manualTimer';
1717

1818
const loanRoot = `${__dirname}/../../../../src/contracts/loan/`;
@@ -47,21 +47,14 @@ test('loan - lend - exit before borrow', async t => {
4747
Loan: loanKit.issuer,
4848
});
4949

50-
const amountMaths = new Map();
51-
amountMaths.set(
52-
collateralKit.brand.getAllegedName(),
53-
collateralKit.amountMath,
54-
);
55-
amountMaths.set(loanKit.brand.getAllegedName(), loanKit.amountMath);
56-
57-
const priceSchedule = {};
5850
const timer = buildManualTimer(console.log);
5951

60-
const priceAuthority = makeFakePriceAuthority(
61-
amountMaths,
62-
priceSchedule,
52+
const priceAuthority = makeFakePriceAuthority({
53+
mathIn: collateralKit.amountMath,
54+
mathOut: loanKit.amountMath,
55+
priceList: [],
6356
timer,
64-
);
57+
});
6558

6659
const { subscription: periodAsyncIterable } = makeSubscriptionKit();
6760

packages/zoe/test/unitTests/contracts/test-automaticRefund.js

-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ test('zoe - alice tries to complete after completion has already occurred', asyn
339339

340340
await E(aliceSeat).getOfferResult();
341341

342-
console.log('EXPECTED ERROR: seat has been exited >>>');
343342
await t.throwsAsync(() => E(aliceSeat).tryExit(), {
344343
message: /seat has been exited/,
345344
});

packages/zoe/test/unitTests/contracts/test-brokenContract.js

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ test('zoe - brokenAutomaticRefund', async t => {
2424

2525
// Alice tries to create an instance, but the contract is badly
2626
// written.
27-
console.log(
28-
'EXPECTED ERROR: The contract did not correctly return a creatorInvitation',
29-
);
3027
await t.throwsAsync(
3128
() => zoe.startInstance(installation, issuerKeywordRecord),
3229
{ message: 'The contract did not correctly return a creatorInvitation' },

0 commit comments

Comments
 (0)