diff --git a/.dockerignore b/.dockerignore index f17d3f7ea..781908d34 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,7 +2,7 @@ node_modules/ yarn-error.log .env -/packages/govern-server/dev-data/ +dev-data/ # extra ignores to help docker caching .git diff --git a/.github/workflows/server-ci-cd.yml b/.github/workflows/server-ci-cd.yml deleted file mode 100644 index e6376b49d..000000000 --- a/.github/workflows/server-ci-cd.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Server CI/CD -on: - push: - paths: - - 'packages/govern-server/**' - branches: - - master - - develop - -env: - # This is a base repository and we use git refs to set the version of the container - # ${GITHUB_REF##*/} will be either a branch name or a tag depending on the event - REPO: aragon/govern-server - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - run: docker login -u ${{secrets.DOCKERHUB_USER}} -p ${{secrets.DOCKERHUB_TOKEN}} - - run: .github/scripts/docker-build.sh . $REPO ${GITHUB_SHA} - - release: - runs-on: ubuntu-latest - needs: build - steps: - - uses: actions/checkout@v2 - - run: docker login -u ${{secrets.DOCKERHUB_USER}} -p ${{secrets.DOCKERHUB_TOKEN}} - - run: .github/scripts/docker-release.sh $REPO:${GITHUB_SHA} $REPO:${GITHUB_REF##*/} - - run: .github/scripts/docker-release.sh $REPO:${GITHUB_SHA} $REPO:latest - - deploy-rinkeby: - if: github.ref == 'refs/heads/develop' - runs-on: ubuntu-latest - needs: release - steps: - - uses: actions/checkout@v2 - - run: .github/scripts/kubectl-config.sh ${{secrets.KUBE_CA}} ${{secrets.KUBE_SERVER}} ${{secrets.KUBE_TOKEN}} - - run: .github/scripts/kubectl-set-image.sh govern-server-rinkeby $REPO:${GITHUB_REF##*/} - - run: .github/scripts/kubectl-wait-ready.sh govern-server-rinkeby - # wait 10 sec for k8s to reroute ingress and check the endpoint - - run: sleep 10 && curl --fail https://govern-rinkeby.backend.aragon.org -H accept:text/html - - deploy-mainnet: - if: startsWith(github.ref, 'refs/heads/master') - runs-on: ubuntu-latest - needs: release - steps: - - uses: actions/checkout@v2 - - run: .github/scripts/kubectl-config.sh ${{secrets.KUBE_CA}} ${{secrets.KUBE_SERVER}} ${{secrets.KUBE_TOKEN}} - - run: .github/scripts/kubectl-set-image.sh govern-server $REPO:${GITHUB_REF##*/} - - run: .github/scripts/kubectl-wait-ready.sh govern-server - # wait 10 sec for k8s to reroute ingress and check the endpoint - - run: sleep 10 && curl --fail https://govern.backend.aragon.org -H accept:text/html diff --git a/.gitignore b/.gitignore index 497a2fcd8..ae0b90c27 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ node_modules/ yarn-error.log .env -/packages/govern-server/dev-data/ +dev-data/ .vscode \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c92853587..40849aacf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,6 @@ COPY ./packages/govern-contract-utils/package.json /app/packages/govern-contr COPY ./packages/govern-core/package.json /app/packages/govern-core/package.json COPY ./packages/govern-create/package.json /app/packages/govern-create/package.json COPY ./packages/govern-discord/package.json /app/packages/govern-discord/package.json -COPY ./packages/govern-server/package.json /app/packages/govern-server/package.json COPY ./packages/govern-subgraph/package.json /app/packages/govern-subgraph/package.json COPY ./packages/govern-token/package.json /app/packages/govern-token/package.json diff --git a/packages/govern-server/docker-compose.yml b/docker-compose.yml similarity index 100% rename from packages/govern-server/docker-compose.yml rename to docker-compose.yml diff --git a/package.json b/package.json index fa5b1a2e0..5767c5f24 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "test": "lerna run --stream --concurrency 1 test", "test:fast": "lerna run --stream test", "init:dev:env": "scripts/init.dev.env.sh", - "start:dev": "cd ./packages/govern-server/ && yarn start:containers", - "start:server": "yarn workspace @aragon/govern-server start:server", + "start:dev": "HOST_UID=$(id -u) HOST_GID=$(id -g) docker-compose up -d", + "stop:dev": "HOST_UID=$(id -u) HOST_GID=$(id -g) docker-compose down", "coverage": "lerna run --stream --concurrency 1 coverage", "build:contracts": "lerna run --scope=erc3k --scope=@aragon/govern-contract-utils --scope=@aragon/govern-core --scope=@aragon/govern-create --scope=@aragon/govern-token --stream compile", "compile:cached": "lerna run --stream compile:cached", diff --git a/packages/govern-server/.gitignore b/packages/govern-server/.gitignore deleted file mode 100644 index 8d4bfcfd8..000000000 --- a/packages/govern-server/.gitignore +++ /dev/null @@ -1 +0,0 @@ -nohup.out diff --git a/packages/govern-server/README.md b/packages/govern-server/README.md deleted file mode 100644 index 7e9005415..000000000 --- a/packages/govern-server/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Govern Server - -## How to query data - -Govern Server is exposing a GraphQL API that lets you fetch data related to your Govern DAOs. Have a look at the [Govern Server API documentation](https://docs.aragon.org/govern/developers/server-api) for the list of types and queries you can use. - -## Directory structure - -``` -# The core server library, which will be in a separate package later. -# We should keep in mind that this part will eventually run in the -# browser, enabling the fully decentralized mode of Aragon Govern. -/src/core - -# API endpoints are prefixed by “api-”. We’ll only have a GraphQL API at first, -# and a REST API will be added later. Each API server exposes a single start() -# function with its configuration as a parameter. -/src/api-graphql -``` - -## Docker container - -Build a docker container and expose server on http://localhost:3000: - -```console -docker build . -t govern-server -docker run -it --rm -d -p 3000:3000 --name govern-server govern-server -``` - -Remove the container: - -```console -docker stop govern-server -``` - -## CI/CD - -Github Actions workflow `server-ci-cd.yml` builds and deploys a server container when creating `v*` tags in the `master` branch. - -Deployments can be triggered using lerna: - -```console -yarn lerna version [ major | minor | patch ] -``` diff --git a/packages/govern-server/package.json b/packages/govern-server/package.json deleted file mode 100644 index 5ac9bf300..000000000 --- a/packages/govern-server/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "@aragon/govern-server", - "version": "1.0.0-beta.12", - "license": "GPL-3.0", - "scripts": { - "dev": "ts-node-dev src/index.ts", - "start": "yarn start:containers && yarn start:server", - "start:server": "node --loader ts-node/esm.mjs src/index.ts", - "start:containers": "HOST_UID=$(id -u) HOST_GID=$(id -g) docker-compose up -d", - "stop:containers": "HOST_UID=$(id -u) HOST_GID=$(id -g) docker-compose down", - "server:healthcheck": "npx wait-on http://localhost:3000/.well-known/apollo/server-health" - }, - "dependencies": { - "@urql/core": "^1.13.1", - "apollo-server": "^2.18.2", - "dotenv": "^8.2.0", - "express": "^4.17.1", - "graphql": "^15.3.0", - "graphql-tag": "^2.10.3", - "isomorphic-unfetch": "^3.1.0", - "ts-node": "^9.0.0" - }, - "devDependencies": { - "@types/express": "^4.17.8", - "ts-node-dev": "^1.0.0", - "typescript": "^3.8.3" - } -} diff --git a/packages/govern-server/src/api-graphql/index.ts b/packages/govern-server/src/api-graphql/index.ts deleted file mode 100644 index f79f74817..000000000 --- a/packages/govern-server/src/api-graphql/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ApolloServer } from 'apollo-server' -import { GovernCore } from '../core' -import resolvers from './resolvers' -import typeDefs from './schema' - -type Configuration = { - govern: GovernCore - httpPort: number -} - -export default async function start({ govern, httpPort }: Configuration) { - const server = new ApolloServer({ - resolvers: resolvers(govern), - typeDefs, - }) - return server.listen(httpPort) -} diff --git a/packages/govern-server/src/api-graphql/resolvers.ts b/packages/govern-server/src/api-graphql/resolvers.ts deleted file mode 100644 index ecea7334a..000000000 --- a/packages/govern-server/src/api-graphql/resolvers.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { IResolvers } from 'apollo-server' -import { GovernCore } from '../core' - -export default function resolvers(govern: GovernCore): IResolvers { - return { - Query: { - async dao(_, args) { - return govern.dao(args.name) - }, - async daos() { - return govern.daos() - }, - async registryEntry(_, args) { - return govern.registryEntry(args.name) - }, - async registryEntries(_, args) { - return govern.registryEntries() - }, - }, - Dao: { - async registryEntries(parent) { - return Promise.all( - parent.registryEntries - .map(async ({ id }: { id: string }) => { - const entry = await govern.registryEntry(id) - return entry - ? { - ...entry, - executor: govern.dao(entry.executor.address), - } - : null - }) - .filter(Boolean) - ) - }, - async queues(parent) { - return govern.queuesForDao(parent.name) - }, - }, - RegistryEntry: { - async executor(parent) { - return govern.queuesForDao(parent.name) - }, - }, - } -} diff --git a/packages/govern-server/src/api-graphql/schema.ts b/packages/govern-server/src/api-graphql/schema.ts deleted file mode 100644 index e9d47625f..000000000 --- a/packages/govern-server/src/api-graphql/schema.ts +++ /dev/null @@ -1,170 +0,0 @@ -import { gql } from 'apollo-server' - -export default gql` - type GovernRegistry { - id: ID! - address: String! - count: Int! - entries: [RegistryEntry!]! - } - - type RegistryEntry { - id: ID! - name: String! - queue: GovernQueue! - executor: Dao! - } - - type Dao { - id: ID! - address: String! - metadata: String - registryEntries: [RegistryEntry!]! - containers: [Container]! - roles: [Role!]! - queues: [GovernQueue]! - } - - type GovernQueue { - id: ID! - address: String! - config: Config! - registryEntries: [RegistryEntry!]! - queued: [Container!]! - roles: [Role!]! - } - - type Config { - id: ID! - queue: GovernQueue! - executionDelay: String! - scheduleDeposit: Collateral! - challengeDeposit: Collateral! - resolver: String! - rules: String! - } - - type Container { - id: ID! - queue: GovernQueue! - state: ContainerState! - config: Config! - payload: ContainerPayload! - history: [ContainerEvent!]! - } - - type ContainerPayload { - id: ID! - container: Container! - nonce: String! - executionTime: String! - submitter: String! - executor: Dao! - actions: [Action!]! - allowFailuresMap: String! - proof: String! - } - - type Collateral { - id: ID! - token: String! - amount: String! - } - - type Action { - id: ID! - payload: ContainerPayload! - to: String! - value: String! - data: String! - } - - type Role { - id: ID! - entity: String! - selector: String! - who: String! - granted: Boolean! - frozen: Boolean! - } - - enum ContainerState { - None - Scheduled - Approved - Challenged - Rejected - Cancelled - Executed - } - - # Container events - - interface ContainerEvent { - id: ID! - container: Container! - createdAt: String! - } - - type ContainerEventChallenge implements ContainerEvent { - id: ID! - container: Container! - createdAt: String! - actor: String! - collateral: Collateral! - disputeId: String! - reason: String! - resolver: String! - } - - type ContainerEventExecute implements ContainerEvent { - id: ID! - container: Container! - createdAt: String! - execResults: [String!]! - } - - type ContainerEventResolve implements ContainerEvent { - id: ID! - container: Container! - createdAt: String! - approved: Boolean! - } - - type ContainerEventRule implements ContainerEvent { - id: ID! - container: Container! - createdAt: String! - ruling: String! - } - - type ContainerEventSchedule implements ContainerEvent { - id: ID! - container: Container! - createdAt: String! - collateral: Collateral! - } - - type ContainerEventSubmitEvidence implements ContainerEvent { - id: ID! - container: Container! - createdAt: String! - evidence: String! - submitter: String! - finished: Boolean! - } - - type ContainerEventVeto implements ContainerEvent { - id: ID! - container: Container! - createdAt: String! - reason: String! - } - - type Query { - daos: [Dao!]! - dao(name: String!): Dao - registryEntry(name: String!): RegistryEntry - registryEntries: [RegistryEntry!] - } -` diff --git a/packages/govern-server/src/core/GovernCore.ts b/packages/govern-server/src/core/GovernCore.ts deleted file mode 100644 index 28fe011df..000000000 --- a/packages/govern-server/src/core/GovernCore.ts +++ /dev/null @@ -1,136 +0,0 @@ -import { - Address, - DaoData, - Networkish, - RegistryEntryData, - GovernQueueData, -} from './types' -import { ErrorInvalidNetwork, ErrorUnexpectedResult } from './errors' -import { toNetwork } from './utils' -import Network from './utils/network' -import GraphqlClient from './GraphqlClient' -import { - QUERY_DAO, - QUERY_DAOS, - QUERY_REGISTRY_ENTRY, - QUERY_REGISTRY_ENTRIES, - QUERY_QUEUE, - QUERY_QUEUES, - QUERY_QUEUES_BY_DAO, -} from './thegraph-queries' - -export type ConnectorTheGraphConfig = { - network: Networkish - subgraphUrl?: string - verbose?: boolean -} - -class GovernCore { - #gql: GraphqlClient - readonly config: ConnectorTheGraphConfig - readonly network: Network - - constructor(config: ConnectorTheGraphConfig) { - this.config = config - this.network = toNetwork(config.network) - - const subgraphUrl = config.subgraphUrl || this.network.subgraphUrl - - if (!subgraphUrl) { - throw new ErrorInvalidNetwork( - `The chainId ${this.network.chainId} is not supported ` + - `by the TheGraph connector.` - ) - } - - this.#gql = new GraphqlClient(subgraphUrl, { - verbose: config.verbose, - }) - } - - private async fetchResult( - queryAndParams: - | [any] - | [ - any, // TODO: use the type returned by gql`` - { [key: string]: any } - ], - errorMessage: string - ): Promise { - const [query, params] = queryAndParams - try { - const result = await this.#gql.performQuery(query, params) - return result.data as R - } catch (err) { - throw new ErrorUnexpectedResult(errorMessage) - } - } - - async dao(name: string): Promise { - const result = await this.fetchResult<{ - registryEntries: RegistryEntryData[] | null - }>( - [QUERY_DAO, { name }], - `Unexpected result when fetching the dao ${name}.` - ) - return result.registryEntries?.[0]?.executor ?? null - } - - async daos(): Promise { - const result = await this.fetchResult<{ governs: DaoData[] }>( - [QUERY_DAOS], - `Unexpected result when fetching the daos.` - ) - return result.governs ?? [] - } - - async queue(address: Address): Promise { - const result = await this.fetchResult<{ - governQueue: GovernQueueData | null - }>( - [QUERY_QUEUE, { queue: address.toLowerCase() }], - `Unexpected result when fetching the queue ${address}.` - ) - return result.governQueue ?? null - } - - async queues(): Promise { - const result = await this.fetchResult<{ - governQueues: GovernQueueData[] - }>([QUERY_QUEUES], `Unexpected result when fetching the queue.`) - return result.governQueues ?? [] - } - - async registryEntry(name: string): Promise { - const result = await this.fetchResult<{ - registryEntry: RegistryEntryData | null - }>( - [QUERY_REGISTRY_ENTRY, { name }], - `Unexpected result when fetching the registry entry ${name}.` - ) - return result.registryEntry ?? null - } - - async registryEntries(): Promise { - const result = await this.fetchResult<{ - registryEntries: RegistryEntryData[] - }>( - [QUERY_REGISTRY_ENTRIES], - `Unexpected result when fetching the registry entries.` - ) - return result.registryEntries ?? [] - } - - async queuesForDao(name: string): Promise { - const result = await this.fetchResult<{ - registryEntries: RegistryEntryData[] - }>( - [QUERY_QUEUES_BY_DAO, { name }], - `Unexpected result when fetching the queues for dao ${name}.` - ) - const queue = result.registryEntries?.[0]?.queue - return queue ? [queue] : [] - } -} - -export default GovernCore diff --git a/packages/govern-server/src/core/GraphqlClient.ts b/packages/govern-server/src/core/GraphqlClient.ts deleted file mode 100644 index 4fa2c7366..000000000 --- a/packages/govern-server/src/core/GraphqlClient.ts +++ /dev/null @@ -1,56 +0,0 @@ -import fetch from 'isomorphic-unfetch' -import { Client } from '@urql/core' -import { DocumentNode } from 'graphql' -import { ErrorConnection } from './errors' -import { QueryResult } from './types' - -type GraphqlClientOptions = { - verbose?: boolean -} - -class GraphqlClient { - #client: Client - #verbose: boolean - - constructor(url: string, options: GraphqlClientOptions = {}) { - this.#verbose = options.verbose ?? false - this.#client = new Client({ maskTypename: true, url, fetch }) - } - - async performQuery( - query: DocumentNode, - args: any = {} - ): Promise { - const result = await this.#client.query(query, args).toPromise() - - const resultMapped = this.mapQueryResult(result) - - if (this.#verbose) { - console.log(resultMapped) - } - - if (result.error) { - throw new ErrorConnection(this.mapQueryResultError(result) + resultMapped) - } - - return result - } - - private mapQueryResult(result: QueryResult): string { - return ( - `Endpoint: ${result.operation.context.url}\n\n` + - `Arguments: ${JSON.stringify(result.operation.variables, null, 2)}\n\n` + - `Query: ${result.operation.query.loc?.source.body}\n\n` + - `Returned data: ${JSON.stringify(result.data, null, 2)}\n\n` - ) - } - - private mapQueryResultError(result: QueryResult): string { - if (!result.error) { - return '' - } - return `${result.error.name}: ${result.error.message}\n\n` - } -} - -export default GraphqlClient diff --git a/packages/govern-server/src/core/config.ts b/packages/govern-server/src/core/config.ts deleted file mode 100644 index 6ba1fa327..000000000 --- a/packages/govern-server/src/core/config.ts +++ /dev/null @@ -1,18 +0,0 @@ -export const networks = [ - { - chainId: 1, - name: 'ethereum', - ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', - subgraphUrl: - 'https://graph.backend.aragon.org/subgraphs/name/aragon/aragon-govern-mainnet', - }, - { - chainId: 4, - name: 'rinkeby', - ensAddress: '0x98df287b6c145399aaa709692c8d308357bc085d', - subgraphUrl: - 'https://graph.backend.aragon.org/subgraphs/name/aragon/aragon-govern-rinkeby', - }, - - // TODO: add xDai -] diff --git a/packages/govern-server/src/core/errors.ts b/packages/govern-server/src/core/errors.ts deleted file mode 100644 index d3bf7a3a3..000000000 --- a/packages/govern-server/src/core/errors.ts +++ /dev/null @@ -1,82 +0,0 @@ -type ErrorOptions = { - code?: string - name?: string -} - -export class ErrorException extends Error { - constructor( - message = 'An unexpected error happened.', - { code = 'ErrorException', name = 'ErrorException' }: ErrorOptions = {} - ) { - super(message) - - // We define these as non-enumarable to prevent them - // from appearing with the error in the console. - this.defineNonEnumerable('name', name) - this.defineNonEnumerable('code', code) - } - - private defineNonEnumerable(name: string, value: any) { - Object.defineProperty(this, name, { value, enumerable: false }) - } -} - -export class ErrorInvalid extends ErrorException { - constructor( - message = 'The resource doesn’t seem to be valid.', - { code = 'ErrorInvalid', name = 'ErrorInvalid' }: ErrorOptions = {} - ) { - super(message, { code, name }) - } -} - -export class ErrorUnsupported extends ErrorException { - constructor( - message = 'The resource is not supported.', - { code = 'ErrorUnsupported', name = 'ErrorUnsupported' }: ErrorOptions = {} - ) { - super(message, { code, name }) - } -} - -export class ErrorNotFound extends ErrorException { - constructor( - message = 'The resource couldn’t be found.', - { code = 'ErrorNotFound', name = 'ErrorNotFound' }: ErrorOptions = {} - ) { - super(message, { code, name }) - } -} - -export class ErrorConnection extends ErrorException { - constructor( - message = 'An error happened while communicating with a remote server.', - { code = 'ErrorConnection', name = 'ErrorConnection' }: ErrorOptions = {} - ) { - super(message, { code, name }) - } -} - -export class ErrorUnexpectedResult extends ErrorException { - constructor( - message = 'The resource doesn’t correspond to the expected result.', - { - code = 'ErrorUnexpectedResult', - name = 'ErrorUnexpectedResult', - }: ErrorOptions = {} - ) { - super(message, { code, name }) - } -} - -export class ErrorInvalidNetwork extends ErrorInvalid { - constructor( - message = 'The network doesn’t seem to be valid.', - { - code = 'ErrorInvalidNetwork', - name = 'ErrorInvalidNetwork', - }: ErrorOptions = {} - ) { - super(message, { code, name }) - } -} diff --git a/packages/govern-server/src/core/index.ts b/packages/govern-server/src/core/index.ts deleted file mode 100644 index 8f1052886..000000000 --- a/packages/govern-server/src/core/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as GovernCore } from './GovernCore' diff --git a/packages/govern-server/src/core/thegraph-queries/dao.ts b/packages/govern-server/src/core/thegraph-queries/dao.ts deleted file mode 100644 index 2fa0a32b3..000000000 --- a/packages/govern-server/src/core/thegraph-queries/dao.ts +++ /dev/null @@ -1,39 +0,0 @@ -import gql from 'graphql-tag' - -const GovernDaoBase = gql` - fragment GovernDaoBase on Govern { - id - address - metadata - registryEntries { - id - } - containers { - id - } - roles { - id - } - } -` - -export const QUERY_DAO = gql` - query RegistryEntry($name: String!) { - registryEntries(where: { name: $name }, first: 1) { - id - executor { - ...GovernDaoBase - } - } - } - ${GovernDaoBase} -` - -export const QUERY_DAOS = gql` - query Govern { - governs { - ...GovernDaoBase - } - } - ${GovernDaoBase} -` diff --git a/packages/govern-server/src/core/thegraph-queries/index.ts b/packages/govern-server/src/core/thegraph-queries/index.ts deleted file mode 100644 index d56e97197..000000000 --- a/packages/govern-server/src/core/thegraph-queries/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export { QUERY_DAO, QUERY_DAOS } from './dao' -export { QUERY_REGISTRY_ENTRY, QUERY_REGISTRY_ENTRIES } from './registry' -export { QUERY_QUEUE, QUERY_QUEUES, QUERY_QUEUES_BY_DAO } from './queue' diff --git a/packages/govern-server/src/core/thegraph-queries/queue.ts b/packages/govern-server/src/core/thegraph-queries/queue.ts deleted file mode 100644 index 535665d9d..000000000 --- a/packages/govern-server/src/core/thegraph-queries/queue.ts +++ /dev/null @@ -1,53 +0,0 @@ -import gql from 'graphql-tag' - -const QueueBase = gql` - fragment QueueBase on GovernQueue { - id - address - config { - id - } - registryEntries { - id - } - queued { - id - state - config { - id - } - } - roles { - id - } - } -` - -export const QUERY_QUEUE = gql` - query GovernQueue($queue: String!) { - governQueue(id: $queue) { - ...QueueBase - } - } - ${QueueBase} -` - -export const QUERY_QUEUES = gql` - query GovernQueue { - governQueues { - ...QueueBase - } - } - ${QueueBase} -` - -export const QUERY_QUEUES_BY_DAO = gql` - query RegistryEntry($name: String!) { - registryEntries(where: { name: $name }, first: 1) { - queue { - ...QueueBase - } - } - } - ${QueueBase} -` diff --git a/packages/govern-server/src/core/thegraph-queries/registry.ts b/packages/govern-server/src/core/thegraph-queries/registry.ts deleted file mode 100644 index 0b3a7b592..000000000 --- a/packages/govern-server/src/core/thegraph-queries/registry.ts +++ /dev/null @@ -1,84 +0,0 @@ -import gql from 'graphql-tag' - -const RegistryEntryBase = gql` - fragment RegistryEntryBase on RegistryEntry { - id - name - queue { - id - } - executor { - id - } - } -` - -const RegistryEntryComplete = gql` - fragment RegistryEntryComplete on RegistryEntry { - id - name - queue { - id - address - config { - executionDelay - scheduleDeposit { - id - token - amount - } - challengeDeposit { - id - token - amount - } - resolver - rules - } - queued { - id - state - payload { - id - nonce - executionTime - submitter - actions { - id - to - value - data - } - allowFailuresMap - proof - } - history { - id - createdAt - } - } - } - executor { - id - address - } - } -` - -export const QUERY_REGISTRY_ENTRY = gql` - query RegistryEntry($name: String!) { - registryEntry(id: $name) { - ...RegistryEntryComplete - } - } - ${RegistryEntryComplete} -` - -export const QUERY_REGISTRY_ENTRIES = gql` - query RegistryEntry { - registryEntries { - ...RegistryEntryComplete - } - } - ${RegistryEntryComplete} -` diff --git a/packages/govern-server/src/core/types.ts b/packages/govern-server/src/core/types.ts deleted file mode 100644 index ee50da923..000000000 --- a/packages/govern-server/src/core/types.ts +++ /dev/null @@ -1,177 +0,0 @@ -import { OperationResult } from '@urql/core' - -export type Address = string - -export type Network = { - name: string - chainId: number - ensAddress: Address - subgraphUrl: string -} - -export type Networkish = - | { - chainId?: number - ensAddress?: Address - name?: string - subgraphUrl?: string - } - | string - | number - -export enum ContainerState { - None, - Scheduled, - Approved, - Challenged, - Rejected, - Cancelled, - Executed, -} - -export type CollateralData = { - id: string - token: string - amount: string -} - -export type RoleData = { - id: string - entity: Address - selector: string - who: Address - granted: boolean - frozen: boolean -} - -export type ActionData = { - id: string - payload: ContainerPayload - to: Address - value: string - data: string -} - -export type ContainerPayload = { - id: string - container: ContainerData - nonce: BigInt - executionTime: BigInt - submitter: string - executor: DaoData - actions: ActionData[] - allowFailuresMap: string - proof: string -} - -export type ContainerData = { - id: string - queue: GovernQueueData - state: ContainerState - config: ConfigData - payload: ContainerPayload - history: ContainerEvent[] -} - -export type DaoData = { - id: string - address: Address - metadata: string - registryEntries: RegistryEntryData[] - containers: ContainerData[] - roles: RoleData[] -} - -export type GovernQueueData = { - id: string - address: Address - config: ConfigData - registryEntries: RegistryEntryData[] - queued: ContainerData[] - roles: RoleData[] -} - -export type ConfigData = { - id: string - queue: GovernQueueData - executionDelay: string - scheduleDeposit: CollateralData - challengeDeposit: CollateralData - resolver: string - rules: string -} - -export type RegistryEntryData = { - id: string - name: string - executor: DaoData - queue: GovernQueueData -} - -export type QueryResult = OperationResult - -// Events - -export type ContainerEvent = - | ContainerEventChallenge - | ContainerEventExecute - | ContainerEventResolve - | ContainerEventRule - | ContainerEventSchedule - | ContainerEventSubmitEvidence - | ContainerEventVeto - -export type ContainerEventChallenge = { - id: string - container: ContainerData - createdAt: BigInt - actor: string - collateral: CollateralData - disputeId: BigInt - reason: string - resolver: string -} - -export type ContainerEventExecute = { - id: string - container: ContainerData - createdAt: BigInt - execResults: string[] -} - -export type ContainerEventResolve = { - id: string - container: ContainerData - createdAt: BigInt - approved: boolean -} - -export type ContainerEventRule = { - id: string - container: ContainerData - createdAt: BigInt - ruling: BigInt -} - -export type ContainerEventSchedule = { - id: string - container: ContainerData - createdAt: BigInt - collateral: CollateralData -} - -export type ContainerEventSubmitEvidence = { - id: string - container: ContainerData - createdAt: BigInt - evidence: string - submitter: string - finished: boolean -} - -export type ContainerEventVeto = { - id: string - container: ContainerData - createdAt: BigInt - reason: string -} diff --git a/packages/govern-server/src/core/utils/index.ts b/packages/govern-server/src/core/utils/index.ts deleted file mode 100644 index 08b5b40b7..000000000 --- a/packages/govern-server/src/core/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './network' diff --git a/packages/govern-server/src/core/utils/network.ts b/packages/govern-server/src/core/utils/network.ts deleted file mode 100644 index 68406b7ac..000000000 --- a/packages/govern-server/src/core/utils/network.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { networks } from '../config' -import { ErrorInvalidNetwork } from '../errors' -import { Address, Network as NetworkType, Networkish } from '../types' - -class Network { - #chainId: number - #ensAddress: Address - #name: string - #subgraphUrl: string - - constructor({ - chainId, - ensAddress, - name, - }: { - chainId?: number - ensAddress?: Address - name?: string - }) { - if (name === undefined && chainId === undefined) { - throw new ErrorInvalidNetwork( - `Network: no name or chainId passed. ` + - `Please provide at least one of these.` - ) - } - - // Handle the case of having a name but no chainId. - if (name !== undefined && chainId === undefined) { - const _chainId = networkFromName(name)?.chainId - - if (_chainId === undefined) { - throw new ErrorInvalidNetwork( - `Network: invalid name provided: ${name}. ` + - `Please use provide a chainId or use one of the following names: ` + - networks.map((network) => network.chainId).join(', ') + - `.` - ) - } - - this.#chainId = _chainId - } - - // Just a little help for TypeScript, at this - // point we know that chainId cannot be undefined. - this.#chainId = chainId as number - - const chainIdNetwork = networkFromChainId(this.#chainId) - - if (!chainIdNetwork) { - throw new ErrorInvalidNetwork( - `Network: invalid chainId provided: ${chainId}. ` + - `Please use one of the following: ` + - networks.map((network) => network.chainId).join(', ') + - `.` - ) - } - - this.#name = name ?? chainIdNetwork.name - this.#ensAddress = ensAddress ?? chainIdNetwork.ensAddress - this.#subgraphUrl = chainIdNetwork.subgraphUrl - } - - get chainId() { - return this.#chainId - } - - get ensAddress() { - return this.#ensAddress - } - - get name() { - return this.#name - } - - get subgraphUrl() { - return this.#subgraphUrl - } -} - -function networkFromChainId(chainId: number): NetworkType | null { - return ( - networks.find((network: NetworkType) => network.chainId === chainId) || null - ) -} - -function networkFromName(name: string): NetworkType | null { - return networks.find((network: NetworkType) => network.name === name) || null -} - -export function toNetwork(network: Networkish): Network { - if (!network) { - throw new ErrorInvalidNetwork(`Network: incorrect value provided.`) - } - - if (typeof network === 'string') { - return new Network({ name: network }) - } - - if (typeof network === 'number') { - return new Network({ chainId: network }) - } - - return new Network(network) -} - -export default Network diff --git a/packages/govern-server/src/env.ts b/packages/govern-server/src/env.ts deleted file mode 100644 index 37f804811..000000000 --- a/packages/govern-server/src/env.ts +++ /dev/null @@ -1,14 +0,0 @@ -function graphqlHttpPort(): number { - const port = parseInt(process.env.GVN_GRAPHQL_HTTP_PORT as string, 10) - return isNaN(port) ? 3000 : port -} - -function chainId(): number { - const chainId = parseInt(process.env.GVN_CHAIN_ID as string, 10) - return isNaN(chainId) ? 4 : chainId -} - -export default { - chainId: chainId(), - graphqlHttpPort: graphqlHttpPort(), -} diff --git a/packages/govern-server/src/index.ts b/packages/govern-server/src/index.ts deleted file mode 100644 index fd81a70dd..000000000 --- a/packages/govern-server/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import env from './env' -import startGraphql from './api-graphql' -import { GovernCore } from './core' - -async function main() { - const govern = new GovernCore({ network: 1 }) - - const { url: graphqlUrl } = await startGraphql({ - govern, - httpPort: env.graphqlHttpPort, - }) - - console.log() - console.log(`GraphQL API listening on ${graphqlUrl}`) -} - -main() diff --git a/packages/govern-server/src/types.ts b/packages/govern-server/src/types.ts deleted file mode 100644 index 79ea8b124..000000000 --- a/packages/govern-server/src/types.ts +++ /dev/null @@ -1 +0,0 @@ -export type Address = string diff --git a/packages/govern-server/tsconfig.json b/packages/govern-server/tsconfig.json deleted file mode 100644 index 3327d4958..000000000 --- a/packages/govern-server/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "allowSyntheticDefaultImports": true, - "alwaysStrict": true, - "baseUrl": ".", - "composite": true, - "declaration": true, - "declarationMap": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "module": "commonjs", - "moduleResolution": "node", - "resolveJsonModule": true, - "skipLibCheck": true, - "sourceMap": true, - "strict": true, - "target": "es2019" - }, - "include": ["src"] -} diff --git a/packages/govern/internal/clients/graphql/GraphQLClient.ts b/packages/govern/internal/clients/graphql/GraphQLClient.ts index 302c674e7..d8872c169 100644 --- a/packages/govern/internal/clients/graphql/GraphQLClient.ts +++ b/packages/govern/internal/clients/graphql/GraphQLClient.ts @@ -4,7 +4,6 @@ import gql from 'graphql-tag' import ClientInterface from '../lib/ClientInterface' /** - * TODO: Use QueryResult type from govern-server/core * * @class GraphQLClient */ diff --git a/scripts/init.dev.env.sh b/scripts/init.dev.env.sh index 1d505683f..19fbeaf7f 100755 --- a/scripts/init.dev.env.sh +++ b/scripts/init.dev.env.sh @@ -35,7 +35,7 @@ fi # Init docker containers # ---------------------------------- -cd ../govern-server/ +cd ../../ if [[ -d "./dev-data" ]]; then rm -rf ./dev-data @@ -45,10 +45,10 @@ mkdir -p ./dev-data/postgres mkdir -p ./dev-data/ipfs if [[ "$(docker ps -a | grep graph)" ]]; then - yarn stop:containers + yarn stop:dev fi -yarn start:containers +yarn start:dev if [ $? -ne 0 ] then @@ -80,7 +80,7 @@ echo -e ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Create local subgraph # --------------------- -cd ../govern-subgraph/ +cd ./packages/govern-subgraph/ yarn create-local if [ $? -ne 0 ] @@ -123,8 +123,8 @@ else echo "** **" echo "** Govern: local dev env initialized **" echo "** **" - echo "** Execute from now on just 'yarn start:dev' in the root folder or **" - echo "** 'yarn start:containers' in the 'govern-server' package. **" + echo "** Execute from now on just 'yarn start:dev' in the root folder. **" + echo "** **" echo "** **" echo -e ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>${NC}" fi