👷 Review update

This commit is contained in:
Thomas Bouder 2021-09-07 10:04:51 +02:00
parent 1a911e508f
commit 90b0a62f47
No known key found for this signature in database
GPG Key ID: 46DDE658A384B046
3 changed files with 25 additions and 7 deletions

View File

@ -2,7 +2,11 @@ pragma solidity ^0.7.0;
interface YearnV2Interface {
function deposit(uint256 amount, address recipient) external returns (uint256);
function withdraw(uint256 maxShares, address recipient) external returns (uint256);
function token() external view returns (address);
function balanceOf(address owner) external view returns (uint256);
}

View File

@ -14,12 +14,14 @@ abstract contract YearnResolver is Events, Basic {
/**
* @dev Deposit funds in the vault, issuing shares to recipient.
* @notice This will deposit funds to a specific Yearn Vault.
* @param token The address of the token to deposit.
* @param vault The address of the vault to deposit funds into.
* @param amt The amount of tokens to deposit.
* @param getId ID to retrieve amt.
* @param setId ID stores the amount of shares received.
*/
function deposit(
address token,
address vault,
uint256 amt,
uint256 getId,
@ -29,11 +31,19 @@ abstract contract YearnResolver is Events, Basic {
YearnV2Interface yearn = YearnV2Interface(vault);
bool isEth = token == ethAddr;
address want = yearn.token();
TokenInterface tokenContract = TokenInterface(want);
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
if (isEth && want == wethAddr) {
_amt = _amt == uint(-1) ? address(this).balance : _amt;
convertEthToWeth(isEth, tokenContract, _amt);
} else {
require(want == token, "incorrect token");
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
}
approve(tokenContract, vault, _amt);
uint256 _shares = yearn.deposit(_amt, address(this));
@ -59,13 +69,17 @@ abstract contract YearnResolver is Events, Basic {
) external payable returns (string memory _eventName, bytes memory _eventParam) {
uint _amt = getUint(getId, amt);
YearnV2Interface yearn = YearnV2Interface(vault);
TokenInterface tokenContract = TokenInterface(vault);
YearnV2Interface vault = YearnV2Interface(vault);
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
uint256 _wantRedeemed = yearn.withdraw(_amt, address(this));
_amt = _amt == uint(-1) ? vault.balanceOf(address(this)) : _amt;
uint256 _wantRedeemed = vault.withdraw(_amt, address(this));
setUint(setId, _wantRedeemed);
TokenInterface tokenContract = TokenInterface(vault.token());
bool isWEth = vault.token() == wethAddr;
convertWethToEth(isWEth, tokenContract, _amt);
_eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(vault, _amt, _wantRedeemed, getId, setId);
}

View File

@ -97,7 +97,7 @@ describe("Yearn", function () {
{
connector: connectorName,
method: "deposit",
args: [DAI_VAULT, amount, 0, setId]
args: [tokens.dai.address, DAI_VAULT, amount, 0, setId]
},
{
connector: connectorName,
@ -124,7 +124,7 @@ describe("Yearn", function () {
{
connector: connectorName,
method: "deposit",
args: [DAI_VAULT, amount, 0, setId]
args: [tokens.dai.address, DAI_VAULT, amount, 0, setId]
}
]