Skip to content

Commit

Permalink
Update package scripts and enhance queries for interest rates calcula…
Browse files Browse the repository at this point in the history
…tion

Removed the "tsc" and "watch" scripts from the scripts section of various package.json files and added new "dev" scripts for development mode. Improved the GraphQL query in MorphoBlueSubgraph for fetching the interest rates by introducing pagination logic. Enhanced the 'get-apy-function' to calculate APY for various time periods and include a detailed breakdown.
  • Loading branch information
jakubswierczek committed Apr 17, 2024
1 parent 26b19f7 commit f7113d2
Show file tree
Hide file tree
Showing 34 changed files with 350 additions and 107 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"private": true,
"scripts": {
"dev": "turbo run dev --concurrency=50",
"prebuild": "turbo run prebuild --cache-dir=.turbo",
"build": "turbo run build --cache-dir=.turbo",
"lint": "turbo run lint --cache-dir=.turbo",
Expand Down
3 changes: 1 addition & 2 deletions packages/aave-spark-subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"test": "jest --passWithNoTests",
"build": "tsc -b -v",
"dev": "tsc -b -w",
"prebuild": "pnpm run generate-ts-types",
"generate-ts-types": "graphql-codegen --config graphql.config.yml",
"lint": "eslint .",
Expand Down
3 changes: 1 addition & 2 deletions packages/abis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"name": "@summerfi/abis",
"version": "1.0.0",
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"test": "jest --passWithNoTests",
"build": "tsc -b -v",
"dev": "tsc -b -w",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/ajna-subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"test": "jest --passWithNoTests",
"build": "tsc -b -v",
"dev": "tsc -b -w",
"prebuild": "pnpm run generate-ts-types",
"generate-ts-types": "graphql-codegen --config graphql.config.yml",
"lint": "eslint .",
Expand Down
3 changes: 1 addition & 2 deletions packages/automation-subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"test": "jest --passWithNoTests",
"build": "tsc -b -v",
"dev": "tsc -b -w",
"prebuild": "pnpm run generate-ts-types",
"generate-ts-types": "graphql-codegen --config graphql.config.yml",
"lint": "eslint .",
Expand Down
3 changes: 1 addition & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
}
},
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"test": "jest --passWithNoTests",
"testw": "jest --watch",
"build": "tsc -b -v ",
"dev": "tsc -b -w",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
Expand Down
1 change: 1 addition & 0 deletions packages/contracts-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"tsc": "tsc",
"build": "tsc -b -v",
"dev": "tsc -b -w",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
Expand Down
1 change: 1 addition & 0 deletions packages/core-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"watch": "tsc -w",
"test": "jest --passWithNoTests",
"build": "tsc -b tsconfig.build.json",
"dev": "tsc -b tsconfig.build.json -w",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"gen-versions": "hardhat run scripts/generate-versions.ts",
Expand Down
3 changes: 1 addition & 2 deletions packages/deployment-configs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
}
},
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"build": "tsc -b tsconfig.build.json",
"dev": "tsc -b tsconfig.build.json -w",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/deployment-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
}
},
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"build": "tsc -b tsconfig.json",
"dev": "tsc -b tsconfig.json -w",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/deployment-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
}
},
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"build": "tsc -b tsconfig.json",
"dev": "tsc -b tsconfig.json -w",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/morpho-blue-external-api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"test": "jest --passWithNoTests",
"build": "tsc -b -v",
"dev": "tsc -b -w",
"prebuild": "pnpm run generate-ts-types",
"generate-ts-types": "graphql-codegen --config graphql.config.yml",
"lint": "eslint .",
Expand Down
5 changes: 1 addition & 4 deletions packages/morpho-blue-subgraph/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
ignorePatterns: ['src/types/graphql/**'],
ignorePatterns: ['src/types/graphql/**', 'jest.config.js'],
extends: ['@summerfi/eslint-config/library.cjs'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
},
}
27 changes: 27 additions & 0 deletions packages/morpho-blue-subgraph/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { pathsToModuleNameMapper } = require('ts-jest')

