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

feat: implement MaxSupply #1319

Merged
merged 56 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ca8df09
supply and withdraw tests
toteki Aug 25, 2022
d17672e
err--
toteki Aug 25, 2022
3f6e746
make proto-all
toteki Aug 25, 2022
18ad3f9
error improvements and fix cascading client test error DEVX
toteki Aug 29, 2022
01a0d9d
TestCollateralize
toteki Aug 29, 2022
55e0242
++
toteki Aug 29, 2022
3ac25d8
TestDe+Collateralize
toteki Aug 29, 2022
fb2465d
case++
toteki Aug 29, 2022
196a2dd
borrow test + more cases
toteki Aug 29, 2022
0c89068
add invariant checks to every msg test case
toteki Aug 29, 2022
a7c28ad
move files
toteki Aug 29, 2022
c24c19b
++
toteki Aug 29, 2022
7bf90ef
TestRepay
toteki Aug 29, 2022
da7a29d
--
toteki Aug 29, 2022
8bdbc1f
Liquidate single-denom test cases
toteki Aug 29, 2022
29075d0
liquidate cases
toteki Aug 30, 2022
f4d3fbf
--
toteki Aug 30, 2022
b6c065b
remove setupAccount and initBorrowScenario
toteki Aug 30, 2022
e0f12e0
Merge branch 'main' into adam/tests
toteki Aug 30, 2022
c317fae
imports
toteki Aug 30, 2022
84b454b
lint++
toteki Aug 30, 2022
137b60b
fix test
toteki Aug 30, 2022
16f6087
++
toteki Aug 30, 2022
c951541
cl++
toteki Aug 30, 2022
abc1520
remove unnecessary interface
toteki Aug 30, 2022
58d3dab
move function
toteki Aug 30, 2022
c38f47f
Merge branch 'main' into adam/tests
toteki Aug 30, 2022
357b4c3
apply s.app, s.ctx, and s.Require() shorthands
toteki Aug 30, 2022
b0058d0
Merge branch 'adam/tests' of github.com:umee-network/umee into adam/t…
toteki Aug 30, 2022
2d7c253
apply coin shorthand in keeper_test package
toteki Aug 30, 2022
104e8f2
use setReserves helper
toteki Aug 30, 2022
f19ad73
improve big number readability
toteki Aug 30, 2022
d69a209
Merge branch 'main' into adam/tests
toteki Aug 30, 2022
29464d2
ensure espected value is on the left for all require.Equal
toteki Aug 30, 2022
95aa22b
use borrow and repay helpers
toteki Aug 30, 2022
28c4707
lint++
toteki Aug 30, 2022
2031109
always require.ErrorIs
toteki Aug 30, 2022
e4c6f67
use forceBorrow helper rather than SetTokenSettings in high utilizati…
toteki Aug 30, 2022
09daf91
Merge branch 'main' into adam/tests
toteki Aug 30, 2022
ed7b666
Merge branch 'main' into adam/tests
toteki Aug 30, 2022
187c0fe
fix #1310
toteki Aug 31, 2022
b0f0ba9
add max supply restriction and test case
toteki Aug 31, 2022
ace8889
Merge branch 'main' into adam/tests
toteki Aug 31, 2022
b3379b6
fix sim tests
toteki Sep 1, 2022
526296d
Merge branch 'adam/tests' into adam/limits
toteki Sep 1, 2022
4e0d6c1
Merge branch 'main' into adam/limits
toteki Sep 1, 2022
826e5bf
Merge branch 'main' into adam/limits
toteki Sep 2, 2022
83b71e2
Merge branch 'main' into adam/limits
RafilxTenfen Sep 6, 2022
4f3cf85
suggestion++
toteki Sep 6, 2022
a758524
suggestion++
toteki Sep 6, 2022
a2a3eae
follow suggested underscore
toteki Sep 6, 2022
8453918
Merge branch 'main' into adam/limits
toteki Sep 6, 2022
069b733
cl++
toteki Sep 6, 2022
54590c9
Merge branch 'main' into adam/limits
toteki Sep 6, 2022
2bd1d57
Merge branch 'main' into adam/limits
toteki Sep 6, 2022
ac1cd1f
Merge branch 'main' into adam/limits
toteki Sep 7, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [1323](https://github.com/umee-network/umee/pull/1323) Oracle cli - Add validator address override option.
- [1329](https://github.com/umee-network/umee/pull/1329) Implement MaxCollateralShare.
- [1330](https://github.com/umee-network/umee/pull/1330) Implemented MaxSupplyUtilization.
- [1319](https://github.com/umee-network/umee/pull/1319) Implemented MaxSupply.
- [1331](https://github.com/umee-network/umee/pull/1331) Implemented MinCollateralLiquidity.

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion x/leverage/fixtures/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ func Token(base, symbol string) types.Token {
MaxCollateralShare: sdk.MustNewDecFromStr("1"),
MaxSupplyUtilization: sdk.MustNewDecFromStr("0.9"),
MinCollateralLiquidity: sdk.MustNewDecFromStr("0"),
MaxSupply: sdk.NewInt(100000000000),
MaxSupply: sdk.NewInt(100_000_000000),
}
}
15 changes: 15 additions & 0 deletions x/leverage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ func (k Keeper) Supply(ctx sdk.Context, supplierAddr sdk.AccAddress, coin sdk.Co
return sdk.Coin{}, err
}

token, err := k.GetTokenSettings(ctx, coin.Denom)
if err != nil {
return sdk.Coin{}, err
}

total, err := k.GetTotalSupply(ctx, coin.Denom)
if err != nil {
return sdk.Coin{}, err
}

if token.MaxSupply.IsPositive() && total.Add(coin).Amount.GTE(token.MaxSupply) {
return sdk.Coin{}, types.ErrMaxSupply.Wrapf("attempted: %s, current supply: %s, max supply: %s",
coin, total.Amount, token.MaxSupply)
}

// determine uToken amount to mint
uToken, err := k.ExchangeToken(ctx, coin)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions x/leverage/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func (s *IntegrationTestSuite) TestSupply() {
s.borrow(borrower, coin(atomDenom, 10_000000))
s.tk.SetBorrow(ctx, borrower, coin(atomDenom, 60_000000))

// create a supplier that will exceed token's default MaxSupply
whale := s.newAccount(coin(umeeDenom, 1_000_000_000000))

tcs := []testCase{
{
"unregistered denom",
Expand Down Expand Up @@ -78,6 +81,13 @@ func (s *IntegrationTestSuite) TestSupply() {
coin("u/"+atomDenom, 40_000000),
nil,
},
{
"max supply",
whale,
coin(umeeDenom, 1_000_000_000000),
sdk.Coin{},
types.ErrMaxSupply,
},
}

for _, tc := range tcs {
Expand Down
1 change: 1 addition & 0 deletions x/leverage/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
ErrMaxSupplyUtilization = sdkerrors.Register(ModuleName, 501, "market would exceed MaxSupplyUtilization")
ErrMinCollateralLiquidity = sdkerrors.Register(ModuleName, 502, "market would fall below MinCollateralLiquidity")
ErrMaxCollateralShare = sdkerrors.Register(ModuleName, 503, "market would exceed MaxCollateralShare")
ErrMaxSupply = sdkerrors.Register(ModuleName, 504, "market would exceed MaxSupply")

// 6XX = Internal Failsafes
ErrInvalidUtilization = sdkerrors.Register(ModuleName, 600, "invalid token utilization")
Expand Down