-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add volt vote and fusd migration contract (#6)
* add volt vote and fusd migration contract * add fusd migration contract
- Loading branch information
Showing
7 changed files
with
1,261 additions
and
0 deletions.
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,75 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity =0.6.12; | ||
|
||
import "@openzeppelin/contracts/math/SafeMath.sol"; | ||
import "./interfaces/IBar.sol"; | ||
import "./interfaces/IERC20.sol"; | ||
|
||
interface IMasterChef { | ||
function userInfo(uint256 pid, address owner) external view returns (uint256, uint256); | ||
} | ||
|
||
contract VoltVote { | ||
using SafeMath for uint256; | ||
|
||
IBar bar; | ||
IERC20 volt; | ||
IMasterChef chef; | ||
uint256 pid; // Pool ID of xVOLT in MasterChefV3 | ||
|
||
function name() public pure returns(string memory) { | ||
return "VoltVote"; | ||
} | ||
|
||
function symbol() public pure returns (string memory) { | ||
return "VOLTVOTE"; | ||
} | ||
|
||
function decimals() public pure returns (uint8) { | ||
return 18; | ||
} | ||
|
||
constructor( | ||
address _bar, | ||
address _volt, | ||
address _chef, | ||
uint256 _pid | ||
) public { | ||
bar = IBar(_bar); | ||
volt = IERC20(_volt); | ||
chef = IMasterChef(_chef); | ||
pid = _pid; | ||
} | ||
|
||
function balanceOf(address owner) public view returns (uint256) { | ||
(uint256 xvoltStakedBalance, ) = chef.userInfo(pid, owner); | ||
uint256 xvoltStakedBalancePowah = xvoltStakedBalance.mul(150).div(100); | ||
|
||
uint256 xvoltBalance = bar.balanceOf(owner); | ||
uint256 xvoltBalancePowah = xvoltBalance.mul(2); | ||
|
||
uint256 voltBalance = volt.balanceOf(owner); | ||
|
||
return xvoltStakedBalancePowah.add(xvoltBalancePowah).add(voltBalance); | ||
} | ||
|
||
function allowance(address, address) public pure returns (uint256) { | ||
return 0; | ||
} | ||
|
||
function transfer(address, uint256) public pure returns (bool) { | ||
return false; | ||
} | ||
|
||
function approve(address, uint256) public pure returns (bool) { | ||
return false; | ||
} | ||
|
||
function transferFrom( | ||
address, | ||
address, | ||
uint256 | ||
) public pure returns (bool) { | ||
return false; | ||
} | ||
} |
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,108 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity =0.6.12; | ||
|
||
import "@openzeppelin/contracts/math/SafeMath.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; | ||
|
||
import "../interfaces/IPegswap.sol"; | ||
import "../interfaces/IStablePool.sol"; | ||
import "../interfaces/IFasset.sol"; | ||
|
||
contract FUSDMigration { | ||
using SafeMath for uint256; | ||
using SafeERC20 for IERC20; | ||
|
||
address public fusdV1; | ||
address public fusdV2; | ||
|
||
address public constant usdc = 0x620fd5fa44BE6af63715Ef4E65DDFA0387aD13F5; | ||
address public constant busd = 0x6a5F6A8121592BeCd6747a38d67451B310F7f156; | ||
address public constant usdt = 0xFaDbBF8Ce7D5b7041bE672561bbA99f79c532e10; | ||
IStablePool public stablePool = IStablePool(0x2a68D7C6Ea986fA06B2665d08b4D08F5e7aF960c); | ||
IPegswap public pegswap = IPegswap(0xdfE016328E7BcD6FA06614fE3AF3877E931F7e0a); | ||
|
||
constructor( | ||
address _fusdV1, | ||
address _fusdV2 | ||
) public { | ||
fusdV1 = _fusdV1; | ||
fusdV2 = _fusdV2; | ||
} | ||
|
||
function migrate(uint256 _amountIn) external { | ||
_migrate(_amountIn); | ||
} | ||
|
||
function outputAmount(uint256 _amountIn) public view returns (uint256) { | ||
|
||
} | ||
|
||
function _approveTokenIfNeeded(address token, address spender) private { | ||
if (IERC20(token).allowance(address(this), spender) == 0) { | ||
IERC20(token).safeApprove(spender, uint256(~0)); | ||
} | ||
} | ||
|
||
function _burn(uint256 _amountIn) private { | ||
pegswap.swap(_amountIn, usdc, fusdV1); | ||
} | ||
|
||
function _mint() private { | ||
uint256 busdAmount = IERC20(busd).balanceOf(address(this)); | ||
uint256 usdtAmount = IERC20(usdt).balanceOf(address(this)); | ||
uint256 usdcAmount = IERC20(usdc).balanceOf(address(this)); | ||
|
||
_approveTokenIfNeeded(usdc, fusdV2); | ||
_approveTokenIfNeeded(usdt, fusdV2); | ||
_approveTokenIfNeeded(busd, fusdV2); | ||
|
||
address[] memory inputs = new address[](3); | ||
inputs[0] = usdt; | ||
inputs[1] = busd; | ||
inputs[2] = usdc; | ||
|
||
uint256[] memory amounts = new uint256[](3); | ||
amounts[0] = usdtAmount; | ||
amounts[1] = busdAmount; | ||
amounts[2] = usdcAmount; | ||
|
||
IFasset(fusdV2).mintMulti( | ||
inputs, | ||
amounts, | ||
0, | ||
msg.sender | ||
); | ||
} | ||
|
||
function _swap(address _from, address _to, uint256 _amountIn) private { | ||
uint256 minAmountOut = stablePool.calculateSwap( | ||
stablePool.getTokenIndex(_from), | ||
stablePool.getTokenIndex(_to), | ||
_amountIn | ||
); | ||
|
||
stablePool.swap( | ||
stablePool.getTokenIndex(_from), | ||
stablePool.getTokenIndex(_to), | ||
_amountIn, | ||
minAmountOut, | ||
block.timestamp + 30000 | ||
); | ||
} | ||
|
||
function _migrate(uint256 _amountIn) private { | ||
IERC20(fusdV1).safeTransferFrom(msg.sender, address(this), _amountIn); | ||
|
||
_burn(_amountIn); | ||
|
||
uint256 usdcAmount = IERC20(usdc).balanceOf(address(this)); | ||
uint256 usdcPortionAmount = usdcAmount.mul(33).div(100); | ||
|
||
_approveTokenIfNeeded(usdc, address(stablePool)); | ||
|
||
_swap(usdc, usdt, usdcPortionAmount); | ||
_swap(usdc, busd, usdcPortionAmount); | ||
|
||
_mint(); | ||
} | ||
} |
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,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.6.12; | ||
|
||
interface IFasset { | ||
function mintMulti( | ||
address[] calldata _inputs, | ||
uint256[] calldata _inputQuantities, | ||
uint256 _minOutputQuantity, | ||
address _recipient | ||
) external returns (uint256 mintOutput); | ||
} |
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,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.6.12; | ||
|
||
interface IPegswap { | ||
function swap(uint256 sourceAmount, address source, address target) external; | ||
} |
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,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.6.12; | ||
|
||
interface IStablePool { | ||
function getTokenIndex(address tokenAddress) external view returns (uint8); | ||
|
||
function calculateSwap( | ||
uint8 tokenIndexFrom, | ||
uint8 tokenIndexTo, | ||
uint256 dx | ||
) external view returns (uint256); | ||
|
||
function swap( | ||
uint8 tokenIndexFrom, | ||
uint8 tokenIndexTo, | ||
uint256 dx, | ||
uint256 minDy, | ||
uint256 deadline | ||
) external returns (uint256); | ||
} |
Oops, something went wrong.