-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metadata cross-chain sync (#165)
* add content * add metadata
- Loading branch information
Showing
6 changed files
with
551 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import hre, { ethers } from "hardhat" | ||
import { NFT__factory } from "../typechain-types/factories/contracts/variants/crosschain/NFT__factory" | ||
import * as fs from "fs" | ||
import * as path from "path" | ||
import color from "cli-color" | ||
var msg = color.xterm(39).bgXterm(128) | ||
|
||
function getDeployedAddress(network: string, contractName: string): string { | ||
try { | ||
const deploymentPath = path.join( | ||
__dirname, | ||
"..", | ||
"deployments", | ||
network, | ||
`${contractName}.json` | ||
) | ||
const deployment = JSON.parse(fs.readFileSync(deploymentPath, "utf8")) | ||
return deployment.address | ||
} catch (error) { | ||
throw new Error( | ||
`Failed to read deployment for ${contractName} on ${network}: ${error}` | ||
) | ||
} | ||
} | ||
|
||
function getProofFromData(): string { | ||
try { | ||
const dataPath = path.join(__dirname, "..", "data.json") | ||
const data = JSON.parse(fs.readFileSync(dataPath, "utf8")) | ||
return data.proof | ||
} catch (error) { | ||
throw new Error(`Failed to read proof from data.json: ${error}`) | ||
} | ||
} | ||
|
||
async function main() { | ||
const SIGNER_PRIVATE_KEY = process.env.SIGNER_PRIVATE_KEY | ||
if (!SIGNER_PRIVATE_KEY) { | ||
throw new Error("Please set SIGNER_PRIVATE_KEY in your .env file") | ||
} | ||
|
||
const networkName = hre.network.name | ||
const NFT_ADDRESS = getDeployedAddress(networkName, "CrosschainNFT") | ||
console.log("Using NFT contract address:", NFT_ADDRESS) | ||
|
||
const provider = new ethers.JsonRpcProvider( | ||
networkName === "op-sepolia" | ||
? process.env.OP_SEPOLIA_RPC_ENDPOINT_URL | ||
: process.env.ARBITRUM_SEPOLIA_RPC_ENDPOINT_URL | ||
) | ||
const signerZero = new ethers.Wallet(SIGNER_PRIVATE_KEY, provider) | ||
|
||
console.log("Using address:", signerZero.address) | ||
|
||
const nft = NFT__factory.connect(NFT_ADDRESS, signerZero) | ||
|
||
const proof = getProofFromData() | ||
console.log("\nUsing metadata proof:", proof) | ||
|
||
try { | ||
console.log("Simulating metadata update claim...") | ||
await nft.claimMetadataUpdate.staticCall(proof) | ||
console.log("✅ Simulation successful") | ||
|
||
console.log("Submitting metadata update claim...") | ||
const tx = await nft.claimMetadataUpdate(proof, { | ||
gasLimit: 500000 | ||
}) | ||
|
||
console.log("Transaction submitted:", msg(tx.hash)) | ||
console.log("Waiting for confirmation...") | ||
|
||
const receipt = await tx.wait() | ||
console.log("Metadata update claimed successfully!") | ||
|
||
const updateEvent = receipt?.logs.find(log => { | ||
try { | ||
return nft.interface.parseLog(log)?.name === "MetadataUpdated" | ||
} catch { | ||
return false | ||
} | ||
}) | ||
|
||
if (updateEvent) { | ||
const parsedEvent = nft.interface.parseLog(updateEvent) | ||
const tokenId = parsedEvent?.args?.tokenId | ||
const newUri = parsedEvent?.args?.newUri | ||
console.log("Updated token ID:", tokenId) | ||
console.log("New metadata URI:", newUri) | ||
} | ||
} catch (error: any) { | ||
console.error("\nError details:", error) | ||
throw error | ||
} | ||
} | ||
|
||
main().catch(error => { | ||
console.error(error) | ||
process.exitCode = 1 | ||
}) |
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 @@ | ||
#!/bin/bash | ||
|
||
# Color codes | ||
GREEN='\033[0;32m' | ||
RED='\033[0;31m' | ||
BLUE='\033[0;34m' | ||
NC='\033[0m' # No Color | ||
|
||
echo -e "${BLUE}Starting cross-chain metadata update process...${NC}\n" | ||
|
||
# Create proposal on OP Sepolia | ||
echo -e "\n${BLUE}Creating metadata update proposal on OP Sepolia...${NC}" | ||
if npx hardhat run scripts/propose-metadata.ts --network op-sepolia; then | ||
echo -e "${GREEN}✓ Metadata update proposal creation successful${NC}" | ||
else | ||
echo -e "${RED}✗ Metadata update proposal creation failed${NC}" | ||
exit 1 | ||
fi | ||
|
||
# Generate metadata proof from OP Sepolia | ||
echo -e "\n${BLUE}Generating metadata proof from OP Sepolia...${NC}" | ||
if npx hardhat run scripts/verify-metadata-proof.ts --network op-sepolia; then | ||
echo -e "${GREEN}✓ Metadata proof generation successful${NC}" | ||
else | ||
echo -e "${RED}✗ Metadata proof generation failed${NC}" | ||
exit 1 | ||
fi | ||
|
||
# Claim metadata update on Arbitrum Sepolia | ||
echo -e "\n${BLUE}Claiming metadata update on Arbitrum Sepolia...${NC}" | ||
if npx hardhat run scripts/claim-metadata.ts --network arbitrum-sepolia; then | ||
echo -e "${GREEN}✓ Metadata update claim successful${NC}" | ||
echo -e "\n${GREEN}✓ All metadata update steps completed successfully!${NC}" | ||
exit 0 | ||
else | ||
echo -e "${RED}✗ Metadata update claim failed${NC}" | ||
exit 1 | ||
fi |
Oops, something went wrong.