Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eth Gateway: An upgradeable version of GatedERC2771 #456

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading