Skip to content

Commit

Permalink
update erc4626 for metamorpho
Browse files Browse the repository at this point in the history
  • Loading branch information
furyXsol committed Jan 15, 2024
1 parent ad56081 commit 3a4d38c
Show file tree
Hide file tree
Showing 2 changed files with 346 additions and 7 deletions.
44 changes: 37 additions & 7 deletions contracts/mainnet/connectors/basic-ERC4626/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ abstract contract BasicConnector is Events, DSMath, Basic {
vaultTokenContract.asset()
);

_underlyingAmt = _underlyingAmt == uint256(-1)
? _underlyingTokenContract.balanceOf(address(this))
: _underlyingAmt;
if (_underlyingAmt == uint256(-1)) {
if (address(_underlyingTokenContract) == wethAddr) {
TokenInterface(wethAddr).deposit{value: address(this).balance}();
}
_underlyingAmt = _underlyingTokenContract.balanceOf(address(this));
} else {
if (address(_underlyingTokenContract) == wethAddr) {
TokenInterface(wethAddr).deposit{value: _underlyingAmt}();
}
}

// Returns final amount in token decimals.
uint256 _minShares = wmul(minSharesPerToken, _underlyingAmt);
Expand Down Expand Up @@ -106,6 +113,10 @@ abstract contract BasicConnector is Events, DSMath, Basic {
_shareAmt
);

if (address(underlyingTokenContract) == wethAddr) {
TokenInterface(wethAddr).deposit{value: address(this).balance}();
}

uint256 _initalUnderlyingBal = underlyingTokenContract.balanceOf(
address(this)
);
Expand All @@ -122,6 +133,10 @@ abstract contract BasicConnector is Events, DSMath, Basic {

require(_maxTokens >= _tokensDeducted, "maxTokenPerShares-exceeds");

if (_tokensDeducted > 0 && address(underlyingTokenContract) == wethAddr) {
TokenInterface(wethAddr).withdraw(_tokensDeducted);
}

setUint(setId, _shareAmt);

_eventName = "LogMint(address,uint256,uint256,uint256,uint256,uint256)";
Expand Down Expand Up @@ -160,9 +175,16 @@ abstract contract BasicConnector is Events, DSMath, Basic {
vaultTokenContract.asset()
);

_underlyingAmt = _underlyingAmt == uint256(-1)
? underlyingTokenContract.balanceOf(address(this))
: _underlyingAmt;
if (_underlyingAmt == uint256(-1)) {
if (address(underlyingTokenContract) == wethAddr) {
TokenInterface(wethAddr).deposit{value: address(this).balance}();
}
_underlyingAmt = underlyingTokenContract.balanceOf(address(this));
} else {
if (address(underlyingTokenContract) == wethAddr) {
TokenInterface(wethAddr).deposit{value: _underlyingAmt}();
}
}

// Returns final amount in token decimals.
uint256 _maxShares = wmul(maxSharesPerToken, _underlyingAmt);
Expand Down Expand Up @@ -223,6 +245,10 @@ abstract contract BasicConnector is Events, DSMath, Basic {
// Returns final amount in token decimals.
uint256 _minUnderlyingAmt = wmul(minTokenPerShares, _shareAmt);

if (address(underlyingTokenContract) == wethAddr && to == address(this)) {
TokenInterface(wethAddr).deposit{value: address(this).balance}();
}

uint256 _initalUnderlyingBal = underlyingTokenContract.balanceOf(to);

// Redeem tokens for shares
Expand All @@ -235,6 +261,10 @@ abstract contract BasicConnector is Events, DSMath, Basic {

require(_minUnderlyingAmt <= _underlyingAmtReceieved, "_minUnderlyingAmt-exceeds");

if (_underlyingAmtReceieved > 0 && to == address(this) && address(underlyingTokenContract) == wethAddr) {
TokenInterface(wethAddr).withdraw(_underlyingAmtReceieved);
}

setUint(setId, _shareAmt);

_eventName = "LogRedeem(address,uint256,uint256,uint256,address,uint256,uint256)";
Expand All @@ -251,5 +281,5 @@ abstract contract BasicConnector is Events, DSMath, Basic {
}

contract ConnectV2BasicERC4626 is BasicConnector {
string public constant name = "BASIC-ERC4626-v1.0";
string public constant name = "BASIC-ERC4626-v1.1";
}
Loading

0 comments on commit 3a4d38c

Please sign in to comment.