Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capx Community Quest and Community Quest Forger With Reputation Score Changes #6

Open
wants to merge 11 commits into
base: feature/gameResources
Choose a base branch
from

Conversation

sanjaybaskaran01
Copy link
Member

No description provided.

@sanjaybaskaran01 sanjaybaskaran01 added the enhancement New feature or request label Dec 25, 2023
@sanjaybaskaran01 sanjaybaskaran01 self-assigned this Dec 25, 2023
@sanjaybaskaran01 sanjaybaskaran01 changed the title Feature/capx reputation score Capx Community Quest and Community Quest Forger With Reputation Score Changes Dec 25, 2023
@@ -73,15 +96,10 @@ contract CapxCommunityQuest is ReentrancyGuard, PausableUpgradeable, OwnableUpgr
return string(buffer);
}

function recoverSigner(bytes32 messagehash, bytes memory signature) public pure returns (address) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unnecessary imports from the file associated to the deleted functions.

import "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";

if(IERC20(currCapxQuest.rewardToken).balanceOf(address(this)) < _rewardAmountInWei) revert NoRewardsToClaim();
require(
_timestamp < block.timestamp,
"CapxCommunityQuest: Cannot Claim Future Rewards"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this error message into an error category.

_timestamp < block.timestamp,
"CapxCommunityQuest: Cannot Claim Future Rewards"
);
require(_questId != 0, "CapxCommunityQuest: Invalid Community QuestId");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this error message into an error category.

_receiver,
_timestamp,
currCapxQuest.rewardToken,
address(this),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the need to have address(this) as a parameter in the even emission ?

@@ -69,6 +87,13 @@ contract CapxCommunityQuestForger is Initializable, UUPSUpgradeable, OwnableUpgr
capxCommunityQuest = _capxCommunityQuest;
}

function updateCapxReputationScoreAddress(address _capxReputationScore)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is capxReputationScore contract not part of the initialize function ?

string memory _questId = string(abi.encodePacked(quest.communityId,"_",uintToStr(quest.questNumber)));
require(
community[quest.communityId] != address(0),
"CapxCommunityQuestForger: Invalid Community Id"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this error message into an error category.

_rewardAmount
require(
address(capxQuest) != address(0),
"CapxCommunityQuestForger: Invalid Capx Quest ID"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this error message into an error category.

);
}else{
revert InvalidRewardType();
}
}

function emitClaim(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we remove this function as emission of the ReputationScore is in the claim function but the IOU Token reward claim has a seperate function. This would reduce the number of internal contract calls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rewardToken is stored in memory in the community contract and not in the forger contract , should I keep a map of communityIds to their respective token contracts in the forger contract? While emitting the event it requires the token contract address as well.


function recoverSigner(bytes32 messagehash, bytes memory signature)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a public function and not an internal function ?

@@ -22,11 +21,9 @@ interface ICapxCommunityQuest {
error ClaimedRewardsExceedTotalRewards();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove un-used error categories from the interface.

QuestDTO memory quest
) external nonReentrant whenNotPaused onlyForger {
// Transfer tokens.
ITokenPoweredByCapx(quest.rewardToken).addToWhitelist(address(this));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanjaybaskaran01 Why are we whitelisting the rewardToken in this method ?

string memory _communityQuestId = string(abi.encodePacked(communityId,"_",uintToStr(_questId)));
if(currCapxQuest.rewardToken != address(0)) revert QuestIdUsed();

function setQuestDetails(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for naming this function setQuestDetails and not createQuest can we modify the quest details apart from the reference variables once we have created it ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for naming this function setQuestDetails and not createQuest can we modify the quest details apart from the reference variables once we have created it ?

Yes, we utilise the same function for updating the quest details.

if(currCapxQuest.rewardToken != address(0)) revert QuestIdUsed();

function setQuestDetails(
QuestDTO memory quest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the naming convention behind QuestDTO ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the naming convention behind QuestDTO ?

We are creating transferrable objects for setting the quest details in both communityQuest contract and as well as reputationScore contract.

CommunityForger -> CapxQuestDetails (struct )

Community -> QuestDTO ( struct , part of CapxQuestDetails of CommunityForger )

CapxReputationScore -> QuestDTO ( struct, part of CapxQuestDetails of CommunityForger )

Using the term DTO to signify that they are merely just a transfer objects for respective contracts which will be set as CapxQuestDetail for their respective contracts.

) external nonReentrant whenNotPaused onlyForger {
// Transfer tokens.
ITokenPoweredByCapx(quest.rewardToken).addToWhitelist(address(this));
IERC20(quest.rewardToken).safeTransferFrom(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the transfer of tokens being done from the community quest contract and not from the CommunityQuestForger ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted all the community specific actions to exist inside the communityQuest contract.

This is the differentiation I was going for:

CapxCommunityQuest Contract:

  • This contract will handle the details of individual community quests
  • Its main job is to manage everything about a quest, like tracking rewards, who is participating, and the quest's overall status
  • It deals with ERC20 token transactions directly. This way, all the important actions and changes for a quest happen in one place, which makes the system more organized and easier to handle

CapxCommunityQuestForger Contract:

  • This contract acts like creator and manager for multiple CapxCommunityQuest instances.
  • Its main role is to set up new community quests, establish their initial settings, and link quests to their respective communities.
  • It should not get involved in the specifics of token transactions for quests. It focuses on higher-level tasks like setting up and managing quests, which keeps things simpler and more focused.

@@ -1,17 +1,22 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
pragma solidity ^0.8.18 .0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this solidity version naming convention ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had it modified due to this linting rule:
https://protofire.github.io/solhint/docs/rules/security/compiler-version.html

This is the stack overflow link:
https://stackoverflow.com/questions/72180057/error-compiler-version-0-8-0-does-not-satisfy-the-r-semver-requirement

But reverted the versioning to ^0.8.18 and removed the linting rule for semver.


// Create Quest.
if (quest.rewardType == 1) {
ICapxCommunityQuest(communityAddress).setQuestDetails(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this method is called, the QuestForger should transfer the necessary amount tokens into the community Forger.


function updateRewardType(
RewardTypeDTO calldata _newRewards,
bytes calldata _IOURewardsData,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the need to encode the IOURewardsData when you are only using the corresponding QuestDTO as the only decoded input value ?

ICapxCommunityQuest(communityAddress).withdrawTokens(tokens);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function missing to withdrawETH & WithdrawTokens from CapxCommunityQuestForger.


// Scores for different categories
// 1. Social 2. Defi 3. Game
struct ReputationScoreTypes {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define all the structs , events in the Interface.


interface ICapxCommunityQuest {

error AlreadyClaimed();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unncessary error types from the contract definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants