I have a common problem while converting a 18 decimal WMatic to a 6 decimal USDC price on polygon mainnet. I have the following scenario:
I took a flash loan of 70 WMatic from Aave. I deposited that 70 WMatic + 30 WMatic (from my wallet) to a lending platform like Compound III. After successfully depositing to Compound III, I want to borrow some USDC based on my collateral (Compound III doesn't allow borrowing & deposit of the same token), which I will swap to WMatic to payback the flash loan (with some fees).
So my question here is how can I calculate the exact amount of USDC I should borrow to successfully payback the flash loan in solidity?
I have tried it several times but end up calculating wrong amount in solidity.