Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Return BASE/QUOTE exchange rate #497

Merged
merged 4 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions x/oracle/wasm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ func (querier WasmQuerier) QueryCustom(ctx sdk.Context, data json.RawMessage) ([

var items []ExchangeRateItem
for _, quoteDenom := range params.ExchangeRates.QuoteDenoms {
// LUNA / QUOTE_DENOM
quoteDenomExchangeRate, err := querier.keeper.GetLunaExchangeRate(ctx, quoteDenom)
if err != nil {
continue
}

// (BASE_DENOM / LUNA) / (DENOM / LUNA) = BASE_DENOM / QUOTE_DENOM
// (LUNA / QUOTE_DENOM) / (BASE_DENOM / LUNA) = BASE_DENOM / QUOTE_DENOM
items = append(items, ExchangeRateItem{
ExchangeRate: baseDenomExchangeRate.Quo(quoteDenomExchangeRate).String(),
ExchangeRate: quoteDenomExchangeRate.Quo(baseDenomExchangeRate).String(),
QuoteDenom: quoteDenom,
})
}
Expand Down
12 changes: 6 additions & 6 deletions x/oracle/wasm/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func TestQueryExchangeRates(t *testing.T) {

// valid query luna exchange rates
queryParams = wasm.ExchangeRateQueryParams{
BaseDenom: core.MicroKRWDenom,
QuoteDenoms: []string{core.MicroLunaDenom, core.MicroUSDDenom, core.MicroSDRDenom},
BaseDenom: core.MicroLunaDenom,
QuoteDenoms: []string{core.MicroKRWDenom, core.MicroUSDDenom, core.MicroSDRDenom},
}
bz, err = json.Marshal(wasm.CosmosQuery{
ExchangeRates: &queryParams,
Expand All @@ -80,18 +80,18 @@ func TestQueryExchangeRates(t *testing.T) {
err = json.Unmarshal(res, &exchangeRatesResponse)
require.NoError(t, err)
require.Equal(t, exchangeRatesResponse, wasm.ExchangeRatesQueryResponse{
BaseDenom: core.MicroKRWDenom,
BaseDenom: core.MicroLunaDenom,
ExchangeRates: []wasm.ExchangeRateItem{
{
ExchangeRate: KRWExchangeRate.String(),
QuoteDenom: core.MicroLunaDenom,
QuoteDenom: core.MicroKRWDenom,
},
{
ExchangeRate: KRWExchangeRate.Quo(USDExchangeRate).String(),
ExchangeRate: USDExchangeRate.String(),
QuoteDenom: core.MicroUSDDenom,
},
{
ExchangeRate: KRWExchangeRate.Quo(SDRExchangeRate).String(),
ExchangeRate: SDRExchangeRate.String(),
QuoteDenom: core.MicroSDRDenom,
},
},
Expand Down
4 changes: 4 additions & 0 deletions x/wasm/keeper/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func (k Keeper) dispatchMessage(ctx sdk.Context, contractAddr sdk.AccAddress, ms
return nil, nil, err
}

if sdkMsg == nil {
return nil, nil, sdkerrors.Wrap(types.ErrInvalidMsg, "failed to parse msg")
}

// Charge tax on result msg
taxes := ante.FilterMsgAndComputeTax(ctx, k.treasuryKeeper, sdkMsg)
if !taxes.IsZero() {
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ func TestExchangeRatesQuerier(t *testing.T) {

exchangeRateQueryMsg := bindingsTesterExchangeRatesQueryMsg{
ExchangeRates: exchangeRatesQueryMsg{
BaseDenom: core.MicroKRWDenom,
BaseDenom: core.MicroLunaDenom,
QuoteDenoms: []string{
core.MicroLunaDenom,
core.MicroKRWDenom,
},
},
}
Expand Down
6 changes: 1 addition & 5 deletions x/wasm/types/msg_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,8 @@ func (p MsgParser) Parse(ctx sdk.Context, contractAddr sdk.AccAddress, msg wasmv
return parser.Parse(contractAddr, msg)
}

return nil, sdkerrors.Wrap(ErrNoRegisteredParser, "distribution")
return nil, sdkerrors.Wrap(ErrNoRegisteredParser, WasmMsgParserRouteDistribution)
case msg.Wasm != nil:
if msg.Wasm.ClearAdmin != nil {
return nil, sdkerrors.Wrap(ErrNoRegisteredParser, "ClearAdmin not supported")
}

if parser, ok := p.Parsers[WasmMsgParserRouteWasm]; ok {
return parser.Parse(contractAddr, msg)
}
Expand Down