Skip to content

Commit

Permalink
fix: adjust migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
1kresh committed Feb 18, 2025
1 parent 90677dd commit 12dc2dc
Show file tree
Hide file tree
Showing 25 changed files with 1,138 additions and 1,043 deletions.
2 changes: 1 addition & 1 deletion out/DelegatorHints.sol/BaseDelegatorHints.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/DelegatorHints.sol/FullRestakeDelegatorHints.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/DelegatorHints.sol/NetworkRestakeDelegatorHints.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/DelegatorHints.sol/OperatorSpecificDelegatorHints.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/SlasherHints.sol/BaseSlasherHints.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/SlasherHints.sol/SlasherHints.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/SlasherHints.sol/VetoSlasherHints.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/Vault.sol/Vault.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/VaultConfigurator.sol/VaultConfigurator.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/VaultHints.sol/VaultHints.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/VaultTokenized.sol/VaultTokenized.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/contracts/common/MigratableEntity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ abstract contract MigratableEntity is

function _initialize(uint64, /* initialVersion */ address, /* owner */ bytes memory /* data */ ) internal virtual {}

function _migrate(uint64, /* oldVersion */ uint64, /* newVersion */ bytes calldata /* data */ ) internal virtual {}
function _migrate(uint64, /* oldVersion */ uint64, /* newVersion */ bytes memory /* data */ ) internal virtual {}

uint256[10] private __gap;
}
2 changes: 1 addition & 1 deletion src/contracts/vault/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau
}
}

function _migrate(uint64, /* oldVersion */ uint64, /* newVersion */ bytes calldata /* data */ ) internal override {
function _migrate(uint64, /* oldVersion */ uint64, /* newVersion */ bytes memory /* data */ ) internal override {
revert();
}
}
68 changes: 42 additions & 26 deletions src/contracts/vault/v1.1/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, Prox
return IMPLEMENTATION;
}

function _processMigrateParams(
IVault.MigrateParams memory params
) internal {
if (params.epochDurationSetEpochsDelay < 3) {
revert IVault.InvalidEpochDurationSetEpochsDelay();
}

if (params.flashFeeReceiver == address(0) && params.flashFeeRate != 0) {
revert IVault.InvalidFlashParams();
}

epochDurationSetEpochsDelay = params.epochDurationSetEpochsDelay;

flashFeeRate = params.flashFeeRate;
flashFeeReceiver = params.flashFeeReceiver;

if (params.epochDurationSetRoleHolder != address(0)) {
_grantRole(EPOCH_DURATION_SET_ROLE, params.epochDurationSetRoleHolder);
}
if (params.flashFeeRateSetRoleHolder != address(0)) {
_grantRole(FLASH_FEE_RATE_SET_ROLE, params.flashFeeRateSetRoleHolder);
}
if (params.flashFeeReceiverSetRoleHolder != address(0)) {
_grantRole(FLASH_FEE_RECEIVER_SET_ROLE, params.flashFeeReceiverSetRoleHolder);
}
}

function _initialize(uint64, address, bytes memory data) internal virtual override {
(IVault.InitParams memory params) = abi.decode(data, (IVault.InitParams));

Expand Down Expand Up @@ -90,13 +117,6 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, Prox
isDepositorWhitelisted[params.depositorsWhitelisted[i]] = true;
}

if (params.epochDurationSetEpochsDelay < 3) {
revert IVault.InvalidEpochDurationSetEpochsDelay();
}

