Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pkg/api/staking_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
)

func convertStakingWhalesPool(address tongo.AccountID, w references.WhalesPoolInfo, poolStatus abi.GetStakingStatusResult, poolConfig abi.GetParams_WhalesNominatorResult, apy float64, verified bool, nominators int, stake uint64) oas.PoolInfo {

return oas.PoolInfo{
Address: address.ToRaw(),
Name: w.Name + " " + w.Queue,
TotalAmount: int64(poolStatus.StakeSent),
NominatorsStake: int64(stake),
ValidatorStake: int64(poolStatus.StakeSent) - int64(stake),
Implementation: oas.PoolImplementationTypeWhales,
Apy: apy * float64(10000-poolConfig.PoolFee) / 10000,
Apy: apy,
MinStake: poolConfig.MinStake + poolConfig.DepositFee + poolConfig.ReceiptPrice,
CycleEnd: int64(poolStatus.StakeUntil),
CycleStart: int64(poolStatus.StakeAt),
Expand All @@ -40,7 +39,7 @@ func convertStakingTFPool(p core.TFPool, info addressbook.TFPoolInfo, apy float6
Name: name,
TotalAmount: p.TotalAmount,
Implementation: oas.PoolImplementationTypeTf,
Apy: apy * float64(10000-p.ValidatorShare) / 10000,
Apy: apy,
MinStake: p.MinNominatorStake + 1_000_000_000, //this is not in contract. just hardcoded value from documentation
CycleStart: int64(p.StakeAt),
CycleEnd: int64(p.StakeAt) + 3600*36, //todo: make correct
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/staking_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ func (h *Handler) GetStakingPoolInfo(ctx context.Context, params oas.GetStakingP
Description: i18n.T(params.AcceptLanguage.Value, i18n.C{MessageID: "poolImplementationDescription", TemplateData: map[string]interface{}{"Deposit": poolConfig.MinStake / 1_000_000_000}}),
URL: references.WhalesPoolImplementationsURL,
},
Pool: convertStakingWhalesPool(pool.ID, w, poolStatus, poolConfig, h.stats.GetAPY(), true, nominators, stake),
Pool: convertStakingWhalesPool(pool.ID, w, poolStatus, poolConfig, h.stats.GetPoolAPY(), true, nominators, stake),
}, nil
}
lPool, err := h.storage.GetLiquidPool(ctx, pool.ID)
if err == nil {
info, _ := h.addressBook.GetAddressInfoByAddress(lPool.Address)
lPool.Name = info.Name
lPool.APY = h.stats.GetAPY()
lPool.APY = h.stats.GetPoolAPY()
config, err := h.storage.GetLastConfig(ctx)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -85,7 +85,7 @@ func (h *Handler) GetStakingPoolInfo(ctx context.Context, params oas.GetStakingP
Description: i18n.T(params.AcceptLanguage.Value, i18n.C{MessageID: "poolImplementationDescription", TemplateData: map[string]interface{}{"Deposit": p.MinNominatorStake / 1_000_000_000}}),
URL: references.TFPoolImplementationsURL,
},
Pool: convertStakingTFPool(p, info, h.stats.GetAPY()),
Pool: convertStakingTFPool(p, info, h.stats.GetPoolAPY()),
}, nil
}

Expand Down Expand Up @@ -114,7 +114,7 @@ func (h *Handler) GetStakingPools(ctx context.Context, params oas.GetStakingPool
var minTF, minWhales int64
for _, p := range tfPools {
info, _ := h.addressBook.GetTFPoolInfo(p.Address)
apy := h.stats.GetAPY()
apy := h.stats.GetPoolAPY()
pool := convertStakingTFPool(p, info, apy)
if minTF == 0 || pool.MinStake < minTF {
minTF = pool.MinStake
Expand All @@ -138,7 +138,7 @@ func (h *Handler) GetStakingPools(ctx context.Context, params oas.GetStakingPool
if err != nil {
continue
}
apy := h.stats.GetAPY()
apy := h.stats.GetPoolAPY()
pool := convertStakingWhalesPool(k, w, poolStatus, poolConfig, apy, true, nominatorsCount, stake)
if minWhales == 0 || pool.MinStake < minWhales {
minWhales = pool.MinStake
Expand Down
9 changes: 5 additions & 4 deletions pkg/rewards/service/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

const maxRounds = 101
const defaultAPY = 0.22
const poolAPYMul = 76.02

var errServiceUnavailable = errors.New("Service Unavailable")

Expand All @@ -37,17 +38,17 @@ func NewStats(options ...liteapi.Option) *Stats {
return res
}

func (s *Stats) GetAPY() float64 {
func (s *Stats) GetPoolAPY() float64 {
s.mu.RLock()
defer s.mu.RUnlock()
timeNow := time.Now()
for i := len(s.rounds); i != 0; i-- {
if s.rounds[i-1].EndTime().Before(timeNow) {
// latest completed round
return s.rounds[i-1].APYOrDefault(defaultAPY) * 100
return s.rounds[i-1].APYOrDefault(defaultAPY) * poolAPYMul
}
}
return defaultAPY * 100
return defaultAPY * poolAPYMul
}

func (s *Stats) GetRewardsStats() (*oas.RewardsStats, error) {
Expand Down Expand Up @@ -88,7 +89,7 @@ func (s *Stats) GetStakingPoolHistory(limit int) (*oas.GetStakingPoolHistoryOK,
if v.EndTime().Before(timeNow) {
// round is completed
apy = append(apy, oas.ApyHistory{
Apy: v.APYOrDefault(defaultAPY) * 100,
Apy: v.APYOrDefault(defaultAPY) * poolAPYMul,
Time: int(v.ValidatorsExt.UtimeUntil),
})
}
Expand Down
Loading