Skip to content

Commit

Permalink
chore(entropy) Deploy on abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya520 committed Oct 23, 2024
1 parent cf9172c commit ec367de
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 84 deletions.
3 changes: 3 additions & 0 deletions contract_manager/store/contracts/EvmEntropyContracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,6 @@
- chain: sanko_testnet
address: "0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb"
type: EvmEntropyContract
- chain: abstract_testnet
address: "0x858687fD592112f7046E394A3Bf10D0C11fF9e63"
type: EvmEntropyContract
2 changes: 1 addition & 1 deletion target_chains/ethereum/contracts/.env.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Network Config
MIGRATIONS_DIR= # ./migrations/prod-receiver
MIGRATIONS_NETWORK= # xyz

MAINNET=

# The duration that a price feed stored in the contract is considered to be
# valid, after this duration, the price feed is stale and will be invalid.
Expand Down
109 changes: 94 additions & 15 deletions target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { CHAINS } from "@pythnetwork/xc-admin-common";
import { assert } from "chai";
import { DefaultStore, EvmChain, EvmWormholeContract } from "@pythnetwork/contract-manager";
import { findWormholeContract, deployWormholeContract } from "./zkSyncDeployWormhole";
import {
DefaultStore,
EvmChain,
EvmWormholeContract,
} from "@pythnetwork/contract-manager";
import {
findWormholeContract,
deployWormholeContract,
} from "./zkSyncDeployWormhole";

// import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work
// import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync";
Expand All @@ -19,26 +26,29 @@ function envOrErr(name: string): string {
}
return res;
}


export const ENTROPY_DEFAULT_PROVIDER = {
mainnet: "0x52DeaA1c84233F7bb8C8A45baeDE41091c616506",
testnet: "0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344",
};
export const ENTROPY_DEFAULT_KEEPER = {
mainnet: "0xbcab779fca45290288c35f5e231c37f9fa87b130",
testnet: "0xa5A68ed167431Afe739846A22597786ba2da85df",
};

