Are staking rewards that are calculated every epoch visible somewhere as transactions? if not - how can we compute such transactions?

Viewed 79

I am trying to calculate na IRR (internal rate of return) of all my staking operations, and for this I need all staking deposits, withdrawals, as well as all rewards calculated and awarded by validators at every epoch.

Deposits and withdrawals from the staking contract are easy to find, but I have absolutely no idea where/how to find the rewards.

Can someone put me on the right track? I'm expecting a transaction executed at the end of every epoch or something similar.

UPDATE: The most detailed description of the mechanics that I'm interested in seems to be on the staking-pool contract itself:

https://github.com/near/core-contracts/tree/master/staking-pool

And my understanding is that I could simply track my staked balance per validator from one transaction to another (the internal_ping function seems to be called all the time to distribute rewards).

So here goes the updated question:

What is the methodology of obtaining a time series of 'staking reward cash flows' - shall I simply look up the state of my staked balance on each of the validators that I delegated to for every epoch that I'm interested in, and 'piece together' the flows from the change in the staked balance?

1 Answers

Yes, as stated here you need to "go over each epoch and query the delegated balance for the given account from the staking pool(s), and display the difference between the value from a previous epoch".

You can query the delegated balance for an earlier block using javascript like this:

fetch('https://archival-rpc.mainnet.near.org', {
        method: 'POST',
        headers: {
            'content-type': 'application/json'
        },
        body: JSON.stringify({
            'jsonrpc': '2.0',
            'id': 'dontcare',
            'method': 'query',
            'params': {
                request_type: 'call_function',
                block_id: block_id,
                account_id: 'VALIDATOR_ACCOUNT.poolv1.near',
                method_name: 'get_account_total_balance',
                args_base64: btoa(JSON.stringify({
                    account_id: 'YOUR_ACCOUNT.near'
                }))
            }
        })
    })
Related