Skip to content

Commit

Permalink
Typescript second try (DefiLlama#92)
Browse files Browse the repository at this point in the history
* Typescript second try

* Typescript gh tests
  • Loading branch information
vrtnd authored Jul 18, 2022
1 parent 29614a0 commit afd3764
Show file tree
Hide file tree
Showing 8 changed files with 752 additions and 266 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": ["@babel/preset-typescript"],
"plugins": [
["@babel/plugin-transform-runtime"]
],
"sourceType": "unambiguous"
}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
for i in $(echo $RUN_FILES | tr -d '"[]' | tr "," "\n")
do
{
node ${{ github.workspace }}/src/adaptors/test.js ${{ github.workspace }}/${i} 2>&1 | tee output.txt
node ${{ github.workspace }}/.github/workflows/commentResult.js /home/runner/work/yield-server/yield-server/output.txt "${{ github.repository_owner }}" "${{ github.event.repository.name }}" "${{ github.event.number }}" ${i}
ts-node ${{ github.workspace }}/src/adaptors/test.js ${{ github.workspace }}/${i} 2>&1 | tee output.txt
ts-node ${{ github.workspace }}/.github/workflows/commentResult.js /home/runner/work/yield-server/yield-server/output.txt "${{ github.repository_owner }}" "${{ github.event.repository.name }}" "${{ github.event.number }}" ${i}
if grep -q "\-\-\-\- ERROR \-\-\-\-" output.txt; then
exit 1;
fi
Expand Down
966 changes: 707 additions & 259 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
},
"devDependencies": {
"@babel/core": "^7.17.8",
"@babel/plugin-transform-runtime": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/runtime": "^7.18.6",
"aws-sdk": "^2.987.0",
"babel-loader": "^8.2.3",
"electron": "^17.1.2",
Expand All @@ -45,6 +48,7 @@
"serverless": "^3.8.0",
"serverless-prune-plugin": "^2.0.1",
"serverless-webpack": "^5.6.1",
"ts-node": "^10.9.1",
"webpack": "^5.70.0"
}
}
13 changes: 11 additions & 2 deletions src/adaptors/venus/index.js → src/adaptors/venus/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
const utils = require('../utils');

const API_URL = 'https://api.venus.io/api/governance/venus';
const API_URL: string = 'https://api.venus.io/api/governance/venus';

interface Market {
address: string;
underlyingSymbol: string;
totalSupplyUsd: string;
totalBorrowsUsd: string;
supplyApy: string;
supplyVenusApy: string;
}

const getApy = async () => {
const markets = await utils.getData(API_URL);
const marketsData = markets.data.markets;
const marketsData: Array<Market> = markets.data.markets;

const pools = marketsData.map((market) => ({
pool: market.address,
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/triggerAdaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports.handler = async (event, context) => {
const main = async (body) => {
// run adaptor
console.log(body.adaptor);
const project = require(`../adaptors/${body.adaptor}/index.js`);
const project = require(`../adaptors/${body.adaptor}`);
let data = await project.apy();

// before storing the data into the db, we check for finite number values
Expand Down
18 changes: 18 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "es2015",
"target": "esnext",
"strict": false,
"types": ["node"],
"resolveJsonModule": true,
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"allowJs": true,
"lib": ["ES2020.Promise"]
},
"include": ["./src/**/*"],
}
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
module: {
rules: [
{
test: /\.js$/,
test: /\.(ts|js)$/,
use: { loader: 'babel-loader' },
include: path.resolve(__dirname, 'src'),
exclude: /node_modules/,
Expand All @@ -17,7 +17,7 @@ module.exports = {
},
resolve: {
mainFields: ['main'],
extensions: ['.js', '.json'],
extensions: ['.js', '.ts', '.json'],
alias: {
'bignumber.js$': 'bignumber.js/bignumber.js',
'node-fetch$': 'node-fetch/lib/index.js',
Expand Down

0 comments on commit afd3764

Please sign in to comment.