Skip to content

Commit

Permalink
fix: userSeat allocation only for testing (#5826)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
erights and mergify[bot] authored Jul 27, 2022
1 parent 3b12fbb commit 9cb561b
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ const start = async zcf => {
{ stopAfter: debt },
);
await Promise.all([E(liqSeat).getOfferResult(), deposited]);
const amounts = await E(liqSeat).getCurrentAllocation();

// This uses getCurrentAllocationJig only to support testing, so is ok
const amounts = await E(liqSeat).getCurrentAllocationJig();
trace('offerResult', { amounts });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ test('amm add and remove liquidity', async t => {
};
await tracker.assertChange(poolLiquidity);

const alloc = await E(addLiquiditySeat).getCurrentAllocation();
const alloc = await E(addLiquiditySeat).getCurrentAllocationJig();
t.deepEqual(alloc, {
Central: central(0n),
Liquidity: AmountMath.make(liquidityBrand, 1_499_999_000n),
Expand Down Expand Up @@ -496,7 +496,7 @@ test('add wrong liquidity', async t => {
}),
);

const alloc = await E(addLiquiditySeat).getCurrentAllocation();
const alloc = await E(addLiquiditySeat).getCurrentAllocationJig();
t.deepEqual(alloc, {
Central: central(0n),
Liquidity: AmountMath.make(liquidityBrand, 1_499_999_000n),
Expand Down
5 changes: 3 additions & 2 deletions packages/inter-protocol/test/psm/test-psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ test('simple trades', async t => {
E(limitedCreatorFacet).makeCollectFeesInvitation(),
);
await E(collectFeesSeat).getOfferResult();
const feePayoutAmount = await E.get(E(collectFeesSeat).getCurrentAllocation())
.RUN;
const feePayoutAmount = await E.get(
E(collectFeesSeat).getCurrentAllocationJig(),
).RUN;
const expectedFee = AmountMath.make(run.brand, 50000n);
trace('Reward Fee', { feePayoutAmount, expectedFee });
t.truthy(AmountMath.isEqual(feePayoutAmount, expectedFee));
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/test/vaultFactory/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export const makeManagerDriver = async (
);
currentOfferResult = await E(currentSeat).getOfferResult();
if (expected) {
const payouts = await E(currentSeat).getCurrentAllocation();
const payouts = await E(currentSeat).getCurrentAllocationJig();
trace(t, 'AMM payouts', payouts);
t.like(payouts, expected);
}
Expand Down
53 changes: 28 additions & 25 deletions packages/inter-protocol/test/vaultFactory/test-vaultFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ test('first', async t => {
);
trace(t, 'correct debt', debtAmount);

const { RUN: lentAmount } = await E(vaultSeat).getCurrentAllocation();
const { RUN: lentAmount } = await E(vaultSeat).getCurrentAllocationJig();
const loanProceeds = await E(vaultSeat).getPayouts();
const runLent = await loanProceeds.RUN;
t.deepEqual(lentAmount, loanAmount, 'received 47 RUN');
Expand Down Expand Up @@ -611,7 +611,7 @@ test('price drop', async t => {
debt: AmountMath.add(loanAmount, fee),
interest: makeRatio(100n, run.brand),
});
const { RUN: lentAmount } = await E(vaultSeat).getCurrentAllocation();
const { RUN: lentAmount } = await E(vaultSeat).getCurrentAllocationJig();
t.truthy(AmountMath.isEqual(lentAmount, loanAmount), 'received 470 RUN');
t.deepEqual(
await E(vault).getCollateralAmount(),
Expand Down Expand Up @@ -751,7 +751,7 @@ test('price falls precipitously', async t => {
);
trace(t, 'correct debt', debtAmount);

const { RUN: lentAmount } = await E(userSeat).getCurrentAllocation();
const { RUN: lentAmount } = await E(userSeat).getCurrentAllocationJig();
t.deepEqual(lentAmount, loanAmount, 'received 470 RUN');
t.deepEqual(
await E(vault).getCollateralAmount(),
Expand Down Expand Up @@ -928,7 +928,7 @@ test('interest on multiple vaults', async t => {
'vault lent 4700 RUN + fees',
);

const { RUN: lentAmount } = await E(aliceLoanSeat).getCurrentAllocation();
const { RUN: lentAmount } = await E(aliceLoanSeat).getCurrentAllocationJig();
const loanProceeds = await E(aliceLoanSeat).getPayouts();
t.deepEqual(lentAmount, aliceLoanAmount, 'received 4700 RUN');

Expand Down Expand Up @@ -967,7 +967,7 @@ test('interest on multiple vaults', async t => {
'vault lent 3200 RUN + fees',
);

const { RUN: bobLentAmount } = await E(bobLoanSeat).getCurrentAllocation();
const { RUN: bobLentAmount } = await E(bobLoanSeat).getCurrentAllocationJig();
const bobLoanProceeds = await E(bobLoanSeat).getPayouts();
t.deepEqual(bobLentAmount, bobLoanAmount, 'received 4700 RUN');

Expand Down Expand Up @@ -1115,7 +1115,7 @@ test('adjust balances', async t => {
let collateralLevel = aeth.make(1000n);

t.deepEqual(debtAmount, runDebtLevel, 'vault lent 5000 RUN + fees');
const { RUN: lentAmount } = await E(aliceLoanSeat).getCurrentAllocation();
const { RUN: lentAmount } = await E(aliceLoanSeat).getCurrentAllocationJig();
const loanProceeds = await E(aliceLoanSeat).getPayouts();
t.deepEqual(lentAmount, aliceLoanAmount, 'received 5000 RUN');

Expand Down Expand Up @@ -1164,7 +1164,7 @@ test('adjust balances', async t => {

const { RUN: lentAmount2 } = await E(
aliceAddCollateralSeat1,
).getCurrentAllocation();
).getCurrentAllocationJig();
const loanProceeds2 = await E(aliceAddCollateralSeat1).getPayouts();
t.deepEqual(lentAmount2, run.makeEmpty(), 'no payout');

Expand Down Expand Up @@ -1208,7 +1208,7 @@ test('adjust balances', async t => {
await E(aliceAddCollateralSeat2).getOfferResult();
const { RUN: lentAmount3 } = await E(
aliceAddCollateralSeat2,
).getCurrentAllocation();
).getCurrentAllocationJig();
const loanProceeds3 = await E(aliceAddCollateralSeat2).getPayouts();
t.deepEqual(lentAmount3, run.make(50n));

Expand Down Expand Up @@ -1257,7 +1257,7 @@ test('adjust balances', async t => {

const { RUN: lentAmount4 } = await E(
aliceReduceCollateralSeat,
).getCurrentAllocation();
).getCurrentAllocationJig();
const loanProceeds4 = await E(aliceReduceCollateralSeat).getPayouts();
t.deepEqual(lentAmount4, run.make(50n));

Expand Down Expand Up @@ -1384,7 +1384,7 @@ test('adjust balances - withdraw RUN', async t => {

const { RUN: lentAmount2 } = await E(
aliceWithdrawRunSeat,
).getCurrentAllocation();
).getCurrentAllocationJig();
const loanProceeds2 = await E(aliceWithdrawRunSeat).getPayouts();
t.deepEqual(lentAmount2, additionalRUN, '100 RUN');

Expand Down Expand Up @@ -1541,7 +1541,7 @@ test('transfer vault', async t => {
// make the invitation first so that we can arrange the interleaving
// of adjust and tranfer
const adjustInvitation = E(transferVault).makeAdjustBalancesInvitation();
const { RUN: lentAmount } = await E(aliceLoanSeat).getCurrentAllocation();
const { RUN: lentAmount } = await E(aliceLoanSeat).getCurrentAllocationJig();
const aliceProceeds = await E(aliceLoanSeat).getPayouts();
t.deepEqual(lentAmount, aliceLoanAmount, 'received 5000 RUN');
const borrowedRun = await aliceProceeds.RUN;
Expand Down Expand Up @@ -1636,7 +1636,7 @@ test('overdeposit', async t => {
const runDebt = AmountMath.add(aliceLoanAmount, fee);

t.deepEqual(debtAmount, runDebt, 'vault lent 5000 RUN + fees');
const { RUN: lentAmount } = await E(aliceLoanSeat).getCurrentAllocation();
const { RUN: lentAmount } = await E(aliceLoanSeat).getCurrentAllocationJig();
const aliceProceeds = await E(aliceLoanSeat).getPayouts();
t.deepEqual(lentAmount, aliceLoanAmount, 'received 5000 RUN');

Expand Down Expand Up @@ -1697,7 +1697,9 @@ test('overdeposit', async t => {
debtAmount = await E(aliceVault).getCurrentDebt();
t.deepEqual(debtAmount, run.makeEmpty());

const { RUN: lentAmount5 } = await E(aliceOverpaySeat).getCurrentAllocation();
const { RUN: lentAmount5 } = await E(
aliceOverpaySeat,
).getCurrentAllocationJig();
const loanProceeds5 = await E(aliceOverpaySeat).getPayouts();
t.deepEqual(lentAmount5, run.make(750n));

Expand All @@ -1713,7 +1715,7 @@ test('overdeposit', async t => {
await E(collectFeesSeat).getOfferResult();
assertAmountsEqual(
t,
await E.get(E(collectFeesSeat).getCurrentAllocation()).RUN,
await E.get(E(collectFeesSeat).getCurrentAllocationJig()).RUN,
run.make(300n),
);
});
Expand Down Expand Up @@ -1795,7 +1797,7 @@ test('mutable liquidity triggers and interest', async t => {
t.deepEqual(aliceDebtAmount, aliceRunDebtLevel, 'vault lent 5000 RUN + fees');
const { RUN: aliceLentAmount } = await E(
aliceLoanSeat,
).getCurrentAllocation();
).getCurrentAllocationJig();
const aliceLoanProceeds = await E(aliceLoanSeat).getPayouts();
t.deepEqual(aliceLentAmount, aliceLoanAmount, 'received 5000 RUN');
trace(t, 'alice vault');
Expand Down Expand Up @@ -1837,7 +1839,7 @@ test('mutable liquidity triggers and interest', async t => {
const bobRunDebtLevel = AmountMath.add(bobLoanAmount, bobFee);

t.deepEqual(bobDebtAmount, bobRunDebtLevel, 'vault lent 5000 RUN + fees');
const { RUN: bobLentAmount } = await E(bobLoanSeat).getCurrentAllocation();
const { RUN: bobLentAmount } = await E(bobLoanSeat).getCurrentAllocationJig();
const bobLoanProceeds = await E(bobLoanSeat).getPayouts();
t.deepEqual(bobLentAmount, bobLoanAmount, 'received 5000 RUN');
trace(t, 'bob vault');
Expand Down Expand Up @@ -1868,7 +1870,7 @@ test('mutable liquidity triggers and interest', async t => {

const { Collateral: aliceWithdrawnAeth } = await E(
aliceReduceCollateralSeat,
).getCurrentAllocation();
).getCurrentAllocationJig();
const loanProceeds4 = await E(aliceReduceCollateralSeat).getPayouts();
t.deepEqual(aliceWithdrawnAeth, aeth.make(300n));

Expand Down Expand Up @@ -2005,7 +2007,7 @@ test('collect fees from loan and AMM', async t => {
t.deepEqual(debtAmount, AmountMath.add(loanAmount, fee), 'vault loaned RUN');
trace(t, 'correct debt', debtAmount);

const { RUN: lentAmount } = await E(vaultSeat).getCurrentAllocation();
const { RUN: lentAmount } = await E(vaultSeat).getCurrentAllocationJig();
const loanProceeds = await E(vaultSeat).getPayouts();
await loanProceeds.RUN;
t.deepEqual(lentAmount, loanAmount, 'received 47 RUN');
Expand Down Expand Up @@ -2043,8 +2045,9 @@ test('collect fees from loan and AMM', async t => {
E(vaultFactory).makeCollectFeesInvitation(),
);
await E(collectFeesSeat).getOfferResult();
const feePayoutAmount = await E.get(E(collectFeesSeat).getCurrentAllocation())
.RUN;
const feePayoutAmount = await E.get(
E(collectFeesSeat).getCurrentAllocationJig(),
).RUN;
trace(t, 'Fee', feePoolBalance, feePayoutAmount);
t.truthy(AmountMath.isGTE(feePayoutAmount, feePoolBalance.RUN));
});
Expand Down Expand Up @@ -2089,7 +2092,7 @@ test('close loan', async t => {
const runDebtLevel = AmountMath.add(aliceLoanAmount, fee);

t.deepEqual(debtAmount, runDebtLevel, 'vault lent 5000 RUN + fees');
const { RUN: lentAmount } = await E(aliceLoanSeat).getCurrentAllocation();
const { RUN: lentAmount } = await E(aliceLoanSeat).getCurrentAllocationJig();
const loanProceeds = await E(aliceLoanSeat).getPayouts();
t.deepEqual(lentAmount, aliceLoanAmount, 'received 5000 RUN');

Expand Down Expand Up @@ -2146,7 +2149,7 @@ test('close loan', async t => {
const closeOfferResult = await E(aliceCloseSeat).getOfferResult();
t.is(closeOfferResult, 'your loan is closed, thank you for your business');

const closeAlloc = await E(aliceCloseSeat).getCurrentAllocation();
const closeAlloc = await E(aliceCloseSeat).getCurrentAllocationJig();
t.deepEqual(closeAlloc, {
RUN: run.make(750n),
Collateral: aeth.make(1000n),
Expand Down Expand Up @@ -2327,7 +2330,7 @@ test('mutable liquidity sensitivity of triggers and interest', async t => {
t.deepEqual(aliceDebtAmount, aliceRunDebtLevel, 'vault lent 5000 RUN + fees');
const { RUN: aliceLentAmount } = await E(
aliceLoanSeat,
).getCurrentAllocation();
).getCurrentAllocationJig();
const aliceLoanProceeds = await E(aliceLoanSeat).getPayouts();
t.deepEqual(aliceLentAmount, aliceLoanAmount, 'received 5000 RUN');

Expand Down Expand Up @@ -2366,7 +2369,7 @@ test('mutable liquidity sensitivity of triggers and interest', async t => {
const bobRunDebtLevel = AmountMath.add(bobLoanAmount, bobFee);

t.deepEqual(bobDebtAmount, bobRunDebtLevel, 'vault lent 5000 RUN + fees');
const { RUN: bobLentAmount } = await E(bobLoanSeat).getCurrentAllocation();
const { RUN: bobLentAmount } = await E(bobLoanSeat).getCurrentAllocationJig();
const bobLoanProceeds = await E(bobLoanSeat).getPayouts();
t.deepEqual(bobLentAmount, bobLoanAmount, 'received 5000 RUN');

Expand Down Expand Up @@ -2395,7 +2398,7 @@ test('mutable liquidity sensitivity of triggers and interest', async t => {

await E(aliceReduceCollateralSeat).getOfferResult();

await E(aliceReduceCollateralSeat).getCurrentAllocation();
await E(aliceReduceCollateralSeat).getCurrentAllocationJig();
const loanProceeds4 = await E(aliceReduceCollateralSeat).getPayouts();
// t.deepEqual(aliceWithdrawnAeth, aeth.make(210n));

Expand Down
5 changes: 4 additions & 1 deletion packages/wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,10 @@ export function makeWallet({
*/
async function subscribeToNotifier(id, seat) {
E(seat)
.getNotifier()
// TODO This uses getAllocationNotifierJig for production, and so
// is likely wrong
// See https://github.com/Agoric/agoric-sdk/issues/5834
.getAllocationNotifierJig()
.then(offerNotifierP => {
if (!idToNotifierP.has(id)) {
idToNotifierP.init(id, offerNotifierP);
Expand Down
5 changes: 4 additions & 1 deletion packages/zoe/src/contractSupport/zoeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ export const offerTo = async (
const depositedPromiseKit = makePromiseKit();

const doDeposit = async payoutPayments => {
const amounts = await E(userSeatPromise).getCurrentAllocation();
// TODO This uses getCurrentAllocationJig for production, and so
// is likely wrong
// https://github.com/Agoric/agoric-sdk/issues/5833
const amounts = await E(userSeatPromise).getCurrentAllocationJig();

// Map back to the original contract's keywords
const mappedAmounts = mapKeywords(amounts, mappingReversed);
Expand Down
10 changes: 7 additions & 3 deletions packages/zoe/src/zoeService/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,19 @@
/**
* @template {object} [OR=unknown]
* @typedef {object} UserSeat
* @property {() => Promise<Allocation>} getCurrentAllocation
* TODO remove getCurrentAllocation query
* @property {() => Promise<ProposalRecord>} getProposal
* @property {() => Promise<PaymentPKeywordRecord>} getPayouts
* @property {(keyword: Keyword) => Promise<Payment>} getPayout
* @property {() => Promise<OR>} getOfferResult
* @property {() => void=} tryExit
* @property {() => Promise<boolean>} hasExited
* @property {() => Promise<Notifier<Allocation>>} getNotifier
*
* @property {() => Promise<Allocation>} getCurrentAllocationJig
* Labelled "Jig" because it *should* only be used for tests, though
* nothing prevents it from being used otherwise.
* @property {() => Promise<Notifier<Allocation>>} getAllocationNotifierJig
* Labelled "Jig" because it *should* only be used for tests, though
* nothing prevents it from being used otherwise.
*/

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/zoe/src/zoeService/zoeSeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export const makeZoeSeatAdminKit = (

/** @type {UserSeat} */
const userSeat = Far('userSeat', {
getCurrentAllocation: async () => currentAllocation,
getProposal: async () => proposal,
getPayouts: async () => payoutPromiseKit.promise,
getPayout: async keyword => {
Expand All @@ -93,7 +92,9 @@ export const makeZoeSeatAdminKit = (
getOfferResult: async () => offerResult,
hasExited: async () => hasExited(zoeSeatAdmin),
tryExit: async () => E(exitObj).exit(),
getNotifier: async () => notifier,

getCurrentAllocationJig: async () => currentAllocation,
getAllocationNotifierJig: async () => notifier,
});

return { userSeat, zoeSeatAdmin, notifier };
Expand Down
Loading

0 comments on commit 9cb561b

Please sign in to comment.