Skip to content

Commit

Permalink
Merge branch 'master' into dynamic-trsry
Browse files Browse the repository at this point in the history
# Conflicts:
#	subgraphs/ethereum/src/utils/Constants.ts
#	subgraphs/ethereum/src/utils/ProtocolAddresses.ts
#	subgraphs/ethereum/src/utils/Silo.ts
#	subgraphs/ethereum/subgraph.yaml
#	subgraphs/ethereum/tests/contractHelper.test.ts
#	subgraphs/ethereum/tests/erc4626.test.ts
#	subgraphs/ethereum/tests/liquidityBalancer.test.ts
#	subgraphs/ethereum/tests/liquidityCalculations.test.ts
#	subgraphs/ethereum/tests/liquidityCurve.test.ts
#	subgraphs/ethereum/tests/liquidityFraxSwap.test.ts
#	subgraphs/ethereum/tests/liquidityUniswapV2.test.ts
#	subgraphs/ethereum/tests/liquityAllocator.test.ts
#	subgraphs/ethereum/tests/price.test.ts
#	subgraphs/ethereum/tests/uniswapV3Helper.ts
  • Loading branch information
0xJem committed Jul 16, 2024
2 parents ae7e30c + d2b856d commit f8e0569
Show file tree
Hide file tree
Showing 76 changed files with 3,903 additions and 4,358 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/query.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "18"
cache: "yarn"
- name: Install
run: |
Expand All @@ -27,9 +27,9 @@ jobs:
DEPLOYMENT_ID=$(jq -r .id subgraphs/${{ matrix.subgraph }}/config.json)
[[ ! -z "$DEPLOYMENT_ID" ]] && echo "deployment id is set" || (echo "::error::deployment id is not set in config.json" && exit 1)
echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_ENV
- name: Get Latest Block
- name: Get Latest Date
run: |
yarn subgraph latest-block ${{ matrix.subgraph }} --deployment ${{ env.DEPLOYMENT_ID }}
yarn subgraph latest-date ${{ matrix.subgraph }} --deployment ${{ env.DEPLOYMENT_ID }}
- name: Get Token Records
run: |
yarn subgraph query ${{ matrix.subgraph }} --branch branch --deployment ${{ env.DEPLOYMENT_ID }}
Expand All @@ -52,7 +52,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "18"
cache: "yarn"
- name: Install
run: |
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "18"
cache: "yarn"
# Looks for an existing comment, so it can be updated
- name: Find Existing Comment
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"eslint.packageManager": "yarn",
"eslint.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"cSpell.words": [
"arbitrum",
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ Gathers data from bonds, liquidity and Olympus treasury.

