mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
feat: update ERC4626 Polygon
This commit is contained in:
parent
4dcd91b1e8
commit
9175ffb23f
|
@ -5,7 +5,6 @@ contract Events {
|
||||||
event LogDeposit(
|
event LogDeposit(
|
||||||
address indexed token,
|
address indexed token,
|
||||||
uint256 underlyingAmt,
|
uint256 underlyingAmt,
|
||||||
uint256 minSharesPerToken,
|
|
||||||
uint256 sharesReceieved,
|
uint256 sharesReceieved,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -14,8 +13,7 @@ contract Events {
|
||||||
event LogMint(
|
event LogMint(
|
||||||
address indexed token,
|
address indexed token,
|
||||||
uint256 shareAmt,
|
uint256 shareAmt,
|
||||||
uint256 maxTokenPerShares,
|
uint256 tokensDeposited,
|
||||||
uint256 tokensDeducted,
|
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
@ -23,7 +21,6 @@ contract Events {
|
||||||
event LogWithdraw(
|
event LogWithdraw(
|
||||||
address indexed token,
|
address indexed token,
|
||||||
uint256 underlyingAmt,
|
uint256 underlyingAmt,
|
||||||
uint256 maxSharesPerToken,
|
|
||||||
uint256 sharedBurned,
|
uint256 sharedBurned,
|
||||||
address indexed to,
|
address indexed to,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
|
@ -33,7 +30,6 @@ contract Events {
|
||||||
event LogRedeem(
|
event LogRedeem(
|
||||||
address indexed token,
|
address indexed token,
|
||||||
uint256 shareAmt,
|
uint256 shareAmt,
|
||||||
uint256 minTokenPerShares,
|
|
||||||
uint256 underlyingAmtReceieved,
|
uint256 underlyingAmtReceieved,
|
||||||
address to,
|
address to,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title Basic D.
|
* @title Basic D V2.
|
||||||
* @dev Deposit, Mint, Withdraw, & Redeem from ERC4626 DSA.
|
* @dev Deposit, Mint, Withdraw, & Redeem from ERC4626 DSA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -14,19 +14,18 @@ import { Basic } from "../../common/basic.sol";
|
||||||
import { Events } from "./events.sol";
|
import { Events } from "./events.sol";
|
||||||
|
|
||||||
abstract contract BasicConnector is Events, DSMath, Basic {
|
abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Deposit underlying asset to ERC4626 Vault.
|
* @dev Deposit underlying asset to ERC4626 Vault.
|
||||||
* @notice Mints vault shares by depositing exactly amount of underlying assets
|
* @notice Mints vault shares by depositing exactly amount of underlying assets
|
||||||
* @param vaultToken ERC4626 Token address.
|
* @param vaultToken ERC4626 Token address.
|
||||||
* @param underlyingAmt The amount of the underlying asset to deposit. (For max: `uint256(-1)`)
|
* @param underlyingAmt The amount of the underlying asset to deposit. (For max: `uint256(-1)`)
|
||||||
* @param minSharesPerToken The min share rate of deposit. Should always be in 18 decimals.
|
|
||||||
* @param getId ID to retrieve amt.
|
* @param getId ID to retrieve amt.
|
||||||
* @param setId ID stores the amount of tokens deposited.
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
*/
|
*/
|
||||||
function deposit(
|
function deposit(
|
||||||
address vaultToken,
|
address vaultToken,
|
||||||
uint256 underlyingAmt,
|
uint256 underlyingAmt,
|
||||||
uint256 minSharesPerToken,
|
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
@ -41,31 +40,18 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
? _underlyingTokenContract.balanceOf(address(this))
|
? _underlyingTokenContract.balanceOf(address(this))
|
||||||
: _underlyingAmt;
|
: _underlyingAmt;
|
||||||
|
|
||||||
// Returns final amount in token decimals.
|
|
||||||
uint256 _minShares = wmul(minSharesPerToken, _underlyingAmt);
|
|
||||||
|
|
||||||
// Initial share balance
|
|
||||||
uint256 _initialVaultBal = vaultTokenContract.balanceOf(address(this));
|
|
||||||
|
|
||||||
approve(_underlyingTokenContract, vaultToken, _underlyingAmt);
|
approve(_underlyingTokenContract, vaultToken, _underlyingAmt);
|
||||||
|
|
||||||
// Deposit tokens for shares
|
// Deposit tokens for shares
|
||||||
|
uint256 _sharesReceieved =
|
||||||
vaultTokenContract.deposit(_underlyingAmt, address(this));
|
vaultTokenContract.deposit(_underlyingAmt, address(this));
|
||||||
|
|
||||||
uint256 _sharesReceieved = sub(
|
|
||||||
vaultTokenContract.balanceOf(address(this)),
|
|
||||||
_initialVaultBal
|
|
||||||
);
|
|
||||||
|
|
||||||
require(_minShares <= _sharesReceieved, "Less shares received");
|
|
||||||
|
|
||||||
setUint(setId, _sharesReceieved);
|
setUint(setId, _sharesReceieved);
|
||||||
|
|
||||||
_eventName = "LogDeposit(address,uint256,uint256,uint256,uint256,uint256)";
|
_eventName = "LogDeposit(address,uint256,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
vaultToken,
|
vaultToken,
|
||||||
_underlyingAmt,
|
_underlyingAmt,
|
||||||
minSharesPerToken,
|
|
||||||
_sharesReceieved,
|
_sharesReceieved,
|
||||||
getId,
|
getId,
|
||||||
setId
|
setId
|
||||||
|
@ -77,14 +63,12 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
* @notice Mints vault shares by minting exactly amount of underlying assets
|
* @notice Mints vault shares by minting exactly amount of underlying assets
|
||||||
* @param vaultToken ERC4626 Token address.
|
* @param vaultToken ERC4626 Token address.
|
||||||
* @param shareAmt The amount of the share to mint. (For max: `uint256(-1)`)
|
* @param shareAmt The amount of the share to mint. (For max: `uint256(-1)`)
|
||||||
* @param maxTokenPerShares The max underyling token rate of mint. Always in 18 decimals.
|
|
||||||
* @param getId ID to retrieve amt.
|
* @param getId ID to retrieve amt.
|
||||||
* @param setId ID stores the amount of tokens minted.
|
* @param setId ID stores the amount of tokens minted.
|
||||||
*/
|
*/
|
||||||
function mint(
|
function mint(
|
||||||
address vaultToken,
|
address vaultToken,
|
||||||
uint256 shareAmt,
|
uint256 shareAmt,
|
||||||
uint256 maxTokenPerShares,
|
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
@ -95,41 +79,23 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
vaultTokenContract.asset()
|
vaultTokenContract.asset()
|
||||||
);
|
);
|
||||||
|
|
||||||
_shareAmt = _shareAmt == uint256(-1)
|
|
||||||
? vaultTokenContract.balanceOf(address(this))
|
|
||||||
: _shareAmt;
|
|
||||||
|
|
||||||
// Returns final amount in token decimals.
|
|
||||||
uint256 _maxTokens = wmul(maxTokenPerShares, _shareAmt);
|
|
||||||
|
|
||||||
uint256 _underlyingTokenAmount = vaultTokenContract.previewMint(
|
uint256 _underlyingTokenAmount = vaultTokenContract.previewMint(
|
||||||
_shareAmt
|
_shareAmt
|
||||||
);
|
);
|
||||||
|
|
||||||
uint256 _initalUnderlyingBal = underlyingTokenContract.balanceOf(
|
|
||||||
address(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
approve(underlyingTokenContract, vaultToken, _underlyingTokenAmount);
|
approve(underlyingTokenContract, vaultToken, _underlyingTokenAmount);
|
||||||
|
|
||||||
// Mint shares for tokens
|
// Mint shares for tokens
|
||||||
|
uint256 _tokensDeposited =
|
||||||
vaultTokenContract.mint(_shareAmt, address(this));
|
vaultTokenContract.mint(_shareAmt, address(this));
|
||||||
|
|
||||||
uint256 _tokensDeducted = sub(
|
setUint(setId, _tokensDeposited);
|
||||||
_initalUnderlyingBal,
|
|
||||||
underlyingTokenContract.balanceOf(address(this))
|
|
||||||
);
|
|
||||||
|
|
||||||
require(_maxTokens >= _tokensDeducted, "maxTokenPerShares-exceeds");
|
_eventName = "LogMint(address,uint256,uint256,uint256,uint256)";
|
||||||
|
|
||||||
setUint(setId, _shareAmt);
|
|
||||||
|
|
||||||
_eventName = "LogMint(address,uint256,uint256,uint256,uint256,uint256)";
|
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
vaultToken,
|
vaultToken,
|
||||||
_shareAmt,
|
_shareAmt,
|
||||||
maxTokenPerShares,
|
_tokensDeposited,
|
||||||
_tokensDeducted,
|
|
||||||
getId,
|
getId,
|
||||||
setId
|
setId
|
||||||
);
|
);
|
||||||
|
@ -140,7 +106,6 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
* @notice Withdraw vault shares with exactly amount of underlying assets
|
* @notice Withdraw vault shares with exactly amount of underlying assets
|
||||||
* @param vaultToken ERC4626 Token address.
|
* @param vaultToken ERC4626 Token address.
|
||||||
* @param underlyingAmt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
* @param underlyingAmt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
||||||
* @param maxSharesPerToken The max share rate of withdrawn amount. Always send in 18 decimals.
|
|
||||||
* @param to The address of receiver.
|
* @param to The address of receiver.
|
||||||
* @param getId ID to retrieve amt.
|
* @param getId ID to retrieve amt.
|
||||||
* @param setId ID stores the amount of tokens withdrawn.
|
* @param setId ID stores the amount of tokens withdrawn.
|
||||||
|
@ -148,7 +113,6 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
function withdraw(
|
function withdraw(
|
||||||
address vaultToken,
|
address vaultToken,
|
||||||
uint256 underlyingAmt,
|
uint256 underlyingAmt,
|
||||||
uint256 maxSharesPerToken,
|
|
||||||
address payable to,
|
address payable to,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -164,25 +128,16 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
? underlyingTokenContract.balanceOf(address(this))
|
? underlyingTokenContract.balanceOf(address(this))
|
||||||
: _underlyingAmt;
|
: _underlyingAmt;
|
||||||
|
|
||||||
// Returns final amount in token decimals.
|
|
||||||
uint256 _maxShares = wmul(maxSharesPerToken, _underlyingAmt);
|
|
||||||
|
|
||||||
uint256 _initialVaultBal = vaultTokenContract.balanceOf(to);
|
|
||||||
|
|
||||||
// Withdraw tokens for shares
|
// Withdraw tokens for shares
|
||||||
|
uint256 _sharesBurned =
|
||||||
vaultTokenContract.withdraw(_underlyingAmt, to, address(this));
|
vaultTokenContract.withdraw(_underlyingAmt, to, address(this));
|
||||||
|
|
||||||
uint256 _sharesBurned = sub(_initialVaultBal, vaultTokenContract.balanceOf(to));
|
|
||||||
|
|
||||||
require(_maxShares >= _sharesBurned, "maxShares-exceeds");
|
|
||||||
|
|
||||||
setUint(setId, _underlyingAmt);
|
setUint(setId, _underlyingAmt);
|
||||||
|
|
||||||
_eventName = "LogWithdraw(address,uint256,uint256,uint256,address,uint256,uint256)";
|
_eventName = "LogWithdraw(address,uint256,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
vaultToken,
|
vaultToken,
|
||||||
_underlyingAmt,
|
_underlyingAmt,
|
||||||
maxSharesPerToken,
|
|
||||||
_sharesBurned,
|
_sharesBurned,
|
||||||
to,
|
to,
|
||||||
getId,
|
getId,
|
||||||
|
@ -195,7 +150,6 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
* @notice Redeem vault shares with exactly amount of underlying assets
|
* @notice Redeem vault shares with exactly amount of underlying assets
|
||||||
* @param vaultToken ERC4626 Token address.
|
* @param vaultToken ERC4626 Token address.
|
||||||
* @param shareAmt The amount of the token to redeem. (For max: `uint256(-1)`)
|
* @param shareAmt The amount of the token to redeem. (For max: `uint256(-1)`)
|
||||||
* @param minTokenPerShares The min underlying token rate of withdraw. Always in 18 decimals.
|
|
||||||
* @param to The address of receiver.
|
* @param to The address of receiver.
|
||||||
* @param getId ID to retrieve amt.
|
* @param getId ID to retrieve amt.
|
||||||
* @param setId ID stores the amount of tokens redeem.
|
* @param setId ID stores the amount of tokens redeem.
|
||||||
|
@ -204,7 +158,6 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
function redeem(
|
function redeem(
|
||||||
address vaultToken,
|
address vaultToken,
|
||||||
uint256 shareAmt,
|
uint256 shareAmt,
|
||||||
uint256 minTokenPerShares,
|
|
||||||
address payable to,
|
address payable to,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -220,28 +173,16 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
? vaultTokenContract.balanceOf(address(this))
|
? vaultTokenContract.balanceOf(address(this))
|
||||||
: _shareAmt;
|
: _shareAmt;
|
||||||
|
|
||||||
// Returns final amount in token decimals.
|
|
||||||
uint256 _minUnderlyingAmt = wmul(minTokenPerShares, _shareAmt);
|
|
||||||
|
|
||||||
uint256 _initalUnderlyingBal = underlyingTokenContract.balanceOf(to);
|
|
||||||
|
|
||||||
// Redeem tokens for shares
|
// Redeem tokens for shares
|
||||||
|
uint256 _underlyingAmtReceieved =
|
||||||
vaultTokenContract.redeem(_shareAmt, to, address(this));
|
vaultTokenContract.redeem(_shareAmt, to, address(this));
|
||||||
|
|
||||||
uint256 _underlyingAmtReceieved = sub(
|
|
||||||
underlyingTokenContract.balanceOf(to),
|
|
||||||
_initalUnderlyingBal
|
|
||||||
);
|
|
||||||
|
|
||||||
require(_minUnderlyingAmt <= _underlyingAmtReceieved, "_minUnderlyingAmt-exceeds");
|
|
||||||
|
|
||||||
setUint(setId, _shareAmt);
|
setUint(setId, _shareAmt);
|
||||||
|
|
||||||
_eventName = "LogRedeem(address,uint256,uint256,uint256,address,uint256,uint256)";
|
_eventName = "LogRedeem(address,uint256,uint256,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
vaultToken,
|
vaultToken,
|
||||||
_shareAmt,
|
_shareAmt,
|
||||||
minTokenPerShares,
|
|
||||||
_underlyingAmtReceieved,
|
_underlyingAmtReceieved,
|
||||||
to,
|
to,
|
||||||
getId,
|
getId,
|
||||||
|
@ -250,6 +191,6 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ConnectV2BasicERC4626Polygon is BasicConnector {
|
contract ConnectV2BasicERC4626V2Polygon is BasicConnector {
|
||||||
string public constant name = "BASIC-ERC4626-v1.0";
|
string public constant name = "BASIC-ERC4626-v2.0";
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user