Skip to content

Commit

Permalink
storage update
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0aa0 committed Dec 12, 2024
1 parent ed00679 commit 66c9caa
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 113 deletions.
18 changes: 9 additions & 9 deletions contracts/script/EigenDADeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -159,11 +159,11 @@ contract EigenDADeployer is DeployOpenEigenLayer {
PaymentVault.initialize.selector,
addressConfig.eigenDACommunityMultisig,
_minNumSymbols,
_globalSymbolsPerBin,
_pricePerSymbol,
_reservationBinInterval,
_priceUpdateCooldown,
_globalRateBinInterval
_globalSymbolsPerPeriod,
_reservationPeriodInterval,
_globalRatePeriodInterval
)
);
}
Expand Down
34 changes: 19 additions & 15 deletions contracts/src/interfaces/IPaymentVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

/**
Expand All @@ -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);
}
65 changes: 34 additions & 31 deletions contracts/src/payments/PaymentVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}

/**
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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;
}
}
}
26 changes: 13 additions & 13 deletions contracts/src/payments/PaymentVaultStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading

0 comments on commit 66c9caa

Please sign in to comment.