diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..392878a --- /dev/null +++ b/Makefile @@ -0,0 +1,52 @@ +SHELL := /bin/bash + +help: + @egrep -h '\s#@\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?#@ "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}' + +# Thor solo +solo-up: #@ Start Thor solo + docker compose -f packages/contracts/docker-compose.yaml up -d --wait thor-solo +solo-down: #@ Stop Thor solo + docker compose -f packages/contracts/docker-compose.yaml down +solo-clean: #@ Clean Thor solo + docker compose -f packages/contracts/docker-compose.yaml down -v --remove-orphans + +# Database +DB_COMMAND=docker compose -f packages/database/docker-compose-mongo.yaml +DB_MAKE_KEY=mkdir -p packages/database/keys; openssl rand -base64 756 > packages/database/keys/keyfile; +DB_REMOVE_KEY=rm -f -R packages/database/keys +DB_SETUP_COMMAND=docker compose -f packages/database/docker-compose-mongo-setup.yaml + +db-all: #@ Remove, clean and start all the database. + make db-down db-clean db-up db-setup +db-up: #@ Start the database. + $(DB_COMMAND) up -d --wait +db-clean: #@ Clean all the database data + $(DB_COMMAND) down -v --remove-orphans; +db-down: #@ Stop the database. + $(DB_COMMAND) down +db-keyfile-create: #@ Generate the keyfile for the database. + $(DB_MAKE_KEY) +db-keyfile-remove: #@ Remove the keyfile for the database. + $(DB_REMOVE_KEY) +db-setup: #@ Setup the database. + $(DB_SETUP_COMMAND) up --build; $(DB_SETUP_COMMAND) rm --force + +NAV_CONTRACTS=cd packages/contracts + +# Contracts +contracts-compile: #@ Compile the contracts. + $(NAV_CONTRACTS); yarn compile +contracts-deploy: contracts-compile solo-up #@ Deploy the contracts. + $(NAV_CONTRACTS); yarn deploy +contracts-test: contracts-compile #@ Test the contracts. + $(NAV_CONTRACTS); yarn test + +# Apps +install: #@ Install the dependencies. + yarn install +build: install #@ Build the app. + yarn build +test: #@ Test the app. + yarn test +.PHONY:build diff --git a/README.md b/README.md new file mode 100644 index 0000000..be67bb9 --- /dev/null +++ b/README.md @@ -0,0 +1,145 @@ +# React Dapp Template πŸš€ + +This is a simple template of a decentralized application (DApp) built with React, and Solidity. It is designed to help you kickstart your DApp development journey. + +This template creates a simple DApp that allows users to interact with an erc20 token contract called *Fiorino*. Users can send and receive tokens, and the contract owner can mint new tokens. + +## Requirements + +Ensure your development environment is set up with the following: + +- **Node.js (v18 or later):** [Download here](https://nodejs.org/en/download/package-manager) πŸ“₯ +- **Yarn:** [Install here](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable) 🧢 +- **Docker (for containerization):** [Get Docker](https://docs.docker.com/get-docker/) 🐳 +- **Hardhat (for smart contracts):** [Getting Started with Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started) ⛑️ + +## Project Structure + +### Frontend (apps/frontend) 🌐 + +A blazing-fast React application powered by Vite: + +- **Vechain dapp-kit:** Streamline wallet connections and interactions. [Learn more](https://docs.vechain.org/developer-resources/sdks-and-providers/dapp-kit) + +### Contracts (packages/contracts) πŸ“œ + +Smart contract in Solidity, managed with Hardhat for deployment on the Vechain Thor network. + +### Packages πŸ“¦ + +Shared configurations and utility functions to unify and simplify your development process. + +### Getting Started + +Clone the repository and install dependencies with ease: + +```bash +yarn # Run this at the root level of the project +``` + +Place your `.env` files in the root folder, you can copy `.env.example` file and rename it to `.env` changing the values to your own: + +## Running on Solo Network Locally (docker needed!) πŸ”§ + +### Spin up the Solo Network in a docker container: + +```bash + yarn solo-up +``` + +### Run the frontend and deploy the contracts on the Local Solo Network (if not deployed yet) with a single command: + +```bash + yarn dev +``` + +You should see a log like this, that means the frontend is running: + +```bash +frontend:dev: VITE v5.3.2 ready in 135 ms +frontend:dev: +frontend:dev: ➜ Local: http://localhost:5001/ +frontend:dev: ➜ Network: http://192.168.1.26:5001/ +frontend:dev: ➜ Network: http://192.168.64.1:5001/ +frontend:dev: ➜ press h + enter to show help +``` + +and then you see a log like this, that means the contracts are deployed: + +```bash +@repo/contracts:check-contracts-deployment: ================ Contracts deployed in 0m 9s +@repo/contracts:check-contracts-deployment: Contracts { fiorino: '0xE55842798426F155Ad7Ff6E9C93378690d1FF46a' } +@repo/contracts:check-contracts-deployment: Contracts and libraries addresses saved to /path/apps/react-dapp-template/packages/contracts/deploy_output +@repo/contracts:check-contracts-deployment: Total execution time: 0m 9s +@repo/contracts:check-contracts-deployment: Deployment completed successfully! +@repo/contracts:check-contracts-deployment: ================================================================================ +@repo/contracts:check-contracts-deployment: Writing new config file to /path/apps/react-dapp-template/packages/config/local.ts +``` + +or a log like this, that means the contracts are already deployed (if you run the `yarn dev` command again): + +```bash +@repo/contracts:check-contracts-deployment: Checking contracts deployment on vechain_solo (http://localhost:8669)... +@repo/contracts:check-contracts-deployment: fiorino contract already deployed +``` + +### Redeploy the contracts: + +```bash + yarn contracts:deploy +``` + +or + +Put empty string in the `fiorinoContractAddress` in the `packages/config/local.ts` file: + +```typescript + fiorinoContractAddress: "", +``` + +and then run the `yarn dev` command again. + +### Spin down the Solo Network + +```bash + yarn solo-down +``` + +### Clean docker solo network + +```bash + yarn solo-clean +``` + +## Running on Testnet 🌐 + +### Deploy the contracts on the Testnet: + +```bash + yarn contracts:deploy:testnet +``` + +### Run the frontend to interact with the contracts on the Testnet: + +```bash + yarn dev:testnet +``` + +## Running on Mainnet 🌐 + +### Deploy the contracts on the Mainnet: + +```bash + yarn contracts:deploy:mainnet +``` + +### Run the frontend to interact with the contracts on the Mainnet: + +```bash + yarn dev:mainnet +``` + + +## Disclaimer ⚠️ + +This template serves as a foundational starting point and should be thoroughly reviewed and customized to suit your project’s specific requirements. Pay special attention to configurations, security settings, and environment variables to ensure a secure and efficient deployment. diff --git a/apps/frontend/package.json b/apps/frontend/package.json index 6bb0153..10e1ce5 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -7,6 +7,8 @@ "build": "tsc && vite build --mode=development", "clean": "rm -rf dist .turbo", "dev": "vite", + "dev:testnet": "vite", + "dev:mainnet": "vite", "gh-pages-build": "tsc && vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview --mode=development", diff --git a/package.json b/package.json index 569ffea..1cca86f 100644 --- a/package.json +++ b/package.json @@ -8,17 +8,18 @@ "purge": "turbo purge", "format": "prettier --write \"**/*.{ts,tsx,md}\"", "dev": "yarn && dotenv -v VITE_APP_ENV=local -- turbo dev --", - "dev:staging": "yarn && dotenv -v VITE_APP_ENV=solo-staging -e .env -- turbo dev --", "dev:testnet": "yarn && dotenv -v VITE_APP_ENV=testnet -e .env -- turbo dev:testnet --", "dev:mainnet": "yarn && dotenv -v VITE_APP_ENV=mainnet -e .env -- turbo dev:mainnet --", "contracts:compile": "dotenv -v VITE_APP_ENV=local -- turbo run compile --filter=@repo/contracts", "contracts:deploy": "dotenv -v VITE_APP_ENV=local -- turbo run deploy --filter=@repo/contracts", - "contracts:deploy:solo-staging": "dotenv -v VITE_APP_ENV=solo-staging -- turbo run deploy --filter=@repo/contracts", "contracts:deploy:testnet": "dotenv -v VITE_APP_ENV=testnet -- turbo run deploy:testnet --filter=@repo/contracts", "contracts:deploy:mainnet": "dotenv -v VITE_APP_ENV=mainnet -- turbo run deploy:mainnet --filter=@repo/contracts", "check-contracts-deployment": "npx hardhat run scripts/checkContractsDeployment.ts", "check-contracts-deployment:testnet": "npx hardhat run scripts/checkContractsDeployment.ts --network vechain_testnet", - "check-contracts-deployment:mainnet": "npx hardhat run scripts/checkContractsDeployment.ts --network vechain_mainnet" + "check-contracts-deployment:mainnet": "npx hardhat run scripts/checkContractsDeployment.ts --network vechain_mainnet", + "solo-up": "make solo-up", + "solo-down": "make solo-down", + "solo-clean": "make solo-clean" }, "devDependencies": { "prettier": "^3.2.5", diff --git a/packages/config/contracts/envs/soloStaging.ts b/packages/config/contracts/envs/soloStaging.ts deleted file mode 100644 index e4619f3..0000000 --- a/packages/config/contracts/envs/soloStaging.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { defineConfig } from "../defineConfig"; - -export function createSoloStagingConfig() { - return defineConfig({ - VITE_APP_ENV: "solo-staging", - XAPP_BASE_URI: "ipfs://", - CONTRACTS_ADMIN_ADDRESS: "0xf077b491b355E64048cE21E3A6Fc4751eEeA77fa", - }); -} diff --git a/packages/config/contracts/index.ts b/packages/config/contracts/index.ts index 3d76385..a52c446 100644 --- a/packages/config/contracts/index.ts +++ b/packages/config/contracts/index.ts @@ -1,18 +1,11 @@ export * from "./type"; import { createLocalConfig } from "./envs/local"; -import { createSoloStagingConfig } from "./envs/soloStaging"; import { createE2EConfig } from "./envs/e2e"; import { createTestnetConfig } from "./envs/testnet"; import { createMainnetConfig } from "./envs/mainnet"; -export const EnvConfigValues = [ - "local", - "e2e", - "solo-staging", - "testnet", - "mainnet", -] as const; +export const EnvConfigValues = ["local", "e2e", "testnet", "mainnet"] as const; export type EnvConfig = (typeof EnvConfigValues)[number]; export function getContractsConfig(env: EnvConfig) { @@ -21,8 +14,6 @@ export function getContractsConfig(env: EnvConfig) { return createLocalConfig(); case "e2e": return createE2EConfig(); - case "solo-staging": - return createSoloStagingConfig(); case "testnet": return createTestnetConfig(); case "mainnet": diff --git a/packages/config/contracts/type.ts b/packages/config/contracts/type.ts index c34d8a9..cde0ecc 100644 --- a/packages/config/contracts/type.ts +++ b/packages/config/contracts/type.ts @@ -1,5 +1,5 @@ export type ContractsConfig = { - VITE_APP_ENV: "local" | "e2e" | "solo-staging" | "testnet" | "mainnet"; + VITE_APP_ENV: "local" | "e2e" | "testnet" | "mainnet"; CONTRACTS_ADMIN_ADDRESS: string; XAPP_BASE_URI: string; }; diff --git a/packages/config/index.ts b/packages/config/index.ts index 2d6b5f2..6f5b117 100644 --- a/packages/config/index.ts +++ b/packages/config/index.ts @@ -1,5 +1,4 @@ import localConfig from "./local"; -import stagingConfig from "./solo-staging"; import testnetConfig from "./testnet"; import mainnetConfig from "./mainnet"; import { EnvConfig, getContractsConfig } from "./contracts"; @@ -21,7 +20,6 @@ export const getConfig = (env?: EnvConfig): AppConfig => { ); if (appEnv === "local") return localConfig; if (appEnv === "e2e") return localConfig; - if (appEnv === "solo-staging") return stagingConfig; if (appEnv === "testnet") return testnetConfig; if (appEnv === "mainnet") return mainnetConfig; throw new Error(`Unsupported VITE_APP_ENV ${appEnv}`); diff --git a/packages/config/local.ts b/packages/config/local.ts index 139b101..ef02d6a 100644 --- a/packages/config/local.ts +++ b/packages/config/local.ts @@ -1,39 +1,37 @@ -import { AppConfig } from "."; -const config: AppConfig = { - environment: "solo-staging", - basePath: "http://localhost:3000", - fiorinoContractAddress: "0x9e993Ac115BF2AC3Dee79f7652E2289c55c9C176", - nodeUrl: "http://localhost:8669", - network: { - id: "solo", - name: "solo", - type: "solo", - defaultNet: true, - urls: ["http://localhost:8669"], - explorerUrl: "https://explore-testnet.vechain.org", - blockTime: 10000, - genesis: { - number: 0, - id: "0x00000000c05a20fbca2bf6ae3affba6af4a74b800b585bf7a4988aba7aea69f6", - size: 170, - parentID: - "0xffffffff53616c757465202620526573706563742c20457468657265756d2100", - timestamp: 1530316800, - gasLimit: 10000000, - beneficiary: "0x0000000000000000000000000000000000000000", - gasUsed: 0, - totalScore: 0, - txsRoot: - "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", - txsFeatures: 0, - stateRoot: - "0x93de0ffb1f33bc0af053abc2a87c4af44594f5dcb1cb879dd823686a15d68550", - receiptsRoot: - "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", - signer: "0x0000000000000000000000000000000000000000", - isTrunk: true, - transactions: [], - }, +import { AppConfig } from "." + const config: AppConfig = { + "environment": "local", + "basePath": "http://localhost:3000", + "nodeUrl": "http://localhost:8669", + "network": { + "id": "solo", + "name": "solo", + "type": "solo", + "defaultNet": true, + "urls": [ + "http://localhost:8669" + ], + "explorerUrl": "https://explore-testnet.vechain.org", + "blockTime": 10000, + "genesis": { + "number": 0, + "id": "0x00000000c05a20fbca2bf6ae3affba6af4a74b800b585bf7a4988aba7aea69f6", + "size": 170, + "parentID": "0xffffffff53616c757465202620526573706563742c20457468657265756d2100", + "timestamp": 1530316800, + "gasLimit": 10000000, + "beneficiary": "0x0000000000000000000000000000000000000000", + "gasUsed": 0, + "totalScore": 0, + "txsRoot": "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", + "txsFeatures": 0, + "stateRoot": "0x93de0ffb1f33bc0af053abc2a87c4af44594f5dcb1cb879dd823686a15d68550", + "receiptsRoot": "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", + "signer": "0x0000000000000000000000000000000000000000", + "isTrunk": true, + "transactions": [] + } }, + "fiorinoContractAddress": "0x5d4188A633E1E6F4c6a3846dEbaBaa730AF58e6A" }; -export default config; + export default config; \ No newline at end of file diff --git a/packages/config/mainnet.ts b/packages/config/mainnet.ts index 5dc3504..11fe6a3 100644 --- a/packages/config/mainnet.ts +++ b/packages/config/mainnet.ts @@ -1,44 +1,40 @@ -import { AppConfig } from "."; -const config: AppConfig = { - environment: "mainnet", - basePath: "https://governance.vebetterdao.org", - fiorinoContractAddress: "0x9e993Ac115BF2AC3Dee79f7652E2289c55c9C176", - nodeUrl: "https://mainnet.vechain.org", - network: { - id: "main", - name: "main", - type: "main", - defaultNet: true, - urls: [ +import { AppConfig } from "." + const config: AppConfig = { + "environment": "mainnet", + "basePath": "https://governance.vebetterdao.org", + "fiorinoContractAddress": "0xDc9927805Df9075113e9786ADDD793Fc1786A170", + "nodeUrl": "https://mainnet.vechain.org", + "network": { + "id": "main", + "name": "main", + "type": "main", + "defaultNet": true, + "urls": [ "https://mainnet.vechain.org", "https://vethor-node.vechain.com", "https://mainnet.veblocks.net", - "https://mainnet.vecha.in", + "https://mainnet.vecha.in" ], - explorerUrl: "https://insight.vecha.in/#/main", - blockTime: 10000, - genesis: { - number: 0, - id: "0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a", - size: 170, - parentID: - "0xffffffff53616c757465202620526573706563742c20457468657265756d2100", - timestamp: 1530316800, - gasLimit: 10000000, - beneficiary: "0x0000000000000000000000000000000000000000", - gasUsed: 0, - totalScore: 0, - txsRoot: - "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", - txsFeatures: 0, - stateRoot: - "0x09bfdf9e24dd5cd5b63f3c1b5d58b97ff02ca0490214a021ed7d99b93867839c", - receiptsRoot: - "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", - signer: "0x0000000000000000000000000000000000000000", - isTrunk: true, - transactions: [], - }, - }, + "explorerUrl": "https://insight.vecha.in/#/main", + "blockTime": 10000, + "genesis": { + "number": 0, + "id": "0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a", + "size": 170, + "parentID": "0xffffffff53616c757465202620526573706563742c20457468657265756d2100", + "timestamp": 1530316800, + "gasLimit": 10000000, + "beneficiary": "0x0000000000000000000000000000000000000000", + "gasUsed": 0, + "totalScore": 0, + "txsRoot": "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", + "txsFeatures": 0, + "stateRoot": "0x09bfdf9e24dd5cd5b63f3c1b5d58b97ff02ca0490214a021ed7d99b93867839c", + "receiptsRoot": "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", + "signer": "0x0000000000000000000000000000000000000000", + "isTrunk": true, + "transactions": [] + } + } }; -export default config; + export default config; \ No newline at end of file diff --git a/packages/config/solo-staging.ts b/packages/config/solo-staging.ts deleted file mode 100644 index 2375259..0000000 --- a/packages/config/solo-staging.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { AppConfig } from "."; - -const config: AppConfig = { - environment: "solo-staging", - basePath: "https://example.app", - fiorinoContractAddress: "0xf077b491b355E64048cE21E3A6Fc4751eEeA77fa", - nodeUrl: "https://thor-solo.dev.b3tr.vechain.org", - network: { - id: "solo-staging", - name: "solo-staging", - type: "solo", - defaultNet: true, - urls: ["https://thor-solo.dev.b3tr.vechain.org"], - explorerUrl: "https://insight.dev.b3tr.vechain.org/#/solo", - blockTime: 10000, - genesis: { - number: 0, - id: "0x00000000c05a20fbca2bf6ae3affba6af4a74b800b585bf7a4988aba7aea69f6", - size: 170, - parentID: - "0xffffffff53616c757465202620526573706563742c20457468657265756d2100", - timestamp: 1530316800, - gasLimit: 10000000, - beneficiary: "0x0000000000000000000000000000000000000000", - gasUsed: 0, - totalScore: 0, - txsRoot: - "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", - txsFeatures: 0, - stateRoot: - "0x93de0ffb1f33bc0af053abc2a87c4af44594f5dcb1cb879dd823686a15d68550", - receiptsRoot: - "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", - signer: "0x0000000000000000000000000000000000000000", - isTrunk: true, - transactions: [], - }, - }, -}; -export default config; diff --git a/packages/config/testnet.ts b/packages/config/testnet.ts index 336f718..4412b7a 100644 --- a/packages/config/testnet.ts +++ b/packages/config/testnet.ts @@ -1,45 +1,40 @@ -import { AppConfig } from "."; - -const config: AppConfig = { - environment: "testnet", - basePath: "https://example.org", - fiorinoContractAddress: "0x9e993Ac115BF2AC3Dee79f7652E2289c55c9C176", - nodeUrl: "https://testnet.vechain.org", - network: { - id: "testnet", - name: "testnet", - type: "test", - defaultNet: true, - urls: [ +import { AppConfig } from "." + const config: AppConfig = { + "environment": "testnet", + "basePath": "https://example.org", + "fiorinoContractAddress": "0x31454bc37feCC3855bf9DF1cA769f25C82eD1e98", + "nodeUrl": "https://testnet.vechain.org", + "network": { + "id": "testnet", + "name": "testnet", + "type": "test", + "defaultNet": true, + "urls": [ "https://testnet.vechain.org", "https://vethor-node-test.vechaindev.com", "https://sync-testnet.veblocks.net", - "https://testnet.vecha.in", + "https://testnet.vecha.in" ], - explorerUrl: "https://insight.vecha.in/#/test", - blockTime: 10000, - genesis: { - number: 0, - id: "0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127", - size: 170, - parentID: - "0xffffffff00000000000000000000000000000000000000000000000000000000", - timestamp: 1530014400, - gasLimit: 10000000, - beneficiary: "0x0000000000000000000000000000000000000000", - gasUsed: 0, - totalScore: 0, - txsRoot: - "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", - txsFeatures: 0, - stateRoot: - "0x4ec3af0acbad1ae467ad569337d2fe8576fe303928d35b8cdd91de47e9ac84bb", - receiptsRoot: - "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", - signer: "0x0000000000000000000000000000000000000000", - isTrunk: true, - transactions: [], - }, - }, + "explorerUrl": "https://insight.vecha.in/#/test", + "blockTime": 10000, + "genesis": { + "number": 0, + "id": "0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127", + "size": 170, + "parentID": "0xffffffff00000000000000000000000000000000000000000000000000000000", + "timestamp": 1530014400, + "gasLimit": 10000000, + "beneficiary": "0x0000000000000000000000000000000000000000", + "gasUsed": 0, + "totalScore": 0, + "txsRoot": "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", + "txsFeatures": 0, + "stateRoot": "0x4ec3af0acbad1ae467ad569337d2fe8576fe303928d35b8cdd91de47e9ac84bb", + "receiptsRoot": "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", + "signer": "0x0000000000000000000000000000000000000000", + "isTrunk": true, + "transactions": [] + } + } }; -export default config; + export default config; \ No newline at end of file diff --git a/packages/contracts/deploy_output/contracts.txt b/packages/contracts/deploy_output/contracts.txt index 148969c..b183b78 100644 --- a/packages/contracts/deploy_output/contracts.txt +++ b/packages/contracts/deploy_output/contracts.txt @@ -1,3 +1,3 @@ { - "fiorino": "0x117bb006a8af929fBcd7E7C245597A8F676eCBcE" + "fiorino": "0xDc9927805Df9075113e9786ADDD793Fc1786A170" } \ No newline at end of file diff --git a/packages/contracts/package.json b/packages/contracts/package.json index b385d32..651762b 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -69,6 +69,7 @@ "@nomicfoundation/hardhat-toolbox": "^3.0.0", "@nomicfoundation/hardhat-verify": "^1.1.1", "@typechain/ethers-v6": "^0.4.3", + "@types/archiver": "^6.0.2", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", @@ -77,4 +78,4 @@ "nft.storage": "^7.1.1", "prettier": "^3.2.4" } -} \ No newline at end of file +} diff --git a/packages/contracts/scripts/checkContractsDeployment.ts b/packages/contracts/scripts/checkContractsDeployment.ts index a8c44d7..1092e5f 100644 --- a/packages/contracts/scripts/checkContractsDeployment.ts +++ b/packages/contracts/scripts/checkContractsDeployment.ts @@ -24,7 +24,10 @@ async function main() { // check if the contracts specified in the config file are deployed on the network, if not, deploy them (only on solo network) async function checkContractsDeployment() { try { - const code = await ethers.provider.getCode(config.fiorinoContractAddress); + const fiorinoContract = config.fiorinoContractAddress; + const code = fiorinoContract + ? await ethers.provider.getCode(fiorinoContract) + : "0x"; if (code === "0x") { console.log( `fiorino contract not deployed at address ${config.fiorinoContractAddress}` @@ -57,11 +60,15 @@ async function overrideLocalConfigWithNewContracts( const toWrite = `import { AppConfig } from \".\" \n const config: AppConfig = ${JSON.stringify(newConfig, null, 2)}; export default config;`; - const fileToWrite = network.name === "solo" ? "local.ts" : "solo-staging.ts"; + const configFiles: { [key: string]: string } = { + solo: "local.ts", + testnet: "testnet.ts", + main: "mainnet.ts", + }; + const fileToWrite = configFiles[network.name]; const localConfigPath = path.resolve(`../config/${fileToWrite}`); console.log(`Writing new config file to ${localConfigPath}`); fs.writeFileSync(localConfigPath, toWrite); - console.log(`*** Deployed successfully ***`); } // We recommend this pattern to be able to use async/await everywhere diff --git a/packages/contracts/scripts/deploy/deploy.ts b/packages/contracts/scripts/deploy/deploy.ts index 0e263f1..81da8b5 100644 --- a/packages/contracts/scripts/deploy/deploy.ts +++ b/packages/contracts/scripts/deploy/deploy.ts @@ -2,6 +2,12 @@ import { ethers, network } from "hardhat"; import { ContractsConfig } from "@repo/config/contracts/type"; import { HttpNetworkConfig } from "hardhat/types"; import { saveContractsToFile } from "../helpers"; +import { Network } from "@repo/constants"; +import { AppConfig, getConfig } from "@repo/config"; +import fs from "fs"; +import path from "path"; + +const appConfig = getConfig(); export async function deployAll(config: ContractsConfig) { const start = performance.now(); @@ -32,20 +38,24 @@ export async function deployAll(config: ContractsConfig) { fiorino: await fiorino.getAddress(), }; + console.log("Contracts", contractAddresses); + await saveContractsToFile(contractAddresses); + + const end = new Date(performance.now() - start); console.log( - "================================================================================" + `Total execution time: ${end.getMinutes()}m ${end.getSeconds()}s` ); + console.log("Deployment completed successfully!"); console.log( "================================================================================" ); - console.log("Contracts", contractAddresses); - await saveContractsToFile(contractAddresses); - - const end = new Date(performance.now() - start); - console.log( - `Total execution time: ${end.getMinutes()}m ${end.getSeconds()}s` + await overrideContractConfigWithNewContracts( + { + fiorino, + }, + appConfig.network ); return { @@ -53,3 +63,27 @@ export async function deployAll(config: ContractsConfig) { }; // close the script } + +export async function overrideContractConfigWithNewContracts( + contracts: Awaited>, + network: Network +) { + const newConfig: AppConfig = { + ...appConfig, + fiorinoContractAddress: await contracts.fiorino.getAddress(), + }; + + // eslint-disable-next-line + const toWrite = `import { AppConfig } from \".\" \n const config: AppConfig = ${JSON.stringify(newConfig, null, 2)}; + export default config;`; + + const configFiles: { [key: string]: string } = { + solo: "local.ts", + testnet: "testnet.ts", + main: "mainnet.ts", + }; + const fileToWrite = configFiles[network.name]; + const localConfigPath = path.resolve(`../config/${fileToWrite}`); + console.log(`Writing new config file to ${localConfigPath}`); + fs.writeFileSync(localConfigPath, toWrite); +} diff --git a/yarn.lock b/yarn.lock index b10fa28..79c5854 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3139,6 +3139,13 @@ dependencies: fs-extra "^9.1.0" +"@types/archiver@^6.0.2": + version "6.0.2" + resolved "https://registry.yarnpkg.com/@types/archiver/-/archiver-6.0.2.tgz#0daf8c83359cbde69de1e4b33dcade6a48a929e2" + integrity sha512-KmROQqbQzKGuaAbmK+ZcytkJ51+YqDa7NmbXjmtC5YBLSyQYo21YaUnQ3HbaPFKL1ooo6RQ6OPYPIDyxfpDDXw== + dependencies: + "@types/readdir-glob" "*" + "@types/babel__core@^7.20.5": version "7.20.5" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.20.5.tgz#3df15f27ba85319caa07ba08d0721889bb39c017" @@ -3394,6 +3401,13 @@ "@types/prop-types" "*" csstype "^3.0.2" +"@types/readdir-glob@*": + version "1.1.5" + resolved "https://registry.yarnpkg.com/@types/readdir-glob/-/readdir-glob-1.1.5.tgz#21a4a98898fc606cb568ad815f2a0eedc24d412a" + integrity sha512-raiuEPUYqXu+nvtY2Pe8s8FEmZ3x5yAH4VkLdihcPdalvsHltomrRC9BzuStrJ9yk06470hS0Crw0f1pXqD+Hg== + dependencies: + "@types/node" "*" + "@types/responselike@^1.0.0": version "1.0.3" resolved "https://registry.yarnpkg.com/@types/responselike/-/responselike-1.0.3.tgz#cc29706f0a397cfe6df89debfe4bf5cea159db50" @@ -5142,6 +5156,7 @@ buffer-from@^1.0.0: integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== "buffer-polyfill@npm:buffer@^6.0.3", buffer@6.0.3, buffer@^6.0.1, buffer@^6.0.3: + name buffer-polyfill version "6.0.3" resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==