Skip to content

Commit

Permalink
make fix for stack to deep and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivaanshK committed Nov 27, 2024
1 parent 932ef56 commit f5c86e5
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 41 deletions.
5 changes: 2 additions & 3 deletions src/RecipeMarketHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,10 @@ contract RecipeMarketHub is RecipeMarketHubBase {
uint256[] memory protocolFeesPaid = new uint256[](numIncentives);
uint256[] memory frontendFeesPaid = new uint256[](numIncentives);

// Calculate the percentage of the offer the AP is filling
uint256 fillPercentage = fillAmount.divWadDown(offer.quantity);

// Perform incentive accounting on a per incentive basis
for (uint256 i = 0; i < numIncentives; ++i) {
// Calculate the percentage of the offer the AP is filling
uint256 fillPercentage = fillAmount.divWadDown(offer.quantity);
// Incentive address
address incentive = offer.incentivesOffered[i];

Expand Down
1 change: 1 addition & 0 deletions test/concrete/RecipeMarketHub/Test_APOfferCreation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract Test_APOfferCreation_RecipeMarketHub is RecipeMarketHubTestBase {
emit RecipeMarketHubBase.APOfferCreated(
0, // Expected offer ID (starts at 0)
marketHash, // Market ID
ALICE_ADDRESS,
address(0), // No funding vault
quantity,
tokensRequested, // Tokens requested
Expand Down
38 changes: 20 additions & 18 deletions test/concrete/RecipeMarketHub/Test_Fill_APOffer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

import "src/base/RecipeMarketHubBase.sol";
import {ERC4626} from "src/RecipeMarketHub.sol";
import { ERC4626 } from "src/RecipeMarketHub.sol";
import "src/WrappedVault.sol";

import { MockERC20, ERC20 } from "../../mocks/MockERC20.sol";
Expand Down Expand Up @@ -62,7 +62,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {

// Expect events for offer fill
vm.expectEmit(false, false, false, false);
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

vm.recordLogs();

Expand Down Expand Up @@ -129,7 +129,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {

// Expect events for offer fill
vm.expectEmit(false, false, false, false);
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

vm.recordLogs();

Expand Down Expand Up @@ -199,7 +199,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(AP_ADDRESS, address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -265,7 +265,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {

// Expect events for offer fill
vm.expectEmit(false, false, false, false);
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

vm.recordLogs();

Expand Down Expand Up @@ -305,7 +305,8 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {
uint256 fillAmount = 25_000e18; // Fill amount

// Create a fillable IP offer
(, RecipeMarketHubBase.APOffer memory offer, Points points) = createAPOffer_ForPoints(marketHash, address(mockVault), offerAmount, AP_ADDRESS, IP_ADDRESS);
(, RecipeMarketHubBase.APOffer memory offer, Points points) =
createAPOffer_ForPoints(marketHash, address(mockVault), offerAmount, AP_ADDRESS, IP_ADDRESS);

(, uint256 expectedFrontendFeeAmount, uint256 expectedProtocolFeeAmount, uint256 expectedIncentiveAmount) =
calculateAPOfferExpectedIncentiveAndFrontendFee(recipeMarketHub.protocolFee(), frontendFee, offerAmount, fillAmount, 1000e18);
Expand Down Expand Up @@ -338,7 +339,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(address(mockVault), address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -395,7 +396,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {

// Expect events for offer fill
vm.expectEmit(false, false, false, false);
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

vm.recordLogs();

Expand Down Expand Up @@ -455,7 +456,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(AP_ADDRESS, address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -521,7 +522,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {

// Expect events for offer fill
vm.expectEmit(false, false, false, false);
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

vm.recordLogs();

Expand Down Expand Up @@ -561,7 +562,8 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {
uint256 fillAmount = 25_000e18; // Fill amount

// Create a fillable IP offer
(, RecipeMarketHubBase.APOffer memory offer, Points points) = createAPOffer_ForPoints(marketHash, address(mockVault), offerAmount, AP_ADDRESS, IP_ADDRESS);
(, RecipeMarketHubBase.APOffer memory offer, Points points) =
createAPOffer_ForPoints(marketHash, address(mockVault), offerAmount, AP_ADDRESS, IP_ADDRESS);

(, uint256 expectedFrontendFeeAmount, uint256 expectedProtocolFeeAmount, uint256 expectedIncentiveAmount) =
calculateAPOfferExpectedIncentiveAndFrontendFee(recipeMarketHub.protocolFee(), frontendFee, offerAmount, fillAmount, 1000e18);
Expand All @@ -584,7 +586,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(address(mockVault), address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -644,7 +646,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {

// Expect events for offer fill
vm.expectEmit(false, false, false, false);
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

vm.recordLogs();

Expand Down Expand Up @@ -704,7 +706,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(AP_ADDRESS, address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -770,7 +772,7 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {

// Expect events for offer fill
vm.expectEmit(false, false, false, false);
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

vm.recordLogs();

Expand Down Expand Up @@ -810,7 +812,8 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {
uint256 fillAmount = 25_000e18; // Fill amount

// Create a fillable IP offer
(, RecipeMarketHubBase.APOffer memory offer, Points points) = createAPOffer_ForPoints(marketHash, address(mockVault), offerAmount, AP_ADDRESS, IP_ADDRESS);
(, RecipeMarketHubBase.APOffer memory offer, Points points) =
createAPOffer_ForPoints(marketHash, address(mockVault), offerAmount, AP_ADDRESS, IP_ADDRESS);

(, uint256 expectedFrontendFeeAmount, uint256 expectedProtocolFeeAmount, uint256 expectedIncentiveAmount) =
calculateAPOfferExpectedIncentiveAndFrontendFee(recipeMarketHub.protocolFee(), frontendFee, offerAmount, fillAmount, 1000e18);
Expand All @@ -826,15 +829,14 @@ contract Test_Fill_APOffer_RecipeMarketHub is RecipeMarketHubTestBase {

vm.stopPrank();


vm.expectEmit(true, false, true, false, address(mockVault));
emit ERC4626.Withdraw(address(recipeMarketHub), address(0), AP_ADDRESS, fillAmount, 0);

vm.expectEmit(true, false, false, true, address(mockLiquidityToken));
emit ERC20.Transfer(address(mockVault), address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.APOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.APOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down
30 changes: 15 additions & 15 deletions test/concrete/RecipeMarketHub/Test_Fill_IPOffer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "src/WrappedVault.sol";

import { MockERC20, ERC20 } from "../../mocks/MockERC20.sol";
import { MockERC4626 } from "test/mocks/MockERC4626.sol";
import {ERC4626} from "src/RecipeMarketHub.sol";
import { ERC4626 } from "src/RecipeMarketHub.sol";
import { RecipeMarketHubTestBase } from "../../utils/RecipeMarketHub/RecipeMarketHubTestBase.sol";
import { FixedPointMathLib } from "lib/solmate/src/utils/FixedPointMathLib.sol";

Expand Down Expand Up @@ -54,7 +54,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(AP_ADDRESS, address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -115,7 +115,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(AP_ADDRESS, address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -182,7 +182,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(AP_ADDRESS, address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -246,7 +246,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(address(mockVault), address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -325,7 +325,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(address(mockVault), address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -373,7 +373,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(AP_ADDRESS, address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -436,7 +436,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(AP_ADDRESS, address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -505,7 +505,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(address(mockVault), address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -580,7 +580,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(address(mockVault), address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -636,7 +636,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(AP_ADDRESS, address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -699,7 +699,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(AP_ADDRESS, address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -768,7 +768,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(address(mockVault), address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand Down Expand Up @@ -843,7 +843,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
emit ERC20.Transfer(address(mockVault), address(0), fillAmount);

vm.expectEmit(false, false, false, false, address(recipeMarketHub));
emit RecipeMarketHubBase.IPOfferFilled(0, 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));
emit RecipeMarketHubBase.IPOfferFilled(0, address(0), 0, address(0), new uint256[](0), new uint256[](0), new uint256[](0));

// Record the logs to capture Transfer events to get Weiroll wallet address
vm.recordLogs();
Expand All @@ -869,7 +869,7 @@ contract Test_Fill_IPOffer_RecipeMarketHub is RecipeMarketHubTestBase {
// Ensure the weiroll wallet got the liquidity
assertEq(mockLiquidityToken.balanceOf(weirollWallet), fillAmount);

// Check the frontend fee recipient received the correct fee
// Check the frontend fee recipient received the correct fee
assertEq(recipeMarketHub.feeClaimantToTokenToAmount(FRONTEND_FEE_RECIPIENT, address(mockIncentiveToken)), 0);

// Check the protocol fee recipient received the correct fee
Expand Down
Loading

0 comments on commit f5c86e5

Please sign in to comment.