-
Notifications
You must be signed in to change notification settings - Fork 46
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
27 changed files
with
843 additions
and
222 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,60 @@ | ||
pragma solidity 0.5.17; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "./LoanTokenLogicStandard.sol"; | ||
|
||
contract LoanTokenLogicLM is LoanTokenLogicStandard { | ||
/** | ||
* @notice deposit into the lending pool and optionally participate at the Liquidity Mining Program | ||
* @param receiver the receiver of the tokens | ||
* @param depositAmount The amount of underlying tokens provided on the loan. | ||
* (Not the number of loan tokens to mint). | ||
* @param useLM if true -> deposit the pool tokens into the Liquidity Mining contract | ||
*/ | ||
function mint(address receiver, uint256 depositAmount, bool useLM) external nonReentrant returns (uint256 minted) { | ||
if(useLM) return _mintWithLM(receiver, depositAmount); | ||
else return _mintToken(receiver, depositAmount); | ||
} | ||
|
||
function _mintWithLM(address receiver, uint256 depositAmount) internal returns (uint256 minted) { | ||
//mint the tokens for the receiver | ||
minted = _mintToken(receiver, depositAmount); | ||
|
||
//transfer the tokens from the receiver to the LM address | ||
_internalTransferFrom(receiver, liquidityMiningAddress, minted, minted); | ||
|
||
//inform the LM mining contract | ||
ILiquidityMining(liquidityMiningAddress).onTokensDeposited(receiver, minted); | ||
} | ||
|
||
/** | ||
* @notice withdraws from the lending pool and optionally retrieves the pool tokens from the | ||
* Liquidity Mining Contract | ||
* @param receiver the receiver of the underlying tokens. note: potetial LM rewards are always sent to the msg.sender | ||
* @param burnAmount The amount of pool tokens to redeem. | ||
* @param useLM if true -> deposit the pool tokens into the Liquidity Mining contract | ||
*/ | ||
function burn(address receiver, uint256 burnAmount, bool useLM) external nonReentrant returns (uint256 redeemed) { | ||
if(useLM) redeemed = _burnFromLM(burnAmount); | ||
else redeemed = _burnToken(burnAmount); | ||
//this needs to be here and not in _burnTokens because of the WRBTC implementation | ||
if (redeemed != 0) { | ||
_safeTransfer(loanTokenAddress, receiver, redeemed, "asset transfer failed"); | ||
} | ||
} | ||
|
||
function _burnFromLM(uint256 burnAmount) internal returns (uint256) { | ||
//withdraw pool tokens and LM rewards to the passed address | ||
ILiquidityMining(liquidityMiningAddress).withdraw(address(this), burnAmount, msg.sender); | ||
//burn the tokens of the msg.sender | ||
return _burnToken(burnAmount); | ||
} | ||
|
||
/** | ||
* @notice sets the liquidity mining contract address | ||
* @param LMAddress the address of the liquidity mining contract | ||
*/ | ||
function setLiquidityMiningAddress(address LMAddress) external onlyOwner { | ||
liquidityMiningAddress = LMAddress; | ||
} | ||
} |
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
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,13 @@ | ||
pragma solidity >=0.5.0 <0.6.0; | ||
|
||
interface ILiquidityMining { | ||
function withdraw( | ||
address _poolToken, | ||
uint256 _amount, | ||
address _user | ||
) external; | ||
|
||
function onTokensDeposited(address _user, uint256 _amount) external; | ||
|
||
function getUserPoolTokenBalance(address _poolToken, address _user) external view returns (uint256); | ||
} |
Oops, something went wrong.