Skip to content

Commit

Permalink
feat(protocol): allow QuotaManager to set quota period (#17497)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Jun 6, 2024
1 parent cc77898 commit 1655aef
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/protocol/contracts/bridge/QuotaManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions packages/protocol/deployments/mainnet-contract-logs-L1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions packages/protocol/test/bridge/QuotaManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 1655aef

Please sign in to comment.