if (params.flashFeeReceiver == address(0) && params.flashFeeRate != 0) {
revert IVault.InvalidFlashParams();
}
if (params.defaultAdminRoleHolder == address(0)) {
if (params.flashFeeReceiver == address(0)) {
if (params.flashFeeRateSetRoleHolder == address(0)) {
Expand All @@ -111,22 +131,29 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, Prox
}
}

_processMigrateParams(
IVault.MigrateParams({
epochDurationSetEpochsDelay: params.epochDurationSetEpochsDelay,
flashFeeRate: params.flashFeeRate,
flashFeeReceiver: params.flashFeeReceiver,
epochDurationSetRoleHolder: params.epochDurationSetRoleHolder,
flashFeeRateSetRoleHolder: params.flashFeeRateSetRoleHolder,
flashFeeReceiverSetRoleHolder: params.flashFeeReceiverSetRoleHolder
})
);

collateral = params.collateral;

burner = params.burner;

epochDurationInit = Time.timestamp();
epochDuration = params.epochDuration;
epochDurationSetEpochsDelay = params.epochDurationSetEpochsDelay;

depositWhitelist = params.depositWhitelist;

isDepositLimit = params.isDepositLimit;
depositLimit = params.depositLimit;

flashFeeRate = params.flashFeeRate;
flashFeeReceiver = params.flashFeeReceiver;

if (params.defaultAdminRoleHolder != address(0)) {
_grantRole(DEFAULT_ADMIN_ROLE, params.defaultAdminRoleHolder);
}
Expand All @@ -142,22 +169,11 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, Prox
if (params.depositLimitSetRoleHolder != address(0)) {
_grantRole(DEPOSIT_LIMIT_SET_ROLE, params.depositLimitSetRoleHolder);
}
if (params.epochDurationSetRoleHolder != address(0)) {
_grantRole(EPOCH_DURATION_SET_ROLE, params.epochDurationSetRoleHolder);
}
if (params.flashFeeRateSetRoleHolder != address(0)) {
_grantRole(FLASH_FEE_RATE_SET_ROLE, params.flashFeeRateSetRoleHolder);
}
if (params.flashFeeReceiverSetRoleHolder != address(0)) {
_grantRole(FLASH_FEE_RECEIVER_SET_ROLE, params.flashFeeReceiverSetRoleHolder);
}
}

function _migrate(
uint64, /* oldVersion */
uint64, /* newVersion */
bytes calldata /* data */
) internal virtual override {
revert();
function _migrate(uint64, /* oldVersion */ uint64, /* newVersion */ bytes memory data) internal virtual override {
(IVault.MigrateParams memory params) = abi.decode(data, (IVault.MigrateParams));

_processMigrateParams(params);
}
}
10 changes: 5 additions & 5 deletions src/contracts/vault/v1.1/VaultTokenized.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.25;
import {Vault} from "./Vault.sol";
import {VaultTokenizedImplementation} from "./VaultTokenizedImplementation.sol";

import {IVault} from "../../../interfaces/vault/v1.1/IVault.sol";
import {IVaultTokenized} from "../../../interfaces/vault/v1.1/IVaultTokenized.sol";

import {Address} from "@openzeppelin/contracts/utils/Address.sol";
Expand All @@ -21,25 +22,24 @@ contract VaultTokenized is Vault {
function _initialize(uint64 initialVersion, address owner_, bytes memory data) internal virtual override {
(IVaultTokenized.InitParamsTokenized memory params) = abi.decode(data, (IVaultTokenized.InitParamsTokenized));

super._initialize(initialVersion, owner_, abi.encode(params.baseParams));
super._initialize(initialVersion, owner_, params.baseParams);

_implementation().functionDelegateCall(
abi.encodeCall(VaultTokenizedImplementation._VaultTokenized_init, (params.name, params.symbol))
);
}

function _migrate(uint64 oldVersion, uint64, /* newVersion */ bytes calldata data) internal virtual override {
function _migrate(uint64 oldVersion, uint64 newVersion, bytes memory data) internal virtual override {
if (oldVersion == 1) {
(IVaultTokenized.MigrateParamsTokenized memory params) =
abi.decode(data, (IVaultTokenized.MigrateParamsTokenized));
super._migrate(oldVersion, newVersion, params.baseParams);
_implementation().functionDelegateCall(
abi.encodeCall(VaultTokenizedImplementation._VaultTokenized_init, (params.name, params.symbol))
);
} else {
// oldVersion == 2
if (data.length > 0) {
revert IVaultTokenized.InvalidData();
}
super._migrate(oldVersion, newVersion, data);
}
}
}
4 changes: 2 additions & 2 deletions src/contracts/vault/v1.1/VaultVotes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ contract VaultVotes is VaultTokenized {
_implementation().functionDelegateCall(abi.encodeCall(VaultVotesImplementation._VaultVotes_init, ()));
}

function _migrate(uint64 oldVersion, uint64, /* newVersion */ bytes calldata data) internal virtual override {
function _migrate(uint64 oldVersion, uint64, /* newVersion */ bytes memory data) internal virtual override {
if (oldVersion != 3) {
revert IVaultVotes.ImproperMigration();
}

if (data.length > 0) {
revert IVaultTokenized.InvalidData();
revert IVaultVotes.InvalidData();
}

_implementation().functionDelegateCall(abi.encodeCall(VaultVotesImplementation._VaultVotes_init, ()));
Expand Down
8 changes: 3 additions & 5 deletions src/contracts/vault/v1.1/VaultVotesImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,15 @@ contract VaultVotesImplementation is VaultStorage, VotesUpgradeable, Proxy, IVau
}

function transfer(address to, uint256 value) external returns (bool result) {
result = abi.decode(
BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IERC20.transfer, (to, value))), (bool)
);
result =
abi.decode(BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IERC20.transfer, (to, value))), (bool));

