mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
Convert WETH to ETH
This commit is contained in:
parent
06c64d0ac5
commit
c1309c7484
|
@ -42,6 +42,17 @@ contract MatchaHelpers is Stores, DSMath {
|
|||
) internal {
|
||||
if (isEth) token.deposit.value(amount)();
|
||||
}
|
||||
|
||||
function convertWethToEth(
|
||||
bool isEth,
|
||||
TokenInterface token,
|
||||
uint256 amount
|
||||
) internal {
|
||||
if (isEth) {
|
||||
token.approve(address(token), amount);
|
||||
token.withdraw(amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
contract MatchaResolver is MatchaHelpers {
|
||||
|
@ -89,17 +100,24 @@ contract MatchaEventResolver is MatchaResolver {
|
|||
contract MatchaResolverHelpers is MatchaEventResolver {
|
||||
function _swap(MatchaData memory matchaData, uint256 setId) internal {
|
||||
TokenInterface _sellAddr = matchaData.sellToken;
|
||||
TokenInterface _buyAddr = matchaData.buyToken;
|
||||
|
||||
uint256 ethAmt;
|
||||
bool isEth = address(_sellAddr) == getEthAddr();
|
||||
if (isEth) {
|
||||
TokenInterface tokenContract = TokenInterface(getWETHAddress());
|
||||
|
||||
if (address(_sellAddr) == getEthAddr()) {
|
||||
ethAmt = matchaData._sellAmt;
|
||||
convertEthToWeth(isEth, TokenInterface(getWETHAddress()), ethAmt);
|
||||
convertEthToWeth(true, tokenContract, ethAmt);
|
||||
} else {
|
||||
TokenInterface(_sellAddr).approve(getMatchaAddress(), matchaData._sellAmt);
|
||||
}
|
||||
|
||||
matchaData._buyAmt = matchaSwap(matchaData, ethAmt);
|
||||
|
||||
if (address(_buyAddr) == getEthAddr()) {
|
||||
convertWethToEth(true, tokenContract, matchaData._buyAmt);
|
||||
}
|
||||
|
||||
setUint(setId, matchaData._buyAmt);
|
||||
|
||||
emitLogSwap(matchaData, setId);
|
||||
|
|
Loading…
Reference in New Issue
Block a user