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

automatic wallet fund #323

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 8 additions & 1 deletion src/paymasters/SponsorPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,14 @@ contract SponsorPaymaster is Initializable, BasePaymaster, UUPSUpgradeable, Reen

address sponsor = appRegistry.getApp(_decodeCallData(userOp.callData));
if (unlockBlock[sponsor] != 0) revert DepositNotLocked();
if (balances[sponsor] < ethMaxCost) revert DepositTooLow();
if (balances[sponsor] < ethMaxCost) {
// Apps need to pay
if (sponsor != userOp.sender) {
revert DepositTooLow();
}
// Wallets get auto funded by kinto core app
sponsor = appRegistry.getApp(address(walletFactory));
}
return (abi.encode(sponsor, userOp.sender, userOp.maxFeePerGas, userOp.maxPriorityFeePerGas), 0);
}

Expand Down
19 changes: 19 additions & 0 deletions test/unit/SponsorPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {IKintoWalletFactory} from "@kinto-core/interfaces/IKintoWalletFactory.so

import "@kinto-core-test/SharedSetup.t.sol";

import "forge-std/console2.sol";

contract SponsorPaymasterUpgrade is SponsorPaymaster {
constructor(IEntryPoint __entryPoint, IKintoWalletFactory factory, address _owner)
SponsorPaymaster(__entryPoint, factory)
Expand Down Expand Up @@ -253,6 +255,23 @@ contract SponsorPaymasterTest is SharedSetup {
_paymaster.validatePaymasterUserOp(userOp, "", 0);
}

function testValidatePaymasterUserOp_WhenWalletIsApp() public {
address wallet = address(alice);
UserOperation memory userOp = _createUserOperation(
wallet, wallet, 0, privateKeys, abi.encodeWithSignature("increment()"), address(_paymaster)
);

address kintoCoreApp = _paymaster.appRegistry().getApp(address(_walletFactory));

vm.prank(address(_entryPoint));
(bytes memory context, uint256 validationData) = _paymaster.validatePaymasterUserOp(userOp, "", 0.01 ether);

assertEq(validationData, 0);
(address sponsor, address sender,,) = abi.decode(context, (address, address, uint256, uint256));
assertEq(sponsor, kintoCoreApp, "Sponsor for the wallet has to be a Kinto App");
assertEq(sender, wallet, "Sender has to be a wallet");
}

function testValidatePaymasterUserOp_RevertWhen_GasLimitIsLessThanCostOfPost() public {
UserOperation memory userOp = _createUserOperation(
address(_kintoWallet),
Expand Down
Loading