-
Notifications
You must be signed in to change notification settings - Fork 31
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
18 changed files
with
1,452 additions
and
45,880 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
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 "dep"] | ||
path = dep | ||
url = https://github.com/Timidan/aave-minimal.git |
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,85 @@ | ||
pragma solidity 0.6.12; | ||
|
||
import {IStaticATokenLM} from "../dep/protocol-v2/contracts/interfaces/IStaticATokenLM.sol"; | ||
import {ILendingPool} from "../dep/protocol-v2/contracts/interfaces/ILendingPool.sol"; | ||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {IStakingFacet} from "./interfaces/IStakingFacet.sol"; | ||
|
||
contract StaticAmGHSTRouter { | ||
ILendingPool public aaveLendingPool = ILendingPool(0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf); | ||
address constant stakingDiamond = 0xA02d547512Bb90002807499F05495Fe9C4C3943f; | ||
IERC20 GHST = IERC20(0x385Eeac5cB85A38A9a07A70c73e0a3271CfB54A7); | ||
address constant amGHST = 0x080b5BF8f360F624628E0fb961F4e67c9e3c7CF1; | ||
address public wamGHSTPool; | ||
uint256 constant MAX_UINT = type(uint256).max; | ||
|
||
constructor(address _wamGhstPoolAddress) public { | ||
wamGHSTPool = _wamGhstPoolAddress; | ||
|
||
//approve lendingpool to spend GHST | ||
GHST.approve(address(aaveLendingPool), MAX_UINT); | ||
|
||
//approve static wrapper contract to spend amGHST | ||
IERC20(amGHST).approve(wamGHSTPool, MAX_UINT); | ||
|
||
//approve stk diamond to spend wAmGhst | ||
IERC20(wamGHSTPool).approve(stakingDiamond, MAX_UINT); | ||
} | ||
|
||
///@notice Allow an address to wrap GHST and automatically deposit resulting wamGHST in the pool | ||
///@notice user can either provide GHST or amGHST directly | ||
///@param _amount Amount of incoming tokens, either GHST or wamGHST | ||
///@param _to Address to stake for | ||
///@param _underlying true if GHST is provided, false if amGHST is provided | ||
function wrapAndDeposit( | ||
uint256 _amount, | ||
address _to, | ||
bool _underlying | ||
) external { | ||
if (_underlying) { | ||
//transfer user GHST | ||
require(GHST.transferFrom(msg.sender, address(this), _amount)); | ||
//convert to amGHST | ||
aaveLendingPool.deposit(address(GHST), _amount, address(this), 0); | ||
} else { | ||
//transfer user amGHST | ||
require(IERC20(amGHST).transferFrom(msg.sender, address(this), _amount)); | ||
} | ||
|
||
//convert to wamGHST | ||
uint256 deposited = IStaticATokenLM(wamGHSTPool).deposit(address(this), _amount, 0, false); | ||
|
||
//forward tokens | ||
IERC20(wamGHSTPool).transfer(_to, deposited); | ||
|
||
//convert to stkWAmGhst on behalf of address(this) | ||
IStakingFacet(stakingDiamond).stakeIntoPoolForUser(wamGHSTPool, deposited, _to); | ||
} | ||
|
||
///@notice Allow an address to withdraw stkwamGHST from the staking pool | ||
///@notice user can either unwrap to amGHST or GHST directly | ||
///@param _amount Amount of tokens to unstake | ||
///@param _to Address to unstake for | ||
///@param _toUnderlying true if amGHST should be converted to GHST before sending back, false if amGHST should be sent back directly | ||
function unwrapAndWithdraw( | ||
uint256 _amount, | ||
address _to, | ||
bool _toUnderlying | ||
) external { | ||
uint256 toWithdraw; | ||
//get user wamGHST by burning stkWamGHST | ||
IStakingFacet(stakingDiamond).withdrawFromPoolForUser(wamGHSTPool, _amount, _to); | ||
//transfer to contract | ||
require(IERC20(wamGHSTPool).transferFrom(_to, address(this), _amount)); | ||
//Convert back to GHST | ||
if (_toUnderlying) { | ||
//convert wamGHST back to amGHST | ||
(, toWithdraw) = IStaticATokenLM(wamGHSTPool).withdraw(address(this), _amount, false); | ||
//convert amGHST to GHST and send directly | ||
aaveLendingPool.withdraw(address(GHST), toWithdraw, _to); | ||
} else { | ||
//withdraw amGHST and send back | ||
IStaticATokenLM(wamGHSTPool).withdraw(_to, _amount, 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
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 @@ | ||
pragma solidity 0.6.12; | ||
pragma experimental ABIEncoderV2; | ||
|
||
interface IStakingFacet { | ||
struct PoolInput { | ||
address _poolAddress; | ||
address _poolReceiptToken; //The receipt token for staking into this pool. | ||
uint256 _rate; | ||
string _poolName; | ||
string _poolUrl; | ||
} | ||
|
||
struct PoolStakedOutput { | ||
address poolAddress; | ||
string poolName; | ||
string poolUrl; | ||
uint256 rate; | ||
uint256 amount; | ||
} | ||
|
||
function addRateManagers(address[] memory rateManagers_) external; | ||
|
||
function bulkFrens(address[] memory _accounts) external view returns (uint256[] memory frens_); | ||
|
||
function bumpEpoch(address _account, uint256 _epoch) external; | ||
|
||
function claimTickets(uint256[] memory _ids, uint256[] memory _values) external; | ||
|
||
function convertTickets(uint256[] memory _ids, uint256[] memory _values) external; | ||
|
||
function currentEpoch() external view returns (uint256); | ||
|
||
function frens(address _account) external view returns (uint256 frens_); | ||
|
||
function getGhstUsdcPoolToken() external view returns (address); | ||
|
||
function getGhstWethPoolToken() external view returns (address); | ||
|
||
function getPoolInfo(address _poolAddress, uint256 _epoch) external view returns (PoolInput memory); | ||
|
||
function getStkGhstUsdcToken() external view returns (address); | ||
|
||
function getStkGhstWethToken() external view returns (address); | ||
|
||
function hasMigrated(address _account) external view returns (bool); | ||
|
||
function initiateEpoch(PoolInput[] memory _pools) external; | ||
|
||
function isRateManager(address account) external view returns (bool); | ||
|
||
function migrateToV2(address[] memory _accounts) external; | ||
|
||
function poolRatesInEpoch(uint256 _epoch) external view returns (PoolStakedOutput[] memory _rates); | ||
|
||
function removeRateManagers(address[] memory rateManagers_) external; | ||
|
||
function stakeGhst(uint256 _ghstValue) external; | ||
|
||
function stakeGhstUsdcPoolTokens(uint256 _poolTokens) external; | ||
|
||
function stakeGhstWethPoolTokens(uint256 _poolTokens) external; | ||
|
||
function stakeIntoPool(address _poolContractAddress, uint256 _amount) external; | ||
|
||
function stakePoolTokens(uint256 _poolTokens) external; | ||
|
||
function withdrawFromPoolForUser( | ||
address _poolContractAddress, | ||
uint256 _amount, | ||
address _sender | ||
) external; | ||
|
||
function stakeIntoPoolForUser( | ||
address _poolContractAddress, | ||
uint256 _amount, | ||
address _sender | ||
) external; | ||
|
||
function staked(address _account) | ||
external | ||
view | ||
returns ( | ||
uint256 ghst_, | ||
uint256 poolTokens_, | ||
uint256 ghstUsdcPoolToken_, | ||
uint256 ghstWethPoolToken_ | ||
); | ||
|
||
function stakedInCurrentEpoch(address _account) external view returns (PoolStakedOutput[] memory _staked); | ||
|
||
function stakedInEpoch(address _account, uint256 _epoch) external view returns (PoolStakedOutput[] memory _staked); | ||
|
||
function ticketCost(uint256 _id) external pure returns (uint256 _frensCost); | ||
|
||
function updateRates(uint256 _currentEpoch, PoolInput[] memory _newPools) external; | ||
|
||
function userEpoch(address _account) external view returns (uint256); | ||
|
||
function withdrawFromPool(address _poolContractAddress, uint256 _amount) external; | ||
|
||
function withdrawGhstStake(uint256 _ghstValue) external; | ||
|
||
function withdrawGhstUsdcPoolStake(uint256 _poolTokens) external; | ||
|
||
function withdrawGhstWethPoolStake(uint256 _poolTokens) external; | ||
|
||
function withdrawPoolStake(uint256 _poolTokens) external; | ||
} |
Oops, something went wrong.