Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekhmet committed Aug 12, 2024
0 parents commit 4d102a4
Show file tree
Hide file tree
Showing 11 changed files with 3,719 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgres://postgres:password@localhost:5432/delegate-registry-api
20 changes: 20 additions & 0 deletions .github/workflows/lint-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint and build
on: [push]
jobs:
lint-build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'yarn'
- name: Set up MySQL
run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE checkpoint;' -uroot -proot
- run: yarn install
- run: yarn lint
- run: yarn build
env:
DATABASE_URL: 'mysql://root:[email protected]:3306/checkpoint'
14 changes: 14 additions & 0 deletions .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 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.
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@snapshot-labs/checkpoint-template",
"version": "0.1.0",
"license": "MIT",
"description": "Checkpoint starter template",
"scripts": {
"codegen": "checkpoint generate",
"lint": "eslint src/ --ext .ts --fix",
"prebuild": "yarn codegen",
"build": "tsc",
"dev": "nodemon src/index.ts",
"start": "node dist/src/index.js"
},
"eslintConfig": {
"extends": "@snapshot-labs"
},
"prettier": "@snapshot-labs/prettier-config",
"dependencies": {
"@snapshot-labs/checkpoint": "^0.1.0-beta.39",
"@types/node": "^18.11.6",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"nodemon": "^2.0.19",
"ts-node": "^10.8.1",
"typescript": "^5.2.2"
},
"devDependencies": {
"@snapshot-labs/eslint-config": "^0.1.0-beta.18",
"@snapshot-labs/prettier-config": "^0.1.0-beta.18",
"eslint": "^8.53.0",
"prettier": "^3.1.0"
}
}
15 changes: 15 additions & 0 deletions src/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"network_node_url": "https://subgrapher.snapshot.org/delegation",
"decimal_types": {
"BigIntVP": {
"p": 80,
"d": 0
},
"BigDecimalVP": {
"p": 80,
"d": 20
}
},
"optimistic_indexing": false,
"sources": []
}
34 changes: 34 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dotenv/config';
import fs from 'fs';
import path from 'path';
import Checkpoint, { LogLevel } from '@snapshot-labs/checkpoint';
import cors from 'cors';
import express from 'express';
import config from './config.json';
import { NoopIndexer } from './noopindexer';

const dir = __dirname.endsWith('dist/src') ? '../' : '';
const schemaFile = path.join(__dirname, `${dir}../src/schema.gql`);
const schema = fs.readFileSync(schemaFile, 'utf8');

const indexer = new NoopIndexer();
const checkpoint = new Checkpoint(config, indexer, schema, {
logLevel: LogLevel.Info,
prettifyLogs: true
});

async function run() {
await checkpoint.reset();
await checkpoint.resetMetadata();
}

run();

const app = express();
app.use(express.json({ limit: '4mb' }));
app.use(express.urlencoded({ limit: '4mb', extended: false }));
app.use(cors({ maxAge: 86400 }));
app.use('/', checkpoint.graphql);

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Listening at http://localhost:${PORT}`));
26 changes: 26 additions & 0 deletions src/noopindexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BaseIndexer, BaseProvider, Instance } from '@snapshot-labs/checkpoint';
import { Logger } from '@snapshot-labs/checkpoint/dist/src/utils/logger';

export class NoopProvider extends BaseProvider {}

export class NoopIndexer extends BaseIndexer {
init({
instance,
log,
abis
}: {
instance: Instance;
log: Logger;
abis?: Record<string, any>;
}) {
this.provider = new NoopProvider({
instance,
log,
abis
});
}

public getHandlers(): string[] {
return [];
}
}
21 changes: 21 additions & 0 deletions src/schema.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
scalar Id
scalar Text
scalar BigIntVP
scalar BigDecimalVP

type Governance {
id: String!
currentDelegates: Int!
totalDelegates: Int!
delegatedVotesRaw: BigIntVP!
delegatedVotes: BigDecimalVP!
}

type Delegate {
id: String!
governance: Governance
user: String!
delegatedVotesRaw: BigIntVP!
delegatedVotes: BigDecimalVP!
tokenHoldersRepresentedAmount: Int!
}
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"rootDir": "./",
"outDir": "./dist",
"esModuleInterop": true,
"strict": true,
"noImplicitAny": false,
"resolveJsonModule": true,
"moduleResolution": "Node"
}
}
Loading

0 comments on commit 4d102a4

Please sign in to comment.