Skip to content

Commit

Permalink
chore: update GelatoRelayERC2771 addresses and add zkSync support (#16)
Browse files Browse the repository at this point in the history
* chore: support other Relay addresses on zkSync

* chore: update GelatoRelayERC2771 addresses

* chore: update .gitignore

* chore: remove dependency from Context.sol

* v3.0.0
  • Loading branch information
denis-pingin authored May 11, 2023
1 parent 2e5ade9 commit 5933227
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 57 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ yarn-error.log
# VS Code
.vscode

.idea

.npmrc
9 changes: 6 additions & 3 deletions contracts/base/GelatoRelayBase.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;

import {GELATO_RELAY} from "../constants/GelatoRelay.sol";
import {GELATO_RELAY, GELATO_RELAY_ZKSYNC} from "../constants/GelatoRelay.sol";

abstract contract GelatoRelayBase {
modifier onlyGelatoRelay() {
require(_isGelatoRelay(msg.sender), "onlyGelatoRelay");
_;
}

function _isGelatoRelay(address _forwarder) internal pure returns (bool) {
return _forwarder == GELATO_RELAY;
function _isGelatoRelay(address _forwarder) internal view returns (bool) {
return
block.chainid == 324 || block.chainid == 280
? _forwarder == GELATO_RELAY_ZKSYNC
: _forwarder == GELATO_RELAY;
}
}
11 changes: 9 additions & 2 deletions contracts/base/GelatoRelayERC2771Base.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;

import {GELATO_RELAY_ERC2771} from "../constants/GelatoRelay.sol";
import {
GELATO_RELAY_ERC2771,
GELATO_RELAY_ERC2771_ZKSYNC
} from "../constants/GelatoRelay.sol";

abstract contract GelatoRelayERC2771Base {
modifier onlyGelatoRelayERC2771() {
Expand All @@ -11,9 +14,13 @@ abstract contract GelatoRelayERC2771Base {

function _isGelatoRelayERC2771(address _forwarder)
internal
pure
view
returns (bool)
{
// Use another address on zkSync
if (block.chainid == 324 || block.chainid == 280) {
return _forwarder == GELATO_RELAY_ERC2771_ZKSYNC;
}
return _forwarder == GELATO_RELAY_ERC2771;
}
}
5 changes: 4 additions & 1 deletion contracts/constants/GelatoRelay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
pragma solidity ^0.8.1;

address constant GELATO_RELAY = 0xaBcC9b596420A9E9172FD5938620E265a0f9Df92;
address constant GELATO_RELAY_ERC2771 = 0xBf175FCC7086b4f9bd59d5EAE8eA67b8f940DE0d;
address constant GELATO_RELAY_ERC2771 = 0xb539068872230f20456CF38EC52EF2f91AF4AE49;

address constant GELATO_RELAY_ZKSYNC = 0xB16a1DbE755f992636705fDbb3A8678a657EB3ea;
address constant GELATO_RELAY_ERC2771_ZKSYNC = 0x22DCC39b2AC376862183dd35A1664798dafC7Da6;
25 changes: 0 additions & 25 deletions contracts/vendor/Context.sol

This file was deleted.

26 changes: 6 additions & 20 deletions contracts/vendor/ERC2771Context.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

pragma solidity ^0.8.1;

import "./Context.sol";

/**
* @dev Context variant with ERC2771 support.
*/
// copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/metatx/ERC2771Context.sol
abstract contract ERC2771Context is Context {
// based on https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/metatx/ERC2771Context.sol
abstract contract ERC2771Context {
address private immutable _trustedForwarder;

constructor(address trustedForwarder) {
Expand All @@ -25,35 +23,23 @@ abstract contract ERC2771Context is Context {
return forwarder == _trustedForwarder;
}

function _msgSender()
internal
view
virtual
override
returns (address sender)
{
function _msgSender() internal view virtual returns (address sender) {
if (isTrustedForwarder(msg.sender)) {
// The assembly code is more direct than the Solidity version using `abi.decode`.
/// @solidity memory-safe-assembly
assembly {
sender := shr(96, calldataload(sub(calldatasize(), 20)))
}
} else {
return super._msgSender();
return msg.sender;
}
}

function _msgData()
internal
view
virtual
override
returns (bytes calldata)
{
function _msgData() internal view virtual returns (bytes calldata) {
if (isTrustedForwarder(msg.sender)) {
return msg.data[:msg.data.length - 20];
} else {
return super._msgData();
return msg.data;
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gelatonetwork/relay-context",
"version": "2.1.0",
"version": "3.0.0",
"description": "Solidity and test helpers for implementing GelatoRelayContext",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down Expand Up @@ -38,7 +38,7 @@
},
"license": "MIT",
"dependencies": {
"@openzeppelin/contracts": "4.8.0"
"@openzeppelin/contracts": "4.8.3"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1446,10 +1446,10 @@
"@types/sinon-chai" "^3.2.3"
"@types/web3" "1.0.19"

"@openzeppelin/[email protected].0":
version "4.8.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.8.0.tgz#6854c37df205dd2c056bdfa1b853f5d732109109"
integrity sha512-AGuwhRRL+NaKx73WKRNzeCxOCOCxpaqF+kp8TJ89QzAipSwZy/NoflkWaL9bywXFRhIzXt8j38sfF7KBKCPWLw==
"@openzeppelin/[email protected].3":
version "4.8.3"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.8.3.tgz#cbef3146bfc570849405f59cba18235da95a252a"
integrity sha512-bQHV8R9Me8IaJoJ2vPG4rXcL7seB7YVuskr4f+f5RyOStSZetwzkWtoqDMl5erkBJy0lDRUnIR2WIkPiC0GJlg==

"@resolver-engine/core@^0.3.3":
version "0.3.3"
Expand Down

0 comments on commit 5933227

Please sign in to comment.