-
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 1cd22ab
Showing
12 changed files
with
265 additions
and
6 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
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,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.10; | ||
|
||
import "../common/lib/LibHasMembers.sol"; | ||
import "../common/lib/LibHasAutomatons.sol"; | ||
import "../common/AHasMembers.sol"; | ||
import "../common/AHasAutomatons.sol"; | ||
import "../interfaces/IERC165.sol"; // Interface Support. | ||
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"; | ||
|
||
/// @notice The Paymaster initialization facet. | ||
contract PaymasterInitFacet is APaymasterFacet { | ||
/// Initializers. | ||
|
||
struct InitializerParams { | ||
address issuer; | ||
} | ||
|
||
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.issuer = params.issuer; | ||
} | ||
} |
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 PaymasterFacet is APaymasterFacet, BasePaymaster { | ||
bool public useRejectOnRecipientRevert = false; | ||
|
||
/// TODO: MAKE THESE ERROR... SUPERNICE™ | ||
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); | ||
require(approvalData.length == 0, "approvalData: invalid length"); | ||
require(relayRequest.relayData.paymasterData.length == 0, "paymasterData: invalid length"); | ||
|
||
return ("", useRejectOnRecipientRevert); | ||
} | ||
|
||
function _postRelayedCall( | ||
bytes calldata context, | ||
bool success, | ||
uint256 gasUseWithoutPost, | ||
GsnTypes.RelayData calldata relayData | ||
) internal virtual override { | ||
(context, success, gasUseWithoutPost, relayData); | ||
} | ||
|
||
// TODO: Setter and be in lib data.... | ||
function versionPaymaster() external view virtual override returns (string memory) { | ||
return "3.0.0-beta.3+opengsn.tokensphere.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,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.10; | ||
|
||
import "../../lib/LibHelpers.sol"; | ||
import "../../common/AHasMembers.sol"; | ||
import "../../interfaces/ICustomErrors.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. | ||
|
||
// function _isIssuerMember(address who) internal view returns (bool) { | ||
// return AHasMembers(LibPaymaster.data().issuer).isMember(who); | ||
// } | ||
|
||
// 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 Issuer contract. | ||
address issuer; | ||
} | ||
|
||
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 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,96 @@ | ||
import { task } from "hardhat/config"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { parseEther } from "ethers/lib/utils"; | ||
import { deploymentSalt } from "../src/utils"; | ||
import { Paymaster } from "../typechain/hardhat-diamond-abi/HardhatDiamondABI.sol"; | ||
|
||
// Tasks. | ||
|
||
interface PaymasterDeployParams { } | ||
|
||
task("paymaster-deploy", "Deploys the main Paymaster contract").setAction( | ||
async (_params: PaymasterDeployParams, hre) => { | ||
const { address: issuerAddr } = await hre.deployments.get("Issuer"); | ||
await deployPaymaster(hre, issuerAddr); | ||
} | ||
); | ||
|
||
interface PaymasterUpdateFacetsParams { } | ||
|
||
task("paymaster-update-facets", "Updates facets of our Paymaster") | ||
.setAction(async (_params: PaymasterUpdateFacetsParams, hre) => { | ||
const { deployments, getNamedAccounts } = hre; | ||
const { deployer } = await getNamedAccounts(); | ||
// Make sure that the fast is known from our tooling. | ||
const { address } = await deployments.get("Paymaster"); | ||
console.log(`Updating paymaster diamond facets at ${address}...`); | ||
await deployments.diamond.deploy("Paymaster", { | ||
from: deployer, | ||
facets: PAYMASTER_FACETS, | ||
deterministicSalt: deploymentSalt(hre), | ||
log: true, | ||
}); | ||
}); | ||
|
||
|
||
interface PaymasterFundParams { } | ||
|
||
task("paymaster-fund", "Funds the Paymaster") | ||
.setAction(async (_params: PaymasterFundParams, hre) => { | ||
const { deployments, getNamedAccounts } = hre; | ||
// Who will juice it? | ||
const { issuerMember } = await getNamedAccounts(); | ||
|
||
// yeeettttttt this out... | ||
const relayHubAddress = "0x3232f21A6E08312654270c78A773f00dd61d60f5"; | ||
const { address: paymasterAddress } = await deployments.get("Paymaster"); | ||
|
||
const RelayHub = await hre.ethers.getContractFactory("RelayHub"); | ||
const relayHub = await RelayHub.attach(relayHubAddress); | ||
|
||
// params... | ||
const tx = await relayHub.depositFor(paymasterAddress, { value: parseEther("0.1") }); | ||
await tx.wait(); | ||
|
||
console.log('Paymaster balance:', await relayHub.balanceOf(paymasterAddress)); | ||
// console.log('Admin wallet balance', await provider.getBalance(admin.address)); | ||
|
||
}); | ||
|
||
// Reusable functions and constants. | ||
|
||
const PAYMASTER_FACETS = [ | ||
"PaymasterTopFacet" | ||
]; | ||
|
||
const deployPaymaster = async ( | ||
hre: HardhatRuntimeEnvironment, | ||
issuerAddr: string | ||
): Promise<Paymaster> => { | ||
const { ethers, deployments, getNamedAccounts } = hre; | ||
const { diamond } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
let deploy = await deployments.getOrNull("Paymaster"); | ||
if (deploy) { | ||
console.log(`Paymaster already deployed at ${deploy.address}, skipping.`); | ||
} else { | ||
// Deploy the diamond with an additional initialization facet. | ||
deploy = await diamond.deploy("Paymaster", { | ||
from: deployer, | ||
owner: deployer, | ||
facets: PAYMASTER_FACETS, | ||
execute: { | ||
contract: "PaymasterInitFacet", | ||
methodName: "initialize", | ||
args: [{ issuer: issuerAddr }], | ||
}, | ||
deterministicSalt: deploymentSalt(hre), | ||
log: true, | ||
}); | ||
} | ||
// Return a handle to the diamond. | ||
return await ethers.getContract<Paymaster>("Paymaster"); | ||
}; | ||
|
||
export { PAYMASTER_FACETS, deployPaymaster }; |
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