Only return bkava tokens when value_in_staked_tokens is true (#1348)

This commit is contained in:
Derrick Lee 2022-10-11 14:38:49 -07:00 committed by GitHub
parent 7847f3ee7b
commit aa2fedaf78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 13 deletions

View File

@ -298,7 +298,14 @@ func (s queryServer) getOneAccountOneVaultDeposit(
if req.ValueInStakedTokens { if req.ValueInStakedTokens {
// Get underlying ukava amount if denom is a derivative // Get underlying ukava amount if denom is a derivative
if s.keeper.liquidKeeper.IsDerivativeDenom(ctx, req.Denom) { 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)) ukavaValue, err := s.keeper.liquidKeeper.GetStakedTokensForDerivatives(ctx, sdk.NewCoins(value))
if err != nil { if err != nil {
// This should "never" happen if IsDerivativeDenom is true // This should "never" happen if IsDerivativeDenom is true
@ -307,7 +314,6 @@ func (s queryServer) getOneAccountOneVaultDeposit(
value = ukavaValue value = ukavaValue
} }
}
return &types.QueryDepositsResponse{ return &types.QueryDepositsResponse{
Deposits: []types.DepositResponse{ Deposits: []types.DepositResponse{
@ -417,9 +423,8 @@ func (s queryServer) getOneAccountAllDeposits(
var valueInStakedTokens []sdk.Coin var valueInStakedTokens []sdk.Coin
for _, coin := range value { for _, coin := range value {
// Non-bkava coins are kept as is // Skip non-bkava coins
if !s.keeper.liquidKeeper.IsDerivativeDenom(ctx, coin.Denom) { if !s.keeper.liquidKeeper.IsDerivativeDenom(ctx, coin.Denom) {
valueInStakedTokens = append(valueInStakedTokens, coin)
continue continue
} }
@ -432,7 +437,20 @@ func (s queryServer) getOneAccountAllDeposits(
valueInStakedTokens = append(valueInStakedTokens, ukavaValue) 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 value = valueInStakedTokens
accountShare.Shares = filteredShares
} }
deposits = append(deposits, types.DepositResponse{ deposits = append(deposits, types.DepositResponse{

View File

@ -404,15 +404,14 @@ func (suite *grpcQueryTestSuite) TestDeposits() {
types.DepositResponse{ types.DepositResponse{
Depositor: acc2.String(), Depositor: acc2.String(),
Shares: types.VaultShares{ Shares: types.VaultShares{
// Does not include non-bkava vaults
types.NewVaultShare(deposit4Amount.Denom, deposit4Amount.Amount.ToDec()), types.NewVaultShare(deposit4Amount.Denom, deposit4Amount.Amount.ToDec()),
types.NewVaultShare(deposit3Amount.Denom, deposit3Amount.Amount.ToDec()), types.NewVaultShare(deposit3Amount.Denom, deposit3Amount.Amount.ToDec()),
types.NewVaultShare(deposit1Amount.Denom, deposit1Amount.Amount.ToDec()),
}, },
Value: sdk.Coins{ Value: sdk.Coins{
// Does not include non-bkava vaults
sdk.NewCoin("ukava", deposit4Amount.Amount), sdk.NewCoin("ukava", deposit4Amount.Amount),
sdk.NewCoin("ukava", deposit3Amount.Amount), sdk.NewCoin("ukava", deposit3Amount.Amount),
// Deposit 1 is last as it's the same order as vault shares
deposit1Amount,
}, },
}, },
res.Deposits[0], res.Deposits[0],