diff --git a/nest/src/ComponentToken.sol b/nest/src/ComponentToken.sol index 8bc6d44..24d578b 100644 --- a/nest/src/ComponentToken.sol +++ b/nest/src/ComponentToken.sol @@ -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 /** diff --git a/nest/src/token/BoringVaultAdapter.sol b/nest/src/token/BoringVaultAdapter.sol index bbb3f62..c0f43e0 100644 --- a/nest/src/token/BoringVaultAdapter.sol +++ b/nest/src/token/BoringVaultAdapter.sol @@ -159,9 +159,10 @@ 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) { if ( owner == address(0) || address(asset_) == address(0) || vault_ == address(0) || teller_ == address(0) || atomicQueue_ == address(0) || lens_ == address(0) || accountant_ == address(0) @@ -169,16 +170,23 @@ abstract contract BoringVaultAdapter is 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); @@ -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(); diff --git a/nest/test/pUSD.t.sol b/nest/test/pUSD.t.sol index 44eac06..fd6aa42 100644 --- a/nest/test/pUSD.t.sol +++ b/nest/test/pUSD.t.sol @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -298,7 +308,9 @@ contract pUSDTest is Test { address(mockTeller), address(0), address(mockLens), - address(mockAccountant) + address(mockAccountant), + "Plume USD", + "pUSD" ); } @@ -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 @@ -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 @@ -480,7 +496,9 @@ contract pUSDTest is Test { address(mockTeller), address(mockAtomicQueue), address(mockLens), - address(mockAccountant) + address(mockAccountant), + "Plume USD", + "pUSD" ); // Test convertToShares revert