From ee3e80136c8d45c0fa5b62e0028a93b726dc1d7a Mon Sep 17 00:00:00 2001 From: Laurent Le Houerou Date: Mon, 11 Apr 2022 21:33:21 +0400 Subject: [PATCH] add epoch_state method to anchor market --- protocols/anchor/market.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/protocols/anchor/market.go b/protocols/anchor/market.go index f6296e1..069dfc5 100644 --- a/protocols/anchor/market.go +++ b/protocols/anchor/market.go @@ -59,6 +59,30 @@ func (m Market) BorrowerInfo(ctx context.Context, borrower cosmos.AccAddress) (B }, nil } +type EpochState struct { + ExchangeRate decimal.Decimal + AUSTSupply decimal.Decimal +} + +func (m Market) EpochState(ctx context.Context) (EpochState, error) { + var q struct { + EpochState struct{} `json:"epoch_state"` + } + type response struct { + ExchangeRate decimal.Decimal `json:"exchange_rate"` + AUSTSupply decimal.Decimal `json:"aterra_supply"` + } + var r response + err := m.QueryStore(ctx, q, &r) + if err != nil { + return EpochState{}, errors.Wrap(err, "querying store") + } + return EpochState{ + ExchangeRate: r.ExchangeRate, + AUSTSupply: terra.AUST.ValueFromTerra(r.AUSTSupply), + }, nil +} + func (m Market) NewDepositUSTMessage(sender cosmos.AccAddress, amount decimal.Decimal) (cosmos.Msg, error) { var q struct { DepositStable struct{} `json:"deposit_stable"`