Skip to content

Commit 94e354a

Browse files
authored
feat(marketplace/offers): implement extensions for marketplace offers (#2806)
Signed-off-by: Jonas Daniels <jonas.daniels@outlook.com>
1 parent e18606e commit 94e354a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1954
-948
lines changed

.changeset/proud-ravens-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Implement `Offers` in the Marketplace extensions, available via `thirdweb/extensions/marketplace`.

packages/thirdweb/package.json

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -109,54 +109,22 @@
109109
},
110110
"typesVersions": {
111111
"*": {
112-
"adapters/*": [
113-
"./dist/types/exports/adapters/*.d.ts"
114-
],
115-
"auth": [
116-
"./dist/types/exports/auth.d.ts"
117-
],
118-
"chains": [
119-
"./dist/types/exports/chains.d.ts"
120-
],
121-
"contract": [
122-
"./dist/types/exports/contract.d.ts"
123-
],
124-
"deploys": [
125-
"./dist/types/exports/deploys.d.ts"
126-
],
127-
"event": [
128-
"./dist/types/exports/event.d.ts"
129-
],
130-
"extensions/*": [
131-
"./dist/types/exports/extensions/*.d.ts"
132-
],
133-
"pay": [
134-
"./dist/types/exports/pay.d.ts"
135-
],
136-
"react": [
137-
"./dist/types/exports/react.d.ts"
138-
],
139-
"react-native": [
140-
"./dist/types/exports/react-native.d.ts"
141-
],
142-
"rpc": [
143-
"./dist/types/exports/rpc.d.ts"
144-
],
145-
"storage": [
146-
"./dist/types/exports/storage.d.ts"
147-
],
148-
"transaction": [
149-
"./dist/types/exports/transaction.d.ts"
150-
],
151-
"utils": [
152-
"./dist/types/exports/utils.d.ts"
153-
],
154-
"wallets": [
155-
"./dist/types/exports/wallets.d.ts"
156-
],
157-
"wallets/*": [
158-
"./dist/types/exports/wallets/*.d.ts"
159-
]
112+
"adapters/*": ["./dist/types/exports/adapters/*.d.ts"],
113+
"auth": ["./dist/types/exports/auth.d.ts"],
114+
"chains": ["./dist/types/exports/chains.d.ts"],
115+
"contract": ["./dist/types/exports/contract.d.ts"],
116+
"deploys": ["./dist/types/exports/deploys.d.ts"],
117+
"event": ["./dist/types/exports/event.d.ts"],
118+
"extensions/*": ["./dist/types/exports/extensions/*.d.ts"],
119+
"pay": ["./dist/types/exports/pay.d.ts"],
120+
"react": ["./dist/types/exports/react.d.ts"],
121+
"react-native": ["./dist/types/exports/react-native.d.ts"],
122+
"rpc": ["./dist/types/exports/rpc.d.ts"],
123+
"storage": ["./dist/types/exports/storage.d.ts"],
124+
"transaction": ["./dist/types/exports/transaction.d.ts"],
125+
"utils": ["./dist/types/exports/utils.d.ts"],
126+
"wallets": ["./dist/types/exports/wallets.d.ts"],
127+
"wallets/*": ["./dist/types/exports/wallets/*.d.ts"]
160128
}
161129
},
162130
"browser": {
@@ -226,7 +194,7 @@
226194
"push": "yalc push",
227195
"size": "size-limit",
228196
"test:watch": "vitest -c ./test/vitest.config.ts dev",
229-
"test": "vitest run -c ./test/vitest.config.ts",
197+
"test": "vitest run -c ./test/vitest.config.ts --coverage",
230198
"test:cov": "vitest dev -c ./test/vitest.config.ts --coverage",
231199
"test:dev": "vitest run -c ./test/vitest.config.ts",
232200
"typedoc": "node scripts/typedoc.mjs",

packages/thirdweb/scripts/generate/abis/marketplace/IOffers.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"event NewOffer(address indexed offeror, uint256 indexed offerId, address indexed assetContract, (uint256 offerId, uint256 tokenId, uint256 quantity, uint256 totalPrice, uint256 expirationTimestamp, address offeror, address assetContract, address currency, uint8 tokenType, uint8 status) offer)",
55
"function acceptOffer(uint256 _offerId)",
66
"function cancelOffer(uint256 _offerId)",
7+
"function totalOffers() view returns (uint256)",
78
"function getAllOffers(uint256 _startId, uint256 _endId) view returns ((uint256 offerId, uint256 tokenId, uint256 quantity, uint256 totalPrice, uint256 expirationTimestamp, address offeror, address assetContract, address currency, uint8 tokenType, uint8 status)[] offers)",
89
"function getAllValidOffers(uint256 _startId, uint256 _endId) view returns ((uint256 offerId, uint256 tokenId, uint256 quantity, uint256 totalPrice, uint256 expirationTimestamp, address offeror, address assetContract, address currency, uint8 tokenType, uint8 status)[] offers)",
910
"function getOffer(uint256 _offerId) view returns ((uint256 offerId, uint256 tokenId, uint256 quantity, uint256 totalPrice, uint256 expirationTimestamp, address offeror, address assetContract, address currency, uint8 tokenType, uint8 status) offer)",

packages/thirdweb/src/exports/extensions/erc20.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,15 @@ export {
7777
setClaimConditions,
7878
type SetClaimConditionsParams,
7979
} from "../../extensions/erc20/drops/write/setClaimConditions.js";
80+
81+
// ----------------------------
82+
// WETH
83+
// ----------------------------
84+
export {
85+
deposit,
86+
type DepositParams,
87+
} from "../../extensions/erc20/write/deposit.js";
88+
export {
89+
withdraw,
90+
type WithdrawParams,
91+
} from "../../extensions/erc20/__generated__/IWETH/write/withdraw.js";

packages/thirdweb/src/exports/extensions/marketplace.ts

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,53 @@
1-
// ----------------------------
2-
// COMMON
3-
// ----------------------------
4-
5-
export type {
6-
DirectListing,
7-
ListingStatus,
8-
} from "../../extensions/marketplace/types.js";
9-
101
// ----------------------------
112
// DIRECT LISTINGS
123
// ----------------------------
134

5+
export type { DirectListing } from "../../extensions/marketplace/direct-listings/types.js";
6+
147
// READ
158
export { totalListings } from "../../extensions/marketplace/__generated__/IDirectListings/read/totalListings.js";
169
export {
1710
getListing,
1811
type GetListingParams,
19-
} from "../../extensions/marketplace/read/direct/getListing.js";
12+
} from "../../extensions/marketplace/direct-listings/read/getListing.js";
2013
export {
2114
getAllListings,
2215
type GetAllListingParams,
23-
} from "../../extensions/marketplace/read/direct/getAllListings.js";
16+
} from "../../extensions/marketplace/direct-listings/read/getAllListings.js";
2417
export {
2518
getAllValidListings,
2619
type GetAllValidListingParams,
27-
} from "../../extensions/marketplace/read/direct/getAllValidListings.js";
20+
} from "../../extensions/marketplace/direct-listings/read/getAllValidListings.js";
2821
export {
2922
isBuyerApprovedForListing,
3023
type IsBuyerApprovedForListingParams,
31-
} from "../../extensions/marketplace/read/direct/isBuyerApprovedForListing.js";
24+
} from "../../extensions/marketplace/direct-listings/read/isBuyerApprovedForListing.js";
3225
export {
3326
isCurrencyApprovedForListing,
3427
type IsCurrencyApprovedForListingParams,
3528
} from "../../extensions/marketplace/__generated__/IDirectListings/read/isCurrencyApprovedForListing.js";
3629
export {
3730
currencyPriceForListing,
3831
type CurrencyPriceForListingParams,
39-
} from "../../extensions/marketplace/read/direct/currencyPriceForListing.js";
32+
} from "../../extensions/marketplace/direct-listings/read/currencyPriceForListing.js";
4033

