@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/sdk/assets.ts CHANGED
@@ -1,18 +1,23 @@
1
1
  import {
2
- type BigNumberish,
3
- Contract,
4
- type ContractTransactionResponse,
5
- ethers,
6
- type Overrides,
7
- type Signer,
8
- } from "ethers"
9
- import { MULTICALL3_ADDRESS, TRANSFER_HELPER_ADDRESS } from "../constants"
2
+ APPROVE_ABI,
3
+ ERC20_ABI,
4
+ ERC721_ABI,
5
+ ERC1155_ABI,
6
+ MULTICALL3_ABI,
7
+ SET_APPROVAL_FOR_ALL_ABI,
8
+ TRANSFER_HELPER_ABI,
9
+ } from "../abi/abis"
10
10
  import {
11
- ERC20__factory,
12
- ERC721__factory,
13
- ERC1155__factory,
14
- } from "../typechain/contracts"
15
- import { type AssetWithTokenStandard, EventType, TokenStandard } from "../types"
11
+ MAX_UINT256,
12
+ MULTICALL3_ADDRESS,
13
+ TRANSFER_HELPER_ADDRESS,
14
+ } from "../constants"
15
+ import {
16
+ type Amount,
17
+ type AssetWithTokenStandard,
18
+ EventType,
19
+ TokenStandard,
20
+ } from "../types"
16
21
  import { getDefaultConduit } from "../utils/utils"
17
22
  import type { SDKContext } from "./context"
18
23
 
