Skip to content

Commit

Permalink
Merge pull request #85 from rhinestonewtf/feature/auto-save-event
Browse files Browse the repository at this point in the history
emit event for auto saving and implement onUninstall
  • Loading branch information
kopy-kat authored Mar 14, 2024
2 parents e0b00e4 + 5352229 commit ea59407
Showing 1 changed file with 12 additions and 2 deletions.
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);
}

function validateSessionParams(
Expand Down

0 comments on commit ea59407

Please sign in to comment.