/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
silent: true,
maxWorkers: 1,
testTimeout: 10000,
testEnvironment: 'node',
setupFilesAfterEnv: ['jest-expect-message'],
testPathIgnorePatterns: ['dist', 'node_modules'],
moduleNameMapper: pathsToModuleNameMapper({
'@summerfi/serverless-shared': ['<rootDir>/../../packages/serverless-shared/src/index.ts'],
'@summerfi/serverless-shared/*': ['<rootDir>/../../packages/serverless-shared/src/*'],
'@summerfi/triggers-shared': ['<rootDir>/../../packages/triggers-shared/src/index.ts'],
}),
transform: {
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.test.json',
},
],
},
}
4 changes: 3 additions & 1 deletion packages/morpho-blue-subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"watch": "tsc -w",
"test": "jest --passWithNoTests",
"build": "tsc -b -v",
"dev": "tsc -b -w",
"prebuild": "pnpm run generate-ts-types",
"generate-ts-types": "graphql-codegen --config graphql.config.yml",
"lint": "eslint .",
Expand All @@ -22,6 +23,7 @@
"@summerfi/eslint-config": "workspace:*",
"@summerfi/typescript-config": "workspace:*",
"@types/node": "^20.12.7",
"eslint": "^8.57.0"
"eslint": "^8.57.0",
"jest": "^29.7.0"
}
}
67 changes: 65 additions & 2 deletions packages/morpho-blue-subgraph/queries/intrest-rates.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
query GetInterestRates($marketId: String!, $marketIdBytes: ID!, $fromTimestamp: BigInt!, $toTimestamp: BigInt!) {
query GetInterestRates(
$marketId: String!,
$marketIdBytes: ID!,
$fromTimestamp: BigInt!,
$toTimestamp: BigInt!
$first: Int!,
$skip: Int!) {
market(id: $marketIdBytes) {
id
collateralToken {
Expand All @@ -10,7 +16,64 @@ query GetInterestRates($marketId: String!, $marketIdBytes: ID!, $fromTimestamp:
symbol
}
}
interestRates(where: { market: $marketId, timestamp_gte: $fromTimestamp, timestamp_lte: $toTimestamp }, orderBy: timestamp, orderDirection: asc) {
interestRates(
where: { market: $marketId, timestamp_gte: $fromTimestamp, timestamp_lte: $toTimestamp },
orderBy: timestamp,
orderDirection: asc,
first: $first,
skip: $skip) {
id
rate
timestamp
type
}
previousBorrowRate: interestRates(
where: { market: $marketId, timestamp_lt: $fromTimestamp, type: "borrow" },
orderBy: timestamp,
orderDirection: desc,
first: 1) {
id
rate
timestamp
type
}

previousLendRate: interestRates(
where: { market: $marketId, timestamp_lt: $fromTimestamp, type: "lend" }, interestRates(
where: { market: $marketId, timestamp_gte: $fromTimestamp, timestamp_lte: $toTimestamp },
orderBy: timestamp,
orderDirection: asc,
first: $first,
skip: $skip) {
id
rate
timestamp
type
}
previousBorrowRate: interestRates(
where: { market: $marketId, timestamp_lt: $fromTimestamp, type: "borrow" },
orderBy: timestamp,
orderDirection: desc,
first: 1) {
id
rate
timestamp
type
}

previousLendRate: interestRates(
where: { market: $marketId, timestamp_lt: $fromTimestamp, type: "lend" },
orderBy: timestamp,
orderDirection: desc,
first: 1) {
id
rate
timestamp
type
}
orderBy: timestamp,
orderDirection: desc,
first: 1) {
id
rate
timestamp
Expand Down
47 changes: 47 additions & 0 deletions packages/morpho-blue-subgraph/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { getMorphoBlueSubgraphClient, MorphoBlueSubgraphClient } from '.'
import { Logger } from '@aws-lambda-powertools/logger'
import { ChainId } from '@summerfi/serverless-shared'

const logger = new Logger({
serviceName: 'moorpho-blue-subgraph-tests',
environment: 'dev',
logLevel: 'debug',
})

function getTimestampInSeconds(unixTimestamp: number): number {
return Math.floor(unixTimestamp / 1000)
}

describe.skip('Exploration test MorphoBlue InterestRates', () => {
let client: MorphoBlueSubgraphClient
const wstETH_ETH_marketId: `0x${string}` =
'0xd0e50cdac92fe2172043f5e0c36532c6369d24947e40968f34a5e8819ca9ec5d'
const fromTimestamp_2024_04_01 = getTimestampInSeconds(new Date().setFullYear(2024, 3, 1))
const toTimestamp_2024_04_15 = getTimestampInSeconds(new Date().setFullYear(2024, 3, 15))

beforeAll(() => {
client = getMorphoBlueSubgraphClient({
chainId: ChainId.MAINNET,
urlBase: '', // set your urlBase here
logger,
})
})
it('should return arrays of interest rates', async () => {
logger.debug('Fetching interest rates', {
marketId: wstETH_ETH_marketId,
fromTimestamp: fromTimestamp_2024_04_01,
toTimestamp: toTimestamp_2024_04_15,
})

const result = await client.getInterestRate({
marketId: wstETH_ETH_marketId,
fromTimestamp: fromTimestamp_2024_04_01,
toTimestamp: toTimestamp_2024_04_15,
})

expect(result.debtToken.symbol).toBe('WETH')
expect(result.collateralToken.symbol).toBe('wstETH')

expect(result.interestRates.borrow[0].fromTimestamp).toBe(fromTimestamp_2024_04_01)
})
})
Loading

0 comments on commit f7113d2

Please sign in to comment.