Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dev #879

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

// GetShareValue multiplies with truncation by receiving int amount and decimal ratio and returns int result.
func GetShareValue(amount sdkmath.Int, ratio sdkmath.LegacyDec) sdkmath.Int {
return sdkmath.LegacyNewDec(amount.Int64()).MulTruncate(ratio).TruncateInt()
return amount.ToLegacyDec().MulTruncate(ratio).TruncateInt()
}

type StrIntMap map[string]sdkmath.Int
Expand Down
4 changes: 2 additions & 2 deletions x/liquidity/amm/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ func DistributeOrderAmountToOrders(orders []Order, amt sdkmath.Int, price sdkmat
if matchableAmt.IsZero() {
continue
}
orderAmt := sdkmath.LegacyNewDec(order.GetAmount().Int64())
proportion := orderAmt.QuoTruncate(sdkmath.LegacyNewDec(totalAmt.Int64()))
orderAmt := order.GetAmount().ToLegacyDec()
proportion := orderAmt.QuoTruncate(totalAmt.ToLegacyDec())
matchedAmt := sdkmath.MinInt(matchableAmt, proportion.MulInt(amt).TruncateInt())
if matchedAmt.IsPositive() {
matchedAmtByOrder[order] = matchedAmt
Expand Down
2 changes: 1 addition & 1 deletion x/liquidity/amm/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func MatchableAmount(order Order, price sdkmath.LegacyDec) (matchableAmt sdkmath
remainingOfferCoinAmt := order.GetOfferCoinAmount().Sub(order.GetPaidOfferCoinAmount())
matchableAmt = sdkmath.MinInt(
order.GetOpenAmount(),
sdkmath.LegacyNewDec(remainingOfferCoinAmt.Int64()).QuoTruncate(price).TruncateInt(),
remainingOfferCoinAmt.ToLegacyDec().QuoTruncate(price).TruncateInt(),
)
case Sell:
matchableAmt = order.GetOpenAmount()
Expand Down
10 changes: 5 additions & 5 deletions x/liquidity/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,11 +738,11 @@ func (k Keeper) TransferFundsForSwapFeeDistribution(ctx sdk.Context, appID, requ
}

requestedPoolShare := poolLiquidityMap[requestedPoolID].Quo(totalLiquidity)
eligibleSwapFeeAmount := requestedPoolShare.Mul(sdkmath.LegacyNewDec(availableBalance.Amount.Int64()))
eligibleSwapFeeAmount := requestedPoolShare.Mul(availableBalance.Amount.ToLegacyDec())
availableBalance.Amount = eligibleSwapFeeAmount.RoundInt()
}

burnAmount := sdkmath.LegacyNewDec(availableBalance.Amount.Int64()).MulTruncate(params.SwapFeeBurnRate).TruncateInt()
burnAmount := availableBalance.Amount.ToLegacyDec().MulTruncate(params.SwapFeeBurnRate).TruncateInt()
burnCoin := sdk.NewCoin(availableBalance.Denom, burnAmount)

if burnCoin.Amount.IsPositive() {
Expand Down Expand Up @@ -798,12 +798,12 @@ func (k Keeper) WasmMsgAddEmissionPoolRewards(ctx sdk.Context, appID, cswapAppID
moduleAddr := k.accountKeeper.GetModuleAddress(types.ModuleName)
farmedCoins := k.bankKeeper.GetBalance(ctx, moduleAddr, pool.PoolCoinDenom)
individualVote := votingRatio[j]
votingR := sdkmath.LegacyNewDec(individualVote.Int64()).Quo(sdkmath.LegacyNewDec(totalVote.Int64()))
shareByPool := votingR.Mul(sdkmath.LegacyNewDec(amount.Int64()))
votingR := individualVote.ToLegacyDec().Quo(totalVote.ToLegacyDec())
shareByPool := votingR.Mul(amount.ToLegacyDec())
if farmedCoins.IsZero() {
continue
}
perUserShareByAmtDec := shareByPool.Quo(sdkmath.LegacyNewDec(farmedCoins.Amount.Int64()))
perUserShareByAmtDec := shareByPool.Quo(farmedCoins.Amount.ToLegacyDec())
allActiveFarmer := k.GetAllActiveFarmers(ctx, cswapAppID, extP)

for _, farmerDetail := range allActiveFarmer {
Expand Down
4 changes: 2 additions & 2 deletions x/liquidity/keeper/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func CalculateSwapFeeAmount(ctx sdk.Context, params types.GenericParams, calculatedOfferCoinAmt sdkmath.Int) sdkmath.Int {
return sdkmath.LegacyNewDec(calculatedOfferCoinAmt.Int64()).MulTruncate(params.SwapFeeRate).TruncateInt()
return calculatedOfferCoinAmt.ToLegacyDec().MulTruncate(params.SwapFeeRate).TruncateInt()
}

func (k Keeper) PriceLimits(ctx sdk.Context, lastPrice sdkmath.LegacyDec, params types.GenericParams) (lowest, highest sdkmath.LegacyDec) {
Expand Down Expand Up @@ -1002,7 +1002,7 @@ func (k Keeper) ConvertAccumulatedSwapFeesWithSwapDistrToken(ctx sdk.Context, ap
switch orderDirection {
case types.OrderDirectionBuy:
maxPrice := lastPrice.Mul(sdkmath.LegacyOneDec().Add(params.MaxPriceLimitRatio))
amount = sdkmath.LegacyNewDec(offerCoin.Amount.Int64()).Quo(maxPrice).TruncateInt()
amount = offerCoin.Amount.ToLegacyDec().Quo(maxPrice).TruncateInt()
demandCoinDenom = swappablePair.BaseCoinDenom
case types.OrderDirectionSell:
amount = offerCoin.Amount
Expand Down
2 changes: 1 addition & 1 deletion x/liquidity/types/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewUserOrder(order Order) *UserOrder {
utils.SafeMath(func() {
amt = sdk.MinInt(
order.OpenAmount,
sdk.NewDec(order.RemainingOfferCoin.Amount.Int64()).QuoTruncate(order.Price).TruncateInt(),
order.RemainingOfferCoin.Amount.ToLegacyDec().QuoTruncate(order.Price).TruncateInt(),
)
}, func() {
amt = order.OpenAmount
Expand Down
2 changes: 1 addition & 1 deletion x/liquidity/types/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewPoolResponse(pool Pool, rx, ry sdk.Coin, poolCoinSupply sdk.Int) PoolRes
// IsTooSmallOrderAmount returns whether the order amount is too small for
// matching, based on the order price.
func IsTooSmallOrderAmount(amt sdk.Int, price sdk.Dec) bool {
return amt.LT(amm.MinCoinAmount) || price.MulInt(amt).LT(sdk.NewDec(amm.MinCoinAmount.Int64()))
return amt.LT(amm.MinCoinAmount) || price.MulInt(amt).LT(amm.MinCoinAmount.ToLegacyDec())
}

// PriceLimits returns the lowest and the highest price limits with given last price
Expand Down
Loading