From c151719b90b9bcb4e7a4ee922097fb565ccc6f7a Mon Sep 17 00:00:00 2001 From: QUAQ Date: Mon, 2 Dec 2024 09:17:06 -0600 Subject: [PATCH 1/6] payments storage packing --- contracts/src/interfaces/IPaymentVault.sol | 18 +++++------ contracts/src/payments/PaymentVault.sol | 28 ++++++++--------- .../src/payments/PaymentVaultStorage.sol | 16 +++++----- contracts/test/unit/PaymentVaultUnit.t.sol | 30 +++++++++---------- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/contracts/src/interfaces/IPaymentVault.sol b/contracts/src/interfaces/IPaymentVault.sol index 399fe3f6ce..971525699f 100644 --- a/contracts/src/interfaces/IPaymentVault.sol +++ b/contracts/src/interfaces/IPaymentVault.sol @@ -16,19 +16,19 @@ interface IPaymentVault { /// @notice Emitted when an on-demand payment is created or updated event OnDemandPaymentUpdated(address indexed account, uint256 onDemandPayment, uint256 totalDeposit); /// @notice Emitted when globalSymbolsPerBin is updated - event GlobalSymbolsPerBinUpdated(uint256 previousValue, uint256 newValue); + event GlobalSymbolsPerBinUpdated(uint128 previousValue, uint128 newValue); /// @notice Emitted when reservationBinInterval is updated - event ReservationBinIntervalUpdated(uint256 previousValue, uint256 newValue); + event ReservationBinIntervalUpdated(uint128 previousValue, uint128 newValue); /// @notice Emitted when globalRateBinInterval is updated - event GlobalRateBinIntervalUpdated(uint256 previousValue, uint256 newValue); + event GlobalRateBinIntervalUpdated(uint128 previousValue, uint128 newValue); /// @notice Emitted when priceParams are updated event PriceParamsUpdated( - uint256 previousMinNumSymbols, - uint256 newMinNumSymbols, - uint256 previousPricePerSymbol, - uint256 newPricePerSymbol, - uint256 previousPriceUpdateCooldown, - uint256 newPriceUpdateCooldown + uint128 previousMinNumSymbols, + uint128 newMinNumSymbols, + uint128 previousPricePerSymbol, + uint128 newPricePerSymbol, + uint128 previousPriceUpdateCooldown, + uint128 newPriceUpdateCooldown ); /** diff --git a/contracts/src/payments/PaymentVault.sol b/contracts/src/payments/PaymentVault.sol index 23bd0205b6..583c85aa40 100644 --- a/contracts/src/payments/PaymentVault.sol +++ b/contracts/src/payments/PaymentVault.sol @@ -25,12 +25,12 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { function initialize( address _initialOwner, - uint256 _minNumSymbols, - uint256 _globalSymbolsPerBin, - uint256 _pricePerSymbol, - uint256 _reservationBinInterval, - uint256 _priceUpdateCooldown, - uint256 _globalRateBinInterval + uint128 _minNumSymbols, + uint128 _globalSymbolsPerBin, + uint128 _pricePerSymbol, + uint128 _reservationBinInterval, + uint128 _priceUpdateCooldown, + uint128 _globalRateBinInterval ) public initializer { _transferOwnership(_initialOwner); @@ -41,7 +41,7 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { priceUpdateCooldown = _priceUpdateCooldown; globalRateBinInterval = _globalRateBinInterval; - lastPriceUpdateTime = block.timestamp; + lastPriceUpdateTime = uint128(block.timestamp); } /** @@ -68,9 +68,9 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { } function setPriceParams( - uint256 _minNumSymbols, - uint256 _pricePerSymbol, - uint256 _priceUpdateCooldown + uint128 _minNumSymbols, + uint128 _pricePerSymbol, + uint128 _priceUpdateCooldown ) external onlyOwner { require(block.timestamp >= lastPriceUpdateTime + priceUpdateCooldown, "price update cooldown not surpassed"); emit PriceParamsUpdated( @@ -81,20 +81,20 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { pricePerSymbol = _pricePerSymbol; minNumSymbols = _minNumSymbols; priceUpdateCooldown = _priceUpdateCooldown; - lastPriceUpdateTime = block.timestamp; + lastPriceUpdateTime = uint128(block.timestamp); } - function setGlobalSymbolsPerBin(uint256 _globalSymbolsPerBin) external onlyOwner { + function setGlobalSymbolsPerBin(uint128 _globalSymbolsPerBin) external onlyOwner { emit GlobalSymbolsPerBinUpdated(globalSymbolsPerBin, _globalSymbolsPerBin); globalSymbolsPerBin = _globalSymbolsPerBin; } - function setReservationBinInterval(uint256 _reservationBinInterval) external onlyOwner { + function setReservationBinInterval(uint128 _reservationBinInterval) external onlyOwner { emit ReservationBinIntervalUpdated(reservationBinInterval, _reservationBinInterval); reservationBinInterval = _reservationBinInterval; } - function setGlobalRateBinInterval(uint256 _globalRateBinInterval) external onlyOwner { + function setGlobalRateBinInterval(uint128 _globalRateBinInterval) external onlyOwner { emit GlobalRateBinIntervalUpdated(globalRateBinInterval, _globalRateBinInterval); globalRateBinInterval = _globalRateBinInterval; } diff --git a/contracts/src/payments/PaymentVaultStorage.sol b/contracts/src/payments/PaymentVaultStorage.sol index 4c364c3c13..f58be0742d 100644 --- a/contracts/src/payments/PaymentVaultStorage.sol +++ b/contracts/src/payments/PaymentVaultStorage.sol @@ -6,25 +6,25 @@ import {IPaymentVault} from "../interfaces/IPaymentVault.sol"; abstract contract PaymentVaultStorage is IPaymentVault { /// @notice minimum chargeable size for on-demand payments - uint256 public minNumSymbols; + uint128 public minNumSymbols; /// @notice price per symbol in wei - uint256 public pricePerSymbol; + uint128 public pricePerSymbol; /// @notice cooldown period before the price can be updated again - uint256 public priceUpdateCooldown; + uint128 public priceUpdateCooldown; /// @notice maximum number of symbols to disperse per second network-wide for on-demand payments (applied to only ETH and EIGEN) - uint256 public globalSymbolsPerBin; + uint128 public globalSymbolsPerBin; /// @notice reservation bin duration - uint256 public reservationBinInterval; + uint128 public reservationBinInterval; /// @notice global rate bin size - uint256 public globalRateBinInterval; + uint128 public globalRateBinInterval; /// @notice timestamp of the last price update - uint256 public lastPriceUpdateTime; + uint128 public lastPriceUpdateTime; /// @notice mapping from user address to current reservation mapping(address => Reservation) public reservations; /// @notice mapping from user address to current on-demand payment mapping(address => uint256) public onDemandPayments; - uint256[42] private __GAP; + uint256[44] private __GAP; } \ No newline at end of file diff --git a/contracts/test/unit/PaymentVaultUnit.t.sol b/contracts/test/unit/PaymentVaultUnit.t.sol index 7d0f386358..f6fab66e21 100644 --- a/contracts/test/unit/PaymentVaultUnit.t.sol +++ b/contracts/test/unit/PaymentVaultUnit.t.sol @@ -13,16 +13,16 @@ contract PaymentVaultUnit is Test { event ReservationUpdated(address indexed account, IPaymentVault.Reservation reservation); event OnDemandPaymentUpdated(address indexed account, uint256 onDemandPayment, uint256 totalDeposit); - event GlobalSymbolsPerBinUpdated(uint256 previousValue, uint256 newValue); - event ReservationBinIntervalUpdated(uint256 previousValue, uint256 newValue); - event GlobalRateBinIntervalUpdated(uint256 previousValue, uint256 newValue); + event GlobalSymbolsPerBinUpdated(uint128 previousValue, uint128 newValue); + event ReservationBinIntervalUpdated(uint128 previousValue, uint128 newValue); + event GlobalRateBinIntervalUpdated(uint128 previousValue, uint128 newValue); event PriceParamsUpdated( - uint256 previousMinNumSymbols, - uint256 newMinNumSymbols, - uint256 previousPricePerSymbol, - uint256 newPricePerSymbol, - uint256 previousPriceUpdateCooldown, - uint256 newPriceUpdateCooldown + uint128 previousMinNumSymbols, + uint128 newMinNumSymbols, + uint128 previousPricePerSymbol, + uint128 newPricePerSymbol, + uint128 previousPriceUpdateCooldown, + uint128 newPriceUpdateCooldown ); PaymentVault paymentVault; @@ -34,13 +34,13 @@ contract PaymentVaultUnit is Test { address user = address(uint160(uint256(keccak256(abi.encodePacked("user"))))); address user2 = address(uint160(uint256(keccak256(abi.encodePacked("user2"))))); - uint256 minNumSymbols = 1; - uint256 globalSymbolsPerBin = 2; - uint256 pricePerSymbol = 3; - uint256 reservationBinInterval = 4; - uint256 globalRateBinInterval = 5; + uint128 minNumSymbols = 1; + uint128 globalSymbolsPerBin = 2; + uint128 pricePerSymbol = 3; + uint128 reservationBinInterval = 4; + uint128 globalRateBinInterval = 5; - uint256 priceUpdateCooldown = 6 days; + uint128 priceUpdateCooldown = 6 days; bytes quorumNumbers = hex"0001"; bytes quorumSplits = hex"3232"; From e2e5ccda7c9d7f3e333fa5dd113c38daf20a8391 Mon Sep 17 00:00:00 2001 From: QUAQ Date: Mon, 2 Dec 2024 10:55:36 -0600 Subject: [PATCH 2/6] uint128 ondemand --- contracts/src/interfaces/IPaymentVault.sol | 8 ++++---- contracts/src/payments/PaymentVault.sol | 10 +++++----- contracts/src/payments/PaymentVaultStorage.sol | 2 +- contracts/test/unit/PaymentVaultUnit.t.sol | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/contracts/src/interfaces/IPaymentVault.sol b/contracts/src/interfaces/IPaymentVault.sol index 971525699f..102e3541c5 100644 --- a/contracts/src/interfaces/IPaymentVault.sol +++ b/contracts/src/interfaces/IPaymentVault.sol @@ -14,7 +14,7 @@ interface IPaymentVault { /// @notice Emitted when a reservation is created or updated event ReservationUpdated(address indexed account, Reservation reservation); /// @notice Emitted when an on-demand payment is created or updated - event OnDemandPaymentUpdated(address indexed account, uint256 onDemandPayment, uint256 totalDeposit); + event OnDemandPaymentUpdated(address indexed account, uint128 onDemandPayment, uint128 totalDeposit); /// @notice Emitted when globalSymbolsPerBin is updated event GlobalSymbolsPerBinUpdated(uint128 previousValue, uint128 newValue); /// @notice Emitted when reservationBinInterval is updated @@ -54,8 +54,8 @@ interface IPaymentVault { function getReservations(address[] memory _accounts) external view returns (Reservation[] memory _reservations); /// @notice Fetches the current total on demand balance of an account - function getOnDemandAmount(address _account) external view returns (uint256); + function getOnDemandAmount(address _account) external view returns (uint128); /// @notice Fetches the current total on demand balances for a set of accounts - function getOnDemandAmounts(address[] memory _accounts) external view returns (uint256[] memory _payments); -} \ No newline at end of file + function getOnDemandAmounts(address[] memory _accounts) external view returns (uint128[] memory _payments); +} diff --git a/contracts/src/payments/PaymentVault.sol b/contracts/src/payments/PaymentVault.sol index 583c85aa40..9370daf2f3 100644 --- a/contracts/src/payments/PaymentVault.sol +++ b/contracts/src/payments/PaymentVault.sol @@ -116,8 +116,8 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { } function _deposit(address _account, uint256 _amount) internal { - onDemandPayments[_account] += _amount; - emit OnDemandPaymentUpdated(_account, _amount, onDemandPayments[_account]); + onDemandPayments[_account] += uint128(_amount); + emit OnDemandPaymentUpdated(_account, uint128(_amount), uint128(onDemandPayments[_account])); } /// @notice Fetches the current reservation for an account @@ -134,13 +134,13 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { } /// @notice Fetches the current total on demand balance of an account - function getOnDemandAmount(address _account) external view returns (uint256) { + function getOnDemandAmount(address _account) external view returns (uint128) { return onDemandPayments[_account]; } /// @notice Fetches the current total on demand balances for a set of accounts - function getOnDemandAmounts(address[] memory _accounts) external view returns (uint256[] memory _payments) { - _payments = new uint256[](_accounts.length); + function getOnDemandAmounts(address[] memory _accounts) external view returns (uint128[] memory _payments) { + _payments = new uint128[](_accounts.length); for(uint256 i; i < _accounts.length; ++i){ _payments[i] = onDemandPayments[_accounts[i]]; } diff --git a/contracts/src/payments/PaymentVaultStorage.sol b/contracts/src/payments/PaymentVaultStorage.sol index f58be0742d..afe2ebf412 100644 --- a/contracts/src/payments/PaymentVaultStorage.sol +++ b/contracts/src/payments/PaymentVaultStorage.sol @@ -24,7 +24,7 @@ abstract contract PaymentVaultStorage is IPaymentVault { /// @notice mapping from user address to current reservation mapping(address => Reservation) public reservations; /// @notice mapping from user address to current on-demand payment - mapping(address => uint256) public onDemandPayments; + mapping(address => uint128) public onDemandPayments; uint256[44] private __GAP; } \ No newline at end of file diff --git a/contracts/test/unit/PaymentVaultUnit.t.sol b/contracts/test/unit/PaymentVaultUnit.t.sol index f6fab66e21..3b044ad707 100644 --- a/contracts/test/unit/PaymentVaultUnit.t.sol +++ b/contracts/test/unit/PaymentVaultUnit.t.sol @@ -12,7 +12,7 @@ contract PaymentVaultUnit is Test { using stdStorage for StdStorage; event ReservationUpdated(address indexed account, IPaymentVault.Reservation reservation); - event OnDemandPaymentUpdated(address indexed account, uint256 onDemandPayment, uint256 totalDeposit); + event OnDemandPaymentUpdated(address indexed account, uint128 onDemandPayment, uint128 totalDeposit); event GlobalSymbolsPerBinUpdated(uint128 previousValue, uint128 newValue); event ReservationBinIntervalUpdated(uint128 previousValue, uint128 newValue); event GlobalRateBinIntervalUpdated(uint128 previousValue, uint128 newValue); @@ -335,7 +335,7 @@ contract PaymentVaultUnit is Test { accounts[0] = user; accounts[1] = user2; - uint256[] memory payments = paymentVault.getOnDemandAmounts(accounts); + uint128[] memory payments = paymentVault.getOnDemandAmounts(accounts); assertEq(payments[0], 100 ether); assertEq(payments[1], 200 ether); } From ba74133bf5b8d3bd67eb914c72f22928776f8d4c Mon Sep 17 00:00:00 2001 From: QUAQ Date: Wed, 4 Dec 2024 19:53:56 -0600 Subject: [PATCH 3/6] DASM link --- contracts/script/EigenDADeployer.s.sol | 37 ++++++++++++++++++- contracts/src/core/EigenDAServiceManager.sol | 6 ++- .../src/core/EigenDAServiceManagerStorage.sol | 9 ++++- contracts/src/interfaces/IPaymentVault.sol | 4 +- contracts/test/unit/EigenDABlobUtils.t.sol | 4 +- .../test/unit/EigenDAServiceManagerUnit.t.sol | 4 +- contracts/test/unit/MockRollup.t.sol | 4 +- 7 files changed, 58 insertions(+), 10 deletions(-) diff --git a/contracts/script/EigenDADeployer.s.sol b/contracts/script/EigenDADeployer.s.sol index 245fc8145b..b4d3fec7b3 100644 --- a/contracts/script/EigenDADeployer.s.sol +++ b/contracts/script/EigenDADeployer.s.sol @@ -19,6 +19,8 @@ import {EigenDAHasher} from "../src/libraries/EigenDAHasher.sol"; import {ISocketRegistry, SocketRegistry} from "eigenlayer-middleware/SocketRegistry.sol"; import {IEigenDAThresholdRegistry} from "../src/interfaces/IEigenDAThresholdRegistry.sol"; import {IEigenDARelayRegistry} from "../src/interfaces/IEigenDARelayRegistry.sol"; +import {IPaymentVault} from "../src/interfaces/IPaymentVault.sol"; +import {PaymentVault} from "../src/payments/PaymentVault.sol"; import {DeployOpenEigenLayer, ProxyAdmin, ERC20PresetFixedSupply, TransparentUpgradeableProxy, IPauserRegistry} from "./DeployOpenEigenLayer.s.sol"; import "forge-std/Test.sol"; @@ -41,6 +43,7 @@ contract EigenDADeployer is DeployOpenEigenLayer { IStakeRegistry public stakeRegistry; ISocketRegistry public socketRegistry; OperatorStateRetriever public operatorStateRetriever; + IPaymentVault public paymentVault; BLSApkRegistry public apkRegistryImplementation; EigenDAServiceManager public eigenDAServiceManagerImplementation; @@ -48,6 +51,14 @@ contract EigenDADeployer is DeployOpenEigenLayer { IIndexRegistry public indexRegistryImplementation; IStakeRegistry public stakeRegistryImplementation; ISocketRegistry public socketRegistryImplementation; + IPaymentVault public paymentVaultImplementation; + + uint128 _minNumSymbols = 4096; + uint128 _globalSymbolsPerBin = 131072; + uint128 _pricePerSymbol = 0.4470 gwei; + uint128 _reservationBinInterval = 300; + uint128 _priceUpdateCooldown = 1; + uint128 _globalRateBinInterval = 30; struct AddressConfig { address eigenLayerCommunityMultisig; @@ -119,6 +130,29 @@ contract EigenDADeployer is DeployOpenEigenLayer { address(new TransparentUpgradeableProxy(address(emptyContract), address(eigenDAProxyAdmin), "")) ); + { + paymentVault = IPaymentVault( + address(new TransparentUpgradeableProxy(address(emptyContract), address(eigenDAProxyAdmin), "")) + ); + + paymentVaultImplementation = new PaymentVault(); + + eigenDAProxyAdmin.upgradeAndCall( + TransparentUpgradeableProxy(payable(address(paymentVault))), + address(paymentVaultImplementation), + abi.encodeWithSelector( + PaymentVault.initialize.selector, + addressConfig.eigenDACommunityMultisig, + _minNumSymbols, + _globalSymbolsPerBin, + _pricePerSymbol, + _reservationBinInterval, + _priceUpdateCooldown, + _globalRateBinInterval + ) + ); + } + indexRegistryImplementation = new IndexRegistry( registryCoordinator ); @@ -206,7 +240,8 @@ contract EigenDADeployer is DeployOpenEigenLayer { registryCoordinator, stakeRegistry, IEigenDAThresholdRegistry(address(0)), - IEigenDARelayRegistry(address(0)) + IEigenDARelayRegistry(address(0)), + paymentVault ); address[] memory confirmers = new address[](1); diff --git a/contracts/src/core/EigenDAServiceManager.sol b/contracts/src/core/EigenDAServiceManager.sol index f49c3206df..d589cc78f5 100644 --- a/contracts/src/core/EigenDAServiceManager.sol +++ b/contracts/src/core/EigenDAServiceManager.sol @@ -10,6 +10,7 @@ import {IRegistryCoordinator} from "eigenlayer-middleware/interfaces/IRegistryCo import {IStakeRegistry} from "eigenlayer-middleware/interfaces/IStakeRegistry.sol"; import {IEigenDAThresholdRegistry} from "../interfaces/IEigenDAThresholdRegistry.sol"; import {IEigenDARelayRegistry} from "../interfaces/IEigenDARelayRegistry.sol"; +import {IPaymentVault} from "../interfaces/IPaymentVault.sol"; import {EigenDAServiceManagerStorage} from "./EigenDAServiceManagerStorage.sol"; import {EigenDAHasher} from "../libraries/EigenDAHasher.sol"; import "../interfaces/IEigenDAStructs.sol"; @@ -40,11 +41,12 @@ contract EigenDAServiceManager is EigenDAServiceManagerStorage, ServiceManagerBa IRegistryCoordinator __registryCoordinator, IStakeRegistry __stakeRegistry, IEigenDAThresholdRegistry __eigenDAThresholdRegistry, - IEigenDARelayRegistry __eigenDARelayRegistry + IEigenDARelayRegistry __eigenDARelayRegistry, + IPaymentVault __paymentVault ) BLSSignatureChecker(__registryCoordinator) ServiceManagerBase(__avsDirectory, __rewardsCoordinator, __registryCoordinator, __stakeRegistry) - EigenDAServiceManagerStorage(__eigenDAThresholdRegistry, __eigenDARelayRegistry) + EigenDAServiceManagerStorage(__eigenDAThresholdRegistry, __eigenDARelayRegistry, __paymentVault) { _disableInitializers(); } diff --git a/contracts/src/core/EigenDAServiceManagerStorage.sol b/contracts/src/core/EigenDAServiceManagerStorage.sol index 843a1107c7..3a04661d99 100644 --- a/contracts/src/core/EigenDAServiceManagerStorage.sol +++ b/contracts/src/core/EigenDAServiceManagerStorage.sol @@ -4,6 +4,8 @@ pragma solidity ^0.8.9; import {IEigenDAServiceManager} from "../interfaces/IEigenDAServiceManager.sol"; import {IEigenDAThresholdRegistry} from "../interfaces/IEigenDAThresholdRegistry.sol"; import {IEigenDARelayRegistry} from "../interfaces/IEigenDARelayRegistry.sol"; +import {IPaymentVault} from "../interfaces/IPaymentVault.sol"; + /** * @title Storage variables for the `EigenDAServiceManager` contract. * @author Layr Labs, Inc. @@ -38,13 +40,16 @@ abstract contract EigenDAServiceManagerStorage is IEigenDAServiceManager { IEigenDAThresholdRegistry public immutable eigenDAThresholdRegistry; IEigenDARelayRegistry public immutable eigenDARelayRegistry; - + IPaymentVault public immutable paymentVault; + constructor( IEigenDAThresholdRegistry _eigenDAThresholdRegistry, - IEigenDARelayRegistry _eigenDARelayRegistry + IEigenDARelayRegistry _eigenDARelayRegistry, + IPaymentVault _paymentVault ) { eigenDAThresholdRegistry = _eigenDAThresholdRegistry; eigenDARelayRegistry = _eigenDARelayRegistry; + paymentVault = _paymentVault; } /// @notice The current batchId diff --git a/contracts/src/interfaces/IPaymentVault.sol b/contracts/src/interfaces/IPaymentVault.sol index 102e3541c5..c118d407df 100644 --- a/contracts/src/interfaces/IPaymentVault.sol +++ b/contracts/src/interfaces/IPaymentVault.sol @@ -7,8 +7,8 @@ interface IPaymentVault { uint64 symbolsPerSecond; // Number of symbols reserved per second uint64 startTimestamp; // timestamp of epoch where reservation begins uint64 endTimestamp; // timestamp of epoch where reservation ends - bytes quorumNumbers; // quorum numbers in an ordered bytes array - bytes quorumSplits; // quorum splits in a bytes array that correspond to the quorum numbers + bytes quorumNumbers; // quorum numbers in an ordered bytes array + bytes quorumSplits; // quorum splits in a bytes array that correspond to the quorum numbers } /// @notice Emitted when a reservation is created or updated diff --git a/contracts/test/unit/EigenDABlobUtils.t.sol b/contracts/test/unit/EigenDABlobUtils.t.sol index 292a2ac347..644dcad7f5 100644 --- a/contracts/test/unit/EigenDABlobUtils.t.sol +++ b/contracts/test/unit/EigenDABlobUtils.t.sol @@ -13,6 +13,7 @@ import {EigenDAServiceManager} from "../../src/core/EigenDAServiceManager.sol"; import {IEigenDAServiceManager} from "../../src/interfaces/IEigenDAServiceManager.sol"; import {IEigenDAThresholdRegistry} from "../../src/interfaces/IEigenDAThresholdRegistry.sol"; import {IEigenDARelayRegistry} from "../../src/interfaces/IEigenDARelayRegistry.sol"; +import {IPaymentVault} from "../../src/interfaces/IPaymentVault.sol"; import "../../src/interfaces/IEigenDAStructs.sol"; import "forge-std/StdStorage.sol"; @@ -50,7 +51,8 @@ contract EigenDABlobUtilsUnit is BLSMockAVSDeployer { registryCoordinator, stakeRegistry, IEigenDAThresholdRegistry(address(0)), - IEigenDARelayRegistry(address(0)) + IEigenDARelayRegistry(address(0)), + IPaymentVault(address(0)) ); address[] memory confirmers = new address[](1); diff --git a/contracts/test/unit/EigenDAServiceManagerUnit.t.sol b/contracts/test/unit/EigenDAServiceManagerUnit.t.sol index cf94677511..8f468f7386 100644 --- a/contracts/test/unit/EigenDAServiceManagerUnit.t.sol +++ b/contracts/test/unit/EigenDAServiceManagerUnit.t.sol @@ -11,6 +11,7 @@ import {IEigenDAServiceManager} from "../../src/interfaces/IEigenDAServiceManage import "../../src/interfaces/IEigenDAStructs.sol"; import {IEigenDAThresholdRegistry} from "../../src/interfaces/IEigenDAThresholdRegistry.sol"; import {IEigenDARelayRegistry} from "../../src/interfaces/IEigenDARelayRegistry.sol"; +import {IPaymentVault} from "../../src/interfaces/IPaymentVault.sol"; contract EigenDAServiceManagerUnit is BLSMockAVSDeployer { using BN254 for BN254.G1Point; @@ -40,7 +41,8 @@ contract EigenDAServiceManagerUnit is BLSMockAVSDeployer { registryCoordinator, stakeRegistry, IEigenDAThresholdRegistry(address(0)), - IEigenDARelayRegistry(address(0)) + IEigenDARelayRegistry(address(0)), + IPaymentVault(address(0)) ); address[] memory confirmers = new address[](1); diff --git a/contracts/test/unit/MockRollup.t.sol b/contracts/test/unit/MockRollup.t.sol index 0150c56a88..dbb103e9a6 100644 --- a/contracts/test/unit/MockRollup.t.sol +++ b/contracts/test/unit/MockRollup.t.sol @@ -14,6 +14,7 @@ import {BN254} from "eigenlayer-middleware/libraries/BN254.sol"; import "../../src/interfaces/IEigenDAStructs.sol"; import {IEigenDAThresholdRegistry} from "../../src/interfaces/IEigenDAThresholdRegistry.sol"; import {IEigenDARelayRegistry} from "../../src/interfaces/IEigenDARelayRegistry.sol"; +import {IPaymentVault} from "../../src/interfaces/IPaymentVault.sol"; import "forge-std/StdStorage.sol"; contract MockRollupTest is BLSMockAVSDeployer { @@ -60,7 +61,8 @@ contract MockRollupTest is BLSMockAVSDeployer { registryCoordinator, stakeRegistry, IEigenDAThresholdRegistry(address(0)), - IEigenDARelayRegistry(address(0)) + IEigenDARelayRegistry(address(0)), + IPaymentVault(address(0)) ); address[] memory confirmers = new address[](1); From ed00679a98cce3bebece1041b777930cdc8354d8 Mon Sep 17 00:00:00 2001 From: QUAQ Date: Wed, 11 Dec 2024 14:28:32 -0600 Subject: [PATCH 4/6] resolve conflicts --- contracts/test/unit/EigenDABlobUtils.t.sol | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/contracts/test/unit/EigenDABlobUtils.t.sol b/contracts/test/unit/EigenDABlobUtils.t.sol index 320cb889ba..5e5d326c69 100644 --- a/contracts/test/unit/EigenDABlobUtils.t.sol +++ b/contracts/test/unit/EigenDABlobUtils.t.sol @@ -16,6 +16,10 @@ import {IEigenDABatchMetadataStorage} from "../../src/interfaces/IEigenDABatchMe import {IEigenDASignatureVerifier} from "../../src/interfaces/IEigenDASignatureVerifier.sol"; import {IRegistryCoordinator} from "../../lib/eigenlayer-middleware/src/interfaces/IRegistryCoordinator.sol"; import {IEigenDARelayRegistry} from "../../src/interfaces/IEigenDARelayRegistry.sol"; +import {EigenDARelayRegistry} from "../../src/core/EigenDARelayRegistry.sol"; +import {IPaymentVault} from "../../src/interfaces/IPaymentVault.sol"; +import {PaymentVault} from "../../src/payments/PaymentVault.sol"; + import "../../src/interfaces/IEigenDAStructs.sol"; import "forge-std/StdStorage.sol"; @@ -76,8 +80,9 @@ contract EigenDABlobUtilsUnit is BLSMockAVSDeployer { rewardsCoordinator, registryCoordinator, stakeRegistry, - IEigenDAThresholdRegistry(address(0)), - IEigenDARelayRegistry(address(0)) + eigenDAThresholdRegistry, + eigenDARelayRegistry, + IPaymentVault(address(0)) ); eigenDAThresholdRegistryImplementation = new EigenDAThresholdRegistry(); From 66c9caaa688815ee10c0e77482ccab09d0df5ca7 Mon Sep 17 00:00:00 2001 From: QUAQ Date: Thu, 12 Dec 2024 10:25:12 -0600 Subject: [PATCH 5/6] storage update --- contracts/script/EigenDADeployer.s.sol | 18 ++-- contracts/src/interfaces/IPaymentVault.sol | 34 ++++--- contracts/src/payments/PaymentVault.sol | 65 +++++++------ .../src/payments/PaymentVaultStorage.sol | 26 ++--- contracts/test/unit/PaymentVaultUnit.t.sol | 96 ++++++++++--------- 5 files changed, 126 insertions(+), 113 deletions(-) diff --git a/contracts/script/EigenDADeployer.s.sol b/contracts/script/EigenDADeployer.s.sol index c4ec2e3267..1b24709282 100644 --- a/contracts/script/EigenDADeployer.s.sol +++ b/contracts/script/EigenDADeployer.s.sol @@ -63,12 +63,12 @@ contract EigenDADeployer is DeployOpenEigenLayer { ISocketRegistry public socketRegistryImplementation; IPaymentVault public paymentVaultImplementation; - uint128 _minNumSymbols = 4096; - uint128 _globalSymbolsPerBin = 131072; - uint128 _pricePerSymbol = 0.4470 gwei; - uint128 _reservationBinInterval = 300; - uint128 _priceUpdateCooldown = 1; - uint128 _globalRateBinInterval = 30; + uint64 _minNumSymbols = 4096; + uint64 _pricePerSymbol = 0.4470 gwei; + uint64 _priceUpdateCooldown = 1; + uint64 _globalSymbolsPerPeriod = 131072; + uint64 _reservationPeriodInterval = 300; + uint64 _globalRatePeriodInterval = 30; struct AddressConfig { address eigenLayerCommunityMultisig; @@ -159,11 +159,11 @@ contract EigenDADeployer is DeployOpenEigenLayer { PaymentVault.initialize.selector, addressConfig.eigenDACommunityMultisig, _minNumSymbols, - _globalSymbolsPerBin, _pricePerSymbol, - _reservationBinInterval, _priceUpdateCooldown, - _globalRateBinInterval + _globalSymbolsPerPeriod, + _reservationPeriodInterval, + _globalRatePeriodInterval ) ); } diff --git a/contracts/src/interfaces/IPaymentVault.sol b/contracts/src/interfaces/IPaymentVault.sol index c118d407df..c40363eea7 100644 --- a/contracts/src/interfaces/IPaymentVault.sol +++ b/contracts/src/interfaces/IPaymentVault.sol @@ -11,24 +11,28 @@ interface IPaymentVault { bytes quorumSplits; // quorum splits in a bytes array that correspond to the quorum numbers } + struct OnDemandPayment { + uint80 totalDeposit; + } + /// @notice Emitted when a reservation is created or updated event ReservationUpdated(address indexed account, Reservation reservation); /// @notice Emitted when an on-demand payment is created or updated - event OnDemandPaymentUpdated(address indexed account, uint128 onDemandPayment, uint128 totalDeposit); - /// @notice Emitted when globalSymbolsPerBin is updated - event GlobalSymbolsPerBinUpdated(uint128 previousValue, uint128 newValue); - /// @notice Emitted when reservationBinInterval is updated - event ReservationBinIntervalUpdated(uint128 previousValue, uint128 newValue); - /// @notice Emitted when globalRateBinInterval is updated - event GlobalRateBinIntervalUpdated(uint128 previousValue, uint128 newValue); + event OnDemandPaymentUpdated(address indexed account, uint80 onDemandPayment, uint80 totalDeposit); + /// @notice Emitted when globalSymbolsPerPeriod is updated + event GlobalSymbolsPerPeriodUpdated(uint64 previousValue, uint64 newValue); + /// @notice Emitted when reservationPeriodInterval is updated + event ReservationPeriodIntervalUpdated(uint64 previousValue, uint64 newValue); + /// @notice Emitted when globalRatePeriodInterval is updated + event GlobalRatePeriodIntervalUpdated(uint64 previousValue, uint64 newValue); /// @notice Emitted when priceParams are updated event PriceParamsUpdated( - uint128 previousMinNumSymbols, - uint128 newMinNumSymbols, - uint128 previousPricePerSymbol, - uint128 newPricePerSymbol, - uint128 previousPriceUpdateCooldown, - uint128 newPriceUpdateCooldown + uint64 previousMinNumSymbols, + uint64 newMinNumSymbols, + uint64 previousPricePerSymbol, + uint64 newPricePerSymbol, + uint64 previousPriceUpdateCooldown, + uint64 newPriceUpdateCooldown ); /** @@ -54,8 +58,8 @@ interface IPaymentVault { function getReservations(address[] memory _accounts) external view returns (Reservation[] memory _reservations); /// @notice Fetches the current total on demand balance of an account - function getOnDemandAmount(address _account) external view returns (uint128); + function getOnDemandTotalDeposit(address _account) external view returns (uint80); /// @notice Fetches the current total on demand balances for a set of accounts - function getOnDemandAmounts(address[] memory _accounts) external view returns (uint128[] memory _payments); + function getOnDemandTotalDeposits(address[] memory _accounts) external view returns (uint80[] memory _payments); } diff --git a/contracts/src/payments/PaymentVault.sol b/contracts/src/payments/PaymentVault.sol index 9370daf2f3..7db344b6a4 100644 --- a/contracts/src/payments/PaymentVault.sol +++ b/contracts/src/payments/PaymentVault.sol @@ -9,7 +9,7 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; * @title Entrypoint for making reservations and on demand payments for EigenDA. * @author Layr Labs, Inc. **/ -contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { +contract PaymentVault is OwnableUpgradeable, PaymentVaultStorage { constructor() { _disableInitializers(); @@ -25,23 +25,23 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { function initialize( address _initialOwner, - uint128 _minNumSymbols, - uint128 _globalSymbolsPerBin, - uint128 _pricePerSymbol, - uint128 _reservationBinInterval, - uint128 _priceUpdateCooldown, - uint128 _globalRateBinInterval + uint64 _minNumSymbols, + uint64 _pricePerSymbol, + uint64 _priceUpdateCooldown, + uint64 _globalSymbolsPerPeriod, + uint64 _reservationPeriodInterval, + uint64 _globalRatePeriodInterval ) public initializer { _transferOwnership(_initialOwner); minNumSymbols = _minNumSymbols; - globalSymbolsPerBin = _globalSymbolsPerBin; pricePerSymbol = _pricePerSymbol; - reservationBinInterval = _reservationBinInterval; priceUpdateCooldown = _priceUpdateCooldown; - globalRateBinInterval = _globalRateBinInterval; + lastPriceUpdateTime = uint64(block.timestamp); - lastPriceUpdateTime = uint128(block.timestamp); + globalSymbolsPerPeriod = _globalSymbolsPerPeriod; + reservationPeriodInterval = _reservationPeriodInterval; + globalRatePeriodInterval = _globalRatePeriodInterval; } /** @@ -68,35 +68,37 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { } function setPriceParams( - uint128 _minNumSymbols, - uint128 _pricePerSymbol, - uint128 _priceUpdateCooldown + uint64 _minNumSymbols, + uint64 _pricePerSymbol, + uint64 _priceUpdateCooldown ) external onlyOwner { require(block.timestamp >= lastPriceUpdateTime + priceUpdateCooldown, "price update cooldown not surpassed"); + emit PriceParamsUpdated( minNumSymbols, _minNumSymbols, pricePerSymbol, _pricePerSymbol, priceUpdateCooldown, _priceUpdateCooldown ); + pricePerSymbol = _pricePerSymbol; minNumSymbols = _minNumSymbols; priceUpdateCooldown = _priceUpdateCooldown; - lastPriceUpdateTime = uint128(block.timestamp); + lastPriceUpdateTime = uint64(block.timestamp); } - function setGlobalSymbolsPerBin(uint128 _globalSymbolsPerBin) external onlyOwner { - emit GlobalSymbolsPerBinUpdated(globalSymbolsPerBin, _globalSymbolsPerBin); - globalSymbolsPerBin = _globalSymbolsPerBin; + function setGlobalSymbolsPerPeriod(uint64 _globalSymbolsPerPeriod) external onlyOwner { + emit GlobalSymbolsPerPeriodUpdated(globalSymbolsPerPeriod, _globalSymbolsPerPeriod); + globalSymbolsPerPeriod = _globalSymbolsPerPeriod; } - function setReservationBinInterval(uint128 _reservationBinInterval) external onlyOwner { - emit ReservationBinIntervalUpdated(reservationBinInterval, _reservationBinInterval); - reservationBinInterval = _reservationBinInterval; + function setReservationPeriodInterval(uint64 _reservationPeriodInterval) external onlyOwner { + emit ReservationPeriodIntervalUpdated(reservationPeriodInterval, _reservationPeriodInterval); + reservationPeriodInterval = _reservationPeriodInterval; } - function setGlobalRateBinInterval(uint128 _globalRateBinInterval) external onlyOwner { - emit GlobalRateBinIntervalUpdated(globalRateBinInterval, _globalRateBinInterval); - globalRateBinInterval = _globalRateBinInterval; + function setGlobalRatePeriodInterval(uint64 _globalRatePeriodInterval) external onlyOwner { + emit GlobalRatePeriodIntervalUpdated(globalRatePeriodInterval, _globalRatePeriodInterval); + globalRatePeriodInterval = _globalRatePeriodInterval; } function withdraw(uint256 _amount) external onlyOwner { @@ -116,8 +118,9 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { } function _deposit(address _account, uint256 _amount) internal { - onDemandPayments[_account] += uint128(_amount); - emit OnDemandPaymentUpdated(_account, uint128(_amount), uint128(onDemandPayments[_account])); + require(_amount <= type(uint80).max, "amount must be less than or equal to 80 bits"); + onDemandPayments[_account].totalDeposit += uint80(_amount); + emit OnDemandPaymentUpdated(_account, uint80(_amount), onDemandPayments[_account].totalDeposit); } /// @notice Fetches the current reservation for an account @@ -134,15 +137,15 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { } /// @notice Fetches the current total on demand balance of an account - function getOnDemandAmount(address _account) external view returns (uint128) { - return onDemandPayments[_account]; + function getOnDemandTotalDeposit(address _account) external view returns (uint80) { + return onDemandPayments[_account].totalDeposit; } /// @notice Fetches the current total on demand balances for a set of accounts - function getOnDemandAmounts(address[] memory _accounts) external view returns (uint128[] memory _payments) { - _payments = new uint128[](_accounts.length); + function getOnDemandTotalDeposits(address[] memory _accounts) external view returns (uint80[] memory _payments) { + _payments = new uint80[](_accounts.length); for(uint256 i; i < _accounts.length; ++i){ - _payments[i] = onDemandPayments[_accounts[i]]; + _payments[i] = onDemandPayments[_accounts[i]].totalDeposit; } } } \ No newline at end of file diff --git a/contracts/src/payments/PaymentVaultStorage.sol b/contracts/src/payments/PaymentVaultStorage.sol index afe2ebf412..c8aae718df 100644 --- a/contracts/src/payments/PaymentVaultStorage.sol +++ b/contracts/src/payments/PaymentVaultStorage.sol @@ -6,25 +6,25 @@ import {IPaymentVault} from "../interfaces/IPaymentVault.sol"; abstract contract PaymentVaultStorage is IPaymentVault { /// @notice minimum chargeable size for on-demand payments - uint128 public minNumSymbols; + uint64 public minNumSymbols; /// @notice price per symbol in wei - uint128 public pricePerSymbol; + uint64 public pricePerSymbol; /// @notice cooldown period before the price can be updated again - uint128 public priceUpdateCooldown; - /// @notice maximum number of symbols to disperse per second network-wide for on-demand payments (applied to only ETH and EIGEN) - uint128 public globalSymbolsPerBin; - /// @notice reservation bin duration - uint128 public reservationBinInterval; - /// @notice global rate bin size - uint128 public globalRateBinInterval; - + uint64 public priceUpdateCooldown; /// @notice timestamp of the last price update - uint128 public lastPriceUpdateTime; + uint64 public lastPriceUpdateTime; + + /// @notice maximum number of symbols to disperse per second network-wide for on-demand payments (applied to only ETH and EIGEN) + uint64 public globalSymbolsPerPeriod; + /// @notice reservation period interval + uint64 public reservationPeriodInterval; + /// @notice global rate period interval + uint64 public globalRatePeriodInterval; /// @notice mapping from user address to current reservation mapping(address => Reservation) public reservations; /// @notice mapping from user address to current on-demand payment - mapping(address => uint128) public onDemandPayments; + mapping(address => OnDemandPayment) public onDemandPayments; - uint256[44] private __GAP; + uint256[46] private __GAP; } \ No newline at end of file diff --git a/contracts/test/unit/PaymentVaultUnit.t.sol b/contracts/test/unit/PaymentVaultUnit.t.sol index 3b044ad707..740c2e7a55 100644 --- a/contracts/test/unit/PaymentVaultUnit.t.sol +++ b/contracts/test/unit/PaymentVaultUnit.t.sol @@ -12,17 +12,17 @@ contract PaymentVaultUnit is Test { using stdStorage for StdStorage; event ReservationUpdated(address indexed account, IPaymentVault.Reservation reservation); - event OnDemandPaymentUpdated(address indexed account, uint128 onDemandPayment, uint128 totalDeposit); - event GlobalSymbolsPerBinUpdated(uint128 previousValue, uint128 newValue); - event ReservationBinIntervalUpdated(uint128 previousValue, uint128 newValue); - event GlobalRateBinIntervalUpdated(uint128 previousValue, uint128 newValue); + event OnDemandPaymentUpdated(address indexed account, uint80 onDemandPayment, uint80 totalDeposit); + event GlobalSymbolsPerPeriodUpdated(uint64 previousValue, uint64 newValue); + event ReservationPeriodIntervalUpdated(uint64 previousValue, uint64 newValue); + event GlobalRatePeriodIntervalUpdated(uint64 previousValue, uint64 newValue); event PriceParamsUpdated( - uint128 previousMinNumSymbols, - uint128 newMinNumSymbols, - uint128 previousPricePerSymbol, - uint128 newPricePerSymbol, - uint128 previousPriceUpdateCooldown, - uint128 newPriceUpdateCooldown + uint64 previousMinNumSymbols, + uint64 newMinNumSymbols, + uint64 previousPricePerSymbol, + uint64 newPricePerSymbol, + uint64 previousPriceUpdateCooldown, + uint64 newPriceUpdateCooldown ); PaymentVault paymentVault; @@ -34,13 +34,12 @@ contract PaymentVaultUnit is Test { address user = address(uint160(uint256(keccak256(abi.encodePacked("user"))))); address user2 = address(uint160(uint256(keccak256(abi.encodePacked("user2"))))); - uint128 minNumSymbols = 1; - uint128 globalSymbolsPerBin = 2; - uint128 pricePerSymbol = 3; - uint128 reservationBinInterval = 4; - uint128 globalRateBinInterval = 5; - - uint128 priceUpdateCooldown = 6 days; + uint64 minNumSymbols = 1; + uint64 globalSymbolsPerPeriod = 2; + uint64 pricePerSymbol = 3; + uint64 reservationPeriodInterval = 4; + uint64 globalRatePeriodInterval = 5; + uint64 priceUpdateCooldown = 6 days; bytes quorumNumbers = hex"0001"; bytes quorumSplits = hex"3232"; @@ -58,11 +57,11 @@ contract PaymentVaultUnit is Test { PaymentVault.initialize.selector, initialOwner, minNumSymbols, - globalSymbolsPerBin, pricePerSymbol, - reservationBinInterval, priceUpdateCooldown, - globalRateBinInterval + globalSymbolsPerPeriod, + reservationPeriodInterval, + globalRatePeriodInterval ) ) ) @@ -75,11 +74,11 @@ contract PaymentVaultUnit is Test { function test_initialize() public { require(paymentVault.owner() == initialOwner, "Owner is not set"); assertEq(paymentVault.minNumSymbols(), minNumSymbols); - assertEq(paymentVault.globalSymbolsPerBin(), globalSymbolsPerBin); + assertEq(paymentVault.globalSymbolsPerPeriod(), globalSymbolsPerPeriod); assertEq(paymentVault.pricePerSymbol(), pricePerSymbol); - assertEq(paymentVault.reservationBinInterval(), reservationBinInterval); + assertEq(paymentVault.reservationPeriodInterval(), reservationPeriodInterval); assertEq(paymentVault.priceUpdateCooldown(), priceUpdateCooldown); - assertEq(paymentVault.globalRateBinInterval(), globalRateBinInterval); + assertEq(paymentVault.globalRatePeriodInterval(), globalRatePeriodInterval); vm.expectRevert("Initializable: contract is already initialized"); paymentVault.initialize(address(0), 0, 0, 0, 0, 0, 0); @@ -167,13 +166,13 @@ contract PaymentVaultUnit is Test { emit OnDemandPaymentUpdated(user, 100 ether, 100 ether); vm.prank(user); paymentVault.depositOnDemand{value: 100 ether}(user); - assertEq(paymentVault.onDemandPayments(user), 100 ether); + assertEq(paymentVault.getOnDemandTotalDeposit(user), 100 ether); vm.expectEmit(address(paymentVault)); emit OnDemandPaymentUpdated(user, 100 ether, 200 ether); vm.prank(user); paymentVault.depositOnDemand{value: 100 ether}(user); - assertEq(paymentVault.onDemandPayments(user), 200 ether); + assertEq(paymentVault.getOnDemandTotalDeposit(user), 200 ether); } function test_depositOnDemand_forOtherUser() public { @@ -184,8 +183,8 @@ contract PaymentVaultUnit is Test { emit OnDemandPaymentUpdated(user2, 100 ether, 100 ether); vm.prank(user); paymentVault.depositOnDemand{value: 100 ether}(user2); - assertEq(paymentVault.onDemandPayments(user2), 100 ether); - assertEq(paymentVault.onDemandPayments(user), 0); + assertEq(paymentVault.getOnDemandTotalDeposit(user2), 100 ether); + assertEq(paymentVault.getOnDemandTotalDeposit(user), 0); } function test_depositOnDemand_fallback() public { @@ -195,7 +194,7 @@ contract PaymentVaultUnit is Test { emit OnDemandPaymentUpdated(user, 100 ether, 100 ether); vm.prank(user); payable(paymentVault).call{value: 100 ether}(hex"69"); - assertEq(paymentVault.onDemandPayments(user), 100 ether); + assertEq(paymentVault.getOnDemandTotalDeposit(user), 100 ether); } function test_depositOnDemand_recieve() public { @@ -205,7 +204,14 @@ contract PaymentVaultUnit is Test { emit OnDemandPaymentUpdated(user, 100 ether, 100 ether); vm.prank(user); payable(paymentVault).call{value: 100 ether}(""); - assertEq(paymentVault.onDemandPayments(user), 100 ether); + assertEq(paymentVault.getOnDemandTotalDeposit(user), 100 ether); + } + + function test_depositOnDemand_revertUint80Overflow() public { + vm.deal(user, uint256(type(uint80).max) + 1); + vm.expectRevert("amount must be less than or equal to 80 bits"); + vm.prank(user); + paymentVault.depositOnDemand{value: uint256(type(uint80).max) + 1}(user); } function test_setPriceParams() public { @@ -230,28 +236,28 @@ contract PaymentVaultUnit is Test { paymentVault.setPriceParams(minNumSymbols + 1, pricePerSymbol + 1, priceUpdateCooldown + 1); } - function test_setGlobalRateBinInterval() public { + function test_setGlobalRatePeriodInterval() public { vm.expectEmit(address(paymentVault)); - emit GlobalRateBinIntervalUpdated(globalRateBinInterval, globalRateBinInterval + 1); + emit GlobalRatePeriodIntervalUpdated(globalRatePeriodInterval, globalRatePeriodInterval + 1); vm.prank(initialOwner); - paymentVault.setGlobalRateBinInterval(globalRateBinInterval + 1); - assertEq(paymentVault.globalRateBinInterval(), globalRateBinInterval + 1); + paymentVault.setGlobalRatePeriodInterval(globalRatePeriodInterval + 1); + assertEq(paymentVault.globalRatePeriodInterval(), globalRatePeriodInterval + 1); } - function test_setGlobalSymbolsPerBin() public { + function test_setGlobalSymbolsPerPeriod() public { vm.expectEmit(address(paymentVault)); - emit GlobalSymbolsPerBinUpdated(globalSymbolsPerBin, globalSymbolsPerBin + 1); + emit GlobalSymbolsPerPeriodUpdated(globalSymbolsPerPeriod, globalSymbolsPerPeriod + 1); vm.prank(initialOwner); - paymentVault.setGlobalSymbolsPerBin(globalSymbolsPerBin + 1); - assertEq(paymentVault.globalSymbolsPerBin(), globalSymbolsPerBin + 1); + paymentVault.setGlobalSymbolsPerPeriod(globalSymbolsPerPeriod + 1); + assertEq(paymentVault.globalSymbolsPerPeriod(), globalSymbolsPerPeriod + 1); } - function test_setReservationBinInterval() public { + function test_setReservationPeriodInterval() public { vm.expectEmit(address(paymentVault)); - emit ReservationBinIntervalUpdated(reservationBinInterval, reservationBinInterval + 1); + emit ReservationPeriodIntervalUpdated(reservationPeriodInterval, reservationPeriodInterval + 1); vm.prank(initialOwner); - paymentVault.setReservationBinInterval(reservationBinInterval + 1); - assertEq(paymentVault.reservationBinInterval(), reservationBinInterval + 1); + paymentVault.setReservationPeriodInterval(reservationPeriodInterval + 1); + assertEq(paymentVault.reservationPeriodInterval(), reservationPeriodInterval + 1); } function test_withdraw() public { @@ -286,11 +292,11 @@ contract PaymentVaultUnit is Test { vm.expectRevert("Ownable: caller is not the owner"); paymentVault.setPriceParams(minNumSymbols + 1, pricePerSymbol + 1, priceUpdateCooldown + 1); vm.expectRevert("Ownable: caller is not the owner"); - paymentVault.setGlobalRateBinInterval(globalRateBinInterval + 1); + paymentVault.setGlobalRatePeriodInterval(globalRatePeriodInterval + 1); vm.expectRevert("Ownable: caller is not the owner"); - paymentVault.setGlobalSymbolsPerBin(globalSymbolsPerBin + 1); + paymentVault.setGlobalSymbolsPerPeriod(globalSymbolsPerPeriod + 1); vm.expectRevert("Ownable: caller is not the owner"); - paymentVault.setReservationBinInterval(reservationBinInterval + 1); + paymentVault.setReservationPeriodInterval(reservationPeriodInterval + 1); } function test_getReservations() public { @@ -335,7 +341,7 @@ contract PaymentVaultUnit is Test { accounts[0] = user; accounts[1] = user2; - uint128[] memory payments = paymentVault.getOnDemandAmounts(accounts); + uint80[] memory payments = paymentVault.getOnDemandTotalDeposits(accounts); assertEq(payments[0], 100 ether); assertEq(payments[1], 200 ether); } From e59457aeab1a512446233f1bf7c3268801309792 Mon Sep 17 00:00:00 2001 From: QUAQ Date: Thu, 12 Dec 2024 10:27:40 -0600 Subject: [PATCH 6/6] nits --- contracts/src/interfaces/IPaymentVault.sol | 4 ++-- contracts/src/payments/PaymentVault.sol | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/src/interfaces/IPaymentVault.sol b/contracts/src/interfaces/IPaymentVault.sol index c40363eea7..0fcfc32a93 100644 --- a/contracts/src/interfaces/IPaymentVault.sol +++ b/contracts/src/interfaces/IPaymentVault.sol @@ -7,8 +7,8 @@ interface IPaymentVault { uint64 symbolsPerSecond; // Number of symbols reserved per second uint64 startTimestamp; // timestamp of epoch where reservation begins uint64 endTimestamp; // timestamp of epoch where reservation ends - bytes quorumNumbers; // quorum numbers in an ordered bytes array - bytes quorumSplits; // quorum splits in a bytes array that correspond to the quorum numbers + bytes quorumNumbers; // quorum numbers in an ordered bytes array + bytes quorumSplits; // quorum splits in a bytes array that correspond to the quorum numbers } struct OnDemandPayment { diff --git a/contracts/src/payments/PaymentVault.sol b/contracts/src/payments/PaymentVault.sol index 7db344b6a4..9dae3cd17c 100644 --- a/contracts/src/payments/PaymentVault.sol +++ b/contracts/src/payments/PaymentVault.sol @@ -53,7 +53,7 @@ contract PaymentVault is OwnableUpgradeable, PaymentVaultStorage { address _account, Reservation memory _reservation ) external onlyOwner { - _checkQuorumSplit(_reservation.quorumNumbers, _reservation.quorumSplits); + _checkQuorumSplit(_reservation.quorumNumbers, _reservation.quorumSplits); require(_reservation.endTimestamp > _reservation.startTimestamp, "end timestamp must be greater than start timestamp"); reservations[_account] = _reservation; emit ReservationUpdated(_account, _reservation); @@ -64,7 +64,7 @@ contract PaymentVault is OwnableUpgradeable, PaymentVaultStorage { * @param _account is the address to deposit the funds for */ function depositOnDemand(address _account) external payable { - _deposit(_account, msg.value); + _deposit(_account, msg.value); } function setPriceParams(