From 26254543c225a68eaaecf46996527c83bc4bc0ae Mon Sep 17 00:00:00 2001 From: web3rover Date: Mon, 8 Sep 2025 12:34:05 +0530 Subject: [PATCH 1/3] fix: vps-02 --- contracts/PositionSwapper/PositionSwapper.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/PositionSwapper/PositionSwapper.sol b/contracts/PositionSwapper/PositionSwapper.sol index 213c7f8..88d90b0 100644 --- a/contracts/PositionSwapper/PositionSwapper.sol +++ b/contracts/PositionSwapper/PositionSwapper.sol @@ -97,6 +97,7 @@ contract PositionSwapper is Ownable2StepUpgradeable, ReentrancyGuardUpgradeable /// @custom:oz-upgrades-unsafe-allow constructor constructor(address _comptroller, address _nativeMarket) { if (_comptroller == address(0)) revert ZeroAddress(); + if (_nativeMarket == address(0)) revert ZeroAddress(); COMPTROLLER = IComptroller(_comptroller); NATIVE_MARKET = _nativeMarket; From 65cb255d77dee91e2cfef6b55e2140f2756441a5 Mon Sep 17 00:00:00 2001 From: web3rover Date: Mon, 8 Sep 2025 12:43:39 +0530 Subject: [PATCH 2/3] fix: vps-03 --- contracts/PositionSwapper/WBNBSwapHelper.sol | 50 ++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/contracts/PositionSwapper/WBNBSwapHelper.sol b/contracts/PositionSwapper/WBNBSwapHelper.sol index 65e435f..24c0049 100644 --- a/contracts/PositionSwapper/WBNBSwapHelper.sol +++ b/contracts/PositionSwapper/WBNBSwapHelper.sol @@ -3,14 +3,17 @@ pragma solidity 0.8.25; import { IWBNB } from "../Interfaces.sol"; import { ISwapHelper } from "./ISwapHelper.sol"; -import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; +import { SafeERC20Upgradeable, IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; +import { Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol"; /** * @title WBNBSwapHelper * @notice Swap helper that wraps or unwraps native BNB into WBNB for PositionSwapper. * @dev Only supports native token (BNB) wrapping into WBNB and unwrapping WBNB into BNB. Meant to be used only by the PositionSwapper. */ -contract WBNBSwapHelper is ISwapHelper { +contract WBNBSwapHelper is Ownable2Step, ISwapHelper { + using SafeERC20Upgradeable for IERC20Upgradeable; + /// @notice Address of the authorized PositionSwapper contract address public immutable POSITION_SWAPPER; @@ -29,6 +32,21 @@ contract WBNBSwapHelper is ISwapHelper { */ event SwappedToBNB(uint256 amount); + /** + * @notice Emitted after the owner sweeps leftover ERC-20 tokens from the contract + * @param token The token that was swept. + * @param receiver The address that received the swept tokens. + * @param amount The amount of tokens that were swept. + */ + event SweepToken(address indexed token, address indexed receiver, uint256 amount); + + /** + * @notice Emitted after the owner sweeps leftover native tokens (e.g., BNB) from the contract + * @param receiver The address that received the swept native tokens. + * @param amount The amount of native tokens that were swept. + */ + event SweepNative(address indexed receiver, uint256 amount); + /// @notice Error thrown when caller is not the authorized PositionSwapper error Unauthorized(); @@ -50,13 +68,39 @@ contract WBNBSwapHelper is ISwapHelper { _; } - constructor(address _wbnb, address _swapper) { + constructor(address _wbnb, address _swapper) Ownable2Step() { if (_wbnb == address(0) || _swapper == address(0)) revert ZeroAddress(); WBNB = IWBNB(_wbnb); POSITION_SWAPPER = _swapper; } + /** + * @notice Allows the owner to sweep leftover ERC-20 tokens from the contract. + * @param token The token to sweep. + * @custom:event Emits SweepToken event. + */ + function sweepToken(IERC20Upgradeable token) external onlyOwner { + uint256 balance = token.balanceOf(address(this)); + if (balance > 0) { + token.safeTransfer(owner(), balance); + emit SweepToken(address(token), owner(), balance); + } + } + + /** + * @notice Allows the owner to sweep leftover native tokens (e.g., BNB) from the contract. + * @custom:event Emits SweepToken event. + */ + function sweepNative() external onlyOwner { + uint256 balance = address(this).balance; + if (balance > 0) { + (bool success, ) = payable(owner()).call{ value: balance }(""); + if (!success) revert TransferFailed(); + emit SweepNative(owner(), balance); + } + } + /// @notice Allows this contract to receive native BNB receive() external payable {} From 7d8a6ad565eb735d0cdc2fbe7518d854e9593460 Mon Sep 17 00:00:00 2001 From: web3rover Date: Mon, 8 Sep 2025 12:44:51 +0530 Subject: [PATCH 3/3] fix: vps-01 --- contracts/PositionSwapper/WBNBSwapHelper.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/PositionSwapper/WBNBSwapHelper.sol b/contracts/PositionSwapper/WBNBSwapHelper.sol index 24c0049..f7d5555 100644 --- a/contracts/PositionSwapper/WBNBSwapHelper.sol +++ b/contracts/PositionSwapper/WBNBSwapHelper.sol @@ -124,7 +124,7 @@ contract WBNBSwapHelper is Ownable2Step, ISwapHelper { WBNB.transfer(msg.sender, amount); emit SwappedToWBNB(amount); } else { - IERC20Upgradeable(WBNB).transferFrom(msg.sender, address(this), amount); + WBNB.transferFrom(msg.sender, address(this), amount); WBNB.withdraw(amount); (bool success, ) = payable(msg.sender).call{ value: amount }("");