How to get the proper deposit and stake value from Near transactions

63 Views Asked by At

I encountered few transactions in which the deposit and stake value is 0 but the logs in the receipts outcome contains the value like in the below curls and their outputs. And also the logs vary in different formats. So is there a way that we can read the value other than logs or is it in specific format for specific transactions.

1. curl --location 'https://archival-rpc.mainnet.near.org' \
--header 'Content-Type: application/json' \
--data '{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "tx",
  "params": ["93u2H6FGbYM6mYk5RXSbGyyLRAvdYjyz4amwsTnhiWKW",
    "figment.poolv1.near"]
}'

output:
One of the receipt outcome contains deposit and staking amount in the logs as "Depositing and staking 138036500012292937987000000000 to the staking pool @figment.poolv1.near" and another has logs as "logs": [
                        "@35b2e85e2e7add13abcd8ae62998cbfad9bad5bf.lockup.near deposited 138036500012292937987000000000. New unstaked balance is 138036500012292937987000000000",
                        "@35b2e85e2e7add13abcd8ae62998cbfad9bad5bf.lockup.near staking 138036500012292937986999999999. Received 115715686411278637645476809257 new staking shares. Total 1 unstaked balance and 115715686411278637645476809257 staking shares",
                        "Contract total staked balance is 4488289301108624506005510113055. Total number of shares 3762522791029402332011927661381" 
where as in the transction the deposit is 0. So how is the deposit and stake amount considered here.
"receipts_outcome": [
            {
                "block_hash": "3G27wyFhirYRPKCHfNScrvXqA671qyxSwd9Yiegfn4wY",
                "id": "BWvjUbTe5uGRhpnDpskdLaY5EccDDiajfeEcTagofPao",
                "outcome": {
                    "executor_id": "35b2e85e2e7add13abcd8ae62998cbfad9bad5bf.lockup.near",
                    "gas_burnt": 7938224161929,
                    "logs": [
                        "Depositing and staking 138036500012292937987000000000 to the staking pool @figment.poolv1.near"
                    ],
                    "metadata": {
                        "gas_profile": [ {...}],
                        "version": 2
                    },
                    "receipt_ids": [
                        "A46ydubqkjPer6AXy11r7iLAckNFYCp54zhqAJp23FsE",
                        "7ainqcvZ7unfokxRvqz12U67n5EjZpcAXqeAiDTxArN4",
                        "HYg6jq9zsHwrjxMVgXreMXZuBuvf3SyChDVcgw3f9rTp"
                    ],
                    "status": {
                        "SuccessReceiptId": "7ainqcvZ7unfokxRvqz12U67n5EjZpcAXqeAiDTxArN4"
                    },
                    "tokens_burnt": "793822416192900000000"
                },
                {
                "block_hash": "J6Z9otYq4YRR1YLdqA8VGSR54mTN5Zh4Z9RWZBkRgLDV",
                "id": "A46ydubqkjPer6AXy11r7iLAckNFYCp54zhqAJp23FsE",
                "outcome": {
                    "executor_id": "figment.poolv1.near",
                    "gas_burnt": 7261086286830,
                    "logs": [
                        "@35b2e85e2e7add13abcd8ae62998cbfad9bad5bf.lockup.near deposited 138036500012292937987000000000. New unstaked balance is 138036500012292937987000000000",
                        "@35b2e85e2e7add13abcd8ae62998cbfad9bad5bf.lockup.near staking 138036500012292937986999999999. Received 115715686411278637645476809257 new staking shares. Total 1 unstaked balance and 115715686411278637645476809257 staking shares",
                        "Contract total staked balance is 4488289301108624506005510113055. Total number of shares 3762522791029402332011927661381"
                    ],
]


"transaction": {
            "actions": [
                {
                    "FunctionCall": {
                        "args": "eyJhbW91bnQiOiIxMzgwMzY1MDAwMTIyOTI5Mzc5ODcwMDAwMDAwMDAifQ==",
                        "deposit": "0",
                        "gas": 125000000000000,
                        "method_name": "deposit_and_stake"
                    }
                }
            ],
            "hash": "93u2H6FGbYM6mYk5RXSbGyyLRAvdYjyz4amwsTnhiWKW",
            "nonce": 65039991000004,
            "public_key": "ed25519:3yL2QUgQnr9ag5Rzf6QerNDap8iZpChn9qwLoBraCae8",
            "receiver_id": "35b2e85e2e7add13abcd8ae62998cbfad9bad5bf.lockup.near",
            "signature": "ed25519:4RTKEUqbBHtz1ADub7oz3CJ66GzDHHWeQuKfRqBhmyakkC1HcF9iQ71sjycyLjCjbV1vFL2UYiTkpxQQ2fJSJmXn",
            "signer_id": "rw3f1.near"
        },

Next scenario for deposit and stake

2. curl --location 'https://archival-rpc.mainnet.near.org' \
--header 'Content-Type: application/json' \
--data '{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "tx",
  "params": ["2ab2aipyngoQN1THngDZGiVfcARte64Mnt6kcc53bNH8",
    "91d7dd9c829e3921840077e73ea9563075d5be141259c13c86afdb6ac50808b8"]
}'

Output:
Here we get the deposit and stake amount in the transaction as "deposit": "1457607948180000000025115492352" but in the receipts outcome the logs as "logs": [
                        "@91d7dd9c829e3921840077e73ea9563075d5be141259c13c86afdb6ac50808b8 deposited 1457607948180000000025115492352. New unstaked balance is 1457607948180000000025115492352",
                        "@91d7dd9c829e3921840077e73ea9563075d5be141259c13c86afdb6ac50808b8 staking 1457607948180000000025115492351. Received 1347378423901495847144957994347 new staking shares. Total 1 unstaked balance and 1347378423901495847144957994347 staking shares",
                        "Contract total staked balance is 9693282423851816559572635719729. Total number of shares 8960241751555465939681377113579"
                    ]
So what to consider here

"receipts_outcome": [
            {
                "block_hash": "2tdAr2SfKcmzKiKHRdC33wjSzmqeL1ovHf11aSbWgaq6",
                "id": "HobaHNFswkUfmmjpPN4CT98Nncd4yVQtXsTqJjSPZ95p",
                "outcome": {
                    "executor_id": "stake1.poolv1.near",
                    "gas_burnt": 7434758325723,
                    "logs": [
                        "@91d7dd9c829e3921840077e73ea9563075d5be141259c13c86afdb6ac50808b8 deposited 1457607948180000000025115492352. New unstaked balance is 1457607948180000000025115492352",
                        "@91d7dd9c829e3921840077e73ea9563075d5be141259c13c86afdb6ac50808b8 staking 1457607948180000000025115492351. Received 1347378423901495847144957994347 new staking shares. Total 1 unstaked balance and 1347378423901495847144957994347 staking shares",
                        "Contract total staked balance is 9693282423851816559572635719729. Total number of shares 8960241751555465939681377113579"
                    ],
"metadata": {...},
"receipt_ids": [
                        "A9BhCeKxftFeDTD9zqmwMWq1zMpiXZQGarTMRLGFzzjV",
                        "9tNEEDEk4jxVtLqNccbXfWTcNn7oWU67LbyfggXsNsgN",
                        "EpHWzK3BWFN9dNFLoxZUnJF3ghEayhq2otp7ipDCxa79"
                    ],
                    "status": {
                        "SuccessValue": ""
                    },
                    "tokens_burnt": "743475832572300000000"
                },
}

"transaction": {
            "actions": [
                {
                    "FunctionCall": {
                        "args": "",
                        "deposit": "1457607948180000000025115492352",
                        "gas": 100000000000000,
                        "method_name": "deposit_and_stake"
                    }
                }
            ],
            "hash": "2ab2aipyngoQN1THngDZGiVfcARte64Mnt6kcc53bNH8",
            "nonce": 81305150000001,
            "public_key": "ed25519:ApK2g7SKKa4FkuRXM9MbN4aFxgc47JCxrgwmqSN2V6Yo",
            "receiver_id": "stake1.poolv1.near",
            "signature": "ed25519:3pnXDx8ZcTkNSkdFmCbrfimUYU3keXHKdhaEcoinaLFWrktYtHpGPzkQhcNUsm5goCZCNDch7iLXGSwXmC3WRvJp",
            "signer_id": "91d7dd9c829e3921840077e73ea9563075d5be141259c13c86afdb6ac50808b8"
        },

Next scenario for withdraw_all

3. curl --location 'https://archival-rpc.mainnet.near.org' \
--header 'Content-Type: application/json' \
--data '{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "tx",
  "params": ["HcEiiVRcAiU7DNEgDinnEeqX94EtmBFmWzZ5U8ZzDdfs",
    "yes_protocol1.poolv1.near"]
}'

Output:
Here the method is withdraw_all and the recipt outcome has "logs": [
                        "@6a8fe4ea2856cb6fa6d8b94bd413acf928151645cdeebde78198c31f6f8fd89f withdrawing 1995000000000000000000000. New unstaked balance is 0"
                    ], 
and the transaction "deposit": "0" so here do we need to consider that 1995000000000000000000000 has been withdrawn from @6a8fe4ea2856cb6fa6d8b94bd413acf928151645cdeebde78198c31f6f8fd89f 
"receipts_outcome": [
            {
                "block_hash": "D3m5UBWCP3BwPw9n9Nd23HYkxwiiLXRPK3E5bLmEdtoP",
                "id": "6eDx6iAEvZUb7hs1mxyTcjkfADaB8CraD1KrNEA6K8So",
                "outcome": {
                    "executor_id": "yes_protocol1.poolv1.near",
                    "gas_burnt": 7698877967143,
                    "logs": [
                        "@6a8fe4ea2856cb6fa6d8b94bd413acf928151645cdeebde78198c31f6f8fd89f withdrawing 1995000000000000000000000. New unstaked balance is 0"
                    ],

"transaction": {
            "actions": [
                {
                    "FunctionCall": {
                        "args": "e30=",
                        "deposit": "0",
                        "gas": 30000000000000,
                        "method_name": "withdraw_all"
                    }
                }
            ],
            "hash": "HcEiiVRcAiU7DNEgDinnEeqX94EtmBFmWzZ5U8ZzDdfs",
            "nonce": 89440260000004,
            "public_key": "ed25519:8AyUegxHtU5UP7vynLAitygK8Bej2Z9ugbLS1XzHRb9g",
            "receiver_id": "yes_protocol1.poolv1.near",
            "signature": "ed25519:3L7wth4Xrk7mVSSA2uoaozFjMaHQfo859z94crDve6dt6Cw2pk3X8L8urWBd4BxEw1prnVavdurzgqkW5ENSdMCc",
            "signer_id": "6a8fe4ea2856cb6fa6d8b94bd413acf928151645cdeebde78198c31f6f8fd89f"
        },

Even for withdraw there are multiple scenarios and different kind of logs. Please let me know how do we consider them while checking deposit and stake and also the balance for an account.

1

There are 1 best solutions below

0
On

lockup and staking-pool contracts are locked (cannot be changed as there is no full access key on the accounts to redeploy the code), so you can hard-code their behavior. Though, depending on your needs you may want to keep it opaque and keep track of the stake value changes, which would be the most efficient way of tracking staked balances.

Still, you may want to use EXPERIMENTAL_tx_status RPC method (instead of tx to see the intermediate receipts (not only the outcomes), and here is the receipt that you need to look at:

   {
      "predecessor_id": "35b2e85e2e7add13abcd8ae62998cbfad9bad5bf.lockup.near",
      "receipt": {
        "Action": {
          "actions": [
            {
              "FunctionCall": {
                "args": "",
                "deposit": "138036500012292937987000000000",
                "gas": 75000000000000,
                "method_name": "deposit_and_stake"
              }
            }
          ],
          "gas_price": "215659127",
          "input_data_ids": [],
          "output_data_receivers": [
            {
              "data_id": "JCvXHTHwD58CAAMvoo6ku7wGBiqZuM6WyUmRULkSeyqk",
              "receiver_id": "35b2e85e2e7add13abcd8ae62998cbfad9bad5bf.lockup.near"
            }
          ],
          "signer_id": "rw3f1.near",
          "signer_public_key": "ed25519:3yL2QUgQnr9ag5Rzf6QerNDap8iZpChn9qwLoBraCae8"
        }
      },
      "receipt_id": "A46ydubqkjPer6AXy11r7iLAckNFYCp54zhqAJp23FsE",
      "receiver_id": "figment.poolv1.near"
    },

Notice that it goes from the lockup contract to the staking pool contract, and its attached deposit is non-zero, which is used to identify how much NEAR is deposited for stake.

withdraw_all will have an intermediate receipt with a Transfer action with the relevant amount.