From 1367d26c7ab067ef04254d9954a681771ae785ee Mon Sep 17 00:00:00 2001 From: Denis Subbotin Date: Tue, 29 Aug 2023 11:45:35 +0300 Subject: [PATCH] liquid staking apy --- api/example.http | 2 +- pkg/api/staking_converters.go | 4 ++-- pkg/api/staking_handlers.go | 5 ++--- pkg/core/staking.go | 1 + pkg/litestorage/stacking.go | 2 ++ 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api/example.http b/api/example.http index 5582784f..26fe5d9a 100644 --- a/api/example.http +++ b/api/example.http @@ -76,4 +76,4 @@ GET {{host}}/v2/blockchain/config GET {{host}}/v2/blockchain/messages/81C7CC0C66452E5F1BC26A5D89B2B30AAB49B3B88EC9D035921B7DD3F343276F/transaction ### -GET {{host}}/v2/staking/pool/0:a45b17f28409229b78360e3290420f13e4fe20f90d7e2bf8c4ac6703259e22fa/history \ No newline at end of file +GET {{host}}/v2/staking/pool/EQCkWxfyhAkim3g2DjKQQg8T5P4g-Q1-K_jErGcDJZ4i-vqR/history \ No newline at end of file diff --git a/pkg/api/staking_converters.go b/pkg/api/staking_converters.go index 60dd4926..e5c5b0fb 100644 --- a/pkg/api/staking_converters.go +++ b/pkg/api/staking_converters.go @@ -53,7 +53,7 @@ func convertStakingTFPool(p core.TFPool, info addressbook.TFPoolInfo, apy float6 } } -func convertLiquidStaking(p core.LiquidPool, apy float64, cycleStart, cycleEnd uint32) oas.PoolInfo { +func convertLiquidStaking(p core.LiquidPool, cycleStart, cycleEnd uint32) oas.PoolInfo { name := p.Name if name == "" { name = p.Address.ToHuman(true, false) @@ -63,7 +63,7 @@ func convertLiquidStaking(p core.LiquidPool, apy float64, cycleStart, cycleEnd u Name: name, TotalAmount: p.TotalAmount, Implementation: oas.PoolInfoImplementationLiquidTF, - Apy: apy, + Apy: p.APY, MinStake: int64(tongo.OneTON), Verified: p.VerifiedSources, CurrentNominators: 1, diff --git a/pkg/api/staking_handlers.go b/pkg/api/staking_handlers.go index 6be3f3a7..9f67f9fa 100644 --- a/pkg/api/staking_handlers.go +++ b/pkg/api/staking_handlers.go @@ -62,7 +62,7 @@ func (h Handler) GetStakingPoolInfo(ctx context.Context, params oas.GetStakingPo Description: i18n.T(params.AcceptLanguage.Value, i18n.C{MessageID: "poolImplementationDescription", TemplateData: map[string]interface{}{"Deposit": 100}}), URL: references.LiquidImplementationsUrl, }, - Pool: convertLiquidStaking(lPool, h.state.GetAPY(), cycleStart, cycleEnd), + Pool: convertLiquidStaking(lPool, cycleStart, cycleEnd), }, nil } p, err := h.storage.GetTFPool(ctx, poolID) @@ -159,7 +159,7 @@ func (h Handler) GetStakingPools(ctx context.Context, params oas.GetStakingPools for _, p := range liquidPools { info, _ := h.addressBook.GetAddressInfoByAddress(p.Address) p.Name = info.Name - result.Pools = append(result.Pools, convertLiquidStaking(p, h.state.GetAPY(), cycleStart, cycleEnd)) + result.Pools = append(result.Pools, convertLiquidStaking(p, cycleStart, cycleEnd)) } slices.SortFunc(result.Pools, func(a, b oas.PoolInfo) bool { @@ -296,7 +296,6 @@ func (h Handler) GetStakingPoolHistory(ctx context.Context, params oas.GetStakin Time: int(l.CreatedAt), }) prevTime = l.CreatedAt - fmt.Printf("%+v\n", round) } return &result, nil } diff --git a/pkg/core/staking.go b/pkg/core/staking.go index 5695e1ca..8f1c19a1 100644 --- a/pkg/core/staking.go +++ b/pkg/core/staking.go @@ -33,4 +33,5 @@ type LiquidPool struct { TotalAmount int64 VerifiedSources bool JettonMaster tongo.AccountID + APY float64 } diff --git a/pkg/litestorage/stacking.go b/pkg/litestorage/stacking.go index 12bd9105..8cf15a83 100644 --- a/pkg/litestorage/stacking.go +++ b/pkg/litestorage/stacking.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "math" "math/big" "github.com/tonkeeper/tongo/tlb" @@ -201,6 +202,7 @@ func (s *LiteStorage) GetLiquidPool(ctx context.Context, pool tongo.AccountID) ( TotalAmount: p.TotalBalance, VerifiedSources: bytes.Equal(hash, references.TFLiquidPoolCodeHash[:]), JettonMaster: *jettonMaster, + APY: (math.Pow(1+float64(p.InterestRate)/float64(1<<24)*(1-float64(p.GovernanceFee)/float64(1<<24)), 3600*24*366/(1<<16)) - 1) * 100, }, err }