getSwapIn method

Future<(BigInt, BigInt)> getSwapIn(
  1. String pairAddress,
  2. BigInt amountOut,
  3. bool swapForY
)

getSwapIn evaluates the input amount of coin and fee needed to obtain the given output amount of coins

Implementation

Future<(BigInt, BigInt)> getSwapIn(String pairAddress, BigInt amountOut, bool swapForY) async {
  final params = Args();
  params.addString(pairAddress);
  params.addU256(amountOut);
  params.addBool(swapForY);
  const targetFunction = "getSwapIn";
  final functionParameters = params.serialise();
  const maximumGas = GasLimit.MAX_GAS_CALL;
  final smartContracAddress = grpc.isBuildnet ? BuildnetConstants.routerAddress : MainnetConstants.routerAddress;

  final response = await grpc.scReadOnlyCall(
    maximumGas: maximumGas.value / 1e9,
    smartContracAddress: smartContracAddress,
    functionName: targetFunction,
    functionParameters: functionParameters,
  );
  //await grpc.close();

  final responseArg = Args(initialData: response);
  final amountIn = responseArg.nextU256();
  final feesIn = responseArg.nextU256();
  return (amountIn, feesIn);
}