Skip to content

Commit 1273eeb

Browse files
committed
english auctions
1 parent 4e914aa commit 1273eeb

File tree

3 files changed

+140
-103
lines changed

3 files changed

+140
-103
lines changed

Thirdweb.Tests/Thirdweb.Extensions/Thirdweb.MarketplaceExtensions.Tests.cs

Lines changed: 101 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ public async Task Marketplace_DirectListings_CreateListing_Success()
7373
Assert.Equal(TokenType.ERC1155, listing.TokenTypeEnum);
7474
Assert.Equal(Status.CREATED, listing.StatusEnum);
7575
Assert.Equal(listing.Reserved, listingParams.Reserved);
76-
77-
var isCurrencyApproved = await contract.Marketplace_DirectListings_IsCurrencyApprovedForListing(listingId, Constants.NATIVE_TOKEN_ADDRESS);
78-
Assert.True(isCurrencyApproved);
79-
80-
var currencyPriceForListing = await contract.Marketplace_DirectListings_CurrencyPriceForListing(listingId, Constants.NATIVE_TOKEN_ADDRESS);
81-
Assert.Equal(currencyPriceForListing, listingParams.PricePerToken);
8276
}
8377

8478
[Fact(Timeout = 120000)]
@@ -229,6 +223,49 @@ public async Task Marketplace_DirectListings_GetListing_Success()
229223

230224
#region IEnglishAuctions
231225

226+
[Fact(Timeout = 120000)]
227+
public async Task Marketplace_EnglishAuctions_CreateAuction_Success()
228+
{
229+
var contract = await this.GetMarketplaceContract();
230+
var wallet = await this.GetSmartWallet(1);
231+
232+
var auctionParams = new AuctionParameters()
233+
{
234+
AssetContract = this._drop1155ContractAddress,
235+
TokenId = 0,
236+
Quantity = 1,
237+
Currency = Constants.NATIVE_TOKEN_ADDRESS,
238+
MinimumBidAmount = 1,
239+
BuyoutBidAmount = BigInteger.Parse("1".ToWei()),
240+
TimeBufferInSeconds = 3600,
241+
BidBufferBps = 100,
242+
StartTimestamp = Utils.GetUnixTimeStampNow() - 3000,
243+
EndTimestamp = Utils.GetUnixTimeStampNow() + (3600 * 24 * 7),
244+
};
245+
246+
var receipt = await contract.Marketplace_EnglishAuctions_CreateAuction(wallet, auctionParams, true);
247+
Assert.NotNull(receipt);
248+
Assert.True(receipt.TransactionHash.Length == 66);
249+
250+
var auctionId = await contract.Marketplace_EnglishAuctions_TotalAuctions() - 1;
251+
var auction = await contract.Marketplace_EnglishAuctions_GetAuction(auctionId);
252+
Assert.NotNull(auction);
253+
Assert.Equal(auction.AuctionId, auctionId);
254+
Assert.Equal(auction.TokenId, auctionParams.TokenId);
255+
Assert.Equal(auction.Quantity, auctionParams.Quantity);
256+
Assert.Equal(auction.MinimumBidAmount, auctionParams.MinimumBidAmount);
257+
Assert.Equal(auction.BuyoutBidAmount, auctionParams.BuyoutBidAmount);
258+
Assert.True(auction.TimeBufferInSeconds >= auctionParams.TimeBufferInSeconds);
259+
Assert.True(auction.BidBufferBps >= auctionParams.BidBufferBps);
260+
Assert.True(auction.StartTimestamp >= auctionParams.StartTimestamp);
261+
Assert.True(auction.EndTimestamp >= auctionParams.EndTimestamp);
262+
Assert.Equal(auction.AuctionCreator, await wallet.GetAddress());
263+
Assert.Equal(auction.AssetContract, auctionParams.AssetContract);
264+
Assert.Equal(auction.Currency, auctionParams.Currency);
265+
Assert.Equal(TokenType.ERC1155, auction.TokenTypeEnum);
266+
Assert.Equal(Status.CREATED, auction.StatusEnum);
267+
}
268+
232269
[Fact(Timeout = 120000)]
233270
public async Task Marketplace_EnglishAuctions_GetAuction_Success()
234271
{
@@ -262,64 +299,78 @@ public async Task Marketplace_EnglishAuctions_GetAllValidAuctions_Success()
262299
Assert.True(auctions.Count >= 0);
263300
}
264301

