-
Notifications
You must be signed in to change notification settings - Fork 261
feat(contract_manager): add support for near contract upgrade #2393
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
70 changes: 70 additions & 0 deletions
70
contract_manager/scripts/generate_upgrade_near_contract_proposal.ts
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,70 @@ | ||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
import { DefaultStore, loadHotWallet } from "../src"; | ||
import { NearChain } from "../src/chains"; | ||
|
||
const parser = yargs(hideBin(process.argv)) | ||
.usage( | ||
"Creates a governance proposal to upgrade the price feeds contract on Near.\n" + | ||
"Usage: $0 --network <mainnet|testnet> --code-hash <hash> --ops-key-path <ops_key_path>\n" | ||
) | ||
.options({ | ||
network: { | ||
type: "string", | ||
choices: ["mainnet", "testnet"], | ||
description: "Network to deploy to", | ||
demandOption: true, | ||
}, | ||
"code-hash": { | ||
type: "string", | ||
description: "Sha-256 HEX of the wasm file", | ||
demandOption: true, | ||
}, | ||
"ops-key-path": { | ||
type: "string", | ||
description: "Path to operations key file", | ||
demandOption: true, | ||
}, | ||
}); | ||
|
||
async function main() { | ||
const argv = await parser.argv; | ||
|
||
// Near wormhole contracts have the same id on testnet and mainnet. | ||
const chain = DefaultStore.chains.near; | ||
if (!(chain instanceof NearChain)) { | ||
throw new Error("Near chain is missing"); | ||
} | ||
|
||
const vault = | ||
DefaultStore.vaults[ | ||
argv.network === "mainnet" | ||
? "mainnet-beta_FVQyHcooAtThJ83XFrNnv74BcinbRH3bRmfFamAHBfuj" | ||
: "devnet_6baWtW1zTUVMSJHJQVxDUXWzqrQeYBr6mu31j3bTKwY3" | ||
]; | ||
|
||
const codeHash = argv["code-hash"]; | ||
if (Buffer.from(codeHash, "hex").length != 32) { | ||
throw new Error("invalid code hash format"); | ||
} | ||
console.log( | ||
`Upgrading contract on Near ${argv.network} to code hash: ${codeHash}` | ||
); | ||
|
||
// Generate governance payload for the upgrade | ||
const payload = chain.generateGovernanceUpgradePayload(codeHash); | ||
console.log("Governance payload:", payload); | ||
|
||
// Create and submit governance proposal | ||
console.log("Using vault for proposal:", vault.getId()); | ||
const keypair = await loadHotWallet(argv["ops-key-path"] as string); | ||
console.log("Using wallet:", keypair.publicKey.toBase58()); | ||
vault.connect(keypair); | ||
const proposal = await vault.proposeWormholeMessage([payload]); | ||
console.log("Proposal address:", proposal.address.toBase58()); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error("Error during upgrade:", error); | ||
process.exit(1); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
- chain: near | ||
address: pyth-oracle.near | ||
type: NearPriceFeedContract | ||
governanceDataSourceChain: 1 | ||
governanceDataSourceAddress: 5635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e | ||
lastExecutedGovernanceSequence: 0 | ||
- chain: near_testnet | ||
address: pyth-oracle.testnet | ||
type: NearPriceFeedContract | ||
governanceDataSourceChain: 1 | ||
governanceDataSourceAddress: 63278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c385 | ||
lastExecutedGovernanceSequence: 100 |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder where you are using these 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are used in the corresponding methods of
NearPriceFeedContract
.