Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK Update #41

Merged
merged 10 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@olympusdao/treasury-subgraph-client",
"version": "1.3.0",
"version": "1.3.1",
"description": "WunderGraph client for the OlympusDAO treasury subgraph",
"repository": {
"type": "git",
Expand All @@ -27,7 +27,7 @@
"publish-package": "yarn publish --access public --otp $YARN_OTP"
},
"dependencies": {
"@wundergraph/sdk": "^0.169.0"
"@wundergraph/sdk": "^0.177.0"
},
"devDependencies": {
"@olympusdao/treasury-subgraph": "*",
Expand Down
11 changes: 11 additions & 0 deletions apps/server/.wundergraph/numberHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const parseNumber = (value: string | number | undefined): number => {
if (typeof value === "undefined") {
return 0;
}

if (typeof value === "number") {
return value;
}

return parseInt(value);
}
3 changes: 2 additions & 1 deletion apps/server/.wundergraph/protocolMetricHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CHAIN_ARBITRUM, CHAIN_ETHEREUM, CHAIN_FANTOM, CHAIN_POLYGON } from "./constants";
import { RawInternalProtocolMetricsResponseData } from "./generated/models";
import { parseNumber } from "./numberHelper";

export type ProtocolMetric = RawInternalProtocolMetricsResponseData["treasuryEthereum_protocolMetrics"][0];