302+
#endregion
303+
304+
#region IOffers
305+
265306
// [Fact(Timeout = 120000)]
266-
// public async Task Marketplace_EnglishAuctions_GetWinningBid_Success()
307+
// public async Task Marketplace_Offers_MakeOffer_Success()
267308
// {
268309
// var contract = await this.GetMarketplaceContract();
269-
// var auctionId = BigInteger.One;
270-
271-
// var (bidder, currency, bidAmount) = await contract.Marketplace_EnglishAuctions_GetWinningBid(auctionId);
272-
// Assert.NotNull(bidder);
273-
// Assert.NotNull(currency);
274-
// Assert.True(bidAmount >= 0);
310+
// var wallet = await this.GetSmartWallet(0);
311+
312+
// var offerParams = new OfferParams()
313+
// {
314+
// AssetContract = this._drop1155ContractAddress,
315+
// TokenId = 0,
316+
// Quantity = 1,
317+
// Currency = ERC20_HERE,
318+
// TotalPrice = 0,
319+
// ExpirationTimestamp = Utils.GetUnixTimeStampNow() + (3600 * 24),
320+
// };
321+
322+
// var receipt = await contract.Marketplace_Offers_MakeOffer(wallet, offerParams, true);
323+
// Assert.NotNull(receipt);
324+
// Assert.True(receipt.TransactionHash.Length == 66);
325+
326+
// var offerId = await contract.Marketplace_Offers_TotalOffers() - 1;
327+
// var offer = await contract.Marketplace_Offers_GetOffer(offerId);
328+
// Assert.NotNull(offer);
329+
// Assert.Equal(offer.OfferId, offerId);
330+
// Assert.Equal(offer.TokenId, offerParams.TokenId);
331+
// Assert.Equal(offer.Quantity, offerParams.Quantity);
332+
// Assert.Equal(offer.TotalPrice, offerParams.TotalPrice);
333+
// Assert.True(offer.ExpirationTimestamp >= offerParams.ExpirationTimestamp);
334+
// Assert.Equal(offer.Offeror, await wallet.GetAddress());
335+
// Assert.Equal(offer.AssetContract, offerParams.AssetContract);
336+
// Assert.Equal(offer.Currency, offerParams.Currency);
337+
// Assert.Equal(TokenType.ERC1155, offer.TokenTypeEnum);
338+
// Assert.Equal(Status.CREATED, offer.StatusEnum);
275339
// }
276340

277341
// [Fact(Timeout = 120000)]
278-
// public async Task Marketplace_EnglishAuctions_IsAuctionExpired_Success()
342+
// public async Task Marketplace_Offers_GetOffer_Success()
279343
// {
280344
// var contract = await this.GetMarketplaceContract();
281-
// var auctionId = BigInteger.One;
345+
// var offerId = BigInteger.One;
282346

283-
// _ = await contract.Marketplace_EnglishAuctions_IsAuctionExpired(auctionId);
347+
// var offer = await contract.Marketplace_Offers_GetOffer(offerId);
348+
// Assert.NotNull(offer);
284349
// }
285350

286-
#endregion
287-
288-
#region IOffers
289-
290-
[Fact(Timeout = 120000)]
291-
public async Task Marketplace_Offers_GetOffer_Success()
292-
{
293-
var contract = await this.GetMarketplaceContract();
294-
var offerId = BigInteger.One;
295-
296-
var offer = await contract.Marketplace_Offers_GetOffer(offerId);
297-
Assert.NotNull(offer);
298-
}
299-
300-
[Fact(Timeout = 120000)]
301-
public async Task Marketplace_Offers_GetAllOffers_Success()
302-
{
303-
var contract = await this.GetMarketplaceContract();
304-
var startId = BigInteger.Zero;
305-
var endId = BigInteger.Zero;
351+
// [Fact(Timeout = 120000)]
352+
// public async Task Marketplace_Offers_GetAllOffers_Success()
353+
// {
354+
// var contract = await this.GetMarketplaceContract();
355+
// var startId = BigInteger.Zero;
356+
// var endId = 10;
306357

307-
var offers = await contract.Marketplace_Offers_GetAllOffers(startId, endId);
308-
Assert.NotNull(offers);
309-
Assert.True(offers.Count >= 0);
310-
}
358+
// var offers = await contract.Marketplace_Offers_GetAllOffers(startId, endId);
359+
// Assert.NotNull(offers);
360+
// Assert.True(offers.Count >= 0);
361+
// }
311362

