-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39e2ec2
commit 6893ead
Showing
6 changed files
with
177 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,65 @@ | ||
import { isProtocolNetworkName } from "@zetachain/protocol-contracts"; | ||
import { ethers, network } from "hardhat"; | ||
|
||
import { getZEVMAppAddress, saveAddress } from "../address.helpers"; | ||
import { verifyContract } from "../explorer.helpers"; | ||
|
||
const networkName = network.name; | ||
|
||
const encodeTag = (tag: string) => ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(["string"], [tag])); | ||
|
||
const executeVerifyContract = async (name: string, address: string, args: any[]) => { | ||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
|
||
console.log(`${name} deployed to:`, address); | ||
saveAddress(`${name}`, address, networkName); | ||
await verifyContract(address, args); | ||
}; | ||
|
||
const deployXPGov = async () => { | ||
const [signer] = await ethers.getSigners(); | ||
|
||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
const zetaXPAddress = getZEVMAppAddress("ZetaXP", networkName); | ||
console.log("ZetaXP address:", zetaXPAddress); | ||
|
||
// Deploy the TimelockController contract | ||
const timelockFactory = await ethers.getContractFactory("TimelockController"); | ||
const timelock = await timelockFactory.deploy(3600, [signer.address], [signer.address], signer.address); | ||
await timelock.deployed(); | ||
|
||
const timelockAddress = timelock.address; | ||
executeVerifyContract("TimelockController", timelockAddress, [ | ||
3600, | ||
[signer.address], | ||
[signer.address], | ||
signer.address, | ||
]); | ||
|
||
const tag = encodeTag("XP_NFT"); | ||
|
||
// Deploy the ZetaXPGov contract | ||
const ZetaXPGovFactory = await ethers.getContractFactory("ZetaXPGov"); | ||
const zetaGov = await ZetaXPGovFactory.deploy(zetaXPAddress, timelockAddress, 4, tag); | ||
await zetaGov.deployed(); | ||
|
||
const zetaGovAddress = zetaGov.address; | ||
|
||
executeVerifyContract("ZetaXPGov", zetaGovAddress, [zetaXPAddress, timelockAddress, 4, tag]); | ||
|
||
// Assign proposer and executor roles to the signer | ||
const proposerRole = await timelock.PROPOSER_ROLE(); | ||
const executorRole = await timelock.EXECUTOR_ROLE(); | ||
await timelock.grantRole(proposerRole, zetaGovAddress); | ||
await timelock.grantRole(executorRole, zetaGovAddress); | ||
}; | ||
|
||
const main = async () => { | ||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
await deployXPGov(); | ||
}; | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/zevm-app-contracts/scripts/xp-nft/gov-query-proposals.ts
This file contains 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,38 @@ | ||
import { isProtocolNetworkName } from "@zetachain/protocol-contracts"; | ||
import { ethers, network } from "hardhat"; | ||
|
||
import { getZEVMAppAddress } from "../address.helpers"; | ||
|
||
const networkName = network.name; | ||
|
||
const callGov = async () => { | ||
const govAddress = getZEVMAppAddress("ZetaXPGov", networkName); | ||
console.log("ZetaXPGov address:", govAddress); | ||
|
||
const ZetaXPGovFactory = await ethers.getContractFactory("ZetaXPGov"); | ||
const zetaGov = await ZetaXPGovFactory.attach(govAddress); | ||
|
||
const start = 7426910 - 1; | ||
const end = 7441292 + 1; | ||
for (let i = start; i < end; i += 1000) { | ||
const proposalIds = await zetaGov.queryFilter(zetaGov.filters.ProposalCreated(), i, i + 1000); | ||
if (proposalIds.length > 0) { | ||
for (let j = 0; j < proposalIds.length; j++) { | ||
const proposalId = proposalIds[j].proposalId; | ||
const votes = await zetaGov.proposalVotes(proposalId); | ||
console.log("Proposal ID:", proposalId); | ||
console.log("Votes:", votes); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const main = async () => { | ||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
await callGov(); | ||
}; | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
68 changes: 68 additions & 0 deletions
68
packages/zevm-app-contracts/scripts/xp-nft/gov-set-level.ts
This file contains 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,68 @@ | ||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; | ||
import { isProtocolNetworkName } from "@zetachain/protocol-contracts"; | ||
import { ethers, network } from "hardhat"; | ||
|
||
import { getSelLevelSignature } from "../../test/xp-nft/test.helpers"; | ||
import { ZetaXP_V2 } from "../../typechain-types"; | ||
import { getZEVMAppAddress, saveAddress } from "../address.helpers"; | ||
|
||
const networkName = network.name; | ||
|
||
const user = "0x3a600ECC217387e7Cf9F82fc2F3ffFb43F20FF80"; | ||
const encodeTag = (tag: string) => ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(["string"], [tag])); | ||
|
||
// Helper function to set the level of an NFT | ||
const setLevelToNFT = async (tokenId: number, level: number, zetaXP: ZetaXP_V2, signer: SignerWithAddress) => { | ||
const currentBlock = await ethers.provider.getBlock("latest"); | ||
const sigTimestamp = currentBlock.timestamp; | ||
const signatureExpiration = sigTimestamp + 1000; | ||
|
||
const currentChainId = (await ethers.provider.getNetwork()).chainId; | ||
const signature = await getSelLevelSignature( | ||
currentChainId, | ||
zetaXP.address, | ||
signer, | ||
signatureExpiration, | ||
sigTimestamp, | ||
tokenId, | ||
level | ||
); | ||
|
||
await zetaXP.setLevel({ level, sigTimestamp, signature, signatureExpiration, tokenId }); | ||
}; | ||
|
||
const callGov = async () => { | ||
const [signer] = await ethers.getSigners(); | ||
|
||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
const zetaXPAddress = getZEVMAppAddress("ZetaXP", networkName); | ||
console.log("ZetaXP address:", zetaXPAddress); | ||
|
||
const XPNFT = await ethers.getContractFactory("ZetaXP_V2"); | ||
const xpnft = await XPNFT.attach(zetaXPAddress); | ||
|
||
const xpSigner = await xpnft.signerAddress(); | ||
console.log("XP Signer:", xpSigner); | ||
|
||
const tag = encodeTag("XP_NFT"); | ||
console.log("Tag:", tag); | ||
const id = await xpnft.tokenByUserTag(user, tag); | ||
console.log("ID:", id); | ||
|
||
const level = await xpnft.getLevel(id); | ||
console.log("Level:", level); | ||
|
||
if (level.toNumber() === 0) { | ||
await setLevelToNFT(id, 3, xpnft, signer); | ||
} | ||
}; | ||
|
||
const main = async () => { | ||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
await callGov(); | ||
}; | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |