Skip to content

Commit

Permalink
refactor(auction): proceedsExpected
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Aug 13, 2024
1 parent 25ec494 commit e9e637c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
21 changes: 12 additions & 9 deletions packages/inter-protocol/src/auction/auctionBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,19 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
Fail`auctionPrice must be set before each round`;
assert(curAuctionPrice);

const { proceedsNeeded, proceedsTarget, collateralTarget } =
amountsToSettle({
bidAlloc,
collateralWanted,
collateralAvailable,
curAuctionPrice,
remainingProceedsGoal,
});
const { proceedsExpected, proceedsTarget, collateralTarget } =
amountsToSettle(
{
bidAlloc,
collateralWanted,
collateralAvailable,
curAuctionPrice,
remainingProceedsGoal,
},
trace,
);

if (proceedsNeeded === null) {
if (proceedsExpected === null) {
seat.fail(Error('price fell to zero'));
return makeEmpty(collateralBrand);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/inter-protocol/src/auction/auctionMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const amountsToSettle = (
curAuctionPrice,
);
if (AmountMath.isEmpty(proceedsExpected)) {
return { proceedsNeeded: null };
return { proceedsExpected: null };
}

const targetByProceeds = proceedsLimit =>
Expand Down Expand Up @@ -76,6 +76,6 @@ export const amountsToSettle = (
'target cannot exceed available',
);

return { proceedsNeeded: proceedsExpected, proceedsTarget, collateralTarget };
return { proceedsExpected, proceedsTarget, collateralTarget };
};
harden(amountsToSettle);
32 changes: 16 additions & 16 deletions packages/inter-protocol/test/auction/auctionMath.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const testAmounts = test.macro(
async (
t,
{ bid, want, avail, price, goal },
{ procNeeded, procTarget, collTarget },
{ expected, procTarget, collTarget },
) => {
/** @type {(n: number) => Amount<'nat'>} */
const amt = n => AmountMath.make(brand, BigInt(n));
Expand All @@ -36,7 +36,7 @@ const testAmounts = test.macro(
});

t.deepEqual(result, {
proceedsNeeded: amt(procNeeded),
proceedsExpected: amt(expected),
proceedsTarget: amt(procTarget),
collateralTarget: amt(collTarget),
});
Expand All @@ -49,7 +49,7 @@ test(
testAmounts,
{ bid: 578, want: 500, avail: 1000, price: [1155, 1000] },
{
procNeeded: 578,
expected: 578,
procTarget: 578,
collTarget: 500,
},
Expand All @@ -60,7 +60,7 @@ test(
testAmounts,
{ bid: 125, want: 100, avail: 400, price: [525, 1000], goal: 200 },
{
procNeeded: 53,
expected: 53,
procTarget: 53,
collTarget: 100,
},
Expand All @@ -71,7 +71,7 @@ test(
testAmounts,
{ bid: 231, want: 200, avail: 1000, price: [1155, 1000] },
{
procNeeded: 231,
expected: 231,
procTarget: 231,
collTarget: 200,
},
Expand All @@ -82,7 +82,7 @@ test(
testAmounts,
{ bid: 232, want: 200, avail: 100, price: [1155, 1000] },
{
procNeeded: 116,
expected: 116,
procTarget: 116,
collTarget: 100,
},
Expand All @@ -93,7 +93,7 @@ test(
testAmounts,
{ bid: 19, want: 300, avail: 300, price: [625, 10000] },
{
procNeeded: 19,
expected: 19,
procTarget: 19,
collTarget: 300,
},
Expand All @@ -104,7 +104,7 @@ test(
testAmounts,
{ bid: 23, want: 200, avail: 500, price: [1125, 10000] },
{
procNeeded: 23,
expected: 23,
procTarget: 23,
collTarget: 200,
},
Expand All @@ -115,7 +115,7 @@ test(
testAmounts,
{ bid: 500, want: 2000, avail: 717, price: [715, 1000] },
{
procNeeded: 513,
expected: 513,
procTarget: 500,
collTarget: 699,
},
Expand All @@ -126,7 +126,7 @@ test(
testAmounts,
{ bid: 240, want: 200, avail: 20, price: [1155, 1000] },
{
procNeeded: 24,
expected: 24,
procTarget: 24,
collTarget: 20,
},
Expand All @@ -137,7 +137,7 @@ test(
testAmounts,
{ bid: 2000, want: 200, avail: 1000, price: [1155, 1000] },
{
procNeeded: 231,
expected: 231,
procTarget: 231,
collTarget: 200,
},
Expand All @@ -148,7 +148,7 @@ test(
testAmounts,
{ bid: 2240, want: 200, avail: 1000, price: [1155, 1000] },
{
procNeeded: 231,
expected: 231,
procTarget: 231,
collTarget: 200,
},
Expand All @@ -159,7 +159,7 @@ test(
testAmounts,
{ bid: 2000, want: 2000, avail: 1000, price: [1, 1] },
{
procNeeded: 1000,
expected: 1000,
procTarget: 1000,
collTarget: 1000,
},
Expand All @@ -170,7 +170,7 @@ test(
testAmounts,
{ bid: 1999, want: 2000, avail: 1000, price: [201, 1] },
{
procNeeded: 201000,
expected: 201000,
procTarget: 1999,
collTarget: 9,
},
Expand All @@ -180,7 +180,7 @@ test(
testAmounts,
{ bid: 1999, want: 2000, avail: 1000, price: [201, 1], goal: 301 },
{
procNeeded: 201000,
expected: 201000,
procTarget: 301,
collTarget: 1,
},
Expand All @@ -197,7 +197,7 @@ test(
goal: 1254_886835, // "remainingProceedsGoal": "1254.886835 IST",
},
{
procNeeded: 492,
expected: 492,
procTarget: 492,
collTarget: 1000,
},
Expand Down

0 comments on commit e9e637c

Please sign in to comment.