withdraw method

Transaction withdraw(
  1. String owner,
  2. Object amountUsdc, {
  3. bool toCoinObject = false,
})

Withdraw amountUsdc from the account back to owner. By default the funds land in the owner's USDC address balance (the versionless accumulator) via 0x2::coin::send_funds — no coin-object churn, and they merge into the same balance deposit draws from, closing the loop. Pass toCoinObject: true to instead receive a discrete Coin<T> object (for wallets/explorers that only render coin objects, or to compose the coin further in your own PTB). Either way the underlying withdraw_funds returns the raw Coin<T> — the PTB-callable form that folds settle → authorize → load → withdraw; command order is auth → withdraw.

Implementation

Transaction withdraw(String owner, Object amountUsdc,
    {bool toCoinObject = false}) {
  final tx = Transaction();
  final coin = authed.withdrawFunds(
    config: _c._config,
    wrapper: _c.wrapperIdFor(owner),
    amount: usdcToRaw(amountUsdc),
    typeArguments: [_c.cfg.quoteCoinType],
  )(tx);
  if (toCoinObject) {
    tx.transferObjects([coin], owner);
  } else {
    // The full-length framework address: the TS builder normalizes the
    // target at serialization, the Dart builder keeps it verbatim.
    tx.moveCall(
      '${normalizeSuiAddress('0x2')}::coin::send_funds',
      typeArguments: [_c.cfg.quoteCoinType],
      arguments: [coin, tx.pureAddress(owner)],
    );
  }
  return tx;
}