_transferVotingUnits(msg.sender, to, value);
}

function transferFrom(address from, address to, uint256 value) external returns (bool result) {
result = abi.decode(
BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IERC20.transferFrom, (from, to, value))),
(bool)
BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IERC20.transferFrom, (from, to, value))), (bool)
);

_transferVotingUnits(from, to, value);
Expand Down
9 changes: 9 additions & 0 deletions src/interfaces/vault/v1.1/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ interface IVault is IVaultStorage, IAccessControl, IERC165, IERC3156FlashLender
address flashFeeReceiverSetRoleHolder;
}

struct MigrateParams {
uint256 epochDurationSetEpochsDelay;
uint256 flashFeeRate;
address flashFeeReceiver;
address epochDurationSetRoleHolder;
address flashFeeRateSetRoleHolder;
address flashFeeReceiverSetRoleHolder;
}

/**
* @notice Hints for an active balance.
* @param activeSharesOfHint hint for the active shares of checkpoint
Expand Down
5 changes: 2 additions & 3 deletions src/interfaces/vault/v1.1/IVaultTokenized.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IER
import {IERC20Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";

interface IVaultTokenized is IERC20, IERC20Metadata, IERC20Errors {
error InvalidData();

/**
* @notice Initial parameters needed for a tokenized vault deployment.
* @param baseParams initial parameters needed for a vault deployment (InitParams)
* @param name name for the ERC20 tokenized vault
* @param symbol symbol for the ERC20 tokenized vault
*/
struct InitParamsTokenized {
IVault.InitParams baseParams;
bytes baseParams;
string name;
string symbol;
}
Expand All @@ -28,6 +26,7 @@ interface IVaultTokenized is IERC20, IERC20Metadata, IERC20Errors {
* @param symbol symbol for the ERC20 tokenized vault
*/
struct MigrateParamsTokenized {
bytes baseParams;
string name;
string symbol;
}
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/vault/v1.1/IVaultVotes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol";
interface IVaultVotes is IERC5805 {
error SafeSupplyExceeded();
error ImproperMigration();
error InvalidData();
}
2 changes: 1 addition & 1 deletion test/mocks/SimpleMigratableEntity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract SimpleMigratableEntity is MigratableEntity {
a = _a;
}

function _migrate(uint64, /* oldVersion */ uint64, /* newVersion */ bytes calldata /* data */ ) internal override {
function _migrate(uint64, /* oldVersion */ uint64, /* newVersion */ bytes memory /* data */ ) internal override {
revert();
}
}
2 changes: 1 addition & 1 deletion test/mocks/SimpleMigratableEntityV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract SimpleMigratableEntityV2 is MigratableEntity {
b = b_;
}

function _migrate(uint64 oldVersion, uint64 newVersion, bytes calldata data) internal override {
function _migrate(uint64 oldVersion, uint64 newVersion, bytes memory data) internal override {
if (newVersion - oldVersion > 1) {
revert();
}
Expand Down
Loading

0 comments on commit 12dc2dc

Please sign in to comment.