Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Mar 16, 2024
1 parent da7f12b commit c1923e5
Show file tree
Hide file tree
Showing 34 changed files with 750 additions and 470 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
test:
strategy:
matrix:
node: ['20.x', '21.x']
node: ["20.x", "21.x"]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -46,4 +46,4 @@ jobs:
run: yarn build

- name: Run tests
run: yarn test
run: yarn test
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
12 changes: 6 additions & 6 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
"plugins": ["assemblyscript-prettier"],
"endOfLine": "lf",
"printWidth": 120,
"tabWidth": 2,
"singleQuote": true,
"semi": false
plugins: ["assemblyscript-prettier"],
endOfLine: "lf",
printWidth: 120,
tabWidth: 2,
singleQuote: false,
semi: false,
}
97 changes: 50 additions & 47 deletions ARB-requirements.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,70 @@
ARB requirements:

- Daily User Growth: A time series metric representing the daily user growth (in addresses) interacting with the protocol’s contracts.
- Events: Deposit/Withdraw/Transfer - Zap - Stake/Unstake/Claim
- count if new user (-> account entity)
- maintain total count daily (-> protocol entity)
- Snapshot by day ( -> protocol snapshot entity)

- Events: Deposit/Withdraw/Transfer - Zap - Stake/Unstake/Claim
- count if new user (-> account entity)
- maintain total count daily (-> protocol entity)
- Snapshot by day ( -> protocol snapshot entity)

- Daily Active Users: A time series metric representing the daily count of unique addresses interacting with the protocol's contracts.
- Events: Deposit/Withdraw/Transfer - Zap - Stake/Unstake/Claim
- Maintain a "last seen date" timestamp for each user (-> account entity . last_seen = "2021-01-01")
- Count if last seen != today
- maintain total count daily (-> protocol entity)
- Snapshot by day ( -> protocol snapshot entity)

- Events: Deposit/Withdraw/Transfer - Zap - Stake/Unstake/Claim
- Maintain a "last seen date" timestamp for each user (-> account entity . last_seen = "2021-01-01")
- Count if last seen != today
- maintain total count daily (-> protocol entity)
- Snapshot by day ( -> protocol snapshot entity)

- Daily Transaction Count: A time series metric representing the daily number of transactions interacting with the protocol's contracts.
- Events: Deposit/Withdraw/Transfer - Zap - Stake/Unstake/Claim
- count if new transaction (-> transaction entity)
- maintain total count daily (-> protocol entity)
- Snapshot by day ( -> protocol snapshot entity)

- Events: Deposit/Withdraw/Transfer - Zap - Stake/Unstake/Claim
- count if new transaction (-> transaction entity)
- maintain total count daily (-> protocol entity)
- Snapshot by day ( -> protocol snapshot entity)

- Daily Protocol Fee: A time series data representing the daily total protocol fee generated. For example, swap fees, borrowing fees, etc., comprising all economic value generated through the protocol, contracts, apps, etc., by users.
- Events: ChargedFees (CL), ZapFee ??? <=== we have that?
- sum of fees (-> protocol entity)
- Snapshot by day ( -> protocol snapshot entity)

- Events: ChargedFees (CL), ZapFee ??? <=== we have that?
- sum of fees (-> protocol entity)
- Snapshot by day ( -> protocol snapshot entity)

- Daily Transaction Fee: A time series, daily total transaction fees generated daily by interactions with the protocol's contracts.
- Events: Deposit/Withdraw/Transfer - Zap - Stake/Unstake/Claim
- sum if new transaction (-> transaction entity)
- extract fee from transaction (-> transaction entity)
- maintain daily sum in native (-> protocol entity)
- Snapshot by day ( -> protocol snapshot entity)

- Events: Deposit/Withdraw/Transfer - Zap - Stake/Unstake/Claim
- sum if new transaction (-> transaction entity)
- extract fee from transaction (-> transaction entity)
- maintain daily sum in native (-> protocol entity)
- Snapshot by day ( -> protocol snapshot entity)

- Daily ARB Expenditure and User Claims: Data on individual ARB incentive claim transactions made by users, as incentivized by the protocol. It should include the timestamp, user address, and the claimed ARB amount. The spent ARB will allow for the normalization of growth metrics.
- Events: Claim
- sum by user and token (-> user position incentive entity? -> claimed_rewards)
- Snapshot by day (-> user position incentive snapshot entity)

