Skip to content

Commit

Permalink
add emojis and replenishment stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
geoknee committed Nov 7, 2024
1 parent 33aa50b commit 7fee788
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,22 @@ async function main() {
const wallet0 = new ethers.Wallet(PRIVATE_KEY, provider0);
const wallet1 = new ethers.Wallet(PRIVATE_KEY, provider1);

console.log("balance is ", ethers.formatEther(await provider0.getBalance(wallet0.address)), "on chain 0")
const relayorAddress = "0xBD4F00cb05C5a5843889746Bc139A659370973c9"

// const reUpRelayorTx = {
// to: "0xBD4F00cb05C5a5843889746Bc139A659370973c9",
// value: ethers.parseEther("0.1"),
// };

// const tX = await wallet0.sendTransaction(reUpRelayorTx)
// console.log("replenshing relayor on chain 1, tx with hash", tX.hash)
// await tX.wait()


console.log("⚖️ User balance is ", ethers.formatEther(await provider0.getBalance(wallet0.address)), "on chain 0")
console.log("⚖️ Relayor balance is ", ethers.formatEther(await provider0.getBalance(relayorAddress)), "on chain 0")
console.log("⚖️ Relayor balance is ", ethers.formatEther(await provider1.getBalance(relayorAddress)), "on chain 1")


// OPStack chains have a CreateX preinstall at 0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed
// we can use function deployCreate2(bytes32 salt, bytes memory initCode) public payable returns (address newContract)
Expand All @@ -60,8 +75,12 @@ async function main() {

const createX0 = new ethers.Contract("0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", functionAbi, wallet0)
const createX1 = new ethers.Contract("0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed", functionAbi, wallet1)

// Increment this to get a fresh deployment even when source code is unchanged.
const salt = wallet0.address + "000000000000000000000000" // to conform with CreateX salt requirements.
console.log("salt", salt)


console.log("🧂 CREATE2 deployment salt:", salt)
const guardedSalt = ethers.keccak256("0x000000000000000000000000" + wallet0.address.slice(2) + salt.slice(2))

const initCodeHash = ethers.keccak256(interopPoWContractArtifact.bytecode.object)
Expand All @@ -71,56 +90,56 @@ async function main() {
if (codeAt == "0x") {
const tx = await createX0.deployCreate2(salt, interopPoWContractArtifact.bytecode.object)
await tx.wait()
console.log("interopPoW deployed to ", interopPoWAddress, " on chain 0")
console.log("📜 interopPoW deployed to ", interopPoWAddress, " on chain 0")
} else {
console.log("interopPoW already deployed to ", interopPoWAddress, " on chain 0")
console.log("📜 interopPoW already deployed to ", interopPoWAddress, " on chain 0")
}

const workerAddress = await createX0.computeCreate2Address(guardedSalt, ethers.keccak256(workerContractArtifact.bytecode.object))
codeAt = await provider0.getCode(workerAddress)
if (codeAt == "0x") {
const tx = await createX0.deployCreate2(salt, workerContractArtifact.bytecode.object)
await tx.wait()
console.log("worker deployed to ", workerAddress, "on chain 0")
console.log("📜 worker deployed to ", workerAddress, "on chain 0")
} else {
console.log("worker already deployed to ", workerAddress, "on chain 0")
console.log("📜 worker already deployed to ", workerAddress, "on chain 0")
}

codeAt = await provider1.getCode(workerAddress)
createX0.connect(wallet1)
if (codeAt == "0x") {
const tx = await createX1.deployCreate2(salt, workerContractArtifact.bytecode.object)
await tx.wait()
console.log("worker deployed to ", workerAddress, "on chain 1")
console.log("📜 worker deployed to ", workerAddress, "on chain 1")
} else {
console.log("worker already deployed to ", workerAddress, " on chain 1")
console.log("📜 worker already deployed to ", workerAddress, " on chain 1")
}

// const worker0 = new ethers.Contract(workerAddress, workerContractArtifact.abi, wallet0)
// const worker1 = new ethers.Contract(workerAddress, workerContractArtifact.abi, wallet1)
const worker0 = new ethers.Contract(workerAddress, workerContractArtifact.abi, wallet0)
const worker1 = new ethers.Contract(workerAddress, workerContractArtifact.abi, wallet1)

// call entrypoint
const interopPoW = new ethers.Contract(interopPoWAddress, interopPoWContractArtifact.abi, wallet0)
const tx = await interopPoW.run(workerAddress, [11473209, 21473209]) // launch everything
// const tx = await interopPoW.run(workerAddress, [21473209]) // launch only on the remote chain. the xdm does not allow sending to your own chain
console.log("interopPoW.run() tx launched with hash", tx.hash)
// const tx = await interopPoW.run(workerAddress, [11473209, 21473209]) // launch everything
const tx = await interopPoW.run(workerAddress, [21473209]) // launch only on the remote chain. the xdm does not allow sending to your own chain
console.log("🗳️ interopPoW.run() tx launching with hash", tx.hash)
await tx.wait()
console.log("launched job...")
console.log("⚒️ tx confirmed")

// wait for event
// event subscriptions are not supported, so we resort
// to short polling
console.log("polling for state every 1s...")
console.log("🗣️ polling for state every 1s...")

let counter = 0;
const interval = setInterval(async () => {
// Code to run every 1 second
console.log("Querying results...", counter++);
console.log("\nQuerying results...", counter++);

// const log0 = await worker0.localResultLog()
// console.log("worker1 local reusult:", log0)
// const log1 = await worker1.localResultLog()
// console.log("worker1 local reusult:", log1)
const log0 = await worker0.localResultLog()
console.log("worker0 (LOCAL) cached result:", log0)
const log1 = await worker1.localResultLog()
console.log("worker1 (REMOTE) cached result:", log1)

const aR = await interopPoW.allResults()
console.log("allResults:", aR)
Expand All @@ -130,7 +149,7 @@ async function main() {
clearInterval(interval);
console.log("Finished after 10 seconds");
}
}, 1000); // 1000 ms = 1 second
}, 2000); // 1000 ms = 1 second

}

Expand Down

0 comments on commit 7fee788

Please sign in to comment.