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

Add new allocator to migrate old LUSD allocator to and rescue funds #339

Open
wants to merge 2 commits into
base: allocators
Choose a base branch
from
Open
Changes from 1 commit
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
78 changes: 78 additions & 0 deletions contracts/allocators/LUSDAllocatorRescue.sol
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);
Copy link

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}("");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, updated

}

// 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";
}
}