| 1 | // Import the ethers library |
| 2 | const { ethers } = require("hardhat"); |
| 3 | const provider = new ethers.getDefaultProvider("https://sepolia-rpc.scroll.io/") |
| 4 | const { TokenboundClient } = require("@tokenbound/sdk"); |
| 5 | const { createWalletClient, http } = require('viem') |
| 6 | const { privateKeyToAccount } = require('viem/accounts') |
| 7 | const { scrollSepolia } = require('viem/chains') |
| 8 | |
| 9 | const account = privateKeyToAccount(`0x` + process.env.TEST_PRIVATE_KEY) |
| 10 | |
| 11 | const walletClient = createWalletClient({ |
| 12 | account, |
| 13 | chain: scrollSepolia, |
| 14 | transport: http("https://sepolia-rpc.scroll.io/") |
| 15 | }) |
| 16 | |
| 17 | |
| 18 | async function Main() { |
| 19 | |
| 20 | // Get the signers from ethers |
| 21 | const wallet = new ethers.Wallet(process.env.TEST_PRIVATE_KEY, provider) |
| 22 | //const tokenboundClient = new TokenboundClient({ signer: wallet, chainId: 534351 }) |
| 23 | console.log(`SERVER_WALLET_PRIVATE_KEY=${process.env.TEST_PRIVATE_KEY}`) |
| 24 | console.log(`SERVER_WALLET_ADDRESS=${wallet.address}`) |
| 25 | |
| 26 | // Deploy NPC contract |
| 27 | const NPCContract = await ethers.getContractFactory("CosmicCowboys"); |
| 28 | const npcContract = await NPCContract.deploy(wallet.address); |
| 29 | const npcContractAddress = await npcContract.getAddress() |
| 30 | console.log(`NPC_CONTRACT_ADDRESS=${npcContractAddress}`); |
| 31 | |
| 32 | // Deploy ERC-20 Contract |
| 33 | const CurrencyContract = await ethers.getContractFactory("GoldenCorn"); |
| 34 | const currencyContract = await CurrencyContract.deploy(wallet.address); |
| 35 | const currencyContractAddress = await currencyContract.getAddress() |
| 36 | console.log(`CURRENCY_CONTRACT_ADDRESS=${currencyContractAddress}`) |
| 37 | |
| 38 | // Deploy 1155 Contracts |
| 39 | const FoodContract = await ethers.getContractFactory("SpaceSlop"); |
| 40 | const foodContract = await FoodContract.deploy(wallet.address); |
| 41 | const foodContractAddress = await foodContract.getAddress() |
| 42 | console.log(`FOOD_CONTRACT_ADDRESS=${foodContractAddress}`); |
| 43 | |
| 44 | const SupplyContract = await ethers.getContractFactory("JupiterJunk"); |
| 45 | const supplyContract = await SupplyContract.deploy(wallet.address); |
| 46 | const supplyContractAddress = await supplyContract.getAddress() |
| 47 | console.log(`SUPPLY_CONTRACT_ADDRESS=${supplyContractAddress}`); |
| 48 | |
| 49 | // Deploy ERC6551 |
| 50 | const RegistryContract = await ethers.getContractFactory("ERC6551Registry"); |
| 51 | const registryContract = await RegistryContract.deploy(); |
| 52 | const registryContractAddress = await registryContract.getAddress() |
| 53 | console.log("Registry Contract deployed to address:", registryContractAddress); |
| 54 | |
| 55 | const AccountContract = await ethers.getContractFactory("ERC6551Account"); |
| 56 | const accountContract = await AccountContract.deploy(); |
| 57 | const accountContractAddress = await accountContract.getAddress() |
| 58 | console.log("Account Contract deployed to address:", accountContractAddress); |
| 59 | |
| 60 | // Deploy Operator Contract |
| 61 | const OperatorContract = await ethers.getContractFactory("Operator"); |
| 62 | const operatorContract = await OperatorContract.deploy(wallet.address, npcContractAddress, currencyContractAddress, foodContractAddress, supplyContractAddress) |
| 63 | const operatorContractAddress = await operatorContract.getAddress() |
| 64 | console.log(`OPERATOR_CONTRACT_ADDRESS=${operatorContractAddress}`) |
| 65 | |
| 66 | // Transfer NPC contract to Operator |
| 67 | await npcContract.transferOwnership(operatorContractAddress); |
| 68 | await currencyContract.transferOwnership(operatorContractAddress); |
| 69 | await foodContract.transferOwnership(operatorContractAddress); |
| 70 | await supplyContract.transferOwnership(operatorContractAddress); |
| 71 | |
| 72 | const tokenboundClient = new TokenboundClient({ |
| 73 | walletClient: walletClient, |
| 74 | chain: scrollSepolia, |
| 75 | implementationAddress: accountContractAddress, |
| 76 | registryAddress: registryContractAddress, |
| 77 | }) |
| 78 | |
| 79 | |
| 80 | /* for (let i = 0; i < 19; i++) { |
| 81 | // create NPC |
| 82 | const npcTx = await operatorContract.createNPC(wallet.address, `ipfs://QmQbwCMwDETHHZ1g8YaSHqLBwCRgVHqFuRNRfiGyNqCcXj/${i}.json`) |
| 83 | const npcTxReceipt = await npcTx.wait() |
| 84 | console.log("NPC Created") |
| 85 | |
| 86 | // After the NPC is created |
| 87 | const latestTokenId = await operatorContract.getLatestTokenId(); |
| 88 | |
| 89 | // create TBA for NPC |
| 90 | const tba = await tokenboundClient.createAccount({ |
| 91 | tokenContract: npcContractAddress, |
| 92 | tokenId: latestTokenId, |
| 93 | }) |
| 94 | console.log("TBA:", tba) |
| 95 | |
| 96 | // equip NPC via TBA |
| 97 | // |
| 98 | const fundNpcTx = await operatorContract.fundNPC(tba, 20) |
| 99 | const fundNpxTxReceipt = await fundNpcTx.wait() |
| 100 | console.log("NPC Funded") |
| 101 | |
| 102 | const feedNpcTx = await operatorContract.feedNPC(tba, 5) |
| 103 | const feedNpcTxReceipt = await feedNpcTx.wait() |
| 104 | console.log("NPC Fed") |
| 105 | |
| 106 | const supplyNpcTx = await operatorContract.supplyNPC(tba, 5) |
| 107 | const supplyNpcTxReceipt = await supplyNpcTx.wait() |
| 108 | console.log("NPC Supplied") |
| 109 | |
| 110 | } */ |
| 111 | } |
| 112 | |
| 113 | Main() |
| 114 | |