Skip to content

Commit

Permalink
improve big number readability
Browse files Browse the repository at this point in the history
  • Loading branch information
toteki committed Aug 30, 2022
1 parent 104e8f2 commit f19ad73
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions x/leverage/keeper/borrows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (s *IntegrationTestSuite) TestCalculateBorrowLimit() {

// Create collateral uTokens (1k u/umee)
umeeCollatDenom := types.ToUTokenDenom(umeeDenom)
umeeCollateral := sdk.NewCoins(coin(umeeCollatDenom, 1000000000))
umeeCollateral := sdk.NewCoins(coin(umeeCollatDenom, 1000_000000))

// Manually compute borrow limit using collateral weight of 0.25
// and placeholder of 1 umee = $4.21.
Expand All @@ -228,7 +228,7 @@ func (s *IntegrationTestSuite) TestCalculateBorrowLimit() {

// Create collateral atom uTokens (1k u/uatom)
atomCollatDenom := types.ToUTokenDenom(atomDenom)
atomCollateral := sdk.NewCoins(coin(atomCollatDenom, 1000000000))
atomCollateral := sdk.NewCoins(coin(atomCollatDenom, 1000_000000))

// Manually compute borrow limit using collateral weight of 0.25
// and placeholder of 1 atom = $39.38
Expand Down
14 changes: 7 additions & 7 deletions x/leverage/keeper/interest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ func (s *IntegrationTestSuite) TestAccrueZeroInterest() {
s.collateralize(addr, coin("u/"+umeeDenom, 1000_000000))

// user borrows 40 umee
err := app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 40000000))
err := app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 40_000000))
require.NoError(err)

// verify user's loan amount (40 umee)
loanBalance := app.LeverageKeeper.GetBorrow(ctx, addr, umeeapp.BondDenom)
require.Equal(loanBalance, coin(umeeapp.BondDenom, 40000000))
require.Equal(loanBalance, coin(umeeapp.BondDenom, 40_000000))

// Because no time has passed since genesis (due to test setup) this will not
// increase borrowed amount.
Expand All @@ -29,7 +29,7 @@ func (s *IntegrationTestSuite) TestAccrueZeroInterest() {

// verify user's loan amount (40 umee)
loanBalance = app.LeverageKeeper.GetBorrow(ctx, addr, umeeapp.BondDenom)
require.Equal(loanBalance, coin(umeeapp.BondDenom, 40000000))
require.Equal(loanBalance, coin(umeeapp.BondDenom, 40_000000))

// borrow APY at utilization = 4%
// when kink utilization = 80%, and base/kink APY are 0.02 and 0.22
Expand Down Expand Up @@ -63,15 +63,15 @@ func (s *IntegrationTestSuite) TestDynamicInterest() {
require.Equal(rate, sdk.MustNewDecFromStr("0.02"))

// user borrows 200 umee, utilization 200/1000
err := app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 200000000))
err := app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 200_000000))
require.NoError(err)

// Between base interest and kink (20% utilization)
rate = app.LeverageKeeper.DeriveBorrowAPY(ctx, umeeapp.BondDenom)
require.Equal(rate, sdk.MustNewDecFromStr("0.07"))

// user borrows 600 more umee, utilization 800/1000
err = app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 600000000))
err = app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 600_000000))
require.NoError(err)

// Kink interest rate (80% utilization)
Expand All @@ -80,7 +80,7 @@ func (s *IntegrationTestSuite) TestDynamicInterest() {
require.Equal(rate, sdk.MustNewDecFromStr("0.22"))

// user borrows 100 more umee, utilization 900/1000
err = app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 100000000))
err = app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 100_000000))
require.NoError(err)

// Between kink interest and max (90% utilization)
Expand All @@ -89,7 +89,7 @@ func (s *IntegrationTestSuite) TestDynamicInterest() {
require.Equal(rate, sdk.MustNewDecFromStr("0.87"))

// user borrows 100 more umee, utilization 1000/1000
err = app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 100000000))
err = app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 100_000000))
require.NoError(err)

// Max interest rate (100% utilization)
Expand Down
6 changes: 3 additions & 3 deletions x/leverage/keeper/invariants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *IntegrationTestSuite) TestCollateralAmountInvariant() {
uTokenDenom := types.ToUTokenDenom(umeeapp.BondDenom)

// withdraw the supplied umee in the initBorrowScenario
_, err := app.LeverageKeeper.Withdraw(ctx, addr, coin(uTokenDenom, 1000000000))
_, err := app.LeverageKeeper.Withdraw(ctx, addr, coin(uTokenDenom, 1000_000000))
require.NoError(err)

// check invariant
Expand All @@ -49,7 +49,7 @@ func (s *IntegrationTestSuite) TestBorrowAmountInvariant() {
s.collateralize(addr, coin("u/"+umeeDenom, 1000_000000))

// user borrows 20 umee
err := app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 20000000))
err := app.LeverageKeeper.Borrow(ctx, addr, coin(umeeapp.BondDenom, 20_000000))
require.NoError(err)

// check invariant
Expand All @@ -58,7 +58,7 @@ func (s *IntegrationTestSuite) TestBorrowAmountInvariant() {

// user repays 30 umee, actually only 20 because is the min between
// the amount borrowed and the amount repaid
_, err = app.LeverageKeeper.Repay(ctx, addr, coin(umeeapp.BondDenom, 30000000))
_, err = app.LeverageKeeper.Repay(ctx, addr, coin(umeeapp.BondDenom, 30_000000))
require.NoError(err)

// check invariant
Expand Down
2 changes: 1 addition & 1 deletion x/leverage/keeper/iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *IntegrationTestSuite) TestGetEligibleLiquidationTargets_OneAddrTwoAsset
// user borrows 4 atom (max current allowed - 1) user amount enabled as collateral * CollateralWeight
// = (50 * 0.1) - 1
// = 4app.
err = app.LeverageKeeper.Borrow(s.ctx, addr, coin(atomDenom, 4000000)) // 4 atom
err = app.LeverageKeeper.Borrow(s.ctx, addr, coin(atomDenom, 4_000000))
require.NoError(err)

