@0xsequence/marketplace-sdk 2.0.0 → 2.0.2

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 (136) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/BellIcon.js +1 -1
  3. package/dist/Card.js +1 -1
  4. package/dist/ShopCard.d.ts +4 -4
  5. package/dist/builder-api.js +1 -1
  6. package/dist/collectible.js +2 -2
  7. package/dist/collectible.js.map +1 -1
  8. package/dist/collection.js +1 -1
  9. package/dist/create-config.d.ts +589 -193
  10. package/dist/create-config.js +1 -1
  11. package/dist/currency.js +3 -3
  12. package/dist/currency.js.map +1 -1
  13. package/dist/dist.js +167 -148
  14. package/dist/dist.js.map +1 -1
  15. package/dist/expirationDateSelect.js +1 -1
  16. package/dist/filter-state.d.ts +1 -1
  17. package/dist/filters.d.ts +1 -1
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.js +3 -3
  20. package/dist/index10.d.ts +1 -1
  21. package/dist/index11.d.ts +17 -17
  22. package/dist/index12.d.ts +21 -21
  23. package/dist/index14.d.ts +3 -3
  24. package/dist/index15.d.ts +3 -3
  25. package/dist/index16.d.ts +2 -2
  26. package/dist/index17.d.ts +75 -75
  27. package/dist/index18.d.ts +40 -40
  28. package/dist/index19.d.ts +5 -5
  29. package/dist/index2.d.ts +4 -1
  30. package/dist/index21.d.ts +15 -15
  31. package/dist/index22.d.ts +8 -65
  32. package/dist/index23.d.ts +21 -13
  33. package/dist/index26.d.ts +4 -4
  34. package/dist/index27.d.ts +4 -4
  35. package/dist/index28.d.ts +10 -10
  36. package/dist/index3.d.ts +2 -2194
  37. package/dist/index31.d.ts +5 -5
  38. package/dist/index33.d.ts +3 -3
  39. package/dist/index34.d.ts +1 -1
  40. package/dist/index35.d.ts +1 -1
  41. package/dist/index36.d.ts +5 -5
  42. package/dist/index37.d.ts +8 -6
  43. package/dist/index38.d.ts +5 -5
  44. package/dist/index39.d.ts +1 -1
  45. package/dist/index4.d.ts +1356 -1356
  46. package/dist/index40.d.ts +2 -2
  47. package/dist/index8.d.ts +11 -3
  48. package/dist/index9.d.ts +2811 -3
  49. package/dist/inventory.d.ts +4 -4
  50. package/dist/inventory.js +3 -3
  51. package/dist/inventory.js.map +1 -1
  52. package/dist/marketplace2.js +3 -3
  53. package/dist/marketplace2.js.map +1 -1
  54. package/dist/metadata.d.ts +41 -41
  55. package/dist/primary-sale-checkout-options.d.ts +4 -4
  56. package/dist/quantityInput.js +1 -1
  57. package/dist/ranges.d.ts +12 -12
  58. package/dist/react/_internal/index.d.ts +1 -1
  59. package/dist/react/_internal/index.js +1 -1
  60. package/dist/react/index.d.ts +1 -1
  61. package/dist/react/queries/collectible/index.d.ts +1 -1
  62. package/dist/react/queries/index.d.ts +1 -1
  63. package/dist/react/ssr/index.d.ts +3 -3
  64. package/dist/react/ssr/index.js +3 -3
  65. package/dist/react/ui/components/marketplace-collectible-card/index.d.ts +1 -1
  66. package/dist/react/ui/modals/CreateListingModal/internal/hooks/index.d.ts +1 -1
  67. package/dist/react/ui/modals/MakeOfferModal/internal/hooks/index.d.ts +1 -1
  68. package/dist/react/ui/modals/_internal/components/alertMessage/index.d.ts +2 -2
  69. package/dist/react/ui/modals/_internal/components/baseModal/index.d.ts +6 -6
  70. package/dist/react/ui/modals/_internal/components/calendar/index.d.ts +2 -2
  71. package/dist/react/ui/modals/_internal/components/currencyImage/index.d.ts +2 -2
  72. package/dist/react/ui/modals/_internal/components/currencyOptionsSelect/index.d.ts +3 -3
  73. package/dist/react/ui/modals/_internal/components/floorPriceText/index.d.ts +2 -2
  74. package/dist/react/ui/modals/_internal/components/priceInput/index.d.ts +3 -5
  75. package/dist/react/ui/modals/_internal/components/quantityInput/index.d.ts +2 -2
  76. package/dist/react/ui/modals/_internal/components/selectWaasFeeOptions/index.d.ts +2 -2
  77. package/dist/react/ui/modals/_internal/components/switchChainErrorModal/index.d.ts +2 -2
  78. package/dist/react/ui/modals/_internal/components/timeAgo/index.d.ts +2 -2
  79. package/dist/react/ui/modals/_internal/components/tokenPreview/index.d.ts +3 -3
  80. package/dist/react/ui/modals/_internal/components/transaction-footer/index.d.ts +3 -3
  81. package/dist/react/ui/modals/_internal/components/transactionDetails/index.d.ts +3 -3
  82. package/dist/react/ui/modals/_internal/components/transactionPreview/index.d.ts +3 -3
  83. package/dist/react/ui/modals/_internal/components/transactionStatusModal/index.d.ts +3 -3
  84. package/dist/react.js +2279 -1919
  85. package/dist/react.js.map +1 -1
  86. package/dist/styles/index.css +15 -0
  87. package/dist/token-balances.d.ts +28 -28
  88. package/dist/transaction-footer.js +1 -1
  89. package/dist/types/index.d.ts +1 -1
  90. package/dist/types/index.js +1 -1
  91. package/dist/types.d.ts +1 -1
  92. package/dist/url-state.js +1 -1
  93. package/dist/utils/index.d.ts +2 -2
  94. package/dist/utils/index.js +2 -2
  95. package/dist/utils.js +31 -4
  96. package/dist/utils.js.map +1 -1
  97. package/package.json +7 -5
  98. package/src/react/hooks/config/useMarketplaceConfig.test.tsx +1 -0
  99. package/src/react/hooks/currency/list.test.tsx +23 -2
  100. package/src/react/hooks/transactions/useCancelTransactionSteps.tsx +4 -1
  101. package/src/react/hooks/transactions/useMarketTransactionSteps.tsx +55 -15
  102. package/src/react/hooks/utils/useEnsureCorrectChain.ts +10 -5
  103. package/src/react/queries/collectible/market-list.ts +5 -3
  104. package/src/react/queries/currency/list.ts +8 -5
  105. package/src/react/queries/inventory/inventory.ts +5 -3
  106. package/src/react/queries/marketplace/filters.ts +5 -3
  107. package/src/react/ui/modals/BuyModal/components/BuyModalContent.tsx +74 -37
  108. package/src/react/ui/modals/BuyModal/components/CryptoPaymentModal.tsx +74 -11
  109. package/src/react/ui/modals/BuyModal/components/Modal.tsx +62 -1
  110. package/src/react/ui/modals/BuyModal/hooks/useExecuteBundledTransactions.ts +13 -26
  111. package/src/react/ui/modals/BuyModal/hooks/useMarketPlatformFee.ts +5 -5
  112. package/src/react/ui/modals/BuyModal/internal/__tests__/buildTrailsMarketBuyActions.test.ts +213 -0
  113. package/src/react/ui/modals/BuyModal/internal/buildTrailsMarketBuyActions.ts +259 -0
  114. package/src/react/ui/modals/BuyModal/internal/buyModalContext.ts +79 -10
  115. package/src/react/ui/modals/BuyModal/internal/cryptoPaymentModalContext.tsx +44 -17
  116. package/src/react/ui/modals/CreateListingModal/internal/store.ts +5 -2
  117. package/src/react/ui/modals/MakeOfferModal/internal/context.ts +21 -1
  118. package/src/react/ui/modals/MakeOfferModal/internal/helpers/validation.ts +16 -1
  119. package/src/react/ui/modals/MakeOfferModal/internal/store.ts +5 -2
  120. package/src/react/ui/modals/SellModal/internal/store.ts +5 -2
  121. package/src/react/ui/modals/_internal/components/baseModal/errors/ModalInitializationError.tsx +8 -6
  122. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +2 -1
  123. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +13 -19
  124. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +5 -2
  125. package/src/react/ui/modals/_internal/helpers/currency.test.ts +27 -0
  126. package/src/react/ui/modals/_internal/helpers/currency.ts +4 -2
  127. package/src/styles/styles.ts +18 -0
  128. package/src/utils/__tests__/getMarketplaceDetails.test.ts +10 -0
  129. package/src/utils/__tests__/getWebRPCErrorMessage.test.ts +28 -0
  130. package/src/utils/__tests__/marketplaceNormalization.test.ts +38 -0
  131. package/src/utils/collection.ts +19 -0
  132. package/src/utils/getConduitAddressForOrderbook.ts +2 -10
  133. package/src/utils/getMarketplaceDetails.ts +11 -4
  134. package/src/utils/getWebRPCErrorMessage.ts +21 -0
  135. package/src/utils/index.ts +1 -0
  136. package/src/utils/normalizeMarketplace.ts +31 -0
