Merge branch 'upgrades' abb22f5e
Steve · 2023-10-17 20:44 4 file(s) · +64 −8
contracts/GoldenCorn.sol +43 −0
6 6
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
7 7
8 8
contract GoldenCorn is ERC20, Ownable, ERC20Permit {
9 +
    mapping(address => bool) private _whitelist;
10 +
9 11
    constructor(
10 12
        address initialOwner
11 13
    )
17 19
    function mint(address to, uint256 amount) public onlyOwner {
18 20
        uint256 mintAmount = amount * (10 ** decimals());
19 21
        _mint(to, mintAmount);
22 +
    }
23 +
24 +
    // Override the transfer function
25 +
    function transfer(
26 +
        address recipient,
27 +
        uint256 amount
28 +
    ) public override returns (bool) {
29 +
        require(
30 +
            _whitelist[msg.sender],
31 +
            "Only whitelisted addresses can initiate transfers"
32 +
        );
33 +
        _transfer(_msgSender(), recipient, amount);
34 +
        return true;
35 +
    }
36 +
37 +
    // Override the transferFrom function
38 +
    function transferFrom(
39 +
        address sender,
40 +
        address recipient,
41 +
        uint256 amount
42 +
    ) public override returns (bool) {
43 +
        require(
44 +
            _whitelist[sender],
45 +
            "Only whitelisted addresses can initiate transfers"
46 +
        );
47 +
        _transfer(sender, recipient, amount);
48 +
        _approve(
49 +
            sender,
50 +
            _msgSender(),
51 +
            allowance(sender, _msgSender()) - amount
52 +
        );
53 +
        return true;
54 +
    }
55 +
56 +
    // Add a function to add or remove addresses from the whitelist
57 +
    function setWhitelisted(address account, bool value) external {
58 +
        require(
59 +
            msg.sender == owner(),
60 +
            "Only the owner can modify the whitelist"
61 +
        );
62 +
        _whitelist[account] = value;
20 63
    }
21 64
}
contracts/Operator.sol +9 −0
87 87
88 88
        goldenCorn.mint(tba, 5);
89 89
    }
90 +
91 +
    function whitelist(address tba, bool status) public onlyOwner {
92 +
        goldenCorn.setWhitelisted(tba, status);
93 +
    }
94 +
95 +
    function withdraw() public onlyOwner {
96 +
        uint256 balance = address(this).balance;
97 +
        payable(owner()).transfer(balance);
98 +
    }
90 99
}
hardhat.config.js +1 −1
15 15
  networks: {
16 16
    goerli: {
17 17
      url: `${process.env.ALCHEMY_URL}`,
18 -
      accounts: [process.env.PRIVATE_KEY],
18 +
      accounts: [process.env.TEST_PRIVATE_KEY],
19 19
      gasPrice: 1500000000,
20 20
21 21
    },
test/Test.js +11 −7
75 75
  console.log("TBA:", tba)
76 76
77 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")
82 78
83 -
  const feedNpcTx = await operatorContract.feedNPC(tba, 5)
79 +
  /* const feedNpcTx = await operatorContract.feedNPC(tba, 5)
84 80
  const feedNpcTxReceipt = await feedNpcTx.wait()
85 -
  console.log("NPC Fed")
81 +
  console.log("NPC Fed") */
86 82
87 -
  const supplyNpcTx = await operatorContract.supplyNPC(tba, 5)
83 +
  const whitelistNpcTx = await operatorContract.whitelist(tba, true)
84 +
  const whitelistNpcTxReceipt = await whitelistNpcTx.wait()
85 +
  console.log("NPC Whitelisted")
86 +
87 +
  const fundNpcTx = await operatorContract.fundNPC(tba, 20)
88 +
  const fundNpxTxReceipt = await fundNpcTx.wait()
89 +
  console.log("NPC Funded")
90 +
91 +
  /* const supplyNpcTx = await operatorContract.supplyNPC(tba, 5)
88 92
  const supplyNpcTxReceipt = await supplyNpcTx.wait()
89 93
  console.log("NPC Supplied") */
90 94