From 5b48dfb1b81b8ecfc515f74dc176c3313153c606 Mon Sep 17 00:00:00 2001 From: Shivaansh Kapoor Date: Fri, 30 Aug 2024 12:25:22 +0400 Subject: [PATCH] setup for the token paymaster --- .gitmodules | 6 ++ ...=> BiconomySponsorshipPaymasterErrors.sol} | 0 .../common/BiconomyTokenPaymasterErrors.sol | 6 ++ .../interfaces/IBiconomyTokenPaymaster.sol | 6 ++ contracts/mocks/Imports.sol | 7 +- .../BiconomySponsorshipPaymaster.sol | 2 +- contracts/token/BiconomyTokenPaymaster.sol | 72 ++++++++++++++++--- contracts/utils/SoladyOwnable.sol | 2 +- lib/v3-core | 1 + lib/v3-periphery | 1 + remappings.txt | 2 + .../base/BaseEventsAndErrors.sol | 2 +- test/{foundry => }/base/TestBase.sol | 1 + ...ipPaymasterWithDynamicAdjustmentTest.t.sol | 0 ..._TestSponsorshipPaymasterWithPremium.t.sol | 0 15 files changed, 89 insertions(+), 19 deletions(-) rename contracts/common/{Errors.sol => BiconomySponsorshipPaymasterErrors.sol} (100%) create mode 100644 contracts/common/BiconomyTokenPaymasterErrors.sol create mode 160000 lib/v3-core create mode 160000 lib/v3-periphery rename test/{foundry => }/base/BaseEventsAndErrors.sol (91%) rename test/{foundry => }/base/TestBase.sol (99%) rename test/{foundry => }/unit/concrete/TestSponsorshipPaymasterWithDynamicAdjustmentTest.t.sol (100%) rename test/{foundry => }/unit/fuzz/TestFuzz_TestSponsorshipPaymasterWithPremium.t.sol (100%) diff --git a/.gitmodules b/.gitmodules index f008824..a2db065 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,9 @@ [submodule "lib/forge-std"] path = lib/forge-std url = https://github.com/foundry-rs/forge-std +[submodule "lib/v3-periphery"] + path = lib/v3-periphery + url = https://github.com/Uniswap/v3-periphery +[submodule "lib/v3-core"] + path = lib/v3-core + url = https://github.com/Uniswap/v3-core diff --git a/contracts/common/Errors.sol b/contracts/common/BiconomySponsorshipPaymasterErrors.sol similarity index 100% rename from contracts/common/Errors.sol rename to contracts/common/BiconomySponsorshipPaymasterErrors.sol diff --git a/contracts/common/BiconomyTokenPaymasterErrors.sol b/contracts/common/BiconomyTokenPaymasterErrors.sol new file mode 100644 index 0000000..9293b21 --- /dev/null +++ b/contracts/common/BiconomyTokenPaymasterErrors.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: LGPL-3.0-only +pragma solidity ^0.8.26; + +contract BiconomyTokenPaymasterErrors { + +} diff --git a/contracts/interfaces/IBiconomyTokenPaymaster.sol b/contracts/interfaces/IBiconomyTokenPaymaster.sol index e69de29..2347f38 100644 --- a/contracts/interfaces/IBiconomyTokenPaymaster.sol +++ b/contracts/interfaces/IBiconomyTokenPaymaster.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity ^0.8.26; + +interface IBiconomyTokenPaymaster { + +} \ No newline at end of file diff --git a/contracts/mocks/Imports.sol b/contracts/mocks/Imports.sol index 131ae80..03ad730 100644 --- a/contracts/mocks/Imports.sol +++ b/contracts/mocks/Imports.sol @@ -3,8 +3,5 @@ pragma solidity ^0.8.26; /* solhint-disable reason-string */ -import "account-abstraction/contracts/core/EntryPoint.sol"; -import "account-abstraction/contracts/core/EntryPointSimulations.sol"; - -import "@biconomy-devx/erc7579-msa/contracts/SmartAccount.sol"; -import "@biconomy-devx/erc7579-msa/contracts/factory/AccountFactory.sol"; +import "@account-abstraction/contracts/core/EntryPoint.sol"; +import "@account-abstraction/contracts/core/EntryPointSimulations.sol"; diff --git a/contracts/sponsorship/BiconomySponsorshipPaymaster.sol b/contracts/sponsorship/BiconomySponsorshipPaymaster.sol index 41c7c90..7faa2d7 100644 --- a/contracts/sponsorship/BiconomySponsorshipPaymaster.sol +++ b/contracts/sponsorship/BiconomySponsorshipPaymaster.sol @@ -8,7 +8,7 @@ import "@account-abstraction/contracts/core/UserOperationLib.sol"; import "@account-abstraction/contracts/core/Helpers.sol"; import { SignatureCheckerLib } from "@solady/src/utils/SignatureCheckerLib.sol"; import { ECDSA as ECDSA_solady } from "@solady/src/utils/ECDSA.sol"; -import { BiconomySponsorshipPaymasterErrors } from "../common/Errors.sol"; +import { BiconomySponsorshipPaymasterErrors } from "../common/BiconomySponsorshipPaymasterErrors.sol"; import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { SafeTransferLib } from "@solady/src/utils/SafeTransferLib.sol"; diff --git a/contracts/token/BiconomyTokenPaymaster.sol b/contracts/token/BiconomyTokenPaymaster.sol index 9658bc0..d8cd1d0 100644 --- a/contracts/token/BiconomyTokenPaymaster.sol +++ b/contracts/token/BiconomyTokenPaymaster.sol @@ -1,17 +1,67 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; -import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; +import { ECDSA as ECDSA_solady } from "@solady/src/utils/ECDSA.sol"; import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; -import {IEntryPoint} from "@account-abstraction/contracts/interfaces/IEntryPoint.sol"; -import {UserOperationLib} from "@account-abstraction/contracts/core/UserOperationLib.sol"; -import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; -import {BasePaymaster} from "../base/BasePaymaster.sol"; -import "@account-abstraction/contracts/core/Helpers.sol" as Helpers; -import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; -import "@openzeppelin/contracts/utils/Address.sol"; +import { IEntryPoint } from "@account-abstraction/contracts/interfaces/IEntryPoint.sol"; +import { SignatureCheckerLib } from "@solady/src/utils/SignatureCheckerLib.sol"; +import { PackedUserOperation, UserOperationLib } from "@account-abstraction/contracts/core/UserOperationLib.sol"; +import { BasePaymaster } from "../base/BasePaymaster.sol"; +import { BiconomyTokenPaymasterErrors } from "../common/BiconomyTokenPaymasterErrors.sol"; +import { IBiconomyTokenPaymaster } from "../interfaces/IBiconomyTokenPaymaster.sol"; +contract BiconomyTokenPaymaster is + BasePaymaster, + ReentrancyGuard, + BiconomyTokenPaymasterErrors, + IBiconomyTokenPaymaster +{ + using UserOperationLib for PackedUserOperation; + using SignatureCheckerLib for address; -contract BiconomyTokenPaymaster { - -} \ No newline at end of file + constructor( + address _owner, + IEntryPoint _entryPoint + ) + BasePaymaster(_owner, _entryPoint) + { } + + /** + * @dev Validate a user operation. + * This method is abstract in BasePaymaster and must be implemented in derived contracts. + * @param userOp The user operation. + * @param userOpHash The hash of the user operation. + * @param maxCost The maximum cost of the user operation. + */ + function _validatePaymasterUserOp( + PackedUserOperation calldata userOp, + bytes32 userOpHash, + uint256 maxCost + ) + internal + override + returns (bytes memory context, uint256 validationData) + { + // Implementation of user operation validation logic + } + + /** + * @dev Post-operation handler. + * This method is abstract in BasePaymaster and must be implemented in derived contracts. + * @param mode The mode of the post operation (opSucceeded, opReverted, or postOpReverted). + * @param context The context value returned by validatePaymasterUserOp. + * @param actualGasCost Actual gas used so far (excluding this postOp call). + * @param actualUserOpFeePerGas The gas price this UserOp pays. + */ + function _postOp( + PostOpMode mode, + bytes calldata context, + uint256 actualGasCost, + uint256 actualUserOpFeePerGas + ) + internal + override + { + // Implementation of post-operation logic + } +} diff --git a/contracts/utils/SoladyOwnable.sol b/contracts/utils/SoladyOwnable.sol index 8b680d3..5db5e71 100644 --- a/contracts/utils/SoladyOwnable.sol +++ b/contracts/utils/SoladyOwnable.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.26; -import { Ownable } from "solady/src/auth/Ownable.sol"; +import { Ownable } from "@solady/src/auth/Ownable.sol"; contract SoladyOwnable is Ownable { constructor(address _owner) Ownable() { diff --git a/lib/v3-core b/lib/v3-core new file mode 160000 index 0000000..e3589b1 --- /dev/null +++ b/lib/v3-core @@ -0,0 +1 @@ +Subproject commit e3589b192d0be27e100cd0daaf6c97204fdb1899 diff --git a/lib/v3-periphery b/lib/v3-periphery new file mode 160000 index 0000000..80f26c8 --- /dev/null +++ b/lib/v3-periphery @@ -0,0 +1 @@ +Subproject commit 80f26c86c57b8a5e4b913f42844d4c8bd274d058 diff --git a/remappings.txt b/remappings.txt index f34af2e..9622f6b 100644 --- a/remappings.txt +++ b/remappings.txt @@ -2,6 +2,8 @@ @prb/test/=node_modules/@prb/test/ @nexus/=lib/nexus/ @forge-std/=lib/forge-std/ +@uniswap/v3-periphery/=lib/v3-periphery +@uniswap/v3-core/=lib/v3-core @account-abstraction=node_modules/account-abstraction/ @modulekit/=node_modules/modulekit/src/ @sentinellist/=node_modules/sentinellist/ diff --git a/test/foundry/base/BaseEventsAndErrors.sol b/test/base/BaseEventsAndErrors.sol similarity index 91% rename from test/foundry/base/BaseEventsAndErrors.sol rename to test/base/BaseEventsAndErrors.sol index 497366e..187a880 100644 --- a/test/foundry/base/BaseEventsAndErrors.sol +++ b/test/base/BaseEventsAndErrors.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.26; import { EventsAndErrors } from "nexus/test/foundry/utils/EventsAndErrors.sol"; -import { BiconomySponsorshipPaymasterErrors } from "./../../../contracts/common/Errors.sol"; +import { BiconomySponsorshipPaymasterErrors } from "./../../../contracts/common/BiconomySponsorshipPaymasterErrors.sol"; contract BaseEventsAndErrors is EventsAndErrors, BiconomySponsorshipPaymasterErrors { // ========================== diff --git a/test/foundry/base/TestBase.sol b/test/base/TestBase.sol similarity index 99% rename from test/foundry/base/TestBase.sol rename to test/base/TestBase.sol index 669fd19..427bfe8 100644 --- a/test/foundry/base/TestBase.sol +++ b/test/base/TestBase.sol @@ -528,6 +528,7 @@ abstract contract TestBase is CheatCodes, BaseEventsAndErrors { uint32 dynamicAdjustment ) internal + view { (uint256 expectedDynamicAdjustment, uint256 actualDynamicAdjustment) = getDynamicAdjustments( bicoPaymaster, initialDappPaymasterBalance, initialFeeCollectorBalance, dynamicAdjustment diff --git a/test/foundry/unit/concrete/TestSponsorshipPaymasterWithDynamicAdjustmentTest.t.sol b/test/unit/concrete/TestSponsorshipPaymasterWithDynamicAdjustmentTest.t.sol similarity index 100% rename from test/foundry/unit/concrete/TestSponsorshipPaymasterWithDynamicAdjustmentTest.t.sol rename to test/unit/concrete/TestSponsorshipPaymasterWithDynamicAdjustmentTest.t.sol diff --git a/test/foundry/unit/fuzz/TestFuzz_TestSponsorshipPaymasterWithPremium.t.sol b/test/unit/fuzz/TestFuzz_TestSponsorshipPaymasterWithPremium.t.sol similarity index 100% rename from test/foundry/unit/fuzz/TestFuzz_TestSponsorshipPaymasterWithPremium.t.sol rename to test/unit/fuzz/TestFuzz_TestSponsorshipPaymasterWithPremium.t.sol