deposit method
Construct transaction block for depositing asset coinId into a pool poolId.
You can omit coinId argument if you are depositing SUI, in which case gas coin will be used.
The quantity to deposit. If omitted, the entire balance of the coin will be deposited
Implementation
/// The [quantity] to deposit. If omitted, the entire balance of the coin will be deposited
Future<TransactionBlock> deposit({
required String poolId,
String? coinId,
int? quantity,
}) async {
final txb = TransactionBlock();
final [baseAsset, quoteAsset] = await getPoolTypeArgs(poolId);
final hasSui =
baseAsset == NORMALIZED_SUI_COIN_TYPE || quoteAsset == NORMALIZED_SUI_COIN_TYPE;
if (coinId == null && !hasSui) {
throw ArgumentError('coinId must be specified if neither baseAsset nor quoteAsset is SUI');
}
final inputCoin = coinId != null ? txb.object(coinId) : txb.gas;
var coin = inputCoin;
if (quantity != null) {
coin = txb.splitCoins(inputCoin, [txb.pureInt(quantity)]).result;
}
final coinType = coinId != null ? await getCoinType(coinId) : NORMALIZED_SUI_COIN_TYPE;
if (coinType != baseAsset && coinType != quoteAsset) {
throw ArgumentError(
"coin $coinId of $coinType type is not a valid asset for pool $poolId, which supports $baseAsset and $quoteAsset",
);
}
final functionName = coinType == baseAsset ? 'deposit_base' : 'deposit_quote';
txb.moveCall(
"$PACKAGE_ID::$MODULE_CLOB::$functionName",
typeArguments: [baseAsset, quoteAsset],
arguments: [txb.object(poolId), coin, txb.object(_checkAccountCap())],
);
return txb;
}