@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
package/src/types.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  import type { ChainIdentifier } from "@opensea/api-types"
2
- import type { BigNumberish } from "ethers"
3
2
  import type { Listing, Offer } from "./api/types"
4
3
  import type { OrderV2 } from "./orders/types"
5
4
 
5
+ /**
6
+ * Numeric type for amounts (replaces ethers BigNumberish).
7
+ * Prefer `string` for decimal amounts (e.g. "1.5") to avoid floating point
8
+ * precision issues — `number` values like `0.1 + 0.2` produce `0.30000000000000004`.
9
+ */
10
+ export type Amount = string | number | bigint
11
+
6
12
  /**
7
13
  * Events emitted by the SDK which can be used by frontend applications
8
14
  * to update state or show useful messages to users.
@@ -68,7 +74,7 @@ export interface EventData {
68
74
  /**
69
75
  * Amount of ETH sent when wrapping or unwrapping.
70
76
  */
71
- amount?: BigNumberish
77
+ amount?: Amount
72
78
  /**
73
79
  * The transaction hash of the event.
74
80
  */
@@ -95,7 +101,7 @@ export interface EventData {
95
101
  assets?: Array<{
96
102
  asset: AssetWithTokenStandard
97
103
  toAddress?: string
98
- amount?: BigNumberish
104
+ amount?: Amount
99
105
  }>
100
106
  }
101
107
 
@@ -157,11 +163,11 @@ type _AssertAPIChainsCovered = ChainIdentifier extends `${Chain}` ? true : never
157
163
  const _assertAPIChainsCovered: _AssertAPIChainsCovered = true
158
164
 
159
165
  /**
160
- * Order side: listing (ask) or offer (bid)
166
+ * Order side: listing or offer
161
167
  */
162
168
  export enum OrderSide {
163
- LISTING = "ask",
164
- OFFER = "bid",
169
+ LISTING = "listing",
170
+ OFFER = "offer",
165
171
  }
166
172
 
167
173
  /**
@@ -0,0 +1,40 @@
1
+ import { keccak_256 } from "@noble/hashes/sha3.js"
2
+ import { bytesToHex } from "@noble/hashes/utils.js"
3
+
4
+ /**
5
+ * EIP-55 checksum an Ethereum address.
6
+ *
7
+ * If the input contains mixed case, it is validated as an existing checksum —
8
+ * an incorrect checksum throws (matching ethers.getAddress behavior).
9
+ * All-lowercase and all-uppercase inputs are checksummed without validation.
10
+ *
11
+ * @param address The address to checksum (must be a valid 0x-prefixed hex address).
12
+ * @returns The checksummed address.
13
+ * @throws Error if the address is not a valid Ethereum address or has an invalid checksum.
14
+ */
15
+ export function checksumAddress(address: string): string {
16
+ if (!/^0x[0-9a-fA-F]{40}$/.test(address)) {
17
+ throw new Error(`Invalid address: ${address}`)
18
+ }
19
+
20
+ const lower = address.slice(2).toLowerCase()
21
+ const hash = bytesToHex(keccak_256(new TextEncoder().encode(lower)))
22
+
23
+ let checksummed = "0x"
24
+ for (let i = 0; i < 40; i++) {
25
+ const char = lower[i]
26
+ const hashNibble = Number.parseInt(hash[i], 16)
27
+ checksummed += hashNibble >= 8 ? char.toUpperCase() : char
28
+ }
29
+
30
+ // If the input has mixed case, validate it matches the computed checksum.
31
+ // All-lowercase and all-uppercase inputs skip validation (they're just being checksummed).
32
+ const hex = address.slice(2)
33
+ const isAllLower = hex === hex.toLowerCase()
34
+ const isAllUpper = hex === hex.toUpperCase()
35
+ if (!isAllLower && !isAllUpper && address !== checksummed) {
36
+ throw new Error(`Invalid address checksum: ${address}`)
37
+ }
38
+
39
+ return checksummed
40
+ }
package/src/utils/fees.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { FixedNumber } from "ethers"
2
- import { FIXED_NUMBER_100 } from "../constants"
3
1
  import type { Fee } from "../types"
