Skip to content

Commit

Permalink
User rewards (#80)
Browse files Browse the repository at this point in the history
* Fix osToken apy

* Add allocator assets

* Add allocator ltv and assets

* Fix network entity

* Remove checkpointcreated handler

* Remove blockHandlersStartBlock config

* WIP

* Fix block number for block handlers

* Revert block initialize to Keeper

* Refactor apy calculation

* Add aggregations, refactor keeper rewards sync

* Update husky precommit

* Add totalEarnedAssets

* Implement reward splitter snapshots

* Fix block handlers

* Add ltvStatus to the allocator

* Add exitRequests and rewardSplitter handlers to keeper

* Fix isClaimable check

* Add vault to reward splitter shares holder

* Revert exit requests handler

* Add exchange rates

* Add DAI Price feed

* Add usdToDaiRate to snapshot

* Fix vault snapshot, osTokenHolder assets calc

* Fix swap xdai to gno

* Remove queued shares
  • Loading branch information
tsudmi authored Oct 11, 2024
1 parent a8ca456 commit 28593ba
Show file tree
Hide file tree
Showing 35 changed files with 2,698 additions and 1,051 deletions.
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@ and entities within the StakeWise ecosystem.
```shell script
npm install
```

2. Build the subgraph to check compile errors
before deploying:

```shell script
npm run build:mainnet
```

3. Deploy subgraph to your graph node
3. Deploy subgraph to your stage environment:

```shell script
IPFS_URL=<your IPFS node> GRAPH_URL=<your graph node> npm run deploy-stage:mainnet
```

4. Deploy subgraph to your prod environment:

```shell script
IPFS_URL=<your IPFS node> LOCAL_GRAPH_URL=<your graph node> npm run deploy-local:mainnet
IPFS_URL=<your IPFS node> GRAPH_URL=<your graph node> npm run deploy-prod:mainnet
```

## Documentation
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "v3-subgraph",
"version": "2.0.6",
"version": "3.0.0",
"description": "Subgraph for the StakeWise Protocol",
"repository": "https://github.com/stakewise/v3-subgraph",
"license": "AGPL-3.0-only",
Expand All @@ -19,8 +19,8 @@
"prepare:holesky": "npm run generate-const:holesky && npm run generate-yaml:holesky && npm run generate-types:holesky",
"build:holesky": "npm run prepare:holesky && npm run generate-wasm:holesky",
"test:holesky": "npm run prepare:holesky && npm run generate-tests-yaml:holesky && graph test",
"deploy-hosted:holesky": "npm run prepare:holesky && npm run deploy network:holesky node:hosted",
"deploy-local:holesky": "npm run prepare:holesky && npm run deploy network:holesky node:local",
"deploy-stage:holesky": "npm run prepare:holesky && npm run deploy network:holesky env:stage",
"deploy-prod:holesky": "npm run prepare:holesky && npm run deploy network:holesky env:prod",
"---MAINNET---": "",
"generate-const:mainnet": "node ./scripts/createConstants.js mainnet",
"generate-yaml:mainnet": "mustache src/config/mainnet.json src/subgraph.template.yaml > src/subgraph-mainnet.yaml",
Expand All @@ -30,8 +30,8 @@
"prepare:mainnet": "npm run generate-const:mainnet && npm run generate-yaml:mainnet && npm run generate-types:mainnet",
"build:mainnet": "npm run prepare:mainnet && npm run generate-wasm:mainnet",
"test:mainnet": "npm run prepare:mainnet && npm run generate-tests-yaml:mainnet && graph test",
"deploy-hosted:mainnet": "npm run prepare:mainnet && npm run deploy network:mainnet node:hosted",
"deploy-local:mainnet": "npm run prepare:mainnet && npm run deploy network:mainnet node:local",
"deploy-stage:mainnet": "npm run prepare:mainnet && npm run deploy network:mainnet env:stage",
"deploy-prod:mainnet": "npm run prepare:mainnet && npm run deploy network:mainnet env:prod",
"---CHIADO---": "",
"generate-const:chiado": "node ./scripts/createConstants.js chiado",
"generate-yaml:chiado": "mustache src/config/chiado.json src/subgraph.template.yaml > src/subgraph-chiado.yaml",
Expand All @@ -41,8 +41,8 @@
"prepare:chiado": "npm run generate-const:chiado && npm run generate-yaml:chiado && npm run generate-types:chiado",
"build:chiado": "npm run prepare:chiado && npm run generate-wasm:chiado",
"test:chiado": "npm run prepare:chiado && npm run generate-tests-yaml:chiado && graph test",
"deploy-hosted:chiado": "npm run prepare:chiado && npm run deploy network:chiado node:hosted",
"deploy-local:chiado": "npm run prepare:chiado && npm run deploy network:chiado node:local",
"deploy-stage:chiado": "npm run prepare:chiado && npm run deploy network:chiado env:stage",
"deploy-prod:chiado": "npm run prepare:chiado && npm run deploy network:chiado env:prod",
"---GNOSIS---": "",
"generate-const:gnosis": "node ./scripts/createConstants.js gnosis",
"generate-yaml:gnosis": "mustache src/config/gnosis.json src/subgraph.template.yaml > src/subgraph-gnosis.yaml",
Expand All @@ -52,8 +52,8 @@
"prepare:gnosis": "npm run generate-const:gnosis && npm run generate-yaml:gnosis && npm run generate-types:gnosis",
"build:gnosis": "npm run prepare:gnosis && npm run generate-wasm:gnosis",
"test:gnosis": "npm run prepare:gnosis && npm run generate-tests-yaml:gnosis && graph test",
"deploy-hosted:gnosis": "npm run prepare:gnosis && npm run deploy network:gnosis node:hosted",
"deploy-local:gnosis": "npm run prepare:gnosis && npm run deploy network:gnosis node:local"
"deploy-stage:gnosis": "npm run prepare:gnosis && npm run deploy network:gnosis env:stage",
"deploy-prod:gnosis": "npm run prepare:gnosis && npm run deploy network:gnosis env:prod"
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.81.0",
Expand Down
58 changes: 16 additions & 42 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ const { execAsync } = require('./util')

require('dotenv').config()

// LOCAL
const IPFS_URL = process.env.IPFS_URL
const LOCAL_GRAPH_URL = process.env.LOCAL_GRAPH_URL

// HOSTED
const HOSTED_GRAPH_TOKEN = process.env.HOSTED_GRAPH_TOKEN
const HOSTED_SUBGRAPH_URL = process.env.HOSTED_SUBGRAPH_URL
const GRAPH_URL = process.env.GRAPH_URL

const args = process.argv.reduce((acc, arg) => {
if (/:/.test(arg)) {
Expand All @@ -22,66 +17,45 @@ const args = process.argv.reduce((acc, arg) => {
}, {})

const validateEnv = () => {
if (args.node === 'hosted') {
if (!HOSTED_GRAPH_TOKEN) {
throw new Error('HOSTED_GRAPH_TOKEN is required env variable for "node:hosted" deployment')
}
if (!HOSTED_SUBGRAPH_URL) {
throw new Error('HOSTED_SUBGRAPH_URL is required env variable for "node:hosted" deployment')
}
if (!GRAPH_URL) {
throw new Error('GRAPH_URL is required env variable')
}
if (args.node === 'local') {
if (!LOCAL_GRAPH_URL) {
throw new Error('LOCAL_GRAPH_URL is required env variable for "node:local" deployment')
}
if (!IPFS_URL) {
throw new Error('IPFS_URL is required env variable for "node:local" deployment')
}
if (!IPFS_URL) {
throw new Error('IPFS_URL is required env variable')
}
}

const validateArgs = () => {
const { network, node } = args
const { network, env } = args

const allowedNetworks = ['holesky', 'mainnet', 'chiado', 'gnosis']
const allowedNodes = ['hosted', 'local']
const allowedEnvs = ['prod', 'stage']

if (!network) {
throw new Error('Argument "network" is required')
}
if (!node) {
throw new Error('Argument "node" is required')
if (!env) {
throw new Error('Argument "env" is required')
}
if (!allowedNetworks.includes(network)) {
throw new Error(`Argument "network" must include one of: ${allowedNetworks.join(', ')}`)
}
if (!allowedNodes.includes(node)) {
throw new Error(`Argument "node" must include one of: ${allowedNodes.join(', ')}`)
if (!allowedEnvs.includes(env)) {
throw new Error(`Argument "env" must include one of: ${allowedEnvs.join(', ')}`)
}
}

const deploy = async () => {
const { network, node } = args
const { network, env } = args

const srcDirectory = path.resolve(__dirname, `../src`)
const buildDirectory = path.resolve(__dirname, `../build/${network}`)

let authCommand = ''
let deployCommand = ''

if (node === 'hosted') {
authCommand = `graph auth --product hosted-service ${HOSTED_GRAPH_TOKEN}`
deployCommand = `graph deploy --product hosted-service ${HOSTED_SUBGRAPH_URL} --output-dir ${buildDirectory} --access-token ${HOSTED_GRAPH_TOKEN}`
}
if (node === 'local') {
const { version } = require('../package.json')

authCommand = `graph create --node ${LOCAL_GRAPH_URL} stakewise/stakewise`
deployCommand = `graph deploy --version-label ${version} --node ${LOCAL_GRAPH_URL} --ipfs ${IPFS_URL} stakewise/stakewise`
}
const { version } = require('../package.json')
const createCommand = `graph create --node ${GRAPH_URL} stakewise/${env}`
const deployCommand = `graph deploy --version-label ${version} --node ${GRAPH_URL} --ipfs ${IPFS_URL} stakewise/${env}`

const command = [
authCommand,
createCommand,
`cd ${srcDirectory}`,
`cp subgraph-${network}.yaml subgraph.yaml`,
deployCommand,
Expand Down
Loading

0 comments on commit 28593ba

Please sign in to comment.