@@ -36,6 +36,7 @@ import type {
3636 ContractMethodReturnType ,
3737 MatchOrdersFulfillment ,
3838 SeaportContract ,
39+ Signer ,
3940} from "./types" ;
4041import { getApprovalActions } from "./utils/approval" ;
4142import {
@@ -65,7 +66,9 @@ export class Seaport {
6566 // Provides the raw interface to the contract for flexibility
6667 public contract : SeaportContract ;
6768
68- private provider : providers . JsonRpcProvider ;
69+ private provider : providers . Provider ;
70+
71+ private signer ?: Signer ;
6972
7073 // Use the multicall provider for reads for batching and performance optimisations
7174 // NOTE: Do NOT await between sequential requests if you're intending to batch
@@ -80,11 +83,11 @@ export class Seaport {
8083 readonly OPENSEA_CONDUIT_KEY : string = OPENSEA_CONDUIT_KEY ;
8184
8285 /**
83- * @param provider - The provider to use for web3-related calls
86+ * @param providerOrSigner - The provider or signer to use for web3-related calls
8487 * @param considerationConfig - A config to provide flexibility in the usage of Seaport
8588 */
8689 public constructor (
87- provider : providers . JsonRpcProvider ,
90+ providerOrSigner : providers . JsonRpcProvider | Signer ,
8891 {
8992 overrides,
9093 // Five minute buffer
@@ -93,8 +96,22 @@ export class Seaport {
9396 conduitKeyToConduit,
9497 } : SeaportConfig = { }
9598 ) {
99+ const provider =
100+ providerOrSigner instanceof providers . Provider
101+ ? providerOrSigner
102+ : providerOrSigner . provider ;
103+
104+ if ( ! provider ) {
105+ throw new Error (
106+ "Either a provider or custom signer with provider must be provided"
107+ ) ;
108+ }
109+
96110 this . provider = provider ;
97- this . multicallProvider = new multicallProviders . MulticallProvider ( provider ) ;
111+
112+ this . multicallProvider = new multicallProviders . MulticallProvider (
113+ this . provider
114+ ) ;
98115
99116 this . contract = new Contract (
100117 overrides ?. contractAddress ?? CROSS_CHAIN_SEAPORT_ADDRESS ,
@@ -115,6 +132,18 @@ export class Seaport {
115132 this . defaultConduitKey = overrides ?. defaultConduitKey ?? NO_CONDUIT ;
116133 }
117134
135+ private _getSigner ( accountAddress ?: string ) : Signer {
136+ if ( this . signer ) {
137+ return this . signer ;
138+ }
139+
140+ if ( ! ( this . provider instanceof providers . JsonRpcProvider ) ) {
141+ throw new Error ( "Either signer or a JsonRpcProvider must be provided" ) ;
142+ }
143+
144+ return this . provider . getSigner ( accountAddress ) ;
145+ }
146+
118147 /**
119148 * Returns the corresponding order type based on whether it allows partial fills and is restricted by zone
120149 *
@@ -177,7 +206,7 @@ export class Seaport {
177206 } : CreateOrderInput ,
178207 accountAddress ?: string
179208 ) : Promise < OrderUseCase < CreateOrderAction > > {
180- const signer = await this . provider . getSigner ( accountAddress ) ;
209+ const signer = this . _getSigner ( accountAddress ) ;
181210 const offerer = await signer . getAddress ( ) ;
182211 const offerItems = offer . map ( mapInputItemToOfferItem ) ;
183212 const considerationItems = [
@@ -349,7 +378,7 @@ export class Seaport {
349378 counter : number ,
350379 accountAddress ?: string
351380 ) : Promise < string > {
352- const signer = this . provider . getSigner ( accountAddress ) ;
381+ const signer = this . _getSigner ( accountAddress ) ;
353382
354383 const domainData = await this . _getDomainData ( ) ;
355384
@@ -379,7 +408,7 @@ export class Seaport {
379408 orders : OrderComponents [ ] ,
380409 accountAddress ?: string
381410 ) : TransactionMethods < ContractMethodReturnType < SeaportContract , "cancel" > > {
382- const signer = this . provider . getSigner ( accountAddress ) ;
411+ const signer = this . _getSigner ( accountAddress ) ;
383412
384413 return getTransactionMethods ( this . contract . connect ( signer ) , "cancel" , [
385414 orders ,
@@ -396,7 +425,7 @@ export class Seaport {
396425 ) : TransactionMethods <
397426 ContractMethodReturnType < SeaportContract , "incrementCounter" >
398427 > {
399- const signer = this . provider . getSigner ( offerer ) ;
428+ const signer = this . _getSigner ( offerer ) ;
400429
401430 return getTransactionMethods (
402431 this . contract . connect ( signer ) ,
@@ -416,7 +445,7 @@ export class Seaport {
416445 orders : Order [ ] ,
417446 accountAddress ?: string
418447 ) : TransactionMethods < ContractMethodReturnType < SeaportContract , "validate" > > {
419- const signer = this . provider . getSigner ( accountAddress ) ;
448+ const signer = this . _getSigner ( accountAddress ) ;
420449
421450 return getTransactionMethods ( this . contract . connect ( signer ) , "validate" , [
422451 orders ,
@@ -610,7 +639,7 @@ export class Seaport {
610639 const { parameters : orderParameters } = order ;
611640 const { offerer, offer, consideration } = orderParameters ;
612641
613- const fulfiller = await this . provider . getSigner ( accountAddress ) ;
642+ const fulfiller = this . _getSigner ( accountAddress ) ;
614643
615644 const fulfillerAddress = await fulfiller . getAddress ( ) ;
616645
@@ -744,7 +773,7 @@ export class Seaport {
744773 conduitKey ?: string ;
745774 recipientAddress ?: string ;
746775 } ) {
747- const fulfiller = await this . provider . getSigner ( accountAddress ) ;
776+ const fulfiller = this . _getSigner ( accountAddress ) ;
748777
749778 const fulfillerAddress = await fulfiller . getAddress ( ) ;
750779
@@ -859,7 +888,7 @@ export class Seaport {
859888 } ) : TransactionMethods <
860889 ContractMethodReturnType < SeaportContract , "matchOrders" >
861890 > {
862- const signer = this . provider . getSigner ( accountAddress ) ;
891+ const signer = this . _getSigner ( accountAddress ) ;
863892
864893 return getTransactionMethods ( this . contract . connect ( signer ) , "matchOrders" , [
865894 orders ,
0 commit comments