4
2
 
5
3
  /**
@@ -18,14 +16,36 @@ export const totalBasisPointsForFees = (fees: Fee[]): bigint => {
18
16
 
19
17
  /**
20
18
  * Converts a fee to its basis points representation.
19
+ * A fee of 2.5 means 2.5%, which is 250 basis points.
20
+ *
21
+ * Uses string-based arithmetic to avoid IEEE 754 floating point errors
22
+ * (e.g. Math.round(2.505 * 100) === 250 due to 2.505 * 100 === 250.49999...).
23
+ * Handles scientific notation (e.g. 1e-7) by normalizing to decimal string first.
21
24
  * @param fee The fee to convert
22
25
  * @returns the basis points
23
26
  */
24
27
  export const basisPointsForFee = (fee: Fee): bigint => {
25
- return BigInt(
26
- FixedNumber.fromString(fee.fee.toString())
27
- .mul(FIXED_NUMBER_100)
28
- .toFormat(0) // format to 0 decimal places to convert to bigint
29
- .toString(),
30
- )
28
+ // Normalize scientific notation to a decimal string.
29
+ // (1e-7).toString() → "1e-7", which needs to become "0.0000001"
30
+ let str = fee.fee.toString()
31
+ if (str.includes("e") || str.includes("E")) {
32
+ // toFixed(10) covers fees down to 0.00000001% — far beyond realistic usage.
33
+ str = fee.fee.toFixed(10).replace(/0+$/, "").replace(/\.$/, "")
34
+ }
35
+
36
+ // Split into integer and fractional parts, then multiply by 100 via decimal shift.
37
+ const [intPart, fracPart = ""] = str.split(".")
38
+
39
+ // We need 2 decimal places of the fractional part (since we multiply by 100)
40
+ const padded = fracPart.padEnd(2, "0")
41
+ const shifted = intPart + padded.slice(0, 2)
42
+ const remainder = padded.slice(2)
43
+
44
+ // Round based on the remaining fractional digits
45
+ let result = BigInt(shifted)
46
+ if (remainder.length > 0 && Number(remainder[0]) >= 5) {
47
+ result += 1n
48
+ }
49
+
50
+ return result
31
51
  }
@@ -3,18 +3,18 @@ import {
3
3
  CROSS_CHAIN_SEAPORT_V1_6_ADDRESS,
4
4
  ItemType,
5
5
  } from "@opensea/seaport-js/lib/constants"
6
- import { ethers } from "ethers"
7
6
  import {
8
7
  ALTERNATE_SEAPORT_V1_6_ADDRESS,
9
8
  SHARED_STOREFRONT_ADDRESSES,
10
9
  SHARED_STOREFRONT_LAZY_MINT_ADAPTER_CROSS_CHAIN_ADDRESS,
11
10
  } from "../constants"
12
11
  import type { TokenStandard } from "../types"
12
+ import { checksumAddress } from "./address"
13
13
 
14
14
  // Pre-compute checksummed protocol addresses for consistent comparisons
15
15
  const VALID_PROTOCOL_ADDRESSES = new Set([
16
- ethers.getAddress(CROSS_CHAIN_SEAPORT_V1_6_ADDRESS),
17
- ethers.getAddress(ALTERNATE_SEAPORT_V1_6_ADDRESS),
16
+ checksumAddress(CROSS_CHAIN_SEAPORT_V1_6_ADDRESS),
17
+ checksumAddress(ALTERNATE_SEAPORT_V1_6_ADDRESS),
18
18
  ])
19
19
 
20
20
  /**
@@ -49,7 +49,7 @@ export const getAssetItemType = (tokenStandard: TokenStandard) => {
49
49
  */
