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

Decouple quest claim data #266

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions contracts/QuestFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,27 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto

if(tx.origin != msg.sender) revert txOriginMismatch();

string memory jsonData_ = this.buildJsonString(txHash_, txHashChainId_, quest_.actionType, quest_.questName);
string memory jsonData_ = _buildJsonString(txHash_, txHashChainId_, quest_.actionType);
bytes memory claimData_ = abi.encode(msg.sender, ref_, questIdString_, jsonData_);

this.claimOptimized{value: msg.value}(abi.encodePacked(r_,vs_), claimData_);
_claimOptimized(abi.encodePacked(r_,vs_), claimData_);
}

/// @notice External use is deprecated
/// @dev Claim rewards for a quest
/// @param data_ The claim data in abi encoded bytes
/// @param signature_ The signature of the claim data
/// @param data_ The claim data in abi encoded bytes
function claimOptimized(bytes calldata signature_, bytes calldata data_) external payable {
_claimOptimized(signature_, data_);
}

/// @dev Claim rewards for a quest
/// @param signature_ The signature of the claim data
/// @param data_ The claim data in abi encoded bytes
function _claimOptimized(
bytes memory signature_,
bytes memory data_
) internal {
(
address claimer_,
address ref_,
Expand Down Expand Up @@ -809,23 +819,40 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
questContract.transferOwnership(sender);
}

/// @dev Build the expected json string for a quest
/// @param txHash The transaction hash
/// @param txHashChainId The chain id of the transaction hash
/// @param actionType The action type for the quest
/// @param -deprecated- The name of the quest
/// @return string The json string
function buildJsonString(
bytes32 txHash,
uint32 txHashChainId,
string memory actionType,
string memory questName
string memory // questName - not used
) external pure returns (string memory) {
return _buildJsonString(txHash, txHashChainId, actionType);
}

/// @dev Build the expected json string for a quest
/// @param txHash The transaction hash
/// @param txHashChainId The chain id of the transaction hash
/// @param actionType The action type for the quest
/// @return string The json string
function _buildJsonString(
bytes32 txHash,
uint32 txHashChainId,
string memory actionType
) internal pure returns (string memory) {
// {
// actionTxHashes: ["actionTxHash1"],
// actionNetworkChainIds: ["chainId1"],
// questName: "quest name",
// actionType: "mint"
// }
return string(abi.encodePacked(
'{"actionTxHashes":["', uint256(txHash).toHexString(32),
'"],"actionNetworkChainIds":[', uint256(txHashChainId).toString(),
'],"questName":"', questName,
'","actionType":"', actionType, '"}'
'],"actionType":"', actionType, '"}'
));
}

Expand Down
10 changes: 6 additions & 4 deletions test/QuestClaimable.t.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.19;

// solhint-disable no-global-import, no-console
import "forge-std/Test.sol";
import "forge-std/console.sol";

import {SampleERC1155} from "contracts/test/SampleERC1155.sol";
import {SampleERC20} from "contracts/test/SampleERC20.sol";
import {QuestFactory} from "contracts/QuestFactory.sol";
Expand Down Expand Up @@ -90,7 +92,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
vm.warp(START_TIME + 1);

bytes32 txHash = hex'001975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516';
string memory json = '{"actionTxHashes":["0x001975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[101],"questName":"questName","actionType":"actionType"}';
string memory json = '{"actionTxHashes":["0x001975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[101],"actionType":"actionType"}';
bytes memory signData = abi.encode(participant, referrer, "550e8400-e29b-41d4-a716-446655440000", json);
bytes32 msgHash = keccak256(signData);
bytes32 digest = ECDSA.toEthSignedMessageHash(msgHash);
Expand Down Expand Up @@ -161,7 +163,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
vm.warp(START_TIME + 1);

bytes32 txHash = hex'001975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516';
string memory json = '{"actionTxHashes":["0x001975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[101],"questName":"questName","actionType":"actionType"}';
string memory json = '{"actionTxHashes":["0x001975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[101],"actionType":"actionType"}';
bytes memory signData = abi.encode(participant, referrer, "550e8400-e29b-41d4-a716-446655440000", json);
bytes32 msgHash = keccak256(signData);
bytes32 digest = ECDSA.toEthSignedMessageHash(msgHash);
Expand Down Expand Up @@ -231,7 +233,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
vm.warp(START_TIME + 1);

bytes32 txHash = hex'7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516';
string memory json = '{"actionTxHashes":["0x7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[7777777],"questName":"questName","actionType":"actionType"}';
string memory json = '{"actionTxHashes":["0x7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[7777777],"actionType":"actionType"}';
bytes memory signData = abi.encode(participant, referrer, "550e8400-e29b-41d4-a716-446655440000", json);
bytes32 msgHash = keccak256(signData);
bytes32 digest = ECDSA.toEthSignedMessageHash(msgHash);
Expand Down Expand Up @@ -276,7 +278,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
vm.warp(START_TIME + 1);

bytes32 txHash = hex'7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516';
string memory json = '{"actionTxHashes":["0x7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[7777777],"questName":"questName","actionType":"actionType"}';
string memory json = '{"actionTxHashes":["0x7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[7777777],"actionType":"actionType"}';
bytes memory signData = abi.encode(participant, referrer, "550e8400-e29b-41d4-a716-446655440000", json);
bytes32 msgHash = keccak256(signData);
bytes32 digest = ECDSA.toEthSignedMessageHash(msgHash);
Expand Down
4 changes: 3 additions & 1 deletion test/QuestFactory.t.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.19;

// solhint-disable no-global-import, no-console
import "forge-std/Test.sol";
import "forge-std/console.sol";

import {SampleERC1155} from "contracts/test/SampleERC1155.sol";
import {SampleERC20} from "contracts/test/SampleERC20.sol";
import {QuestFactory} from "contracts/QuestFactory.sol";
Expand Down Expand Up @@ -46,7 +48,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
PROJECT_NAME: "projectName",
CHAIN_ID : 7777777,
TX_HASH : hex'7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516',
JSON_MSG : '{"actionTxHashes":["0x7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[7777777],"questName":"questName","actionType":"actionType"}'
JSON_MSG : '{"actionTxHashes":["0x7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[7777777],"actionType":"actionType"}'
});
address protocolFeeRecipient = makeAddr("protocolFeeRecipient");
address questCreator = makeAddr(("questCreator"));
Expand Down
Loading