11/**
2- * Copyright 2024 , BitGo, Inc. All Rights Reserved.
2+ * Copyright 2025 , BitGo, Inc. All Rights Reserved.
33 */
44import { BitGoAPI } from '@bitgo/sdk-api' ;
55import { Trx } from '@bitgo/sdk-coin-trx' ;
66import * as fs from 'fs' ;
7+ import BigNumber from 'bignumber.js' ;
78require ( 'dotenv' ) . config ( { path : '../../.env' } ) ;
89
910const bitgo = new BitGoAPI ( {
@@ -16,6 +17,8 @@ bitgo.register(coin, Trx.createInstance);
1617
1718const walletId = '' ;
1819
20+ // This script is used for fetching the amount of TRX that can be consolidated
21+ // specifically for wallets which use gas tank to fund addresses in case of token deposit (we block 36 trx for each unique token that is present in the address)
1922async function main ( ) {
2023 const wallet = await bitgo . coin ( coin ) . wallets ( ) . get ( { id : walletId } ) ;
2124 let prevId = undefined ;
@@ -27,20 +30,31 @@ async function main() {
2730
2831 for ( const { address, balance, needsConsolidation, tokenConsolidationState } of addresses . addresses ) {
2932 const { tokens, spendableBalanceString } = balance ;
30- const usdtBalance = tokens [ 'trx:usdt' ] ?. spendableBalanceString ;
31-
33+ let tokenCounter = 0 ;
3234 console . log ( `Address ${ index } : ${ address } ` ) ;
33- console . log ( 'USDT token balance: ' , usdtBalance || 'Does not have USDT balance ' ) ;
34- console . log ( 'TRX balance: ' , spendableBalanceString ) ;
35+ const trxSpendableBalance = new BigNumber ( spendableBalanceString || '0 ' ) ;
36+ console . log ( 'TRX balance: ' , trxSpendableBalance ) ;
3537
36- if ( usdtBalance > 0 && spendableBalanceString > 36000000 ) {
37- const data = `${ address } , USDT balance: ${ usdtBalance } , TRX balance: ${ spendableBalanceString } , V1: ${ needsConsolidation } , V2: ${ tokenConsolidationState [ 'trx' ] } \n` ;
38- fs . appendFileSync ( 'addresses-with-usdt-balance-and-trx-greater-than-36.txt' , data ) ;
38+ // Process token balances if any
39+ for ( const key in tokens ) {
40+ const tokenSpendableBalance = new BigNumber ( tokens [ key ] ?. spendableBalanceString || '0' ) ;
41+ console . log ( `Token: ${ key } , Token spendable balance: ${ tokenSpendableBalance } ` ) ;
42+ if ( tokenSpendableBalance . isGreaterThan ( 0 ) ) {
43+ tokenCounter += 1 ;
44+ }
3945 }
4046
41- if ( ( ! usdtBalance || usdtBalance <= 0 ) && spendableBalanceString > 1000000 ) {
42- const data = `${ address } , USDT balance: ${ usdtBalance } , TRX balance: ${ spendableBalanceString } , V1: ${ needsConsolidation } , V2: ${ tokenConsolidationState [ 'trx' ] } \n` ;
43- fs . appendFileSync ( 'addresses-without-usdt-and-trx-greater-than-1.txt' , data ) ;
47+ if ( tokenCounter > 0 && trxSpendableBalance . isGreaterThanOrEqualTo ( 0 ) ) {
48+ // This is for enteprises which use gas tank for funding receive addresses with TRX on token deposit
49+ // we block 36 TRX for each unique token that needs to be consolidated and arrive at the amout of TRX that can be consolidated
50+ const trxBalanceThatCanBeConsolidated = BigNumber . max ( trxSpendableBalance . minus ( tokenCounter * 36000000 ) , 0 ) ;
51+ const data = `${ address } , No of tokens: ${ tokenCounter } , TRX balance: ${ trxSpendableBalance } , TRX balance that can be consolidated: ${ trxBalanceThatCanBeConsolidated } , V1 flag: ${ needsConsolidation } , V2 flag: ${ tokenConsolidationState [ 'trx' ] } \n` ;
52+ fs . appendFileSync ( 'addresses-with-token-balance-and-trx-to-be-consolidated.txt' , data ) ;
53+ } else if ( tokenCounter == 0 && trxSpendableBalance . isGreaterThanOrEqualTo ( 0 ) ) {
54+ // if address does not have any tokens and has more than 1 TRX, then we need to subtract 1 TRX from it (min TRX thats left in the address)
55+ const trxBalanceThatCanBeConsolidated = BigNumber . max ( trxSpendableBalance . minus ( 1000000 ) , 0 ) ;
56+ const data = `${ address } , No of tokens: ${ tokenCounter } , TRX balance: ${ trxSpendableBalance } , TRX balance that can be consolidated: ${ trxBalanceThatCanBeConsolidated } , V1 flag: ${ needsConsolidation } , V2 flag: ${ tokenConsolidationState [ 'trx' ] } \n` ;
57+ fs . appendFileSync ( 'addresses-without-token-balance-and-trx-to-be-consolidated.txt' , data ) ;
4458 }
4559
4660 index += 1 ;
0 commit comments