Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/service deployments #260

Merged
merged 31 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b80ca28
Refactor existing infra
shanejearley Feb 14, 2023
058cbfa
Add nodes provider to cdk
shanejearley Feb 14, 2023
353c9e0
Add nodes cdk index and tests
shanejearley Feb 14, 2023
7c85efd
Edit @casimir/keys tsconf
shanejearley Feb 14, 2023
2c65ff2
Remove stale git cache
shanejearley Feb 15, 2023
6e49eb3
Switch auth server from lambda to fargate
shanejearley Feb 16, 2023
c010a23
Clean up auth tsconfig
shanejearley Feb 16, 2023
12f75a5
Add auth df
shanejearley Feb 16, 2023
b54202a
Update auth port and service asset path
shanejearley Feb 16, 2023
7f82950
Update about in README.md
shanejearley Feb 16, 2023
82fec64
Move submodules pull to preinstall
shanejearley Feb 16, 2023
6bbaab2
Move submodules pull to preinstall
shanejearley Feb 16, 2023
5d06836
Clean up cdk providers
shanejearley Feb 18, 2023
cb6cb58
Update include in cdk.json
shanejearley Feb 18, 2023
b0c47ff
Update conditional logic for stacks
shanejearley Feb 18, 2023
334019e
Comment out empty signTransaction
shanejearley Feb 18, 2023
6950bfc
Fix conflicts
shanejearley Feb 18, 2023
b6bf88e
Remove unused pages plugin
shanejearley Feb 18, 2023
916bd96
Update README.md to latest instructions
shanejearley Feb 18, 2023
b6814dc
Update users asset path
shanejearley Feb 18, 2023
f79429b
Remove contract docs from git
shanejearley Feb 18, 2023
2b28a7e
Refactor cdk stacks
shanejearley Feb 19, 2023
36525fc
Switch from fargate to lb-ecs-ec2 service pattern
shanejearley Feb 19, 2023
968b2ca
Remove a floating line of code
shanejearley Feb 19, 2023
b844147
Condense stack interfaces to single file
shanejearley Feb 21, 2023
083aff6
Update users df
shanejearley Feb 21, 2023
8c0bea0
Refactor config strings
shanejearley Feb 21, 2023
6daf827
Refactor static props to config
shanejearley Feb 21, 2023
1393ae7
Update dev script
shanejearley Feb 22, 2023
e6622fb
Switch users service to fargate
shanejearley Feb 22, 2023
042b22a
Fix merge conflicts
shanejearley Feb 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
env:
PUBLIC_STAGE: ${{ env.STAGE }}

- name: Test cdk stacks
run: npm run test --workspace @casimir/cdk
- name: Test cdk deployment
run: npm run test:cdk
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
PUBLIC_STAGE: ${{ env.STAGE }}

- name: Deploy cdk infrastructure
run: npm run deploy
run: npm run deploy:cdk

