From 382a5ba6ac1ba2dd1e4de1adffd083a2db1d0674 Mon Sep 17 00:00:00 2001 From: liberhe Date: Sun, 14 May 2023 20:27:44 +0800 Subject: [PATCH 1/3] add rai description add ipfs doc add orbit add scroll test add scroll task --- basic/22-zk-snarkjs/public.json | 3 + basic/22-zk-snarkjs/verification_key.json | 96 ++++++++++++ basic/34-scroll-layer2/.env.example | 2 + basic/34-scroll-layer2/.gitignore | 9 ++ basic/34-scroll-layer2/README.md | 29 ++++ .../contracts/ExampleContract.sol | 9 ++ .../contracts/ExampleContractFactory.sol | 37 +++++ .../contracts/SimpleToken.sol | 28 ++++ basic/34-scroll-layer2/hardhat.config.js | 97 ++++++++++++ basic/34-scroll-layer2/package.json | 27 ++++ .../34-scroll-layer2/scripts/create2Deploy.js | 54 +++++++ basic/34-scroll-layer2/scripts/deploy.js | 33 ++++ basic/{34-aa => 49-aa}/.gitignore | 0 basic/{34-aa => 49-aa}/README.md | 0 basic/{34-aa => 49-aa}/demowallet/.gitignore | 0 basic/{34-aa => 49-aa}/demowallet/README.md | 0 .../demowallet/contracts/DemoAccount.sol | 0 .../demowallet/contracts/EntryPointDbg.sol | 0 .../demowallet/contracts/TargetContract.sol | 0 .../contracts/factories/ERC4337Factory.sol | 0 .../contracts/libs/EntryPointManager.sol | 0 .../paymaster/GasPrefundPaymaster.sol | 0 .../contracts/paymaster/USDCPaymaster.sol | 0 .../demowallet/hardhat.config.js | 0 .../{34-aa => 49-aa}/demowallet/package.json | 0 .../demowallet/scripts/basic.js | 0 .../demowallet/scripts/deploy.js | 0 .../demowallet/scripts/eip2470.js | 0 .../demowallet/scripts/fac_and_paymaster.js | 0 .../demowallet/src/api/msig_paymaster_api.js | 0 .../src/api/multi_sig_account_api.js | 0 .../src/paymaster/paymaster_api_naive.js | 0 .../demowallet/src/utils/create2.js | 0 .../{34-aa => 49-aa}/demowallet/test/Test.js | 0 .../{34-aa => 49-aa}/demowallet/unhandled.js | 0 basic/77-orbit/README.md | 4 + basic/77-orbit/ipfs.md | 147 ++++++++++++++++++ defi/RAI/README.md | 100 +++++++++--- 38 files changed, 655 insertions(+), 20 deletions(-) create mode 100644 basic/22-zk-snarkjs/public.json create mode 100644 basic/22-zk-snarkjs/verification_key.json create mode 100644 basic/34-scroll-layer2/.env.example create mode 100644 basic/34-scroll-layer2/.gitignore create mode 100644 basic/34-scroll-layer2/README.md create mode 100644 basic/34-scroll-layer2/contracts/ExampleContract.sol create mode 100644 basic/34-scroll-layer2/contracts/ExampleContractFactory.sol create mode 100644 basic/34-scroll-layer2/contracts/SimpleToken.sol create mode 100644 basic/34-scroll-layer2/hardhat.config.js create mode 100644 basic/34-scroll-layer2/package.json create mode 100644 basic/34-scroll-layer2/scripts/create2Deploy.js create mode 100644 basic/34-scroll-layer2/scripts/deploy.js rename basic/{34-aa => 49-aa}/.gitignore (100%) rename basic/{34-aa => 49-aa}/README.md (100%) rename basic/{34-aa => 49-aa}/demowallet/.gitignore (100%) rename basic/{34-aa => 49-aa}/demowallet/README.md (100%) rename basic/{34-aa => 49-aa}/demowallet/contracts/DemoAccount.sol (100%) rename basic/{34-aa => 49-aa}/demowallet/contracts/EntryPointDbg.sol (100%) rename basic/{34-aa => 49-aa}/demowallet/contracts/TargetContract.sol (100%) rename basic/{34-aa => 49-aa}/demowallet/contracts/factories/ERC4337Factory.sol (100%) rename basic/{34-aa => 49-aa}/demowallet/contracts/libs/EntryPointManager.sol (100%) rename basic/{34-aa => 49-aa}/demowallet/contracts/paymaster/GasPrefundPaymaster.sol (100%) rename basic/{34-aa => 49-aa}/demowallet/contracts/paymaster/USDCPaymaster.sol (100%) rename basic/{34-aa => 49-aa}/demowallet/hardhat.config.js (100%) rename basic/{34-aa => 49-aa}/demowallet/package.json (100%) rename basic/{34-aa => 49-aa}/demowallet/scripts/basic.js (100%) rename basic/{34-aa => 49-aa}/demowallet/scripts/deploy.js (100%) rename basic/{34-aa => 49-aa}/demowallet/scripts/eip2470.js (100%) rename basic/{34-aa => 49-aa}/demowallet/scripts/fac_and_paymaster.js (100%) rename basic/{34-aa => 49-aa}/demowallet/src/api/msig_paymaster_api.js (100%) rename basic/{34-aa => 49-aa}/demowallet/src/api/multi_sig_account_api.js (100%) rename basic/{34-aa => 49-aa}/demowallet/src/paymaster/paymaster_api_naive.js (100%) rename basic/{34-aa => 49-aa}/demowallet/src/utils/create2.js (100%) rename basic/{34-aa => 49-aa}/demowallet/test/Test.js (100%) rename basic/{34-aa => 49-aa}/demowallet/unhandled.js (100%) create mode 100644 basic/77-orbit/README.md create mode 100644 basic/77-orbit/ipfs.md diff --git a/basic/22-zk-snarkjs/public.json b/basic/22-zk-snarkjs/public.json new file mode 100644 index 000000000..bf2030970 --- /dev/null +++ b/basic/22-zk-snarkjs/public.json @@ -0,0 +1,3 @@ +[ + "33" +] \ No newline at end of file diff --git a/basic/22-zk-snarkjs/verification_key.json b/basic/22-zk-snarkjs/verification_key.json new file mode 100644 index 000000000..69c3c2f2c --- /dev/null +++ b/basic/22-zk-snarkjs/verification_key.json @@ -0,0 +1,96 @@ +{ + "protocol": "original", + "nPublic": 1, + "IC": [ + [ + "9155592233442963692799890034945512853605849659679247432481546974621101201962", + "18274439233561819201307369476607658432815807869411799859601349817821217150111", + "1" + ], + [ + "561745365187495368212308007430936670726749312758305512947760534358533556901", + "7648792604192734147903292948708711400885961936197589242458991515414353355187", + "1" + ] + ], + "vk_a": [ + [ + "21072565589916774035687938585981809557074926139454763116924633922226829877111", + "17239672583573343443517894645203416577825492536634467123636894889843890444563" + ], + [ + "21247807717917763387675947520311636505612380190314215368073890876121274171603", + "7551155645987247715057782651190776477933088326108388251957542168777097160552" + ], + [ + "1", + "0" + ] + ], + "vk_b": [ + "3672305866982554850422046113366393955858333801177015055071637416743535040910", + "1432439494480137916826571285178606007316227580537896323186901986809518603357", + "1" + ], + "vk_c": [ + [ + "12036086795010357793649968767129811610674917394127758255430492662570764060264", + "2447219013442392710330033451824781148704995424544094653298773661275251093527" + ], + [ + "17669308103516307541157947646612067865273637660074065534807413746130327637576", + "2665909309081157279513744829543838053491238775940842437667826902534803313073" + ], + [ + "1", + "0" + ] + ], + "vk_gb_1": [ + "16267645246396480268942761368760161316412850131422727989582352964801289551533", + "9908051937849910796790557613459791073458452996192666429429625290730009953915", + "1" + ], + "vk_gb_2": [ + [ + "19798585070521421666557889136144214101139893826982127818164101654433351166321", + "3538659409347627208954211905791565986912697204254766630110832040135931713686" + ], + [ + "14275854324627913059484112768075619301228265966401230020785867655715051675158", + "332510447662296563168692923901851959453500231430685682886746196275212839199" + ], + [ + "1", + "0" + ] + ], + "vk_g": [ + [ + "15790110281644309074980530533377720505697986909443663925111446233788639776829", + "10636234695309799878715028371707156977646328136643436773988322549073350781492" + ], + [ + "11390071610906013134375570422938966625887047947378694273594197745901516168037", + "11952058231397685448109057117674167306903619969313744060535220451082006243029" + ], + [ + "1", + "0" + ] + ], + "vk_z": [ + [ + "5631900945227230701335915406246015808791039151176715322074628181046888797977", + "5583032375200313479477014113500257719541392558692452565201664775156726555082" + ], + [ + "18299970135934322706153192121513405392368863356128279222397666397226939838808", + "8129708947064998264356063077922292698559874940174670220920154351608759142119" + ], + [ + "1", + "0" + ] + ] +} \ No newline at end of file diff --git a/basic/34-scroll-layer2/.env.example b/basic/34-scroll-layer2/.env.example new file mode 100644 index 000000000..67b793141 --- /dev/null +++ b/basic/34-scroll-layer2/.env.example @@ -0,0 +1,2 @@ +PRIVATE_KEY=xxxxxxxxxxxxxxxx +INFURA_ID=yyyyyyyy \ No newline at end of file diff --git a/basic/34-scroll-layer2/.gitignore b/basic/34-scroll-layer2/.gitignore new file mode 100644 index 000000000..36077f288 --- /dev/null +++ b/basic/34-scroll-layer2/.gitignore @@ -0,0 +1,9 @@ +node_modules +.env +coverage +coverage.json +typechain + +#Hardhat files +cache +artifacts diff --git a/basic/34-scroll-layer2/README.md b/basic/34-scroll-layer2/README.md new file mode 100644 index 000000000..7ad55b331 --- /dev/null +++ b/basic/34-scroll-layer2/README.md @@ -0,0 +1,29 @@ +# Scroll + +## bridge +https://scroll.io/bridge + + +## Contract Deploy +``` +npx hardhat run --network scrollSepolia scripts/deploy.js +``` +## contract +``` +npx hardhat verify --network scrollSepolia + +``` + + +## Ethereum & Scroll Differences +https://docs.scroll.io/en/developers/ethereum-and-scroll-differences/ + +## Scroll Architecture +https://docs.scroll.io/en/technology/ + +## REFERENCE +- scroll doc: https://docs.scroll.io/en/developers/developer-quickstart/#hardhat +- scroll demo: https://github.com/scroll-tech/scroll-guides.git +- bridge erc20: https://docs.scroll.io/en/developers/guides/bridge-erc20-through-the-custom-gateway/ +- scroll youtube: https://www.youtube.com/@Scroll_ZKP + diff --git a/basic/34-scroll-layer2/contracts/ExampleContract.sol b/basic/34-scroll-layer2/contracts/ExampleContract.sol new file mode 100644 index 000000000..3614d342b --- /dev/null +++ b/basic/34-scroll-layer2/contracts/ExampleContract.sol @@ -0,0 +1,9 @@ +pragma solidity ^0.8.17; + +contract ExampleContract { + uint public exampleVariable; + + constructor(uint _exampleParam) { + exampleVariable = _exampleParam; + } +} \ No newline at end of file diff --git a/basic/34-scroll-layer2/contracts/ExampleContractFactory.sol b/basic/34-scroll-layer2/contracts/ExampleContractFactory.sol new file mode 100644 index 000000000..e0ef62d0b --- /dev/null +++ b/basic/34-scroll-layer2/contracts/ExampleContractFactory.sol @@ -0,0 +1,37 @@ +pragma solidity ^0.8.17; + +import "./ExampleContract.sol"; + +contract ExampleContractFactory { + + event DeterministicContractDeployed(address contractAddress); + + function deployDeterministically( + uint _exampleParam, + uint _salt + ) public returns (address) { + ExampleContract deterministicContract = new ExampleContract{salt: bytes32(_salt)}(_exampleParam); + address deterministicContractAddress = address(deterministicContract); + + emit DeterministicContractDeployed(deterministicContractAddress); + return deterministicContractAddress; + } + + function getAddress( + bytes memory bytecode, + uint _salt + ) public view returns (address) { + bytes32 hash = keccak256( + abi.encodePacked(bytes1(0xff), msg.sender, _salt, keccak256(bytecode)) + ); + + // NOTE: cast last 20 bytes of hash to address + return address(uint160(uint(hash))); + } + + function getBytecode(uint _exampleParam) public pure returns (bytes memory) { + bytes memory bytecode = type(ExampleContract).creationCode; + + return abi.encodePacked(bytecode, abi.encode(_exampleParam)); + } +} \ No newline at end of file diff --git a/basic/34-scroll-layer2/contracts/SimpleToken.sol b/basic/34-scroll-layer2/contracts/SimpleToken.sol new file mode 100644 index 000000000..9f165ef57 --- /dev/null +++ b/basic/34-scroll-layer2/contracts/SimpleToken.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts-0.8/token/ERC20/presets/ERC20PresetMinterPauser.sol"; + +contract SimpleToken is ERC20PresetMinterPauser { + /** + * @dev Constructor that gives msg.sender all of existing tokens. + */ + + uint8 private _decimals; + uint256 public INITIAL_SUPPLY; + + function decimals() public view override returns (uint8) { + return _decimals; + } + + constructor( + string memory name, + string memory symbol, + uint8 decimals_, + uint256 initial_supply + ) ERC20PresetMinterPauser(name, symbol) { + _decimals = decimals_; + INITIAL_SUPPLY = initial_supply * (10**uint256(decimals_)); + _mint(msg.sender, initial_supply * (10**uint256(decimals_))); + } +} diff --git a/basic/34-scroll-layer2/hardhat.config.js b/basic/34-scroll-layer2/hardhat.config.js new file mode 100644 index 000000000..abeae5f93 --- /dev/null +++ b/basic/34-scroll-layer2/hardhat.config.js @@ -0,0 +1,97 @@ +require("@nomiclabs/hardhat-waffle"); +const fs = require("fs"); +require('dotenv').config() + + +// This is a sample Hardhat task. To learn how to create your own go to +// https://hardhat.org/guides/create-task.html +task("accounts", "Prints the list of accounts", async () => { + const accounts = await ethers.getSigners(); + + for (const account of accounts) { + console.log(account.address); + } +}); + +function mnemonic() { + + return process.env.PRIVATE_KEY; + +} + +/** + * @type import('hardhat/config').HardhatUserConfig + */ +module.exports = { + solidity: { + "compilers": [ + { + "version": "0.6.11", + "settings": { + "optimizer": { + "enabled": true, + "runs": 100 + } + } + }, + { + "version": "0.8.17", + "settings": { + "optimizer": { + "enabled": true, + "runs": 100 + } + } + } + ] + }, + networks: { + localhost: { + url: "http://localhost:8545", + //gasPrice: 125000000000,//you can adjust gasPrice locally to see how much it will cost on production + /* + notice no mnemonic here? it will just use account 0 of the hardhat node to deploy + (you can put in a mnemonic here to set the deployer locally) + */ + }, + rinkeby: { + url: `https://rinkeby.infura.io/v3/${process.env.INFURA_ID}`, //<---- YOUR INFURA ID! (or it won't work) + accounts: [ + mnemonic() + ], + }, + arbitrum: { + url: 'https://arb1.arbitrum.io/rpc', + accounts: [ + mnemonic() + ], + }, + arbitrum_rinkeby: { + url: 'https://rinkeby.arbitrum.io/rpc', + accounts: [ + mnemonic() + ], + }, + scrollSepolia: { + url: "https://sepolia-rpc.scroll.io/", + accounts: [ + mnemonic() + ] + }, + }, + etherscan: { + apiKey: { + scrollSepolia: 'abc', + }, + customChains: [ + { + network: 'scrollSepolia', + chainId: 534351, + urls: { + apiURL: 'https://sepolia-blockscout.scroll.io/api', + browserURL: 'https://sepolia-blockscout.scroll.io/', + }, + }, + ], +} +}; \ No newline at end of file diff --git a/basic/34-scroll-layer2/package.json b/basic/34-scroll-layer2/package.json new file mode 100644 index 000000000..670a43993 --- /dev/null +++ b/basic/34-scroll-layer2/package.json @@ -0,0 +1,27 @@ +{ + "name": "34-Scroll-layer2", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "npx hardhat test" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "dotenv": "^10.0.0", + "hardhat": "^2.6.5" + }, + "devDependencies": { + "@arbitrum/sdk": "^1.1.4", + "@nomiclabs/hardhat-ethers": "^2.0.0", + "@nomiclabs/hardhat-waffle": "^2.0.0", + "arb-bridge-eth": "^0.7.7", + "arb-shared-dependencies": "^1.0.0", + "arbos-precompiles": "^1.0.2", + "chai": "^4.2.0", + "ethereum-waffle": "^3.0.0", + "ethers": "^5.0.0" + } +} diff --git a/basic/34-scroll-layer2/scripts/create2Deploy.js b/basic/34-scroll-layer2/scripts/create2Deploy.js new file mode 100644 index 000000000..b1c3867aa --- /dev/null +++ b/basic/34-scroll-layer2/scripts/create2Deploy.js @@ -0,0 +1,54 @@ +// We require the Hardhat Runtime Environment explicitly here. This is optional +// but useful for running the script in a standalone fashion through `node