4134
// WRITE
4235
export {
4336
createListing,
4437
type CreateListingParams,
45-
} from "../../extensions/marketplace/write/direct/createListing.js";
38+
} from "../../extensions/marketplace/direct-listings/write/createListing.js";
4639
export {
4740
updateListing,
4841
type UpdateListingParams,
49-
} from "../../extensions/marketplace/write/direct/updateListing.js";
42+
} from "../../extensions/marketplace/direct-listings/write/updateListing.js";
5043
export {
5144
cancelListing,
5245
type CancelListingParams,
5346
} from "../../extensions/marketplace/__generated__/IDirectListings/write/cancelListing.js";
5447
export {
5548
buyFromListing,
5649
type BuyFromListingParams,
57-
} from "../../extensions/marketplace/write/direct/buyFromListing.js";
50+
} from "../../extensions/marketplace/direct-listings/write/buyFromListing.js";
5851
export {
5952
approveBuyerForListing,
6053
type ApproveBuyerForListingParams,
@@ -94,24 +87,26 @@ export {
9487
// ENGLISH AUCTIONS
9588
// ----------------------------
9689

90+
export type { EnglishAuction } from "../../extensions/marketplace/english-auctions/types.js";
91+
9792
// READ
9893
export { totalAuctions } from "../../extensions/marketplace/__generated__/IEnglishAuctions/read/totalAuctions.js";
9994
export {
10095
getAuction,
10196
type GetAuctionParams,
102-
} from "../../extensions/marketplace/read/english-auction/getAuction.js";
97+
} from "../../extensions/marketplace/english-auctions/read/getAuction.js";
10398
export {
10499
getAllAuctions,
105100
type GetAllAuctionParams,
106-
} from "../../extensions/marketplace/read/english-auction/getAllAuctions.js";
101+
} from "../../extensions/marketplace/english-auctions/read/getAllAuctions.js";
107102
export {
108103
getAllValidAuctions,
109104
type GetAllValidAuctionParams,
110-
} from "../../extensions/marketplace/read/english-auction/getAllValidAuctions.js";
105+
} from "../../extensions/marketplace/english-auctions/read/getAllValidAuctions.js";
111106
export {
112107
getWinningBid,
113108
type GetWinningBidParams,
114-
} from "../../extensions/marketplace/read/english-auction/getWinningBid.js";
109+
} from "../../extensions/marketplace/english-auctions/read/getWinningBid.js";
115110
export {
116111
isNewWinningBid,
117112
type IsNewWinningBidParams,
@@ -121,19 +116,19 @@ export {
121116
export {
122117
createAuction,
123118
type CreateAuctionParams,
124-
} from "../../extensions/marketplace/write/english-auction/createAuction.js";
119+
} from "../../extensions/marketplace/english-auctions/write/createAuction.js";
125120
export {
126121
bidInAuction,
127122
type BidInAuctionParams,
128-
} from "../../extensions/marketplace/write/english-auction/bidInAuction.js";
123+
} from "../../extensions/marketplace/english-auctions/write/bidInAuction.js";
129124
export {
130125
cancelAuction,
131126
type CancelAuctionParams,
132127
} from "../../extensions/marketplace/__generated__/IEnglishAuctions/write/cancelAuction.js";
133128
export {
134129
buyoutAuction,
135130
type BuyoutAuctionParams,
136-
} from "../../extensions/marketplace/write/english-auction/buyoutAuction.js";
131+
} from "../../extensions/marketplace/english-auctions/write/buyoutAuction.js";
137132
export {
138133
collectAuctionPayout,
139134
type CollectAuctionPayoutParams,
@@ -145,7 +140,7 @@ export {
145140
export {
146141
executeSale,
147142
type ExecuteSaleParams,
148-
} from "../../extensions/marketplace/write/english-auction/executeSale.js";
143+
} from "../../extensions/marketplace/english-auctions/write/executeSale.js";
149144

150145
// EVENTS
151146
export {
@@ -164,3 +159,52 @@ export {
164159
newBidEvent,
165160
type NewBidEventFilters,
166161
} from "../../extensions/marketplace/__generated__/IEnglishAuctions/events/NewBid.js";
162+
163+
// ----------------------------
164+
// OFFERS
165+
// ----------------------------
166+
167+
export type { Offer } from "../../extensions/marketplace/offers/types.js";
168+
169+
// READ
170+
export { totalOffers } from "../../extensions/marketplace/__generated__/IOffers/read/totalOffers.js";
171+
export {
172+
getAllOffers,
173+
type GetAllOffersParams,
174+
} from "../../extensions/marketplace/offers/read/getAllOffers.js";
175+
export {
176+
getAllValidOffers,
177+
type GetAllValidOffersParams,
178+
} from "../../extensions/marketplace/offers/read/getAllValidOffers.js";
179+
export {
180+
getOffer,
181+
type GetOfferParams,
182+
} from "../../extensions/marketplace/offers/read/getOffer.js";
183+
184+
// WRITE
185+
export {
186+
makeOffer,
187+
type MakeOfferParams,
188+
} from "../../extensions/marketplace/offers/write/makeOffer.js";
189+
export {
190+
cancelOffer,
191+
type CancelOfferParams,
192+
} from "../../extensions/marketplace/__generated__/IOffers/write/cancelOffer.js";
193+
export {
194+
acceptOffer,
195+
type AcceptOfferParams,
196+
} from "../../extensions/marketplace/offers/write/acceptOffer.js";
197+
198+
// EVENTS
199+
export {
200+
acceptedOfferEvent,
201+
type AcceptedOfferEventFilters,
202+
} from "../../extensions/marketplace/__generated__/IOffers/events/AcceptedOffer.js";
203+
export {
204+
cancelledOfferEvent,
205+
type CancelledOfferEventFilters,
206+
} from "../../extensions/marketplace/__generated__/IOffers/events/CancelledOffer.js";
207+
export {
208+
newOfferEvent,
209+
type NewOfferEventFilters,
210+
} from "../../extensions/marketplace/__generated__/IOffers/events/NewOffer.js";
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { prepareContractCall } from "../../../transaction/prepare-contract-call.js";
2+
import type { BaseTransactionOptions } from "../../../transaction/types.js";
3+
import { toWei } from "../../../utils/units.js";
4+
import { FN_SELECTOR } from "../__generated__/IWETH/write/deposit.js";
5+
6+
export type DepositParams =
7+
| {
8+
amount: string;
9+
}
10+
| { amountWei: bigint };
11+
12+
/**
13+
* Calls the "deposit" function on the contract.
14+
* @param options - The options for the "deposit" function.
15+
* @returns A prepared transaction object.
16+
* @extension ERC20
17+
* @example
18+
* ```ts
19+
* import { deposit } from "thirdweb/extensions/erc20";
20+
*
21+
* const transaction = deposit();
22+
*
23+
* // Send the transaction
24+
* ...
25+
*
26+
* ```
27+
*/
28+
export function deposit(options: BaseTransactionOptions<DepositParams>) {
29+
return prepareContractCall({
30+
contract: options.contract,
31+
method: [FN_SELECTOR, [], []] as const,
32+
value: "amountWei" in options ? options.amountWei : toWei(options.amount),
33+
});
34+
}

0 commit comments

Comments
 (0)