swapTokensForExactMAS method
swapTokensForExactMAS swaps specified input amount of coins to an exact output ammount of MAS coins
Implementation
Future<(String, bool)> swapTokensForExactMAS(BigInt amountIn, BigInt amountOut, List<dynamic> binSteps,
List<dynamic> tokenPath, String toAddress, int deadline) async {
final deadline2 = BigInt.from(DateTime.timestamp().millisecondsSinceEpoch + deadline);
final storageCost = 0.1;
final params = Args();
params.addU256(amountOut);
params.addU256(amountIn);
params.addArray(binSteps, ArrayTypes.U64);
params.addArray(tokenPath, ArrayTypes.STRING);
params.addString(toAddress);
params.addU64(deadline2);
const targetFunction = "swapTokensForExactMAS";
final functionParameters = params.serialise();
final maximumGas = toMAS(BigInt.from(GasLimit.MAX_GAS_CALL.value));
final smartContracAddress = grpc.isBuildnet ? BuildnetConstants.routerAddress : MainnetConstants.routerAddress;
final coins = storageCost;
return await grpc.scCall(
account: grpc.account,
fee: minimumFee,
coins: coins,
maximumGas: maximumGas,
smartContracAddress: smartContracAddress,
functionName: targetFunction,
functionParameters: functionParameters,
);
}