Skip to content

Commit

Permalink
fix: emit QuestClaimReferred to include referral token rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathandiep committed Apr 5, 2024
1 parent 2e75c9e commit ed12804
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 20 deletions.
5 changes: 5 additions & 0 deletions contracts/Quest1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ contract Quest1155 is ERC1155Holder, ReentrancyGuardUpgradeable, PausableUpgrade
uint256 public tokenId;
uint256 public questFee;
string public questId;
uint256 public referralRewardFee;

/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
Expand Down Expand Up @@ -180,6 +181,10 @@ contract Quest1155 is ERC1155Holder, ReentrancyGuardUpgradeable, PausableUpgrade
return questId;
}

function referralRewardAmount() external pure returns (uint256) {
return 0;
}

/*//////////////////////////////////////////////////////////////
INTERNAL VIEW
//////////////////////////////////////////////////////////////*/
Expand Down
99 changes: 79 additions & 20 deletions contracts/QuestFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {LibZip} from "solady/utils/LibZip.sol";
import {IERC1155} from "openzeppelin-contracts/token/ERC1155/IERC1155.sol";
import {IQuestOwnable} from "./interfaces/IQuestOwnable.sol";
import {IQuest1155Ownable} from "./interfaces/IQuest1155Ownable.sol";
import {Quest as QuestContract} from "./Quest.sol";

/// @title QuestFactory
/// @author RabbitHole.gg
Expand Down Expand Up @@ -54,6 +55,7 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
uint16 public referralFee;
address private __deprecated_sablierV2LockupLinearAddress; // not used
mapping(address => address) private __deprecated_mintFeeRecipientList; // not used
uint256 public referralRewardTimestamp;
// insert new vars here at the end to keep the storage layout the same

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -82,6 +84,7 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
erc1155QuestAddress = erc1155QuestAddress_;
referralFee = referralFee_;
mintFee = mintFee_;
referralRewardTimestamp = block.timestamp;
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -425,7 +428,29 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
emit QuestClaimed(claimer_, quest.questAddress, questId_, rewardToken_, rewardAmountOrTokenId);
}
if(ref_ != address(0)){
emit QuestClaimedReferred(claimer_, quest.questAddress, questId_, rewardToken_, rewardAmountOrTokenId, ref_, 3333, mintFee);
if (IQuestOwnable(quest.questAddress).startTime() > referralRewardTimestamp) {
emit QuestClaimReferred(
claimer_,
quest.questAddress,
questId_,
rewardToken_,
rewardAmountOrTokenId,
ref_, 3333,
mintFee,
QuestContract(payable(quest.questAddress)).referralRewardFee(),
QuestContract(payable(quest.questAddress)).referralRewardAmount())
;
} else {
emit QuestClaimedReferred(
claimer_,
quest.questAddress,
questId_,
rewardToken_,
rewardAmountOrTokenId,
ref_, 3333,
mintFee
);
}
emit MintFeePaid(questId_, address(0), 0, address(0), 0, ref_, mintFee / 3);
}
}
Expand Down Expand Up @@ -490,6 +515,10 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
defaultMintFeeRecipient = mintFeeRecipient_;
}

function setReferralRewardTimestamp(uint256 timestamp_) external onlyOwner {
referralRewardTimestamp = timestamp_;
}

/*//////////////////////////////////////////////////////////////
EXTERNAL VIEW
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -619,16 +648,31 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
);

if (claimData_.ref != address(0)) {
emit QuestClaimedReferred(
claimData_.claimer,
currentQuest.questAddress,
claimData_.questId,
questContract_.rewardToken(),
questContract_.tokenId(),
claimData_.ref,
3333, //referralFee,
mintFee
if (IQuestOwnable(currentQuest.questAddress).startTime() > referralRewardTimestamp) {
emit QuestClaimReferred(
claimData_.claimer,
currentQuest.questAddress,
claimData_.questId,
questContract_.rewardToken(),
questContract_.tokenId(),
claimData_.ref,
3333, //referralFee,
mintFee,
0,
0
);
} else {
emit QuestClaimedReferred(
claimData_.claimer,
currentQuest.questAddress,
claimData_.questId,
questContract_.rewardToken(),
questContract_.tokenId(),
claimData_.ref,
3333, //referralFee,
mintFee
);
}
}
}

Expand Down Expand Up @@ -671,16 +715,31 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
);

if (claimData_.ref != address(0)) {
emit QuestClaimedReferred(
claimData_.claimer,
currentQuest.questAddress,
claimData_.questId,
questContract_.rewardToken(),
questContract_.rewardAmountInWei(),
claimData_.ref,
3333, //referralFee,
mintFee
);
if (IQuestOwnable(currentQuest.questAddress).startTime() > referralRewardTimestamp) {
emit QuestClaimReferred(
claimData_.claimer,
currentQuest.questAddress,
claimData_.questId,
questContract_.rewardToken(),
questContract_.rewardAmountInWei(),
claimData_.ref,
3333, //referralFee,
mintFee,
0,
0
);
} else {
emit QuestClaimedReferred(
claimData_.claimer,
currentQuest.questAddress,
claimData_.questId,
questContract_.rewardToken(),
questContract_.rewardAmountInWei(),
claimData_.ref,
3333, //referralFee,
mintFee
);
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions contracts/interfaces/IQuestFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ interface IQuestFactory {
uint16 referralFee,
uint256 mintFeeEthWei
);
event QuestClaimReferred(
address indexed recipient,
address indexed questAddress,
string questId,
address rewardToken,
uint256 rewardAmountInWeiOrTokenId,
address referrer,
uint16 referralFee,
uint256 mintFeeEthWei,
uint256 tokenReferralFee,
uint256 referralClaimAmount
);
event MintFeePaid(
string questId,
address rabbitHoleAddress,
Expand Down

0 comments on commit ed12804

Please sign in to comment.