@opensea/sdk 9.0.0 → 10.1.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 (311) hide show
  1. package/README.md +35 -6
  2. package/lib/abi/abis.d.ts +301 -0
  3. package/lib/abi/abis.js +231 -0
  4. package/lib/abi/abis.js.map +1 -0
  5. package/lib/api/api.d.ts +26 -2
  6. package/lib/api/api.js +83 -51
  7. package/lib/api/api.js.map +1 -1
  8. package/lib/api/apiPaths.d.ts +2 -0
  9. package/lib/api/apiPaths.js +9 -1
  10. package/lib/api/apiPaths.js.map +1 -1
  11. package/lib/api/nfts.d.ts +13 -2
  12. package/lib/api/nfts.js +18 -0
  13. package/lib/api/nfts.js.map +1 -1
  14. package/lib/api/orders.js +2 -2
  15. package/lib/api/orders.js.map +1 -1
  16. package/lib/api/types.d.ts +7 -0
  17. package/lib/api/types.js.map +1 -1
  18. package/lib/constants.d.ts +2 -2
  19. package/lib/constants.js +7 -4
  20. package/lib/constants.js.map +1 -1
  21. package/lib/index.d.ts +2 -0
  22. package/lib/index.js +1 -0
  23. package/lib/index.js.map +1 -1
  24. package/lib/orders/privateListings.js +2 -2
  25. package/lib/orders/privateListings.js.map +1 -1
  26. package/lib/orders/utils.js +9 -1
  27. package/lib/orders/utils.js.map +1 -1
  28. package/lib/provider/ethers-adapter.d.ts +17 -0
  29. package/lib/provider/ethers-adapter.js +135 -0
  30. package/lib/provider/ethers-adapter.js.map +1 -0
  31. package/lib/provider/seaport-bridge.d.ts +11 -0
  32. package/lib/provider/seaport-bridge.js +130 -0
  33. package/lib/provider/seaport-bridge.js.map +1 -0
  34. package/lib/provider/types.d.ts +62 -0
  35. package/lib/provider/types.js +7 -0
  36. package/lib/provider/types.js.map +1 -0
  37. package/lib/provider/viem-adapter.d.ts +27 -0
  38. package/lib/provider/viem-adapter.js +122 -0
  39. package/lib/provider/viem-adapter.js.map +1 -0
  40. package/lib/sdk/assets.d.ts +7 -23
  41. package/lib/sdk/assets.js +101 -77
  42. package/lib/sdk/assets.js.map +1 -1
  43. package/lib/sdk/base.d.ts +350 -0
  44. package/lib/sdk/base.js +325 -0
  45. package/lib/sdk/base.js.map +1 -0
  46. package/lib/sdk/cancellation.d.ts +1 -2
  47. package/lib/sdk/cancellation.js +4 -4
  48. package/lib/sdk/cancellation.js.map +1 -1
  49. package/lib/sdk/context.d.ts +5 -5
  50. package/lib/sdk/fulfillment.d.ts +20 -59
  51. package/lib/sdk/fulfillment.js +18 -58
  52. package/lib/sdk/fulfillment.js.map +1 -1
  53. package/lib/sdk/orders.d.ts +25 -26
  54. package/lib/sdk/orders.js +8 -9
  55. package/lib/sdk/orders.js.map +1 -1
  56. package/lib/sdk/tokens.d.ts +3 -3
  57. package/lib/sdk/tokens.js +17 -7
  58. package/lib/sdk/tokens.js.map +1 -1
  59. package/lib/sdk.d.ts +16 -550
  60. package/lib/sdk.js +35 -663
  61. package/lib/sdk.js.map +1 -1
  62. package/lib/types.d.ts +11 -6
  63. package/lib/types.js +3 -3
  64. package/lib/types.js.map +1 -1
  65. package/lib/utils/address.d.ts +12 -0
  66. package/lib/utils/address.js +39 -0
  67. package/lib/utils/address.js.map +1 -0
  68. package/lib/utils/chain.d.ts +1 -1
  69. package/lib/utils/fees.d.ts +5 -0
  70. package/lib/utils/fees.js +24 -6
  71. package/lib/utils/fees.js.map +1 -1
  72. package/lib/utils/protocol.js +5 -5
  73. package/lib/utils/protocol.js.map +1 -1
  74. package/lib/utils/units.d.ts +12 -0
  75. package/lib/utils/units.js +43 -0
  76. package/lib/utils/units.js.map +1 -0
  77. package/lib/utils/utils.d.ts +2 -10
  78. package/lib/utils/utils.js +2 -17
  79. package/lib/utils/utils.js.map +1 -1
  80. package/lib/viem.d.ts +44 -0
  81. package/lib/viem.js +114 -0
  82. package/lib/viem.js.map +1 -0
  83. package/package.json +31 -13
  84. package/src/abi/abis.ts +236 -0
  85. package/src/api/api.ts +100 -59
  86. package/src/api/apiPaths.ts +16 -0
  87. package/src/api/nfts.ts +37 -1
  88. package/src/api/orders.ts +2 -2
  89. package/src/api/types.ts +8 -0
  90. package/src/constants.ts +7 -3
  91. package/src/index.ts +8 -0
  92. package/src/orders/privateListings.ts +2 -2
  93. package/src/orders/utils.ts +8 -1
  94. package/src/provider/ethers-adapter.ts +182 -0
  95. package/src/provider/seaport-bridge.ts +163 -0
  96. package/src/provider/types.ts +67 -0
  97. package/src/provider/viem-adapter.ts +165 -0
  98. package/src/sdk/assets.ts +128 -158
  99. package/src/sdk/base.ts +577 -0
  100. package/src/sdk/cancellation.ts +6 -9
  101. package/src/sdk/context.ts +5 -5
  102. package/src/sdk/fulfillment.ts +34 -73
  103. package/src/sdk/orders.ts +44 -44
  104. package/src/sdk/tokens.ts +18 -18
  105. package/src/sdk.ts +40 -1011
  106. package/src/types.ts +12 -6
  107. package/src/utils/address.ts +40 -0
  108. package/src/utils/fees.ts +28 -8
  109. package/src/utils/protocol.ts +5 -5
  110. package/src/utils/units.ts +47 -0
  111. package/src/utils/utils.ts +2 -22
  112. package/src/viem.ts +125 -0
  113. package/lib/src/api/accounts.d.ts +0 -18
  114. package/lib/src/api/accounts.js +0 -30
  115. package/lib/src/api/accounts.js.map +0 -1
  116. package/lib/src/api/api.d.ts +0 -429
  117. package/lib/src/api/api.js +0 -652
  118. package/lib/src/api/api.js.map +0 -1
  119. package/lib/src/api/apiPaths.d.ts +0 -37
  120. package/lib/src/api/apiPaths.js +0 -140
  121. package/lib/src/api/apiPaths.js.map +0 -1
  122. package/lib/src/api/collections.d.ts +0 -26
  123. package/lib/src/api/collections.js +0 -57
  124. package/lib/src/api/collections.js.map +0 -1
  125. package/lib/src/api/events.d.ts +0 -26
  126. package/lib/src/api/events.js +0 -42
  127. package/lib/src/api/events.js.map +0 -1
  128. package/lib/src/api/fetcher.d.ts +0 -24
  129. package/lib/src/api/fetcher.js +0 -3
  130. package/lib/src/api/fetcher.js.map +0 -1
  131. package/lib/src/api/index.d.ts +0 -2
  132. package/lib/src/api/index.js +0 -19
  133. package/lib/src/api/index.js.map +0 -1
  134. package/lib/src/api/listings.d.ts +0 -44
  135. package/lib/src/api/listings.js +0 -86
  136. package/lib/src/api/listings.js.map +0 -1
  137. package/lib/src/api/nfts.d.ts +0 -35
  138. package/lib/src/api/nfts.js +0 -66
  139. package/lib/src/api/nfts.js.map +0 -1
  140. package/lib/src/api/offers.d.ts +0 -54
  141. package/lib/src/api/offers.js +0 -122
  142. package/lib/src/api/offers.js.map +0 -1
  143. package/lib/src/api/orders.d.ts +0 -50
  144. package/lib/src/api/orders.js +0 -151
  145. package/lib/src/api/orders.js.map +0 -1
  146. package/lib/src/api/search.d.ts +0 -13
  147. package/lib/src/api/search.js +0 -21
  148. package/lib/src/api/search.js.map +0 -1
  149. package/lib/src/api/tokens.d.ts +0 -25
  150. package/lib/src/api/tokens.js +0 -42
  151. package/lib/src/api/tokens.js.map +0 -1
  152. package/lib/src/api/types.d.ts +0 -840
  153. package/lib/src/api/types.js +0 -65
  154. package/lib/src/api/types.js.map +0 -1
  155. package/lib/src/constants.d.ts +0 -22
  156. package/lib/src/constants.js +0 -52
  157. package/lib/src/constants.js.map +0 -1
  158. package/lib/src/index.d.ts +0 -18
  159. package/lib/src/index.js +0 -24
  160. package/lib/src/index.js.map +0 -1
  161. package/lib/src/orders/privateListings.d.ts +0 -12
  162. package/lib/src/orders/privateListings.js +0 -130
  163. package/lib/src/orders/privateListings.js.map +0 -1
  164. package/lib/src/orders/types.d.ts +0 -160
  165. package/lib/src/orders/types.js +0 -10
  166. package/lib/src/orders/types.js.map +0 -1
  167. package/lib/src/orders/utils.d.ts +0 -89
  168. package/lib/src/orders/utils.js +0 -177
  169. package/lib/src/orders/utils.js.map +0 -1
  170. package/lib/src/sdk/assets.d.ts +0 -104
  171. package/lib/src/sdk/assets.js +0 -397
  172. package/lib/src/sdk/assets.js.map +0 -1
  173. package/lib/src/sdk/cancellation.d.ts +0 -97
  174. package/lib/src/sdk/cancellation.js +0 -234
  175. package/lib/src/sdk/cancellation.js.map +0 -1
  176. package/lib/src/sdk/context.d.ts +0 -28
  177. package/lib/src/sdk/context.js +0 -3
  178. package/lib/src/sdk/context.js.map +0 -1
  179. package/lib/src/sdk/fulfillment.d.ts +0 -153
  180. package/lib/src/sdk/fulfillment.js +0 -296
  181. package/lib/src/sdk/fulfillment.js.map +0 -1
  182. package/lib/src/sdk/orders.d.ts +0 -253
  183. package/lib/src/sdk/orders.js +0 -677
  184. package/lib/src/sdk/orders.js.map +0 -1
  185. package/lib/src/sdk/tokens.d.ts +0 -31
  186. package/lib/src/sdk/tokens.js +0 -64
  187. package/lib/src/sdk/tokens.js.map +0 -1
  188. package/lib/src/sdk.d.ts +0 -560
  189. package/lib/src/sdk.js +0 -675
  190. package/lib/src/sdk.js.map +0 -1
  191. package/lib/src/typechain/contracts/ERC1155.d.ts +0 -236
  192. package/lib/src/typechain/contracts/ERC1155.js +0 -3
  193. package/lib/src/typechain/contracts/ERC1155.js.map +0 -1
  194. package/lib/src/typechain/contracts/ERC20.d.ts +0 -141
  195. package/lib/src/typechain/contracts/ERC20.js +0 -3
  196. package/lib/src/typechain/contracts/ERC20.js.map +0 -1
  197. package/lib/src/typechain/contracts/ERC721.d.ts +0 -213
  198. package/lib/src/typechain/contracts/ERC721.js +0 -3
  199. package/lib/src/typechain/contracts/ERC721.js.map +0 -1
  200. package/lib/src/typechain/contracts/Multicall3.d.ts +0 -57
  201. package/lib/src/typechain/contracts/Multicall3.js +0 -3
  202. package/lib/src/typechain/contracts/Multicall3.js.map +0 -1
  203. package/lib/src/typechain/contracts/TransferHelper.d.ts +0 -55
  204. package/lib/src/typechain/contracts/TransferHelper.js +0 -3
  205. package/lib/src/typechain/contracts/TransferHelper.js.map +0 -1
  206. package/lib/src/typechain/contracts/common.d.ts +0 -50
  207. package/lib/src/typechain/contracts/common.js +0 -3
  208. package/lib/src/typechain/contracts/common.js.map +0 -1
  209. package/lib/src/typechain/contracts/factories/ERC1155__factory.d.ts +0 -250
  210. package/lib/src/typechain/contracts/factories/ERC1155__factory.js +0 -332
  211. package/lib/src/typechain/contracts/factories/ERC1155__factory.js.map +0 -1
  212. package/lib/src/typechain/contracts/factories/ERC20__factory.d.ts +0 -174
  213. package/lib/src/typechain/contracts/factories/ERC20__factory.js +0 -240
  214. package/lib/src/typechain/contracts/factories/ERC20__factory.js.map +0 -1
  215. package/lib/src/typechain/contracts/factories/ERC721__factory.d.ts +0 -268
  216. package/lib/src/typechain/contracts/factories/ERC721__factory.js +0 -351
  217. package/lib/src/typechain/contracts/factories/ERC721__factory.js.map +0 -1
  218. package/lib/src/typechain/contracts/factories/Multicall3__factory.d.ts +0 -43
  219. package/lib/src/typechain/contracts/factories/Multicall3__factory.js +0 -68
  220. package/lib/src/typechain/contracts/factories/Multicall3__factory.js.map +0 -1
  221. package/lib/src/typechain/contracts/factories/TransferHelper__factory.d.ts +0 -46
  222. package/lib/src/typechain/contracts/factories/TransferHelper__factory.js +0 -71
  223. package/lib/src/typechain/contracts/factories/TransferHelper__factory.js.map +0 -1
  224. package/lib/src/typechain/contracts/factories/index.d.ts +0 -5
  225. package/lib/src/typechain/contracts/factories/index.js +0 -17
  226. package/lib/src/typechain/contracts/factories/index.js.map +0 -1
  227. package/lib/src/typechain/contracts/index.d.ts +0 -11
  228. package/lib/src/typechain/contracts/index.js +0 -48
  229. package/lib/src/typechain/contracts/index.js.map +0 -1
  230. package/lib/src/types.d.ts +0 -387
  231. package/lib/src/types.js +0 -127
  232. package/lib/src/types.js.map +0 -1
  233. package/lib/src/utils/chain.d.ts +0 -60
  234. package/lib/src/utils/chain.js +0 -248
  235. package/lib/src/utils/chain.js.map +0 -1
  236. package/lib/src/utils/converters.d.ts +0 -37
  237. package/lib/src/utils/converters.js +0 -137
  238. package/lib/src/utils/converters.js.map +0 -1
  239. package/lib/src/utils/dateHelper.d.ts +0 -38
  240. package/lib/src/utils/dateHelper.js +0 -52
  241. package/lib/src/utils/dateHelper.js.map +0 -1
  242. package/lib/src/utils/fees.d.ts +0 -13
  243. package/lib/src/utils/fees.js +0 -29
  244. package/lib/src/utils/fees.js.map +0 -1
  245. package/lib/src/utils/index.d.ts +0 -2
  246. package/lib/src/utils/index.js +0 -19
  247. package/lib/src/utils/index.js.map +0 -1
  248. package/lib/src/utils/protocol.d.ts +0 -75
  249. package/lib/src/utils/protocol.js +0 -161
  250. package/lib/src/utils/protocol.js.map +0 -1
  251. package/lib/src/utils/rateLimit.d.ts +0 -34
  252. package/lib/src/utils/rateLimit.js +0 -97
  253. package/lib/src/utils/rateLimit.js.map +0 -1
  254. package/lib/src/utils/stringHelper.d.ts +0 -18
  255. package/lib/src/utils/stringHelper.js +0 -24
  256. package/lib/src/utils/stringHelper.js.map +0 -1
  257. package/lib/src/utils/utils.d.ts +0 -18
  258. package/lib/src/utils/utils.js +0 -45
  259. package/lib/src/utils/utils.js.map +0 -1
  260. package/lib/typechain/contracts/ERC1155.d.ts +0 -236
  261. package/lib/typechain/contracts/ERC1155.js +0 -3
  262. package/lib/typechain/contracts/ERC1155.js.map +0 -1
  263. package/lib/typechain/contracts/ERC20.d.ts +0 -141
  264. package/lib/typechain/contracts/ERC20.js +0 -3
  265. package/lib/typechain/contracts/ERC20.js.map +0 -1
  266. package/lib/typechain/contracts/ERC721.d.ts +0 -213
  267. package/lib/typechain/contracts/ERC721.js +0 -3
  268. package/lib/typechain/contracts/ERC721.js.map +0 -1
  269. package/lib/typechain/contracts/Multicall3.d.ts +0 -57
  270. package/lib/typechain/contracts/Multicall3.js +0 -3
  271. package/lib/typechain/contracts/Multicall3.js.map +0 -1
  272. package/lib/typechain/contracts/TransferHelper.d.ts +0 -55
  273. package/lib/typechain/contracts/TransferHelper.js +0 -3
  274. package/lib/typechain/contracts/TransferHelper.js.map +0 -1
  275. package/lib/typechain/contracts/common.d.ts +0 -50
  276. package/lib/typechain/contracts/common.js +0 -3
  277. package/lib/typechain/contracts/common.js.map +0 -1
  278. package/lib/typechain/contracts/factories/ERC1155__factory.d.ts +0 -250
  279. package/lib/typechain/contracts/factories/ERC1155__factory.js +0 -332
  280. package/lib/typechain/contracts/factories/ERC1155__factory.js.map +0 -1
  281. package/lib/typechain/contracts/factories/ERC20__factory.d.ts +0 -174
  282. package/lib/typechain/contracts/factories/ERC20__factory.js +0 -240
  283. package/lib/typechain/contracts/factories/ERC20__factory.js.map +0 -1
  284. package/lib/typechain/contracts/factories/ERC721__factory.d.ts +0 -268
  285. package/lib/typechain/contracts/factories/ERC721__factory.js +0 -351
  286. package/lib/typechain/contracts/factories/ERC721__factory.js.map +0 -1
  287. package/lib/typechain/contracts/factories/Multicall3__factory.d.ts +0 -43
  288. package/lib/typechain/contracts/factories/Multicall3__factory.js +0 -68
  289. package/lib/typechain/contracts/factories/Multicall3__factory.js.map +0 -1
  290. package/lib/typechain/contracts/factories/TransferHelper__factory.d.ts +0 -46
  291. package/lib/typechain/contracts/factories/TransferHelper__factory.js +0 -71
  292. package/lib/typechain/contracts/factories/TransferHelper__factory.js.map +0 -1
  293. package/lib/typechain/contracts/factories/index.d.ts +0 -5
  294. package/lib/typechain/contracts/factories/index.js +0 -17
  295. package/lib/typechain/contracts/factories/index.js.map +0 -1
  296. package/lib/typechain/contracts/index.d.ts +0 -11
  297. package/lib/typechain/contracts/index.js +0 -48
  298. package/lib/typechain/contracts/index.js.map +0 -1
  299. package/src/typechain/contracts/ERC1155.ts +0 -440
  300. package/src/typechain/contracts/ERC20.ts +0 -286
  301. package/src/typechain/contracts/ERC721.ts +0 -412
  302. package/src/typechain/contracts/Multicall3.ts +0 -117
  303. package/src/typechain/contracts/TransferHelper.ts +0 -122
  304. package/src/typechain/contracts/common.ts +0 -131
  305. package/src/typechain/contracts/factories/ERC1155__factory.ts +0 -331
  306. package/src/typechain/contracts/factories/ERC20__factory.ts +0 -239
  307. package/src/typechain/contracts/factories/ERC721__factory.ts +0 -350
  308. package/src/typechain/contracts/factories/Multicall3__factory.ts +0 -67
  309. package/src/typechain/contracts/factories/TransferHelper__factory.ts +0 -76
  310. package/src/typechain/contracts/factories/index.ts +0 -8
  311. package/src/typechain/contracts/index.ts +0 -14
