Skip to content

Commit c417bda

Browse files
gregfromstljnsdls
andauthored
Fix v4 marketplace gas estimate (#3054)
Co-authored-by: Jonas Daniels <jonas.daniels@outlook.com>
1 parent 02c3eeb commit c417bda

File tree

5 files changed

+97
-32
lines changed

5 files changed

+97
-32
lines changed

.changeset/mean-mayflies-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/sdk": patch
3+
---
4+
5+
Fixes gas estimates on marketplace writes

legacy_packages/sdk/src/evm/core/classes/internal/marketplace/marketplace-auction.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class MarketplaceAuction {
238238
listingStartTime = blockTime;
239239
}
240240

241-
return Transaction.fromContractWrapper({
241+
const tx = Transaction.fromContractWrapper({
242242
contractWrapper: this.contractWrapper,
243243
method: "createListing",
244244
args: [
@@ -265,6 +265,8 @@ export class MarketplaceAuction {
265265
};
266266
},
267267
});
268+
tx.setGasLimitMultiple(1.2);
269+
return tx;
268270
},
269271
);
270272

@@ -289,7 +291,7 @@ export class MarketplaceAuction {
289291
)
290292
).map((tx) => tx.encode());
291293

292-
return Transaction.fromContractWrapper({
294+
const tx = Transaction.fromContractWrapper({
293295
contractWrapper: this.contractWrapper,
294296
method: "multicall",
295297
args: [data],
@@ -306,6 +308,8 @@ export class MarketplaceAuction {
306308
});
307309
},
308310
});
311+
tx.setGasLimitMultiple(1.2);
312+
return tx;
309313
},
310314
);
311315

