Skip to content

Commit 6008db8

Browse files
committed
chore: changed field multiplier to decimals in asset type
1 parent f95d4b6 commit 6008db8

File tree

4 files changed

+65
-58
lines changed

4 files changed

+65
-58
lines changed

proto/sentinel/oracle/v1/asset.proto

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ option (gogoproto.goproto_getters_all) = false;
99

1010
message Asset {
1111
string denom = 1;
12-
string multiplier = 2 [
13-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
14-
(gogoproto.nullable) = false
15-
];
12+
int64 decimals = 2;
1613
uint64 pool_id = 3 [(gogoproto.customname) = "PoolID"];
1714
string base_asset_denom = 4;
1815
string quote_asset_denom = 5;

x/oracle/keeper/relay.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (k *Keeper) processSpotPriceResponse(ctx sdk.Context, portID, channelID str
100100
return err
101101
}
102102

103-
asset.Price = spotPrice.MulInt(asset.Multiplier).TruncateInt()
103+
asset.Price = spotPrice.MulInt(asset.Exponent()).TruncateInt()
104104
k.SetAsset(ctx, asset)
105105

106106
return nil

x/oracle/types/v1/asset.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package v1
22

33
import (
4+
sdkmath "cosmossdk.io/math"
5+
"errors"
46
abcitypes "github.com/cometbft/cometbft/abci/types"
57
"github.com/cosmos/cosmos-sdk/codec"
8+
sdk "github.com/cosmos/cosmos-sdk/types"
9+
"math/big"
610

711
"github.com/sentinel-official/hub/v12/third_party/osmosis/x/poolmanager/client/queryproto"
812
protorevtypes "github.com/sentinel-official/hub/v12/third_party/osmosis/x/protorev/types"
@@ -32,3 +36,28 @@ func (a *Asset) SpotPriceRequest(cdc codec.Codec) abcitypes.RequestQuery {
3236
Path: "/osmosis.poolmanager.v1beta1.Query/SpotPrice",
3337
}
3438
}
39+
40+
func (a *Asset) Exponent() sdkmath.Int {
41+
i := new(big.Int).Exp(big.NewInt(10), big.NewInt(a.Decimals), nil)
42+
return sdkmath.NewIntFromBigInt(i)
43+
}
44+
45+
func (a *Asset) Validate() error {
46+
if err := sdk.ValidateDenom(a.Denom); err != nil {
47+
return err
48+
}
49+
if a.Decimals < 0 {
50+
return errors.New("decimals must be non-negative")
51+
}
52+
if len(a.BaseAssetDenom) == 0 {
53+
return errors.New("base_asset_denom cannot be empty")
54+
}
55+
if len(a.QuoteAssetDenom) == 0 {
56+
return errors.New("quote_asset_denom cannot be empty")
57+
}
58+
if a.BaseAssetDenom == a.QuoteAssetDenom {
59+
return errors.New("base_asset_denom and quote_asset_denom must be different")
60+
}
61+
62+
return nil
63+
}

x/oracle/types/v1/asset.pb.go

Lines changed: 34 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)