Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: track withdraw amounts #245

Open
joel-u410 opened this issue Jan 9, 2025 · 3 comments
Open

feat: track withdraw amounts #245

joel-u410 opened this issue Jan 9, 2025 · 3 comments

Comments

@joel-u410
Copy link
Contributor

joel-u410 commented Jan 9, 2025

Problem

When there is a withdraw transaction, we cannot see the amount withdrawn by looking at the transaction data.

Example raw data for a withdraw:

{
  "source": "tnam1qpv70mr6mg9nnxwch2zkvp2dvhjxtf4qx5cy0k73",
  "validator": "tnam1q9pt4hukg0ga362jq2slhg4tuf692zqqngzzz54k"
}

Proposed Solution

I think we can assume that the entire available unbond amount is withdrawn. This can be determined by the following:

SELECT sum(raw_amount)
FROM unbonds
WHERE
    address = {{withdraw.source}}
    AND validator_id = (SELECT id FROM validators WHERE namada_address = {{withdraw.validator}})
    AND withdraw_epoch <= {{epoch of block containing withdraw transaction}}

or, in other words, by summing the raw_amount from all the unbonds that would be deleted by repository::pos::remove_withdraws.

I would propose introducing a new table withdraws that records these amounts:

CREATE TABLE withdraws (
    id integer,
    address varchar,
    validator_id integer,
    raw_amount numeric(78,0),
    block_height integer,
    epoch integer,
    inner_transaction_id varchar(64),
);

This way, an application that wishes to understand inner_transactions can look up any withdraw amount.

@Fraccaman @mateuszjasiuk what do you think of this approach? I'll probably work on it next week & send a PR.

@joel-u410 joel-u410 changed the title feat: track withdraws feat: track withdraw amounts Jan 9, 2025
@Fraccaman
Copy link
Member

sounds good, feel free to open a PR, I can review it! we will probably make some changes to the protocol to make this kind of query easier (not in the short future)

@joel-u410
Copy link
Contributor Author

we will probably make some changes to the protocol to make this kind of query easier (not in the short future)

Yes, I was thinking longer term having something like a transaction receipt and/or event logs that can be queried for any transaction would be helpful.

@Fraccaman
Copy link
Member

Yes, I was thinking longer term having something like a transaction receipt and/or event logs that can be queried for any transaction would be helpful.

yeah thats what we are planning!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants