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

emit event for auto saving and implement onUninstall #85

Merged
merged 2 commits into from
Mar 14, 2024
Merged
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
14 changes: 12 additions & 2 deletions examples/src/AutoSavings/AutoSavings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ contract AutoSavingToVault is ERC7579ExecutorBase, SessionKeyBase {

mapping(address account => mapping(address token => Config)) internal _config;

event AutoSaveExecuted(
address indexed smartAccount, address indexed token, uint256 amountReceived
);

/*//////////////////////////////////////////////////////////////////////////
CONFIG
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -57,7 +61,11 @@ contract AutoSavingToVault is ERC7579ExecutorBase, SessionKeyBase {
}

function onUninstall(bytes calldata data) external override {
// Todo
if (data.length == 0) return;
address[] memory tokens = abi.decode(data, (address[]));
for (uint256 i; i < tokens.length; i++) {
delete _config[msg.sender][tokens[i]];
}
}

function isInitialized(address smartAccount) external view returns (bool) {
Expand All @@ -76,7 +84,7 @@ contract AutoSavingToVault is ERC7579ExecutorBase, SessionKeyBase {
pure
returns (uint256)
{
return amountReceived * percentage / 100;
return (amountReceived * percentage) / 100;
}

function autoSave(Params calldata params) external {
Expand Down Expand Up @@ -117,6 +125,8 @@ contract AutoSavingToVault is ERC7579ExecutorBase, SessionKeyBase {

// execute deposit to vault on account
_execute(approveAndDeposit);

emit AutoSaveExecuted(msg.sender, params.token, amountIn);
Copy link
Member

Choose a reason for hiding this comment

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

fyi amountIn is the amount going into the vault (ie amountReceived * percentage) but this works too

}

function validateSessionParams(
Expand Down
Loading