From 3c34078d412ec1791a045fb37efe21926c815f85 Mon Sep 17 00:00:00 2001 From: Bjarte Stien Karlsen Date: Mon, 5 Aug 2024 23:11:14 +0200 Subject: [PATCH] add happy day tests for lease market with flow --- lease_market_auction_soft_flow_test.go | 378 ++++++++++++++++++ lease_market_auction_soft_test.go | 369 +---------------- lease_market_direct_offer_soft_flow_test.go | 20 + lease_market_sale_flow_test.go | 25 ++ setup_test.go | 7 + test_utils.go | 157 ++++++++ transactions/acceptLeaseDirectOfferSoft.cdc | 45 ++- .../acceptLeaseDirectOfferSoftDapper.cdc | 1 - .../bidLeaseMarketDirectOfferSoft.cdc | 13 +- transactions/buyLeaseForSale.cdc | 60 +++ transactions/createProfileDapper.cdc | 1 + transactions/listLeaseForAuctionSoft.cdc | 2 +- transactions/listLeaseForSale.cdc | 61 +++ transactions/listLeaseForSaleDapper.cdc | 3 - 14 files changed, 752 insertions(+), 390 deletions(-) create mode 100644 lease_market_auction_soft_flow_test.go create mode 100644 lease_market_direct_offer_soft_flow_test.go create mode 100644 lease_market_sale_flow_test.go create mode 100644 transactions/buyLeaseForSale.cdc create mode 100644 transactions/listLeaseForSale.cdc diff --git a/lease_market_auction_soft_flow_test.go b/lease_market_auction_soft_flow_test.go new file mode 100644 index 00000000..6f3c22e7 --- /dev/null +++ b/lease_market_auction_soft_flow_test.go @@ -0,0 +1,378 @@ +package test_main + +import ( + "testing" + + . "github.com/bjartek/overflow/v2" +) + +func TestLeaseMarketAuctionSoft(t *testing.T) { + otu := &OverflowTestUtils{T: t, O: ot.O} + + price := 10.0 + preIncrement := 5.0 + + eventIdentifier := otu.identifier("FindLeaseMarketAuctionSoft", "EnglishAuction") + royaltyIdentifier := otu.identifier("FindLeaseMarket", "RoyaltyPaid") + + bidTx := otu.O.TxFileNameFN("bidLeaseMarketAuctionSoftDapper", + WithSigner("user6"), + WithArg("leaseName", "user5"), + WithArg("amount", price), + ) + + increaseBidTx := otu.O.TxFileNameFN("increaseBidLeaseMarketAuctionSoft", + WithSigner("user6"), + WithArg("leaseName", "user5"), + WithArg("amount", preIncrement), + ) + + listTx := otu.O.TxFileNameFN("listLeaseForAuctionSoftDapper", + WithSigner("user5"), + WithArg("leaseName", "user5"), + WithArg("ftAliasOrIdentifier", "FUT"), + WithArg("price", price), + WithArg("auctionReservePrice", price+5.0), + WithArg("auctionDuration", 300.0), + WithArg("auctionExtensionOnLateBid", 60.0), + WithArg("minimumBidIncrement", 1.0), + WithArg("auctionValidUntil", otu.currentTime()+10.0), + ) + ot.Run(t, "Should not be able to list an item for auction twice, and will give error message.", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price) + + listTx().AssertFailure(t, "Auction listing for this item is already created.") + }) + + ot.Run(t, "Should be able to sell at auction", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price). + auctionBidLeaseMarketSoft("user6", "user5", price+5.0). + tickClock(400.0). + saleLeaseListed("user5", "finished_completed", price+5.0). + fulfillLeaseMarketAuctionSoft("user6", "user5", 15.0) + }) + + ot.Run(t, "Should be able to cancel listing if the pointer is no longer valid", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price). + auctionBidLeaseMarketSoft("user6", "user5", price+5.0). + tickClock(400.0). + saleLeaseListed("user5", "finished_completed", price+5.0). + moveNameTo("user5", "user6", "user5") + + otu.O.Tx("cancelLeaseMarketAuctionSoft", + WithSigner("user5"), + WithArg("leaseNames", `["user5"]`), + ).AssertSuccess(t). + AssertEvent(t, eventIdentifier, map[string]interface{}{ + "seller": otu.O.Address("user5"), + "buyer": otu.O.Address("user6"), + "amount": 15.0, + "status": "cancel_ghostlisting", + }) + }) + + ot.Run(t, "Should not be able to list with price 0", func(t *testing.T) { + listTx(WithArg("price", 0.0)). + AssertFailure(t, "Auction start price should be greater than 0") + }) + + ot.Run(t, "Should not be able to list with invalid reserve price", func(t *testing.T) { + listTx(WithArg("auctionReservePrice", price-5.0)). + AssertFailure(t, "Auction reserve price should be greater than Auction start price") + }) + + ot.Run(t, "Should not be able to list with invalid time", func(t *testing.T) { + listTx(WithArg("auctionValidUntil", 0.0)). + AssertFailure(t, "Valid until is before current time") + }) + + ot.Run(t, "Should be able to add bid at auction", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price). + auctionBidLeaseMarketSoft("user6", "user5", price+5.0). + increaseAuctionBidLeaseMarketSoft("user6", "user5", 5.0, price+10.0). + tickClock(400.0). + saleLeaseListed("user5", "finished_completed", price+10.0). + fulfillLeaseMarketAuctionSoft("user6", "user5", price+10.0) + }) + + ot.Run(t, "Should not be able to bid expired auction listing", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price). + tickClock(1000.0) + + bidTx().AssertFailure(t, "This auction listing is already expired") + }) + + ot.Run(t, "Should not be able to bid your own listing", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price) + + bidTx(WithSigner("user5")). + AssertFailure(t, "You cannot bid on your own resource") + }) + + ot.Run(t, "Should be able to cancel an auction", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price) + + name := "user5" + + otu.O.Tx("cancelLeaseMarketAuctionSoft", + WithSigner(name), + WithArg("leaseNames", `["user5"]`), + ). + AssertSuccess(t). + AssertEvent(t, eventIdentifier, map[string]interface{}{ + "seller": otu.O.Address(name), + "amount": 10.0, + "status": "cancel", + }) + }) + + ot.Run(t, "Should not be able to cancel an ended auction", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price). + auctionBidLeaseMarketSoft("user6", "user5", price+5.0). + tickClock(4000.0). + saleLeaseListed("user5", "finished_completed", price+5.0) + + name := "user5" + + otu.O.Tx("cancelLeaseMarketAuctionSoft", + WithSigner(name), + WithArg("leaseNames", `["user5"]`), + ). + AssertFailure(t, "Cannot cancel finished auction, fulfill it instead") + + otu.fulfillLeaseMarketAuctionSoft("user6", "user5", price+5.0) + }) + + ot.Run(t, "Cannot fulfill a not yet ended auction", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price) + + otu.auctionBidLeaseMarketSoft("user6", "user5", price+5.0) + + otu.tickClock(100.0) + + otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", + WithSigner("user6"), + WithPayloadSigner("dapper"), + WithArg("leaseName", "user5"), + WithArg("amount", price+5.0), + ). + AssertFailure(t, "Auction has not ended yet") + }) + + ot.Run(t, "Should allow seller to cancel auction if it failed to meet reserve price", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price). + auctionBidLeaseMarketSoft("user6", "user5", price+1.0). + tickClock(400.0). + saleLeaseListed("user5", "finished_failed", 11.0) + + buyer := "user6" + name := "user5" + + otu.O.Tx("cancelLeaseMarketAuctionSoft", + WithSigner(name), + WithArg("leaseNames", `["user5"]`), + ). + AssertEvent(t, eventIdentifier, map[string]interface{}{ + "seller": otu.O.Address(name), + "buyer": otu.O.Address(buyer), + "amount": 11.0, + "status": "cancel_reserved_not_met", + }) + }) + + ot.Run(t, "Should be able to bid and increase bid by same user", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price). + auctionBidLeaseMarketSoft("user6", "user5", price+preIncrement). + saleLeaseListed("user5", "active_ongoing", price+preIncrement) + + increaseBidTx(WithArg("amount", 0.1)). + AssertFailure(t, "must be larger then previous bid+bidIncrement") + }) + + ot.Run(t, "Should not be able to list after deprecated", func(t *testing.T) { + otu.alterLeaseMarketOption("deprecate") + + listTx().AssertFailure(t, "Tenant has deprected mutation options on this item") + }) + + ot.Run(t, "Should not be able to bid below listing price", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price) + + bidTx(WithArg("amount", 1.0)). + AssertFailure(t, "You need to bid more then the starting price of 10.00000000") + }) + + // platform 0.15 + // artist 0.05 + // find 0.025 + // tenant nil + ot.Run(t, "Royalties should be sent to correspondence upon fulfill action", func(t *testing.T) { + price = 5.0 + + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price). + auctionBidLeaseMarketSoft("user6", "user5", price+5.0) + + otu.tickClock(500.0) + + otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", + WithSigner("user6"), + WithPayloadSigner("dapper"), + WithArg("leaseName", "user5"), + WithArg("amount", 10.0), + ). + AssertSuccess(t). + AssertEvent(t, royaltyIdentifier, map[string]interface{}{ + "address": otu.O.Address("find"), + "amount": 0.25, + "royaltyName": "find", + }) + }) + /* + + t.Run("Should be able to ban user, user is only allowed to cancel listing.", func(t *testing.T) { + + otu.listLeaseForSoftAuction("user5", "user5", price). + listLeaseForSoftAuction("user5", "name2", price). + auctionBidLeaseMarketSoft("user6", "user5", price+5.0). + tickClock(400.0). + leaseProfileBan("user5") + + otu.O.Tx("listLeaseForAuctionSoftDapper", + WithSigner("user5"), + WithArg("leaseName", "name3"), + WithArg("ftAliasOrIdentifier", "FUT"), + WithArg("price", price), + WithArg("auctionReservePrice", price+5.0), + WithArg("auctionDuration", 300.0), + WithArg("auctionExtensionOnLateBid", 60.0), + WithArg("minimumBidIncrement", 1.0), + WithArg("auctionValidUntil", otu.currentTime()+10.0), + ). + AssertFailure(t, "Seller banned by Tenant") + + otu.O.Tx("bidLeaseMarketAuctionSoftDapper", + WithSigner("user6"), + WithArg("leaseName", "name2"), + WithArg("amount", price), + ). + AssertFailure(t, "Seller banned by Tenant") + + otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", + WithSigner("user6"), + WithPayloadSigner("dapper"), + WithArg("leaseName", "user5"), + WithArg("amount", price+5.0), + ). + AssertFailure(t, "Seller banned by Tenant") + + otu.O.Tx("cancelLeaseMarketAuctionSoft", + WithSigner("user5"), + WithArg("leaseNames", `["name2"]`), + ). + AssertSuccess(t) + + otu.removeLeaseProfileBan("user5") + + otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", + WithSigner("user6"), + WithPayloadSigner("dapper"), + WithArg("leaseName", "user5"), + WithArg("amount", price+5.0), + ). + AssertSuccess(t) + + otu.delistAllLeaseForSoftAuction("user5"). + moveNameTo("user6", "user5", "user5") + + }) + + t.Run("Should be able to ban user, user cannot bid NFT.", func(t *testing.T) { + + otu.listLeaseForSoftAuction("user5", "user5", price). + listLeaseForSoftAuction("user5", "name2", price). + auctionBidLeaseMarketSoft("user6", "user5", price+5.0). + tickClock(400.0). + leaseProfileBan("user6") + + otu.O.Tx("bidLeaseMarketAuctionSoftDapper", + WithSigner("user6"), + WithArg("leaseName", "name2"), + WithArg("amount", price), + ). + AssertFailure(t, "Buyer banned by Tenant") + + otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", + WithSigner("user6"), + WithPayloadSigner("dapper"), + WithArg("leaseName", "user5"), + WithArg("amount", price+5.0), + ). + AssertFailure(t, "Buyer banned by Tenant") + + otu.removeLeaseProfileBan("user6") + + otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", + WithSigner("user6"), + WithPayloadSigner("dapper"), + WithArg("leaseName", "user5"), + WithArg("amount", price+5.0), + ). + AssertSuccess(t) + + otu.delistAllLeaseForSoftAuction("user5"). + moveNameTo("user6", "user5", "user5") + + }) + + */ + ot.Run(t, "Should emit previous bidder if outbid", func(t *testing.T) { + otu.listLeaseForSoftAuction("user5", "user5", price). + saleLeaseListed("user5", "active_listed", price). + auctionBidLeaseMarketSoft("user6", "user5", price+5.0). + saleLeaseListed("user5", "active_ongoing", price+5.0) + + otu.O.Tx("bidLeaseMarketAuctionSoftDapper", + WithSigner("user7"), + WithArg("leaseName", "user5"), + WithArg("amount", 20.0), + ). + AssertSuccess(t). + AssertEvent(t, eventIdentifier, map[string]interface{}{ + "amount": 20.0, + "buyer": otu.O.Address("user7"), + "previousBuyer": otu.O.Address("user6"), + "status": "active_ongoing", + }) + }) + + ot.Run(t, "Should be able to list an NFT for auction and bid it with DUC", func(t *testing.T) { + otu.listLeaseForSoftAuctionDUC("user5", "user5", price) + + otu.saleLeaseListed("user5", "active_listed", price). + auctionBidLeaseMarketSoftDUC("user6", "user5", price+5.0) + + otu.O.Tx("increaseBidLeaseMarketAuctionSoft", + WithSigner("user6"), + WithArg("leaseName", "user5"), + WithArg("amount", 5.0), + ). + AssertSuccess(t) + + otu.tickClock(400.0). + saleLeaseListed("user5", "finished_completed", price+10.0). + fulfillLeaseMarketAuctionSoftDUC("user6", "user5", price+10.0) + }) +} diff --git a/lease_market_auction_soft_test.go b/lease_market_auction_soft_test.go index 6f3c22e7..74a1ea63 100644 --- a/lease_market_auction_soft_test.go +++ b/lease_market_auction_soft_test.go @@ -2,377 +2,20 @@ package test_main import ( "testing" - - . "github.com/bjartek/overflow/v2" ) -func TestLeaseMarketAuctionSoft(t *testing.T) { +func TestLeaseMarketAuctionSoftFlow(t *testing.T) { otu := &OverflowTestUtils{T: t, O: ot.O} price := 10.0 - preIncrement := 5.0 - - eventIdentifier := otu.identifier("FindLeaseMarketAuctionSoft", "EnglishAuction") - royaltyIdentifier := otu.identifier("FindLeaseMarket", "RoyaltyPaid") - - bidTx := otu.O.TxFileNameFN("bidLeaseMarketAuctionSoftDapper", - WithSigner("user6"), - WithArg("leaseName", "user5"), - WithArg("amount", price), - ) - - increaseBidTx := otu.O.TxFileNameFN("increaseBidLeaseMarketAuctionSoft", - WithSigner("user6"), - WithArg("leaseName", "user5"), - WithArg("amount", preIncrement), - ) - - listTx := otu.O.TxFileNameFN("listLeaseForAuctionSoftDapper", - WithSigner("user5"), - WithArg("leaseName", "user5"), - WithArg("ftAliasOrIdentifier", "FUT"), - WithArg("price", price), - WithArg("auctionReservePrice", price+5.0), - WithArg("auctionDuration", 300.0), - WithArg("auctionExtensionOnLateBid", 60.0), - WithArg("minimumBidIncrement", 1.0), - WithArg("auctionValidUntil", otu.currentTime()+10.0), - ) - ot.Run(t, "Should not be able to list an item for auction twice, and will give error message.", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price) - - listTx().AssertFailure(t, "Auction listing for this item is already created.") - }) ot.Run(t, "Should be able to sell at auction", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price). - auctionBidLeaseMarketSoft("user6", "user5", price+5.0). - tickClock(400.0). - saleLeaseListed("user5", "finished_completed", price+5.0). - fulfillLeaseMarketAuctionSoft("user6", "user5", 15.0) - }) - - ot.Run(t, "Should be able to cancel listing if the pointer is no longer valid", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price). - auctionBidLeaseMarketSoft("user6", "user5", price+5.0). - tickClock(400.0). - saleLeaseListed("user5", "finished_completed", price+5.0). - moveNameTo("user5", "user6", "user5") - - otu.O.Tx("cancelLeaseMarketAuctionSoft", - WithSigner("user5"), - WithArg("leaseNames", `["user5"]`), - ).AssertSuccess(t). - AssertEvent(t, eventIdentifier, map[string]interface{}{ - "seller": otu.O.Address("user5"), - "buyer": otu.O.Address("user6"), - "amount": 15.0, - "status": "cancel_ghostlisting", - }) - }) - - ot.Run(t, "Should not be able to list with price 0", func(t *testing.T) { - listTx(WithArg("price", 0.0)). - AssertFailure(t, "Auction start price should be greater than 0") - }) - - ot.Run(t, "Should not be able to list with invalid reserve price", func(t *testing.T) { - listTx(WithArg("auctionReservePrice", price-5.0)). - AssertFailure(t, "Auction reserve price should be greater than Auction start price") - }) - - ot.Run(t, "Should not be able to list with invalid time", func(t *testing.T) { - listTx(WithArg("auctionValidUntil", 0.0)). - AssertFailure(t, "Valid until is before current time") - }) - - ot.Run(t, "Should be able to add bid at auction", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price). - auctionBidLeaseMarketSoft("user6", "user5", price+5.0). - increaseAuctionBidLeaseMarketSoft("user6", "user5", 5.0, price+10.0). - tickClock(400.0). - saleLeaseListed("user5", "finished_completed", price+10.0). - fulfillLeaseMarketAuctionSoft("user6", "user5", price+10.0) - }) - - ot.Run(t, "Should not be able to bid expired auction listing", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price). - tickClock(1000.0) - - bidTx().AssertFailure(t, "This auction listing is already expired") - }) - - ot.Run(t, "Should not be able to bid your own listing", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price) - - bidTx(WithSigner("user5")). - AssertFailure(t, "You cannot bid on your own resource") - }) - - ot.Run(t, "Should be able to cancel an auction", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price) - - name := "user5" - - otu.O.Tx("cancelLeaseMarketAuctionSoft", - WithSigner(name), - WithArg("leaseNames", `["user5"]`), - ). - AssertSuccess(t). - AssertEvent(t, eventIdentifier, map[string]interface{}{ - "seller": otu.O.Address(name), - "amount": 10.0, - "status": "cancel", - }) - }) - - ot.Run(t, "Should not be able to cancel an ended auction", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price). - auctionBidLeaseMarketSoft("user6", "user5", price+5.0). - tickClock(4000.0). - saleLeaseListed("user5", "finished_completed", price+5.0) - - name := "user5" - - otu.O.Tx("cancelLeaseMarketAuctionSoft", - WithSigner(name), - WithArg("leaseNames", `["user5"]`), - ). - AssertFailure(t, "Cannot cancel finished auction, fulfill it instead") - - otu.fulfillLeaseMarketAuctionSoft("user6", "user5", price+5.0) - }) - - ot.Run(t, "Cannot fulfill a not yet ended auction", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price) - - otu.auctionBidLeaseMarketSoft("user6", "user5", price+5.0) - - otu.tickClock(100.0) - - otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", - WithSigner("user6"), - WithPayloadSigner("dapper"), - WithArg("leaseName", "user5"), - WithArg("amount", price+5.0), - ). - AssertFailure(t, "Auction has not ended yet") - }) - ot.Run(t, "Should allow seller to cancel auction if it failed to meet reserve price", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price). - auctionBidLeaseMarketSoft("user6", "user5", price+1.0). + otu.listLeaseForSoftAuctionFlow("user1", "user1", price). + saleLeaseListed("user1", "active_listed", price). + auctionBidLeaseMarketSoftFlow("user2", "user1", price+5.0). tickClock(400.0). - saleLeaseListed("user5", "finished_failed", 11.0) - - buyer := "user6" - name := "user5" - - otu.O.Tx("cancelLeaseMarketAuctionSoft", - WithSigner(name), - WithArg("leaseNames", `["user5"]`), - ). - AssertEvent(t, eventIdentifier, map[string]interface{}{ - "seller": otu.O.Address(name), - "buyer": otu.O.Address(buyer), - "amount": 11.0, - "status": "cancel_reserved_not_met", - }) - }) - - ot.Run(t, "Should be able to bid and increase bid by same user", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price). - auctionBidLeaseMarketSoft("user6", "user5", price+preIncrement). - saleLeaseListed("user5", "active_ongoing", price+preIncrement) - - increaseBidTx(WithArg("amount", 0.1)). - AssertFailure(t, "must be larger then previous bid+bidIncrement") - }) - - ot.Run(t, "Should not be able to list after deprecated", func(t *testing.T) { - otu.alterLeaseMarketOption("deprecate") - - listTx().AssertFailure(t, "Tenant has deprected mutation options on this item") - }) - - ot.Run(t, "Should not be able to bid below listing price", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price) - - bidTx(WithArg("amount", 1.0)). - AssertFailure(t, "You need to bid more then the starting price of 10.00000000") - }) - - // platform 0.15 - // artist 0.05 - // find 0.025 - // tenant nil - ot.Run(t, "Royalties should be sent to correspondence upon fulfill action", func(t *testing.T) { - price = 5.0 - - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price). - auctionBidLeaseMarketSoft("user6", "user5", price+5.0) - - otu.tickClock(500.0) - - otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", - WithSigner("user6"), - WithPayloadSigner("dapper"), - WithArg("leaseName", "user5"), - WithArg("amount", 10.0), - ). - AssertSuccess(t). - AssertEvent(t, royaltyIdentifier, map[string]interface{}{ - "address": otu.O.Address("find"), - "amount": 0.25, - "royaltyName": "find", - }) - }) - /* - - t.Run("Should be able to ban user, user is only allowed to cancel listing.", func(t *testing.T) { - - otu.listLeaseForSoftAuction("user5", "user5", price). - listLeaseForSoftAuction("user5", "name2", price). - auctionBidLeaseMarketSoft("user6", "user5", price+5.0). - tickClock(400.0). - leaseProfileBan("user5") - - otu.O.Tx("listLeaseForAuctionSoftDapper", - WithSigner("user5"), - WithArg("leaseName", "name3"), - WithArg("ftAliasOrIdentifier", "FUT"), - WithArg("price", price), - WithArg("auctionReservePrice", price+5.0), - WithArg("auctionDuration", 300.0), - WithArg("auctionExtensionOnLateBid", 60.0), - WithArg("minimumBidIncrement", 1.0), - WithArg("auctionValidUntil", otu.currentTime()+10.0), - ). - AssertFailure(t, "Seller banned by Tenant") - - otu.O.Tx("bidLeaseMarketAuctionSoftDapper", - WithSigner("user6"), - WithArg("leaseName", "name2"), - WithArg("amount", price), - ). - AssertFailure(t, "Seller banned by Tenant") - - otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", - WithSigner("user6"), - WithPayloadSigner("dapper"), - WithArg("leaseName", "user5"), - WithArg("amount", price+5.0), - ). - AssertFailure(t, "Seller banned by Tenant") - - otu.O.Tx("cancelLeaseMarketAuctionSoft", - WithSigner("user5"), - WithArg("leaseNames", `["name2"]`), - ). - AssertSuccess(t) - - otu.removeLeaseProfileBan("user5") - - otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", - WithSigner("user6"), - WithPayloadSigner("dapper"), - WithArg("leaseName", "user5"), - WithArg("amount", price+5.0), - ). - AssertSuccess(t) - - otu.delistAllLeaseForSoftAuction("user5"). - moveNameTo("user6", "user5", "user5") - - }) - - t.Run("Should be able to ban user, user cannot bid NFT.", func(t *testing.T) { - - otu.listLeaseForSoftAuction("user5", "user5", price). - listLeaseForSoftAuction("user5", "name2", price). - auctionBidLeaseMarketSoft("user6", "user5", price+5.0). - tickClock(400.0). - leaseProfileBan("user6") - - otu.O.Tx("bidLeaseMarketAuctionSoftDapper", - WithSigner("user6"), - WithArg("leaseName", "name2"), - WithArg("amount", price), - ). - AssertFailure(t, "Buyer banned by Tenant") - - otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", - WithSigner("user6"), - WithPayloadSigner("dapper"), - WithArg("leaseName", "user5"), - WithArg("amount", price+5.0), - ). - AssertFailure(t, "Buyer banned by Tenant") - - otu.removeLeaseProfileBan("user6") - - otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", - WithSigner("user6"), - WithPayloadSigner("dapper"), - WithArg("leaseName", "user5"), - WithArg("amount", price+5.0), - ). - AssertSuccess(t) - - otu.delistAllLeaseForSoftAuction("user5"). - moveNameTo("user6", "user5", "user5") - - }) - - */ - ot.Run(t, "Should emit previous bidder if outbid", func(t *testing.T) { - otu.listLeaseForSoftAuction("user5", "user5", price). - saleLeaseListed("user5", "active_listed", price). - auctionBidLeaseMarketSoft("user6", "user5", price+5.0). - saleLeaseListed("user5", "active_ongoing", price+5.0) - - otu.O.Tx("bidLeaseMarketAuctionSoftDapper", - WithSigner("user7"), - WithArg("leaseName", "user5"), - WithArg("amount", 20.0), - ). - AssertSuccess(t). - AssertEvent(t, eventIdentifier, map[string]interface{}{ - "amount": 20.0, - "buyer": otu.O.Address("user7"), - "previousBuyer": otu.O.Address("user6"), - "status": "active_ongoing", - }) - }) - - ot.Run(t, "Should be able to list an NFT for auction and bid it with DUC", func(t *testing.T) { - otu.listLeaseForSoftAuctionDUC("user5", "user5", price) - - otu.saleLeaseListed("user5", "active_listed", price). - auctionBidLeaseMarketSoftDUC("user6", "user5", price+5.0) - - otu.O.Tx("increaseBidLeaseMarketAuctionSoft", - WithSigner("user6"), - WithArg("leaseName", "user5"), - WithArg("amount", 5.0), - ). - AssertSuccess(t) - - otu.tickClock(400.0). - saleLeaseListed("user5", "finished_completed", price+10.0). - fulfillLeaseMarketAuctionSoftDUC("user6", "user5", price+10.0) + saleLeaseListed("user1", "finished_completed", price+5.0). + fulfillLeaseMarketAuctionSoftFlow("user2", "user1", 15.0) }) } diff --git a/lease_market_direct_offer_soft_flow_test.go b/lease_market_direct_offer_soft_flow_test.go new file mode 100644 index 00000000..12d323f1 --- /dev/null +++ b/lease_market_direct_offer_soft_flow_test.go @@ -0,0 +1,20 @@ +package test_main + +import ( + "testing" +) + +func TestLeaseMarketDirectOfferSoftFlow(t *testing.T) { + otu := &OverflowTestUtils{T: t, O: ot.O} + + price := 10.0 + + + ot.Run(t, "Should be able to add direct offer and then sell", func(t *testing.T) { + otu.directOfferLeaseMarketSoftFlow("user2", "user1", price). + saleLeaseListed("user1", "active_ongoing", price). + acceptLeaseDirectOfferMarketSoftFlow("user2", "user1", "user1", price). + saleLeaseListed("user1", "active_finished", price). + fulfillLeaseMarketDirectOfferSoftFlow("user2", "user1", price) + }) +} diff --git a/lease_market_sale_flow_test.go b/lease_market_sale_flow_test.go new file mode 100644 index 00000000..b7316d15 --- /dev/null +++ b/lease_market_sale_flow_test.go @@ -0,0 +1,25 @@ +package test_main + +import ( + "testing" + + //. "github.com/bjartek/overflow/v2" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestLeaseMarketSaleFlow(t *testing.T) { + otu := &OverflowTestUtils{T: t, O: ot.O} + price := 10.0 + + ot.Run(t, "Should be able to list a lease for sale and buy it", func(t *testing.T) { + otu.listLeaseForSale("user1", "user1", price) + + itemsForSale := otu.getLeasesForSale("user1") + require.Equal(t, 1, len(itemsForSale)) + assert.Equal(t, "active_listed", itemsForSale[0].SaleType) + + otu.buyLeaseForMarketSale("user2", "user1", "user1", price) + }) + +} diff --git a/setup_test.go b/setup_test.go index 5cfce224..c014f63f 100644 --- a/setup_test.go +++ b/setup_test.go @@ -424,6 +424,13 @@ func SetupFIND(o *OverflowState) error { WithArg("cut", 0.0), ) + stx("tenantsetLeaseOptionMarket", + WithSigner("find"), + WithArg("nftName", "Lease"), + WithArg("nftType", findleaseQI), + WithArg("cut", 0.0), + ) + return nil } diff --git a/test_utils.go b/test_utils.go index 6c08ebe8..39e0e871 100644 --- a/test_utils.go +++ b/test_utils.go @@ -338,6 +338,29 @@ func (otu *OverflowTestUtils) listNFTForSoftAuction(name string, id uint64, pric return otu } +func (otu *OverflowTestUtils) listLeaseForSoftAuctionFlow(user string, name string, price float64) *OverflowTestUtils { + otu.O.Tx("listLeaseForAuctionSoft", + WithSigner(user), + WithArg("leaseName", name), + WithArg("ftAliasOrIdentifier", "Flow"), + WithArg("price", price), + WithArg("auctionReservePrice", price+5.0), + WithArg("auctionDuration", 300.0), + WithArg("auctionExtensionOnLateBid", 60.0), + WithArg("minimumBidIncrement", 1.0), + WithArg("auctionValidUntil", otu.currentTime()+100.0), + ). + AssertSuccess(otu.T). + AssertEvent(otu.T, "FindLeaseMarketAuctionSoft.EnglishAuction", map[string]interface{}{ + "status": "active_listed", + "amount": price, + "auctionReservePrice": price + 5.0, + "seller": otu.O.Address(user), + }) + + return otu +} + func (otu *OverflowTestUtils) listLeaseForSoftAuction(user string, name string, price float64) *OverflowTestUtils { otu.O.Tx("listLeaseForAuctionSoftDapper", WithSigner(user), @@ -496,6 +519,22 @@ func (otu *OverflowTestUtils) auctionBidMarketSoft(name string, seller string, i return otu } +func (otu *OverflowTestUtils) auctionBidLeaseMarketSoftFlow(buyer string, name string, price float64) *OverflowTestUtils { + otu.O.Tx("bidLeaseMarketAuctionSoft", + WithSigner(buyer), + WithArg("leaseName", name), + WithArg("amount", price), + ). + AssertSuccess(otu.T). + AssertEvent(otu.T, "FindLeaseMarketAuctionSoft.EnglishAuction", map[string]interface{}{ + "amount": price, + "buyer": otu.O.Address(buyer), + "status": "active_ongoing", + }) + + return otu +} + func (otu *OverflowTestUtils) auctionBidLeaseMarketSoft(buyer string, name string, price float64) *OverflowTestUtils { otu.O.Tx("bidLeaseMarketAuctionSoftDapper", WithSigner(buyer), @@ -608,6 +647,23 @@ func (otu *OverflowTestUtils) directOfferMarketSoft(name string, seller string, return otu } +func (otu *OverflowTestUtils) directOfferLeaseMarketSoftFlow(user string, name string, price float64) *OverflowTestUtils { + otu.O.Tx("bidLeaseMarketDirectOfferSoft", + WithSigner(user), + WithArg("leaseName", name), + WithArg("ftAliasOrIdentifier", "Flow"), + WithArg("amount", price), + WithArg("validUntil", otu.currentTime()+100.0), + ). + AssertSuccess(otu.T). + AssertEvent(otu.T, "FindLeaseMarketDirectOfferSoft.DirectOffer", map[string]interface{}{ + "amount": price, + "buyer": otu.O.Address(user), + }) + + return otu +} + func (otu *OverflowTestUtils) directOfferLeaseMarketSoft(user string, name string, price float64) *OverflowTestUtils { otu.O.Tx("bidLeaseMarketDirectOfferSoftDapper", WithSigner(user), @@ -659,6 +715,22 @@ func (otu *OverflowTestUtils) acceptDirectOfferMarketSoft(name string, id uint64 return otu } +func (otu *OverflowTestUtils) acceptLeaseDirectOfferMarketSoftFlow(buyer, seller string, name string, price float64) *OverflowTestUtils { + otu.O.Tx("acceptLeaseDirectOfferSoft", + WithSigner(seller), + WithArg("leaseName", name), + ). + AssertSuccess(otu.T). + AssertEvent(otu.T, "FindLeaseMarketDirectOfferSoft.DirectOffer", map[string]interface{}{ + "seller": otu.O.Address(seller), + "buyer": otu.O.Address(buyer), + "amount": price, + "status": "active_accepted", + }) + + return otu +} + func (otu *OverflowTestUtils) acceptLeaseDirectOfferMarketSoft(buyer, seller string, name string, price float64) *OverflowTestUtils { otu.O.Tx("acceptLeaseDirectOfferSoftDapper", WithSigner(seller), @@ -818,6 +890,22 @@ func (otu *OverflowTestUtils) fulfillMarketAuctionSoft(name string, id uint64, p return otu } +func (otu *OverflowTestUtils) fulfillLeaseMarketAuctionSoftFlow(user string, name string, price float64) *OverflowTestUtils { + otu.O.Tx("fulfillLeaseMarketAuctionSoft", + WithSigner(user), + WithArg("leaseName", name), + WithArg("amount", price), + ). + AssertSuccess(otu.T). + AssertEvent(otu.T, "FindLeaseMarketAuctionSoft.EnglishAuction", map[string]interface{}{ + "buyer": otu.O.Address(user), + "amount": price, + "status": "sold", + }) + + return otu +} + func (otu *OverflowTestUtils) fulfillLeaseMarketAuctionSoft(user string, name string, price float64) *OverflowTestUtils { otu.O.Tx("fulfillLeaseMarketAuctionSoftDapper", WithSigner(user), @@ -870,6 +958,22 @@ func (otu *OverflowTestUtils) fulfillLeaseMarketDirectOfferSoft(user, name strin return otu } +func (otu *OverflowTestUtils) fulfillLeaseMarketDirectOfferSoftFlow(user, name string, price float64) *OverflowTestUtils { + otu.O.Tx("fulfillLeaseMarketDirectOfferSoft", + WithSigner(user), + WithArg("leaseName", name), + WithArg("amount", price), + ). + AssertSuccess(otu.T). + AssertEvent(otu.T, "FindLeaseMarketDirectOfferSoft.DirectOffer", map[string]interface{}{ + "buyer": otu.O.Address(user), + "amount": price, + "status": "sold", + }) + + return otu +} + type Cap struct { Address string Id uint64 @@ -1122,6 +1226,23 @@ func (otu *OverflowTestUtils) listNFTForSaleDUC(name string, id uint64, price fl return res } +func (otu *OverflowTestUtils) listLeaseForSale(user string, name string, price float64) *OverflowTestUtils { + ftIden, err := otu.O.QualifiedIdentifier("FlowToken", "Vault") + assert.NoError(otu.T, err) + + res := otu.O.Tx("listLeaseForSale", + WithSigner(user), + WithArg("leaseName", name), + WithArg("ftAliasOrIdentifier", ftIden), + WithArg("directSellPrice", price), + WithArg("validUntil", otu.currentTime()+100.0), + ) + + res.AssertSuccess(otu.T) + + return otu +} + func (otu *OverflowTestUtils) listLeaseForSaleDUC(user string, name string, price float64) *OverflowTestUtils { ftIden, err := otu.O.QualifiedIdentifier("DapperUtilityCoin", "Vault") assert.NoError(otu.T, err) @@ -1178,6 +1299,42 @@ func (otu *OverflowTestUtils) buyLeaseForMarketSaleDUC(buyer, seller, name strin return otu } +func (otu *OverflowTestUtils) buyLeaseForMarketSale(buyer, seller, name string, price float64) *OverflowTestUtils { + amount := price * 0.025 + + eventIden, err := otu.O.QualifiedIdentifier("FindLeaseMarketSale", "Sale") + assert.NoError(otu.T, err) + + otu.O.Tx("buyLeaseForSale", + WithSigner(buyer), + WithArg("leaseName", name), + WithArg("amount", price), + ). + AssertSuccess(otu.T). + AssertEvent(otu.T, eventIden, map[string]interface{}{ + "amount": price, + "seller": otu.O.Address(seller), + "buyer": otu.O.Address(buyer), + "status": "sold", + }). + AssertEvent(otu.T, "RoyaltyPaid", map[string]interface{}{ + "amount": amount, + "address": otu.O.Address("find"), + "royaltyName": "find", + "tenant": "find", + }) + /*. + AssertEvent(otu.T, "RoyaltyPaid", map[string]interface{}{ + "amount": dapperAmount, + "address": otu.O.Address("dapper"), + "royaltyName": "dapper", + "tenant": "find", + }) + */ + + return otu +} + func (otu *OverflowTestUtils) listNFTForSoftAuctionDUC(name string, id uint64, price float64) []uint64 { ftIden, err := otu.O.QualifiedIdentifier("DapperUtilityCoin", "Vault") assert.NoError(otu.T, err) diff --git a/transactions/acceptLeaseDirectOfferSoft.cdc b/transactions/acceptLeaseDirectOfferSoft.cdc index 083abb8d..cfbab5c2 100644 --- a/transactions/acceptLeaseDirectOfferSoft.cdc +++ b/transactions/acceptLeaseDirectOfferSoft.cdc @@ -8,22 +8,33 @@ import "FIND" transaction(leaseName: String) { - let market : &FindLeaseMarketDirectOfferSoft.SaleItemCollection - let pointer : FindLeaseMarket.AuthLeasePointer - - prepare(account: auth(BorrowValue) &Account) { - let marketplace = FindMarket.getFindTenantAddress() - let tenant=FindMarket.getTenant(marketplace) - let storagePath=tenant.getStoragePath(Type<@FindLeaseMarketDirectOfferSoft.SaleItemCollection>()) - self.market = account.storage.borrow<&FindLeaseMarketDirectOfferSoft.SaleItemCollection>(from: storagePath)! - let marketOption = FindMarket.getMarketOptionFromType(Type<@FindLeaseMarketDirectOfferSoft.SaleItemCollection>()) - let item = FindLeaseMarket.assertOperationValid(tenant: marketplace, name: leaseName, marketOption: marketOption) - let ref = account.capabilities.storage.get(from: FIND.LeaseStoragePath) ?? panic("Cannot borrow reference to find lease collection. Account : ".concat(account.address.toString())) - self.pointer= FindLeaseMarket.AuthLeasePointer(ref: ref, name: leaseName) - } - - execute { - self.market.acceptOffer(self.pointer) - } + let market : auth(FindLeaseMarketDirectOfferSoft.Seller) &FindLeaseMarketDirectOfferSoft.SaleItemCollection + let pointer : FindLeaseMarket.AuthLeasePointer + + prepare(account: auth(Storage, IssueStorageCapabilityController) &Account) { + let marketplace = FindMarket.getFindTenantAddress() + let tenant=FindMarket.getTenant(marketplace) + let storagePath=tenant.getStoragePath(Type<@FindLeaseMarketDirectOfferSoft.SaleItemCollection>()) + self.market = account.storage.borrow(from: storagePath)! + + + let storagePathIdentifer = FIND.LeaseStoragePath.toString().split(separator:"/")[1] + let providerIdentifier = storagePathIdentifer.concat("ProviderFlow") + let providerStoragePath = StoragePath(identifier: providerIdentifier)! + + var existingProvider= account.storage.copy>(from: providerStoragePath) + if existingProvider==nil { + existingProvider=account.capabilities.storage.issue(FIND.LeaseStoragePath) + account.storage.save(existingProvider!, to: providerStoragePath) + } + var cap = existingProvider! + self.pointer= FindLeaseMarket.AuthLeasePointer(cap: cap, name: leaseName) + + + } + + execute { + self.market.acceptOffer(self.pointer) + } } diff --git a/transactions/acceptLeaseDirectOfferSoftDapper.cdc b/transactions/acceptLeaseDirectOfferSoftDapper.cdc index 824fda30..bb2818d7 100644 --- a/transactions/acceptLeaseDirectOfferSoftDapper.cdc +++ b/transactions/acceptLeaseDirectOfferSoftDapper.cdc @@ -4,7 +4,6 @@ import "MetadataViews" import "FindViews" import "FindMarket" import "FindLeaseMarket" -import "FungibleToken" import "FIND" transaction(leaseName: String) { diff --git a/transactions/bidLeaseMarketDirectOfferSoft.cdc b/transactions/bidLeaseMarketDirectOfferSoft.cdc index 88105215..5f7150af 100644 --- a/transactions/bidLeaseMarketDirectOfferSoft.cdc +++ b/transactions/bidLeaseMarketDirectOfferSoft.cdc @@ -8,7 +8,7 @@ import "FindLeaseMarketDirectOfferSoft" transaction(leaseName: String, ftAliasOrIdentifier:String, amount: UFix64, validUntil: UFix64?) { - let bidsReference: &FindLeaseMarketDirectOfferSoft.MarketBidCollection? + let bidsReference: auth(FindLeaseMarketDirectOfferSoft.Buyer) &FindLeaseMarketDirectOfferSoft.MarketBidCollection? let ftVaultType: Type prepare(account: auth(StorageCapabilities, SaveValue,PublishCapability, BorrowValue) &Account) { @@ -29,17 +29,20 @@ transaction(leaseName: String, ftAliasOrIdentifier:String, amount: UFix64, valid let leaseTenantCapability= FindMarket.getTenantCapability(leaseMarketplace)! let leaseTenant = leaseTenantCapability.borrow()! - let receiverCap=account.capabilities.get<&{FungibleToken.Receiver}>(Profile.publicReceiverPath)! + + + let receiverCap=account.capabilities.get<&{FungibleToken.Receiver}>(Profile.publicReceiverPath) let leaseDOSBidType= Type<@FindLeaseMarketDirectOfferSoft.MarketBidCollection>() let leaseDOSBidPublicPath=leaseTenant.getPublicPath(leaseDOSBidType) let leaseDOSBidStoragePath= leaseTenant.getStoragePath(leaseDOSBidType) - let leaseDOSBidCap= account.getCapability<&FindLeaseMarketDirectOfferSoft.MarketBidCollection>(leaseDOSBidPublicPath) + let leaseDOSBidCap= account.capabilities.get<&FindLeaseMarketDirectOfferSoft.MarketBidCollection>(leaseDOSBidPublicPath) if !leaseDOSBidCap.check() { account.storage.save<@FindLeaseMarketDirectOfferSoft.MarketBidCollection>(<- FindLeaseMarketDirectOfferSoft.createEmptyMarketBidCollection(receiver:receiverCap, tenantCapability:leaseTenantCapability), to: leaseDOSBidStoragePath) - account.link<&FindLeaseMarketDirectOfferSoft.MarketBidCollection>(leaseDOSBidPublicPath, target: leaseDOSBidStoragePath) + let cap = account.capabilities.storage.issue<&FindLeaseMarketDirectOfferSoft.MarketBidCollection>(leaseDOSBidStoragePath) + account.capabilities.publish(cap, at: leaseDOSBidPublicPath) } - self.bidsReference= account.storage.borrow<&FindLeaseMarketDirectOfferSoft.MarketBidCollection>(from: leaseDOSBidStoragePath) + self.bidsReference= account.storage.borrow(from: leaseDOSBidStoragePath) } diff --git a/transactions/buyLeaseForSale.cdc b/transactions/buyLeaseForSale.cdc new file mode 100644 index 00000000..a8015bf6 --- /dev/null +++ b/transactions/buyLeaseForSale.cdc @@ -0,0 +1,60 @@ +import "FindMarket" +import "FTRegistry" +import "FungibleToken" +import "FIND" +import "Profile" +import "FindLeaseMarketSale" +import "FindLeaseMarket" + +transaction(leaseName: String, amount: UFix64) { + + let buyer : Address + let walletReference : auth(FungibleToken.Withdraw) &{FungibleToken.Vault} + + let saleItemCollection: &{FindLeaseMarketSale.SaleItemCollectionPublic, FindLeaseMarket.SaleItemCollectionPublic} + + prepare(account: auth(BorrowValue, SaveValue, IssueStorageCapabilityController) &Account) { + + let profile=account.storage.borrow<&Profile.User>(from: Profile.storagePath) ?? panic("You do not have a profile set up, initialize the user first") + + let address = FIND.resolve(leaseName) ?? panic("The address input is not a valid name nor address. Input : ".concat(leaseName)) + + if address == nil { + panic("The address input is not a valid name nor address. Input : ".concat(leaseName)) + } + + let leaseMarketplace = FindMarket.getTenantAddress("find") ?? panic("Cannot find find tenant") + let saleItemsCap= FindLeaseMarketSale.getSaleItemCapability(marketplace: leaseMarketplace, user:address) ?? panic("cannot find sale item cap for find") + + let leaseTenantCapability= FindMarket.getTenantCapability(leaseMarketplace)! + let leaseTenant = leaseTenantCapability.borrow()! + + let leaseSaleItemType= Type<@FindLeaseMarketSale.SaleItemCollection>() + let leasePublicPath=FindMarket.getPublicPath(leaseSaleItemType, name: "find") + let leaseStoragePath= FindMarket.getStoragePath(leaseSaleItemType, name:"find") + var leaseSaleItemCap= account.capabilities.get<&{FindLeaseMarketSale.SaleItemCollectionPublic, FindLeaseMarket.SaleItemCollectionPublic}>(leasePublicPath) + if !leaseSaleItemCap.check(){ + //The link here has to be a capability not a tenant, because it can change. + account.storage.save<@FindLeaseMarketSale.SaleItemCollection>(<- FindLeaseMarketSale.createEmptySaleItemCollection(leaseTenantCapability), to: leaseStoragePath) + leaseSaleItemCap= account.capabilities.storage.issue<&{FindLeaseMarket.SaleItemCollectionPublic, FindLeaseMarketSale.SaleItemCollectionPublic}>(leaseStoragePath) + } + + self.saleItemCollection = saleItemsCap.borrow()! + let item = self.saleItemCollection.borrowSaleItem(leaseName) + + let ft = FTRegistry.getFTInfoByTypeIdentifier(item.getFtType().identifier) ?? panic("This FT is not supported by the Find Market yet. Type : ".concat(item.getFtType().identifier)) + + + self.walletReference = account.storage.borrow(from: ft.vaultPath) ?? panic("No suitable wallet linked for this account") + self.buyer = account.address + } + + pre { + self.walletReference.balance > amount : "Your wallet does not have enough funds to pay for this item" + } + + execute { + let vault <- self.walletReference.withdraw(amount: amount) + self.saleItemCollection.buy(name:leaseName, vault: <- vault, to: self.buyer) + } +} diff --git a/transactions/createProfileDapper.cdc b/transactions/createProfileDapper.cdc index 65393917..d57814ea 100644 --- a/transactions/createProfileDapper.cdc +++ b/transactions/createProfileDapper.cdc @@ -15,6 +15,7 @@ import "FindViews" transaction(name: String) { prepare(account: auth(Profile.Admin, StorageCapabilities, SaveValue,PublishCapability, BorrowValue) &Account) { + let leaseCollection = account.capabilities.get<&FIND.LeaseCollection>(FIND.LeasePublicPath) if !leaseCollection.check() { account.storage.save(<- FIND.createEmptyLeaseCollection(), to: FIND.LeaseStoragePath) diff --git a/transactions/listLeaseForAuctionSoft.cdc b/transactions/listLeaseForAuctionSoft.cdc index 090b4890..b545df09 100644 --- a/transactions/listLeaseForAuctionSoft.cdc +++ b/transactions/listLeaseForAuctionSoft.cdc @@ -34,7 +34,7 @@ transaction(leaseName: String, ftAliasOrIdentifier:String, price:UFix64, auction let storagePathIdentifer = FIND.LeaseStoragePath.toString().split(separator:"/")[1] - let providerIdentifier = storagePathIdentifer.concat("Provider") + let providerIdentifier = storagePathIdentifer.concat("ProviderFlow") let providerStoragePath = StoragePath(identifier: providerIdentifier)! var existingProvider= account.storage.copy>(from: providerStoragePath) diff --git a/transactions/listLeaseForSale.cdc b/transactions/listLeaseForSale.cdc new file mode 100644 index 00000000..ee993c11 --- /dev/null +++ b/transactions/listLeaseForSale.cdc @@ -0,0 +1,61 @@ +import "FindMarket" +import "FIND" +import "FTRegistry" +import "FindLeaseMarketSale" +import "FindLeaseMarket" +import "FindMarketSale" + +transaction(leaseName: String, ftAliasOrIdentifier: String, directSellPrice:UFix64, validUntil: UFix64?) { + + let saleItems : auth(FindLeaseMarketSale.Seller) &FindLeaseMarketSale.SaleItemCollection + let pointer : FindLeaseMarket.AuthLeasePointer + let vaultType : Type + + prepare(account: auth(Storage, IssueStorageCapabilityController, PublishCapability, IssueStorageCapabilityController) &Account) { + + // Get the salesItemRef from tenant + let leaseMarketplace = FindMarket.getFindTenantAddress() + let leaseTenantCapability= FindMarket.getTenantCapability(leaseMarketplace)! + let leaseTenant = leaseTenantCapability.borrow()! + + let leaseSaleItemType= Type<@FindLeaseMarketSale.SaleItemCollection>() + let leasePublicPath=leaseTenant.getPublicPath(leaseSaleItemType) + let leaseStoragePath= leaseTenant.getStoragePath(leaseSaleItemType) + let leaseSaleItemCap= account.capabilities.get<&{FindLeaseMarket.SaleItemCollectionPublic, FindLeaseMarketSale.SaleItemCollectionPublic}>(leasePublicPath) + if !leaseSaleItemCap.check() { + //The link here has to be a capability not a tenant, because it can change. + account.storage.save<@FindLeaseMarketSale.SaleItemCollection>(<- FindLeaseMarketSale.createEmptySaleItemCollection(leaseTenantCapability), to: leaseStoragePath) + let leaseSaleItemCap= account.capabilities.storage.issue<&{FindLeaseMarket.SaleItemCollectionPublic, FindLeaseMarketSale.SaleItemCollectionPublic}>(leaseStoragePath) + account.capabilities.publish(leaseSaleItemCap, at: leasePublicPath) + } + + + self.saleItems= account.storage.borrow(from: leaseStoragePath)! + + // Get supported NFT and FT Information from Registries from input alias + let ft = FTRegistry.getFTInfo(ftAliasOrIdentifier) ?? panic("This FT is not supported by the Find Market yet. Type : ".concat(ftAliasOrIdentifier)) + self.vaultType= ft.type + + let storagePathIdentifer = FIND.LeaseStoragePath.toString().split(separator:"/")[1] + let providerIdentifier = storagePathIdentifer.concat("ProviderFlow") + let providerStoragePath = StoragePath(identifier: providerIdentifier)! + + var existingProvider= account.storage.copy>(from: providerStoragePath) + if existingProvider==nil { + existingProvider=account.capabilities.storage.issue(FIND.LeaseStoragePath) + account.storage.save(existingProvider!, to: providerStoragePath) + } + var cap = existingProvider! + self.pointer= FindLeaseMarket.AuthLeasePointer(cap: cap, name: leaseName) + } + + pre{ + self.saleItems != nil : "Cannot borrow reference to saleItem" + } + + execute{ + self.saleItems.listForSale(pointer: self.pointer, vaultType: self.vaultType, directSellPrice: directSellPrice, validUntil: validUntil, extraField: {}) + } + +} + diff --git a/transactions/listLeaseForSaleDapper.cdc b/transactions/listLeaseForSaleDapper.cdc index 3c767e91..a63fd4b5 100644 --- a/transactions/listLeaseForSaleDapper.cdc +++ b/transactions/listLeaseForSaleDapper.cdc @@ -29,10 +29,7 @@ transaction(leaseName: String, ftAliasOrIdentifier: String, directSellPrice:UFix account.capabilities.publish(leaseSaleItemCap, at: leasePublicPath) } - self.saleItems= account.storage.borrow(from: leaseStoragePath)! - - // Get supported NFT and FT Information from Registries from input alias let ft = FTRegistry.getFTInfo(ftAliasOrIdentifier) ?? panic("This FT is not supported by the Find Market yet. Type : ".concat(ftAliasOrIdentifier)) self.vaultType= ft.type