@@ -1,4 +1,4 @@
1
- import { T as MarketplaceWalletType } from "./dist.js";
1
+ import { D as MarketplaceWalletType } from "./dist.js";
2
2
  import { t as networkToWagmiChain } from "./networkconfigToWagmiChain.js";
3
3
  import { n as MissingConfigError } from "./transaction.js";
4
4
  import { allNetworks, findNetworkConfig } from "@0xsequence/network";
package/dist/currency.js CHANGED
@@ -1,4 +1,4 @@
1
- import { l as compareAddress } from "./utils.js";
1
+ import { d as findMarketCollection, p as compareAddress } from "./utils.js";
2
2
  import { g as getQueryClient, r as getMarketplaceClient } from "./api.js";
3
3
  import { r as buildQueryOptions } from "./_internal.js";
4
4
  import { n as marketplaceConfigOptions } from "./config.js";
@@ -16,8 +16,8 @@ async function fetchMarketCurrencies(params) {
16
16
  contractAddress: currency.contractAddress || zeroAddress
17
17
  })));
18
18
  if (collectionAddress) {
19
- const currenciesOptions = (await getQueryClient().fetchQuery(marketplaceConfigOptions(config))).market.collections.find((collection) => compareAddress(collection.itemsAddress, collectionAddress))?.currencyOptions;
20
- if (currenciesOptions) currencies = currencies.filter((currency) => currenciesOptions.includes(currency.contractAddress));
19
+ const currenciesOptions = findMarketCollection((await getQueryClient().fetchQuery(marketplaceConfigOptions(config))).market.collections, collectionAddress, chainId)?.currencyOptions;
20
+ if (currenciesOptions) currencies = currencies.filter((currency) => currenciesOptions.some((option) => compareAddress(option, currency.contractAddress)));
21
21
  }
22
22
  if (!includeNativeCurrencyOption) currencies = currencies.filter((currency) => !currency.nativeCurrency);
23
23
  return currencies;
