I've one error when, swapping ERC20 -> ERC20 with 0x API, the swap failed , previoulsy was getting an error when fetching from etherscan , but manage it to work by calling contract from abi with brownie. I'm getting this error
dai.approve(zap.address, amount, {"from": user1})
> zap.zapIn(dai.address, crv.address, amount, target.address, dataSwap, {"from": user1})
E brownie.exceptions.VirtualMachineError: revert: Error Swapping Tokens 1
E Trace step -1, program counter 2560:
E File "contracts/zap/Zap.sol", line 85, in Zap._fillQuote:
E uint256 initBal = _getBalance(_toTokens);
E require(approvedTargets[_swapTarget], "Target not Autorizhed");
E (bool success, ) = _swapTarget.call{ value: valueToSend }(swapData);
E require(success, "FAIL");
E uint256 finalBal = _getBalance(_toTokens);
E
E amtBought = finalBal - initBal;
and here is an implementation of the function fillQuote that deals with the 0x-API
function _fillQuote(
address _fromTokens,
address _toTokens,
uint256 _amount,
address _swapTarget,
bytes memory swapData
) internal returns (uint256 amtBought) {
if(_fromTokens == _toTokens) {
return _amount;
}
if(_fromTokens == address(0) && _toTokens == wethTokenAddress) {
IWETH(wethTokenAddress).deposit{value: _amount}();
return _amount;
}
uint256 valueToSend;
if(_fromTokens == address(0)) {
valueToSend = _amount;
} else {
_approveToken(_fromTokens, _swapTarget);
}
uint256 initBal = _getBalance(_toTokens);
require(approvedTargets[_swapTarget], "Target not Autorizhed");
(bool success, ) = _swapTarget.call{ value: valueToSend }(swapData);
require(success, "FAIL");
uint256 finalBal = _getBalance(_toTokens);
amtBought = finalBal - initBal;
}