diff --git a/contracts/script/EigenDADeployer.s.sol b/contracts/script/EigenDADeployer.s.sol index 9c63cf4c31..1b24709282 100644 --- a/contracts/script/EigenDADeployer.s.sol +++ b/contracts/script/EigenDADeployer.s.sol @@ -22,9 +22,10 @@ import {IEigenDAThresholdRegistry} from "../src/interfaces/IEigenDAThresholdRegi import {IEigenDABatchMetadataStorage} from "../src/interfaces/IEigenDABatchMetadataStorage.sol"; import {IEigenDASignatureVerifier} from "../src/interfaces/IEigenDASignatureVerifier.sol"; import {IEigenDARelayRegistry} from "../src/interfaces/IEigenDARelayRegistry.sol"; +import {IPaymentVault} from "../src/interfaces/IPaymentVault.sol"; +import {PaymentVault} from "../src/payments/PaymentVault.sol"; import {EigenDARelayRegistry} from "../src/core/EigenDARelayRegistry.sol"; import {ISocketRegistry, SocketRegistry} from "eigenlayer-middleware/SocketRegistry.sol"; - import {DeployOpenEigenLayer, ProxyAdmin, ERC20PresetFixedSupply, TransparentUpgradeableProxy, IPauserRegistry} from "./DeployOpenEigenLayer.s.sol"; import "forge-std/Test.sol"; import "forge-std/Script.sol"; @@ -49,6 +50,7 @@ contract EigenDADeployer is DeployOpenEigenLayer { IStakeRegistry public stakeRegistry; ISocketRegistry public socketRegistry; OperatorStateRetriever public operatorStateRetriever; + IPaymentVault public paymentVault; EigenDARelayRegistry public eigenDARelayRegistry; BLSApkRegistry public apkRegistryImplementation; @@ -59,6 +61,14 @@ contract EigenDADeployer is DeployOpenEigenLayer { EigenDAThresholdRegistry public eigenDAThresholdRegistryImplementation; EigenDARelayRegistry public eigenDARelayRegistryImplementation; ISocketRegistry public socketRegistryImplementation; + IPaymentVault public paymentVaultImplementation; + + uint64 _minNumSymbols = 4096; + uint64 _pricePerSymbol = 0.4470 gwei; + uint64 _priceUpdateCooldown = 1; + uint64 _globalSymbolsPerPeriod = 131072; + uint64 _reservationPeriodInterval = 300; + uint64 _globalRatePeriodInterval = 30; struct AddressConfig { address eigenLayerCommunityMultisig; @@ -135,6 +145,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, + _pricePerSymbol, + _priceUpdateCooldown, + _globalSymbolsPerPeriod, + _reservationPeriodInterval, + _globalRatePeriodInterval + ) + ); + } + indexRegistryImplementation = new IndexRegistry( registryCoordinator ); @@ -222,7 +255,8 @@ contract EigenDADeployer is DeployOpenEigenLayer { registryCoordinator, stakeRegistry, eigenDAThresholdRegistry, - eigenDARelayRegistry + eigenDARelayRegistry, + paymentVault ); address[] memory confirmers = new address[](1); diff --git a/contracts/src/core/EigenDAServiceManager.sol b/contracts/src/core/EigenDAServiceManager.sol index fcbfb2895a..029785eb7c 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 d98cdbbdb5..3a04661d99 100644 --- a/contracts/src/core/EigenDAServiceManagerStorage.sol +++ b/contracts/src/core/EigenDAServiceManagerStorage.sol @@ -4,6 +4,7 @@ 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. @@ -39,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 399fe3f6ce..0fcfc32a93 100644 --- a/contracts/src/interfaces/IPaymentVault.sol +++ b/contracts/src/interfaces/IPaymentVault.sol @@ -7,28 +7,32 @@ 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 { + 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, uint256 onDemandPayment, uint256 totalDeposit); - /// @notice Emitted when globalSymbolsPerBin is updated - event GlobalSymbolsPerBinUpdated(uint256 previousValue, uint256 newValue); - /// @notice Emitted when reservationBinInterval is updated - event ReservationBinIntervalUpdated(uint256 previousValue, uint256 newValue); - /// @notice Emitted when globalRateBinInterval is updated - event GlobalRateBinIntervalUpdated(uint256 previousValue, uint256 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( - uint256 previousMinNumSymbols, - uint256 newMinNumSymbols, - uint256 previousPricePerSymbol, - uint256 newPricePerSymbol, - uint256 previousPriceUpdateCooldown, - uint256 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 (uint256); + 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 (uint256[] memory _payments); -} \ No newline at end of file + 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 23bd0205b6..9dae3cd17c 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, - uint256 _minNumSymbols, - uint256 _globalSymbolsPerBin, - uint256 _pricePerSymbol, - uint256 _reservationBinInterval, - uint256 _priceUpdateCooldown, - uint256 _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 = block.timestamp; + globalSymbolsPerPeriod = _globalSymbolsPerPeriod; + reservationPeriodInterval = _reservationPeriodInterval; + globalRatePeriodInterval = _globalRatePeriodInterval; } /** @@ -53,7 +53,7 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { 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,39 +64,41 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { * @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( - uint256 _minNumSymbols, - uint256 _pricePerSymbol, - uint256 _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 = block.timestamp; + lastPriceUpdateTime = uint64(block.timestamp); } - function setGlobalSymbolsPerBin(uint256 _globalSymbolsPerBin) external onlyOwner { - emit GlobalSymbolsPerBinUpdated(globalSymbolsPerBin, _globalSymbolsPerBin); - globalSymbolsPerBin = _globalSymbolsPerBin; + function setGlobalSymbolsPerPeriod(uint64 _globalSymbolsPerPeriod) external onlyOwner { + emit GlobalSymbolsPerPeriodUpdated(globalSymbolsPerPeriod, _globalSymbolsPerPeriod); + globalSymbolsPerPeriod = _globalSymbolsPerPeriod; } - function setReservationBinInterval(uint256 _reservationBinInterval) external onlyOwner { - emit ReservationBinIntervalUpdated(reservationBinInterval, _reservationBinInterval); - reservationBinInterval = _reservationBinInterval; + function setReservationPeriodInterval(uint64 _reservationPeriodInterval) external onlyOwner { + emit ReservationPeriodIntervalUpdated(reservationPeriodInterval, _reservationPeriodInterval); + reservationPeriodInterval = _reservationPeriodInterval; } - function setGlobalRateBinInterval(uint256 _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] += _amount; - emit OnDemandPaymentUpdated(_account, _amount, 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 (uint256) { - 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 (uint256[] memory _payments) { - _payments = new uint256[](_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 4c364c3c13..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 - uint256 public minNumSymbols; + uint64 public minNumSymbols; /// @notice price per symbol in wei - uint256 public pricePerSymbol; + uint64 public pricePerSymbol; /// @notice cooldown period before the price can be updated again - uint256 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; - /// @notice reservation bin duration - uint256 public reservationBinInterval; - /// @notice global rate bin size - uint256 public globalRateBinInterval; - + uint64 public priceUpdateCooldown; /// @notice timestamp of the last price update - uint256 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 => uint256) public onDemandPayments; + mapping(address => OnDemandPayment) public onDemandPayments; - uint256[42] private __GAP; + uint256[46] private __GAP; } \ No newline at end of file diff --git a/contracts/test/rollup/MockRollup.t.sol b/contracts/test/rollup/MockRollup.t.sol index bb676e1a1b..aa37291b2e 100644 --- a/contracts/test/rollup/MockRollup.t.sol +++ b/contracts/test/rollup/MockRollup.t.sol @@ -17,6 +17,7 @@ import {IEigenDABatchMetadataStorage} from "../../src/interfaces/IEigenDABatchMe import {IEigenDASignatureVerifier} from "../../src/interfaces/IEigenDASignatureVerifier.sol"; import {OperatorStateRetriever} from "../../lib/eigenlayer-middleware/src/OperatorStateRetriever.sol"; import {IEigenDARelayRegistry} from "../../src/interfaces/IEigenDARelayRegistry.sol"; +import {IPaymentVault} from "../../src/interfaces/IPaymentVault.sol"; import {EigenDARelayRegistry} from "../../src/core/EigenDARelayRegistry.sol"; import {IRegistryCoordinator} from "../../lib/eigenlayer-middleware/src/interfaces/IRegistryCoordinator.sol"; import "../../src/interfaces/IEigenDAStructs.sol"; @@ -94,7 +95,8 @@ contract MockRollupTest is BLSMockAVSDeployer { registryCoordinator, stakeRegistry, eigenDAThresholdRegistry, - eigenDARelayRegistry + eigenDARelayRegistry, + IPaymentVault(address(0)) ); eigenDAThresholdRegistryImplementation = new EigenDAThresholdRegistry(); diff --git a/contracts/test/unit/EigenDABlobUtils.t.sol b/contracts/test/unit/EigenDABlobUtils.t.sol index 3eca831bc4..5e5d326c69 100644 --- a/contracts/test/unit/EigenDABlobUtils.t.sol +++ b/contracts/test/unit/EigenDABlobUtils.t.sol @@ -17,6 +17,9 @@ import {IEigenDASignatureVerifier} from "../../src/interfaces/IEigenDASignatureV 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"; @@ -78,7 +81,8 @@ contract EigenDABlobUtilsUnit is BLSMockAVSDeployer { registryCoordinator, stakeRegistry, eigenDAThresholdRegistry, - eigenDARelayRegistry + eigenDARelayRegistry, + IPaymentVault(address(0)) ); eigenDAThresholdRegistryImplementation = new EigenDAThresholdRegistry(); diff --git a/contracts/test/unit/EigenDAServiceManagerUnit.t.sol b/contracts/test/unit/EigenDAServiceManagerUnit.t.sol index 669edf49f6..f550889bcb 100644 --- a/contracts/test/unit/EigenDAServiceManagerUnit.t.sol +++ b/contracts/test/unit/EigenDAServiceManagerUnit.t.sol @@ -14,6 +14,7 @@ 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 {IPaymentVault} from "../../src/interfaces/IPaymentVault.sol"; import {EigenDARelayRegistry} from "../../src/core/EigenDARelayRegistry.sol"; import "../../src/interfaces/IEigenDAStructs.sol"; @@ -75,7 +76,8 @@ contract EigenDAServiceManagerUnit is BLSMockAVSDeployer { registryCoordinator, stakeRegistry, eigenDAThresholdRegistry, - eigenDARelayRegistry + eigenDARelayRegistry, + IPaymentVault(address(0)) ); address[] memory confirmers = new address[](1); diff --git a/contracts/test/unit/PaymentVaultUnit.t.sol b/contracts/test/unit/PaymentVaultUnit.t.sol index 7d0f386358..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, uint256 onDemandPayment, uint256 totalDeposit); - event GlobalSymbolsPerBinUpdated(uint256 previousValue, uint256 newValue); - event ReservationBinIntervalUpdated(uint256 previousValue, uint256 newValue); - event GlobalRateBinIntervalUpdated(uint256 previousValue, uint256 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( - uint256 previousMinNumSymbols, - uint256 newMinNumSymbols, - uint256 previousPricePerSymbol, - uint256 newPricePerSymbol, - uint256 previousPriceUpdateCooldown, - uint256 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"))))); - uint256 minNumSymbols = 1; - uint256 globalSymbolsPerBin = 2; - uint256 pricePerSymbol = 3; - uint256 reservationBinInterval = 4; - uint256 globalRateBinInterval = 5; - - uint256 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; - uint256[] memory payments = paymentVault.getOnDemandAmounts(accounts); + uint80[] memory payments = paymentVault.getOnDemandTotalDeposits(accounts); assertEq(payments[0], 100 ether); assertEq(payments[1], 200 ether); }