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

[NES-260] [Fix] Additional approvals problem #109

Merged
merged 1 commit into from
Dec 6, 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
22 changes: 21 additions & 1 deletion nest/src/token/BoringVaultAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ abstract contract BoringVaultAdapter is
$.asset = asset_;

$.version = 1; // Set initial version

// Set approvals for the underlying asset
SafeERC20.forceApprove(asset_, vault_, type(uint256).max);
SafeERC20.forceApprove(asset_, teller_, type(uint256).max);
SafeERC20.forceApprove(asset_, atomicQueue_, type(uint256).max);

// Set approvals for the pUSD token itself
_approve(address(this), vault_, type(uint256).max);
_approve(address(this), teller_, type(uint256).max);
_approve(address(this), atomicQueue_, type(uint256).max);
}

function reinitialize(
Expand All @@ -148,7 +158,7 @@ abstract contract BoringVaultAdapter is
address atomicQueue_,
address lens_,
address accountant_
) public onlyRole(UPGRADER_ROLE) {
) public virtual onlyRole(UPGRADER_ROLE) {
// Reinitialize as needed
if (
owner == address(0) || address(asset_) == address(0) || vault_ == address(0) || teller_ == address(0)
Expand All @@ -167,6 +177,16 @@ abstract contract BoringVaultAdapter is
$.boringVault.lens = ILens(lens_);
$.boringVault.accountant = IAccountantWithRateProviders(accountant_);

// Set approvals for the underlying asset
SafeERC20.forceApprove(asset_, vault_, type(uint256).max);
SafeERC20.forceApprove(asset_, teller_, type(uint256).max);
SafeERC20.forceApprove(asset_, atomicQueue_, type(uint256).max);

// Set approvals for the pUSD token itself
_approve(address(this), vault_, type(uint256).max);
_approve(address(this), teller_, type(uint256).max);
_approve(address(this), atomicQueue_, type(uint256).max);

emit Reinitialized($.version);
}

Expand Down
15 changes: 0 additions & 15 deletions nest/test/pUSDPlume.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,6 @@ contract pUSDPlumeTest is Test {

vm.startPrank(user1);

// Approve both token and vault
asset.approve(address(token), type(uint256).max);
asset.approve(address(vault), type(uint256).max);
asset.approve(TELLER_ADDRESS, type(uint256).max);

// Additional approval needed for the vault to transfer from pUSD
vm.stopPrank();

// Add approval from pUSD to vault
vm.startPrank(address(token));
asset.approve(address(vault), type(uint256).max);
vm.stopPrank();

vm.startPrank(user1);

console.log("Asset balance before deposit:", asset.balanceOf(user1));
console.log("Asset allowance for token:", asset.allowance(user1, address(token)));
console.log("Asset allowance for vault:", asset.allowance(user1, address(vault)));
Expand Down
Loading