- Incentivized User List & Gini: The list should include users incentivized by the protocol along with their performance metrics. For instance, if trading volume is incentivized, this would be a list of traders with their respective trading volumes. If liquidity providers are incentivized, it would include a list of LPs and their liquidities in USD. Protocols should also strive for more uniform engagement levels across a wide user base for long-term sustainability, which will be measured through a gini coefficient across reward recipients.
- LP incentivized with a boost
- Events: Claim
- sum by user and token (-> user position incentive entity? -> claimed_rewards)
- Snapshot by day (-> user position incentive snapshot entity)

- Incentivized User List & Gini: The list should include users incentivized by the protocol along with their performance metrics. For instance, if trading volume is incentivized, this would be a list of traders with their respective trading volumes. If liquidity providers are incentivized, it would include a list of LPs and their liquidities in USD. Protocols should also strive for more uniform engagement levels across a wide user base for long-term sustainability, which will be measured through a gini coefficient across reward recipients.

- LP incentivized with a boost

- TVL: A daily time series expressed in USD.
- Events: Deposit/Withdraw/Transfer + Some Daily Clock event (to make sure we update daily)
- Get TVL + prices from the lens (-> lens deployed)
- Snapshot by day ( -> protocol snapshot entity)

- Events: Deposit/Withdraw/Transfer + Some Daily Clock event (to make sure we update daily)
- Get TVL + prices from the lens (-> lens deployed)
- Snapshot by day ( -> protocol snapshot entity)

- List of Depositors: A list of current and past participants who have deposited during the incentivized period to the protocol. The list should include depositor addresses, their current deposits in USD, time-weighted deposits in USD, and the duration of their deposit participation.
-> Events: Stake/Unstake
-> extract boost token price from lens (-> boost lens deployed + boost factory) OR encode in thegraph to get the price
-> wtf is time-weighted deposits in USD????
-> extract duration of deposit participation (-> user position incentive entity -> position_size_usd, depositor address, claimed_rewards_usd, total_duration_eligible)
-> Snapshot by day ( -> user position incentive snapshot entity)
-> Events: Stake/Unstake
-> extract boost token price from lens (-> boost lens deployed + boost factory) OR encode in thegraph to get the price
-> wtf is time-weighted deposits in USD????
-> extract duration of deposit participation (-> user position incentive entity -> position_size_usd, depositor address, claimed_rewards_usd, total_duration_eligible)
-> Snapshot by day ( -> user position incentive snapshot entity)

- Trading Volume: A daily time series, also measured in USD. List of Liquidity Providers: A list of current and past participants who have provided liquidity to the protocol during the incentivized period. The list should include LP addresses, their current liquidity in USD, time-weighted liquidity in USD, and the duration of liquidity provision.
-> Events: Deposit/Withdraw/Transfer
-> get position size from lens (-> lens deployed)
-> wtf is time-weighted liquidity in USD????
-> extract duration of liquidity provision (-> user position entity -> position_size_usd, depositor address, duration)
-> Snapshot by day ( -> user position snapshot entity)

-> Events: Deposit/Withdraw/Transfer
-> get position size from lens (-> lens deployed)
-> wtf is time-weighted liquidity in USD????
-> extract duration of liquidity provision (-> user position entity -> position_size_usd, depositor address, duration)
-> Snapshot by day ( -> user position snapshot entity)

- Exogenous User Growth: Growing the daily active users of the protocol

Expand All @@ -69,17 +77,12 @@ ARB requirements:
- Capital Inflow Rate: The rate at which new capital is deposited into yield-generating products, indicating trust and attractiveness.

- Reinvestment Rate: The rate at which earned yields are reinvested into the protocol, showing user confidence and compounding interest potential.
Diversification of Yield Sources: A variety of yield-generating strategies employed, reducing risk and improving stability.
Diversification of Yield Sources: A variety of yield-generating strategies employed, reducing risk and improving stability.

- Average Yield Rate: The average yield rate provided to investors, showcasing the platform's performance and attractiveness.






Assumptions to build this with thegraph quickly:

- We have a uniswap-view-quoter deployed on ARB
- We have good zap events
- We will build a boost factory and boost lens