- name: Select success emoji
if: ${{ success() }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
PUBLIC_STAGE: ${{ env.STAGE }}

- name: Deploy cdk infrastructure
run: npm run deploy
run: npm run deploy:cdk

- name: Sync new version with develop
if: ${{ github.actor != 'nektos/act' }}
Expand Down
2 changes: 0 additions & 2 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

git submodule update --init --recursive

git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD --exit-code -- package-lock.json > /dev/null 2>&1 || echo "📦 package-lock.json changed. Running npm install..." && npm install
149 changes: 63 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

## About

Casimir is an all-in-one platform that allows users to trade, stake and track their assets while holding their own keys. One of Casimir's primary objectives is to reward crypto users for directly participating-in and strengthening the networks they rely on – by helping them stake directly to the most reliable (big and small) validators on PoS networks.
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

Expand All @@ -33,14 +33,8 @@ Make sure your development environment has these prerequisites.

3. [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`.

4. [SAM CLI (v1.x)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-mac.html) - tool for mocking backend services locally.

> 🚩 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).

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

### Setup

Clone the repository, checkout a new branch from develop, and install all workspace dependencies.
Expand All @@ -54,131 +48,115 @@ 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).

### Apps
### Serve

You can get up and running without configuration. You can also mock local backend changes and customize your environment.

1. For frontend changes – run the development server and use the `dev` stage backend services.

```zsh
npm run dev
```
For frontend changes – run the development server and use the `dev` stage backend services.

> 🚩 This will also preconfigure the application environment with the AWS credentials for the `consensus-networks-dev` profile (set PROFILE="some-other-name" in a [.env](.env) if you want to override).

2. For fullstack changes – run the development server and mock the local backend services.

```zsh
npm run dev --mock
```

> 🚩 You will need the [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-mac.html) for local mocking.
```zsh
npm run dev
```

3. Emulate a Ledger hardware wallet. The default application is ethereum, and we also currently have support for the bitcoin and solana applications.
> 🚩 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).

```zsh
npm run dev --ledger # or specify --ledger=ethereum, --ledger=bitcoin, or --ledger=solana
```
For fullstack changes – run the development server and mock the local backend services.

> 🚩 On MacOS, if you get an error because port 5000 is in use, go to  > System Preferences... > Sharing and uncheck Airplay Receiver.
```zsh
npm run dev --mock
```

4. Emulate a Trezor hardware wallet. You also need to make sure to add [these prerequisites](https://github.com/trezor/trezor-user-env#prerequisites).
Emulate a Ledger hardware wallet. The default application is ethereum, and we also currently have support for the bitcoin and solana applications.

```zsh
npm run dev --trezor
```
```zsh
npm run dev --ledger # or specify --ledger=ethereum, --ledger=bitcoin, or --ledger=solana
```

5. Expose any servers running on local ports using local tunnel.
> 🚩 On MacOS, if you get an error because port 5000 is in use, go to  > System Preferences... > Sharing and uncheck Airplay Receiver.

```zsh
npm run dev --external
```

6. The commands and flags 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`.
Emulate a Trezor hardware wallet. You also need to make sure to add [these prerequisites](https://github.com/trezor/trezor-user-env#prerequisites).

```zsh
# @casimir/web
npm run dev # or
npm run dev:web
```zsh
npm run dev --trezor
```

# @casimir/landing
npm run dev:landing
```
Expose any servers running on local ports using local tunnel.

### Hardhat
```zsh
npm run dev --external
```

Ethereum contract development is serviced through [Hardhat](https://hardhat.io/). The Hardhat development environment is configured in the [contracts/ethereum/hardhat.config.ts](contracts/ethereum/hardhat.config.ts) file.
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`.

1. Compile the contracts in [contracts/ethereum](contracts/ethereum).

```zsh
npm run task:compile --workspace @casimir/ethereum
```
```zsh
# @casimir/web
npm run dev # or
npm run dev:web

2. Deploy a contract, specifically [contracts/ethereum/src/SSVManager.sol](contracts/ethereum/src/Sample.sol) with [contracts/ethereum/deploy/ssv.deploy.ts](contracts/ethereum/deploy/ssv.deploy.ts).
# @casimir/landing
npm run dev:landing
```

```zsh
npm run deploy:ssv --workspace @casimir/ethereum
```
### Contracts

3. Test the Sample with the tests in [contracts/ethereum/test/sample.ts](contracts/ethereum/test/sample.ts).
Ethereum contracts are configured with a Hardhat development environment in the [contracts/ethereum/hardhat.config.ts](contracts/ethereum/hardhat.config.ts) file.

```zsh
npm run test --workspace @casimir/ethereum
```
Run all contract tests.

4. Use a contract in the Casimir web app.
```zsh
npm run test:ethereum
```

```typescript
// Todo add Casimir Typescript usage
```
Compile the contracts in [contracts/ethereum](contracts/ethereum).

5. Clean [contracts/ethereum/build/artifacts](contracts/ethereum/build/artifacts) and [contracts/ethereum/build/cache](contracts/ethereum/build/cache)).
```zsh
npm run task:compile --workspace @casimir/ethereum
```

```zsh
npm run task:clean --workspace @casimir/ethereum
```
Deploy a contract, specifically [contracts/ethereum/src/SSVManager.sol](contracts/ethereum/src/SSVManager.sol) with [contracts/ethereum/scripts/ssv.deploy.ts](contracts/ethereum/deploy/ssv.deploy.ts).

> 🚩 Note, this is required if you change the Hardhat configuration.
```zsh
npm run deploy:ssv --workspace @casimir/ethereum
```

### Local Nodes

Run local cryptonodes for fast and flexible development.

1. Run a local Ethereum node without archived data.
Run a local Ethereum node without archived data.

```zsh
npm run dev:ethereum
```
```zsh
npm run dev:ethereum
```

2. Run a local Ethereum node with archived data from mainnet.
Run a local Ethereum node with archived data from mainnet.

```zsh
npm run dev:ethereum --fork=mainnet
```
```zsh
npm run dev:ethereum --fork=mainnet
```

3. Run a local Ethereum node with archived data from Goerli testnet.
Run a local Ethereum node with archived data from Goerli testnet.

```zsh
npm run dev:ethereum --fork=goerli
```
```zsh
npm run dev:ethereum --fork=goerli
```

> 🚩 Note, while the fork starts with the same state as the specified network, it lives as a local development network.
> 🚩 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.

```zsh
PROFILE="some-other-aws-name"
AWS_PROFILE="some-other-aws-name"
STAGE="sandbox"
```

#### Supported Variables

| Name | Description | Default |
| --- | --- | --- |
| `PROFILE` | AWS profile name | `"consensus-networks-dev"` |
| `AWS_PROFILE` | AWS profile name | `"consensus-networks-dev"` |
| `STAGE` | Environment stage name | `"dev"` |

### Scripts and dependencies
Expand All @@ -191,7 +169,7 @@ Install all monorepo dependencies.
npm install
```

Clean all monorepo dependencies (remove all `node_modules` before a fresh install).
Clean all monorepo dependencies (remove all `node_modules` and `package-lock.json` before a fresh install).

```zsh
npm run clean
Expand Down Expand Up @@ -232,7 +210,7 @@ Code is organized into work directories (apps, services, infrastructure – and
├── scripts/ (devops and build scripts)
| └── local/ (mock and serve tasks)
├── services/ (backend services)
| └── auth/ (auth lambda api)
| └── users/ (users express api)
└── package.json (project-wide npm dependencies and scripts)
```

Expand All @@ -253,4 +231,3 @@ Feel free to use any editor, but here's a configuration that works with this cod
This respository is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md)

10 changes: 5 additions & 5 deletions apps/web/src/composables/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LoginCredentials } from '@casimir/types'
import useEnvironment from '@/composables/environment'
import { ProviderString } from '@casimir/types'

const { authBaseURL } = useEnvironment()
const { usersBaseURL } = useEnvironment()

export default function useAuth() {
async function getMessage(provider: ProviderString, address: string) {
Expand All @@ -13,7 +13,7 @@ export default function useAuth() {
'Content-Type': 'application/json'
}
}
return await fetch(`${authBaseURL}/auth/${provider}/${address}`, requestOptions)
return await fetch(`${usersBaseURL}/auth/${provider}/${address}`, requestOptions)
}

async function signupOrLoginAuth(signupCredentials: SignupLoginCredentials) {
Expand All @@ -24,7 +24,7 @@ export default function useAuth() {
},
body: JSON.stringify(signupCredentials)
}
return await fetch(`${authBaseURL}/signupLogin`, requestOptions)
return await fetch(`${usersBaseURL}/signupLogin`, requestOptions)
}

async function signUpAuth(signupCredentials: SignupLoginCredentials) {
Expand All @@ -35,7 +35,7 @@ export default function useAuth() {
},
body: JSON.stringify(signupCredentials)
}
const response = await fetch(`${authBaseURL}/signup`, requestOptions)
const response = await fetch(`${usersBaseURL}/signup`, requestOptions)
return response
}

