Contract MyContract
function callApprove(address denomAsset, address spenderForApprove, uint256 amount) public onlyOwner {
IERC20 denomAssetContract = IERC20(denomAsset);//for example: WETH_ADDR
uint256 tokenAmountOfPool = denomAssetContract.balanceOf(address(this));
require(amount <= tokenAmountOfPool, "Not enough token in the Pool!");
bool approveSuccess = denomAssetContract.approve(spenderForApprove, amount);
require(approveSuccess, "Approvement failed!");
}
function callSwap(address denomAsset, address spenderForApprove, uint256 amountIn) public onlyOwner {
/////// how to add this part //////////////////////////
this.callApprove(denomAsset, spenderForApprove, amountIn);
///////////////////////////////////////////////
IMyUni myUniContract = IMyUni(myUniContractAddress);
myUniContract.swapExactInputSingle(amountIn);
}
There is a token belonging to MyContract (example WETH token). This token is requested to be swapped by the owner of MyContract. (example WETH -> UNI). First, we approve with "callApprove", then the "callSwap" function is called and the swap is done successfully.
But in the "callSwap" function, I want to call the "callApprove" function and do the approve process in it. In order not to call them separately. Is it possible?
Thank you in advance.