Skip to content

Commit

Permalink
Merge branch 'main' into BTT-drop-erc20
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaryash90 authored Oct 16, 2023
2 parents 1c3304d + 3935bec commit 20d6a0a
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 101 deletions.
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"@thirdweb-dev/dynamic-contracts": "^1.1.2"
},
"engines": {
"node": ">=20.0.0"
"node": ">=18.0.0"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"@openzeppelin/contracts": "4.7.3",
"@openzeppelin/contracts-upgradeable": "4.7.3",
"@thirdweb-dev/dynamic-contracts": "^1.1.2",
"@thirdweb-dev/sdk": "^3.10.64",
"@thirdweb-dev/sdk": "^4",
"@thirdweb-dev/chains": "^0.1.54",
"@typechain/ethers-v5": "^10.0.0",
"@types/fs-extra": "^9.0.13",
"@types/mocha": "^9.1.0",
Expand Down
51 changes: 45 additions & 6 deletions scripts/deploy-prebuilt-deterministic/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
import {
Arbitrum,
ArbitrumGoerli,
Avalanche,
AvalancheFuji,
Base,
BaseGoerli,
CeloAlfajoresTestnet,
Ethereum,
Goerli,
Linea,
LineaTestnet,
Mumbai,
Optimism,
OptimismGoerli,
Polygon,
Sepolia,
} from "@thirdweb-dev/chains";
import { ChainId } from "@thirdweb-dev/sdk";
import dotenv from "dotenv";

dotenv.config();

export const DEFAULT_CHAINS = [
Ethereum,
Goerli,
Sepolia,
Polygon,
Mumbai,
Optimism,
OptimismGoerli,
Arbitrum,
ArbitrumGoerli,
Avalanche,
AvalancheFuji,
Base,
BaseGoerli,
Linea,
LineaTestnet,
CeloAlfajoresTestnet,
];

export const chainIdToName: Record<number, string> = {
[ChainId.Mumbai]: "mumbai",
[ChainId.Goerli]: "goerli",
Expand All @@ -12,19 +49,16 @@ export const chainIdToName: Record<number, string> = {
[ChainId.OptimismGoerli]: "optimism-goerli",
[ChainId.Arbitrum]: "arbitrum",
[ChainId.ArbitrumGoerli]: "arbitrum-goerli",
[ChainId.Fantom]: "fantom",
[ChainId.FantomTestnet]: "fantom-testnet",
[ChainId.Avalanche]: "avalanche",
[ChainId.AvalancheFujiTestnet]: "avalanche-testnet",
[ChainId.BinanceSmartChainMainnet]: "binance",
[ChainId.BinanceSmartChainTestnet]: "binance-testnet",
[84531]: "base-goerli",
[8453]: "base",
};

export const chainIdApiKey: Record<number, string | undefined> = {
[ChainId.Mumbai]: process.env.POLYGONSCAN_API_KEY || process.env.SCAN_API_KEY,
[ChainId.Goerli]: process.env.ETHERSCAN_API_KEY || process.env.SCAN_API_KEY,
[Sepolia.chainId]: process.env.ETHERSCAN_API_KEY || process.env.SCAN_API_KEY,
[ChainId.Polygon]: process.env.POLYGONSCAN_API_KEY || process.env.SCAN_API_KEY,
[ChainId.Mainnet]: process.env.ETHERSCAN_API_KEY || process.env.SCAN_API_KEY,
[ChainId.Optimism]: process.env.OPTIMISM_SCAN_API_KEY || process.env.SCAN_API_KEY,
Expand All @@ -37,13 +71,16 @@ export const chainIdApiKey: Record<number, string | undefined> = {
[ChainId.AvalancheFujiTestnet]: process.env.SNOWTRACE_API_KEY || process.env.SCAN_API_KEY,
[ChainId.BinanceSmartChainMainnet]: process.env.BINANCE_SCAN_API_KEY || process.env.SCAN_API_KEY,
[ChainId.BinanceSmartChainTestnet]: process.env.BINANCE_SCAN_API_KEY || process.env.SCAN_API_KEY,
[84531]: "" as string,
[8453]: process.env.BASE_SCAN_API_KEY || process.env.SCAN_API_KEY,
[Base.chainId]: process.env.BASE_SCAN_API_KEY || process.env.SCAN_API_KEY,
[BaseGoerli.chainId]: process.env.BASE_SCAN_API_KEY || process.env.SCAN_API_KEY,
[Linea.chainId]: process.env.LINEA_SCAN_API_KEY || process.env.SCAN_API_KEY,
[LineaTestnet.chainId]: process.env.LINEA_SCAN_API_KEY || process.env.SCAN_API_KEY,
};

export const apiMap: Record<number, string> = {
1: "https://api.etherscan.io/api",
5: "https://api-goerli.etherscan.io/api",
[Sepolia.chainId]: "https://api-sepolia.etherscan.io/api",
10: "https://api-optimistic.etherscan.io/api",
56: "https://api.bscscan.com/api",
97: "https://api-testnet.bscscan.com/api",
Expand All @@ -58,6 +95,8 @@ export const apiMap: Record<number, string> = {
80001: "https://api-testnet.polygonscan.com/api",
84531: "https://api-goerli.basescan.org/api",
8453: "https://api.basescan.org/api",
[Linea.chainId]: "https://api.lineascan.build/api",
[LineaTestnet.chainId]: "https://api-testnet.lineascan.build/api",
};

export const contractsToDeploy = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,53 @@ import {
resolveAddress,
} from "@thirdweb-dev/sdk";
import { Signer } from "ethers";
import { apiMap, chainIdApiKey, chainIdToName } from "./constants";
import { DEFAULT_CHAINS, apiMap, chainIdApiKey } from "./constants";

////// To run this script: `npx ts-node scripts/deploy-prebuilt-deterministic/deploy-deterministic-std-chains.ts` //////
///// MAKE SURE TO PUT IN THE RIGHT CONTRACT NAME HERE AFTER PUBLISHING IT /////
//// THE CONTRACT SHOULD BE PUBLISHED WITH THE NEW PUBLISH FLOW ////
const publishedContractName = "DropERC1155";
const publisherKey: string = process.env.THIRDWEB_PUBLISHER_PRIVATE_KEY as string;
const publishedContractName = "AccountExtension";
const publisherAddress: string = "deployer.thirdweb.eth";
const deployerKey: string = process.env.PRIVATE_KEY as string;
const secretKey: string = process.env.THIRDWEB_SECRET_KEY as string;

const polygonSDK = ThirdwebSDK.fromPrivateKey(publisherKey, "polygon", { secretKey });
const polygonSDK = new ThirdwebSDK("polygon", { secretKey });

async function main() {
const publisher = await polygonSDK.wallet.getAddress();
const latest = await polygonSDK.getPublisher().getLatest(publisher, publishedContractName);
const latest = await polygonSDK.getPublisher().getLatest(publisherAddress, publishedContractName);

if (latest && latest.metadataUri) {
const { extendedMetadata } = await fetchAndCacheDeployMetadata(latest?.metadataUri, polygonSDK.storage);

for (const [chainId, networkName] of Object.entries(chainIdToName)) {
for (const chain of DEFAULT_CHAINS) {
const isNetworkEnabled =
extendedMetadata?.networksForDeployment?.networksEnabled.includes(parseInt(chainId)) ||
extendedMetadata?.networksForDeployment?.networksEnabled.includes(chain.chainId) ||
extendedMetadata?.networksForDeployment?.allNetworks;

if (extendedMetadata?.networksForDeployment && !isNetworkEnabled) {
console.log(`Deployment of ${publishedContractName} disabled on ${networkName}\n`);
console.log(`Deployment of ${publishedContractName} disabled on ${chain.slug}\n`);
continue;
}

console.log(`Deploying ${publishedContractName} on ${networkName}`);
const sdk = ThirdwebSDK.fromPrivateKey(deployerKey, chainId, { secretKey }); // can also hardcode the chain here
console.log(`Deploying ${publishedContractName} on ${chain.slug}`);
const sdk = ThirdwebSDK.fromPrivateKey(deployerKey, chain, { secretKey }); // can also hardcode the chain here
const signer = sdk.getSigner() as Signer;
// const chainId = (await sdk.getProvider().getNetwork()).chainId;

try {
const implAddr = await getThirdwebContractAddress(publishedContractName, parseInt(chainId), sdk.storage);
const implAddr = await getThirdwebContractAddress(publishedContractName, chain.chainId, sdk.storage);
if (implAddr) {
console.log(`implementation ${implAddr} already deployed on chainId: ${chainId}`);
console.log(`implementation ${implAddr} already deployed on chainId: ${chain.slug}`);
console.log();
continue;
}
} catch (error) {}
} catch (error) {
// no-op
}

try {
console.log("Deploying as", await signer?.getAddress());
console.log("Deploying as", await sdk.wallet.getAddress());
console.log("Balance", await sdk.wallet.balance().then(b => b.displayValue));
// any evm deployment flow

// Deploy CREATE2 factory (if not already exists)
Expand Down Expand Up @@ -133,14 +135,16 @@ async function main() {
console.log();
console.log("---------- Verification ---------");
console.log();
for (const [chainId, networkName] of Object.entries(chainIdToName)) {
const sdk = new ThirdwebSDK(chainId);
console.log("Network: ", networkName);
for (const chain of DEFAULT_CHAINS) {
const sdk = new ThirdwebSDK(chain, {
secretKey,
});
console.log("Verifying on: ", chain.slug);
try {
await sdk.verifier.verifyThirdwebContract(
publishedContractName,
apiMap[parseInt(chainId)],
chainIdApiKey[parseInt(chainId)] as string,
apiMap[chain.chainId],
chainIdApiKey[chain.chainId] as string,
);
console.log();
} catch (error) {
Expand Down
23 changes: 15 additions & 8 deletions scripts/deploy-prebuilt-deterministic/verify.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import { ThirdwebSDK } from "@thirdweb-dev/sdk";

import { apiMap, chainIdApiKey, chainIdToName } from "./constants";
import { DEFAULT_CHAINS, apiMap, chainIdApiKey } from "./constants";

////// To run this script: `npx ts-node scripts/deploy-prebuilt-deterministic/verify.ts` //////
const deployedContractName = "VoteERC20";
const deployedContractName = "AccountExtension";
const secretKey: string = process.env.THIRDWEB_SECRET_KEY as string;

async function main() {
console.log("---------- Verification ---------");
console.log();
for (const [chainId, networkName] of Object.entries(chainIdToName)) {
const sdk = new ThirdwebSDK(chainId);
console.log("Network: ", networkName);
for (const chain of DEFAULT_CHAINS) {
const sdk = new ThirdwebSDK(chain, {
secretKey,
});
console.log("Network: ", chain.slug);
try {
await sdk.verifier.verifyThirdwebContract(
deployedContractName,
apiMap[parseInt(chainId)],
chainIdApiKey[parseInt(chainId)] as string,
apiMap[chain.chainId],
chainIdApiKey[chain.chainId] as string,
);
console.log();
} catch (error) {
console.log(error);
if ((error as Error)?.message?.includes("already verified")) {
console.log("Already verified");
} else {
console.log(error);
}
console.log();
}
}
Expand Down
Loading

0 comments on commit 20d6a0a

Please sign in to comment.