@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
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"}