Skip to content

Commit f135450

Browse files
committed
improve liquidation price query
1 parent 5b39f7f commit f135450

File tree

7 files changed

+569
-437
lines changed

7 files changed

+569
-437
lines changed

api/side/lending/query.pulsar.go

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

docs/static/openapi.yml

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

proto/side/lending/query.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ message QueryLiquidationPriceRequest {
121121
}
122122

123123
message QueryLiquidationPriceResponse {
124-
string liquidation_price = 1;
124+
string price = 1;
125+
string pair = 2;
125126
}
126127

127128
message QueryDlcEventCountRequest {}

x/lending/keeper/dlc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (k Keeper) UpdateDLCEvent(ctx sdk.Context, loanId string) {
143143

144144
// update outcomes
145145
dlcEvent.Outcomes = []string{
146-
fmt.Sprintf("Liquidated at %s", types.FormatPrice(loan.LiquidationPrice, types.GetPricePair(pool.Config))),
146+
fmt.Sprintf("Liquidated at %s", types.FormatPriceWithPair(loan.LiquidationPrice, types.GetPricePair(pool.Config))),
147147
fmt.Sprintf("Default liquidated at %d", loan.MaturityTime),
148148
"Repaid",
149149
}

x/lending/keeper/queries.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ func (k Keeper) LiquidationPrice(goCtx context.Context, req *types.QueryLiquidat
138138
liquidationPrice := types.GetLiquidationPrice(collateralAmount.Amount, int(poolConfig.CollateralAsset.Decimals), borrowedAmount.Amount, int(poolConfig.LendingAsset.Decimals), trancheConfig.Maturity, trancheConfig.BorrowAPR, k.GetBlocksPerYear(ctx), poolConfig.LiquidationThreshold, poolConfig.CollateralAsset.IsBasePriceAsset)
139139

140140
return &types.QueryLiquidationPriceResponse{
141-
LiquidationPrice: types.FormatPrice(liquidationPrice, types.GetPricePair(poolConfig)),
141+
Price: types.FormatPrice(liquidationPrice),
142+
Pair: types.GetPricePair(poolConfig),
142143
}, nil
143144
}
144145

x/lending/types/lending.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"strconv"
77
"strings"
88

9+
"github.com/shopspring/decimal"
10+
911
errorsmod "cosmossdk.io/errors"
1012
sdkmath "cosmossdk.io/math"
1113
sdk "github.com/cosmos/cosmos-sdk/types"
12-
"github.com/shopspring/decimal"
1314

1415
"github.com/sideprotocol/side/bitcoin/crypto/adaptor"
1516
liquidationtypes "github.com/sideprotocol/side/x/liquidation/types"
@@ -108,10 +109,16 @@ func GetPricePair(poolConfig PoolConfig) string {
108109

109110
// FormatPrice formats the given price
110111
// Assume that the given price is valid
111-
func FormatPrice(price sdkmath.LegacyDec, pair string) string {
112+
func FormatPrice(price sdkmath.LegacyDec) string {
112113
decimalPrice, _ := decimal.NewFromString(price.String())
113114

114-
return fmt.Sprintf("%s%s", decimalPrice.String(), pair)
115+
return decimalPrice.String()
116+
}
117+
118+
// FormatPrice formats the given price with the specified pair
119+
// Assume that the given price is valid
120+
func FormatPriceWithPair(price sdkmath.LegacyDec, pair string) string {
121+
return fmt.Sprintf("%s%s", FormatPrice(price), pair)
115122
}
116123

117124
// NormalizePrice normalizes the given price

x/lending/types/query.pb.go

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

0 commit comments

Comments
 (0)