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

[PDE-234] add onlyInitializing reinitializer to ComponentToken #125

Merged
merged 1 commit into from
Dec 13, 2024
Merged
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
29 changes: 29 additions & 0 deletions nest/src/ComponentToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,35 @@ abstract contract ComponentToken is
$.asyncRedeem = asyncRedeem;
}

/**
* @notice Reinitialize the ComponentToken
* @param owner Address of the owner of the ComponentToken
* @param name Name of the ComponentToken
* @param symbol Symbol of the ComponentToken
* @param asset_ Asset used to mint and burn the ComponentToken
* @param asyncDeposit True if deposits are asynchronous; false otherwise
* @param asyncRedeem True if redemptions are asynchronous; false otherwise
*/
function reinitialize(
address owner,
string memory name,
string memory symbol,
IERC20 asset_,
bool asyncDeposit,
bool asyncRedeem
) public onlyInitializing {
__ERC20_init(name, symbol);
__ERC4626_init(asset_);

_grantRole(DEFAULT_ADMIN_ROLE, owner);
_grantRole(ADMIN_ROLE, owner);
_grantRole(UPGRADER_ROLE, owner);

ComponentTokenStorage storage $ = _getComponentTokenStorage();
$.asyncDeposit = asyncDeposit;
$.asyncRedeem = asyncRedeem;
}

// Override Functions

/**
Expand Down
22 changes: 15 additions & 7 deletions nest/src/token/BoringVaultAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,34 @@ abstract contract BoringVaultAdapter is
address teller_,
address atomicQueue_,
address lens_,
address accountant_
) public virtual onlyRole(UPGRADER_ROLE) {
// Reinitialize as needed
address accountant_,
string memory name,
string memory symbol
) public onlyRole(UPGRADER_ROLE) reinitializer(3) {
eyqs marked this conversation as resolved.
Show resolved Hide resolved
if (
owner == address(0) || address(asset_) == address(0) || vault_ == address(0) || teller_ == address(0)
|| atomicQueue_ == address(0) || lens_ == address(0) || accountant_ == address(0)
) {
revert ZeroAddress();
}

BoringVaultAdapterStorage storage $ = _getBoringVaultAdapterStorage();
try IERC20Metadata(address(asset_)).decimals() returns (uint8) { }
catch {
revert InvalidAsset();
}

// Set async redeem to true
super.reinitialize(owner, name, symbol, asset_, false, true);

// Increment version
$.version += 1;
BoringVaultAdapterStorage storage $ = _getBoringVaultAdapterStorage();
$.boringVault.teller = ITeller(teller_);
$.boringVault.vault = IBoringVault(vault_);
$.boringVault.atomicQueue = IAtomicQueue(atomicQueue_);
$.boringVault.lens = ILens(lens_);
$.boringVault.accountant = IAccountantWithRateProviders(accountant_);

$.version += 1; // Increment version

// Set approvals for the underlying asset
SafeERC20.forceApprove(asset_, vault_, type(uint256).max);
SafeERC20.forceApprove(asset_, teller_, type(uint256).max);
Expand Down Expand Up @@ -369,7 +377,7 @@ abstract contract BoringVaultAdapter is
try $.boringVault.accountant.getRateInQuote(ERC20(asset())) returns (uint256 rate) {
shares = assets.mulDivDown(10 ** shareDecimals, rate);
} catch {
revert InvalidAccountant(); // Or could create a new error like `InvalidAccountant`
revert InvalidAccountant();
}
} catch {
revert InvalidVault();
Expand Down
36 changes: 27 additions & 9 deletions nest/test/pUSD.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ contract pUSDTest is Test {
address(mockTeller),
address(mockAtomicQueue),
address(mockLens),
address(mockAccountant)
address(mockAccountant),
"Plume USD",
"pUSD"
);

assertNotEq(token.version(), 1);
Expand All @@ -253,7 +255,9 @@ contract pUSDTest is Test {
address(mockTeller),
address(mockAtomicQueue),
address(mockLens),
address(mockAccountant)
address(mockAccountant),
"Plume USD",
"pUSD"
);

vm.expectRevert(BoringVaultAdapter.ZeroAddress.selector);
Expand All @@ -265,7 +269,9 @@ contract pUSDTest is Test {
address(mockTeller),
address(mockAtomicQueue),
address(mockLens),
address(mockAccountant)
address(mockAccountant),
"Plume USD",
"pUSD"
);

vm.expectRevert(BoringVaultAdapter.ZeroAddress.selector);
Expand All @@ -276,7 +282,9 @@ contract pUSDTest is Test {
address(mockTeller),
address(mockAtomicQueue),
address(mockLens),
address(mockAccountant)
address(mockAccountant),
"Plume USD",
"pUSD"
);

vm.expectRevert(BoringVaultAdapter.ZeroAddress.selector);
Expand All @@ -287,7 +295,9 @@ contract pUSDTest is Test {
address(0),
address(mockAtomicQueue),
address(mockLens),
address(mockAccountant)
address(mockAccountant),
"Plume USD",
"pUSD"
);

vm.expectRevert(BoringVaultAdapter.ZeroAddress.selector);
Expand All @@ -298,7 +308,9 @@ contract pUSDTest is Test {
address(mockTeller),
address(0),
address(mockLens),
address(mockAccountant)
address(mockAccountant),
"Plume USD",
"pUSD"
);
}

Expand Down Expand Up @@ -416,7 +428,9 @@ contract pUSDTest is Test {
address(mockTeller),
address(mockAtomicQueue),
address(mockLens),
address(mockAccountant)
address(mockAccountant),
"Plume USD",
"pUSD"
);

// Now we can test the preview functions with the new vault
Expand All @@ -441,7 +455,9 @@ contract pUSDTest is Test {
address(mockTeller),
address(mockAtomicQueue),
address(mockLens),
address(mockAccountant)
address(mockAccountant),
"Plume USD",
"pUSD"
);

// Now we can test the preview functions with the new vault
Expand Down Expand Up @@ -480,7 +496,9 @@ contract pUSDTest is Test {
address(mockTeller),
address(mockAtomicQueue),
address(mockLens),
address(mockAccountant)
address(mockAccountant),
"Plume USD",
"pUSD"
);

// Test convertToShares revert
Expand Down
Loading