Skip to content

Commit

Permalink
adjust VaultStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Korokhov committed May 22, 2024
1 parent 72e004a commit ea03bf9
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 161 deletions.
79 changes: 0 additions & 79 deletions src/contracts/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ contract Vault is VaultStorage, MulticallUpgradeable, IVault {
address networkOptInPlugin
) VaultStorage(networkRegistry, operatorRegistry, networkMiddlewarePlugin, networkOptInPlugin) {}

/**
* @inheritdoc IVault
*/
function currentEpoch() public view returns (uint256) {
return (clock() - epochDurationInit) / epochDuration;
}

/**
* @inheritdoc IVault
*/
function currentEpochStart() public view returns (uint48) {
return uint48(epochDurationInit + currentEpoch() * epochDuration);
}

/**
* @inheritdoc IVault
*/
Expand All @@ -52,63 +38,6 @@ contract Vault is VaultStorage, MulticallUpgradeable, IVault {
return activeSupply() + withdrawals[epoch] + withdrawals[epoch + 1];
}

/**
* @inheritdoc IVault
*/
function activeSharesAt(uint48 timestamp) public view returns (uint256) {
return _activeShares.upperLookupRecent(timestamp);
}

/**
* @inheritdoc IVault
*/
function activeShares() public view returns (uint256) {
return _activeShares.latest();
}

/**
* @inheritdoc IVault
*/
function activeSupplyAt(uint48 timestamp) public view returns (uint256) {
return _activeSupplies.upperLookupRecent(timestamp);
}

/**
* @inheritdoc IVault
*/
function activeSupply() public view returns (uint256) {
return _activeSupplies.latest();
}

/**
* @inheritdoc IVault
*/
function activeSharesOfAt(address account, uint48 timestamp) public view returns (uint256) {
return _activeSharesOf[account].upperLookupRecent(timestamp);
}

/**
* @inheritdoc IVault
*/
function activeSharesOf(address account) public view returns (uint256) {
return _activeSharesOf[account].latest();
}

/**
* @inheritdoc IVault
*/
function activeSharesOfCheckpointsLength(address account) public view returns (uint256) {
return _activeSharesOf[account].length();
}

/**
* @inheritdoc IVault
*/
function activeSharesOfCheckpoint(address account, uint32 pos) public view returns (uint48, uint256) {
Checkpoints.Checkpoint256 memory checkpoint = _activeSharesOf[account].at(pos);
return (checkpoint._key, checkpoint._value);
}

/**
* @inheritdoc IVault
*/
Expand Down Expand Up @@ -140,14 +69,6 @@ contract Vault is VaultStorage, MulticallUpgradeable, IVault {
return Math.min(totalSupply(), Math.min(networkLimit(network, resolver), operatorLimit(operator, network)));
}

function slashRequestsLength() public view returns (uint256) {
return slashRequests.length;
}

function rewardsLength(address token) public view returns (uint256) {
return rewards[token].length;
}

/**
* @inheritdoc IVault
*/
Expand Down
87 changes: 87 additions & 0 deletions src/contracts/VaultStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ contract VaultStorage is
ReentrancyGuardUpgradeable,
IVaultStorage
{
using Checkpoints for Checkpoints.Trace256;

/**
* @dev Some dead address to transfer slashed tokens to.
*/
Expand Down Expand Up @@ -207,6 +209,91 @@ contract VaultStorage is
NETWORK_OPT_IN_PLUGIN = networkOptInPlugin;
}

/**
* @inheritdoc IVaultStorage
*/
function currentEpoch() public view returns (uint256) {
return (clock() - epochDurationInit) / epochDuration;
}

/**
* @inheritdoc IVaultStorage
*/
function currentEpochStart() public view returns (uint48) {
return uint48(epochDurationInit + currentEpoch() * epochDuration);
}

/**
* @inheritdoc IVaultStorage
*/
function activeSharesAt(uint48 timestamp) public view returns (uint256) {
return _activeShares.upperLookupRecent(timestamp);
}

/**
* @inheritdoc IVaultStorage
*/
function activeShares() public view returns (uint256) {
return _activeShares.latest();
}

/**
* @inheritdoc IVaultStorage
*/
function activeSupplyAt(uint48 timestamp) public view returns (uint256) {
return _activeSupplies.upperLookupRecent(timestamp);
}

/**
* @inheritdoc IVaultStorage
*/
function activeSupply() public view returns (uint256) {
return _activeSupplies.latest();
}

