-
Notifications
You must be signed in to change notification settings - Fork 63
feat: add rVirtual conversion via RVirtualConverter #181
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
Open
koo-virtuals
wants to merge
1
commit into
main
Choose a base branch
from
feat/vp-2434
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| interface IRVirtualConverter { | ||
| function convertVirtualToRVirtual( | ||
| uint256 amount, | ||
| address rVirtualReceiver | ||
| ) external; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
| import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
| import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; | ||
| import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; | ||
| import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
| import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
|
||
| /// @notice Open, permissionless 1:1 converter from VIRTUAL to rVirtual. | ||
| /// | ||
| /// Pre-funded with the full rVirtual supply before launch - conversions draw down that | ||
| /// balance rather than minting on demand. Any caller (a regular wallet, or veVirtual's | ||
| /// convertVeVirtualToRVirtual()) uses the exact same convertVirtualToRVirtual() entrypoint; | ||
| /// there is no privileged "veVirtual-only" path here. | ||
| contract RVirtualConverter is | ||
| Initializable, | ||
| ReentrancyGuardUpgradeable, | ||
| AccessControlUpgradeable, | ||
| UUPSUpgradeable | ||
| { | ||
| using SafeERC20 for IERC20; | ||
|
|
||
| bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE"); | ||
|
|
||
| address public virtualToken; | ||
| address public rVirtualToken; | ||
| address public adminWallet; | ||
|
|
||
| event ConvertedVirtualToRVirtual( | ||
| address indexed caller, | ||
| address indexed rVirtualReceiver, | ||
| uint256 amount | ||
| ); | ||
| event AdminWalletUpdated(address adminWallet); | ||
| event VirtualWithdrawn(address adminWallet, uint256 amount); | ||
|
|
||
| function initialize( | ||
| address virtualToken_, | ||
| address rVirtualToken_ | ||
| ) external initializer { | ||
| __ReentrancyGuard_init(); | ||
| __AccessControl_init(); | ||
| __UUPSUpgradeable_init(); | ||
|
|
||
| require(virtualToken_ != address(0), "Invalid virtual token"); | ||
| require(rVirtualToken_ != address(0), "Invalid rVirtual token"); | ||
| virtualToken = virtualToken_; | ||
| rVirtualToken = rVirtualToken_; | ||
|
|
||
| _grantRole(DEFAULT_ADMIN_ROLE, _msgSender()); | ||
| _grantRole(ADMIN_ROLE, _msgSender()); | ||
| } | ||
|
|
||
| /// @notice Convert `amount` VIRTUAL (pulled from the caller) into `amount` rVirtual, | ||
| /// sent to `rVirtualReceiver`. Fully open - no allowlist, no cap. | ||
| function convertVirtualToRVirtual( | ||
| uint256 amount, | ||
| address rVirtualReceiver | ||
| ) external nonReentrant { | ||
| require(amount > 0, "Amount must be greater than 0"); | ||
| require(rVirtualReceiver != address(0), "Invalid receiver"); | ||
|
|
||
| IERC20(virtualToken).safeTransferFrom( | ||
| _msgSender(), | ||
| address(this), | ||
| amount | ||
| ); | ||
| IERC20(rVirtualToken).safeTransfer(rVirtualReceiver, amount); | ||
|
|
||
| emit ConvertedVirtualToRVirtual(_msgSender(), rVirtualReceiver, amount); | ||
| } | ||
|
|
||
| function setAdminWallet(address adminWallet_) external onlyRole(ADMIN_ROLE) { | ||
| require(adminWallet_ != address(0), "Invalid admin wallet"); | ||
| adminWallet = adminWallet_; | ||
| emit AdminWalletUpdated(adminWallet_); | ||
| } | ||
|
|
||
| /// @notice Withdraw accumulated VIRTUAL out of this contract. Only VIRTUAL - there is | ||
| /// intentionally no withdrawal path for rVirtual or any other token here, so | ||
| /// adminWallet is never exposed to rVirtual's transfer tax. | ||
| function withdrawVirtual(uint256 amount) external nonReentrant { | ||
| require(_msgSender() == adminWallet, "Only admin wallet"); | ||
| IERC20(virtualToken).safeTransfer(adminWallet, amount); | ||
| emit VirtualWithdrawn(adminWallet, amount); | ||
| } | ||
|
|
||
| function _authorizeUpgrade( | ||
| address newImplementation | ||
| ) internal override onlyRole(ADMIN_ROLE) {} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import "./RVirtualConverter.sol"; | ||
|
|
||
| /// @notice Test-only V2 used to verify RVirtualConverter's UUPS upgrade path round-trips | ||
| /// cleanly. Adds one new event + trigger function on top of V1; never deployed to | ||
| /// production - exists purely so a test can upgrade forward, prove the new code is | ||
| /// live, then upgrade back and confirm the final bytecode matches the original V1. | ||
| contract RVirtualConverterV2Mock is RVirtualConverter { | ||
| event V2UpgradeMarker(string message); | ||
|
|
||
| function triggerV2Marker() external { | ||
| emit V2UpgradeMarker("upgraded"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation initializers left enabled
Medium Severity
RVirtualConverteris UUPS-upgradeable but never disables initializers on the implementation. Unlike other upgradeable contracts here (for exampleMinter), anyone can callinitializeon the implementation itself, take over its admin roles, and empty any tokens sent to that address.Reviewed by Cursor Bugbot for commit b98ca31. Configure here.