deposit method

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

Deposit amountUsdc (human units, num or decimal String) into the owner's account.

create: true composes first-time funding into ONE PTB: create the account wrapper, deposit into it through the fresh handle, and share it LAST (once shared, by-value use of the handle is over). The wrapper is derived from the transaction SENDER (account_registry::new takes no owner), so owner MUST be the address that signs this transaction — a sponsored/backend signer would silently fund its own fresh account instead. The caller also asserts the account does not exist yet: new ABORTS at the deterministic address if it already exists — no chain read is done here. Gate on your own existence check (wrapperIdFor(owner) + a getObject), or retry without the flag on that abort.

Without create, the sourced coin goes into the existing account's stored balance via the PTB-callable deposit_funds (folds settle → authorize → load → deposit; clock auto-injected). Command order is auth → deposit (auth is a hot potato consumed by the deposit).

Implementation

Transaction deposit(String owner, Object amountUsdc, {bool create = false}) {
  final tx = Transaction();
  final coin =
      tx.coin(_c.cfg.quoteCoinType, usdcToRaw(amountUsdc), useGasCoin: false);
  if (create) {
    accountContract(_c.cfg).createAccountAndDeposit(
      coin: coin,
      coinType: _c.cfg.quoteCoinType,
    )(tx);
  } else {
    authed.depositFunds(
      config: _c._config,
      wrapper: _c.wrapperIdFor(owner),
      coin: coin,
      typeArguments: [_c.cfg.quoteCoinType],
    )(tx);
  }
  return tx;
}