Skip to content

Commit

Permalink
Merge pull request #1 from Scaffold-Stark/refactor/arch
Browse files Browse the repository at this point in the history
Refactor/arch
  • Loading branch information
ngjupeng authored Sep 26, 2024
2 parents a6cf43d + ce5d0ed commit 95e87d1
Show file tree
Hide file tree
Showing 271 changed files with 8,864 additions and 1,754 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Run foundry node, deploy contracts (& generate contracts typescript output)
env:
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
run: yarn chain::eth & yarn deploy::eth
run: yarn chain:eth & yarn deploy:eth

- name: Run nextjs lint
run: yarn next:lint --max-warnings=0
Expand Down
6 changes: 0 additions & 6 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ const buildNextEslintCommand = (filenames) =>

const checkTypesNextCommand = () => "yarn next:check-types";

const buildHardhatEslintCommand = (filenames) =>
`yarn hardhat:lint-staged --fix ${filenames
.map((f) => path.relative(path.join("packages", "hardhat"), f))
.join(" ")}`;

module.exports = {
"packages/nextjs/**/*.{ts,tsx}": [
buildNextEslintCommand,
checkTypesNextCommand,
],
"packages/hardhat/**/*.{ts,tsx}": [buildHardhatEslintCommand],
};
59 changes: 30 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sse-2",
"name": "ses",
"version": "0.0.1",
"private": true,
"workspaces": {
Expand All @@ -8,36 +8,37 @@
]
},
"scripts": {
"chain::strk": "yarn workspace @sse-2/snfoundry chain",
"deploy::strk": "yarn workspace @sse-2/snfoundry deploy",
"deploy:reset::strk": "yarn workspace @sse-2/snfoundry deploy:reset",
"test::strk": "yarn workspace @sse-2/snfoundry test",
"compile::strk": "yarn workspace @sse-2/snfoundry compile",
"format::strk": "yarn workspace @sse-2/snfoundry format",
"account::eth": "yarn workspace @sse-2/foundry account",
"chain::eth": "yarn workspace @sse-2/foundry chain",
"compile::eth": "yarn workspace @sse-2/foundry compile",
"deploy::eth": "yarn workspace @sse-2/foundry deploy",
"deploy:verify::eth": "yarn workspace @sse-2/foundry deploy:verify",
"flatten::eth": "yarn workspace @sse-2/foundry flatten",
"fork::eth": "yarn workspace @sse-2/foundry fork",
"foundry:format::eth": "yarn workspace @sse-2/foundry format",
"foundry:lint::eth": "yarn workspace @sse-2/foundry lint",
"foundry:test::eth": "yarn workspace @sse-2/foundry test",
"generate::eth": "yarn workspace @sse-2/foundry generate",
"verify::eth": "yarn workspace @sse-2/foundry verify",
"chain:strk": "yarn workspace @ss-2/snfoundry chain",
"chain:eth": "yarn workspace @se-2/foundry chain",
"deploy:strk": "yarn workspace @ss-2/snfoundry deploy",
"deploy:eth": "yarn workspace @se-2/foundry deploy",
"deploy": "yarn deploy:eth && yarn deploy:strk",
"deploy:reset:strk": "yarn workspace @ss-2/snfoundry deploy:reset",
"test:strk": "yarn workspace @ss-2/snfoundry test",
"compile:strk": "yarn workspace @ss-2/snfoundry compile",
"format:strk": "yarn workspace @ss-2/snfoundry format",
"account:eth": "yarn workspace @se-2/foundry account",
"compile:eth": "yarn workspace @se-2/foundry compile",
"deploy:verify:eth": "yarn workspace @se-2/foundry deploy:verify",
"flatten:eth": "yarn workspace @se-2/foundry flatten",
"fork:eth": "yarn workspace @se-2/foundry fork",
"foundry:format:eth": "yarn workspace @se-2/foundry format",
"foundry:lint:eth": "yarn workspace @se-2/foundry lint",
"foundry:test:eth": "yarn workspace @se-2/foundry test",
"generate:eth": "yarn workspace @se-2/foundry generate",
"verify:eth": "yarn workspace @se-2/foundry verify",
"postinstall": "husky install",
"next:build": "yarn workspace @sse-2/nextjs build",
"next:check-types": "yarn workspace @sse-2/nextjs check-types",
"next:format": "yarn workspace @sse-2/nextjs format",
"next:lint": "yarn workspace @sse-2/nextjs lint",
"next:serve": "yarn workspace @sse-2/nextjs serve",
"next:build": "yarn workspace @ses/nextjs build",
"next:check-types": "yarn workspace @ses/nextjs check-types",
"next:format": "yarn workspace @ses/nextjs format",
"next:lint": "yarn workspace @ses/nextjs lint",
"next:serve": "yarn workspace @ses/nextjs serve",
"precommit": "lint-staged",
"start": "yarn workspace @sse-2/nextjs dev",
"vercel": "yarn workspace @sse-2/nextjs vercel",
"vercel:yolo": "yarn workspace @sse-2/nextjs vercel:yolo",
"test": "yarn foundry:test::eth && test::strk",
"format": "yarn next:format && yarn foundry:format::eth && format::strk"
"start": "yarn workspace @ses/nextjs dev",
"vercel": "yarn workspace @ses/nextjs vercel",
"vercel:yolo": "yarn workspace @ses/nextjs vercel:yolo",
"test": "yarn foundry:test:eth && test:strk",
"format": "yarn next:format && yarn foundry:format:eth && format:strk"
},
"devDependencies": {
"daisyui": "^4.7.3",
Expand Down
89 changes: 89 additions & 0 deletions packages/foundry/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
.PHONY: build deploy generate-abis verify-keystore account chain compile deploy-verify flatten fork format lint test verify

# setup wallet for anvil
setup-anvil-wallet:
shx rm ~/.foundry/keystores/scaffold-eth-default 2>/dev/null; \
cast wallet import --private-key 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6 --unsafe-password 'localhost' scaffold-eth-default

# Start local chain
chain: setup-anvil-wallet
anvil

# Start a fork
fork: setup-anvil-wallet
anvil --fork-url ${FORK_URL} --chain-id 31337

# Build the project
build:
forge build --build-info --build-info-path out/build-info/

# Deploy the project
deploy:
@if [ "$(RPC_URL)" = "localhost" ]; then \
forge script script/Deploy.s.sol --rpc-url localhost --password localhost --broadcast --legacy --ffi; \
else \
forge script script/Deploy.s.sol --rpc-url $(RPC_URL) --broadcast --legacy --ffi; \
fi

# Build and deploy target
build-and-deploy: build deploy generate-abis

# Generate TypeScript ABIs
generate-abis:
node scripts-js/generateTsAbis.js

verify-keystore:
if grep -q "scaffold-eth-default" .env; then \
cast wallet address --password localhost; \
else \
cast wallet address; \
fi

# List account
account:
@node scripts-js/ListAccount.js $$(make verify-keystore)

# Generate a new account
account-generate:
@cast wallet import $(ACCOUNT_NAME) --private-key $$(cast wallet new | grep 'Private key:' | awk '{print $$3}')
@echo "Please update .env file with ETH_KEYSTORE_ACCOUNT=$(ACCOUNT_NAME)"

# Import an existing account
account-import:
@cast wallet import ${ACCOUNT_NAME} --interactive

# Compile contracts
compile:
forge compile

# Deploy and verify
deploy-verify:
@if [ "$(RPC_URL)" = "localhost" ]; then \
forge script script/Deploy.s.sol --rpc-url localhost --password localhost --broadcast --legacy --ffi --verify; \
else \
forge script script/Deploy.s.sol --rpc-url $(RPC_URL) --broadcast --legacy --ffi --verify; \
fi
node scripts-js/generateTsAbis.js

# Flatten contracts
flatten:
forge flatten

# Format code
format:
forge fmt && prettier --write ./script/**/*.js

# Lint code
lint:
forge fmt --check && prettier --check ./script/**/*.js

# Run tests
test:
forge test

# Verify contracts
verify:
forge script script/VerifyAll.s.sol --ffi --rpc-url $(RPC_URL)

build-and-verify: build verify

8 changes: 6 additions & 2 deletions packages/foundry/contracts/YourContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ contract YourContract {

// Constructor: Called once on contract deployment
// Check packages/foundry/deploy/Deploy.s.sol
constructor(address _owner) {
constructor(
address _owner
) {
owner = _owner;
}

Expand All @@ -47,7 +49,9 @@ contract YourContract {
*
* @param _newGreeting (string memory) - new greeting to save on the contract
*/
function setGreeting(string memory _newGreeting) public payable {
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");
Expand Down
2 changes: 1 addition & 1 deletion packages/foundry/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@sse-2/foundry",
"name": "@se-2/foundry",
"version": "0.0.1",
"scripts": {
"account": "node script/ListAccount.js",
Expand Down
24 changes: 15 additions & 9 deletions packages/foundry/script/VerifyAll.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ struct FfiResult {
}

interface tempVm {
function tryFfi(string[] calldata) external returns (FfiResult memory);
function tryFfi(
string[] calldata
) external returns (FfiResult memory);
}

contract VerifyAll is Script {
Expand All @@ -39,7 +41,9 @@ contract VerifyAll is Script {
}
}

function _verifyIfContractDeployment(string memory content) internal {
function _verifyIfContractDeployment(
string memory content
) internal {
string memory txType = abi.decode(
vm.parseJson(content, searchStr(currTransactionIdx, "transactionType")),
(string)
Expand All @@ -49,7 +53,9 @@ contract VerifyAll is Script {
}
}

function _verifyContract(string memory content) internal {
function _verifyContract(
string memory content
) internal {
string memory contractName = abi.decode(
vm.parseJson(content, searchStr(currTransactionIdx, "contractName")),
(string)
Expand Down Expand Up @@ -98,19 +104,19 @@ contract VerifyAll is Script {
return;
}

function nextTransaction(string memory content) external view returns (bool) {
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)
{
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");
Expand Down
4 changes: 2 additions & 2 deletions packages/foundry/script/generateTsAbis.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function main() {
});
});

const TARGET_DIR = "../nextjs/core/eth/contracts/";
const TARGET_DIR = "../nextjs/lib/scaffold-eth-2/contracts/";

const fileContent = Object.entries(allGeneratedContracts).reduce(
(content, [chainId, chainConfig]) => {
Expand All @@ -131,7 +131,7 @@ function main() {
fs.writeFileSync(
`${TARGET_DIR}deployedContracts.ts`,
prettier.format(
`${generatedContractComment} import { GenericContractsDeclaration } from "~~/core/eth/utils/scaffold-eth/contract"; \n\n
`${generatedContractComment} import { GenericContractsDeclaration } from "@scaffold-eth-2/utils/scaffold-eth/contract"; \n\n
const deployedContracts = {${fileContent}} as const; \n\n export default deployedContracts satisfies GenericContractsDeclaration`,
{
parser: "typescript",
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules/
**/*.png
**/*.svg
**/generated/**/*
**/lib/*
5 changes: 3 additions & 2 deletions packages/nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ export const metadata: Metadata = {
icons: "/logo.ico",
};

const ScaffoldStarkApp = ({ children }: { children: React.ReactNode }) => {
const ScaffoldEthStarkApp = ({ children }: { children: React.ReactNode }) => {
return (
<html suppressHydrationWarning>
<body>
<ThemeProvider forcedTheme="light">
{" "}
<ScaffoldAppWithProviders>{children}</ScaffoldAppWithProviders>
</ThemeProvider>
</body>
</html>
);
};

export default ScaffoldStarkApp;
export default ScaffoldEthStarkApp;
Loading

0 comments on commit 95e87d1

Please sign in to comment.