Used in the [Olympus Treasury Dashboard](https://app.olympusdao.finance/).

Deployed at <https://thegraph.com/hosted-service/subgraph/olympusdao/olympus-protocol-metrics>
Deployed at:

- [Ethereum mainnet](https://thegraph.com/explorer/subgraphs/7jeChfyUTWRyp2JxPGuuzxvGt3fDKMkC9rLjm7sfLcNp?view=Overview&chain=arbitrum-one)
- [Polygon](https://thegraph.com/explorer/subgraphs/aF7zBXagiSjwwM1yAUiyrWFJDhh5RLpVn2nuvVbKwDw?view=Overview&chain=arbitrum-one)
- [Arbitrum](https://thegraph.com/explorer/subgraphs/8Zxb1kVv9ZBChHXEPSgtC5u5gjCijMn5k8ErpzRYWNgH?view=Overview&chain=arbitrum-one)
- [Fantom](https://thegraph.com/hosted-service/subgraph/olympusdao/protocol-metrics-polygon)

## Initial Setup

Expand Down
8 changes: 4 additions & 4 deletions bin/subgraph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ program
.description("CLI for the deployment and testing of Olympus subgraphs");

program
.command("latest-block")
.description("Determines the latest block for a subgraph")
.command("latest-date")
.description("Determines the latest date for a subgraph")
.argument("<subgraph>", `the subgraph to use, one of: ${subgraphNames.join(", ")}`, parseSubgraph)
.requiredOption("--deployment <deployment id>", "the deployment id (starts with 'Qm')", parseDeploymentId)
.action(async (subgraph, options) => {
const query = await getSubgraphHandler(subgraph, options.deployment, null);
query.doLatestBlock();
query.doLatestDate();
});

program
Expand Down Expand Up @@ -243,7 +243,7 @@ program

console.info("*** Running graph test");
spawnProcess(
`yarn graph test --version 0.5.3 ${options.recompile == true ? "--recompile" : ""}`,
`yarn graph test --version 0.6.0 ${options.recompile == true ? "--recompile" : ""}`,
(testExitCode: number) => {
if (testExitCode > 0) {
process.exit(testExitCode);
Expand Down
4 changes: 2 additions & 2 deletions bin/subgraph/src/networkHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface NetworkHandler {
subgraphId: string;
branch: string;

doLatestBlock(): void;
doLatestDate(): void;
doQuery(): void;
doComparison(): void;
}
Expand All @@ -27,7 +27,7 @@ export class BaseNetworkHandler implements NetworkHandler {
this.outputPath = outputPath;
}

public async doLatestBlock(): Promise<void> {
public async doLatestDate(): Promise<void> {
throw new Error("Method not implemented.");
}
public async doQuery(): Promise<void> {
Expand Down
48 changes: 27 additions & 21 deletions bin/subgraph/src/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,29 @@ const performQuery = async (subgraphId: string, query: string): Promise<any> =>
return await gqlClient.query({ query: gql(query) });
};

export const getLatestBlock = async (subgraphId: string, date: string): Promise<string> => {
const query = `
{
tokenRecords(first: 1, orderBy: block, orderDirection: desc, where: {date: "${date}"}) {
block
}
}
`;
console.info(
`Fetching latest block on date ${date} for subgraph id ${subgraphId} with query: ${query}`,
);
const dayBeforeResults = await performQuery(subgraphId, query);
if (!dayBeforeResults.data) {
throw new Error("getTestBlock: day before latest block query returned no results");
}

const latestBlock = dayBeforeResults.data.tokenRecords[0].block;
console.info(`Received latest block ${latestBlock}`);
return latestBlock;
}

/**
* Determines a block that can be used for testing.
* Determines a date that can be used for testing.
*
* Currently, this looks for the latest block that is available, and determines
* the latest block for the previous day. The absolute latest block
Expand All @@ -24,7 +45,7 @@ const performQuery = async (subgraphId: string, query: string): Promise<any> =>
* @returns
* @throws Error if there are no results from the GraphQL query
*/
export const getTestBlock = async (subgraphId: string): Promise<string> => {
export const getTestDate = async (subgraphId: string): Promise<string> => {
// We first fetch the latest block for the query
const latestBlockQuery = `
{
Expand All @@ -50,24 +71,8 @@ export const getTestBlock = async (subgraphId: string): Promise<string> => {
const dayBeforeDate = new Date(latestBlockDate);
dayBeforeDate.setTime(dayBeforeDate.getTime() - DAY_MS);
const dayBeforeDateString = dayBeforeDate.toISOString().split("T")[0];
const dayBeforeQuery = `
{
tokenRecords(first: 1, orderBy: block, orderDirection: desc, where: {date: "${dayBeforeDateString}"}) {
block
}
}
`;
console.info(
`Fetching latest block on date ${dayBeforeDateString} for subgraph id ${subgraphId} with query: ${dayBeforeQuery}`,
);
const dayBeforeResults = await performQuery(subgraphId, dayBeforeQuery);
if (!dayBeforeResults.data) {
throw new Error("getTestBlock: day before latest block query returned no results");
}

const dayBeforeLatestBlock = dayBeforeResults.data.tokenRecords[0].block;
console.info(`Received latest block ${dayBeforeLatestBlock}`);
return dayBeforeLatestBlock;
return dayBeforeDateString;
};

export type TokenRecord = {
Expand Down Expand Up @@ -100,7 +105,7 @@ export const getTokenRecords = async (
): Promise<TokenRecord[]> => {
const query = `
{
tokenRecords(where: {block: ${block}}) {
tokenRecords(orderBy: token, where: {block: ${block}}) {
id
block
date
Expand Down Expand Up @@ -153,11 +158,12 @@ export const getTokenSupplies = async (
): Promise<TokenSupply[]> => {
const query = `
{
tokenSupplies(where: {block: ${block}}) {
tokenSupplies(orderBy: token, where: {block: ${block}}) {
id
block
date
token
pool
source
balance
supplyBalance
Expand Down
6 changes: 3 additions & 3 deletions bin/subgraph/src/subgraphs/ethereum/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ export const combineOutput = (network: string, comparisonFile: ComparisonResults
*/
comparisonFile.results.output = `
**Network:** ${network}
**Block Tested:** ${comparisonFile.latestBlock}
**Date:** ${comparisonFile.latestDate}
**Subgraph Id:**
Base: ${comparisonFile.branches.base.subgraphId}
Branch: ${comparisonFile.branches.branch.subgraphId}
Base: ${comparisonFile.branches.base.subgraphId} (Block: ${comparisonFile.branches.base.blockNumber})
Branch: ${comparisonFile.branches.branch.subgraphId} (Block: ${comparisonFile.branches.branch.blockNumber})
## Asset Records
${comparisonFile.results.marketValue.output}
Expand Down
27 changes: 17 additions & 10 deletions bin/subgraph/src/subgraphs/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseNetworkHandler } from "../../networkHandler";
import { getOhmPrice, getTestBlock, getTokenRecords, getTokenSupplies } from "../../subgraph";
import { getLatestBlock, getOhmPrice, getTestDate, getTokenRecords, getTokenSupplies } from "../../subgraph";
import {
combineOutput,
compareBackedSupplyRecords,
Expand All @@ -13,28 +13,35 @@ import {
import { readComparisonFile, writeComparisonFile } from "./results";

export default class EthereumHandler extends BaseNetworkHandler {
async doLatestBlock(): Promise<void> {
async doLatestDate(): Promise<void> {
const comparisonFile = readComparisonFile(this.outputPath);

const latestBlock = await getTestBlock(this.subgraphId);
const latestDate = await getTestDate(this.subgraphId);
comparisonFile.latestDate = latestDate;

comparisonFile.latestBlock = latestBlock;
writeComparisonFile(comparisonFile, this.outputPath);
}

async doQuery(): Promise<void> {
const comparisonFile = readComparisonFile(this.outputPath);
const branchInfo = {
subgraphId: "",
blockNumber: "",
};

// Fetch the latest block for each branch
const latestBlock = await getLatestBlock(this.subgraphId, comparisonFile.latestDate);
branchInfo.blockNumber = latestBlock;

const tokenRecords = await getTokenRecords(this.subgraphId, comparisonFile.latestBlock);
const tokenSupplies = await getTokenSupplies(this.subgraphId, comparisonFile.latestBlock);
const tokenRecords = await getTokenRecords(this.subgraphId, latestBlock);
const tokenSupplies = await getTokenSupplies(this.subgraphId, latestBlock);

// Update the comparison results and write
comparisonFile.branches[this.branch] = {
subgraphId: this.subgraphId,
};
branchInfo.subgraphId = this.subgraphId;

comparisonFile.records.tokenRecords[this.branch] = tokenRecords;
comparisonFile.records.tokenSupplies[this.branch] = tokenSupplies;
comparisonFile.branches[this.branch] = branchInfo;

writeComparisonFile(comparisonFile, this.outputPath);
}
Expand All @@ -54,7 +61,7 @@ export default class EthereumHandler extends BaseNetworkHandler {

// Get OHM price
const subgraphId = comparisonFile.branches.branch.subgraphId;
const block = comparisonFile.latestBlock;
const block = comparisonFile.branches.branch.blockNumber;
const ohmPrice = await getOhmPrice(subgraphId, block);

doLiquidBackingCheck(tokenRecordsBranch, tokenSuppliesBranch, ohmPrice, comparisonFile);
Expand Down
4 changes: 3 additions & 1 deletion bin/subgraph/src/subgraphs/ethereum/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { dirname } from "path";
import { TokenRecord, TokenSupply } from "../../subgraph";

export type ComparisonResults = {
latestBlock?: string;
latestDate?: string;
branches: {
base?: {
blockNumber?: string;
subgraphId: string;
};
branch?: {
blockNumber?: string;
subgraphId: string;
};
};
Expand Down
6 changes: 3 additions & 3 deletions bin/subgraph/src/subgraphs/shared/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ export const combineOutput = (network: string, comparisonFile: ComparisonResults
*/
comparisonFile.results.output = `
**Network:** ${network}
**Block Tested:** ${comparisonFile.latestBlock}
**Date:** ${comparisonFile.latestDate}
**Subgraph Id:**
Base: ${comparisonFile.branches.base.subgraphId}
Branch: ${comparisonFile.branches.branch.subgraphId}
Base: ${comparisonFile.branches.base.subgraphId} (Block: ${comparisonFile.branches.base.blockNumber})
Branch: ${comparisonFile.branches.branch.subgraphId} (Block: ${comparisonFile.branches.branch.blockNumber})
## Asset Records
${comparisonFile.results.marketValue.output}
Expand Down
25 changes: 16 additions & 9 deletions bin/subgraph/src/subgraphs/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseNetworkHandler } from "../../networkHandler";
import { getTestBlock, getTokenRecords, getTokenSupplies } from "../../subgraph";
import { getLatestBlock, getTestDate, getTokenRecords, getTokenSupplies } from "../../subgraph";
import {
combineOutput,
compareLiquidBackingRecords,
Expand All @@ -10,28 +10,35 @@ import {
import { readComparisonFile, writeComparisonFile } from "./results";

export default class EthereumHandler extends BaseNetworkHandler {
async doLatestBlock(): Promise<void> {
async doLatestDate(): Promise<void> {
const comparisonFile = readComparisonFile(this.outputPath);

const latestBlock = await getTestBlock(this.subgraphId);
const latestDate = await getTestDate(this.subgraphId);
comparisonFile.latestDate = latestDate;

comparisonFile.latestBlock = latestBlock;
writeComparisonFile(comparisonFile, this.outputPath);
}

async doQuery(): Promise<void> {
const comparisonFile = readComparisonFile(this.outputPath);
const branchInfo = {
subgraphId: "",
blockNumber: "",
};

// Fetch the latest block for each branch
const latestBlock = await getLatestBlock(this.subgraphId, comparisonFile.latestDate);
branchInfo.blockNumber = latestBlock;

const tokenRecords = await getTokenRecords(this.subgraphId, comparisonFile.latestBlock);
const tokenSupplies = await getTokenSupplies(this.subgraphId, comparisonFile.latestBlock);
const tokenRecords = await getTokenRecords(this.subgraphId, latestBlock);
const tokenSupplies = await getTokenSupplies(this.subgraphId, latestBlock);

// Update the comparison results and write
comparisonFile.branches[this.branch] = {
subgraphId: this.subgraphId,
};
branchInfo.subgraphId = this.subgraphId;

comparisonFile.records.tokenRecords[this.branch] = tokenRecords;
comparisonFile.records.tokenSupplies[this.branch] = tokenSupplies;
comparisonFile.branches[this.branch] = branchInfo;

writeComparisonFile(comparisonFile, this.outputPath);
}
Expand Down
4 changes: 3 additions & 1 deletion bin/subgraph/src/subgraphs/shared/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { dirname } from "path";
import { TokenRecord, TokenSupply } from "../../subgraph";

export type ComparisonResults = {
latestBlock?: string;
latestDate?: string;
branches: {
base?: {
blockNumber?: string;
subgraphId: string;
};
branch?: {
blockNumber?: string;
subgraphId: string;
};
};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@apollo/client": "^3.8.4",
"@graphprotocol/graph-cli": "^0.57.0",
"@graphprotocol/graph-cli": "^0.67.0",
"@graphprotocol/graph-ts": "^0.31.0",
"assemblyscript-json": "^1.1.0",
"commander": "^9.4.0",
Expand Down Expand Up @@ -49,4 +49,4 @@
"ramda": "^0.27.2",
"yargs-parser": "^18.1.1"
}
}
}
Loading

0 comments on commit f8e0569

Please sign in to comment.