@@ -0,0 +1,577 @@
1
+ import EventEmitter = require("node:events")
2
+
3
+ import type { Seaport } from "@opensea/seaport-js"
4
+ import type { OrderComponents } from "@opensea/seaport-js/lib/types"
5
+ import type { OpenSeaAPI } from "../api/api"
6
+ import type { CollectionOffer, Listing, Offer, Order } from "../api/types"
7
+ import { ZERO_ADDRESS } from "../constants"
8
+ import type { OrderV2 } from "../orders/types"
9
+ import type { ContractCaller, OpenSeaWallet } from "../provider/types"
10
+ import type {
11
+ Amount,
12
+ AssetWithTokenId,
13
+ AssetWithTokenStandard,
14
+ Chain,
15
+ EventData,
16
+ OpenSeaAPIConfig,
17
+ } from "../types"
18
+ import { EventType, OrderSide } from "../types"
19
+ import { checksumAddress } from "../utils/address"
20
+ import { parseUnits } from "../utils/units"
21
+ import { AssetsManager } from "./assets"
22
+ import { CancellationManager } from "./cancellation"
23
+ import { FulfillmentManager } from "./fulfillment"
24
+ import { type BulkOrderResult, OrdersManager } from "./orders"
25
+ import { TokensManager } from "./tokens"
26
+
27
+ /**
28
+ * Configuration passed to the base SDK by entry-point constructors.
29
+ */
30
+ export interface BaseSDKConfig {
31
+ wallet: OpenSeaWallet
32
+ contractCaller: ContractCaller
33
+ seaport: Seaport
34
+ api: OpenSeaAPI
35
+ chain: Chain
36
+ logger: (arg: string) => void
37
+ /** Get available account addresses for requireAccountIsAvailable checks */
38
+ getAvailableAccounts: () => Promise<string[]>
39
+ cachedPaymentTokenDecimals: { [address: string]: number }
40
+ }
41
+
42
+ /**
43
+ * Base OpenSea SDK class containing all shared business logic.
44
+ * Entry-point classes (ethers, viem) extend this and only differ in constructor.
45
+ * @category Main Classes
46
+ */
47
+ export class BaseOpenSeaSDK {
48
+ /** Seaport client @see {@link https://github.com/ProjectOpenSea/seaport-js} */
49
+ public seaport: Seaport
50
+ /** Logger function to use when debugging */
51
+ public logger: (arg: string) => void
52
+ /** API instance */
53
+ public readonly api: OpenSeaAPI
54
+ /** The configured chain */
55
+ public readonly chain: Chain
56
+
57
+ protected _wallet: OpenSeaWallet
58
+ protected _contractCaller: ContractCaller
59
+ private _emitter: EventEmitter
60
+ private _cachedPaymentTokenDecimals: { [address: string]: number }
61
+ private _getAvailableAccounts: () => Promise<string[]>
62
+
63
+ // Manager instances
64
+ private _tokensManager: TokensManager
65
+ private _assetsManager: AssetsManager
66
+ private _cancellationManager: CancellationManager
67
+ private _ordersManager: OrdersManager
68
+ private _fulfillmentManager: FulfillmentManager
69
+
70
+ protected constructor(config: BaseSDKConfig) {
71
+ this.chain = config.chain
72
+ this.api = config.api
73
+ this.seaport = config.seaport
74
+ this.logger = config.logger
75
+ this._wallet = config.wallet
76
+ this._contractCaller = config.contractCaller
77
+ this._cachedPaymentTokenDecimals = config.cachedPaymentTokenDecimals
78
+ this._getAvailableAccounts = config.getAvailableAccounts
79
+ this._emitter = new EventEmitter()
80
+
81
+ const context = {
82
+ chain: this.chain,
83
+ wallet: this._wallet,
84
+ contractCaller: this._contractCaller,
85
+ api: this.api,
86
+ seaport: this.seaport,
87
+ logger: this.logger,
88
+ dispatch: this._dispatch.bind(this),
89
+ confirmTransaction: this._confirmTransaction.bind(this),
90
+ requireAccountIsAvailable: this._requireAccountIsAvailable.bind(this),
91
+ }
92
+
93
+ this._tokensManager = new TokensManager(context)
94
+ this._assetsManager = new AssetsManager(context)
95
+ this._cancellationManager = new CancellationManager(context)
96
+ this._ordersManager = new OrdersManager(
97
+ context,
98
+ this._getPriceParameters.bind(this),
99
+ )
100
+ this._fulfillmentManager = new FulfillmentManager(
101
+ context,
102
+ this._ordersManager,
103
+ )
104
+ }
105
+
106
+ // ─── Event Listeners ───────────────────────────────────────────────
107
+
108
+ /**
109
+ * Add a listener for events emitted by the SDK.
110
+ * @param event The {@link EventType} to listen to.
111
+ * @param listener A callback that will accept an object with {@link EventData}
112
+ * @param once Whether the listener should only be called once.
113
+ */
114
+ public addListener(
115
+ event: EventType,
116
+ listener: (data: EventData) => void,
117
+ once = false,
118
+ ) {
119
+ if (once) {
120
+ this._emitter.once(event, listener)
121
+ } else {
122
+ this._emitter.addListener(event, listener)
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Remove an event listener.
128
+ * @param event The {@link EventType} to remove a listener for
129
+ * @param listener The listener to remove
130
+ */
131
+ public removeListener(event: EventType, listener: (data: EventData) => void) {
132
+ this._emitter.removeListener(event, listener)
133
+ }
134
+
135
+ /**
136
+ * Remove all event listeners. Call when unmounting a component that listens to events.
137
+ * @param event Optional EventType to remove listeners for
138
+ */
139
+ public removeAllListeners(event?: EventType) {
140
+ this._emitter.removeAllListeners(event)
141
+ }
142
+
143
+ // ─── Token Operations ──────────────────────────────────────────────
144
+
145
+ /**
146
+ * Wrap native asset into wrapped native asset (e.g. ETH into WETH, POL into WPOL).
147
+ * Wrapped native assets are needed for making offers.
148
+ * @param options
149
+ * @param options.amountInEth Amount of native asset to wrap
150
+ * @param options.accountAddress Address of the user's wallet containing the native asset
151
+ */
152
+ public async wrapEth(options: {
153
+ amountInEth: Amount
154
+ accountAddress: string
155
+ }) {
156
+ return this._tokensManager.wrapEth(options)
157
+ }
158
+
159
+ /**
160
+ * Unwrap wrapped native asset into native asset (e.g. WETH into ETH, WPOL into POL).
161
+ * Emits the `UnwrapWeth` event when the transaction is prompted.
162
+ * @param options
163
+ * @param options.amountInEth How much wrapped native asset to unwrap
164
+ * @param options.accountAddress Address of the user's wallet containing the wrapped native asset
165
+ */
166
+ public async unwrapWeth(options: {
167
+ amountInEth: Amount
168
+ accountAddress: string
169
+ }) {
170
+ return this._tokensManager.unwrapWeth(options)
171
+ }
172
+
173
+ // ─── Order Creation ────────────────────────────────────────────────
174
+
175
+ /**
176
+ * Create and submit an offer on 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 offer.
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 bid for. Defaults to 1.
182
+ * @param options.domain Optional domain for onchain attribution.
183
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
184
+ * @param options.expirationTime Expiration time for the order, in UTC seconds
185
+ * @param options.zone Zone for order protection. Defaults to chain's signed zone.
186
+ * @returns The {@link OrderV2} that was created.
187
+ */
188
+ public async createOffer(options: {
189
+ asset: AssetWithTokenId
190
+ accountAddress: string
191
+ amount: Amount
192
+ quantity?: Amount
193
+ domain?: string
194
+ salt?: Amount
195
+ expirationTime?: Amount
196
+ zone?: string
197
+ }): Promise<OrderV2> {
198
+ return this._ordersManager.createOffer(options)
199
+ }
200
+
201
+ /**
202
+ * Create and submit a listing for an asset.
203
+ * @param options
204
+ * @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
205
+ * @param options.accountAddress Address of the wallet making the listing
206
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
207
+ * @param options.quantity Number of assets to list. Defaults to 1.
208
+ * @param options.domain Optional domain for onchain attribution.
209
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
210
+ * @param options.listingTime Optional time when the order will become fulfillable, in UTC seconds.
211
+ * @param options.expirationTime Expiration time for the order, in UTC seconds.
212
+ * @param options.buyerAddress Optional address that's allowed to purchase this item.
213
+ * @param options.includeOptionalCreatorFees If true, optional creator fees will be included. Default: false.
214
+ * @param options.zone Zone for order protection. Defaults to no zone.
215
+ * @returns The {@link OrderV2} that was created.
216
+ */
217
+ public async createListing(options: {
218
+ asset: AssetWithTokenId
219
+ accountAddress: string
220
+ amount: Amount
221
+ quantity?: Amount
222
+ domain?: string
223
+ salt?: Amount
224
+ listingTime?: number
225
+ expirationTime?: number
226
+ buyerAddress?: string
227
+ includeOptionalCreatorFees?: boolean
228
+ zone?: string
229
+ }): Promise<OrderV2> {
230
+ return this._ordersManager.createListing(options)
231
+ }
232
+
233
+ /** Create and submit multiple listings using Seaport's bulk order creation. */
234
+ public async createBulkListings(options: {
235
+ listings: Array<{
236
+ asset: AssetWithTokenId
237
+ amount: Amount
238
+ quantity?: Amount
239
+ domain?: string
240
+ salt?: Amount
241
+ listingTime?: number
242
+ expirationTime?: number
243
+ buyerAddress?: string
244
+ includeOptionalCreatorFees?: boolean
245
+ zone?: string
246
+ }>
247
+ accountAddress: string
248
+ continueOnError?: boolean
249
+ onProgress?: (completed: number, total: number) => void
250
+ }): Promise<BulkOrderResult> {
251
+ return this._ordersManager.createBulkListings(options)
252
+ }
253
+
254
+ /** Create and submit multiple offers using Seaport's bulk order creation. */
255
+ public async createBulkOffers(options: {
256
+ offers: Array<{
257
+ asset: AssetWithTokenId
258
+ amount: Amount
259
+ quantity?: Amount
260
+ domain?: string
261
+ salt?: Amount
262
+ expirationTime?: Amount
263
+ zone?: string
264
+ }>
265
+ accountAddress: string
266
+ continueOnError?: boolean
267
+ onProgress?: (completed: number, total: number) => void
268
+ }): Promise<BulkOrderResult> {
269
+ return this._ordersManager.createBulkOffers(options)
270
+ }
271
+
272
+ /** Create and submit a collection offer. */
273
+ public async createCollectionOffer(options: {
274
+ collectionSlug: string
275
+ accountAddress: string
276
+ amount: Amount
277
+ quantity: number
278
+ domain?: string
279
+ salt?: Amount
280
+ expirationTime?: number | string
281
+ offerProtectionEnabled?: boolean
282
+ traitType?: string
283
+ traitValue?: string
284
+ traits?: Array<{ type: string; value: string }>
285
+ numericTraits?: Array<{ type: string; min?: number; max?: number }>
286
+ }): Promise<CollectionOffer | null> {
287
+ return this._ordersManager.createCollectionOffer(options)
288
+ }
289
+
290
+ // ─── Order Fulfillment ─────────────────────────────────────────────
291
+
292
+ /**
293
+ * Fulfill an order for an asset. The order can be either a listing or an offer.
294
+ * Uses the OpenSea API to generate fulfillment transaction data and executes it directly.
295
+ * @param options
296
+ * @param options.order The order to fulfill, a.k.a. "take"
297
+ * @param options.accountAddress Address of the wallet taking the offer.
298
+ * @param options.assetContractAddress Optional address of the NFT contract for criteria offers.
299
+ * @param options.tokenId Optional token ID for criteria offers.
300
+ * @param options.unitsToFill Optional number of units to fill. Defaults to 1.
301
+ * @param options.recipientAddress Optional recipient address for the NFT when fulfilling a listing.
302
+ * @param options.includeOptionalCreatorFees Whether to include optional creator fees. Defaults to false.
303
+ * @param options.overrides Transaction overrides (gasLimit, maxFeePerGas, etc.).
304
+ * @returns Transaction hash of the order.
305
+ */
306
+ public async fulfillOrder(options: {
307
+ order: OrderV2 | Order | Listing | Offer
308
+ accountAddress: string
309
+ assetContractAddress?: string
310
+ tokenId?: string
311
+ unitsToFill?: Amount
312
+ recipientAddress?: string
313
+ includeOptionalCreatorFees?: boolean
314
+ overrides?: Record<string, unknown>
315
+ }): Promise<string> {
316
+ return this._fulfillmentManager.fulfillOrder(options)
317
+ }
318
+
319
+ /**
320
+ * Fulfill a private listing directly using Seaport's matchOrders.
321
+ * The order must have a taker address set (i.e., it is a private listing).
322
+ * @param options
323
+ * @param options.order The private listing order to fulfill. Must have a taker address.
324
+ * @param options.accountAddress Address of the wallet fulfilling the order.
325
+ * @param options.domain Optional domain for onchain attribution.
326
+ * @param options.overrides Transaction overrides (gasLimit, maxFeePerGas, etc.).
327
+ * @returns Transaction hash of the fulfillment.
328
+ */
329
+ public async fulfillPrivateOrder(options: {
330
+ order: OrderV2
331
+ accountAddress: string
332
+ domain?: string
333
+ overrides?: Record<string, unknown>
334
+ }): Promise<string> {
335
+ return this._fulfillmentManager.fulfillPrivateOrder(options)
336
+ }
337
+
338
+ /** Returns whether an order is fulfillable. */
339
+ public async isOrderFulfillable(options: {
340
+ order: OrderV2
341
+ accountAddress: string
342
+ }): Promise<boolean> {
343
+ return this._fulfillmentManager.isOrderFulfillable(options)
344
+ }
345
+
346
+ /** Approve an order with an onchain transaction. */
347
+ public async approveOrder(order: OrderV2, domain?: string) {
348
+ return this._fulfillmentManager.approveOrder(order, domain)
349
+ }
350
+
351
+ /** Validates an order onchain using Seaport's validate() method. */
352
+ public async validateOrderOnchain(
353
+ orderComponents: OrderComponents,
354
+ accountAddress: string,
355
+ ) {
356
+ return this._fulfillmentManager.validateOrderOnchain(
357
+ orderComponents,
358
+ accountAddress,
359
+ )
360
+ }
361
+
362
+ /** Create and validate a listing onchain. */
363
+ public async createListingAndValidateOnchain(options: {
364
+ asset: AssetWithTokenId
365
+ accountAddress: string
366
+ amount: Amount
367
+ quantity?: Amount
368
+ domain?: string
369
+ salt?: Amount
370
+ listingTime?: number
371
+ expirationTime?: number
372
+ buyerAddress?: string
373
+ includeOptionalCreatorFees?: boolean
374
+ zone?: string
375
+ }): Promise<string> {
376
+ return this._fulfillmentManager.createListingAndValidateOnchain(options)
377
+ }
378
+
379
+ /** Create and validate an offer onchain. */
380
+ public async createOfferAndValidateOnchain(options: {
381
+ asset: AssetWithTokenId
382
+ accountAddress: string
383
+ amount: Amount
384
+ quantity?: Amount
385
+ domain?: string
386
+ salt?: Amount
387
+ expirationTime?: Amount
388
+ zone?: string
389
+ }): Promise<string> {
390
+ return this._fulfillmentManager.createOfferAndValidateOnchain(options)
391
+ }
392
+
393
+ // ─── Order Cancellation ────────────────────────────────────────────
394
+
395
+ /**
396
+ * Cancel multiple orders onchain, preventing them from being fulfilled.
397
+ * @param options
398
+ * @param options.orders Array of orders to cancel. Can be OrderV2 objects or OrderComponents.
399
+ * @param options.orderHashes Optional array of order hashes to cancel.
400
+ * @param options.accountAddress The account address cancelling the orders.
401
+ * @param options.protocolAddress The Seaport protocol address for the orders.
402
+ * @param options.domain Optional domain for onchain attribution.
403
+ * @param options.overrides Transaction overrides (gasLimit, maxFeePerGas, etc.).
404
+ * @returns Transaction hash of the cancellation.
405
+ */
406
+ public async cancelOrders(options: {
407
+ orders?: Array<OrderV2 | OrderComponents>
408
+ orderHashes?: string[]
409
+ accountAddress: string
410
+ protocolAddress?: string
411
+ domain?: string
412
+ overrides?: Record<string, unknown>
413
+ }): Promise<string> {
414
+ return this._cancellationManager.cancelOrders(options)
415
+ }
416
+
417
+ /** Cancel an order onchain, preventing it from ever being fulfilled. */
418
+ public async cancelOrder(options: {
419
+ order?: OrderV2
420
+ orderHash?: string
421
+ accountAddress: string
422
+ protocolAddress?: string
423
+ domain?: string
424
+ }) {
425
+ return this._cancellationManager.cancelOrder(options)
426
+ }
427
+
428
+ /** Offchain cancel an order by its order hash when protected by the SignedZone. */
429
+ public async offchainCancelOrder(
430
+ protocolAddress: string,
431
+ orderHash: string,
432
+ chain: Chain = this.chain,
433
+ offererSignature?: string,
434
+ useSignerToDeriveOffererSignature?: boolean,
435
+ ) {
436
+ return this._cancellationManager.offchainCancelOrder(
437
+ protocolAddress,
438
+ orderHash,
439
+ chain,
440
+ offererSignature,
441
+ useSignerToDeriveOffererSignature,
442
+ )
443
+ }
444
+
445
+ // ─── Asset Operations ──────────────────────────────────────────────
446
+
447
+ /**
448
+ * Get an account's balance of any Asset.
449
+ */
450
+ public async getBalance(options: {
451
+ accountAddress: string
452
+ asset: AssetWithTokenStandard
453
+ }): Promise<bigint> {
454
+ return this._assetsManager.getBalance(options)
455
+ }
456
+
457
+ /**
458
+ * Transfer an asset. This asset can be an ERC20, ERC1155, or ERC721.
459
+ * @param options
460
+ * @param options.asset The Asset to transfer. tokenStandard must be set.
461
+ * @param options.amount Amount of asset to transfer. Not used for ERC721.
462
+ * @param options.fromAddress The address to transfer from
463
+ * @param options.toAddress The address to transfer to
464
+ * @param options.overrides Transaction overrides (gasLimit, maxFeePerGas, etc.).
465
+ */
466
+ public async transfer(options: {
467
+ asset: AssetWithTokenStandard
468
+ amount?: Amount
469
+ fromAddress: string
470
+ toAddress: string
471
+ overrides?: Record<string, unknown>
472
+ }): Promise<void> {
473
+ return this._assetsManager.transfer(options)
474
+ }
475
+
476
+ /** Bulk transfer multiple assets using OpenSea's TransferHelper contract. */
477
+ public async bulkTransfer(options: {
478
+ assets: Array<{
479
+ asset: AssetWithTokenStandard
480
+ toAddress: string
481
+ amount?: Amount
482
+ }>
483
+ fromAddress: string
484
+ overrides?: Record<string, unknown>
485
+ }): Promise<string> {
486
+ return this._assetsManager.bulkTransfer(options)
487
+ }
488
+
489
+ /** Batch approve multiple assets for transfer to the OpenSea conduit. */
490
+ public async batchApproveAssets(options: {
491
+ assets: Array<{
492
+ asset: AssetWithTokenStandard
493
+ amount?: Amount
494
+ }>
495
+ fromAddress: string
496
+ overrides?: Record<string, unknown>
497
+ }): Promise<string | undefined> {
498
+ return this._assetsManager.batchApproveAssets(options)
499
+ }
500
+
501
+ // ─── Private Helpers ───────────────────────────────────────────────
502
+
503
+ /**
504
+ * Compute the `basePrice` parameter to be used to price an order.
505
+ */
506
+ private async _getPriceParameters(
507
+ orderSide: OrderSide,
508
+ tokenAddress: string,
509
+ amount: Amount,
510
+ ) {
511
+ tokenAddress = tokenAddress.toLowerCase()
512
+ const isEther = tokenAddress === ZERO_ADDRESS
513
+ let decimals = 18
514
+ if (!isEther) {
515
+ if (tokenAddress in this._cachedPaymentTokenDecimals) {
516
+ decimals = this._cachedPaymentTokenDecimals[tokenAddress]
517
+ } else {
518
+ const paymentToken = await this.api.getPaymentToken(tokenAddress)
519
+ this._cachedPaymentTokenDecimals[tokenAddress] = paymentToken.decimals
520
+ decimals = paymentToken.decimals
521
+ }
522
+ }
523
+
524
+ const amountWei = parseUnits(amount.toString(), decimals)
525
+ const basePrice = amountWei
526
+
527
+ if (amount == null || amountWei < 0) {
528
+ throw new Error("Starting price must be a number >= 0")
529
+ }
530
+ if (isEther && orderSide === OrderSide.OFFER) {
531
+ throw new Error("Offers must use wrapped ETH or an ERC-20 token.")
532
+ }
533
+ return { basePrice }
534
+ }
535
+
536
+ private _dispatch(event: EventType, data: EventData) {
537
+ this._emitter.emit(event, data)
538
+ }
539
+
540
+ private async _requireAccountIsAvailable(accountAddress: string) {
541
+ const checksummed = checksumAddress(accountAddress)
542
+ const availableAccounts = await this._getAvailableAccounts()
543
+
544
+ if (availableAccounts.includes(checksummed)) {
545
+ return
546
+ }
547
+
548
+ throw new Error(
549
+ `Specified accountAddress is not available through wallet or provider: ${checksummed}. Accounts available: ${
550
+ availableAccounts.length > 0 ? availableAccounts.join(", ") : "none"
551
+ }`,
552
+ )
553
+ }
554
+
555
+ private async _confirmTransaction(
556
+ transactionHash: string,
557
+ event: EventType,
558
+ description: string,
559
+ ): Promise<void> {
560
+ const transactionEventData = { transactionHash, event }
561
+ this.logger(`Transaction started: ${description}`)
562
+
563
+ try {
564
+ this._dispatch(EventType.TransactionCreated, transactionEventData)
565
+ await this._wallet.provider.waitForTransaction(transactionHash)
566
+ this.logger(`Transaction succeeded: ${description}`)
567
+ this._dispatch(EventType.TransactionConfirmed, transactionEventData)
568
+ } catch (error) {
569
+ this.logger(`Transaction failed: ${description}`)
570
+ this._dispatch(EventType.TransactionFailed, {
571
+ ...transactionEventData,
572
+ error,
573
+ })
574
+ throw error
575
+ }
576
+ }
577
+ }
@@ -1,5 +1,4 @@
1
1
  import type { OrderComponents } from "@opensea/seaport-js/lib/types"
2
- import type { Overrides, Signer } from "ethers"
3
2
  import type { Listing, Offer } from "../api/types"
4
3
  import type { OrderV2 } from "../orders/types"
5
4
  import { DEFAULT_SEAPORT_CONTRACT_ADDRESS } from "../orders/utils"
@@ -140,7 +139,7 @@ export class CancellationManager {
140
139
  accountAddress: string
141
140
  protocolAddress?: string
142
141
  domain?: string
143
- overrides?: Overrides
142
+ overrides?: Record<string, unknown>
144
143
  }): Promise<string> {
145
144
  // Validate input before making any external calls
146
145
  if (!orders && !orderHashes) {
@@ -267,7 +266,7 @@ export class CancellationManager {
267
266
  accountAddress: string
268
267
  domain?: string
269
268
  protocolAddress?: string
270
- overrides?: Overrides
269
+ overrides?: Record<string, unknown>
271
270
  }): Promise<string> {
272
271
  const seaport = getSeaportInstance(protocolAddress, this.context.seaport)
273
272
 
@@ -291,16 +290,14 @@ export class CancellationManager {
291
290
  const name = "Seaport"
292
291
  const version = getSeaportVersion(protocolAddress)
293
292
 
294
- if (
295
- typeof (this.context.signerOrProvider as Signer).signTypedData ===
296
- "undefined"
297
- ) {
293
+ const wallet = this.context.wallet
294
+ if (!("signer" in wallet)) {
298
295
  throw new Error(
299
- "Please pass an ethers Signer into this sdk to derive an offerer signature",
296
+ "Please pass a Signer into this SDK to derive an offerer signature",
300
297
  )
301
298
  }
302
299
 
303
- return (this.context.signerOrProvider as Signer).signTypedData(
300
+ return wallet.signer.signTypedData(
304
301
  { chainId, name, version, verifyingContract: protocolAddress },
305
302
  { OrderHash: [{ name: "orderHash", type: "bytes32" }] },
306
303
  { orderHash },
@@ -1,6 +1,6 @@
1
1
  import type { Seaport } from "@opensea/seaport-js"
2
- import type { JsonRpcProvider, Signer } from "ethers"
3
2
  import type { OpenSeaAPI } from "../api/api"
3
+ import type { ContractCaller, OpenSeaWallet } from "../provider/types"
4
4
  import type { Chain, EventData, EventType } from "../types"
5
5
 
6
6
  /**
@@ -10,10 +10,10 @@ import type { Chain, EventData, EventType } from "../types"
10
10
  export interface SDKContext {
11
11
  /** The blockchain chain being used */
12
12
  chain: Chain
13
- /** Signer or provider for blockchain interactions */
14
- signerOrProvider: Signer | JsonRpcProvider
15
- /** JSON-RPC provider for read operations */
16
- provider: JsonRpcProvider
13
+ /** Abstract wallet (signer + provider) */
14
+ wallet: OpenSeaWallet
15
+ /** Contract read/write caller */
16
+ contractCaller: ContractCaller
17
17
  /** OpenSea API client */
18
18
  api: OpenSeaAPI
19
19
  /** Seaport client instance */