Skip to content

Commit

Permalink
feat: enumerable to array
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Feb 20, 2024
1 parent 5db7958 commit 162d7bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
41 changes: 22 additions & 19 deletions solidity/contracts/core/AutomationVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ contract AutomationVault is IAutomationVault {
/**
* @notice List of approved relays
*/
mapping(address _relay => mapping(address _job => EnumerableSet.Bytes32Set _selectors)) internal
_approvedJobSelectorsList;
mapping(address _relay => mapping(address _job => bytes4[] _selectors)) internal _approvedJobSelectorsList;

/**
* @notice List of approved relays
Expand Down Expand Up @@ -79,7 +78,7 @@ contract AutomationVault is IAutomationVault {
// Get the list of jobs and their selectors
for (uint256 _i; _i < _jobsLength;) {
// Get the length of the selectors array
_selectorsLength = _approvedJobSelectorsList[_relay][_jobs[_i]].length();
_selectorsLength = _approvedJobSelectorsList[_relay][_jobs[_i]].length;

// Create the array of selectors data with the selectors length
SelectorData[] memory _selectorsData;
Expand All @@ -91,7 +90,7 @@ contract AutomationVault is IAutomationVault {

// Get the list of selectors
for (uint256 _j; _j < _selectorsLength;) {
_selectorsData[_j].selector = bytes4(_approvedJobSelectorsList[_relay][_jobs[_i]].at(_j));
_selectorsData[_j].selector = _approvedJobSelectorsList[_relay][_jobs[_i]][_j];
_selectorsData[_j].hookData = _approvedJobSelectorsWithHooks[_relay][_jobs[_i]][_selectorsData[_j].selector];

unchecked {
Expand Down Expand Up @@ -197,7 +196,7 @@ contract AutomationVault is IAutomationVault {
// Set the selectors for the job
for (_j = 0; _j < _selectorsLength;) {
// Add the selector to the list of selectors
_approvedJobSelectorsList[_relay][_jobData.job].add(_selectorsData[_j].selector);
_approvedJobSelectorsList[_relay][_jobData.job].push(_selectorsData[_j].selector);

// Add the selector to the list of selectors with hooks
_approvedJobSelectorsWithHooks[_relay][_jobData.job][_selectorsData[_j].selector] =
Expand Down Expand Up @@ -257,7 +256,7 @@ contract AutomationVault is IAutomationVault {
_valuesLength = _jobs.length;

// Create the selector length variable
bytes32[] memory _selectors;
bytes4[] memory _selectors;

// Create the length variable
uint256 _selectorsLength;
Expand All @@ -267,15 +266,17 @@ contract AutomationVault is IAutomationVault {
_approvedJobs[_relay].remove(_jobs[_i]);

// Get the length of the selectors array
_selectorsLength = _approvedJobSelectorsList[_relay][_jobs[_i]].length();
_selectorsLength = _approvedJobSelectorsList[_relay][_jobs[_i]].length;

// Get the list of selectors
_selectors = _approvedJobSelectorsList[_relay][_jobs[_i]].values();
_selectors = _approvedJobSelectorsList[_relay][_jobs[_i]];

// Delete selectors list
delete _approvedJobSelectorsList[_relay][_jobs[_i]];

// Remove the selectors
for (_j = 0; _j < _selectorsLength;) {
delete _approvedJobSelectorsWithHooks[_relay][_jobs[_i]][bytes4(_selectors[_j])];
_approvedJobSelectorsList[_relay][_jobs[_i]].remove(_selectors[_j]);

unchecked {
++_j;
Expand Down Expand Up @@ -351,7 +352,7 @@ contract AutomationVault is IAutomationVault {
uint256 _jobsLength = _jobs.length;

// Create the selector length variable
bytes32[] memory _selectors;
bytes4[] memory _selectors;

// Create the length variable
uint256 _selectorsLength;
Expand All @@ -361,15 +362,17 @@ contract AutomationVault is IAutomationVault {
_approvedJobs[_relay].remove(_jobs[_i]);

// Get the length of the selectors array
_selectorsLength = _approvedJobSelectorsList[_relay][_jobs[_i]].length();
_selectorsLength = _approvedJobSelectorsList[_relay][_jobs[_i]].length;

// Get the list of selectors
_selectors = _approvedJobSelectorsList[_relay][_jobs[_i]].values();
_selectors = _approvedJobSelectorsList[_relay][_jobs[_i]];

// Delete selectors list
delete _approvedJobSelectorsList[_relay][_jobs[_i]];

// Remove the selectors
for (_j = 0; _j < _selectorsLength;) {
delete _approvedJobSelectorsWithHooks[_relay][_jobs[_i]][bytes4(_selectors[_j])];
_approvedJobSelectorsList[_relay][_jobs[_i]].remove(_selectors[_j]);

unchecked {
++_j;
Expand Down Expand Up @@ -404,7 +407,7 @@ contract AutomationVault is IAutomationVault {
// Set the selectors for the job
for (_j = 0; _j < _selectorsLength;) {
// Add the selector to the list of selectors
_approvedJobSelectorsList[_relay][_jobData.job].add(_selectorsData[_j].selector);
_approvedJobSelectorsList[_relay][_jobData.job].push(_selectorsData[_j].selector);

// Add the selector to the list of selectors with hooks
_approvedJobSelectorsWithHooks[_relay][_jobData.job][_selectorsData[_j].selector] =
Expand Down Expand Up @@ -448,15 +451,15 @@ contract AutomationVault is IAutomationVault {
for (_i; _i < _dataLength;) {
_dataToExecute = _execData[_i];

// Check that the selector is approved to be called
if (!_approvedJobSelectorsList[msg.sender][_dataToExecute.job].contains(bytes4(_dataToExecute.jobData))) {
revert AutomationVault_NotApprovedJobSelector();
}

// Get the hook data
HookData memory _hookData =
_approvedJobSelectorsWithHooks[msg.sender][_dataToExecute.job][bytes4(_dataToExecute.jobData)];

// Check that the selector is approved to be called
if (_hookData.selectorType == JobSelectorType.DISABLED) {
revert AutomationVault_NotApprovedJobSelector();
}

// If the selector type is enabled, execute the job
if (_hookData.selectorType == JobSelectorType.ENABLED) {
(_success,) = _dataToExecute.job.call(_dataToExecute.jobData);
Expand Down
4 changes: 2 additions & 2 deletions solidity/test/unit/AutomationVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract AutomationVaultForTest is AutomationVault {

function addJobSelectorForTest(address _relay, address _job, SelectorData memory _selectorData) public {
_approvedJobs[_relay].add(_job);
_approvedJobSelectorsList[_relay][_job].add(bytes32(_selectorData.selector));
_approvedJobSelectorsList[_relay][_job].push(_selectorData.selector);
_approvedJobSelectorsWithHooks[_relay][_job][_selectorData.selector] = _selectorData.hookData;
}

Expand All @@ -45,7 +45,7 @@ contract AutomationVaultForTest is AutomationVault {
}

for (uint256 _i; _i < _selectors.length; ++_i) {
_approvedJobSelectorsList[_relay][_job].add(bytes32(_selectors[_i]));
_approvedJobSelectorsList[_relay][_job].push(_selectors[_i]);
_approvedJobSelectorsWithHooks[_relay][_job][_selectors[_i]] =
IAutomationVault.HookData(_jobSelectorTypes[_i], _preHooks[_i], _postHooks[_i]);
}
Expand Down

0 comments on commit 162d7bf

Please sign in to comment.