dsa-connectors/contracts/mainnet/connectors/yearn_v2/main.sol

87 lines
2.9 KiB
Solidity
Raw Normal View History

2021-08-23 21:35:06 +00:00
pragma solidity ^0.7.0;
/**
* @title Yearn V2.
* @dev Vaults & yield.
*/
import { TokenInterface } from "../../common/interfaces.sol";
import { Basic } from "../../common/basic.sol";
import { Events } from "./events.sol";
import { YearnV2Interface } from "./interface.sol";
abstract contract YearnResolver is Events, Basic {
/**
* @dev Deposit funds in the vault, issuing shares to recipient.
2021-08-23 21:35:31 +00:00
* @notice This will deposit funds to a specific Yearn Vault.
2021-08-23 21:35:06 +00:00
* @param vault The address of the vault to deposit funds into.
* @param amt The amount of tokens to deposit.
2021-09-02 08:00:55 +00:00
* @param getId ID to retrieve amt.
2021-08-23 21:35:06 +00:00
* @param setId ID stores the amount of shares received.
*/
function deposit(
address vault,
uint256 amt,
uint256 getId,
uint256 setId
2021-08-23 21:35:31 +00:00
) external payable returns (string memory _eventName, bytes memory _eventParam) {
2021-08-23 21:35:06 +00:00
uint _amt = getUint(getId, amt);
YearnV2Interface yearn = YearnV2Interface(vault);
2021-08-23 21:35:31 +00:00
2021-08-23 21:35:06 +00:00
address want = yearn.token();
2021-09-07 11:34:54 +00:00
bool iswETH = want == wethAddr;
2021-08-23 21:35:06 +00:00
TokenInterface tokenContract = TokenInterface(want);
2021-09-07 11:34:54 +00:00
if (iswETH) {
2021-09-07 08:04:51 +00:00
_amt = _amt == uint(-1) ? address(this).balance : _amt;
2021-09-07 11:34:54 +00:00
convertEthToWeth(iswETH, tokenContract, _amt);
2021-09-07 08:04:51 +00:00
} else {
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
}
2021-08-23 21:35:06 +00:00
approve(tokenContract, vault, _amt);
uint256 _shares = yearn.deposit(_amt, address(this));
setUint(setId, _shares);
2021-09-02 08:00:55 +00:00
_eventName = "LogDeposit(address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(vault, _shares, _amt, getId, setId);
2021-08-23 21:35:06 +00:00
}
/**
* @dev Withdraw shares from the vault.
2021-08-23 21:35:31 +00:00
* @notice This will withdraw the share from a specific Yearn Vault.
2021-08-23 21:35:06 +00:00
* @param vault The address of the vault to withdraw shares from.
* @param amt The amount of shares to withdraw.
2021-09-02 08:00:55 +00:00
* @param getId ID to retrieve amt.
2021-08-23 21:35:06 +00:00
* @param setId ID stores the amount want token redeemed.
*/
function withdraw(
address vault,
uint256 amt,
uint256 getId,
uint256 setId
2021-08-23 21:35:31 +00:00
) external payable returns (string memory _eventName, bytes memory _eventParam) {
2021-08-23 21:35:06 +00:00
uint _amt = getUint(getId, amt);
2021-09-07 08:04:51 +00:00
YearnV2Interface vault = YearnV2Interface(vault);
2021-08-23 21:35:06 +00:00
2021-09-07 08:04:51 +00:00
_amt = _amt == uint(-1) ? vault.balanceOf(address(this)) : _amt;
uint256 _wantRedeemed = vault.withdraw(_amt, address(this));
2021-08-23 21:35:06 +00:00
setUint(setId, _wantRedeemed);
2021-09-07 08:04:51 +00:00
TokenInterface tokenContract = TokenInterface(vault.token());
bool isWEth = vault.token() == wethAddr;
convertWethToEth(isWEth, tokenContract, _amt);
2021-09-02 08:00:55 +00:00
_eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(vault, _amt, _wantRedeemed, getId, setId);
2021-08-23 21:35:06 +00:00
}
}
contract ConnectV2YearnV2 is YearnResolver {
string public constant name = "YearnV2-v1.0";
}