export default async function (hre: HardhatRuntimeEnvironment) {
// Initialize the wallet.
const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC"));
const isMainnet = envOrErr("MAINNET") === "true";

// Create deployer object and load the artifact of the contract we want to deploy.
const deployer = new Deployer(hre, wallet);



const {
wormholeGovernanceChainId,
wormholeGovernanceContract,
wormholeInitialSigners,
governanceEmitter,
governanceChainId,
emitterAddresses,
emitterChainIds,
} = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK"));

const chainName = envOrErr("MIGRATIONS_NETWORK");
Expand All @@ -50,29 +60,67 @@ export default async function (hre: HardhatRuntimeEnvironment) {
if (!wormholeReceiverContractAddress) {
console.log(`Wormhole contract not found for chain ${chainName}`);
console.log("Deploying Wormhole contract...");
wormholeReceiverContractAddress = await deployWormholeContract(deployer, chainName, wormholeGovernanceChainId, wormholeGovernanceContract, wormholeInitialSigners, wormholeReceiverChainId);
wormholeReceiverContractAddress = await deployWormholeContract(
deployer,
chainName,
wormholeGovernanceChainId,
wormholeGovernanceContract,
wormholeInitialSigners,
wormholeReceiverChainId
);
}

console.log("WormholeReceiver contract address:", wormholeReceiverContractAddress);

console.log(
"WormholeReceiver contract address:",
wormholeReceiverContractAddress
);

// // TODO: Top up accounts if necessary

const executorContractAddress = await deployExecutorContract(deployer, wormholeReceiverContractAddress, wormholeReceiverChainId, governanceEmitter);
const executorContractAddress = await deployExecutorContract(
deployer,
wormholeReceiverContractAddress,
wormholeReceiverChainId,
governanceChainId,
governanceEmitter
);

console.log("Executor contract address:", executorContractAddress);

const entropyContractAddress = await deployEntropyContract(
deployer,
executorContractAddress,
wormholeReceiverChainId,
isMainnet
);

console.log("Entropy contract address:", entropyContractAddress);
}

async function deployExecutorContract(deployer: Deployer, wormholeReceiverContractAddress: string, wormholeReceiverChainId: number, governanceEmitter: string) {
const executorImplArtifact = await deployer.loadArtifact("ExecutorUpgradable");
async function deployExecutorContract(
deployer: Deployer,
wormholeReceiverContractAddress: string,
wormholeReceiverChainId: number,
governanceChainId: string,
governanceEmitter: string
) {
const executorImplArtifact = await deployer.loadArtifact(
"ExecutorUpgradable"
);
const executorImplContract = await deployer.deploy(executorImplArtifact);
console.log(
"Deployed ExecutorImpl contract on",
executorImplContract.address
);

const executorInitData = executorImplContract.interface.encodeFunctionData(
"initialize",
[
wormholeReceiverContractAddress,
0, // lastExecutedSequence,
wormholeReceiverChainId,
governanceChainId,
governanceEmitter,
governanceEmitter
]
);

Expand All @@ -87,3 +135,34 @@ async function deployExecutorContract(deployer: Deployer, wormholeReceiverContra

return executorProxyContract.address;
}

async function deployEntropyContract(
deployer: Deployer,
executorContractAddress: string,
chainId: number,
isMainnet: boolean
) {
const entropyImplArtifact = await deployer.loadArtifact("EntropyUpgradable");
const entropyImplContract = await deployer.deploy(entropyImplArtifact);

const entropyInitData = entropyImplContract.interface.encodeFunctionData(
"initialize",
[
executorContractAddress,
executorContractAddress,
1,
isMainnet
? ENTROPY_DEFAULT_PROVIDER.mainnet
: ENTROPY_DEFAULT_PROVIDER.testnet,
true,
]
);

const entropyProxyArtifact = await deployer.loadArtifact("ERC1967Proxy");
const entropyProxyContract = await deployer.deploy(entropyProxyArtifact, [
entropyImplContract.address,
entropyInitData,
]);

return entropyProxyContract.address;
}
68 changes: 13 additions & 55 deletions target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { CHAINS } from "@pythnetwork/xc-admin-common";
import { assert } from "chai";
import { writeFileSync } from "fs";
import { deployWormholeContract, findWormholeContract } from "./zkSyncDeployWormhole";
import {
deployWormholeContract,
findWormholeContract,
} from "./zkSyncDeployWormhole";
// import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work
// import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync";

Expand Down Expand Up @@ -53,16 +56,21 @@ export default async function (hre: HardhatRuntimeEnvironment) {

const wormholeReceiverChainId = CHAINS[chainName];
assert(wormholeReceiverChainId !== undefined);

let wormholeReceiverContractAddress = await findWormholeContract(chainName);
if (!wormholeReceiverContractAddress) {
console.log(`Wormhole contract not found for chain ${chainName}`);
console.log("Deploying Wormhole contract...");
wormholeReceiverContractAddress = await deployWormholeContract(deployer, chainName, wormholeReceiverChainId, wormholeGovernanceChainId, wormholeGovernanceContract, wormholeInitialSigners);
wormholeReceiverContractAddress = await deployWormholeContract(
deployer,
chainName,
wormholeReceiverChainId,
wormholeGovernanceChainId,
wormholeGovernanceContract,
wormholeInitialSigners
);
}



// Hardcoding the initial sequence number for governance messages.
const governanceInitialSequence = Number("0");

Expand Down Expand Up @@ -118,53 +126,3 @@ export default async function (hre: HardhatRuntimeEnvironment) {
// )
// );
}






// const wormholeReceiverChainId = CHAINS[chainName];
// assert(wormholeReceiverChainId !== undefined);

// const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup");
// const receiverImplArtifact = await deployer.loadArtifact(
// "ReceiverImplementation"
// );
// const wormholeReceiverArtifact = await deployer.loadArtifact(
// "WormholeReceiver"
// );

// console.log("Deploying WormholeReceiver contract...");
// const receiverSetupContract = await deployer.deploy(receiverSetupArtifact);
// console.log("Deployed ReceiverSetup on", receiverSetupContract.address);

// console.log("Deploying ReceiverImplementation contract...");
// // deploy implementation
// const receiverImplContract = await deployer.deploy(receiverImplArtifact);
// console.log(
// "Deployed ReceiverImplementation on",
// receiverImplContract.address
// );

// // encode initialisation data
// const whInitData = receiverSetupContract.interface.encodeFunctionData(
// "setup",
// [
// receiverImplContract.address,
// wormholeInitialSigners,
// wormholeReceiverChainId,
// wormholeGovernanceChainId,
// wormholeGovernanceContract,
// ]
// );

// // deploy proxy
// const wormholeReceiverContract = await deployer.deploy(
// wormholeReceiverArtifact,
// [receiverSetupContract.address, whInitData]
// );

// console.log(
// `Deployed WormholeReceiver on ${wormholeReceiverContract.address}`
// );
34 changes: 21 additions & 13 deletions target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import { DefaultStore, EvmChain, EvmWormholeContract } from "@pythnetwork/contract-manager";
import {
DefaultStore,
EvmChain,
EvmWormholeContract,
} from "@pythnetwork/contract-manager";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { CHAINS } from "@pythnetwork/xc-admin-common";
import { assert } from "chai";

export function findWormholeContract(chainId: string): string | undefined {
for (const contract of Object.values(DefaultStore.wormhole_contracts)) {
if (
contract instanceof EvmWormholeContract &&
contract.getChain().getId() === chainId
) {
return contract.address;
}
for (const contract of Object.values(DefaultStore.wormhole_contracts)) {
if (
contract instanceof EvmWormholeContract &&
contract.getChain().getId() === chainId
) {
return contract.address;
}
}
}


export async function deployWormholeContract(deployer: Deployer, chainName: string, wormholeGovernanceChainId: string, wormholeGovernanceContract: string, wormholeInitialSigners: string[], wormholeReceiverChainId: number): Promise<string> {


export async function deployWormholeContract(
deployer: Deployer,
chainName: string,
wormholeGovernanceChainId: string,
wormholeGovernanceContract: string,
wormholeInitialSigners: string[],
wormholeReceiverChainId: number
): Promise<string> {
const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup");
const receiverImplArtifact = await deployer.loadArtifact(
"ReceiverImplementation"
Expand All @@ -26,7 +34,7 @@ export async function deployWormholeContract(deployer: Deployer, chainName: stri
"WormholeReceiver"
);
console.log("Deploying WormholeReceiver contract...");

const receiverSetupContract = await deployer.deploy(receiverSetupArtifact);
console.log("Deployed ReceiverSetup on", receiverSetupContract.address);
console.log("Deploying ReceiverImplementation contract...");
Expand Down

0 comments on commit ec367de

Please sign in to comment.