Skip to content

Commit fc873d4

Browse files
authored
Merge pull request #71 from Merit-Systems/feat/signer
Add Signer
2 parents eba7ac8 + baa5f12 commit fc873d4

File tree

12 files changed

+30
-10
lines changed

12 files changed

+30
-10
lines changed

interface/IEscrow.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface IEscrow {
3737
event TokenWhitelisted (address indexed token);
3838
event TokenRemovedFromWhitelist(address indexed token);
3939
event BatchDeposited (uint indexed batchId, uint repoId, uint timestamp, uint[] depositIds);
40+
event SignerSet (address indexed newSigner);
4041

4142
/**
4243
* @notice Deposits tokens into the escrow on behalf of a specified sender and recipient.

libraries/Params.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity =0.8.26;
44
library Params {
55
address constant MAINNET_USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
66
address constant OWNER = 0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F;
7+
address constant SIGNER = 0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F;
78

89
// BASE
910
address constant BASE_WETH = 0x4200000000000000000000000000000000000006;

script/Deploy.Base.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ contract DeployBase is Deploy {
1111
address[] memory initialWhitelistedTokens = new address[](1);
1212
initialWhitelistedTokens[0] = Params.BASE_USDC;
1313

14-
escrow = deploy(Params.OWNER, initialWhitelistedTokens, Params.BASE_FEE_BPS);
14+
escrow = deploy(Params.OWNER, Params.SIGNER, initialWhitelistedTokens, Params.BASE_FEE_BPS);
1515
}
1616
}

script/Deploy.BaseSepolia.s.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ contract DeployBaseSepolia is DeployTestBase {
1818
testers,
1919
Params.BASESEPOLIA_WETH,
2020
Params.BASESEPOLIA_USDC,
21-
Params.OWNER
21+
Params.OWNER,
22+
Params.SIGNER
2223
);
2324

2425
createTestPayments(

script/Deploy.Sepolia.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ contract DeploySepolia is DeployTestBase {
1818
testers,
1919
Params.SEPOLIA_WETH,
2020
Params.SEPOLIA_USDC,
21-
Params.OWNER
21+
Params.OWNER,
22+
Params.SIGNER
2223
);
2324

2425
createTestPayments(

script/Deploy.Test.Base.s.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ abstract contract DeployTestBase is Deploy {
1818
address[] memory testers,
1919
address weth,
2020
address usdc,
21-
address owner
21+
address owner,
22+
address signer
2223
) internal {
2324
vm.startBroadcast();
2425

@@ -34,7 +35,7 @@ abstract contract DeployTestBase is Deploy {
3435
initialWhitelistedTokens[1] = usdc;
3536
initialWhitelistedTokens[2] = address(mockUSDC);
3637

37-
escrow = deploy(owner, initialWhitelistedTokens, 0);
38+
escrow = deploy(owner, signer, initialWhitelistedTokens, 0);
3839
}
3940

4041
function createTestPayments(

script/Deploy.s.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {Script} from "forge-std/Script.sol";
88
contract Deploy is Script {
99
function deploy(
1010
address owner,
11+
address signer,
1112
address[] memory initialWhitelistedTokens,
1213
uint feeBps
1314
)
@@ -18,6 +19,7 @@ contract Deploy is Script {
1819

1920
escrow = new Escrow(
2021
owner,
22+
signer,
2123
initialWhitelistedTokens,
2224
feeBps
2325
);

script/utils/Gas.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ contract DeploySepolia is Script {
2020
address[] memory initialWhitelistedTokens = new address[](1);
2121
initialWhitelistedTokens[0] = address(mockUSDC);
2222

23-
Escrow escrow = new Deploy().deploy(Params.OWNER, initialWhitelistedTokens, 0);
23+
Escrow escrow = new Deploy().deploy(Params.OWNER, Params.SIGNER, initialWhitelistedTokens, 0);
2424

2525
for (uint256 j = 0; j < NUM_DEPOSITS.length; j++) {
2626
uint256 numDeposits = NUM_DEPOSITS[j];

src/Escrow.sol

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ contract Escrow is Owned, IEscrow {
2727
mapping(address => bool) public canClaim;
2828
mapping(address => uint) public recipientNonces;
2929

30+
address public signer;
31+
3032
struct Deposit {
3133
uint amount;
3234
ERC20 token;
@@ -47,6 +49,7 @@ contract Escrow is Owned, IEscrow {
4749

4850
constructor(
4951
address _owner,
52+
address _signer,
5053
address[] memory _initialWhitelistedTokens,
5154
uint _initialFeeBps
5255
) Owned(_owner) {
@@ -55,6 +58,7 @@ contract Escrow is Owned, IEscrow {
5558
protocolFeeBps = _initialFeeBps;
5659
CLAIM_INITIAL_CHAIN_ID = block.chainid;
5760
CLAIM_INITIAL_DOMAIN_SEPARATOR = _computeClaimDomainSeparator();
61+
signer = _signer;
5862

5963
for (uint256 i = 0; i < _initialWhitelistedTokens.length; i++) {
6064
_whitelistedTokens.add(_initialWhitelistedTokens[i]);
@@ -240,8 +244,8 @@ contract Escrow is Owned, IEscrow {
240244
abi.encodePacked("\x19\x01", CLAIM_DOMAIN_SEPARATOR(), structHash)
241245
);
242246

243-
address signer = ECDSA.recover(digest, v, r, s);
244-
require(signer == owner, Errors.INVALID_SIGNATURE);
247+
address recoveredSigner = ECDSA.recover(digest, v, r, s);
248+
require(recoveredSigner == signer, Errors.INVALID_SIGNATURE);
245249

246250
recipientNonces[recipient]++;
247251

@@ -324,4 +328,12 @@ contract Escrow is Owned, IEscrow {
324328
emit FeeRecipientSet(_newFeeRecipient);
325329
}
326330

331+
/*//////////////////////////////////////////////////////////////
332+
SIGNER MANAGEMENT (Owner Only)
333+
//////////////////////////////////////////////////////////////*/
334+
function setSigner(address _newSigner) external onlyOwner {
335+
require(_newSigner != address(0), Errors.INVALID_ADDRESS);
336+
signer = _newSigner;
337+
emit SignerSet(_newSigner);
338+
}
327339
}

test/Deploy.t.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ contract Deploy_Test is Test {
2020
assertTrue(address(escrow) != address(0), "Escrow not deployed");
2121
assertTrue(escrow.isTokenWhitelisted(Params.BASE_USDC), "WETH not whitelisted");
2222
assertEq (escrow.owner(), Params.OWNER, "Incorrect owner");
23+
assertEq (escrow.signer(), Params.SIGNER, "Incorrect signer");
2324
assertEq (escrow.feeRecipient(), Params.OWNER, "Incorrect fee recipient");
2425
assertEq (escrow.protocolFeeBps(), Params.BASE_FEE_BPS, "Incorrect fee");
2526
}

0 commit comments

Comments
 (0)