@0xsequence/marketplace-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/README.md +8 -0
  2. package/dist/chunk-3TYUQEFM.js +115 -0
  3. package/dist/chunk-3TYUQEFM.js.map +1 -0
  4. package/dist/chunk-4ESPWOBV.js +13 -0
  5. package/dist/chunk-4ESPWOBV.js.map +1 -0
  6. package/dist/chunk-4PFMUVE4.js +78 -0
  7. package/dist/chunk-4PFMUVE4.js.map +1 -0
  8. package/dist/chunk-5WRI5ZAA.js +31 -0
  9. package/dist/chunk-5WRI5ZAA.js.map +1 -0
  10. package/dist/chunk-6S4FYXP6.js +43 -0
  11. package/dist/chunk-6S4FYXP6.js.map +1 -0
  12. package/dist/chunk-7OO74L2K.js +41 -0
  13. package/dist/chunk-7OO74L2K.js.map +1 -0
  14. package/dist/chunk-BBB3XUB4.js +213 -0
  15. package/dist/chunk-BBB3XUB4.js.map +1 -0
  16. package/dist/chunk-BCNFYVAL.js +1 -0
  17. package/dist/chunk-BCNFYVAL.js.map +1 -0
  18. package/dist/chunk-D7QQP6MS.js +2 -0
  19. package/dist/chunk-D7QQP6MS.js.map +1 -0
  20. package/dist/chunk-DBFOPEV6.js +23 -0
  21. package/dist/chunk-DBFOPEV6.js.map +1 -0
  22. package/dist/chunk-EDTC7UES.js +176 -0
  23. package/dist/chunk-EDTC7UES.js.map +1 -0
  24. package/dist/chunk-G3D572BT.js +249 -0
  25. package/dist/chunk-G3D572BT.js.map +1 -0
  26. package/dist/chunk-HGBEC3WX.js +1285 -0
  27. package/dist/chunk-HGBEC3WX.js.map +1 -0
  28. package/dist/chunk-MJ4YU7RW.js +2 -0
  29. package/dist/chunk-MJ4YU7RW.js.map +1 -0
  30. package/dist/chunk-NJ2GXOPW.js +2 -0
  31. package/dist/chunk-NJ2GXOPW.js.map +1 -0
  32. package/dist/chunk-O5JXKTWP.js +1029 -0
  33. package/dist/chunk-O5JXKTWP.js.map +1 -0
  34. package/dist/chunk-O642NH7U.js +15 -0
  35. package/dist/chunk-O642NH7U.js.map +1 -0
  36. package/dist/chunk-QOJXWHRZ.js +71 -0
  37. package/dist/chunk-QOJXWHRZ.js.map +1 -0
  38. package/dist/chunk-QVFMD6S2.js +21 -0
  39. package/dist/chunk-QVFMD6S2.js.map +1 -0
  40. package/dist/chunk-RNUHUVLC.js +214 -0
  41. package/dist/chunk-RNUHUVLC.js.map +1 -0
  42. package/dist/chunk-SM7V6ZWI.js +2740 -0
  43. package/dist/chunk-SM7V6ZWI.js.map +1 -0
  44. package/dist/chunk-STO74F2I.js +14 -0
  45. package/dist/chunk-STO74F2I.js.map +1 -0
  46. package/dist/chunk-TZGLKJRF.js +198 -0
  47. package/dist/chunk-TZGLKJRF.js.map +1 -0
  48. package/dist/chunk-UYRQ5MJQ.js +1027 -0
  49. package/dist/chunk-UYRQ5MJQ.js.map +1 -0
  50. package/dist/chunk-VPGWEMWL.js +162 -0
  51. package/dist/chunk-VPGWEMWL.js.map +1 -0
  52. package/dist/chunk-ZE2LNX65.js +394 -0
  53. package/dist/chunk-ZE2LNX65.js.map +1 -0
  54. package/dist/create-config-Dz0gCiQ0.d.ts +8 -0
  55. package/dist/get-query-client-D46hbjk6.d.ts +5 -0
  56. package/dist/index.css +232 -0
  57. package/dist/index.d.ts +16 -0
  58. package/dist/index.js +76 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/marketplace-config-DZbtyrma.d.ts +57 -0
  61. package/dist/marketplace.gen-Ceofb9Cs.d.ts +904 -0
  62. package/dist/react/_internal/api/index.d.ts +51 -0
  63. package/dist/react/_internal/api/index.js +134 -0
  64. package/dist/react/_internal/api/index.js.map +1 -0
  65. package/dist/react/_internal/index.d.ts +22 -0
  66. package/dist/react/_internal/index.js +150 -0
  67. package/dist/react/_internal/index.js.map +1 -0
  68. package/dist/react/_internal/wagmi/index.d.ts +12 -0
  69. package/dist/react/_internal/wagmi/index.js +12 -0
  70. package/dist/react/_internal/wagmi/index.js.map +1 -0
  71. package/dist/react/hooks/index.d.ts +381 -0
  72. package/dist/react/hooks/index.js +82 -0
  73. package/dist/react/hooks/index.js.map +1 -0
  74. package/dist/react/index.css +233 -0
  75. package/dist/react/index.css.map +1 -0
  76. package/dist/react/index.d.ts +27 -0
  77. package/dist/react/index.js +113 -0
  78. package/dist/react/index.js.map +1 -0
  79. package/dist/react/ssr/index.d.ts +94 -0
  80. package/dist/react/ssr/index.js +351 -0
  81. package/dist/react/ssr/index.js.map +1 -0
  82. package/dist/react/ui/icons/index.css +25 -0
  83. package/dist/react/ui/icons/index.css.map +1 -0
  84. package/dist/react/ui/icons/index.d.ts +2 -0
  85. package/dist/react/ui/icons/index.js +12 -0
  86. package/dist/react/ui/icons/index.js.map +1 -0
  87. package/dist/react/ui/index.css +233 -0
  88. package/dist/react/ui/index.css.map +1 -0
  89. package/dist/react/ui/index.d.ts +112 -0
  90. package/dist/react/ui/index.js +34 -0
  91. package/dist/react/ui/index.js.map +1 -0
  92. package/dist/react/ui/modals/_internal/components/actionModal/index.css +44 -0
  93. package/dist/react/ui/modals/_internal/components/actionModal/index.css.map +1 -0
  94. package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +31 -0
  95. package/dist/react/ui/modals/_internal/components/actionModal/index.js +39 -0
  96. package/dist/react/ui/modals/_internal/components/actionModal/index.js.map +1 -0
  97. package/dist/react/ui/styles/index.css +36 -0
  98. package/dist/react/ui/styles/index.css.map +1 -0
  99. package/dist/react/ui/styles/index.d.ts +5 -0
  100. package/dist/react/ui/styles/index.js +13 -0
  101. package/dist/react/ui/styles/index.js.map +1 -0
  102. package/dist/sdk-config-xWkdBdrL.d.ts +24 -0
  103. package/dist/services-BIwQ1C1c.d.ts +20 -0
  104. package/dist/styles/index.css +233 -0
  105. package/dist/styles/index.css.map +1 -0
  106. package/dist/styles/index.d.ts +58 -0
  107. package/dist/styles/index.js +5019 -0
  108. package/dist/styles/index.js.map +1 -0
  109. package/dist/styles.css-BVaTR5nO.d.ts +3 -0
  110. package/dist/types/index.d.ts +12 -0
  111. package/dist/types/index.js +39 -0
  112. package/dist/types/index.js.map +1 -0
  113. package/dist/types-BrAQ8-w4.d.ts +12 -0
  114. package/dist/utils/abi/abi/standard/index.d.ts +25 -0
  115. package/dist/utils/abi/abi/standard/index.js +8 -0
  116. package/dist/utils/abi/abi/standard/index.js.map +1 -0
  117. package/dist/utils/abi/abi/token/index.d.ts +1125 -0
  118. package/dist/utils/abi/abi/token/index.js +13 -0
  119. package/dist/utils/abi/abi/token/index.js.map +1 -0
  120. package/dist/utils/abi/clients/index.d.ts +27 -0
  121. package/dist/utils/abi/clients/index.js +13 -0
  122. package/dist/utils/abi/clients/index.js.map +1 -0
  123. package/dist/utils/index.d.ts +23 -0
  124. package/dist/utils/index.js +37 -0
  125. package/dist/utils/index.js.map +1 -0
  126. package/package.json +74 -0
  127. package/src/consts.ts +2 -0
  128. package/src/index.ts +3 -0
  129. package/src/react/_internal/api/get-query-client.ts +32 -0
  130. package/src/react/_internal/api/index.ts +5 -0
  131. package/src/react/_internal/api/marketplace-api.ts +31 -0
  132. package/src/react/_internal/api/marketplace.gen.ts +1911 -0
  133. package/src/react/_internal/api/query-keys.ts +61 -0
  134. package/src/react/_internal/api/services.ts +101 -0
  135. package/src/react/_internal/consts.ts +1 -0
  136. package/src/react/_internal/get-provider.ts +6 -0
  137. package/src/react/_internal/index.ts +5 -0
  138. package/src/react/_internal/types.ts +13 -0
  139. package/src/react/_internal/wagmi/create-config.ts +62 -0
  140. package/src/react/_internal/wagmi/embedded.ts +87 -0
  141. package/src/react/_internal/wagmi/index.ts +3 -0
  142. package/src/react/_internal/wagmi/universal.ts +82 -0
  143. package/src/react/hooks/index.ts +17 -0
  144. package/src/react/hooks/options/marketplaceConfigOptions.ts +62 -0
  145. package/src/react/hooks/useBalanceOfCollectible.tsx +51 -0
  146. package/src/react/hooks/useCollectible.tsx +47 -0
  147. package/src/react/hooks/useCollection.tsx +42 -0
  148. package/src/react/hooks/useCollectionCounts.tsx +61 -0
  149. package/src/react/hooks/useConfig.tsx +15 -0
  150. package/src/react/hooks/useCurrencies.tsx +76 -0
  151. package/src/react/hooks/useFilters.tsx +39 -0
  152. package/src/react/hooks/useFloorOrder.tsx +28 -0
  153. package/src/react/hooks/useGenerateListingTransaction.tsx +63 -0
  154. package/src/react/hooks/useGenerateOfferTransaction.tsx +60 -0
  155. package/src/react/hooks/useGenerateSellTransaction.tsx +43 -0
  156. package/src/react/hooks/useHighestOffer.tsx +46 -0
  157. package/src/react/hooks/useListBalances.tsx +56 -0
  158. package/src/react/hooks/useListCollectibles.tsx +54 -0
  159. package/src/react/hooks/useListOffersForCollectible.tsx +53 -0
  160. package/src/react/hooks/useLowestListing.tsx +47 -0
  161. package/src/react/hooks/useMarketplaceConfig.tsx +10 -0
  162. package/src/react/hooks/useRoyaltyPercentage.tsx +45 -0
  163. package/src/react/hooks/useTransferTokens.tsx +81 -0
  164. package/src/react/index.ts +5 -0
  165. package/src/react/provider.tsx +24 -0
  166. package/src/react/ssr/create-ssr-client.ts +31 -0
  167. package/src/react/ssr/index.ts +1 -0
  168. package/src/react/ui/icons/ArrowUp.tsx +29 -0
  169. package/src/react/ui/icons/CalendarIcon.tsx +29 -0
  170. package/src/react/ui/icons/InfoIcon.tsx +36 -0
  171. package/src/react/ui/icons/InventoryIcon.tsx +41 -0
  172. package/src/react/ui/icons/MinusIcon.tsx +31 -0
  173. package/src/react/ui/icons/PlusIcon.tsx +29 -0
  174. package/src/react/ui/icons/PositiveCircleIcon.tsx +35 -0
  175. package/src/react/ui/icons/index.ts +7 -0
  176. package/src/react/ui/icons/styles.css.ts +35 -0
  177. package/src/react/ui/index.ts +6 -0
  178. package/src/react/ui/modals/Account/index.tsx +29 -0
  179. package/src/react/ui/modals/CreateListingModal/_store.ts +326 -0
  180. package/src/react/ui/modals/CreateListingModal/_utils/getCreateListingTransactionTitleMessage.ts +30 -0
  181. package/src/react/ui/modals/CreateListingModal/index.tsx +146 -0
  182. package/src/react/ui/modals/MakeOfferModal/_store.ts +296 -0
  183. package/src/react/ui/modals/MakeOfferModal/_utils/getMakeOfferTransactionTitleMessage.ts +28 -0
  184. package/src/react/ui/modals/MakeOfferModal/index.tsx +157 -0
  185. package/src/react/ui/modals/SellModal/_store.ts +274 -0
  186. package/src/react/ui/modals/SellModal/_utils/getSellTransactionTitleMessage.ts +28 -0
  187. package/src/react/ui/modals/SellModal/index.tsx +126 -0
  188. package/src/react/ui/modals/SellModal/utils.ts +38 -0
  189. package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +58 -0
  190. package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +186 -0
  191. package/src/react/ui/modals/SuccessfulPurchaseModal/styles.css.ts +52 -0
  192. package/src/react/ui/modals/TransferModal/_store.ts +58 -0
  193. package/src/react/ui/modals/TransferModal/_utils/getTransferTransactionTitleMessage.ts +28 -0
  194. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +102 -0
  195. package/src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx +130 -0
  196. package/src/react/ui/modals/TransferModal/index.tsx +92 -0
  197. package/src/react/ui/modals/TransferModal/messages.ts +14 -0
  198. package/src/react/ui/modals/TransferModal/styles.css.ts +20 -0
  199. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +94 -0
  200. package/src/react/ui/modals/_internal/components/actionModal/index.ts +3 -0
  201. package/src/react/ui/modals/_internal/components/actionModal/store.ts +19 -0
  202. package/src/react/ui/modals/_internal/components/actionModal/styles.css.ts +15 -0
  203. package/src/react/ui/modals/_internal/components/alertMessage/index.tsx +21 -0
  204. package/src/react/ui/modals/_internal/components/alertMessage/styles.css.ts +22 -0
  205. package/src/react/ui/modals/_internal/components/calendar/index.tsx +59 -0
  206. package/src/react/ui/modals/_internal/components/calendarPopover/index.tsx +41 -0
  207. package/src/react/ui/modals/_internal/components/calendarPopover/styles.css.ts +16 -0
  208. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +76 -0
  209. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/styles.css.ts +33 -0
  210. package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +127 -0
  211. package/src/react/ui/modals/_internal/components/expirationDateSelect/styles.css.ts +25 -0
  212. package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +54 -0
  213. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +72 -0
  214. package/src/react/ui/modals/_internal/components/priceInput/styles.css.ts +23 -0
  215. package/src/react/ui/modals/_internal/components/priceInput/types.ts +4 -0
  216. package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +168 -0
  217. package/src/react/ui/modals/_internal/components/quantityInput/styles.css.ts +30 -0
  218. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +132 -0
  219. package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +41 -0
  220. package/src/react/ui/modals/_internal/components/switchChainModal/styles.css.ts +37 -0
  221. package/src/react/ui/modals/_internal/components/timeAgo/index.tsx +32 -0
  222. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +58 -0
  223. package/src/react/ui/modals/_internal/components/tokenPreview/styles.css.ts +11 -0
  224. package/src/react/ui/modals/_internal/components/transaction-footer/index.tsx +48 -0
  225. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +80 -0
  226. package/src/react/ui/modals/_internal/components/transactionHeader/index.tsx +30 -0
  227. package/src/react/ui/modals/_internal/components/transactionPreview/consts.ts +27 -0
  228. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +111 -0
  229. package/src/react/ui/modals/_internal/components/transactionPreview/useTransactionPreviewTitle.tsx +24 -0
  230. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +123 -0
  231. package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +87 -0
  232. package/src/react/ui/modals/_internal/components/transactionStatusModal/styles.css.ts +15 -0
  233. package/src/react/ui/modals/_internal/stores/accountModal.ts +3 -0
  234. package/src/react/ui/modals/modal-provider.tsx +27 -0
  235. package/src/react/ui/styles/index.ts +1 -0
  236. package/src/react/ui/styles/modal.css.ts +73 -0
  237. package/src/styles/index.ts +18 -0
  238. package/src/types/api-types.ts +48 -0
  239. package/src/types/index.ts +4 -0
  240. package/src/types/marketplace-config.ts +63 -0
  241. package/src/types/messages.ts +43 -0
  242. package/src/types/sdk-config.ts +23 -0
  243. package/src/types/types.ts +6 -0
  244. package/src/utils/abi/abi/standard/EIP2981.ts +15 -0
  245. package/src/utils/abi/abi/standard/index.ts +1 -0
  246. package/src/utils/abi/abi/token/ERC1155.ts +324 -0
  247. package/src/utils/abi/abi/token/ERC20.ts +185 -0
  248. package/src/utils/abi/abi/token/ERC721.ts +506 -0
  249. package/src/utils/abi/abi/token/index.ts +3 -0
  250. package/src/utils/abi/clients/ERC1155.ts +82 -0
  251. package/src/utils/abi/clients/ERC20.ts +101 -0
  252. package/src/utils/abi/clients/ERC721.ts +97 -0
  253. package/src/utils/abi/clients/index.ts +3 -0
  254. package/src/utils/address.ts +26 -0
  255. package/src/utils/get-public-rpc-client.ts +32 -0
  256. package/src/utils/index.ts +6 -0
  257. package/src/utils/network.ts +5 -0
  258. package/src/utils/price.ts +21 -0
