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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
38 changes: 36 additions & 2 deletions contracts/script/EigenDADeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -59,6 +61,14 @@ contract EigenDADeployer is DeployOpenEigenLayer {
EigenDAThresholdRegistry public eigenDAThresholdRegistryImplementation;
EigenDARelayRegistry public eigenDARelayRegistryImplementation;
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;

struct AddressConfig {
address eigenLayerCommunityMultisig;
Expand Down Expand Up @@ -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,
_globalSymbolsPerBin,
_pricePerSymbol,
_reservationBinInterval,
_priceUpdateCooldown,
_globalRateBinInterval
)
);
}

indexRegistryImplementation = new IndexRegistry(
registryCoordinator
);
Expand Down Expand Up @@ -222,7 +255,8 @@ contract EigenDADeployer is DeployOpenEigenLayer {
registryCoordinator,
stakeRegistry,
eigenDAThresholdRegistry,
eigenDARelayRegistry
eigenDARelayRegistry,
paymentVault
);

address[] memory confirmers = new address[](1);
Expand Down
6 changes: 4 additions & 2 deletions contracts/src/core/EigenDAServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
}
Expand Down
8 changes: 6 additions & 2 deletions contracts/src/core/EigenDAServiceManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions contracts/src/interfaces/IPaymentVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ 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
}

/// @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,
Comment on lines +28 to +29
Copy link
Contributor

@ian-shim ian-shim Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much gas savings are we talking here? I assume we're going to price this in mwei, but I wonder if we should just keep this in wei if the cost savings are trivial. This allows us to express any pricing better granularity
(If we do need to use mwei, can we document that?)

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]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we validate if _accounts[i] exists in onDemandPayments?

}
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;
}
4 changes: 3 additions & 1 deletion contracts/test/rollup/MockRollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -94,7 +95,8 @@ contract MockRollupTest is BLSMockAVSDeployer {
registryCoordinator,
stakeRegistry,
eigenDAThresholdRegistry,
eigenDARelayRegistry
eigenDARelayRegistry,
IPaymentVault(address(0))
);

eigenDAThresholdRegistryImplementation = new EigenDAThresholdRegistry();
Expand Down
6 changes: 5 additions & 1 deletion contracts/test/unit/EigenDABlobUtils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -78,7 +81,8 @@ contract EigenDABlobUtilsUnit is BLSMockAVSDeployer {
registryCoordinator,
stakeRegistry,
eigenDAThresholdRegistry,
eigenDARelayRegistry
eigenDARelayRegistry,
IPaymentVault(address(0))
);

eigenDAThresholdRegistryImplementation = new EigenDAThresholdRegistry();
Expand Down
4 changes: 3 additions & 1 deletion contracts/test/unit/EigenDAServiceManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -75,7 +76,8 @@ contract EigenDAServiceManagerUnit is BLSMockAVSDeployer {
registryCoordinator,
stakeRegistry,
eigenDAThresholdRegistry,
eigenDARelayRegistry
eigenDARelayRegistry,
IPaymentVault(address(0))
);

address[] memory confirmers = new address[](1);
Expand Down
Loading
Loading