@@ -38,37 +43,39 @@ export class AssetsManager {
38
43
  accountAddress: string
39
44
  asset: AssetWithTokenStandard
40
45
  }): Promise<bigint> {
46
+ const cc = this.context.contractCaller
47
+
41
48
  switch (asset.tokenStandard) {
42
49
  case TokenStandard.ERC20: {
43
- const contract = ERC20__factory.connect(
44
- asset.tokenAddress,
45
- this.context.provider,
46
- )
47
- return await contract.balanceOf.staticCall(accountAddress)
50
+ return (await cc.readContract({
51
+ address: asset.tokenAddress,
52
+ abi: ERC20_ABI,
53
+ functionName: "balanceOf",
54
+ args: [accountAddress],
55
+ })) as bigint
48
56
  }
49
57
  case TokenStandard.ERC1155: {
50
58
  if (asset.tokenId === undefined || asset.tokenId === null) {
51
59
  throw new Error("Missing ERC1155 tokenId for getBalance")
52
60
  }
53
- const contract = ERC1155__factory.connect(
54
- asset.tokenAddress,
55
- this.context.provider,
56
- )
57
- return await contract.balanceOf.staticCall(
58
- accountAddress,
59
- asset.tokenId,
60
- )
61
+ return (await cc.readContract({
62
+ address: asset.tokenAddress,
63
+ abi: ERC1155_ABI,
64
+ functionName: "balanceOf",
65
+ args: [accountAddress, asset.tokenId],
66
+ })) as bigint
61
67
  }
62
68
  case TokenStandard.ERC721: {
63
69
  if (asset.tokenId === undefined || asset.tokenId === null) {
64
70
  throw new Error("Missing ERC721 tokenId for getBalance")
65
71
  }
66
- const contract = ERC721__factory.connect(
67
- asset.tokenAddress,
68
- this.context.provider,
69
- )
70
72
  try {
71
- const owner = await contract.ownerOf.staticCall(asset.tokenId)
73
+ const owner = (await cc.readContract({
74
+ address: asset.tokenAddress,
75
+ abi: ERC721_ABI,
76
+ functionName: "ownerOf",
77
+ args: [asset.tokenId],
78
+ })) as string
72
79
  return BigInt(owner.toLowerCase() === accountAddress.toLowerCase())
73
80
  } catch (error: any) {
74
81
  this.context.logger(
@@ -99,24 +106,28 @@ export class AssetsManager {
99
106
  overrides,
100
107
  }: {
101
108
  asset: AssetWithTokenStandard
102
- amount?: BigNumberish
109
+ amount?: Amount
103
110
  fromAddress: string
104
111
  toAddress: string
105
- overrides?: Overrides
112
+ overrides?: Record<string, unknown>
106
113
  }): Promise<void> {
107
- overrides = { ...overrides, from: fromAddress }
108
- let transaction: Promise<ContractTransactionResponse>
114
+ const cc = this.context.contractCaller
115
+ const txOverrides = { ...overrides, from: fromAddress }
116
+
117
+ let txPromise: Promise<{ hash: string; wait(): Promise<void> }>
109
118
 
110
119
  switch (asset.tokenStandard) {
111
120
  case TokenStandard.ERC20: {
112
121
  if (!amount) {
113
122
  throw new Error("Missing ERC20 amount for transfer")
114
123
  }
115
- const contract = ERC20__factory.connect(
116
- asset.tokenAddress,
117
- this.context.signerOrProvider,
118
- )
119
- transaction = contract.transfer(toAddress, amount, overrides)
124
+ txPromise = cc.writeContract({
125
+ address: asset.tokenAddress,
126
+ abi: ERC20_ABI,
127
+ functionName: "transfer",
128
+ args: [toAddress, amount],
129
+ overrides: txOverrides,
130
+ })
120
131
  break
121
132
  }
122
133
  case TokenStandard.ERC1155: {
@@ -126,34 +137,26 @@ export class AssetsManager {
126
137
  if (!amount) {
127
138
  throw new Error("Missing ERC1155 amount for transfer")
128
139
  }
129
- const contract = ERC1155__factory.connect(
130
- asset.tokenAddress,
131
- this.context.signerOrProvider,
132
- )
133
- transaction = contract.safeTransferFrom(
134
- fromAddress,
135
- toAddress,
136
- asset.tokenId,
137
- amount,
138
- "0x",
139
- overrides,
140
- )
140
+ txPromise = cc.writeContract({
141
+ address: asset.tokenAddress,
142
+ abi: ERC1155_ABI,
143
+ functionName: "safeTransferFrom",
144
+ args: [fromAddress, toAddress, asset.tokenId, amount, "0x"],
145
+ overrides: txOverrides,
146
+ })
141
147
  break
142
148
  }
143
149
  case TokenStandard.ERC721: {
144
150
  if (asset.tokenId === undefined || asset.tokenId === null) {
145
151
  throw new Error("Missing ERC721 tokenId for transfer")
146
152
  }
147
- const contract = ERC721__factory.connect(
148
- asset.tokenAddress,
149
- this.context.signerOrProvider,
150
- )
151
- transaction = contract.transferFrom(
152
- fromAddress,
153
- toAddress,
154
- asset.tokenId,
155
- overrides,
156
- )
153
+ txPromise = cc.writeContract({
154
+ address: asset.tokenAddress,
155
+ abi: ERC721_ABI,
156
+ functionName: "transferFrom",
157
+ args: [fromAddress, toAddress, asset.tokenId],
158
+ overrides: txOverrides,
159
+ })
157
160
  break
158
161
  }
159
162
  default:
@@ -161,7 +164,7 @@ export class AssetsManager {
161
164
  }
162
165
 
163
166
  try {
164
- const transactionResponse = await transaction
167
+ const transactionResponse = await txPromise
165
168
  await this.context.confirmTransaction(
166
169
  transactionResponse.hash,
167
170
  EventType.Transfer,
@@ -198,10 +201,10 @@ export class AssetsManager {
198
201
  assets: Array<{
199
202
  asset: AssetWithTokenStandard
200
203
  toAddress: string
201
- amount?: BigNumberish
204
+ amount?: Amount
202
205
  }>
203
206
  fromAddress: string
204
- overrides?: Overrides
207
+ overrides?: Record<string, unknown>
205
208
  }): Promise<string> {
206
209
  // Validate basic parameters before making any blockchain calls
207
210
  if (assets.length === 0) {
@@ -300,21 +303,19 @@ export class AssetsManager {
300
303
  )
301
304
  }
302
305
 
303
- // Create TransferHelper contract instance
304
- const transferHelper = this.getTransferHelperContract()
305
-
306
306
  this.context.dispatch(EventType.Transfer, {
307
307
  accountAddress: fromAddress,
308
308
  assets,
309
309
  })
310
310
 
311
311
  try {
312
- // Use chain-specific conduit key for bulk transfers
313
- const transaction = await transferHelper.bulkTransfer(
314
- transferItems,
315
- defaultConduit.key,
316
- { ...overrides, from: fromAddress },
317
- )
312
+ const transaction = await this.context.contractCaller.writeContract({
313
+ address: TRANSFER_HELPER_ADDRESS,
314
+ abi: TRANSFER_HELPER_ABI,
315
+ functionName: "bulkTransfer",
316
+ args: [transferItems, defaultConduit.key],
317
+ overrides: { ...overrides, from: fromAddress },
318
+ })
318
319
 
319
320
  await this.context.confirmTransaction(
320
321
  transaction.hash,
@@ -355,10 +356,10 @@ export class AssetsManager {
355
356
  }: {
356
357
  assets: Array<{
357
358
  asset: AssetWithTokenStandard
358
- amount?: BigNumberish
359
+ amount?: Amount
359
360
  }>
360
361
  fromAddress: string
361
- overrides?: Overrides
362
+ overrides?: Record<string, unknown>
362
363
  }): Promise<string | undefined> {
363
364
  // Validate basic parameters before making any blockchain calls
364
365
  if (assets.length === 0) {
@@ -379,6 +380,7 @@ export class AssetsManager {
379
380
 
380
381
  // Get the chain-specific default conduit
381
382
  const defaultConduit = getDefaultConduit(this.context.chain)
383
+ const cc = this.context.contractCaller
382
384
 
383
385
  // Check which assets need approval and build approval calldata
384
386
  const approvalsNeeded: Array<{ target: string; callData: string }> = []
@@ -404,26 +406,22 @@ export class AssetsManager {
404
406
  processedContracts.add(asset.tokenAddress.toLowerCase())
405
407
 
406
408
  // setApprovalForAll(operator, true)
407
- const iface = new ethers.Interface([
408
- "function setApprovalForAll(address operator, bool approved)",
409
- ])
410
- const callData = iface.encodeFunctionData("setApprovalForAll", [
411
- defaultConduit.address,
412
- true,
413
- ])
409
+ const callData = cc.encodeFunctionData({
410
+ abi: SET_APPROVAL_FOR_ALL_ABI,
411
+ functionName: "setApprovalForAll",
412
+ args: [defaultConduit.address, true],
413
+ })
414
414
  approvalsNeeded.push({
415
415
  target: asset.tokenAddress,
416
416
  callData,
417
417
  })
418
418
  } else if (asset.tokenStandard === TokenStandard.ERC20) {
419
419
  // approve(spender, amount) - use max uint256 for unlimited
420
- const iface = new ethers.Interface([
421
- "function approve(address spender, uint256 amount) returns (bool)",
422
- ])
423
- const callData = iface.encodeFunctionData("approve", [
424
- defaultConduit.address,
425
- ethers.MaxUint256, // Approve max for convenience
426
- ])
420
+ const callData = cc.encodeFunctionData({
421
+ abi: APPROVE_ABI,
422
+ functionName: "approve",
423
+ args: [defaultConduit.address, MAX_UINT256],
424
+ })
427
425
  approvalsNeeded.push({
428
426
  target: asset.tokenAddress,
429
427
  callData,
@@ -437,15 +435,18 @@ export class AssetsManager {
437
435
  return undefined
438
436
  }
439
437
 
440
- // Single approval: send directly
438
+ // Single approval: send directly using the signer
441
439
  if (approvalsNeeded.length === 1) {
442
440
  const { target, callData } = approvalsNeeded[0]
443
- const signer = this.context.signerOrProvider as Signer
444
- const tx = await signer.sendTransaction({
441
+ const wallet = this.context.wallet
442
+ if (!("signer" in wallet)) {
443
+ throw new Error("A signer is required to approve assets")
444
+ }
445
+ const tx = await wallet.signer.sendTransaction({
445
446
  to: target,
446
447
  data: callData,
447
- ...overrides,
448
448
  from: fromAddress,
449
+ overrides: overrides as Record<string, unknown>,
449
450
  })
450
451
 
451
452
  await this.context.confirmTransaction(
@@ -458,8 +459,6 @@ export class AssetsManager {
458
459
  }
459
460
 
460
461
  // Multiple approvals: use Multicall3
461
- const multicall3 = this.getMulticall3Contract()
462
-
463
462
  const calls = approvalsNeeded.map(({ target, callData }) => ({
464
463
  target,
465
464
  allowFailure: false,
@@ -467,9 +466,12 @@ export class AssetsManager {
467
466
  }))
468
467
 
469
468
  try {
470
- const transaction = await multicall3.aggregate3(calls, {
471
- ...overrides,
472
- from: fromAddress,
469
+ const transaction = await cc.writeContract({
470
+ address: MULTICALL3_ADDRESS,
471
+ abi: MULTICALL3_ABI,
472
+ functionName: "aggregate3",
473
+ args: [calls],
474
+ overrides: { ...overrides, from: fromAddress },
473
475
  })
474
476
 
475
477
  await this.context.confirmTransaction(
@@ -491,27 +493,24 @@ export class AssetsManager {
491
493
 
492
494
  /**
493
495
  * Check if an asset is approved for transfer to a specific operator (conduit).
494
- * @param asset The asset to check approval for
495
- * @param owner The owner address
496
- * @param operator The operator address (conduit)
497
- * @param amount Optional amount for ERC20 tokens
498
- * @returns True if approved, false otherwise
499
496
  */
500
497
  private async checkAssetApproval(
501
498
  asset: AssetWithTokenStandard,
502
499
  owner: string,
503
500
  operator: string,
504
- amount?: BigNumberish,
501
+ amount?: Amount,
505
502
  ): Promise<boolean> {
503
+ const cc = this.context.contractCaller
504
+
506
505
  try {
507
506
  switch (asset.tokenStandard) {
508
507
  case TokenStandard.ERC20: {
509
- const contract = ERC20__factory.connect(
510
- asset.tokenAddress,
511
- this.context.provider,
512
- )
513
- const allowance = await contract.allowance.staticCall(owner, operator)
514
- // Check if allowance is sufficient
508
+ const allowance = (await cc.readContract({
509
+ address: asset.tokenAddress,
510
+ abi: ERC20_ABI,
511
+ functionName: "allowance",
512
+ args: [owner, operator],
513
+ })) as bigint
515
514
  if (!amount) {
516
515
  return false
517
516
  }
@@ -519,73 +518,44 @@ export class AssetsManager {
519
518
  }
520
519
 
521
520
  case TokenStandard.ERC721: {
522
- const contract = ERC721__factory.connect(
523
- asset.tokenAddress,
524
- this.context.provider,
525
- )
526
- // Check isApprovedForAll first
527
- const isApprovedForAll = await contract.isApprovedForAll.staticCall(
528
- owner,
529
- operator,
530
- )
521
+ const isApprovedForAll = (await cc.readContract({
522
+ address: asset.tokenAddress,
523
+ abi: ERC721_ABI,
524
+ functionName: "isApprovedForAll",
525
+ args: [owner, operator],
526
+ })) as boolean
531
527
  if (isApprovedForAll) {
532
528
  return true
533
529
  }
534
- // Check individual token approval
535
530
  if (asset.tokenId !== undefined && asset.tokenId !== null) {
536
- const approved = await contract.getApproved.staticCall(
537
- asset.tokenId,
538
- )
531
+ const approved = (await cc.readContract({
532
+ address: asset.tokenAddress,
533
+ abi: ERC721_ABI,
534
+ functionName: "getApproved",
535
+ args: [asset.tokenId],
536
+ })) as string
539
537
  return approved.toLowerCase() === operator.toLowerCase()
540
538
  }
541
539
  return false
542
540
  }
543
541
 
544
542
  case TokenStandard.ERC1155: {
545
- const contract = ERC1155__factory.connect(
546
- asset.tokenAddress,
547
- this.context.provider,
548
- )
549
- return await contract.isApprovedForAll.staticCall(owner, operator)
543
+ return (await cc.readContract({
544
+ address: asset.tokenAddress,
545
+ abi: ERC1155_ABI,
546
+ functionName: "isApprovedForAll",
547
+ args: [owner, operator],
548
+ })) as boolean
550
549
  }
551
550
 
552
551
  default:
553
552
  return false
554
553
  }
555
554
  } catch (error) {
556
- // If there's an error checking approval (e.g., contract doesn't exist), return false
557
555
  this.context.logger(
558
556
  `Error checking approval for ${asset.tokenAddress}: ${error}`,
559
557
  )
560
558
  return false
561
559
  }
562
560
  }
563
-
564
- /**
565
- * Get a TransferHelper contract instance.
566
- * @returns Contract instance for TransferHelper
567
- */
568
- private getTransferHelperContract(): Contract {
569
- return new Contract(
570
- TRANSFER_HELPER_ADDRESS,
571
- [
572
- "function bulkTransfer(tuple(uint8 itemType, address token, uint256 identifier, uint256 amount, address recipient)[] items, bytes32 conduitKey) external returns (bytes4)",
573
- ],
574
- this.context.signerOrProvider,
575
- )
576
- }
577
-
578
- /**
579
- * Get a Multicall3 contract instance.
580
- * @returns Contract instance for Multicall3
581
- */
582
- private getMulticall3Contract(): Contract {
583
- return new Contract(
584
- MULTICALL3_ADDRESS,
585
- [
586
- "function aggregate3(tuple(address target, bool allowFailure, bytes callData)[] calls) payable returns (tuple(bool success, bytes returnData)[] returnData)",
587
- ],
588
- this.context.signerOrProvider,
589
- )
590
- }
591
561
  }