Skip to content

Commit

Permalink
clm vaults (#35)
Browse files Browse the repository at this point in the history
* add classic support

* lint
  • Loading branch information
ReflectiveChimp authored Aug 23, 2024
1 parent 70de0d5 commit ffa1c2f
Show file tree
Hide file tree
Showing 17 changed files with 1,056 additions and 241 deletions.
43 changes: 19 additions & 24 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.2/schema.json",
"files": {
"ignore": [
"./.husky/**",
"./.idea/**",
"./.vscode/**",
"./build/**",
"./node_modules/**",
"./src/queries/codegen/sdk.ts",
"./src/queries/codegen/schema.graphql"
]
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 100,
"attributePosition": "auto",
"ignore": [
"./.husky/**",
"./build/**",
"./node_modules/**",
"src/queries/codegen/sdk.ts",
"src/queries/codegen/schema.graphql"
]
"attributePosition": "auto"
},
"organizeImports": {
"enabled": true,
"ignore": [
"./.husky/**",
"./build/**",
"./node_modules/**",
"src/queries/codegen/sdk.ts",
"src/queries/codegen/schema.graphql"
]
"enabled": true
},
"linter": {
"enabled": true,
"ignore": [
"./.husky/**",
"./build/**",
"./node_modules/**",
"src/queries/codegen/sdk.ts",
"src/queries/codegen/schema.graphql"
],
"rules": { "recommended": true }
"rules": {
"recommended": true,
"complexity": {
"noForEach": "off"
}
}
},
"javascript": {
"formatter": {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"inspect": "node --inspect build/index.js",
"deploy": "git checkout prod && git rebase main && git push && git checkout -",
"dev": "ts-node-dev --respawn --require=dotenv/config src/index.ts",
"format": "biome check src/**/*.{ts,graphql}",
"format:fix": "biome check --write --unsafe src/**/*.{ts,graphql}",
"format": "biome check",
"format:fix": "biome check --write",
"format:fix:unsafe": "biome check --write --unsafe",
"test": "npm run test:ts && npm run test:unit && npm run test:lint",
"test:unit": "jest",
"test:ts": "tsc --noEmit",
Expand Down Expand Up @@ -48,7 +49,7 @@
"pino": "^8.19.0"
},
"lint-staged": {
"src/**/*.{ts,tsx,graphql,json}": "biome format --write"
"src/**/*.{ts,graphql,json}": "biome check --write"
},
"devDependencies": {
"@biomejs/biome": "1.8.2",
Expand Down
109 changes: 89 additions & 20 deletions src/queries/InvestorTimeline.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fragment Token on Token {
decimals
}

fragment InvestorTimelineClmPosition on CLM {
fragment InvestorTimelineClmPositionClm on CLM {
address: id
managerToken {
...Token
Expand All @@ -27,9 +27,15 @@ fragment InvestorTimelineClmPosition on CLM {
nativeToUSDPrice
}

fragment InvestorTimelineClmPosition on ClmPosition {
id
clm {
...InvestorTimelineClmPositionClm
}
}

fragment InvestorTimelineClmPositionInteraction on ClmPositionInteraction {
id

timestamp
blockNumber
createdWith {
Expand All @@ -50,30 +56,93 @@ fragment InvestorTimelineClmPositionInteraction on ClmPositionInteraction {
type
}

fragment InvestorTimelineClassicPositionClassic on Classic {
address: id
rewardPoolTokens {
...Token
}
rewardPoolTokensOrder
rewardPoolsTotalSupply
vaultSharesToken {
...Token
}
vaultSharesTotalSupply
underlyingToken {
...Token
}
underlyingAmount
underlyingToNativePrice
underlyingBreakdownTokens {
...Token
}
underlyingBreakdownTokensOrder
}

fragment InvestorTimelineClassicPosition on ClassicPosition {
id
classic {
...InvestorTimelineClassicPositionClassic
}
}

fragment InvestorTimelineClassicPositionInteraction on ClassicPositionInteraction {
id
timestamp
blockNumber
createdWith {
hash: id
}
rewardPoolBalances
rewardPoolBalancesDelta
vaultBalance
vaultBalanceDelta
boostBalance
boostBalanceDelta
totalBalance
vaultSharesTotalSupply
vaultUnderlyingAmount
vaultUnderlyingBreakdownBalances
vaultUnderlyingTotalSupply
underlyingBreakdownToNativePrices
underlyingToNativePrice
nativeToUSDPrice
type
}

query InvestorTimeline($investor_address: String!, $first: Int = 1000, $skip: Int = 0) {
clmPositions(skip: $skip, first: $first, where: { investor: $investor_address, totalBalance_gt: 0 }) {
id

managerBalance
rewardPoolBalances
totalBalance
clm {
...InvestorTimelineClmPosition
}
...InvestorTimelineClmPosition
}

clmPositionInteractions(
first: $first
skip: $skip
orderBy: timestamp
orderDirection: asc
where: {
investor: $investor_address,
type_in: [MANAGER_DEPOSIT, MANAGER_WITHDRAW, CLM_REWARD_POOL_STAKE, CLM_REWARD_POOL_UNSTAKE]
}
first: $first
skip: $skip
orderBy: timestamp
orderDirection: asc
where: {
investor: $investor_address,
type_in: [MANAGER_DEPOSIT, MANAGER_WITHDRAW, CLM_REWARD_POOL_STAKE, CLM_REWARD_POOL_UNSTAKE]
}
) {
...InvestorTimelineClmPositionInteraction

investorPosition {
id
}
}

classicPositions(skip: $skip, first: $first, where: { investor: $investor_address, totalBalance_gt: 0 }) {
...InvestorTimelineClassicPosition
}

classicPositionInteractions(first: $first
skip: $skip
orderBy: timestamp
orderDirection: asc
where: {
investor: $investor_address,
type_in: [VAULT_DEPOSIT, VAULT_WITHDRAW, CLASSIC_REWARD_POOL_STAKE, CLASSIC_REWARD_POOL_UNSTAKE]
}) {
...InvestorTimelineClassicPositionInteraction
investorPosition {
id
}
Expand Down
33 changes: 27 additions & 6 deletions src/queries/VaultHarvests.graphql
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
fragment HarvestData on ClmHarvestEvent {
fragment ClmHarvestData on ClmHarvestEvent {
id
timestamp
compoundedAmount0
compoundedAmount1
nativeToUSDPrice
token0ToNativePrice
token1ToNativePrice
nativeToUSDPrice
underlyingAmount0
underlyingAmount1
totalSupply: managerTotalSupply
createdWith {
id
}
}

fragment ClassicHarvestData on ClassicHarvestEvent {
id
timestamp
compoundedAmount
nativeToUSDPrice
underlyingToNativePrice
underlyingAmount
totalSupply: vaultSharesTotalSupply
}

query VaultHarvests($vault_address: ID!) {
Expand All @@ -23,7 +33,18 @@ query VaultHarvests($vault_address: ID!) {
decimals
}
harvests(orderBy: timestamp, orderDirection: desc, first: 1000) {
...HarvestData
...ClmHarvestData
}
}
classic(id: $vault_address) {
underlyingToken {
decimals
}
sharesToken: vaultSharesToken {
decimals
}
harvests(orderBy: timestamp, orderDirection: desc, first: 1000) {
...ClassicHarvestData
}
}
}
87 changes: 71 additions & 16 deletions src/queries/VaultHistoricPrices.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,73 @@ fragment Token on Token {
decimals
}

fragment ClmSnapshotData on ClmSnapshot {
roundedTimestamp
nativeToUSDPrice
priceRangeMin1
priceOfToken0InToken1
priceRangeMax1
token0ToNativePrice
token1ToNativePrice
totalUnderlyingAmount0
totalUnderlyingAmount1
totalSupply: managerTotalSupply
}

fragment ClassicSnapshotData on ClassicSnapshot {
roundedTimestamp
nativeToUSDPrice
underlyingAmount
underlyingToNativePrice
underlyingBreakdownToNativePrices
vaultUnderlyingBreakdownBalances
vaultUnderlyingTotalSupply
totalSupply: vaultSharesTotalSupply
}

fragment ClmPriceData on CLM {
sharesToken: managerToken {
...Token
}
underlyingToken0 {
...Token
}
underlyingToken1 {
...Token
}
snapshots(
first: $first
skip: $skip
orderBy: roundedTimestamp
orderDirection: asc
where: { roundedTimestamp_gte: $since, period: $period }
) {
...ClmSnapshotData
}
}

fragment ClassicPriceData on Classic {
sharesToken: vaultSharesToken {
...Token
}
underlyingToken {
...Token
}
underlyingBreakdownTokens {
...Token
}
underlyingBreakdownTokensOrder
snapshots(
first: $first
skip: $skip
orderBy: roundedTimestamp
orderDirection: asc
where: { roundedTimestamp_gte: $since, period: $period }
) {
...ClassicSnapshotData
}
}

query VaultHistoricPrices(
$vault_address: ID!
$since: BigInt!
Expand All @@ -13,21 +80,9 @@ query VaultHistoricPrices(
$skip: Int = 0
) {
clm(id: $vault_address) {
underlyingToken1 {
...Token
}
snapshots(
first: $first
skip: $skip
orderBy: roundedTimestamp
orderDirection: asc
# TODO remove managerTotalSupply_gt once reindexed to not save snapshots when total supply is 0
where: { roundedTimestamp_gte: $since, period: $period, managerTotalSupply_gt: 0 }
) {
roundedTimestamp
priceRangeMin1
priceOfToken0InToken1
priceRangeMax1
}
...ClmPriceData
}
classic(id: $vault_address) {
...ClassicPriceData
}
}
Loading

0 comments on commit ffa1c2f

Please sign in to comment.