This content applies to WaaS 1.0 only. We highly recommend that you upgrade to WaaS 2.0.
Overview
Digital asset platforms and crypto exchanges often deal with the management of a substantial number of wallet addresses. These addresses are assigned to various end-users, each of whom deposits assets by initiating transfers to designated wallet addresses. In such cases, these platforms often conduct token sweeping to consolidate assets dispersed across different wallet addresses into a select few addresses. The rationale behind this approach is to curtail the number of on-chain transactions, thereby minimizing associated gas fees. Token sweeping may be triggered based on the following considerations:- Total amount of assets on a single address
- Frequency (e.g., daily, weekly)
- Current network gas fees
Code Samples
Below are code samples along with corresponding explanations for your references. You can choose to optimize the token sweeping strategy according to your business needs. Token sweeping includes two categories: token sweeping for native tokens and non-native tokens. Java: https://github.com/CoboGlobal/cobo-java-api/blob/main/example/src/main/java/com/cobo/custody/mpc/MPCFundCollection.java Python: https://github.com/CoboGlobal/cobo-python-api/blob/main/mpc_fund_collection.pyToken Sweeping Logics
- Verify if the destination address is valid. If validation fails, please exit directly as the token sweeping will be marked as a failure.
- Query the coin type used for settling transaction fees.
- Consolidate the balances of the queried coin type across all addresses under the MPC Wallet. If the aggregated balance falls below the estimated transaction fees amount, please exit directly as the token sweeping will be marked as a failure.
- Transfer the balances of the specified coin type across all addresses to the destination address. The token sweeping process concludes when the total swept amount reaches the predefined threshold.
- When you sweep native tokens, the amount to sweep is computed based on the total address balances, your pre-set sweeping threshold, and the estimated transaction fees.
- When you sweep non-native tokens, verify first that “fromAddr” has sufficient balance to cover the estimated transaction fees. If insufficient, please transfer funds from “feeAddr” to “fromAddr” to ensure the success of token sweeping.
Feel free to share your feedback to improve our documentation!