Skip to content

Commit

Permalink
Merge pull request #132 from roycoprotocol/feat/event-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
corddry authored Nov 29, 2024
2 parents 7dd8e0e + bab003f commit 06edfbe
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 57 deletions.
22 changes: 15 additions & 7 deletions src/RecipeMarketHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ contract RecipeMarketHub is RecipeMarketHubBase {
offerHashToRemainingQuantity[offerHash] = quantity;

/// @dev APOffer events are stored in events and do not exist onchain outside of the offerHashToRemainingQuantity mapping
emit APOfferCreated(numAPOffers, targetMarketHash, fundingVault, quantity, incentivesRequested, incentiveAmountsRequested, expiry);
emit APOfferCreated(numAPOffers, targetMarketHash, msg.sender, fundingVault, quantity, incentivesRequested, incentiveAmountsRequested, expiry);

// Increment the number of AP offers created
numAPOffers++;
Expand Down Expand Up @@ -269,7 +269,16 @@ contract RecipeMarketHub is RecipeMarketHubBase {

// Emit IP offer creation event
emit IPOfferCreated(
numIPOffers, offerHash, targetMarketHash, quantity, incentivesOffered, incentiveAmountsOffered, protocolFeesToBePaid, frontendFeesToBePaid, expiry
numIPOffers,
offerHash,
targetMarketHash,
msg.sender,
quantity,
incentivesOffered,
incentiveAmountsOffered,
protocolFeesToBePaid,
frontendFeesToBePaid,
expiry
);

// Increment the number of IP offers created
Expand Down Expand Up @@ -368,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 Expand Up @@ -410,7 +418,7 @@ contract RecipeMarketHub is RecipeMarketHubBase {
// Execute deposit recipe
wallet.executeWeiroll(market.depositRecipe.weirollCommands, market.depositRecipe.weirollState);

emit IPOfferFilled(offerHash, fillAmount, address(wallet), incentiveAmountsPaid, protocolFeesPaid, frontendFeesPaid);
emit IPOfferFilled(offerHash, msg.sender, fillAmount, address(wallet), incentiveAmountsPaid, protocolFeesPaid, frontendFeesPaid);
}

/// @dev Fill multiple AP offers
Expand Down Expand Up @@ -535,7 +543,7 @@ contract RecipeMarketHub is RecipeMarketHubBase {
// Execute deposit recipe
wallet.executeWeiroll(market.depositRecipe.weirollCommands, market.depositRecipe.weirollState);

emit APOfferFilled(offer.offerID, fillAmount, address(wallet), incentiveAmountsPaid, protocolFeesPaid, frontendFeesPaid);
emit APOfferFilled(offer.offerID, msg.sender, fillAmount, address(wallet), incentiveAmountsPaid, protocolFeesPaid, frontendFeesPaid);
}

/// @notice Cancel an AP offer, setting the remaining quantity available to fill to 0
Expand Down
12 changes: 7 additions & 5 deletions src/VaultMarketHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ contract VaultMarketHub is Ownable2Step, ReentrancyGuardTransient {

/// @notice The minimum time a campaign must run for before someone can be allocated into it
uint256 public constant MIN_CAMPAIGN_DURATION = 1 weeks;

/// @notice whether offer fills are paused
bool public offersPaused;

/// @dev The minimum quantity of tokens for an offer
uint256 internal constant MINIMUM_QUANTITY = 1e6;

Expand All @@ -49,6 +49,7 @@ contract VaultMarketHub is Ownable2Step, ReentrancyGuardTransient {

/// @param offerID Set to numOffers - 1 on offer creation (zero-indexed)
/// @param marketID The ID of the market to place the offer in
/// @param ap The address that created this AP offer
/// @param fundingVault The address of the vault where the input tokens will be withdrawn from
/// @param quantity The total amount of the base asset to be withdrawn from the funding vault
/// @param incentivesRequested The incentives requested by the AP in offer to fill the offer
Expand All @@ -57,6 +58,7 @@ contract VaultMarketHub is Ownable2Step, ReentrancyGuardTransient {
event APOfferCreated(
uint256 indexed offerID,
address indexed marketID,
address indexed ap,
address fundingVault,
uint256 quantity,
address[] incentivesRequested,
Expand Down Expand Up @@ -154,7 +156,7 @@ contract VaultMarketHub is Ownable2Step, ReentrancyGuardTransient {
}

// Emit the offer creation event, used for matching offers
emit APOfferCreated(numOffers, targetVault, fundingVault, quantity, incentivesRequested, incentivesRatesRequested, expiry);
emit APOfferCreated(numOffers, targetVault, msg.sender, fundingVault, quantity, incentivesRequested, incentivesRatesRequested, expiry);
// Set the quantity of the offer
APOffer memory offer = APOffer(numOffers, targetVault, msg.sender, fundingVault, expiry, incentivesRequested, incentivesRatesRequested);
offerHashToRemainingQuantity[getOfferHash(offer)] = quantity;
Expand Down Expand Up @@ -211,7 +213,7 @@ contract VaultMarketHub is Ownable2Step, ReentrancyGuardTransient {
} else {
// Get pre-withdraw token balance of VaultMarketHub
uint256 preWithdrawTokenBalance = targetAsset.balanceOf(address(this));

// Withdraw from the funding vault to the VaultMarketHub
ERC4626(offer.fundingVault).withdraw(fillAmount, address(this), offer.ap);

Expand All @@ -225,7 +227,7 @@ contract VaultMarketHub is Ownable2Step, ReentrancyGuardTransient {
}

for (uint256 i; i < offer.incentivesRatesRequested.length; ++i) {
(, uint32 end, ) = WrappedVault(offer.targetVault).rewardToInterval(offer.incentivesRequested[i]);
(, uint32 end,) = WrappedVault(offer.targetVault).rewardToInterval(offer.incentivesRequested[i]);
if (end < MIN_CAMPAIGN_DURATION + block.timestamp) {
revert OfferConditionsNotMet();
}
Expand Down
12 changes: 10 additions & 2 deletions src/base/RecipeMarketHubBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract contract RecipeMarketHubBase is Owned, ReentrancyGuardTransient {
address public immutable POINTS_FACTORY;

/// @notice The minimum percent you can fill an AP offer with, to prevent griefing attacks
uint256 public constant MIN_FILL_PERCENT = 0.10e18; // == 10%
uint256 public constant MIN_FILL_PERCENT = 0.1e18; // == 10%

/// @dev The minimum quantity of tokens for an offer
uint256 internal constant MINIMUM_QUANTITY = 1e6;
Expand Down Expand Up @@ -148,6 +148,7 @@ abstract contract RecipeMarketHubBase is Owned, ReentrancyGuardTransient {

/// @param offerID Set to numAPOffers (zero-indexed) - ordered separately for AP and IP offers
/// @param marketHash The hash of the weiroll market which the AP offer is for
/// @param ap The address of the AP that created this offer.
/// @param fundingVault The address of the vault where the input tokens will be withdrawn from
/// @param quantity The total amount of input tokens to be deposited
/// @param incentiveAddresses The requested rewards
Expand All @@ -156,6 +157,7 @@ abstract contract RecipeMarketHubBase is Owned, ReentrancyGuardTransient {
event APOfferCreated(
uint256 indexed offerID,
bytes32 indexed marketHash,
address indexed ap,
address fundingVault,
uint256 quantity,
address[] incentiveAddresses,
Expand All @@ -166,16 +168,18 @@ abstract contract RecipeMarketHubBase is Owned, ReentrancyGuardTransient {
/// @param offerID Set to numIPOffers (zero-indexed) - ordered separately for AP and IP offers
/// @param offerHash Set to the hash of the offer (used to identify IP offers)
/// @param marketHash The hash of the weiroll market which the IP offer is for
/// @param ip The address of the IP that created this offer.
/// @param quantity The total amount of input tokens to be deposited
/// @param incentivesOffered The offered rewards
/// @param incentiveAmounts The offered rewards per input token
/// @param protocolFeeAmounts The offered rewards protocol fee per input token
/// @param frontendFeeAmounts The offered rewards frontend fee per input token
/// @param expiry The timestamp after which the offer is considered expired
event IPOfferCreated(
uint256 indexed offerID,
uint256 offerID,
bytes32 indexed offerHash,
bytes32 indexed marketHash,
address indexed ip,
uint256 quantity,
address[] incentivesOffered,
uint256[] incentiveAmounts,
Expand All @@ -185,13 +189,15 @@ abstract contract RecipeMarketHubBase is Owned, ReentrancyGuardTransient {
);

/// @param offerHash Hash of the offer (used to identify IP offers)
/// @param ap The address of the AP that filled this offer.
/// @param fillAmount The amount of the offer that was filled in the market input token
/// @param weirollWallet The address of the weiroll wallet containing the AP's funds, created on fill, used to execute the recipes
/// @param incentiveAmounts The amount of incentives allocated to the AP on fill (claimable as per the market's reward type)
/// @param protocolFeeAmounts The protocol fee per incentive on fill (claimable as per the market's reward type)
/// @param frontendFeeAmounts The rewards frontend fee per incentive on fill (claimable as per the market's reward type)
event IPOfferFilled(
bytes32 indexed offerHash,
address indexed ap,
uint256 fillAmount,
address weirollWallet,
uint256[] incentiveAmounts,
Expand All @@ -200,13 +206,15 @@ abstract contract RecipeMarketHubBase is Owned, ReentrancyGuardTransient {
);

/// @param offerID The ID of the AP offer filled
/// @param ip The address of the IP that filled this offer.
/// @param fillAmount The amount of the offer that was filled in the market input token
/// @param weirollWallet The address of the weiroll wallet containing the AP's funds, created on fill, used to execute the recipes
/// @param incentiveAmounts The amount of incentives allocated to the AP on fill (claimable as per the market's reward type)
/// @param protocolFeeAmounts The amount taken as the protocol fee per incentive on fill (claimable as per the market's reward type)
/// @param frontendFeeAmounts The amount taken as the frontend fee per incentive on fill (claimable as per the market's reward type)
event APOfferFilled(
uint256 indexed offerID,
address indexed ip,
uint256 fillAmount,
address weirollWallet,
uint256[] incentiveAmounts,
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
Loading

0 comments on commit 06edfbe

Please sign in to comment.