getSwapOut method
getSwapOut evaluates the output amount of coin and fee needed to obtain the given input amount of coins
Implementation
Future<(BigInt, BigInt)> getSwapOut(String pairAddress, BigInt amountIn, bool swapForY) async {
final params = Args();
params.addString(pairAddress);
params.addU256(amountIn);
params.addBool(swapForY);
const targetFunction = "getSwapOut";
final functionParameters = params.serialise();
const maximumGas = 1.0;
final smartContracAddress = grpc.isBuildnet ? BuildnetConstants.routerAddress : MainnetConstants.routerAddress;
final response = await grpc.scReadOnlyCall(
maximumGas: maximumGas,
smartContracAddress: smartContracAddress,
functionName: targetFunction,
functionParameters: functionParameters,
);
final responseArg = Args(initialData: response);
final amountOut = responseArg.nextU256();
final feesIn = responseArg.nextU256();
return (amountOut, feesIn);
}