Skip to content

Commit

Permalink
add adam's requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivaanshK committed Jul 3, 2024
1 parent d97036f commit 5da6fbe
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 251 deletions.
14 changes: 6 additions & 8 deletions contracts/common/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
pragma solidity ^0.8.26;

contract BiconomySponsorshipPaymasterErrors {

/**
* @notice Throws when the paymaster address provided is address(0)
*/
error PaymasterIdCannotBeZero();
error PaymasterIdCanNotBeZero();

/**
* @notice Throws when the 0 has been provided as deposit
Expand All @@ -16,26 +15,25 @@ contract BiconomySponsorshipPaymasterErrors {
/**
* @notice Throws when the verifiying signer address provided is address(0)
*/
error VerifyingSignerCannotBeZero();
error VerifyingSignerCanNotBeZero();

/**
* @notice Throws when the fee collector address provided is address(0)
*/
error FeeCollectorCannotBeZero();
error FeeCollectorCanNotBeZero();

/**
* @notice Throws when the fee collector address provided is a deployed contract
*/
error FeeCollectorCannotBeContract();
error FeeCollectorCanNotBeContract();

/**
* @notice Throws when the fee collector address provided is a deployed contract
*/
error VerifyingSignerCannotBeContract();
error VerifyingSignerCanNotBeContract();

/**
* @notice Throws when trying to withdraw to address(0)
*/
error CanNotWithdrawToZeroAddress();

}
}
8 changes: 4 additions & 4 deletions contracts/sponsorship/SponsorshipPaymasterWithPremium.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract BiconomySponsorshipPaymaster is BasePaymaster, ReentrancyGuard, Biconom
* @param paymasterId dapp identifier for which deposit is being made
*/
function depositFor(address paymasterId) external payable nonReentrant {
if (paymasterId == address(0)) revert PaymasterIdCannotBeZero();
if (paymasterId == address(0)) revert PaymasterIdCanNotBeZero();
if (msg.value == 0) revert DepositCanNotBeZero();
paymasterIdBalances[paymasterId] += msg.value;
entryPoint.depositTo{value: msg.value}(address(this));
Expand All @@ -73,9 +73,9 @@ contract BiconomySponsorshipPaymaster is BasePaymaster, ReentrancyGuard, Biconom
) external payable onlyOwner {
uint256 size;
assembly { size := extcodesize(_newVerifyingSigner) }
if(size > 0) revert VerifyingSignerCannotBeContract();
if(size > 0) revert VerifyingSignerCanNotBeContract();
if (_newVerifyingSigner == address(0))
revert VerifyingSignerCannotBeZero();
revert VerifyingSignerCanNotBeZero();
address oldSigner = verifyingSigner;
assembly {
sstore(verifyingSigner.slot, _newVerifyingSigner)
Expand All @@ -93,7 +93,7 @@ contract BiconomySponsorshipPaymaster is BasePaymaster, ReentrancyGuard, Biconom
function setFeeCollector(
address _newFeeCollector
) external payable onlyOwner {
if (_newFeeCollector == address(0)) revert FeeCollectorCannotBeZero();
if (_newFeeCollector == address(0)) revert FeeCollectorCanNotBeZero();
address oldFeeCollector = feeCollector;
assembly {
sstore(feeCollector.slot, _newFeeCollector)
Expand Down
1 change: 1 addition & 0 deletions lib/nexus.git
Submodule nexus.git added at 5d81e5
17 changes: 17 additions & 0 deletions test/foundry/base/BaseEventsAndErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.26;

import { EventsAndErrors } from "nexus/test/foundry/utils/EventsAndErrors.sol";
import { BiconomySponsorshipPaymasterErrors } from "./../../../contracts/common/Errors.sol";

contract BaseEventsAndErrors is EventsAndErrors, BiconomySponsorshipPaymasterErrors {
// ==========================
// Events
// ==========================
event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);

// ==========================
// Errors
// ==========================
error NewOwnerIsZeroAddress();
}
49 changes: 18 additions & 31 deletions test/foundry/base/NexusTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ pragma solidity ^0.8.26;

import { Test } from "forge-std/src/Test.sol";
import { Vm } from "forge-std/src/Vm.sol";
import { console2 } from "forge-std/src/console2.sol";

import "solady/src/utils/ECDSA.sol";

import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

import { EntryPoint } from "account-abstraction/contracts/core/EntryPoint.sol";
import { IEntryPoint } from "account-abstraction/contracts/interfaces/IEntryPoint.sol";
import { PackedUserOperation } from "account-abstraction/contracts/interfaces/PackedUserOperation.sol";
Expand All @@ -17,31 +14,14 @@ import { Nexus } from "nexus/contracts/Nexus.sol";
import { NexusAccountFactory } from "nexus/contracts/factory/NexusAccountFactory.sol";
import { BiconomyMetaFactory } from "nexus/contracts/factory/BiconomyMetaFactory.sol";
import { MockValidator } from "nexus/contracts/mocks/MockValidator.sol";
import { MockHook } from "nexus/contracts/mocks/MockHook.sol";
// import { MockExecutor } from "nexus/contracts/mocks/MockExecutor.sol";
import { MockHandler } from "nexus/contracts/mocks/MockHandler.sol";
import { BootstrapLib } from "nexus/contracts/lib/BootstrapLib.sol";
import {
ModeLib,
ExecutionMode,
ExecType,
CallType,
CALLTYPE_BATCH,
CALLTYPE_SINGLE,
EXECTYPE_DEFAULT,
EXECTYPE_TRY
} from "nexus/contracts/lib/ModeLib.sol";
// import { ExecLib, Execution } from "nexus/contracts/lib/ExecLib.sol";
import { Bootstrap, BootstrapConfig } from "nexus/contracts/utils/Bootstrap.sol";
import { CheatCodes } from "nexus/test/foundry/utils/CheatCodes.sol";
import { EventsAndErrors } from "nexus/test/foundry/utils/EventsAndErrors.sol";
import { BaseEventsAndErrors } from "./BaseEventsAndErrors.sol";

import { BiconomySponsorshipPaymaster } from "../../../contracts/sponsorship/SponsorshipPaymasterWithPremium.sol";

abstract contract NexusTestBase is CheatCodes, EventsAndErrors {
// Events
event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);

abstract contract NexusTestBase is CheatCodes, BaseEventsAndErrors {
// -----------------------------------------
// State Variables
// -----------------------------------------
Expand Down Expand Up @@ -76,13 +56,20 @@ abstract contract NexusTestBase is CheatCodes, EventsAndErrors {

NexusAccountFactory internal FACTORY;
BiconomyMetaFactory internal META_FACTORY;
MockHandler internal HANDLER_MODULE;
// MockExecutor internal EXECUTOR_MODULE;
MockValidator internal VALIDATOR_MODULE;
Nexus internal ACCOUNT_IMPLEMENTATION;

Bootstrap internal BOOTSTRAPPER;

// -----------------------------------------
// Modifiers
// -----------------------------------------
modifier prankModifier(address pranker) {
startPrank(pranker);
_;
stopPrank();
}

// -----------------------------------------
// Setup Functions
// -----------------------------------------
Expand Down Expand Up @@ -132,8 +119,6 @@ abstract contract NexusTestBase is CheatCodes, EventsAndErrors {
META_FACTORY = new BiconomyMetaFactory(address(FACTORY_OWNER.addr));
vm.prank(FACTORY_OWNER.addr);
META_FACTORY.addFactoryToWhitelist(address(FACTORY));
HANDLER_MODULE = new MockHandler();
// EXECUTOR_MODULE = new MockExecutor();
VALIDATOR_MODULE = new MockValidator();
BOOTSTRAPPER = new Bootstrap();
}
Expand Down Expand Up @@ -273,11 +258,11 @@ abstract contract NexusTestBase is CheatCodes, EventsAndErrors {
bytes memory signature = signUserOp(wallet, userOp);
userOp.signature = signature;
}

/// @notice Retrieves the nonce for a given account and validator
/// @param account The account address
/// @param validator The validator address
/// @return nonce The retrieved nonce

function getNonce(address account, address validator) internal view returns (uint256 nonce) {
uint192 key = uint192(bytes24(bytes20(address(validator))));
nonce = ENTRYPOINT.getNonce(address(account), key);
Expand Down Expand Up @@ -439,6 +424,8 @@ abstract contract NexusTestBase is CheatCodes, EventsAndErrors {
PackedUserOperation memory userOp,
Vm.Wallet memory signer,
BiconomySponsorshipPaymaster paymaster,
uint128 paymasterValGasLimit,
uint128 paymasterPostOpGasLimit,
address paymasterId,
uint48 validUntil,
uint48 validAfter,
Expand All @@ -451,8 +438,8 @@ abstract contract NexusTestBase is CheatCodes, EventsAndErrors {
// Initial paymaster data with zero signature
bytes memory initialPmData = abi.encodePacked(
address(paymaster),
uint128(3e6),
uint128(3e6),
paymasterValGasLimit,
paymasterPostOpGasLimit,
paymasterId,
validUntil,
validAfter,
Expand All @@ -473,8 +460,8 @@ abstract contract NexusTestBase is CheatCodes, EventsAndErrors {
// Final paymaster data with the actual signature
bytes memory finalPmData = abi.encodePacked(
address(paymaster),
uint128(3e6),
uint128(3e6),
paymasterValGasLimit,
paymasterPostOpGasLimit,
paymasterId,
validUntil,
validAfter,
Expand Down
Loading

0 comments on commit 5da6fbe

Please sign in to comment.