github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/farm/keeper/earnings.go (about) 1 package keeper 2 3 import ( 4 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 5 "github.com/fibonacci-chain/fbc/x/farm/types" 6 ) 7 8 // GetEarnings gets the earnings info by a given user address and a specific pool name 9 func (k Keeper) GetEarnings( 10 ctx sdk.Context, poolName string, accAddr sdk.AccAddress, 11 ) (types.Earnings, sdk.Error) { 12 var earnings types.Earnings 13 lockInfo, found := k.GetLockInfo(ctx, accAddr, poolName) 14 if !found { 15 return earnings, types.ErrNoLockInfoFound(accAddr.String(), poolName) 16 } 17 18 pool, found := k.GetFarmPool(ctx, poolName) 19 if !found { 20 return earnings, types.ErrNoFarmPoolFound(poolName) 21 } 22 23 // 1.1 Calculate how many provided token & native token have been yielded 24 // between start block height and current height 25 updatedPool, yieldedTokens := k.CalculateAmountYieldedBetween(ctx, pool) 26 27 endingPeriod := k.IncrementPoolPeriod(ctx, poolName, updatedPool.TotalValueLocked, yieldedTokens) 28 rewards := k.calculateRewards(ctx, poolName, accAddr, endingPeriod, lockInfo) 29 30 earnings = types.NewEarnings(ctx.BlockHeight(), lockInfo.Amount, rewards) 31 return earnings, nil 32 }