-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: subgraph vesting data (#1886)
* chore: add vesting subgraph client * chore: subgraph vesting data parsing WIP * chore: subgraph vesting data parsing: cliff and pauses * chore: use latest pause log for time vested calculation * chore: replace alchemy vestings usage for subgraph * chore: replace VESTINGS_QUERY_ENDPOINT with published version * refactor: remove console logs * refactor: address pr comments
- Loading branch information
Showing
12 changed files
with
388 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export type SubgraphVesting = { | ||
id: string | ||
version: number | ||
duration: string | ||
cliff: string | ||
beneficiary: string | ||
revoked: boolean | ||
revocable: boolean | ||
released: string | ||
start: string | ||
periodDuration: string | ||
vestedPerPeriod: string[] | ||
paused: boolean | ||
pausable: boolean | ||
stop: string | ||
linear: boolean | ||
token: string | ||
owner: string | ||
total: string | ||
releaseLogs: SubgraphReleaseLog[] | ||
pausedLogs: SubgraphPausedLog[] | ||
revokeTimestamp: bigint | ||
} | ||
|
||
type SubgraphReleaseLog = { | ||
id: string | ||
timestamp: string | ||
amount: string | ||
} | ||
|
||
type SubgraphPausedLog = { | ||
id: string | ||
timestamp: string | ||
eventType: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import fetch from 'isomorphic-fetch' | ||
|
||
import { VESTINGS_QUERY_ENDPOINT } from '../entities/Snapshot/constants' | ||
|
||
import { SubgraphVesting } from './VestingSubgraphTypes' | ||
import { trimLastForwardSlash } from './utils' | ||
|
||
export class VestingsSubgraph { | ||
static Cache = new Map<string, VestingsSubgraph>() | ||
private readonly queryEndpoint: string | ||
|
||
static from(baseUrl: string) { | ||
baseUrl = trimLastForwardSlash(baseUrl) | ||
if (!this.Cache.has(baseUrl)) { | ||
this.Cache.set(baseUrl, new this(baseUrl)) | ||
} | ||
|
||
return this.Cache.get(baseUrl)! | ||
} | ||
|
||
static get() { | ||
return this.from(this.getQueryEndpoint()) | ||
} | ||
|
||
constructor(baseUrl: string) { | ||
this.queryEndpoint = baseUrl | ||
} | ||
|
||
private static getQueryEndpoint() { | ||
if (!VESTINGS_QUERY_ENDPOINT) { | ||
throw new Error( | ||
'Failed to determine vestings subgraph query endpoint. Please check VESTINGS_QUERY_ENDPOINT env is defined' | ||
) | ||
} | ||
return VESTINGS_QUERY_ENDPOINT | ||
} | ||
|
||
async getVesting(address: string): Promise<SubgraphVesting> { | ||
const query = ` | ||
query getVesting($address: String!) { | ||
vestings(where: { id: $address }){ | ||
id | ||
version | ||
duration | ||
cliff | ||
beneficiary | ||
revoked | ||
revocable | ||
released | ||
start | ||
periodDuration | ||
vestedPerPeriod | ||
paused | ||
pausable | ||
stop | ||
linear | ||
token | ||
owner | ||
total | ||
revokeTimestamp | ||
releaseLogs{ | ||
id | ||
timestamp | ||
amount | ||
} | ||
pausedLogs{ | ||
id | ||
timestamp | ||
eventType | ||
} | ||
} | ||
} | ||
` | ||
|
||
const variables = { address } | ||
const response = await fetch(this.queryEndpoint, { | ||
method: 'post', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
query, | ||
variables: variables, | ||
}), | ||
}) | ||
|
||
const body = await response.json() | ||
return body?.data?.vestings[0] || {} | ||
} | ||
|
||
async getVestings(addresses: string[]): Promise<SubgraphVesting[]> { | ||
const query = ` | ||
query getVestings($addresses: [String]!) { | ||
vestings(where: { id_in: $addresses }){ | ||
id | ||
version | ||
duration | ||
cliff | ||
beneficiary | ||
revoked | ||
revocable | ||
released | ||
start | ||
periodDuration | ||
vestedPerPeriod | ||
paused | ||
pausable | ||
stop | ||
linear | ||
token | ||
owner | ||
total | ||
revokeTimestamp | ||
releaseLogs{ | ||
id | ||
timestamp | ||
amount | ||
} | ||
pausedLogs{ | ||
id | ||
timestamp | ||
eventType | ||
} | ||
} | ||
} | ||
` | ||
|
||
const variables = { addresses } | ||
const response = await fetch(this.queryEndpoint, { | ||
method: 'post', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
query, | ||
variables: variables, | ||
}), | ||
}) | ||
|
||
const body = await response.json() | ||
return body?.data?.vestings || [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.