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

refactor: rename lashare to sb(snowball) #191

Merged
merged 1 commit into from
Aug 31, 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
38 changes: 19 additions & 19 deletions x/liquidamm/keeper/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ func (s *KeeperTestSuite) TestPlaceBid() {

bidderAddr1 := utils.TestAddress(2)
s.MintShare(bidderAddr1, publicPosition.Id, utils.ParseCoins("100_000000ucre,500_000000uusd"), true)
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000lashare1"))
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000sb1"))
s.NextBlock()

s.AdvanceRewardsAuctions()

auction, _ = s.keeper.GetLastRewardsAuction(s.Ctx, publicPosition.Id)

s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000lashare1"))
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000sb1"))

bidderAddr2 := utils.TestAddress(3)
s.MintShare(bidderAddr2, publicPosition.Id, utils.ParseCoins("100_000000ucre,500_000000uusd"), true)
s.PlaceBid(bidderAddr2, publicPosition.Id, auction.Id, utils.ParseCoin("200000lashare1"))
s.PlaceBid(bidderAddr2, publicPosition.Id, auction.Id, utils.ParseCoin("200000sb1"))
s.NextBlock()

s.Require().Len(s.keeper.GetAllBids(s.Ctx), 2)
Expand All @@ -49,25 +49,25 @@ func (s *KeeperTestSuite) TestPlaceBid() {
{
"happy case",
types.NewMsgPlaceBid(
bidderAddr3, publicPosition.Id, auction.Id, utils.ParseCoin("300000lashare1")),
bidderAddr3, publicPosition.Id, auction.Id, utils.ParseCoin("300000sb1")),
"",
},
{
"minimum bid amount",
types.NewMsgPlaceBid(
bidderAddr3, publicPosition.Id, auction.Id, utils.ParseCoin("100lashare1")),
bidderAddr3, publicPosition.Id, auction.Id, utils.ParseCoin("100sb1")),
"share amount must not be smaller than 10000: invalid request",
},
{
"smaller than winning bid",
types.NewMsgPlaceBid(
bidderAddr3, publicPosition.Id, auction.Id, utils.ParseCoin("150000lashare1")),
bidderAddr3, publicPosition.Id, auction.Id, utils.ParseCoin("150000sb1")),
"share amount must be greater than winning bid's share 200000: insufficient bid amount",
},
{
"finished auction",
types.NewMsgPlaceBid(
bidderAddr3, publicPosition.Id, auction.Id-1, utils.ParseCoin("300000lashare1")),
bidderAddr3, publicPosition.Id, auction.Id-1, utils.ParseCoin("300000sb1")),
"rewards auction is not started: invalid request",
},
} {
Expand Down Expand Up @@ -146,14 +146,14 @@ func (s *KeeperTestSuite) TestPlaceBid_Refund() {

auction, found := s.keeper.GetLastRewardsAuction(s.Ctx, publicPosition.Id)
s.Require().True(found)
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000lashare1"))
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000sb1"))
s.NextBlock()

balancesBefore := s.GetAllBalances(bidderAddr1)
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("200000lashare1"))
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("200000sb1"))
s.NextBlock()
balancesAfter := s.GetAllBalances(bidderAddr1)
s.Require().Equal("100000lashare1", balancesBefore.Sub(balancesAfter).String())
s.Require().Equal("100000sb1", balancesBefore.Sub(balancesAfter).String())
}

