added base e6994c0c
Steve · 2023-10-16 19:43 10 file(s) · +69 −131
contracts/CosmicCowboy.sol +4 −36
1 1
// SPDX-License-Identifier: MIT
2 -
pragma solidity ^0.8.0;
2 +
pragma solidity ^0.8.20;
3 3
4 4
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
5 +
import "@openzeppelin/contracts/access/Ownable.sol";
5 6
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
6 -
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
7 -
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
8 -
import "@openzeppelin/contracts/access/Ownable.sol";
9 7
import "@openzeppelin/contracts/utils/Strings.sol";
10 8
11 -
contract CosmicCowboys is
12 -
    ERC721,
13 -
    ERC721Enumerable,
14 -
    ERC721URIStorage,
15 -
    ERC721Burnable,
16 -
    Ownable
17 -
{
9 +
contract CosmicCowboys is ERC721, Ownable, ERC721URIStorage {
18 10
    uint256 private _nextTokenId;
19 11
    uint256 public latestTokenId;
20 12
    enum Location {
91 83
92 84
    // The following functions are overrides required by Solidity.
93 85
94 -
    function _update(
95 -
        address to,
96 -
        uint256 tokenId,
97 -
        address auth
98 -
    ) internal override(ERC721, ERC721Enumerable) returns (address) {
99 -
        return super._update(to, tokenId, auth);
100 -
    }
101 -
102 -
    function _increaseBalance(
103 -
        address account,
104 -
        uint128 value
105 -
    ) internal override(ERC721, ERC721Enumerable) {
106 -
        super._increaseBalance(account, value);
107 -
    }
108 -
109 86
    function tokenURI(
110 87
        uint256 tokenId
111 88
    ) public view override(ERC721, ERC721URIStorage) returns (string memory) {
114 91
115 92
    function supportsInterface(
116 93
        bytes4 interfaceId
117 -
    )
118 -
        public
119 -
        view
120 -
        override(ERC721, ERC721Enumerable, ERC721URIStorage)
121 -
        returns (bool)
122 -
    {
94 +
    ) public view override(ERC721, ERC721URIStorage) returns (bool) {
123 95
        return super.supportsInterface(interfaceId);
124 -
    }
125 -
126 -
    function getOwner() external view returns (address) {
127 -
        return owner();
128 96
    }
129 97
}
contracts/GoldenCorn.sol +2 −28
1 1
// SPDX-License-Identifier: MIT
2 -
pragma solidity ^0.8.0;
2 +
pragma solidity ^0.8.20;
3 3
4 4
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5 -
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
6 -
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
7 5
import "@openzeppelin/contracts/access/Ownable.sol";
8 6
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
9 7
10 -
contract GoldenCorn is
11 -
    ERC20,
12 -
    ERC20Burnable,
13 -
    ERC20Pausable,
14 -
    Ownable,
15 -
    ERC20Permit
16 -
{
8 +
contract GoldenCorn is ERC20, Ownable, ERC20Permit {
17 9
    constructor(
18 10
        address initialOwner
19 11
    )
22 14
        ERC20Permit("GoldenCorn")
23 15
    {}
24 16
25 -
    function pause() public onlyOwner {
26 -
        _pause();
27 -
    }
28 -
29 -
    function unpause() public onlyOwner {
30 -
        _unpause();
31 -
    }
32 -
33 17
    function mint(address to, uint256 amount) public onlyOwner {
34 18
        uint256 mintAmount = amount * (10 ** decimals());
35 19
        _mint(to, mintAmount);
36 -
    }
37 -
38 -
    // The following functions are overrides required by Solidity.
39 -
40 -
    function _update(
41 -
        address from,
42 -
        address to,
43 -
        uint256 value
44 -
    ) internal override(ERC20, ERC20Pausable) {
45 -
        super._update(from, to, value);
46 20
    }
47 21
}
contracts/JupiterJunk.sol +2 −15
1 1
// SPDX-License-Identifier: MIT
2 -
pragma solidity ^0.8.0;
2 +
pragma solidity ^0.8.20;
3 3
4 4
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
5 5
import "@openzeppelin/contracts/access/Ownable.sol";
6 -
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
7 -
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
8 6
9 -
contract JupiterJunk is ERC1155, Ownable, ERC1155Burnable, ERC1155Supply {
7 +
contract JupiterJunk is ERC1155, Ownable {
10 8
    constructor(
11 9
        address initialOwner
12 10
    )
29 27
        bytes memory data
30 28
    ) public onlyOwner {
31 29
        _mintBatch(to, ids, amounts, data);
32 -
    }
33 -
34 -
    // The following functions are overrides required by Solidity.
35 -
36 -
    function _update(
37 -
        address from,
38 -
        address to,
39 -
        uint256[] memory ids,
40 -
        uint256[] memory values
41 -
    ) internal override(ERC1155, ERC1155Supply) {
42 -
        super._update(from, to, ids, values);
43 30
    }
44 31
}
contracts/Operator.sol +1 −1
1 1
// SPDX-License-Identifier: MIT
2 -
pragma solidity ^0.8.0;
2 +
pragma solidity ^0.8.20;
3 3
4 4
import "@openzeppelin/contracts/access/Ownable.sol";
5 5
import "./CosmicCowboy.sol";
contracts/SpaceSlop.sol +2 −15
1 1
// SPDX-License-Identifier: MIT
2 -
pragma solidity ^0.8.0;
2 +
pragma solidity ^0.8.20;
3 3
4 4
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
5 5
import "@openzeppelin/contracts/access/Ownable.sol";
6 -
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
7 -
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
8 6
9 -
contract SpaceSlop is ERC1155, Ownable, ERC1155Burnable, ERC1155Supply {
7 +
contract SpaceSlop is ERC1155, Ownable {
10 8
    constructor(
11 9
        address initialOwner
12 10
    )
29 27
        bytes memory data
30 28
    ) public onlyOwner {
31 29
        _mintBatch(to, ids, amounts, data);
32 -
    }
33 -
34 -
    // The following functions are overrides required by Solidity.
35 -
36 -
    function _update(
37 -
        address from,
38 -
        address to,
39 -
        uint256[] memory ids,
40 -
        uint256[] memory values
41 -
    ) internal override(ERC1155, ERC1155Supply) {
42 -
        super._update(from, to, ids, values);
43 30
    }
44 31
}
hardhat.config.js +16 −6
3 3
4 4
/** @type import('hardhat/config').HardhatUserConfig */
5 5
module.exports = {
6 -
  solidity: "0.8.20",
6 +
  solidity: {
7 +
    version: "0.8.20",
8 +
    settings: {
9 +
      optimizer: {
10 +
        enabled: true,
11 +
        runs: 10000
12 +
      }
13 +
    }
14 +
  },
7 15
  networks: {
8 16
    goerli: {
9 17
      url: `${process.env.ALCHEMY_URL}`,
19 27
    'base-goerli': {
20 28
      url: `${process.env.ALCHEMY_URL_BASE}`,
21 29
      accounts: [process.env.PRIVATE_KEY],
22 -
      gasPrice: 1000000000,
30 +
      gasPrice: 1500000000,
31 +
      allowUnlimitedContractSize: true,
32 +
23 33
    },
24 34
    sepolia: {
25 35
      url: `${process.env.SEPOLIA_URL}`,
27 37
    }
28 38
  },
29 39
  /* etherscan: {
40 +
    apiKey: process.env.ETHERSCAN_API_KEY
41 +
  }, */
42 +
  etherscan: {
30 43
    apiKey: {
31 44
      "base-goerli": "PLACEHOLDER_STRING"
32 45
    },
40 53
        }
41 54
      }
42 55
    ]
43 -
  }, */
44 -
  etherscan: {
45 -
    apiKey: process.env.ETHERSCAN_API_KEY
46 -
  }
56 +
  },
47 57
48 58
};
package-lock.json +5 −4
10 10
        "@tokenbound/sdk": "^0.3.12",
11 11
        "axios": "^1.5.1",
12 12
        "dotenv": "^16.3.1",
13 -
        "ethers": "^6.7.1"
13 +
        "ethers": "^6.7.1",
14 +
        "viem": "^1.16.5"
14 15
      },
