-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
4,675 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE_URL=mysql://root:default_password@localhost:3306/checkpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
Oops, something went wrong.