@@ -396,7 +400,7 @@ export class MarketplaceAuction {
396400
listing.currencyContractAddress,
397401
overrides,
398402
);
399-
return Transaction.fromContractWrapper({
403+
const tx = Transaction.fromContractWrapper({
400404
contractWrapper: this.contractWrapper,
401405
method: "offer",
402406
args: [
@@ -408,6 +412,8 @@ export class MarketplaceAuction {
408412
],
409413
overrides,
410414
});
415+
tx.setGasLimitMultiple(1.2);
416+
return tx;
411417
},
412418
);
413419

@@ -436,14 +442,16 @@ export class MarketplaceAuction {
436442
throw new AuctionAlreadyStartedError(listingId.toString());
437443
}
438444

439-
return Transaction.fromContractWrapper({
445+
const tx = Transaction.fromContractWrapper({
440446
contractWrapper: this.contractWrapper,
441447
method: "closeAuction",
442448
args: [
443449
BigNumber.from(listingId),
444450
await this.contractWrapper.getSignerAddress(),
445451
],
446452
});
453+
tx.setGasLimitMultiple(1.2);
454+
return tx;
447455
},
448456
);
449457

@@ -469,11 +477,13 @@ export class MarketplaceAuction {
469477
}
470478
const listing = await this.validateListing(BigNumber.from(listingId));
471479
try {
472-
return Transaction.fromContractWrapper({
480+
const tx = Transaction.fromContractWrapper({
473481
contractWrapper: this.contractWrapper,
474482
method: "closeAuction",
475483
args: [BigNumber.from(listingId), closeFor],
476484
});
485+
tx.setGasLimitMultiple(1.2);
486+
return tx;
477487
} catch (err: any) {
478488
if (err.message.includes("cannot close auction before it has ended")) {
479489
throw new AuctionHasNotEndedError(
@@ -515,11 +525,13 @@ export class MarketplaceAuction {
515525
listingId,
516526
winningBid.buyerAddress,
517527
]);
518-
return Transaction.fromContractWrapper({
528+
const tx = Transaction.fromContractWrapper({
519529
contractWrapper: this.contractWrapper,
520530
method: "multicall",
521531
args: [closeForSeller, closeForBuyer],
522532
});
533+
tx.setGasLimitMultiple(1.2);
534+
return tx;
523535
} catch (err: any) {
524536
if (err.message.includes("cannot close auction before it has ended")) {
525537
throw new AuctionHasNotEndedError(
@@ -539,7 +551,7 @@ export class MarketplaceAuction {
539551
*/
540552
updateListing = /* @__PURE__ */ buildTransactionFunction(
541553
async (listing: AuctionListing) => {
542-
return Transaction.fromContractWrapper({
554+
const tx = Transaction.fromContractWrapper({
543555
contractWrapper: this.contractWrapper,
544556
method: "updateListing",
545557
args: [
@@ -552,6 +564,8 @@ export class MarketplaceAuction {
552564
listing.endTimeInEpochSeconds,
553565
],
554566
});
567+
tx.setGasLimitMultiple(1.2);
568+
return tx;
555569
},
556570
);
557571

legacy_packages/sdk/src/evm/core/classes/internal/marketplace/marketplace-direct.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class MarketplaceDirect {
189189
listingStartTime = blockTime;
190190
}
191191

192-
return Transaction.fromContractWrapper({
192+
const tx = Transaction.fromContractWrapper({
193193
contractWrapper: this.contractWrapper,
194194
method: "createListing",
195195
args: [
@@ -216,6 +216,8 @@ export class MarketplaceDirect {
216216
};
217217
},
218218
});
219+
tx.setGasLimitMultiple(1.2);
220+
return tx;
219221
},
220222
);
221223

@@ -240,7 +242,7 @@ export class MarketplaceDirect {
240242
)
241243
).map((tx) => tx.encode());
242244

243-
return Transaction.fromContractWrapper({
245+
const tx = Transaction.fromContractWrapper({
244246
contractWrapper: this.contractWrapper,
245247
method: "multicall",
246248
args: [data],
@@ -257,6 +259,8 @@ export class MarketplaceDirect {
257259
});
258260
},
259261
});
262+
tx.setGasLimitMultiple(1.2);
263+
return tx;
260264
},
261265
);
262266

@@ -330,7 +334,7 @@ export class MarketplaceDirect {
330334
);
331335
}
332336

333-
return Transaction.fromContractWrapper({
337+
const tx = Transaction.fromContractWrapper({
334338
contractWrapper: this.contractWrapper,
335339
method: "offer",
336340
args: [
@@ -342,6 +346,8 @@ export class MarketplaceDirect {
342346
],
343347
overrides,
344348
});
349+
tx.setGasLimitMultiple(1.2);
350+
return tx;
345351
},
346352
);
347353

@@ -373,11 +379,13 @@ export class MarketplaceDirect {
373379
resolvedAddress,
374380
]);
375381

376-
return Transaction.fromContractWrapper({
382+
const tx = Transaction.fromContractWrapper({
377383
contractWrapper: this.contractWrapper,
378384
method: "acceptOffer",
379385
args: [listingId, resolvedAddress, offer.currency, offer.pricePerToken],
380386
});
387+
tx.setGasLimitMultiple(1.2);
388+
return tx;
381389
},
382390
);
383391

@@ -427,7 +435,7 @@ export class MarketplaceDirect {
427435
overrides,
428436
);
429437

430-
return Transaction.fromContractWrapper({
438+
const tx = Transaction.fromContractWrapper({
431439
contractWrapper: this.contractWrapper,
432440
method: "buy",
433441
args: [
@@ -439,6 +447,8 @@ export class MarketplaceDirect {
439447
],
440448
overrides,
441449
});
450+
tx.setGasLimitMultiple(1.2);
451+
return tx;
442452
},
443453
);
444454

@@ -451,7 +461,7 @@ export class MarketplaceDirect {
451461
*/
452462
updateListing = /* @__PURE__ */ buildTransactionFunction(
453463
async (listing: DirectListing) => {
454-
return Transaction.fromContractWrapper({
464+
const tx = Transaction.fromContractWrapper({
455465
contractWrapper: this.contractWrapper,
456466
method: "updateListing",
457467
args: [
@@ -464,6 +474,8 @@ export class MarketplaceDirect {
464474
listing.secondsUntilEnd,
465475
],
466476
});
477+
tx.setGasLimitMultiple(1.2);
478+
return tx;
467479
},
468480
);
469481

@@ -482,11 +494,13 @@ export class MarketplaceDirect {
482494
*/
483495
cancelListing = /* @__PURE__ */ buildTransactionFunction(
484496
async (listingId: BigNumberish) => {
485-
return Transaction.fromContractWrapper({
497+
const tx = Transaction.fromContractWrapper({
486498
contractWrapper: this.contractWrapper,
487499
method: "cancelDirectListing",
488500
args: [listingId],
489501
});
502+
tx.setGasLimitMultiple(1.2);
503+
return tx;
490504
},
491505
);
492506

legacy_packages/sdk/src/evm/core/classes/marketplacev3-direct-listings.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
366366
parsedListing.startTimestamp = BigNumber.from(blockTime);
367367
}
368368

369-
return Transaction.fromContractWrapper({
369+
const tx = Transaction.fromContractWrapper({
370370
contractWrapper: this.contractWrapper,
371371
method: "createListing",
372372
args: [
@@ -394,6 +394,8 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
394394
};
395395
},
396396
});
397+
tx.setGasLimitMultiple(1.2);
398+
return tx;
397399
},
398400
);
399401

@@ -418,7 +420,7 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
418420
)
419421
).map((tx) => tx.encode());
420422

421-
return Transaction.fromContractWrapper({
423+
const tx = Transaction.fromContractWrapper({
422424
contractWrapper: this
423425
.contractWrapper as unknown as ContractWrapper<MarketplaceV3>,
424426
method: "multicall",
@@ -436,6 +438,8 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
436438
});
437439
},
438440
});
441+
tx.setGasLimitMultiple(1.2);
442+
return tx;
439443
},
440444
);
441445

@@ -498,7 +502,7 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
498502
parsedListing.currencyContractAddress,
499503
);
500504

501-
return Transaction.fromContractWrapper({
505+
const tx = Transaction.fromContractWrapper({
502506
contractWrapper: this.contractWrapper,
503507
method: "updateListing",
504508
args: [
@@ -527,6 +531,8 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
527531
};
528532
},
529533
});
534+
tx.setGasLimitMultiple(1.2);
535+
return tx;
530536
},
531537
);
532538

@@ -546,11 +552,13 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
546552
*/
547553
cancelListing = /* @__PURE__ */ buildTransactionFunction(
548554
async (listingId: BigNumberish) => {
549-
return Transaction.fromContractWrapper({
555+
const tx = Transaction.fromContractWrapper({
550556
contractWrapper: this.contractWrapper,
551557
method: "cancelListing",
552558
args: [listingId],
553559
});
560+
tx.setGasLimitMultiple(1.2);
561+
return tx;
554562
},
555563
);
556564

@@ -605,7 +613,7 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
605613
overrides,
606614
);
607615

608-
return Transaction.fromContractWrapper({
616+
const tx = Transaction.fromContractWrapper({
609617
contractWrapper: this.contractWrapper,
610618
method: "buyFromListing",
611619
args: [
@@ -617,6 +625,8 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
617625
],
618626
overrides,
619627
});
628+
tx.setGasLimitMultiple(1.2);
629+
return tx;
620630
},
621631
);
622632

@@ -642,11 +652,13 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
642652
const isApproved = await this.isBuyerApprovedForListing(listingId, buyer);
643653

644654
if (!isApproved) {
645-
return Transaction.fromContractWrapper({
655+
const tx = Transaction.fromContractWrapper({
646656
contractWrapper: this.contractWrapper,
647657
method: "approveBuyerForListing",
648658
args: [listingId, buyer, true],
649659
});
660+
tx.setGasLimitMultiple(1.2);
661+
return tx;
650662
} else {
651663
throw new Error(
652664
`Buyer ${buyer} already approved for listing ${listingId}.`,
@@ -678,11 +690,13 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
678690
);
679691

680692
if (isApproved) {
681-
return Transaction.fromContractWrapper({
693+
const tx = Transaction.fromContractWrapper({
682694
contractWrapper: this.contractWrapper,
683695
method: "approveBuyerForListing",
684696
args: [listingId, buyer, false],
685697
});
698+
tx.setGasLimitMultiple(1.2);
699+
return tx;
686700
} else {
687701
throw new Error(
688702
`Buyer ${buyer} not approved for listing ${listingId}.`,
@@ -735,11 +749,13 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
735749
"Currency already approved with this price.",
736750
);
737751

738-
return Transaction.fromContractWrapper({
752+
const tx = Transaction.fromContractWrapper({
739753
contractWrapper: this.contractWrapper,
740754
method: "approveCurrencyForListing",
741755
args: [listingId, resolvedCurrencyAddress, pricePerTokenInCurrency],
742756
});
757+
tx.setGasLimitMultiple(1.2);
758+
return tx;
743759
},
744760
);
745761

@@ -776,11 +792,13 @@ export class MarketplaceV3DirectListings<TContract extends DirectListingsLogic>
776792
);
777793
invariant(!currencyPrice.isZero(), "Currency not approved.");
778794

779-
return Transaction.fromContractWrapper({
795+
const tx = Transaction.fromContractWrapper({
780796
contractWrapper: this.contractWrapper,
781797
method: "approveCurrencyForListing",
782798
args: [listingId, resolvedCurrencyAddress, BigNumber.from(0)],
783799
});
800+
tx.setGasLimitMultiple(1.2);
801+
return tx;
784802
},
785803
);
786804

0 commit comments

Comments
 (0)