Skip to content

Commit

Permalink
Merge pull request #34 from Axis-Fi/settle-recipient
Browse files Browse the repository at this point in the history
AuctionHouse: Bug with settlement recipient
  • Loading branch information
0xJem authored Feb 5, 2024
2 parents 236d4ed + 57345c1 commit be449f3
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 53 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ https://book.getfoundry.sh/
### Build

```shell
$ forge build
$ pnpm run build
```

### Test
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"yarn": "use-pnpm"
},
"scripts": {
"build": "forge build",
"build:rsa-cli": "cd rsa-cli && cargo build && cd ..",
"build": "forge build && pnpm run build:rsa-cli",
"fmt": "forge fmt",
"fmt:check": "forge fmt --check",
"solhint": "solhint --fix --config ./.solhint.json 'src/**/*.sol'",
Expand Down
4 changes: 2 additions & 2 deletions src/AuctionHouse.sol
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,10 @@ contract AuctionHouse is Derivatizer, Auctioneer, Router {
uint256 payoutRemaining = remainingCapacity;
uint256 bidCount = winningBids.length;
for (uint256 i; i < bidCount; i++) {
// Send payout to each bidder
// Send payout to each bid's recipient
_sendPayout(
lotId_,
winningBids[i].bidder,
winningBids[i].recipient,
winningBids[i].minAmountOut,
routing,
auctionOutput
Expand Down
130 changes: 81 additions & 49 deletions test/AuctionHouse/settle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ contract SettleTest is Test, Permit2User {
address internal immutable protocol = address(0x2);
address internal immutable referrer = address(0x4);
address internal immutable auctionOwner = address(0x5);
address internal immutable recipient = address(0x6);
address internal immutable bidderOne = address(0x7);
address internal immutable bidderTwo = address(0x8);
address internal immutable recipientOne = address(0x9);
address internal immutable recipientTwo = address(0x10);

uint48 internal constant protocolFee = 1000; // 1%
uint48 internal constant referrerFee = 500; // 0.5%
Expand Down Expand Up @@ -141,6 +142,7 @@ contract SettleTest is Test, Permit2User {

function _createBid(
address bidder_,
address recipient_,
uint256 bidAmount_,
uint256 bidAmountOut_
) internal returns (uint96 bidId_, LocalSealedBidBatchAuction.Decrypt memory decryptedBid) {
Expand All @@ -151,7 +153,7 @@ contract SettleTest is Test, Permit2User {

Router.BidParams memory bidParams = Router.BidParams({
lotId: lotId,
recipient: recipient,
recipient: recipient_,
referrer: referrer,
amount: bidAmount_,
auctionData: auctionData_,
Expand Down Expand Up @@ -262,7 +264,7 @@ contract SettleTest is Test, Permit2User {
// Create bids
// 4 < 10
(, LocalSealedBidBatchAuction.Decrypt memory decryptedBidOne) =
_createBid(bidderOne, bidOneAmount, bidOneAmountOut);
_createBid(bidderOne, recipientOne, bidOneAmount, bidOneAmountOut);
decryptedBids.push(decryptedBidOne);

// bidOne first (price = 1)
Expand All @@ -284,9 +286,9 @@ contract SettleTest is Test, Permit2User {
// Create bids
// 4 + 6 = 10
(, LocalSealedBidBatchAuction.Decrypt memory decryptedBidOne) =
_createBid(bidderOne, bidOneAmount, bidOneAmountOut);
_createBid(bidderOne, recipientOne, bidOneAmount, bidOneAmountOut);
(, LocalSealedBidBatchAuction.Decrypt memory decryptedBidTwo) =
_createBid(bidderTwo, bidTwoAmount, bidTwoAmountOut);
_createBid(bidderTwo, recipientTwo, bidTwoAmount, bidTwoAmountOut);
decryptedBids.push(decryptedBidOne);
decryptedBids.push(decryptedBidTwo);

Expand All @@ -309,9 +311,9 @@ contract SettleTest is Test, Permit2User {
// Create bids
// 4 + 7 = 11 (over-subscribed)
(, LocalSealedBidBatchAuction.Decrypt memory decryptedBidOne) =
_createBid(bidderOne, bidOneAmount, bidOneAmountOut);
_createBid(bidderOne, recipientOne, bidOneAmount, bidOneAmountOut);
(, LocalSealedBidBatchAuction.Decrypt memory decryptedBidThree) =
_createBid(bidderTwo, bidThreeAmount, bidThreeAmountOut);
_createBid(bidderTwo, recipientTwo, bidThreeAmount, bidThreeAmountOut);
decryptedBids.push(decryptedBidOne);
decryptedBids.push(decryptedBidThree);

Expand All @@ -334,9 +336,9 @@ contract SettleTest is Test, Permit2User {
// Create bids
// 4 + 2 = 6
(, LocalSealedBidBatchAuction.Decrypt memory decryptedBidOne) =
_createBid(bidderOne, bidFourAmount, bidFourAmountOut);
_createBid(bidderOne, recipientOne, bidFourAmount, bidFourAmountOut);
(, LocalSealedBidBatchAuction.Decrypt memory decryptedBidTwo) =
_createBid(bidderTwo, bidFiveAmount, bidFiveAmountOut);
_createBid(bidderTwo, recipientTwo, bidFiveAmount, bidFiveAmountOut);
decryptedBids.push(decryptedBidOne);
decryptedBids.push(decryptedBidTwo);

Expand Down Expand Up @@ -486,15 +488,17 @@ contract SettleTest is Test, Permit2User {
auctionHouse.settle(lotId);

// Check base token balances
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidOneAmountOut,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
);
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderTwo),
baseToken.balanceOf(recipientTwo),
bidTwoAmountOut,
"bidderTwo: incorrect balance of base token"
"recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner), 0, "auction owner: incorrect balance of base token"
Expand Down Expand Up @@ -549,15 +553,17 @@ contract SettleTest is Test, Permit2User {
auctionHouse.settle(lotId);

// Check base token balances
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidOneAmountOut,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
);
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderTwo),
baseToken.balanceOf(recipientTwo),
bidTwoAmountOut,
"bidderTwo: incorrect balance of base token"
"recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner), 0, "auction owner: incorrect balance of base token"
Expand Down Expand Up @@ -612,13 +618,15 @@ contract SettleTest is Test, Permit2User {
auctionHouse.settle(lotId);

// Check base token balances
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidOneAmountOut,
"bidderOne: incorrect balance of base token"
);
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderTwo),
baseToken.balanceOf(recipientTwo),
bidTwoAmountOut,
"bidderTwo: incorrect balance of base token"
);
Expand Down Expand Up @@ -675,15 +683,17 @@ contract SettleTest is Test, Permit2User {

// Check base token balances
uint256 bidOneAmountOutActual = 3e18;
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token"); // Received partial payout. 10 - 7 = 3
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidOneAmountOutActual,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
); // Received partial payout. 10 - 7 = 3
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderTwo),
baseToken.balanceOf(recipientTwo),
bidThreeAmountOut,
"bidderTwo: incorrect balance of base token"
"recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner), 0, "auction owner: incorrect balance of base token"
Expand Down Expand Up @@ -744,15 +754,17 @@ contract SettleTest is Test, Permit2User {

// Check base token balances
uint256 bidOneAmountOutActual = 3 * 10 ** baseTokenDecimals;
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token"); // Received partial payout. 10 - 7 = 3
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidOneAmountOutActual,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
); // Received partial payout. 10 - 7 = 3
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderTwo),
baseToken.balanceOf(recipientTwo),
bidThreeAmountOut,
"bidderTwo: incorrect balance of base token"
"recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner), 0, "auction owner: incorrect balance of base token"
Expand Down Expand Up @@ -813,15 +825,17 @@ contract SettleTest is Test, Permit2User {

// Check base token balances
uint256 bidOneAmountOutActual = 3 * 10 ** baseTokenDecimals;
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token"); // Received partial payout. 10 - 7 = 3
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidOneAmountOutActual,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
); // Received partial payout. 10 - 7 = 3
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderTwo),
baseToken.balanceOf(recipientTwo),
bidThreeAmountOut,
"bidderTwo: incorrect balance of base token"
"recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner), 0, "auction owner: incorrect balance of base token"
Expand Down Expand Up @@ -881,15 +895,17 @@ contract SettleTest is Test, Permit2User {

// Check base token balances
uint256 bidFourAmountOutActual = bidFourAmount * SCALE / marginalPrice;
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidFourAmountOutActual,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
);
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderTwo),
baseToken.balanceOf(recipientTwo),
bidFiveAmountOut,
"bidderTwo: incorrect balance of base token"
"recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner),
Expand Down Expand Up @@ -947,15 +963,17 @@ contract SettleTest is Test, Permit2User {

// Check base token balances
uint256 bidFourAmountOutActual = _getAmountOut(bidFourAmount, marginalPrice);
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidFourAmountOutActual,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
);
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderTwo),
baseToken.balanceOf(recipientTwo),
bidFiveAmountOut,
"bidderTwo: incorrect balance of base token"
"recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner),
Expand Down Expand Up @@ -1013,15 +1031,17 @@ contract SettleTest is Test, Permit2User {

// Check base token balances
uint256 bidFourAmountOutActual = _getAmountOut(bidFourAmount, marginalPrice);
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidFourAmountOutActual,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
);
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderTwo),
baseToken.balanceOf(recipientTwo),
bidFiveAmountOut,
"bidderTwo: incorrect balance of base token"
"recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner),
Expand Down Expand Up @@ -1077,12 +1097,16 @@ contract SettleTest is Test, Permit2User {
auctionHouse.settle(lotId);

// Check base token balances
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidOneAmountOut,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
);
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(recipientTwo), 0, "recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner),
_lotCapacity - bidOneAmountOut,
Expand Down Expand Up @@ -1138,12 +1162,16 @@ contract SettleTest is Test, Permit2User {
auctionHouse.settle(lotId);

// Check base token balances
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidOneAmountOut,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
);
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(recipientTwo), 0, "recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner),
_lotCapacity - bidOneAmountOut,
Expand Down Expand Up @@ -1199,12 +1227,16 @@ contract SettleTest is Test, Permit2User {
auctionHouse.settle(lotId);

// Check base token balances
assertEq(baseToken.balanceOf(bidderOne), 0, "bidderOne: incorrect balance of base token");
assertEq(
baseToken.balanceOf(bidderOne),
baseToken.balanceOf(recipientOne),
bidOneAmountOut,
"bidderOne: incorrect balance of base token"
"recipientOne: incorrect balance of base token"
);
assertEq(baseToken.balanceOf(bidderTwo), 0, "bidderTwo: incorrect balance of base token");
assertEq(
baseToken.balanceOf(recipientTwo), 0, "recipientTwo: incorrect balance of base token"
);
assertEq(
baseToken.balanceOf(auctionOwner),
_lotCapacity - bidOneAmountOut,
Expand Down

0 comments on commit be449f3

Please sign in to comment.