Skip to content

feat: add script for fetching TRX balance that can be consolidated #6517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2024, BitGo, Inc. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 2025

*/
import { BitGoAPI } from '@bitgo/sdk-api';
import { Trx } from '@bitgo/sdk-coin-trx';
import * as fs from 'fs';
require('dotenv').config({ path: '../../.env' });

const bitgo = new BitGoAPI({
accessToken: '',
env: 'prod',
});

const coin = 'trx';
bitgo.register(coin, Trx.createInstance);

const walletId = '';

async function main() {
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });
let prevId = undefined;
let index = 1;

do {
const addresses = await wallet.addresses({ includeBalances: true, prevId });
prevId = addresses.nextBatchPrevId;

for (const { address, balance, needsConsolidation, tokenConsolidationState } of addresses.addresses) {
const { tokens, spendableBalanceString } = balance;
const usdtBalance = tokens['trx:usdt']?.spendableBalanceString;

console.log(`Address ${index}: ${address}`);
console.log('USDT token balance: ', usdtBalance || 'Does not have USDT balance');
console.log('TRX balance: ', spendableBalanceString);

if (usdtBalance > 0 && spendableBalanceString > 36000000) {
const data = `${address}, USDT balance: ${usdtBalance}, TRX balance: ${spendableBalanceString}, V1: ${needsConsolidation}, V2: ${tokenConsolidationState['trx']}\n`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V2: ${tokenConsolidationState['trx']
why console v2 flag related to trx and not token, trying to understand the reason

Copy link
Contributor Author

@Vijay-Jagannathan Vijay-Jagannathan Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're only printing the flag states for TRX because we're finding the TRX balance that can be consolidated

if incase there's some TRX that can be consolidated but V2 flag is false, we need to reset, hence TRX

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, my only concern is that if client is having some other supported token, then this won't be able to fetch the correct addresses as more amount will be blocked

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, this was written for a specific case, but we can tweak this to work on any token; can do that as a followup

fs.appendFileSync('addresses-with-usdt-balance-and-trx-greater-than-36.txt', data);
}

if ((!usdtBalance || usdtBalance <= 0) && spendableBalanceString > 1000000) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what list of addresses are you trying to get here? Should we check addresses having no tokens and spendable greater than 1000000?

Copy link
Contributor Author

@Vijay-Jagannathan Vijay-Jagannathan Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for addresses which don't have USDT (this code is specific to a client usecase who had only USDT and TRX, hence we only have these 2 conditions, but can be adapted to other tokens or multiple tokens as well) but TRX

we want this because, we've already checked the addresses which have both USDT and TRX prior

const data = `${address}, USDT balance: ${usdtBalance}, TRX balance: ${spendableBalanceString}, V1: ${needsConsolidation}, V2: ${tokenConsolidationState['trx']}\n`;
fs.appendFileSync('addresses-without-usdt-and-trx-greater-than-1.txt', data);
}

index += 1;
}
} while (prevId !== undefined);
}

main().catch((e) => console.error(e));