swapExactQuoteForBase method

Future<TransactionBlock> swapExactQuoteForBase({
  1. required String poolId,
  2. required dynamic tokenObjectIn,
  3. required int amountIn,
  4. required String currentAddress,
  5. int? clientOrderId,
  6. TransactionBlock? txb,
})

Swap exact quote for base.

poolId Object id of pool, created after invoking createPool.

tokenObjectIn Object id of the token to swap.

amountIn amount of token to buy or sell.

currentAddress current user address.

clientOrderId a client side defined order id for bookkeeping purpose, eg: "1" , "2", ... If omitted, the sdk will assign an increasing number starting from 0. But this number might be duplicated if you are using multiple sdk instances

Implementation

/// assign an increasing number starting from 0. But this number might be duplicated if you are using multiple sdk instances
	Future<TransactionBlock> swapExactQuoteForBase({
		required String poolId,
		required TransactionObjectInput tokenObjectIn,
		required int amountIn, // quantity of USDC
		required String currentAddress,
		int? clientOrderId,
		TransactionBlock? txb
	}) async {
  txb ??= TransactionBlock();
		// in this case, we assume that the tokenIn--tokenOut always exists.
		final resp = txb.moveCall(
			"$PACKAGE_ID::$MODULE_CLOB::swap_exact_quote_for_base",
			typeArguments: await getPoolTypeArgs(poolId),
			arguments: [
				txb.object(poolId),
				txb.pureInt(clientOrderId ?? _nextClientOrderId()),
				txb.object(_checkAccountCap()),
				txb.pureInt(amountIn),
				txb.object(SUI_CLOCK_OBJECT_ID),
				tokenObjectIn is String ? txb.object(tokenObjectIn) : tokenObjectIn,
			],
		);
  final base_coin_ret = resp[0];
  final quote_coin_ret = resp[1];
		txb.transferObjects([base_coin_ret], txb.pureAddress(currentAddress));
		txb.transferObjects([quote_coin_ret], txb.pureAddress(currentAddress));
		return txb;
	}