@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.
- package/README.md +35 -6
- package/lib/abi/abis.d.ts +301 -0
- package/lib/abi/abis.js +231 -0
- package/lib/abi/abis.js.map +1 -0
- package/lib/api/api.d.ts +26 -2
- package/lib/api/api.js +83 -51
- package/lib/api/api.js.map +1 -1
- package/lib/api/apiPaths.d.ts +2 -0
- package/lib/api/apiPaths.js +9 -1
- package/lib/api/apiPaths.js.map +1 -1
- package/lib/api/nfts.d.ts +13 -2
- package/lib/api/nfts.js +18 -0
- package/lib/api/nfts.js.map +1 -1
- package/lib/api/orders.js +2 -2
- package/lib/api/orders.js.map +1 -1
- package/lib/api/types.d.ts +7 -0
- package/lib/api/types.js.map +1 -1
- package/lib/constants.d.ts +2 -2
- package/lib/constants.js +7 -4
- package/lib/constants.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/orders/privateListings.js +2 -2
- package/lib/orders/privateListings.js.map +1 -1
- package/lib/orders/utils.js +9 -1
- package/lib/orders/utils.js.map +1 -1
- package/lib/provider/ethers-adapter.d.ts +17 -0
- package/lib/provider/ethers-adapter.js +135 -0
- package/lib/provider/ethers-adapter.js.map +1 -0
- package/lib/provider/seaport-bridge.d.ts +11 -0
- package/lib/provider/seaport-bridge.js +130 -0
- package/lib/provider/seaport-bridge.js.map +1 -0
- package/lib/provider/types.d.ts +62 -0
- package/lib/provider/types.js +7 -0
- package/lib/provider/types.js.map +1 -0
- package/lib/provider/viem-adapter.d.ts +27 -0
- package/lib/provider/viem-adapter.js +122 -0
- package/lib/provider/viem-adapter.js.map +1 -0
- package/lib/sdk/assets.d.ts +7 -23
- package/lib/sdk/assets.js +101 -77
- package/lib/sdk/assets.js.map +1 -1
- package/lib/sdk/base.d.ts +350 -0
- package/lib/sdk/base.js +325 -0
- package/lib/sdk/base.js.map +1 -0
- package/lib/sdk/cancellation.d.ts +1 -2
- package/lib/sdk/cancellation.js +4 -4
- package/lib/sdk/cancellation.js.map +1 -1
- package/lib/sdk/context.d.ts +5 -5
- package/lib/sdk/fulfillment.d.ts +20 -59
- package/lib/sdk/fulfillment.js +18 -58
- package/lib/sdk/fulfillment.js.map +1 -1
- package/lib/sdk/orders.d.ts +25 -26
- package/lib/sdk/orders.js +8 -9
- package/lib/sdk/orders.js.map +1 -1
- package/lib/sdk/tokens.d.ts +3 -3
- package/lib/sdk/tokens.js +17 -7
- package/lib/sdk/tokens.js.map +1 -1
- package/lib/sdk.d.ts +16 -550
- package/lib/sdk.js +35 -663
- package/lib/sdk.js.map +1 -1
- package/lib/types.d.ts +11 -6
- package/lib/types.js +3 -3
- package/lib/types.js.map +1 -1
- package/lib/utils/address.d.ts +12 -0
- package/lib/utils/address.js +39 -0
- package/lib/utils/address.js.map +1 -0
- package/lib/utils/chain.d.ts +1 -1
- package/lib/utils/fees.d.ts +5 -0
- package/lib/utils/fees.js +24 -6
- package/lib/utils/fees.js.map +1 -1
- package/lib/utils/protocol.js +5 -5
- package/lib/utils/protocol.js.map +1 -1
- package/lib/utils/units.d.ts +12 -0
- package/lib/utils/units.js +43 -0
- package/lib/utils/units.js.map +1 -0
- package/lib/utils/utils.d.ts +2 -10
- package/lib/utils/utils.js +2 -17
- package/lib/utils/utils.js.map +1 -1
- package/lib/viem.d.ts +44 -0
- package/lib/viem.js +114 -0
- package/lib/viem.js.map +1 -0
- package/package.json +31 -13
- package/src/abi/abis.ts +236 -0
- package/src/api/api.ts +100 -59
- package/src/api/apiPaths.ts +16 -0
- package/src/api/nfts.ts +37 -1
- package/src/api/orders.ts +2 -2
- package/src/api/types.ts +8 -0
- package/src/constants.ts +7 -3
- package/src/index.ts +8 -0
- package/src/orders/privateListings.ts +2 -2
- package/src/orders/utils.ts +8 -1
- package/src/provider/ethers-adapter.ts +182 -0
- package/src/provider/seaport-bridge.ts +163 -0
- package/src/provider/types.ts +67 -0
- package/src/provider/viem-adapter.ts +165 -0
- package/src/sdk/assets.ts +128 -158
- package/src/sdk/base.ts +577 -0
- package/src/sdk/cancellation.ts +6 -9
- package/src/sdk/context.ts +5 -5
- package/src/sdk/fulfillment.ts +34 -73
- package/src/sdk/orders.ts +44 -44
- package/src/sdk/tokens.ts +18 -18
- package/src/sdk.ts +40 -1011
- package/src/types.ts +12 -6
- package/src/utils/address.ts +40 -0
- package/src/utils/fees.ts +28 -8
- package/src/utils/protocol.ts +5 -5
- package/src/utils/units.ts +47 -0
- package/src/utils/utils.ts +2 -22
- package/src/viem.ts +125 -0
- package/lib/src/api/accounts.d.ts +0 -18
- package/lib/src/api/accounts.js +0 -30
- package/lib/src/api/accounts.js.map +0 -1
- package/lib/src/api/api.d.ts +0 -429
- package/lib/src/api/api.js +0 -652
- package/lib/src/api/api.js.map +0 -1
- package/lib/src/api/apiPaths.d.ts +0 -37
- package/lib/src/api/apiPaths.js +0 -140
- package/lib/src/api/apiPaths.js.map +0 -1
- package/lib/src/api/collections.d.ts +0 -26
- package/lib/src/api/collections.js +0 -57
- package/lib/src/api/collections.js.map +0 -1
- package/lib/src/api/events.d.ts +0 -26
- package/lib/src/api/events.js +0 -42
- package/lib/src/api/events.js.map +0 -1
- package/lib/src/api/fetcher.d.ts +0 -24
- package/lib/src/api/fetcher.js +0 -3
- package/lib/src/api/fetcher.js.map +0 -1
- package/lib/src/api/index.d.ts +0 -2
- package/lib/src/api/index.js +0 -19
- package/lib/src/api/index.js.map +0 -1
- package/lib/src/api/listings.d.ts +0 -44
- package/lib/src/api/listings.js +0 -86
- package/lib/src/api/listings.js.map +0 -1
- package/lib/src/api/nfts.d.ts +0 -35
- package/lib/src/api/nfts.js +0 -66
- package/lib/src/api/nfts.js.map +0 -1
- package/lib/src/api/offers.d.ts +0 -54
- package/lib/src/api/offers.js +0 -122
- package/lib/src/api/offers.js.map +0 -1
- package/lib/src/api/orders.d.ts +0 -50
- package/lib/src/api/orders.js +0 -151
- package/lib/src/api/orders.js.map +0 -1
- package/lib/src/api/search.d.ts +0 -13
- package/lib/src/api/search.js +0 -21
- package/lib/src/api/search.js.map +0 -1
- package/lib/src/api/tokens.d.ts +0 -25
- package/lib/src/api/tokens.js +0 -42
- package/lib/src/api/tokens.js.map +0 -1
- package/lib/src/api/types.d.ts +0 -840
- package/lib/src/api/types.js +0 -65
- package/lib/src/api/types.js.map +0 -1
- package/lib/src/constants.d.ts +0 -22
- package/lib/src/constants.js +0 -52
- package/lib/src/constants.js.map +0 -1
- package/lib/src/index.d.ts +0 -18
- package/lib/src/index.js +0 -24
- package/lib/src/index.js.map +0 -1
- package/lib/src/orders/privateListings.d.ts +0 -12
- package/lib/src/orders/privateListings.js +0 -130
- package/lib/src/orders/privateListings.js.map +0 -1
- package/lib/src/orders/types.d.ts +0 -160
- package/lib/src/orders/types.js +0 -10
- package/lib/src/orders/types.js.map +0 -1
- package/lib/src/orders/utils.d.ts +0 -89
- package/lib/src/orders/utils.js +0 -177
- package/lib/src/orders/utils.js.map +0 -1
- package/lib/src/sdk/assets.d.ts +0 -104
- package/lib/src/sdk/assets.js +0 -397
- package/lib/src/sdk/assets.js.map +0 -1
- package/lib/src/sdk/cancellation.d.ts +0 -97
- package/lib/src/sdk/cancellation.js +0 -234
- package/lib/src/sdk/cancellation.js.map +0 -1
- package/lib/src/sdk/context.d.ts +0 -28
- package/lib/src/sdk/context.js +0 -3
- package/lib/src/sdk/context.js.map +0 -1
- package/lib/src/sdk/fulfillment.d.ts +0 -153
- package/lib/src/sdk/fulfillment.js +0 -296
- package/lib/src/sdk/fulfillment.js.map +0 -1
- package/lib/src/sdk/orders.d.ts +0 -253
- package/lib/src/sdk/orders.js +0 -677
- package/lib/src/sdk/orders.js.map +0 -1
- package/lib/src/sdk/tokens.d.ts +0 -31
- package/lib/src/sdk/tokens.js +0 -64
- package/lib/src/sdk/tokens.js.map +0 -1
- package/lib/src/sdk.d.ts +0 -560
- package/lib/src/sdk.js +0 -675
- package/lib/src/sdk.js.map +0 -1
- package/lib/src/typechain/contracts/ERC1155.d.ts +0 -236
- package/lib/src/typechain/contracts/ERC1155.js +0 -3
- package/lib/src/typechain/contracts/ERC1155.js.map +0 -1
- package/lib/src/typechain/contracts/ERC20.d.ts +0 -141
- package/lib/src/typechain/contracts/ERC20.js +0 -3
- package/lib/src/typechain/contracts/ERC20.js.map +0 -1
- package/lib/src/typechain/contracts/ERC721.d.ts +0 -213
- package/lib/src/typechain/contracts/ERC721.js +0 -3
- package/lib/src/typechain/contracts/ERC721.js.map +0 -1
- package/lib/src/typechain/contracts/Multicall3.d.ts +0 -57
- package/lib/src/typechain/contracts/Multicall3.js +0 -3
- package/lib/src/typechain/contracts/Multicall3.js.map +0 -1
- package/lib/src/typechain/contracts/TransferHelper.d.ts +0 -55
- package/lib/src/typechain/contracts/TransferHelper.js +0 -3
- package/lib/src/typechain/contracts/TransferHelper.js.map +0 -1
- package/lib/src/typechain/contracts/common.d.ts +0 -50
- package/lib/src/typechain/contracts/common.js +0 -3
- package/lib/src/typechain/contracts/common.js.map +0 -1
- package/lib/src/typechain/contracts/factories/ERC1155__factory.d.ts +0 -250
- package/lib/src/typechain/contracts/factories/ERC1155__factory.js +0 -332
- package/lib/src/typechain/contracts/factories/ERC1155__factory.js.map +0 -1
- package/lib/src/typechain/contracts/factories/ERC20__factory.d.ts +0 -174
- package/lib/src/typechain/contracts/factories/ERC20__factory.js +0 -240
- package/lib/src/typechain/contracts/factories/ERC20__factory.js.map +0 -1
- package/lib/src/typechain/contracts/factories/ERC721__factory.d.ts +0 -268
- package/lib/src/typechain/contracts/factories/ERC721__factory.js +0 -351
- package/lib/src/typechain/contracts/factories/ERC721__factory.js.map +0 -1
- package/lib/src/typechain/contracts/factories/Multicall3__factory.d.ts +0 -43
- package/lib/src/typechain/contracts/factories/Multicall3__factory.js +0 -68
- package/lib/src/typechain/contracts/factories/Multicall3__factory.js.map +0 -1
- package/lib/src/typechain/contracts/factories/TransferHelper__factory.d.ts +0 -46
- package/lib/src/typechain/contracts/factories/TransferHelper__factory.js +0 -71
- package/lib/src/typechain/contracts/factories/TransferHelper__factory.js.map +0 -1
- package/lib/src/typechain/contracts/factories/index.d.ts +0 -5
- package/lib/src/typechain/contracts/factories/index.js +0 -17
- package/lib/src/typechain/contracts/factories/index.js.map +0 -1
- package/lib/src/typechain/contracts/index.d.ts +0 -11
- package/lib/src/typechain/contracts/index.js +0 -48
- package/lib/src/typechain/contracts/index.js.map +0 -1
- package/lib/src/types.d.ts +0 -387
- package/lib/src/types.js +0 -127
- package/lib/src/types.js.map +0 -1
- package/lib/src/utils/chain.d.ts +0 -60
- package/lib/src/utils/chain.js +0 -248
- package/lib/src/utils/chain.js.map +0 -1
- package/lib/src/utils/converters.d.ts +0 -37
- package/lib/src/utils/converters.js +0 -137
- package/lib/src/utils/converters.js.map +0 -1
- package/lib/src/utils/dateHelper.d.ts +0 -38
- package/lib/src/utils/dateHelper.js +0 -52
- package/lib/src/utils/dateHelper.js.map +0 -1
- package/lib/src/utils/fees.d.ts +0 -13
- package/lib/src/utils/fees.js +0 -29
- package/lib/src/utils/fees.js.map +0 -1
- package/lib/src/utils/index.d.ts +0 -2
- package/lib/src/utils/index.js +0 -19
- package/lib/src/utils/index.js.map +0 -1
- package/lib/src/utils/protocol.d.ts +0 -75
- package/lib/src/utils/protocol.js +0 -161
- package/lib/src/utils/protocol.js.map +0 -1
- package/lib/src/utils/rateLimit.d.ts +0 -34
- package/lib/src/utils/rateLimit.js +0 -97
- package/lib/src/utils/rateLimit.js.map +0 -1
- package/lib/src/utils/stringHelper.d.ts +0 -18
- package/lib/src/utils/stringHelper.js +0 -24
- package/lib/src/utils/stringHelper.js.map +0 -1
- package/lib/src/utils/utils.d.ts +0 -18
- package/lib/src/utils/utils.js +0 -45
- package/lib/src/utils/utils.js.map +0 -1
- package/lib/typechain/contracts/ERC1155.d.ts +0 -236
- package/lib/typechain/contracts/ERC1155.js +0 -3
- package/lib/typechain/contracts/ERC1155.js.map +0 -1
- package/lib/typechain/contracts/ERC20.d.ts +0 -141
- package/lib/typechain/contracts/ERC20.js +0 -3
- package/lib/typechain/contracts/ERC20.js.map +0 -1
- package/lib/typechain/contracts/ERC721.d.ts +0 -213
- package/lib/typechain/contracts/ERC721.js +0 -3
- package/lib/typechain/contracts/ERC721.js.map +0 -1
- package/lib/typechain/contracts/Multicall3.d.ts +0 -57
- package/lib/typechain/contracts/Multicall3.js +0 -3
- package/lib/typechain/contracts/Multicall3.js.map +0 -1
- package/lib/typechain/contracts/TransferHelper.d.ts +0 -55
- package/lib/typechain/contracts/TransferHelper.js +0 -3
- package/lib/typechain/contracts/TransferHelper.js.map +0 -1
- package/lib/typechain/contracts/common.d.ts +0 -50
- package/lib/typechain/contracts/common.js +0 -3
- package/lib/typechain/contracts/common.js.map +0 -1
- package/lib/typechain/contracts/factories/ERC1155__factory.d.ts +0 -250
- package/lib/typechain/contracts/factories/ERC1155__factory.js +0 -332
- package/lib/typechain/contracts/factories/ERC1155__factory.js.map +0 -1
- package/lib/typechain/contracts/factories/ERC20__factory.d.ts +0 -174
- package/lib/typechain/contracts/factories/ERC20__factory.js +0 -240
- package/lib/typechain/contracts/factories/ERC20__factory.js.map +0 -1
- package/lib/typechain/contracts/factories/ERC721__factory.d.ts +0 -268
- package/lib/typechain/contracts/factories/ERC721__factory.js +0 -351
- package/lib/typechain/contracts/factories/ERC721__factory.js.map +0 -1
- package/lib/typechain/contracts/factories/Multicall3__factory.d.ts +0 -43
- package/lib/typechain/contracts/factories/Multicall3__factory.js +0 -68
- package/lib/typechain/contracts/factories/Multicall3__factory.js.map +0 -1
- package/lib/typechain/contracts/factories/TransferHelper__factory.d.ts +0 -46
- package/lib/typechain/contracts/factories/TransferHelper__factory.js +0 -71
- package/lib/typechain/contracts/factories/TransferHelper__factory.js.map +0 -1
- package/lib/typechain/contracts/factories/index.d.ts +0 -5
- package/lib/typechain/contracts/factories/index.js +0 -17
- package/lib/typechain/contracts/factories/index.js.map +0 -1
- package/lib/typechain/contracts/index.d.ts +0 -11
- package/lib/typechain/contracts/index.js +0 -48
- package/lib/typechain/contracts/index.js.map +0 -1
- package/src/typechain/contracts/ERC1155.ts +0 -440
- package/src/typechain/contracts/ERC20.ts +0 -286
- package/src/typechain/contracts/ERC721.ts +0 -412
- package/src/typechain/contracts/Multicall3.ts +0 -117
- package/src/typechain/contracts/TransferHelper.ts +0 -122
- package/src/typechain/contracts/common.ts +0 -131
- package/src/typechain/contracts/factories/ERC1155__factory.ts +0 -331
- package/src/typechain/contracts/factories/ERC20__factory.ts +0 -239
- package/src/typechain/contracts/factories/ERC721__factory.ts +0 -350
- package/src/typechain/contracts/factories/Multicall3__factory.ts +0 -67
- package/src/typechain/contracts/factories/TransferHelper__factory.ts +0 -76
- package/src/typechain/contracts/factories/index.ts +0 -8
- package/src/typechain/contracts/index.ts +0 -14
package/src/sdk/assets.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from "../
|
|
15
|
-
import {
|
|
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
|
-
|
|
44
|
-
asset.tokenAddress,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
54
|
-
asset.tokenAddress,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
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?:
|
|
109
|
+
amount?: Amount
|
|
103
110
|
fromAddress: string
|
|
104
111
|
toAddress: string
|
|
105
|
-
overrides?:
|
|
112
|
+
overrides?: Record<string, unknown>
|
|
106
113
|
}): Promise<void> {
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
116
|
-
asset.tokenAddress,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
130
|
-
asset.tokenAddress,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
148
|
-
asset.tokenAddress,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
|
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?:
|
|
204
|
+
amount?: Amount
|
|
202
205
|
}>
|
|
203
206
|
fromAddress: string
|
|
204
|
-
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
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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?:
|
|
359
|
+
amount?: Amount
|
|
359
360
|
}>
|
|
360
361
|
fromAddress: string
|
|
361
|
-
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
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
|
444
|
-
|
|
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
|
|
471
|
-
|
|
472
|
-
|
|
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?:
|
|
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
|
|
510
|
-
asset.tokenAddress,
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
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
|
|
523
|
-
asset.tokenAddress,
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
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
|
|
537
|
-
asset.
|
|
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
|
-
|
|
546
|
-
asset.tokenAddress,
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
}
|