-
Notifications
You must be signed in to change notification settings - Fork 889
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
Add new allocator to migrate old LUSD allocator to and rescue funds #339
Open
0xLienid
wants to merge
2
commits into
allocators
Choose a base branch
from
lusd-alloc-rescue
base: allocators
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,78 @@ | ||
pragma solidity ^0.8.10; | ||
|
||
import "../interfaces/IAllocator.sol"; | ||
import "./interfaces/IWETH.sol"; | ||
import "../types/BaseAllocator.sol"; | ||
|
||
error LUSDAllocator_InputTooLarge(); | ||
error LUSDAllocator_TreasuryAddressZero(); | ||
|
||
/** | ||
* Contract deploys LUSD from treasury into the liquity stabilty pool. Each update, rewards are harvested. | ||
* The allocator stakes the LQTY rewards and sells part of the ETH rewards to stack more LUSD. | ||
* This contract inherits BaseAllocator is and meant to be used with Treasury extender. | ||
*/ | ||
contract LUSDAllocatorV2R is BaseAllocator { | ||
using SafeERC20 for IERC20; | ||
|
||
/* ======== STATE VARIABLES ======== */ | ||
address public immutable wethAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; | ||
address public immutable lqtyTokenAddress = 0x6DEA81C8171D0bA574754EF6F8b412F2Ed88c54D; | ||
|
||
/** | ||
* @notice tokens in AllocatorInitData should be [LUSD Address] | ||
* LUSD Address (0x5f98805A4E8be255a32880FDeC7F6728C6568bA0) | ||
*/ | ||
constructor(AllocatorInitData memory data) BaseAllocator(data) {} | ||
|
||
// Send ETH to an address | ||
function sendETH(address to_) external { | ||
_onlyGuardian(); | ||
|
||
payable(to_).transfer(address(this).balance); | ||
} | ||
|
||
// Send token to an address | ||
function sendToken(address token_, address to_) external { | ||
_onlyGuardian(); | ||
|
||
IERC20(token_).safeTransfer(to_, IERC20(token_).balanceOf(address(this))); | ||
} | ||
|
||
/** | ||
* @notice Need this because StabilityPool::withdrawFromSP() and LQTYStaking::stake() will send ETH here | ||
*/ | ||
receive() external payable {} | ||
|
||
/* ======== INTERNAL FUNCTIONS TO MATCH ALLOCATOR INTERFACE ======== */ | ||
|
||
function _update(uint256 id) internal override returns (uint128 gain, uint128 loss) {} | ||
|
||
function deallocate(uint256[] memory amounts) public override {} | ||
|
||
function _deactivate(bool panic) internal override {} | ||
|
||
function _prepareMigration() internal override { | ||
// If for some reason there's an ETH balance, deposit to WETH | ||
uint256 ethBalance = address(this).balance; | ||
if (ethBalance > 0) IWETH(wethAddress).deposit{value: ethBalance}(); | ||
} | ||
|
||
/* ======== VIEW FUNCTIONS ======== */ | ||
|
||
function amountAllocated(uint256 id) public view override returns (uint256) {} | ||
|
||
function rewardTokens() public view override returns (IERC20[] memory) {} | ||
|
||
// Keeping this in case something goes wrong and we need to migrate again | ||
function utilityTokens() public view override returns (IERC20[] memory) { | ||
IERC20[] memory utility = new IERC20[](2); | ||
utility[0] = IERC20(lqtyTokenAddress); | ||
utility[1] = IERC20(wethAddress); | ||
return utility; | ||
} | ||
|
||
function name() external view override returns (string memory) { | ||
return "LUSD Allocator Rescue"; | ||
} | ||
} |
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.
It's better to use a low-level call since if you send it to a smart contract wallet or a contract, it could get bricked in the future if the gas cost of op codes change. Transfer only forwards 2300 gas.
payable(to_).call{value: address(this).balance}("");
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.
cool, updated