Skip to content

Commit

Permalink
liquid staking apy
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-tron committed Aug 29, 2023
1 parent 93dcf5e commit 1367d26
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/example.http
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ GET {{host}}/v2/blockchain/config
GET {{host}}/v2/blockchain/messages/81C7CC0C66452E5F1BC26A5D89B2B30AAB49B3B88EC9D035921B7DD3F343276F/transaction

###
GET {{host}}/v2/staking/pool/0:a45b17f28409229b78360e3290420f13e4fe20f90d7e2bf8c4ac6703259e22fa/history
GET {{host}}/v2/staking/pool/EQCkWxfyhAkim3g2DjKQQg8T5P4g-Q1-K_jErGcDJZ4i-vqR/history
4 changes: 2 additions & 2 deletions pkg/api/staking_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions pkg/api/staking_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions pkg/core/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ type LiquidPool struct {
TotalAmount int64
VerifiedSources bool
JettonMaster tongo.AccountID
APY float64
}
2 changes: 2 additions & 0 deletions pkg/litestorage/stacking.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"math"
"math/big"

"github.com/tonkeeper/tongo/tlb"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 1367d26

Please sign in to comment.