@opensea/sdk 9.0.0

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 (363) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +70 -0
  3. package/lib/api/accounts.d.ts +27 -0
  4. package/lib/api/accounts.js +46 -0
  5. package/lib/api/accounts.js.map +1 -0
  6. package/lib/api/api.d.ts +489 -0
  7. package/lib/api/api.js +754 -0
  8. package/lib/api/api.js.map +1 -0
  9. package/lib/api/apiPaths.d.ts +46 -0
  10. package/lib/api/apiPaths.js +176 -0
  11. package/lib/api/apiPaths.js.map +1 -0
  12. package/lib/api/chains.d.ts +13 -0
  13. package/lib/api/chains.js +22 -0
  14. package/lib/api/chains.js.map +1 -0
  15. package/lib/api/collections.d.ts +34 -0
  16. package/lib/api/collections.js +80 -0
  17. package/lib/api/collections.js.map +1 -0
  18. package/lib/api/drops.d.ts +21 -0
  19. package/lib/api/drops.js +39 -0
  20. package/lib/api/drops.js.map +1 -0
  21. package/lib/api/events.d.ts +26 -0
  22. package/lib/api/events.js +43 -0
  23. package/lib/api/events.js.map +1 -0
  24. package/lib/api/fetcher.d.ts +24 -0
  25. package/lib/api/fetcher.js +3 -0
  26. package/lib/api/fetcher.js.map +1 -0
  27. package/lib/api/index.d.ts +2 -0
  28. package/lib/api/index.js +19 -0
  29. package/lib/api/index.js.map +1 -0
  30. package/lib/api/listings.d.ts +44 -0
  31. package/lib/api/listings.js +88 -0
  32. package/lib/api/listings.js.map +1 -0
  33. package/lib/api/nfts.d.ts +39 -0
  34. package/lib/api/nfts.js +79 -0
  35. package/lib/api/nfts.js.map +1 -0
  36. package/lib/api/offers.d.ts +54 -0
  37. package/lib/api/offers.js +124 -0
  38. package/lib/api/offers.js.map +1 -0
  39. package/lib/api/orders.d.ts +50 -0
  40. package/lib/api/orders.js +153 -0
  41. package/lib/api/orders.js.map +1 -0
  42. package/lib/api/search.d.ts +13 -0
  43. package/lib/api/search.js +22 -0
  44. package/lib/api/search.js.map +1 -0
  45. package/lib/api/tokens.d.ts +25 -0
  46. package/lib/api/tokens.js +43 -0
  47. package/lib/api/tokens.js.map +1 -0
  48. package/lib/api/types.d.ts +1113 -0
  49. package/lib/api/types.js +65 -0
  50. package/lib/api/types.js.map +1 -0
  51. package/lib/constants.d.ts +22 -0
  52. package/lib/constants.js +52 -0
  53. package/lib/constants.js.map +1 -0
  54. package/lib/index.d.ts +18 -0
  55. package/lib/index.js +24 -0
  56. package/lib/index.js.map +1 -0
  57. package/lib/orders/privateListings.d.ts +12 -0
  58. package/lib/orders/privateListings.js +130 -0
  59. package/lib/orders/privateListings.js.map +1 -0
  60. package/lib/orders/types.d.ts +160 -0
  61. package/lib/orders/types.js +10 -0
  62. package/lib/orders/types.js.map +1 -0
  63. package/lib/orders/utils.d.ts +89 -0
  64. package/lib/orders/utils.js +177 -0
  65. package/lib/orders/utils.js.map +1 -0
  66. package/lib/sdk/assets.d.ts +104 -0
  67. package/lib/sdk/assets.js +398 -0
  68. package/lib/sdk/assets.js.map +1 -0
  69. package/lib/sdk/cancellation.d.ts +97 -0
  70. package/lib/sdk/cancellation.js +235 -0
  71. package/lib/sdk/cancellation.js.map +1 -0
  72. package/lib/sdk/context.d.ts +28 -0
  73. package/lib/sdk/context.js +3 -0
  74. package/lib/sdk/context.js.map +1 -0
  75. package/lib/sdk/fulfillment.d.ts +153 -0
  76. package/lib/sdk/fulfillment.js +298 -0
  77. package/lib/sdk/fulfillment.js.map +1 -0
  78. package/lib/sdk/orders.d.ts +253 -0
  79. package/lib/sdk/orders.js +679 -0
  80. package/lib/sdk/orders.js.map +1 -0
  81. package/lib/sdk/tokens.d.ts +31 -0
  82. package/lib/sdk/tokens.js +65 -0
  83. package/lib/sdk/tokens.js.map +1 -0
  84. package/lib/sdk.d.ts +560 -0
  85. package/lib/sdk.js +693 -0
  86. package/lib/sdk.js.map +1 -0
  87. package/lib/src/api/accounts.d.ts +18 -0
  88. package/lib/src/api/accounts.js +30 -0
  89. package/lib/src/api/accounts.js.map +1 -0
  90. package/lib/src/api/api.d.ts +429 -0
  91. package/lib/src/api/api.js +652 -0
  92. package/lib/src/api/api.js.map +1 -0
  93. package/lib/src/api/apiPaths.d.ts +37 -0
  94. package/lib/src/api/apiPaths.js +140 -0
  95. package/lib/src/api/apiPaths.js.map +1 -0
  96. package/lib/src/api/collections.d.ts +26 -0
  97. package/lib/src/api/collections.js +57 -0
  98. package/lib/src/api/collections.js.map +1 -0
  99. package/lib/src/api/events.d.ts +26 -0
  100. package/lib/src/api/events.js +42 -0
  101. package/lib/src/api/events.js.map +1 -0
  102. package/lib/src/api/fetcher.d.ts +24 -0
  103. package/lib/src/api/fetcher.js +3 -0
  104. package/lib/src/api/fetcher.js.map +1 -0
  105. package/lib/src/api/index.d.ts +2 -0
  106. package/lib/src/api/index.js +19 -0
  107. package/lib/src/api/index.js.map +1 -0
  108. package/lib/src/api/listings.d.ts +44 -0
  109. package/lib/src/api/listings.js +86 -0
  110. package/lib/src/api/listings.js.map +1 -0
  111. package/lib/src/api/nfts.d.ts +35 -0
  112. package/lib/src/api/nfts.js +66 -0
  113. package/lib/src/api/nfts.js.map +1 -0
  114. package/lib/src/api/offers.d.ts +54 -0
  115. package/lib/src/api/offers.js +122 -0
  116. package/lib/src/api/offers.js.map +1 -0
  117. package/lib/src/api/orders.d.ts +50 -0
  118. package/lib/src/api/orders.js +151 -0
  119. package/lib/src/api/orders.js.map +1 -0
  120. package/lib/src/api/search.d.ts +13 -0
  121. package/lib/src/api/search.js +21 -0
  122. package/lib/src/api/search.js.map +1 -0
  123. package/lib/src/api/tokens.d.ts +25 -0
  124. package/lib/src/api/tokens.js +42 -0
  125. package/lib/src/api/tokens.js.map +1 -0
  126. package/lib/src/api/types.d.ts +840 -0
  127. package/lib/src/api/types.js +65 -0
  128. package/lib/src/api/types.js.map +1 -0
  129. package/lib/src/constants.d.ts +22 -0
  130. package/lib/src/constants.js +52 -0
  131. package/lib/src/constants.js.map +1 -0
  132. package/lib/src/index.d.ts +18 -0
  133. package/lib/src/index.js +24 -0
  134. package/lib/src/index.js.map +1 -0
  135. package/lib/src/orders/privateListings.d.ts +12 -0
  136. package/lib/src/orders/privateListings.js +130 -0
  137. package/lib/src/orders/privateListings.js.map +1 -0
  138. package/lib/src/orders/types.d.ts +160 -0
  139. package/lib/src/orders/types.js +10 -0
  140. package/lib/src/orders/types.js.map +1 -0
  141. package/lib/src/orders/utils.d.ts +89 -0
  142. package/lib/src/orders/utils.js +177 -0
  143. package/lib/src/orders/utils.js.map +1 -0
  144. package/lib/src/sdk/assets.d.ts +104 -0
  145. package/lib/src/sdk/assets.js +397 -0
  146. package/lib/src/sdk/assets.js.map +1 -0
  147. package/lib/src/sdk/cancellation.d.ts +97 -0
  148. package/lib/src/sdk/cancellation.js +234 -0
  149. package/lib/src/sdk/cancellation.js.map +1 -0
  150. package/lib/src/sdk/context.d.ts +28 -0
  151. package/lib/src/sdk/context.js +3 -0
  152. package/lib/src/sdk/context.js.map +1 -0
  153. package/lib/src/sdk/fulfillment.d.ts +153 -0
  154. package/lib/src/sdk/fulfillment.js +296 -0
  155. package/lib/src/sdk/fulfillment.js.map +1 -0
  156. package/lib/src/sdk/orders.d.ts +253 -0
  157. package/lib/src/sdk/orders.js +677 -0
  158. package/lib/src/sdk/orders.js.map +1 -0
  159. package/lib/src/sdk/tokens.d.ts +31 -0
  160. package/lib/src/sdk/tokens.js +64 -0
  161. package/lib/src/sdk/tokens.js.map +1 -0
  162. package/lib/src/sdk.d.ts +560 -0
  163. package/lib/src/sdk.js +675 -0
  164. package/lib/src/sdk.js.map +1 -0
  165. package/lib/src/typechain/contracts/ERC1155.d.ts +236 -0
  166. package/lib/src/typechain/contracts/ERC1155.js +3 -0
  167. package/lib/src/typechain/contracts/ERC1155.js.map +1 -0
  168. package/lib/src/typechain/contracts/ERC20.d.ts +141 -0
  169. package/lib/src/typechain/contracts/ERC20.js +3 -0
  170. package/lib/src/typechain/contracts/ERC20.js.map +1 -0
  171. package/lib/src/typechain/contracts/ERC721.d.ts +213 -0
  172. package/lib/src/typechain/contracts/ERC721.js +3 -0
  173. package/lib/src/typechain/contracts/ERC721.js.map +1 -0
  174. package/lib/src/typechain/contracts/Multicall3.d.ts +57 -0
  175. package/lib/src/typechain/contracts/Multicall3.js +3 -0
  176. package/lib/src/typechain/contracts/Multicall3.js.map +1 -0
  177. package/lib/src/typechain/contracts/TransferHelper.d.ts +55 -0
  178. package/lib/src/typechain/contracts/TransferHelper.js +3 -0
  179. package/lib/src/typechain/contracts/TransferHelper.js.map +1 -0
  180. package/lib/src/typechain/contracts/common.d.ts +50 -0
  181. package/lib/src/typechain/contracts/common.js +3 -0
  182. package/lib/src/typechain/contracts/common.js.map +1 -0
  183. package/lib/src/typechain/contracts/factories/ERC1155__factory.d.ts +250 -0
  184. package/lib/src/typechain/contracts/factories/ERC1155__factory.js +332 -0
  185. package/lib/src/typechain/contracts/factories/ERC1155__factory.js.map +1 -0
  186. package/lib/src/typechain/contracts/factories/ERC20__factory.d.ts +174 -0
  187. package/lib/src/typechain/contracts/factories/ERC20__factory.js +240 -0
  188. package/lib/src/typechain/contracts/factories/ERC20__factory.js.map +1 -0
  189. package/lib/src/typechain/contracts/factories/ERC721__factory.d.ts +268 -0
  190. package/lib/src/typechain/contracts/factories/ERC721__factory.js +351 -0
  191. package/lib/src/typechain/contracts/factories/ERC721__factory.js.map +1 -0
  192. package/lib/src/typechain/contracts/factories/Multicall3__factory.d.ts +43 -0
  193. package/lib/src/typechain/contracts/factories/Multicall3__factory.js +68 -0
  194. package/lib/src/typechain/contracts/factories/Multicall3__factory.js.map +1 -0
  195. package/lib/src/typechain/contracts/factories/TransferHelper__factory.d.ts +46 -0
  196. package/lib/src/typechain/contracts/factories/TransferHelper__factory.js +71 -0
  197. package/lib/src/typechain/contracts/factories/TransferHelper__factory.js.map +1 -0
  198. package/lib/src/typechain/contracts/factories/index.d.ts +5 -0
  199. package/lib/src/typechain/contracts/factories/index.js +17 -0
  200. package/lib/src/typechain/contracts/factories/index.js.map +1 -0
  201. package/lib/src/typechain/contracts/index.d.ts +11 -0
  202. package/lib/src/typechain/contracts/index.js +48 -0
  203. package/lib/src/typechain/contracts/index.js.map +1 -0
  204. package/lib/src/types.d.ts +387 -0
  205. package/lib/src/types.js +127 -0
  206. package/lib/src/types.js.map +1 -0
  207. package/lib/src/utils/chain.d.ts +60 -0
  208. package/lib/src/utils/chain.js +248 -0
  209. package/lib/src/utils/chain.js.map +1 -0
  210. package/lib/src/utils/converters.d.ts +37 -0
  211. package/lib/src/utils/converters.js +137 -0
  212. package/lib/src/utils/converters.js.map +1 -0
  213. package/lib/src/utils/dateHelper.d.ts +38 -0
  214. package/lib/src/utils/dateHelper.js +52 -0
  215. package/lib/src/utils/dateHelper.js.map +1 -0
  216. package/lib/src/utils/fees.d.ts +13 -0
  217. package/lib/src/utils/fees.js +29 -0
  218. package/lib/src/utils/fees.js.map +1 -0
  219. package/lib/src/utils/index.d.ts +2 -0
  220. package/lib/src/utils/index.js +19 -0
  221. package/lib/src/utils/index.js.map +1 -0
  222. package/lib/src/utils/protocol.d.ts +75 -0
  223. package/lib/src/utils/protocol.js +161 -0
  224. package/lib/src/utils/protocol.js.map +1 -0
  225. package/lib/src/utils/rateLimit.d.ts +34 -0
  226. package/lib/src/utils/rateLimit.js +97 -0
  227. package/lib/src/utils/rateLimit.js.map +1 -0
  228. package/lib/src/utils/stringHelper.d.ts +18 -0
  229. package/lib/src/utils/stringHelper.js +24 -0
  230. package/lib/src/utils/stringHelper.js.map +1 -0
  231. package/lib/src/utils/utils.d.ts +18 -0
  232. package/lib/src/utils/utils.js +45 -0
  233. package/lib/src/utils/utils.js.map +1 -0
  234. package/lib/typechain/contracts/ERC1155.d.ts +236 -0
  235. package/lib/typechain/contracts/ERC1155.js +3 -0
  236. package/lib/typechain/contracts/ERC1155.js.map +1 -0
  237. package/lib/typechain/contracts/ERC20.d.ts +141 -0
  238. package/lib/typechain/contracts/ERC20.js +3 -0
  239. package/lib/typechain/contracts/ERC20.js.map +1 -0
  240. package/lib/typechain/contracts/ERC721.d.ts +213 -0
  241. package/lib/typechain/contracts/ERC721.js +3 -0
  242. package/lib/typechain/contracts/ERC721.js.map +1 -0
  243. package/lib/typechain/contracts/Multicall3.d.ts +57 -0
  244. package/lib/typechain/contracts/Multicall3.js +3 -0
  245. package/lib/typechain/contracts/Multicall3.js.map +1 -0
  246. package/lib/typechain/contracts/TransferHelper.d.ts +55 -0
  247. package/lib/typechain/contracts/TransferHelper.js +3 -0
  248. package/lib/typechain/contracts/TransferHelper.js.map +1 -0
  249. package/lib/typechain/contracts/common.d.ts +50 -0
  250. package/lib/typechain/contracts/common.js +3 -0
  251. package/lib/typechain/contracts/common.js.map +1 -0
  252. package/lib/typechain/contracts/factories/ERC1155__factory.d.ts +250 -0
  253. package/lib/typechain/contracts/factories/ERC1155__factory.js +332 -0
  254. package/lib/typechain/contracts/factories/ERC1155__factory.js.map +1 -0
  255. package/lib/typechain/contracts/factories/ERC20__factory.d.ts +174 -0
  256. package/lib/typechain/contracts/factories/ERC20__factory.js +240 -0
  257. package/lib/typechain/contracts/factories/ERC20__factory.js.map +1 -0
  258. package/lib/typechain/contracts/factories/ERC721__factory.d.ts +268 -0
  259. package/lib/typechain/contracts/factories/ERC721__factory.js +351 -0
  260. package/lib/typechain/contracts/factories/ERC721__factory.js.map +1 -0
  261. package/lib/typechain/contracts/factories/Multicall3__factory.d.ts +43 -0
  262. package/lib/typechain/contracts/factories/Multicall3__factory.js +68 -0
  263. package/lib/typechain/contracts/factories/Multicall3__factory.js.map +1 -0
  264. package/lib/typechain/contracts/factories/TransferHelper__factory.d.ts +46 -0
  265. package/lib/typechain/contracts/factories/TransferHelper__factory.js +71 -0
  266. package/lib/typechain/contracts/factories/TransferHelper__factory.js.map +1 -0
  267. package/lib/typechain/contracts/factories/index.d.ts +5 -0
  268. package/lib/typechain/contracts/factories/index.js +17 -0
  269. package/lib/typechain/contracts/factories/index.js.map +1 -0
  270. package/lib/typechain/contracts/index.d.ts +11 -0
  271. package/lib/typechain/contracts/index.js +48 -0
  272. package/lib/typechain/contracts/index.js.map +1 -0
  273. package/lib/types.d.ts +389 -0
  274. package/lib/types.js +129 -0
  275. package/lib/types.js.map +1 -0
  276. package/lib/utils/chain.d.ts +64 -0
  277. package/lib/utils/chain.js +211 -0
  278. package/lib/utils/chain.js.map +1 -0
  279. package/lib/utils/chainIds.generated.d.ts +7 -0
  280. package/lib/utils/chainIds.generated.js +37 -0
  281. package/lib/utils/chainIds.generated.js.map +1 -0
  282. package/lib/utils/converters.d.ts +37 -0
  283. package/lib/utils/converters.js +137 -0
  284. package/lib/utils/converters.js.map +1 -0
  285. package/lib/utils/dateHelper.d.ts +38 -0
  286. package/lib/utils/dateHelper.js +52 -0
  287. package/lib/utils/dateHelper.js.map +1 -0
  288. package/lib/utils/fees.d.ts +13 -0
  289. package/lib/utils/fees.js +29 -0
  290. package/lib/utils/fees.js.map +1 -0
  291. package/lib/utils/index.d.ts +2 -0
  292. package/lib/utils/index.js +19 -0
  293. package/lib/utils/index.js.map +1 -0
  294. package/lib/utils/protocol.d.ts +75 -0
  295. package/lib/utils/protocol.js +161 -0
  296. package/lib/utils/protocol.js.map +1 -0
  297. package/lib/utils/rateLimit.d.ts +34 -0
  298. package/lib/utils/rateLimit.js +97 -0
  299. package/lib/utils/rateLimit.js.map +1 -0
  300. package/lib/utils/stringHelper.d.ts +18 -0
  301. package/lib/utils/stringHelper.js +24 -0
  302. package/lib/utils/stringHelper.js.map +1 -0
  303. package/lib/utils/utils.d.ts +18 -0
  304. package/lib/utils/utils.js +45 -0
  305. package/lib/utils/utils.js.map +1 -0
  306. package/package.json +72 -0
  307. package/src/abi/ERC1155.json +314 -0
  308. package/src/abi/ERC20.json +222 -0
  309. package/src/abi/ERC721.json +333 -0
  310. package/src/abi/Multicall3.json +50 -0
  311. package/src/abi/TransferHelper.json +53 -0
  312. package/src/api/accounts.ts +69 -0
  313. package/src/api/api.ts +1152 -0
  314. package/src/api/apiPaths.ts +208 -0
  315. package/src/api/chains.ts +18 -0
  316. package/src/api/collections.ts +120 -0
  317. package/src/api/drops.ts +49 -0
  318. package/src/api/events.ts +71 -0
  319. package/src/api/fetcher.ts +31 -0
  320. package/src/api/index.ts +2 -0
  321. package/src/api/listings.ts +126 -0
  322. package/src/api/nfts.ts +144 -0
  323. package/src/api/offers.ts +242 -0
  324. package/src/api/orders.ts +283 -0
  325. package/src/api/search.ts +21 -0
  326. package/src/api/tokens.ts +67 -0
  327. package/src/api/types.ts +1210 -0
  328. package/src/constants.ts +90 -0
  329. package/src/index.ts +22 -0
  330. package/src/orders/privateListings.ts +173 -0
  331. package/src/orders/types.ts +191 -0
  332. package/src/orders/utils.ts +253 -0
  333. package/src/sdk/assets.ts +591 -0
  334. package/src/sdk/cancellation.ts +346 -0
  335. package/src/sdk/context.ts +33 -0
  336. package/src/sdk/fulfillment.ts +478 -0
  337. package/src/sdk/orders.ts +1149 -0
  338. package/src/sdk/tokens.ts +95 -0
  339. package/src/sdk.ts +1051 -0
  340. package/src/typechain/contracts/ERC1155.ts +440 -0
  341. package/src/typechain/contracts/ERC20.ts +286 -0
  342. package/src/typechain/contracts/ERC721.ts +412 -0
  343. package/src/typechain/contracts/Multicall3.ts +117 -0
  344. package/src/typechain/contracts/TransferHelper.ts +122 -0
  345. package/src/typechain/contracts/common.ts +131 -0
  346. package/src/typechain/contracts/factories/ERC1155__factory.ts +331 -0
  347. package/src/typechain/contracts/factories/ERC20__factory.ts +239 -0
  348. package/src/typechain/contracts/factories/ERC721__factory.ts +350 -0
  349. package/src/typechain/contracts/factories/Multicall3__factory.ts +67 -0
  350. package/src/typechain/contracts/factories/TransferHelper__factory.ts +76 -0
  351. package/src/typechain/contracts/factories/index.ts +8 -0
  352. package/src/typechain/contracts/index.ts +14 -0
  353. package/src/types.ts +413 -0
  354. package/src/utils/chain.ts +224 -0
  355. package/src/utils/chainIds.generated.ts +34 -0
  356. package/src/utils/converters.ts +145 -0
  357. package/src/utils/dateHelper.ts +48 -0
  358. package/src/utils/fees.ts +31 -0
  359. package/src/utils/index.ts +2 -0
  360. package/src/utils/protocol.ts +185 -0
  361. package/src/utils/rateLimit.ts +147 -0
  362. package/src/utils/stringHelper.ts +25 -0
  363. package/src/utils/utils.ts +36 -0
