Skip to content
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

tokens --by_acct is ignored, only first address is treated as token #3964

Open
vincentmele opened this issue Feb 15, 2025 · 2 comments
Open

Comments

@vincentmele
Copy link

vincentmele commented Feb 15, 2025

I am trying to lookup the balances of multiple tokens for one wallet address using the "tokens" command, but it appears to not properly use the --by_acct flag.

Version: trueblocks-core v4.2.0, amd64
Operation system: Ubuntu 22.04

Wallet address: 0xca3Fc56d07235E97D11FA85fc9Bada41d6C6a7bc
Token 1 - Resolv USD (USR) - address: 0x66a1E37c9b0eAddca17d3662D6c05F4DECf3e110
Token 2 - YT Ethena USDe 27MAR2025 (YT-USDe-27MAR2025) - address: 0x4A8036EFA1307F1cA82d932C0895faa18dB0c9eE

Retrieve balance of Token 1 for wallet, works as expected:

./trueblocks-core tokens  --fmt json 0x66a1E37c9b0eAddca17d3662D6c05F4DECf3e110 0xca3Fc56d07235E97D11FA85fc9Bada41d6C6a7bc
{
  "data": [
    {
      "address": "0x66a1e37c9b0eaddca17d3662d6c05f4decf3e110",
      "balance": "64327379524875262870",
      "balanceDec": "64.32737952487526287",
      "blockNumber": 21854761,
      "decimals": 18,
      "holder": "0xca3fc56d07235e97d11fa85fc9bada41d6c6a7bc",
      "name": "",
      "symbol": ""
    }
  ]
}

Retrieve balance of Token 2 for wallet, works as expected:

./trueblocks-core tokens --fmt json 0x4A8036EFA1307F1cA82d932C0895faa18dB0c9eE 0xca3Fc56d07235E97D11FA85fc9Bada41d6C6a7bc
{
  "data": [
    {
      "address": "0x4a8036efa1307f1ca82d932c0895faa18db0c9ee",
      "balance": "7265275781813624951445",
      "balanceDec": "7265.275781813624951445",
      "blockNumber": 21854778,
      "decimals": 18,
      "holder": "0xca3fc56d07235e97d11fa85fc9bada41d6c6a7bc",
      "name": "",
      "symbol": ""
    }
  ]
}

Omit --by_acct and use three addresses for tokens command, works as expected

In normal operation the first item in the address_list is assumed to be an ERC20 token contract whose balances are being queried, whereas the remainder of the list is assumed to be addresses on which to report.

./trueblocks-core tokens --fmt json 0x4A8036EFA1307F1cA82d932C0895faa18dB0c9eE 0x66a1E37c9b0eAddca17d3662D6c05F4DECf3e110 0xca3Fc56d07235E97D11FA85fc9Bada41d6C6a7bc
{
  "data": [
    {
      "address": "0x4a8036efa1307f1ca82d932c0895faa18db0c9ee",
      "balance": "0",
      "balanceDec": "0",
      "blockNumber": 21854836,
      "decimals": 18,
      "holder": "0x66a1e37c9b0eaddca17d3662d6c05f4decf3e110",
      "name": "",
      "symbol": ""
    },
    {
      "address": "0x4a8036efa1307f1ca82d932c0895faa18db0c9ee",
      "balance": "7265275781813624951445",
      "balanceDec": "7265.275781813624951445",
      "blockNumber": 21854836,
      "decimals": 18,
      "holder": "0xca3fc56d07235e97d11fa85fc9bada41d6c6a7bc",
      "name": "",
      "symbol": ""
    }
  ]
}

Retrieve balances for both tokens for the wallet, use --by_acct, duplicates result as without flag

In --byAcct mode, all addresses in the address_list are assumed to be ERC20 token contracts, except the final one which is the account whose token balances are reported.

It seems to ignore the --by_acct flag by treating only the first address as the token, and then the last two addresses as wallets for which to look up balances, as the prior example:

./trueblocks-core tokens --by_acct --fmt json 0x4A8036EFA1307F1cA82d932C0895faa18dB0c9eE 0x66a1E37c9b0eAddca17d3662D6c05F4DECf3e110 0xca3Fc56d07235E97D11FA85fc9Bada41d6C6a7bc
{
  "data": [
    {
      "address": "0x4a8036efa1307f1ca82d932c0895faa18db0c9ee",
      "balance": "0",
      "balanceDec": "0",
      "blockNumber": 21854784,
      "decimals": 18,
      "holder": "0x66a1e37c9b0eaddca17d3662d6c05f4decf3e110",
      "name": "",
      "symbol": ""
    },
    {
      "address": "0x4a8036efa1307f1ca82d932c0895faa18db0c9ee",
      "balance": "7265275781813624951445",
      "balanceDec": "7265.275781813624951445",
      "blockNumber": 21854784,
      "decimals": 18,
      "holder": "0xca3fc56d07235e97d11fa85fc9bada41d6c6a7bc",
      "name": "",
      "symbol": ""
    }
  ]
}

Expected result (cannot obtain this)

./trueblocks-core tokens --by_acct --fmt json 0x4A8036EFA1307F1cA82d932C0895faa18dB0c9eE 0x66a1E37c9b0eAddca17d3662D6c05F4DECf3e110 0xca3Fc56d07235E97D11FA85fc9Bada41d6C6a7bc
{
  "data": [
    {
      "address": "0x66a1e37c9b0eaddca17d3662d6c05f4decf3e110",
      "balance": "64327379524875262870",
      "balanceDec": "64.32737952487526287",
      "blockNumber": 21854761,
      "decimals": 18,
      "holder": "0xca3fc56d07235e97d11fa85fc9bada41d6c6a7bc",
      "name": "",
      "symbol": ""
    },
    {
      "address": "0x4a8036efa1307f1ca82d932c0895faa18db0c9ee",
      "balance": "7265275781813624951445",
      "balanceDec": "7265.275781813624951445",
      "blockNumber": 21854784,
      "decimals": 18,
      "holder": "0xca3fc56d07235e97d11fa85fc9bada41d6c6a7bc",
      "name": "",
      "symbol": ""
    }
  ]
}
@tjayrush
Copy link
Member

Thanks for reporting.

That option's docs say,

  -b, --by_acct         consider each address an ERC20 token except the last, whose balance is reported for each token

So it appears to be a bug...

Do you have any interest in trying to debug it? I'm flat out on the next release. If you make a valid PR, I'll merge it for the next release. Otherwise, this will probably get put on a back-log.

The solution is almost certainly in this code: https://github.com/TrueBlocks/trueblocks-core/blob/master/src/apps/chifra/internal/tokens/handle_show.go

which appears to completely ignore the option (called ByAcct).

If you do this, I will incorporate your example into our testing suite (something easier for me to do than you), but you can also try to write some unit testing...

vincentmele added a commit to vincentmele/trueblocks-core that referenced this issue Feb 17, 2025
Fixes Issue TrueBlocks#3964 where `chifra token --by-acct` was not implemented.

Signed-off-by: Vincent Mele <[email protected]>
@vincentmele
Copy link
Author

Thank you for the fast response, and overall for making TrueBlocks.

I've made the changes and the pull request. The examples I give above all still work and I am able to achieve the expected result in the last example. I have also tested a larger number of token contracts via serve api and it also works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants