You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new ERC20StreamAmountEnforcer.sol should have a similar structure, but with additional epoch terms arguments.
For example you likely want to include startEpoch_ and endEpoch_ to declare when the stream starts and ends.
function getTermsInfo(bytescalldata_terms) publicpurereturns (addressallowedContract_, uint256maxTokens_) {
require(_terms.length==52, "ERC20TransferAmountEnforcer:invalid-terms-length"); // <- Calculate the new length
allowedContract_ =address((bytes20(_terms[:20])));
maxTokens_ =uint256(bytes32(_terms[20:]));
startEpoch_ =uint128(bytes32(_terms[X:Y])); // <- Calculate the correct bytes length and position
endEpoch_ =uint128(bytes32(_terms[Y:])); // <- Calculate the correct bytes length and position
}
The startEpoch_ and endEpoch term inputs will then consume arguments like 1733011200 and 1734134400 packed in bytecode format. Which equates to Sunday, December 1, 2024 12:00:00 AM through Saturday, December 14, 2024 12:00:00 AM for a total of 1123200 seconds i.e. the difference between the start and end times.
Hook Validation
Use the ERC20TransferAmountEnforcer.sol _validateAndIncrease function as a starting point for creating the new ERC20StreamAmountEnforcer.sol validation logic.
Below is commented code for where to start.
function _validateAndIncrease(
bytescalldata_terms,
bytescalldata_executionCallData,
bytes32_delegationHash
)
internalreturns (uint256limit_, uint256spent_)
{
(addresstarget_,, bytescalldatacallData_) = _executionCallData.decodeSingle();
require(callData_.length==68, "ERC20TransferAmountEnforcer:invalid-execution-length");
address allowedContract_;
/// TODO: Return the new terms arguments.
(allowedContract_, limit_) =getTermsInfo(_terms);
require(allowedContract_ == target_, "ERC20TransferAmountEnforcer:invalid-contract");
require(bytes4(callData_[0:4]) ==IERC20.transfer.selector, "ERC20TransferAmountEnforcer:invalid-method");
/// TODO: Validate the startEpoch_ and endEpoch_ values against the current block timestamp./// TODO: Validate the limit_ value against the current stream total calculation.
spent_ = spentMap[msg.sender][_delegationHash] +=uint256(bytes32(callData_[36:68]));
require(spent_ <= limit_, "ERC20TransferAmountEnforcer:allowance-exceeded");
}
Builders Are Rewarded
Create a secure Delegation Framework Enforcer to stream X amount ERC20 tokens over Y time.
The full scope of the issue might not be captured in this ticket. Do your best to think of all security concerns related to the implementation you choose. Full coverage unit tests are expected.
We increase bounty payouts for work that goes above and beyond!
The text was updated successfully, but these errors were encountered:
vishwamartur
added a commit
to vishwamartur/universal-smart-wallet
that referenced
this issue
Nov 26, 2024
Related to district-labs#2
Add ERC20StreamAmountEnforcer module to stream ERC20 tokens over a specified time period.
* Create `ERC20StreamAmountEnforcer.sol` to implement streaming functionality with `getTermsInfo` and `_validateAndIncrease` methods.
* Add unit tests for `ERC20StreamAmountEnforcer.sol` in `test/ERC20StreamAmountEnforcer.t.sol` to ensure complete coverage.
* Update `script/EnforcersDeploy.s.sol` to include deployment of `ERC20StreamAmountEnforcer`.
Context
The Universal wallet uses the MetaMask Delegation Framework for handling wallet delegations, authorizations and intents. The framework includes 20+ enforcer smart contract modules for dictating transaction execution capabilities.
Scope
Create a new enforcer module, similar to ERC20TransferAmountEnforcer to stream X tokens over Y time.
The enforcer module should be named
ERC20StreamAmountEnforcer.sol
and include complete unit test coverage.User Story
As a user I want to stream 100 USDC to my friends wallets over a 2 week time period.
Enforcer Terms
Terms are how users control enforcer module behavior.
Below is an example the
ERC20TransferAmountEnforcer.sol
getTermsInfo function.The new
ERC20StreamAmountEnforcer.sol
should have a similar structure, but with additional epoch terms arguments.For example you likely want to include
startEpoch_
andendEpoch_
to declare when the stream starts and ends.The
startEpoch_
andendEpoch
term inputs will then consume arguments like1733011200
and1734134400
packed in bytecode format. Which equates toSunday, December 1, 2024 12:00:00 AM
throughSaturday, December 14, 2024 12:00:00 AM
for a total of1123200
seconds i.e. the difference between the start and end times.Hook Validation
Use the ERC20TransferAmountEnforcer.sol _validateAndIncrease function as a starting point for creating the new
ERC20StreamAmountEnforcer.sol
validation logic.Below is commented code for where to start.
Builders Are Rewarded
Create a secure Delegation Framework Enforcer to stream X amount ERC20 tokens over Y time.
The full scope of the issue might not be captured in this ticket. Do your best to think of all security concerns related to the implementation you choose. Full coverage unit tests are expected.
We increase bounty payouts for work that goes above and beyond!
The text was updated successfully, but these errors were encountered: