-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beb5ed5
commit d700530
Showing
20 changed files
with
337 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.10; | ||
|
||
import "../common/lib/LibHasForwarder.sol"; | ||
|
||
import "@opengsn/contracts/src/ERC2771Recipient.sol"; | ||
|
||
/** | ||
* @title The Forwarder Smart Contract. | ||
* @notice The HasForwarder abstract contract is in charge of... | ||
*/ | ||
abstract contract AHasForwarder is ERC2771Recipient { | ||
/** | ||
* @notice ERC2771Recipient stuff... | ||
* FIX THE MODIFIER !!!!!!!!!!!!!!!!!!!!!! | ||
*/ | ||
function setTrustedForwarder(address _forwarderAddress) external { | ||
LibHasForwarder.Data storage ds = LibHasForwarder.data(); | ||
ds.forwarderAddress = _forwarderAddress; | ||
_setTrustedForwarder(_forwarderAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.10; | ||
|
||
library LibHasForwarder { | ||
// The current version of the storage. | ||
uint16 internal constant STORAGE_VERSION = 1; | ||
// This is `keccak256('HasForwarder.storage.Main')`. | ||
bytes32 internal constant STORAGE_SLOT = 0xa9930c2ffa1b605b0243ba36b3020146bcba5a29c05a711f5ca7c705a8e851ca; | ||
|
||
struct Data { | ||
/// @notice The latest intializer version that was called. | ||
uint16 version; | ||
/// @notice This is where we store the trusted forwarder address. | ||
address forwarderAddress; | ||
} | ||
|
||
function data() internal pure returns (Data storage s) { | ||
assembly { | ||
s.slot := STORAGE_SLOT | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.10; | ||
|
||
import "../interfaces/IERC173.sol"; // Ownership. | ||
import "../interfaces/IDiamondCut.sol"; // Facet management. | ||
import "../interfaces/IDiamondLoupe.sol"; // Facet introspection. | ||
import "../interfaces/ICustomErrors.sol"; | ||
import "../lib/LibDiamond.sol"; | ||
import "./lib/APaymasterFacet.sol"; | ||
import "./lib/LibPaymaster.sol"; | ||
|
||
import "@openzeppelin/contracts/interfaces/IERC165.sol"; | ||
|
||
/// @notice The Paymaster initialization facet. | ||
contract PaymasterInitFacet is APaymasterFacet { | ||
/// Initializers. | ||
|
||
struct InitializerParams { | ||
address marketplace; | ||
} | ||
|
||
function initialize(InitializerParams calldata params) external onlyDeployer { | ||
// Make sure we haven't initialized yet. | ||
if (LibPaymaster.data().version >= LibPaymaster.STORAGE_VERSION) revert ICustomErrors.AlreadyInitialized(); | ||
|
||
// Register interfaces. | ||
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); | ||
ds.supportedInterfaces[type(IERC165).interfaceId] = true; | ||
ds.supportedInterfaces[type(IERC173).interfaceId] = true; | ||
ds.supportedInterfaces[type(IDiamondCut).interfaceId] = true; | ||
ds.supportedInterfaces[type(IDiamondLoupe).interfaceId] = true; | ||
|
||
// ------------------------------------- // | ||
|
||
// Initialize top-level storage. | ||
LibPaymaster.Data storage topData = LibPaymaster.data(); | ||
topData.version = LibPaymaster.STORAGE_VERSION; | ||
topData.marketplace = params.marketplace; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.10; | ||
|
||
import "./lib/LibPaymaster.sol"; | ||
import "./lib/APaymasterFacet.sol"; | ||
|
||
import "@opengsn/contracts/src/BasePaymaster.sol"; | ||
|
||
contract PaymasterTopFacet is APaymasterFacet, BasePaymaster { | ||
bool public useRejectOnRecipientRevert = false; | ||
|
||
// TODO: Do we use the Marketplace at this point to check that the sender is allowed? | ||
function _preRelayedCall( | ||
GsnTypes.RelayRequest calldata relayRequest, | ||
bytes calldata signature, | ||
bytes calldata approvalData, | ||
uint256 maxPossibleGas | ||
) internal virtual override returns (bytes memory context, bool revertOnRecipientRevert) { | ||
(signature, maxPossibleGas); | ||
if (approvalData.length == 0) revert ICustomErrors.InvalidApprovalDataLength(); | ||
if (relayRequest.relayData.paymasterData.length == 0) revert ICustomErrors.InvalidPaymasterDataLength(); | ||
|
||
return ("", useRejectOnRecipientRevert); | ||
} | ||
|
||
function _postRelayedCall( | ||
bytes calldata context, | ||
bool success, | ||
uint256 gasUseWithoutPost, | ||
GsnTypes.RelayData calldata relayData | ||
) internal virtual override { | ||
(context, success, gasUseWithoutPost, relayData); | ||
} | ||
|
||
function versionPaymaster() external view virtual override returns (string memory) { | ||
return "3.0.0-beta.3+opengsn.accepteverything.ipaymaster"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.10; | ||
|
||
import "../../common/AHasMembers.sol"; | ||
import "../../interfaces/ICustomErrors.sol"; | ||
import "../../lib/LibHelpers.sol"; | ||
import "../lib/LibPaymaster.sol"; | ||
|
||
/** | ||
* @notice This contract is a group of modifiers that can be used by any Paymaster facets to guard against | ||
* certain permissions. | ||
*/ | ||
abstract contract APaymasterFacet { | ||
/// Internal ACL functions. | ||
|
||
/// ... | ||
|
||
// Modifiers. | ||
|
||
/// @notice Ensures that a method can only be called by the singleton deployer contract factory. | ||
modifier onlyDeployer() virtual { | ||
if (!LibHelpers._isDeployer(msg.sender)) revert ICustomErrors.InternalMethod(); | ||
_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.10; | ||
|
||
library LibPaymaster { | ||
// The current version of the storage. | ||
uint16 internal constant STORAGE_VERSION = 1; | ||
// This is keccak256('Paymaster.storage'): | ||
bytes32 internal constant STORAGE_SLOT = 0x8f0e66ee30211ca069424cd4b533ee66f04c45421216c1a6601cf23359c1f7f8; | ||
|
||
struct Data { | ||
/// @notice The latest intializer version that was called. | ||
uint16 version; | ||
/// @notice The internal pointer to the Marketplace contract. | ||
address marketplace; | ||
} | ||
|
||
function data() internal pure returns (Data storage s) { | ||
assembly { | ||
s.slot := STORAGE_SLOT | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
import { deployPaymaster } from "../tasks/paymaster"; | ||
import { deployments } from "hardhat"; | ||
|
||
const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { | ||
console.log("----------------------------------- 30_deployPaymaster"); | ||
|
||
await deployPaymaster(hre, (await deployments.get("Marketplace")).address); | ||
}; | ||
func.tags = ["DeployPaymaster"]; | ||
export default func; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.