diff --git a/protocols/prism/farm.go b/protocols/prism/farm.go index f52ac4d..eb1ce7f 100644 --- a/protocols/prism/farm.go +++ b/protocols/prism/farm.go @@ -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"` diff --git a/protocols/prism/governance.go b/protocols/prism/governance.go new file mode 100644 index 0000000..341c232 --- /dev/null +++ b/protocols/prism/governance.go @@ -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 + +} diff --git a/protocols/prism/prism.go b/protocols/prism/prism.go index 8d689c7..bb89d2b 100644 --- a/protocols/prism/prism.go +++ b/protocols/prism/prism.go @@ -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 }