import { ethers } from 'ethers' ; import { AirnodeRrpFactory , AirnodeRrpAddresses , RequesterAuthorizerWithAirnodeAddresses , authorizers , AirnodeRrp , } from '@api3/airnode-protocol' ; async function getAirnodeRrpAddress ( provider ) { const network = await provider . getNetwork ( ) ; return AirnodeRrpAddresses [ network . chainId ] ; } async function getRequesterAuthorizerWithAirnodeAddress ( provider ) { const network = await provider . getNetwork ( ) ; return RequesterAuthorizerWithAirnodeAddresses [ network . chainId ] ; } export async function getAirnodeRrp ( providerUrl , props ? ) { let signerOrProvider = new ethers . providers . JsonRpcProvider ( providerUrl ) ; const address = props ?. airnodeRrpAddress || ( await getAirnodeRrpAddress ( signerOrProvider ) ) ; if ( ! address ) throw new Error ( `AirnodeRrp address is not provided. Please specify the address using "--airnode-rrp-address" parameter.` ) ; if ( props ?. signer ) { signerOrProvider = ethers . Wallet . fromMnemonic ( props . signer . mnemonic , props . signer . derivationPath ) . connect ( signerOrProvider ) ; } return AirnodeRrpFactory . connect ( address , signerOrProvider ) ; } export function useAirnodeRrp ( airnodeRrpContract ) { return airnodeRrpContract as AirnodeRrp ; } export async function getRequesterAuthorizerWithAirnode ( providerUrl , props ? ) { let signerOrProvider = new ethers . providers . JsonRpcProvider ( providerUrl ) ; const address = props ?. requesterAuthorizerWithAirnodeAddress || ( await getRequesterAuthorizerWithAirnodeAddress ( signerOrProvider ) ) ; if ( ! address ) throw new Error ( `RequesterAuthorizerWithAirnode address is not provided` ) ; if ( props ?. signer ) { signerOrProvider = ethers . Wallet . fromMnemonic ( props ?. signer . mnemonic , props . signer . derivationPath ) . connect ( signerOrProvider ) ; } return authorizers . RequesterAuthorizerWithAirnodeFactory . connect ( address , signerOrProvider ) ; }