15 16
      "devDependencies": {
16 17
        "@nomicfoundation/hardhat-toolbox": "^3.0.0",
7124 7125
      "peer": true
7125 7126
    },
7126 7127
    "node_modules/viem": {
7127 -
      "version": "1.16.2",
7128 -
      "resolved": "https://registry.npmjs.org/viem/-/viem-1.16.2.tgz",
7129 -
      "integrity": "sha512-ZQ8kemNvRVwucwcsj4/SjKohK+wZv9Vxx/gXAlwqGMCW7r+niOeECtFku/1L7UPTmPgdmq4kic9R71t6XQDmGw==",
7128 +
      "version": "1.16.5",
7129 +
      "resolved": "https://registry.npmjs.org/viem/-/viem-1.16.5.tgz",
7130 +
      "integrity": "sha512-D8aE6cp/5w6PDtOOkJjkN+FtLyfsNWkfE78N4yTgCt4BG7KsBsePp4O68r1IaTVTVa41anebiZAy9kNEIwAXiw==",
7130 7131
      "funding": [
7131 7132
        {
7132 7133
          "type": "github",
package.json +2 −1
11 11
    "@tokenbound/sdk": "^0.3.12",
12 12
    "axios": "^1.5.1",
13 13
    "dotenv": "^16.3.1",
14 -
    "ethers": "^6.7.1"
14 +
    "ethers": "^6.7.1",
15 +
    "viem": "^1.16.5"
15 16
  }
16 17
}
scripts/deployContractsBase.js +34 −23
2 2
const { ethers } = require("hardhat");
3 3
const provider = new ethers.JsonRpcProvider(process.env.ALCHEMY_URL_BASE)
4 4
const { TokenboundClient } = require("@tokenbound/sdk");
5 -
function wait(ms) {
6 -
  return new Promise(resolve => setTimeout(resolve, ms));
7 -
}
5 +
const { createWalletClient, http } = require('viem')
6 +
const { privateKeyToAccount } = require('viem/accounts')
7 +
const { baseGoerli } = require('viem/chains')
8 +
const registryContractAddress = "0xae470391D4dee2ca9CA33192e1865b45F47F3527"
9 +
const accountContractAddress = "0xF4df15ED8002BDB96F263702CeeB94f5FCB28aBc"
10 +
11 +
const account = privateKeyToAccount(`0x` + process.env.PRIVATE_KEY)
8 12
13 +
const walletClient = createWalletClient({
14 +
  account,
15 +
  chain: baseGoerli,
16 +
  transport: http(process.env.ALCHEMY_URL_BASE)
17 +
})
9 18
10 19
async function Operator() {
11 20
12 -
21 +
  const network = await provider.getNetwork()
22 +
  const chainId = network.chainId
23 +
  console.log(chainId)
13 24
  // Get the signers from ethers
14 25
  const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider)
15 -
  const tokenboundClient = new TokenboundClient({ signer: wallet, chainId: 84531 })
16 26
  console.log(`SERVER_WALLET_PRIVATE_KEY=${process.env.PRIVATE_KEY}`)
17 27
  console.log(`SERVER_WALLET_ADDRESS=${wallet.address}`)
18 28
39 49
  const supplyContractAddress = await supplyContract.getAddress()
40 50
  console.log(`SUPPLY_CONTRACT_ADDRESS=${supplyContractAddress}`);
41 51
42 -
  // Deploy ERC6551
43 -
  /* const RegistryContract = await ethers.getContractFactory("ERC6551Registry");
52 +
  /* // Deploy ERC6551
53 +
  const RegistryContract = await ethers.getContractFactory("ERC6551Registry");
44 54
  const registryContract = await RegistryContract.deploy();
45 55
  const registryContractAddress = await registryContract.getAddress()
46 56
  console.log("Registry Contract deployed to address:", registryContractAddress);
62 72
  await foodContract.transferOwnership(operatorContractAddress);
63 73
  await supplyContract.transferOwnership(operatorContractAddress);
64 74
65 -
  for (let i = 0; i < 2; i++) {
75 +
  const tokenboundClient = new TokenboundClient({
76 +
    walletClient: walletClient,
77 +
    chain: baseGoerli,
78 +
    implementationAddress: accountContractAddress,
79 +
    registryAddress: registryContractAddress,
80 +
  })
81 +
82 +
  for (let i = 0; i < 20; i++) {
66 83
    // create NPC
67 84
    const npcTx = await operatorContract.createNPC(wallet.address, `ipfs://QmQbwCMwDETHHZ1g8YaSHqLBwCRgVHqFuRNRfiGyNqCcXj/${i}.json`)
68 85
    const npcTxReceipt = await npcTx.wait()
69 86
    console.log("NPC Created")
70 -
    wait(2000)
71 87
72 88
    // After the NPC is created
73 89
    const latestTokenId = await operatorContract.getLatestTokenId();
78 94
      tokenId: latestTokenId,
79 95
    })
80 96
    console.log("TBA:", tba)
81 -
    wait(4000)
82 97
83 98
    // equip NPC via TBA
99 +
    const fundNpcTx = await operatorContract.fundNPC(tba, 20)
100 +
    const fundNpxTxReceipt = await fundNpcTx.wait()
101 +
    console.log("NPC Funded")
84 102
85 -
    /* const fundTx = await operatorContract.fundNPC(tba, 20)
86 -
    const fundTxReceipt = await fundTx.wait()
87 -
    console.log("NPC Funded") */
88 -
    const giveFoodTx = await operatorContract.giveFood(tba, 1)
89 -
    const giveFoodTxReceipt = await giveFoodTx.wait()
103 +
    const feedNpcTx = await operatorContract.feedNPC(tba, 5)
104 +
    const feedNpcTxReceipt = await feedNpcTx.wait()
90 105
    console.log("NPC Fed")
91 -
    /* const giveSupplyTx = await operatorContract.supplyNPC(tba, 5)
92 -
    const giveSupplyTxReceipt = await giveSupplyTx.wait()
93 -
    console.log("NPC Supplied") */
94 106
95 -
    /* const equipTx = await operatorContract.equipNPC(tba, 20, 5, 5)
96 -
    const equipTxReceipt = await equipTx.wait()
97 -
    console.log("NPC Equipped") */
107 +
    const supplyNpcTx = await operatorContract.supplyNPC(tba, 5)
108 +
    const supplyNpcTxReceipt = await supplyNpcTx.wait()
109 +
    console.log("NPC Supplied")
110 +
98 111
  }
99 -
100 -
101 112
}
102 113
103 114
Operator()
scripts/deployContractsSepolia.js +1 −2
9 9
  // Get the signers from ethers
10 10
  const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider)
11 11
  const tokenboundClient = new TokenboundClient({ signer: wallet, chainId: 11155111 })
12 -
  console.log(`SERVER_WALLET_PRIVATE_KEY=${process.env.PRIVATE_KEY}`)
13 -
  console.log(`SERVER_WALLET_ADDRESS=${wallet.address}`)
12 +
  console.log(`SERVER_WALLET_PRIVATE_KEY=${process.env.PRIVATE_KEY}`) console.log(`SERVER_WALLET_ADDRESS=${wallet.address}`)
14 13
15 14
  // Deploy NPC contract
16 15
  const NPCContract = await ethers.getContractFactory("CosmicCowboys");