-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
2,474 additions
and
6 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,3 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std |
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
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
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 @@ | ||
pragma solidity ^0.8.10; | ||
|
||
interface IAdapter { | ||
function deposit(uint256 amount) external; | ||
|
||
function withdraw(address account, uint256 amount) external; | ||
|
||
function totalAvailableAmount() external returns (uint256); | ||
|
||
function withdrawAll() external returns (uint256); | ||
} |
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,9 @@ | ||
pragma solidity ^0.8.10; | ||
|
||
interface IEarnPool { | ||
function deposit(address account, uint256 gemAmount, uint256 lisUSDAmount) external; | ||
|
||
function withdrawLisUSD(address account, uint256 amount) external returns (uint256); | ||
|
||
function withdrawGem(address account, uint256 amount) external returns (uint256); | ||
} |
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,5 @@ | ||
pragma solidity ^0.8.10; | ||
|
||
interface ILisUSDPool { | ||
function depositFor(address pool, address account, uint256 amount) 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,7 @@ | ||
pragma solidity ^0.8.10; | ||
|
||
interface IPSM { | ||
function buy(uint256 amount) external; | ||
|
||
function sell(uint256 amount) 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,15 @@ | ||
pragma solidity ^0.8.10; | ||
|
||
interface IVBep20Delegate { | ||
function mint(uint256 mintAmount) external returns (uint256); | ||
|
||
function redeem(uint256 redeemTokens) external returns (uint256); | ||
|
||
function exchangeRateStored() external view returns (uint256); | ||
|
||
function accrueInterest() external returns (uint256); | ||
|
||
function borrow(uint256 borrowAmount) external returns (uint256); | ||
|
||
function repayBorrow(uint256 repayAmount) external returns (uint256); | ||
} |
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,7 @@ | ||
pragma solidity ^0.8.10; | ||
|
||
interface IVaultManager { | ||
function deposit(uint256 amount) external; | ||
|
||
function withdraw(address receiver, uint256 amount) 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
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: GPL-3.0-only | ||
pragma solidity ^0.8.10; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
contract MockUSDC is ERC20 { | ||
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) { | ||
uint256 initialSupply = 1e18 * 1e9; | ||
_mint(msg.sender, initialSupply); | ||
} | ||
} |
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,125 @@ | ||
pragma solidity ^0.8.10; | ||
|
||
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
import "../interfaces/ILisUSDPool.sol"; | ||
import "../interfaces/IPSM.sol"; | ||
import "../interfaces/IStakeLisUSDListaDistributor.sol"; | ||
|
||
contract EarnPool is AccessControlUpgradeable, ReentrancyGuardUpgradeable, PausableUpgradeable, UUPSUpgradeable { | ||
using SafeERC20 for IERC20; | ||
|
||
// token => psm | ||
mapping(address => address) public psm; | ||
|
||
address public lisUSDPool; // lisUSD pool address | ||
address public lisUSD; // lisUSD address | ||
|
||
bytes32 public constant MANAGER = keccak256("MANAGER"); // manager role | ||
bytes32 public constant PAUSE = keccak256("PAUSE"); // pause role | ||
|
||
event SetLisUSDPool(address lisUSDPool); | ||
event SetLisUSD(address lisUSD); | ||
|
||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
/** | ||
* @dev initialize contract | ||
* @param _admin admin address | ||
* @param _manager manager address | ||
* @param _lisUSDPool lisUSD pool address | ||
* @param _lisUSD lisUSD address | ||
*/ | ||
function initialize( | ||
address _admin, | ||
address _manager, | ||
address _lisUSDPool, | ||
address _lisUSD | ||
) public initializer { | ||
require(_admin != address(0), "admin cannot be zero address"); | ||
require(_manager != address(0), "manager cannot be zero address"); | ||
require(_lisUSDPool != address(0), "lisUSDPool cannot be zero address"); | ||
require(_lisUSD != address(0), "lisUSD cannot be zero address"); | ||
__AccessControl_init(); | ||
__ReentrancyGuard_init(); | ||
__Pausable_init(); | ||
__UUPSUpgradeable_init(); | ||
|
||
_setupRole(DEFAULT_ADMIN_ROLE, _admin); | ||
_setupRole(MANAGER, _manager); | ||
|
||
lisUSDPool = _lisUSDPool; | ||
lisUSD = _lisUSD; | ||
|
||
emit SetLisUSDPool(_lisUSDPool); | ||
emit SetLisUSD(_lisUSD); | ||
} | ||
|
||
/** | ||
* @dev deposit token to earn pool | ||
* @param amount token amount | ||
*/ | ||
function deposit(address token, uint256 amount) external nonReentrant whenNotPaused { | ||
require(amount > 0, "amount must be greater than zero"); | ||
require(psm[token] != address(0), "psm not set"); | ||
|
||
address account = msg.sender; | ||
// transfer token to earn pool | ||
IERC20(token).safeTransferFrom(account, address(this), amount); | ||
|
||
// convert token to lisUSD by psm | ||
IERC20(token).safeIncreaseAllowance(psm[token], amount); | ||
uint256 before = IERC20(lisUSD).balanceOf(address(this)); | ||
IPSM(psm[token]).sell(amount); | ||
uint256 lisUSDAmount = IERC20(lisUSD).balanceOf(address(this)) - before; | ||
|
||
// deposit lisUSD to lisUSD pool | ||
IERC20(lisUSD).safeIncreaseAllowance(lisUSDPool, lisUSDAmount); | ||
ILisUSDPool(lisUSDPool).depositFor(token, account, lisUSDAmount); | ||
} | ||
|
||
|
||
/** | ||
* @dev pause contract | ||
*/ | ||
function pause() external onlyRole(PAUSE) { | ||
_pause(); | ||
} | ||
|
||
/** | ||
* @dev toggle pause contract | ||
*/ | ||
function togglePause() external onlyRole(DEFAULT_ADMIN_ROLE) { | ||
paused() ? _unpause() : _pause(); | ||
} | ||
|
||
/** | ||
* @dev set psm | ||
* @param _token token address | ||
* @param _psm psm address | ||
*/ | ||
function setPSM(address _token, address _psm) external onlyRole(MANAGER) { | ||
require(_token != address(0), "token cannot be zero address"); | ||
require(_psm != address(0), "psm cannot be zero address"); | ||
require(psm[_token] == address(0), "psm already set"); | ||
psm[_token] = _psm; | ||
} | ||
|
||
/** | ||
* @dev remove psm | ||
* @param _token token address | ||
*/ | ||
function removePSM(address _token) external onlyRole(MANAGER) { | ||
delete psm[_token]; | ||
} | ||
|
||
function _authorizeUpgrade(address newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE) {} | ||
|
||
} |
Oops, something went wrong.