@@ -1 +1 @@
1
- {"version":3,"file":"currency.js","names":["currency"],"sources":["../src/react/queries/currency/list.ts","../src/react/queries/currency/convert-to-usd.ts","../src/react/queries/currency/compare-prices.ts","../src/react/queries/currency/currency.ts"],"sourcesContent":["import type {\n\tAddress,\n\tCurrency,\n\tListCurrenciesRequest,\n} from '@0xsequence/api-client';\nimport { zeroAddress } from 'viem';\nimport { compareAddress } from '../../../utils';\nimport {\n\tbuildQueryOptions,\n\tgetMarketplaceClient,\n\tgetQueryClient,\n\ttype SdkQueryParams,\n\ttype WithOptionalParams,\n\ttype WithRequired,\n} from '../../_internal';\nimport { marketplaceConfigOptions } from '../marketplace/config';\n\nexport type FetchMarketCurrenciesParams = ListCurrenciesRequest & {\n\tincludeNativeCurrency?: boolean;\n\tcollectionAddress?: Address;\n};\n\nexport type MarketCurrenciesQueryOptions =\n\tSdkQueryParams<FetchMarketCurrenciesParams>;\n\n/**\n * Fetches supported currencies for a marketplace\n */\nexport async function fetchMarketCurrencies(\n\tparams: WithRequired<MarketCurrenciesQueryOptions, 'chainId' | 'config'>,\n): Promise<Currency[]> {\n\tconst { chainId, includeNativeCurrency, collectionAddress, config } = params;\n\tconst includeNativeCurrencyOption = includeNativeCurrency ?? true;\n\tconst marketplaceClient = getMarketplaceClient(config);\n\n\tlet currencies = await marketplaceClient\n\t\t.listCurrencies({\n\t\t\tchainId,\n\t\t})\n\t\t.then((resp) =>\n\t\t\tresp.currencies.map((currency) => ({\n\t\t\t\t...currency,\n\t\t\t\tcontractAddress: currency.contractAddress || zeroAddress,\n\t\t\t})),\n\t\t);\n\n\tif (collectionAddress) {\n\t\tconst queryClient = getQueryClient();\n\t\tconst marketplaceConfig = await queryClient.fetchQuery(\n\t\t\tmarketplaceConfigOptions(config),\n\t\t);\n\n\t\tconst currenciesOptions = marketplaceConfig.market.collections.find(\n\t\t\t(collection) =>\n\t\t\t\tcompareAddress(collection.itemsAddress, collectionAddress),\n\t\t)?.currencyOptions;\n\n\t\t// Filter currencies based on collection currency options\n\t\tif (currenciesOptions) {\n\t\t\tcurrencies = currencies.filter((currency) =>\n\t\t\t\tcurrenciesOptions.includes(currency.contractAddress),\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!includeNativeCurrencyOption) {\n\t\tcurrencies = currencies.filter((currency) => !currency.nativeCurrency);\n\t}\n\n\treturn currencies;\n}\n\nexport function getMarketCurrenciesQueryKey(\n\tparams: MarketCurrenciesQueryOptions,\n) {\n\treturn [\n\t\t'currency',\n\t\t'list',\n\t\t{\n\t\t\tchainId: params.chainId,\n\t\t\tincludeNativeCurrency: params.includeNativeCurrency,\n\t\t\tcollectionAddress: params.collectionAddress,\n\t\t},\n\t] as const;\n}\n\nexport function marketCurrenciesQueryOptions(\n\tparams: WithOptionalParams<\n\t\tWithRequired<MarketCurrenciesQueryOptions, 'chainId' | 'config'>\n\t>,\n) {\n\treturn buildQueryOptions(\n\t\t{\n\t\t\tgetQueryKey: getMarketCurrenciesQueryKey,\n\t\t\trequiredParams: ['chainId', 'config'] as const,\n\t\t\tfetcher: fetchMarketCurrencies,\n\t\t},\n\t\tparams,\n\t);\n}\n","import type { Address, ChainId } from '@0xsequence/api-client';\nimport { formatUnits } from 'viem';\nimport {\n\tbuildQueryOptions,\n\ttype Currency,\n\tgetQueryClient,\n\ttype SdkQueryParams,\n\ttype WithOptionalParams,\n\ttype WithRequired,\n} from '../../_internal';\nimport { marketCurrenciesQueryOptions } from './list';\n\nexport type FetchConvertPriceToUSDParams = {\n\tchainId: ChainId;\n\tcurrencyAddress: Address;\n\tamountRaw: string;\n};\n\nexport type ConvertPriceToUSDReturn = {\n\tusdAmount: number;\n\tusdAmountFormatted: string;\n};\n\nexport type ConvertPriceToUSDQueryOptions =\n\tSdkQueryParams<FetchConvertPriceToUSDParams>;\n\n/**\n * Converts a price amount from a specific currency to USD using exchange rates\n */\nexport async function fetchConvertPriceToUSD(\n\tparams: WithRequired<\n\t\tConvertPriceToUSDQueryOptions,\n\t\t'chainId' | 'currencyAddress' | 'amountRaw' | 'config'\n\t>,\n): Promise<ConvertPriceToUSDReturn> {\n\tconst { chainId, currencyAddress, amountRaw, config } = params;\n\n\tconst queryClient = getQueryClient();\n\tconst currencies = await queryClient.fetchQuery(\n\t\tmarketCurrenciesQueryOptions({\n\t\t\tchainId,\n\t\t\tconfig,\n\t\t}),\n\t);\n\n\tconst currencyDetails = currencies.find(\n\t\t(c: Currency) =>\n\t\t\tc.contractAddress.toLowerCase() === currencyAddress.toLowerCase(),\n\t);\n\n\tif (!currencyDetails) {\n\t\tthrow new Error('Currency not found');\n\t}\n\n\tconst amountDecimal = Number(\n\t\tformatUnits(BigInt(amountRaw), currencyDetails.decimals),\n\t);\n\tconst usdAmount = amountDecimal * currencyDetails.exchangeRate;\n\n\treturn {\n\t\tusdAmount,\n\t\tusdAmountFormatted: usdAmount.toFixed(2),\n\t};\n}\n\nexport function getConvertPriceToUSDQueryKey(\n\tparams: ConvertPriceToUSDQueryOptions,\n) {\n\tconst apiArgs = {\n\t\tchainId: params.chainId,\n\t\tcurrencyAddress: params.currencyAddress,\n\t\tamountRaw: params.amountRaw,\n\t};\n\n\treturn ['currency', 'convert-to-usd', apiArgs] as const;\n}\n\nexport function convertPriceToUSDQueryOptions(\n\tparams: WithOptionalParams<\n\t\tWithRequired<\n\t\t\tConvertPriceToUSDQueryOptions,\n\t\t\t'chainId' | 'currencyAddress' | 'amountRaw' | 'config'\n\t\t>\n\t>,\n) {\n\treturn buildQueryOptions(\n\t\t{\n\t\t\tgetQueryKey: getConvertPriceToUSDQueryKey,\n\t\t\trequiredParams: [\n\t\t\t\t'chainId',\n\t\t\t\t'currencyAddress',\n\t\t\t\t'amountRaw',\n\t\t\t\t'config',\n\t\t\t] as const,\n\t\t\tfetcher: fetchConvertPriceToUSD,\n\t\t},\n\t\tparams,\n\t);\n}\n","import type { Address, ChainId } from '@0xsequence/api-client';\nimport {\n\tbuildQueryOptions,\n\ttype SdkQueryParams,\n\ttype WithOptionalParams,\n\ttype WithRequired,\n} from '../../_internal';\nimport { fetchConvertPriceToUSD } from './convert-to-usd';\n\nexport type FetchComparePricesParams = {\n\tchainId?: ChainId;\n\tpriceAmountRaw?: string;\n\tpriceCurrencyAddress?: Address;\n\tcompareToPriceAmountRaw?: string;\n\tcompareToPriceCurrencyAddress?: Address;\n};\n\nexport type ComparePricesReturn = {\n\tpercentageDifference: number;\n\tpercentageDifferenceFormatted: string;\n\tstatus: 'above' | 'same' | 'below';\n};\n\nexport type ComparePricesQueryOptions =\n\tSdkQueryParams<FetchComparePricesParams>;\n\n/**\n * Compares prices between different currencies by converting both to USD\n */\nexport async function fetchComparePrices(\n\tparams: WithRequired<\n\t\tComparePricesQueryOptions,\n\t\t| 'chainId'\n\t\t| 'priceAmountRaw'\n\t\t| 'priceCurrencyAddress'\n\t\t| 'compareToPriceAmountRaw'\n\t\t| 'compareToPriceCurrencyAddress'\n\t\t| 'config'\n\t>,\n): Promise<ComparePricesReturn> {\n\tconst {\n\t\tchainId,\n\t\tpriceAmountRaw,\n\t\tpriceCurrencyAddress,\n\t\tcompareToPriceAmountRaw,\n\t\tcompareToPriceCurrencyAddress,\n\t\tconfig,\n\t} = params;\n\n\tconst [priceUSD, compareToPriceUSD] = await Promise.all([\n\t\tfetchConvertPriceToUSD({\n\t\t\tchainId,\n\t\t\tcurrencyAddress: priceCurrencyAddress,\n\t\t\tamountRaw: priceAmountRaw,\n\t\t\tconfig,\n\t\t}),\n\t\tfetchConvertPriceToUSD({\n\t\t\tchainId,\n\t\t\tcurrencyAddress: compareToPriceCurrencyAddress,\n\t\t\tamountRaw: compareToPriceAmountRaw,\n\t\t\tconfig,\n\t\t}),\n\t]);\n\n\tconst difference = priceUSD.usdAmount - compareToPriceUSD.usdAmount;\n\n\tif (compareToPriceUSD.usdAmount === 0) {\n\t\tthrow new Error('Cannot compare to zero price');\n\t}\n\n\tconst percentageDifference = (difference / compareToPriceUSD.usdAmount) * 100;\n\tconst isAbove = percentageDifference > 0;\n\tconst isSame = percentageDifference === 0;\n\n\treturn {\n\t\tpercentageDifference,\n\t\tpercentageDifferenceFormatted: Math.abs(percentageDifference).toFixed(2),\n\t\tstatus: isAbove ? 'above' : isSame ? 'same' : 'below',\n\t};\n}\n\nexport function getComparePricesQueryKey(params: ComparePricesQueryOptions) {\n\tconst apiArgs = {\n\t\tchainId: params.chainId,\n\t\tpriceAmountRaw: params.priceAmountRaw,\n\t\tpriceCurrencyAddress: params.priceCurrencyAddress,\n\t\tcompareToPriceAmountRaw: params.compareToPriceAmountRaw,\n\t\tcompareToPriceCurrencyAddress: params.compareToPriceCurrencyAddress,\n\t};\n\n\treturn ['currency', 'compare-prices', apiArgs] as const;\n}\n\nexport function comparePricesQueryOptions(\n\tparams: WithOptionalParams<\n\t\tWithRequired<\n\t\t\tComparePricesQueryOptions,\n\t\t\t| 'chainId'\n\t\t\t| 'priceAmountRaw'\n\t\t\t| 'priceCurrencyAddress'\n\t\t\t| 'compareToPriceAmountRaw'\n\t\t\t| 'compareToPriceCurrencyAddress'\n\t\t\t| 'config'\n\t\t>\n\t>,\n) {\n\treturn buildQueryOptions(\n\t\t{\n\t\t\tgetQueryKey: getComparePricesQueryKey,\n\t\t\trequiredParams: [\n\t\t\t\t'chainId',\n\t\t\t\t'priceAmountRaw',\n\t\t\t\t'priceCurrencyAddress',\n\t\t\t\t'compareToPriceAmountRaw',\n\t\t\t\t'compareToPriceCurrencyAddress',\n\t\t\t\t'config',\n\t\t\t] as const,\n\t\t\tfetcher: fetchComparePrices,\n\t\t},\n\t\tparams,\n\t);\n}\n","import type { Address, ListCurrenciesRequest } from '@0xsequence/api-client';\nimport { isAddress } from 'viem';\nimport {\n\tbuildQueryOptions,\n\ttype Currency,\n\tgetMarketplaceClient,\n\tgetQueryClient,\n\ttype SdkQueryParams,\n\ttype WithOptionalParams,\n\ttype WithRequired,\n} from '../../_internal';\n\nexport type FetchCurrencyParams = ListCurrenciesRequest & {\n\tcurrencyAddress: Address;\n};\n\n/**\n * Fetches currency details from the marketplace API\n */\nexport async function fetchCurrency(\n\tparams: WithRequired<\n\t\tCurrencyQueryOptions,\n\t\t'chainId' | 'currencyAddress' | 'config'\n\t>,\n): Promise<Currency | undefined> {\n\tconst { chainId, currencyAddress, config } = params;\n\tconst queryClient = getQueryClient();\n\n\tlet currencies = queryClient.getQueryData<Currency[]>([\n\t\t'currency',\n\t\t'list',\n\t\tchainId,\n\t]);\n\n\tif (!currencies) {\n\t\tconst marketplaceClient = getMarketplaceClient(config);\n\t\tconst response = await marketplaceClient.listCurrencies({ chainId });\n\t\tcurrencies = response.currencies;\n\t}\n\n\tif (!currencies?.length) {\n\t\tthrow new Error('No currencies returned');\n\t}\n\tconst currency = currencies.find(\n\t\t(currency) =>\n\t\t\tcurrency.contractAddress.toLowerCase() === currencyAddress.toLowerCase(),\n\t);\n\n\tif (!currency) {\n\t\tthrow new Error('Currency not found');\n\t}\n\n\treturn currency;\n}\n\nexport type CurrencyQueryOptions = SdkQueryParams<FetchCurrencyParams>;\n\nexport function getCurrencyQueryKey(params: CurrencyQueryOptions) {\n\tconst apiArgs = {\n\t\tchainId: String(params.chainId ?? 0),\n\t\tcurrencyAddress: params.currencyAddress ?? '',\n\t};\n\n\treturn ['currency', 'currency', apiArgs] as const;\n}\n\nexport function currencyQueryOptions(\n\tparams: WithOptionalParams<\n\t\tWithRequired<CurrencyQueryOptions, 'chainId' | 'currencyAddress' | 'config'>\n\t>,\n) {\n\treturn buildQueryOptions(\n\t\t{\n\t\t\tgetQueryKey: getCurrencyQueryKey,\n\t\t\trequiredParams: ['chainId', 'currencyAddress', 'config'] as const,\n\t\t\tfetcher: fetchCurrency,\n\t\t\tcustomValidation: (p) =>\n\t\t\t\t!!p.currencyAddress && isAddress(p.currencyAddress),\n\t\t},\n\t\tparams,\n\t);\n}\n"],"mappings":";;;;;;;;;;AA4BA,eAAsB,sBACrB,QACsB;CACtB,MAAM,EAAE,SAAS,uBAAuB,mBAAmB,WAAW;CACtE,MAAM,8BAA8B,yBAAyB;CAG7D,IAAI,aAAa,MAFS,qBAAqB,OAAO,CAGpD,eAAe,EACf,SACA,CAAC,CACD,MAAM,SACN,KAAK,WAAW,KAAK,cAAc;EAClC,GAAG;EACH,iBAAiB,SAAS,mBAAmB;EAC7C,EAAE,CACH;AAEF,KAAI,mBAAmB;EAMtB,MAAM,qBAJoB,MADN,gBAAgB,CACQ,WAC3C,yBAAyB,OAAO,CAChC,EAE2C,OAAO,YAAY,MAC7D,eACA,eAAe,WAAW,cAAc,kBAAkB,CAC3D,EAAE;AAGH,MAAI,kBACH,cAAa,WAAW,QAAQ,aAC/B,kBAAkB,SAAS,SAAS,gBAAgB,CACpD;;AAIH,KAAI,CAAC,4BACJ,cAAa,WAAW,QAAQ,aAAa,CAAC,SAAS,eAAe;AAGvE,QAAO;;AAGR,SAAg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B,CAAC,CAAC,EAAE,mBAAmB,UAAU,EAAE,gBAAgB;EACpD,EACD,OACA"}
1
+ {"version":3,"file":"currency.js","names":["currency"],"sources":["../src/react/queries/currency/list.ts","../src/react/queries/currency/convert-to-usd.ts","../src/react/queries/currency/compare-prices.ts","../src/react/queries/currency/currency.ts"],"sourcesContent":["import type {\n\tAddress,\n\tCurrency,\n\tListCurrenciesRequest,\n} from '@0xsequence/api-client';\nimport { zeroAddress } from 'viem';\nimport { compareAddress, findMarketCollection } from '../../../utils';\nimport {\n\tbuildQueryOptions,\n\tgetMarketplaceClient,\n\tgetQueryClient,\n\ttype SdkQueryParams,\n\ttype WithOptionalParams,\n\ttype WithRequired,\n} from '../../_internal';\nimport { marketplaceConfigOptions } from '../marketplace/config';\n\nexport type FetchMarketCurrenciesParams = ListCurrenciesRequest & {\n\tincludeNativeCurrency?: boolean;\n\tcollectionAddress?: Address;\n};\n\nexport type MarketCurrenciesQueryOptions =\n\tSdkQueryParams<FetchMarketCurrenciesParams>;\n\n/**\n * Fetches supported currencies for a marketplace\n */\nexport async function fetchMarketCurrencies(\n\tparams: WithRequired<MarketCurrenciesQueryOptions, 'chainId' | 'config'>,\n): Promise<Currency[]> {\n\tconst { chainId, includeNativeCurrency, collectionAddress, config } = params;\n\tconst includeNativeCurrencyOption = includeNativeCurrency ?? true;\n\tconst marketplaceClient = getMarketplaceClient(config);\n\n\tlet currencies = await marketplaceClient\n\t\t.listCurrencies({\n\t\t\tchainId,\n\t\t})\n\t\t.then((resp) =>\n\t\t\tresp.currencies.map((currency) => ({\n\t\t\t\t...currency,\n\t\t\t\tcontractAddress: currency.contractAddress || zeroAddress,\n\t\t\t})),\n\t\t);\n\n\tif (collectionAddress) {\n\t\tconst queryClient = getQueryClient();\n\t\tconst marketplaceConfig = await queryClient.fetchQuery(\n\t\t\tmarketplaceConfigOptions(config),\n\t\t);\n\n\t\tconst currenciesOptions = findMarketCollection(\n\t\t\tmarketplaceConfig.market.collections,\n\t\t\tcollectionAddress,\n\t\t\tchainId,\n\t\t)?.currencyOptions;\n\n\t\t// Filter currencies based on collection currency options\n\t\tif (currenciesOptions) {\n\t\t\tcurrencies = currencies.filter((currency) =>\n\t\t\t\tcurrenciesOptions.some((option) =>\n\t\t\t\t\tcompareAddress(option, currency.contractAddress),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!includeNativeCurrencyOption) {\n\t\tcurrencies = currencies.filter((currency) => !currency.nativeCurrency);\n\t}\n\n\treturn currencies;\n}\n\nexport function getMarketCurrenciesQueryKey(\n\tparams: MarketCurrenciesQueryOptions,\n) {\n\treturn [\n\t\t'currency',\n\t\t'list',\n\t\t{\n\t\t\tchainId: params.chainId,\n\t\t\tincludeNativeCurrency: params.includeNativeCurrency,\n\t\t\tcollectionAddress: params.collectionAddress,\n\t\t},\n\t] as const;\n}\n\nexport function marketCurrenciesQueryOptions(\n\tparams: WithOptionalParams<\n\t\tWithRequired<MarketCurrenciesQueryOptions, 'chainId' | 'config'>\n\t>,\n) {\n\treturn buildQueryOptions(\n\t\t{\n\t\t\tgetQueryKey: getMarketCurrenciesQueryKey,\n\t\t\trequiredParams: ['chainId', 'config'] as const,\n\t\t\tfetcher: fetchMarketCurrencies,\n\t\t},\n\t\tparams,\n\t);\n}\n","import type { Address, ChainId } from '@0xsequence/api-client';\nimport { formatUnits } from 'viem';\nimport {\n\tbuildQueryOptions,\n\ttype Currency,\n\tgetQueryClient,\n\ttype SdkQueryParams,\n\ttype WithOptionalParams,\n\ttype WithRequired,\n} from '../../_internal';\nimport { marketCurrenciesQueryOptions } from './list';\n\nexport type FetchConvertPriceToUSDParams = {\n\tchainId: ChainId;\n\tcurrencyAddress: Address;\n\tamountRaw: string;\n};\n\nexport type ConvertPriceToUSDReturn = {\n\tusdAmount: number;\n\tusdAmountFormatted: string;\n};\n\nexport type ConvertPriceToUSDQueryOptions =\n\tSdkQueryParams<FetchConvertPriceToUSDParams>;\n\n/**\n * Converts a price amount from a specific currency to USD using exchange rates\n */\nexport async function fetchConvertPriceToUSD(\n\tparams: WithRequired<\n\t\tConvertPriceToUSDQueryOptions,\n\t\t'chainId' | 'currencyAddress' | 'amountRaw' | 'config'\n\t>,\n): Promise<ConvertPriceToUSDReturn> {\n\tconst { chainId, currencyAddress, amountRaw, config } = params;\n\n\tconst queryClient = getQueryClient();\n\tconst currencies = await queryClient.fetchQuery(\n\t\tmarketCurrenciesQueryOptions({\n\t\t\tchainId,\n\t\t\tconfig,\n\t\t}),\n\t);\n\n\tconst currencyDetails = currencies.find(\n\t\t(c: Currency) =>\n\t\t\tc.contractAddress.toLowerCase() === currencyAddress.toLowerCase(),\n\t);\n\n\tif (!currencyDetails) {\n\t\tthrow new Error('Currency not found');\n\t}\n\n\tconst amountDecimal = Number(\n\t\tformatUnits(BigInt(amountRaw), currencyDetails.decimals),\n\t);\n\tconst usdAmount = amountDecimal * currencyDetails.exchangeRate;\n\n\treturn {\n\t\tusdAmount,\n\t\tusdAmountFormatted: usdAmount.toFixed(2),\n\t};\n}\n\nexport function getConvertPriceToUSDQueryKey(\n\tparams: ConvertPriceToUSDQueryOptions,\n) {\n\tconst apiArgs = {\n\t\tchainId: params.chainId,\n\t\tcurrencyAddress: params.currencyAddress,\n\t\tamountRaw: params.amountRaw,\n\t};\n\n\treturn ['currency', 'convert-to-usd', apiArgs] as const;\n}\n\nexport function convertPriceToUSDQueryOptions(\n\tparams: WithOptionalParams<\n\t\tWithRequired<\n\t\t\tConvertPriceToUSDQueryOptions,\n\t\t\t'chainId' | 'currencyAddress' | 'amountRaw' | 'config'\n\t\t>\n\t>,\n) {\n\treturn buildQueryOptions(\n\t\t{\n\t\t\tgetQueryKey: getConvertPriceToUSDQueryKey,\n\t\t\trequiredParams: [\n\t\t\t\t'chainId',\n\t\t\t\t'currencyAddress',\n\t\t\t\t'amountRaw',\n\t\t\t\t'config',\n\t\t\t] as const,\n\t\t\tfetcher: fetchConvertPriceToUSD,\n\t\t},\n\t\tparams,\n\t);\n}\n","import type { Address, ChainId } from '@0xsequence/api-client';\nimport {\n\tbuildQueryOptions,\n\ttype SdkQueryParams,\n\ttype WithOptionalParams,\n\ttype WithRequired,\n} from '../../_internal';\nimport { fetchConvertPriceToUSD } from './convert-to-usd';\n\nexport type FetchComparePricesParams = {\n\tchainId?: ChainId;\n\tpriceAmountRaw?: string;\n\tpriceCurrencyAddress?: Address;\n\tcompareToPriceAmountRaw?: string;\n\tcompareToPriceCurrencyAddress?: Address;\n};\n\nexport type ComparePricesReturn = {\n\tpercentageDifference: number;\n\tpercentageDifferenceFormatted: string;\n\tstatus: 'above' | 'same' | 'below';\n};\n\nexport type ComparePricesQueryOptions =\n\tSdkQueryParams<FetchComparePricesParams>;\n\n/**\n * Compares prices between different currencies by converting both to USD\n */\nexport async function fetchComparePrices(\n\tparams: WithRequired<\n\t\tComparePricesQueryOptions,\n\t\t| 'chainId'\n\t\t| 'priceAmountRaw'\n\t\t| 'priceCurrencyAddress'\n\t\t| 'compareToPriceAmountRaw'\n\t\t| 'compareToPriceCurrencyAddress'\n\t\t| 'config'\n\t>,\n): Promise<ComparePricesReturn> {\n\tconst {\n\t\tchainId,\n\t\tpriceAmountRaw,\n\t\tpriceCurrencyAddress,\n\t\tcompareToPriceAmountRaw,\n\t\tcompareToPriceCurrencyAddress,\n\t\tconfig,\n\t} = params;\n\n\tconst [priceUSD, compareToPriceUSD] = await Promise.all([\n\t\tfetchConvertPriceToUSD({\n\t\t\tchainId,\n\t\t\tcurrencyAddress: priceCurrencyAddress,\n\t\t\tamountRaw: priceAmountRaw,\n\t\t\tconfig,\n\t\t}),\n\t\tfetchConvertPriceToUSD({\n\t\t\tchainId,\n\t\t\tcurrencyAddress: compareToPriceCurrencyAddress,\n\t\t\tamountRaw: compareToPriceAmountRaw,\n\t\t\tconfig,\n\t\t}),\n\t]);\n\n\tconst difference = priceUSD.usdAmount - compareToPriceUSD.usdAmount;\n\n\tif (compareToPriceUSD.usdAmount === 0) {\n\t\tthrow new Error('Cannot compare to zero price');\n\t}\n\n\tconst percentageDifference = (difference / compareToPriceUSD.usdAmount) * 100;\n\tconst isAbove = percentageDifference > 0;\n\tconst isSame = percentageDifference === 0;\n\n\treturn {\n\t\tpercentageDifference,\n\t\tpercentageDifferenceFormatted: Math.abs(percentageDifference).toFixed(2),\n\t\tstatus: isAbove ? 'above' : isSame ? 'same' : 'below',\n\t};\n}\n\nexport function getComparePricesQueryKey(params: ComparePricesQueryOptions) {\n\tconst apiArgs = {\n\t\tchainId: params.chainId,\n\t\tpriceAmountRaw: params.priceAmountRaw,\n\t\tpriceCurrencyAddress: params.priceCurrencyAddress,\n\t\tcompareToPriceAmountRaw: params.compareToPriceAmountRaw,\n\t\tcompareToPriceCurrencyAddress: params.compareToPriceCurrencyAddress,\n\t};\n\n\treturn ['currency', 'compare-prices', apiArgs] as const;\n}\n\nexport function comparePricesQueryOptions(\n\tparams: WithOptionalParams<\n\t\tWithRequired<\n\t\t\tComparePricesQueryOptions,\n\t\t\t| 'chainId'\n\t\t\t| 'priceAmountRaw'\n\t\t\t| 'priceCurrencyAddress'\n\t\t\t| 'compareToPriceAmountRaw'\n\t\t\t| 'compareToPriceCurrencyAddress'\n\t\t\t| 'config'\n\t\t>\n\t>,\n) {\n\treturn buildQueryOptions(\n\t\t{\n\t\t\tgetQueryKey: getComparePricesQueryKey,\n\t\t\trequiredParams: [\n\t\t\t\t'chainId',\n\t\t\t\t'priceAmountRaw',\n\t\t\t\t'priceCurrencyAddress',\n\t\t\t\t'compareToPriceAmountRaw',\n\t\t\t\t'compareToPriceCurrencyAddress',\n\t\t\t\t'config',\n\t\t\t] as const,\n\t\t\tfetcher: fetchComparePrices,\n\t\t},\n\t\tparams,\n\t);\n}\n","import type { Address, ListCurrenciesRequest } from '@0xsequence/api-client';\nimport { isAddress } from 'viem';\nimport {\n\tbuildQueryOptions,\n\ttype Currency,\n\tgetMarketplaceClient,\n\tgetQueryClient,\n\ttype SdkQueryParams,\n\ttype WithOptionalParams,\n\ttype WithRequired,\n} from '../../_internal';\n\nexport type FetchCurrencyParams = ListCurrenciesRequest & {\n\tcurrencyAddress: Address;\n};\n\n/**\n * Fetches currency details from the marketplace API\n */\nexport async function fetchCurrency(\n\tparams: WithRequired<\n\t\tCurrencyQueryOptions,\n\t\t'chainId' | 'currencyAddress' | 'config'\n\t>,\n): Promise<Currency | undefined> {\n\tconst { chainId, currencyAddress, config } = params;\n\tconst queryClient = getQueryClient();\n\n\tlet currencies = queryClient.getQueryData<Currency[]>([\n\t\t'currency',\n\t\t'list',\n\t\tchainId,\n\t]);\n\n\tif (!currencies) {\n\t\tconst marketplaceClient = getMarketplaceClient(config);\n\t\tconst response = await marketplaceClient.listCurrencies({ chainId });\n\t\tcurrencies = response.currencies;\n\t}\n\n\tif (!currencies?.length) {\n\t\tthrow new Error('No currencies returned');\n\t}\n\tconst currency = currencies.find(\n\t\t(currency) =>\n\t\t\tcurrency.contractAddress.toLowerCase() === currencyAddress.toLowerCase(),\n\t);\n\n\tif (!currency) {\n\t\tthrow new Error('Currency not found');\n\t}\n\n\treturn currency;\n}\n\nexport type CurrencyQueryOptions = SdkQueryParams<FetchCurrencyParams>;\n\nexport function getCurrencyQueryKey(params: CurrencyQueryOptions) {\n\tconst apiArgs = {\n\t\tchainId: String(params.chainId ?? 0),\n\t\tcurrencyAddress: params.currencyAddress ?? '',\n\t};\n\n\treturn ['currency', 'currency', apiArgs] as const;\n}\n\nexport function currencyQueryOptions(\n\tparams: WithOptionalParams<\n\t\tWithRequired<CurrencyQueryOptions, 'chainId' | 'currencyAddress' | 'config'>\n\t>,\n) {\n\treturn buildQueryOptions(\n\t\t{\n\t\t\tgetQueryKey: getCurrencyQueryKey,\n\t\t\trequiredParams: ['chainId', 'currencyAddress', 'config'] as const,\n\t\t\tfetcher: fetchCurrency,\n\t\t\tcustomValidation: (p) =>\n\t\t\t\t!!p.currencyAddress && isAddress(p.currencyAddress),\n\t\t},\n\t\tparams,\n\t);\n}\n"],"mappings":";;;;;;;;;;AA4BA,eAAsB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AAyB;EACrD;EACA;EACA;EACA,CAAC;AAEF,KAAI,CAAC,WAGJ,eADiB,MADS,qBAAqB,OAAO,CACb,eAAe,EAAE,SAAS,CAAC,EAC9C;AAGvB,KAAI,CAAC,YAAY,OAChB,OAAM,IAAI,MAAM,yBAAyB;CAE1C,MAAM,WAAW,WAAW,MAC1B,eACAA,WAAS,gBAAgB,aAAa,KAAK,gBAAgB,aAAa,CACzE;AAED,KAAI,CAAC,SACJ,OAAM,IAAI,MAAM,qBAAqB;AAGtC,QAAO;;AAKR,SAAgB,oBAAoB,QAA8B;AAMjE,QAAO;EAAC;EAAY;EALJ;GACf,SAAS,OAAO,OAAO,WAAW,EAAE;GACpC,iBAAiB,OAAO,mBAAmB;GAC3C;EAEuC;;AAGzC,SAAgB,qBACf,QAGC;AACD,QAAO,kBACN;EACC,aAAa;EACb,gBAAgB;GAAC;GAAW;GAAmB;GAAS;EACxD,SAAS;EACT,mBAAmB,MAClB,CAAC,CAAC,EAAE,mBAAmB,UAAU,EAAE,gBAAgB;EACpD,EACD,OACA"}
package/dist/dist.js CHANGED
@@ -459,152 +459,6 @@ function spreadWith(obj, overrides) {
459
459
  };
