added function and deployed 7f3c950d
Steve · 2023-10-16 21:43 4 file(s) · +54 −47
contracts/Operator.sol +8 −2
16 16
    JupiterJunk public jupiterJunk;
17 17
18 18
    uint256 public newTokenId;
19 +
    uint256 public constant donationAmount = 10 ** 15;
19 20
20 21
    constructor(
21 22
        address initialOwner,
78 79
        cosmicCowboys.setHealth(tokenId, newHealth);
79 80
    }
80 81
81 -
    function getOwner() external view returns (address) {
82 -
        return owner();
82 +
    function donate(address tba) external payable {
83 +
        require(
84 +
            msg.value == donationAmount,
85 +
            "Donation amount must be exactly 0.001 Ether"
86 +
        );
87 +
88 +
        goldenCorn.mint(tba, 5);
83 89
    }
84 90
}
hardhat.config.js +6 −4
16 16
    goerli: {
17 17
      url: `${process.env.ALCHEMY_URL}`,
18 18
      accounts: [process.env.PRIVATE_KEY],
19 +
      gasPrice: 1500000000,
20 +
19 21
    },
20 22
    scrollSepolia: {
21 23
      url: "https://sepolia-rpc.scroll.io/" || "",
36 38
      accounts: [process.env.PRIVATE_KEY],
37 39
    }
38 40
  },
39 -
  /* etherscan: {
40 -
    apiKey: process.env.ETHERSCAN_API_KEY
41 -
  }, */
42 41
  etherscan: {
42 +
    apiKey: process.env.ETHERSCAN_API_KEY
43 +
  },
44 +
  /* etherscan: {
43 45
    apiKey: {
44 46
      "base-goerli": "PLACEHOLDER_STRING"
45 47
    },
53 55
        }
54 56
      }
55 57
    ]
56 -
  },
58 +
  }, */
57 59
58 60
};
scripts/deployContracts.js +1 −1
58 58
  await foodContract.transferOwnership(operatorContractAddress);
59 59
  await supplyContract.transferOwnership(operatorContractAddress);
