Skip to content

Commit

Permalink
[Tier]: Add more fields to query (#657)
Browse files Browse the repository at this point in the history
* add more fields

* update query

* fix

* fix

* fix
  • Loading branch information
amityadav0 authored Jul 17, 2024
1 parent d8fa76e commit 07597e3
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 91 deletions.
4 changes: 3 additions & 1 deletion proto/elys/tier/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ message QueryGetConsolidatedPriceRequest {
}

message QueryGetConsolidatedPriceResponse {
string price = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string ammPrice = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string oraclePrice = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string oraclePriceDec = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
}

message QueryStakedRequest {
Expand Down
21 changes: 14 additions & 7 deletions x/tier/keeper/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,24 +246,31 @@ func (k Keeper) RetrieveLeverageLpTotal(ctx sdk.Context, user sdk.AccAddress) sd
return totalValue
}

func (k Keeper) RetrieveConsolidatedPrice(ctx sdk.Context, denom string) (sdk.Dec, error) {
func (k Keeper) RetrieveConsolidatedPrice(ctx sdk.Context, denom string) (sdk.Dec, sdk.Dec, sdk.Dec) {
if denom == ptypes.Eden {
denom = ptypes.Elys
}
tokenPrice := k.oracleKeeper.GetAssetPriceFromDenom(ctx, denom)
tokenPriceOracle := k.oracleKeeper.GetAssetPriceFromDenom(ctx, denom)
asset, found := k.assetProfileKeeper.GetEntryByDenom(ctx, denom)
if !found {
return sdk.ZeroDec(), types.ErrNotFound
tokenPriceOracle = sdk.NewDec(0)
}
if tokenPrice.Equal(sdk.ZeroDec()) {
tokenPrice = k.CalcAmmPrice(ctx, asset.Denom, asset.Decimals)
tokenPriceAmm := k.CalcAmmPrice(ctx, asset.Denom, asset.Decimals)
info, found := k.oracleKeeper.GetAssetInfo(ctx, denom)
tokenPriceOracleDec := sdk.ZeroDec()
if found {
tokenPriceOracleD, found := k.oracleKeeper.GetAssetPrice(ctx, info.Display)
if found {
tokenPriceOracleDec = tokenPriceOracleD.Price
}
}
return tokenPrice, nil

return tokenPriceOracle, tokenPriceAmm, tokenPriceOracleDec
}

func (k Keeper) CalcAmmPrice(ctx sdk.Context, denom string, decimal uint64) sdk.Dec {
usdcDenom, found := k.assetProfileKeeper.GetUsdcDenom(ctx)
if !found {
if !found || denom == usdcDenom {
return sdk.ZeroDec()
}
usdcPrice := k.oracleKeeper.GetAssetPriceFromDenom(ctx, usdcDenom)
Expand Down
9 changes: 4 additions & 5 deletions x/tier/keeper/query_get_consolidated_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ func (k Keeper) GetConsolidatedPrice(goCtx context.Context, req *types.QueryGetC

ctx := sdk.UnwrapSDKContext(goCtx)

resp, err := k.RetrieveConsolidatedPrice(ctx, req.Denom)
if err != nil {
return nil, err
}
oracle, amm, oracleDec := k.RetrieveConsolidatedPrice(ctx, req.Denom)

return &types.QueryGetConsolidatedPriceResponse{
Price: resp,
AmmPrice: amm,
OraclePrice: oracle,
OraclePriceDec: oracleDec,
}, nil
}
1 change: 1 addition & 0 deletions x/tier/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type BankKeeper interface {
}

type OracleKeeper interface {
GetAssetInfo(ctx sdk.Context, denom string) (val oracletypes.AssetInfo, found bool)
GetAssetPrice(ctx sdk.Context, asset string) (oracletypes.Price, bool)
GetAssetPriceFromDenom(ctx sdk.Context, denom string) sdk.Dec
GetPriceFeeder(ctx sdk.Context, feeder string) (val oracletypes.PriceFeeder, found bool)
Expand Down
Loading

0 comments on commit 07597e3

Please sign in to comment.