diff --git a/contracts/src/interfaces/IPaymentVault.sol b/contracts/src/interfaces/IPaymentVault.sol index 84993306ba..bbdb25f396 100644 --- a/contracts/src/interfaces/IPaymentVault.sol +++ b/contracts/src/interfaces/IPaymentVault.sol @@ -15,12 +15,19 @@ interface IPaymentVault { 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 minChargeableSize is updated - event MinChargeableSizeUpdated(uint256 previousValue, uint256 newValue); /// @notice Emitted when globalSymbolsPerSecond is updated event GlobalSymbolsPerSecondUpdated(uint256 previousValue, uint256 newValue); - /// @notice Emitted when pricePerSymbol is updated - event PricePerSymbolUpdated(uint256 previousValue, uint256 newValue); + /// @notice Emitted when reservationBinInterval is updated + event ReservationBinIntervalUpdated(uint256 previousValue, uint256 newValue); + /// @notice Emitted when priceParams are updated + event PriceParamsUpdated( + uint256 previousMinChargeableSize, + uint256 newMinChargeableSize, + uint256 previousPricePerSymbol, + uint256 newPricePerSymbol, + uint256 previousPriceUpdateCooldown, + uint256 newPriceUpdateCooldown + ); /** * @notice This function is called by EigenDA governance to store reservations diff --git a/contracts/src/payments/PaymentVault.sol b/contracts/src/payments/PaymentVault.sol index 39fb865623..9841a38050 100644 --- a/contracts/src/payments/PaymentVault.sol +++ b/contracts/src/payments/PaymentVault.sol @@ -11,28 +11,35 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; **/ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { - constructor( - uint256 _reservationBinInterval, - uint256 _reservationBinStartTimestamp, - uint256 _priceUpdateCooldown - ) PaymentVaultStorage( - _reservationBinInterval, - _reservationBinStartTimestamp, - _priceUpdateCooldown - ){ + constructor() { _disableInitializers(); } + receive() external payable { + _deposit(msg.sender, msg.value); + } + + fallback() external payable { + _deposit(msg.sender, msg.value); + } + function initialize( address _initialOwner, uint256 _minChargeableSize, uint256 _globalSymbolsPerSecond, - uint256 _pricePerSymbol + uint256 _pricePerSymbol, + uint256 _reservationBinInterval, + uint256 _priceUpdateCooldown ) public initializer { transferOwnership(_initialOwner); + minChargeableSize = _minChargeableSize; globalSymbolsPerSecond = _globalSymbolsPerSecond; pricePerSymbol = _pricePerSymbol; + reservationBinInterval = _reservationBinInterval; + priceUpdateCooldown = _priceUpdateCooldown; + + lastPriceUpdateTime = block.timestamp; } /** @@ -54,15 +61,24 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { * @param _account is the address to deposit the funds for */ function depositOnDemand(address _account) external payable { - onDemandPayments[_account] += msg.value; - emit OnDemandPaymentUpdated(_account, msg.value, onDemandPayments[_account]); + _deposit(_account, msg.value); } - function setMinChargeableSize(uint256 _minChargeableSize) external onlyOwner { + function setPriceParams( + uint256 _minChargeableSize, + uint256 _pricePerSymbol, + uint256 _priceUpdateCooldown + ) external onlyOwner { require(block.timestamp >= lastPriceUpdateTime + priceUpdateCooldown, "price update cooldown not surpassed"); - emit MinChargeableSizeUpdated(minChargeableSize, _minChargeableSize); - lastPriceUpdateTime = block.timestamp; + emit PriceParamsUpdated( + minChargeableSize, _minChargeableSize, + pricePerSymbol, _pricePerSymbol, + priceUpdateCooldown, _priceUpdateCooldown + ); + pricePerSymbol = _pricePerSymbol; minChargeableSize = _minChargeableSize; + priceUpdateCooldown = _priceUpdateCooldown; + lastPriceUpdateTime = block.timestamp; } function setGlobalSymbolsPerSecond(uint256 _globalSymbolsPerSecond) external onlyOwner { @@ -70,9 +86,9 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { globalSymbolsPerSecond = _globalSymbolsPerSecond; } - function setPricePerSymbol(uint256 _pricePerSymbol) external onlyOwner { - emit PricePerSymbolUpdated(pricePerSymbol, _pricePerSymbol); - pricePerSymbol = _pricePerSymbol; + function setReservationBinInterval(uint256 _reservationBinInterval) external onlyOwner { + emit ReservationBinIntervalUpdated(reservationBinInterval, _reservationBinInterval); + reservationBinInterval = _reservationBinInterval; } function withdraw(uint256 _amount) external onlyOwner { @@ -91,6 +107,11 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable { require(total == 100, "sum of quorumSplits must be 100"); } + function _deposit(address _account, uint256 _amount) internal { + onDemandPayments[_account] += _amount; + emit OnDemandPaymentUpdated(_account, _amount, onDemandPayments[_account]); + } + /// @notice Fetches the current reservation for an account function getReservation(address _account) external view returns (Reservation memory) { return reservations[_account]; diff --git a/contracts/src/payments/PaymentVaultStorage.sol b/contracts/src/payments/PaymentVaultStorage.sol index 977b852092..e4f686c2ce 100644 --- a/contracts/src/payments/PaymentVaultStorage.sol +++ b/contracts/src/payments/PaymentVaultStorage.sol @@ -4,37 +4,25 @@ pragma solidity ^0.8.9; import {IPaymentVault} from "../interfaces/IPaymentVault.sol"; abstract contract PaymentVaultStorage is IPaymentVault { - - /// @notice reservation bin duration - uint256 public immutable reservationBinInterval; - /// @notice start timestamp of reservation bins - uint256 public immutable reservationBinStartTimestamp; - /// @notice cooldown period before the price can be updated again - uint256 public immutable priceUpdateCooldown; - - constructor( - uint256 _reservationBinInterval, - uint256 _reservationBinStartTimestamp, - uint256 _priceUpdateCooldown - ){ - reservationBinInterval = _reservationBinInterval; - reservationBinStartTimestamp = _reservationBinStartTimestamp; - priceUpdateCooldown = _priceUpdateCooldown; - } /// @notice minimum chargeable size for on-demand payments - uint256 public minChargeableSize; - /// @notice maximum number of symbols to disperse per second network-wide for on-demand payments (applied to only ETH and EIGEN) - uint256 public globalSymbolsPerSecond; + uint256 public minChargeableSize; /// @notice price per symbol in wei uint256 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 globalSymbolsPerSecond; + /// @notice reservation bin duration + uint256 public reservationBinInterval; + /// @notice timestamp of the last price update - uint256 public lastPriceUpdateTime; + uint256 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[44] private __GAP; + uint256[42] private __GAP; } \ No newline at end of file