/**
* @inheritdoc IVaultStorage
*/
function activeSharesOfAt(address account, uint48 timestamp) public view returns (uint256) {
return _activeSharesOf[account].upperLookupRecent(timestamp);
}

/**
* @inheritdoc IVaultStorage
*/
function activeSharesOf(address account) public view returns (uint256) {
return _activeSharesOf[account].latest();
}

/**
* @inheritdoc IVaultStorage
*/
function activeSharesOfCheckpointsLength(address account) public view returns (uint256) {
return _activeSharesOf[account].length();
}

/**
* @inheritdoc IVaultStorage
*/
function activeSharesOfCheckpoint(address account, uint32 pos) public view returns (uint48, uint256) {
Checkpoints.Checkpoint256 memory checkpoint = _activeSharesOf[account].at(pos);
return (checkpoint._key, checkpoint._value);
}

/**
* @inheritdoc IVaultStorage
*/
function slashRequestsLength() public view returns (uint256) {
return slashRequests.length;
}

/**
* @inheritdoc IVaultStorage
*/
function rewardsLength(address token) public view returns (uint256) {
return rewards[token].length;
}

/**
* @inheritdoc IMigratableEntity
*/
Expand Down
82 changes: 0 additions & 82 deletions src/interfaces/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,81 +202,12 @@ interface IVault is IVaultStorage {
*/
event SetOperatorLimit(address indexed operator, address indexed network, uint256 amount);

/**
* @notice Get a current vault epoch.
* @return current epoch
*/
function currentEpoch() external view returns (uint256);

/**
* @notice Get a start of the current vault epoch.
* @return start of the current epoch
*/
function currentEpochStart() external view returns (uint48);

/**
* @notice Get a total amount of the collateral deposited in the vault.
* @return total amount of the collateral deposited
*/
function totalSupply() external view returns (uint256);

/**
* @notice Get a total amount of the active shares in the vault at a given timestamp.
* @param timestamp time point to get the total amount of the active shares at
* @return total amount of the active shares at the timestamp
*/
function activeSharesAt(uint48 timestamp) external view returns (uint256);

/**
* @notice Get a total amount of the active shares in the vault.
* @return total amount of the active shares
*/
function activeShares() external view returns (uint256);

/**
* @notice Get a total amount of the active supply in the vault at a given timestamp.
* @param timestamp time point to get the total active supply at
* @return total amount of the active supply at the timestamp
*/
function activeSupplyAt(uint48 timestamp) external view returns (uint256);

/**
* @notice Get a total amount of the active supply in the vault.
* @return total amount of the active supply
*/
function activeSupply() external view returns (uint256);

/**
* @notice Get a total amount of the active shares for a particular account at a given timestamp.
* @param account account to get the amount of the active shares for
* @param timestamp time point to get the amount of the active shares for the account at
* @return total amount of the active shares for the account at the timestamp
*/
function activeSharesOfAt(address account, uint48 timestamp) external view returns (uint256);

/**
* @notice Get an amount of the active shares for a particular account.
* @param account account to get the amount of the active shares for
* @return amount of the active shares for the account
*/
function activeSharesOf(address account) external view returns (uint256);

/**
* @notice Get a total number of the activeSharesOf checkpoints for a particular account.
* @param account account to get the total number of the activeSharesOf checkpoints for
* @return total number of the activeSharesOf checkpoints for the account
*/
function activeSharesOfCheckpointsLength(address account) external view returns (uint256);

/**
* @notice Get an activeSharesOf checkpoint for a particular account at a given index.
* @param account account to get the activeSharesOf checkpoint for
* @param pos index of the checkpoint
* @return timestamp time point of the checkpoint
* @return amount of active shares at the checkpoint
*/
function activeSharesOfCheckpoint(address account, uint32 pos) external view returns (uint48, uint256);

/**
* @notice Get an active balance for a particular account at a given timestamp.
* @param account account to get the active balance for
Expand Down Expand Up @@ -309,19 +240,6 @@ interface IVault is IVaultStorage {
*/
function maxSlash(address network, address resolver, address operator) external view returns (uint256);

/**
* @notice Get a total number of slash requests.
* @return total number of slash requests
*/
function slashRequestsLength() external view returns (uint256);

/**
* @notice Get a total number of rewards using a particular token.
* @param token address of the token
* @return total number of rewards using the token
*/
function rewardsLength(address token) external view returns (uint256);

/**
* @notice Get if a given network-resolver pair is opted in.
* @return if the network-resolver pair is opted in
Expand Down
Loading

0 comments on commit ea03bf9

Please sign in to comment.