mirror of
https://github.com/galacticship/terra.git
synced 2024-11-09 01:37:51 +00:00
add xastro/astro ratio in astroport staking
This commit is contained in:
parent
b0d2c071c5
commit
4aa9e12c92
@ -1,6 +1,8 @@
|
||||
package astroport
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/galacticship/terra"
|
||||
"github.com/galacticship/terra/cosmos"
|
||||
"github.com/pkg/errors"
|
||||
@ -22,6 +24,45 @@ func NewStaking(querier *terra.Querier) (*Staking, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Staking) TotalShares(ctx context.Context) (decimal.Decimal, error) {
|
||||
var q struct {
|
||||
TotalShares struct{} `json:"total_shares"`
|
||||
}
|
||||
var r decimal.Decimal
|
||||
err := s.QueryStore(ctx, q, &r)
|
||||
if err != nil {
|
||||
return decimal.Zero, errors.Wrap(err, "querying contract")
|
||||
}
|
||||
return terra.XASTRO.ValueFromTerra(r), nil
|
||||
}
|
||||
|
||||
func (s *Staking) TotalDeposit(ctx context.Context) (decimal.Decimal, error) {
|
||||
var q struct {
|
||||
TotalDeposit struct{} `json:"total_deposit"`
|
||||
}
|
||||
var r decimal.Decimal
|
||||
err := s.QueryStore(ctx, q, &r)
|
||||
if err != nil {
|
||||
return decimal.Zero, errors.Wrap(err, "querying contract")
|
||||
}
|
||||
return terra.ASTRO.ValueFromTerra(r), nil
|
||||
}
|
||||
|
||||
func (s *Staking) XASTROPerASTRO(ctx context.Context) (decimal.Decimal, error) {
|
||||
totalShares, err := s.TotalShares(ctx)
|
||||
if err != nil {
|
||||
return decimal.Zero, errors.Wrap(err, "getting total shares")
|
||||
}
|
||||
totalDeposit, err := s.TotalDeposit(ctx)
|
||||
if err != nil {
|
||||
return decimal.Zero, errors.Wrap(err, "getting total deposit")
|
||||
}
|
||||
if totalDeposit.Equals(decimal.Zero) {
|
||||
return decimal.NewFromInt(1), nil
|
||||
}
|
||||
return totalShares.Div(totalDeposit), nil
|
||||
}
|
||||
|
||||
func (s *Staking) NewEnterMessage(sender cosmos.AccAddress, amount decimal.Decimal) (cosmos.Msg, error) {
|
||||
var q struct {
|
||||
Enter struct{} `json:"enter"`
|
||||
|
Loading…
Reference in New Issue
Block a user