-
Notifications
You must be signed in to change notification settings - Fork 5
FleetTreasuryPaymaster — whitelisted contract destinations #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
Douglasacost
wants to merge
1
commit into
main
Choose a base branch
from
feat/fleet-paymastering
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,8 +12,9 @@ import {QuotaControl} from "../QuotaControl.sol"; | |||||||||||||||||||||||||||
| /// users call FleetIdentityUpgradeable.claimUuidSponsored(), which calls | ||||||||||||||||||||||||||||
| /// this contract's `consumeSponsoredBond` to validate + consume quota, | ||||||||||||||||||||||||||||
| /// then pulls the NODL bond via `transferFrom`. | ||||||||||||||||||||||||||||
| /// The ZkSync paymaster validation ensures only whitelisted users calling | ||||||||||||||||||||||||||||
| /// FleetIdentity get gas-sponsored. | ||||||||||||||||||||||||||||
| /// Gas sponsorship: `fleetIdentity` is seeded into `isWhitelistedContract` at | ||||||||||||||||||||||||||||
| /// deploy; admins add more destinations the same way. Admin-only calls to this | ||||||||||||||||||||||||||||
| /// contract use `WHITELIST_ADMIN_ROLE` instead of user whitelist. | ||||||||||||||||||||||||||||
| contract FleetTreasuryPaymaster is BasePaymaster, QuotaControl { | ||||||||||||||||||||||||||||
| using SafeERC20 for IERC20; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -23,16 +24,22 @@ contract FleetTreasuryPaymaster is BasePaymaster, QuotaControl { | |||||||||||||||||||||||||||
| IERC20 public immutable bondToken; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| mapping(address => bool) public isWhitelistedUser; | ||||||||||||||||||||||||||||
| /// @notice Allowed destinations for sponsored txs; always includes `fleetIdentity` (set in constructor). | ||||||||||||||||||||||||||||
| mapping(address => bool) public isWhitelistedContract; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| event WhitelistedUsersAdded(address[] users); | ||||||||||||||||||||||||||||
| event WhitelistedUsersRemoved(address[] users); | ||||||||||||||||||||||||||||
| event WhitelistedContractsAdded(address[] contracts); | ||||||||||||||||||||||||||||
| event WhitelistedContractsRemoved(address[] contracts); | ||||||||||||||||||||||||||||
| event TokensWithdrawn(address indexed token, address indexed to, uint256 amount); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| error UserIsNotWhitelisted(); | ||||||||||||||||||||||||||||
| error DestIsNotWhitelisted(); | ||||||||||||||||||||||||||||
| error DestinationNotAllowed(); | ||||||||||||||||||||||||||||
| error PaymasterBalanceTooLow(); | ||||||||||||||||||||||||||||
| error NotFleetIdentity(); | ||||||||||||||||||||||||||||
| error InsufficientBondBalance(); | ||||||||||||||||||||||||||||
| error CannotRemoveFleetIdentity(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| constructor( | ||||||||||||||||||||||||||||
| address admin, | ||||||||||||||||||||||||||||
|
|
@@ -45,6 +52,10 @@ contract FleetTreasuryPaymaster is BasePaymaster, QuotaControl { | |||||||||||||||||||||||||||
| _grantRole(WHITELIST_ADMIN_ROLE, admin); | ||||||||||||||||||||||||||||
| fleetIdentity = fleetIdentity_; | ||||||||||||||||||||||||||||
| bondToken = IERC20(bondToken_); | ||||||||||||||||||||||||||||
| isWhitelistedContract[fleetIdentity_] = true; | ||||||||||||||||||||||||||||
| address[] memory seeded = new address[](1); | ||||||||||||||||||||||||||||
| seeded[0] = fleetIdentity_; | ||||||||||||||||||||||||||||
| emit WhitelistedContractsAdded(seeded); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // ────────────────────────────────────────────── | ||||||||||||||||||||||||||||
|
|
@@ -86,6 +97,23 @@ contract FleetTreasuryPaymaster is BasePaymaster, QuotaControl { | |||||||||||||||||||||||||||
| emit WhitelistedUsersRemoved(users); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| function addWhitelistedContracts(address[] calldata contracts_) external { | ||||||||||||||||||||||||||||
| _checkRole(WHITELIST_ADMIN_ROLE); | ||||||||||||||||||||||||||||
| for (uint256 i = 0; i < contracts_.length; i++) { | ||||||||||||||||||||||||||||
| isWhitelistedContract[contracts_[i]] = true; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| emit WhitelistedContractsAdded(contracts_); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| function removeWhitelistedContracts(address[] calldata contracts_) external { | ||||||||||||||||||||||||||||
| _checkRole(WHITELIST_ADMIN_ROLE); | ||||||||||||||||||||||||||||
| for (uint256 i = 0; i < contracts_.length; i++) { | ||||||||||||||||||||||||||||
| if (contracts_[i] == fleetIdentity) revert CannotRemoveFleetIdentity(); | ||||||||||||||||||||||||||||
| isWhitelistedContract[contracts_[i]] = false; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| emit WhitelistedContractsRemoved(contracts_); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // ────────────────────────────────────────────── | ||||||||||||||||||||||||||||
| // ERC-20 Withdrawal | ||||||||||||||||||||||||||||
| // ────────────────────────────────────────────── | ||||||||||||||||||||||||||||
|
|
@@ -102,14 +130,21 @@ contract FleetTreasuryPaymaster is BasePaymaster, QuotaControl { | |||||||||||||||||||||||||||
| // ────────────────────────────────────────────── | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| function _validateAndPayGeneralFlow(address from, address to, uint256 requiredETH) internal view override { | ||||||||||||||||||||||||||||
| if (to == fleetIdentity) { | ||||||||||||||||||||||||||||
| if (!isWhitelistedUser[from]) revert UserIsNotWhitelisted(); | ||||||||||||||||||||||||||||
| } else if (to == address(this)) { | ||||||||||||||||||||||||||||
| if (!hasRole(WHITELIST_ADMIN_ROLE, from)) revert DestinationNotAllowed(); | ||||||||||||||||||||||||||||
| if (to == address(this)) { | ||||||||||||||||||||||||||||
| if (!hasRole(WHITELIST_ADMIN_ROLE, from)) { | ||||||||||||||||||||||||||||
| revert DestinationNotAllowed(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } else if (isWhitelistedContract[to]) { | ||||||||||||||||||||||||||||
| if (!isWhitelistedUser[from]) { | ||||||||||||||||||||||||||||
| revert UserIsNotWhitelisted(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+133
to
+140
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest a simplification as follows
Suggested change
Then make sure that in the constructor you add |
||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| revert DestinationNotAllowed(); | ||||||||||||||||||||||||||||
| revert DestIsNotWhitelisted(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (address(this).balance < requiredETH) { | ||||||||||||||||||||||||||||
| revert PaymasterBalanceTooLow(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| if (address(this).balance < requiredETH) revert PaymasterBalanceTooLow(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| function _validateAndPayApprovalBasedFlow(address, address, address, uint256, bytes memory, uint256) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If you take my other suggestions, then consider renaming FleetTreasuryPaymaster to TreasuryPaymaster or use your AI assistant to suggest a better name that matches the contract logic.