Skip to content

feat: add example spending limit hook #102

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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open

Conversation

zhongeric
Copy link
Collaborator

No description provided.

@zhongeric zhongeric changed the base branch from main to develop-set-can-execute-hook April 7, 2025 19:21
@zhongeric zhongeric changed the base branch from develop-set-can-execute-hook to main April 8, 2025 01:27
/// @dev An enumerable set of the periods.
EnumerableSetLib.Uint8Set periods;
/// @dev Mapping of `uint8(period)` to `TokenPeriodSpendStorage`.
mapping(uint256 => TokenPeriodSpendStorage) spends;
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 BY period? How would that work if you have two spend periods for the same token that overlap? You'll have to check both periods states and combine the spends somehow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you have two periods for the same token they all must be true:

  • Minute, 10 AND hour, 100

You would loop through all of the periods, increment the spend for each and check none exceed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You add the same amount to each tracked period spend

/// @dev Set the spend limit for a key hash.
/// Uses msg.sender to compute the accountKeyHash.
function setSpendLimit(bytes32 keyHash, address token, SpendPeriod period, uint256 limit) external {
AccountKeyHash accountKeyHash = keyHash.wrap(msg.sender);
Copy link
Member

Choose a reason for hiding this comment

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

maybe use a different word? wrap is keyword for a custom type

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok! I did hashSender

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

Successfully merging this pull request may close these issues.

2 participants