460
460
  }
461
461
 
462
- //#endregion
463
- //#region ../api/dist/transforms.js
464
- function toContractInfo(raw) {
465
- if (!raw.address || !raw.address.startsWith("0x") || raw.address.length !== 42) return;
466
- return spreadWith(raw, {
467
- chainId: normalizeChainId(raw.chainId),
468
- address: normalizeAddress(raw.address),
469
- extensions: transformOptional(raw.extensions, (ext) => {
470
- const result = { ...ext };
471
- if (ext.originChainId !== void 0) result.originChainId = normalizeChainId(ext.originChainId);
472
- if (ext.originAddress?.startsWith("0x") && ext.originAddress.length === 42) result.originAddress = normalizeAddress(ext.originAddress);
473
- return result;
474
- })
475
- });
476
- }
477
- function toTokenMetadata(raw) {
478
- return spreadWith(raw, {
479
- tokenId: normalizeTokenId(raw.tokenId),
480
- attributes: raw.attributes
481
- });
482
- }
483
- function toNativeTokenBalance(raw) {
484
- const result = {
485
- accountAddress: normalizeAddress(raw.accountAddress),
486
- chainId: normalizeChainId(raw.chainId),
487
- balance: BigInt(raw.balance)
488
- };
489
- if (raw.errorReason) result.errorReason = raw.errorReason;
490
- return result;
491
- }
492
- function toTokenBalance(raw) {
493
- const { tokenID, contractType, ...rest } = raw;
494
- return spreadWith(rest, {
495
- contractType,
496
- contractAddress: normalizeAddress(raw.contractAddress),
497
- accountAddress: normalizeAddress(raw.accountAddress),
498
- tokenId: raw.tokenID ? normalizeTokenId(raw.tokenID) : 0n,
499
- balance: BigInt(raw.balance),
500
- chainId: normalizeChainId(raw.chainId),
501
- contractInfo: transformOptional(raw.contractInfo, toContractInfo),
502
- tokenMetadata: transformOptional(raw.tokenMetadata, toTokenMetadata),
503
- uniqueCollectibles: transformOptional(raw.uniqueCollectibles, BigInt)
504
- });
505
- }
506
- function toTokenSupply(raw, contractAddress) {
507
- return {
508
- tokenId: normalizeTokenId(raw.tokenID),
509
- supply: BigInt(raw.supply),
510
- chainId: normalizeChainId(raw.chainId),
511
- contractAddress,
512
- contractInfo: transformOptional(raw.contractInfo, toContractInfo),
513
- tokenMetadata: transformOptional(raw.tokenMetadata, toTokenMetadata)
514
- };
515
- }
516
- function toTransactionReceipt(raw) {
517
- return spreadWith(raw, {
518
- effectiveGasPrice: BigInt(raw.effectiveGasPrice),
519
- from: raw.from?.startsWith("0x") && raw.from.length === 42 ? normalizeAddress(raw.from) : void 0,
520
- to: raw.to?.startsWith("0x") && raw.to.length === 42 ? normalizeAddress(raw.to) : void 0,
521
- logs: transformArray(raw.logs, (log) => {
522
- const { contractAddress, index, ...rest } = log;
523
- return spreadWith(rest, {
524
- address: normalizeAddress(contractAddress),
525
- logIndex: index
526
- });
527
- })
528
- });
529
- }
530
- function toTokenIDRange(raw) {
531
- return {
532
- startTokenId: normalizeTokenId(raw.start),
533
- endTokenId: normalizeTokenId(raw.end)
534
- };
535
- }
536
- function toPage(raw) {
537
- if (!raw) return {
538
- page: 0,
539
- pageSize: 0,
540
- more: false
541
- };
542
- return spreadWith(raw, {
543
- page: raw.page || 0,
544
- pageSize: raw.pageSize || 0,
545
- more: raw.more || false
546
- });
547
- }
548
- function toGetTokenBalancesResponse(raw) {
549
- return spreadWith(raw, {
550
- balances: transformArray(raw.balances, toTokenBalance),
551
- page: toPage(raw.page)
552
- });
553
- }
554
- function toGetTokenSuppliesResponse(raw, contractAddress) {
555
- const tokenIDs = transformOptionalArray(raw.tokenIDs, (tokenSupply) => toTokenSupply(tokenSupply, contractAddress)) || [];
556
- return spreadWith(raw, {
557
- contractAddress,
558
- tokenIDs,
559
- supplies: tokenIDs,
560
- page: toPage(raw.page)
561
- });
562
- }
563
- function toGetTokenIDRangesResponse(raw, contractAddress) {
564
- const tokenIDRanges = transformOptionalArray(raw.tokenIDRanges, toTokenIDRange) || [];
565
- return spreadWith(raw, {
566
- contractAddress,
567
- tokenIDRanges,
568
- ranges: tokenIDRanges
569
- });
570
- }
571
- function toGetTokenBalancesDetailsResponse(raw) {
572
- return spreadWith(raw, {
573
- page: toPage(raw.page),
574
- nativeBalances: (raw.nativeBalances || []).map(toNativeTokenBalance),
575
- balances: raw.balances.map(toTokenBalance)
576
- });
577
- }
578
- function toGetTokenBalancesByContractResponse(raw) {
579
- return spreadWith(raw, {
580
- page: toPage(raw.page),
581
- balances: raw.balances.map(toTokenBalance)
582
- });
583
- }
584
- function toGetNativeTokenBalanceResponse(raw) {
585
- return spreadWith(raw, { balance: toNativeTokenBalance(raw.balance) });
586
- }
587
- function toGetTokenBalancesArgs(req) {
588
- const { tokenId, ...rest } = req;
589
- const accountAddress = "userAddress" in req && req.userAddress ? req.userAddress : "accountAddress" in req ? req.accountAddress : void 0;
590
- const contractAddress = "collectionAddress" in req && req.collectionAddress ? req.collectionAddress : "contractAddress" in req && req.contractAddress ? req.contractAddress : void 0;
591
- return {
592
- ...rest,
593
- ...accountAddress && { accountAddress },
594
- ...contractAddress && { contractAddress },
595
- ...tokenId !== void 0 && { tokenID: tokenId.toString() }
596
- };
597
- }
598
- function toGetUserCollectionBalancesArgs(req) {
599
- return {
600
- filter: {
601
- accountAddresses: [req.userAddress],
602
- contractAddresses: [req.collectionAddress]
603
- },
604
- omitMetadata: req.includeMetadata === false ? true : void 0
605
- };
606
- }
607
-
608
462
  //#endregion
