Skip to content

Commit

Permalink
fix additional approvals problem (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
ungaro authored Dec 6, 2024
1 parent 16ca3c8 commit ba7ddbe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
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

0 comments on commit ba7ddbe

Please sign in to comment.