Expand All @@ -12,7 +13,7 @@ type ProtocolMetricByDate = {
export const filterLatestBlockByDay = (records: ProtocolMetric[]): ProtocolMetric[] => {
const filteredData = Object.values(records.reduce((acc: Record<string, ProtocolMetricByDate>, curr: ProtocolMetric) => {
const { date, block } = curr;
const blockNumber = parseInt(block);
const blockNumber = parseNumber(block);
if (!acc[date] || acc[date].block < blockNumber) {
acc[date] = { date, block: blockNumber, records: [curr] };
} else if (acc[date].block === blockNumber) {
Expand Down
3 changes: 2 additions & 1 deletion apps/server/.wundergraph/tokenRecordHelper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { parseNumber } from "../tests/numberHelper";
import { CHAIN_ARBITRUM, CHAIN_ETHEREUM, CHAIN_FANTOM, CHAIN_POLYGON } from "./constants";
import { TokenRecordsLatestResponseData } from "./generated/models";

Expand All @@ -18,7 +19,7 @@ type TokenRecordByDate = {
export const filterLatestBlockByDay = (records: TokenRecord[]): TokenRecord[] => {
const filteredData = Object.values(records.reduce((acc: Record<string, TokenRecordByDate>, curr: TokenRecord) => {
const { date, block } = curr;
const blockNumber = parseInt(block);
const blockNumber = parseNumber(block);
if (!acc[date] || acc[date].block < blockNumber) {
acc[date] = { date, block: blockNumber, records: [curr] };
} else if (acc[date].block === blockNumber) {
Expand Down
3 changes: 2 additions & 1 deletion apps/server/.wundergraph/tokenSupplyHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CHAIN_ARBITRUM, CHAIN_ETHEREUM, CHAIN_FANTOM, CHAIN_POLYGON } from "./constants";
import { TokenSuppliesLatestResponseData } from "./generated/models";
import { parseNumber } from "./numberHelper";

export type TokenSupply = TokenSuppliesLatestResponseData["treasuryEthereum_tokenSupplies"][0];

Expand All @@ -12,7 +13,7 @@ type TokenSupplyByDate = {
export const filterLatestBlockByDay = (records: TokenSupply[]): TokenSupply[] => {
const filteredData = Object.values(records.reduce((acc: Record<string, TokenSupplyByDate>, curr: TokenSupply) => {
const { date, block } = curr;
const blockNumber = parseInt(block);
const blockNumber = parseNumber(block);
if (!acc[date] || acc[date].block < blockNumber) {
acc[date] = { date, block: blockNumber, records: [curr] };
} else if (acc[date].block === blockNumber) {
Expand Down
4 changes: 1 addition & 3 deletions apps/server/.wundergraph/wundergraph.server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { configureWunderGraphServer } from '@wundergraph/sdk/server';
import type { HooksConfig } from './generated/wundergraph.hooks';
import type { InternalClient } from './generated/wundergraph.internal.client';

export default configureWunderGraphServer<HooksConfig, InternalClient>(() => ({
export default configureWunderGraphServer(() => ({
hooks: {
queries: {},
mutations: {},
Expand Down
3 changes: 1 addition & 2 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"turbo": "^1.9.3",
"typescript": "^5.0.4"
},
"dependencies": {
"@wundergraph/sdk": "^0.169.0",
"@wundergraph/sdk": "^0.177.0",
"date-fns": "^2.30.0"
},
"scripts": {
Expand Down
49 changes: 25 additions & 24 deletions apps/server/tests/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getSupplyBalanceForTypes } from "./metricsHelper";
import { TokenRecord, filterReduce, filter as filterTokenRecords, getFirstRecord as getFirstTokenRecord } from "./tokenRecordHelper";
import { TokenSupply, filter as filterTokenSupplies, getFirstRecord as getFirstTokenSupplies } from "./tokenSupplyHelper";
import { ProtocolMetric } from "./protocolMetricHelper";
import { parseNumber } from "./numberHelper";

const wg = createTestServer();

Expand Down Expand Up @@ -141,17 +142,17 @@ describe("latest", () => {

// Raw data has an array property for each chain
const arbitrumRawResult = rawResult.data?.treasuryArbitrum_tokenRecords[0];
const arbitrumRawBlock: number = arbitrumRawResult?.block ? parseInt(arbitrumRawResult.block) : 0;
const arbitrumRawTimestamp: number = arbitrumRawResult?.timestamp ? parseInt(arbitrumRawResult.timestamp) : 0;
const arbitrumRawBlock: number = parseNumber(arbitrumRawResult?.block);
const arbitrumRawTimestamp: number = parseNumber(arbitrumRawResult?.timestamp);
const ethereumRawResult = rawResult.data?.treasuryEthereum_tokenRecords[0];
const ethereumRawBlock: number = ethereumRawResult?.block ? parseInt(ethereumRawResult.block) : 0;
const ethereumRawTimestamp: number = ethereumRawResult?.timestamp ? parseInt(ethereumRawResult.timestamp) : 0;
const ethereumRawBlock: number = parseNumber(ethereumRawResult?.block);
const ethereumRawTimestamp: number = parseNumber(ethereumRawResult?.timestamp);
const fantomRawResult = rawResult.data?.treasuryFantom_tokenRecords[0];
const fantomRawBlock: number = fantomRawResult?.block ? parseInt(fantomRawResult.block) : 0;
const fantomRawTimestamp: number = fantomRawResult?.timestamp ? parseInt(fantomRawResult.timestamp) : 0;
const fantomRawBlock: number = parseNumber(fantomRawResult?.block);
const fantomRawTimestamp: number = parseNumber(fantomRawResult?.timestamp);
const polygonRawResult = rawResult.data?.treasuryPolygon_tokenRecords[0];
const polygonRawBlock: number = polygonRawResult?.block ? parseInt(polygonRawResult.block) : 0;
const polygonRawTimestamp: number = polygonRawResult?.timestamp ? parseInt(polygonRawResult.timestamp) : 0;
const polygonRawBlock: number = parseNumber(polygonRawResult?.block);
const polygonRawTimestamp: number = parseNumber(polygonRawResult?.timestamp);

// Grab the results from the latest operation
const result = await wg.client().query({
Expand Down Expand Up @@ -186,17 +187,17 @@ describe("earliest", () => {

// Raw data has an array property for each chain
const arbitrumRawResult = rawResult.data?.treasuryArbitrum_tokenRecords[0];
const arbitrumRawBlock: number = arbitrumRawResult?.block ? parseInt(arbitrumRawResult.block) : 0;
const arbitrumRawTimestamp: number = arbitrumRawResult?.timestamp ? parseInt(arbitrumRawResult.timestamp) : 0;
const arbitrumRawBlock: number = parseNumber(arbitrumRawResult?.block);
const arbitrumRawTimestamp: number = parseNumber(arbitrumRawResult?.timestamp);
const ethereumRawResult = rawResult.data?.treasuryEthereum_tokenRecords[0];
const ethereumRawBlock: number = ethereumRawResult?.block ? parseInt(ethereumRawResult.block) : 0;
const ethereumRawTimestamp: number = ethereumRawResult?.timestamp ? parseInt(ethereumRawResult.timestamp) : 0;
const ethereumRawBlock: number = parseNumber(ethereumRawResult?.block);
const ethereumRawTimestamp: number = parseNumber(ethereumRawResult?.timestamp);
const fantomRawResult = rawResult.data?.treasuryFantom_tokenRecords[0];
const fantomRawBlock: number = fantomRawResult?.block ? parseInt(fantomRawResult.block) : 0;
const fantomRawTimestamp: number = fantomRawResult?.timestamp ? parseInt(fantomRawResult.timestamp) : 0;
const fantomRawBlock: number = parseNumber(fantomRawResult?.block);
const fantomRawTimestamp: number = parseNumber(fantomRawResult?.timestamp);
const polygonRawResult = rawResult.data?.treasuryPolygon_tokenRecords[0];
const polygonRawBlock: number = polygonRawResult?.block ? parseInt(polygonRawResult.block) : 0;
const polygonRawTimestamp: number = polygonRawResult?.timestamp ? parseInt(polygonRawResult.timestamp) : 0;
const polygonRawBlock: number = parseNumber(polygonRawResult?.block);
const polygonRawTimestamp: number = parseNumber(polygonRawResult?.timestamp);

// Grab the results from the earliest operation
const result = await wg.client().query({
Expand Down Expand Up @@ -236,17 +237,17 @@ describe("atBlock", () => {

// Raw data has an array property for each chain
const arbitrumRawResult = getFirstTokenRecord(rawResult.data, CHAIN_ARBITRUM, startDate);
const arbitrumRawBlock: number = arbitrumRawResult?.block ? parseInt(arbitrumRawResult.block) : 0;
const arbitrumRawTimestamp: number = arbitrumRawResult?.timestamp ? parseInt(arbitrumRawResult.timestamp) : 0;
const arbitrumRawBlock: number = parseNumber(arbitrumRawResult?.block);
const arbitrumRawTimestamp: number = parseNumber(arbitrumRawResult?.timestamp);
const ethereumRawResult = getFirstTokenRecord(rawResult.data, CHAIN_ETHEREUM, startDate);
const ethereumRawBlock: number = ethereumRawResult?.block ? parseInt(ethereumRawResult.block) : 0;
const ethereumRawTimestamp: number = ethereumRawResult?.timestamp ? parseInt(ethereumRawResult.timestamp) : 0;
const ethereumRawBlock: number = parseNumber(ethereumRawResult?.block);
const ethereumRawTimestamp: number = parseNumber(ethereumRawResult?.timestamp);
const fantomRawResult = getFirstTokenRecord(rawResult.data, CHAIN_FANTOM, startDate);
const fantomRawBlock: number = fantomRawResult?.block ? parseInt(fantomRawResult.block) : 0;
const fantomRawTimestamp: number = fantomRawResult?.timestamp ? parseInt(fantomRawResult.timestamp) : 0;
const fantomRawBlock: number = parseNumber(fantomRawResult?.block);
const fantomRawTimestamp: number = parseNumber(fantomRawResult?.timestamp);
const polygonRawResult = getFirstTokenRecord(rawResult.data, CHAIN_POLYGON, startDate);
const polygonRawBlock: number = polygonRawResult?.block ? parseInt(polygonRawResult.block) : 0;
const polygonRawTimestamp: number = polygonRawResult?.timestamp ? parseInt(polygonRawResult.timestamp) : 0;
const polygonRawBlock: number = parseNumber(polygonRawResult?.block);
const polygonRawTimestamp: number = parseNumber(polygonRawResult?.timestamp);

// Grab the results from the earliest operation
const result = await wg.client().query({
Expand Down
11 changes: 11 additions & 0 deletions apps/server/tests/numberHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const parseNumber = (value: string | number | undefined): number => {
if (typeof value === "undefined") {
return 0;
}

if (typeof value === "number") {
return value;
}

return parseInt(value);
}
27 changes: 14 additions & 13 deletions apps/server/tests/tokenRecords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { createTestServer } from "../.wundergraph/generated/testing";
import { getISO8601DateString } from "./dateHelper";
import { CHAIN_ARBITRUM, CHAIN_ETHEREUM, CHAIN_FANTOM, CHAIN_POLYGON } from "../.wundergraph/constants";
import { getFirstRecord } from "./tokenRecordHelper";
import { parseNumber } from "./numberHelper";

const wg = createTestServer();

beforeAll(async () => {
await wg.start();
});
}, 10 * 1000);

afterAll(async () => {
await wg.stop();
Expand Down Expand Up @@ -200,22 +201,22 @@ describe("atBlock", () => {

// Raw data has an array property for each chain
const arbitrumRawResult = getFirstRecord(rawResult.data, CHAIN_ARBITRUM, startDate);
const arbitrumRawBlock = arbitrumRawResult?.block || "0";
const arbitrumRawBlock = parseNumber(arbitrumRawResult?.block);
const ethereumRawResult = getFirstRecord(rawResult.data, CHAIN_ETHEREUM, startDate);
const ethereumRawBlock = ethereumRawResult?.block || "0";
const ethereumRawBlock = parseNumber(ethereumRawResult?.block);
const fantomRawResult = getFirstRecord(rawResult.data, CHAIN_FANTOM, startDate);
const fantomRawBlock = fantomRawResult?.block || "0";
const fantomRawBlock = parseNumber(fantomRawResult?.block);
const polygonRawResult = getFirstRecord(rawResult.data, CHAIN_POLYGON, startDate);
const polygonRawBlock = polygonRawResult?.block || "0";
const polygonRawBlock = parseNumber(polygonRawResult?.block);

// Grab the results from the earliest operation
const result = await wg.client().query({
operationName: "atBlock/tokenRecords",
input: {
arbitrumBlock: parseInt(arbitrumRawBlock),
ethereumBlock: parseInt(ethereumRawBlock),
fantomBlock: parseInt(fantomRawBlock),
polygonBlock: parseInt(polygonRawBlock),
arbitrumBlock: arbitrumRawBlock,
ethereumBlock: ethereumRawBlock,
fantomBlock: fantomRawBlock,
polygonBlock: polygonRawBlock,
}
});

Expand All @@ -227,10 +228,10 @@ describe("atBlock", () => {
const polygonResult = getFirstRecord(records, CHAIN_POLYGON);

// Check that the block is the same
expect(arbitrumResult?.block).toEqual(arbitrumRawBlock);
expect(ethereumResult?.block).toEqual(ethereumRawBlock);
expect(fantomResult?.block).toEqual(fantomRawBlock);
expect(polygonResult?.block).toEqual(polygonRawBlock);
expect(parseNumber(arbitrumResult?.block)).toEqual(arbitrumRawBlock);
expect(parseNumber(ethereumResult?.block)).toEqual(ethereumRawBlock);
expect(parseNumber(fantomResult?.block)).toEqual(fantomRawBlock);
expect(parseNumber(polygonResult?.block)).toEqual(polygonRawBlock);
});
});

Expand Down
9 changes: 5 additions & 4 deletions apps/server/tests/tokenSupplies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createTestServer } from "../.wundergraph/generated/testing";
import { getISO8601DateString } from "./dateHelper";
import { CHAIN_ARBITRUM, CHAIN_ETHEREUM, CHAIN_FANTOM, CHAIN_POLYGON } from "../.wundergraph/constants";
import { getFirstRecord } from "./tokenSupplyHelper";
import { parseNumber } from "./numberHelper";

const wg = createTestServer();

Expand Down Expand Up @@ -214,10 +215,10 @@ describe("atBlock", () => {
const result = await wg.client().query({
operationName: "atBlock/tokenSupplies",
input: {
arbitrumBlock: parseInt(arbitrumRawBlock || "0"),
ethereumBlock: parseInt(ethereumRawBlock || "0"),
fantomBlock: parseInt(fantomRawBlock || "0"),
polygonBlock: parseInt(polygonRawBlock || "0"),
arbitrumBlock: parseNumber(arbitrumRawBlock),
ethereumBlock: parseNumber(ethereumRawBlock),
fantomBlock: parseNumber(fantomRawBlock),
polygonBlock: parseNumber(polygonRawBlock),
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
"syncpack": "^9.8.6",
"turbo": "^1.9.3"
}
}
}
Loading