Skip to content

Commit

Permalink
feat: Deploy system contracts to Amoy
Browse files Browse the repository at this point in the history
  • Loading branch information
andresaiello committed Jun 28, 2024
1 parent 9d0791e commit b430334
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 30 deletions.
16 changes: 15 additions & 1 deletion data/addresses.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@
"chain_name": "bsc_testnet",
"type": "tssUpdater"
},
{
"address": "0x8531a5aB847ff5B22D855633C25ED1DA3255247e",
"category": "omnichain",
"chain_id": 80002,
"chain_name": "amoy_testnet",
"type": "tss"
},
{
"address": "0x55122f7590164Ac222504436943FAB17B62F5d7d",
"category": "omnichain",
"chain_id": 80002,
"chain_name": "amoy_testnet",
"type": "tssUpdater"
},
{
"address": "0xB7926C0430Afb07AA7DEfDE6DA862aE0Bde767bc",
"category": "messaging",
Expand Down Expand Up @@ -368,4 +382,4 @@
"chain_name": "sepolia_testnet",
"type": "zetaTokenConsumerUniV3"
}
]
]
13 changes: 13 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,26 @@ const config: HardhatUserConfig = {
//@ts-ignore
etherscan: {
apiKey: {
amoy_testnet: process.env.POYLGONSCAN_API_KEY || "",
// BSC
bsc: process.env.BSCSCAN_API_KEY || "",

bscTestnet: process.env.BSCSCAN_API_KEY || "",
// ETH
goerli: process.env.ETHERSCAN_API_KEY || "",
mainnet: process.env.ETHERSCAN_API_KEY || "",
},
//@ts-ignore
customChains: [
{
chainId: 80002,
network: "amoy_testnet",
urls: {
apiURL: "https://api-amoy.polygonscan.com/api",
browserURL: "https://amoy.polygonscan.com",
},
},
],
},
networks: {
...getHardhatConfigNetworks(),
Expand Down
10 changes: 2 additions & 8 deletions lib/address.tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export declare type ZetaZEVMAddress =
| "zrc20";

export declare type ZetaProtocolTestNetwork =
| "amoy_testnet"
| "baobab_testnet"
| "bsc_testnet"
| "btc_testnet"
Expand All @@ -47,6 +48,7 @@ export const zetaProtocolTestNetworks: ZetaProtocolTestNetwork[] = [
"sepolia_testnet",
"mumbai_testnet",
"zeta_testnet",
"amoy_testnet",
];

export declare type NonZetaAddress =
Expand Down Expand Up @@ -83,14 +85,6 @@ export const isMainnetNetwork = (network: ZetaProtocolTestNetwork): boolean => {
return false;
};

// export const getAddress = (address: ZetaProtocolAddress | ZetaZEVMAddress, network: ZetaProtocolNetwork): string => {
// if (isZetaProtocolAddress(address)) {
// return (addresses["ccm"] as any)[network][address];
// }

// return (addresses["zevm"] as any)[network][address];
// };

export const getZRC20Address = (network: ZetaProtocolNetwork): string => {
return (addresses["zevm"] as any)[network]["zrc20"];
};
Expand Down
12 changes: 12 additions & 0 deletions lib/contracts.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
ERC20Custody,
ERC20Custody__factory as ERC20CustodyFactory,
ImmutableCreate2Factory,
ImmutableCreate2Factory__factory,
ZetaConnectorBase,
Expand Down Expand Up @@ -63,6 +65,16 @@ export const deployZetaConnectorNonEth = async ({
return zetaConnectorContract;
};

export const deployERC20Custody = async ({ args }: { args: Parameters<ERC20CustodyFactory["deploy"]> }) => {
const Factory = (await ethers.getContractFactory("ERC20Custody")) as ERC20CustodyFactory;

const ERC20CustodyContract = (await Factory.deploy(...args)) as ERC20Custody;

await ERC20CustodyContract.deployed();

return ERC20CustodyContract;
};

export const deployZetaReceiverMock = async () => {
const Factory = (await ethers.getContractFactory("ZetaReceiverMock")) as ZetaReceiverMockFactory;

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@uniswap/v2-core": "^1.0.1",
"@uniswap/v2-periphery": "^1.1.0-beta.0",
"@uniswap/v3-periphery": "^1.4.3",
"@zetachain/networks": "6.0.0",
"@zetachain/networks": "8.0.0-rc1",
"axios": "^1.6.5",
"chai": "^4.3.6",
"cpx": "^1.5.0",
Expand Down Expand Up @@ -85,4 +85,4 @@
},
"types": "./dist/lib/index.d.ts",
"version": "0.0.8"
}
}
23 changes: 23 additions & 0 deletions scripts/deployments/core/deploy-deterministic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { network } from "hardhat";

import { isProtocolNetworkName } from "../../../lib/address.tools";
import { deterministicDeployERC20Custody } from "./deterministic-deploy-erc20-custody";
import { deterministicDeployZetaConnector } from "./deterministic-deploy-zeta-connector";
import { deterministicDeployZetaToken } from "./deterministic-deploy-zeta-token";

const networkName = network.name;

async function main() {
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name");

await deterministicDeployZetaToken();
await deterministicDeployZetaConnector();
await deterministicDeployERC20Custody();
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
36 changes: 36 additions & 0 deletions scripts/deployments/core/deploy-erc20-custody.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Contract } from "ethers";
import { ethers, network } from "hardhat";
import { getAddress, isProtocolNetworkName } from "lib";

import { ERC20_CUSTODY_ZETA_FEE, ERC20_CUSTODY_ZETA_MAX_FEE } from "../../../lib/contracts.constants";
import { deployERC20Custody as deployERC20CustodyHelper } from "../../../lib/contracts.helpers";

export async function deployERC20Custody(zetaTokenAddress: string) {
if (!isProtocolNetworkName(network.name)) {
throw new Error(`network.name: ${network.name} isn't supported.`);
}
const accounts = await ethers.getSigners();
const [signer] = accounts;
const initialBalance = await signer.getBalance();

const tssAddress = getAddress("tss", network.name);
const tssUpdaterAddress = getAddress("tssUpdater", network.name);

const zetaFee = ERC20_CUSTODY_ZETA_FEE;
const zetaMaxFee = ERC20_CUSTODY_ZETA_MAX_FEE;

let contract: Contract;
console.log(`Deploying ERC20Custody to ${network.name}`);

const constructorArgs = [tssAddress, tssUpdaterAddress, zetaFee.toString(), zetaMaxFee.toString(), zetaTokenAddress];
contract = await deployERC20CustodyHelper({
args: constructorArgs,
});

const finalBalance = await signer.getBalance();
console.log("Deployed ERC20Custody. Address:", contract.address);
console.log("Constructor Args", constructorArgs);
console.log("ETH spent:", initialBalance.sub(finalBalance).toString());

return contract.address;
}
18 changes: 12 additions & 6 deletions scripts/deployments/core/deploy-zeta-connector.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import { Contract } from "ethers";
import { network } from "hardhat";
import { getAddress, isProtocolNetworkName } from "lib/address.tools";
import { ethers, network } from "hardhat";
import { getAddress, isProtocolNetworkName } from "lib";

import { deployZetaConnectorEth, deployZetaConnectorNonEth, isEthNetworkName } from "../../../lib/contracts.helpers";

export async function deployZetaConnector() {
export async function deployZetaConnector(zetaTokenAddress: string) {
if (!isProtocolNetworkName(network.name)) {
throw new Error(`network.name: ${network.name} isn't supported.`);
}
const accounts = await ethers.getSigners();
const [signer] = accounts;
const initialBalance = await signer.getBalance();

const zetaTokenAddress = getAddress("zetaToken", network.name);
const tssAddress = getAddress("tss", network.name);
const tssUpdaterAddress = getAddress("tssUpdater", network.name);

const constructorArgs = [zetaTokenAddress, tssAddress, tssUpdaterAddress, tssUpdaterAddress];
let contract: Contract;
console.log(`Deploying ZetaConnector to ${network.name}`);

if (isEthNetworkName(network.name)) {
contract = await deployZetaConnectorEth({
args: [zetaTokenAddress, tssAddress, tssUpdaterAddress, tssUpdaterAddress],
args: constructorArgs,
});
} else {
contract = await deployZetaConnectorNonEth({
args: [zetaTokenAddress, tssAddress, tssUpdaterAddress, tssUpdaterAddress],
args: constructorArgs,
});
}

const finalBalance = await signer.getBalance();
console.log("Deployed ZetaConnector. Address:", contract.address);
console.log("Constructor Args", constructorArgs);
console.log("ETH spent:", initialBalance.sub(finalBalance).toString());
return contract.address;
}
14 changes: 11 additions & 3 deletions scripts/deployments/core/deploy-zeta-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,32 @@ export async function deployZetaToken() {

const accounts = await ethers.getSigners();
const [signer] = accounts;
const initialBalance = await signer.getBalance();

const DEPLOYER_ADDRESS = process.env.DEPLOYER_ADDRESS || signer.address;

const tssAddress = getAddress("tss", network.name);
const tssUpdaterAddress = getAddress("tssUpdater", network.name);

let contract: Contract;
let constructorArgs: any;
console.log(`Deploying ZetaToken to ${network.name}`);

if (isEthNetworkName(network.name)) {
constructorArgs = [DEPLOYER_ADDRESS, ZETA_INITIAL_SUPPLY];
contract = await deployZetaEth({
args: [DEPLOYER_ADDRESS, ZETA_INITIAL_SUPPLY],
args: constructorArgs,
});
} else {
constructorArgs = [tssAddress, tssUpdaterAddress];
contract = await deployZetaNonEth({
args: [tssAddress, tssUpdaterAddress],
args: constructorArgs,
});
}

console.log("Deployed Zeta to:", contract.address);
const finalBalance = await signer.getBalance();
console.log("Deployed ZetaToken. Address:", contract.address);
console.log("Constructor Args", constructorArgs);
console.log("ETH spent:", initialBalance.sub(finalBalance).toString());
return contract.address;
}
12 changes: 6 additions & 6 deletions scripts/deployments/core/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { network } from "hardhat";

import { isProtocolNetworkName } from "../../../lib/address.tools";
import { deterministicDeployERC20Custody } from "./deterministic-deploy-erc20-custody";
import { deterministicDeployZetaConnector } from "./deterministic-deploy-zeta-connector";
import { deterministicDeployZetaToken } from "./deterministic-deploy-zeta-token";
import { deployERC20Custody } from "./deploy-erc20-custody";
import { deployZetaConnector } from "./deploy-zeta-connector";
import { deployZetaToken } from "./deploy-zeta-token";

const networkName = network.name;

async function main() {
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name");

await deterministicDeployZetaToken();
await deterministicDeployZetaConnector();
await deterministicDeployERC20Custody();
const zetaTokenAddress = await deployZetaToken();
await deployZetaConnector(zetaTokenAddress);
await deployERC20Custody(zetaTokenAddress);
}

main()
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2164,10 +2164,10 @@
"@uniswap/v3-core" "1.0.0"
base64-sol "1.0.1"

"@zetachain/networks@6.0.0":
version "6.0.0"
resolved "https://registry.npmjs.org/@zetachain/networks/-/networks-6.0.0.tgz"
integrity sha512-yKFVP/yJDp76Q5lBGfZSpY/KO3TZ9ldo0lhE4MpBW43EsBxOZWixg6sqb56mcU/gg1lbWG8sHHWtYFK51SByjQ==
"@zetachain/networks@8.0.0-rc1":
version "8.0.0-rc1"
resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-8.0.0-rc1.tgz#3ad8891a7e2120509ef560720c6fa573a0a0b73f"
integrity sha512-rw09aariRcNItoNYClHq6Gm2IUNoBOFHOO3VHNyN7krapbY0Jy4HCQQj8iq7oNWZyNfwDIxIqkiQURPvIfpsMw==
dependencies:
dotenv "^16.1.4"

Expand Down

0 comments on commit b430334

Please sign in to comment.