mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
Only return bkava tokens when value_in_staked_tokens is true (#1348)
This commit is contained in:
parent
7847f3ee7b
commit
aa2fedaf78
@ -298,15 +298,21 @@ func (s queryServer) getOneAccountOneVaultDeposit(
|
||||
|
||||
if req.ValueInStakedTokens {
|
||||
// Get underlying ukava amount if denom is a derivative
|
||||
if s.keeper.liquidKeeper.IsDerivativeDenom(ctx, req.Denom) {
|
||||
ukavaValue, err := s.keeper.liquidKeeper.GetStakedTokensForDerivatives(ctx, sdk.NewCoins(value))
|
||||
if err != nil {
|
||||
// This should "never" happen if IsDerivativeDenom is true
|
||||
panic("Error getting ukava value for " + req.Denom)
|
||||
}
|
||||
|
||||
value = ukavaValue
|
||||
if !s.keeper.liquidKeeper.IsDerivativeDenom(ctx, req.Denom) {
|
||||
return nil, status.Errorf(
|
||||
codes.InvalidArgument,
|
||||
"denom %s is not a derivative, ValueInStakedTokens can only be used with liquid derivatives",
|
||||
req.Denom,
|
||||
)
|
||||
}
|
||||
|
||||
ukavaValue, err := s.keeper.liquidKeeper.GetStakedTokensForDerivatives(ctx, sdk.NewCoins(value))
|
||||
if err != nil {
|
||||
// This should "never" happen if IsDerivativeDenom is true
|
||||
panic("Error getting ukava value for " + req.Denom)
|
||||
}
|
||||
|
||||
value = ukavaValue
|
||||
}
|
||||
|
||||
return &types.QueryDepositsResponse{
|
||||
@ -417,9 +423,8 @@ func (s queryServer) getOneAccountAllDeposits(
|
||||
var valueInStakedTokens []sdk.Coin
|
||||
|
||||
for _, coin := range value {
|
||||
// Non-bkava coins are kept as is
|
||||
// Skip non-bkava coins
|
||||
if !s.keeper.liquidKeeper.IsDerivativeDenom(ctx, coin.Denom) {
|
||||
valueInStakedTokens = append(valueInStakedTokens, coin)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -432,7 +437,20 @@ func (s queryServer) getOneAccountAllDeposits(
|
||||
valueInStakedTokens = append(valueInStakedTokens, ukavaValue)
|
||||
}
|
||||
|
||||
var filteredShares types.VaultShares
|
||||
for _, share := range accountShare.Shares {
|
||||
// Remove non-bkava coins from shares as they are used to
|
||||
// determine which value is mapped to which denom
|
||||
// These should be in the same order as valueInStakedTokens
|
||||
if !s.keeper.liquidKeeper.IsDerivativeDenom(ctx, share.Denom) {
|
||||
continue
|
||||
}
|
||||
|
||||
filteredShares = append(filteredShares, share)
|
||||
}
|
||||
|
||||
value = valueInStakedTokens
|
||||
accountShare.Shares = filteredShares
|
||||
}
|
||||
|
||||
deposits = append(deposits, types.DepositResponse{
|
||||
|
@ -404,15 +404,14 @@ func (suite *grpcQueryTestSuite) TestDeposits() {
|
||||
types.DepositResponse{
|
||||
Depositor: acc2.String(),
|
||||
Shares: types.VaultShares{
|
||||
// Does not include non-bkava vaults
|
||||
types.NewVaultShare(deposit4Amount.Denom, deposit4Amount.Amount.ToDec()),
|
||||
types.NewVaultShare(deposit3Amount.Denom, deposit3Amount.Amount.ToDec()),
|
||||
types.NewVaultShare(deposit1Amount.Denom, deposit1Amount.Amount.ToDec()),
|
||||
},
|
||||
Value: sdk.Coins{
|
||||
// Does not include non-bkava vaults
|
||||
sdk.NewCoin("ukava", deposit4Amount.Amount),
|
||||
sdk.NewCoin("ukava", deposit3Amount.Amount),
|
||||
// Deposit 1 is last as it's the same order as vault shares
|
||||
deposit1Amount,
|
||||
},
|
||||
},
|
||||
res.Deposits[0],
|
||||
|
Loading…
Reference in New Issue
Block a user