package/lib/sdk.js ADDED
@@ -0,0 +1,693 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenSeaSDK = void 0;
4
+ const EventEmitter = require("node:events");
5
+ const seaport_js_1 = require("@opensea/seaport-js");
6
+ const ethers_1 = require("ethers");
7
+ const api_1 = require("./api/api");
8
+ const assets_1 = require("./sdk/assets");
9
+ const cancellation_1 = require("./sdk/cancellation");
10
+ const fulfillment_1 = require("./sdk/fulfillment");
11
+ const orders_1 = require("./sdk/orders");
12
+ const tokens_1 = require("./sdk/tokens");
13
+ const types_1 = require("./types");
14
+ const utils_1 = require("./utils/utils");
15
+ /**
16
+ * The OpenSea SDK main class.
17
+ * @category Main Classes
18
+ */
19
+ class OpenSeaSDK {
20
+ /** Provider to use for transactions. */
21
+ provider;
22
+ /** Seaport client @see {@link https://github.com/ProjectOpenSea/seaport-js} */
23
+ seaport;
24
+ /** Logger function to use when debugging */
25
+ logger;
26
+ /** API instance */
27
+ api;
28
+ /** The configured chain */
29
+ chain;
30
+ /** Internal cache of decimals for payment tokens to save network requests */
31
+ _cachedPaymentTokenDecimals = {};
32
+ _emitter;
33
+ _signerOrProvider;
34
+ // Manager instances
35
+ _tokensManager;
36
+ _assetsManager;
37
+ _cancellationManager;
38
+ _ordersManager;
39
+ _fulfillmentManager;
40
+ /**
41
+ * Create a new instance of OpenSeaSDK.
42
+ * @param signerOrProvider Signer or provider to use for transactions. For example:
43
+ * `new ethers.providers.JsonRpcProvider('https://mainnet.infura.io')` or
44
+ * `new ethers.Wallet(privKey, provider)`
45
+ * @param apiConfig configuration options, including `chain`
46
+ * @param logger optional function for logging debug strings. defaults to no logging
47
+ */
48
+ constructor(signerOrProvider, apiConfig = {}, logger) {
49
+ // API config
50
+ apiConfig.chain ??= types_1.Chain.Mainnet;
51
+ this.chain = apiConfig.chain;
52
+ this.api = new api_1.OpenSeaAPI(apiConfig);
53
+ this.provider = (signerOrProvider.provider ??
54
+ signerOrProvider);
55
+ this._signerOrProvider = signerOrProvider ?? this.provider;
56
+ const defaultConduit = (0, utils_1.getDefaultConduit)(this.chain);
57
+ const seaportAddress = (0, utils_1.getSeaportAddress)(this.chain);
58
+ this.seaport = new seaport_js_1.Seaport(this._signerOrProvider, {
59
+ conduitKeyToConduit: {
60
+ [defaultConduit.key]: defaultConduit.address,
61
+ },
62
+ overrides: {
63
+ defaultConduitKey: defaultConduit.key,
64
+ contractAddress: seaportAddress,
65
+ },
66
+ });
67
+ // Emit events
68
+ this._emitter = new EventEmitter();
69
+ // Logger: default to no logging if fn not provided
70
+ this.logger = logger ?? ((arg) => arg);
71
+ // Cache decimals for offer and listing payment tokens to skip network request
72
+ const offerPaymentToken = (0, utils_1.getOfferPaymentToken)(this.chain).toLowerCase();
73
+ const listingPaymentToken = (0, utils_1.getListingPaymentToken)(this.chain).toLowerCase();
74
+ this._cachedPaymentTokenDecimals[offerPaymentToken] = 18;
75
+ this._cachedPaymentTokenDecimals[listingPaymentToken] = 18;
76
+ // Create shared context for all managers
77
+ const context = {
78
+ chain: this.chain,
79
+ signerOrProvider: this._signerOrProvider,
80
+ provider: this.provider,
81
+ api: this.api,
82
+ seaport: this.seaport,
83
+ logger: this.logger,
84
+ dispatch: this._dispatch.bind(this),
85
+ confirmTransaction: this._confirmTransaction.bind(this),
86
+ requireAccountIsAvailable: this._requireAccountIsAvailable.bind(this),
87
+ };
88
+ // Initialize manager instances
89
+ this._tokensManager = new tokens_1.TokensManager(context);
90
+ this._assetsManager = new assets_1.AssetsManager(context);
91
+ this._cancellationManager = new cancellation_1.CancellationManager(context);
92
+ this._ordersManager = new orders_1.OrdersManager(context, this._getPriceParameters.bind(this));
93
+ this._fulfillmentManager = new fulfillment_1.FulfillmentManager(context, this._ordersManager);
94
+ }
95
+ /**
96
+ * Add a listener for events emitted by the SDK.
97
+ * @param event The {@link EventType} to listen to.
98
+ * @param listener A callback that will accept an object with {@link EventData}\
99
+ * @param once Whether the listener should only be called once, or continue listening until removed.
100
+ */
101
+ addListener(event, listener, once = false) {
102
+ if (once) {
103
+ this._emitter.once(event, listener);
104
+ }
105
+ else {
106
+ this._emitter.addListener(event, listener);
107
+ }
108
+ }
109
+ /**
110
+ * Remove an event listener by calling `.removeListener()` on an event and listener.
111
+ * @param event The {@link EventType} to remove a listener for\
112
+ * @param listener The listener to remove
113
+ */
114
+ removeListener(event, listener) {
115
+ this._emitter.removeListener(event, listener);
116
+ }
117
+ /**
118
+ * Remove all event listeners. This should be called when you're unmounting
119
+ * a component that listens to events to make UI updates.
120
+ * @param event Optional EventType to remove listeners for
121
+ */
122
+ removeAllListeners(event) {
123
+ this._emitter.removeAllListeners(event);
124
+ }
125
+ /**
126
+ * Wrap native asset into wrapped native asset (e.g. ETH into WETH, POL into WPOL).
127
+ * Wrapped native assets are needed for making offers.
128
+ * @param options
129
+ * @param options.amountInEth Amount of native asset to wrap
130
+ * @param options.accountAddress Address of the user's wallet containing the native asset
131
+ */
132
+ async wrapEth({ amountInEth, accountAddress, }) {
133
+ return this._tokensManager.wrapEth({ amountInEth, accountAddress });
134
+ }
135
+ /**
136
+ * Unwrap wrapped native asset into native asset (e.g. WETH into ETH, WPOL into POL).
137
+ * Emits the `UnwrapWeth` event when the transaction is prompted.
138
+ * @param options
139
+ * @param options.amountInEth How much wrapped native asset to unwrap
140
+ * @param options.accountAddress Address of the user's wallet containing the wrapped native asset
141
+ */
142
+ async unwrapWeth({ amountInEth, accountAddress, }) {
143
+ return this._tokensManager.unwrapWeth({ amountInEth, accountAddress });
144
+ }
145
+ /**
146
+ * Create and submit an offer on an asset.
147
+ * @param options
148
+ * @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
149
+ * @param options.accountAddress Address of the wallet making the offer.
150
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
151
+ * @param options.quantity Number of assets to bid for. Defaults to 1.
152
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
153
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
154
+ * @param options.expirationTime Expiration time for the order, in UTC seconds
155
+ * @param options.zone Zone for order protection. Defaults to chain's signed zone.
156
+ *
157
+ * @returns The {@link OrderV2} that was created.
158
+ *
159
+ * @throws Error if the asset does not contain a token id.
160
+ * @throws Error if the accountAddress is not available through wallet or provider.
161
+ * @throws Error if the amount is not greater than 0.
162
+ */
163
+ async createOffer({ asset, accountAddress, amount, quantity = 1, domain, salt, expirationTime, zone, }) {
164
+ return this._ordersManager.createOffer({
165
+ asset,
166
+ accountAddress,
167
+ amount,
168
+ quantity,
169
+ domain,
170
+ salt,
171
+ expirationTime,
172
+ zone,
173
+ });
174
+ }
175
+ /**
176
+ * Create and submit a listing for an asset.
177
+ * @param options
178
+ * @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
179
+ * @param options.accountAddress Address of the wallet making the listing
180
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
181
+ * @param options.quantity Number of assets to list. Defaults to 1.
182
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
183
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
184
+ * @param options.listingTime Optional time when the order will become fulfillable, in UTC seconds. Undefined means it will start now.
185
+ * @param options.expirationTime Expiration time for the order, in UTC seconds.
186
+ * @param options.buyerAddress Optional address that's allowed to purchase this item. If specified, no other address will be able to take the order, unless its value is the null address.
187
+ * @param options.includeOptionalCreatorFees If true, optional creator fees will be included in the listing. Default: false.
188
+ * @param options.zone Zone for order protection. Defaults to no zone.
189
+ * @returns The {@link OrderV2} that was created.
190
+ *
191
+ * @throws Error if the asset does not contain a token id.
192
+ * @throws Error if the accountAddress is not available through wallet or provider.
193
+ * @throws Error if the amount is not greater than 0.
194
+ */
195
+ async createListing({ asset, accountAddress, amount, quantity = 1, domain, salt, listingTime, expirationTime, buyerAddress, includeOptionalCreatorFees = false, zone, }) {
196
+ return this._ordersManager.createListing({
197
+ asset,
198
+ accountAddress,
199
+ amount,
200
+ quantity,
201
+ domain,
202
+ salt,
203
+ listingTime,
204
+ expirationTime,
205
+ buyerAddress,
206
+ includeOptionalCreatorFees,
207
+ zone,
208
+ });
209
+ }
210
+ /**
211
+ * Create and submit multiple listings using Seaport's bulk order creation.
212
+ * This method uses a single signature for all listings and submits them individually to the OpenSea API with rate limit handling.
213
+ * All listings must be from the same account address.
214
+ *
215
+ * Note: If only one listing is provided, this method will use a normal order signature instead of a bulk signature,
216
+ * as bulk signatures are more expensive to decode onchain due to the merkle proof verification.
217
+ *
218
+ * @param options
219
+ * @param options.listings Array of listing parameters. Each listing requires asset, amount, and optionally other listing parameters.
220
+ * @param options.accountAddress Address of the wallet making the listings
221
+ * @param options.continueOnError If true, continue submitting remaining listings even if some fail. Default: false (throw on first error).
222
+ * @param options.onProgress Optional callback for progress updates. Called after each listing is submitted (successfully or not).
223
+ * @returns {@link BulkOrderResult} containing successful orders and any failures.
224
+ *
225
+ * @throws Error if listings array is empty
226
+ * @throws Error if the accountAddress is not available through wallet or provider.
227
+ * @throws Error if any asset does not contain a token id.
228
+ * @throws Error if continueOnError is false and any submission fails.
229
+ */
230
+ async createBulkListings({ listings, accountAddress, continueOnError, onProgress, }) {
231
+ return this._ordersManager.createBulkListings({
232
+ listings,
233
+ accountAddress,
234
+ continueOnError,
235
+ onProgress,
236
+ });
237
+ }
238
+ /**
239
+ * Create and submit multiple offers using Seaport's bulk order creation.
240
+ * This method uses a single signature for all offers and submits them individually to the OpenSea API with rate limit handling.
241
+ * All offers must be from the same account address.
242
+ *
243
+ * Note: If only one offer is provided, this method will use a normal order signature instead of a bulk signature,
244
+ * as bulk signatures are more expensive to decode onchain due to the merkle proof verification.
245
+ *
246
+ * @param options
247
+ * @param options.offers Array of offer parameters. Each offer requires asset, amount, and optionally other offer parameters.
248
+ * @param options.accountAddress Address of the wallet making the offers
249
+ * @param options.continueOnError If true, continue submitting remaining offers even if some fail. Default: false (throw on first error).
250
+ * @param options.onProgress Optional callback for progress updates. Called after each offer is submitted (successfully or not).
251
+ * @returns {@link BulkOrderResult} containing successful orders and any failures.
252
+ *
253
+ * @throws Error if offers array is empty
254
+ * @throws Error if the accountAddress is not available through wallet or provider.
255
+ * @throws Error if any asset does not contain a token id.
256
+ * @throws Error if continueOnError is false and any submission fails.
257
+ */
258
+ async createBulkOffers({ offers, accountAddress, continueOnError, onProgress, }) {
259
+ return this._ordersManager.createBulkOffers({
260
+ offers,
261
+ accountAddress,
262
+ continueOnError,
263
+ onProgress,
264
+ });
265
+ }
266
+ /**
267
+ * Create and submit a collection offer.
268
+ * @param options
269
+ * @param options.collectionSlug Identifier for the collection.
270
+ * @param options.accountAddress Address of the wallet making the offer.
271
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
272
+ * @param options.quantity Number of assets to bid for.
273
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
274
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
275
+ * @param options.expirationTime Expiration time (UTC seconds).
276
+ * @param options.offerProtectionEnabled Use signed zone for protection against disabled items. Default: true.
277
+ * @param options.traitType If defined, the trait name to create the collection offer for.
278
+ * @param options.traitValue If defined, the trait value to create the collection offer for.
279
+ * @param options.traits If defined, an array of traits to create the multi-trait collection offer for.
280
+ * @param options.numericTraits If defined, an array of numeric trait criteria with min/max ranges.
281
+ * @returns The {@link CollectionOffer} that was created.
282
+ */
283
+ async createCollectionOffer({ collectionSlug, accountAddress, amount, quantity, domain, salt, expirationTime, offerProtectionEnabled = true, traitType, traitValue, traits, numericTraits, }) {
284
+ return this._ordersManager.createCollectionOffer({
285
+ collectionSlug,
286
+ accountAddress,
287
+ amount,
288
+ quantity,
289
+ domain,
290
+ salt,
291
+ expirationTime,
292
+ offerProtectionEnabled,
293
+ traitType,
294
+ traitValue,
295
+ traits,
296
+ numericTraits,
297
+ });
298
+ }
299
+ /**
300
+ * Fulfill an order for an asset. The order can be either a listing or an offer.
301
+ * Uses the OpenSea API to generate fulfillment transaction data and executes it directly.
302
+ * @param options
303
+ * @param options.order The order to fulfill, a.k.a. "take"
304
+ * @param options.accountAddress Address of the wallet taking the offer.
305
+ * @param options.assetContractAddress Optional address of the NFT contract for criteria offers (e.g., collection offers). Required when fulfilling collection offers.
306
+ * @param options.tokenId Optional token ID for criteria offers (e.g., collection offers). Required when fulfilling collection offers.
307
+ * @param options.unitsToFill Optional number of units to fill. Defaults to 1 for both listings and offers.
308
+ * @param options.recipientAddress Optional recipient address for the NFT when fulfilling a listing. Not applicable for offers.
309
+ * @param options.includeOptionalCreatorFees Whether to include optional creator fees in the fulfillment. If creator fees are already required, this is a no-op. Defaults to false.
310
+ * @param options.overrides Transaction overrides, ignored if not set.
311
+ * @returns Transaction hash of the order.
312
+ *
313
+ * @throws Error if the accountAddress is not available through wallet or provider.
314
+ * @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
315
+ * @throws Error if a signer is not provided (read-only providers cannot fulfill orders).
316
+ * @throws Error if the order hash is not available.
317
+ */
318
+ async fulfillOrder({ order, accountAddress, assetContractAddress, tokenId, unitsToFill, recipientAddress, includeOptionalCreatorFees = false, overrides, }) {
319
+ return this._fulfillmentManager.fulfillOrder({
320
+ order,
321
+ accountAddress,
322
+ assetContractAddress,
323
+ tokenId,
324
+ unitsToFill,
325
+ recipientAddress,
326
+ includeOptionalCreatorFees,
327
+ overrides,
328
+ });
329
+ }
330
+ /**
331
+ * Cancel multiple orders onchain, preventing them from being fulfilled.
332
+ * This method accepts either full OrderV2 objects, OrderComponents, or order hashes with protocol address.
333
+ *
334
+ * **Event Behavior**: For backwards compatibility with the singular `cancelOrder` method,
335
+ * this method dispatches a `CancelOrder` event for the first order only, and only when
336
+ * an OrderV2 object is available (either provided directly or fetched via orderHashes).
337
+ * No event is dispatched when using OrderComponents directly, as they lack the full order data.
338
+ *
339
+ * @param options
340
+ * @param options.orders Array of orders to cancel. Can be OrderV2 objects or OrderComponents.
341
+ * @param options.orderHashes Optional array of order hashes to cancel. Must provide protocolAddress if using this.
342
+ * @param options.accountAddress The account address cancelling the orders.
343
+ * @param options.protocolAddress Required when using orderHashes. The Seaport protocol address for the orders.
344
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in calldata.
345
+ * @param options.overrides Transaction overrides, ignored if not set.
346
+ * @returns Transaction hash of the cancellation.
347
+ *
348
+ * @throws Error if orderHashes is provided without protocolAddress.
349
+ * @throws Error if neither orders nor orderHashes is provided.
350
+ * @throws Error if the accountAddress is not available through wallet or provider.
351
+ * @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
352
+ */
353
+ async cancelOrders({ orders, orderHashes, accountAddress, protocolAddress, domain, overrides, }) {
354
+ return this._cancellationManager.cancelOrders({
355
+ orders,
356
+ orderHashes,
357
+ accountAddress,
358
+ protocolAddress,
359
+ domain,
360
+ overrides,
361
+ });
362
+ }
363
+ /**
364
+ * Cancel an order onchain, preventing it from ever being fulfilled.
365
+ * This method accepts either a full OrderV2 object or an order hash with protocol address.
366
+ *
367
+ * @param options
368
+ * @param options.order The order to cancel (OrderV2 object)
369
+ * @param options.orderHash Optional order hash to cancel. Must provide protocolAddress if using this.
370
+ * @param options.accountAddress The account address that will be cancelling the order.
371
+ * @param options.protocolAddress Required when using orderHash. The Seaport protocol address for the order.
372
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in calldata.
373
+ *
374
+ * @throws Error if neither order nor orderHash is provided.
375
+ * @throws Error if the accountAddress is not available through wallet or provider.
376
+ * @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
377
+ *
378
+ * @example
379
+ * // Cancel using OrderV2 object
380
+ * await sdk.cancelOrder({
381
+ * order: orderV2Object,
382
+ * accountAddress: "0x..."
383
+ * });
384
+ *
385
+ * @example
386
+ * // Cancel using order hash
387
+ * await sdk.cancelOrder({
388
+ * orderHash: "0x123...",
389
+ * protocolAddress: "0xabc...",
390
+ * accountAddress: "0x..."
391
+ * });
392
+ */
393
+ async cancelOrder({ order, orderHash, accountAddress, protocolAddress, domain, }) {
394
+ return this._cancellationManager.cancelOrder({
395
+ order,
396
+ orderHash,
397
+ accountAddress,
398
+ protocolAddress,
399
+ domain,
400
+ });
401
+ }
402
+ /**
403
+ * Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone.
404
+ * Protocol and Chain are required to prevent hash collisions.
405
+ * Please note cancellation is only assured if a fulfillment signature was not vended prior to cancellation.
406
+ * @param protocolAddress The Seaport address for the order.
407
+ * @param orderHash The order hash, or external identifier, of the order.
408
+ * @param chain The chain where the order is located.
409
+ * @param offererSignature An EIP-712 signature from the offerer of the order.
410
+ * If this is not provided, the API key used to initialize the SDK must belong to the order's offerer.
411
+ * The signature must be a EIP-712 signature consisting of the order's Seaport contract's
412
+ * name, version, address, and chain. The struct to sign is `OrderHash` containing a
413
+ * single bytes32 field.
414
+ * @param useSignerToDeriveOffererSignature Derive the offererSignature from the Ethers signer passed into this sdk.
415
+ * @returns The response from the API.
416
+ */
417
+ async offchainCancelOrder(protocolAddress, orderHash, chain = this.chain, offererSignature, useSignerToDeriveOffererSignature) {
418
+ return this._cancellationManager.offchainCancelOrder(protocolAddress, orderHash, chain, offererSignature, useSignerToDeriveOffererSignature);
419
+ }
420
+ /**
421
+ * Returns whether an order is fulfillable.
422
+ * An order may not be fulfillable if a target item's transfer function
423
+ * is locked for some reason, e.g. an item is being rented within a game
424
+ * or trading has been locked for an item type.
425
+ * @param options
426
+ * @param options.order Order to check
427
+ * @param options.accountAddress The account address that will be fulfilling the order
428
+ * @returns True if the order is fulfillable, else False.
429
+ *
430
+ * @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
431
+ */
432
+ async isOrderFulfillable({ order, accountAddress, }) {
433
+ return this._fulfillmentManager.isOrderFulfillable({
434
+ order,
435
+ accountAddress,
436
+ });
437
+ }
438
+ /**
439
+ * Get an account's balance of any Asset. This asset can be an ERC20, ERC1155, or ERC721.
440
+ * @param options
441
+ * @param options.accountAddress Account address to check
442
+ * @param options.asset The Asset to check balance for. tokenStandard must be set.
443
+ * @returns The balance of the asset for the account.
444
+ *
445
+ * @throws Error if the token standard does not support balanceOf.
446
+ */
447
+ async getBalance({ accountAddress, asset, }) {
448
+ return this._assetsManager.getBalance({ accountAddress, asset });
449
+ }
450
+ /**
451
+ * Transfer an asset. This asset can be an ERC20, ERC1155, or ERC721.
452
+ * @param options
453
+ * @param options.asset The Asset to transfer. tokenStandard must be set.
454
+ * @param options.amount Amount of asset to transfer. Not used for ERC721.
455
+ * @param options.fromAddress The address to transfer from
456
+ * @param options.toAddress The address to transfer to
457
+ * @param options.overrides Transaction overrides, ignored if not set.
458
+ */
459
+ async transfer({ asset, amount, fromAddress, toAddress, overrides, }) {
460
+ return this._assetsManager.transfer({
461
+ asset,
462
+ amount,
463
+ fromAddress,
464
+ toAddress,
465
+ overrides,
466
+ });
467
+ }
468
+ /**
469
+ * Bulk transfer multiple assets using OpenSea's TransferHelper contract.
470
+ * This method is more gas-efficient than calling transfer() multiple times.
471
+ * Note: All assets must be approved for transfer to the OpenSea conduit before calling this method.
472
+ * @param options
473
+ * @param options.assets Array of assets to transfer. Each asset must have tokenStandard set.
474
+ * @param options.fromAddress The address to transfer from
475
+ * @param options.overrides Transaction overrides, ignored if not set.
476
+ * @returns Transaction hash of the bulk transfer
477
+ *
478
+ * @throws Error if any asset is missing required fields (tokenId for NFTs, amount for ERC20/ERC1155).
479
+ * @throws Error if any asset is not approved for transfer to the OpenSea conduit.
480
+ * @throws Error if the fromAddress is not available through wallet or provider.
481
+ */
482
+ async bulkTransfer({ assets, fromAddress, overrides, }) {
483
+ return this._assetsManager.bulkTransfer({
484
+ assets,
485
+ fromAddress,
486
+ overrides,
487
+ });
488
+ }
489
+ /**
490
+ * Batch approve multiple assets for transfer to the OpenSea conduit.
491
+ * This method checks which assets need approval and batches them efficiently:
492
+ * - 0 approvals needed: Returns early
493
+ * - 1 approval needed: Sends single transaction
494
+ * - 2+ approvals needed: Uses Multicall3 to batch all approvals in one transaction
495
+ *
496
+ * @param options
497
+ * @param options.assets Array of assets to approve for transfer
498
+ * @param options.fromAddress The address that owns the assets
499
+ * @param options.overrides Transaction overrides, ignored if not set.
500
+ * @returns Transaction hash of the approval transaction, or undefined if no approvals needed
501
+ *
502
+ * @throws Error if the fromAddress is not available through wallet or provider.
503
+ */
504
+ async batchApproveAssets({ assets, fromAddress, overrides, }) {
505
+ return this._assetsManager.batchApproveAssets({
506
+ assets,
507
+ fromAddress,
508
+ overrides,
509
+ });
510
+ }
511
+ /**
512
+ * Instead of signing an off-chain order, this method allows you to approve an order
513
+ * with an onchain transaction.
514
+ * @param order Order to approve
515
+ * @param domain An optional domain to be hashed and included at the end of fulfillment calldata. This can be used for onchain order attribution to assist with analytics.
516
+ * @returns Transaction hash of the approval transaction
517
+ *
518
+ * @throws Error if the accountAddress is not available through wallet or provider.
519
+ * @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
520
+ */
521
+ async approveOrder(order, domain) {
522
+ return this._fulfillmentManager.approveOrder(order, domain);
523
+ }
524
+ /**
525
+ * Validates an order onchain using Seaport's validate() method. This submits the order onchain
526
+ * and pre-validates the order using Seaport, which makes it cheaper to fulfill since a signature
527
+ * is not needed to be verified during fulfillment for the order, but is not strictly required
528
+ * and the alternative is orders can be submitted to the API for free instead of sent onchain.
529
+ * @param orderComponents Order components to validate onchain
530
+ * @param accountAddress Address of the wallet that will pay the gas to validate the order
531
+ * @returns Transaction hash of the validation transaction
532
+ *
533
+ * @throws Error if the accountAddress is not available through wallet or provider.
534
+ */
535
+ async validateOrderOnchain(orderComponents, accountAddress) {
536
+ return this._fulfillmentManager.validateOrderOnchain(orderComponents, accountAddress);
537
+ }
538
+ /**
539
+ * Create and validate a listing onchain. Combines order building with onchain validation.
540
+ * Validation costs gas upfront but makes fulfillment cheaper (no signature verification needed).
541
+ * @param options
542
+ * @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
543
+ * @param options.accountAddress Address of the wallet making the listing
544
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
545
+ * @param options.quantity Number of assets to list. Defaults to 1.
546
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
547
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
548
+ * @param options.listingTime When order becomes fulfillable (UTC seconds). Defaults to now.
549
+ * @param options.expirationTime Expiration time (UTC seconds).
550
+ * @param options.buyerAddress Optional buyer restriction. Only this address can purchase.
551
+ * @param options.includeOptionalCreatorFees Include optional creator fees. Default: false.
552
+ * @param options.zone Zone for order protection. Defaults to no zone.
553
+ * @returns Transaction hash
554
+ *
555
+ * @throws Error if asset missing token id or accountAddress unavailable.
556
+ */
557
+ async createListingAndValidateOnchain({ asset, accountAddress, amount, quantity = 1, domain, salt, listingTime, expirationTime, buyerAddress, includeOptionalCreatorFees = false, zone, }) {
558
+ return this._fulfillmentManager.createListingAndValidateOnchain({
559
+ asset,
560
+ accountAddress,
561
+ amount,
562
+ quantity,
563
+ domain,
564
+ salt,
565
+ listingTime,
566
+ expirationTime,
567
+ buyerAddress,
568
+ includeOptionalCreatorFees,
569
+ zone,
570
+ });
571
+ }
572
+ /**
573
+ * Create and validate an offer onchain. Combines order building with onchain validation.
574
+ * Validation costs gas upfront but makes fulfillment cheaper (no signature verification needed).
575
+ * @param options
576
+ * @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
577
+ * @param options.accountAddress Address of the wallet making the offer.
578
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
579
+ * @param options.quantity Number of assets to bid for. Defaults to 1.
580
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
581
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
582
+ * @param options.expirationTime Expiration time (UTC seconds).
583
+ * @param options.zone Zone for order protection. Defaults to chain's signed zone.
584
+ * @returns Transaction hash
585
+ *
586
+ * @throws Error if asset missing token id or accountAddress unavailable.
587
+ */
588
+ async createOfferAndValidateOnchain({ asset, accountAddress, amount, quantity = 1, domain, salt, expirationTime, zone, }) {
589
+ return this._fulfillmentManager.createOfferAndValidateOnchain({
590
+ asset,
591
+ accountAddress,
592
+ amount,
593
+ quantity,
594
+ domain,
595
+ salt,
596
+ expirationTime,
597
+ zone,
598
+ });
599
+ }
600
+ /**
601
+ * Compute the `basePrice` parameter to be used to price an order.
602
+ * Also validates the price and token address.
603
+ * @param tokenAddress Address of the ERC-20 token to use for trading. Use the null address for ETH.
604
+ * @param amount The value for the order, in the token's main units (e.g. ETH instead of wei)
605
+ */
606
+ async _getPriceParameters(orderSide, tokenAddress, amount) {
607
+ tokenAddress = tokenAddress.toLowerCase();
608
+ const isEther = tokenAddress === ethers_1.ethers.ZeroAddress;
609
+ let decimals = 18;
610
+ if (!isEther) {
611
+ if (tokenAddress in this._cachedPaymentTokenDecimals) {
612
+ decimals = this._cachedPaymentTokenDecimals[tokenAddress];
613
+ }
614
+ else {
615
+ const paymentToken = await this.api.getPaymentToken(tokenAddress);
616
+ this._cachedPaymentTokenDecimals[tokenAddress] = paymentToken.decimals;
617
+ decimals = paymentToken.decimals;
618
+ }
619
+ }
620
+ const amountWei = ethers_1.ethers.parseUnits(amount.toString(), decimals);
621
+ const basePrice = amountWei;
622
+ // Validation
623
+ if (amount == null || amountWei < 0) {
624
+ throw new Error("Starting price must be a number >= 0");
625
+ }
626
+ if (isEther && orderSide === types_1.OrderSide.OFFER) {
627
+ throw new Error("Offers must use wrapped ETH or an ERC-20 token.");
628
+ }
629
+ return { basePrice };
630
+ }
631
+ _dispatch(event, data) {
632
+ this._emitter.emit(event, data);
633
+ }
634
+ /** Get the accounts available from the signer or provider. */
635
+ async _getAvailableAccounts() {
636
+ const availableAccounts = [];
637
+ try {
638
+ if ("address" in this._signerOrProvider) {
639
+ availableAccounts.push(this._signerOrProvider.address);
640
+ }
641
+ else if ("listAccounts" in this._signerOrProvider) {
642
+ const addresses = (await this._signerOrProvider.listAccounts()).map(acct => acct.address);
643
+ availableAccounts.push(...addresses);
644
+ }
645
+ else if ("getAddress" in this._signerOrProvider) {
646
+ availableAccounts.push(await this._signerOrProvider.getAddress());
647
+ }
648
+ }
649
+ catch (error) {
650
+ // If we can't get accounts (e.g., RPC error), treat as no accounts available
651
+ this.logger(`Failed to get available accounts: ${error instanceof Error ? error.message : error}`);
652
+ }
653
+ return availableAccounts;
654
+ }
655
+ /**
656
+ * Throws an error if an account is not available through the provider.
657
+ * @param accountAddress The account address to check is available.
658
+ */
659
+ async _requireAccountIsAvailable(accountAddress) {
660
+ const accountAddressChecksummed = ethers_1.ethers.getAddress(accountAddress);
661
+ const availableAccounts = await this._getAvailableAccounts();
662
+ if (availableAccounts.includes(accountAddressChecksummed)) {
663
+ return;
664
+ }
665
+ throw new Error(`Specified accountAddress is not available through wallet or provider: ${accountAddressChecksummed}. Accounts available: ${availableAccounts.length > 0 ? availableAccounts.join(", ") : "none"}`);
666
+ }
667
+ /**
668
+ * Wait for a transaction to confirm and log the success or failure.
669
+ * @param transactionHash The transaction hash to wait for.
670
+ * @param event The event type to log.
671
+ * @param description The description of the transaction.
672
+ */
673
+ async _confirmTransaction(transactionHash, event, description) {
674
+ const transactionEventData = { transactionHash, event };
675
+ this.logger(`Transaction started: ${description}`);
676
+ try {
677
+ this._dispatch(types_1.EventType.TransactionCreated, transactionEventData);
678
+ await this.provider.waitForTransaction(transactionHash);
679
+ this.logger(`Transaction succeeded: ${description}`);
680
+ this._dispatch(types_1.EventType.TransactionConfirmed, transactionEventData);
681
+ }
682
+ catch (error) {
683
+ this.logger(`Transaction failed: ${description}`);
684
+ this._dispatch(types_1.EventType.TransactionFailed, {
685
+ ...transactionEventData,
686
+ error,
687
+ });
688
+ throw error;
689
+ }
690
+ }
691
+ }
692
+ exports.OpenSeaSDK = OpenSeaSDK;
693
+ //# sourceMappingURL=sdk.js.map