312-
[Fact(Timeout = 120000)]
313-
public async Task Marketplace_Offers_GetAllValidOffers_Success()
314-
{
315-
var contract = await this.GetMarketplaceContract();
316-
var startId = BigInteger.Zero;
317-
var endId = BigInteger.Zero;
363+
// [Fact(Timeout = 120000)]
364+
// public async Task Marketplace_Offers_GetAllValidOffers_Success()
365+
// {
366+
// var contract = await this.GetMarketplaceContract();
367+
// var startId = BigInteger.Zero;
368+
// var endId = 10;
318369

319-
var offers = await contract.Marketplace_Offers_GetAllValidOffers(startId, endId);
320-
Assert.NotNull(offers);
321-
Assert.True(offers.Count >= 0);
322-
}
370+
// var offers = await contract.Marketplace_Offers_GetAllValidOffers(startId, endId);
371+
// Assert.NotNull(offers);
372+
// Assert.True(offers.Count >= 0);
373+
// }
323374

324375
#endregion
325376
}

Thirdweb/Thirdweb.Extensions/ThirdwebMarketplaceExtensions.Types.cs

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -240,25 +240,25 @@ public class AuctionParameters
240240
/// The buffer time in seconds to extend the auction expiration if a new bid is made.
241241
/// </summary>
242242
[Parameter("uint64", "timeBufferInSeconds", 7)]
243-
public ulong TimeBufferInSeconds { get; set; }
243+
public long TimeBufferInSeconds { get; set; }
244244

245245
/// <summary>
246246
/// The bid buffer in basis points to ensure a new bid must be a certain percentage higher than the current bid.
247247
/// </summary>
248248
[Parameter("uint64", "bidBufferBps", 8)]
249-
public ulong BidBufferBps { get; set; }
249+
public long BidBufferBps { get; set; }
250250

251251
/// <summary>
252252
/// The timestamp at and after which bids can be made to the auction.
253253
/// </summary>
254254
[Parameter("uint64", "startTimestamp", 9)]
255-
public ulong StartTimestamp { get; set; }
255+
public long StartTimestamp { get; set; }
256256

257257
/// <summary>
258258
/// The timestamp after which bids cannot be made to the auction.
259259
/// </summary>
260260
[Parameter("uint64", "endTimestamp", 10)]
261-
public ulong EndTimestamp { get; set; }
261+
public long EndTimestamp { get; set; }
262262
}
263263

264264
/// <summary>
@@ -301,25 +301,25 @@ public class Auction
301301
/// The buffer time in seconds to extend the auction expiration if a new bid is made.
302302
/// </summary>
303303
[Parameter("uint64", "timeBufferInSeconds", 6)]
304-
public ulong TimeBufferInSeconds { get; set; }
304+
public long TimeBufferInSeconds { get; set; }
305305

306306
/// <summary>
307307
/// The bid buffer in basis points to ensure a new bid must be a certain percentage higher than the current bid.
308308
/// </summary>
309309
[Parameter("uint64", "bidBufferBps", 7)]
310-
public ulong BidBufferBps { get; set; }
310+
public long BidBufferBps { get; set; }
311311

312312
/// <summary>
313313
/// The timestamp at and after which bids can be made to the auction.
314314
/// </summary>
315315
[Parameter("uint64", "startTimestamp", 8)]
316-
public ulong StartTimestamp { get; set; }
316+
public long StartTimestamp { get; set; }
317317

