diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 2274dff15..44c799977 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -4,6 +4,11 @@ on: pull_request: branches: [master, develop] +env: + PROJECT: casimir + STAGE: test + AWS_REGION: us-east-2 + jobs: test: name: Test @@ -14,6 +19,13 @@ jobs: with: submodules: 'recursive' + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + - name: Install and build all package dependencies run: npm ci env: diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index db16ea45d..cd3b91586 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -22,6 +22,10 @@ jobs: uses: actions/checkout@v3 with: submodules: 'recursive' + + - name: Install action dependencies + run: | + curl -sSf https://atlasgo.sh | sh - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 @@ -38,6 +42,9 @@ jobs: - name: Deploy cdk infrastructure run: npm run deploy:cdk + - name: Migrate users database + run: npm run migrations:users + - name: Slack the team if: ${{ success() || failure() }} uses: slackapi/slack-github-action@v1.23.0 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d8b6782ee..e7462738f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,6 +38,9 @@ jobs: - name: Deploy cdk infrastructure run: npm run deploy:cdk + - name: Migrate users database + run: npm run migrations:users + - name: Check out develop uses: actions/checkout@v3 with: diff --git a/.github/workflows/sandbox.yml b/.github/workflows/sandbox.yml new file mode 100644 index 000000000..41a478351 --- /dev/null +++ b/.github/workflows/sandbox.yml @@ -0,0 +1,49 @@ +# Reset to the latest file code in the develop branch before merging to develop +# Clean up your `Casimir${Stack}${Stage}` stacks from the AWS CloudFormation console after use +# If you want to use a different branch or stage name (not sandbox), edit line 7 or 11 accordingly +name: Push +on: + push: + branches: [sandbox] # Replace with your branch name + +env: + PROJECT: casimir + STAGE: sandbox # Replace with your stage name + AWS_REGION: us-east-2 + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + + # Skip any pushes with commit flag '(skip deploy)' + # Comment out for testing + if: ${{ !contains(github.event.head_commit.message, '(skip deploy)') }} + + steps: + - name: Check out the repo + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Install action dependencies + run: | + curl -sSf https://atlasgo.sh | sh + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Install and build all package dependencies + run: npm ci + env: + PUBLIC_STAGE: ${{ env.STAGE }} + + - name: Deploy cdk infrastructure + run: npm run deploy:cdk + + - name: Migrate users database + run: npm run migrations:users \ No newline at end of file diff --git a/.gitignore b/.gitignore index 41a103915..a3534697a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,6 @@ cdk-outputs.json # Sensitive **/**/secrets/*.json -services/crawler/.env \ No newline at end of file +services/crawler/.env + +.out \ No newline at end of file diff --git a/README.md b/README.md index 2f24c5dc2..fa7d2134b 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,6 @@ Casimir is a complete platform that allows users to monitor, move, and stake their assets while holding their own keys. With Casimir staking, users can easily and securely move funds in and out of decentralized staking pools that are operated by high-performing validators. -## Status - -Casimir is an early work-in-progress – check out [our website](https://casimir.co) for more information about what we're building. See ongoing tasks on our [project board](https://github.com/orgs/consensusnetworks/projects/9/views/1). - -Also, feel free to join our [discord server](https://discord.com/invite/Vy2b3gSZx8) if you want to say hello and discuss the project. - ## πŸ’» Development Get started contributing to Casimir's codebase. @@ -27,178 +21,147 @@ Get started contributing to Casimir's codebase. Make sure your development environment has these prerequisites. -1. [AWS CLI (v2.x)](https://aws.amazon.com/cli/) – create an [AWS profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) named `consensus-networks-dev`. +1. [Docker (v4.x)](https://docs.docker.com/engine/install/). -2. [Docker (v4.x)](https://docs.docker.com/engine/install/) - make sure your Docker runs on startup. +2. [Git (v2.x)](https://git-scm.com/downloads). You also need to make sure to have at least one SSH authentication key on your GitHub account (for the git cloning of submodules in various scripts). See [Adding a new SSH key to your GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account). -3. [Git (v2.x)](https://git-scm.com/downloads) – we use [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to manage shared code. +3. [Go (v1.18.x)](https://golang.org/doc/install). -4. [Go (v1.18.x)](https://golang.org/doc/install) – we use [Go modules](https://blog.golang.org/using-go-modules) to manage Go dependencies. +4. [Node.js (v18.x)](https://nodejs.org/en/download/). -5. [Node.js (v18.x)](https://nodejs.org/en/download/) – we use [nvm](https://github.com/nvm-sh/nvm) to manage Node.js versions. - -> 🚩 You also need to make sure to have at least one SSH authentication key on your GitHub account (for the git cloning of submodules in various scripts). See [Adding a new SSH key to your GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account). +5. (**Consensus Networks team only**) [AWS CLI (v2.x)](https://aws.amazon.com/cli/) – create an [AWS profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) named `consensus-networks-dev`. ### Setup -Clone the repository, checkout a new branch from develop, and install all workspace dependencies. +Clone the repository and checkout a new branch from develop, and install all workspace dependencies. ```zsh git clone https://github.com/consensusnetworks/casimir.git cd casimir git checkout -b feature/stake-button develop -npm install ``` -> 🚩 'All workspace dependencies' includes `package.json` dependencies listed in the project root and any workspace subdirectories. See [Scripts and dependencies](#scripts-and-dependencies). - -### Serve +### Install -You can get up and running without configuration. You can also mock local backend changes and customize your environment. +We are using [npm workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces) to simplify monorepo development workflows while keeping project-wide resources accessible. The core commands are below. -For frontend changes – run the development server and use the `dev` stage backend services. +Install all monorepo dependencies. The postinstall script will also build all contract types. ```zsh -npm run dev +npm install ``` -> 🚩 This will also preconfigure the application environment with the AWS credentials for the `consensus-networks-dev` profile (set AWS_PROFILE="some-other-name" in a [.env](.env) if you want to override). - -**All options:** - -| Flag | Description | Default | Example | -| --- | --- | --- | --- | -| `--app` | Which app to run | web | --app=landing | -| `--clean` | Whether to clean the local database | true | --clean=false | -| `--emulate` | Whether to use local wallet emulators | false | --emulate=ethereum | -| `--fork` | Which live Ethereum network to fork locally | goerli | --fork=mainnet | -| `--mock` | Whether to mock backend services and external contracts | true | --mock=false | -| `--network` | Which live Ethereum network to use | goerli | --network=mainnet | +Additional install commands: -**Example commands:** - -For fullstack changes – run the development server and mock the local backend services. +Clean all monorepo dependencies (remove all `node_modules` and `package-lock.json` before a fresh install). ```zsh -npm run dev --mock +npm run clean ``` -Emulate a Ledger hardware wallet. The default application is ethereum, and we also currently have support for the bitcoin and solana applications. +Install a project-wide dev dependency. ```zsh -npm run dev --ledger # or specify --ledger=ethereum, --ledger=bitcoin, or --ledger=solana +npm install -D some-dev-dependency ``` -> 🚩 On MacOS, if you get an error because port 5000 is in use, go to ο£Ώ > System Preferences... > Sharing and uncheck Airplay Receiver. - -Emulate a Trezor hardware wallet. You also need to make sure to add [these prerequisites](https://github.com/trezor/trezor-user-env#prerequisites). +Install a workspace dependency or dev dependency. ```zsh -npm run dev --trezor +npm install some-dependency --workspace @casimir/workspace-name # i.e. @casimir/web +# or +npm install -D some-dev-dependency --workspace @casimir/workspace-name ``` -The commands above apply to any package in the [apps](apps/) directory. While the default app is [@casimir/web](apps/web/), you can specify others by passing a subcommand to `npm run dev`. +### Environment -```zsh -# @casimir/web -npm run dev # or -npm run dev:web +Customize and override the defaults for your *local development environment* by creating a [.env](.env) file in the project root and adding values for any supported variables. Variable usage is explained more as needed in the sections below. -# @casimir/landing -npm run dev:landing -``` +**If you are on the Consensus Networks team**, make sure your AWS CLI and profile are configured correctly. By default, the scripts look for the `consensus-networks-dev` named profile, but you can override the `AWS_PROFILE` name to be used in the [.env](.env) file. Regardless, the profile must have access to the `consensus-networks-dev` account resources. -### Contracts +**If you are outside of the Consensus Networks team**, make sure to set `USE_SECRETS` to `false` and provide a valid `ETHEREUM_FORK_RPC_URL`. -Ethereum contracts are configured with a Hardhat development environment in the [contracts/ethereum/hardhat.config.ts](contracts/ethereum/hardhat.config.ts) file. Read more about `@casimir/ethereum` staking [here](contracts/ethereum/README.md). Below are some helpful commands for developing on or with the contracts. - -Run all contract tests. - -```zsh -npm run test:ethereum -``` +#### Supported Variables -Build the contracts in [contracts/ssv](contracts/ssv). +| Name | Description | Default | +| --- | --- | --- | +| `USE_SECRETS` | Whether to use AWS Secrets Manager | `true` | +| `AWS_PROFILE` | AWS profile name for accessing secrets | `consensus-networks-dev` | +| `PROJECT` | Project name | `casimir` | +| `STAGE` | Environment stage name | `dev` | +| `ETHEREUM_FORK_RPC_URL` | Ethereum RPC URL for local fork network | `https://eth-goerli.alchemyapi.io/v2/` | +| `ETHEREUM_RPC_URL` | Ethereum RPC URL for live networks | `http://127.0.0.1:8545` | +| `NETWORK` | Set live network (defaults to local fork network) | `` | +| `FORK` | Local fork network (defaults to supported testnet for each chain) | `testnet` | +| `MANAGER_ADDRESS` | Manager contract address | `` | +| `VIEWS_ADDRESS` | Views contract address | `` | +| `CRYPTO_COMPARE_API_KEY` | CryptoCompare API key | `` | +| `TUNNEL` | Whether to tunnel local network RPC URLs (for remote wallets) | `false` | +| `EMULATE` | Whether to emulate wallets | `false` | +| `LEDGER_APP` | Ledger app name | `ethereum` | +| `MOCK_ORACLE` | Whether to mock oracle | `true` | +| `MOCK_SERVICES` | Whether to mock backend services | `true` | +| `BUILD_PREVIEW` | Whether to preview web app production build | `false` | +| `VALIDATOR_COUNT` | Number of validators to generate for tests | `4` | + +### Apps + +The apps packages provide a vite server, and the accompanying scripts set up the chain networks, backend services, and deployed contracts as needed. + +Run the web app (with accompanying scripts) from the root directory. ```zsh -npm run build --workspace @casimir/ethereum +npm run dev ``` -Deploy a contract, specifically [contracts/ethereum/src/CasimirManager.sol](contracts/ethereum/src/CasimirManager.sol) with [contracts/ethereum/scripts/ssv.deploy.ts](contracts/ethereum/deploy/ssv.deploy.ts). +Run the landing (page) app from the root directory. ```zsh -npm run deploy:ssv --workspace @casimir/ethereum +npm run dev:landing ``` -### Local Nodes - -Run local cryptonodes for fast and flexible development. +**Additional configuration:** -Run a local Ethereum node without archived data. - -```zsh -npm run dev:ethereum -``` +- Set `EMULATE` to `true` to emulate Ledger and Trezor hardware wallets. +- Set `LEDGER_APP` to the name of the Ledger app to emulate (defaults to `ethereum`). +- Set `TUNNEL` to `true` to tunnel the local network RPC URLs (for remote wallets). +- Set `MOCK_ORACLE` to `false` to use pregenerated validators (or create them if unavailable). +- Set `MOCK_SERVICES` to `false` to use the deployed backend services for the current stage. +- Set `BUILD_PREVIEW` to `true` to run the local script with a production build preview of the web app. +- Set `VALIDATOR_COUNT` to the number of validators to generate for tests (defaults to `4`). -Run a local Ethereum node with archived data from mainnet. +### Contracts -```zsh -npm run dev:ethereum --fork=mainnet -``` +Ethereum contracts are configured with a Hardhat development environment in the [contracts/ethereum/hardhat.config.ts](contracts/ethereum/hardhat.config.ts) file. Read more about `@casimir/ethereum` staking [here](contracts/ethereum/README.md). Below are some helpful commands for developing on or with the contracts. -Run a local Ethereum node with archived data from Goerli testnet. +Run all contract tests. ```zsh -npm run dev:ethereum --fork=goerli +npm run test:ethereum ``` -> 🚩 Note, while the fork starts with the same state as the specified network, it lives as a local development network independent of the live network. - -### Environment - -Optionally customize and override the defaults for your *local development environment* by creating a [.env](.env) file in the project root and adding values for any supported variables. +Build the contracts in [contracts/ssv](contracts/ssv). ```zsh -AWS_PROFILE="some-other-aws-name" -STAGE="sandbox" +npm run build --workspace @casimir/ethereum ``` -#### Supported Variables - -| Name | Description | Default | -| --- | --- | --- | -| `AWS_PROFILE` | AWS profile name | `"consensus-networks-dev"` | -| `STAGE` | Environment stage name | `"dev"` | - -### Scripts and dependencies - -We are using [npm workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces) to simplify monorepo development workflows while keeping project-wide resources accessible. The core commands are below. - -Install all monorepo dependencies. +Run a local Ethereum network with deployed contracts, simulation scripts, and archived data from Goerli testnet. ```zsh -npm install +npm run dev:ethereum ``` -Clean all monorepo dependencies (remove all `node_modules` and `package-lock.json` before a fresh install). +**Additional configuration:** -```zsh -npm run clean -``` +- Set `MOCK_ORACLE` to `false` to use pregenerated validators (or create them if unavailable). +- Set `VALIDATOR_COUNT` to the number of validators to generate for tests (defaults to `4`). -Install a project-wide dev dependency. +### Emulators -```zsh -npm install -D some-dev-dependency -``` - -Install a workspace dependency or dev dependency. +We can emulate Ledger and Trezor hardware wallet wallets by setting the environment variable `EMULATE` to `true`. For Ledger, the default app is `ethereum`, but the app can be specified by setting the environment variable `LEDGER_APP`. For Trezor, we also need to make sure to add [these prerequisites](https://github.com/trezor/trezor-user-env#prerequisites). -```zsh -npm install some-dependency --workspace @casimir/workspace-name # i.e. @casimir/web -# or -npm install -D some-dev-dependency --workspace @casimir/workspace-name -``` +> 🚩 On MacOS, if you get an error because port 5000 is in use, go to ο£Ώ > System Preferences... > Sharing and uncheck Airplay Receiver. ## πŸ“Š Data @@ -206,18 +169,20 @@ Data schemas, data operations/workflows, and analytics and ML notebooks are stor ## Layout -Code is organized into work directories (apps, services, infrastructure – and more listed below). +Code is organized into work directories (apps, common, contracts, infrastructure, services, scripts, and more listed below). ```tree β”œβ”€β”€ .github/ (workflows and issue templates) | └── workflows/ (gh actions workflows) β”œβ”€β”€ apps/ (frontend apps) - |── landing/ (landing page app) +| |── landing/ (landing page app) | └── web/ (main web app) -β”œβ”€β”€ infrastructure/ (deployment resources) -| └── cdk/ (aws stacks) β”œβ”€β”€ common/ (shared code) | └── helpers/ (general utilities) +β”œβ”€β”€ contracts/ (blockchain contracts) +| └── ethereum/ (ethereum contracts) +β”œβ”€β”€ infrastructure/ (deployment resources) +| └── cdk/ (aws stacks) β”œβ”€β”€ scripts/ (devops and build scripts) | └── local/ (mock and serve tasks) β”œβ”€β”€ services/ (backend services) @@ -225,8 +190,6 @@ Code is organized into work directories (apps, services, infrastructure – and └── package.json (project-wide npm dependencies and scripts) ``` -> 🚩 While developing, most likely, you shouldn't have to change into any subdirectories to run commands. Individual **npm packages** (directories with a `package.json`) are managed from the project root with [workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces). See [Scripts and dependencies](#-scripts-and-dependencies). - ## Editor Feel free to use any editor, but here's a configuration that works with this codebase. diff --git a/apps/landing/package.json b/apps/landing/package.json index 2e1de7dfa..51005bb10 100644 --- a/apps/landing/package.json +++ b/apps/landing/package.json @@ -15,12 +15,12 @@ "vue-router": "^4.0.15" }, "devDependencies": { - "@vitejs/plugin-vue": "^2.3.3", + "@vitejs/plugin-vue": "^3.0.0", "autoprefixer": "^10.4.12", "postcss": "^8.4.18", "tailwindcss": "^3.2.0", "typescript": "^4.5.4", - "vite": "^2.9.9", + "vite": "^3.0.0", "vue-tsc": "^0.34.7" } } diff --git a/apps/landing/vite.config.ts b/apps/landing/vite.config.ts index ed3293579..c59bb6cae 100644 --- a/apps/landing/vite.config.ts +++ b/apps/landing/vite.config.ts @@ -4,9 +4,9 @@ import { fileURLToPath } from 'url' import * as path from 'path' export default defineConfig({ - server: { port: 3001 }, + server: { port: 3002 }, plugins: [ - vue({ include: [/\.vue$/] }) + vue() ], define: { 'global': 'globalThis', diff --git a/apps/web/index.html b/apps/web/index.html index ae191672f..dc80b1bf2 100644 --- a/apps/web/index.html +++ b/apps/web/index.html @@ -17,6 +17,10 @@
+ diff --git a/apps/web/package.json b/apps/web/package.json index f6f7768be..f7d49d5ed 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -3,8 +3,8 @@ "description": "Casimir web app", "private": true, "scripts": { - "dev": "vite", - "build": "vue-tsc --noEmit && vite build || echo '@casimir/web build failed because script + dependency issues are unresolved. Disregard any errors listed above this line.' && exit 0", + "dev": "vite --force", + "build": "vue-tsc --noEmit && vite build", "preview": "vite preview" }, "dependencies": { @@ -12,7 +12,6 @@ "@solana/web3.js": "^1.63.1", "@walletconnect/web3-provider": "^1.8.0", "borsh": "^0.7.0", - "browserify": "^17.0.0", "buffer": "^6.0.3", "d3": "^7.8.1", "ethers": "^5.7.2", @@ -24,17 +23,13 @@ "xlsx": "^0.18.5" }, "devDependencies": { - "@esbuild-plugins/node-globals-polyfill": "^0.1.1", - "@esbuild-plugins/node-modules-polyfill": "^0.1.4", - "@rollup/plugin-inject": "^4.0.4", - "@vitejs/plugin-vue": "^2.3.3", - "autoprefixer": "^10.4.7", - "esbuild-plugins-node-modules-polyfill": "^1.0.9", + "@vitejs/plugin-vue": "^3.0.0", + "autoprefixer": "^10.4.12", "postcss": "^8.4.14", "rollup-plugin-polyfill-node": "^0.11.0", - "tailwindcss": "^3.0.24", + "tailwindcss": "^3.2.0", "typescript": "^4.5.4", - "vite": "^2.9.9", + "vite": "^3.0.0", "vue-tsc": "^0.34.7" } } diff --git a/apps/web/src/@types/index.d.ts b/apps/web/src/@types/index.d.ts new file mode 100644 index 000000000..8829cb769 --- /dev/null +++ b/apps/web/src/@types/index.d.ts @@ -0,0 +1,4 @@ +declare module '@walletconnect/web3-provider/dist/umd/index.min.js' { + import WalletConnectProvider from '@walletconnect/web3-provider/dist/umd/index.min.js' + export default WalletConnectProvider +} \ No newline at end of file diff --git a/apps/web/src/App.vue b/apps/web/src/App.vue index 453470763..bcc9c80b2 100644 --- a/apps/web/src/App.vue +++ b/apps/web/src/App.vue @@ -1,11 +1,6 @@ diff --git a/apps/web/src/components/Wallet.vue b/apps/web/src/components/Wallet.vue index 01d05896c..e6f93d0c6 100644 --- a/apps/web/src/components/Wallet.vue +++ b/apps/web/src/components/Wallet.vue @@ -49,7 +49,7 @@ -