| 1 | // Import the ethers library |
| 2 | const { ethers } = require("hardhat"); |
| 3 | const { TokenboundClient } = require("@tokenbound/sdk"); |
| 4 | const provider = new ethers.AlchemyProvider("goerli", process.env.ALCHEMY_KEY) |
| 5 | const operatorAbi = require("../artifacts/contracts/Operator.sol/Operator.json") |
| 6 | |
| 7 | |
| 8 | async function Operator() { |
| 9 | |
| 10 | // Get the signers from ethers |
| 11 | let owner; |
| 12 | [owner] = await ethers.getSigners(); |
| 13 | const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider) |
| 14 | console.log(`SERVER_WALLET_PRIVATE_KEY=${process.env.PRIVATE_KEY}`) |
| 15 | console.log(`SERVER_WALLET_ADDRESS=${wallet.address}`) |
| 16 | const tokenboundClient = new TokenboundClient({ signer: wallet, chainId: 5 }) |
| 17 | |
| 18 | // Deploy NPC contract |
| 19 | const NPCContract = await ethers.getContractFactory("CosmicCowboys"); |
| 20 | const npcContract = await NPCContract.deploy(owner.address); |
| 21 | const npcContractAddress = await npcContract.getAddress() |
| 22 | console.log(`NPC_CONTRACT_ADDRESS=${npcContractAddress}`); |
| 23 | |
| 24 | // Deploy ERC-20 Contract |
| 25 | const CurrencyContract = await ethers.getContractFactory("GoldenCorn"); |
| 26 | const currencyContract = await CurrencyContract.deploy(owner.address); |
| 27 | const currencyContractAddress = await currencyContract.getAddress() |
| 28 | console.log(`CURRENCY_CONTRACT_ADDRESS=${currencyContractAddress}`) |
| 29 | |
| 30 | // Deploy 1155 Contracts |
| 31 | const FoodContract = await ethers.getContractFactory("SpaceSlop"); |
| 32 | const foodContract = await FoodContract.deploy(owner.address); |
| 33 | const foodContractAddress = await foodContract.getAddress() |
| 34 | console.log(`FOOD_CONTRACT_ADDRESS=${foodContractAddress}`); |
| 35 | |
| 36 | const SupplyContract = await ethers.getContractFactory("JupiterJunk"); |
| 37 | const supplyContract = await SupplyContract.deploy(owner.address); |
| 38 | const supplyContractAddress = await supplyContract.getAddress() |
| 39 | console.log(`SUPPLY_CONTRACT_ADDRESS=${supplyContractAddress}`); |
| 40 | |
| 41 | // Deploy ERC6551 |
| 42 | /* const RegistryContract = await ethers.getContractFactory("ERC6551Registry"); |
| 43 | const registryContract = await RegistryContract.deploy(); |
| 44 | const registryContractAddress = await registryContract.getAddress() |
| 45 | console.log("Registry Contract deployed to address:", registryContractAddress); |
| 46 | |
| 47 | const AccountContract = await ethers.getContractFactory("ERC6551Account"); |
| 48 | const accountContract = await AccountContract.deploy(); |
| 49 | const accountContractAddress = await accountContract.getAddress() |
| 50 | console.log("Account Contract deployed to address:", accountContractAddress); */ |
| 51 | |
| 52 | // Deploy Operator Contract |
| 53 | const OperatorContract = await ethers.getContractFactory("Operator"); |
| 54 | const operatorContract = await OperatorContract.deploy(owner.address, npcContractAddress, currencyContractAddress, foodContractAddress, supplyContractAddress) |
| 55 | const operatorContractAddress = await operatorContract.getAddress() |
| 56 | console.log("OPERATOR_CONTRACT_ADDRESS", operatorContractAddress) |
| 57 | |
| 58 | /* const operatorContract = new ethers.Contract("0x575C0B5777eF7F620E51ff33b33ccB854B856e84", operatorAbi.abi, wallet) |
| 59 | npcContractAddress = "0xF0fEFC86335E227c85aA778b24061B6B70B80Ef4" */ |
| 60 | |
| 61 | // Transfer NPC contract to Operator |
| 62 | await npcContract.transferOwnership(operatorContractAddress); |
| 63 | await currencyContract.transferOwnership(operatorContractAddress); |
| 64 | await foodContract.transferOwnership(operatorContractAddress); |
| 65 | await supplyContract.transferOwnership(operatorContractAddress); |
| 66 | |
| 67 | const npcTx = await operatorContract.createNPC(owner.address, `ipfs://QmQbwCMwDETHHZ1g8YaSHqLBwCRgVHqFuRNRfiGyNqCcXj/1.json`) |
| 68 | const npcTxReceipt = await npcTx.wait() |
| 69 | console.log("NFT Minted") |
| 70 | |
| 71 | const stats = await operatorContract.getNPCStats(0) |
| 72 | console.log(stats) |
| 73 | |
| 74 | |
| 75 | /* for (let i = 16; i < 21; i++) { |
| 76 | // create NPC |
| 77 | const npcTx = await operatorContract.createNPC(owner.address, `ipfs://QmQbwCMwDETHHZ1g8YaSHqLBwCRgVHqFuRNRfiGyNqCcXj/${i}.json`) |
| 78 | const npcTxReceipt = await npcTx.wait() |
| 79 | console.log("NPC Created") |
| 80 | |
| 81 | // After the NPC is created |
| 82 | const latestTokenId = await operatorContract.getLatestTokenId(); |
| 83 | |
| 84 | // create TBA for NPC |
| 85 | const tba = await tokenboundClient.createAccount({ |
| 86 | tokenContract: npcContractAddress, |
| 87 | tokenId: latestTokenId, |
| 88 | }) |
| 89 | console.log("TBA:", tba) |
| 90 | |
| 91 | // equip NPC via TBA |
| 92 | |
| 93 | const equipTx = await operatorContract.equipNPC(tba, 20, 5, 5) |
| 94 | const equipTxReceipt = await equipTx.wait() |
| 95 | console.log("NPC Equipped") |
| 96 | } */ |
| 97 | } |
| 98 | |
| 99 | Operator() |