Loading user balances is vital to understand a user's position in a Friktion volt. This is made non-trivial by the pending deposit/withdrawal epoch system Friktion employs. The following example demonstrates how to understand the balances returned by our SDK
User flow followed by the diff in output of getBalancesForuser() at every step.
1. Epoch Begins
User starts epoch with 15 volt tokens in wallet. They made one claimable pending deposit in the previous epoch for 0.1 SOL. No pending withdrawals. There are 100 volt tokens in circulation and 1 SOL inside the volt. Thus, each volt token is worth 0.01 SOL, 5 volt tokens = 0.05 SOL, 10 volt tokens = 0.1 SOL.
{ totalBalance:0.25,// total # SOL user has in Friktion (e.g 0.001 SOL) normalBalance:0.15,// SOL value of volt tokens in user's wallet pendingDeposits:0.1,// SOL value of users's unclaimed and pending deposits pendingWithdrawals:0.0,// SOL value of user's unclaimed and pending withdrawals mintableShares:0.1,// # of volt tokens user could mint immediately. from the claimable deposit claimableUnderlying:0.0,// SOL value of user's *mintableShares* normFactor:1000000000,// 10^(number of decimals in SOL mint) = 10^9 for SOL, varies depending on deposit token vaultNormFactor:1000000000// generally equivalent to normFactor, but may differ if deposit token was migrated (e.g sollet deprecation)}
2. Initiates Pending Withdrawal
User burns 5 volt tokens to create a pending withdrawal. There are now 95 volt tokens in circulation
Current epoch ends with 0.1 SOL of rewards for the volt. New epoch starts with 1.3 SOL ( 1.0 - 0.05 + 0.25 + 0.1) in the volt. User's pending deposit becomes claimable, pending withdrawal becomes claimable.