Description
Currently, our swap function only supports "Exact Input" (e.g., I want to sell exactly 100 XLM and get whatever USDC it's worth).
Advanced traders and smart contracts often need "Exact Output" routing (e.g., I need exactly 50 USDC, tell me how much XLM to charge me).
We need to scaffold the mathematical formula for this reverse calculation using the constant product formula.
This is purely a mathematical addition for this issue and won't be hooked into the transfer logic yet.
Requirements
Description
Currently, our swap function only supports "Exact Input" (e.g., I want to sell exactly 100 XLM and get whatever USDC it's worth).
Advanced traders and smart contracts often need "Exact Output" routing (e.g., I need exactly 50 USDC, tell me how much XLM to charge me).
We need to scaffold the mathematical formula for this reverse calculation using the constant product formula.
This is purely a mathematical addition for this issue and won't be hooked into the transfer logic yet.
Requirements
calculate_amount_in(amount_out, reserve_in, reserve_out).numerator = reserve_in * amount_out * 1000anddenominator = (reserve_out - amount_out) * 997.amount_inrequired to execute the trade.