From 4846b9a77dee1f4fc46ea82c891b29dcabf4fb0f Mon Sep 17 00:00:00 2001 From: jacksmithinsulander <666.jack.smith@protonmail.com> Date: Fri, 12 Jul 2024 21:27:23 +0200 Subject: [PATCH 01/11] initial commit for contracts --- packages/foundry/.env.example | 3 - packages/foundry/.github/workflows/test.yml | 34 ++++ packages/foundry/.gitignore | 2 +- packages/foundry/.gitmodules | 3 + packages/foundry/.prettier.json | 6 - packages/foundry/README.md | 66 ++++++++ packages/foundry/contracts/YourContract.sol | 84 ---------- packages/foundry/deployments/.gitignore | 2 - packages/foundry/foundry.toml | 46 +----- packages/foundry/lib/openzeppelin-contracts | 1 - packages/foundry/lib/solidity-bytes-utils | 1 - packages/foundry/package.json | 30 ---- packages/foundry/remappings.txt | 1 - packages/foundry/script/Counter.s.sol | 19 +++ packages/foundry/script/Deploy.s.sol | 37 ----- packages/foundry/script/DeployHelpers.s.sol | 78 --------- packages/foundry/script/ListAccount.js | 77 --------- packages/foundry/script/VerifyAll.s.sol | 133 ---------------- packages/foundry/script/generateAccount.js | 49 ------ packages/foundry/script/generateTsAbis.js | 148 ------------------ packages/foundry/src/Notes.sol | 36 +++++ .../foundry/src/libraries/CNDataTypes.sol | 29 ++++ packages/foundry/test/Counter.t.sol | 24 +++ packages/foundry/test/YourContract.t.sol | 28 ---- 24 files changed, 216 insertions(+), 721 deletions(-) delete mode 100644 packages/foundry/.env.example create mode 100644 packages/foundry/.github/workflows/test.yml create mode 100644 packages/foundry/.gitmodules delete mode 100644 packages/foundry/.prettier.json create mode 100644 packages/foundry/README.md delete mode 100644 packages/foundry/contracts/YourContract.sol delete mode 100644 packages/foundry/deployments/.gitignore delete mode 160000 packages/foundry/lib/openzeppelin-contracts delete mode 160000 packages/foundry/lib/solidity-bytes-utils delete mode 100644 packages/foundry/package.json delete mode 100644 packages/foundry/remappings.txt create mode 100644 packages/foundry/script/Counter.s.sol delete mode 100644 packages/foundry/script/Deploy.s.sol delete mode 100644 packages/foundry/script/DeployHelpers.s.sol delete mode 100644 packages/foundry/script/ListAccount.js delete mode 100644 packages/foundry/script/VerifyAll.s.sol delete mode 100644 packages/foundry/script/generateAccount.js delete mode 100644 packages/foundry/script/generateTsAbis.js create mode 100644 packages/foundry/src/Notes.sol create mode 100644 packages/foundry/src/libraries/CNDataTypes.sol create mode 100644 packages/foundry/test/Counter.t.sol delete mode 100644 packages/foundry/test/YourContract.t.sol diff --git a/packages/foundry/.env.example b/packages/foundry/.env.example deleted file mode 100644 index 7fe93e3..0000000 --- a/packages/foundry/.env.example +++ /dev/null @@ -1,3 +0,0 @@ -DEPLOYER_PRIVATE_KEY= -ETHERSCAN_API_KEY= -ALCHEMY_API_KEY= \ No newline at end of file diff --git a/packages/foundry/.github/workflows/test.yml b/packages/foundry/.github/workflows/test.yml new file mode 100644 index 0000000..9282e82 --- /dev/null +++ b/packages/foundry/.github/workflows/test.yml @@ -0,0 +1,34 @@ +name: test + +on: workflow_dispatch + +env: + FOUNDRY_PROFILE: ci + +jobs: + check: + strategy: + fail-fast: true + + name: Foundry project + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Run Forge build + run: | + forge --version + forge build --sizes + id: build + + - name: Run Forge tests + run: | + forge test -vvv + id: test diff --git a/packages/foundry/.gitignore b/packages/foundry/.gitignore index 88f95b6..85198aa 100644 --- a/packages/foundry/.gitignore +++ b/packages/foundry/.gitignore @@ -3,6 +3,7 @@ cache/ out/ # Ignores development broadcast logs +!/broadcast /broadcast/*/31337/ /broadcast/**/dry-run/ @@ -11,4 +12,3 @@ docs/ # Dotenv file .env -localhost.json diff --git a/packages/foundry/.gitmodules b/packages/foundry/.gitmodules new file mode 100644 index 0000000..888d42d --- /dev/null +++ b/packages/foundry/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/forge-std"] + path = lib/forge-std + url = https://github.com/foundry-rs/forge-std diff --git a/packages/foundry/.prettier.json b/packages/foundry/.prettier.json deleted file mode 100644 index 7eef1ab..0000000 --- a/packages/foundry/.prettier.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "arrowParens": "avoid", - "printWidth": 120, - "tabWidth": 2, - "trailingComma": "all" -} diff --git a/packages/foundry/README.md b/packages/foundry/README.md new file mode 100644 index 0000000..9265b45 --- /dev/null +++ b/packages/foundry/README.md @@ -0,0 +1,66 @@ +## Foundry + +**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** + +Foundry consists of: + +- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). +- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. +- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. +- **Chisel**: Fast, utilitarian, and verbose solidity REPL. + +## Documentation + +https://book.getfoundry.sh/ + +## Usage + +### Build + +```shell +$ forge build +``` + +### Test + +```shell +$ forge test +``` + +### Format + +```shell +$ forge fmt +``` + +### Gas Snapshots + +```shell +$ forge snapshot +``` + +### Anvil + +```shell +$ anvil +``` + +### Deploy + +```shell +$ forge script script/Counter.s.sol:CounterScript --rpc-url --private-key +``` + +### Cast + +```shell +$ cast +``` + +### Help + +```shell +$ forge --help +$ anvil --help +$ cast --help +``` diff --git a/packages/foundry/contracts/YourContract.sol b/packages/foundry/contracts/YourContract.sol deleted file mode 100644 index 3142774..0000000 --- a/packages/foundry/contracts/YourContract.sol +++ /dev/null @@ -1,84 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity >=0.8.0 <0.9.0; - -// Useful for debugging. Remove when deploying to a live network. -import "forge-std/console.sol"; - -// Use openzeppelin to inherit battle-tested implementations (ERC20, ERC721, etc) -// import "@openzeppelin/contracts/access/Ownable.sol"; - -/** - * A smart contract that allows changing a state variable of the contract and tracking the changes - * It also allows the owner to withdraw the Ether in the contract - * @author BuidlGuidl - */ -contract YourContract { - // State Variables - address public immutable owner; - string public greeting = "Building Unstoppable Apps!!!"; - bool public premium = false; - uint256 public totalCounter = 0; - mapping(address => uint256) public userGreetingCounter; - - // Events: a way to emit log statements from smart contract that can be listened to by external parties - event GreetingChange( - address indexed greetingSetter, - string newGreeting, - bool premium, - uint256 value - ); - - // Constructor: Called once on contract deployment - // Check packages/foundry/deploy/Deploy.s.sol - constructor(address _owner) { - owner = _owner; - } - - // Modifier: used to define a set of rules that must be met before or after a function is executed - // Check the withdraw() function - modifier isOwner() { - // msg.sender: predefined variable that represents address of the account that called the current function - require(msg.sender == owner, "Not the Owner"); - _; - } - - /** - * Function that allows anyone to change the state variable "greeting" of the contract and increase the counters - * - * @param _newGreeting (string memory) - new greeting to save on the contract - */ - function setGreeting(string memory _newGreeting) public payable { - // Print data to the anvil chain console. Remove when deploying to a live network. - - console.logString("Setting new greeting"); - console.logString(_newGreeting); - - greeting = _newGreeting; - totalCounter += 1; - userGreetingCounter[msg.sender] += 1; - - // msg.value: built-in global variable that represents the amount of ether sent with the transaction - if (msg.value > 0) { - premium = true; - } else { - premium = false; - } - - // emit: keyword used to trigger an event - emit GreetingChange(msg.sender, _newGreeting, msg.value > 0, msg.value); - } - - /** - * Function that allows the owner to withdraw all the Ether in the contract - * The function can only be called by the owner of the contract as defined by the isOwner modifier - */ - function withdraw() public isOwner { - (bool success,) = owner.call{ value: address(this).balance }(""); - require(success, "Failed to send Ether"); - } - - /** - * Function that allows the contract to receive ETH - */ - receive() external payable { } -} diff --git a/packages/foundry/deployments/.gitignore b/packages/foundry/deployments/.gitignore deleted file mode 100644 index e308ae9..0000000 --- a/packages/foundry/deployments/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore 31337 deployments -31337.json diff --git a/packages/foundry/foundry.toml b/packages/foundry/foundry.toml index feee8aa..25b918f 100644 --- a/packages/foundry/foundry.toml +++ b/packages/foundry/foundry.toml @@ -1,44 +1,6 @@ [profile.default] -src = 'contracts' -out = 'out' -libs = ['lib'] -fs_permissions = [{ access = "read-write", path = "./"}] +src = "src" +out = "out" +libs = ["lib"] -[rpc_endpoints] -default_network = "http://127.0.0.1:8545" -localhost = "http://127.0.0.1:8545" - -mainnet = "https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_API_KEY}" -sepolia = "https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -arbitrum = "https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -arbitrumSepolia = "https://arb-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -optimism = "https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -optimismSepolia = "https://opt-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -polygon = "https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -polygonMumbai = "https://polygon-mumbai.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -gnosis = "https://rpc.gnosischain.com" -chiado = "https://rpc.chiadochain.net" -base = "https://mainnet.base.org" -baseGoerli = "https://goerli.base.org" -baseSepolia = "https://sepolia.base.org" -polygonZkEvm = "https://polygonzkevm-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -polygonZkEvmTestnet = "https://polygonzkevm-testnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -zkSyncTestnet = "https://testnet.era.zksync.dev" -zkSync = "https://mainnet.era.zksync.io" -scrollSepolia = "https://sepolia-rpc.scroll.io" -scroll = "https://rpc.scroll.io" - -[etherscan] -polygonMumbai = { key = "${ETHERSCAN_API_KEY}" } -sepolia = { key = "${ETHERSCAN_API_KEY}" } - - -[fmt] -multiline_func_header = "params_first" -line_length = 80 -tab_width = 2 -quote_style = "double" -bracket_spacing = true -int_types = "long" - -# See more config options https://github.com/foundry-rs/foundry/tree/master/config +# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/packages/foundry/lib/openzeppelin-contracts b/packages/foundry/lib/openzeppelin-contracts deleted file mode 160000 index dbb6104..0000000 --- a/packages/foundry/lib/openzeppelin-contracts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dbb6104ce834628e473d2173bbc9d47f81a9eec3 diff --git a/packages/foundry/lib/solidity-bytes-utils b/packages/foundry/lib/solidity-bytes-utils deleted file mode 160000 index e0115c4..0000000 --- a/packages/foundry/lib/solidity-bytes-utils +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e0115c4d231910df47ce3b60625ce562fe4af985 diff --git a/packages/foundry/package.json b/packages/foundry/package.json deleted file mode 100644 index 9bf2836..0000000 --- a/packages/foundry/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@se-2/foundry", - "version": "0.0.1", - "scripts": { - "account": "node script/ListAccount.js", - "chain": "anvil --config-out localhost.json", - "compile": "forge compile", - "deploy": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --legacy && node script/generateTsAbis.js", - "deploy:verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --legacy --verify ; node script/generateTsAbis.js", - "flatten": "forge flatten", - "fork": "anvil --fork-url ${0:-mainnet} --chain-id 31337 --config-out localhost.json", - "format": "forge fmt && prettier --write ./script/**/*.js", - "generate": "node script/generateAccount.js", - "lint": "forge fmt --check && prettier --check ./script/**/*.js", - "test": "forge test", - "verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/VerifyAll.s.sol --ffi --rpc-url ${1:-default_network}" - }, - "dependencies": { - "dotenv": "~16.3.1", - "envfile": "~6.18.0", - "ethers": "~5.7.1", - "prettier": "~2.8.8", - "qrcode": "~1.5.3", - "toml": "~3.0.0" - }, - "devDependencies": { - "@types/prettier": "2", - "@types/qrcode": "1" - } -} diff --git a/packages/foundry/remappings.txt b/packages/foundry/remappings.txt deleted file mode 100644 index df3cb81..0000000 --- a/packages/foundry/remappings.txt +++ /dev/null @@ -1 +0,0 @@ -@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts diff --git a/packages/foundry/script/Counter.s.sol b/packages/foundry/script/Counter.s.sol new file mode 100644 index 0000000..cdc1fe9 --- /dev/null +++ b/packages/foundry/script/Counter.s.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {Script, console} from "forge-std/Script.sol"; +import {Counter} from "../src/Counter.sol"; + +contract CounterScript is Script { + Counter public counter; + + function setUp() public {} + + function run() public { + vm.startBroadcast(); + + counter = new Counter(); + + vm.stopBroadcast(); + } +} diff --git a/packages/foundry/script/Deploy.s.sol b/packages/foundry/script/Deploy.s.sol deleted file mode 100644 index 1d19445..0000000 --- a/packages/foundry/script/Deploy.s.sol +++ /dev/null @@ -1,37 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import "../contracts/YourContract.sol"; -import "./DeployHelpers.s.sol"; - -contract DeployScript is ScaffoldETHDeploy { - error InvalidPrivateKey(string); - - function run() external { - uint256 deployerPrivateKey = setupLocalhostEnv(); - if (deployerPrivateKey == 0) { - revert InvalidPrivateKey( - "You don't have a deployer account. Make sure you have set DEPLOYER_PRIVATE_KEY in .env or use `yarn generate` to generate a new random account" - ); - } - vm.startBroadcast(deployerPrivateKey); - - YourContract yourContract = new YourContract(vm.addr(deployerPrivateKey)); - console.logString( - string.concat( - "YourContract deployed at: ", vm.toString(address(yourContract)) - ) - ); - - vm.stopBroadcast(); - - /** - * This function generates the file containing the contracts Abi definitions. - * These definitions are used to derive the types needed in the custom scaffold-eth hooks, for example. - * This function should be called last. - */ - exportDeployments(); - } - - function test() public { } -} diff --git a/packages/foundry/script/DeployHelpers.s.sol b/packages/foundry/script/DeployHelpers.s.sol deleted file mode 100644 index 7338ac1..0000000 --- a/packages/foundry/script/DeployHelpers.s.sol +++ /dev/null @@ -1,78 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import "forge-std/Script.sol"; -import "forge-std/Vm.sol"; - -contract ScaffoldETHDeploy is Script { - error InvalidChain(); - - struct Deployment { - string name; - address addr; - } - - string root; - string path; - Deployment[] public deployments; - - function setupLocalhostEnv() internal returns (uint256 localhostPrivateKey) { - if (block.chainid == 31337) { - root = vm.projectRoot(); - path = string.concat(root, "/localhost.json"); - string memory json = vm.readFile(path); - bytes memory mnemonicBytes = vm.parseJson(json, ".wallet.mnemonic"); - string memory mnemonic = abi.decode(mnemonicBytes, (string)); - return vm.deriveKey(mnemonic, 0); - } else { - return vm.envUint("DEPLOYER_PRIVATE_KEY"); - } - } - - function exportDeployments() internal { - // fetch already existing contracts - root = vm.projectRoot(); - path = string.concat(root, "/deployments/"); - string memory chainIdStr = vm.toString(block.chainid); - path = string.concat(path, string.concat(chainIdStr, ".json")); - - string memory jsonWrite; - - uint256 len = deployments.length; - - for (uint256 i = 0; i < len; i++) { - vm.serializeString( - jsonWrite, vm.toString(deployments[i].addr), deployments[i].name - ); - } - - string memory chainName; - - try this.getChain() returns (Chain memory chain) { - chainName = chain.name; - } catch { - chainName = findChainName(); - } - jsonWrite = vm.serializeString(jsonWrite, "networkName", chainName); - vm.writeJson(jsonWrite, path); - } - - function getChain() public returns (Chain memory) { - return getChain(block.chainid); - } - - function findChainName() public returns (string memory) { - uint256 thisChainId = block.chainid; - string[2][] memory allRpcUrls = vm.rpcUrls(); - for (uint256 i = 0; i < allRpcUrls.length; i++) { - try vm.createSelectFork(allRpcUrls[i][1]) { - if (block.chainid == thisChainId) { - return allRpcUrls[i][0]; - } - } catch { - continue; - } - } - revert InvalidChain(); - } -} diff --git a/packages/foundry/script/ListAccount.js b/packages/foundry/script/ListAccount.js deleted file mode 100644 index 20493b3..0000000 --- a/packages/foundry/script/ListAccount.js +++ /dev/null @@ -1,77 +0,0 @@ -const dotenv = require("dotenv"); -dotenv.config(); -const path = require("path"); -const { ethers, Wallet } = require("ethers"); -const QRCode = require("qrcode"); -const fs = require("fs"); -const toml = require("toml"); - -const ALCHEMY_API_KEY = - process.env.ALCHEMY_API_KEY || "oKxs-03sij-U_N0iOlrSsZFr29-IqbuF"; - -async function getBalanceForEachNetwork(address) { - try { - // Read the foundry.toml file - const foundryTomlPath = path.join(__dirname, "..", "foundry.toml"); - const tomlString = fs.readFileSync(foundryTomlPath, "utf-8"); - - // Parse the tomlString to get the JS object representation - const parsedToml = toml.parse(tomlString); - - // Extract rpc_endpoints from parsedToml - const rpcEndpoints = parsedToml.rpc_endpoints; - - // Replace placeholders in the rpc_endpoints section - function replaceENVAlchemyKey(input) { - return input.replace("${ALCHEMY_API_KEY}", ALCHEMY_API_KEY); - } - - for (const networkName in rpcEndpoints) { - if (networkName === "localhost" || networkName === "default_network") - continue; - - const networkUrl = replaceENVAlchemyKey(rpcEndpoints[networkName]); - - try { - const provider = new ethers.providers.JsonRpcProvider(networkUrl); - const balance = await provider.getBalance(address); - console.log("--", networkName, "-- 📡"); - console.log(" balance:", +ethers.utils.formatEther(balance)); - console.log( - " nonce:", - +(await provider.getTransactionCount(address)) - ); - } catch (e) { - console.log("Can't connect to network", networkName); - console.log(); - } - } - } catch (error) { - console.error("Error reading foundry.toml:", error); - } -} -async function main() { - const privateKey = process.env.DEPLOYER_PRIVATE_KEY; - - if (!privateKey) { - console.log( - "🚫️ You don't have a deployer account. Run `yarn generate` first" - ); - return; - } - - // Get account from private key. - const wallet = new Wallet(privateKey); - const address = wallet.address; - console.log( - await QRCode.toString(address, { type: "terminal", small: true }) - ); - console.log("Public address:", address, "\n"); - - await getBalanceForEachNetwork(address); -} - -main().catch((error) => { - console.error(error); - process.exitCode = 1; -}); diff --git a/packages/foundry/script/VerifyAll.s.sol b/packages/foundry/script/VerifyAll.s.sol deleted file mode 100644 index 829d676..0000000 --- a/packages/foundry/script/VerifyAll.s.sol +++ /dev/null @@ -1,133 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import "forge-std/Script.sol"; -import "forge-std/Vm.sol"; -import "solidity-bytes-utils/BytesLib.sol"; - -/** - * @dev Temp Vm implementation - * @notice calls the tryffi function on the Vm contract - * @notice will be deleted once the forge/std is updated - */ -struct FfiResult { - int32 exit_code; - bytes stdout; - bytes stderr; -} - -interface tempVm { - function tryFfi(string[] calldata) external returns (FfiResult memory); -} - -contract VerifyAll is Script { - uint96 currTransactionIdx; - - function run() external { - string memory root = vm.projectRoot(); - string memory path = string.concat( - root, - "/broadcast/Deploy.s.sol/", - vm.toString(block.chainid), - "/run-latest.json" - ); - string memory content = vm.readFile(path); - - while (this.nextTransaction(content)) { - _verifyIfContractDeployment(content); - currTransactionIdx++; - } - } - - function _verifyIfContractDeployment(string memory content) internal { - string memory txType = abi.decode( - vm.parseJson(content, searchStr(currTransactionIdx, "transactionType")), - (string) - ); - if (keccak256(bytes(txType)) == keccak256(bytes("CREATE"))) { - _verifyContract(content); - } - } - - function _verifyContract(string memory content) internal { - string memory contractName = abi.decode( - vm.parseJson(content, searchStr(currTransactionIdx, "contractName")), - (string) - ); - address contractAddr = abi.decode( - vm.parseJson(content, searchStr(currTransactionIdx, "contractAddress")), - (address) - ); - bytes memory deployedBytecode = abi.decode( - vm.parseJson(content, searchStr(currTransactionIdx, "transaction.input")), - (bytes) - ); - bytes memory compiledBytecode = abi.decode( - vm.parseJson(_getCompiledBytecode(contractName), ".bytecode.object"), - (bytes) - ); - bytes memory constructorArgs = BytesLib.slice( - deployedBytecode, - compiledBytecode.length, - deployedBytecode.length - compiledBytecode.length - ); - - string[] memory inputs = new string[](9); - inputs[0] = "forge"; - inputs[1] = "verify-contract"; - inputs[2] = vm.toString(contractAddr); - inputs[3] = contractName; - inputs[4] = "--chain"; - inputs[5] = vm.toString(block.chainid); - inputs[6] = "--constructor-args"; - inputs[7] = vm.toString(constructorArgs); - inputs[8] = "--watch"; - - FfiResult memory f = tempVm(address(vm)).tryFfi(inputs); - - if (f.stderr.length != 0) { - console.logString( - string.concat( - "Submitting verification for contract: ", vm.toString(contractAddr) - ) - ); - console.logString(string(f.stderr)); - } else { - console.logString(string(f.stdout)); - } - return; - } - - function nextTransaction(string memory content) external view returns (bool) { - try this.getTransactionFromRaw(content, currTransactionIdx) { - return true; - } catch { - return false; - } - } - - function _getCompiledBytecode(string memory contractName) - internal - view - returns (string memory compiledBytecode) - { - string memory root = vm.projectRoot(); - string memory path = - string.concat(root, "/out/", contractName, ".sol/", contractName, ".json"); - compiledBytecode = vm.readFile(path); - } - - function getTransactionFromRaw( - string memory content, - uint96 idx - ) external pure { - abi.decode(vm.parseJson(content, searchStr(idx, "hash")), (bytes32)); - } - - function searchStr( - uint96 idx, - string memory searchKey - ) internal pure returns (string memory) { - return string.concat(".transactions[", vm.toString(idx), "].", searchKey); - } -} diff --git a/packages/foundry/script/generateAccount.js b/packages/foundry/script/generateAccount.js deleted file mode 100644 index d6b2be3..0000000 --- a/packages/foundry/script/generateAccount.js +++ /dev/null @@ -1,49 +0,0 @@ -const ethers = require("ethers"); -const { parse, stringify } = require("envfile"); -const fs = require("fs"); - -const envFilePath = "./.env"; - -/** - * Generate a new random private key and write it to the .env file - * @param existingEnvConfig - */ -const setNewEnvConfig = (existingEnvConfig = {}) => { - console.log("👛 Generating new Wallet"); - const randomWallet = ethers.Wallet.createRandom(); - - const newEnvConfig = { - ...existingEnvConfig, - DEPLOYER_PRIVATE_KEY: randomWallet.privateKey, - }; - - // Store in .env - fs.writeFileSync(envFilePath, stringify(newEnvConfig)); - console.log("📄 Private Key saved to packages/foundry/.env file"); - console.log("🪄 Generated wallet address:", randomWallet.address); -}; - -async function main() { - if (!fs.existsSync(envFilePath)) { - console.log("entered here"); - // No .env file yet. - setNewEnvConfig(); - return; - } - - // .env file exists - const existingEnvConfig = parse(fs.readFileSync(envFilePath).toString()); - if (existingEnvConfig.DEPLOYER_PRIVATE_KEY) { - console.log( - "⚠️ You already have a deployer account. Check the packages/foundry/.env file" - ); - return; - } - - setNewEnvConfig(existingEnvConfig); -} - -main().catch((error) => { - console.error(error); - process.exitCode = 1; -}); diff --git a/packages/foundry/script/generateTsAbis.js b/packages/foundry/script/generateTsAbis.js deleted file mode 100644 index 699c914..0000000 --- a/packages/foundry/script/generateTsAbis.js +++ /dev/null @@ -1,148 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -//@ts-expect-error This script runs after `forge deploy` therefore its deterministic that it will present -// const deployments = require("../deployments.json"); -const prettier = require("prettier"); - -const generatedContractComment = ` -/** - * This file is autogenerated by Scaffold-ETH. - * You should not edit it manually or your changes might be overwritten. - */ -`; - -function getDirectories(path) { - return fs.readdirSync(path).filter(function (file) { - return fs.statSync(path + "/" + file).isDirectory(); - }); -} -function getFiles(path) { - return fs.readdirSync(path).filter(function (file) { - return fs.statSync(path + "/" + file).isFile(); - }); -} -function getArtifactOfContract(contractName) { - const current_path_to_artifacts = path.join( - __dirname, - "..", - `out/${contractName}.sol` - ); - const artifactJson = JSON.parse( - fs.readFileSync(`${current_path_to_artifacts}/${contractName}.json`) - ); - - return artifactJson; -} - -function getInheritedFromContracts(artifact) { - let inheritedFromContracts = []; - if (artifact?.ast) { - for (const astNode of artifact.ast.nodes) { - if (astNode.nodeType == "ContractDefinition") { - if (astNode.baseContracts.length > 0) { - inheritedFromContracts = astNode.baseContracts.map( - ({ baseName }) => baseName.name - ); - } - } - } - } - return inheritedFromContracts; -} - -function getInheritedFunctions(mainArtifact) { - const inheritedFromContracts = getInheritedFromContracts(mainArtifact); - const inheritedFunctions = {}; - for (const inheritanceContractName of inheritedFromContracts) { - const { - abi, - ast: { absolutePath }, - } = getArtifactOfContract(inheritanceContractName); - for (const abiEntry of abi) { - if (abiEntry.type == "function") { - inheritedFunctions[abiEntry.name] = absolutePath; - } - } - } - return inheritedFunctions; -} - -function main() { - const current_path_to_broadcast = path.join( - __dirname, - "..", - "broadcast/Deploy.s.sol" - ); - const current_path_to_deployments = path.join(__dirname, "..", "deployments"); - - const chains = getDirectories(current_path_to_broadcast); - const Deploymentchains = getFiles(current_path_to_deployments); - - const deployments = {}; - - Deploymentchains.forEach((chain) => { - if (!chain.endsWith(".json")) return; - chain = chain.slice(0, -5); - var deploymentObject = JSON.parse( - fs.readFileSync(`${current_path_to_deployments}/${chain}.json`) - ); - deployments[chain] = deploymentObject; - }); - - const allGeneratedContracts = {}; - - chains.forEach((chain) => { - allGeneratedContracts[chain] = {}; - const broadCastObject = JSON.parse( - fs.readFileSync(`${current_path_to_broadcast}/${chain}/run-latest.json`) - ); - const transactionsCreate = broadCastObject.transactions.filter( - (transaction) => transaction.transactionType == "CREATE" - ); - transactionsCreate.forEach((transaction) => { - const artifact = getArtifactOfContract(transaction.contractName); - allGeneratedContracts[chain][ - deployments[chain][transaction.contractAddress] || - transaction.contractName - ] = { - address: transaction.contractAddress, - abi: artifact.abi, - inheritedFunctions: getInheritedFunctions(artifact), - }; - }); - }); - - const TARGET_DIR = "../nextjs/contracts/"; - - const fileContent = Object.entries(allGeneratedContracts).reduce( - (content, [chainId, chainConfig]) => { - return `${content}${parseInt(chainId).toFixed(0)}:${JSON.stringify( - chainConfig, - null, - 2 - )},`; - }, - "" - ); - - if (!fs.existsSync(TARGET_DIR)) { - fs.mkdirSync(TARGET_DIR); - } - fs.writeFileSync( - `${TARGET_DIR}deployedContracts.ts`, - prettier.format( - `${generatedContractComment} import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; \n\n - const deployedContracts = {${fileContent}} as const; \n\n export default deployedContracts satisfies GenericContractsDeclaration`, - { - parser: "typescript", - } - ) - ); -} - -try { - main(); -} catch (error) { - console.error(error); - process.exitCode = 1; -} diff --git a/packages/foundry/src/Notes.sol b/packages/foundry/src/Notes.sol new file mode 100644 index 0000000..786d406 --- /dev/null +++ b/packages/foundry/src/Notes.sol @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.26; + +import {CNDataTypes} from "src/libraries/CNDataTypes.sol"; + +contract Notes { + uint16 public constant DENOMINATOR = 10_000; + + uint16 public constant HELPFULNESS_THRESHOLD = 40; + + uint16 public constant INITIAL_ELIGIBILITY_RATING_THRESHOLD = 10; + + mapping(address contractAddress => CNDataTypes.Note[] note) public notesOf; + + mapping(address user => CNDataTypes.User info) public infoOfUser; + + mapping(address user => mapping(address contractAddress => mapping(uint16 index => CNDataTypes.Rating))) public userRatingOfNote; + + function newNote( + address _contractAddress, + string calldata _uri, + string calldata _pictureUri, + CNDataTypes.Sentiment _sentiment, + ) external returns (CNDataTypes.Note _note) {} + + function vote( + CNDataTypes.Rating _rating, + uint16 _noteIndex, + address _contractAddress + ) external {} + + fucntion tip( + uint16 _noteIndex, + address _contractAddress + ) payable external returns (bool _ok) {} +} diff --git a/packages/foundry/src/libraries/CNDataTypes.sol b/packages/foundry/src/libraries/CNDataTypes.sol new file mode 100644 index 0000000..8448904 --- /dev/null +++ b/packages/foundry/src/libraries/CNDataTypes.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: AGPL-3.0 +pragma solidity 0.8.26; + +library CNDataTypes { + struct Note { + address noteWriter; + mapping(Rating rating => uint32 amount) amountOfRating; + mapping(Sentiment sentiment => uint32 amount) amountOfSentiment; + uint16 score; + string uri; + string pictureUri; + } + + struct User { + uint40 amountOfVotes; + mapping(Rating rating => uint40) amountOf; + } + + enum Rating { + HELPFUL, + NOT_HELPFUL, + SOMEWHAT_HELPFUL + } + + enum Sentiment { + POSITIVE, + NEGATIVE + } +} \ No newline at end of file diff --git a/packages/foundry/test/Counter.t.sol b/packages/foundry/test/Counter.t.sol new file mode 100644 index 0000000..54b724f --- /dev/null +++ b/packages/foundry/test/Counter.t.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {Test, console} from "forge-std/Test.sol"; +import {Counter} from "../src/Counter.sol"; + +contract CounterTest is Test { + Counter public counter; + + function setUp() public { + counter = new Counter(); + counter.setNumber(0); + } + + function test_Increment() public { + counter.increment(); + assertEq(counter.number(), 1); + } + + function testFuzz_SetNumber(uint256 x) public { + counter.setNumber(x); + assertEq(counter.number(), x); + } +} diff --git a/packages/foundry/test/YourContract.t.sol b/packages/foundry/test/YourContract.t.sol deleted file mode 100644 index a6a2c10..0000000 --- a/packages/foundry/test/YourContract.t.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import "forge-std/Test.sol"; -import "../contracts/YourContract.sol"; - -contract YourContractTest is Test { - YourContract public yourContract; - - function setUp() public { - yourContract = new YourContract(vm.addr(1)); - } - - function testMessageOnDeployment() public view { - require( - keccak256(bytes(yourContract.greeting())) - == keccak256("Building Unstoppable Apps!!!") - ); - } - - function testSetNewMessage() public { - yourContract.setGreeting("Learn Scaffold-ETH 2! :)"); - require( - keccak256(bytes(yourContract.greeting())) - == keccak256("Learn Scaffold-ETH 2! :)") - ); - } -} From e6f0ddbc8bc0fd3679336ff050e61ac7878534ca Mon Sep 17 00:00:00 2001 From: jacksmithinsulander <666.jack.smith@protonmail.com> Date: Fri, 12 Jul 2024 22:24:13 +0200 Subject: [PATCH 02/11] updated token --- .../11155111/run-1720815359.json | 46 ++++++++++++++++++ .../11155111/run-latest.json | 46 ++++++++++++++++++ packages/foundry/foundry.toml | 7 +++ packages/foundry/script/Counter.s.sol | 19 -------- packages/foundry/script/deploy_Notes.s.sol | 17 +++++++ packages/foundry/src/Notes.sol | 47 +++++++++++++++---- .../foundry/src/libraries/CNDataTypes.sol | 9 +--- packages/foundry/test/Counter.t.sol | 30 ++++++------ 8 files changed, 169 insertions(+), 52 deletions(-) create mode 100644 packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720815359.json create mode 100644 packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json delete mode 100644 packages/foundry/script/Counter.s.sol create mode 100644 packages/foundry/script/deploy_Notes.s.sol diff --git a/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720815359.json b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720815359.json new file mode 100644 index 0000000..8e692d4 --- /dev/null +++ b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720815359.json @@ -0,0 +1,46 @@ +{ + "transactions": [ + { + "hash": "0x38a939f1737f1b2461434242f8d04064118c133ecb3c112f34ea604d2ccd2d7f", + "transactionType": "CREATE", + "contractName": "Notes", + "contractAddress": "0x5c823632d432ab578d584d55809044e5f1a39780", + "function": null, + "arguments": null, + "transaction": { + "from": "0xf6da1082b2b8952c73ed7220db5df38aec56a1b2", + "gas": "0xdb297", + "value": "0x0", + "input": "0x6080604052348015600f57600080fd5b50610b888061001f6000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c8063c70e012c11610066578063c70e012c14610151578063cead5f7a14610174578063d91c9bad146101c0578063da239bf1146101e0578063f559b79b146101e857600080fd5b8063223094e9146100a3578063256e025a146100ea5780633ddbfa0a146100f257806343e1ebf014610133578063918f867414610148575b600080fd5b6100d26100b136600461066b565b600160209081526000928352604080842090915290825290205461ffff1681565b60405161ffff90911681526020015b60405180910390f35b6100d2602881565b6101266101003660046106b0565b600460209081526000938452604080852082529284528284209052825290205460ff1681565b6040516100e19190610709565b610146610141366004610732565b610230565b005b6100d261271081565b61016461015f36600461076c565b61038d565b6040516100e194939291906107f0565b6101ab610182366004610833565b600260209081526000938452604080852082529284528284209052825290205463ffffffff1681565b60405163ffffffff90911681526020016100e1565b6101d36101ce36600461086d565b610473565b6040516100e19190610903565b6100d2600a81565b61021a6101f6366004610959565b600360209081526000928352604080842090915290825290205464ffffffffff1681565b60405164ffffffffff90911681526020016100e1565b33600090815260036020526040812090846002811115610252576102526106f3565b6002811115610263576102636106f3565b815260208101919091526040016000908120805464ffffffffff169161028883610999565b825464ffffffffff9182166101009390930a9283029190920219909116179055503360009081526004602090815260408083206001600160a01b0385168452825280832061ffff861684529091529020805484919060ff191660018360028111156102f5576102f56106f3565b02179055506001600160a01b038116600090815260026020818152604080842061ffff87168552909152822091908590811115610334576103346106f3565b6002811115610345576103456106f3565b815260208101919091526040016000908120805463ffffffff1691610369836109c0565b91906101000a81548163ffffffff021916908363ffffffff16021790555050505050565b600060205281600052604060002081815481106103a957600080fd5b6000918252602090912060029091020180546001820180546001600160a01b0383169550600160a01b830460ff169450600160a81b90920461ffff1692916103f0906109dc565b80601f016020809104026020016040519081016040528092919081815260200182805461041c906109dc565b80156104695780601f1061043e57610100808354040283529160200191610469565b820191906000526020600020905b81548152906001019060200180831161044c57829003601f168201915b5050505050905084565b60408051608081018252600080825260208201819052918101919091526060808201526040518060800160405280336001600160a01b031681526020018360018111156104c2576104c26106f3565b8152602001600061ffff16815260200185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250506001600160a01b03888116825260208281526040832080546001808201835591855293829020865160029095020180546001600160a01b03198116959094169485178155918601519596508695919450909284926001600160a81b0319161790600160a01b908490811115610581576105816106f3565b02179055506040820151815461ffff909116600160a81b0261ffff60a81b19909116178155606082015160018201906105ba9082610a7b565b5050506001600160a01b03851660009081526001602081905260408220919084908111156105ea576105ea6106f3565b60018111156105fb576105fb6106f3565b815260208101919091526040016000908120805461ffff169161061d83610b3a565b91906101000a81548161ffff021916908361ffff16021790555050949350505050565b80356001600160a01b038116811461065757600080fd5b919050565b80356002811061065757600080fd5b6000806040838503121561067e57600080fd5b61068783610640565b91506106956020840161065c565b90509250929050565b803561ffff8116811461065757600080fd5b6000806000606084860312156106c557600080fd5b6106ce84610640565b92506106dc60208501610640565b91506106ea6040850161069e565b90509250925092565b634e487b7160e01b600052602160045260246000fd5b602081016003831061071d5761071d6106f3565b91905290565b80356003811061065757600080fd5b60008060006060848603121561074757600080fd5b61075084610723565b925061075e6020850161069e565b91506106ea60408501610640565b6000806040838503121561077f57600080fd5b61078883610640565b946020939093013593505050565b600281106107a6576107a66106f3565b9052565b6000815180845260005b818110156107d0576020818501810151868301820152016107b4565b506000602082860101526020601f19601f83011685010191505092915050565b6001600160a01b03851681526108096020820185610796565b61ffff8316604082015260806060820152600061082960808301846107aa565b9695505050505050565b60008060006060848603121561084857600080fd5b61085184610640565b925061085f6020850161069e565b91506106ea60408501610723565b6000806000806060858703121561088357600080fd5b61088c85610640565b9350602085013567ffffffffffffffff8111156108a857600080fd5b8501601f810187136108b957600080fd5b803567ffffffffffffffff8111156108d057600080fd5b8760208284010111156108e257600080fd5b602091909101935091506108f86040860161065c565b905092959194509250565b602080825282516001600160a01b03168282015282015160009061092a6040840182610796565b5061ffff6040840151166060830152606083015160808084015261095160a08401826107aa565b949350505050565b6000806040838503121561096c57600080fd5b61097583610640565b915061069560208401610723565b634e487b7160e01b600052601160045260246000fd5b600064ffffffffff821664ffffffffff81036109b7576109b7610983565b60010192915050565b600063ffffffff821663ffffffff81036109b7576109b7610983565b600181811c908216806109f057607f821691505b602082108103610a1057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b601f821115610a7657806000526020600020601f840160051c81016020851015610a535750805b601f840160051c820191505b81811015610a735760008155600101610a5f565b50505b505050565b815167ffffffffffffffff811115610a9557610a95610a16565b610aa981610aa384546109dc565b84610a2c565b6020601f821160018114610add5760008315610ac55750848201515b600019600385901b1c1916600184901b178455610a73565b600084815260208120601f198516915b82811015610b0d5787850151825560209485019460019092019101610aed565b5084821015610b2b5786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b600061ffff821661ffff81036109b7576109b761098356fea26469706673582212204cd3dc89fa495e4af31394da182a24cefacd6cfeeb1be554b869598f4eeebccf64736f6c634300081a0033", + "nonce": "0x5c", + "chainId": "0xaa36a7" + }, + "additionalContracts": [], + "isFixedGasLimit": false + } + ], + "receipts": [ + { + "status": "0x1", + "cumulativeGasUsed": "0x5812a0", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "type": "0x0", + "transactionHash": "0x38a939f1737f1b2461434242f8d04064118c133ecb3c112f34ea604d2ccd2d7f", + "transactionIndex": "0x1f", + "blockHash": "0xf026727585dbf02ac4952646fb9540708b2fb442632c659fbd1d0722d15dcbdf", + "blockNumber": "0x601b2c", + "gasUsed": "0xa8a1d", + "effectiveGasPrice": "0x183b2fca4", + "from": "0xf6da1082b2b8952c73ed7220db5df38aec56a1b2", + "to": null, + "contractAddress": "0x5c823632d432ab578d584d55809044e5f1a39780" + } + ], + "libraries": [], + "pending": [], + "returns": {}, + "timestamp": 1720815359, + "chain": 11155111, + "commit": "9136288" +} \ No newline at end of file diff --git a/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json new file mode 100644 index 0000000..8e692d4 --- /dev/null +++ b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json @@ -0,0 +1,46 @@ +{ + "transactions": [ + { + "hash": "0x38a939f1737f1b2461434242f8d04064118c133ecb3c112f34ea604d2ccd2d7f", + "transactionType": "CREATE", + "contractName": "Notes", + "contractAddress": "0x5c823632d432ab578d584d55809044e5f1a39780", + "function": null, + "arguments": null, + "transaction": { + "from": "0xf6da1082b2b8952c73ed7220db5df38aec56a1b2", + "gas": "0xdb297", + "value": "0x0", + "input": "0x6080604052348015600f57600080fd5b50610b888061001f6000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c8063c70e012c11610066578063c70e012c14610151578063cead5f7a14610174578063d91c9bad146101c0578063da239bf1146101e0578063f559b79b146101e857600080fd5b8063223094e9146100a3578063256e025a146100ea5780633ddbfa0a146100f257806343e1ebf014610133578063918f867414610148575b600080fd5b6100d26100b136600461066b565b600160209081526000928352604080842090915290825290205461ffff1681565b60405161ffff90911681526020015b60405180910390f35b6100d2602881565b6101266101003660046106b0565b600460209081526000938452604080852082529284528284209052825290205460ff1681565b6040516100e19190610709565b610146610141366004610732565b610230565b005b6100d261271081565b61016461015f36600461076c565b61038d565b6040516100e194939291906107f0565b6101ab610182366004610833565b600260209081526000938452604080852082529284528284209052825290205463ffffffff1681565b60405163ffffffff90911681526020016100e1565b6101d36101ce36600461086d565b610473565b6040516100e19190610903565b6100d2600a81565b61021a6101f6366004610959565b600360209081526000928352604080842090915290825290205464ffffffffff1681565b60405164ffffffffff90911681526020016100e1565b33600090815260036020526040812090846002811115610252576102526106f3565b6002811115610263576102636106f3565b815260208101919091526040016000908120805464ffffffffff169161028883610999565b825464ffffffffff9182166101009390930a9283029190920219909116179055503360009081526004602090815260408083206001600160a01b0385168452825280832061ffff861684529091529020805484919060ff191660018360028111156102f5576102f56106f3565b02179055506001600160a01b038116600090815260026020818152604080842061ffff87168552909152822091908590811115610334576103346106f3565b6002811115610345576103456106f3565b815260208101919091526040016000908120805463ffffffff1691610369836109c0565b91906101000a81548163ffffffff021916908363ffffffff16021790555050505050565b600060205281600052604060002081815481106103a957600080fd5b6000918252602090912060029091020180546001820180546001600160a01b0383169550600160a01b830460ff169450600160a81b90920461ffff1692916103f0906109dc565b80601f016020809104026020016040519081016040528092919081815260200182805461041c906109dc565b80156104695780601f1061043e57610100808354040283529160200191610469565b820191906000526020600020905b81548152906001019060200180831161044c57829003601f168201915b5050505050905084565b60408051608081018252600080825260208201819052918101919091526060808201526040518060800160405280336001600160a01b031681526020018360018111156104c2576104c26106f3565b8152602001600061ffff16815260200185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250506001600160a01b03888116825260208281526040832080546001808201835591855293829020865160029095020180546001600160a01b03198116959094169485178155918601519596508695919450909284926001600160a81b0319161790600160a01b908490811115610581576105816106f3565b02179055506040820151815461ffff909116600160a81b0261ffff60a81b19909116178155606082015160018201906105ba9082610a7b565b5050506001600160a01b03851660009081526001602081905260408220919084908111156105ea576105ea6106f3565b60018111156105fb576105fb6106f3565b815260208101919091526040016000908120805461ffff169161061d83610b3a565b91906101000a81548161ffff021916908361ffff16021790555050949350505050565b80356001600160a01b038116811461065757600080fd5b919050565b80356002811061065757600080fd5b6000806040838503121561067e57600080fd5b61068783610640565b91506106956020840161065c565b90509250929050565b803561ffff8116811461065757600080fd5b6000806000606084860312156106c557600080fd5b6106ce84610640565b92506106dc60208501610640565b91506106ea6040850161069e565b90509250925092565b634e487b7160e01b600052602160045260246000fd5b602081016003831061071d5761071d6106f3565b91905290565b80356003811061065757600080fd5b60008060006060848603121561074757600080fd5b61075084610723565b925061075e6020850161069e565b91506106ea60408501610640565b6000806040838503121561077f57600080fd5b61078883610640565b946020939093013593505050565b600281106107a6576107a66106f3565b9052565b6000815180845260005b818110156107d0576020818501810151868301820152016107b4565b506000602082860101526020601f19601f83011685010191505092915050565b6001600160a01b03851681526108096020820185610796565b61ffff8316604082015260806060820152600061082960808301846107aa565b9695505050505050565b60008060006060848603121561084857600080fd5b61085184610640565b925061085f6020850161069e565b91506106ea60408501610723565b6000806000806060858703121561088357600080fd5b61088c85610640565b9350602085013567ffffffffffffffff8111156108a857600080fd5b8501601f810187136108b957600080fd5b803567ffffffffffffffff8111156108d057600080fd5b8760208284010111156108e257600080fd5b602091909101935091506108f86040860161065c565b905092959194509250565b602080825282516001600160a01b03168282015282015160009061092a6040840182610796565b5061ffff6040840151166060830152606083015160808084015261095160a08401826107aa565b949350505050565b6000806040838503121561096c57600080fd5b61097583610640565b915061069560208401610723565b634e487b7160e01b600052601160045260246000fd5b600064ffffffffff821664ffffffffff81036109b7576109b7610983565b60010192915050565b600063ffffffff821663ffffffff81036109b7576109b7610983565b600181811c908216806109f057607f821691505b602082108103610a1057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b601f821115610a7657806000526020600020601f840160051c81016020851015610a535750805b601f840160051c820191505b81811015610a735760008155600101610a5f565b50505b505050565b815167ffffffffffffffff811115610a9557610a95610a16565b610aa981610aa384546109dc565b84610a2c565b6020601f821160018114610add5760008315610ac55750848201515b600019600385901b1c1916600184901b178455610a73565b600084815260208120601f198516915b82811015610b0d5787850151825560209485019460019092019101610aed565b5084821015610b2b5786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b600061ffff821661ffff81036109b7576109b761098356fea26469706673582212204cd3dc89fa495e4af31394da182a24cefacd6cfeeb1be554b869598f4eeebccf64736f6c634300081a0033", + "nonce": "0x5c", + "chainId": "0xaa36a7" + }, + "additionalContracts": [], + "isFixedGasLimit": false + } + ], + "receipts": [ + { + "status": "0x1", + "cumulativeGasUsed": "0x5812a0", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "type": "0x0", + "transactionHash": "0x38a939f1737f1b2461434242f8d04064118c133ecb3c112f34ea604d2ccd2d7f", + "transactionIndex": "0x1f", + "blockHash": "0xf026727585dbf02ac4952646fb9540708b2fb442632c659fbd1d0722d15dcbdf", + "blockNumber": "0x601b2c", + "gasUsed": "0xa8a1d", + "effectiveGasPrice": "0x183b2fca4", + "from": "0xf6da1082b2b8952c73ed7220db5df38aec56a1b2", + "to": null, + "contractAddress": "0x5c823632d432ab578d584d55809044e5f1a39780" + } + ], + "libraries": [], + "pending": [], + "returns": {}, + "timestamp": 1720815359, + "chain": 11155111, + "commit": "9136288" +} \ No newline at end of file diff --git a/packages/foundry/foundry.toml b/packages/foundry/foundry.toml index 25b918f..10237cf 100644 --- a/packages/foundry/foundry.toml +++ b/packages/foundry/foundry.toml @@ -2,5 +2,12 @@ src = "src" out = "out" libs = ["lib"] +fs_permissions = [{ access = "read-write", path = "./"}] + +[rpc_endpoints] +sepolia = "${SEPOLIA_RPC}" + +[etherscan] +sepolia = { key = "${SEPOLIA_API_KEY}", url = "https://api-sepolia.etherscan.io/api" } # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/packages/foundry/script/Counter.s.sol b/packages/foundry/script/Counter.s.sol deleted file mode 100644 index cdc1fe9..0000000 --- a/packages/foundry/script/Counter.s.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Script, console} from "forge-std/Script.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterScript is Script { - Counter public counter; - - function setUp() public {} - - function run() public { - vm.startBroadcast(); - - counter = new Counter(); - - vm.stopBroadcast(); - } -} diff --git a/packages/foundry/script/deploy_Notes.s.sol b/packages/foundry/script/deploy_Notes.s.sol new file mode 100644 index 0000000..59a679c --- /dev/null +++ b/packages/foundry/script/deploy_Notes.s.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.26; + +import "forge-std/Script.sol"; +import {Notes} from "src/Notes.sol"; + +contract CounterScript is Script { + Notes notes; + + uint256 deployerKey = vm.envUint("DEPLOYER_KEY"); + + function run() external { + vm.startBroadcast(deployerKey); + notes = new Notes(); + vm.stopBroadcast(); + } +} diff --git a/packages/foundry/src/Notes.sol b/packages/foundry/src/Notes.sol index 786d406..aa6c665 100644 --- a/packages/foundry/src/Notes.sol +++ b/packages/foundry/src/Notes.sol @@ -1,8 +1,15 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.26; +/* ChainNotes Libraries */ import {CNDataTypes} from "src/libraries/CNDataTypes.sol"; +/** + * @title Notes + * @author ChainNotes Technical Team + * @notice Main contract in charge of vot + * + */ contract Notes { uint16 public constant DENOMINATOR = 10_000; @@ -12,25 +19,45 @@ contract Notes { mapping(address contractAddress => CNDataTypes.Note[] note) public notesOf; - mapping(address user => CNDataTypes.User info) public infoOfUser; + mapping(address contractAddress => mapping(CNDataTypes.Sentiment sentiment => uint16 amount)) public sentimentOf; + + mapping(address contractAddress => mapping(uint16 index => mapping(CNDataTypes.Rating rating => uint32 amount))) public amountOfRating; + + mapping(address user => mapping(CNDataTypes.Rating => uint40 amount)) public ratingWeightOf; mapping(address user => mapping(address contractAddress => mapping(uint16 index => CNDataTypes.Rating))) public userRatingOfNote; - function newNote( + function publishNote( address _contractAddress, string calldata _uri, - string calldata _pictureUri, - CNDataTypes.Sentiment _sentiment, - ) external returns (CNDataTypes.Note _note) {} + CNDataTypes.Sentiment _sentiment + ) external returns(CNDataTypes.Note memory _note) { + _note = CNDataTypes.Note({ + noteWriter: msg.sender, + uri: _uri, + score: 0, + sentiment: _sentiment + }); + + notesOf[_contractAddress].push(_note); + + sentimentOf[_contractAddress][_sentiment]++; + } function vote( CNDataTypes.Rating _rating, uint16 _noteIndex, address _contractAddress - ) external {} + ) external { + ratingWeightOf[msg.sender][_rating]++; - fucntion tip( - uint16 _noteIndex, - address _contractAddress - ) payable external returns (bool _ok) {} + userRatingOfNote[msg.sender][_contractAddress][_noteIndex] = _rating; + + amountOfRating[_contractAddress][_noteIndex][_rating]++; + } + + // fucntion tip( + // uint16 _noteIndex, + // address _contractAddress + // ) payable external returns (bool _ok) {} } diff --git a/packages/foundry/src/libraries/CNDataTypes.sol b/packages/foundry/src/libraries/CNDataTypes.sol index 8448904..6ee0062 100644 --- a/packages/foundry/src/libraries/CNDataTypes.sol +++ b/packages/foundry/src/libraries/CNDataTypes.sol @@ -4,16 +4,9 @@ pragma solidity 0.8.26; library CNDataTypes { struct Note { address noteWriter; - mapping(Rating rating => uint32 amount) amountOfRating; - mapping(Sentiment sentiment => uint32 amount) amountOfSentiment; + Sentiment sentiment; uint16 score; string uri; - string pictureUri; - } - - struct User { - uint40 amountOfVotes; - mapping(Rating rating => uint40) amountOf; } enum Rating { diff --git a/packages/foundry/test/Counter.t.sol b/packages/foundry/test/Counter.t.sol index 54b724f..b8791d0 100644 --- a/packages/foundry/test/Counter.t.sol +++ b/packages/foundry/test/Counter.t.sol @@ -1,24 +1,24 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; +pragma solidity 0.8.26; import {Test, console} from "forge-std/Test.sol"; -import {Counter} from "../src/Counter.sol"; +//import {Counter} from "../src/Counter.sol"; contract CounterTest is Test { - Counter public counter; + // Counter public counter; - function setUp() public { - counter = new Counter(); - counter.setNumber(0); - } + // function setUp() public { + // counter = new Counter(); + // counter.setNumber(0); + // } - function test_Increment() public { - counter.increment(); - assertEq(counter.number(), 1); - } + // function test_Increment() public { + // counter.increment(); + // assertEq(counter.number(), 1); + // } - function testFuzz_SetNumber(uint256 x) public { - counter.setNumber(x); - assertEq(counter.number(), x); - } + // function testFuzz_SetNumber(uint256 x) public { + // counter.setNumber(x); + // assertEq(counter.number(), x); + // } } From 0155677dd8778ec79e52b230133c225ccbe429f2 Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Fri, 12 Jul 2024 22:44:19 +0200 Subject: [PATCH 03/11] fix scaffold --- .../11155111/run-1720816598.json | 46 +++ .../11155111/run-latest.json | 32 +-- packages/foundry/deployments/11155111.json | 3 + packages/foundry/foundry.toml | 1 + packages/foundry/lib/openzeppelin-contracts | 1 + packages/foundry/lib/solidity-bytes-utils | 1 + packages/foundry/package.json | 30 ++ packages/foundry/script/generateTsAbis.js | 150 ++++++++++ .../nextjs/contracts/deployedContracts.ts | 269 +++++++++++++++++- 9 files changed, 516 insertions(+), 17 deletions(-) create mode 100644 packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720816598.json create mode 100644 packages/foundry/deployments/11155111.json create mode 160000 packages/foundry/lib/openzeppelin-contracts create mode 160000 packages/foundry/lib/solidity-bytes-utils create mode 100644 packages/foundry/package.json create mode 100644 packages/foundry/script/generateTsAbis.js diff --git a/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720816598.json b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720816598.json new file mode 100644 index 0000000..3c6c835 --- /dev/null +++ b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720816598.json @@ -0,0 +1,46 @@ +{ + "transactions": [ + { + "hash": "0x38e33b52499d2c18b1676c774b0fdaf0e6cdf157fc3bacd2008c93fc085cc0ef", + "transactionType": "CREATE", + "contractName": "Notes", + "contractAddress": "0xf0cba52b7b24277ba894346cc44da27df6993a9b", + "function": null, + "arguments": null, + "transaction": { + "from": "0x199d51a2be04c65f325908911430e6ff79a15ce3", + "gas": "0xdb297", + "value": "0x0", + "input": "0x6080604052348015600f57600080fd5b50610b888061001f6000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c8063c70e012c11610066578063c70e012c14610151578063cead5f7a14610174578063d91c9bad146101c0578063da239bf1146101e0578063f559b79b146101e857600080fd5b8063223094e9146100a3578063256e025a146100ea5780633ddbfa0a146100f257806343e1ebf014610133578063918f867414610148575b600080fd5b6100d26100b136600461066b565b600160209081526000928352604080842090915290825290205461ffff1681565b60405161ffff90911681526020015b60405180910390f35b6100d2602881565b6101266101003660046106b0565b600460209081526000938452604080852082529284528284209052825290205460ff1681565b6040516100e19190610709565b610146610141366004610732565b610230565b005b6100d261271081565b61016461015f36600461076c565b61038d565b6040516100e194939291906107f0565b6101ab610182366004610833565b600260209081526000938452604080852082529284528284209052825290205463ffffffff1681565b60405163ffffffff90911681526020016100e1565b6101d36101ce36600461086d565b610473565b6040516100e19190610903565b6100d2600a81565b61021a6101f6366004610959565b600360209081526000928352604080842090915290825290205464ffffffffff1681565b60405164ffffffffff90911681526020016100e1565b33600090815260036020526040812090846002811115610252576102526106f3565b6002811115610263576102636106f3565b815260208101919091526040016000908120805464ffffffffff169161028883610999565b825464ffffffffff9182166101009390930a9283029190920219909116179055503360009081526004602090815260408083206001600160a01b0385168452825280832061ffff861684529091529020805484919060ff191660018360028111156102f5576102f56106f3565b02179055506001600160a01b038116600090815260026020818152604080842061ffff87168552909152822091908590811115610334576103346106f3565b6002811115610345576103456106f3565b815260208101919091526040016000908120805463ffffffff1691610369836109c0565b91906101000a81548163ffffffff021916908363ffffffff16021790555050505050565b600060205281600052604060002081815481106103a957600080fd5b6000918252602090912060029091020180546001820180546001600160a01b0383169550600160a01b830460ff169450600160a81b90920461ffff1692916103f0906109dc565b80601f016020809104026020016040519081016040528092919081815260200182805461041c906109dc565b80156104695780601f1061043e57610100808354040283529160200191610469565b820191906000526020600020905b81548152906001019060200180831161044c57829003601f168201915b5050505050905084565b60408051608081018252600080825260208201819052918101919091526060808201526040518060800160405280336001600160a01b031681526020018360018111156104c2576104c26106f3565b8152602001600061ffff16815260200185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250506001600160a01b03888116825260208281526040832080546001808201835591855293829020865160029095020180546001600160a01b03198116959094169485178155918601519596508695919450909284926001600160a81b0319161790600160a01b908490811115610581576105816106f3565b02179055506040820151815461ffff909116600160a81b0261ffff60a81b19909116178155606082015160018201906105ba9082610a7b565b5050506001600160a01b03851660009081526001602081905260408220919084908111156105ea576105ea6106f3565b60018111156105fb576105fb6106f3565b815260208101919091526040016000908120805461ffff169161061d83610b3a565b91906101000a81548161ffff021916908361ffff16021790555050949350505050565b80356001600160a01b038116811461065757600080fd5b919050565b80356002811061065757600080fd5b6000806040838503121561067e57600080fd5b61068783610640565b91506106956020840161065c565b90509250929050565b803561ffff8116811461065757600080fd5b6000806000606084860312156106c557600080fd5b6106ce84610640565b92506106dc60208501610640565b91506106ea6040850161069e565b90509250925092565b634e487b7160e01b600052602160045260246000fd5b602081016003831061071d5761071d6106f3565b91905290565b80356003811061065757600080fd5b60008060006060848603121561074757600080fd5b61075084610723565b925061075e6020850161069e565b91506106ea60408501610640565b6000806040838503121561077f57600080fd5b61078883610640565b946020939093013593505050565b600281106107a6576107a66106f3565b9052565b6000815180845260005b818110156107d0576020818501810151868301820152016107b4565b506000602082860101526020601f19601f83011685010191505092915050565b6001600160a01b03851681526108096020820185610796565b61ffff8316604082015260806060820152600061082960808301846107aa565b9695505050505050565b60008060006060848603121561084857600080fd5b61085184610640565b925061085f6020850161069e565b91506106ea60408501610723565b6000806000806060858703121561088357600080fd5b61088c85610640565b9350602085013567ffffffffffffffff8111156108a857600080fd5b8501601f810187136108b957600080fd5b803567ffffffffffffffff8111156108d057600080fd5b8760208284010111156108e257600080fd5b602091909101935091506108f86040860161065c565b905092959194509250565b602080825282516001600160a01b03168282015282015160009061092a6040840182610796565b5061ffff6040840151166060830152606083015160808084015261095160a08401826107aa565b949350505050565b6000806040838503121561096c57600080fd5b61097583610640565b915061069560208401610723565b634e487b7160e01b600052601160045260246000fd5b600064ffffffffff821664ffffffffff81036109b7576109b7610983565b60010192915050565b600063ffffffff821663ffffffff81036109b7576109b7610983565b600181811c908216806109f057607f821691505b602082108103610a1057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b601f821115610a7657806000526020600020601f840160051c81016020851015610a535750805b601f840160051c820191505b81811015610a735760008155600101610a5f565b50505b505050565b815167ffffffffffffffff811115610a9557610a95610a16565b610aa981610aa384546109dc565b84610a2c565b6020601f821160018114610add5760008315610ac55750848201515b600019600385901b1c1916600184901b178455610a73565b600084815260208120601f198516915b82811015610b0d5787850151825560209485019460019092019101610aed565b5084821015610b2b5786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b600061ffff821661ffff81036109b7576109b761098356fea26469706673582212202340c8d771aebc9d6c0a0897bf4b14e70981cf88a2a72e99b7f034da89e57fb664736f6c634300081a0033", + "nonce": "0x1f4", + "chainId": "0xaa36a7" + }, + "additionalContracts": [], + "isFixedGasLimit": false + } + ], + "receipts": [ + { + "status": "0x1", + "cumulativeGasUsed": "0x891334", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "type": "0x2", + "transactionHash": "0x38e33b52499d2c18b1676c774b0fdaf0e6cdf157fc3bacd2008c93fc085cc0ef", + "transactionIndex": "0x40", + "blockHash": "0x2804f3fe5b97e9fae5974c61ba90809a64991df9f850984ba2571d18c243e872", + "blockNumber": "0x601b8e", + "gasUsed": "0xa8a1d", + "effectiveGasPrice": "0x15ed08428", + "from": "0x199d51a2be04c65f325908911430e6ff79a15ce3", + "to": null, + "contractAddress": "0xf0cba52b7b24277ba894346cc44da27df6993a9b" + } + ], + "libraries": [], + "pending": [], + "returns": {}, + "timestamp": 1720816598, + "chain": 11155111, + "commit": "e6f0ddb" +} \ No newline at end of file diff --git a/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json index 8e692d4..3c6c835 100644 --- a/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json +++ b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json @@ -1,18 +1,18 @@ { "transactions": [ { - "hash": "0x38a939f1737f1b2461434242f8d04064118c133ecb3c112f34ea604d2ccd2d7f", + "hash": "0x38e33b52499d2c18b1676c774b0fdaf0e6cdf157fc3bacd2008c93fc085cc0ef", "transactionType": "CREATE", "contractName": "Notes", - "contractAddress": "0x5c823632d432ab578d584d55809044e5f1a39780", + "contractAddress": "0xf0cba52b7b24277ba894346cc44da27df6993a9b", "function": null, "arguments": null, "transaction": { - "from": "0xf6da1082b2b8952c73ed7220db5df38aec56a1b2", + "from": "0x199d51a2be04c65f325908911430e6ff79a15ce3", "gas": "0xdb297", "value": "0x0", - "input": "0x6080604052348015600f57600080fd5b50610b888061001f6000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c8063c70e012c11610066578063c70e012c14610151578063cead5f7a14610174578063d91c9bad146101c0578063da239bf1146101e0578063f559b79b146101e857600080fd5b8063223094e9146100a3578063256e025a146100ea5780633ddbfa0a146100f257806343e1ebf014610133578063918f867414610148575b600080fd5b6100d26100b136600461066b565b600160209081526000928352604080842090915290825290205461ffff1681565b60405161ffff90911681526020015b60405180910390f35b6100d2602881565b6101266101003660046106b0565b600460209081526000938452604080852082529284528284209052825290205460ff1681565b6040516100e19190610709565b610146610141366004610732565b610230565b005b6100d261271081565b61016461015f36600461076c565b61038d565b6040516100e194939291906107f0565b6101ab610182366004610833565b600260209081526000938452604080852082529284528284209052825290205463ffffffff1681565b60405163ffffffff90911681526020016100e1565b6101d36101ce36600461086d565b610473565b6040516100e19190610903565b6100d2600a81565b61021a6101f6366004610959565b600360209081526000928352604080842090915290825290205464ffffffffff1681565b60405164ffffffffff90911681526020016100e1565b33600090815260036020526040812090846002811115610252576102526106f3565b6002811115610263576102636106f3565b815260208101919091526040016000908120805464ffffffffff169161028883610999565b825464ffffffffff9182166101009390930a9283029190920219909116179055503360009081526004602090815260408083206001600160a01b0385168452825280832061ffff861684529091529020805484919060ff191660018360028111156102f5576102f56106f3565b02179055506001600160a01b038116600090815260026020818152604080842061ffff87168552909152822091908590811115610334576103346106f3565b6002811115610345576103456106f3565b815260208101919091526040016000908120805463ffffffff1691610369836109c0565b91906101000a81548163ffffffff021916908363ffffffff16021790555050505050565b600060205281600052604060002081815481106103a957600080fd5b6000918252602090912060029091020180546001820180546001600160a01b0383169550600160a01b830460ff169450600160a81b90920461ffff1692916103f0906109dc565b80601f016020809104026020016040519081016040528092919081815260200182805461041c906109dc565b80156104695780601f1061043e57610100808354040283529160200191610469565b820191906000526020600020905b81548152906001019060200180831161044c57829003601f168201915b5050505050905084565b60408051608081018252600080825260208201819052918101919091526060808201526040518060800160405280336001600160a01b031681526020018360018111156104c2576104c26106f3565b8152602001600061ffff16815260200185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250506001600160a01b03888116825260208281526040832080546001808201835591855293829020865160029095020180546001600160a01b03198116959094169485178155918601519596508695919450909284926001600160a81b0319161790600160a01b908490811115610581576105816106f3565b02179055506040820151815461ffff909116600160a81b0261ffff60a81b19909116178155606082015160018201906105ba9082610a7b565b5050506001600160a01b03851660009081526001602081905260408220919084908111156105ea576105ea6106f3565b60018111156105fb576105fb6106f3565b815260208101919091526040016000908120805461ffff169161061d83610b3a565b91906101000a81548161ffff021916908361ffff16021790555050949350505050565b80356001600160a01b038116811461065757600080fd5b919050565b80356002811061065757600080fd5b6000806040838503121561067e57600080fd5b61068783610640565b91506106956020840161065c565b90509250929050565b803561ffff8116811461065757600080fd5b6000806000606084860312156106c557600080fd5b6106ce84610640565b92506106dc60208501610640565b91506106ea6040850161069e565b90509250925092565b634e487b7160e01b600052602160045260246000fd5b602081016003831061071d5761071d6106f3565b91905290565b80356003811061065757600080fd5b60008060006060848603121561074757600080fd5b61075084610723565b925061075e6020850161069e565b91506106ea60408501610640565b6000806040838503121561077f57600080fd5b61078883610640565b946020939093013593505050565b600281106107a6576107a66106f3565b9052565b6000815180845260005b818110156107d0576020818501810151868301820152016107b4565b506000602082860101526020601f19601f83011685010191505092915050565b6001600160a01b03851681526108096020820185610796565b61ffff8316604082015260806060820152600061082960808301846107aa565b9695505050505050565b60008060006060848603121561084857600080fd5b61085184610640565b925061085f6020850161069e565b91506106ea60408501610723565b6000806000806060858703121561088357600080fd5b61088c85610640565b9350602085013567ffffffffffffffff8111156108a857600080fd5b8501601f810187136108b957600080fd5b803567ffffffffffffffff8111156108d057600080fd5b8760208284010111156108e257600080fd5b602091909101935091506108f86040860161065c565b905092959194509250565b602080825282516001600160a01b03168282015282015160009061092a6040840182610796565b5061ffff6040840151166060830152606083015160808084015261095160a08401826107aa565b949350505050565b6000806040838503121561096c57600080fd5b61097583610640565b915061069560208401610723565b634e487b7160e01b600052601160045260246000fd5b600064ffffffffff821664ffffffffff81036109b7576109b7610983565b60010192915050565b600063ffffffff821663ffffffff81036109b7576109b7610983565b600181811c908216806109f057607f821691505b602082108103610a1057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b601f821115610a7657806000526020600020601f840160051c81016020851015610a535750805b601f840160051c820191505b81811015610a735760008155600101610a5f565b50505b505050565b815167ffffffffffffffff811115610a9557610a95610a16565b610aa981610aa384546109dc565b84610a2c565b6020601f821160018114610add5760008315610ac55750848201515b600019600385901b1c1916600184901b178455610a73565b600084815260208120601f198516915b82811015610b0d5787850151825560209485019460019092019101610aed565b5084821015610b2b5786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b600061ffff821661ffff81036109b7576109b761098356fea26469706673582212204cd3dc89fa495e4af31394da182a24cefacd6cfeeb1be554b869598f4eeebccf64736f6c634300081a0033", - "nonce": "0x5c", + "input": "0x6080604052348015600f57600080fd5b50610b888061001f6000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c8063c70e012c11610066578063c70e012c14610151578063cead5f7a14610174578063d91c9bad146101c0578063da239bf1146101e0578063f559b79b146101e857600080fd5b8063223094e9146100a3578063256e025a146100ea5780633ddbfa0a146100f257806343e1ebf014610133578063918f867414610148575b600080fd5b6100d26100b136600461066b565b600160209081526000928352604080842090915290825290205461ffff1681565b60405161ffff90911681526020015b60405180910390f35b6100d2602881565b6101266101003660046106b0565b600460209081526000938452604080852082529284528284209052825290205460ff1681565b6040516100e19190610709565b610146610141366004610732565b610230565b005b6100d261271081565b61016461015f36600461076c565b61038d565b6040516100e194939291906107f0565b6101ab610182366004610833565b600260209081526000938452604080852082529284528284209052825290205463ffffffff1681565b60405163ffffffff90911681526020016100e1565b6101d36101ce36600461086d565b610473565b6040516100e19190610903565b6100d2600a81565b61021a6101f6366004610959565b600360209081526000928352604080842090915290825290205464ffffffffff1681565b60405164ffffffffff90911681526020016100e1565b33600090815260036020526040812090846002811115610252576102526106f3565b6002811115610263576102636106f3565b815260208101919091526040016000908120805464ffffffffff169161028883610999565b825464ffffffffff9182166101009390930a9283029190920219909116179055503360009081526004602090815260408083206001600160a01b0385168452825280832061ffff861684529091529020805484919060ff191660018360028111156102f5576102f56106f3565b02179055506001600160a01b038116600090815260026020818152604080842061ffff87168552909152822091908590811115610334576103346106f3565b6002811115610345576103456106f3565b815260208101919091526040016000908120805463ffffffff1691610369836109c0565b91906101000a81548163ffffffff021916908363ffffffff16021790555050505050565b600060205281600052604060002081815481106103a957600080fd5b6000918252602090912060029091020180546001820180546001600160a01b0383169550600160a01b830460ff169450600160a81b90920461ffff1692916103f0906109dc565b80601f016020809104026020016040519081016040528092919081815260200182805461041c906109dc565b80156104695780601f1061043e57610100808354040283529160200191610469565b820191906000526020600020905b81548152906001019060200180831161044c57829003601f168201915b5050505050905084565b60408051608081018252600080825260208201819052918101919091526060808201526040518060800160405280336001600160a01b031681526020018360018111156104c2576104c26106f3565b8152602001600061ffff16815260200185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250506001600160a01b03888116825260208281526040832080546001808201835591855293829020865160029095020180546001600160a01b03198116959094169485178155918601519596508695919450909284926001600160a81b0319161790600160a01b908490811115610581576105816106f3565b02179055506040820151815461ffff909116600160a81b0261ffff60a81b19909116178155606082015160018201906105ba9082610a7b565b5050506001600160a01b03851660009081526001602081905260408220919084908111156105ea576105ea6106f3565b60018111156105fb576105fb6106f3565b815260208101919091526040016000908120805461ffff169161061d83610b3a565b91906101000a81548161ffff021916908361ffff16021790555050949350505050565b80356001600160a01b038116811461065757600080fd5b919050565b80356002811061065757600080fd5b6000806040838503121561067e57600080fd5b61068783610640565b91506106956020840161065c565b90509250929050565b803561ffff8116811461065757600080fd5b6000806000606084860312156106c557600080fd5b6106ce84610640565b92506106dc60208501610640565b91506106ea6040850161069e565b90509250925092565b634e487b7160e01b600052602160045260246000fd5b602081016003831061071d5761071d6106f3565b91905290565b80356003811061065757600080fd5b60008060006060848603121561074757600080fd5b61075084610723565b925061075e6020850161069e565b91506106ea60408501610640565b6000806040838503121561077f57600080fd5b61078883610640565b946020939093013593505050565b600281106107a6576107a66106f3565b9052565b6000815180845260005b818110156107d0576020818501810151868301820152016107b4565b506000602082860101526020601f19601f83011685010191505092915050565b6001600160a01b03851681526108096020820185610796565b61ffff8316604082015260806060820152600061082960808301846107aa565b9695505050505050565b60008060006060848603121561084857600080fd5b61085184610640565b925061085f6020850161069e565b91506106ea60408501610723565b6000806000806060858703121561088357600080fd5b61088c85610640565b9350602085013567ffffffffffffffff8111156108a857600080fd5b8501601f810187136108b957600080fd5b803567ffffffffffffffff8111156108d057600080fd5b8760208284010111156108e257600080fd5b602091909101935091506108f86040860161065c565b905092959194509250565b602080825282516001600160a01b03168282015282015160009061092a6040840182610796565b5061ffff6040840151166060830152606083015160808084015261095160a08401826107aa565b949350505050565b6000806040838503121561096c57600080fd5b61097583610640565b915061069560208401610723565b634e487b7160e01b600052601160045260246000fd5b600064ffffffffff821664ffffffffff81036109b7576109b7610983565b60010192915050565b600063ffffffff821663ffffffff81036109b7576109b7610983565b600181811c908216806109f057607f821691505b602082108103610a1057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b601f821115610a7657806000526020600020601f840160051c81016020851015610a535750805b601f840160051c820191505b81811015610a735760008155600101610a5f565b50505b505050565b815167ffffffffffffffff811115610a9557610a95610a16565b610aa981610aa384546109dc565b84610a2c565b6020601f821160018114610add5760008315610ac55750848201515b600019600385901b1c1916600184901b178455610a73565b600084815260208120601f198516915b82811015610b0d5787850151825560209485019460019092019101610aed565b5084821015610b2b5786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b600061ffff821661ffff81036109b7576109b761098356fea26469706673582212202340c8d771aebc9d6c0a0897bf4b14e70981cf88a2a72e99b7f034da89e57fb664736f6c634300081a0033", + "nonce": "0x1f4", "chainId": "0xaa36a7" }, "additionalContracts": [], @@ -22,25 +22,25 @@ "receipts": [ { "status": "0x1", - "cumulativeGasUsed": "0x5812a0", + "cumulativeGasUsed": "0x891334", "logs": [], "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "type": "0x0", - "transactionHash": "0x38a939f1737f1b2461434242f8d04064118c133ecb3c112f34ea604d2ccd2d7f", - "transactionIndex": "0x1f", - "blockHash": "0xf026727585dbf02ac4952646fb9540708b2fb442632c659fbd1d0722d15dcbdf", - "blockNumber": "0x601b2c", + "type": "0x2", + "transactionHash": "0x38e33b52499d2c18b1676c774b0fdaf0e6cdf157fc3bacd2008c93fc085cc0ef", + "transactionIndex": "0x40", + "blockHash": "0x2804f3fe5b97e9fae5974c61ba90809a64991df9f850984ba2571d18c243e872", + "blockNumber": "0x601b8e", "gasUsed": "0xa8a1d", - "effectiveGasPrice": "0x183b2fca4", - "from": "0xf6da1082b2b8952c73ed7220db5df38aec56a1b2", + "effectiveGasPrice": "0x15ed08428", + "from": "0x199d51a2be04c65f325908911430e6ff79a15ce3", "to": null, - "contractAddress": "0x5c823632d432ab578d584d55809044e5f1a39780" + "contractAddress": "0xf0cba52b7b24277ba894346cc44da27df6993a9b" } ], "libraries": [], "pending": [], "returns": {}, - "timestamp": 1720815359, + "timestamp": 1720816598, "chain": 11155111, - "commit": "9136288" + "commit": "e6f0ddb" } \ No newline at end of file diff --git a/packages/foundry/deployments/11155111.json b/packages/foundry/deployments/11155111.json new file mode 100644 index 0000000..51d245f --- /dev/null +++ b/packages/foundry/deployments/11155111.json @@ -0,0 +1,3 @@ +{ + "networkName": "Sepolia" +} \ No newline at end of file diff --git a/packages/foundry/foundry.toml b/packages/foundry/foundry.toml index 10237cf..e4e495b 100644 --- a/packages/foundry/foundry.toml +++ b/packages/foundry/foundry.toml @@ -5,6 +5,7 @@ libs = ["lib"] fs_permissions = [{ access = "read-write", path = "./"}] [rpc_endpoints] +default_network = "${SEPOLIA_RPC}" sepolia = "${SEPOLIA_RPC}" [etherscan] diff --git a/packages/foundry/lib/openzeppelin-contracts b/packages/foundry/lib/openzeppelin-contracts new file mode 160000 index 0000000..dbb6104 --- /dev/null +++ b/packages/foundry/lib/openzeppelin-contracts @@ -0,0 +1 @@ +Subproject commit dbb6104ce834628e473d2173bbc9d47f81a9eec3 diff --git a/packages/foundry/lib/solidity-bytes-utils b/packages/foundry/lib/solidity-bytes-utils new file mode 160000 index 0000000..e0115c4 --- /dev/null +++ b/packages/foundry/lib/solidity-bytes-utils @@ -0,0 +1 @@ +Subproject commit e0115c4d231910df47ce3b60625ce562fe4af985 diff --git a/packages/foundry/package.json b/packages/foundry/package.json new file mode 100644 index 0000000..e22aacf --- /dev/null +++ b/packages/foundry/package.json @@ -0,0 +1,30 @@ +{ + "name": "@se-2/foundry", + "version": "0.0.1", + "scripts": { + "account": "node script/ListAccount.js", + "chain": "anvil --config-out localhost.json", + "compile": "forge compile", + "deploy": "forge build --build-info --build-info-path out/build-info/ && forge script script/deploy_Notes.s.sol --rpc-url ${1:-default_network} —broadcast —legacy —slow —rpc-url sepolia —verify && node script/generateTsAbis.js", + "deploy:verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --verify ; node script/generateTsAbis.js", + "flatten": "forge flatten", + "fork": "anvil --fork-url ${0:-mainnet} --chain-id 31337 --config-out localhost.json", + "format": "forge fmt && prettier --write ./script/**/*.js", + "generate": "node script/generateAccount.js", + "lint": "forge fmt --check && prettier --check ./script/**/*.js", + "test": "forge test", + "verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/VerifyAll.s.sol --ffi --rpc-url ${1:-default_network}" + }, + "dependencies": { + "dotenv": "~16.3.1", + "envfile": "~6.18.0", + "ethers": "~5.7.1", + "prettier": "~2.8.8", + "qrcode": "~1.5.3", + "toml": "~3.0.0" + }, + "devDependencies": { + "@types/prettier": "2", + "@types/qrcode": "1" + } +} diff --git a/packages/foundry/script/generateTsAbis.js b/packages/foundry/script/generateTsAbis.js new file mode 100644 index 0000000..c91e2dd --- /dev/null +++ b/packages/foundry/script/generateTsAbis.js @@ -0,0 +1,150 @@ +const fs = require("fs"); +const path = require("path"); +//@ts-expect-error This script runs after `forge deploy` therefore its deterministic that it will present +// const deployments = require("../deployments.json"); +const prettier = require("prettier"); + +const generatedContractComment = ` +/** + * This file is autogenerated by Scaffold-ETH. + * You should not edit it manually or your changes might be overwritten. + */ +`; + +function getDirectories(path) { + return fs.readdirSync(path).filter(function (file) { + return fs.statSync(path + "/" + file).isDirectory(); + }); +} +function getFiles(path) { + return fs.readdirSync(path).filter(function (file) { + return fs.statSync(path + "/" + file).isFile(); + }); +} +function getArtifactOfContract(contractName) { + const current_path_to_artifacts = path.join( + __dirname, + "..", + `out/${contractName}.sol` + ); + const artifactJson = JSON.parse( + fs.readFileSync(`${current_path_to_artifacts}/${contractName}.json`) + ); + + return artifactJson; +} + +function getInheritedFromContracts(artifact) { + let inheritedFromContracts = []; + if (artifact?.ast) { + for (const astNode of artifact.ast.nodes) { + if (astNode.nodeType == "ContractDefinition") { + if (astNode.baseContracts.length > 0) { + inheritedFromContracts = astNode.baseContracts.map( + ({ baseName }) => baseName.name + ); + } + } + } + } + return inheritedFromContracts; +} + +function getInheritedFunctions(mainArtifact) { + const inheritedFromContracts = getInheritedFromContracts(mainArtifact); + const inheritedFunctions = {}; + for (const inheritanceContractName of inheritedFromContracts) { + const { + abi, + ast: { absolutePath }, + } = getArtifactOfContract(inheritanceContractName); + for (const abiEntry of abi) { + if (abiEntry.type == "function") { + inheritedFunctions[abiEntry.name] = absolutePath; + } + } + } + return inheritedFunctions; +} + +function main() { + const current_path_to_broadcast = path.join( + __dirname, + "..", + "broadcast/deploy_Notes.s.sol" + ); + const current_path_to_deployments = path.join(__dirname, "..", "deployments"); + + const chains = getDirectories(current_path_to_broadcast); + const Deploymentchains = getFiles(current_path_to_deployments); + + const deployments = {}; + + Deploymentchains.forEach((chain) => { + if (!chain.endsWith(".json")) return; + chain = chain.slice(0, -5); + var deploymentObject = JSON.parse( + fs.readFileSync(`${current_path_to_deployments}/${chain}.json`) + ); + deployments[chain] = deploymentObject; + }); + + const allGeneratedContracts = {}; + + chains.forEach((chain) => { + allGeneratedContracts[chain] = {}; + const broadCastObject = JSON.parse( + fs.readFileSync(`${current_path_to_broadcast}/${chain}/run-latest.json`) + ); + const transactionsCreate = broadCastObject.transactions.filter( + (transaction) => transaction.transactionType == "CREATE" + ); + transactionsCreate.forEach((transaction) => { + const artifact = getArtifactOfContract(transaction.contractName); + allGeneratedContracts[chain][ + deployments[chain][transaction.contractAddress] || + transaction.contractName + ] = { + address: transaction.contractAddress, + abi: artifact.abi, + inheritedFunctions: getInheritedFunctions(artifact), + }; + }); + }); + + console.log(allGeneratedContracts); + + const TARGET_DIR = "../nextjs/contracts/"; + + const fileContent = Object.entries(allGeneratedContracts).reduce( + (content, [chainId, chainConfig]) => { + return `${content}${parseInt(chainId).toFixed(0)}:${JSON.stringify( + chainConfig, + null, + 2 + )},`; + }, + "" + ); + + if (!fs.existsSync(TARGET_DIR)) { + fs.mkdirSync(TARGET_DIR); + } + fs.writeFileSync( + `${TARGET_DIR}deployedContracts.ts`, + prettier.format( + `${generatedContractComment} import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; \n\n + const deployedContracts = {${fileContent}} as const; \n\n export default deployedContracts satisfies GenericContractsDeclaration`, + { + parser: "typescript", + } + ) + ); +} + +try { + main(); +} catch (error) { + console.error(error); + process.exitCode = 1; +} diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index 008d4eb..cd2c5de 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -4,6 +4,273 @@ */ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; -const deployedContracts = {} as const; +const deployedContracts = { + 11155111: { + Notes: { + address: "0xf0cba52b7b24277ba894346cc44da27df6993a9b", + abi: [ + { + type: "function", + name: "DENOMINATOR", + inputs: [], + outputs: [ + { + name: "", + type: "uint16", + internalType: "uint16", + }, + ], + stateMutability: "view", + }, + { + type: "function", + name: "HELPFULNESS_THRESHOLD", + inputs: [], + outputs: [ + { + name: "", + type: "uint16", + internalType: "uint16", + }, + ], + stateMutability: "view", + }, + { + type: "function", + name: "INITIAL_ELIGIBILITY_RATING_THRESHOLD", + inputs: [], + outputs: [ + { + name: "", + type: "uint16", + internalType: "uint16", + }, + ], + stateMutability: "view", + }, + { + type: "function", + name: "amountOfRating", + inputs: [ + { + name: "contractAddress", + type: "address", + internalType: "address", + }, + { + name: "index", + type: "uint16", + internalType: "uint16", + }, + { + name: "rating", + type: "uint8", + internalType: "enum CNDataTypes.Rating", + }, + ], + outputs: [ + { + name: "amount", + type: "uint32", + internalType: "uint32", + }, + ], + stateMutability: "view", + }, + { + type: "function", + name: "notesOf", + inputs: [ + { + name: "contractAddress", + type: "address", + internalType: "address", + }, + { + name: "", + type: "uint256", + internalType: "uint256", + }, + ], + outputs: [ + { + name: "noteWriter", + type: "address", + internalType: "address", + }, + { + name: "sentiment", + type: "uint8", + internalType: "enum CNDataTypes.Sentiment", + }, + { + name: "score", + type: "uint16", + internalType: "uint16", + }, + { + name: "uri", + type: "string", + internalType: "string", + }, + ], + stateMutability: "view", + }, + { + type: "function", + name: "publishNote", + inputs: [ + { + name: "_contractAddress", + type: "address", + internalType: "address", + }, + { + name: "_uri", + type: "string", + internalType: "string", + }, + { + name: "_sentiment", + type: "uint8", + internalType: "enum CNDataTypes.Sentiment", + }, + ], + outputs: [ + { + name: "_note", + type: "tuple", + internalType: "struct CNDataTypes.Note", + components: [ + { + name: "noteWriter", + type: "address", + internalType: "address", + }, + { + name: "sentiment", + type: "uint8", + internalType: "enum CNDataTypes.Sentiment", + }, + { + name: "score", + type: "uint16", + internalType: "uint16", + }, + { + name: "uri", + type: "string", + internalType: "string", + }, + ], + }, + ], + stateMutability: "nonpayable", + }, + { + type: "function", + name: "ratingWeightOf", + inputs: [ + { + name: "user", + type: "address", + internalType: "address", + }, + { + name: "", + type: "uint8", + internalType: "enum CNDataTypes.Rating", + }, + ], + outputs: [ + { + name: "amount", + type: "uint40", + internalType: "uint40", + }, + ], + stateMutability: "view", + }, + { + type: "function", + name: "sentimentOf", + inputs: [ + { + name: "contractAddress", + type: "address", + internalType: "address", + }, + { + name: "sentiment", + type: "uint8", + internalType: "enum CNDataTypes.Sentiment", + }, + ], + outputs: [ + { + name: "amount", + type: "uint16", + internalType: "uint16", + }, + ], + stateMutability: "view", + }, + { + type: "function", + name: "userRatingOfNote", + inputs: [ + { + name: "user", + type: "address", + internalType: "address", + }, + { + name: "contractAddress", + type: "address", + internalType: "address", + }, + { + name: "index", + type: "uint16", + internalType: "uint16", + }, + ], + outputs: [ + { + name: "", + type: "uint8", + internalType: "enum CNDataTypes.Rating", + }, + ], + stateMutability: "view", + }, + { + type: "function", + name: "vote", + inputs: [ + { + name: "_rating", + type: "uint8", + internalType: "enum CNDataTypes.Rating", + }, + { + name: "_noteIndex", + type: "uint16", + internalType: "uint16", + }, + { + name: "_contractAddress", + type: "address", + internalType: "address", + }, + ], + outputs: [], + stateMutability: "nonpayable", + }, + ], + inheritedFunctions: {}, + }, + }, +} as const; export default deployedContracts satisfies GenericContractsDeclaration; From c9f0aa873cc86dd37b7d08c5da6338621b563b57 Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Fri, 12 Jul 2024 22:44:25 +0200 Subject: [PATCH 04/11] scaffold fix 2 --- .husky/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 44d21ba..d0b4caa 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -yarn lint-staged --verbose \ No newline at end of file +# yarn lint-staged --verbose \ No newline at end of file From 7d2a5e98f64eedca5935a465fa8ae63a5549feea Mon Sep 17 00:00:00 2001 From: jacksmithinsulander <666.jack.smith@protonmail.com> Date: Fri, 12 Jul 2024 22:52:29 +0200 Subject: [PATCH 05/11] added a tipping function --- packages/foundry/src/Notes.sol | 55 +++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/packages/foundry/src/Notes.sol b/packages/foundry/src/Notes.sol index aa6c665..aaa568e 100644 --- a/packages/foundry/src/Notes.sol +++ b/packages/foundry/src/Notes.sol @@ -11,27 +11,47 @@ import {CNDataTypes} from "src/libraries/CNDataTypes.sol"; * */ contract Notes { + /// @dev Denominator used for calculating uint16 public constant DENOMINATOR = 10_000; + /// @dev Threshold for being scored helpful aka .40 uint16 public constant HELPFULNESS_THRESHOLD = 40; + /// @dev Threshold to be removed from being helpful aka .10 uint16 public constant INITIAL_ELIGIBILITY_RATING_THRESHOLD = 10; + /// @dev Array of notes for a specific contract address mapping(address contractAddress => CNDataTypes.Note[] note) public notesOf; + /// @dev The amount of posetive / negative sentiment for a specific contract address mapping(address contractAddress => mapping(CNDataTypes.Sentiment sentiment => uint16 amount)) public sentimentOf; + /// @dev The amount of different ratoings for a specific note mapping(address contractAddress => mapping(uint16 index => mapping(CNDataTypes.Rating rating => uint32 amount))) public amountOfRating; + /// @dev The rating weight of a user mapping(address user => mapping(CNDataTypes.Rating => uint40 amount)) public ratingWeightOf; + /// @dev A users rating on a specific note mapping(address user => mapping(address contractAddress => mapping(uint16 index => CNDataTypes.Rating))) public userRatingOfNote; + /** + * @notice + * Allows a user to publish a note for a specific contract + * + * @param _contractAddress address off contract we are about to add a note for + * @param _uri IPFS uri for note + * @param _sentiment if the comment is POSETIVE or NEGATIVE + * + * @return _note the finalized note datastructure + * + */ function publishNote( address _contractAddress, string calldata _uri, CNDataTypes.Sentiment _sentiment ) external returns(CNDataTypes.Note memory _note) { + // Create the note _note = CNDataTypes.Note({ noteWriter: msg.sender, uri: _uri, @@ -39,25 +59,52 @@ contract Notes { sentiment: _sentiment }); + // Push note into the notesOf array for specific contract notesOf[_contractAddress].push(_note); + // Increment the specified sentiment for the contract sentimentOf[_contractAddress][_sentiment]++; } + /** + * @notice + * allows users to vote for a specific note + * + * @param _rating rating to share if note was helpful or not + * @param _noteIndex index of specific note + * @param _contractAddress the contract address with the specific note + * + */ function vote( CNDataTypes.Rating _rating, uint16 _noteIndex, address _contractAddress ) external { + // Update rating Weight of user ratingWeightOf[msg.sender][_rating]++; + // Update voters rating of a note userRatingOfNote[msg.sender][_contractAddress][_noteIndex] = _rating; + // Increment the notes number of _rating choice amountOfRating[_contractAddress][_noteIndex][_rating]++; } - // fucntion tip( - // uint16 _noteIndex, - // address _contractAddress - // ) payable external returns (bool _ok) {} + /** + * @notice + * allows users to tip a note that they found specifically helpful + * + * @param _noteIndex index of note of which writer should be tipped + * @param _contractAddress address of which note is associated + * + * @return _success status if it succeeded or not + * + */ + fucntion tip( + uint16 _noteIndex, + address _contractAddress + ) payable external returns (bool _success) { + // Pay the author of the note + (_success,) = payable(notesOf[_contractAddress][_noteIndex].noteWriter).call{value: msg.value}(""); + } } From d9b016d4071c7cd09c9e66fb69b374b1ea61a8be Mon Sep 17 00:00:00 2001 From: jacksmithinsulander <666.jack.smith@protonmail.com> Date: Fri, 12 Jul 2024 23:23:07 +0200 Subject: [PATCH 06/11] updated contract --- packages/foundry/src/Notes.sol | 30 +++++++++++++++++++-- packages/foundry/src/libraries/CNEvents.sol | 29 ++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 packages/foundry/src/libraries/CNEvents.sol diff --git a/packages/foundry/src/Notes.sol b/packages/foundry/src/Notes.sol index aaa568e..ab565a1 100644 --- a/packages/foundry/src/Notes.sol +++ b/packages/foundry/src/Notes.sol @@ -1,8 +1,9 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: AGPL-3.0 pragma solidity 0.8.26; /* ChainNotes Libraries */ import {CNDataTypes} from "src/libraries/CNDataTypes.sol"; +import {CNEvents} from "src/libraries/CNEvents.sol"; /** * @title Notes @@ -64,6 +65,14 @@ contract Notes { // Increment the specified sentiment for the contract sentimentOf[_contractAddress][_sentiment]++; + + // Emit the NotePublished event + emit CNEvents.NotePublished( + msg.sender, + _contractAddress, + notesOf[_contractAddress].length, + _note + ); } /** @@ -88,6 +97,14 @@ contract Notes { // Increment the notes number of _rating choice amountOfRating[_contractAddress][_noteIndex][_rating]++; + + // Emit Voted event + emit CNEvents.Voted( + msg.sender, + _contractAddress, + _noteIndex, + _rating + ); } /** @@ -100,11 +117,20 @@ contract Notes { * @return _success status if it succeeded or not * */ - fucntion tip( + function tip( uint16 _noteIndex, address _contractAddress ) payable external returns (bool _success) { // Pay the author of the note (_success,) = payable(notesOf[_contractAddress][_noteIndex].noteWriter).call{value: msg.value}(""); + + // Emit Tipped event + emit CNEvents.Tipped( + msg.sender, + notesOf[_contractAddress][_noteIndex].noteWriter, + _contractAddress, + msg.value, + notesOf[_contractAddress][_noteIndex] + ); } } diff --git a/packages/foundry/src/libraries/CNEvents.sol b/packages/foundry/src/libraries/CNEvents.sol new file mode 100644 index 0000000..4d58e46 --- /dev/null +++ b/packages/foundry/src/libraries/CNEvents.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: AGPL-3.0 +pragma solidity 0.8.26; + +import {CNDataTypes} from "src/libraries/CNDataTypes.sol"; + +library CNEvents { + event NotePublished( + address indexed author, + address indexed contractAddress, + uint256 amountOfNotesForContract, + CNDataTypes.Note note + + ); + + event Voted( + address indexed voter, + address indexed contractAddress, + uint16 noteIndex, + CNDataTypes.Rating rating + ); + + event Tipped( + address indexed tipper, + address indexed author, + address indexed contractAddress, + uint256 tipAmount, + CNDataTypes.Note note + ); +} \ No newline at end of file From caea6fc7a2f57796fbac914af6610aa01feab2bf Mon Sep 17 00:00:00 2001 From: jacksmithinsulander <666.jack.smith@protonmail.com> Date: Fri, 12 Jul 2024 23:47:10 +0200 Subject: [PATCH 07/11] retrieval added --- packages/foundry/src/Notes.sol | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/foundry/src/Notes.sol b/packages/foundry/src/Notes.sol index ab565a1..3e705bc 100644 --- a/packages/foundry/src/Notes.sol +++ b/packages/foundry/src/Notes.sol @@ -133,4 +133,8 @@ contract Notes { notesOf[_contractAddress][_noteIndex] ); } + + function retrieveContractNotes(address _contractAddress) external view returns (CNDataTypes.Note[] memory _notes) { + _notes = notesOf[_contractAddress]; + } } From 6793f6bcf2e0b4c5a51ca165f8997caf312cdcae Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Sat, 13 Jul 2024 07:41:09 +0200 Subject: [PATCH 08/11] deploy fix --- .../11155111/run-1720849233.json | 46 ++++ .../11155111/run-latest.json | 32 +-- packages/foundry/package.json | 2 +- .../nextjs/contracts/deployedContracts.ts | 210 +++++++++++++++++- 4 files changed, 272 insertions(+), 18 deletions(-) create mode 100644 packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720849233.json diff --git a/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720849233.json b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720849233.json new file mode 100644 index 0000000..31adffc --- /dev/null +++ b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-1720849233.json @@ -0,0 +1,46 @@ +{ + "transactions": [ + { + "hash": "0x8a29548619651effd24485f586a80ce461e08909565d7bb4e121cbe9d8a03f32", + "transactionType": "CREATE", + "contractName": "Notes", + "contractAddress": "0x62a4d5b0f16d8eb9065310afbb7f2622d981f124", + "function": null, + "arguments": null, + "transaction": { + "from": "0x199d51a2be04c65f325908911430e6ff79a15ce3", + "gas": "0x1461cd", + "value": "0x0", + "input": "0x6080604052348015600f57600080fd5b506111a18061001f6000396000f3fe6080604052600436106100a75760003560e01c8063cead5f7a11610064578063cead5f7a146101cb578063d1d368e714610224578063d306794d14610247578063d91c9bad14610274578063da239bf1146102a1578063f559b79b146102b657600080fd5b8063223094e9146100ac578063256e025a146101005780633ddbfa0a1461011557806343e1ebf014610163578063918f867414610185578063c70e012c1461019b575b600080fd5b3480156100b857600080fd5b506100e86100c7366004610aa2565b600160209081526000928352604080842090915290825290205461ffff1681565b60405161ffff90911681526020015b60405180910390f35b34801561010c57600080fd5b506100e8602881565b34801561012157600080fd5b50610156610130366004610ae7565b600460209081526000938452604080852082529284528284209052825290205460ff1681565b6040516100f79190610b54565b34801561016f57600080fd5b5061018361017e366004610b77565b61030b565b005b34801561019157600080fd5b506100e861271081565b3480156101a757600080fd5b506101bb6101b6366004610bb1565b6104b5565b6040516100f79493929190610c31565b3480156101d757600080fd5b5061020f6101e6366004610c74565b600260209081526000938452604080852082529284528284209052825290205463ffffffff1681565b60405163ffffffff90911681526020016100f7565b610237610232366004610cae565b61059b565b60405190151581526020016100f7565b34801561025357600080fd5b50610267610262366004610cd8565b6106f0565b6040516100f79190610d4c565b34801561028057600080fd5b5061029461028f366004610db1565b610852565b6040516100f79190610e47565b3480156102ad57600080fd5b506100e8600a81565b3480156102c257600080fd5b506102f56102d1366004610e5a565b600360209081526000928352604080842090915290825290205464ffffffffff1681565b60405164ffffffffff90911681526020016100f7565b3360009081526003602052604081209084600281111561032d5761032d610b2a565b600281111561033e5761033e610b2a565b815260208101919091526040016000908120805464ffffffffff169161036383610e9a565b825464ffffffffff9182166101009390930a9283029190920219909116179055503360009081526004602090815260408083206001600160a01b0385168452825280832061ffff861684529091529020805484919060ff191660018360028111156103d0576103d0610b2a565b02179055506001600160a01b038116600090815260026020818152604080842061ffff8716855290915282209190859081111561040f5761040f610b2a565b600281111561042057610420610b2a565b815260208101919091526040016000908120805463ffffffff169161044483610ec1565b91906101000a81548163ffffffff021916908363ffffffff16021790555050806001600160a01b0316336001600160a01b03167fd7606eeec49af0ac1a6036583ecf7df49a186152ca6b5c2b22c1b67144f8814084866040516104a8929190610edd565b60405180910390a3505050565b600060205281600052604060002081815481106104d157600080fd5b6000918252602090912060029091020180546001820180546001600160a01b0383169550600160a01b830460ff169450600160a81b90920461ffff16929161051890610ef5565b80601f016020809104026020016040519081016040528092919081815260200182805461054490610ef5565b80156105915780601f1061056657610100808354040283529160200191610591565b820191906000526020600020905b81548152906001019060200180831161057457829003601f168201915b5050505050905084565b6001600160a01b0381166000908152602081905260408120805461ffff85169081106105c9576105c9610f2f565b600091825260208220600290910201546040516001600160a01b039091169134919081818185875af1925050503d8060008114610622576040519150601f19603f3d011682016040523d82523d6000602084013e610627565b606091505b50506001600160a01b03831660008181526020819052604090208054929350909161ffff861690811061065c5761065c610f2f565b600091825260208083206002909202909101546001600160a01b0386811684529183905260409092208054919092169133917f57053f48567dea2e75619fde8276ff7c003c914c887670fc4d9b188161df4fdf91349161ffff8a169081106106c6576106c6610f2f565b90600052602060002090600202016040516106e2929190610f45565b60405180910390a492915050565b6001600160a01b038116600090815260208181526040808320805482518185028101850190935280835260609492939192909184015b8282101561084757600084815260209081902060408051608081019091526002850290910180546001600160a01b03811683529192909190830190600160a01b900460ff16600181111561077c5761077c610b2a565b600181111561078d5761078d610b2a565b81528154600160a81b900461ffff1660208201526001820180546040909201916107b690610ef5565b80601f01602080910402602001604051908101604052809291908181526020018280546107e290610ef5565b801561082f5780601f106108045761010080835404028352916020019161082f565b820191906000526020600020905b81548152906001019060200180831161081257829003601f168201915b50505050508152505081526020019060010190610726565b505050509050919050565b60408051608081018252600080825260208201819052918101919091526060808201526040518060800160405280336001600160a01b031681526020018360018111156108a1576108a1610b2a565b8152602001600061ffff16815260200185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250506001600160a01b03888116825260208281526040832080546001808201835591855293829020865160029095020180546001600160a01b03198116959094169485178155918601519596508695919450909284926001600160a81b0319161790600160a01b90849081111561096057610960610b2a565b02179055506040820151815461ffff909116600160a81b0261ffff60a81b1990911617815560608201516001820190610999908261107b565b5050506001600160a01b03851660009081526001602081905260408220919084908111156109c9576109c9610b2a565b60018111156109da576109da610b2a565b815260208101919091526040016000908120805461ffff16916109fc8361113a565b825461ffff9182166101009390930a9283029190920219909116179055506001600160a01b0385166000818152602081905260409081902054905133917f708b39c063b29363eb66b5e7aa513c18fdc10c034666e7e1de252ab7f085ee6d91610a6791908690611152565b60405180910390a3949350505050565b80356001600160a01b0381168114610a8e57600080fd5b919050565b803560028110610a8e57600080fd5b60008060408385031215610ab557600080fd5b610abe83610a77565b9150610acc60208401610a93565b90509250929050565b803561ffff81168114610a8e57600080fd5b600080600060608486031215610afc57600080fd5b610b0584610a77565b9250610b1360208501610a77565b9150610b2160408501610ad5565b90509250925092565b634e487b7160e01b600052602160045260246000fd5b60038110610b5057610b50610b2a565b9052565b60208101610b628284610b40565b92915050565b803560038110610a8e57600080fd5b600080600060608486031215610b8c57600080fd5b610b9584610b68565b9250610ba360208501610ad5565b9150610b2160408501610a77565b60008060408385031215610bc457600080fd5b610bcd83610a77565b946020939093013593505050565b60028110610b5057610b50610b2a565b6000815180845260005b81811015610c1157602081850181015186830182015201610bf5565b506000602082860101526020601f19601f83011685010191505092915050565b6001600160a01b0385168152610c4a6020820185610bdb565b61ffff83166040820152608060608201526000610c6a6080830184610beb565b9695505050505050565b600080600060608486031215610c8957600080fd5b610c9284610a77565b9250610ca060208501610ad5565b9150610b2160408501610b68565b60008060408385031215610cc157600080fd5b610cca83610ad5565b9150610acc60208401610a77565b600060208284031215610cea57600080fd5b610cf382610a77565b9392505050565b80516001600160a01b03168252602080820151600091610d1c90850182610bdb565b5061ffff6040830151166040840152606082015160806060850152610d446080850182610beb565b949350505050565b6000602082016020835280845180835260408501915060408160051b86010192506020860160005b82811015610da557603f19878603018452610d90858351610cfa565b94506020938401939190910190600101610d74565b50929695505050505050565b60008060008060608587031215610dc757600080fd5b610dd085610a77565b9350602085013567ffffffffffffffff811115610dec57600080fd5b8501601f81018713610dfd57600080fd5b803567ffffffffffffffff811115610e1457600080fd5b876020828401011115610e2657600080fd5b60209190910193509150610e3c60408601610a93565b905092959194509250565b602081526000610cf36020830184610cfa565b60008060408385031215610e6d57600080fd5b610e7683610a77565b9150610acc60208401610b68565b634e487b7160e01b600052601160045260246000fd5b600064ffffffffff821664ffffffffff8103610eb857610eb8610e84565b60010192915050565b600063ffffffff821663ffffffff8103610eb857610eb8610e84565b61ffff8316815260408101610cf36020830184610b40565b600181811c90821680610f0957607f821691505b602082108103610f2957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052603260045260246000fd5b828152604060208201526000825460018060a01b0381166040840152610f746060840160ff8360a01c16610bdb565b61ffff8160a81c1660808401525060018301608060a084015260008154610f9a81610ef5565b8060c08701526001821660008114610fb95760018114610fd557611009565b60ff19831660e088015260e082151560051b8801019350611009565b84600052602060002060005b8381101561100057815489820160e00152600190910190602001610fe1565b880160e0019450505b5091979650505050505050565b634e487b7160e01b600052604160045260246000fd5b601f82111561107657806000526020600020601f840160051c810160208510156110535750805b601f840160051c820191505b81811015611073576000815560010161105f565b50505b505050565b815167ffffffffffffffff81111561109557611095611016565b6110a9816110a38454610ef5565b8461102c565b6020601f8211600181146110dd57600083156110c55750848201515b600019600385901b1c1916600184901b178455611073565b600084815260208120601f198516915b8281101561110d57878501518255602094850194600190920191016110ed565b508482101561112b5786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b600061ffff821661ffff8103610eb857610eb8610e84565b828152604060208201526000610d446040830184610cfa56fea2646970667358221220b9632d064543922677c27173e27e640029bbf9d44f89275199b41a35cfbea63e64736f6c634300081a0033", + "nonce": "0x1f8", + "chainId": "0xaa36a7" + }, + "additionalContracts": [], + "isFixedGasLimit": false + } + ], + "receipts": [ + { + "status": "0x1", + "cumulativeGasUsed": "0x96132e", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "type": "0x0", + "transactionHash": "0x8a29548619651effd24485f586a80ce461e08909565d7bb4e121cbe9d8a03f32", + "transactionIndex": "0x48", + "blockHash": "0x2c9216bf8ed51991a702f33b048cb3b6d419d2e3685e15ccef88e2b404864d52", + "blockNumber": "0x602507", + "gasUsed": "0xfaece", + "effectiveGasPrice": "0xf8efb827", + "from": "0x199d51a2be04c65f325908911430e6ff79a15ce3", + "to": null, + "contractAddress": "0x62a4d5b0f16d8eb9065310afbb7f2622d981f124" + } + ], + "libraries": [], + "pending": [], + "returns": {}, + "timestamp": 1720849233, + "chain": 11155111, + "commit": "caea6fc" +} \ No newline at end of file diff --git a/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json index 3c6c835..31adffc 100644 --- a/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json +++ b/packages/foundry/broadcast/deploy_Notes.s.sol/11155111/run-latest.json @@ -1,18 +1,18 @@ { "transactions": [ { - "hash": "0x38e33b52499d2c18b1676c774b0fdaf0e6cdf157fc3bacd2008c93fc085cc0ef", + "hash": "0x8a29548619651effd24485f586a80ce461e08909565d7bb4e121cbe9d8a03f32", "transactionType": "CREATE", "contractName": "Notes", - "contractAddress": "0xf0cba52b7b24277ba894346cc44da27df6993a9b", + "contractAddress": "0x62a4d5b0f16d8eb9065310afbb7f2622d981f124", "function": null, "arguments": null, "transaction": { "from": "0x199d51a2be04c65f325908911430e6ff79a15ce3", - "gas": "0xdb297", + "gas": "0x1461cd", "value": "0x0", - "input": "0x6080604052348015600f57600080fd5b50610b888061001f6000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c8063c70e012c11610066578063c70e012c14610151578063cead5f7a14610174578063d91c9bad146101c0578063da239bf1146101e0578063f559b79b146101e857600080fd5b8063223094e9146100a3578063256e025a146100ea5780633ddbfa0a146100f257806343e1ebf014610133578063918f867414610148575b600080fd5b6100d26100b136600461066b565b600160209081526000928352604080842090915290825290205461ffff1681565b60405161ffff90911681526020015b60405180910390f35b6100d2602881565b6101266101003660046106b0565b600460209081526000938452604080852082529284528284209052825290205460ff1681565b6040516100e19190610709565b610146610141366004610732565b610230565b005b6100d261271081565b61016461015f36600461076c565b61038d565b6040516100e194939291906107f0565b6101ab610182366004610833565b600260209081526000938452604080852082529284528284209052825290205463ffffffff1681565b60405163ffffffff90911681526020016100e1565b6101d36101ce36600461086d565b610473565b6040516100e19190610903565b6100d2600a81565b61021a6101f6366004610959565b600360209081526000928352604080842090915290825290205464ffffffffff1681565b60405164ffffffffff90911681526020016100e1565b33600090815260036020526040812090846002811115610252576102526106f3565b6002811115610263576102636106f3565b815260208101919091526040016000908120805464ffffffffff169161028883610999565b825464ffffffffff9182166101009390930a9283029190920219909116179055503360009081526004602090815260408083206001600160a01b0385168452825280832061ffff861684529091529020805484919060ff191660018360028111156102f5576102f56106f3565b02179055506001600160a01b038116600090815260026020818152604080842061ffff87168552909152822091908590811115610334576103346106f3565b6002811115610345576103456106f3565b815260208101919091526040016000908120805463ffffffff1691610369836109c0565b91906101000a81548163ffffffff021916908363ffffffff16021790555050505050565b600060205281600052604060002081815481106103a957600080fd5b6000918252602090912060029091020180546001820180546001600160a01b0383169550600160a01b830460ff169450600160a81b90920461ffff1692916103f0906109dc565b80601f016020809104026020016040519081016040528092919081815260200182805461041c906109dc565b80156104695780601f1061043e57610100808354040283529160200191610469565b820191906000526020600020905b81548152906001019060200180831161044c57829003601f168201915b5050505050905084565b60408051608081018252600080825260208201819052918101919091526060808201526040518060800160405280336001600160a01b031681526020018360018111156104c2576104c26106f3565b8152602001600061ffff16815260200185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250506001600160a01b03888116825260208281526040832080546001808201835591855293829020865160029095020180546001600160a01b03198116959094169485178155918601519596508695919450909284926001600160a81b0319161790600160a01b908490811115610581576105816106f3565b02179055506040820151815461ffff909116600160a81b0261ffff60a81b19909116178155606082015160018201906105ba9082610a7b565b5050506001600160a01b03851660009081526001602081905260408220919084908111156105ea576105ea6106f3565b60018111156105fb576105fb6106f3565b815260208101919091526040016000908120805461ffff169161061d83610b3a565b91906101000a81548161ffff021916908361ffff16021790555050949350505050565b80356001600160a01b038116811461065757600080fd5b919050565b80356002811061065757600080fd5b6000806040838503121561067e57600080fd5b61068783610640565b91506106956020840161065c565b90509250929050565b803561ffff8116811461065757600080fd5b6000806000606084860312156106c557600080fd5b6106ce84610640565b92506106dc60208501610640565b91506106ea6040850161069e565b90509250925092565b634e487b7160e01b600052602160045260246000fd5b602081016003831061071d5761071d6106f3565b91905290565b80356003811061065757600080fd5b60008060006060848603121561074757600080fd5b61075084610723565b925061075e6020850161069e565b91506106ea60408501610640565b6000806040838503121561077f57600080fd5b61078883610640565b946020939093013593505050565b600281106107a6576107a66106f3565b9052565b6000815180845260005b818110156107d0576020818501810151868301820152016107b4565b506000602082860101526020601f19601f83011685010191505092915050565b6001600160a01b03851681526108096020820185610796565b61ffff8316604082015260806060820152600061082960808301846107aa565b9695505050505050565b60008060006060848603121561084857600080fd5b61085184610640565b925061085f6020850161069e565b91506106ea60408501610723565b6000806000806060858703121561088357600080fd5b61088c85610640565b9350602085013567ffffffffffffffff8111156108a857600080fd5b8501601f810187136108b957600080fd5b803567ffffffffffffffff8111156108d057600080fd5b8760208284010111156108e257600080fd5b602091909101935091506108f86040860161065c565b905092959194509250565b602080825282516001600160a01b03168282015282015160009061092a6040840182610796565b5061ffff6040840151166060830152606083015160808084015261095160a08401826107aa565b949350505050565b6000806040838503121561096c57600080fd5b61097583610640565b915061069560208401610723565b634e487b7160e01b600052601160045260246000fd5b600064ffffffffff821664ffffffffff81036109b7576109b7610983565b60010192915050565b600063ffffffff821663ffffffff81036109b7576109b7610983565b600181811c908216806109f057607f821691505b602082108103610a1057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b601f821115610a7657806000526020600020601f840160051c81016020851015610a535750805b601f840160051c820191505b81811015610a735760008155600101610a5f565b50505b505050565b815167ffffffffffffffff811115610a9557610a95610a16565b610aa981610aa384546109dc565b84610a2c565b6020601f821160018114610add5760008315610ac55750848201515b600019600385901b1c1916600184901b178455610a73565b600084815260208120601f198516915b82811015610b0d5787850151825560209485019460019092019101610aed565b5084821015610b2b5786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b600061ffff821661ffff81036109b7576109b761098356fea26469706673582212202340c8d771aebc9d6c0a0897bf4b14e70981cf88a2a72e99b7f034da89e57fb664736f6c634300081a0033", - "nonce": "0x1f4", + "input": "0x6080604052348015600f57600080fd5b506111a18061001f6000396000f3fe6080604052600436106100a75760003560e01c8063cead5f7a11610064578063cead5f7a146101cb578063d1d368e714610224578063d306794d14610247578063d91c9bad14610274578063da239bf1146102a1578063f559b79b146102b657600080fd5b8063223094e9146100ac578063256e025a146101005780633ddbfa0a1461011557806343e1ebf014610163578063918f867414610185578063c70e012c1461019b575b600080fd5b3480156100b857600080fd5b506100e86100c7366004610aa2565b600160209081526000928352604080842090915290825290205461ffff1681565b60405161ffff90911681526020015b60405180910390f35b34801561010c57600080fd5b506100e8602881565b34801561012157600080fd5b50610156610130366004610ae7565b600460209081526000938452604080852082529284528284209052825290205460ff1681565b6040516100f79190610b54565b34801561016f57600080fd5b5061018361017e366004610b77565b61030b565b005b34801561019157600080fd5b506100e861271081565b3480156101a757600080fd5b506101bb6101b6366004610bb1565b6104b5565b6040516100f79493929190610c31565b3480156101d757600080fd5b5061020f6101e6366004610c74565b600260209081526000938452604080852082529284528284209052825290205463ffffffff1681565b60405163ffffffff90911681526020016100f7565b610237610232366004610cae565b61059b565b60405190151581526020016100f7565b34801561025357600080fd5b50610267610262366004610cd8565b6106f0565b6040516100f79190610d4c565b34801561028057600080fd5b5061029461028f366004610db1565b610852565b6040516100f79190610e47565b3480156102ad57600080fd5b506100e8600a81565b3480156102c257600080fd5b506102f56102d1366004610e5a565b600360209081526000928352604080842090915290825290205464ffffffffff1681565b60405164ffffffffff90911681526020016100f7565b3360009081526003602052604081209084600281111561032d5761032d610b2a565b600281111561033e5761033e610b2a565b815260208101919091526040016000908120805464ffffffffff169161036383610e9a565b825464ffffffffff9182166101009390930a9283029190920219909116179055503360009081526004602090815260408083206001600160a01b0385168452825280832061ffff861684529091529020805484919060ff191660018360028111156103d0576103d0610b2a565b02179055506001600160a01b038116600090815260026020818152604080842061ffff8716855290915282209190859081111561040f5761040f610b2a565b600281111561042057610420610b2a565b815260208101919091526040016000908120805463ffffffff169161044483610ec1565b91906101000a81548163ffffffff021916908363ffffffff16021790555050806001600160a01b0316336001600160a01b03167fd7606eeec49af0ac1a6036583ecf7df49a186152ca6b5c2b22c1b67144f8814084866040516104a8929190610edd565b60405180910390a3505050565b600060205281600052604060002081815481106104d157600080fd5b6000918252602090912060029091020180546001820180546001600160a01b0383169550600160a01b830460ff169450600160a81b90920461ffff16929161051890610ef5565b80601f016020809104026020016040519081016040528092919081815260200182805461054490610ef5565b80156105915780601f1061056657610100808354040283529160200191610591565b820191906000526020600020905b81548152906001019060200180831161057457829003601f168201915b5050505050905084565b6001600160a01b0381166000908152602081905260408120805461ffff85169081106105c9576105c9610f2f565b600091825260208220600290910201546040516001600160a01b039091169134919081818185875af1925050503d8060008114610622576040519150601f19603f3d011682016040523d82523d6000602084013e610627565b606091505b50506001600160a01b03831660008181526020819052604090208054929350909161ffff861690811061065c5761065c610f2f565b600091825260208083206002909202909101546001600160a01b0386811684529183905260409092208054919092169133917f57053f48567dea2e75619fde8276ff7c003c914c887670fc4d9b188161df4fdf91349161ffff8a169081106106c6576106c6610f2f565b90600052602060002090600202016040516106e2929190610f45565b60405180910390a492915050565b6001600160a01b038116600090815260208181526040808320805482518185028101850190935280835260609492939192909184015b8282101561084757600084815260209081902060408051608081019091526002850290910180546001600160a01b03811683529192909190830190600160a01b900460ff16600181111561077c5761077c610b2a565b600181111561078d5761078d610b2a565b81528154600160a81b900461ffff1660208201526001820180546040909201916107b690610ef5565b80601f01602080910402602001604051908101604052809291908181526020018280546107e290610ef5565b801561082f5780601f106108045761010080835404028352916020019161082f565b820191906000526020600020905b81548152906001019060200180831161081257829003601f168201915b50505050508152505081526020019060010190610726565b505050509050919050565b60408051608081018252600080825260208201819052918101919091526060808201526040518060800160405280336001600160a01b031681526020018360018111156108a1576108a1610b2a565b8152602001600061ffff16815260200185858080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250506001600160a01b03888116825260208281526040832080546001808201835591855293829020865160029095020180546001600160a01b03198116959094169485178155918601519596508695919450909284926001600160a81b0319161790600160a01b90849081111561096057610960610b2a565b02179055506040820151815461ffff909116600160a81b0261ffff60a81b1990911617815560608201516001820190610999908261107b565b5050506001600160a01b03851660009081526001602081905260408220919084908111156109c9576109c9610b2a565b60018111156109da576109da610b2a565b815260208101919091526040016000908120805461ffff16916109fc8361113a565b825461ffff9182166101009390930a9283029190920219909116179055506001600160a01b0385166000818152602081905260409081902054905133917f708b39c063b29363eb66b5e7aa513c18fdc10c034666e7e1de252ab7f085ee6d91610a6791908690611152565b60405180910390a3949350505050565b80356001600160a01b0381168114610a8e57600080fd5b919050565b803560028110610a8e57600080fd5b60008060408385031215610ab557600080fd5b610abe83610a77565b9150610acc60208401610a93565b90509250929050565b803561ffff81168114610a8e57600080fd5b600080600060608486031215610afc57600080fd5b610b0584610a77565b9250610b1360208501610a77565b9150610b2160408501610ad5565b90509250925092565b634e487b7160e01b600052602160045260246000fd5b60038110610b5057610b50610b2a565b9052565b60208101610b628284610b40565b92915050565b803560038110610a8e57600080fd5b600080600060608486031215610b8c57600080fd5b610b9584610b68565b9250610ba360208501610ad5565b9150610b2160408501610a77565b60008060408385031215610bc457600080fd5b610bcd83610a77565b946020939093013593505050565b60028110610b5057610b50610b2a565b6000815180845260005b81811015610c1157602081850181015186830182015201610bf5565b506000602082860101526020601f19601f83011685010191505092915050565b6001600160a01b0385168152610c4a6020820185610bdb565b61ffff83166040820152608060608201526000610c6a6080830184610beb565b9695505050505050565b600080600060608486031215610c8957600080fd5b610c9284610a77565b9250610ca060208501610ad5565b9150610b2160408501610b68565b60008060408385031215610cc157600080fd5b610cca83610ad5565b9150610acc60208401610a77565b600060208284031215610cea57600080fd5b610cf382610a77565b9392505050565b80516001600160a01b03168252602080820151600091610d1c90850182610bdb565b5061ffff6040830151166040840152606082015160806060850152610d446080850182610beb565b949350505050565b6000602082016020835280845180835260408501915060408160051b86010192506020860160005b82811015610da557603f19878603018452610d90858351610cfa565b94506020938401939190910190600101610d74565b50929695505050505050565b60008060008060608587031215610dc757600080fd5b610dd085610a77565b9350602085013567ffffffffffffffff811115610dec57600080fd5b8501601f81018713610dfd57600080fd5b803567ffffffffffffffff811115610e1457600080fd5b876020828401011115610e2657600080fd5b60209190910193509150610e3c60408601610a93565b905092959194509250565b602081526000610cf36020830184610cfa565b60008060408385031215610e6d57600080fd5b610e7683610a77565b9150610acc60208401610b68565b634e487b7160e01b600052601160045260246000fd5b600064ffffffffff821664ffffffffff8103610eb857610eb8610e84565b60010192915050565b600063ffffffff821663ffffffff8103610eb857610eb8610e84565b61ffff8316815260408101610cf36020830184610b40565b600181811c90821680610f0957607f821691505b602082108103610f2957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052603260045260246000fd5b828152604060208201526000825460018060a01b0381166040840152610f746060840160ff8360a01c16610bdb565b61ffff8160a81c1660808401525060018301608060a084015260008154610f9a81610ef5565b8060c08701526001821660008114610fb95760018114610fd557611009565b60ff19831660e088015260e082151560051b8801019350611009565b84600052602060002060005b8381101561100057815489820160e00152600190910190602001610fe1565b880160e0019450505b5091979650505050505050565b634e487b7160e01b600052604160045260246000fd5b601f82111561107657806000526020600020601f840160051c810160208510156110535750805b601f840160051c820191505b81811015611073576000815560010161105f565b50505b505050565b815167ffffffffffffffff81111561109557611095611016565b6110a9816110a38454610ef5565b8461102c565b6020601f8211600181146110dd57600083156110c55750848201515b600019600385901b1c1916600184901b178455611073565b600084815260208120601f198516915b8281101561110d57878501518255602094850194600190920191016110ed565b508482101561112b5786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b600061ffff821661ffff8103610eb857610eb8610e84565b828152604060208201526000610d446040830184610cfa56fea2646970667358221220b9632d064543922677c27173e27e640029bbf9d44f89275199b41a35cfbea63e64736f6c634300081a0033", + "nonce": "0x1f8", "chainId": "0xaa36a7" }, "additionalContracts": [], @@ -22,25 +22,25 @@ "receipts": [ { "status": "0x1", - "cumulativeGasUsed": "0x891334", + "cumulativeGasUsed": "0x96132e", "logs": [], "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "type": "0x2", - "transactionHash": "0x38e33b52499d2c18b1676c774b0fdaf0e6cdf157fc3bacd2008c93fc085cc0ef", - "transactionIndex": "0x40", - "blockHash": "0x2804f3fe5b97e9fae5974c61ba90809a64991df9f850984ba2571d18c243e872", - "blockNumber": "0x601b8e", - "gasUsed": "0xa8a1d", - "effectiveGasPrice": "0x15ed08428", + "type": "0x0", + "transactionHash": "0x8a29548619651effd24485f586a80ce461e08909565d7bb4e121cbe9d8a03f32", + "transactionIndex": "0x48", + "blockHash": "0x2c9216bf8ed51991a702f33b048cb3b6d419d2e3685e15ccef88e2b404864d52", + "blockNumber": "0x602507", + "gasUsed": "0xfaece", + "effectiveGasPrice": "0xf8efb827", "from": "0x199d51a2be04c65f325908911430e6ff79a15ce3", "to": null, - "contractAddress": "0xf0cba52b7b24277ba894346cc44da27df6993a9b" + "contractAddress": "0x62a4d5b0f16d8eb9065310afbb7f2622d981f124" } ], "libraries": [], "pending": [], "returns": {}, - "timestamp": 1720816598, + "timestamp": 1720849233, "chain": 11155111, - "commit": "e6f0ddb" + "commit": "caea6fc" } \ No newline at end of file diff --git a/packages/foundry/package.json b/packages/foundry/package.json index e22aacf..ca27156 100644 --- a/packages/foundry/package.json +++ b/packages/foundry/package.json @@ -5,7 +5,7 @@ "account": "node script/ListAccount.js", "chain": "anvil --config-out localhost.json", "compile": "forge compile", - "deploy": "forge build --build-info --build-info-path out/build-info/ && forge script script/deploy_Notes.s.sol --rpc-url ${1:-default_network} —broadcast —legacy —slow —rpc-url sepolia —verify && node script/generateTsAbis.js", + "deploy": "forge build --build-info --build-info-path out/build-info/ && forge script script/deploy_Notes.s.sol --rpc-url ${1:-default_network} --broadcast --legacy --slow --verify && node script/generateTsAbis.js", "deploy:verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --verify ; node script/generateTsAbis.js", "flatten": "forge flatten", "fork": "anvil --fork-url ${0:-mainnet} --chain-id 31337 --config-out localhost.json", diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index cd2c5de..1d6ed07 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -7,7 +7,7 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; const deployedContracts = { 11155111: { Notes: { - address: "0xf0cba52b7b24277ba894346cc44da27df6993a9b", + address: "0x62a4d5b0f16d8eb9065310afbb7f2622d981f124", abi: [ { type: "function", @@ -191,6 +191,47 @@ const deployedContracts = { ], stateMutability: "view", }, + { + type: "function", + name: "retrieveContractNotes", + inputs: [ + { + name: "_contractAddress", + type: "address", + internalType: "address", + }, + ], + outputs: [ + { + name: "_notes", + type: "tuple[]", + internalType: "struct CNDataTypes.Note[]", + components: [ + { + name: "noteWriter", + type: "address", + internalType: "address", + }, + { + name: "sentiment", + type: "uint8", + internalType: "enum CNDataTypes.Sentiment", + }, + { + name: "score", + type: "uint16", + internalType: "uint16", + }, + { + name: "uri", + type: "string", + internalType: "string", + }, + ], + }, + ], + stateMutability: "view", + }, { type: "function", name: "sentimentOf", @@ -215,6 +256,30 @@ const deployedContracts = { ], stateMutability: "view", }, + { + type: "function", + name: "tip", + inputs: [ + { + name: "_noteIndex", + type: "uint16", + internalType: "uint16", + }, + { + name: "_contractAddress", + type: "address", + internalType: "address", + }, + ], + outputs: [ + { + name: "_success", + type: "bool", + internalType: "bool", + }, + ], + stateMutability: "payable", + }, { type: "function", name: "userRatingOfNote", @@ -267,6 +332,149 @@ const deployedContracts = { outputs: [], stateMutability: "nonpayable", }, + { + type: "event", + name: "NotePublished", + inputs: [ + { + name: "author", + type: "address", + indexed: true, + internalType: "address", + }, + { + name: "contractAddress", + type: "address", + indexed: true, + internalType: "address", + }, + { + name: "amountOfNotesForContract", + type: "uint256", + indexed: false, + internalType: "uint256", + }, + { + name: "note", + type: "tuple", + indexed: false, + internalType: "struct CNDataTypes.Note", + components: [ + { + name: "noteWriter", + type: "address", + internalType: "address", + }, + { + name: "sentiment", + type: "uint8", + internalType: "enum CNDataTypes.Sentiment", + }, + { + name: "score", + type: "uint16", + internalType: "uint16", + }, + { + name: "uri", + type: "string", + internalType: "string", + }, + ], + }, + ], + anonymous: false, + }, + { + type: "event", + name: "Tipped", + inputs: [ + { + name: "tipper", + type: "address", + indexed: true, + internalType: "address", + }, + { + name: "author", + type: "address", + indexed: true, + internalType: "address", + }, + { + name: "contractAddress", + type: "address", + indexed: true, + internalType: "address", + }, + { + name: "tipAmount", + type: "uint256", + indexed: false, + internalType: "uint256", + }, + { + name: "note", + type: "tuple", + indexed: false, + internalType: "struct CNDataTypes.Note", + components: [ + { + name: "noteWriter", + type: "address", + internalType: "address", + }, + { + name: "sentiment", + type: "uint8", + internalType: "enum CNDataTypes.Sentiment", + }, + { + name: "score", + type: "uint16", + internalType: "uint16", + }, + { + name: "uri", + type: "string", + internalType: "string", + }, + ], + }, + ], + anonymous: false, + }, + { + type: "event", + name: "Voted", + inputs: [ + { + name: "voter", + type: "address", + indexed: true, + internalType: "address", + }, + { + name: "contractAddress", + type: "address", + indexed: true, + internalType: "address", + }, + { + name: "noteIndex", + type: "uint16", + indexed: false, + internalType: "uint16", + }, + { + name: "rating", + type: "uint8", + indexed: false, + internalType: "enum CNDataTypes.Rating", + }, + ], + anonymous: false, + }, ], inheritedFunctions: {}, }, From 13f540d65fab8ebc3513aa98f0cccdeb0a9f4cb7 Mon Sep 17 00:00:00 2001 From: jacksmithinsulander <666.jack.smith@protonmail.com> Date: Sat, 13 Jul 2024 09:23:41 +0200 Subject: [PATCH 09/11] fixes with the score --- packages/foundry/src/Notes.sol | 42 +++++++++++++++++++ .../foundry/src/libraries/CNDataTypes.sol | 5 +++ packages/foundry/src/libraries/CNEvents.sol | 3 +- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/foundry/src/Notes.sol b/packages/foundry/src/Notes.sol index 3e705bc..38bf74d 100644 --- a/packages/foundry/src/Notes.sol +++ b/packages/foundry/src/Notes.sol @@ -30,6 +30,8 @@ contract Notes { /// @dev The amount of different ratoings for a specific note mapping(address contractAddress => mapping(uint16 index => mapping(CNDataTypes.Rating rating => uint32 amount))) public amountOfRating; + mapping(address contractAddress => mapping(uint16 index => CNDataTypes.NoteScore)) public scoreInfoOf; + /// @dev The rating weight of a user mapping(address user => mapping(CNDataTypes.Rating => uint40 amount)) public ratingWeightOf; @@ -98,6 +100,46 @@ contract Notes { // Increment the notes number of _rating choice amountOfRating[_contractAddress][_noteIndex][_rating]++; + // Get total votes for note + uint32 totalVotes = + amountOfRating[_contractAddress][_noteIndex][CNDataTypes.Rating.HELPFUL] + + amountOfRating[_contractAddress][_noteIndex][CNDataTypes.Rating.SOMEWHAT_HELPFUL] + + amountOfRating[_contractAddress][_noteIndex][CNDataTypes.Rating.NOT_HELPFUL]; + + // Instantiate score + uint256 score; + + // If totalvotes is more than 0... + if (totalVotes > 0) { + // ... calculate the score ... + score = ((amountOfRating[_contractAddress][_noteIndex][CNDataTypes.Rating.HELPFUL] * 100) + + (amountOfRating[_contractAddress][_noteIndex][CNDataTypes.Rating.SOMEWHAT_HELPFUL] * 50)) + / totalVotes; + // ... else... + } else { + // ... score is 0 .. + score = 0; + } + + // Instantiate new a new NoteScore datatype + CNDataTypes.NoteScore newScore; + + // Set the calculated score + newScore.score = score; + + // Checking if note should be considered helpful + if (!newScore.consideredHelpful && score > 40 && totalVotes > 10) { + // And if so toggle the status + newScore.consideredHelpful = true; + // Checking if note should be downgraded as not helpful + } else if (newScore.consideredHelpful && score < 10 %% totalVotes > 10 ) { + // And if so toggle the status + newScore.consideredHelpful = false; + } + + // Set the score info to the note + scoreInfoOf[_contractAddress][_noteIndex] = newScore; + // Emit Voted event emit CNEvents.Voted( msg.sender, diff --git a/packages/foundry/src/libraries/CNDataTypes.sol b/packages/foundry/src/libraries/CNDataTypes.sol index 6ee0062..70d2111 100644 --- a/packages/foundry/src/libraries/CNDataTypes.sol +++ b/packages/foundry/src/libraries/CNDataTypes.sol @@ -9,6 +9,11 @@ library CNDataTypes { string uri; } + struct NoteScore { + uint256 score; + bool consideredHelpful; + } + enum Rating { HELPFUL, NOT_HELPFUL, diff --git a/packages/foundry/src/libraries/CNEvents.sol b/packages/foundry/src/libraries/CNEvents.sol index 4d58e46..207fe34 100644 --- a/packages/foundry/src/libraries/CNEvents.sol +++ b/packages/foundry/src/libraries/CNEvents.sol @@ -16,7 +16,8 @@ library CNEvents { address indexed voter, address indexed contractAddress, uint16 noteIndex, - CNDataTypes.Rating rating + CNDataTypes.Rating rating, + uint256 score ); event Tipped( From 4b31643e39c4a7865872f9527b50cdd64a4f566a Mon Sep 17 00:00:00 2001 From: jacksmithinsulander <666.jack.smith@protonmail.com> Date: Sat, 13 Jul 2024 09:36:25 +0200 Subject: [PATCH 10/11] event fix --- packages/foundry/src/Notes.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/foundry/src/Notes.sol b/packages/foundry/src/Notes.sol index 38bf74d..e8ee4f7 100644 --- a/packages/foundry/src/Notes.sol +++ b/packages/foundry/src/Notes.sol @@ -145,7 +145,8 @@ contract Notes { msg.sender, _contractAddress, _noteIndex, - _rating + _rating, + score ); } From bf40754408df5b1eec13d51ad73a12feee4556ec Mon Sep 17 00:00:00 2001 From: jacksmithinsulander <666.jack.smith@protonmail.com> Date: Sat, 13 Jul 2024 10:22:53 +0200 Subject: [PATCH 11/11] started doing multichain setup --- packages/foundry/foundry.toml | 10 +++++++++- packages/foundry/package.json | 5 +++-- packages/foundry/src/Notes.sol | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/foundry/foundry.toml b/packages/foundry/foundry.toml index e4e495b..37e6488 100644 --- a/packages/foundry/foundry.toml +++ b/packages/foundry/foundry.toml @@ -5,8 +5,16 @@ libs = ["lib"] fs_permissions = [{ access = "read-write", path = "./"}] [rpc_endpoints] -default_network = "${SEPOLIA_RPC}" +#default_network = "${SEPOLIA_RPC}" sepolia = "${SEPOLIA_RPC}" +base-sepolia = "${BASE_SEPOLIA_RPC}" +arbitrum-sepolia = "${ARBITRUM_SEPOLIA_RPC}" +morph-holesky = "${MORPH_HOLESKY_RPC}" +scroll-sepolia = "${SCROLL_SEPOLIA_RPC}" +linea-sepolia = "${LINNEA_SEPOLIA_RPC}" +zircuit = "${ZIRCUIT_TESTNET_RPC}" +apechain = "${APECHAIN_JENKINS_RPC}" +zero-sepolia = "${ZERO_SEPOLIA_RPC}" [etherscan] sepolia = { key = "${SEPOLIA_API_KEY}", url = "https://api-sepolia.etherscan.io/api" } diff --git a/packages/foundry/package.json b/packages/foundry/package.json index ca27156..d025bb8 100644 --- a/packages/foundry/package.json +++ b/packages/foundry/package.json @@ -5,8 +5,9 @@ "account": "node script/ListAccount.js", "chain": "anvil --config-out localhost.json", "compile": "forge compile", - "deploy": "forge build --build-info --build-info-path out/build-info/ && forge script script/deploy_Notes.s.sol --rpc-url ${1:-default_network} --broadcast --legacy --slow --verify && node script/generateTsAbis.js", - "deploy:verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --verify ; node script/generateTsAbis.js", + "deploy": "forge build --build-info --build-info-path out/build-info/ && forge script script/deploy_Notes.s.sol --rpc-url ${1:-sepolia} --broadcast --legacy --slow --verify && node script/generateTsAbis.js", + "deploy-test": "forge build --build-info --build-info-path out/build-info/ && forge script script/deploy_Notes.s.sol --rpc-url sepolia --broadcast --legacy --slow --verify && node script/generateTsAbis.js", + "deploy:verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-sepolia} --broadcast --verify ; node script/generateTsAbis.js", "flatten": "forge flatten", "fork": "anvil --fork-url ${0:-mainnet} --chain-id 31337 --config-out localhost.json", "format": "forge fmt && prettier --write ./script/**/*.js", diff --git a/packages/foundry/src/Notes.sol b/packages/foundry/src/Notes.sol index e8ee4f7..7f0cd69 100644 --- a/packages/foundry/src/Notes.sol +++ b/packages/foundry/src/Notes.sol @@ -112,8 +112,8 @@ contract Notes { // If totalvotes is more than 0... if (totalVotes > 0) { // ... calculate the score ... - score = ((amountOfRating[_contractAddress][_noteIndex][CNDataTypes.Rating.HELPFUL] * 100) + - (amountOfRating[_contractAddress][_noteIndex][CNDataTypes.Rating.SOMEWHAT_HELPFUL] * 50)) + score = ((amountOfRating[_contractAddress][_noteIndex][CNDataTypes.Rating.HELPFUL] * 80) + + (amountOfRating[_contractAddress][_noteIndex][CNDataTypes.Rating.SOMEWHAT_HELPFUL] * 40)) / totalVotes; // ... else... } else {