Skip to content

Commit

Permalink
chore: import sx-api repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekhmet committed Feb 15, 2024
2 parents a9ffcfa + 6f50d25 commit 309b05d
Show file tree
Hide file tree
Showing 31 changed files with 4,675 additions and 62 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,44 @@ on:
- master

jobs:
deploy_api_mainnet:
name: Deploy API to mainnet
environment: api_mainnet
concurrency:
group: api_mainnet
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Deploy if files have changed
run: ./scripts/deploy-changed.sh apps/api ${{ vars.DIGITALOCEAN_APP_ID }}

deploy_api_testnet:
name: Deploy API to testnet
environment: api_testnet
concurrency:
group: api_testnet
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Deploy if files have changed
run: ./scripts/deploy-changed.sh apps/api ${{ vars.DIGITALOCEAN_APP_ID }}

deploy_mana_prod:
name: Deploy mana to production
environment: mana_prod
Expand All @@ -22,5 +60,5 @@ jobs:
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Deploy if files changed
run: git diff-tree --no-commit-id --name-only HEAD -r | grep ^apps/mana && doctl apps create-deployment ${{ vars.DIGITALOCEAN_APP_ID }} || echo "No changes to mana"
- name: Deploy if files have changed
run: ./scripts/deploy-changed.sh apps/api ${{ vars.DIGITALOCEAN_APP_ID }}
12 changes: 12 additions & 0 deletions apps/api/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = LF
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=mysql://root:default_password@localhost:3306/checkpoint
14 changes: 14 additions & 0 deletions apps/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.DS_Store
node_modules
dist
build
.env
coverage

# Remove some common IDE working directories
.idea
.vscode
*.log

# Checkpoint
.checkpoint
21 changes: 21 additions & 0 deletions apps/api/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Snapshot Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
67 changes: 67 additions & 0 deletions apps/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SX-API

This API uses Checkpoint to index Snapshot X spaces information on StarkNet.

For more about how checkpoint works, refer to its documentation.

## Getting Started (Local Development)

This API depends on a couple of services:

- Node.js (>= v16.0.0)
- MySQL (v8.0)
- Starknet Provider (optional).

To get start, first install all dependencies with:

```sh
yarn

```

Next, you need to have a MySQL server running and accessible. You can use the docker-compose service to start one up quickly with:

```sh
docker compose up mysql # this will start mysql on port 3306
```

Next, make a copy of `.env.example` and rename it as `.env`. Then update the credentials in the file to the correct values for your
local setup.

> Note: If using docker compose to start dependencies then the default .env.example value should be okay as it is.
Finally, to run the service you do:

```sh
yarn dev
```

This should start the service to be listening on port 3000.

### Running Tests

Before running tests, ensure you have MySQL server running (see getting started guide for some pointer to do this).

Next, run:

```
yarn test
```

This will run all tests.

### Using local Checkpoint

Because `graphql` package needs single copy of itself to work properly using Apollo and Checkpoint
at the same time (which depend on `graphql`) can cause issues when using linked local copy of Checkpoint
as it brings two copies (one from `sx-api` one from linked `checkpoint`).

To workaround this you need to do this

```sh
cd checkpoint/node_modules/graphql
yarn link

cd sx-api
yarn link graphql
```
17 changes: 17 additions & 0 deletions apps/api/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'
services:
mysql:
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
cap_add:
- SYS_NICE
ports:
- '3306:3306'
environment:
- MYSQL_ROOT_PASSWORD=default_password
- MYSQL_DATABASE=checkpoint
volumes:
- mysql:/var/lib/mysql
volumes:
mysql:
driver: local
20 changes: 20 additions & 0 deletions apps/api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

export default {
clearMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',

// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/dist/', '<rootDir>/test/fixtures/'],

preset: 'ts-jest',
testEnvironment: 'node',
setupFiles: ['dotenv/config'],
//setupFilesAfterEnv: ['<rootDir>src/setupTests.ts'],
moduleFileExtensions: ['js', 'ts']
};
49 changes: 49 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "api",
"version": "0.1.0",
"private": true,
"license": "MIT",
"scripts": {
"codegen": "checkpoint generate",
"lint": "eslint src/ test/ --ext .ts --fix",
"prebuild": "yarn codegen",
"build": "tsc -p tsconfig.build.json",
"dev": "nodemon src/index.ts",
"start": "node dist/src/index.js",
"test": "jest"
},
"eslintConfig": {
"extends": "@snapshot-labs"
},
"prettier": "@snapshot-labs/prettier-config",
"dependencies": {
"@apollo/server": "^4.2.2",
"@ethersproject/address": "^5.6.1",
"@ethersproject/bignumber": "^5.6.1",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@ethersproject/units": "^5.6.1",
"@faker-js/faker": "^7.4.0",
"@snapshot-labs/checkpoint": "^0.1.0-beta.27",
"@snapshot-labs/sx": "^0.1.0",
"@types/bn.js": "^5.1.0",
"@types/jest": "^27.5.0",
"@types/mysql": "^2.15.21",
"@types/node": "^18.11.6",
"cross-fetch": "^4.0.0",
"dotenv": "^16.0.1",
"starknet": "^5.19.3"
},
"devDependencies": {
"@snapshot-labs/eslint-config": "0.1.0-beta.13",
"@snapshot-labs/prettier-config": "0.1.0-beta.11",
"eslint": "^8.53.0",
"jest": "^27.5.1",
"jest-mock-extended": "^2.0.6",
"nodemon": "^3.0.1",
"prettier": "^3.1.0",
"ts-jest": "^27.1.4",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
}
}
28 changes: 28 additions & 0 deletions apps/api/src/abis/encoders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"name": "sx::utils::types::Strategy",
"type": "struct",
"members": [
{ "name": "address", "type": "core::starknet::contract_address::ContractAddress" },
{ "name": "params", "type": "core::array::Array::<core::felt252>" }
]
},
{
"name": "core::integer::u256",
"type": "struct",
"members": [
{ "name": "low", "type": "core::integer::u128" },
{ "name": "high", "type": "core::integer::u128" }
]
},
{
"name": "proposition_power_params",
"type": "function",
"inputs": [],
"outputs": [
{ "name": "proposal_threshold", "type": "core::integer::u256" },
{ "name": "allowed_strategies", "type": "core::array::Array::<sx::utils::types::Strategy>" }
],
"state_mutability": "external"
}
]
Loading

0 comments on commit 309b05d

Please sign in to comment.