Skip to content

Commit

Permalink
modules refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsingh33 committed Jan 11, 2024
2 parents 97d3d43 + c76f78c commit 47bd654
Show file tree
Hide file tree
Showing 27 changed files with 69 additions and 69 deletions.
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
2 changes: 1 addition & 1 deletion x/auction/keeper/debt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (s *KeeperTestSuite) TestDebtBid() {
s.Require().Equal(afterAuction.BiddingIds[tc.bidID-uint64(1)].BidId, tc.bidID)
s.Require().Equal(afterAuction.BiddingIds[tc.bidID-uint64(1)].BidOwner, tc.msg.Bidder)
if tc.bidID != uint64(1) {
s.Require().True(afterAuction.ExpectedMintedToken.Amount.LTE(sdk.NewDec(beforeAuction.ExpectedMintedToken.Amount.Int64()).Mul(sdk.MustNewDecFromStr("1").Sub(beforeAuction.BidFactor)).TruncateInt()))
s.Require().True(afterAuction.ExpectedMintedToken.Amount.LTE(sdk.NewDecFromInt(beforeAuction.ExpectedMintedToken.Amount).Mul(sdk.MustNewDecFromStr("1").Sub(beforeAuction.BidFactor)).TruncateInt()))
}
s.Require().Equal(beforeHarborBalance, afterHarborBalance)
s.Require().Equal(beforeCmstBalance.Sub(expectedUserToken), afterCmstBalance)
Expand Down
2 changes: 1 addition & 1 deletion x/auction/keeper/dutch.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (k Keeper) StartDutchAuction(
outFlowTokenPrice = twaData.Twa
// set target amount for debt
inFlowTokenTargetAmount := lockedVault.AmountOut
mulfactor := sdk.NewDec(inFlowTokenTargetAmount.Int64()).Mul(liquidationPenalty)
mulfactor := sdk.NewDecFromInt(inFlowTokenTargetAmount).Mul(liquidationPenalty)
inFlowTokenTargetAmount = inFlowTokenTargetAmount.Add(mulfactor.TruncateInt()).Add(lockedVault.InterestAccumulated)
inFlowTokenTarget := sdk.NewCoin(inFlowToken.Denom, inFlowTokenTargetAmount)
// These prices are in uusd
Expand Down
2 changes: 1 addition & 1 deletion x/auction/keeper/dutch_lend.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (k Keeper) PlaceLendDutchAuctionBid(ctx sdk.Context, appID, auctionMappingI

// calculating additional auction bonus to the bidder

auctionBonus := sdk.NewDec(slice.Int64()).Mul(assetStats.LiquidationBonus)
auctionBonus := sdk.NewDecFromInt(slice).Mul(assetStats.LiquidationBonus)
totalAmountToBidder := sdk.NewCoin(auction.OutflowTokenInitAmount.Denom, slice.Add(auctionBonus.TruncateInt()))

biddingID, err := k.CreateNewDutchLendBid(ctx, appID, auctionMappingID, auctionID, bidder.String(), inFlowTokenCoin, outFlowTokenCoin)
Expand Down
10 changes: 5 additions & 5 deletions x/auction/keeper/dutch_lend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func (s *KeeperTestSuite) TestLiquidateBorrows() {
updatedPrice := price.Sub(price.Mul(Dec("0.09090909090")))

s.Require().Equal(lockedVault[0].CollateralToBeAuctioned.TruncateInt(), updatedPrice.TruncateInt())
s.Require().Equal(lockedVault[0].CrAtLiquidation, sdk.NewDec(lockedVault[0].AmountOut.Int64()).Mul(s.GetAssetPrice(2)).Quo(sdk.NewDec(beforeAmtIn.Int64()).Mul(s.GetAssetPrice(1))))
s.Require().Equal(lockedVault[0].CrAtLiquidation, sdk.NewDecFromInt(lockedVault[0].AmountOut).Mul(s.GetAssetPrice(2)).Quo(sdk.NewDecFromInt(beforeAmtIn).Mul(s.GetAssetPrice(1))))
}

func (s *KeeperTestSuite) TestDutchActivatorLend() {
Expand Down Expand Up @@ -808,8 +808,8 @@ func (s *KeeperTestSuite) TestLendDutchBid() {
s.Require().NoError(err)

userBid, err := k.GetDutchLendUserBidding(*ctx, userAddress1, appID, biddingID)
userReceivableAmount := sdk.NewDec(tc.msg.Amount.Amount.Int64()).Mul(beforeAuction.OutflowTokenCurrentPrice).Quo(beforeAuction.InflowTokenCurrentPrice).TruncateInt()
auctionBonus := sdk.NewDec(userReceivableAmount.Int64()).Mul(Dec("0.005"))
userReceivableAmount := sdk.NewDecFromInt(tc.msg.Amount.Amount).Mul(beforeAuction.OutflowTokenCurrentPrice).Quo(beforeAuction.InflowTokenCurrentPrice).TruncateInt()
auctionBonus := sdk.NewDecFromInt(userReceivableAmount).Mul(Dec("0.005"))
userOutflowCoin := sdk.NewCoin("ucmdx", userReceivableAmount)
userOutflowCoinFinal := sdk.NewCoin("ucmdx", userReceivableAmount.Add(auctionBonus.TruncateInt()))
userInflowCoin := tc.msg.Amount
Expand Down Expand Up @@ -937,8 +937,8 @@ func (s *KeeperTestSuite) TestLendDutchBid3() {
s.Require().NoError(err)

userBid, err := k.GetDutchLendUserBidding(*ctx, userAddress1, appID, biddingID)
userReceivableAmount := sdk.NewDec(tc.msg.Amount.Amount.Int64()).Mul(beforeAuction.OutflowTokenCurrentPrice).Quo(beforeAuction.InflowTokenCurrentPrice).TruncateInt()
auctionBonus := sdk.NewDec(userReceivableAmount.Int64()).Mul(Dec("0.005"))
userReceivableAmount := sdk.NewDecFromInt(tc.msg.Amount.Amount).Mul(beforeAuction.OutflowTokenCurrentPrice).Quo(beforeAuction.InflowTokenCurrentPrice).TruncateInt()
auctionBonus := sdk.NewDecFromInt(userReceivableAmount).Mul(Dec("0.005"))
userOutflowCoin := sdk.NewCoin("uosmo", userReceivableAmount)
userOutflowCoinFinal := sdk.NewCoin("uosmo", userReceivableAmount.Add(auctionBonus.TruncateInt()))
userInflowCoin := tc.msg.Amount
Expand Down
8 changes: 4 additions & 4 deletions x/auction/keeper/dutch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (s *KeeperTestSuite) LiquidateVaults1() {
price, err := s.app.MarketKeeper.CalcAssetPrice(*ctx, uint64(1), beforeVault.AmountIn)
s.Require().NoError(err)
s.Require().Equal(lockedVault[0].CollateralToBeAuctioned, price)
s.Require().Equal(lockedVault[0].CrAtLiquidation, sdk.NewDec(lockedVault[0].AmountIn.Int64()).Mul(s.GetAssetPrice(1)).Quo(sdk.NewDec(lockedVault[0].AmountOut.Int64()).Mul(s.GetAssetPrice(2))))
s.Require().Equal(lockedVault[0].CrAtLiquidation, sdk.NewDecFromInt(lockedVault[0].AmountIn).Mul(s.GetAssetPrice(1)).Quo(sdk.NewDecFromInt(lockedVault[0].AmountOut).Mul(s.GetAssetPrice(2))))
}

func (s *KeeperTestSuite) AddAuctionParams() {
Expand Down Expand Up @@ -317,7 +317,7 @@ func (s *KeeperTestSuite) TestDutchActivator() {
s.Require().Equal(dutchAuction.InflowTokenCurrentAmount.Amount, sdk.ZeroInt())

inFlowTokenTargetAmount := lockedVault.AmountOut
mulfactor := sdk.NewDec(inFlowTokenTargetAmount.Int64()).Mul(dutchAuction.LiquidationPenalty)
mulfactor := sdk.NewDecFromInt(inFlowTokenTargetAmount).Mul(dutchAuction.LiquidationPenalty)
inFlowTokenTargetAmount = inFlowTokenTargetAmount.Add(mulfactor.TruncateInt()).Add(lockedVault.InterestAccumulated)

s.Require().Equal(dutchAuction.InflowTokenTargetAmount.Amount, inFlowTokenTargetAmount)
Expand Down Expand Up @@ -439,7 +439,7 @@ func (s *KeeperTestSuite) TestDutchBid() {
s.Require().NoError(err)

userBid, err := k.GetDutchUserBidding(*ctx, userAddress1, appID, biddingID)
userReceivableAmount := sdk.NewDec(tc.msg.Amount.Amount.Int64()).Mul(beforeAuction.OutflowTokenCurrentPrice).Quo(beforeAuction.InflowTokenCurrentPrice).TruncateInt()
userReceivableAmount := sdk.NewDecFromInt(tc.msg.Amount.Amount).Mul(beforeAuction.OutflowTokenCurrentPrice).Quo(beforeAuction.InflowTokenCurrentPrice).TruncateInt()
userOutflowCoin := sdk.NewCoin("ucmst", userReceivableAmount)
userInflowCoin := tc.msg.Amount
s.Require().Equal(beforeAuction.OutflowTokenCurrentAmount.Sub(userInflowCoin), afterAuction.OutflowTokenCurrentAmount)
Expand Down Expand Up @@ -558,7 +558,7 @@ func (s *KeeperTestSuite) TestCloseDutchAuctionWithProtocolLoss() {
// verify loss
stats, found := k.GetProtocolStat(*ctx, appId, 2)
s.Require().True(found)
loss := sdk.NewDec(afterAuction.InflowTokenTargetAmount.Sub(afterAuction.InflowTokenCurrentAmount).Amount.Int64())
loss := sdk.NewDecFromInt(afterAuction.InflowTokenTargetAmount.Sub(afterAuction.InflowTokenCurrentAmount).Amount)
s.Require().Equal(loss, stats.Loss)
}

Expand Down
6 changes: 3 additions & 3 deletions x/auction/keeper/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func Multiply(a, b sdk.Dec) sdk.Dec {
}

func (k Keeper) getOutflowTokenInitialPrice(price sdk.Int, buffer sdk.Dec) sdk.Dec {
result := buffer.Mul(sdk.NewDec(price.Int64()))
result := buffer.Mul(sdk.NewDecFromInt(price))
return result
}

Expand All @@ -20,7 +20,7 @@ func (k Keeper) getOutflowTokenEndPrice(price, cusp sdk.Dec) sdk.Dec {

func (k Keeper) getPriceFromLinearDecreaseFunction(top sdk.Dec, tau, dur sdk.Int) sdk.Dec {
result1 := tau.Sub(dur)
result2 := top.Mul(sdk.NewDec(result1.Int64()))
result3 := result2.Quo(sdk.NewDec(tau.Int64()))
result2 := top.Mul(sdk.NewDecFromInt(result1))
result3 := result2.Quo(sdk.NewDecFromInt(tau))
return result3
}
2 changes: 1 addition & 1 deletion x/auction/keeper/math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func getBurnAmount(amount sdk.Int, liqPenalty sdk.Dec) sdk.Int {
liqPenalty = liqPenalty.Add(sdk.NewDec(1))
result := sdk.NewDec(amount.Int64()).Quo(liqPenalty).Ceil().TruncateInt()
result := sdk.NewDecFromInt(amount).Quo(liqPenalty).Ceil().TruncateInt()
return result
}

Expand Down
4 changes: 2 additions & 2 deletions x/auction/keeper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ func (k Keeper) SetProtocolStatistics(ctx sdk.Context, appID, assetID uint64, am
)
stat, found := k.GetProtocolStat(ctx, appID, assetID)
if found {
stat.Loss = stat.Loss.Add(sdk.NewDec(amount.Int64()))
stat.Loss = stat.Loss.Add(sdk.NewDecFromInt(amount))
value := k.cdc.MustMarshal(&stat)
store.Set(key, value)
} else {
var stats auctiontypes.ProtocolStatistics
stats.AppId = appID
stats.AssetId = assetID
stats.Loss = sdk.NewDec(amount.Int64())
stats.Loss = sdk.NewDecFromInt(amount)
value := k.cdc.MustMarshal(&stats)
store.Set(key, value)
}
Expand Down
2 changes: 1 addition & 1 deletion x/auction/keeper/surplus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (s *KeeperTestSuite) TestSurplusBid() {
s.Require().Equal(afterAuction.BiddingIds[tc.bidID-uint64(1)].BidId, tc.bidID)
s.Require().Equal(afterAuction.BiddingIds[tc.bidID-uint64(1)].BidOwner, tc.msg.Bidder)
if tc.bidID != uint64(1) {
s.Require().True(afterAuction.Bid.Amount.GTE(sdk.NewDec(beforeAuction.Bid.Amount.Int64()).Mul(sdk.MustNewDecFromStr("1").Sub(beforeAuction.BidFactor)).TruncateInt()))
s.Require().True(afterAuction.Bid.Amount.GTE(sdk.NewDecFromInt(beforeAuction.Bid.Amount).Mul(sdk.MustNewDecFromStr("1").Sub(beforeAuction.BidFactor)).TruncateInt()))
}
s.Require().Equal(beforeCmstBalance, afterCmstBalance)
s.Require().Equal(beforeHarborBalance.Sub(bid), afterHarborBalance)
Expand Down
6 changes: 3 additions & 3 deletions x/auctionsV2/keeper/maths.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ func Multiply(a, b sdk.Dec) sdk.Dec {
}

func (k Keeper) GetCollalteralTokenInitialPrice(price sdk.Int, premium sdk.Dec) sdk.Dec {
result := premium.Mul(sdk.NewDec(price.Int64()))
result := premium.Mul(sdk.NewDecFromInt(price))
return result
}

func (k Keeper) GetPriceFromLinearDecreaseFunction(CollateralTokenAuctionPrice sdk.Dec, timeToReachZeroPrice, timeElapsed sdk.Int) sdk.Dec {
timeDifference := timeToReachZeroPrice.Sub(timeElapsed)
resultantPrice := CollateralTokenAuctionPrice.Mul(sdk.NewDec(timeDifference.Int64()))
currentPrice := resultantPrice.Quo(sdk.NewDec(timeToReachZeroPrice.Int64()))
resultantPrice := CollateralTokenAuctionPrice.Mul(sdk.NewDecFromInt(timeDifference))
currentPrice := resultantPrice.Quo(sdk.NewDecFromInt(timeToReachZeroPrice))
return currentPrice
}

Expand Down
8 changes: 4 additions & 4 deletions x/auctionsV2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ func (s *KeeperTestSuite) TestLiquidateVaults() {
s.Require().Equal(lockedVault[0].Owner, beforeVault.Owner)
s.Require().Equal(lockedVault[0].CollateralToken.Amount, beforeVault.AmountIn)
s.Require().Equal(lockedVault[0].DebtToken.Amount, beforeVault.AmountOut)
s.Require().Equal(lockedVault[0].TargetDebt.Amount, lockedVault[0].DebtToken.Amount.Add(sdk.NewDec(beforeVault.AmountOut.Int64()).Mul(newDec("0.12")).TruncateInt()))
s.Require().Equal(lockedVault[0].FeeToBeCollected, sdk.NewDec(beforeVault.AmountOut.Int64()).Mul(newDec("0.12")).TruncateInt())
s.Require().Equal(lockedVault[0].TargetDebt.Amount, lockedVault[0].DebtToken.Amount.Add(sdk.NewDecFromInt(beforeVault.AmountOut).Mul(newDec("0.12")).TruncateInt()))
s.Require().Equal(lockedVault[0].FeeToBeCollected, sdk.NewDecFromInt(beforeVault.AmountOut).Mul(newDec("0.12")).TruncateInt())
s.Require().Equal(lockedVault[0].IsDebtCmst, false)
s.Require().Equal(lockedVault[0].CollateralAssetId, uint64(2))
s.Require().Equal(lockedVault[0].DebtAssetId, uint64(3))
Expand Down Expand Up @@ -363,8 +363,8 @@ func (s *KeeperTestSuite) TestLiquidateBorrows() {
s.Require().Equal(lockedVault[0].Owner, beforeLend.Owner)
s.Require().Equal(lockedVault[0].CollateralToken.Amount, beforeBorrow.AmountIn.Amount)
s.Require().Equal(lockedVault[0].DebtToken.Amount, beforeBorrow.AmountOut.Amount)
s.Require().Equal(lockedVault[0].TargetDebt.Amount, lockedVault[0].DebtToken.Amount.Add(sdk.NewDec(beforeBorrow.AmountOut.Amount.Int64()).Mul(newDec("0.05")).TruncateInt()))
s.Require().Equal(lockedVault[0].FeeToBeCollected, sdk.NewDec(beforeBorrow.AmountOut.Amount.Int64()).Mul(newDec("0.05")).TruncateInt())
s.Require().Equal(lockedVault[0].TargetDebt.Amount, lockedVault[0].DebtToken.Amount.Add(sdk.NewDecFromInt(beforeBorrow.AmountOut.Amount).Mul(newDec("0.05")).TruncateInt()))
s.Require().Equal(lockedVault[0].FeeToBeCollected, sdk.NewDecFromInt(beforeBorrow.AmountOut.Amount).Mul(newDec("0.05")).TruncateInt())
s.Require().Equal(lockedVault[0].IsDebtCmst, false)
s.Require().Equal(lockedVault[0].CollateralAssetId, uint64(1))
s.Require().Equal(lockedVault[0].DebtAssetId, uint64(2))
Expand Down
4 changes: 2 additions & 2 deletions x/lend/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func (k Keeper) BorrowAsset(ctx sdk.Context, addr string, lendID, pairID uint64,
mappingData.BorrowId = append(mappingData.BorrowId, borrowPos.ID)
k.SetUserLendBorrowMapping(ctx, mappingData)
} else {
updatedAmtIn := sdk.NewDec(AmountIn.Amount.Int64()).Mul(assetInRatesStatsLtv)
updatedAmtIn := sdk.NewDecFromInt(AmountIn.Amount).Mul(assetInRatesStatsLtv)
updatedAmtInPrice, err := k.Market.CalcAssetPrice(ctx, lendPos.AssetID, updatedAmtIn.TruncateInt())
if err != nil {
return err
Expand Down Expand Up @@ -1699,7 +1699,7 @@ func (k Keeper) CreteNewBorrow(ctx sdk.Context, liqBorrow liquidationtypes.Locke

// Adjusting bridged asset qty after auctions
if !kind.BridgedAssetAmount.Amount.Equal(sdk.ZeroInt()) {
amtIn, _ := k.Market.CalcAssetPrice(ctx, pair.AssetIn, sdk.NewDec(borrowPos.AmountIn.Amount.Int64()).Mul(assetInRatesStats.Ltv).TruncateInt())
amtIn, _ := k.Market.CalcAssetPrice(ctx, pair.AssetIn, sdk.NewDecFromInt(borrowPos.AmountIn.Amount).Mul(assetInRatesStats.Ltv).TruncateInt())
priceFirstBridgedAsset, _ := k.Market.CalcAssetPrice(ctx, firstTransitAssetID, sdk.OneInt())
priceSecondBridgedAsset, _ := k.Market.CalcAssetPrice(ctx, secondTransitAssetID, sdk.OneInt())
firstBridgedAsset, _ := k.Asset.GetAsset(ctx, firstTransitAssetID)
Expand Down
10 changes: 5 additions & 5 deletions x/lend/keeper/maths.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ func (k Keeper) GetUtilisationRatioByPoolIDAndAssetID(ctx sdk.Context, poolID, a
if !found {
return sdk.ZeroDec(), types.ErrAssetStatsNotFound
}
if sdk.NewDec(moduleBalance.Int64()).Add(sdk.NewDec(assetStats.TotalBorrowed.Add(assetStats.TotalStableBorrowed).Int64())).IsZero() {
if sdk.NewDecFromInt(moduleBalance).Add(sdk.NewDecFromInt(assetStats.TotalBorrowed.Add(assetStats.TotalStableBorrowed))).IsZero() {
return sdk.ZeroDec(), nil
}
utilizationRatio := (sdk.NewDec(assetStats.TotalBorrowed.Add(assetStats.TotalStableBorrowed).Int64())).Quo(sdk.NewDec(moduleBalance.Int64()).Add(sdk.NewDec(assetStats.TotalBorrowed.Add(assetStats.TotalStableBorrowed).Int64())))
utilizationRatio := (sdk.NewDecFromInt(assetStats.TotalBorrowed.Add(assetStats.TotalStableBorrowed))).Quo(sdk.NewDecFromInt(moduleBalance).Add(sdk.NewDecFromInt(assetStats.TotalBorrowed.Add(assetStats.TotalStableBorrowed))))
return utilizationRatio, nil
}

Expand Down Expand Up @@ -80,10 +80,10 @@ func (k Keeper) GetLendAPRByAssetIDAndPoolID(ctx sdk.Context, poolID, assetID ui

func (k Keeper) GetAverageBorrowRate(ctx sdk.Context, poolID, assetID uint64) (sdk.Dec, error) {
assetStats, _ := k.UpdateAPR(ctx, poolID, assetID)
factor1 := assetStats.BorrowApr.Mul(sdk.NewDec(assetStats.TotalBorrowed.Int64()))
factor2 := assetStats.StableBorrowApr.Mul(sdk.NewDec(assetStats.TotalStableBorrowed.Int64()))
factor1 := assetStats.BorrowApr.Mul(sdk.NewDecFromInt(assetStats.TotalBorrowed))
factor2 := assetStats.StableBorrowApr.Mul(sdk.NewDecFromInt(assetStats.TotalStableBorrowed))
numerator := factor1.Add(factor2)
denominator := sdk.NewDec(assetStats.TotalStableBorrowed.Add(assetStats.TotalBorrowed).Int64())
denominator := sdk.NewDecFromInt(assetStats.TotalStableBorrowed.Add(assetStats.TotalBorrowed))

if denominator.LTE(sdk.ZeroDec()) {
return sdk.ZeroDec(), types.ErrAverageBorrowRate
Expand Down
2 changes: 1 addition & 1 deletion x/liquidation/keeper/liquidate_borrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,5 +662,5 @@ func (s *KeeperTestSuite) TestLiquidateBorrows() {
updatedPrice := price.Sub(price.Mul(Dec("0.09090909090")))

s.Require().Equal(lockedVault[0].CollateralToBeAuctioned.TruncateInt(), updatedPrice.TruncateInt())
s.Require().Equal(lockedVault[0].CrAtLiquidation, sdk.NewDec(lockedVault[0].AmountOut.Int64()).Mul(s.GetAssetPrice(2)).Quo(sdk.NewDec(beforeAmtIn.Int64()).Mul(s.GetAssetPrice(1))))
s.Require().Equal(lockedVault[0].CrAtLiquidation, sdk.NewDecFromInt(lockedVault[0].AmountOut).Mul(s.GetAssetPrice(2)).Quo(sdk.NewDecFromInt(beforeAmtIn).Mul(s.GetAssetPrice(1))))
}
4 changes: 2 additions & 2 deletions x/liquidation/keeper/liquidate_vaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ func (s *KeeperTestSuite) TestLiquidateVaults1() {
price, err := s.app.MarketKeeper.CalcAssetPrice(*ctx, uint64(1), beforeVault.AmountIn)
s.Require().NoError(err)
s.Require().Equal(lockedVault[0].CollateralToBeAuctioned, price)
s.Require().Equal(lockedVault[0].CrAtLiquidation, sdk.NewDec(lockedVault[0].AmountIn.Int64()).Mul(s.GetAssetPrice(1)).Quo(sdk.NewDec(lockedVault[0].AmountOut.Int64()).Mul(s.GetAssetPrice(2))))
s.Require().Equal(lockedVault[0].CrAtLiquidation, sdk.NewDecFromInt(lockedVault[0].AmountIn).Mul(s.GetAssetPrice(1)).Quo(sdk.NewDecFromInt(lockedVault[0].AmountOut).Mul(s.GetAssetPrice(2))))
}

func (s *KeeperTestSuite) TestUpdateLockedVaults() {
s.TestLiquidateVaults1()
liquidationKeeper, ctx := &s.liquidationKeeper, &s.ctx

lockedVault1 := liquidationKeeper.GetLockedVaults(*ctx)
s.Require().Equal(lockedVault1[0].CrAtLiquidation, sdk.NewDec(lockedVault1[0].AmountIn.Int64()).Mul(s.GetAssetPrice(1)).Quo(sdk.NewDec(lockedVault1[0].AmountOut.Int64()).Mul(s.GetAssetPrice(2))))
s.Require().Equal(lockedVault1[0].CrAtLiquidation, sdk.NewDecFromInt(lockedVault1[0].AmountIn).Mul(s.GetAssetPrice(1)).Quo(sdk.NewDecFromInt(lockedVault1[0].AmountOut).Mul(s.GetAssetPrice(2))))
}

func (s *KeeperTestSuite) TestSetFlags() {
Expand Down
Loading

0 comments on commit 47bd654

Please sign in to comment.