-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from Instadapp/erc4626-polygon
Add erc4626 resolver
- Loading branch information
Showing
2 changed files
with
191 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.19; | ||
|
||
interface TokenInterface { | ||
function balanceOf(address) external view returns (uint256); | ||
|
||
function allowance(address owner, address spender) external view returns (uint256); | ||
|
||
function decimals() external view returns (uint256); | ||
|
||
function name() external view returns (string memory); | ||
|
||
function symbol() external view returns (string memory); | ||
} | ||
|
||
interface VaultInterface { | ||
function decimals() external view returns (uint256); | ||
|
||
function name() external view returns (string memory); | ||
|
||
function symbol() external view returns (string memory); | ||
|
||
function asset() external view returns (address); | ||
|
||
function totalAssets() external view returns (uint256); | ||
|
||
function totalSupply() external view returns (uint256); | ||
|
||
function balanceOf(address) external view returns (uint256); | ||
|
||
function allowance(address owner, address spender) external view returns (uint256); | ||
|
||
function nonces(address) external view returns (uint256); | ||
|
||
function convertToShares(uint256 assets) external view returns (uint256); | ||
|
||
function convertToAssets(uint256 shares) external view returns (uint256); | ||
|
||
function previewDeposit(uint256 assets) external view returns (uint256); | ||
|
||
function previewMint(uint256 shares) external view returns (uint256); | ||
|
||
function previewWithdraw(uint256 assets) external view returns (uint256); | ||
|
||
function previewRedeem(uint256 shares) external view returns (uint256); | ||
|
||
function maxDeposit(address) external view returns (uint256); | ||
|
||
function maxMint(address) external view returns (uint256); | ||
|
||
function maxWithdraw(address owner) external view returns (uint256); | ||
|
||
function maxRedeem(address owner) external view returns (uint256); | ||
} |
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,137 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.19; | ||
import "./interfaces.sol"; | ||
|
||
contract Resolver { | ||
|
||
struct VaultData { | ||
bool isToken; | ||
string name; | ||
string symbol; | ||
uint256 decimals; | ||
address asset; | ||
uint256 totalAssets; | ||
uint256 totalSupply; | ||
uint256 convertToShares; | ||
uint256 convertToAssets; | ||
} | ||
|
||
struct UserPosition { | ||
uint256 underlyingBalance; | ||
uint256 vaultBalance; | ||
} | ||
|
||
struct VaultPreview { | ||
uint256 previewDeposit; | ||
uint256 previewMint; | ||
uint256 previewWithdraw; | ||
uint256 previewRedeem; | ||
uint256 decimals; | ||
uint256 underlyingDecimals; | ||
} | ||
|
||
struct MetaMorphoDetails { | ||
uint256 totalCap; | ||
address loanToken; | ||
address collateralToken; | ||
uint256 lltv; | ||
uint256 fee; | ||
bool enabled; // Whether the market is in the withdraw queue | ||
VaultData vaultData; | ||
} | ||
|
||
function getVaultDetails(address[] memory vaultAddresses) public view returns (VaultData[] memory) { | ||
VaultData[] memory _vaultData = new VaultData[](vaultAddresses.length); | ||
for (uint256 i = 0; i < vaultAddresses.length; i++) { | ||
VaultInterface vaultToken = VaultInterface(vaultAddresses[i]); | ||
bool isToken = true; | ||
|
||
try vaultToken.symbol() {} catch { | ||
isToken = false; | ||
continue; | ||
} | ||
|
||
try vaultToken.name() {} catch { | ||
isToken = false; | ||
continue; | ||
} | ||
|
||
try vaultToken.decimals() {} catch { | ||
isToken = false; | ||
continue; | ||
} | ||
|
||
try vaultToken.asset() {} catch { | ||
isToken = false; | ||
continue; | ||
} | ||
|
||
TokenInterface _underlyingToken = TokenInterface(vaultToken.asset()); | ||
|
||
_vaultData[i] = VaultData( | ||
isToken, | ||
vaultToken.name(), | ||
vaultToken.symbol(), | ||
vaultToken.decimals(), | ||
vaultToken.asset(), | ||
vaultToken.totalAssets(), | ||
vaultToken.totalSupply(), | ||
vaultToken.convertToShares(10 ** _underlyingToken.decimals()), // example convertToShares | ||
vaultToken.convertToAssets(10 ** vaultToken.decimals()) // example convertToAssets for 10 ** decimal | ||
); | ||
} | ||
|
||
return _vaultData; | ||
} | ||
|
||
function getPositions(address owner, address[] memory vaultAddress) public view returns (UserPosition[] memory) { | ||
UserPosition[] memory _userPosition = new UserPosition[](vaultAddress.length); | ||
for (uint256 i = 0; i < vaultAddress.length; i++) { | ||
VaultInterface vaultToken = VaultInterface(vaultAddress[i]); | ||
|
||
address _underlyingAddress = vaultToken.asset(); | ||
TokenInterface underlyingToken = TokenInterface(_underlyingAddress); | ||
|
||
_userPosition[i].underlyingBalance = underlyingToken.balanceOf(owner); | ||
_userPosition[i].vaultBalance = vaultToken.balanceOf(owner); | ||
} | ||
|
||
return _userPosition; | ||
} | ||
|
||
function getAllowances(address owner, address[] memory vaultAddresses) public view returns (uint256[] memory) { | ||
uint256[] memory _tokenAllowance = new uint256[](vaultAddresses.length); | ||
|
||
for (uint256 i = 0; i < vaultAddresses.length; i++) { | ||
VaultInterface vaultToken = VaultInterface(vaultAddresses[i]); | ||
_tokenAllowance[i] = vaultToken.allowance(owner, vaultAddresses[i]); | ||
} | ||
|
||
return _tokenAllowance; | ||
} | ||
|
||
function getVaultPreview( | ||
uint256 amount, | ||
address[] memory vaultAddresses | ||
) public view returns (VaultPreview[] memory) { | ||
VaultPreview[] memory _vaultPreview = new VaultPreview[](vaultAddresses.length); | ||
|
||
for (uint256 i = 0; i < vaultAddresses.length; i++) { | ||
VaultInterface vaultToken = VaultInterface(vaultAddresses[i]); | ||
|
||
_vaultPreview[i].previewDeposit = vaultToken.previewDeposit(amount); | ||
_vaultPreview[i].previewMint = vaultToken.previewMint(amount); | ||
_vaultPreview[i].previewWithdraw = vaultToken.previewWithdraw(amount); | ||
_vaultPreview[i].previewRedeem = vaultToken.previewRedeem(amount); | ||
_vaultPreview[i].decimals = vaultToken.decimals(); | ||
TokenInterface _underlyingToken = TokenInterface(vaultToken.asset()); | ||
_vaultPreview[i].underlyingDecimals = _underlyingToken.decimals(); | ||
} | ||
|
||
return _vaultPreview; | ||
} | ||
} | ||
|
||
contract InstaERC4626ResolverPolygon is Resolver { | ||
string public constant name = "ERC4626-Resolver-v1.0"; | ||
} |