Skip to content

Commit

Permalink
Merge pull request #48 from OlympusDAO/sdai-fix
Browse files Browse the repository at this point in the history
More liquid backing fixes
  • Loading branch information
0xJem authored Sep 14, 2023
2 parents 2c5904c + dcd5b1a commit 0c70925
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
15 changes: 8 additions & 7 deletions apps/server/.wundergraph/operations/paginated/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ export default createOperation.query({
includeRecords: z.boolean({ description: "If true, includes the records used to calculate each metric." }).optional(),
}),
handler: async (ctx) => {
console.log(`Commencing paginated query for Metric`);
console.log(`Input: ${JSON.stringify(ctx.input)}`);
const FUNC = "paginated/metrics";
console.log(`${FUNC}: Commencing paginated query for Metric`);
console.log(`${FUNC}: Input: ${JSON.stringify(ctx.input)}`);
const finalStartDate: Date = new Date(ctx.input.startDate);
console.log(`finalStartDate: ${finalStartDate.toISOString()}`);
console.log(`${FUNC}: finalStartDate: ${finalStartDate.toISOString()}`);
if (isNaN(finalStartDate.getTime())) {
throw new Error(`startDate should be in the YYYY-MM-DD format.`);
}
Expand Down Expand Up @@ -53,7 +54,7 @@ export default createOperation.query({
byDateRecords.set(date, recordContainer);
});

console.log(`Processed ${protocolMetricsQueryResult.data.length} ProtocolMetric records.`);
console.log(`${FUNC}: Processed ${protocolMetricsQueryResult.data.length} ProtocolMetric records.`);
}

const tokenRecordsQueryResult = await ctx.operations.query({
Expand All @@ -79,7 +80,7 @@ export default createOperation.query({
byDateRecords.set(date, recordContainer);
});

console.log(`Processed ${tokenRecordsQueryResult.data.length} TokenRecord records.`);
console.log(`${FUNC}: Processed ${tokenRecordsQueryResult.data.length} TokenRecord records.`);
}

const tokenSuppliesQueryResult = await ctx.operations.query({
Expand All @@ -105,14 +106,14 @@ export default createOperation.query({
byDateRecords.set(date, recordContainer);
});

console.log(`Processed ${tokenSuppliesQueryResult.data.length} TokenSupply records.`);
console.log(`${FUNC}: Processed ${tokenSuppliesQueryResult.data.length} TokenSupply records.`);
}

// Convert into new Metric objects
byDateRecords.forEach((recordContainer, date) => {
const metricRecord: Metric | null = getMetricObject(recordContainer.tokenRecords, recordContainer.tokenSupplies, recordContainer.protocolMetrics, ctx.input.includeRecords);
if (!metricRecord) {
console.log(`Skipping date ${date} because it is missing data.`);
console.log(`${FUNC}: Skipping date ${date} because it is missing data.`);
return;
}

Expand Down
13 changes: 7 additions & 6 deletions apps/server/.wundergraph/operations/paginated/protocolMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export default createOperation.query({
dateOffset: z.number({ description: "The number of days to paginate by. Reduce the value if data is missing." }).optional(),
}),
handler: async (ctx) => {
console.log(`Commencing paginated query for ProtocolMetric`);
console.log(`Input: ${JSON.stringify(ctx.input)}`);
const FUNC = "paginated/protocolMetrics";
console.log(`${FUNC}: Commencing paginated query for ProtocolMetric`);
console.log(`${FUNC}: Input: ${JSON.stringify(ctx.input)}`);
const finalStartDate: Date = new Date(ctx.input.startDate);
console.log(`finalStartDate: ${finalStartDate.toISOString()}`);
console.log(`${FUNC}: finalStartDate: ${finalStartDate.toISOString()}`);
if (isNaN(finalStartDate.getTime())) {
throw new Error(`startDate should be in the YYYY-MM-DD format.`);
}
Expand All @@ -34,7 +35,7 @@ export default createOperation.query({
let currentEndDate: Date = getNextEndDate(null);

while (currentStartDate.getTime() >= finalStartDate.getTime()) {
console.log(`Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
console.log(`${FUNC}: Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
const queryResult = await ctx.operations.query({
operationName: "raw/internal/protocolMetrics",
input: {
Expand All @@ -56,12 +57,12 @@ export default createOperation.query({
// Ensures that a finalStartDate close to the current date (within the first page) is handled correctly
// There is probably a cleaner way to do this, but this works for now
if (currentStartDate == finalStartDate) {
console.log(`Reached final start date.`);
console.log(`${FUNC}: Reached final start date.`);
break;
}
}

console.log(`Returning ${combinedProtocolMetrics.length} records.`);
console.log(`${FUNC}: Returning ${combinedProtocolMetrics.length} records.`);
return sortRecordsDescending(combinedProtocolMetrics);
},
});
13 changes: 7 additions & 6 deletions apps/server/.wundergraph/operations/paginated/tokenRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ export default createOperation.query({
crossChainDataComplete: z.boolean({ description: "If true, returns data up to the most recent day in which all subgraphs have data." }).optional(),
}),
handler: async (ctx) => {
console.log(`Commencing paginated query for TokenRecord`);
console.log(`Input: ${JSON.stringify(ctx.input)}`);
const FUNC = "paginated/tokenRecords";
console.log(`${FUNC}: Commencing paginated query for TokenRecord`);
console.log(`${FUNC}: Input: ${JSON.stringify(ctx.input)}`);
const finalStartDate: Date = new Date(ctx.input.startDate);
console.log(`finalStartDate: ${finalStartDate.toISOString()}`);
console.log(`${FUNC}: finalStartDate: ${finalStartDate.toISOString()}`);
if (isNaN(finalStartDate.getTime())) {
throw new Error(`startDate should be in the YYYY-MM-DD format.`);
}
Expand All @@ -65,7 +66,7 @@ export default createOperation.query({
let hasProcessedFirstDate = false;

while (currentStartDate.getTime() >= finalStartDate.getTime()) {
console.log(`Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
console.log(`${FUNC}: Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
const queryResult = await ctx.operations.query({
operationName: "tokenRecords",
input: {
Expand All @@ -88,12 +89,12 @@ export default createOperation.query({
// Ensures that a finalStartDate close to the current date (within the first page) is handled correctly
// There is probably a cleaner way to do this, but this works for now
if (currentStartDate == finalStartDate) {
console.log(`Reached final start date.`);
console.log(`${FUNC}: Reached final start date.`);
break;
}
}

console.log(`Returning ${combinedTokenRecords.length} records.`);
console.log(`${FUNC}: Returning ${combinedTokenRecords.length} records.`);
return sortRecordsDescending(combinedTokenRecords);
},
});
13 changes: 7 additions & 6 deletions apps/server/.wundergraph/operations/paginated/tokenSupplies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ export default createOperation.query({
crossChainDataComplete: z.boolean({ description: "If true, returns data up to the most recent day in which all subgraphs have data." }).optional(),
}),
handler: async (ctx) => {
console.log(`Commencing paginated query for TokenSupply`);
console.log(`Input: ${JSON.stringify(ctx.input)}`);
const FUNC = "paginated/tokenSupplies";
console.log(`${FUNC}: Commencing paginated query for TokenSupply`);
console.log(`${FUNC}: Input: ${JSON.stringify(ctx.input)}`);
const finalStartDate: Date = new Date(ctx.input.startDate);
console.log(`finalStartDate: ${finalStartDate.toISOString()}`);
console.log(`${FUNC}: finalStartDate: ${finalStartDate.toISOString()}`);
if (isNaN(finalStartDate.getTime())) {
throw new Error(`startDate should be in the YYYY-MM-DD format.`);
}
Expand All @@ -69,7 +70,7 @@ export default createOperation.query({
let hasProcessedFirstDate = false;

while (currentStartDate.getTime() >= finalStartDate.getTime()) {
console.log(`Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
console.log(`${FUNC}: Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
const queryResult = await ctx.operations.query({
operationName: "tokenSupplies",
input: {
Expand All @@ -92,12 +93,12 @@ export default createOperation.query({
// Ensures that a finalStartDate close to the current date (within the first page) is handled correctly
// There is probably a cleaner way to do this, but this works for now
if (currentStartDate == finalStartDate) {
console.log(`Reached final start date.`);
console.log(`${FUNC}: Reached final start date.`);
break;
}
}

console.log(`Returning ${combinedTokenSupplies.length} records.`);
console.log(`${FUNC}: Returning ${combinedTokenSupplies.length} records.`);
return sortRecordsDescending(combinedTokenSupplies);
},
});
2 changes: 1 addition & 1 deletion apps/server/.wundergraph/wundergraph.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const resolveSubgraphUrl = (url: string): string => {

const treasuryEthereum = introspect.graphql({
apiNamespace: "treasuryEthereum",
url: resolveSubgraphUrl("https://gateway-arbitrum.network.thegraph.com/api/[api-key]/deployments/id/QmZ3HZvfgSTZz29q22tJpReEL4Xiprs2croPymiuyEJknK"), // 4.12.2
url: resolveSubgraphUrl("https://gateway-arbitrum.network.thegraph.com/api/[api-key]/deployments/id/QmSwwBfAoWJLHQeSTagFnkibnkrjeprxcQpXAHk6AVrysA"), // 4.12.6
schemaExtension: schemaExtension,
});

Expand Down

0 comments on commit 0c70925

Please sign in to comment.