@@ -0,0 +1,61 @@
1
+ import {
2
+ type ChainId,
3
+ type CollectiblesFilter,
4
+ type OrderSide,
5
+ type QueryArg,
6
+ collectableKeys,
7
+ getMarketplaceClient,
8
+ } from '@internal';
9
+ import { queryOptions, useQuery } from '@tanstack/react-query';
10
+ import type { SdkConfig } from '@types';
11
+ import { useConfig } from './useConfig';
12
+
13
+ type ExtendedCollectiblesFilter = { side: OrderSide } & CollectiblesFilter;
14
+
15
+ export type UseCountOfCollectablesArgs = {
16
+ collectionAddress: string;
17
+ chainId: ChainId;
18
+ filter?: ExtendedCollectiblesFilter;
19
+ } & QueryArg;
20
+
21
+ export type UseHighestOfferReturn = ReturnType<typeof fetchCountOfCollectables>;
22
+
23
+ const fetchCountOfCollectables = async (
24
+ args: UseCountOfCollectablesArgs,
25
+ config: SdkConfig,
26
+ ) => {
27
+ const marketplaceClient = getMarketplaceClient(args.chainId, config);
28
+ if (args.filter) {
29
+ return marketplaceClient
30
+ .getCountOfFilteredCollectibles({
31
+ ...args,
32
+ contractAddress: args.collectionAddress,
33
+ side: args.filter.side,
34
+ })
35
+ .then((resp) => resp.count);
36
+ // biome-ignore lint/style/noUselessElse: <explanation>
37
+ } else {
38
+ return marketplaceClient
39
+ .getCountOfAllCollectibles({
40
+ ...args,
41
+ contractAddress: args.collectionAddress,
42
+ })
43
+ .then((resp) => resp.count);
44
+ }
45
+ };
46
+
47
+ export const countOfCollectablesOptions = (
48
+ args: UseCountOfCollectablesArgs,
49
+ config: SdkConfig,
50
+ ) => {
51
+ return queryOptions({
52
+ ...args.query,
53
+ queryKey: [...collectableKeys.counts, args],
54
+ queryFn: () => fetchCountOfCollectables(args, config),
55
+ });
56
+ };
57
+
58
+ export const useCountOfCollectables = (args: UseCountOfCollectablesArgs) => {
59
+ const config = useConfig();
60
+ return useQuery(countOfCollectablesOptions(args, config));
61
+ };
@@ -0,0 +1,15 @@
1
+ 'use client';
2
+
3
+ import { useContext } from 'react';
4
+
5
+ import { MarketplaceSdkContext } from '../provider';
6
+
7
+ export function useConfig() {
8
+ const context = useContext(MarketplaceSdkContext);
9
+ if (!context) {
10
+ throw new Error(
11
+ 'Marketplace SDK must be used within a MarketplaceSdkProvider',
12
+ );
13
+ }
14
+ return context;
15
+ }
@@ -0,0 +1,76 @@
1
+ import {
2
+ type ChainId,
3
+ type Currency,
4
+ type QueryArg,
5
+ configKeys,
6
+ currencyKeys,
7
+ getMarketplaceClient,
8
+ getQueryClient,
9
+ } from '@internal';
10
+ import { queryOptions, useQuery } from '@tanstack/react-query';
11
+ import type { MarketplaceConfig, SdkConfig } from '@types';
12
+ import { useConfig } from './useConfig';
13
+
14
+ export type UseCurrenciesArgs = {
15
+ chainId: ChainId;
16
+ collectionAddress?: string;
17
+ includeNativeCurrency?: boolean;
18
+ } & QueryArg;
19
+
20
+ export type UseCurrenciesReturn = ReturnType<typeof fetchCurrencies>;
21
+
22
+ const fetchCurrencies = async (chainId: ChainId, config: SdkConfig) => {
23
+ const marketplaceClient = getMarketplaceClient(chainId, config);
24
+ return marketplaceClient.listCurrencies().then((resp) => resp.currencies);
25
+ };
26
+
27
+ const selectCurrencies = (data: Currency[], args: UseCurrenciesArgs) => {
28
+ // if collectionAddress is passed, filter currencies based on collection currency options
29
+ if (args.collectionAddress) {
30
+ const queryClient = getQueryClient();
31
+ const marketplaceConfigCache = queryClient.getQueriesData({
32
+ queryKey: configKeys.marketplace,
33
+ })[0][1] as MarketplaceConfig;
34
+
35
+ const collection = marketplaceConfigCache?.collections.find(
36
+ (collection) => collection.collectionAddress === args.collectionAddress,
37
+ );
38
+
39
+ if (!collection) {
40
+ throw new Error("Collection doesn't exist");
41
+ }
42
+
43
+ return data.filter(
44
+ (currency) =>
45
+ collection.currencyOptions?.includes(currency.contractAddress) ||
46
+ // biome-ignore lint/suspicious/noDoubleEquals: <explanation>
47
+ currency.nativeCurrency == args.includeNativeCurrency ||
48
+ currency.defaultChainCurrency,
49
+ );
50
+ }
51
+ // if includeNativeCurrency is true, return all currencies
52
+ if (args.includeNativeCurrency) {
53
+ return data;
54
+ }
55
+
56
+ // if includeNativeCurrency is false or undefined, filter out native currencies
57
+ return data.filter((currency) => !currency.nativeCurrency);
58
+ };
59
+
60
+ export const currenciesOptions = (
61
+ args: UseCurrenciesArgs,
62
+ config: SdkConfig,
63
+ ) => {
64
+ return queryOptions({
65
+ ...args.query,
66
+ queryKey: [...currencyKeys.lists, args.chainId],
67
+ queryFn: () => fetchCurrencies(args.chainId, config),
68
+ select: (data) => selectCurrencies(data, args),
69
+ enabled: args.query?.enabled,
70
+ });
71
+ };
72
+
73
+ export const useCurrencies = (args: UseCurrenciesArgs) => {
74
+ const config = useConfig();
75
+ return useQuery(currenciesOptions(args, config));
76
+ };
@@ -0,0 +1,39 @@
1
+ import {
2
+ type ChainId,
3
+ type QueryArg,
4
+ collectableKeys,
5
+ getMetadataClient,
6
+ } from '@internal';
7
+ import { queryOptions, useQuery } from '@tanstack/react-query';
8
+ import type { SdkConfig } from '@types';
9
+ import { useConfig } from './useConfig';
10
+
11
+ export type UseFiltersArgs = {
12
+ chainId: ChainId;
13
+ collectionAddress: string;
14
+ } & QueryArg;
15
+
16
+ export type UseFilterReturn = ReturnType<typeof fetchFilters>;
17
+
18
+ export const fetchFilters = async (args: UseFiltersArgs, config: SdkConfig) => {
19
+ const metadataClient = getMetadataClient(config);
20
+ return metadataClient
21
+ .tokenCollectionFilters({
22
+ chainID: String(args.chainId),
23
+ contractAddress: args.collectionAddress,
24
+ })
25
+ .then((resp) => resp.filters);
26
+ };
27
+
28
+ export const filtersOptions = (args: UseFiltersArgs, config: SdkConfig) => {
29
+ return queryOptions({
30
+ ...args.query,
31
+ queryKey: [...collectableKeys.filter, args, config],
32
+ queryFn: () => fetchFilters(args, config),
33
+ });
34
+ };
35
+
36
+ export const useFilters = (args: UseFiltersArgs) => {
37
+ const config = useConfig();
38
+ return useQuery(filtersOptions(args, config));
39
+ };
@@ -0,0 +1,28 @@
1
+ import { collectableKeys, getMarketplaceClient } from '@internal';
2
+ import { queryOptions, useQuery } from '@tanstack/react-query';
3
+ import type { SdkConfig } from '@types';
4
+ import { useConfig } from './useConfig';
5
+
6
+ export type UseFloorOrder = {
7
+ chainId: string;
8
+ collectionAddress: string;
9
+ };
10
+
11
+ const fetchFloorOrder = async (args: UseFloorOrder, config: SdkConfig) => {
12
+ const marketplaceClient = getMarketplaceClient(args.chainId, config);
13
+ return marketplaceClient
14
+ .getFloorOrder({ contractAddress: args.collectionAddress })
15
+ .then((data) => data.collectible);
16
+ };
17
+
18
+ export const floorOrderOptions = (args: UseFloorOrder, config: SdkConfig) => {
19
+ return queryOptions({
20
+ queryKey: [...collectableKeys.floorOrders, args, config],
21
+ queryFn: () => fetchFloorOrder(args, config),
22
+ });
23
+ };
24
+
25
+ export const useFloorOrder = (args: UseFloorOrder) => {
26
+ const config = useConfig();
27
+ return useQuery(floorOrderOptions(args, config));
28
+ };
@@ -0,0 +1,63 @@
1
+ import {
2
+ type ChainId,
3
+ type GenerateListingTransactionArgs,
4
+ getMarketplaceClient,
5
+ } from '@internal';
6
+ import { useMutation } from '@tanstack/react-query';
7
+ import type { SdkConfig, Step } from '@types';
8
+ import { useConfig } from './useConfig';
9
+
10
+ export type UseGenerateListingTransactionArgs = {
11
+ chainId: ChainId;
12
+ onSuccess?: (data?: Step[]) => void;
13
+ };
14
+
15
+ import type { CreateReq } from '@types';
16
+
17
+ export type CreateReqWithDateExpiry = Omit<CreateReq, 'expiry'> & {
18
+ expiry: Date;
19
+ };
20
+
21
+ export type GenerateListingTransactionProps = Omit<
22
+ GenerateListingTransactionArgs,
23
+ 'listing'
24
+ > & {
25
+ listing: CreateReqWithDateExpiry;
26
+ };
27
+
28
+ const dateToUnixTime = (date: Date) =>
29
+ Math.floor(date.getTime() / 1000).toString();
30
+
31
+ export const generateListingTransaction = async (
32
+ params: GenerateListingTransactionProps,
33
+ config: SdkConfig,
34
+ chainId: ChainId,
35
+ ) => {
36
+ const args = {
37
+ ...params,
38
+ listing: {
39
+ ...params.listing,
40
+ expiry: dateToUnixTime(params.listing.expiry),
41
+ },
42
+ } satisfies GenerateListingTransactionArgs;
43
+ const marketplaceClient = getMarketplaceClient(chainId, config);
44
+ return (await marketplaceClient.generateListingTransaction(args)).steps;
45
+ };
46
+
47
+ export const useGenerateListingTransaction = (
48
+ params: UseGenerateListingTransactionArgs,
49
+ ) => {
50
+ const config = useConfig();
51
+
52
+ const { mutate, mutateAsync, ...result } = useMutation({
53
+ onSuccess: params.onSuccess,
54
+ mutationFn: (args: GenerateListingTransactionProps) =>
55
+ generateListingTransaction(args, config, params.chainId),
56
+ });
57
+
58
+ return {
59
+ ...result,
60
+ generateListingTransaction: mutate,
61
+ generateListingTransactionAsync: mutateAsync,
62
+ };
63
+ };
@@ -0,0 +1,60 @@
1
+ import {
2
+ type ChainId,
3
+ type GenerateOfferTransactionArgs,
4
+ getMarketplaceClient,
5
+ } from '@internal';
6
+ import { useMutation } from '@tanstack/react-query';
7
+ import type { SdkConfig, Step } from '@types';
8
+ import { useConfig } from './useConfig';
9
+
10
+ export type UseGenerateOfferTransactionArgs = {
11
+ chainId: ChainId;
12
+ onSuccess?: (data?: Step[]) => void;
13
+ };
14
+
15
+ import type { CreateReq } from '@types';
16
+
17
+ type CreateReqWithDateExpiry = Omit<CreateReq, 'expiry'> & {
18
+ expiry: Date;
19
+ };
20
+
21
+ export type GenerateOfferTransactionProps = Omit<
22
+ GenerateOfferTransactionArgs,
23
+ 'offer'
24
+ > & {
25
+ offer: CreateReqWithDateExpiry;
26
+ };
27
+
28
+ const dateToUnixTime = (date: Date) =>
29
+ Math.floor(date.getTime() / 1000).toString();
30
+
31
+ export const generateOfferTransaction = async (
32
+ params: GenerateOfferTransactionProps,
33
+ config: SdkConfig,
34
+ chainId: ChainId,
35
+ ) => {
36
+ const args = {
37
+ ...params,
38
+ offer: { ...params.offer, expiry: dateToUnixTime(params.offer.expiry) },
39
+ } satisfies GenerateOfferTransactionArgs;
40
+ const marketplaceClient = getMarketplaceClient(chainId, config);
41
+ return (await marketplaceClient.generateOfferTransaction(args)).steps;
42
+ };
43
+
44
+ export const useGenerateOfferTransaction = (
45
+ params: UseGenerateOfferTransactionArgs,
46
+ ) => {
47
+ const config = useConfig();
48
+
49
+ const { mutate, mutateAsync, ...result } = useMutation({
50
+ onSuccess: params.onSuccess,
51
+ mutationFn: (args: GenerateOfferTransactionProps) =>
52
+ generateOfferTransaction(args, config, params.chainId),
53
+ });
54
+
55
+ return {
56
+ ...result,
57
+ generateOfferTransaction: mutate,
58
+ generateOfferTransactionAsync: mutateAsync,
59
+ };
60
+ };
@@ -0,0 +1,43 @@
1
+ import {
2
+ type ChainId,
3
+ type GenerateSellTransactionArgs,
4
+ getMarketplaceClient,
5
+ } from '@internal';
6
+ import { useMutation } from '@tanstack/react-query';
7
+ import type { SdkConfig } from '@types';
8
+ import { useConfig } from './useConfig';
9
+
10
+ export type UseGenerateSellTransactionArgs = {
11
+ chainId: ChainId;
12
+ onSuccess?: () => void | Promise<void>;
13
+ };
14
+
15
+ export const generateSellTransaction = async (
16
+ args: GenerateSellTransactionArgs,
17
+ config: SdkConfig,
18
+ chainId: ChainId,
19
+ ) => {
20
+ console.log('generateSellTransaction');
21
+ console.log(args);
22
+ console.log(chainId);
23
+ const marketplaceClient = getMarketplaceClient(chainId, config);
24
+ return marketplaceClient.generateSellTransaction(args);
25
+ };
26
+
27
+ export const useGenerateSellTransaction = (
28
+ params: UseGenerateSellTransactionArgs,
29
+ ) => {
30
+ const config = useConfig();
31
+
32
+ const { mutate, mutateAsync, ...result } = useMutation({
33
+ onSuccess: params.onSuccess,
34
+ mutationFn: (args: GenerateSellTransactionArgs) =>
35
+ generateSellTransaction(args, config, params.chainId),
36
+ });
37
+
38
+ return {
39
+ ...result,
40
+ generateSellTransaction: mutate,
41
+ generateSellTransactionAsync: mutateAsync,
42
+ };
43
+ };
@@ -0,0 +1,46 @@
1
+ import {
2
+ type GetCollectibleHighestOfferArgs,
3
+ type QueryArg,
4
+ collectableKeys,
5
+ getMarketplaceClient,
6
+ } from '@internal';
7
+ import { queryOptions, useQuery } from '@tanstack/react-query';
8
+ import type { SdkConfig } from '@types';
9
+ import { useConfig } from './useConfig';
10
+
11
+ export type UseHighestOfferArgs = Omit<
12
+ GetCollectibleHighestOfferArgs,
13
+ 'contractAddress'
14
+ > & {
15
+ collectionAddress: string;
16
+ chainId: string;
17
+ } & QueryArg;
18
+
19
+ export type UseHighestOfferReturn = ReturnType<typeof fetchHighestOffer>;
20
+
21
+ const fetchHighestOffer = async (
22
+ args: UseHighestOfferArgs,
23
+ config: SdkConfig,
24
+ ) => {
25
+ const marketplaceClient = getMarketplaceClient(args.chainId, config);
26
+ return marketplaceClient.getCollectibleHighestOffer({
27
+ ...args,
28
+ contractAddress: args.collectionAddress,
29
+ });
30
+ };
31
+
32
+ export const highestOfferOptions = (
33
+ args: UseHighestOfferArgs,
34
+ config: SdkConfig,
35
+ ) => {
36
+ return queryOptions({
37
+ ...args.query,
38
+ queryKey: [...collectableKeys.highestOffers, args, config],
39
+ queryFn: () => fetchHighestOffer(args, config),
40
+ });
41
+ };
42
+
43
+ export const useHighestOffer = (args: UseHighestOfferArgs) => {
44
+ const config = useConfig();
45
+ return useQuery(highestOfferOptions(args, config));
46
+ };
@@ -0,0 +1,56 @@
1
+ import type { MetadataOptions, Page } from '@0xsequence/indexer';
2
+ import {
3
+ type ChainId,
4
+ type QueryArg,
5
+ balanceQueries,
6
+ getIndexerClient,
7
+ } from '@internal';
8
+ import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
9
+ import type { SdkConfig } from '@types';
10
+ import { useConfig } from './useConfig';
11
+
12
+ export type UseTokenBalancesArgs = {
13
+ chainId: ChainId;
14
+ accountAddress?: string;
15
+ contractAddress?: string;
16
+ tokenId?: string;
17
+ includeMetadata?: boolean;
18
+ metadataOptions?: MetadataOptions;
19
+ includeCollectionTokens?: boolean;
20
+ page?: Page;
21
+ } & QueryArg;
22
+
23
+ export type UseFetchTokenBalancesReturn = ReturnType<typeof fetchTokenBalances>;
24
+
25
+ const fetchTokenBalances = async (
26
+ args: UseTokenBalancesArgs,
27
+ page: Page,
28
+ config: SdkConfig,
29
+ ) => {
30
+ const indexerClient = getIndexerClient(args.chainId, config);
31
+
32
+ return indexerClient.getTokenBalances({
33
+ ...args,
34
+ tokenID: args.tokenId,
35
+ page: page,
36
+ });
37
+ };
38
+
39
+ export const tokenBalancesOptions = (
40
+ args: UseTokenBalancesArgs,
41
+ config: SdkConfig,
42
+ ) => {
43
+ return infiniteQueryOptions({
44
+ ...args.query,
45
+ queryKey: [...balanceQueries.lists, args, config],
46
+ queryFn: ({ pageParam }: { pageParam: Page }) =>
47
+ fetchTokenBalances(args, pageParam, config),
48
+ initialPageParam: { page: 1, pageSize: 30 } as Page,
49
+ getNextPageParam: (lastPage) => lastPage.page.after,
50
+ });
51
+ };
52
+
53
+ export const useTokenBalances = (args: UseTokenBalancesArgs) => {
54
+ const config = useConfig();
55
+ return useInfiniteQuery(tokenBalancesOptions(args, config));
56
+ };
@@ -0,0 +1,54 @@
1
+ import {
2
+ type ChainId,
3
+ type ListCollectiblesArgs,
4
+ type Page,
5
+ collectableKeys,
6
+ getMarketplaceClient,
7
+ } from '@internal';
8
+ import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
9
+ import type { SdkConfig } from '@types';
10
+ import { useConfig } from './useConfig';
11
+
12
+ export type UseListCollectiblesArgs = Omit<
13
+ ListCollectiblesArgs,
14
+ 'contractAddress'
15
+ > & {
16
+ collectionAddress: string;
17
+ chainId: ChainId;
18
+ };
19
+
20
+ export type UseListCollectiblesReturn = ReturnType<typeof fetchCollectibles>;
21
+
22
+ const fetchCollectibles = async (
23
+ args: UseListCollectiblesArgs,
24
+ page: Page,
25
+ marketplaceClient: ReturnType<typeof getMarketplaceClient>,
26
+ ) => {
27
+ const arg = {
28
+ ...args,
29
+ contractAddress: args.collectionAddress,
30
+ page,
31
+ } satisfies ListCollectiblesArgs;
32
+
33
+ return marketplaceClient.listCollectibles(arg);
34
+ };
35
+
36
+ export const listCollectiblesOptions = (
37
+ args: UseListCollectiblesArgs,
38
+ config: SdkConfig,
39
+ ) => {
40
+ const marketplaceClient = getMarketplaceClient(args.chainId, config);
41
+ return infiniteQueryOptions({
42
+ queryKey: [...collectableKeys.lists, args, marketplaceClient],
43
+ queryFn: ({ pageParam }) =>
44
+ fetchCollectibles(args, pageParam, marketplaceClient),
45
+ initialPageParam: { page: 1, pageSize: 30 },
46
+ getNextPageParam: (lastPage) =>
47
+ lastPage.page?.more ? lastPage.page : undefined,
48
+ });
49
+ };
50
+
51
+ export const useListCollectibles = (args: UseListCollectiblesArgs) => {
52
+ const config = useConfig();
53
+ return useInfiniteQuery(listCollectiblesOptions(args, config));
54
+ };
@@ -0,0 +1,53 @@
1
+ import {
2
+ type ListOffersForCollectibleArgs,
3
+ collectableKeys,
4
+ getMarketplaceClient,
5
+ } from '@internal';
6
+ import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
7
+ import type { Page, SdkConfig } from '@types';
8
+ import { useConfig } from './useConfig';
9
+
10
+ export type UseListOffersForCollectibleArgs = ListOffersForCollectibleArgs & {
11
+ chainId: string;
12
+ };
13
+
14
+ export type UseListOffersForCollectible = ReturnType<
15
+ typeof fetchListOffersForCollectible
16
+ >;
17
+
18
+ const fetchListOffersForCollectible = async (
19
+ config: SdkConfig,
20
+ args: UseListOffersForCollectibleArgs,
21
+ page: Page,
22
+ ) => {
23
+ const arg = {
24
+ contractAddress: args.contractAddress,
25
+ tokenId: args.tokenId,
26
+ filter: args.filter,
27
+ page,
28
+ } satisfies ListOffersForCollectibleArgs;
29
+
30
+ const marketplaceClient = getMarketplaceClient(args.chainId, config);
31
+ return marketplaceClient.listCollectibleOffers(arg);
32
+ };
33
+
34
+ export const listOffersForCollectibleOptions = (
35
+ args: UseListOffersForCollectibleArgs,
36
+ config: SdkConfig,
37
+ ) => {
38
+ return infiniteQueryOptions({
39
+ queryKey: [...collectableKeys.offers, args, config],
40
+ queryFn: ({ pageParam }) =>
41
+ fetchListOffersForCollectible(config, args, pageParam),
42
+ initialPageParam: { page: 1, pageSize: 30 },
43
+ getNextPageParam: (lastPage) =>
44
+ lastPage.page?.more ? lastPage.page : undefined,
45
+ });
46
+ };
47
+
48
+ export const useListOffersForCollectible = (
49
+ args: UseListOffersForCollectibleArgs,
50
+ ) => {
51
+ const config = useConfig();
52
+ return useInfiniteQuery(listOffersForCollectibleOptions(args, config));
53
+ };
@@ -0,0 +1,47 @@
1
+ import {
2
+ type ChainId,
3
+ type GetCollectibleLowestListingArgs,
4
+ type QueryArg,
5
+ collectableKeys,
6
+ getMarketplaceClient,
7
+ } from '@internal';
8
+ import { queryOptions, useQuery } from '@tanstack/react-query';
9
+ import type { SdkConfig } from '@types';
10
+ import { useConfig } from './useConfig';
11
+
12
+ export type UseLowestListingArgs = Omit<
13
+ GetCollectibleLowestListingArgs,
14
+ 'contractAddress'
15
+ > & {
16
+ collectionAddress: string;
17
+ chainId: ChainId;
18
+ } & QueryArg;
19
+
20
+ export type UseLowestListingReturn = ReturnType<typeof fetchLowestListing>;
21
+
22
+ const fetchLowestListing = async (
23
+ args: UseLowestListingArgs,
24
+ config: SdkConfig,
25
+ ) => {
26
+ const marketplaceClient = getMarketplaceClient(args.chainId, config);
27
+ return marketplaceClient.getCollectibleLowestListing({
28
+ ...args,
29
+ contractAddress: args.collectionAddress,
30
+ });
31
+ };
32
+
33
+ export const lowestListingOptions = (
34
+ args: UseLowestListingArgs,
35
+ config: SdkConfig,
36
+ ) => {
37
+ return queryOptions({
38
+ ...args.query,
39
+ queryKey: [...collectableKeys.lowestListings, args, config],
40
+ queryFn: () => fetchLowestListing(args, config),
41
+ });
42
+ };
43
+
44
+ export const useLowestListing = (args: UseLowestListingArgs) => {
45
+ const config = useConfig();
46
+ return useQuery(lowestListingOptions(args, config));
47
+ };
@@ -0,0 +1,10 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { marketplaceConfigOptions } from './options/marketplaceConfigOptions';
3
+ import { useConfig } from './useConfig';
4
+
5
+ export * from './options/marketplaceConfigOptions';
6
+
7
+ export const useMarketplaceConfig = () => {
8
+ const config = useConfig();
9
+ return useQuery(marketplaceConfigOptions(config));
10
+ };