44 changes: 22 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
version: '3'
version: "3"
services:
postgres:
image: postgres:14
ports:
- '5432:5432'
command: ['postgres', '-cshared_preload_libraries=pg_stat_statements', '-cmax_connections=200']
- "5432:5432"
command: ["postgres", "-cshared_preload_libraries=pg_stat_statements", "-cmax_connections=200"]
environment:
POSTGRES_USER: graph-node
POSTGRES_PASSWORD: let-me-in
POSTGRES_DB: graph-node
POSTGRES_INITDB_ARGS: '-E UTF8 --locale=C'
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
volumes:
- ./docker/data/postgres:/var/lib/postgresql/data
logging:
driver: 'local'
driver: "local"
options:
max-size: '5M'
max-file: '3'
max-size: "5M"
max-file: "3"
healthcheck:
test: ['CMD-SHELL', 'pg_isready -q -d graph-node -U graph-node']
test: ["CMD-SHELL", "pg_isready -q -d graph-node -U graph-node"]
interval: 1s
timeout: 5s
retries: 10

ipfs:
image: ipfs/kubo:v0.14.0
ports:
- '5001:5001'
- "5001:5001"
volumes:
- ./docker/data/ipfs:/data/ipfs
logging:
driver: 'local'
driver: "local"
options:
max-size: '5M'
max-file: '3'
max-size: "5M"
max-file: "3"
healthcheck:
test: ['CMD', 'ipfs', 'id']
test: ["CMD", "ipfs", "id"]
interval: 1s
timeout: 5s
retries: 5

graph-node:
image: graphprotocol/graph-node
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'
- '8040:8040'
- "8000:8000"
- "8001:8001"
- "8020:8020"
- "8030:8030"
- "8040:8040"
depends_on:
postgres:
condition: service_healthy
Expand All @@ -58,11 +58,11 @@ services:
volumes:
- ./docker/graph-node:/etc/graph-node
logging:
driver: 'local'
driver: "local"
options:
max-size: '10M'
max-file: '3'
max-size: "10M"
max-file: "3"
environment:
ipfs: 'ipfs:5001'
ipfs: "ipfs:5001"
GRAPH_LOG: debug
GRAPH_NODE_CONFIG: /etc/graph-node/config.toml
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"name": "subgraphs",
"private": true,
"scripts": {
"prepare": "husky install",
"postinstall": "npm run codegen",
"codegen": "rm -Rf generated && graph codegen",
"build": "graph build",
"format": "prettier . --write",
"test": "yarn run --silent test:lint && yarn run --silent test:graph",
"test:graph": "graph test",
"test:lint": "prettier . --check",
Expand All @@ -22,12 +24,16 @@
"@0xgraph/cli": "^0.1.1",
"@graphprotocol/graph-cli": "^0.68.0",
"@graphprotocol/graph-ts": "^0.33.0",
"assemblyscript-prettier": "^3.0.1",
"blockchain-addressbook": "^0.46.28",
"husky": ">=7",
"lint-staged": ">=10",
"matchstick-as": "^0.6.0",
"prettier": "^3.2.5",
"typescript": "^5.3.3"
},
"dependencies": {
"assemblyscript-prettier": "^3.0.1"
"dependencies": {},
"lint-staged": {
"*.--check": "prettier --write"
}
}
8 changes: 5 additions & 3 deletions src/entity/clock.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { BigInt, Bytes } from '@graphprotocol/graph-ts'
import { getIntervalFromTimestamp } from '../utils/time'
import { getSnapshotIdSuffix } from '../utils/snapshot'
import { BigInt, Bytes } from "@graphprotocol/graph-ts"
import { getIntervalFromTimestamp } from "../utils/time"
import { getSnapshotIdSuffix } from "../utils/snapshot"


@inline
export function getClockTickId(timestamp: BigInt, period: BigInt): Bytes {
const interval = getIntervalFromTimestamp(timestamp, period)
return getSnapshotIdSuffix(period, interval)
}


