Skip to content

Commit

Permalink
Fix: rosetta zero balance accounts (#8830)
Browse files Browse the repository at this point in the history
* fix: add zero-balance account check to rosetta

* fix: slightly less magic-numbery

---------

Co-authored-by: near-bulldozer[bot] <73298989+near-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and posvyatokum committed Mar 29, 2023
1 parent 4834ce1 commit d04637d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions chain/rosetta-rpc/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,23 @@ where
}
}

/// Zero-balance account (NEP-448)
fn is_zero_balance_account(account: &near_primitives::account::Account) -> bool {
account.storage_usage() <= 770
}

/// Tokens not locked due to staking (=liquid) but reserved for state.
fn get_liquid_balance_for_storage(
account: &near_primitives::account::Account,
storage_amount_per_byte: near_primitives::types::Balance,
) -> near_primitives::types::Balance {
let required_amount =
near_primitives::types::Balance::from(account.storage_usage()) * storage_amount_per_byte;
required_amount.saturating_sub(account.locked())
let staked_for_storage = if is_zero_balance_account(account) {
0
} else {
near_primitives::types::Balance::from(account.storage_usage()) * storage_amount_per_byte
};

staked_for_storage.saturating_sub(account.locked())
}

pub(crate) struct RosettaAccountBalances {
Expand Down

0 comments on commit d04637d

Please sign in to comment.