mirror of
https://github.com/galacticship/terra.git
synced 2024-11-12 19:27:52 +00:00
add WithdrawableRewards method to prism farm
add prism governance contract & xprism_state method
This commit is contained in:
parent
a7c79b7106
commit
3da7f589eb
@ -1,6 +1,8 @@
|
|||||||
package prism
|
package prism
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/galacticship/terra"
|
"github.com/galacticship/terra"
|
||||||
"github.com/galacticship/terra/cosmos"
|
"github.com/galacticship/terra/cosmos"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -21,6 +23,23 @@ func NewFarm(querier *terra.Querier) (*Farm, error) {
|
|||||||
}, nil
|
}, 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) {
|
func (f *Farm) NewBondMessage(sender cosmos.AccAddress, amount decimal.Decimal) (cosmos.Msg, error) {
|
||||||
var q struct {
|
var q struct {
|
||||||
Bond struct{} `json:"bond"`
|
Bond struct{} `json:"bond"`
|
||||||
|
57
protocols/prism/governance.go
Normal file
57
protocols/prism/governance.go
Normal 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
|
||||||
|
|
||||||
|
}
|
@ -9,6 +9,7 @@ type Prism struct {
|
|||||||
Amps *Amps
|
Amps *Amps
|
||||||
YLUNAStaking *YLUNAStaking
|
YLUNAStaking *YLUNAStaking
|
||||||
Farm *Farm
|
Farm *Farm
|
||||||
|
Governance *Governance
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPrism(querier *terra.Querier) (*Prism, error) {
|
func NewPrism(querier *terra.Querier) (*Prism, error) {
|
||||||
@ -24,10 +25,14 @@ func NewPrism(querier *terra.Querier) (*Prism, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "creating farm")
|
return nil, errors.Wrap(err, "creating farm")
|
||||||
}
|
}
|
||||||
|
gov, err := NewGovernance(querier)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "creating governance")
|
||||||
|
}
|
||||||
return &Prism{
|
return &Prism{
|
||||||
Amps: amps,
|
Amps: amps,
|
||||||
YLUNAStaking: ylunastaking,
|
YLUNAStaking: ylunastaking,
|
||||||
Farm: farm,
|
Farm: farm,
|
||||||
|
Governance: gov,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user