609
463
  //#region ../api/dist/marketplace.gen.js
610
464
  let SortOrder = /* @__PURE__ */ function(SortOrder$1) {
@@ -2015,6 +1869,152 @@ const webrpcErrorByCode = {
2015
1869
  const WebrpcHeader = "Webrpc";
2016
1870
  const WebrpcHeaderValue = "webrpc@v0.31.1;gen-typescript@v0.23.1;api-client@v0-25.11.10+051e186";
2017
1871
 
1872
+ //#endregion
1873
+ //#region ../api/dist/transforms.js
1874
+ function toContractInfo(raw) {
1875
+ if (!raw.address || !raw.address.startsWith("0x") || raw.address.length !== 42) return;
1876
+ return spreadWith(raw, {
1877
+ chainId: normalizeChainId(raw.chainId),
1878
+ address: normalizeAddress(raw.address),
1879
+ extensions: transformOptional(raw.extensions, (ext) => {
1880
+ const result = { ...ext };
1881
+ if (ext.originChainId !== void 0) result.originChainId = normalizeChainId(ext.originChainId);
1882
+ if (ext.originAddress?.startsWith("0x") && ext.originAddress.length === 42) result.originAddress = normalizeAddress(ext.originAddress);
1883
+ return result;
1884
+ })
1885
+ });
1886
+ }
1887
+ function toTokenMetadata(raw) {
1888
+ return spreadWith(raw, {
1889
+ tokenId: normalizeTokenId(raw.tokenId),
1890
+ attributes: raw.attributes
1891
+ });
1892
+ }
1893
+ function toNativeTokenBalance(raw) {
1894
+ const result = {
1895
+ accountAddress: normalizeAddress(raw.accountAddress),
1896
+ chainId: normalizeChainId(raw.chainId),
1897
+ balance: BigInt(raw.balance)
1898
+ };
1899
+ if (raw.errorReason) result.errorReason = raw.errorReason;
1900
+ return result;
1901
+ }
1902
+ function toTokenBalance(raw) {
1903
+ const { tokenID, contractType, ...rest } = raw;
1904
+ return spreadWith(rest, {
1905
+ contractType,
1906
+ contractAddress: normalizeAddress(raw.contractAddress),
1907
+ accountAddress: normalizeAddress(raw.accountAddress),
1908
+ tokenId: raw.tokenID ? normalizeTokenId(raw.tokenID) : 0n,
1909
+ balance: BigInt(raw.balance),
1910
+ chainId: normalizeChainId(raw.chainId),
1911
+ contractInfo: transformOptional(raw.contractInfo, toContractInfo),
1912
+ tokenMetadata: transformOptional(raw.tokenMetadata, toTokenMetadata),
1913
+ uniqueCollectibles: transformOptional(raw.uniqueCollectibles, BigInt)
1914
+ });
1915
+ }
1916
+ function toTokenSupply(raw, contractAddress) {
1917
+ return {
1918
+ tokenId: normalizeTokenId(raw.tokenID),
1919
+ supply: BigInt(raw.supply),
1920
+ chainId: normalizeChainId(raw.chainId),
1921
+ contractAddress,
1922
+ contractInfo: transformOptional(raw.contractInfo, toContractInfo),
1923
+ tokenMetadata: transformOptional(raw.tokenMetadata, toTokenMetadata)
1924
+ };
1925
+ }
1926
+ function toTransactionReceipt(raw) {
1927
+ return spreadWith(raw, {
1928
+ effectiveGasPrice: BigInt(raw.effectiveGasPrice),
1929
+ from: raw.from?.startsWith("0x") && raw.from.length === 42 ? normalizeAddress(raw.from) : void 0,
1930
+ to: raw.to?.startsWith("0x") && raw.to.length === 42 ? normalizeAddress(raw.to) : void 0,
1931
+ logs: transformArray(raw.logs, (log) => {
1932
+ const { contractAddress, index, ...rest } = log;
1933
+ return spreadWith(rest, {
1934
+ address: normalizeAddress(contractAddress),
1935
+ logIndex: index
1936
+ });
1937
+ })
1938
+ });
1939
+ }
1940
+ function toTokenIDRange(raw) {
1941
+ return {
1942
+ startTokenId: normalizeTokenId(raw.start),
1943
+ endTokenId: normalizeTokenId(raw.end)
1944
+ };
1945
+ }
1946
+ function toPage(raw) {
1947
+ if (!raw) return {
1948
+ page: 0,
1949
+ pageSize: 0,
1950
+ more: false
1951
+ };
1952
+ return spreadWith(raw, {
1953
+ page: raw.page || 0,
1954
+ pageSize: raw.pageSize || 0,
1955
+ more: raw.more || false
1956
+ });
1957
+ }
1958
+ function toGetTokenBalancesResponse(raw) {
1959
+ return spreadWith(raw, {
1960
+ balances: transformArray(raw.balances, toTokenBalance),
1961
+ page: toPage(raw.page)
1962
+ });
1963
+ }
1964
+ function toGetTokenSuppliesResponse(raw, contractAddress) {
1965
+ const tokenIDs = transformOptionalArray(raw.tokenIDs, (tokenSupply) => toTokenSupply(tokenSupply, contractAddress)) || [];
1966
+ return spreadWith(raw, {
1967
+ contractAddress,
1968
+ tokenIDs,
1969
+ supplies: tokenIDs,
1970
+ page: toPage(raw.page)
1971
+ });
1972
+ }
1973
+ function toGetTokenIDRangesResponse(raw, contractAddress) {
1974
+ const tokenIDRanges = transformOptionalArray(raw.tokenIDRanges, toTokenIDRange) || [];
1975
+ return spreadWith(raw, {
1976
+ contractAddress,
1977
+ tokenIDRanges,
1978
+ ranges: tokenIDRanges
1979
+ });
1980
+ }
1981
+ function toGetTokenBalancesDetailsResponse(raw) {
1982
+ return spreadWith(raw, {
1983
+ page: toPage(raw.page),
1984
+ nativeBalances: (raw.nativeBalances || []).map(toNativeTokenBalance),
1985
+ balances: raw.balances.map(toTokenBalance)
1986
+ });
1987
+ }
1988
+ function toGetTokenBalancesByContractResponse(raw) {
1989
+ return spreadWith(raw, {
1990
+ page: toPage(raw.page),
1991
+ balances: raw.balances.map(toTokenBalance)
1992
+ });
1993
+ }
1994
+ function toGetNativeTokenBalanceResponse(raw) {
1995
+ return spreadWith(raw, { balance: toNativeTokenBalance(raw.balance) });
1996
+ }
1997
+ function toGetTokenBalancesArgs(req) {
1998
+ const { tokenId, ...rest } = req;
1999
+ const accountAddress = "userAddress" in req && req.userAddress ? req.userAddress : "accountAddress" in req ? req.accountAddress : void 0;
2000
+ const contractAddress = "collectionAddress" in req && req.collectionAddress ? req.collectionAddress : "contractAddress" in req && req.contractAddress ? req.contractAddress : void 0;
2001
+ return {
2002
+ ...rest,
2003
+ ...accountAddress && { accountAddress },
2004
+ ...contractAddress && { contractAddress },
2005
+ ...tokenId !== void 0 && { tokenID: tokenId.toString() }
2006
+ };
2007
+ }
2008
+ function toGetUserCollectionBalancesArgs(req) {
2009
+ return {
2010
+ filter: {
2011
+ accountAddresses: [req.userAddress],
2012
+ contractAddresses: [req.collectionAddress]
2013
+ },
2014
+ omitMetadata: req.includeMetadata === false ? true : void 0
2015
+ };
2016
+ }
2017
+
2018
2018
  //#endregion
2019
2019
  //#region ../api/dist/transforms2.js
2020
2020
  function toBridgeInfo(raw) {
@@ -2128,6 +2128,12 @@ function toGetTokenMetadataPropertyFiltersReturn(raw) {
2128
2128
 
2129
2129
  //#endregion
2130
2130
  //#region ../api/dist/index.js
2131
+ function normalizeMarketplaceKind(kind) {
2132
+ return kind === MarketplaceKind.magic_eden ? MarketplaceKind.opensea : kind;
2133
+ }
2134
+ function normalizeOrderbookKind(kind) {
2135
+ return kind === OrderbookKind.magic_eden ? OrderbookKind.opensea : kind;
2136
+ }
2131
2137
  function toLookupMarketplaceReturn(data) {
2132
2138
  const marketCollections = transformArray(data.marketCollections, toMarketCollection);
2133
2139
  const shopCollections = transformArray(data.shopCollections, toShopCollection);
@@ -2154,7 +2160,7 @@ function toMarketCollection(data) {
2154
2160
  chainId: normalizeChainId(data.chainId),
2155
2161
  itemsAddress: normalizeAddress(data.itemsAddress),
2156
2162
  contractType: data.contractType,
2157
- destinationMarketplace: data.destinationMarketplace
2163
+ destinationMarketplace: normalizeOrderbookKind(data.destinationMarketplace)
2158
2164
  };
2159
2165
  }
2160
2166
  function toShopCollection(data) {
@@ -2407,6 +2413,7 @@ function toCurrencies(raw) {
2407
2413
  function toOrder(raw) {
2408
2414
  return {
2409
2415
  ...raw,
2416
+ marketplace: normalizeMarketplaceKind(raw.marketplace),
2410
2417
  priceCurrencyAddress: normalizeAddress(raw.priceCurrencyAddress)
2411
2418
  };
2412
2419
  }
@@ -2684,6 +2691,18 @@ function isTransactionStep(step) {
2684
2691
  StepType.createListing
2685
2692
  ].includes(step.id);
2686
2693
  }
2694
+ function isApprovalStep(step) {
2695
+ return step.id === StepType.tokenApproval;
2696
+ }
2697
+ function isBuyStep(step) {
2698
+ return step.id === StepType.buy;
2699
+ }
2700
+ function findApprovalStep(steps) {
2701
+ return steps.find(isApprovalStep);
2702
+ }
2703
+ function findBuyStep(steps) {
2704
+ return steps.find(isBuyStep);
2705
+ }
2687
2706
  /**
2688
2707
  * Wrapped Metadata Client
2689
2708
  *
@@ -2767,5 +2786,5 @@ var MetadataClient = class {
2767
2786
  };
2768
2787
 
2769
2788
  //#endregion
2770
- export { FilterCondition as C, WalletKind as S, MarketplaceWalletType as T, PropertyType as _, builder_exports as a, TransactionCrypto as b, CollectionStatus as c, MarketplaceKind as d, MetadataStatus as f, OrderbookKind as g, OrderStatus as h, MetadataClient as i, CurrencyStatus as l, OrderSide as m, IndexerClient as n, isSignatureStep as o, OfferType as p, MarketplaceClient as r, isTransactionStep as s, ContractType$2 as t, ExecuteType as u, SortOrder as v, MarketplaceService as w, TransactionOnRampProvider as x, StepType as y };
2789
+ export { TransactionOnRampProvider as C, MarketplaceWalletType as D, MarketplaceService as E, TransactionCrypto as S, FilterCondition as T, OrderStatus as _, builder_exports as a, SortOrder as b, isSignatureStep as c, CurrencyStatus as d, ExecuteType as f, OrderSide as g, OfferType as h, MetadataClient as i, isTransactionStep as l, MetadataStatus as m, IndexerClient as n, findApprovalStep as o, MarketplaceKind as p, MarketplaceClient as r, findBuyStep as s, ContractType$2 as t, CollectionStatus as u, OrderbookKind as v, WalletKind as w, StepType as x, PropertyType as y };
2771
2790
  //# sourceMappingURL=dist.js.map