From 112b99c1441c343ed8d9f8acf1e79323263a3157 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 2 Dec 2024 12:39:02 +0200 Subject: [PATCH] - fixes & added new tasks --- .openzeppelin/base-sepolia.json | 921 ++++++++++++++++++++++++++++ contracts/ERC20Safe.sol | 28 +- tasks/deploy/force-import-bridge.ts | 19 + tasks/deploy/force-import-safe.ts | 19 + tasks/deploy/index.ts | 2 + test/Safe.test.js | 12 +- 6 files changed, 981 insertions(+), 20 deletions(-) create mode 100644 .openzeppelin/base-sepolia.json create mode 100644 tasks/deploy/force-import-bridge.ts create mode 100644 tasks/deploy/force-import-safe.ts diff --git a/.openzeppelin/base-sepolia.json b/.openzeppelin/base-sepolia.json new file mode 100644 index 0000000..9c7da2e --- /dev/null +++ b/.openzeppelin/base-sepolia.json @@ -0,0 +1,921 @@ +{ + "manifestVersion": "3.2", + "proxies": [ + { + "address": "0xd1B537b9f9c119371976b2CCf37b607098D0f185", + "kind": "transparent" + }, + { + "address": "0xC10F8792926DC85FEDEd347C245d41BE7818cDf0", + "kind": "transparent" + } + ], + "impls": { + "46e0313941613e19a78e16195b8a30cca06cc8e9bc7ebf3b5baac4b6a4d3fe58": { + "address": "0xB4fbAd36699eAB4c8b919CdC5336975FfFf8BfDa", + "layout": { + "solcVersion": "0.8.20", + "storage": [ + { + "label": "_admin", + "offset": 0, + "slot": "0", + "type": "t_address", + "contract": "AdminRole", + "src": "contracts/access/AdminRole.sol:20" + }, + { + "label": "_bridge", + "offset": 0, + "slot": "1", + "type": "t_address", + "contract": "BridgeRole", + "src": "contracts/access/BridgeRole.sol:37" + }, + { + "label": "_paused", + "offset": 20, + "slot": "1", + "type": "t_bool", + "contract": "Pausable", + "src": "contracts/lib/Pausable.sol:10" + }, + { + "label": "batchesCount", + "offset": 21, + "slot": "1", + "type": "t_uint64", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:35" + }, + { + "label": "depositsCount", + "offset": 0, + "slot": "2", + "type": "t_uint64", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:36" + }, + { + "label": "batchSize", + "offset": 8, + "slot": "2", + "type": "t_uint16", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:37" + }, + { + "label": "batchBlockLimit", + "offset": 10, + "slot": "2", + "type": "t_uint8", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:39" + }, + { + "label": "batchSettleLimit", + "offset": 11, + "slot": "2", + "type": "t_uint8", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:40" + }, + { + "label": "__gap", + "offset": 0, + "slot": "3", + "type": "t_array(t_uint256)10_storage", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:43" + }, + { + "label": "batches", + "offset": 0, + "slot": "13", + "type": "t_mapping(t_uint256,t_struct(Batch)5764_storage)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:45" + }, + { + "label": "whitelistedTokens", + "offset": 0, + "slot": "14", + "type": "t_mapping(t_address,t_bool)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:46" + }, + { + "label": "mintBurnTokens", + "offset": 0, + "slot": "15", + "type": "t_mapping(t_address,t_bool)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:47" + }, + { + "label": "nativeTokens", + "offset": 0, + "slot": "16", + "type": "t_mapping(t_address,t_bool)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:48" + }, + { + "label": "tokenMinLimits", + "offset": 0, + "slot": "17", + "type": "t_mapping(t_address,t_uint256)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:49" + }, + { + "label": "tokenMaxLimits", + "offset": 0, + "slot": "18", + "type": "t_mapping(t_address,t_uint256)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:50" + }, + { + "label": "totalBalances", + "offset": 0, + "slot": "19", + "type": "t_mapping(t_address,t_uint256)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:51" + }, + { + "label": "mintBalances", + "offset": 0, + "slot": "20", + "type": "t_mapping(t_address,t_uint256)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:52" + }, + { + "label": "burnBalances", + "offset": 0, + "slot": "21", + "type": "t_mapping(t_address,t_uint256)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:53" + }, + { + "label": "batchDeposits", + "offset": 0, + "slot": "22", + "type": "t_mapping(t_uint256,t_array(t_struct(Deposit)5748_storage)dyn_storage)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:54" + } + ], + "types": { + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_struct(InitializableStorage)158_storage": { + "label": "struct Initializable.InitializableStorage", + "members": [ + { + "label": "_initialized", + "type": "t_uint64", + "offset": 0, + "slot": "0" + }, + { + "label": "_initializing", + "type": "t_bool", + "offset": 8, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_uint64": { + "label": "uint64", + "numberOfBytes": "8" + }, + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_struct(Deposit)5748_storage)dyn_storage": { + "label": "struct Deposit[]", + "numberOfBytes": "32" + }, + "t_array(t_uint256)10_storage": { + "label": "uint256[10]", + "numberOfBytes": "320" + }, + "t_bytes32": { + "label": "bytes32", + "numberOfBytes": "32" + }, + "t_enum(DepositStatus)5734": { + "label": "enum DepositStatus", + "members": [ + "None", + "Pending", + "InProgress", + "Executed", + "Rejected" + ], + "numberOfBytes": "1" + }, + "t_mapping(t_address,t_bool)": { + "label": "mapping(address => bool)", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_uint256)": { + "label": "mapping(address => uint256)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_array(t_struct(Deposit)5748_storage)dyn_storage)": { + "label": "mapping(uint256 => struct Deposit[])", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_struct(Batch)5764_storage)": { + "label": "mapping(uint256 => struct Batch)", + "numberOfBytes": "32" + }, + "t_struct(Batch)5764_storage": { + "label": "struct Batch", + "members": [ + { + "label": "nonce", + "type": "t_uint112", + "offset": 0, + "slot": "0" + }, + { + "label": "blockNumber", + "type": "t_uint64", + "offset": 14, + "slot": "0" + }, + { + "label": "lastUpdatedBlockNumber", + "type": "t_uint64", + "offset": 22, + "slot": "0" + }, + { + "label": "depositsCount", + "type": "t_uint16", + "offset": 30, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_struct(Deposit)5748_storage": { + "label": "struct Deposit", + "members": [ + { + "label": "nonce", + "type": "t_uint112", + "offset": 0, + "slot": "0" + }, + { + "label": "tokenAddress", + "type": "t_address", + "offset": 0, + "slot": "1" + }, + { + "label": "amount", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "depositor", + "type": "t_address", + "offset": 0, + "slot": "3" + }, + { + "label": "recipient", + "type": "t_bytes32", + "offset": 0, + "slot": "4" + }, + { + "label": "status", + "type": "t_enum(DepositStatus)5734", + "offset": 0, + "slot": "5" + } + ], + "numberOfBytes": "192" + }, + "t_uint112": { + "label": "uint112", + "numberOfBytes": "14" + }, + "t_uint16": { + "label": "uint16", + "numberOfBytes": "2" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + }, + "namespaces": { + "erc7201:openzeppelin.storage.Initializable": [ + { + "contract": "Initializable", + "label": "_initialized", + "type": "t_uint64", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:69", + "offset": 0, + "slot": "0" + }, + { + "contract": "Initializable", + "label": "_initializing", + "type": "t_bool", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:73", + "offset": 8, + "slot": "0" + } + ] + } + } + }, + "eb5122261d1b60fe73f5f81dfdd9a2f090a7da9da93128d556c7e7f7112d6031": { + "address": "0x10530280f2751773e1909079604D2c806a02d105", + "layout": { + "solcVersion": "0.8.20", + "storage": [ + { + "label": "_admin", + "offset": 0, + "slot": "0", + "type": "t_address", + "contract": "AdminRole", + "src": "contracts/access/AdminRole.sol:20" + }, + { + "label": "_relayers", + "offset": 0, + "slot": "1", + "type": "t_struct(AddressSet)6547_storage", + "contract": "RelayerRole", + "src": "contracts/access/RelayerRole.sol:18" + }, + { + "label": "_paused", + "offset": 0, + "slot": "3", + "type": "t_bool", + "contract": "Pausable", + "src": "contracts/lib/Pausable.sol:10" + }, + { + "label": "batchSettleBlockCount", + "offset": 0, + "slot": "4", + "type": "t_uint256", + "contract": "Bridge", + "src": "contracts/Bridge.sol:36" + }, + { + "label": "quorum", + "offset": 0, + "slot": "5", + "type": "t_uint256", + "contract": "Bridge", + "src": "contracts/Bridge.sol:38" + }, + { + "label": "__gap", + "offset": 0, + "slot": "6", + "type": "t_array(t_uint256)10_storage", + "contract": "Bridge", + "src": "contracts/Bridge.sol:40" + }, + { + "label": "safe", + "offset": 0, + "slot": "16", + "type": "t_contract(ERC20Safe)5548", + "contract": "Bridge", + "src": "contracts/Bridge.sol:42" + }, + { + "label": "executedBatches", + "offset": 0, + "slot": "17", + "type": "t_mapping(t_uint256,t_bool)", + "contract": "Bridge", + "src": "contracts/Bridge.sol:44" + }, + { + "label": "crossTransferStatuses", + "offset": 0, + "slot": "18", + "type": "t_mapping(t_uint256,t_struct(CrossTransferStatus)5755_storage)", + "contract": "Bridge", + "src": "contracts/Bridge.sol:45" + } + ], + "types": { + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_struct(InitializableStorage)158_storage": { + "label": "struct Initializable.InitializableStorage", + "members": [ + { + "label": "_initialized", + "type": "t_uint64", + "offset": 0, + "slot": "0" + }, + { + "label": "_initializing", + "type": "t_bool", + "offset": 8, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_uint64": { + "label": "uint64", + "numberOfBytes": "8" + }, + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_address)dyn_storage": { + "label": "address[]", + "numberOfBytes": "32" + }, + "t_array(t_enum(DepositStatus)5734)dyn_storage": { + "label": "enum DepositStatus[]", + "numberOfBytes": "32" + }, + "t_array(t_uint256)10_storage": { + "label": "uint256[10]", + "numberOfBytes": "320" + }, + "t_contract(ERC20Safe)5548": { + "label": "contract ERC20Safe", + "numberOfBytes": "20" + }, + "t_enum(DepositStatus)5734": { + "label": "enum DepositStatus", + "members": [ + "None", + "Pending", + "InProgress", + "Executed", + "Rejected" + ], + "numberOfBytes": "1" + }, + "t_mapping(t_address,t_uint256)": { + "label": "mapping(address => uint256)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_bool)": { + "label": "mapping(uint256 => bool)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_struct(CrossTransferStatus)5755_storage)": { + "label": "mapping(uint256 => struct CrossTransferStatus)", + "numberOfBytes": "32" + }, + "t_struct(AddressSet)6547_storage": { + "label": "struct EnumerableSet.AddressSet", + "members": [ + { + "label": "_values", + "type": "t_array(t_address)dyn_storage", + "offset": 0, + "slot": "0" + }, + { + "label": "_indexes", + "type": "t_mapping(t_address,t_uint256)", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_struct(CrossTransferStatus)5755_storage": { + "label": "struct CrossTransferStatus", + "members": [ + { + "label": "statuses", + "type": "t_array(t_enum(DepositStatus)5734)dyn_storage", + "offset": 0, + "slot": "0" + }, + { + "label": "createdBlockNumber", + "type": "t_uint256", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + } + }, + "namespaces": { + "erc7201:openzeppelin.storage.Initializable": [ + { + "contract": "Initializable", + "label": "_initialized", + "type": "t_uint64", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:69", + "offset": 0, + "slot": "0" + }, + { + "contract": "Initializable", + "label": "_initializing", + "type": "t_bool", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:73", + "offset": 8, + "slot": "0" + } + ] + } + } + }, + "e93c905ef693d20e46f85583b4186d2808146c49a1eaef027c5a0cf133056b3d": { + "address": "0x1D914dDa18C072e7758f68AAD1320fE466f27831", + "txHash": "0x3ffa02f794dd49efa5e65ff30c929dc67cf7dbc024e3f49e37e977f77f342b80", + "layout": { + "solcVersion": "0.8.20", + "storage": [ + { + "label": "_admin", + "offset": 0, + "slot": "0", + "type": "t_address", + "contract": "AdminRole", + "src": "contracts/access/AdminRole.sol:20" + }, + { + "label": "_bridge", + "offset": 0, + "slot": "1", + "type": "t_address", + "contract": "BridgeRole", + "src": "contracts/access/BridgeRole.sol:37" + }, + { + "label": "_paused", + "offset": 20, + "slot": "1", + "type": "t_bool", + "contract": "Pausable", + "src": "contracts/lib/Pausable.sol:10" + }, + { + "label": "batchesCount", + "offset": 21, + "slot": "1", + "type": "t_uint64", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:35" + }, + { + "label": "depositsCount", + "offset": 0, + "slot": "2", + "type": "t_uint64", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:36" + }, + { + "label": "batchSize", + "offset": 8, + "slot": "2", + "type": "t_uint16", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:37" + }, + { + "label": "batchBlockLimit", + "offset": 10, + "slot": "2", + "type": "t_uint8", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:39" + }, + { + "label": "batchSettleLimit", + "offset": 11, + "slot": "2", + "type": "t_uint8", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:40" + }, + { + "label": "__gap", + "offset": 0, + "slot": "3", + "type": "t_array(t_uint256)10_storage", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:43" + }, + { + "label": "batches", + "offset": 0, + "slot": "13", + "type": "t_mapping(t_uint256,t_struct(Batch)3596_storage)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:45" + }, + { + "label": "whitelistedTokens", + "offset": 0, + "slot": "14", + "type": "t_mapping(t_address,t_bool)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:46" + }, + { + "label": "mintBurnTokens", + "offset": 0, + "slot": "15", + "type": "t_mapping(t_address,t_bool)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:47" + }, + { + "label": "nativeTokens", + "offset": 0, + "slot": "16", + "type": "t_mapping(t_address,t_bool)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:48" + }, + { + "label": "tokenMinLimits", + "offset": 0, + "slot": "17", + "type": "t_mapping(t_address,t_uint256)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:49" + }, + { + "label": "tokenMaxLimits", + "offset": 0, + "slot": "18", + "type": "t_mapping(t_address,t_uint256)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:50" + }, + { + "label": "totalBalances", + "offset": 0, + "slot": "19", + "type": "t_mapping(t_address,t_uint256)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:51" + }, + { + "label": "mintBalances", + "offset": 0, + "slot": "20", + "type": "t_mapping(t_address,t_uint256)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:52" + }, + { + "label": "burnBalances", + "offset": 0, + "slot": "21", + "type": "t_mapping(t_address,t_uint256)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:53" + }, + { + "label": "batchDeposits", + "offset": 0, + "slot": "22", + "type": "t_mapping(t_uint256,t_array(t_struct(Deposit)3580_storage)dyn_storage)", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:54" + }, + { + "label": "batchBlockLimitV2", + "offset": 0, + "slot": "23", + "type": "t_uint16", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:59" + }, + { + "label": "batchSettleLimitV2", + "offset": 2, + "slot": "23", + "type": "t_uint16", + "contract": "ERC20Safe", + "src": "contracts/ERC20Safe.sol:60" + } + ], + "types": { + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_struct(InitializableStorage)7_storage": { + "label": "struct Initializable.InitializableStorage", + "members": [ + { + "label": "_initialized", + "type": "t_uint64", + "offset": 0, + "slot": "0" + }, + { + "label": "_initializing", + "type": "t_bool", + "offset": 8, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_uint64": { + "label": "uint64", + "numberOfBytes": "8" + }, + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_struct(Deposit)3580_storage)dyn_storage": { + "label": "struct Deposit[]", + "numberOfBytes": "32" + }, + "t_array(t_uint256)10_storage": { + "label": "uint256[10]", + "numberOfBytes": "320" + }, + "t_bytes32": { + "label": "bytes32", + "numberOfBytes": "32" + }, + "t_enum(DepositStatus)3566": { + "label": "enum DepositStatus", + "members": [ + "None", + "Pending", + "InProgress", + "Executed", + "Rejected" + ], + "numberOfBytes": "1" + }, + "t_mapping(t_address,t_bool)": { + "label": "mapping(address => bool)", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_uint256)": { + "label": "mapping(address => uint256)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_array(t_struct(Deposit)3580_storage)dyn_storage)": { + "label": "mapping(uint256 => struct Deposit[])", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_struct(Batch)3596_storage)": { + "label": "mapping(uint256 => struct Batch)", + "numberOfBytes": "32" + }, + "t_struct(Batch)3596_storage": { + "label": "struct Batch", + "members": [ + { + "label": "nonce", + "type": "t_uint112", + "offset": 0, + "slot": "0" + }, + { + "label": "blockNumber", + "type": "t_uint64", + "offset": 14, + "slot": "0" + }, + { + "label": "lastUpdatedBlockNumber", + "type": "t_uint64", + "offset": 22, + "slot": "0" + }, + { + "label": "depositsCount", + "type": "t_uint16", + "offset": 30, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_struct(Deposit)3580_storage": { + "label": "struct Deposit", + "members": [ + { + "label": "nonce", + "type": "t_uint112", + "offset": 0, + "slot": "0" + }, + { + "label": "tokenAddress", + "type": "t_address", + "offset": 0, + "slot": "1" + }, + { + "label": "amount", + "type": "t_uint256", + "offset": 0, + "slot": "2" + }, + { + "label": "depositor", + "type": "t_address", + "offset": 0, + "slot": "3" + }, + { + "label": "recipient", + "type": "t_bytes32", + "offset": 0, + "slot": "4" + }, + { + "label": "status", + "type": "t_enum(DepositStatus)3566", + "offset": 0, + "slot": "5" + } + ], + "numberOfBytes": "192" + }, + "t_uint112": { + "label": "uint112", + "numberOfBytes": "14" + }, + "t_uint16": { + "label": "uint16", + "numberOfBytes": "2" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + }, + "namespaces": { + "erc7201:openzeppelin.storage.Initializable": [ + { + "contract": "Initializable", + "label": "_initialized", + "type": "t_uint64", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:69", + "offset": 0, + "slot": "0" + }, + { + "contract": "Initializable", + "label": "_initializing", + "type": "t_bool", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:73", + "offset": 8, + "slot": "0" + } + ] + } + } + } + } +} diff --git a/contracts/ERC20Safe.sol b/contracts/ERC20Safe.sol index b96169d..97d1b49 100644 --- a/contracts/ERC20Safe.sol +++ b/contracts/ERC20Safe.sol @@ -36,14 +36,11 @@ contract ERC20Safe is Initializable, BridgeRole, Pausable { uint64 public depositsCount; uint16 public batchSize; uint16 private constant maxBatchSize = 100; - uint16 public batchBlockLimit; - uint16 public batchSettleLimit; + uint8 public batchBlockLimit; + uint8 public batchSettleLimit; // Reserved storage slots for future upgrades - uint16 private __gap16; - uint32 private __gap32; - uint64[3] private __gap64; - uint256[9] private __gap; + uint256[10] private __gap; mapping(uint256 => Batch) public batches; mapping(address => bool) public whitelistedTokens; @@ -59,6 +56,9 @@ contract ERC20Safe is Initializable, BridgeRole, Pausable { event ERC20Deposit(uint112 batchId, uint112 depositNonce); event ERC20SCDeposit(uint112 indexed batchId, uint112 depositNonce, bytes callData); + uint16 public batchBlockLimitV2; + uint16 public batchSettleLimitV2; + function initialize() public initializer { __BridgeRole_init(); __Pausable_init(); @@ -67,8 +67,8 @@ contract ERC20Safe is Initializable, BridgeRole, Pausable { function __ERC20Safe__init_unchained() internal onlyInitializing { batchSize = 10; - batchBlockLimit = 40; - batchSettleLimit = 40; + batchBlockLimitV2 = 40; + batchSettleLimitV2 = 40; } /** @@ -127,8 +127,8 @@ contract ERC20Safe is Initializable, BridgeRole, Pausable { @param newBatchBlockLimit New block number limit that will be set until a batch is considered final */ function setBatchBlockLimit(uint16 newBatchBlockLimit) external onlyAdmin { - require(newBatchBlockLimit <= batchSettleLimit, "Cannot increase batch block limit over settlement limit"); - batchBlockLimit = newBatchBlockLimit; + require(newBatchBlockLimit <= batchSettleLimitV2, "Cannot increase batch block limit over settlement limit"); + batchBlockLimitV2 = newBatchBlockLimit; } /** @@ -138,10 +138,10 @@ contract ERC20Safe is Initializable, BridgeRole, Pausable { function setBatchSettleLimit(uint16 newBatchSettleLimit) external onlyAdmin whenPaused { require(!isAnyBatchInProgress(), "Cannot change batchSettleLimit with pending batches"); require( - newBatchSettleLimit >= batchBlockLimit, + newBatchSettleLimit >= batchBlockLimitV2, "Cannot decrease batchSettleLimit under the value of batch block limit" ); - batchSettleLimit = newBatchSettleLimit; + batchSettleLimitV2 = newBatchSettleLimit; } /** @@ -392,14 +392,14 @@ contract ERC20Safe is Initializable, BridgeRole, Pausable { } function _isBatchFinal(Batch memory batch) private view returns (bool) { - return (batch.lastUpdatedBlockNumber + batchSettleLimit) < block.number; + return (batch.lastUpdatedBlockNumber + batchSettleLimitV2) < block.number; } function _isBatchProgessOver(uint16 depCount, uint64 blockNumber) private view returns (bool) { if (depCount == 0) { return false; } - return (blockNumber + batchBlockLimit) < block.number; + return (blockNumber + batchBlockLimitV2) < block.number; } function _shouldCreateNewBatch() private view returns (bool) { diff --git a/tasks/deploy/force-import-bridge.ts b/tasks/deploy/force-import-bridge.ts new file mode 100644 index 0000000..020a5d3 --- /dev/null +++ b/tasks/deploy/force-import-bridge.ts @@ -0,0 +1,19 @@ +import "@nomicfoundation/hardhat-toolbox"; + +task("force-import-bridge", "Imports the Bridge configuration in the .openzeppelin directory. IMPORTANT: use this on the current deployed version of the code") + .addOptionalParam("price", "Gas price in gwei for this transaction", undefined) + .setAction(async (taskArgs, hre) => { + const [adminWallet] = await hre.ethers.getSigners(); + console.log("Admin Public Address: ", adminWallet.address); + + const fs = require("fs"); + const filename = "setup.config.json"; + const config = JSON.parse(fs.readFileSync(filename, "utf8")); + const bridgeAddress = config["bridge"]; + console.log("Bridge deployed to: ", bridgeAddress); + + const factory = (await hre.ethers.getContractFactory("Bridge")).connect(adminWallet); + await hre.upgrades.forceImport(bridgeAddress, factory) + + console.log("Bridge imported"); + }); diff --git a/tasks/deploy/force-import-safe.ts b/tasks/deploy/force-import-safe.ts new file mode 100644 index 0000000..47c868b --- /dev/null +++ b/tasks/deploy/force-import-safe.ts @@ -0,0 +1,19 @@ +import "@nomicfoundation/hardhat-toolbox"; + +task("force-import-safe", "Imports the ERC20Safe configuration in the .openzeppelin directory. IMPORTANT: use this on the current deployed version of the code") + .addOptionalParam("price", "Gas price in gwei for this transaction", undefined) + .setAction(async (taskArgs, hre) => { + const [adminWallet] = await hre.ethers.getSigners(); + console.log("Admin Public Address: ", adminWallet.address); + + const fs = require("fs"); + const filename = "setup.config.json"; + const config = JSON.parse(fs.readFileSync(filename, "utf8")); + const safeAddress = config["erc20Safe"]; + console.log("ERC20Safe deployed to: ", safeAddress); + + const factory = (await hre.ethers.getContractFactory("ERC20Safe")).connect(adminWallet); + await hre.upgrades.forceImport(safeAddress, factory) + + console.log("ERC20Safe imported"); + }); diff --git a/tasks/deploy/index.ts b/tasks/deploy/index.ts index c17be77..48cb2ae 100644 --- a/tasks/deploy/index.ts +++ b/tasks/deploy/index.ts @@ -6,3 +6,5 @@ import "./evil-erc"; import "./mint-burn-tokens"; import "./upgrade-safe" import "./approve-non-zero-tokens"; +import "./force-import-safe" +import "./force-import-bridge" diff --git a/test/Safe.test.js b/test/Safe.test.js index c684207..3614f59 100644 --- a/test/Safe.test.js +++ b/test/Safe.test.js @@ -61,12 +61,12 @@ describe("ERC20Safe", function () { describe("ERC20Safe - setting batch block limit works as expected", async function () { it("is default correct", async function () { const tenMinutes = 40; - expect(await safe.batchBlockLimit()).to.eq(tenMinutes); + expect(await safe.batchBlockLimitV2()).to.eq(tenMinutes); }); it("updates the batch time limit", async function () { const eight = 8; await safe.setBatchBlockLimit(eight); - expect(await safe.batchBlockLimit()).to.equal(eight); + expect(await safe.batchBlockLimitV2()).to.equal(eight); }); it("reverts", async function () { await expect(safe.connect(otherWallet).setBatchBlockLimit(30)).to.be.revertedWith( @@ -81,7 +81,7 @@ describe("ERC20Safe", function () { describe("ERC20Safe - setting batch settle limit works as expected", async function () { it("is default correct", async function () { const tenMinutes = 40; - expect(await safe.batchSettleLimit()).to.eq(tenMinutes); + expect(await safe.batchSettleLimitV2()).to.eq(tenMinutes); }); it("reverts", async function () { await expect(safe.connect(adminWallet).setBatchSettleLimit(50)).to.be.revertedWith("Pausable: not paused"); @@ -147,7 +147,7 @@ describe("ERC20Safe", function () { const batchSettleLimit = 50; await safe.connect(adminWallet).setBatchSettleLimit(batchSettleLimit); - expect(await safe.batchSettleLimit()).to.equal(batchSettleLimit); + expect(await safe.batchSettleLimitV2()).to.equal(batchSettleLimit); await safe.unpause(); }); @@ -308,7 +308,7 @@ describe("ERC20Safe", function () { }); it("creates new batches as time passes", async function () { - const batchBlockLimit = parseInt((await safe.batchBlockLimit()).toString()); + const batchBlockLimit = parseInt((await safe.batchBlockLimitV2()).toString()); await safe.setBatchSize(2); expect(await safe.batchesCount()).to.be.eq(0); @@ -452,7 +452,7 @@ describe("ERC20Safe", function () { it("returns batch only after final", async function () { await safe.setBatchSize(3); - const batchBlockLimit = parseInt((await safe.batchBlockLimit()).toString()); + const batchBlockLimit = parseInt((await safe.batchBlockLimitV2()).toString()); await safe.deposit( genericERC20.address,