Skip to content

Commit 907bff6

Browse files
authored
Merge pull request #75 from Merit-Systems/feat/memo-field
Add data field to batchDeposit
2 parents 770f8b6 + f16690e commit 907bff6

File tree

11 files changed

+1379
-72
lines changed

11 files changed

+1379
-72
lines changed

broadcast/Deploy.Sepolia.sol/11155111/run-1744918968.json

Lines changed: 198 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/Deploy.Sepolia.sol/11155111/run-1744920841.json

Lines changed: 626 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/Deploy.Sepolia.sol/11155111/run-latest.json

Lines changed: 483 additions & 45 deletions
Large diffs are not rendered by default.

interface/IEscrow.sol

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface IEscrow {
3636
event FeeRecipientSet (address newFeeRecipient);
3737
event TokenWhitelisted (address indexed token);
3838
event TokenRemovedFromWhitelist(address indexed token);
39-
event BatchDeposited (uint indexed batchId, uint repoId, uint timestamp, uint[] depositIds);
39+
event BatchDeposited (uint indexed batchId, uint[] depositIds, bytes data);
4040
event SignerSet (address indexed newSigner);
4141
event BatchDepositLimitSet (uint newLimit);
4242

@@ -56,11 +56,10 @@ interface IEscrow {
5656
/**
5757
* @notice Allows batch creation of multiple deposits in a single transaction.
5858
* @param params An array of `DepositParams` structs for each deposit.
59-
* @param repoId The ID of the repository.
60-
* @param timestamp The timestamp of the batch deposit.
59+
* @param data Arbitrary data to be stored with the batch deposit.
6160
* @return depositIds An array of newly assigned deposit IDs.
6261
*/
63-
function batchDeposit(DepositParams[] calldata params, uint repoId, uint timestamp) external returns (uint[] memory depositIds);
62+
function batchDeposit(DepositParams[] calldata params, bytes calldata data) external returns (uint[] memory depositIds);
6463

6564
/**
6665
* @notice Claims the tokens of a single deposit, if the caller is authorized by signature.

libraries/Encoder.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity =0.8.26;
3+
4+
library DepositEncoder {
5+
uint8 constant ENCODING_VERSION = 1;
6+
7+
enum DEPOSIT_TYPE {
8+
REPO,
9+
SOLO
10+
}
11+
12+
function encode(
13+
DEPOSIT_TYPE depositType,
14+
uint64 repoId,
15+
uint64 timestamp
16+
) internal pure returns (bytes memory) {
17+
return abi.encode(ENCODING_VERSION, depositType, repoId, timestamp);
18+
}
19+
}

libraries/Params.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
pragma solidity =0.8.26;
33

44
library Params {
5-
address constant MAINNET_USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
6-
address constant OWNER = 0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F;
7-
address constant SIGNER = 0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F;
5+
address constant MAINNET_USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
6+
address constant OWNER = 0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F;
7+
address constant SIGNER = 0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F;
88

99
uint constant BATCH_DEPOSIT_LIMIT = 500;
1010

script/Deploy.Base.s.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Deploy} from "./Deploy.s.sol";
55
import {Params} from "../libraries/Params.sol";
66
import {Script} from "forge-std/Script.sol";
77
import {Escrow} from "../src/Escrow.sol";
8+
import {console} from "forge-std/console.sol";
89

910
contract DeployBase is Deploy {
1011
function run() public returns (Escrow escrow) {
@@ -18,5 +19,7 @@ contract DeployBase is Deploy {
1819
Params.BASE_FEE_BPS,
1920
Params.BATCH_DEPOSIT_LIMIT
2021
);
22+
23+
console.log("Escrow deployed at:", address(escrow));
2124
}
2225
}

script/Deploy.Test.Base.s.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
77
import {Script} from "forge-std/Script.sol";
88
import {CreatePayments} from "./utils/CreatePayments.s.sol";
99
import {Escrow} from "../src/Escrow.sol";
10+
import {DepositEncoder} from "../libraries/Encoder.sol";
1011

1112
abstract contract DeployTestBase is Deploy {
1213
uint constant AMOUNT_TO_MINT = 100_000_000 * 10**6;
@@ -42,13 +43,15 @@ abstract contract DeployTestBase is Deploy {
4243
address sender,
4344
address recipient
4445
) internal {
45-
new CreatePayments().deploy(
46+
new CreatePayments().createPayment(
4647
address(escrow),
4748
address(mockUSDC),
4849
5,
4950
100 * 10**6,
5051
sender,
51-
recipient
52+
recipient,
53+
DepositEncoder.DEPOSIT_TYPE.REPO,
54+
100
5255
);
5356
}
5457
}

script/utils/CreatePayments.s.sol

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,57 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.26;
33

4-
import {Deploy} from "../Deploy.s.sol";
5-
import {Params} from "../../libraries/Params.sol";
6-
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
7-
import {Script} from "forge-std/Script.sol";
8-
import {DepositParams} from "../../src/Escrow.sol";
9-
import {Escrow} from "../../src/Escrow.sol";
4+
import {Deploy} from "../Deploy.s.sol";
5+
import {Params} from "../../libraries/Params.sol";
6+
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
7+
import {Script} from "forge-std/Script.sol";
8+
import {DepositParams} from "../../src/Escrow.sol";
9+
import {Escrow} from "../../src/Escrow.sol";
10+
import {DepositEncoder} from "../../libraries/Encoder.sol";
1011

1112
contract CreatePayments is Script {
1213
// NOTE: You need to change these values before running this script
1314
uint constant NUMBER_OF_DEPOSITS = 5;
1415
uint constant AMOUNT_PER_DEPOSIT = 100 * 10**6;
1516
address constant ESCROW_ADDRESS = 0x18578b0168D940623b89Dd0Be880fF994305Fd7e;
1617
address constant TOKEN = 0x883066fabE2CC5b8f5dC626bF2eb47C6FBD4BE03;
17-
uint constant REPO_ID = 1234;
18+
uint64 constant REPO_ID = 1234;
1819

1920
function run() public {
20-
deploy(
21+
// Create repo payment
22+
createPayment(
2123
ESCROW_ADDRESS,
2224
TOKEN,
2325
NUMBER_OF_DEPOSITS,
2426
AMOUNT_PER_DEPOSIT,
2527
Params.SEPOLIA_TESTER_SHAFU,
26-
Params.SEPOLIA_TESTER_JSON
27-
);
28+
Params.SEPOLIA_TESTER_JSON,
29+
DepositEncoder.DEPOSIT_TYPE.REPO,
30+
REPO_ID
31+
);
32+
33+
// Create solo payment
34+
createPayment(
35+
ESCROW_ADDRESS,
36+
TOKEN,
37+
1, // Solo payments have exactly one deposit
38+
AMOUNT_PER_DEPOSIT,
39+
Params.SEPOLIA_TESTER_SHAFU,
40+
Params.SEPOLIA_TESTER_JSON,
41+
DepositEncoder.DEPOSIT_TYPE.SOLO,
42+
0 // Solo payments use repo ID 0
43+
);
2844
}
2945

30-
function deploy(
46+
function createPayment(
3147
address escrowAddress,
3248
address token,
3349
uint256 numberOfDeposits,
3450
uint256 amountPerDeposit,
3551
address sender,
36-
address recipient
52+
address recipient,
53+
DepositEncoder.DEPOSIT_TYPE depositType,
54+
uint64 repoId
3755
) public {
3856
MockERC20 mockUSDC = MockERC20(token);
3957
Escrow escrow = Escrow(escrowAddress);
@@ -54,9 +72,13 @@ contract CreatePayments is Script {
5472

5573
mockUSDC.mint(sender, amountPerDeposit * numberOfDeposits);
5674
mockUSDC.approve(address(escrow), amountPerDeposit * numberOfDeposits);
57-
escrow.batchDeposit(depositParams, REPO_ID, block.timestamp);
75+
bytes memory data = DepositEncoder.encode(
76+
depositType,
77+
repoId,
78+
uint64(block.timestamp)
79+
);
80+
escrow.batchDeposit(depositParams, data);
5881

5982
vm.stopBroadcast();
60-
6183
}
6284
}

script/utils/Gas.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ contract DeploySepolia is Script {
4444
mockUSDC.approve(address(escrow), totalAmount);
4545

4646
uint256 gasBefore = gasleft();
47-
escrow.batchDeposit(depositParams, 1, block.timestamp);
47+
escrow.batchDeposit(depositParams, abi.encode(1, block.timestamp));
4848
uint256 gasAfter = gasleft();
4949
console.log("Gas used for %d deposits:", numDeposits, gasBefore - gasAfter);
5050
}

0 commit comments

Comments
 (0)