Skip to content

Commit

Permalink
Merge pull request #993 from liberhe/dev
Browse files Browse the repository at this point in the history
add scroll and ipfs
  • Loading branch information
yingjingyang authored Oct 5, 2023
2 parents 0fc78c7 + e814164 commit a5f47f6
Show file tree
Hide file tree
Showing 45 changed files with 806 additions and 0 deletions.
2 changes: 2 additions & 0 deletions basic/34-scroll-layer2/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRIVATE_KEY=xxxxxxxxxxxxxxxx
INFURA_ID=yyyyyyyy
9 changes: 9 additions & 0 deletions basic/34-scroll-layer2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.env
coverage
coverage.json
typechain

#Hardhat files
cache
artifacts
29 changes: 29 additions & 0 deletions basic/34-scroll-layer2/README.md
Original file line number Diff line number Diff line change
@@ -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 <contract address> <space separated constructor parameters>
```


## 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

9 changes: 9 additions & 0 deletions basic/34-scroll-layer2/contracts/ExampleContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pragma solidity ^0.8.17;

contract ExampleContract {
uint public exampleVariable;

constructor(uint _exampleParam) {
exampleVariable = _exampleParam;
}
}
37 changes: 37 additions & 0 deletions basic/34-scroll-layer2/contracts/ExampleContractFactory.sol
Original file line number Diff line number Diff line change
@@ -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), address(this), _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));
}
}
28 changes: 28 additions & 0 deletions basic/34-scroll-layer2/contracts/SimpleToken.sol
Original file line number Diff line number Diff line change
@@ -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_)));
}
}
97 changes: 97 additions & 0 deletions basic/34-scroll-layer2/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -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/',
},
},
],
}
};
27 changes: 27 additions & 0 deletions basic/34-scroll-layer2/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
54 changes: 54 additions & 0 deletions basic/34-scroll-layer2/scripts/create2Deploy.js
Original file line number Diff line number Diff line change
@@ -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 <script>`.
//
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const { ethers } = require("hardhat");

async function main() {

const [deployer] = await ethers.getSigners();
console.log("Network ChainId:", (await ethers.provider.getNetwork()).chainId);

console.log(
"Deploying contracts with the account:",
deployer.address
);

console.log("Account balance:", (await deployer.getBalance()).toString());

const factoryContractDeployer = await ethers.getContractFactory("ExampleContractFactory");
const contractDeployer = await ethers.getContractFactory("ExampleContract");
const factoryContractdeployed = await factoryContractDeployer.deploy()

const exampleParam = 1
const salt = 1

const exampleContractBytecode = await factoryContractdeployed.getBytecode(exampleParam);
console.log("bytecode" , exampleContractBytecode)

const contractAddress = await factoryContractdeployed.getAddress(exampleContractBytecode, salt);
console.log("contract address calculated",contractAddress)

const contract = await contractDeployer.attach(contractAddress)

const deploy = await factoryContractdeployed.deployDeterministically(exampleParam,salt)

const receipt = await deploy.wait();

console.log("Factory deployed to:", receipt.events[0].args.contractAddress);

// let val = await contract.exampleVariable();

// console.log("exampleVariable ", val);

}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
33 changes: 33 additions & 0 deletions basic/34-scroll-layer2/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const { ethers } = require("hardhat");

async function main() {

const [deployer] = await ethers.getSigners();
console.log("Network ChainId:", (await ethers.provider.getNetwork()).chainId);

console.log(
"Deploying contracts with the account:",
deployer.address
);

console.log("Account balance:", (await deployer.getBalance()).toString());

const Token = await ethers.getContractFactory("SimpleToken");
const token = await Token.deploy("Dapp-Learning-scroll", "DL", 1, 100000000);

console.log("Token address:", token.address);
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions basic/51-taiko-layer2/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRIVATE_KEY=xxxxxxxxxxxxxxxx
INFURA_ID=yyyyyyyy
9 changes: 9 additions & 0 deletions basic/51-taiko-layer2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.env
coverage
coverage.json
typechain

#Hardhat files
cache
artifacts
22 changes: 22 additions & 0 deletions basic/51-taiko-layer2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Taiko

## bridge



## Contract Deploy
```
npx hardhat run --network taiko scripts/deploy.js
```
## contract
```
npx hardhat verify --network taiko <contract address> <space separated constructor parameters>
```


## Taiko Architecture


## REFERENCE
- taiko doc: https://taiko.xyz/docs
9 changes: 9 additions & 0 deletions basic/51-taiko-layer2/contracts/ExampleContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pragma solidity ^0.8.17;

contract ExampleContract {
uint public exampleVariable;

constructor(uint _exampleParam) {
exampleVariable = _exampleParam;
}
}
Loading

0 comments on commit a5f47f6

Please sign in to comment.