60 60
61 -
  for (let i = 0; i < 19; i++) {
61 +
  for (let i = 0; i < 20; i++) {
62 62
    // create NPC
63 63
    const npcTx = await operatorContract.createNPC(wallet.address, `ipfs://QmQbwCMwDETHHZ1g8YaSHqLBwCRgVHqFuRNRfiGyNqCcXj/${i}.json`)
64 64
    const npcTxReceipt = await npcTx.wait()
test/Test.js +39 −40
1 1
// Import the ethers library
2 2
const { ethers } = require("hardhat");
3 -
const { TokenboundClient } = require("@tokenbound/sdk");
4 3
const provider = new ethers.AlchemyProvider("goerli", process.env.ALCHEMY_KEY)
5 -
const operatorAbi = require("../artifacts/contracts/Operator.sol/Operator.json")
4 +
const { TokenboundClient } = require("@tokenbound/sdk");
6 5
6 +
async function Main() {
7 7
8 -
async function Operator() {
9 8
10 9
  // 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}`)
10 +
  const wallet = new ethers.Wallet(process.env.TEST_PRIVATE_KEY, provider)
16 11
  const tokenboundClient = new TokenboundClient({ signer: wallet, chainId: 5 })
12 +
  console.log(`SERVER_WALLET_PRIVATE_KEY=${process.env.TEST_PRIVATE_KEY}`)
13 +
  console.log(`SERVER_WALLET_ADDRESS=${wallet.address}`)
17 14
18 15
  // Deploy NPC contract
19 16
  const NPCContract = await ethers.getContractFactory("CosmicCowboys");
20 -
  const npcContract = await NPCContract.deploy(owner.address);
17 +
  const npcContract = await NPCContract.deploy(wallet.address);
21 18
  const npcContractAddress = await npcContract.getAddress()
22 19
  console.log(`NPC_CONTRACT_ADDRESS=${npcContractAddress}`);
23 20
24 21
  // Deploy ERC-20 Contract
25 22
  const CurrencyContract = await ethers.getContractFactory("GoldenCorn");
26 -
  const currencyContract = await CurrencyContract.deploy(owner.address);
23 +
  const currencyContract = await CurrencyContract.deploy(wallet.address);
27 24
  const currencyContractAddress = await currencyContract.getAddress()
28 25
  console.log(`CURRENCY_CONTRACT_ADDRESS=${currencyContractAddress}`)
29 26
30 27
  // Deploy 1155 Contracts
31 28
  const FoodContract = await ethers.getContractFactory("SpaceSlop");
32 -
  const foodContract = await FoodContract.deploy(owner.address);
29 +
  const foodContract = await FoodContract.deploy(wallet.address);
33 30
  const foodContractAddress = await foodContract.getAddress()
34 31
  console.log(`FOOD_CONTRACT_ADDRESS=${foodContractAddress}`);
35 32
36 33
  const SupplyContract = await ethers.getContractFactory("JupiterJunk");
37 -
  const supplyContract = await SupplyContract.deploy(owner.address);
34 +
  const supplyContract = await SupplyContract.deploy(wallet.address);
38 35
  const supplyContractAddress = await supplyContract.getAddress()
39 36
  console.log(`SUPPLY_CONTRACT_ADDRESS=${supplyContractAddress}`);
40 37
51 48
52 49
  // Deploy Operator Contract
53 50
  const OperatorContract = await ethers.getContractFactory("Operator");
54 -
  const operatorContract = await OperatorContract.deploy(owner.address, npcContractAddress, currencyContractAddress, foodContractAddress, supplyContractAddress)
51 +
  const operatorContract = await OperatorContract.deploy(wallet.address, npcContractAddress, currencyContractAddress, foodContractAddress, supplyContractAddress)
55 52
  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" */
53 +
  console.log(`OPERATOR_CONTRACT_ADDRESS=${operatorContractAddress}`)
60 54
61 55
  // Transfer NPC contract to Operator
62 56
  await npcContract.transferOwnership(operatorContractAddress);
63 57
  await currencyContract.transferOwnership(operatorContractAddress);
64 58
  await foodContract.transferOwnership(operatorContractAddress);
65 59
  await supplyContract.transferOwnership(operatorContractAddress);
60 +
  console.log("ownership transferred")
66 61
67 -
  const npcTx = await operatorContract.createNPC(owner.address, `ipfs://QmQbwCMwDETHHZ1g8YaSHqLBwCRgVHqFuRNRfiGyNqCcXj/1.json`)
62 +
  // create NPC
63 +
  const npcTx = await operatorContract.createNPC(wallet.address, `ipfs://QmQbwCMwDETHHZ1g8YaSHqLBwCRgVHqFuRNRfiGyNqCcXj/0.json`)
68 64
  const npcTxReceipt = await npcTx.wait()
69 -
  console.log("NFT Minted")
65 +
  console.log("NPC Created")
70 66
71 -
  const stats = await operatorContract.getNPCStats(0)
72 -
  console.log(stats)
67 +
  // After the NPC is created
68 +
  const latestTokenId = await operatorContract.getLatestTokenId();
73 69
70 +
  // create TBA for NPC
71 +
  const tba = await tokenboundClient.createAccount({
72 +
    tokenContract: npcContractAddress,
73 +
    tokenId: latestTokenId,
74 +
  })
75 +
  console.log("TBA:", tba)
74 76
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")
77 +
  // equip NPC via TBA
78 +
  //
79 +
  /* const fundNpcTx = await operatorContract.fundNPC(tba, 20)
80 +
  const fundNpxTxReceipt = await fundNpcTx.wait()
81 +
  console.log("NPC Funded")
80 82
81 -
    // After the NPC is created
82 -
    const latestTokenId = await operatorContract.getLatestTokenId();
83 +
  const feedNpcTx = await operatorContract.feedNPC(tba, 5)
84 +
  const feedNpcTxReceipt = await feedNpcTx.wait()
85 +
  console.log("NPC Fed")
83 86
84 -
    // create TBA for NPC
85 -
    const tba = await tokenboundClient.createAccount({
86 -
      tokenContract: npcContractAddress,
87 -
      tokenId: latestTokenId,
88 -
    })
89 -
    console.log("TBA:", tba)
87 +
  const supplyNpcTx = await operatorContract.supplyNPC(tba, 5)
88 +
  const supplyNpcTxReceipt = await supplyNpcTx.wait()
89 +
  console.log("NPC Supplied") */
90 90
91 -
    // equip NPC via TBA
91 +
  const donationAmount = ethers.parseEther("0.001")
92 +
  const donateNpcTx = await operatorContract.donate(tba, { value: donationAmount })
93 +
  const donateNpcTxReceipt = await donateNpcTx.wait()
94 +
  console.log("NPC Donated")
92 95
93 -
    const equipTx = await operatorContract.equipNPC(tba, 20, 5, 5)
94 -
    const equipTxReceipt = await equipTx.wait()
95 -
    console.log("NPC Equipped")
96 -
  } */
97 96
}
98 97
99 -
Operator()
98 +
Main()