Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Track changes (#14)
Browse files Browse the repository at this point in the history
Add changes for manager and strategies
Add Deposit and Withdraw tracking
Add Claimed Performance Fee
Remove Trends
  • Loading branch information
milonite authored Apr 5, 2022
1 parent 6500bd9 commit e850475
Show file tree
Hide file tree
Showing 31 changed files with 753 additions and 510 deletions.
15 changes: 9 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# dev = local ensonet
# prod = remote ensonet
MODE=dev
MODE="dev"

# Only needed if MODE=dev
INFURA_API_KEY=
MNEMONIC=
ARCHIVE_NODE=
INFURA_API_KEY=""
MNEMONIC=""
ARCHIVE_NODE=""

# Only needed if MODE=prod
ENSONET_URL=
# Only needed deploying directly (without docker)
GRAPH_ADMIN_URL="http://localhost:8020"
IPFS_URL="http://localhost:5001"
# If MODE=prod, only this variable is needed! (remote ensonet)
ENSONET_URL="http://localhost:3000"
35 changes: 35 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Deploy Enso Subgraph

on: [push]

jobs:
deploy:
name: Deploy on EC2 Instance
runs-on: ubuntu-latest
steps:
- name: Checkout Enso Subgraph
uses: actions/checkout@v1
- name: Deploy to my EC2 instance
uses: easingthemes/[email protected]
env:
SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}
REMOTE_HOST: '18.220.98.192'
REMOTE_USER: 'ubuntu'
TARGET: '/home/ubuntu/enso-subgraph'
- name: Run Enso Subgraph
env:
MODE: prod
ENSONET_URL: https://testnet.enso.finance
uses: appleboy/ssh-action@master
with:
envs: MODE,ENSONET_URL
host: '18.220.98.192'
username: 'ubuntu'
key: ${{ secrets.EC2_SSH_KEY }}
script: |
export MODE=$MODE
export ENSONET_URL=$ENSONET_URL
cd /home/ubuntu/enso-subgraph
yarn
yarn start
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ generated
# Ignore the files generated by templates
subgraph.yaml
src/addresses.ts
data
data
9 changes: 9 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ http://subgraph.dev.enso.finance/subgraphs/name/ensofinance/enso-v1

## Setup and deploy on ✨ EnsoNet ✨

