1+ using System . Collections . Generic ;
2+ using System . Threading . Tasks ;
3+
4+ namespace Thirdweb
5+ {
6+ /// <summary>
7+ /// Interact with a Marketplace contract.
8+ /// </summary>
9+ public class Marketplace
10+ {
11+ public string chain ;
12+ public string address ;
13+ public MarketplaceDirect direct ;
14+ public MarketplaceAuction auction ;
15+
16+ public Marketplace ( string chain , string address )
17+ {
18+ this . chain = chain ;
19+ this . address = address ;
20+ this . direct = new MarketplaceDirect ( chain , address ) ;
21+ this . auction = new MarketplaceAuction ( chain , address ) ;
22+ }
23+
24+ /// READ FUNCTIONS
25+
26+ public async Task < Listing > GetListing ( string listingId )
27+ {
28+ return await Bridge . InvokeRoute < Listing > ( getRoute ( "getListing" ) , Utils . ToJsonStringArray ( listingId ) ) ;
29+ }
30+
31+ public async Task < List < Listing > > GetAllListings ( MarketplaceFilter filter = null )
32+ {
33+ return await Bridge . InvokeRoute < List < Listing > > ( getRoute ( "getAllListings" ) , Utils . ToJsonStringArray ( filter ) ) ;
34+ }
35+
36+ public async Task < List < Listing > > GetActiveListings ( MarketplaceFilter filter = null )
37+ {
38+ return await Bridge . InvokeRoute < List < Listing > > ( getRoute ( "getActiveListings" ) , Utils . ToJsonStringArray ( filter ) ) ;
39+ }
40+
41+ public async Task < List < Offer > > GetOffers ( string listingId )
42+ {
43+ return await Bridge . InvokeRoute < List < Offer > > ( getRoute ( "getOffers" ) , Utils . ToJsonStringArray ( listingId ) ) ;
44+ }
45+
46+ /// WRITE FUNCTIONS
47+
48+ public async Task < TransactionResult > BuyListing ( string listingId , int ? quantityDesired = null , string receiverAddress = null )
49+ {
50+ return await Bridge . InvokeRoute < TransactionResult > ( getRoute ( "buyoutListing" ) , Utils . ToJsonStringArray ( listingId , quantityDesired , receiverAddress ) ) ;
51+ }
52+
53+ public async Task < TransactionResult > MakeOffer ( string listingId , string pricePerToken , int ? quantity = null )
54+ {
55+ return await Bridge . InvokeRoute < TransactionResult > ( getRoute ( "makeOffer" ) , Utils . ToJsonStringArray ( listingId , pricePerToken , quantity ) ) ;
56+ }
57+
58+ /// PRIVATE
59+
60+ private string getRoute ( string functionPath ) {
61+ return this . address + ".marketplace." + functionPath ;
62+ }
63+ }
64+
65+ // DIRECT
66+
67+ public class MarketplaceDirect {
68+ public string chain ;
69+ public string address ;
70+
71+ public MarketplaceDirect ( string chain , string address )
72+ {
73+ this . chain = chain ;
74+ this . address = address ;
75+ }
76+
77+ public async Task < DirectListing > GetListing ( string listingId )
78+ {
79+ return await Bridge . InvokeRoute < DirectListing > ( getRoute ( "getListing" ) , Utils . ToJsonStringArray ( listingId ) ) ;
80+ }
81+
82+ public async Task < Offer > GetActiveOffer ( string listingId , string address )
83+ {
84+ return await Bridge . InvokeRoute < Offer > ( getRoute ( "getActiveOffer" ) , Utils . ToJsonStringArray ( listingId ) ) ;
85+ }
86+
87+ public async Task < TransactionResult > CreateListing ( NewDirectListing listing )
88+ {
89+ return await Bridge . InvokeRoute < TransactionResult > ( getRoute ( "createListing" ) , Utils . ToJsonStringArray ( listing ) ) ;
90+ }
91+
92+ public async Task < TransactionResult > AcceptOffer ( NewDirectListing listing , string addressOfOfferor )
93+ {
94+ return await Bridge . InvokeRoute < TransactionResult > ( getRoute ( "acceptOffer" ) , Utils . ToJsonStringArray ( listing , addressOfOfferor ) ) ;
95+ }
96+
97+ public async Task < TransactionResult > CancelListing ( string listingId )
98+ {
99+ return await Bridge . InvokeRoute < TransactionResult > ( getRoute ( "cancelListing" ) , Utils . ToJsonStringArray ( listingId ) ) ;
100+ }
101+
102+ private string getRoute ( string functionPath ) {
103+ return this . address + ".marketplace.direct." + functionPath ;
104+ }
105+ }
106+
107+ // AUCTION
108+
109+ public class MarketplaceAuction {
110+ public string chain ;
111+ public string address ;
112+
113+ public MarketplaceAuction ( string chain , string address )
114+ {
115+ this . chain = chain ;
116+ this . address = address ;
117+ }
118+
119+ public async Task < AuctionListing > GetListing ( string listingId )
120+ {
121+ return await Bridge . InvokeRoute < AuctionListing > ( getRoute ( "getListing" ) , Utils . ToJsonStringArray ( listingId ) ) ;
122+ }
123+
124+ public async Task < Offer > GetWinningBid ( string listingId )
125+ {
126+ return await Bridge . InvokeRoute < Offer > ( getRoute ( "getWinningBid" ) , Utils . ToJsonStringArray ( listingId ) ) ;
127+ }
128+
129+ public async Task < CurrencyValue > GetMinimumNextBid ( string listingId )
130+ {
131+ return await Bridge . InvokeRoute < CurrencyValue > ( getRoute ( "getMinimumNextBid" ) , Utils . ToJsonStringArray ( listingId ) ) ;
132+ }
133+
134+ public async Task < string > GetWinner ( string listingId )
135+ {
136+ return await Bridge . InvokeRoute < string > ( getRoute ( "getWinner" ) , Utils . ToJsonStringArray ( listingId ) ) ;
137+ }
138+
139+ public async Task < TransactionResult > CreateListing ( NewAuctionListing listing )
140+ {
141+ return await Bridge . InvokeRoute < TransactionResult > ( getRoute ( "createListing" ) , Utils . ToJsonStringArray ( listing ) ) ;
142+ }
143+
144+ public async Task < TransactionResult > CancelListing ( string listingId )
145+ {
146+ return await Bridge . InvokeRoute < TransactionResult > ( getRoute ( "cancelListing" ) , Utils . ToJsonStringArray ( listingId ) ) ;
147+ }
148+
149+ public async Task < TransactionResult > ExecuteSale ( string listingId )
150+ {
151+ return await Bridge . InvokeRoute < TransactionResult > ( getRoute ( "executeSale" ) , Utils . ToJsonStringArray ( listingId ) ) ;
152+ }
153+
154+ private string getRoute ( string functionPath ) {
155+ return this . address + ".marketplace.auction." + functionPath ;
156+ }
157+ }
158+ }
0 commit comments