add WithdrawableRewards method to prism farm

add prism governance contract & xprism_state method
This commit is contained in:
Laurent Le Houerou 2022-04-08 09:10:57 +04:00
parent a7c79b7106
commit 3da7f589eb
3 changed files with 82 additions and 1 deletions

View File

@ -1,6 +1,8 @@
package prism
import (
"context"
"github.com/galacticship/terra"
"github.com/galacticship/terra/cosmos"
"github.com/pkg/errors"
@ -21,6 +23,23 @@ func NewFarm(querier *terra.Querier) (*Farm, error) {
}, nil
}
func (f *Farm) WithdrawableRewards(ctx context.Context, address cosmos.AccAddress) (decimal.Decimal, error) {
var q struct {
VestingStatus struct {
StakerAddr string `json:"staker_addr"`
} `json:"vesting_status"`
}
q.VestingStatus.StakerAddr = address.String()
var r struct {
Withdrawable decimal.Decimal `json:"withdrawable"`
}
err := f.QueryStore(ctx, q, &r)
if err != nil {
return decimal.Zero, errors.Wrap(err, "querying contract store")
}
return terra.PRISM.ValueFromTerra(r.Withdrawable), nil
}
func (f *Farm) NewBondMessage(sender cosmos.AccAddress, amount decimal.Decimal) (cosmos.Msg, error) {
var q struct {
Bond struct{} `json:"bond"`

View File

@ -0,0 +1,57 @@
package prism
import (
"context"
"github.com/galacticship/terra"
"github.com/pkg/errors"
"github.com/shopspring/decimal"
)
type Governance struct {
*terra.Contract
}
func NewGovernance(querier *terra.Querier) (*Governance, error) {
c, err := terra.NewContract(querier, "terra1h4al753uvwmhxwhn2dlvm9gfk0jkf52xqasmq2")
if err != nil {
return nil, errors.Wrap(err, "init base contract")
}
return &Governance{
c,
}, nil
}
type XPrismState struct {
ExchangeRate decimal.Decimal `json:"exchange_rate"`
EffectiveXprismSupply decimal.Decimal `json:"effective_xprism_supply"`
EffectiveUnderlyingPrism decimal.Decimal `json:"effective_underlying_prism"`
TotalPendingWithdrawXprism decimal.Decimal `json:"total_pending_withdraw_xprism"`
TotalPendingWithdrawPrism decimal.Decimal `json:"total_pending_withdraw_prism"`
}
func (g *Governance) XPrismState(ctx context.Context) (XPrismState, error) {
var q struct {
XprismState struct{} `json:"xprism_state"`
}
type response struct {
ExchangeRate decimal.Decimal `json:"exchange_rate"`
EffectiveXprismSupply decimal.Decimal `json:"effective_xprism_supply"`
EffectiveUnderlyingPrism decimal.Decimal `json:"effective_underlying_prism"`
TotalPendingWithdrawXprism decimal.Decimal `json:"total_pending_withdraw_xprism"`
TotalPendingWithdrawPrism decimal.Decimal `json:"total_pending_withdraw_prism"`
}
var r response
err := g.QueryStore(ctx, q, &r)
if err != nil {
return XPrismState{}, errors.Wrap(err, "querying contract store")
}
return XPrismState{
ExchangeRate: r.ExchangeRate,
EffectiveXprismSupply: terra.XPRISM.ValueFromTerra(r.EffectiveXprismSupply),
EffectiveUnderlyingPrism: terra.PRISM.ValueFromTerra(r.EffectiveUnderlyingPrism),
TotalPendingWithdrawXprism: terra.XPRISM.ValueFromTerra(r.TotalPendingWithdrawXprism),
TotalPendingWithdrawPrism: terra.PRISM.ValueFromTerra(r.TotalPendingWithdrawPrism),
}, nil
}

View File

@ -9,6 +9,7 @@ type Prism struct {
Amps *Amps
YLUNAStaking *YLUNAStaking
Farm *Farm
Governance *Governance
}
func NewPrism(querier *terra.Querier) (*Prism, error) {
@ -24,10 +25,14 @@ func NewPrism(querier *terra.Querier) (*Prism, error) {
if err != nil {
return nil, errors.Wrap(err, "creating farm")
}
gov, err := NewGovernance(querier)
if err != nil {
return nil, errors.Wrap(err, "creating governance")
}
return &Prism{
Amps: amps,
YLUNAStaking: ylunastaking,
Farm: farm,
Governance: gov,
}, nil
}