Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payments storage packing #942

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions contracts/src/interfaces/IPaymentVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ 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(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,
0x0aa0 marked this conversation as resolved.
Show resolved Hide resolved
uint128 previousPriceUpdateCooldown,
uint128 newPriceUpdateCooldown
);

/**
Expand All @@ -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);
}
function getOnDemandAmounts(address[] memory _accounts) external view returns (uint128[] memory _payments);
}
38 changes: 19 additions & 19 deletions contracts/src/payments/PaymentVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -41,7 +41,7 @@ contract PaymentVault is PaymentVaultStorage, OwnableUpgradeable {
priceUpdateCooldown = _priceUpdateCooldown;
globalRateBinInterval = _globalRateBinInterval;

lastPriceUpdateTime = block.timestamp;
lastPriceUpdateTime = uint128(block.timestamp);
}

/**
Expand All @@ -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(
Expand All @@ -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;
}
Expand All @@ -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
Expand All @@ -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]];
0x0aa0 marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
18 changes: 9 additions & 9 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
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;
mapping(address => uint128) public onDemandPayments;

uint256[42] private __GAP;
uint256[44] private __GAP;
}
34 changes: 17 additions & 17 deletions contracts/test/unit/PaymentVaultUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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, uint128 onDemandPayment, uint128 totalDeposit);
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;
Expand All @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down
Loading