❗️ Link your github ssh key to `~/.ssh/ensonet` (or use the service account's key) ❗️

* **local** ✨ EnsoNet ✨ -> `MODE=dev`
* **remote** ✨ EnsoNet ✨ -> `MODE=prod`

`yarn start`

### Fast iteration

1. export env variables: `export $(grep -v '^#' .env | xargs)`
2. run prepare command: `yarn prepare ensonet`
3. run build & compile command: `yarn build:graph`
4. run deploy command: `yarn deploy:local`

## Setup and deploy on kovan

1. Authenticate
Expand Down
132 changes: 109 additions & 23 deletions abis/Strategy.json

Large diffs are not rendered by default.

42 changes: 18 additions & 24 deletions abis/StrategyController.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ services:
ipfs: 'ipfs:5001'
ethereum: 'mainnet:${ENSONET_URL}'
GRAPH_LOG: info
GRAPH_ALLOW_NON_DETERMINISTIC_FULLTEXT_SEARCH: 1
GRAPH_ETHEREUM_CLEANUP_BLOCKS: 1
GRAPH_ALLOW_NON_DETERMINISTIC_FULLTEXT_SEARCH: "true"
GRAPH_ETHEREUM_MAX_BLOCK_RANGE_SIZE: 10

ipfs:
image: ipfs/go-ipfs:v0.4.23
Expand Down
30 changes: 17 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,48 @@ services:
ports:
- 3000:3000
environment:
- PORT=3000
- INFURA_API_KEY=${INFURA_API_KEY}
- MNEMONIC=${MNEMONIC}
- ARCHIVE_NODE=${ARCHIVE_NODE}
- LOG=quiet
PORT: 3000
INFURA_API_KEY: ${INFURA_API_KEY}
MNEMONIC: "${MNEMONIC}"
ARCHIVE_NODE: ${ARCHIVE_NODE}
LOG: quiet
secrets:
- ssh_key
healthcheck:
test: "wget -q localhost:3000/api/deployments -O - | grep v1-core"
interval: "10s"
timeout: "15s"
start_period: "3m"
start_period: "4m"
retries: 24

graph-node:
image: graphprotocol/graph-node:v0.24.0
image: graphprotocol/graph-node:v0.25.2
ports:
- '8000:8000'
- '8020:8020'
depends_on:
ipfs:
condition: service_started
postgres:
condition: service_started
ensonet:
condition: service_healthy
environment:
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
postgres_db: graph-node
ipfs: ipfs:5001
ethereum: 'mainnet:http://ensonet:3000'
GRAPH_LOG: info
GRAPH_ALLOW_NON_DETERMINISTIC_FULLTEXT_SEARCH: 1
GRAPH_ETHEREUM_CLEANUP_BLOCKS: 1
GRAPH_ALLOW_NON_DETERMINISTIC_FULLTEXT_SEARCH: "true"
GRAPH_ETHEREUM_MAX_BLOCK_RANGE_SIZE: 10
GRAPH_ETHEREUM_CLEANUP_BLOCKS: "true"

ipfs:
image: ipfs/go-ipfs:v0.4.23
image: ipfs/go-ipfs:v0.12.1
ports:
- '5001:5001'

postgres:
image: postgres
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"start": "./scripts/run.sh",
"prepare": "./scripts/build-manifest.sh",
"build:graph": "graph codegen && graph build",
"deploy:local": "graph remove --node $GRAPH_ADMIN_URL ensofinance/enso-v1 && graph create --node $GRAPH_ADMIN_URL ensofinance/enso-v1 && graph deploy --node $GRAPH_ADMIN_URL --ipfs $IPFS_URL ensofinance/enso-v1",
"deploy:remote": "graph remove --node http://$DOCKHERO_HOST:8020 ensofinance/enso-v1 && graph create --node http://$DOCKHERO_HOST:8020 ensofinance/enso-v1 && graph deploy --node http://$DOCKHERO_HOST:8020 --ipfs http://$DOCKHERO_HOST:5001 ensofinance/enso-v1",
"deploy:local": "graph create --node $GRAPH_ADMIN_URL ensofinance/enso-v1 && graph deploy --node $GRAPH_ADMIN_URL --ipfs $IPFS_URL ensofinance/enso-v1",
"deploy:remote": "graph create --node http://$DOCKHERO_HOST:8020 ensofinance/enso-v1 && graph deploy --node http://$DOCKHERO_HOST:8020 --ipfs http://$DOCKHERO_HOST:5001 ensofinance/enso-v1",
"deploy:kovan": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ ensofinance/enso-v1"
},
"devDependencies": {
Expand Down
125 changes: 59 additions & 66 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ type Manager @entity {
id: ID!
strategiesCount: Int!
strategies: [Strategy!]!
startTime: BigInt!
createdAtTimestamp: BigInt!
tvl: BigDecimal!
totalNav: BigDecimal!
strategiesAverageNav: BigDecimal!
strategiesAverageNavChange: BigDecimal!
tvlChange: BigDecimal!
tvl24hChange: BigDecimal!
totalPrice: BigDecimal! # aux entity
strategiesAveragePrice: BigDecimal! # aux entity
holdersCount: Int!
holders24hDiff: Int!
commonItems: [CommonItem!]!
managerDaysData: [ManagerDayData!]! @derivedFrom(field: "manager")
managerTrends: [ManagerTrends!]! @derivedFrom(field: "manager")
managerChanges: [ManagerChanges!]! @derivedFrom(field: "manager")
claimedPerfFee: [ClaimedPerfFee!]! @derivedFrom(field: "manager")
}

Expand All @@ -42,42 +38,19 @@ type Strategy @entity {
name: String!
symbol: String!
state: StrategyState
startTime: BigInt!
nav: BigDecimal!
createdAtTimestamp: BigInt!
tvl: BigDecimal!
tvlChange: BigDecimal!
tvl24hChange: BigDecimal!
navChange: BigDecimal!
nav24hChange: BigDecimal!
price: BigDecimal!
holdersCount: Int!
holders24hDiff: Int!
createdAtBlockNumber: BigInt!
items: [StrategyItemHolding!]!
lastRestructure: BigInt!
totalSupply: BigInt!
totalSupply: BigDecimal!
tokenHolders: [StrategyTokenHolding]! @derivedFrom(field: "strategy")
strategyDaysData: [StrategyDayData!]! @derivedFrom(field: "strategy")
strategyChanges: [StrategyChanges!]! @derivedFrom(field: "strategy")
rebalances: [Rebalance]! @derivedFrom(field: "strategy")
restructures: [Restructure]! @derivedFrom(field: "strategy")
trends: StrategyTrends! @derivedFrom(field: "strategy")
}

type StrategyTrends @entity {
id: ID!
strategy: Strategy!
trend1d: BigDecimal!
trend7d: BigDecimal!
trend30d: BigDecimal!
trendAll: BigDecimal!
}

type ManagerTrends @entity {
id: ID!
manager: Manager!
trend1d: BigDecimal!
trend7d: BigDecimal!
trend30d: BigDecimal!
trendAll: BigDecimal!
}

type StrategyState @entity {
Expand All @@ -99,6 +72,16 @@ type StrategyTokenHolding @entity {
balance: BigDecimal!
}

type StrategyTokenHoldingData @entity {
id: ID!
investor: String!
strategy: Strategy!
balance: BigDecimal!
timestamp: BigInt!
blockNumber: BigInt!
txHash: String!
}

type StrategyItemHolding @entity {
id: ID!
timestamp: BigInt!
Expand Down Expand Up @@ -141,39 +124,45 @@ type StrategyDayData @entity {
strategy: Strategy!
timestamp: BigInt!
tvlLastTracked: BigDecimal!
navLastTracked: BigDecimal!
priceLastTracked: BigDecimal!
holdersCount: Int!
}

type ManagerDayData @entity {
# strategy address + timestamp
type StrategyChanges @entity {
id: ID!
manager: Manager!
timestamp: BigInt!
tvlLastTracked: BigDecimal!
totalNavLastTracked: BigDecimal!
strategiesAverageNav: BigDecimal!
holdersCount: Int!
strategy: Strategy!
tvl1d: BigDecimal!
tvl1w: BigDecimal!
tvl1m: BigDecimal!
tvlInception: BigDecimal!
price1d: BigDecimal!
price1w: BigDecimal!
price1m: BigDecimal!
priceInception: BigDecimal!
holders1d: Int!
}

type StrategyHourData @entity {
# strategy address + timestamp
type ManagerChanges @entity {
id: ID!
strategy: Strategy!
timestamp: BigInt!
tvlLastTracked: BigDecimal!
navLastTracked: BigDecimal!
holdersCount: Int!
manager: Manager!
tvl1d: BigDecimal!
tvl1w: BigDecimal!
tvl1m: BigDecimal!
tvlInception: BigDecimal!
averagePrice1d: BigDecimal!
averagePrice1w: BigDecimal!
averagePrice1m: BigDecimal!
averagePriceInception: BigDecimal!
holders1d: Int!
}

type ManagerHourData @entity {
type ManagerDayData @entity {
# strategy address + timestamp
id: ID!
manager: Manager!
timestamp: BigInt!
tvlLastTracked: BigDecimal!
totalNavLastTracked: BigDecimal!
strategiesAverageNav: BigDecimal!
totalPriceLastTracked: BigDecimal!
holdersCount: Int!
}

Expand All @@ -196,25 +185,29 @@ type Restructure @entity {
after: [StrategyItemHolding!]!
}

type Tournament @entity {
type Cron @entity {
id: ID!
startTime: BigInt!
endTime: BigInt!
strategiesCount: Int!
strategiesData: [TournamentStrategyData]! @derivedFrom(field: "tournament")
cron: BigInt!
}

type TournamentStrategyData @entity {
id: ID! #strategy/torunamentId
manager: Manager!
type DepositEvent @entity {
id: ID!
strategy: Strategy!
roi: BigDecimal!
tournament: Tournament!
user: String!
amount: BigDecimal!
value: BigDecimal!
timestamp: BigInt!
txHash: String!
}

type Cron @entity {
type WithdrawEvent @entity {
id: ID!
cron: BigInt!
strategy: Strategy!
user: String!
amount: BigDecimal!
value: BigDecimal!
timestamp: BigInt!
txHash: String!
}

enum RestructureStatus {
Expand Down
22 changes: 18 additions & 4 deletions scripts/build-manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,24 @@ if [[ "$NETWORK" == "local" ]]; then
fi

if [[ "$NETWORK" == "ensonet" ]]; then
REMOTE_BLOCK=$(curl -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"eth_blockNumber","id":1}' $ENSONET_URL | node_modules/node-jq/bin/jq ".result" | tr -d '"')
ENSONET_DEPLOYMENTS=$(curl $ENSONET_URL/api/deployments)
echo $ENSONET_DEPLOYMENTS | node_modules/node-jq/bin/jq '."v1-core" + {"network":"mainnet","ChainlinkFeedRegistry":"0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf","blockNumber":'$(($REMOTE_BLOCK))'}' | node_modules/.bin/mustache - templates/subgraph.template.yaml > subgraph.yaml
echo $ENSONET_DEPLOYMENTS | node_modules/node-jq/bin/jq '."v1-core" + {"ChainlinkFeedRegistry":"0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf"}' | node_modules/.bin/mustache - templates/addresses.ts > src/addresses.ts
[[ "$MODE" == "prod" ]] && BLOCKS_TO_SYNC="10000" || BLOCKS_TO_SYNC="100"
REMOTE_BLOCK=$(curl -sS -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"eth_blockNumber","id":1}' $ENSONET_URL | node_modules/node-jq/bin/jq ".result" | tr -d '"')
if [[ $(curl -sSI $ENSONET_URL/api/deployments | head -n 1| cut -d$' ' -f2) == 200 ]]
then
until curl -sS $ENSONET_URL/api/deployments | grep "v1-core"
do
echo "Waiting for v1-core deployment on ensonet..."
BLOCKS_TO_SYNC="0"
sleep 10
done

ENSONET_DEPLOYMENTS=$(curl $ENSONET_URL/api/deployments)
echo $ENSONET_DEPLOYMENTS | node_modules/node-jq/bin/jq '."v1-core" + {"network":"mainnet","ChainlinkFeedRegistry":"0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf","blockNumber":'$(($REMOTE_BLOCK-$BLOCKS_TO_SYNC))'}' | node_modules/.bin/mustache - templates/subgraph.template.yaml > subgraph.yaml
echo $ENSONET_DEPLOYMENTS | node_modules/node-jq/bin/jq '."v1-core" + {"ChainlinkFeedRegistry":"0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf"}' | node_modules/.bin/mustache - templates/addresses.ts > src/addresses.ts
else
echo "$ENSONET_URL deployments is not up!"
exit 0;
fi
fi

if [[ "$NETWORK" == "remote" ]]; then
Expand Down
Loading

0 comments on commit e850475

Please sign in to comment.