@inline
export function getPreviousClockTickId(timestamp: BigInt, period: BigInt): Bytes {
return getClockTickId(timestamp.minus(period), period)
Expand Down
10 changes: 5 additions & 5 deletions src/entity/investor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BigDecimal, BigInt, Bytes } from '@graphprotocol/graph-ts'
import { Investor, InvestorSnapshot } from '../../generated/schema'
import { ZERO_BD, ZERO_BI } from '../utils/decimal'
import { getIntervalFromTimestamp } from '../utils/time'
import { getPreviousSnapshotIdSuffix, getSnapshotIdSuffix } from '../utils/snapshot'
import { BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts"
import { Investor, InvestorSnapshot } from "../../generated/schema"
import { ZERO_BD, ZERO_BI } from "../utils/decimal"
import { getIntervalFromTimestamp } from "../utils/time"
import { getPreviousSnapshotIdSuffix, getSnapshotIdSuffix } from "../utils/snapshot"

export function isNewInvestor(investor: Investor): boolean {
// safe to assume as we only create investors when they interact with the protocol
Expand Down
14 changes: 7 additions & 7 deletions src/entity/position.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BigDecimal, BigInt, Bytes } from '@graphprotocol/graph-ts'
import { BeefyCLVault, Investor, InvestorPosition, InvestorPositionSnapshot } from '../../generated/schema'
import { ADDRESS_ZERO } from '../utils/address'
import { ZERO_BD, ZERO_BI } from '../utils/decimal'
import { getIntervalFromTimestamp } from '../utils/time'
import { getSnapshotIdSuffix } from '../utils/snapshot'
import { BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts"
import { BeefyCLVault, Investor, InvestorPosition, InvestorPositionSnapshot } from "../../generated/schema"
import { ADDRESS_ZERO } from "../utils/address"
import { ZERO_BD, ZERO_BI } from "../utils/decimal"
import { getIntervalFromTimestamp } from "../utils/time"
import { getSnapshotIdSuffix } from "../utils/snapshot"

// @ts-ignore
@inline
Expand Down Expand Up @@ -72,6 +72,6 @@ export function getInvestorPositionSnapshot(
snapshot.underlyingBalance1USD = previousSnapshot.underlyingBalance1USD
snapshot.positionValueUSD = previousSnapshot.positionValueUSD
}

return snapshot
}
14 changes: 7 additions & 7 deletions src/entity/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { BigInt, Bytes } from '@graphprotocol/graph-ts'
import { Protocol, ProtocolSnapshot } from '../../generated/schema'
import { ONE_BI, ZERO_BD } from '../utils/decimal'
import { getIntervalFromTimestamp } from '../utils/time'
import { getPreviousSnapshotIdSuffix, getSnapshotIdSuffix } from '../utils/snapshot'
import { BigInt, Bytes } from "@graphprotocol/graph-ts"
import { Protocol, ProtocolSnapshot } from "../../generated/schema"
import { ONE_BI, ZERO_BD } from "../utils/decimal"
import { getIntervalFromTimestamp } from "../utils/time"
import { getPreviousSnapshotIdSuffix, getSnapshotIdSuffix } from "../utils/snapshot"

export type ProtocolId = String
export const PROTOCOL_BEEFY_CL: ProtocolId = 'BeefyCL'
export const PROTOCOL_BEEFY_CL: ProtocolId = "BeefyCL"
export const PROTOCOL_BEEFY_CL_ID: Bytes = Bytes.fromByteArray(Bytes.fromBigInt(ONE_BI))

export function getBeefyCLProtocol(): Protocol {
const protocolId = PROTOCOL_BEEFY_CL_ID
let protocol = Protocol.load(protocolId)
if (!protocol) {
protocol = new Protocol(protocolId)
protocol.name = 'Beefy CL'
protocol.name = "Beefy CL"
protocol.totalValueLockedUSD = ZERO_BD
protocol.activeVaultCount = 0
protocol.activeInvestorCount = 0
Expand Down
8 changes: 4 additions & 4 deletions src/entity/token.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BigInt, Bytes } from '@graphprotocol/graph-ts'
import { Token } from '../../generated/schema'
import { BigInt, Bytes } from "@graphprotocol/graph-ts"
import { Token } from "../../generated/schema"

export function getToken(tokenAddress: Bytes): Token {
let token = Token.load(tokenAddress)
if (!token) {
token = new Token(tokenAddress)
token.symbol = ''
token.name = ''
token.symbol = ""
token.name = ""
token.decimals = BigInt.fromI32(18)
}
return token
Expand Down
6 changes: 3 additions & 3 deletions src/entity/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethereum, log } from '@graphprotocol/graph-ts'
import { Transaction } from '../../generated/schema'
import { weiToBigDecimal } from '../utils/decimal'
import { ethereum, log } from "@graphprotocol/graph-ts"
import { Transaction } from "../../generated/schema"
import { weiToBigDecimal } from "../utils/decimal"

export function getTransaction(
block: ethereum.Block,
Expand Down
Loading

0 comments on commit c1923e5

Please sign in to comment.