diff --git a/packages/protocol/contracts/bridge/QuotaManager.sol b/packages/protocol/contracts/bridge/QuotaManager.sol index 2b8a4e5e8a0..b5bf55ecfd8 100644 --- a/packages/protocol/contracts/bridge/QuotaManager.sol +++ b/packages/protocol/contracts/bridge/QuotaManager.sol @@ -24,6 +24,7 @@ contract QuotaManager is EssentialContract, IQuotaManager { uint256[48] private __gap; event QuotaUpdated(address indexed token, uint256 oldQuota, uint256 newQuota); + event QuotaPeriodUpdated(uint256 quotaPeriod); error QM_INVALID_PARAM(); error QM_OUT_OF_QUOTA(); @@ -40,21 +41,20 @@ contract QuotaManager is EssentialContract, IQuotaManager { external initializer { - if (_quotaPeriod == 0) revert QM_INVALID_PARAM(); - __Essential_init(_owner, _addressManager); - quotaPeriod = _quotaPeriod; + _setQuotaPeriod(_quotaPeriod); } /// @notice Updates the daily quota for a given address. /// @param _token The token address with Ether represented by address(0). /// @param _quota The new quota for the defined period. function updateQuota(address _token, uint104 _quota) external onlyOwner whenNotPaused { - uint104 currQuota = tokenQuota[_token].quota; - if (_quota == currQuota) revert QM_INVALID_PARAM(); + emit QuotaUpdated(_token, tokenQuota[_token].quota, _quota); + tokenQuota[_token] = Quota(0, _quota, _quota); + } - emit QuotaUpdated(_token, currQuota, _quota); - tokenQuota[_token].quota = _quota; + function setQuotaPeriod(uint24 _quotaPeriod) external onlyOwner whenNotPaused { + _setQuotaPeriod(_quotaPeriod); } /// @inheritdoc IQuotaManager @@ -89,4 +89,10 @@ contract QuotaManager is EssentialContract, IQuotaManager { uint256 issuance = q.quota * (block.timestamp + _leap - q.updatedAt) / quotaPeriod; return (issuance + q.available).min(q.quota); } + + function _setQuotaPeriod(uint24 _quotaPeriod) private { + if (_quotaPeriod == 0) revert QM_INVALID_PARAM(); + quotaPeriod = _quotaPeriod; + emit QuotaPeriodUpdated(_quotaPeriod); + } } diff --git a/packages/protocol/deployments/mainnet-contract-logs-L1.md b/packages/protocol/deployments/mainnet-contract-logs-L1.md index 7a0df43158f..85a73d5b792 100644 --- a/packages/protocol/deployments/mainnet-contract-logs-L1.md +++ b/packages/protocol/deployments/mainnet-contract-logs-L1.md @@ -91,6 +91,18 @@ - logs: - deployed on May 13, 2024 at commit `b90b932` - admin.taiko.eth accepted the ownership @tx`0x2d6ce1781137899f65c1810e42f556c27caa4e9bd13077ba5bc7a9a0975eefcb` +- todo: + + - upgrade the contract + - set quota_period to 86400 and: + + ``` + ETH 0x0000000000000000000000000000000000000000 1000000000000000000000 + WETH 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 1000000000000000000000 + TAIKO 0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800 2000000000000000000000000 + USDT 0xdAC17F958D2ee523a2206206994597C13D831ec7 4000000000000 + USDC 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 4000000000000 + ``` #### erc20_vault diff --git a/packages/protocol/test/bridge/QuotaManager.t.sol b/packages/protocol/test/bridge/QuotaManager.t.sol index be308c6e09b..367c1063835 100644 --- a/packages/protocol/test/bridge/QuotaManager.t.sol +++ b/packages/protocol/test/bridge/QuotaManager.t.sol @@ -71,4 +71,22 @@ contract QuotaManagerTest is TaikoTest { qm.consumeQuota(token, 6 ether); assertEq(qm.availableQuota(token, 0), type(uint256).max); } + + function test_calc_quota() public { + uint24 quotaPeriod = 24 hours; + uint104 value = 4_000_000; // USD + uint104 priceETH = 4000; // USD + uint104 priceTKO = 2; // USD + + console2.log("quota period:", quotaPeriod); + console2.log("quota value: ", value); + console2.log("Ether amount ", value / priceETH); + console2.log("ETH ", address(0), value * 1 ether / priceETH); + console2.log( + "WETH ", 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, value * 1 ether / priceETH + ); + console2.log("TAIKO", 0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800, value * 1e18 / priceTKO); + console2.log("USDT ", 0xdAC17F958D2ee523a2206206994597C13D831ec7, value * 1e6); + console2.log("USDC ", 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, value * 1e6); + } }