Skip to content

Commit 6655e16

Browse files
feat: add final GN-1628 changes (#48)
1 parent 3a44ade commit 6655e16

File tree

5 files changed

+22
-142
lines changed

5 files changed

+22
-142
lines changed

contracts/GelatoRelay.sol

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pragma solidity 0.8.17;
33

44
import {IGelatoRelay} from "./interfaces/IGelatoRelay.sol";
55
import {IGelato1Balance} from "./interfaces/IGelato1Balance.sol";
6-
import {GelatoRelayBase} from "./abstract/GelatoRelayBase.sol";
76
import {GelatoCallUtils} from "./lib/GelatoCallUtils.sol";
87
import {GelatoTokenUtils} from "./lib/GelatoTokenUtils.sol";
98
import {SponsoredCall} from "./types/CallTypes.sol";
@@ -27,17 +26,20 @@ import {_deprecatedRelayContext} from "./functions/DeprecatedUtils.sol";
2726
/// @dev This contract must NEVER hold funds!
2827
/// @dev Maliciously crafted transaction payloads could wipe out any funds left here
2928
// solhint-disable-next-line max-states-count
30-
contract GelatoRelay is IGelatoRelay, IGelato1Balance, GelatoRelayBase {
29+
contract GelatoRelay is IGelatoRelay, IGelato1Balance {
3130
using GelatoCallUtils for address;
3231
using GelatoTokenUtils for address;
3332

34-
//solhint-disable-next-line const-name-snakecase
35-
string public constant name = "GelatoRelay";
36-
//solhint-disable-next-line const-name-snakecase
37-
string public constant version = "2";
33+
address public immutable gelato;
3834

39-
// solhint-disable-next-line no-empty-blocks
40-
constructor(address _gelato) GelatoRelayBase(_gelato) {}
35+
modifier onlyGelato() {
36+
require(msg.sender == gelato, "Only callable by gelato");
37+
_;
38+
}
39+
40+
constructor(address _gelato) {
41+
gelato = _gelato;
42+
}
4143

4244
/// @dev Previous version kept for backward compatibility
4345
function callWithSyncFee(
@@ -58,7 +60,7 @@ contract GelatoRelay is IGelatoRelay, IGelato1Balance, GelatoRelayBase {
5860

5961
uint256 fee = postBalance - preBalance;
6062

61-
_feeToken.transfer(msg.sender, fee);
63+
if (fee != 0) _feeToken.transfer(msg.sender, fee);
6264

6365
emit LogCallWithSyncFee(_target, _feeToken, _fee, _taskId);
6466
}
@@ -77,9 +79,11 @@ contract GelatoRelay is IGelatoRelay, IGelato1Balance, GelatoRelayBase {
7779
bytes32 _correlationId
7880
) external onlyGelato {
7981
address feeToken;
82+
address feeCollector;
8083
uint256 preBalance;
8184

8285
if (_isRelayContext) {
86+
feeCollector = _getFeeCollectorRelayContext();
8387
feeToken = _getFeeTokenRelayContext();
8488
preBalance = feeToken.getBalance(address(this));
8589
}
@@ -88,7 +92,7 @@ contract GelatoRelay is IGelatoRelay, IGelato1Balance, GelatoRelayBase {
8892
? _target.revertingContractCall(
8993
_encodeRelayContext(
9094
_data,
91-
_getFeeCollectorRelayContext(),
95+
feeCollector,
9296
feeToken,
9397
_getFeeRelayContext()
9498
),
@@ -101,14 +105,13 @@ contract GelatoRelay is IGelatoRelay, IGelato1Balance, GelatoRelayBase {
101105

102106
if (_isRelayContext) {
103107
uint256 fee = feeToken.getBalance(address(this)) - preBalance;
104-
if (fee != 0) feeToken.transfer(msg.sender, fee);
108+
if (fee != 0) feeToken.transfer(feeCollector, fee);
105109
}
106110

107111
emit LogCallWithSyncFeeV2(_target, _correlationId);
108112
}
109113

110114
/// @notice Relay call + One Balance payment - with sponsor authentication
111-
/// @notice Sponsor signature allows for payment via sponsor's 1Balance balance
112115
/// @dev Payment is handled with off-chain accounting using Gelato's 1Balance system
113116
/// @param _call Relay call data packed into SponsoredCall struct
114117
/// @notice Oracle value for exchange rate between native tokens and fee token
@@ -126,7 +129,10 @@ contract GelatoRelay is IGelatoRelay, IGelato1Balance, GelatoRelayBase {
126129
bytes32 _correlationId
127130
) external onlyGelato {
128131
// CHECKS
129-
_requireChainId(_call.chainId, "GelatoRelay.sponsoredCall:");
132+
require(
133+
_call.chainId == block.chainid,
134+
"GelatoRelay.sponsoredCall:chainid"
135+
);
130136

131137
// INTERACTIONS
132138
_call.target.revertingContractCall(
@@ -144,27 +150,4 @@ contract GelatoRelay is IGelatoRelay, IGelato1Balance, GelatoRelayBase {
144150
_correlationId
145151
);
146152
}
147-
148-
//solhint-disable-next-line func-name-mixedcase
149-
function DOMAIN_SEPARATOR() external view returns (bytes32) {
150-
return _getDomainSeparator();
151-
}
152-
153-
function _getDomainSeparator() internal view returns (bytes32) {
154-
return
155-
keccak256(
156-
abi.encode(
157-
keccak256(
158-
bytes(
159-
//solhint-disable-next-line max-line-length
160-
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
161-
)
162-
),
163-
keccak256(bytes(name)),
164-
keccak256(bytes(version)),
165-
block.chainid,
166-
address(this)
167-
)
168-
);
169-
}
170153
}

contracts/abstract/GelatoRelayBase.sol

Lines changed: 0 additions & 94 deletions
This file was deleted.

contracts/interfaces/IGelatoRelay.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ interface IGelatoRelay {
1616
bytes32 indexed correlationId
1717
);
1818

19+
function gelato() external view returns (address);
20+
1921
function callWithSyncFee(
2022
address _target,
2123
bytes calldata _data,

contracts/interfaces/IGelatoRelayBase.sol

Lines changed: 0 additions & 11 deletions
This file was deleted.

hardhat/tasks/checkGelato.task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { task } from "hardhat/config";
2-
import { IGelatoRelayBase as GelatoRelay } from "../../typechain";
2+
import { IGelatoRelay as GelatoRelay } from "../../typechain";
33

44
export const checkGelato = task(
55
"checkGelato",

0 commit comments

Comments
 (0)