-
Notifications
You must be signed in to change notification settings - Fork 295
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2024, BitGo, Inc. All Rights Reserved. | ||
*/ | ||
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`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. V2: ${tokenConsolidationState['trx'] There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 2025