Skip to content

Commit

Permalink
BE-654 | Add liquidity cap overflow flag
Browse files Browse the repository at this point in the history
  • Loading branch information
deividaspetraitis committed Nov 21, 2024
1 parent a6e3f3e commit 1eb0dcc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions router/usecase/quote_in_given_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type quoteExactAmountOut struct {
AmountOut sdk.Coin `json:"amount_out"`
Route []domain.SplitRoute `json:"route"`
LiquidityCap osmomath.Int `json:"liquidity_cap"`
LiquidityCapOverflow bool `json:"liquidity_cap_overflow"`
EffectiveFee osmomath.Dec `json:"effective_fee"`
PriceImpact osmomath.Dec `json:"price_impact"`
InBaseOutQuoteSpotPrice osmomath.Dec `json:"in_base_out_quote_spot_price"`
Expand All @@ -48,6 +49,7 @@ func (q *quoteExactAmountOut) PrepareResult(ctx context.Context, scalingFactor o
q.AmountIn = q.quoteExactAmountIn.AmountOut
q.Route = q.quoteExactAmountIn.Route
q.LiquidityCap = q.quoteExactAmountIn.LiquidityCap
q.LiquidityCapOverflow = q.quoteExactAmountIn.LiquidityCapOverflow
q.EffectiveFee = q.quoteExactAmountIn.EffectiveFee
q.PriceImpact = q.quoteExactAmountIn.PriceImpact
q.InBaseOutQuoteSpotPrice = q.quoteExactAmountIn.InBaseOutQuoteSpotPrice
Expand Down
10 changes: 9 additions & 1 deletion router/usecase/quote_out_given_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type quoteExactAmountIn struct {
AmountOut osmomath.Int `json:"amount_out"`
Route []domain.SplitRoute `json:"route"`
LiquidityCap osmomath.Int `json:"liquidity_cap"`
LiquidityCapOverflow bool `json:"liquidity_cap_overflow"`
EffectiveFee osmomath.Dec `json:"effective_fee"`
PriceImpact osmomath.Dec `json:"price_impact"`
InBaseOutQuoteSpotPrice osmomath.Dec `json:"in_base_out_quote_spot_price"`
Expand All @@ -58,6 +59,7 @@ func (q *quoteExactAmountIn) PrepareResult(ctx context.Context, scalingFactor os
totalAmountIn := q.AmountIn.Amount.ToLegacyDec()
totalFeeAcrossRoutes := osmomath.ZeroDec()

totalLiquidityCapOverflow := false
totalLiquidityCap := osmomath.ZeroInt()
totalSpotPriceInBaseOutQuote := osmomath.ZeroDec()
totalEffectiveSpotPriceInBaseOutQuote := osmomath.ZeroDec()
Expand Down Expand Up @@ -93,7 +95,12 @@ func (q *quoteExactAmountIn) PrepareResult(ctx context.Context, scalingFactor os
// Calculate total liquidity cap for the route
for _, pool := range newPools {
if cap := pool.GetLiquidityCap(); !cap.IsNil() {
totalLiquidityCap = totalLiquidityCap.Add(pool.GetLiquidityCap())
var err error
totalLiquidityCap, err = totalLiquidityCap.SafeAdd(pool.GetLiquidityCap())
if err != nil {
totalLiquidityCapOverflow = true
break
}
}
}

Expand All @@ -113,6 +120,7 @@ func (q *quoteExactAmountIn) PrepareResult(ctx context.Context, scalingFactor os
}

q.LiquidityCap = totalLiquidityCap
q.LiquidityCapOverflow = totalLiquidityCapOverflow
q.EffectiveFee = totalFeeAcrossRoutes
q.Route = resultRoutes
q.InBaseOutQuoteSpotPrice = totalSpotPriceInBaseOutQuote
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
}
],
"liquidity_cap": "1605069224",
"liquidity_cap_overflow": false,
"effective_fee": "0.011696000000000000",
"price_impact": "-0.565353638051463862",
"in_base_out_quote_spot_price": "4.500000000000000000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
}
],
"liquidity_cap": "1605069224",
"liquidity_cap_overflow": false,
"effective_fee": "0.011696000000000000",
"price_impact": "-0.565353638051463862",
"in_base_out_quote_spot_price": "4.500000000000000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
}
],
"liquidity_cap": "1605069224",
"liquidity_cap_overflow": false,
"effective_fee": "0.011696000000000000",
"price_impact": "-0.565353638051463862",
"in_base_out_quote_spot_price": "4.500000000000000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
}
],
"liquidity_cap": "1605069224",
"liquidity_cap_overflow": false,
"effective_fee": "0.010946000000000000",
"price_impact": "-0.593435820925030124",
"in_base_out_quote_spot_price": "3.500000000000000000"
Expand Down

0 comments on commit 1eb0dcc

Please sign in to comment.