Skip to content
Merged
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
35 changes: 31 additions & 4 deletions src/enforcers/MultiTokenPeriodEnforcer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,14 @@ contract MultiTokenPeriodEnforcer is CaveatEnforcer {
view
returns (uint256 availableAmount_, bool isNewPeriod_, uint256 currentPeriod_)
{
uint256 index_ = abi.decode(_args, (uint256));
(address token_,,,) = getTermsInfo(_terms, index_);
(bytes32 hashKey_, uint256 periodAmount_, uint256 periodDuration_, uint256 startDate_) =
_getValues(_delegationHash, _delegationManager, _terms, _args);

bytes32 hashKey_ = _getHashKey(_delegationManager, token_, _delegationHash, index_);
PeriodicAllowance memory storedAllowance_ = periodicAllowances[hashKey_];
if (storedAllowance_.startDate != 0) {
return _getAvailableAmount(storedAllowance_);
}

(, uint256 periodAmount_, uint256 periodDuration_, uint256 startDate_) = getTermsInfo(_terms, index_);
// Not yet initialized; simulate using provided terms.
PeriodicAllowance memory allowance_ = PeriodicAllowance({
periodAmount: periodAmount_,
Expand Down Expand Up @@ -367,4 +365,33 @@ contract MultiTokenPeriodEnforcer is CaveatEnforcer {
{
return keccak256(abi.encode(_delegationManager, _token, _delegationHash, _index));
}

/**
* @notice Extracts and processes values from delegation terms and arguments
* @dev Decodes the index from args, gets token info from terms, and generates a unique hash key
* @param _delegationHash The hash of the delegation
* @param _delegationManager The address of the delegation manager contract
* @param _terms The encoded terms containing token configurations
* @param _args The encoded arguments containing the token configuration index
* @return hashKey_ A unique hash key for identifying this specific delegation/token combination
* @return periodAmount_ The maximum amount that can be transferred per period
* @return periodDuration_ The duration of each period in seconds
* @return startDate_ The timestamp when the periodic allowance begins
*/
function _getValues(
bytes32 _delegationHash,
address _delegationManager,
bytes calldata _terms,
bytes calldata _args
)
internal
pure
returns (bytes32 hashKey_, uint256 periodAmount_, uint256 periodDuration_, uint256 startDate_)
{
uint256 index_ = abi.decode(_args, (uint256));
address token_;
(token_, periodAmount_, periodDuration_, startDate_) = getTermsInfo(_terms, index_);

hashKey_ = _getHashKey(_delegationManager, token_, _delegationHash, index_);
}
}
Loading