Skip to content

Commit

Permalink
Adds issuer init param, refactors tests - wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesduncombe committed Oct 31, 2023
1 parent 48c0275 commit 6dd7481
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 56 deletions.
2 changes: 2 additions & 0 deletions contracts/paymaster/PaymasterInitFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract PaymasterInitFacet is APaymasterFacet {

struct InitializerParams {
address marketplace;
address issuer;
}

function initialize(InitializerParams calldata params) external onlyDeployer {
Expand All @@ -38,5 +39,6 @@ contract PaymasterInitFacet is APaymasterFacet {
LibPaymaster.Data storage topData = LibPaymaster.data();
topData.version = LibPaymaster.STORAGE_VERSION;
topData.marketplace = params.marketplace;
topData.issuer = params.issuer;
}
}
17 changes: 10 additions & 7 deletions contracts/paymaster/PaymasterTopFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ contract PaymasterTopFacet is APaymasterFacet, IPaymaster {
* **Warning** The deposit on the previous RelayHub must be withdrawn first.
* @param hub The address of the new RelayHub.
*/
function setRelayHub(IRelayHub hub) public onlyOwner {
function setRelayHub(IRelayHub hub) public onlyIssuerMember {
if (!IERC165(address(hub)).supportsInterface(type(IRelayHub).interfaceId))
revert IPaymasterErrors.InterfaceNotSupported("IRelayHub");
relayHub = hub;
Expand All @@ -132,7 +132,7 @@ contract PaymasterTopFacet is APaymasterFacet, IPaymaster {
* the Recipients must trust this Forwarder as well in order for the configuration to remain functional.
* @param forwarder The address of the new Forwarder.
*/
function setTrustedForwarder(address forwarder) public onlyOwner {
function setTrustedForwarder(address forwarder) public onlyIssuerMember {
if (!IERC165(forwarder).supportsInterface(type(IForwarder).interfaceId))
revert IPaymasterErrors.InterfaceNotSupported("IForwarder");
trustedForwarder = forwarder;
Expand All @@ -151,20 +151,23 @@ contract PaymasterTopFacet is APaymasterFacet, IPaymaster {
* @param amount The amount to be subtracted from the sender.
* @param target The target to which the amount will be transferred.
*/
function withdrawRelayHubDepositTo(uint256 amount, address payable target) public onlyOwner {
function withdrawRelayHubDepositTo(uint256 amount, address payable target) public onlyIssuerMember {
relayHub.withdraw(target, amount);
}

/// Modifiers.

modifier onlyRelayHub() virtual {
/// @notice Ensures that a method can only be called by the RelayHub.
modifier onlyRelayHub() {
if (msg.sender != getRelayHub()) revert IPaymasterErrors.RequiresRelayHubCaller();
_;
}

// TODO: Who is owner?
modifier onlyOwner() {
// if (msg.sender != LibPaymaster.data().owner) revert ICustomErrors.RequiresOwner();
// TODO: Check this.
/// @notice Ensures that a method can only be called by an Issuer.
modifier onlyIssuerMember() {
LibPaymaster.Data storage s = LibPaymaster.data();
if (!AHasMembers(s.issuer).isMember(msg.sender)) revert ICustomErrors.RequiresIssuerMemberCaller();
_;
}
}
2 changes: 2 additions & 0 deletions contracts/paymaster/lib/LibPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ library LibPaymaster {
uint16 version;
/// @notice The internal pointer to the Marketplace contract.
address marketplace;
/// @notice The internal pointer to the Issuer contract.
address issuer;
}

function data() internal pure returns (Data storage s) {
Expand Down
11 changes: 8 additions & 3 deletions tasks/paymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ interface PaymasterDeployParams { }
task("paymaster-deploy", "Deploys the main Paymaster contract").setAction(
async (_params: PaymasterDeployParams, hre) => {
const { address: marketplaceAddr } = await hre.deployments.get("Marketplace");
await deployPaymaster(hre, marketplaceAddr);
const { address: issuerAddr } = await hre.deployments.get("Issuer");
await deployPaymaster(hre, marketplaceAddr, issuerAddr);
}
);

Expand Down Expand Up @@ -69,7 +70,8 @@ const PAYMASTER_FACETS = [

const deployPaymaster = async (
hre: HardhatRuntimeEnvironment,
marketplaceAddr: string
marketplaceAddr: string,
issuerAddr: string
): Promise<Paymaster> => {
const { ethers, deployments, getNamedAccounts } = hre;
const { diamond } = deployments;
Expand All @@ -87,7 +89,10 @@ const deployPaymaster = async (
execute: {
contract: "PaymasterInitFacet",
methodName: "initialize",
args: [{ marketplace: marketplaceAddr }],
args: [{
marketplace: marketplaceAddr,
issuer: issuerAddr
}],
},
deterministicSalt: deploymentSalt(hre),
log: true,
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/paymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Paymaster } from "../../typechain/hardhat-diamond-abi/HardhatDiamondABI
export const PAYMASTER_INIT_DEFAULTS: PaymasterInitFacet.InitializerParamsStruct =
{
marketplace: ZERO_ADDRESS,
issuer: ZERO_ADDRESS,
};

interface PaymasterFixtureResult {
Expand Down
6 changes: 6 additions & 0 deletions test/paymaster/PaymasterInitFacet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { impersonateContract } from "../utils";
import { DEPLOYER_FACTORY_COMMON } from "../../src/utils";
import {
Marketplace,
Issuer,
Paymaster,
} from "../../typechain/hardhat-diamond-abi/HardhatDiamondABI.sol";
chai.use(solidity);
Expand All @@ -19,6 +20,7 @@ chai.use(smock.matchers);
describe("PaymasterInitFacet", () => {
let deployer: SignerWithAddress;
let marketplace: FakeContract<Marketplace>,
issuer: FakeContract<Issuer>,
paymaster: Paymaster,
top: PaymasterTopFacet;

Expand All @@ -31,6 +33,8 @@ describe("PaymasterInitFacet", () => {
[deployer] = await ethers.getSigners();
// Mock a Marketplace contract.
marketplace = await smock.fake("Marketplace");
// Mock an Issuer contract.
issuer = await smock.fake("Issuer");
});

beforeEach(async () => {
Expand All @@ -48,6 +52,7 @@ describe("PaymasterInitFacet", () => {
},
initWith: {
marketplace: marketplace.address,
issuer: issuer.address,
},
});
});
Expand All @@ -65,6 +70,7 @@ describe("PaymasterInitFacet", () => {
);
const subject = paymasterInitAsItself.initialize({
marketplace: marketplace.address,
issuer: issuer.address,
});

await expect(subject).to.have.revertedWith("AlreadyInitialized");
Expand Down
Loading

0 comments on commit 6dd7481

Please sign in to comment.