Skip to content
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

fix approve #2722

Open
wants to merge 2 commits into
base: xl/remove_salt
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 0 additions & 10 deletions packages/hebao_v3/contracts/base/SmartWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 3 additions & 14 deletions packages/hebao_v3/contracts/base/libwallet/AutomationLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ library AutomationLib {
uint validUntils
);

event AutomationUnapproveExecutor(address wallet, address executor);

function _spell(
address _target,
bytes memory _data
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion packages/hebao_v3/deployments/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
"USDT": "0xB2DC2da9684DfEF77CFa5c6bb07e733023715292",
"LRC": "0xc837BbEa8C7b0caC0e8928f797ceB04A34c9c06e"
}
}
}
5 changes: 5 additions & 0 deletions packages/hebao_v3/test/automation/automation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions packages/hebao_v3/test/automation/automation_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
const {
smartWallet,
Expand All @@ -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]
Expand Down Expand Up @@ -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,
Expand Down