Skip to content

Commit

Permalink
feat: convert the fakePriceAuthority to a PlayerPiano model (#1985)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Nov 6, 2020
1 parent c646bb6 commit cd7ebd8
Show file tree
Hide file tree
Showing 17 changed files with 405 additions and 347 deletions.
2 changes: 1 addition & 1 deletion packages/ERTP/src/localAmountMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { E } from '@agoric/eventual-send';
import { makeAmountMath } from './amountMath';

/**
* @param {Issuer} issuer
* @param {ERef<Issuer>} issuer
* @returns {Promise<AmountMath>}
*/
const makeLocalAmountMath = async issuer => {
Expand Down
21 changes: 21 additions & 0 deletions packages/cosmic-swingset/lib/ag-solo/vats/vat-priceAuthority.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import { makePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry';
import { makeFakePriceAuthority } from '@agoric/zoe/tools/fakePriceAuthority';
import { makeLocalAmountMath } from '@agoric/ertp';

export function buildRootObject(_vatPowers) {
return harden({
makePriceAuthority: makePriceAuthorityRegistry,
async makeFakePriceAuthority(
issuerIn,
issuerOut,
priceList,
timer,
quoteInterval = undefined,
) {
const [mathIn, mathOut] = await Promise.all([
makeLocalAmountMath(issuerIn),
makeLocalAmountMath(issuerOut),
]);
return makeFakePriceAuthority(
mathIn,
mathOut,
priceList,
timer,
quoteInterval,
);
},
});
}
15 changes: 15 additions & 0 deletions packages/zoe/src/contracts/loan/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@
* Used to tell the contract when a period has occurred
*
* @property {number} interestRate
*
* @property {ContractFacet} zcf
* @property {ConfigMinusGetDebt} configMinusGetDebt
*/

/**
* @typedef {Object} ConfigMinusGetDebt
* @property {ZCFSeat} collateralSeat
* @property {PromiseRecord<any>} liquidationPromiseKit
* @property {number} [mmr]
* @property {InstanceHandle} autoswapInstance
* @property {PriceAuthority} priceAuthority
* @property {AsyncIterable<undefined>} periodAsyncIterable
* @property {number} interestRate
* @property {ZCFSeat} lenderSeat
*/

/**
Expand Down
156 changes: 0 additions & 156 deletions packages/zoe/test/fakePriceAuthority.js

This file was deleted.

19 changes: 6 additions & 13 deletions packages/zoe/test/unitTests/contracts/loan/test-addCollateral.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '@agoric/install-ses';
import test from 'ava';

import { makeAddCollateralInvitation } from '../../../../src/contracts/loan/addCollateral';
import { makeFakePriceAuthority } from '../../../fakePriceAuthority';
import { makeFakePriceAuthority } from '../../../../tools/fakePriceAuthority';
import buildManualTimer from '../../../../tools/manualTimer';

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

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

const amountMaths = new Map();
amountMaths.set(
collateralKit.brand.getAllegedName(),
collateralKit.amountMath,
);
amountMaths.set(loanKit.brand.getAllegedName(), loanKit.amountMath);

const priceSchedule = {};
const timer = buildManualTimer(console.log);

const priceAuthority = makeFakePriceAuthority(
amountMaths,
priceSchedule,
const priceAuthority = makeFakePriceAuthority({
mathIn: collateralKit.amountMath,
mathOut: loanKit.amountMath,
priceList: [],
timer,
);
});

const autoswapInstance = {};
const getDebt = () => loanKit.amountMath.make(100);
Expand Down
32 changes: 12 additions & 20 deletions packages/zoe/test/unitTests/contracts/loan/test-borrow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ts-check
// @ts-check

import '../../../../exported';

Expand All @@ -22,7 +22,7 @@ import {
makeAutoswapInstance,
} from './helpers';

import { makeFakePriceAuthority } from '../../../fakePriceAuthority';
import { makeFakePriceAuthority } from '../../../../tools/fakePriceAuthority';
import buildManualTimer from '../../../../tools/manualTimer';

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

const amountMaths = new Map();
amountMaths.set(
collateralKit.brand.getAllegedName(),
collateralKit.amountMath,
);
amountMaths.set(loanKit.brand.getAllegedName(), loanKit.amountMath);

const priceSchedule = [
{ time: 0, price: 2 },
{ time: 1, price: 1 },
];
const priceList = [2, 1, 1, 1];
const timer = buildManualTimer(console.log);

const priceAuthority = makeFakePriceAuthority(
amountMaths,
priceSchedule,
const priceAuthority = await makeFakePriceAuthority({
mathIn: collateralKit.amountMath,
mathOut: loanKit.amountMath,
priceList,
timer,
);
});
await timer.tick();

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

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

const quoteIssuer = await E(priceAuthority).getQuoteIssuer(
const quoteIssuer = E(priceAuthority).getQuoteIssuer(
collateralKit.brand,
loanKit.brand,
);
Expand All @@ -214,7 +206,7 @@ test('borrow getLiquidationPromise', async t => {
amountIn: collateralGiven,
amountOut: loanKit.amountMath.make(100),
timer,
timestamp: 1,
timestamp: 2,
},
]),
),
Expand Down Expand Up @@ -274,7 +266,7 @@ test('borrow, then addCollateral, then getLiquidationPromise', async t => {
amountIn: collateralGiven,
amountOut: loanKit.amountMath.make(103),
timer,
timestamp: 2,
timestamp: 3,
},
]),
),
Expand Down
19 changes: 6 additions & 13 deletions packages/zoe/test/unitTests/contracts/loan/test-loan-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { makeSubscriptionKit } from '@agoric/notifier';

import { checkDetails, checkPayout } from './helpers';
import { setup } from '../../setupBasicMints';
import { makeFakePriceAuthority } from '../../../fakePriceAuthority';
import { makeFakePriceAuthority } from '../../../../tools/fakePriceAuthority';
import buildManualTimer from '../../../../tools/manualTimer';

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

const amountMaths = new Map();
amountMaths.set(
collateralKit.brand.getAllegedName(),
collateralKit.amountMath,
);
amountMaths.set(loanKit.brand.getAllegedName(), loanKit.amountMath);

const priceSchedule = {};
const timer = buildManualTimer(console.log);

const priceAuthority = makeFakePriceAuthority(
amountMaths,
priceSchedule,
const priceAuthority = makeFakePriceAuthority({
mathIn: collateralKit.amountMath,
mathOut: loanKit.amountMath,
priceList: [],
timer,
);
});

const { subscription: periodAsyncIterable } = makeSubscriptionKit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ test('zoe - alice tries to complete after completion has already occurred', asyn

await E(aliceSeat).getOfferResult();

console.log('EXPECTED ERROR: seat has been exited >>>');
await t.throwsAsync(() => E(aliceSeat).tryExit(), {
message: /seat has been exited/,
});
Expand Down
3 changes: 0 additions & 3 deletions packages/zoe/test/unitTests/contracts/test-brokenContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ test('zoe - brokenAutomaticRefund', async t => {

// Alice tries to create an instance, but the contract is badly
// written.
console.log(
'EXPECTED ERROR: The contract did not correctly return a creatorInvitation',
);
await t.throwsAsync(
() => zoe.startInstance(installation, issuerKeywordRecord),
{ message: 'The contract did not correctly return a creatorInvitation' },
Expand Down
Loading

0 comments on commit cd7ebd8

Please sign in to comment.