Expand All @@ -53,7 +53,7 @@ export default function useAuth() {
},
body: JSON.stringify(loginCredentials)
}
return await fetch(`${authBaseURL}/login`, requestOptions)
return await fetch(`${usersBaseURL}/login`, requestOptions)
}

return {
Expand Down
14 changes: 8 additions & 6 deletions apps/web/src/composables/environment.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
export default function useEnvironment() {
const authBaseURL = _getAuthBaseURL()
const usersBaseURL = getUsersBaseURL()
const ethereumURL = import.meta.env.PUBLIC_ETHEREUM_URL || 'http://127.0.0.1:8545'
const ledgerType = import.meta.env.PUBLIC_SPECULOS_PORT ? 'speculos' : 'usb'
const speculosURL = import.meta.env.PUBLIC_SPECULOS_PORT ? `http://127.0.0.1:${import.meta.env.PUBLIC_SPECULOS_PORT}` : undefined
const walletConnectURL = 'https://bridge.walletconnect.org'

/**
* Get the auth base url for the current environment
* Get the users base url for the current environment
*
* @returns {string} The base URL for the auth API
* @returns {string} The base URL for the users API
*/
function _getAuthBaseURL(): string {
function getUsersBaseURL(): string {
if (import.meta.env.PUBLIC_AUTH_PORT) {
return `http://localhost:${import.meta.env.PUBLIC_AUTH_PORT}`
} else {
return `https://auth.${import.meta.env.PUBLIC_STAGE || 'dev'}.casimir.co`
const stage = import.meta.env.PUBLIC_STAGE
const subdomain = stage === 'prod' ? '' : `${stage}.`
return `https://users.${subdomain}casimir.co`
}
}
return {
authBaseURL,
usersBaseURL,
ethereumURL,
ledgerType,
speculosURL,
Expand Down
12 changes: 5 additions & 7 deletions apps/web/src/composables/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import { Account } from '@casimir/types'
import { Currency } from '@casimir/types'
import { ProviderString } from '@casimir/types'

// Demo const for user
const { usersBaseURL, ethereumURL } = useEnvironment()
import { dummy_user_account } from '@/pages/user-dash/composables/dummy_data.js'

const { authBaseURL, ethereumURL } = useEnvironment()
// 0xd557a5745d4560B24D36A68b52351ffF9c86A212
const user = ref<User | null>(null)

Expand Down Expand Up @@ -80,7 +78,7 @@ export default function useUsers () {
account: accountToAdd
})
}
const response = await fetch(`${authBaseURL}/users/add-sub-account`, requestOptions)
const response = await fetch(`${usersBaseURL}/users/add-sub-account`, requestOptions)
const json = await response.json()
return json
}
Expand All @@ -102,11 +100,11 @@ export default function useUsers () {
currency
})
}
return await fetch(`${authBaseURL}/users/remove-sub-account`, requestOptions)
return await fetch(`${usersBaseURL}/users/remove-sub-account`, requestOptions)
}

async function getMessage(address: string) {
const response = await fetch(`${authBaseURL}/auth/${address}`)
const response = await fetch(`${usersBaseURL}/auth/${address}`)
const json = await response.json()
const { message } = json
return message
Expand All @@ -120,7 +118,7 @@ export default function useUsers () {
},
body: JSON.stringify({ primaryAddress, updatedProvider, updatedAddress })
}
return await fetch(`${authBaseURL}/users/update-primary-account`, requestOptions)
return await fetch(`${usersBaseURL}/users/update-primary-account`, requestOptions)
}

const createDemoUser = (toggle: boolean) => {
Expand Down
Loading