@opensea/sdk 9.0.0 → 10.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 (300) hide show
  1. package/README.md +25 -4
  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 +6 -1
  6. package/lib/api/api.js +60 -51
  7. package/lib/api/api.js.map +1 -1
  8. package/lib/api/orders.js +2 -2
  9. package/lib/api/orders.js.map +1 -1
  10. package/lib/constants.d.ts +2 -2
  11. package/lib/constants.js +7 -4
  12. package/lib/constants.js.map +1 -1
  13. package/lib/index.d.ts +2 -0
  14. package/lib/index.js +1 -0
  15. package/lib/index.js.map +1 -1
  16. package/lib/orders/privateListings.js +2 -2
  17. package/lib/orders/privateListings.js.map +1 -1
  18. package/lib/orders/utils.js +9 -1
  19. package/lib/orders/utils.js.map +1 -1
  20. package/lib/provider/ethers-adapter.d.ts +17 -0
  21. package/lib/provider/ethers-adapter.js +135 -0
  22. package/lib/provider/ethers-adapter.js.map +1 -0
  23. package/lib/provider/seaport-bridge.d.ts +11 -0
  24. package/lib/provider/seaport-bridge.js +130 -0
  25. package/lib/provider/seaport-bridge.js.map +1 -0
  26. package/lib/provider/types.d.ts +62 -0
  27. package/lib/provider/types.js +7 -0
  28. package/lib/provider/types.js.map +1 -0
  29. package/lib/provider/viem-adapter.d.ts +27 -0
  30. package/lib/provider/viem-adapter.js +122 -0
  31. package/lib/provider/viem-adapter.js.map +1 -0
  32. package/lib/sdk/assets.d.ts +7 -23
  33. package/lib/sdk/assets.js +101 -77
  34. package/lib/sdk/assets.js.map +1 -1
  35. package/lib/sdk/base.d.ts +334 -0
  36. package/lib/sdk/base.js +312 -0
  37. package/lib/sdk/base.js.map +1 -0
  38. package/lib/sdk/cancellation.d.ts +1 -2
  39. package/lib/sdk/cancellation.js +4 -4
  40. package/lib/sdk/cancellation.js.map +1 -1
  41. package/lib/sdk/context.d.ts +5 -5
  42. package/lib/sdk/fulfillment.d.ts +13 -58
  43. package/lib/sdk/fulfillment.js +16 -58
  44. package/lib/sdk/fulfillment.js.map +1 -1
  45. package/lib/sdk/orders.d.ts +25 -26
  46. package/lib/sdk/orders.js +8 -9
  47. package/lib/sdk/orders.js.map +1 -1
  48. package/lib/sdk/tokens.d.ts +3 -3
  49. package/lib/sdk/tokens.js +17 -7
  50. package/lib/sdk/tokens.js.map +1 -1
  51. package/lib/sdk.d.ts +16 -550
  52. package/lib/sdk.js +35 -663
  53. package/lib/sdk.js.map +1 -1
  54. package/lib/types.d.ts +11 -6
  55. package/lib/types.js +3 -3
  56. package/lib/types.js.map +1 -1
  57. package/lib/utils/address.d.ts +12 -0
  58. package/lib/utils/address.js +39 -0
  59. package/lib/utils/address.js.map +1 -0
  60. package/lib/utils/chain.d.ts +1 -1
  61. package/lib/utils/fees.d.ts +5 -0
  62. package/lib/utils/fees.js +24 -6
  63. package/lib/utils/fees.js.map +1 -1
  64. package/lib/utils/protocol.js +5 -5
  65. package/lib/utils/protocol.js.map +1 -1
  66. package/lib/utils/units.d.ts +12 -0
  67. package/lib/utils/units.js +43 -0
  68. package/lib/utils/units.js.map +1 -0
  69. package/lib/utils/utils.d.ts +2 -10
  70. package/lib/utils/utils.js +2 -17
  71. package/lib/utils/utils.js.map +1 -1
  72. package/lib/viem.d.ts +44 -0
  73. package/lib/viem.js +114 -0
  74. package/lib/viem.js.map +1 -0
  75. package/package.json +25 -8
  76. package/src/abi/abis.ts +236 -0
  77. package/src/api/api.ts +66 -59
  78. package/src/api/orders.ts +2 -2
  79. package/src/constants.ts +7 -3
  80. package/src/index.ts +8 -0
  81. package/src/orders/privateListings.ts +2 -2
  82. package/src/orders/utils.ts +8 -1
  83. package/src/provider/ethers-adapter.ts +182 -0
  84. package/src/provider/seaport-bridge.ts +163 -0
  85. package/src/provider/types.ts +67 -0
  86. package/src/provider/viem-adapter.ts +165 -0
  87. package/src/sdk/assets.ts +128 -158
  88. package/src/sdk/base.ts +558 -0
  89. package/src/sdk/cancellation.ts +6 -9
  90. package/src/sdk/context.ts +5 -5
  91. package/src/sdk/fulfillment.ts +31 -72
  92. package/src/sdk/orders.ts +44 -44
  93. package/src/sdk/tokens.ts +18 -18
  94. package/src/sdk.ts +40 -1011
  95. package/src/types.ts +12 -6
  96. package/src/utils/address.ts +40 -0
  97. package/src/utils/fees.ts +28 -8
  98. package/src/utils/protocol.ts +5 -5
  99. package/src/utils/units.ts +47 -0
  100. package/src/utils/utils.ts +2 -22
  101. package/src/viem.ts +125 -0
  102. package/lib/src/api/accounts.d.ts +0 -18
  103. package/lib/src/api/accounts.js +0 -30
  104. package/lib/src/api/accounts.js.map +0 -1
  105. package/lib/src/api/api.d.ts +0 -429
  106. package/lib/src/api/api.js +0 -652
  107. package/lib/src/api/api.js.map +0 -1
  108. package/lib/src/api/apiPaths.d.ts +0 -37
  109. package/lib/src/api/apiPaths.js +0 -140
  110. package/lib/src/api/apiPaths.js.map +0 -1
  111. package/lib/src/api/collections.d.ts +0 -26
  112. package/lib/src/api/collections.js +0 -57
  113. package/lib/src/api/collections.js.map +0 -1
  114. package/lib/src/api/events.d.ts +0 -26
  115. package/lib/src/api/events.js +0 -42
  116. package/lib/src/api/events.js.map +0 -1
  117. package/lib/src/api/fetcher.d.ts +0 -24
  118. package/lib/src/api/fetcher.js +0 -3
  119. package/lib/src/api/fetcher.js.map +0 -1
  120. package/lib/src/api/index.d.ts +0 -2
  121. package/lib/src/api/index.js +0 -19
  122. package/lib/src/api/index.js.map +0 -1
  123. package/lib/src/api/listings.d.ts +0 -44
  124. package/lib/src/api/listings.js +0 -86
  125. package/lib/src/api/listings.js.map +0 -1
  126. package/lib/src/api/nfts.d.ts +0 -35
  127. package/lib/src/api/nfts.js +0 -66
  128. package/lib/src/api/nfts.js.map +0 -1
  129. package/lib/src/api/offers.d.ts +0 -54
  130. package/lib/src/api/offers.js +0 -122
  131. package/lib/src/api/offers.js.map +0 -1
  132. package/lib/src/api/orders.d.ts +0 -50
  133. package/lib/src/api/orders.js +0 -151
  134. package/lib/src/api/orders.js.map +0 -1
  135. package/lib/src/api/search.d.ts +0 -13
  136. package/lib/src/api/search.js +0 -21
  137. package/lib/src/api/search.js.map +0 -1
  138. package/lib/src/api/tokens.d.ts +0 -25
  139. package/lib/src/api/tokens.js +0 -42
  140. package/lib/src/api/tokens.js.map +0 -1
  141. package/lib/src/api/types.d.ts +0 -840
  142. package/lib/src/api/types.js +0 -65
  143. package/lib/src/api/types.js.map +0 -1
  144. package/lib/src/constants.d.ts +0 -22
  145. package/lib/src/constants.js +0 -52
  146. package/lib/src/constants.js.map +0 -1
  147. package/lib/src/index.d.ts +0 -18
  148. package/lib/src/index.js +0 -24
  149. package/lib/src/index.js.map +0 -1
  150. package/lib/src/orders/privateListings.d.ts +0 -12
  151. package/lib/src/orders/privateListings.js +0 -130
  152. package/lib/src/orders/privateListings.js.map +0 -1
  153. package/lib/src/orders/types.d.ts +0 -160
  154. package/lib/src/orders/types.js +0 -10
  155. package/lib/src/orders/types.js.map +0 -1
  156. package/lib/src/orders/utils.d.ts +0 -89
  157. package/lib/src/orders/utils.js +0 -177
  158. package/lib/src/orders/utils.js.map +0 -1
  159. package/lib/src/sdk/assets.d.ts +0 -104
  160. package/lib/src/sdk/assets.js +0 -397
  161. package/lib/src/sdk/assets.js.map +0 -1
  162. package/lib/src/sdk/cancellation.d.ts +0 -97
  163. package/lib/src/sdk/cancellation.js +0 -234
  164. package/lib/src/sdk/cancellation.js.map +0 -1
  165. package/lib/src/sdk/context.d.ts +0 -28
  166. package/lib/src/sdk/context.js +0 -3
  167. package/lib/src/sdk/context.js.map +0 -1
  168. package/lib/src/sdk/fulfillment.d.ts +0 -153
  169. package/lib/src/sdk/fulfillment.js +0 -296
  170. package/lib/src/sdk/fulfillment.js.map +0 -1
  171. package/lib/src/sdk/orders.d.ts +0 -253
  172. package/lib/src/sdk/orders.js +0 -677
  173. package/lib/src/sdk/orders.js.map +0 -1
  174. package/lib/src/sdk/tokens.d.ts +0 -31
  175. package/lib/src/sdk/tokens.js +0 -64
  176. package/lib/src/sdk/tokens.js.map +0 -1
  177. package/lib/src/sdk.d.ts +0 -560
  178. package/lib/src/sdk.js +0 -675
  179. package/lib/src/sdk.js.map +0 -1
  180. package/lib/src/typechain/contracts/ERC1155.d.ts +0 -236
  181. package/lib/src/typechain/contracts/ERC1155.js +0 -3
  182. package/lib/src/typechain/contracts/ERC1155.js.map +0 -1
  183. package/lib/src/typechain/contracts/ERC20.d.ts +0 -141
  184. package/lib/src/typechain/contracts/ERC20.js +0 -3
  185. package/lib/src/typechain/contracts/ERC20.js.map +0 -1
  186. package/lib/src/typechain/contracts/ERC721.d.ts +0 -213
  187. package/lib/src/typechain/contracts/ERC721.js +0 -3
  188. package/lib/src/typechain/contracts/ERC721.js.map +0 -1
  189. package/lib/src/typechain/contracts/Multicall3.d.ts +0 -57
  190. package/lib/src/typechain/contracts/Multicall3.js +0 -3
  191. package/lib/src/typechain/contracts/Multicall3.js.map +0 -1
  192. package/lib/src/typechain/contracts/TransferHelper.d.ts +0 -55
  193. package/lib/src/typechain/contracts/TransferHelper.js +0 -3
  194. package/lib/src/typechain/contracts/TransferHelper.js.map +0 -1
  195. package/lib/src/typechain/contracts/common.d.ts +0 -50
  196. package/lib/src/typechain/contracts/common.js +0 -3
  197. package/lib/src/typechain/contracts/common.js.map +0 -1
  198. package/lib/src/typechain/contracts/factories/ERC1155__factory.d.ts +0 -250
  199. package/lib/src/typechain/contracts/factories/ERC1155__factory.js +0 -332
  200. package/lib/src/typechain/contracts/factories/ERC1155__factory.js.map +0 -1
  201. package/lib/src/typechain/contracts/factories/ERC20__factory.d.ts +0 -174
  202. package/lib/src/typechain/contracts/factories/ERC20__factory.js +0 -240
  203. package/lib/src/typechain/contracts/factories/ERC20__factory.js.map +0 -1
  204. package/lib/src/typechain/contracts/factories/ERC721__factory.d.ts +0 -268
  205. package/lib/src/typechain/contracts/factories/ERC721__factory.js +0 -351
  206. package/lib/src/typechain/contracts/factories/ERC721__factory.js.map +0 -1
  207. package/lib/src/typechain/contracts/factories/Multicall3__factory.d.ts +0 -43
  208. package/lib/src/typechain/contracts/factories/Multicall3__factory.js +0 -68
  209. package/lib/src/typechain/contracts/factories/Multicall3__factory.js.map +0 -1
  210. package/lib/src/typechain/contracts/factories/TransferHelper__factory.d.ts +0 -46
  211. package/lib/src/typechain/contracts/factories/TransferHelper__factory.js +0 -71
  212. package/lib/src/typechain/contracts/factories/TransferHelper__factory.js.map +0 -1
  213. package/lib/src/typechain/contracts/factories/index.d.ts +0 -5
  214. package/lib/src/typechain/contracts/factories/index.js +0 -17
  215. package/lib/src/typechain/contracts/factories/index.js.map +0 -1
  216. package/lib/src/typechain/contracts/index.d.ts +0 -11
  217. package/lib/src/typechain/contracts/index.js +0 -48
  218. package/lib/src/typechain/contracts/index.js.map +0 -1
  219. package/lib/src/types.d.ts +0 -387
  220. package/lib/src/types.js +0 -127
  221. package/lib/src/types.js.map +0 -1
  222. package/lib/src/utils/chain.d.ts +0 -60
  223. package/lib/src/utils/chain.js +0 -248
  224. package/lib/src/utils/chain.js.map +0 -1
  225. package/lib/src/utils/converters.d.ts +0 -37
  226. package/lib/src/utils/converters.js +0 -137
  227. package/lib/src/utils/converters.js.map +0 -1
  228. package/lib/src/utils/dateHelper.d.ts +0 -38
  229. package/lib/src/utils/dateHelper.js +0 -52
  230. package/lib/src/utils/dateHelper.js.map +0 -1
  231. package/lib/src/utils/fees.d.ts +0 -13
  232. package/lib/src/utils/fees.js +0 -29
  233. package/lib/src/utils/fees.js.map +0 -1
  234. package/lib/src/utils/index.d.ts +0 -2
  235. package/lib/src/utils/index.js +0 -19
  236. package/lib/src/utils/index.js.map +0 -1
  237. package/lib/src/utils/protocol.d.ts +0 -75
  238. package/lib/src/utils/protocol.js +0 -161
  239. package/lib/src/utils/protocol.js.map +0 -1
  240. package/lib/src/utils/rateLimit.d.ts +0 -34
  241. package/lib/src/utils/rateLimit.js +0 -97
  242. package/lib/src/utils/rateLimit.js.map +0 -1
  243. package/lib/src/utils/stringHelper.d.ts +0 -18
  244. package/lib/src/utils/stringHelper.js +0 -24
  245. package/lib/src/utils/stringHelper.js.map +0 -1
  246. package/lib/src/utils/utils.d.ts +0 -18
  247. package/lib/src/utils/utils.js +0 -45
  248. package/lib/src/utils/utils.js.map +0 -1
  249. package/lib/typechain/contracts/ERC1155.d.ts +0 -236
  250. package/lib/typechain/contracts/ERC1155.js +0 -3
  251. package/lib/typechain/contracts/ERC1155.js.map +0 -1
  252. package/lib/typechain/contracts/ERC20.d.ts +0 -141
  253. package/lib/typechain/contracts/ERC20.js +0 -3
  254. package/lib/typechain/contracts/ERC20.js.map +0 -1
  255. package/lib/typechain/contracts/ERC721.d.ts +0 -213
  256. package/lib/typechain/contracts/ERC721.js +0 -3
  257. package/lib/typechain/contracts/ERC721.js.map +0 -1
  258. package/lib/typechain/contracts/Multicall3.d.ts +0 -57
  259. package/lib/typechain/contracts/Multicall3.js +0 -3
  260. package/lib/typechain/contracts/Multicall3.js.map +0 -1
  261. package/lib/typechain/contracts/TransferHelper.d.ts +0 -55
  262. package/lib/typechain/contracts/TransferHelper.js +0 -3
  263. package/lib/typechain/contracts/TransferHelper.js.map +0 -1
  264. package/lib/typechain/contracts/common.d.ts +0 -50
  265. package/lib/typechain/contracts/common.js +0 -3
  266. package/lib/typechain/contracts/common.js.map +0 -1
  267. package/lib/typechain/contracts/factories/ERC1155__factory.d.ts +0 -250
  268. package/lib/typechain/contracts/factories/ERC1155__factory.js +0 -332
  269. package/lib/typechain/contracts/factories/ERC1155__factory.js.map +0 -1
  270. package/lib/typechain/contracts/factories/ERC20__factory.d.ts +0 -174
  271. package/lib/typechain/contracts/factories/ERC20__factory.js +0 -240
  272. package/lib/typechain/contracts/factories/ERC20__factory.js.map +0 -1
  273. package/lib/typechain/contracts/factories/ERC721__factory.d.ts +0 -268
  274. package/lib/typechain/contracts/factories/ERC721__factory.js +0 -351
  275. package/lib/typechain/contracts/factories/ERC721__factory.js.map +0 -1
  276. package/lib/typechain/contracts/factories/Multicall3__factory.d.ts +0 -43
  277. package/lib/typechain/contracts/factories/Multicall3__factory.js +0 -68
  278. package/lib/typechain/contracts/factories/Multicall3__factory.js.map +0 -1
  279. package/lib/typechain/contracts/factories/TransferHelper__factory.d.ts +0 -46
  280. package/lib/typechain/contracts/factories/TransferHelper__factory.js +0 -71
  281. package/lib/typechain/contracts/factories/TransferHelper__factory.js.map +0 -1
  282. package/lib/typechain/contracts/factories/index.d.ts +0 -5
  283. package/lib/typechain/contracts/factories/index.js +0 -17
  284. package/lib/typechain/contracts/factories/index.js.map +0 -1
  285. package/lib/typechain/contracts/index.d.ts +0 -11
  286. package/lib/typechain/contracts/index.js +0 -48
  287. package/lib/typechain/contracts/index.js.map +0 -1
  288. package/src/typechain/contracts/ERC1155.ts +0 -440
  289. package/src/typechain/contracts/ERC20.ts +0 -286
  290. package/src/typechain/contracts/ERC721.ts +0 -412
  291. package/src/typechain/contracts/Multicall3.ts +0 -117
  292. package/src/typechain/contracts/TransferHelper.ts +0 -122
  293. package/src/typechain/contracts/common.ts +0 -131
  294. package/src/typechain/contracts/factories/ERC1155__factory.ts +0 -331
  295. package/src/typechain/contracts/factories/ERC20__factory.ts +0 -239
  296. package/src/typechain/contracts/factories/ERC721__factory.ts +0 -350
  297. package/src/typechain/contracts/factories/Multicall3__factory.ts +0 -67
  298. package/src/typechain/contracts/factories/TransferHelper__factory.ts +0 -76
  299. package/src/typechain/contracts/factories/index.ts +0 -8
  300. package/src/typechain/contracts/index.ts +0 -14