// Note: Setting umee liquidation threshold to 0.05 to make the user eligible for liquidation
Expand Down
14 changes: 7 additions & 7 deletions x/leverage/keeper/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func (s *IntegrationTestSuite) TestOracle_TokenValue() {
app, ctx, require := s.app, s.ctx, s.Require()

// 2.4 UMEE * $4.21
v, err := app.LeverageKeeper.TokenValue(ctx, coin(umeeapp.BondDenom, 2400000))
v, err := app.LeverageKeeper.TokenValue(ctx, coin(umeeapp.BondDenom, 2_400000))
require.NoError(err)
require.Equal(sdk.MustNewDecFromStr("10.104"), v)

v, err = app.LeverageKeeper.TokenValue(ctx, coin("foo", 2400000))
v, err = app.LeverageKeeper.TokenValue(ctx, coin("foo", 2_400000))
require.Error(err)
require.Equal(sdk.ZeroDec(), v)
}
Expand All @@ -83,8 +83,8 @@ func (s *IntegrationTestSuite) TestOracle_TotalTokenValue() {
v, err := app.LeverageKeeper.TotalTokenValue(
ctx,
sdk.NewCoins(
coin(umeeapp.BondDenom, 2400000),
coin(atomDenom, 4700000),
coin(umeeapp.BondDenom, 2_400000),
coin(atomDenom, 4_700000),
),
)
require.NoError(err)
Expand All @@ -94,9 +94,9 @@ func (s *IntegrationTestSuite) TestOracle_TotalTokenValue() {
v, err = app.LeverageKeeper.TotalTokenValue(
ctx,
sdk.NewCoins(
coin(umeeapp.BondDenom, 2400000),
coin(atomDenom, 4700000),
coin("foo", 4700000),
coin(umeeapp.BondDenom, 2_400000),
coin(atomDenom, 4_700000),
coin("foo", 4_700000),
),
)
require.NoError(err)
Expand Down
12 changes: 6 additions & 6 deletions x/leverage/keeper/reserves_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (s *IntegrationTestSuite) TestSetReserves() {
s.setReserves(coin(umeeapp.BondDenom, 200_000000))
// get new reserves
amount = app.LeverageKeeper.GetReserveAmount(ctx, umeeapp.BondDenom)
require.Equal(amount, sdk.NewInt(200000000))
require.Equal(amount, sdk.NewInt(200_000000))
}

func (s *IntegrationTestSuite) TestRepayBadDebt() {
Expand All @@ -31,15 +31,15 @@ func (s *IntegrationTestSuite) TestRepayBadDebt() {
addr2 := s.newAccount()

// Create an uncollateralized debt position
badDebt := coin(umeeDenom, 100000000) // 100 umee
badDebt := coin(umeeDenom, 100_000000)
err := s.tk.SetBorrow(ctx, addr2, badDebt)
require.NoError(err)

// Manually mark the bad debt for repayment
require.NoError(s.tk.SetBadDebtAddress(ctx, addr2, umeeDenom, true))

// Manually set reserves to 60 umee
reserve := coin(umeeDenom, 60000000)
reserve := coin(umeeDenom, 60_000000)
s.setReserves(reserve)

// Sweep all bad debts, which should repay 60 umee of the bad debt (partial repayment)
Expand All @@ -48,14 +48,14 @@ func (s *IntegrationTestSuite) TestRepayBadDebt() {

// Confirm that a debt of 40 umee remains
remainingDebt := app.LeverageKeeper.GetBorrow(ctx, addr2, umeeDenom)
require.Equal(coin(umeeDenom, 40000000), remainingDebt)
require.Equal(coin(umeeDenom, 40_000000), remainingDebt)

// Confirm that reserves are exhausted
remainingReserve := app.LeverageKeeper.GetReserveAmount(ctx, umeeDenom)
require.Equal(sdk.ZeroInt(), remainingReserve)

// Manually set reserves to 70 umee
reserve = coin(umeeDenom, 70000000)
reserve = coin(umeeDenom, 70_000000)
s.setReserves(reserve)

// Sweep all bad debts, which should fully repay the bad debt this time
Expand All @@ -68,7 +68,7 @@ func (s *IntegrationTestSuite) TestRepayBadDebt() {

// Confirm that reserves are now at 30 umee
remainingReserve = app.LeverageKeeper.GetReserveAmount(ctx, umeeDenom)
require.Equal(sdk.NewInt(30000000), remainingReserve)
require.Equal(sdk.NewInt(30_000000), remainingReserve)

// Sweep all bad debts - but there are none
err = app.LeverageKeeper.SweepBadDebts(ctx)
Expand Down
5 changes: 2 additions & 3 deletions x/leverage/keeper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import (
)

const (
initialPower = int64(10000000000)
umeeDenom = umeeapp.BondDenom
atomDenom = fixtures.AtomDenom
umeeDenom = umeeapp.BondDenom
atomDenom = fixtures.AtomDenom
)

type IntegrationTestSuite struct {
Expand Down

0 comments on commit f19ad73

Please sign in to comment.