func (s *KeeperTestSuite) TestAfterRewardsAllocated() {
Expand All @@ -177,26 +177,26 @@ func (s *KeeperTestSuite) TestAfterRewardsAllocated() {
s.MintShare(bidderAddr2, publicPosition.Id, utils.ParseCoins("100_000000ucre,500_000000uusd"), true)
s.MintShare(bidderAddr3, publicPosition.Id, utils.ParseCoins("100_000000ucre,500_000000uusd"), true)
// Previous share balance
s.Require().Equal("4357388321lashare1", s.GetBalance(bidderAddr1, "lashare1").String())
s.Require().Equal("4357388321lashare1", s.GetBalance(bidderAddr2, "lashare1").String())
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000lashare1"))
s.PlaceBid(bidderAddr2, publicPosition.Id, auction.Id, utils.ParseCoin("200000lashare1"))
s.PlaceBid(bidderAddr3, publicPosition.Id, auction.Id, utils.ParseCoin("300000lashare1"))
s.Require().Equal("4357388321sb1", s.GetBalance(bidderAddr1, "sb1").String())
s.Require().Equal("4357388321sb1", s.GetBalance(bidderAddr2, "sb1").String())
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000sb1"))
s.PlaceBid(bidderAddr2, publicPosition.Id, auction.Id, utils.ParseCoin("200000sb1"))
s.PlaceBid(bidderAddr3, publicPosition.Id, auction.Id, utils.ParseCoin("300000sb1"))

s.NextBlock()
s.AdvanceRewardsAuctions()

// Ensure that two bidders got their shares back to their balances
s.Require().Equal("4357388321lashare1", s.GetBalance(bidderAddr1, "lashare1").String())
s.Require().Equal("4357388321lashare1", s.GetBalance(bidderAddr2, "lashare1").String())
s.Require().Equal("4357388321sb1", s.GetBalance(bidderAddr1, "sb1").String())
s.Require().Equal("4357388321sb1", s.GetBalance(bidderAddr2, "sb1").String())
s.Require().True(s.GetBalance(bidderAddr3, "uatom").Amount.GT(sdk.NewInt(1)))

// One more epoch should be advanced
s.NextBlock()
s.AdvanceRewardsAuctions()

// Ensure liquidity per share increased due to the auction result
removedLiquidity, _, _ := s.BurnShare(minterAddr, publicPosition.Id, s.GetBalance(minterAddr, "lashare1"))
removedLiquidity, _, _ := s.BurnShare(minterAddr, publicPosition.Id, s.GetBalance(minterAddr, "sb1"))
s.Require().True(removedLiquidity.GT(liquidity))
}

Expand Down Expand Up @@ -233,7 +233,7 @@ func (s *KeeperTestSuite) TestRewardsAuction_RewardsAndFees() {
bidderAddr1 := utils.TestAddress(2)
s.MintShare(bidderAddr1, publicPosition.Id, utils.ParseCoins("100_000000ucre,500_000000uusd"), true)
auction, _ := s.keeper.GetLastRewardsAuction(s.Ctx, publicPosition.Id)
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000lashare1"))
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000sb1"))
s.NextBlock()

position := s.keeper.MustGetAMMPosition(s.Ctx, publicPosition)
Expand Down
2 changes: 1 addition & 1 deletion x/liquidamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (k Querier) Rewards(c context.Context, req *types.QueryRewardsRequest) (*ty
return &types.QueryRewardsResponse{Rewards: rewards}, nil
}

// ExchangeRate queries exchange rate, such as mint rate and burn rate per 1 lashare.
// ExchangeRate queries exchange rate, such as mint rate and burn rate per 1 sb.
func (k Querier) ExchangeRate(c context.Context, req *types.QueryExchangeRateRequest) (*types.QueryExchangeRateResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
Expand Down
4 changes: 2 additions & 2 deletions x/liquidamm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func (s *KeeperTestSuite) TestQueryRewardsAuctions() {
auction := resp.RewardsAuctions[0]
s.Require().EqualValues(1, auction.Id)
s.Require().Equal(types.AuctionStatusFinished, auction.Status)
s.Require().Equal(utils.ParseCoin("1307216496lashare1"), auction.WinningBid.Share)
s.Require().Equal(utils.ParseCoin("1307216496sb1"), auction.WinningBid.Share)
auction = resp.RewardsAuctions[1]
s.Require().EqualValues(2, auction.Id)
s.Require().Equal(types.AuctionStatusStarted, auction.Status)
s.Require().Equal(utils.ParseCoin("814642164lashare1"), auction.WinningBid.Share)
s.Require().Equal(utils.ParseCoin("814642164sb1"), auction.WinningBid.Share)
},
},
{
Expand Down
26 changes: 13 additions & 13 deletions x/liquidamm/keeper/public_position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *KeeperTestSuite) TestMintShare() {
utils.ParseCoins("100_000000ucre,500_000000uusd"),
),
func(resp *types.MsgMintShareResponse) {
s.Require().Equal(utils.ParseCoin("4357388321lashare1"), resp.MintedShare)
s.Require().Equal(utils.ParseCoin("4357388321sb1"), resp.MintedShare)
s.Require().Equal(sdk.NewInt(4357388321), resp.Liquidity)
s.Require().Equal(utils.ParseCoins("90686676ucre,500000000uusd"), resp.Amount)
},
Expand Down Expand Up @@ -104,7 +104,7 @@ func (s *KeeperTestSuite) TestBurnShare() {
}{
{
"happy case",
types.NewMsgBurnShare(minterAddr, publicPosition.Id, utils.ParseCoin("100000lashare1")),
types.NewMsgBurnShare(minterAddr, publicPosition.Id, utils.ParseCoin("100000sb1")),
func(resp *types.MsgBurnShareResponse) {
s.Require().Equal(sdk.NewInt(100000), resp.RemovedLiquidity)
s.Require().Equal(utils.ParseCoins("2081ucre,11474uusd"), resp.Amount)
Expand All @@ -116,7 +116,7 @@ func (s *KeeperTestSuite) TestBurnShare() {
types.NewMsgBurnShare(
minterAddr,
2,
utils.ParseCoin("100000lashare2"),
utils.ParseCoin("100000sb2"),
),
nil,
"public position not found: not found",
Expand Down Expand Up @@ -149,8 +149,8 @@ func (s *KeeperTestSuite) TestBurnShare_Complex_WithRewards() {
s.NextBlock()

// Ensure that the minters have received the minted share
s.Require().Equal("4357388321lashare1", s.GetBalance(minterAddr1, "lashare1").String())
s.Require().Equal("8714776642lashare1", s.GetBalance(minterAddr2, "lashare1").String())
s.Require().Equal("4357388321sb1", s.GetBalance(minterAddr1, "sb1").String())
s.Require().Equal("8714776642sb1", s.GetBalance(minterAddr2, "sb1").String())

s.AdvanceRewardsAuctions()

Expand All @@ -162,8 +162,8 @@ func (s *KeeperTestSuite) TestBurnShare_Complex_WithRewards() {
bidderAddr2 := utils.TestAddress(4)
s.MintShare(bidderAddr1, publicPosition.Id, utils.ParseCoins("100_000000ucre,500_000000uusd"), true)
s.MintShare(bidderAddr2, publicPosition.Id, utils.ParseCoins("200_000000ucre,1000_000000uusd"), true)
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000lashare1"))
s.PlaceBid(bidderAddr2, publicPosition.Id, auction.Id, utils.ParseCoin("200000lashare1"))
s.PlaceBid(bidderAddr1, publicPosition.Id, auction.Id, utils.ParseCoin("100000sb1"))
s.PlaceBid(bidderAddr2, publicPosition.Id, auction.Id, utils.ParseCoin("200000sb1"))
s.NextBlock()

s.AdvanceRewardsAuctions()
Expand All @@ -172,7 +172,7 @@ func (s *KeeperTestSuite) TestBurnShare_Complex_WithRewards() {
publicPosition, _ = s.keeper.GetPublicPosition(s.Ctx, publicPosition.Id)
auction, found = s.keeper.GetPreviousRewardsAuction(s.Ctx, publicPosition)
s.Require().True(found)
s.Require().Equal("200000lashare1", auction.WinningBid.Share.String())
s.Require().Equal("200000sb1", auction.WinningBid.Share.String())

// Ensure bidderAddr2 has received rewards
s.Require().True(s.GetBalance(bidderAddr2, "uatom").Amount.GT(sdk.NewInt(1)))
Expand All @@ -185,21 +185,21 @@ func (s *KeeperTestSuite) TestBurnShare_Complex_WithRewards() {
auction, _ = s.keeper.GetLastRewardsAuction(s.Ctx, publicPosition.Id)
s.MintShare(bidderAddr3, publicPosition.Id, utils.ParseCoins("100_000000ucre,500_000000uusd"), true)
s.MintShare(bidderAddr4, publicPosition.Id, utils.ParseCoins("300_000000ucre,1500_000000uusd"), true)
s.PlaceBid(bidderAddr3, publicPosition.Id, auction.Id, utils.ParseCoin("100000lashare1"))
s.PlaceBid(bidderAddr4, publicPosition.Id, auction.Id, utils.ParseCoin("300000lashare1"))
s.PlaceBid(bidderAddr3, publicPosition.Id, auction.Id, utils.ParseCoin("100000sb1"))
s.PlaceBid(bidderAddr4, publicPosition.Id, auction.Id, utils.ParseCoin("300000sb1"))

s.AdvanceRewardsAuctions()

// Ensure compounding rewards are updated with the new bidding amount in the store
publicPosition, _ = s.keeper.GetPublicPosition(s.Ctx, publicPosition.Id)
auction, found = s.keeper.GetPreviousRewardsAuction(s.Ctx, publicPosition)
s.Require().True(found)
s.Require().Equal("300000lashare1", auction.WinningBid.Share.String())
s.Require().Equal("300000sb1", auction.WinningBid.Share.String())

// Ensure bidderAddr4 has received farming rewards
s.Require().True(s.GetBalance(bidderAddr4, "uatom").Amount.GT(sdk.NewInt(1)))

// Burn all shares
s.BurnShare(minterAddr1, publicPosition.Id, s.GetBalance(minterAddr1, "lashare1"))
s.BurnShare(minterAddr2, publicPosition.Id, s.GetBalance(minterAddr2, "lashare1"))
s.BurnShare(minterAddr1, publicPosition.Id, s.GetBalance(minterAddr1, "sb1"))
s.BurnShare(minterAddr2, publicPosition.Id, s.GetBalance(minterAddr2, "sb1"))
}
12 changes: 6 additions & 6 deletions x/liquidamm/types/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestRewardsAuction_Validate(t *testing.T) {
auction := types.NewRewardsAuction(
1, 2, utils.ParseTime("2023-05-01T00:00:00Z"), utils.ParseTime("2023-05-01T01:00:00Z"),
types.AuctionStatusStarted)
winningBid := types.NewBid(1, 2, utils.TestAddress(1), utils.ParseCoin("10000lashare1"))
winningBid := types.NewBid(1, 2, utils.TestAddress(1), utils.ParseCoin("10000sb1"))
auction.SetWinningBid(&winningBid)
auction.SetRewards(utils.ParseCoins("100000uatom"))
auction.SetFees(utils.ParseCoins("300uatom"))
Expand Down Expand Up @@ -132,20 +132,20 @@ func TestBidValidate(t *testing.T) {
{
"invalid share",
func(bid *types.Bid) {
bid.Share = utils.ParseCoin("0lashare1")
bid.Share = utils.ParseCoin("0sb1")
},
"share amount must be positive: 0lashare1",
"share amount must be positive: 0sb1",
},
{
"invalid share denom",
func(bid *types.Bid) {
bid.Share = utils.ParseCoin("10000lashare2")
bid.Share = utils.ParseCoin("10000sb2")
},
"share denom must be lashare1",
"share denom must be sb1",
},
} {
t.Run(tc.name, func(t *testing.T) {
bid := types.NewBid(1, 2, utils.TestAddress(1), utils.ParseCoin("10000lashare1"))
bid := types.NewBid(1, 2, utils.TestAddress(1), utils.ParseCoin("10000sb1"))
tc.malleate(&bid)
err := bid.Validate()
if tc.expectedErr == "" {
Expand Down
20 changes: 10 additions & 10 deletions x/liquidamm/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,20 @@ func TestMsgBurnShare(t *testing.T) {
{
"invalid share",
func(msg *types.MsgBurnShare) {
msg.Share = utils.ParseCoin("0lashare1")
msg.Share = utils.ParseCoin("0sb1")
},
"share amount must be positive: 0lashare1: invalid request",
"share amount must be positive: 0sb1: invalid request",
},
{
"invalid share denom",
func(msg *types.MsgBurnShare) {
msg.Share = utils.ParseCoin("10000lashare2")
msg.Share = utils.ParseCoin("10000sb2")
},
"share denom must be lashare1: invalid request",
"share denom must be sb1: invalid request",
},
} {
t.Run(tc.name, func(t *testing.T) {
msg := types.NewMsgBurnShare(utils.TestAddress(0), 1, utils.ParseCoin("1000000lashare1"))
msg := types.NewMsgBurnShare(utils.TestAddress(0), 1, utils.ParseCoin("1000000sb1"))
tc.malleate(msg)
require.Equal(t, types.TypeMsgBurnShare, msg.Type())
require.Equal(t, types.RouterKey, msg.Route())
Expand Down Expand Up @@ -178,20 +178,20 @@ func TestMsgPlaceBid(t *testing.T) {
{
"invalid share",
func(msg *types.MsgPlaceBid) {
msg.Share = utils.ParseCoin("0lashare1")
msg.Share = utils.ParseCoin("0sb1")
},
"share amount must be positive: 0lashare1: invalid request",
"share amount must be positive: 0sb1: invalid request",
},
{
"invalid share denom",
func(msg *types.MsgPlaceBid) {
msg.Share = utils.ParseCoin("10000lashare2")
msg.Share = utils.ParseCoin("10000sb2")
},
"share denom must be lashare1: invalid request",
"share denom must be sb1: invalid request",
},
} {
t.Run(tc.name, func(t *testing.T) {
msg := types.NewMsgPlaceBid(utils.TestAddress(0), 1, 1, utils.ParseCoin("1000000lashare1"))
msg := types.NewMsgPlaceBid(utils.TestAddress(0), 1, 1, utils.ParseCoin("1000000sb1"))
tc.malleate(msg)
require.Equal(t, types.TypeMsgPlaceBid, msg.Type())
require.Equal(t, types.RouterKey, msg.Route())
Expand Down
4 changes: 2 additions & 2 deletions x/liquidamm/types/public_position.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
)

const (
ShareDenomPrefix = "lashare"
ShareDenomPrefix = "sb"
)

var (
shareDenomRe = regexp.MustCompile(`^lashare([1-9]\d*)$`)
shareDenomRe = regexp.MustCompile(`^sb([1-9]\d*)$`)
)

// DeriveBidReserveAddress creates the reserve address for bids
Expand Down
16 changes: 8 additions & 8 deletions x/liquidamm/types/public_position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func TestShareDenom(t *testing.T) {
denom string
expectsErr bool
}{
{"lashare1", false},
{"lashare10", false},
{"lashare18446744073709551615", false},
{"lashare18446744073709551616", true},
{"lashareabc", true},
{"lashare01", true},
{"lashare-10", true},
{"lashare+10", true},
{"sb1", false},
{"sb10", false},
{"sb18446744073709551615", false},
{"sb18446744073709551616", true},
{"sbabc", true},
{"sb01", true},
{"sb-10", true},
{"sb+10", true},
{"ucre", true},
{"denom1", true},
} {
Expand Down