@@ -0,0 +1,558 @@
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
+ /** Returns whether an order is fulfillable. */
320
+ public async isOrderFulfillable(options: {
321
+ order: OrderV2
322
+ accountAddress: string
323
+ }): Promise<boolean> {
324
+ return this._fulfillmentManager.isOrderFulfillable(options)
325
+ }
326
+
327
+ /** Approve an order with an onchain transaction. */
328
+ public async approveOrder(order: OrderV2, domain?: string) {
329
+ return this._fulfillmentManager.approveOrder(order, domain)
330
+ }
331
+
332
+ /** Validates an order onchain using Seaport's validate() method. */
333
+ public async validateOrderOnchain(
334
+ orderComponents: OrderComponents,
335
+ accountAddress: string,
336
+ ) {
337
+ return this._fulfillmentManager.validateOrderOnchain(
338
+ orderComponents,
339
+ accountAddress,
340
+ )
341
+ }
342
+
343
+ /** Create and validate a listing onchain. */
344
+ public async createListingAndValidateOnchain(options: {
345
+ asset: AssetWithTokenId
346
+ accountAddress: string
347
+ amount: Amount
348
+ quantity?: Amount
349
+ domain?: string
350
+ salt?: Amount
351
+ listingTime?: number
352
+ expirationTime?: number
353
+ buyerAddress?: string
354
+ includeOptionalCreatorFees?: boolean
355
+ zone?: string
356
+ }): Promise<string> {
357
+ return this._fulfillmentManager.createListingAndValidateOnchain(options)
358
+ }
359
+
360
+ /** Create and validate an offer onchain. */
361
+ public async createOfferAndValidateOnchain(options: {
362
+ asset: AssetWithTokenId
363
+ accountAddress: string
364
+ amount: Amount
365
+ quantity?: Amount
366
+ domain?: string
367
+ salt?: Amount
368
+ expirationTime?: Amount
369
+ zone?: string
370
+ }): Promise<string> {
371
+ return this._fulfillmentManager.createOfferAndValidateOnchain(options)
372
+ }
373
+
374
+ // ─── Order Cancellation ────────────────────────────────────────────
375
+
376
+ /**
377
+ * Cancel multiple orders onchain, preventing them from being fulfilled.
378
+ * @param options
379
+ * @param options.orders Array of orders to cancel. Can be OrderV2 objects or OrderComponents.
380
+ * @param options.orderHashes Optional array of order hashes to cancel.
381
+ * @param options.accountAddress The account address cancelling the orders.
382
+ * @param options.protocolAddress The Seaport protocol address for the orders.
383
+ * @param options.domain Optional domain for onchain attribution.
384
+ * @param options.overrides Transaction overrides (gasLimit, maxFeePerGas, etc.).
385
+ * @returns Transaction hash of the cancellation.
386
+ */
387
+ public async cancelOrders(options: {
388
+ orders?: Array<OrderV2 | OrderComponents>
389
+ orderHashes?: string[]
390
+ accountAddress: string
391
+ protocolAddress?: string
392
+ domain?: string
393
+ overrides?: Record<string, unknown>
394
+ }): Promise<string> {
395
+ return this._cancellationManager.cancelOrders(options)
396
+ }
397
+
398
+ /** Cancel an order onchain, preventing it from ever being fulfilled. */
399
+ public async cancelOrder(options: {
400
+ order?: OrderV2
401
+ orderHash?: string
402
+ accountAddress: string
403
+ protocolAddress?: string
404
+ domain?: string
405
+ }) {
406
+ return this._cancellationManager.cancelOrder(options)
407
+ }
408
+
409
+ /** Offchain cancel an order by its order hash when protected by the SignedZone. */
410
+ public async offchainCancelOrder(
411
+ protocolAddress: string,
412
+ orderHash: string,
413
+ chain: Chain = this.chain,
414
+ offererSignature?: string,
415
+ useSignerToDeriveOffererSignature?: boolean,
416
+ ) {
417
+ return this._cancellationManager.offchainCancelOrder(
418
+ protocolAddress,
419
+ orderHash,
420
+ chain,
421
+ offererSignature,
422
+ useSignerToDeriveOffererSignature,
423
+ )
424
+ }
425
+
426
+ // ─── Asset Operations ──────────────────────────────────────────────
427
+
428
+ /**
429
+ * Get an account's balance of any Asset.
430
+ */
431
+ public async getBalance(options: {
432
+ accountAddress: string
433
+ asset: AssetWithTokenStandard
434
+ }): Promise<bigint> {
435
+ return this._assetsManager.getBalance(options)
436
+ }
437
+
438
+ /**
439
+ * Transfer an asset. This asset can be an ERC20, ERC1155, or ERC721.
440
+ * @param options
441
+ * @param options.asset The Asset to transfer. tokenStandard must be set.
442
+ * @param options.amount Amount of asset to transfer. Not used for ERC721.
443
+ * @param options.fromAddress The address to transfer from
444
+ * @param options.toAddress The address to transfer to
445
+ * @param options.overrides Transaction overrides (gasLimit, maxFeePerGas, etc.).
446
+ */
447
+ public async transfer(options: {
448
+ asset: AssetWithTokenStandard
449
+ amount?: Amount
450
+ fromAddress: string
451
+ toAddress: string
452
+ overrides?: Record<string, unknown>
453
+ }): Promise<void> {
454
+ return this._assetsManager.transfer(options)
455
+ }
456
+
457
+ /** Bulk transfer multiple assets using OpenSea's TransferHelper contract. */
458
+ public async bulkTransfer(options: {
459
+ assets: Array<{
460
+ asset: AssetWithTokenStandard
461
+ toAddress: string
462
+ amount?: Amount
463
+ }>
464
+ fromAddress: string
465
+ overrides?: Record<string, unknown>
466
+ }): Promise<string> {
467
+ return this._assetsManager.bulkTransfer(options)
468
+ }
469
+
470
+ /** Batch approve multiple assets for transfer to the OpenSea conduit. */
471
+ public async batchApproveAssets(options: {
472
+ assets: Array<{
473
+ asset: AssetWithTokenStandard
474
+ amount?: Amount
475
+ }>
476
+ fromAddress: string
477
+ overrides?: Record<string, unknown>
478
+ }): Promise<string | undefined> {
479
+ return this._assetsManager.batchApproveAssets(options)
480
+ }
481
+
482
+ // ─── Private Helpers ───────────────────────────────────────────────
483
+
484
+ /**
485
+ * Compute the `basePrice` parameter to be used to price an order.
486
+ */
487
+ private async _getPriceParameters(
488
+ orderSide: OrderSide,
489
+ tokenAddress: string,
490
+ amount: Amount,
491
+ ) {
492
+ tokenAddress = tokenAddress.toLowerCase()
493
+ const isEther = tokenAddress === ZERO_ADDRESS
494
+ let decimals = 18
495
+ if (!isEther) {
496
+ if (tokenAddress in this._cachedPaymentTokenDecimals) {
497
+ decimals = this._cachedPaymentTokenDecimals[tokenAddress]
498
+ } else {
499
+ const paymentToken = await this.api.getPaymentToken(tokenAddress)
500
+ this._cachedPaymentTokenDecimals[tokenAddress] = paymentToken.decimals
501
+ decimals = paymentToken.decimals
502
+ }
503
+ }
504
+
505
+ const amountWei = parseUnits(amount.toString(), decimals)
506
+ const basePrice = amountWei
507
+
508
+ if (amount == null || amountWei < 0) {
509
+ throw new Error("Starting price must be a number >= 0")
510
+ }
511
+ if (isEther && orderSide === OrderSide.OFFER) {
512
+ throw new Error("Offers must use wrapped ETH or an ERC-20 token.")
513
+ }
514
+ return { basePrice }
515
+ }
516
+
517
+ private _dispatch(event: EventType, data: EventData) {
518
+ this._emitter.emit(event, data)
519
+ }
520
+
521
+ private async _requireAccountIsAvailable(accountAddress: string) {
522
+ const checksummed = checksumAddress(accountAddress)
523
+ const availableAccounts = await this._getAvailableAccounts()
524
+
525
+ if (availableAccounts.includes(checksummed)) {
526
+ return
527
+ }
528
+
529
+ throw new Error(
530
+ `Specified accountAddress is not available through wallet or provider: ${checksummed}. Accounts available: ${
531
+ availableAccounts.length > 0 ? availableAccounts.join(", ") : "none"
532
+ }`,
533
+ )
534
+ }
535
+
536
+ private async _confirmTransaction(
537
+ transactionHash: string,
538
+ event: EventType,
539
+ description: string,
540
+ ): Promise<void> {
541
+ const transactionEventData = { transactionHash, event }
542
+ this.logger(`Transaction started: ${description}`)
543
+
544
+ try {
545
+ this._dispatch(EventType.TransactionCreated, transactionEventData)
546
+ await this._wallet.provider.waitForTransaction(transactionHash)
547
+ this.logger(`Transaction succeeded: ${description}`)
548
+ this._dispatch(EventType.TransactionConfirmed, transactionEventData)
549
+ } catch (error) {
550
+ this.logger(`Transaction failed: ${description}`)
551
+ this._dispatch(EventType.TransactionFailed, {
552
+ ...transactionEventData,
553
+ error,
554
+ })
555
+ throw error
556
+ }
557
+ }
558
+ }
@@ -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 */