-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new asset proxy to support yearn vault 4.2 (#207)
* contract update for new yearn vault' * linting' * refactor to reduce code duplication * lint * Update contracts/YVaultV4AssetProxy.sol Co-authored-by: Daejun Park <daejunpark@gmail.com> * basic tests * Update contracts/YVaultAssetProxy.sol Co-authored-by: Jonny Rhea <5555162+jrhea@users.noreply.github.com> * natspec returns Co-authored-by: Daejun Park <daejunpark@gmail.com> Co-authored-by: Jonny Rhea <5555162+jrhea@users.noreply.github.com>
- Loading branch information
1 parent
cb909af
commit 42f7d4d
Showing
9 changed files
with
275 additions
and
15 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,58 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// WARNING: This has been validated for yearn vaults version 4.2, do not use for lower or higher | ||
// versions without review | ||
pragma solidity ^0.8.0; | ||
|
||
import "./interfaces/IERC20.sol"; | ||
import "./interfaces/IYearnVault.sol"; | ||
import "./YVaultAssetProxy.sol"; | ||
|
||
/// @author Element Finance | ||
/// @title Yearn Vault Asset Proxy | ||
contract YVaultV4AssetProxy is YVaultAssetProxy { | ||
/// @notice Constructs this contract by calling into the super constructor | ||
/// @param vault_ The yearn v2 vault, must be version 0.4.2 | ||
/// @param _token The underlying token. | ||
/// This token should revert in the event of a transfer failure. | ||
/// @param _name The name of the token created | ||
/// @param _symbol The symbol of the token created | ||
constructor( | ||
address vault_, | ||
IERC20 _token, | ||
string memory _name, | ||
string memory _symbol | ||
) YVaultAssetProxy(vault_, _token, _name, _symbol) {} | ||
|
||
/// @notice Overrides the version checking to check for 0.4.2 instead | ||
/// @param _vault The yearn vault address | ||
/// @dev This function can be overridden by an inheriting upgrade contract | ||
function _versionCheck(IYearnVault _vault) internal override view { | ||
string memory apiVersion = _vault.apiVersion(); | ||
require(_stringEq(apiVersion, "0.4.2"), "Unsupported Version"); | ||
} | ||
|
||
/// @notice Converts an input of shares to it's output of underlying or an input | ||
/// of underlying to an output of shares, using yearn 's deposit pricing | ||
/// @param amount the amount of input, shares if 'sharesIn == true' underlying if not | ||
/// @param sharesIn true to convert from yearn shares to underlying, false to convert from | ||
/// underlying to yearn shares | ||
/// @dev WARNING - Fails for 0.3.2-0.3.5, please only use with 0.4.2 | ||
/// @return The converted output of either underlying or yearn shares | ||
function _yearnDepositConverter(uint256 amount, bool sharesIn) | ||
internal | ||
override | ||
view | ||
returns (uint256) | ||
{ | ||
// Load the yearn price per share | ||
uint256 pricePerShare = vault.pricePerShare(); | ||
// If we are converted shares to underlying | ||
if (sharesIn) { | ||
// If the input is shares we multiply by the price per share | ||
return (pricePerShare * amount) / 10**vaultDecimals; | ||
} else { | ||
// If the input is in underlying we divide by price per share | ||
return (amount * 10**vaultDecimals) / (pricePerShare + 1); | ||
} | ||
} | ||
} |
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,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "./TestYVault.sol"; | ||
|
||
// NOTE - the test y vault uses the formula of 0.4.2 and versions prior to | ||
// 0.3.2, so when we test the YAssetProxyV4 we actually want the same logic | ||
// except that we want to return a diff version. | ||
// The subtly of 0.3.2 - 0.3.5 yearn vaults is tested in the mainnet tests. | ||
|
||
contract TestYVaultV4 is TestYVault { | ||
constructor(address _token, uint8 _decimals) | ||
TestYVault(_token, _decimals) | ||
{} | ||
|
||
function apiVersion() external override pure returns (string memory) { | ||
return ("0.4.2"); | ||
} | ||
} |
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