From e9e637c0d47cca86f40d5705e413c19824faba39 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 23 Jul 2024 14:04:29 -0700 Subject: [PATCH] refactor(auction): proceedsExpected --- .../inter-protocol/src/auction/auctionBook.js | 21 ++++++------ .../inter-protocol/src/auction/auctionMath.js | 4 +-- .../test/auction/auctionMath.test.js | 32 +++++++++---------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/packages/inter-protocol/src/auction/auctionBook.js b/packages/inter-protocol/src/auction/auctionBook.js index 3906b49b543..df65ba02847 100644 --- a/packages/inter-protocol/src/auction/auctionBook.js +++ b/packages/inter-protocol/src/auction/auctionBook.js @@ -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); } diff --git a/packages/inter-protocol/src/auction/auctionMath.js b/packages/inter-protocol/src/auction/auctionMath.js index 3ad1752b08f..33a7875c1a7 100644 --- a/packages/inter-protocol/src/auction/auctionMath.js +++ b/packages/inter-protocol/src/auction/auctionMath.js @@ -45,7 +45,7 @@ export const amountsToSettle = ( curAuctionPrice, ); if (AmountMath.isEmpty(proceedsExpected)) { - return { proceedsNeeded: null }; + return { proceedsExpected: null }; } const targetByProceeds = proceedsLimit => @@ -76,6 +76,6 @@ export const amountsToSettle = ( 'target cannot exceed available', ); - return { proceedsNeeded: proceedsExpected, proceedsTarget, collateralTarget }; + return { proceedsExpected, proceedsTarget, collateralTarget }; }; harden(amountsToSettle); diff --git a/packages/inter-protocol/test/auction/auctionMath.test.js b/packages/inter-protocol/test/auction/auctionMath.test.js index e6c4714b4f0..337c2d36dfe 100644 --- a/packages/inter-protocol/test/auction/auctionMath.test.js +++ b/packages/inter-protocol/test/auction/auctionMath.test.js @@ -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)); @@ -36,7 +36,7 @@ const testAmounts = test.macro( }); t.deepEqual(result, { - proceedsNeeded: amt(procNeeded), + proceedsExpected: amt(expected), proceedsTarget: amt(procTarget), collateralTarget: amt(collTarget), }); @@ -49,7 +49,7 @@ test( testAmounts, { bid: 578, want: 500, avail: 1000, price: [1155, 1000] }, { - procNeeded: 578, + expected: 578, procTarget: 578, collTarget: 500, }, @@ -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, }, @@ -71,7 +71,7 @@ test( testAmounts, { bid: 231, want: 200, avail: 1000, price: [1155, 1000] }, { - procNeeded: 231, + expected: 231, procTarget: 231, collTarget: 200, }, @@ -82,7 +82,7 @@ test( testAmounts, { bid: 232, want: 200, avail: 100, price: [1155, 1000] }, { - procNeeded: 116, + expected: 116, procTarget: 116, collTarget: 100, }, @@ -93,7 +93,7 @@ test( testAmounts, { bid: 19, want: 300, avail: 300, price: [625, 10000] }, { - procNeeded: 19, + expected: 19, procTarget: 19, collTarget: 300, }, @@ -104,7 +104,7 @@ test( testAmounts, { bid: 23, want: 200, avail: 500, price: [1125, 10000] }, { - procNeeded: 23, + expected: 23, procTarget: 23, collTarget: 200, }, @@ -115,7 +115,7 @@ test( testAmounts, { bid: 500, want: 2000, avail: 717, price: [715, 1000] }, { - procNeeded: 513, + expected: 513, procTarget: 500, collTarget: 699, }, @@ -126,7 +126,7 @@ test( testAmounts, { bid: 240, want: 200, avail: 20, price: [1155, 1000] }, { - procNeeded: 24, + expected: 24, procTarget: 24, collTarget: 20, }, @@ -137,7 +137,7 @@ test( testAmounts, { bid: 2000, want: 200, avail: 1000, price: [1155, 1000] }, { - procNeeded: 231, + expected: 231, procTarget: 231, collTarget: 200, }, @@ -148,7 +148,7 @@ test( testAmounts, { bid: 2240, want: 200, avail: 1000, price: [1155, 1000] }, { - procNeeded: 231, + expected: 231, procTarget: 231, collTarget: 200, }, @@ -159,7 +159,7 @@ test( testAmounts, { bid: 2000, want: 2000, avail: 1000, price: [1, 1] }, { - procNeeded: 1000, + expected: 1000, procTarget: 1000, collTarget: 1000, }, @@ -170,7 +170,7 @@ test( testAmounts, { bid: 1999, want: 2000, avail: 1000, price: [201, 1] }, { - procNeeded: 201000, + expected: 201000, procTarget: 1999, collTarget: 9, }, @@ -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, }, @@ -197,7 +197,7 @@ test( goal: 1254_886835, // "remainingProceedsGoal": "1254.886835 IST", }, { - procNeeded: 492, + expected: 492, procTarget: 492, collTarget: 1000, },