Skip to content

Commit

Permalink
get asset by denom
Browse files Browse the repository at this point in the history
  • Loading branch information
amityadav0 committed Jun 16, 2024
1 parent 37a5dd3 commit df5be14
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions x/tier/keeper/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (k Keeper) RetreiveAllPortfolio(ctx sdk.Context, user string) {
totalValue := sdk.NewDec(0)
for _, balance := range balances {
tokenPrice := k.oracleKeeper.GetAssetPriceFromDenom(ctx, balance.Denom)
asset, found := k.assetProfileKeeper.GetEntry(ctx, balance.Denom)
asset, found := k.assetProfileKeeper.GetEntryByDenom(ctx, balance.Denom)
if !found {
continue
}
Expand All @@ -45,7 +45,7 @@ func (k Keeper) RetreiveAllPortfolio(ctx sdk.Context, user string) {
if err1 == nil {
for _, balance := range estaking.Total {
tokenPrice := k.oracleKeeper.GetAssetPriceFromDenom(ctx, balance.Denom)
asset, found := k.assetProfileKeeper.GetEntry(ctx, balance.Denom)
asset, found := k.assetProfileKeeper.GetEntryByDenom(ctx, balance.Denom)
if !found {
continue
}
Expand All @@ -57,7 +57,7 @@ func (k Keeper) RetreiveAllPortfolio(ctx sdk.Context, user string) {
if err2 == nil {
for _, balance := range masterchef.TotalRewards {
tokenPrice := k.oracleKeeper.GetAssetPriceFromDenom(ctx, balance.Denom)
asset, found := k.assetProfileKeeper.GetEntry(ctx, balance.Denom)
asset, found := k.assetProfileKeeper.GetEntryByDenom(ctx, balance.Denom)
if !found {
continue
}
Expand All @@ -70,7 +70,7 @@ func (k Keeper) RetreiveAllPortfolio(ctx sdk.Context, user string) {
perpetuals, _, err := k.perpetual.GetMTPsForAddress(ctx, sender, &query.PageRequest{})
if err == nil {
for _, perpetual := range perpetuals {
asset, found := k.assetProfileKeeper.GetEntry(ctx, perpetual.GetTradingAsset())
asset, found := k.assetProfileKeeper.GetEntryByDenom(ctx, perpetual.GetTradingAsset())
if !found {
continue
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func (k Keeper) RetreiveAllPortfolio(ctx sdk.Context, user string) {
totalValue = totalValue.Add(amount.Mul(info.LpTokenPrice))
} else {
tokenPrice := k.oracleKeeper.GetAssetPriceFromDenom(ctx, commitment.Denom)
asset, found := k.assetProfileKeeper.GetEntry(ctx, commitment.Denom)
asset, found := k.assetProfileKeeper.GetEntryByDenom(ctx, commitment.Denom)
if !found {
continue
}
Expand All @@ -111,7 +111,7 @@ func (k Keeper) RetreiveAllPortfolio(ctx sdk.Context, user string) {
delegations := k.stakingKeeper.GetAllDelegatorDelegations(ctx, sender)
bondDenom := k.stakingKeeper.BondDenom(ctx)
tokenPrice := k.oracleKeeper.GetAssetPriceFromDenom(ctx, bondDenom)
asset, found := k.assetProfileKeeper.GetEntry(ctx, bondDenom)
asset, found := k.assetProfileKeeper.GetEntryByDenom(ctx, bondDenom)
if found {
for _, delegation := range delegations {
amount := delegation.Shares.Quo(Pow10(asset.Decimals))
Expand Down
3 changes: 2 additions & 1 deletion x/tier/keeper/portfolio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ func SetupCoinPrices(ctx sdk.Context, oracle oraclekeeper.Keeper, assetProfiler
Display: "ATOM",
Decimal: 6,
})
assetProfiler.SetEntry(ctx, profiletypes.Entry{BaseDenom: ptypes.Elys})
assetProfiler.SetEntry(ctx, profiletypes.Entry{BaseDenom: ptypes.Elys, Denom: ptypes.Elys})
assetProfiler.SetEntry(ctx, profiletypes.Entry{BaseDenom: ptypes.BaseCurrency, Denom: ptypes.BaseCurrency})

oracle.SetPrice(ctx, oracletypes.Price{
Asset: "USDC",
Expand Down
2 changes: 2 additions & 0 deletions x/tier/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type AssetProfileKeeper interface {
GetEntry(ctx sdk.Context, baseDenom string) (val assetprofiletypes.Entry, found bool)
// GetUsdcDenom returns USDC denom
GetUsdcDenom(ctx sdk.Context) (string, bool)
// GetEntryByDenom returns a entry from its denom value
GetEntryByDenom(ctx sdk.Context, denom string) (val assetprofiletypes.Entry, found bool)
}

type AmmKeeper interface {
Expand Down

0 comments on commit df5be14

Please sign in to comment.