@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.
- package/README.md +25 -4
- 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 +6 -1
- package/lib/api/api.js +60 -51
- package/lib/api/api.js.map +1 -1
- package/lib/api/orders.js +2 -2
- package/lib/api/orders.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 +334 -0
- package/lib/sdk/base.js +312 -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 +13 -58
- package/lib/sdk/fulfillment.js +16 -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 +25 -8
- package/src/abi/abis.ts +236 -0
- package/src/api/api.ts +66 -59
- package/src/api/orders.ts +2 -2
- 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 +558 -0
- package/src/sdk/cancellation.ts +6 -9
- package/src/sdk/context.ts +5 -5
- package/src/sdk/fulfillment.ts +31 -72
- 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
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ethers v6 adapter — wraps ethers Signer/Provider into the SDK's abstract interfaces.
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
Contract,
|
|
6
|
+
ethers as ethersLib,
|
|
7
|
+
type JsonRpcProvider,
|
|
8
|
+
type Signer,
|
|
9
|
+
} from "ethers"
|
|
10
|
+
import type {
|
|
11
|
+
ContractCaller,
|
|
12
|
+
OpenSeaProvider,
|
|
13
|
+
OpenSeaSigner,
|
|
14
|
+
OpenSeaWallet,
|
|
15
|
+
TransactionResponse,
|
|
16
|
+
} from "./types"
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates an OpenSeaWallet from an ethers Signer or JsonRpcProvider.
|
|
20
|
+
*/
|
|
21
|
+
export function createEthersWallet(
|
|
22
|
+
signerOrProvider: Signer | JsonRpcProvider,
|
|
23
|
+
): OpenSeaWallet {
|
|
24
|
+
const provider = createEthersProvider(signerOrProvider)
|
|
25
|
+
|
|
26
|
+
if (isEthersSigner(signerOrProvider)) {
|
|
27
|
+
return {
|
|
28
|
+
signer: createEthersSigner(signerOrProvider),
|
|
29
|
+
provider,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return { provider }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates an OpenSeaSigner from an ethers Signer.
|
|
38
|
+
*/
|
|
39
|
+
function createEthersSigner(signer: Signer): OpenSeaSigner {
|
|
40
|
+
return {
|
|
41
|
+
async getAddress(): Promise<string> {
|
|
42
|
+
if ("address" in signer) {
|
|
43
|
+
return signer.address as string
|
|
44
|
+
}
|
|
45
|
+
return signer.getAddress()
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
async sendTransaction(tx) {
|
|
49
|
+
const ethTx = await signer.sendTransaction({
|
|
50
|
+
to: tx.to,
|
|
51
|
+
data: tx.data,
|
|
52
|
+
value: tx.value,
|
|
53
|
+
from: tx.from,
|
|
54
|
+
...tx.overrides,
|
|
55
|
+
})
|
|
56
|
+
return {
|
|
57
|
+
hash: ethTx.hash,
|
|
58
|
+
async wait() {
|
|
59
|
+
await ethTx.wait()
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
async signTypedData(domain, types, value) {
|
|
65
|
+
if (typeof (signer as any).signTypedData !== "function") {
|
|
66
|
+
throw new Error(
|
|
67
|
+
"The provided signer does not support signTypedData. Please use an ethers Signer that supports EIP-712 signing.",
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
return (signer as any).signTypedData(domain, types, value)
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Creates an OpenSeaProvider from an ethers Signer or JsonRpcProvider.
|
|
77
|
+
*/
|
|
78
|
+
function createEthersProvider(
|
|
79
|
+
signerOrProvider: Signer | JsonRpcProvider,
|
|
80
|
+
): OpenSeaProvider {
|
|
81
|
+
const provider = isEthersSigner(signerOrProvider)
|
|
82
|
+
? (signerOrProvider.provider as JsonRpcProvider)
|
|
83
|
+
: signerOrProvider
|
|
84
|
+
|
|
85
|
+
if (!provider) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
"Signer must be connected to a provider. " +
|
|
88
|
+
"Use `signer.connect(provider)` or pass a JsonRpcProvider directly.",
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
async waitForTransaction(hash: string) {
|
|
94
|
+
await provider.waitForTransaction(hash)
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Creates a ContractCaller using ethers Contract.
|
|
101
|
+
*/
|
|
102
|
+
export function createEthersContractCaller(
|
|
103
|
+
signerOrProvider: Signer | JsonRpcProvider,
|
|
104
|
+
): ContractCaller {
|
|
105
|
+
const readProvider = isEthersSigner(signerOrProvider)
|
|
106
|
+
? (signerOrProvider.provider as JsonRpcProvider)
|
|
107
|
+
: signerOrProvider
|
|
108
|
+
|
|
109
|
+
if (!readProvider) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
"Signer must be connected to a provider. " +
|
|
112
|
+
"Use `signer.connect(provider)` or pass a JsonRpcProvider directly.",
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
async readContract({ address, abi, functionName, args }) {
|
|
118
|
+
const contract = new Contract(address, abi as any[], readProvider)
|
|
119
|
+
return contract[functionName].staticCall(...args)
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
async writeContract({
|
|
123
|
+
address,
|
|
124
|
+
abi,
|
|
125
|
+
functionName,
|
|
126
|
+
args,
|
|
127
|
+
value,
|
|
128
|
+
overrides,
|
|
129
|
+
}): Promise<TransactionResponse> {
|
|
130
|
+
const contract = new Contract(address, abi as any[], signerOrProvider)
|
|
131
|
+
const txArgs = [...args]
|
|
132
|
+
if (value !== undefined || overrides) {
|
|
133
|
+
txArgs.push({ ...overrides, value })
|
|
134
|
+
}
|
|
135
|
+
const tx = await contract[functionName](...txArgs)
|
|
136
|
+
return {
|
|
137
|
+
hash: tx.hash,
|
|
138
|
+
async wait() {
|
|
139
|
+
await tx.wait()
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
encodeFunctionData({ abi, functionName, args }) {
|
|
145
|
+
const iface = new ethersLib.Interface(abi as any[])
|
|
146
|
+
return iface.encodeFunctionData(functionName, args)
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Get available accounts from an ethers Signer or JsonRpcProvider.
|
|
153
|
+
*/
|
|
154
|
+
export async function getEthersAccounts(
|
|
155
|
+
signerOrProvider: Signer | JsonRpcProvider,
|
|
156
|
+
logger: (msg: string) => void,
|
|
157
|
+
): Promise<string[]> {
|
|
158
|
+
const accounts: string[] = []
|
|
159
|
+
try {
|
|
160
|
+
if ("address" in signerOrProvider) {
|
|
161
|
+
accounts.push(signerOrProvider.address as string)
|
|
162
|
+
} else if ("listAccounts" in signerOrProvider) {
|
|
163
|
+
const listed = (
|
|
164
|
+
await (signerOrProvider as JsonRpcProvider).listAccounts()
|
|
165
|
+
).map(acct => acct.address)
|
|
166
|
+
accounts.push(...listed)
|
|
167
|
+
} else if ("getAddress" in signerOrProvider) {
|
|
168
|
+
accounts.push(await (signerOrProvider as Signer).getAddress())
|
|
169
|
+
}
|
|
170
|
+
} catch (error) {
|
|
171
|
+
logger(
|
|
172
|
+
`Failed to get available accounts: ${error instanceof Error ? error.message : error}`,
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
return accounts
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function isEthersSigner(
|
|
179
|
+
signerOrProvider: Signer | JsonRpcProvider,
|
|
180
|
+
): signerOrProvider is Signer {
|
|
181
|
+
return "signTransaction" in signerOrProvider
|
|
182
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge that wraps viem clients as an ethers-compatible Signer for seaport-js.
|
|
3
|
+
* seaport-js only accepts ethers Signer | JsonRpcProvider, so we need this shim.
|
|
4
|
+
*/
|
|
5
|
+
import {
|
|
6
|
+
AbstractSigner,
|
|
7
|
+
JsonRpcProvider,
|
|
8
|
+
type TransactionRequest,
|
|
9
|
+
type TransactionResponse,
|
|
10
|
+
} from "ethers"
|
|
11
|
+
import type { ViemAdapterParams } from "./viem-adapter"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates an ethers-compatible Signer from viem clients, for use with seaport-js.
|
|
15
|
+
* If only a publicClient is provided (no walletClient), returns a read-only JsonRpcProvider.
|
|
16
|
+
*/
|
|
17
|
+
export function createSeaportBridge(
|
|
18
|
+
params: ViemAdapterParams,
|
|
19
|
+
logger?: (msg: string) => void,
|
|
20
|
+
): AbstractSigner | JsonRpcProvider {
|
|
21
|
+
const { publicClient, walletClient, rpcUrl: explicitRpcUrl } = params
|
|
22
|
+
|
|
23
|
+
// We need the chain's RPC URL to create an ethers provider for seaport-js.
|
|
24
|
+
// Prefer an explicit rpcUrl if provided (needed for non-HTTP transports).
|
|
25
|
+
// Otherwise, extract it from the viem transport's internal properties.
|
|
26
|
+
// NOTE: transport.url / transport.value.url are viem internals that may
|
|
27
|
+
// change across viem versions.
|
|
28
|
+
const transport = (publicClient as any).transport
|
|
29
|
+
const detectedUrl = transport?.url ?? transport?.value?.url
|
|
30
|
+
const rpcUrl = explicitRpcUrl ?? detectedUrl
|
|
31
|
+
if (!rpcUrl) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"OpenSeaSDK viem entry point requires an HTTP RPC URL. " +
|
|
34
|
+
"Either use `http(url)` when creating your publicClient, or pass " +
|
|
35
|
+
"`rpcUrl` explicitly in the constructor params.",
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
if (!explicitRpcUrl && detectedUrl && logger) {
|
|
39
|
+
logger(
|
|
40
|
+
"Seaport bridge: auto-detected RPC URL from viem transport internals. " +
|
|
41
|
+
"Pass `rpcUrl` explicitly for stability across viem versions.",
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const ethersProvider = new JsonRpcProvider(rpcUrl)
|
|
46
|
+
|
|
47
|
+
if (!walletClient) {
|
|
48
|
+
return ethersProvider
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return new ViemEthersSigner(walletClient, ethersProvider)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Minimal ethers AbstractSigner implementation backed by a viem WalletClient.
|
|
56
|
+
* Implements the methods that seaport-js calls: getAddress, sendTransaction,
|
|
57
|
+
* signMessage, and signTypedData.
|
|
58
|
+
*
|
|
59
|
+
* sendTransaction is overridden to use viem's walletClient.sendTransaction directly,
|
|
60
|
+
* bypassing ethers' default signTransaction + broadcastTransaction flow (similar to
|
|
61
|
+
* how ethers' own JsonRpcSigner overrides it to use eth_sendTransaction).
|
|
62
|
+
*/
|
|
63
|
+
class ViemEthersSigner extends AbstractSigner {
|
|
64
|
+
private _walletClient: any
|
|
65
|
+
|
|
66
|
+
constructor(walletClient: any, provider: JsonRpcProvider) {
|
|
67
|
+
super(provider)
|
|
68
|
+
this._walletClient = walletClient
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async getAddress(): Promise<string> {
|
|
72
|
+
if (!this._walletClient.account) {
|
|
73
|
+
throw new Error("WalletClient must have an account")
|
|
74
|
+
}
|
|
75
|
+
return this._walletClient.account.address
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// seaport-js checks `.address` property directly on the signer.
|
|
79
|
+
// Throw if no account is set rather than returning empty string,
|
|
80
|
+
// which could cause subtle bugs in truthy checks.
|
|
81
|
+
get address(): string {
|
|
82
|
+
if (!this._walletClient.account?.address) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
"WalletClient must have an account. Use `createWalletClient` with an `account` parameter.",
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
return this._walletClient.account.address
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Override sendTransaction to delegate to viem's walletClient.sendTransaction.
|
|
92
|
+
* This bypasses AbstractSigner's default flow (signTransaction → broadcastTransaction)
|
|
93
|
+
* since viem handles signing internally via the wallet.
|
|
94
|
+
*/
|
|
95
|
+
async sendTransaction(tx: TransactionRequest): Promise<TransactionResponse> {
|
|
96
|
+
const hash = await this._walletClient.sendTransaction({
|
|
97
|
+
to: tx.to as `0x${string}`,
|
|
98
|
+
data: tx.data as `0x${string}` | undefined,
|
|
99
|
+
value: tx.value != null ? BigInt(tx.value.toString()) : undefined,
|
|
100
|
+
// Forward gas parameters when provided by seaport-js or callers
|
|
101
|
+
gas: tx.gasLimit != null ? BigInt(tx.gasLimit.toString()) : undefined,
|
|
102
|
+
gasPrice:
|
|
103
|
+
tx.gasPrice != null ? BigInt(tx.gasPrice.toString()) : undefined,
|
|
104
|
+
maxFeePerGas:
|
|
105
|
+
tx.maxFeePerGas != null
|
|
106
|
+
? BigInt(tx.maxFeePerGas.toString())
|
|
107
|
+
: undefined,
|
|
108
|
+
maxPriorityFeePerGas:
|
|
109
|
+
tx.maxPriorityFeePerGas != null
|
|
110
|
+
? BigInt(tx.maxPriorityFeePerGas.toString())
|
|
111
|
+
: undefined,
|
|
112
|
+
nonce: tx.nonce != null ? Number(tx.nonce) : undefined,
|
|
113
|
+
account: this._walletClient.account,
|
|
114
|
+
chain: this._walletClient.chain,
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
// Return an ethers-compatible TransactionResponse by fetching from the provider
|
|
118
|
+
const response = await this.provider!.getTransaction(hash)
|
|
119
|
+
if (!response) {
|
|
120
|
+
// Fallback: construct minimal response if the tx isn't indexed yet
|
|
121
|
+
return {
|
|
122
|
+
hash,
|
|
123
|
+
wait: () => this.provider!.waitForTransaction(hash),
|
|
124
|
+
} as unknown as TransactionResponse
|
|
125
|
+
}
|
|
126
|
+
return response
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async signTransaction(): Promise<string> {
|
|
130
|
+
throw new Error(
|
|
131
|
+
"signTransaction is not supported via the viem bridge. " +
|
|
132
|
+
"sendTransaction is overridden to delegate to viem directly.",
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async signMessage(message: string | Uint8Array): Promise<string> {
|
|
137
|
+
return this._walletClient.signMessage({
|
|
138
|
+
message: typeof message === "string" ? message : { raw: message as any },
|
|
139
|
+
account: this._walletClient.account,
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async signTypedData(domain: any, types: any, value: any): Promise<string> {
|
|
144
|
+
const primaryType =
|
|
145
|
+
Object.keys(types).find(key => key !== "EIP712Domain") ||
|
|
146
|
+
Object.keys(types)[0]
|
|
147
|
+
|
|
148
|
+
return this._walletClient.signTypedData({
|
|
149
|
+
domain: {
|
|
150
|
+
...domain,
|
|
151
|
+
chainId: domain.chainId ? Number(domain.chainId) : undefined,
|
|
152
|
+
},
|
|
153
|
+
types,
|
|
154
|
+
primaryType,
|
|
155
|
+
message: value,
|
|
156
|
+
account: this._walletClient.account,
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
connect(): ViemEthersSigner {
|
|
161
|
+
return this
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract provider interfaces for the OpenSea SDK.
|
|
3
|
+
* These allow the SDK to work with both ethers and viem (or any other library).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Transaction receipt returned after sending a transaction. */
|
|
7
|
+
export interface TransactionResponse {
|
|
8
|
+
hash: string
|
|
9
|
+
wait(): Promise<void>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Minimal signer interface for the OpenSea SDK. */
|
|
13
|
+
export interface OpenSeaSigner {
|
|
14
|
+
getAddress(): Promise<string>
|
|
15
|
+
sendTransaction(tx: {
|
|
16
|
+
to: string
|
|
17
|
+
data?: string
|
|
18
|
+
value?: bigint
|
|
19
|
+
from?: string
|
|
20
|
+
overrides?: Record<string, unknown>
|
|
21
|
+
}): Promise<TransactionResponse>
|
|
22
|
+
signTypedData(
|
|
23
|
+
domain: {
|
|
24
|
+
chainId: string | number
|
|
25
|
+
name: string
|
|
26
|
+
version: string
|
|
27
|
+
verifyingContract: string
|
|
28
|
+
},
|
|
29
|
+
types: Record<string, Array<{ name: string; type: string }>>,
|
|
30
|
+
value: Record<string, unknown>,
|
|
31
|
+
): Promise<string>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Minimal provider interface for the OpenSea SDK. */
|
|
35
|
+
export interface OpenSeaProvider {
|
|
36
|
+
waitForTransaction(hash: string): Promise<void>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Combined wallet: either signer+provider or provider-only. */
|
|
40
|
+
export type OpenSeaWallet =
|
|
41
|
+
| { signer: OpenSeaSigner; provider: OpenSeaProvider }
|
|
42
|
+
| { provider: OpenSeaProvider }
|
|
43
|
+
|
|
44
|
+
/** Contract read/write interface. */
|
|
45
|
+
export interface ContractCaller {
|
|
46
|
+
readContract(params: {
|
|
47
|
+
address: string
|
|
48
|
+
abi: readonly unknown[]
|
|
49
|
+
functionName: string
|
|
50
|
+
args: unknown[]
|
|
51
|
+
}): Promise<unknown>
|
|
52
|
+
|
|
53
|
+
writeContract(params: {
|
|
54
|
+
address: string
|
|
55
|
+
abi: readonly unknown[]
|
|
56
|
+
functionName: string
|
|
57
|
+
args: unknown[]
|
|
58
|
+
value?: bigint
|
|
59
|
+
overrides?: Record<string, unknown>
|
|
60
|
+
}): Promise<TransactionResponse>
|
|
61
|
+
|
|
62
|
+
encodeFunctionData(params: {
|
|
63
|
+
abi: readonly unknown[]
|
|
64
|
+
functionName: string
|
|
65
|
+
args: unknown[]
|
|
66
|
+
}): string
|
|
67
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Viem adapter — wraps viem WalletClient/PublicClient into the SDK's abstract interfaces.
|
|
3
|
+
*
|
|
4
|
+
* viem is an optional peerDependency and a devDependency (for type-checking).
|
|
5
|
+
* This module is only executed at runtime by code importing from "@opensea/sdk/viem",
|
|
6
|
+
* which requires viem to be installed.
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
type PublicClient,
|
|
10
|
+
encodeFunctionData as viemEncodeFunctionData,
|
|
11
|
+
type WalletClient,
|
|
12
|
+
} from "viem"
|
|
13
|
+
import type {
|
|
14
|
+
ContractCaller,
|
|
15
|
+
OpenSeaProvider,
|
|
16
|
+
OpenSeaSigner,
|
|
17
|
+
OpenSeaWallet,
|
|
18
|
+
TransactionResponse,
|
|
19
|
+
} from "./types"
|
|
20
|
+
|
|
21
|
+
export interface ViemAdapterParams {
|
|
22
|
+
publicClient: PublicClient
|
|
23
|
+
walletClient?: WalletClient
|
|
24
|
+
/**
|
|
25
|
+
* Explicit RPC URL for seaport-js (which requires an ethers provider internally).
|
|
26
|
+
* If not provided, the SDK attempts to extract the URL from the publicClient's
|
|
27
|
+
* HTTP transport. Required when using non-HTTP transports (WebSocket, custom).
|
|
28
|
+
*/
|
|
29
|
+
rpcUrl?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates an OpenSeaWallet from viem clients.
|
|
34
|
+
*/
|
|
35
|
+
export function createViemWallet(params: ViemAdapterParams): OpenSeaWallet {
|
|
36
|
+
const provider = createViemProvider(params.publicClient)
|
|
37
|
+
|
|
38
|
+
if (params.walletClient) {
|
|
39
|
+
return {
|
|
40
|
+
signer: createViemSigner(params.walletClient, params.publicClient),
|
|
41
|
+
provider,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { provider }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function createViemSigner(
|
|
49
|
+
walletClient: WalletClient,
|
|
50
|
+
publicClient: PublicClient,
|
|
51
|
+
): OpenSeaSigner {
|
|
52
|
+
return {
|
|
53
|
+
async getAddress() {
|
|
54
|
+
if (!walletClient.account) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
"WalletClient must have an account. Use `createWalletClient` with an `account` parameter.",
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
return walletClient.account.address
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
async sendTransaction(tx) {
|
|
63
|
+
const hash = await walletClient.sendTransaction({
|
|
64
|
+
to: tx.to as `0x${string}`,
|
|
65
|
+
data: tx.data as `0x${string}` | undefined,
|
|
66
|
+
value: tx.value,
|
|
67
|
+
account: walletClient.account!,
|
|
68
|
+
chain: walletClient.chain,
|
|
69
|
+
...(tx.overrides as any),
|
|
70
|
+
})
|
|
71
|
+
return {
|
|
72
|
+
hash,
|
|
73
|
+
async wait() {
|
|
74
|
+
await publicClient.waitForTransactionReceipt({ hash })
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
async signTypedData(domain, types, value) {
|
|
80
|
+
return walletClient.signTypedData({
|
|
81
|
+
domain: {
|
|
82
|
+
chainId: Number(domain.chainId),
|
|
83
|
+
name: domain.name,
|
|
84
|
+
version: domain.version,
|
|
85
|
+
verifyingContract: domain.verifyingContract as `0x${string}`,
|
|
86
|
+
},
|
|
87
|
+
types,
|
|
88
|
+
primaryType:
|
|
89
|
+
Object.keys(types).find(key => key !== "EIP712Domain") ||
|
|
90
|
+
Object.keys(types)[0],
|
|
91
|
+
message: value,
|
|
92
|
+
account: walletClient.account!,
|
|
93
|
+
})
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function createViemProvider(publicClient: PublicClient): OpenSeaProvider {
|
|
99
|
+
return {
|
|
100
|
+
async waitForTransaction(hash: string) {
|
|
101
|
+
await publicClient.waitForTransactionReceipt({
|
|
102
|
+
hash: hash as `0x${string}`,
|
|
103
|
+
})
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Creates a ContractCaller using viem clients.
|
|
110
|
+
*/
|
|
111
|
+
export function createViemContractCaller(
|
|
112
|
+
params: ViemAdapterParams,
|
|
113
|
+
): ContractCaller {
|
|
114
|
+
const { publicClient, walletClient } = params
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
async readContract({ address, abi, functionName, args }) {
|
|
118
|
+
return publicClient.readContract({
|
|
119
|
+
address: address as `0x${string}`,
|
|
120
|
+
abi: abi as any,
|
|
121
|
+
functionName,
|
|
122
|
+
args: args as any,
|
|
123
|
+
})
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
async writeContract({
|
|
127
|
+
address,
|
|
128
|
+
abi,
|
|
129
|
+
functionName,
|
|
130
|
+
args,
|
|
131
|
+
value,
|
|
132
|
+
overrides,
|
|
133
|
+
}): Promise<TransactionResponse> {
|
|
134
|
+
if (!walletClient) {
|
|
135
|
+
throw new Error("A WalletClient is required for write operations")
|
|
136
|
+
}
|
|
137
|
+
const hash = await walletClient.writeContract({
|
|
138
|
+
address: address as `0x${string}`,
|
|
139
|
+
abi: abi as any,
|
|
140
|
+
functionName,
|
|
141
|
+
args: args as any,
|
|
142
|
+
value,
|
|
143
|
+
account: walletClient.account!,
|
|
144
|
+
chain: walletClient.chain,
|
|
145
|
+
...(overrides as any),
|
|
146
|
+
})
|
|
147
|
+
return {
|
|
148
|
+
hash,
|
|
149
|
+
async wait() {
|
|
150
|
+
await publicClient.waitForTransactionReceipt({
|
|
151
|
+
hash: hash as `0x${string}`,
|
|
152
|
+
})
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
encodeFunctionData({ abi, functionName, args }) {
|
|
158
|
+
return viemEncodeFunctionData({
|
|
159
|
+
abi: abi as any,
|
|
160
|
+
functionName,
|
|
161
|
+
args: args as any,
|
|
162
|
+
})
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
}
|