-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helper to verify proxy contract on etherscan
- Loading branch information
1 parent
0332c46
commit 6342392
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import axios from "axios"; | ||
import { PartyEvent } from "types"; | ||
|
||
/** | ||
* Verify a proxy contract using the etherscan api | ||
* etherscan docs - https://docs.etherscan.io/api-endpoints/contracts#verify-proxy-contract | ||
* @param {string} address - party address | ||
* @returns {boolean} - true if verified, false otherwise | ||
*/ | ||
export const verifyProxyContract = async ( | ||
address: string | ||
): Promise<boolean> => { | ||
if (!address) { | ||
throw new Error("Missing argument: address"); | ||
} | ||
|
||
try { | ||
const resp = await axios.post( | ||
`https://api.etherscan.io/api?module=contract&action=verifyproxycontract&apikey=${ETHERSCAN_API_KEY}`, | ||
{ address } | ||
); | ||
|
||
if (!(resp && resp.data)) { | ||
throw new Error(`Invalid response from Etherscan API for ${address}`); | ||
} | ||
const { data } = resp; | ||
if (data.status === "1" && data.result) { | ||
console.log( | ||
`Successfully verified proxy contract for ${address}. guid ${data.result}.` | ||
); | ||
return true; | ||
} else { | ||
throw new Error(`Could not verify proxy contract for ${address}`); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
return false; | ||
} | ||
}; | ||
|
||
/** | ||
* verify proxy contract on etherscan if the event is a start event | ||
* @param {PartyEvent} event | ||
* @returns true/false if verified | ||
*/ | ||
export const verifyProxyContractForStartEvent = async ( | ||
event: PartyEvent | ||
): Promise<boolean> => { | ||
if (event.eventType === "start") { | ||
const { partyAddress } = event.party; | ||
return verifyProxyContract(partyAddress); | ||
} | ||
}; |