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

Expose state stake and account balance breakdown #298

Closed
kcole16 opened this issue Apr 28, 2020 · 4 comments · Fixed by #316
Closed

Expose state stake and account balance breakdown #298

kcole16 opened this issue Apr 28, 2020 · 4 comments · Fixed by #316
Assignees

Comments

@kcole16
Copy link

kcole16 commented Apr 28, 2020

Overview

We currently do not expose an account's complete balance breakdown, specifically the "state stake". This is necessary to compute the account's spendable balance.

Both the Wallet and Explorer need to retrieve and display the state stake amount, and it's likely app devs will want the same data (so they can determine if users have a sufficient NEAR balance for a TX).

account/<account_id> RPC example

{
  "result": {
    "amount": "10000000999999952626000000",
    "locked": "0",
    "storage_usage": 387
  }
}

The spendable balance = amount - state_stake

The state stake can be calculated from storage_usage * storage_amount_per_byte.

cost_per_byte can be retrieved from RPC method = EXPERIMENTAL_genesis_config which exposes runtime_config.storage_amount_per_byte

cc @Patrick1904 @vgrichina

@kcole16
Copy link
Author

kcole16 commented Apr 28, 2020

One way to do this is to add this getAccountBalance function to the Account object: https://github.com/near/near-api-js/blob/master/src/account.ts

I'd also change it to just return object with all different "types" of balance instead of taking type argument.

Originally posted by @vgrichina in near/near-wallet#534 (comment)

Should return a balance object with the following:

{
	total: '1000',
	state-staked: '1',
	staked: '100',
	available: ‘899'
}

Or add the above balance param to the AccountState interface

@vgrichina
Copy link
Contributor

Note that there is generally no changes needed in near-api-js to get info from experimental endpoints.

sendJsonRpc can be used directly for such situations:

async sendJsonRpc(method: string, params: any[]): Promise<any> {

@bowenwang1996
Copy link
Contributor

@kcole16 for regular users state stake is usually quite small (something like 0.01), do you think it is still good to display that?

@kcole16
Copy link
Author

kcole16 commented May 7, 2020

@bowenwang1996 We're planning to display as "minimum balance". The total balance will be displayed in most places by default, and spendable will be highlighted on TX and "Send Money" pages.

near/near-wallet#481

@marcinbodnar marcinbodnar self-assigned this May 8, 2020
@marcinbodnar marcinbodnar linked a pull request May 13, 2020 that will close this issue
marcinbodnar added a commit that referenced this issue May 13, 2020
vgrichina added a commit that referenced this issue May 13, 2020
Add account balance to account state (#298)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants