diff --git a/packages/hebao_v3/contracts/base/SmartWallet.sol b/packages/hebao_v3/contracts/base/SmartWallet.sol index f10a56d65..342ce671b 100644 --- a/packages/hebao_v3/contracts/base/SmartWallet.sol +++ b/packages/hebao_v3/contracts/base/SmartWallet.sol @@ -498,16 +498,6 @@ abstract contract SmartWallet is return AutomationLib.approveExecutor(wallet, executor, validUntil); } - function unApproveExecutor( - address executor - ) external onlyFromEntryPointOrWalletOrOwnerWhenUnlocked { - _require( - AutomationLib.isExecutorOrOwner(wallet, executor), - Errors.NOT_EXECUTOR - ); - return AutomationLib.unApproveExecutor(wallet, executor); - } - function castFromEntryPoint( address[] calldata targets, bytes[] calldata datas diff --git a/packages/hebao_v3/contracts/base/libwallet/AutomationLib.sol b/packages/hebao_v3/contracts/base/libwallet/AutomationLib.sol index 7e8fd6993..c9b4ae7e8 100644 --- a/packages/hebao_v3/contracts/base/libwallet/AutomationLib.sol +++ b/packages/hebao_v3/contracts/base/libwallet/AutomationLib.sol @@ -16,8 +16,6 @@ library AutomationLib { uint validUntils ); - event AutomationUnapproveExecutor(address wallet, address executor); - function _spell( address _target, bytes memory _data @@ -86,19 +84,10 @@ library AutomationLib { address executor, uint256 validUntil ) internal { - require( - wallet.executorsPermission[executor] < validUntil, - "approve failed" - ); + uint256 curValidUntil = wallet.executorsPermission[executor]; + require(curValidUntil == 0 || validUntil == 0, "approve failed"); wallet.executorsPermission[executor] = validUntil; - emit AutomationApproveExecutor(address(this), executor, validUntil); - } - function unApproveExecutor( - Wallet storage wallet, - address executor - ) internal { - wallet.executorsPermission[executor] = 0; - emit AutomationUnapproveExecutor(address(this), executor); + emit AutomationApproveExecutor(address(this), executor, validUntil); } } diff --git a/packages/hebao_v3/deployments/deployments.json b/packages/hebao_v3/deployments/deployments.json index fa5478148..be6a4df0a 100644 --- a/packages/hebao_v3/deployments/deployments.json +++ b/packages/hebao_v3/deployments/deployments.json @@ -58,4 +58,4 @@ "USDT": "0xB2DC2da9684DfEF77CFa5c6bb07e733023715292", "LRC": "0xc837BbEa8C7b0caC0e8928f797ceB04A34c9c06e" } -} \ No newline at end of file +} diff --git a/packages/hebao_v3/test/automation/automation.test.ts b/packages/hebao_v3/test/automation/automation.test.ts index fe7b1b4e2..6114175ea 100644 --- a/packages/hebao_v3/test/automation/automation.test.ts +++ b/packages/hebao_v3/test/automation/automation.test.ts @@ -81,6 +81,11 @@ describe('automation test', () => { ).to.revertedWith('LRC#104') const executor = ethers.Wallet.createRandom() await approveExecutor(loadedFixture, executor.address) + await approveExecutor( + loadedFixture, + executor.address, + ethers.constants.MaxUint256 + ) // check it is a valid executor const { smartWallet } = loadedFixture expect(await smartWallet.isExecutorOrOwner(executor.address)).to diff --git a/packages/hebao_v3/test/automation/automation_utils.ts b/packages/hebao_v3/test/automation/automation_utils.ts index 00691e80a..95fcd3ea8 100644 --- a/packages/hebao_v3/test/automation/automation_utils.ts +++ b/packages/hebao_v3/test/automation/automation_utils.ts @@ -335,7 +335,10 @@ export const userOpCast = async ( export const approveExecutor = async ( loadedFixture: Fixture, - executorAddr: string + executorAddr: string, + validUntil: BigNumberish = Math.floor( + Date.now() / 1000 + 24 * 60 * 60 + ).toString() ): Promise => { const { smartWallet, @@ -345,9 +348,6 @@ export const approveExecutor = async ( sendUserOp } = loadedFixture const nonce = await smartWallet.getNonce() - const validUntil = Math.floor( - Date.now() / 1000 + 24 * 60 * 60 - ).toString() const data = smartWallet.interface.encodeFunctionData( 'approveExecutor', [executorAddr, validUntil] @@ -387,8 +387,8 @@ export const unApproveExecutor = async ( } = loadedFixture const nonce = await smartWallet.getNonce() const data = smartWallet.interface.encodeFunctionData( - 'unApproveExecutor', - [executor] + 'approveExecutor', + [executor, 0] ) const signedUserOp = await getSignedUserOp( data,