318318
/// <summary>
319319
/// The timestamp after which bids cannot be made to the auction.
320320
/// </summary>
321321
[Parameter("uint64", "endTimestamp", 9)]
322-
public ulong EndTimestamp { get; set; }
322+
public long EndTimestamp { get; set; }
323323

324324
/// <summary>
325325
/// The address of the auction creator.
@@ -352,50 +352,6 @@ public class Auction
352352
public Status StatusEnum { get; set; }
353353
}
354354

355-
/// <summary>
356-
/// Represents a bid in an auction.
357-
/// </summary>
358-
[Struct("Bid")]
359-
public class Bid
360-
{
361-
/// <summary>
362-
/// The unique ID of the auction for which the bid is placed.
363-
/// </summary>
364-
[Parameter("uint256", "auctionId", 1)]
365-
public BigInteger AuctionId { get; set; }
366-
367-
/// <summary>
368-
/// The address of the bidder.
369-
/// </summary>
370-
[Parameter("address", "bidder", 2)]
371-
public string Bidder { get; set; }
372-
373-
/// <summary>
374-
/// The bid amount for the auction.
375-
/// </summary>
376-
[Parameter("uint256", "bidAmount", 3)]
377-
public BigInteger BidAmount { get; set; }
378-
}
379-
380-
/// <summary>
381-
/// Represents the status of the payout for an auction.
382-
/// </summary>
383-
[Struct("AuctionPayoutStatus")]
384-
public class AuctionPayoutStatus
385-
{
386-
/// <summary>
387-
/// Whether the auction tokens have been paid out.
388-
/// </summary>
389-
[Parameter("bool", "paidOutAuctionTokens", 1)]
390-
public bool PaidOutAuctionTokens { get; set; }
391-
392-
/// <summary>
393-
/// Whether the bid amount has been paid out.
394-
/// </summary>
395-
[Parameter("bool", "paidOutBidAmount", 2)]
396-
public bool PaidOutBidAmount { get; set; }
397-
}
398-
399355
#endregion
400356

401357
#region IOffers
@@ -446,7 +402,7 @@ public class OfferParams
446402
/// <summary>
447403
/// Represents an offer made on NFTs.
448404
/// </summary>
449-
[Struct("Offer")]
405+
[FunctionOutput]
450406
public class Offer
451407
{
452408
/// <summary>

Thirdweb/Thirdweb.Extensions/ThirdwebMarketplaceExtensions.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,21 @@ public static async Task<bool> Marketplace_EnglishAuctions_IsAuctionExpired(this
700700
return await contract.Read<bool>("isAuctionExpired", auctionId);
701701
}
702702

703+
/// <summary>
704+
/// Gets the total number of auctions created.
705+
/// </summary>
706+
/// <param name="contract">The contract instance.</param>
707+
/// <returns>A task that represents the total number of auctions.</returns>
708+
public static async Task<BigInteger> Marketplace_EnglishAuctions_TotalAuctions(this ThirdwebContract contract)
709+
{
710+
if (contract == null)
711+
{
712+
throw new ArgumentNullException(nameof(contract));
713+
}
714+
715+
return await contract.Read<BigInteger>("totalAuctions");
716+
}
717+
703718
#endregion
704719

705720
#region IOffers
@@ -854,5 +869,20 @@ public static async Task<List<Offer>> Marketplace_Offers_GetAllValidOffers(this
854869
return await contract.Read<List<Offer>>("getAllValidOffers", startId, endId);
855870
}
856871

872+
/// <summary>
873+
/// Gets the total number of offers created.
874+
/// </summary>
875+
/// <param name="contract">The contract instance.</param>
876+
/// <returns>A task that represents the total number of offers.</returns>
877+
public static async Task<BigInteger> Marketplace_Offers_TotalOffers(this ThirdwebContract contract)
878+
{
879+
if (contract == null)
880+
{
881+
throw new ArgumentNullException(nameof(contract));
882+
}
883+
884+
return await contract.Read<BigInteger>("totalOffers");
885+
}
886+
857887
#endregion
858888
}

0 commit comments

Comments
 (0)