getMarketPrice method

Future<MarketPrice> getMarketPrice(
  1. String poolId
)

Get the market price {bestBidPrice, bestAskPrice} by pool id poolId.

Implementation

Future<MarketPrice> getMarketPrice(String poolId) async {
		final txb = TransactionBlock();
  final typeArgs = await getPoolTypeArgs(poolId);
		txb.moveCall(
			"$PACKAGE_ID::$MODULE_CLOB::get_market_price",
			typeArguments: typeArgs,
			arguments: [txb.object(poolId)],
		);

  final results = (
			await suiClient.devInspectTransactionBlock(
				currentAddress,
				txb,
			)
		).results;

  final returnValues = results![0].returnValues as List;

  final resp = returnValues.map((val) {
    final opt = deepbookBCS.de('Option<u64>', Uint8List.fromList((val[0] as List).cast<int>()));
    return opt["Some"] != null ? int.tryParse(opt["Some"]) : null;
  }).toList();

  return MarketPrice(
    resp[0],
    resp[1]
  );
	}