diff --git a/evm/sdk/ts/src/platforms/evm/src/admin.ts b/evm/sdk/ts/src/platforms/evm/src/admin.ts index 5e9f664..ff4b2ce 100644 --- a/evm/sdk/ts/src/platforms/evm/src/admin.ts +++ b/evm/sdk/ts/src/platforms/evm/src/admin.ts @@ -9,20 +9,8 @@ import { export async function claimAdmin( contractAddress: string, signer: ethers.Signer, - withExecutor: boolean = true, ): Promise { - let contract: WormholeGuardiansAdapter | WormholeGuardiansAdapterWithExecutor; - if (withExecutor) { - contract = WormholeGuardiansAdapterWithExecutor__factory.connect( - contractAddress, - signer, - ); - } else { - contract = WormholeGuardiansAdapter__factory.connect( - contractAddress, - signer, - ); - } + let contract = await getContract(contractAddress, signer); const tx = await contract.claimAdmin(); await tx.wait(); } @@ -30,20 +18,8 @@ export async function claimAdmin( export async function discardAdmin( contractAddress: string, signer: ethers.Signer, - withExecutor: boolean = true, ): Promise { - let contract: WormholeGuardiansAdapter | WormholeGuardiansAdapterWithExecutor; - if (withExecutor) { - contract = WormholeGuardiansAdapterWithExecutor__factory.connect( - contractAddress, - signer, - ); - } else { - contract = WormholeGuardiansAdapter__factory.connect( - contractAddress, - signer, - ); - } + let contract = await getContract(contractAddress, signer); const tx = await contract.discardAdmin(); await tx.wait(); } @@ -51,42 +27,17 @@ export async function discardAdmin( export async function pendingAdmin( contractAddress: string, signer: ethers.Signer, - withExecutor: boolean = true, ): Promise { - let contract: WormholeGuardiansAdapter | WormholeGuardiansAdapterWithExecutor; - if (withExecutor) { - contract = WormholeGuardiansAdapterWithExecutor__factory.connect( - contractAddress, - signer, - ); - } else { - contract = WormholeGuardiansAdapter__factory.connect( - contractAddress, - signer, - ); - } - const result: string = await contract.pendingAdmin(); - return result; + let contract = await getContract(contractAddress, signer); + return await contract.pendingAdmin(); } export async function transferAdmin( contractAddress: string, signer: ethers.Signer, newAdmin: string, - withExecutor: boolean = true, ): Promise { - let contract: WormholeGuardiansAdapter | WormholeGuardiansAdapterWithExecutor; - if (withExecutor) { - contract = WormholeGuardiansAdapterWithExecutor__factory.connect( - contractAddress, - signer, - ); - } else { - contract = WormholeGuardiansAdapter__factory.connect( - contractAddress, - signer, - ); - } + let contract = await getContract(contractAddress, signer); const tx = await contract.transferAdmin(newAdmin); await tx.wait(); } @@ -95,20 +46,8 @@ export async function updateAdmin( contractAddress: string, signer: ethers.Signer, newAdmin: string, - withExecutor: boolean = true, ): Promise { - let contract: WormholeGuardiansAdapter | WormholeGuardiansAdapterWithExecutor; - if (withExecutor) { - contract = WormholeGuardiansAdapterWithExecutor__factory.connect( - contractAddress, - signer, - ); - } else { - contract = WormholeGuardiansAdapter__factory.connect( - contractAddress, - signer, - ); - } + let contract = await getContract(contractAddress, signer); const tx = await contract.updateAdmin(newAdmin); await tx.wait(); } @@ -116,32 +55,45 @@ export async function updateAdmin( export async function getAdapterType( contractAddress: string, signer: ethers.Signer, - withExecutor: boolean = true, ): Promise { - let contract: WormholeGuardiansAdapter | WormholeGuardiansAdapterWithExecutor; - if (withExecutor) { - contract = WormholeGuardiansAdapterWithExecutor__factory.connect( - contractAddress, - signer, - ); - } else { - contract = WormholeGuardiansAdapter__factory.connect( - contractAddress, - signer, - ); - } - const result: string = await contract.getAdapterType(); - return result; + let contract = await getContract(contractAddress, signer); + return await contract.getAdapterType(); } export async function amIExecutor( contractAddress: string, signer: ethers.Signer, ): Promise { - const type: string = await getAdapterType(contractAddress, signer); - // TODO: See if this version string is somewhere in a const - if (type === "WormholeGuardiansAdapterWithExecutor-0.0.1") { - return true; + try { + const type: string = await getAdapterType(contractAddress, signer); + // TODO: See if this version string is somewhere in a const + if (type === "WormholeGuardiansAdapterWithExecutor-0.0.1") { + return true; + } + } catch (e) { + console.log("Error getting adapter type", e); } return false; } + +async function getContract( + contractAddress: string, + signer: ethers.Signer, +): Promise { + try { + return WormholeGuardiansAdapterWithExecutor__factory.connect( + contractAddress, + signer, + ); + } catch (e) { + console.log("Error connecting to contract with executor", e); + } + try { + return WormholeGuardiansAdapter__factory.connect(contractAddress, signer); + } catch (e) { + console.log("Error connecting to contract without executor", e); + } + throw new Error( + `Contract address ${contractAddress} is not a WormholeGuardiansAdapter or WormholeGuardiansAdapterWithExecutor contract`, + ); +}