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
27 changes: 27 additions & 0 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -11816,6 +11816,33 @@
]
}
},
"/v2/rewards/apy": {
"get": {
"description": "Returns the current TON blockchain APY as a percent based on the latest completed validation round.",
"operationId": "getRewardsApy",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"example": 3.3,
"format": "double",
"type": "number"
}
}
},
"description": "current TON blockchain APY as a percent"
},
"default": {
"$ref": "#/components/responses/Error"
}
},
"summary": "Get current TON blockchain APY",
"tags": [
"Rewards"
]
}
},
"/v2/rewards/round-rewards": {
"get": {
"description": "Computes per-validator and per-nominator reward distribution for a finished validation round using the elector's bonuses value.\n",
Expand Down
18 changes: 18 additions & 0 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3147,6 +3147,24 @@ paths:
$ref: '#/components/schemas/RewardsStats'
'default':
$ref: '#/components/responses/Error'
/v2/rewards/apy:
get:
operationId: getRewardsApy
tags:
- Rewards
summary: Get current TON blockchain APY
description: Returns the current TON blockchain APY as a percent based on the latest completed validation round.
responses:
'200':
description: current TON blockchain APY as a percent
content:
application/json:
schema:
type: number
format: double
example: 3.3
'default':
$ref: '#/components/responses/Error'
components:
parameters:
masterchainSeqno:
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/rewards_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,7 @@ func (h *Handler) GetRoundRewards(ctx context.Context, params oas.GetRoundReward
func (h *Handler) GetRewardsStats(ctx context.Context) (*oas.RewardsStats, error) {
return h.stats.GetRewardsStats()
}

func (h *Handler) GetRewardsApy(ctx context.Context) (float64, error) {
return h.stats.GetAPY(100), nil
}
22 changes: 14 additions & 8 deletions pkg/api/staking_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/tonkeeper/opentonapi/pkg/references"
)

const tonstakersAPYMul = 76.02 // 100% - (validator & governance fee)

func (h *Handler) GetStakingPoolInfo(ctx context.Context, params oas.GetStakingPoolInfoParams) (*oas.GetStakingPoolInfoOK, error) {
pool, err := tongo.ParseAddress(params.AccountID)
if err != nil {
Expand All @@ -39,14 +41,17 @@ 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.GetPoolAPY(), true, nominators, stake),
Pool: convertStakingWhalesPool(pool.ID, w, poolStatus, poolConfig, h.state.GetAPY(), 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.GetPoolAPY()
switch pool.ID {
case references.TonstakersAccountPool:
lPool.APY = h.stats.GetAPY(tonstakersAPYMul)
}
config, err := h.storage.GetLastConfig(ctx)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -85,7 +90,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.GetPoolAPY()),
Pool: convertStakingTFPool(p, info, h.state.GetAPY()),
}, nil
}

Expand Down Expand Up @@ -114,7 +119,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.GetPoolAPY()
apy := h.state.GetAPY()
pool := convertStakingTFPool(p, info, apy)
if minTF == 0 || pool.MinStake < minTF {
minTF = pool.MinStake
Expand All @@ -138,7 +143,7 @@ func (h *Handler) GetStakingPools(ctx context.Context, params oas.GetStakingPool
if err != nil {
continue
}
apy := h.stats.GetPoolAPY()
apy := h.state.GetAPY()
pool := convertStakingWhalesPool(k, w, poolStatus, poolConfig, apy, true, nominatorsCount, stake)
if minWhales == 0 || pool.MinStake < minWhales {
minWhales = pool.MinStake
Expand Down Expand Up @@ -270,13 +275,14 @@ func (h *Handler) GetStakingPoolHistory(ctx context.Context, params oas.GetStaki
if errors.Is(err, core.ErrEntityNotFound) {
return nil, toError(http.StatusNotFound, err)
}
limit := int(params.Limit.Or(100))
if !params.BeforeLt.Set {
return h.stats.GetStakingPoolHistory(limit)
switch pool.ID {
case references.TonstakersAccountPool:
return h.stats.GetStakingPoolHistory(tonstakersAPYMul, int(params.Limit.Value))
}
logAddress := tlb.MsgAddress{SumType: "AddrExtern"}
addr := g.Must(boc.BitStringFromFiftHex("0000000000000000000000000000000000000000000000000000000000000003"))
logAddress.AddrExtern = &addr
limit := int(params.Limit.Or(100))
var beforeLT uint64
if v, ok := params.BeforeLt.Get(); ok {
beforeLT = uint64(v)
Expand Down
80 changes: 80 additions & 0 deletions pkg/oas/oas_client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

135 changes: 135 additions & 0 deletions pkg/oas/oas_handlers_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/oas/oas_operations_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading