-
Notifications
You must be signed in to change notification settings - Fork 23
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
add claimCompressed #238
add claimCompressed #238
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - tried to signal to anywhere I see room for future improvements but I think this is good as is. Do with my comments what you wish
@@ -147,6 +148,7 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto | |||
/// @param totalParticipants_ The total amount of participants (accounts) the quest will have | |||
/// @param tokenId_ The reward token id of the erc1155 at rewardTokenAddress_ | |||
/// @param questId_ The id of the quest | |||
/// @param actionType_ The action type for the quest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add questName_
to params
contracts/QuestFactory.sol
Outdated
bytes memory uuid = new bytes(36); // UUID length with hyphens | ||
|
||
uint256 j = 0; // Position in uuid | ||
for (uint256 i = 0; i < 16; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do this with a single index vs 2 if we keep the j++
statements and do a while instead of a for. I think it'd be possible with a for too just without the third statement. Not sure if this is worth it though - as we've found compute is cheap!
contracts/QuestFactory.sol
Outdated
)); | ||
} | ||
|
||
function bytes16ToUUID(bytes16 data) public pure returns (string memory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you comment the encoding and expectations around the form of the bytes16
data here?
contracts/QuestFactory.sol
Outdated
( | ||
address ref, | ||
bytes32 txHash, | ||
uint32 txHashChainId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's few enough chains that we could use a smaller value here and then leverage a lookup table - uint8 should work fine for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine to capture this for a follow-on just trying to see where else we could trim the call data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added notes in the description about possible ways to get the bytes down in the future.
contracts/QuestFactory.sol
Outdated
@@ -293,6 +247,68 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto | |||
/*////////////////////////////////////////////////////////////// | |||
CLAIM | |||
//////////////////////////////////////////////////////////////*/ | |||
function claimCompressed(bytes calldata compressedData) external payable { | |||
bytes memory data = LibZip.cdDecompress(compressedData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wild - do we know if ordering effects the efficiency of the compression at all? That code is hard to parse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ordering does, generally you want to have zero bytes in the middle.
bytes16 questid, | ||
bytes32 r, | ||
bytes32 vs | ||
) = abi.decode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put the params smaller than a block at the end? I don't think it matters here but generally good form.
contracts/QuestFactory.sol
Outdated
(address, bytes32, uint32, bytes16, bytes32, bytes32) | ||
); | ||
|
||
string memory questIdString = bytes16ToUUID(questid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So cool - love this. I'm surprised there's not an off-the-shelf bytes16toUUID util. Maybe we can ask for one in solady/solmate and import that once the optomizzeeddd version is available wdyt? Again though, not super important since apparently compute is so cheap on L2
contracts/QuestFactory.sol
Outdated
|
||
string memory questIdString = bytes16ToUUID(questid); | ||
Quest storage quest = quests[questIdString]; | ||
string memory jsonData = buildJsonString(uint256(txHash).toHexString(), uint256(txHashChainId).toString(), quest.actionType, quest.questName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah - here is where you're pulling that back in. Totally makes sense now.
return string(uuid); | ||
} | ||
|
||
|
||
function claimOptimized(bytes calldata signature_, bytes calldata data_) external payable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should change the visibility of this to internal or public if we're using it internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to keep it external so that it's backwards compatible. Eventually once everyone is using the new function we can make it internal.
Non breaking changes
claimCompressed
function for optimized calldata, it just forwards toclaimOptimized
, so no breaking changes.QuestCreatedWithAction
event as it wasn't used.createERC20Quest
andcreateERC1155Quest
functions that include two new string params:actionType_
andquestName_
.Deployment plan
questName
andactionType
the newclaimCompressed
function not work on any quests that don't have this data saved on chain, this function should only be used on quests that have this data.Ideas for further reducing claim calldata
abi.encodePacked
to encode the calldata andcalldataload
to get data from offset (not recommended if ever plan to pass dynamic types), this would remove the need for LibZip