@@ -92,6 +92,8 @@ export type ContractItem = { contract: Contract, multicallContract: MulticallCon
9292
9393class Curve implements ICurve {
9494 provider : ethers . BrowserProvider | ethers . JsonRpcProvider ;
95+ abstractProvider ?: { chainId : number , name : string } ;
96+ isNoRPC : boolean ;
9597 multicallProvider : MulticallProvider ;
9698 signer : ethers . Signer | null ;
9799 signerAddress : string ;
@@ -109,6 +111,7 @@ class Curve implements ICurve {
109111 this . provider = null ;
110112 // @ts -ignore
111113 this . signer = null ;
114+ this . isNoRPC = false ;
112115 this . signerAddress = '' ;
113116 this . chainId = 1 ;
114117 this . isLiteChain = false ;
@@ -143,8 +146,8 @@ class Curve implements ICurve {
143146 }
144147
145148 async init (
146- providerType : 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy' ,
147- providerSettings : { url ?: string , privateKey ?: string , batchMaxCount ? : number } | { externalProvider : ethers . Eip1193Provider } | { network ?: Networkish , apiKey ?: string } ,
149+ providerType : 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy' | 'NoRPC' ,
150+ providerSettings : { url ?: string , privateKey ?: string , batchMaxCount ? : number } | { externalProvider : ethers . Eip1193Provider } | { network ?: Networkish , apiKey ?: string } | { chainId : number , networkName : string } ,
148151 options : { gasPrice ?: number , maxFeePerGas ?: number , maxPriorityFeePerGas ?: number , chainId ?: number } = { } // gasPrice in Gwei
149152 ) : Promise < void > {
150153 // @ts -ignore
@@ -226,11 +229,19 @@ class Curve implements ICurve {
226229 providerSettings = providerSettings as { network ?: Networkish , apiKey ?: string } ;
227230 this . provider = new ethers . AlchemyProvider ( providerSettings . network , providerSettings . apiKey ) ;
228231 this . signer = null ;
232+ } else if ( providerType . toLowerCase ( ) === 'NoRPC' . toLowerCase ( ) ) {
233+ providerSettings = providerSettings as { chainId : number , networkName : string } ;
234+ this . isNoRPC = true ;
235+ this . abstractProvider = {
236+ chainId : providerSettings . chainId as number ,
237+ name : providerSettings . networkName as string ,
238+ }
239+ this . signer = null ;
229240 } else {
230241 throw Error ( 'Wrong providerType' ) ;
231242 }
232243
233- const network = await this . provider . getNetwork ( ) ;
244+ const network = this . abstractProvider || await this . provider . getNetwork ( ) ;
234245 console . log ( "CURVE-JS IS CONNECTED TO NETWORK:" , { name : network . name . toUpperCase ( ) , chainId : Number ( network . chainId ) } ) ;
235246 this . chainId = Number ( network . chainId ) === 133 || Number ( network . chainId ) === 31337 ? 1 : Number ( network . chainId ) as IChainId ;
236247
@@ -389,8 +400,10 @@ class Curve implements ICurve {
389400 this . setContract ( this . constants . ALIASES . factory , factoryABI ) ;
390401
391402 const factoryContract = this . contracts [ this . constants . ALIASES . factory ] . contract ;
392- this . constants . ALIASES . factory_admin = ( await factoryContract . admin ( this . constantOptions ) as string ) . toLowerCase ( ) ;
393- this . setContract ( this . constants . ALIASES . factory_admin , factoryAdminABI ) ;
403+ if ( ! this . isNoRPC ) {
404+ this . constants . ALIASES . factory_admin = ( await factoryContract . admin ( this . constantOptions ) as string ) . toLowerCase ( ) ;
405+ this . setContract ( this . constants . ALIASES . factory_admin , factoryAdminABI ) ;
406+ }
394407 }
395408
396409 this . setContract ( this . constants . ALIASES . crvusd_factory , factoryABI ) ;
@@ -523,7 +536,7 @@ class Curve implements ICurve {
523536 this . constants . FACTORY_POOLS_DATA = await this . _filterHiddenPools ( this . constants . FACTORY_POOLS_DATA ) ;
524537 this . _updateDecimalsAndGauges ( this . constants . FACTORY_POOLS_DATA ) ;
525538
526- this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory" ] = await this . contracts [ this . constants . ALIASES . factory ] . contract . gauge_implementation ( this . constantOptions ) ;
539+ this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory" ] = this . isNoRPC ? null : await this . contracts [ this . constants . ALIASES . factory ] . contract . gauge_implementation ( this . constantOptions ) ;
527540 }
528541
529542 fetchCrvusdFactoryPools = async ( useApi = true ) : Promise < void > => {
@@ -532,6 +545,9 @@ class Curve implements ICurve {
532545 if ( useApi ) {
533546 this . constants . CRVUSD_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses ( await getFactoryPoolsDataFromApi . call ( this , "factory-crvusd" ) ) ;
534547 } else {
548+ if ( this . isNoRPC ) {
549+ throw new Error ( 'RPC connection is required' ) ;
550+ }
535551 this . constants . CRVUSD_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses (
536552 await getFactoryPoolData . call ( this , 0 , undefined , this . constants . ALIASES . crvusd_factory )
537553 ) ;
@@ -546,6 +562,9 @@ class Curve implements ICurve {
546562 if ( useApi ) {
547563 this . constants . EYWA_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses ( await getFactoryPoolsDataFromApi . call ( this , "factory-eywa" ) ) ;
548564 } else {
565+ if ( this . isNoRPC ) {
566+ throw new Error ( 'RPC connection is required' ) ;
567+ }
549568 this . constants . EYWA_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses (
550569 await getFactoryPoolData . call ( this , 0 , undefined , this . constants . ALIASES . eywa_factory )
551570 ) ;
@@ -560,12 +579,15 @@ class Curve implements ICurve {
560579 if ( useApi ) {
561580 this . constants . CRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses ( await getFactoryPoolsDataFromApi . call ( this , "factory-crypto" ) ) ;
562581 } else {
582+ if ( this . isNoRPC ) {
583+ throw new Error ( 'RPC connection is required' ) ;
584+ }
563585 this . constants . CRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses ( await getCryptoFactoryPoolData . call ( this ) ) ;
564586 }
565587 this . constants . CRYPTO_FACTORY_POOLS_DATA = await this . _filterHiddenPools ( this . constants . CRYPTO_FACTORY_POOLS_DATA ) ;
566588 this . _updateDecimalsAndGauges ( this . constants . CRYPTO_FACTORY_POOLS_DATA ) ;
567589
568- this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory-crypto" ] = await this . contracts [ this . constants . ALIASES . crypto_factory ] . contract . gauge_implementation ( this . constantOptions ) ;
590+ this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory-crypto" ] = this . isNoRPC ? null : await this . contracts [ this . constants . ALIASES . crypto_factory ] . contract . gauge_implementation ( this . constantOptions ) ;
569591 }
570592
571593 fetchStableNgFactoryPools = async ( useApi = true ) : Promise < void > => {
@@ -574,6 +596,9 @@ class Curve implements ICurve {
574596 if ( useApi ) {
575597 this . constants . STABLE_NG_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses ( await getFactoryPoolsDataFromApi . call ( this , "factory-stable-ng" ) ) ;
576598 } else {
599+ if ( this . isNoRPC ) {
600+ throw new Error ( 'RPC connection is required' ) ;
601+ }
577602 this . constants . STABLE_NG_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses ( await getFactoryPoolData . call ( this , 0 , undefined , this . constants . ALIASES . stable_ng_factory ) ) ;
578603 }
579604
@@ -587,16 +612,19 @@ class Curve implements ICurve {
587612 if ( useApi ) {
588613 this . constants . TWOCRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses ( await getFactoryPoolsDataFromApi . call ( this , "factory-twocrypto" ) ) ;
589614 } else {
615+ if ( this . isNoRPC ) {
616+ throw new Error ( 'RPC connection is required' ) ;
617+ }
590618 this . constants . TWOCRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses ( await getTwocryptoFactoryPoolData . call ( this ) ) ;
591619 }
592620 this . constants . TWOCRYPTO_FACTORY_POOLS_DATA = await this . _filterHiddenPools ( this . constants . TWOCRYPTO_FACTORY_POOLS_DATA ) ;
593621 this . _updateDecimalsAndGauges ( this . constants . TWOCRYPTO_FACTORY_POOLS_DATA ) ;
594622
595623 if ( this . chainId === 1 ) {
596- this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory-twocrypto" ] =
624+ this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory-twocrypto" ] = this . isNoRPC ? null :
597625 await this . contracts [ this . constants . ALIASES . twocrypto_factory ] . contract . gauge_implementation ( this . constantOptions ) ;
598626 } else {
599- this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory-twocrypto" ] =
627+ this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory-twocrypto" ] = this . isNoRPC ? null :
600628 await this . contracts [ this . constants . ALIASES . child_gauge_factory ] . contract . get_implementation ( this . constantOptions ) ;
601629 }
602630 }
@@ -607,16 +635,19 @@ class Curve implements ICurve {
607635 if ( useApi ) {
608636 this . constants . TRICRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses ( await getFactoryPoolsDataFromApi . call ( this , "factory-tricrypto" ) ) ;
609637 } else {
638+ if ( this . isNoRPC ) {
639+ throw new Error ( 'RPC connection is required' ) ;
640+ }
610641 this . constants . TRICRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses ( await getTricryptoFactoryPoolData . call ( this ) ) ;
611642 }
612643 this . constants . TRICRYPTO_FACTORY_POOLS_DATA = await this . _filterHiddenPools ( this . constants . TRICRYPTO_FACTORY_POOLS_DATA ) ;
613644 this . _updateDecimalsAndGauges ( this . constants . TRICRYPTO_FACTORY_POOLS_DATA ) ;
614645
615646 if ( this . chainId === 1 ) {
616- this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory-tricrypto" ] =
647+ this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory-tricrypto" ] = this . isNoRPC ? null :
617648 await this . contracts [ this . constants . ALIASES . tricrypto_factory ] . contract . gauge_implementation ( this . constantOptions ) ;
618649 } else {
619- this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory-tricrypto" ] =
650+ this . constants . FACTORY_GAUGE_IMPLEMENTATIONS [ "factory-tricrypto" ] = this . isNoRPC ? null :
620651 await this . contracts [ this . constants . ALIASES . child_gauge_factory ] . contract . get_implementation ( this . constantOptions ) ;
621652 }
622653 }
@@ -787,6 +818,10 @@ class Curve implements ICurve {
787818 }
788819
789820 async updateFeeData ( ) : Promise < void > {
821+ if ( this . isNoRPC ) {
822+ return
823+ }
824+
790825 const feeData = await this . provider . getFeeData ( ) ;
791826 if ( feeData . maxFeePerGas === null || feeData . maxPriorityFeePerGas === null ) {
792827 delete this . options . maxFeePerGas ;
0 commit comments