Closing Contract Account with Multiple Balances

Contract (logicsig) account with 2 balances: USDC & ALGO.
The ALGO is obviously necessary just for the account to function, and the USDC is the asset being transferred.
When doing an Asset Transfer transaction (makeAssetTransferTxnWithSuggestedParams), the closeRemainderTo refers to the asset in question, if there is any left.
Simultaneous with this I want to move the remaining ALGOs to a “close out” account, i.e. slam dunk the closing of the contract account!
Do I need 2 transactions for this (1) Asset Transfer, followed by (2) Pay transaction for algos ?
Also, any recommendations to make (1) & (2) atomic to ensure it all happens at once?

Hi @pheathwa,

Please keep in mind that CloseReminderTo and AssetCloseTo are two different properties. The first refers just to Payment transactions, the second just to AssetTransfer transactions.

In order to “slam dunk” the account completely you have to execute the following operations in the right order:

  1. An AssetCloseTo, for each ASA opted-in by the Contract Account;
  2. A CloseReminderTo, to completely close the Contract Account;

You can group those transactions in a single Atomic Transfer, in the right order.

My suggestion is: be very careful in allowing those actions on purpose, strictly binding their approval perimeter, otherwise you will expose your contract to unforeseen (and dangerous) behaviours.