Skip to content

Commit

Permalink
mutable vars
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0aa0 committed Oct 22, 2024
1 parent 37cd19c commit 99570a5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 44 deletions.
15 changes: 11 additions & 4 deletions contracts/src/interfaces/IPaymentVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 39 additions & 18 deletions contracts/src/payments/PaymentVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -54,25 +61,34 @@ 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 {
emit GlobalSymbolsPerSecondUpdated(globalSymbolsPerSecond, _globalSymbolsPerSecond);
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 {
Expand All @@ -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];
Expand Down
32 changes: 10 additions & 22 deletions contracts/src/payments/PaymentVaultStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 99570a5

Please sign in to comment.