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: rename nftbackedloan #667

Merged
merged 1 commit into from
Aug 11, 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
4 changes: 2 additions & 2 deletions proto/ununifi/nftbackedloan/nftbackedloan.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ message Listing {
string owner = 2;
ListingState state = 3;
string bid_denom = 4;
string minimum_deposit_rate = 5 [
string min_deposit_rate = 5 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
google.protobuf.Duration minimum_bid_period = 6 [
google.protobuf.Duration min_bid_period = 6 [
(gogoproto.stdduration) = true,
(gogoproto.nullable) = false
];
Expand Down
4 changes: 2 additions & 2 deletions proto/ununifi/nftbackedloan/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ message MsgListNft {
string sender = 1;
NftId nft_id = 2 [(gogoproto.nullable) = false];
string bid_denom = 3;
string minimum_deposit_rate = 4 [
string min_deposit_rate = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
google.protobuf.Duration minimum_bidding_period = 5 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
google.protobuf.Duration min_bid_period = 5 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
}
message MsgListNftResponse {}

Expand Down
4 changes: 2 additions & 2 deletions x/nftbackedloan/keeper/bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ func (k Keeper) PlaceBid(ctx sdk.Context, msg *types.MsgPlaceBid) error {
}

// check over min_deposit_rate
minDeposit := listing.MinimumDepositRate.Mul(sdk.NewDecFromInt(msg.Price.Amount)).TruncateInt()
minDeposit := listing.MinDepositRate.Mul(sdk.NewDecFromInt(msg.Price.Amount)).TruncateInt()
if msg.Deposit.Amount.LT(minDeposit) {
return types.ErrInvalidDepositAmount
}

// todo add test case
minimumBiddingPeriodHour := time.Now().Add(listing.MinimumBidPeriod)
minimumBiddingPeriodHour := time.Now().Add(listing.MinBidPeriod)
if msg.Expiry.Before(minimumBiddingPeriodHour) {
return types.ErrSmallExpiryPeriod
}
Expand Down
60 changes: 30 additions & 30 deletions x/nftbackedloan/keeper/bid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func (suite *KeeperTestSuite) TestPlaceBid() {
bidder := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes())

listing := types.Listing{
NftId: types.NftId{ClassId: "class1", TokenId: "nft1"},
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: "uguu",
MinimumDepositRate: sdk.NewDecWithPrec(1, 1),
StartedAt: time.Now(),
NftId: types.NftId{ClassId: "class1", TokenId: "nft1"},
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: "uguu",
MinDepositRate: sdk.NewDecWithPrec(1, 1),
StartedAt: time.Now(),
}

tests := []struct {
Expand Down Expand Up @@ -93,10 +93,10 @@ func (suite *KeeperTestSuite) TestPlaceBid() {
}, owner)

err := suite.app.NftbackedloanKeeper.ListNft(suite.ctx, &types.MsgListNft{
Sender: listing.Owner,
NftId: listing.NftId,
BidDenom: listing.BidDenom,
MinimumDepositRate: listing.MinimumDepositRate,
Sender: listing.Owner,
NftId: listing.NftId,
BidDenom: listing.BidDenom,
MinDepositRate: listing.MinDepositRate,
})
suite.Require().NoError(err)

Expand All @@ -120,12 +120,12 @@ func (suite *KeeperTestSuite) TestSafeCloseBid() {
bidder := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes())

listing := types.Listing{
NftId: types.NftId{ClassId: "class1", TokenId: "nft1"},
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: "uguu",
MinimumDepositRate: sdk.NewDecWithPrec(1, 1),
StartedAt: time.Now(),
NftId: types.NftId{ClassId: "class1", TokenId: "nft1"},
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: "uguu",
MinDepositRate: sdk.NewDecWithPrec(1, 1),
StartedAt: time.Now(),
}

tests := []struct {
Expand Down Expand Up @@ -171,10 +171,10 @@ func (suite *KeeperTestSuite) TestSafeCloseBid() {
}, owner)

err := suite.app.NftbackedloanKeeper.ListNft(suite.ctx, &types.MsgListNft{
Sender: listing.Owner,
NftId: listing.NftId,
BidDenom: listing.BidDenom,
MinimumDepositRate: listing.MinimumDepositRate,
Sender: listing.Owner,
NftId: listing.NftId,
BidDenom: listing.BidDenom,
MinDepositRate: listing.MinDepositRate,
})
suite.Require().NoError(err)

Expand Down Expand Up @@ -202,12 +202,12 @@ func (suite *KeeperTestSuite) TestPayRemainder() {
bidder := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes())

listing := types.Listing{
NftId: types.NftId{ClassId: "class1", TokenId: "nft1"},
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: "uguu",
MinimumDepositRate: sdk.NewDecWithPrec(1, 1),
StartedAt: time.Now(),
NftId: types.NftId{ClassId: "class1", TokenId: "nft1"},
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: "uguu",
MinDepositRate: sdk.NewDecWithPrec(1, 1),
StartedAt: time.Now(),
}

tests := []struct {
Expand Down Expand Up @@ -255,10 +255,10 @@ func (suite *KeeperTestSuite) TestPayRemainder() {
}, owner)

err := suite.app.NftbackedloanKeeper.ListNft(suite.ctx, &types.MsgListNft{
Sender: listing.Owner,
NftId: listing.NftId,
BidDenom: listing.BidDenom,
MinimumDepositRate: listing.MinimumDepositRate,
Sender: listing.Owner,
NftId: listing.NftId,
BidDenom: listing.BidDenom,
MinDepositRate: listing.MinDepositRate,
})
suite.Require().NoError(err)

Expand Down
16 changes: 8 additions & 8 deletions x/nftbackedloan/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *KeeperTestSuite) TestListedNfts() {
Owner: s.addrs[0].String(),
State: 1,
BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
StartedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
LiquidatedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
FullPaymentEndAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
Expand All @@ -88,7 +88,7 @@ func (s *KeeperTestSuite) TestListedNfts() {
NftId: types.NftId{ClassId: "class5", TokenId: "nft5"},
Owner: s.addrs[0].String(),
State: 1, BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
StartedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
LiquidatedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
FullPaymentEndAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
Expand All @@ -110,7 +110,7 @@ func (s *KeeperTestSuite) TestListedNfts() {
NftId: types.NftId{ClassId: "class6", TokenId: "nft6"},
Owner: s.addrs[0].String(),
State: 1, BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
StartedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
LiquidatedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
FullPaymentEndAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
Expand Down Expand Up @@ -146,7 +146,7 @@ func (s *KeeperTestSuite) TestListedNfts() {
NftId: types.NftId{ClassId: "class7", TokenId: "nft7"},
Owner: s.addrs[1].String(),
State: 1, BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
StartedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
LiquidatedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
FullPaymentEndAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
Expand Down Expand Up @@ -181,7 +181,7 @@ func (s *KeeperTestSuite) TestListedNfts() {
Owner: s.addrs[0].String(),
State: 1,
BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
StartedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
LiquidatedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
FullPaymentEndAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
Expand All @@ -203,7 +203,7 @@ func (s *KeeperTestSuite) TestListedNfts() {
NftId: types.NftId{ClassId: "class5", TokenId: "nft5"},
Owner: s.addrs[0].String(),
State: 1, BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
StartedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
LiquidatedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
FullPaymentEndAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
Expand All @@ -225,7 +225,7 @@ func (s *KeeperTestSuite) TestListedNfts() {
NftId: types.NftId{ClassId: "class6", TokenId: "nft6"},
Owner: s.addrs[0].String(),
State: 1, BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
StartedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
LiquidatedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
FullPaymentEndAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
Expand All @@ -247,7 +247,7 @@ func (s *KeeperTestSuite) TestListedNfts() {
NftId: types.NftId{ClassId: "class7", TokenId: "nft7"},
Owner: s.addrs[1].String(),
State: 1, BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
StartedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
LiquidatedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
FullPaymentEndAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
Expand Down
40 changes: 20 additions & 20 deletions x/nftbackedloan/keeper/loan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func (suite *KeeperTestSuite) TestManualBorrow() {
bidder := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes())

listing := types.Listing{
NftId: types.NftId{ClassId: "class1", TokenId: "nft1"},
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: "uguu",
MinimumDepositRate: sdk.NewDecWithPrec(1, 1),
StartedAt: time.Now(),
NftId: types.NftId{ClassId: "class1", TokenId: "nft1"},
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: "uguu",
MinDepositRate: sdk.NewDecWithPrec(1, 1),
StartedAt: time.Now(),
}
msgBid := types.MsgPlaceBid{
Sender: bidder.String(),
Expand Down Expand Up @@ -139,10 +139,10 @@ func (suite *KeeperTestSuite) TestManualBorrow() {
}, owner)

err := suite.app.NftbackedloanKeeper.ListNft(suite.ctx, &types.MsgListNft{
Sender: listing.Owner,
NftId: listing.NftId,
BidDenom: listing.BidDenom,
MinimumDepositRate: listing.MinimumDepositRate,
Sender: listing.Owner,
NftId: listing.NftId,
BidDenom: listing.BidDenom,
MinDepositRate: listing.MinDepositRate,
})
suite.Require().NoError(err)

Expand Down Expand Up @@ -170,12 +170,12 @@ func (suite *KeeperTestSuite) TestManualRepay() {
bidder := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes())

listing := types.Listing{
NftId: types.NftId{ClassId: "class1", TokenId: "nft1"},
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: "uguu",
MinimumDepositRate: sdk.NewDecWithPrec(1, 1),
StartedAt: time.Now(),
NftId: types.NftId{ClassId: "class1", TokenId: "nft1"},
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: "uguu",
MinDepositRate: sdk.NewDecWithPrec(1, 1),
StartedAt: time.Now(),
}
msgBid := types.MsgPlaceBid{
Sender: bidder.String(),
Expand Down Expand Up @@ -303,10 +303,10 @@ func (suite *KeeperTestSuite) TestManualRepay() {
}, owner)

err := suite.app.NftbackedloanKeeper.ListNft(suite.ctx, &types.MsgListNft{
Sender: listing.Owner,
NftId: listing.NftId,
BidDenom: listing.BidDenom,
MinimumDepositRate: listing.MinimumDepositRate,
Sender: listing.Owner,
NftId: listing.NftId,
BidDenom: listing.BidDenom,
MinDepositRate: listing.MinDepositRate,
})
suite.Require().NoError(err)

Expand Down
4 changes: 2 additions & 2 deletions x/nftbackedloan/keeper/nft_listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ func (k Keeper) ListNft(ctx sdk.Context, msg *types.MsgListNft) error {
Owner: owner.String(),
State: types.ListingState_LISTING,
BidDenom: msg.BidDenom,
MinimumDepositRate: msg.MinimumDepositRate,
MinDepositRate: msg.MinDepositRate,
StartedAt: ctx.BlockTime(),
CollectedAmount: sdk.NewCoin(msg.BidDenom, sdk.ZeroInt()),
CollectedAmountNegative: false,
MinimumBidPeriod: msg.MinimumBiddingPeriod,
MinBidPeriod: msg.MinBidPeriod,
}

// disable NFT transfer
Expand Down
32 changes: 16 additions & 16 deletions x/nftbackedloan/keeper/nft_listing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,18 @@ func (suite *KeeperTestSuite) TestListNft() {
if tc.listBefore {
// use keeper directly to be executed with hooks structs
err := keeper.ListNft(suite.ctx, &types.MsgListNft{
Sender: tc.lister.String(),
NftId: types.NftId{ClassId: tc.classId, TokenId: tc.nftId},
BidDenom: tc.BidDenom,
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
Sender: tc.lister.String(),
NftId: types.NftId{ClassId: tc.classId, TokenId: tc.nftId},
BidDenom: tc.BidDenom,
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
})
suite.Require().NoError(err)
}
err := keeper.ListNft(suite.ctx, &types.MsgListNft{
Sender: tc.lister.String(),
NftId: types.NftId{ClassId: tc.classId, TokenId: tc.nftId},
BidDenom: tc.BidDenom,
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
Sender: tc.lister.String(),
NftId: types.NftId{ClassId: tc.classId, TokenId: tc.nftId},
BidDenom: tc.BidDenom,
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
})

if tc.expectPass {
Expand Down Expand Up @@ -275,10 +275,10 @@ func (suite *KeeperTestSuite) TestCancelNftListing() {
nftIdentifier := types.NftId{ClassId: tc.classId, TokenId: tc.nftId}
if tc.listBefore {
err := suite.app.NftbackedloanKeeper.ListNft(suite.ctx, &types.MsgListNft{
Sender: tc.nftOwner.String(),
NftId: nftIdentifier,
BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
Sender: tc.nftOwner.String(),
NftId: nftIdentifier,
BidDenom: "uguu",
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
})
suite.Require().NoError(err)
}
Expand Down Expand Up @@ -375,10 +375,10 @@ func (suite *KeeperTestSuite) TestDeliverSuccessfulBids() {

nftIdentifier := types.NftId{ClassId: classId, TokenId: nftId}
err = suite.app.NftbackedloanKeeper.ListNft(suite.ctx, &types.MsgListNft{
Sender: nftOwner.String(),
NftId: nftIdentifier,
BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
Sender: nftOwner.String(),
NftId: nftIdentifier,
BidDenom: "uguu",
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
})
suite.Require().NoError(err)

Expand Down
8 changes: 4 additions & 4 deletions x/nftbackedloan/keeper/sell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ func (suite *KeeperTestSuite) TestSellingDecision() {
nftIdentifier := types.NftId{ClassId: tc.classId, TokenId: tc.nftId}
if tc.listBefore {
err := suite.app.NftbackedloanKeeper.ListNft(suite.ctx, &types.MsgListNft{
Sender: tc.nftOwner.String(),
NftId: nftIdentifier,
BidDenom: "uguu",
MinimumDepositRate: sdk.MustNewDecFromStr("0.1"),
Sender: tc.nftOwner.String(),
NftId: nftIdentifier,
BidDenom: "uguu",
MinDepositRate: sdk.MustNewDecFromStr("0.1"),
})
suite.Require().NoError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/nftbackedloan/keeper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ValidateListNftMsg(k Keeper, ctx sdk.Context, msg *types.MsgListNft) error
if err != nil {
return err
}
return CheckListNft(k, ctx, sender, msg.NftId, msg.BidDenom, msg.MinimumDepositRate)
return CheckListNft(k, ctx, sender, msg.NftId, msg.BidDenom, msg.MinDepositRate)
}

func CheckListNft(k Keeper, ctx sdk.Context, sender sdk.AccAddress, nftId types.NftId, bidToken string, minimumDepositRate sdk.Dec) error {
Expand Down
Loading