Skip to content

Commit

Permalink
round withdraws
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-tron committed Oct 13, 2023
1 parent f83d018 commit 9ec6d92
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions pkg/api/staking_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
"github.com/shopspring/decimal"
"github.com/tonkeeper/tongo/ton"
"math"
"net/http"

Expand Down Expand Up @@ -229,34 +231,32 @@ func (h *Handler) GetAccountNominatorsPools(ctx context.Context, params oas.GetA
if _, ok := references.WhalesPools[w.Pool]; !ok {
continue //skip unknown pools
}
result.Pools = append(result.Pools, oas.AccountStakingInfo{
Pool: w.Pool.ToRaw(),
Amount: w.MemberBalance,
PendingDeposit: w.MemberPendingDeposit,
PendingWithdraw: w.MemberPendingWithdraw,
ReadyWithdraw: w.MemberWithdraw,
})
result.Pools = append(result.Pools, convertStaking(w))
}
for _, w := range tfPools {
result.Pools = append(result.Pools, oas.AccountStakingInfo{
Pool: w.Pool.ToRaw(),
Amount: w.MemberBalance,
PendingDeposit: w.MemberPendingDeposit,
PendingWithdraw: w.MemberPendingWithdraw,
ReadyWithdraw: w.MemberWithdraw,
})
result.Pools = append(result.Pools, convertStaking(w))
}
for _, w := range liquidPools {
result.Pools = append(result.Pools, oas.AccountStakingInfo{
Pool: w.Pool.ToRaw(),
Amount: w.MemberBalance,
PendingDeposit: w.MemberPendingDeposit,
PendingWithdraw: w.MemberPendingWithdraw,
ReadyWithdraw: w.MemberWithdraw,
})
result.Pools = append(result.Pools, convertStaking(w))
}
return &result, nil
}
func convertStaking(w core.Nominator) oas.AccountStakingInfo {
return oas.AccountStakingInfo{
Pool: w.Pool.ToRaw(),
Amount: w.MemberBalance,
PendingDeposit: w.MemberPendingDeposit,
PendingWithdraw: roundTons(w.MemberPendingWithdraw),
ReadyWithdraw: w.MemberWithdraw,
}
}

func roundTons(amount int64) int64 {
if amount < int64(ton.OneTON) {
return amount
}
return decimal.New(amount, 0).Round(-7).IntPart()
}

func (h *Handler) GetStakingPoolHistory(ctx context.Context, params oas.GetStakingPoolHistoryParams) (*oas.GetStakingPoolHistoryOK, error) {
poolID, err := tongo.ParseAccountID(params.AccountID)
Expand Down

0 comments on commit 9ec6d92

Please sign in to comment.