-
Notifications
You must be signed in to change notification settings - Fork 301
feat(contract_manager): add deploy_evm_pulse_contracts script #2439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c6e16fa
feat(pulse): implement withdrawFees function and update ABI for Pulse…
cctdaniel 0de0f9a
feat(deploy): enhance bytecode handling and add default provider opti…
cctdaniel ca0e8dc
add hardcoded default provider and keeper
cctdaniel b698a1c
refactor(deploy): simplify ERC1967Proxy deployment logic and remove u…
cctdaniel ec17794
feat(deploy): extract common functions
cctdaniel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
cctdaniel marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,174 @@ | ||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
import { EvmChain } from "../src/chains"; | ||
import { DefaultStore } from "../src/store"; | ||
import { | ||
DeploymentType, | ||
toDeploymentType, | ||
toPrivateKey, | ||
EvmPulseContract, | ||
PULSE_DEFAULT_PROVIDER, | ||
PULSE_DEFAULT_KEEPER, | ||
} from "../src"; | ||
import { | ||
COMMON_DEPLOY_OPTIONS, | ||
deployIfNotCached, | ||
getWeb3Contract, | ||
getOrDeployWormholeContract, | ||
BaseDeployConfig, | ||
topupAccountsIfNecessary, | ||
DefaultAddresses, | ||
} from "./common"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
interface DeploymentConfig extends BaseDeployConfig { | ||
type: DeploymentType; | ||
saveContract: boolean; | ||
} | ||
|
||
const CACHE_FILE = ".cache-deploy-evm-pulse-contracts"; | ||
|
||
const parser = yargs(hideBin(process.argv)) | ||
.scriptName("deploy_evm_pulse_contracts.ts") | ||
.usage( | ||
"Usage: $0 --std-output-dir <path/to/std-output-dir/> --private-key <private-key> --chain <chain> --default-provider <default-provider> --wormhole-addr <wormhole-addr>" | ||
) | ||
.options({ | ||
...COMMON_DEPLOY_OPTIONS, | ||
chain: { | ||
type: "string", | ||
demandOption: true, | ||
desc: "Chain to upload the contract on. Can be one of the evm chains available in the store", | ||
}, | ||
}); | ||
|
||
async function deployPulseContracts( | ||
chain: EvmChain, | ||
config: DeploymentConfig, | ||
executorAddr: string | ||
): Promise<string> { | ||
console.log("Deploying PulseUpgradeable on", chain.getId(), "..."); | ||
|
||
// Get the artifact and ensure bytecode is properly formatted | ||
const pulseArtifact = JSON.parse( | ||
fs.readFileSync( | ||
path.join(config.jsonOutputDir, "PulseUpgradeable.json"), | ||
"utf8" | ||
) | ||
); | ||
console.log("PulseArtifact bytecode type:", typeof pulseArtifact.bytecode); | ||
|
||
const pulseImplAddr = await deployIfNotCached( | ||
CACHE_FILE, | ||
chain, | ||
config, | ||
"PulseUpgradeable", | ||
[] | ||
); | ||
|
||
console.log("PulseUpgradeable implementation deployed at:", pulseImplAddr); | ||
|
||
const pulseImplContract = getWeb3Contract( | ||
config.jsonOutputDir, | ||
"PulseUpgradeable", | ||
pulseImplAddr | ||
); | ||
|
||
console.log("Preparing initialization data..."); | ||
|
||
const pulseInitData = pulseImplContract.methods | ||
.initialize( | ||
executorAddr, // owner | ||
executorAddr, // admin | ||
"1", // pythFeeInWei | ||
executorAddr, // pythAddress - using executor as a placeholder | ||
chain.isMainnet() | ||
? PULSE_DEFAULT_PROVIDER.mainnet | ||
: PULSE_DEFAULT_PROVIDER.testnet, | ||
true, // prefillRequestStorage | ||
3600 // exclusivityPeriodSeconds - 1 hour | ||
) | ||
.encodeABI(); | ||
|
||
console.log("Deploying ERC1967Proxy for Pulse..."); | ||
|
||
return await deployIfNotCached( | ||
CACHE_FILE, | ||
chain, | ||
config, | ||
"ERC1967Proxy", | ||
[pulseImplAddr, pulseInitData], | ||
// NOTE: we are deploying a ERC1967Proxy when deploying executor | ||
// we need to provide a different cache key. As the `artifactname` | ||
// is same in both case which means the cache key will be same | ||
`${chain.getId()}-ERC1967Proxy-PULSE1` | ||
); | ||
} | ||
|
||
async function topupPulseAccountsIfNecessary( | ||
chain: EvmChain, | ||
deploymentConfig: DeploymentConfig | ||
) { | ||
const accounts: Array<[string, DefaultAddresses]> = [ | ||
["keeper", PULSE_DEFAULT_KEEPER], | ||
["provider", PULSE_DEFAULT_PROVIDER], | ||
]; | ||
|
||
await topupAccountsIfNecessary(chain, deploymentConfig, accounts); | ||
} | ||
|
||
async function main() { | ||
const argv = await parser.argv; | ||
|
||
const chainName = argv.chain; | ||
const chain = DefaultStore.chains[chainName]; | ||
if (!chain) { | ||
throw new Error(`Chain ${chainName} not found`); | ||
} else if (!(chain instanceof EvmChain)) { | ||
throw new Error(`Chain ${chainName} is not an EVM chain`); | ||
} | ||
|
||
const deploymentConfig: DeploymentConfig = { | ||
type: toDeploymentType(argv.deploymentType), | ||
gasMultiplier: argv.gasMultiplier, | ||
gasPriceMultiplier: argv.gasPriceMultiplier, | ||
privateKey: toPrivateKey(argv.privateKey), | ||
jsonOutputDir: argv.stdOutputDir, | ||
saveContract: argv.saveContract, | ||
}; | ||
|
||
const wormholeContract = await getOrDeployWormholeContract( | ||
chain, | ||
deploymentConfig, | ||
CACHE_FILE | ||
); | ||
|
||
await topupPulseAccountsIfNecessary(chain, deploymentConfig); | ||
|
||
console.log( | ||
`Deployment config: ${JSON.stringify(deploymentConfig, null, 2)}\n` | ||
); | ||
|
||
console.log(`Deploying pulse contracts on ${chain.getId()}...`); | ||
|
||
const executorAddr = wormholeContract.address; // Using wormhole contract as executor for Pulse | ||
const pulseAddr = await deployPulseContracts( | ||
chain, | ||
deploymentConfig, | ||
executorAddr | ||
); | ||
|
||
if (deploymentConfig.saveContract) { | ||
console.log("Saving the contract in the store..."); | ||
const contract = new EvmPulseContract(chain, pulseAddr); | ||
DefaultStore.pulse_contracts[contract.getId()] = contract; | ||
DefaultStore.saveAllContracts(); | ||
} | ||
|
||
console.log( | ||
`✅ Deployed pulse contracts on ${chain.getId()} at ${pulseAddr}\n\n` | ||
); | ||
} | ||
|
||
main(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.