50
50
  export const remapSharedStorefrontAddress = (tokenAddress: string): string => {
51
51
  if (SHARED_STOREFRONT_ADDRESSES.has(tokenAddress.toLowerCase())) {
52
- return ethers.getAddress(
52
+ return checksumAddress(
53
53
  SHARED_STOREFRONT_LAZY_MINT_ADAPTER_CROSS_CHAIN_ADDRESS,
54
54
  )
55
55
  }
@@ -62,7 +62,7 @@ export const remapSharedStorefrontAddress = (tokenAddress: string): string => {
62
62
  */
63
63
  export const isValidProtocol = (protocolAddress: string): boolean => {
64
64
  try {
65
- return VALID_PROTOCOL_ADDRESSES.has(ethers.getAddress(protocolAddress))
65
+ return VALID_PROTOCOL_ADDRESSES.has(checksumAddress(protocolAddress))
66
66
  } catch {
67
67
  return false
68
68
  }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Parse a decimal string into its base unit representation (e.g. ETH -> wei).
3
+ * @param value The decimal value as a string or number (e.g. "1.5")
4
+ * @param decimals The number of decimal places (e.g. 18 for ETH)
5
+ * @returns The value in base units as a bigint
6
+ */
7
+ export function parseUnits(
8
+ value: string | number | bigint,
9
+ decimals: number,
10
+ ): bigint {
11
+ let str = value.toString()
12
+
13
+ // Handle JavaScript scientific notation (e.g. 1e-8 → "0.00000001").
14
+ // Note: toFixed has precision limits for very large numbers, but this is
15
+ // sufficient for realistic token amounts (up to ~2^53).
16
+ if (typeof value === "number" && str.includes("e")) {
17
+ str = value.toFixed(decimals)
18
+ }
19
+
20
+ // Handle negative values
21
+ const isNegative = str.startsWith("-")
22
+ const abs = isNegative ? str.slice(1) : str
23
+
24
+ const [intPart, fracPart = ""] = abs.split(".")
25
+ if (abs.split(".").length > 2) {
26
+ throw new Error(`Invalid decimal value: ${str}`)
27
+ }
28
+
29
+ // Reject excess decimal places to match ethers.parseUnits behavior
30
+ if (fracPart.length > decimals) {
31
+ throw new Error(`Too many decimal places: ${fracPart.length} > ${decimals}`)
32
+ }
33
+ const paddedFrac = fracPart.padEnd(decimals, "0")
34
+ const combined = (intPart || "0") + paddedFrac
35
+
36
+ // Remove leading zeros then parse
37
+ const result = BigInt(combined)
38
+ return isNegative ? -result : result
39
+ }
40
+
41
+ /**
42
+ * Parse an ether-denominated value into wei.
43
+ * Shorthand for `parseUnits(value, 18)`.
44
+ */
45
+ export function parseEther(value: string | number | bigint): bigint {
46
+ return parseUnits(value, 18)
47
+ }
@@ -1,30 +1,10 @@
1
- import type { ethers } from "ethers"
2
-
1
+ export * from "./address"
3
2
  export * from "./chain"
4
3
  // Re-export all utilities from specialized modules
5
4
  export * from "./converters"
6
5
  export * from "./fees"
7
6
  export * from "./protocol"
8
-
9
- /**
10
- * Estimate gas usage for a transaction.
11
- * @param provider The Provider
12
- * @param from Address sending transaction
13
- * @param to Destination contract address
14
- * @param data Data to send to contract
15
- * @param value Value in ETH to send with data
16
- */
17
- export async function estimateGas(
18
- provider: ethers.Provider,
19
- { from, to, data, value = 0n }: ethers.Transaction,
20
- ) {
21
- return await provider.estimateGas({
22
- from,
23
- to,
24
- value: value.toString(),
25
- data,
26
- })
27
- }
7
+ export * from "./units"
28
8
 
29
9
  interface ErrorWithCode extends Error {
30
10
  code: string
package/src/viem.ts ADDED
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Viem entry point for the OpenSea SDK.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { createPublicClient, createWalletClient, http } from 'viem'
7
+ * import { mainnet } from 'viem/chains'
8
+ * import { OpenSeaSDK, Chain } from '@opensea/sdk/viem'
9
+ *
10
+ * const publicClient = createPublicClient({ chain: mainnet, transport: http() })
11
+ * const walletClient = createWalletClient({ chain: mainnet, transport: http(), account: '0x...' })
12
+ *
13
+ * const sdk = new OpenSeaSDK(
14
+ * { publicClient, walletClient },
15
+ * { chain: Chain.Mainnet, apiKey: 'YOUR_API_KEY' },
16
+ * )
17
+ * ```
18
+ */
19
+
20
+ // seaport-js has a hard dependency on ethers, so importing it pulls ethers
21
+ // into the bundle. This is a known tradeoff — see FAQ for details.
22
+ import { Seaport } from "@opensea/seaport-js"
23
+ import { OpenSeaAPI } from "./api/api"
24
+ import { createSeaportBridge } from "./provider/seaport-bridge"
25
+ import {
26
+ createViemContractCaller,
27
+ createViemWallet,
28
+ type ViemAdapterParams,
29
+ } from "./provider/viem-adapter"
30
+ import { BaseOpenSeaSDK } from "./sdk/base"
31
+ import { Chain, type OpenSeaAPIConfig } from "./types"
32
+ import { checksumAddress } from "./utils/address"
33
+ import {
34
+ getDefaultConduit,
35
+ getListingPaymentToken,
36
+ getOfferPaymentToken,
37
+ getSeaportAddress,
38
+ } from "./utils/utils"
39
+
40
+ // Re-export everything from the main entry point
41
+ export * from "./api/types"
42
+ export * from "./constants"
43
+ export * from "./orders/types"
44
+ export type {
45
+ ContractCaller,
46
+ OpenSeaProvider,
47
+ OpenSeaSigner,
48
+ OpenSeaWallet,
49
+ TransactionResponse,
50
+ } from "./provider/types"
51
+ export * from "./types"
52
+ export * from "./utils"
53
+
54
+ /**
55
+ * OpenSea SDK for use with viem.
56
+ *
57
+ * Accepts viem `PublicClient` and optional `WalletClient` instead of ethers types.
58
+ * The public API surface is identical to the ethers entry point.
59
+ *
60
+ * @category Main Classes
61
+ */
62
+ export class OpenSeaSDK extends BaseOpenSeaSDK {
63
+ /**
64
+ * Create a new instance of OpenSeaSDK using viem clients.
65
+ * @param viemClients The viem PublicClient and optional WalletClient
66
+ * @param apiConfig Configuration options, including `chain`
67
+ * @param logger Optional function for logging debug strings
68
+ */
69
+ constructor(
70
+ viemClients: ViemAdapterParams,
71
+ apiConfig: OpenSeaAPIConfig = {},
72
+ logger?: (arg: string) => void,
73
+ ) {
74
+ apiConfig.chain ??= Chain.Mainnet
75
+ const chain = apiConfig.chain
76
+ const api = new OpenSeaAPI(apiConfig)
77
+ const resolvedLogger = logger ?? ((arg: string) => arg)
78
+
79
+ const wallet = createViemWallet(viemClients)
80
+ const contractCaller = createViemContractCaller(viemClients)
81
+
82
+ // Create ethers-compatible signer/provider for seaport-js
83
+ const seaportSignerOrProvider = createSeaportBridge(
84
+ viemClients,
85
+ resolvedLogger,
86
+ )
87
+
88
+ const defaultConduit = getDefaultConduit(chain)
89
+ const seaportAddress = getSeaportAddress(chain)
90
+ const seaport = new Seaport(seaportSignerOrProvider, {
91
+ conduitKeyToConduit: {
92
+ [defaultConduit.key]: defaultConduit.address,
93
+ },
94
+ overrides: {
95
+ defaultConduitKey: defaultConduit.key,
96
+ contractAddress: seaportAddress,
97
+ },
98
+ })
99
+
100
+ const cachedPaymentTokenDecimals: { [address: string]: number } = {}
101
+ cachedPaymentTokenDecimals[getOfferPaymentToken(chain).toLowerCase()] = 18
102
+ cachedPaymentTokenDecimals[getListingPaymentToken(chain).toLowerCase()] = 18
103
+
104
+ super({
105
+ wallet,
106
+ contractCaller,
107
+ seaport,
108
+ api,
109
+ chain,
110
+ logger: resolvedLogger,
111
+ getAvailableAccounts: async () => {
112
+ if ("signer" in wallet) {
113
+ try {
114
+ const address = await wallet.signer.getAddress()
115
+ return [checksumAddress(address)]
116
+ } catch {
117
+ return []
118
+ }
119
+ }
120
+ return []
121
+ },
122
+ cachedPaymentTokenDecimals,
123
+ })
124
+ }
125
+ }
@@ -1,18 +0,0 @@
1
- import type { Chain, OpenSeaAccount, OpenSeaPaymentToken } from "../types";
2
- import type { Fetcher } from "./fetcher";
3
- /**
4
- * Account and payment token related API operations
5
- */
6
- export declare class AccountsAPI {
7
- private fetcher;
8
- private chain;
9
- constructor(fetcher: Fetcher, chain: Chain);
10
- /**
11
- * Fetch a payment token.
12
- */
13
- getPaymentToken(address: string, chain?: Chain): Promise<OpenSeaPaymentToken>;
14
- /**
15
- * Fetch account for an address.
16
- */
17
- getAccount(address: string): Promise<OpenSeaAccount>;
18
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccountsAPI = void 0;
4
- const converters_1 = require("../utils/converters");
5
- const apiPaths_1 = require("./apiPaths");
6
- /**
7
- * Account and payment token related API operations
8
- */
9
- class AccountsAPI {
10
- constructor(fetcher, chain) {
11
- this.fetcher = fetcher;
12
- this.chain = chain;
13
- }
14
- /**
15
- * Fetch a payment token.
16
- */
17
- async getPaymentToken(address, chain = this.chain) {
18
- const json = await this.fetcher.get((0, apiPaths_1.getPaymentTokenPath)(chain, address));
19
- return (0, converters_1.paymentTokenFromJSON)(json);
20
- }
21
- /**
22
- * Fetch account for an address.
23
- */
24
- async getAccount(address) {
25
- const json = await this.fetcher.get((0, apiPaths_1.getAccountPath)(address));
26
- return (0, converters_1.accountFromJSON)(json);
27
- }
28
- }
29
- exports.AccountsAPI = AccountsAPI;
30
- //# sourceMappingURL=accounts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../../src/api/accounts.ts"],"names":[],"mappings":";;;AACA,oDAA2E;AAC3E,yCAAgE;AAGhE;;GAEG;AACH,MAAa,WAAW;IACtB,YACU,OAAgB,EAChB,KAAY;QADZ,YAAO,GAAP,OAAO,CAAS;QAChB,UAAK,GAAL,KAAK,CAAO;IACnB,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,eAAe,CACnB,OAAe,EACf,KAAK,GAAG,IAAI,CAAC,KAAK;QAElB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CACjC,IAAA,8BAAmB,EAAC,KAAK,EAAE,OAAO,CAAC,CACpC,CAAA;QACD,OAAO,IAAA,iCAAoB,EAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,OAAe;QAC9B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAiB,IAAA,yBAAc,EAAC,OAAO,CAAC,CAAC,CAAA;QAC5E,OAAO,IAAA,4BAAe,EAAC,IAAI,CAAC,CAAA;IAC9B,CAAC;CACF;AA1BD,kCA0BC"}