getUserPosition method
Get the base and quote token in custodian account by poolId and accountCap.
poolId eg: 0xcaee8e1c046b58e55196105f1436a2337dcaa0c340a7a8c8baf65e4afb8823a4
accountCap eg: 0x6f699fef193723277559c8f499ca3706121a65ac96d273151b8e52deb29135d3. If not provided, this.accountCap will be used.
Implementation
Future<UserPosition> getUserPosition({
required String poolId,
String? accountCap
}) async {
final txb = TransactionBlock();
final cap = _checkAccountCap(accountCap);
final typeArgs = await getPoolTypeArgs(poolId);
txb.moveCall(
"$PACKAGE_ID::$MODULE_CLOB::account_balance",
typeArguments: typeArgs,
arguments: [txb.object(normalizeSuiObjectId(poolId)), txb.object(cap)],
);
final resp = await suiClient.devInspectTransactionBlock(
currentAddress,
txb,
);
final returnValues = resp.results![0].returnValues as List;
final values = returnValues.map((item) => int.parse(deepbookBCS.de('u64', Uint8List.fromList((item[0] as List).cast<int>()))));
final [availableBaseAmount, lockedBaseAmount, availableQuoteAmount, lockedQuoteAmount] = values.toList();
return UserPosition(
availableBaseAmount,
lockedBaseAmount,
availableQuoteAmount,
lockedQuoteAmount,
);
}