Skip to content

Commit

Permalink
Eth Gateway: An upgradeable version of GatedERC2771
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelleher committed Aug 2, 2023
1 parent 860c541 commit 33ec5cd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 37 deletions.
32 changes: 32 additions & 0 deletions ethereum/smart-contract/contracts/GatedERC2771Upgradeable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import {IGatewayTokenVerifier} from "./interfaces/IGatewayTokenVerifier.sol";
import {MultiERC2771Context} from "./MultiERC2771Context.sol";

abstract contract GatedERC2771Upgradeable is MultiERC2771Context {
address private _gatewayTokenContract;
uint256 private _gatekeeperNetwork;

/// The gateway token is not valid.
error IsGated__InvalidGatewayToken(address gatewayToken);

modifier gated() {
IGatewayTokenVerifier verifier = IGatewayTokenVerifier(_gatewayTokenContract);
if (!verifier.verifyToken(_msgSender(), _gatekeeperNetwork)) {
revert IsGated__InvalidGatewayToken(_gatewayTokenContract);
}
_;
}

// solhint-disable-next-line func-name-mixedcase
function __GatedERC2771Upgradeable_init(
address gatewayTokenContract,
uint256 gatekeeperNetwork,
address[] calldata trustedForwarders
) internal initializer {
_gatewayTokenContract = gatewayTokenContract;
_gatekeeperNetwork = gatekeeperNetwork;
__MultiERC2771Context_init(trustedForwarders);
}
}
37 changes: 0 additions & 37 deletions ethereum/smart-contract/scripts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,6 @@ export const getAccounts = async (hre: HardhatRuntimeEnvironment) => {
gatekeeper: gatekeeper || authority || deployer,
};
};
export const deployProxy = async (
hre: HardhatRuntimeEnvironment,
contractName: string,
args: any[],
reuseDeployments = true,
opts: any = {},
) => {
const { deployments, ethers, upgrades } = hre;
const { save } = deployments;

const Contract = await ethers.getContractFactory(contractName);

const existingDeployment = await deployments.getOrNull(contractName);
if (existingDeployment && reuseDeployments) {
console.log(`Deploy ${contractName} proxy skipped - reusing existing deployment at ${existingDeployment.address}`);
return ethers.getContractAt(contractName, existingDeployment.address);
}

const proxy = await upgrades.deployProxy(Contract, args, { kind: 'uups', ...opts });
await proxy.deployed();
console.log(`Deploy ${contractName} Proxy done -> ${proxy.address}`);

// Integration between hardhat-deploy and hardhat-upgrades inspired by
// https://github.com/wighawag/hardhat-deploy/issues/242#issuecomment-998790266
// // TODO Do we need this?
// const impl = await upgrades.upgradeProxy(proxy, Contract, opts);
// console.log(`Deploy ${contractName} Impl done -> ${impl.address}`);
const artifact = await deployments.getExtendedArtifact(contractName);
const proxyDeployments = {
address: proxy.address,
...artifact,
};
await save(contractName, proxyDeployments);

return ethers.getContractAt(contractName, proxy.address);
};

export const deployProxyCreate2 = async (hre: HardhatRuntimeEnvironment, contractName: string, args: any[]) => {
const { getNamedAccounts, deployments, ethers } = hre;
const { deploy } = deployments;
Expand Down

0 comments on commit 33ec5cd

Please sign in to comment.