Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
asyx21 committed Nov 22, 2023
2 parents 557c19f + 3ddbda4 commit 90689f8
Show file tree
Hide file tree
Showing 645 changed files with 169,050 additions and 13,132 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ jobs:
OPTIMISM_RPC: ${{ secrets.OPTIMISM_RPC }}
AVAX_RPC: ${{ secrets.AVAX_RPC }}
ARBITRUM_RPC: ${{ secrets.ARBITRUM_RPC }}
BASE_RPC: ${{ secrets.BASE_RPC }}
TVL_SPIKE_WEBHOOK: ${{ secrets.TVL_SPIKE_WEBHOOK }}
NEW_YIELDS_WEBHOOK: ${{ secrets.NEW_YIELDS_WEBHOOK }}
STALE_PROJECTS_WEBHOOK: ${{ secrets.STALE_PROJECTS_WEBHOOK }}
ZEROX_API: ${{ secrets.ZEROX_API }}
SMARDEX_SUBGRAPH_API_KEY: ${{ secrets.SMARDEX_SUBGRAPH_API_KEY }}
VENDOR_FINANCE: ${{ secrets.VENDOR_FINANCE }}
3 changes: 3 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ module.exports = {
OPTIMISM_RPC: process.env.OPTIMISM_RPC,
AVAX_RPC: process.env.AVAX_RPC,
ARBITRUM_RPC: process.env.ARBITRUM_RPC,
BASE_RPC: process.env.BASE_RPC,
TVL_SPIKE_WEBHOOK: process.env.TVL_SPIKE_WEBHOOK,
NEW_YIELDS_WEBHOOK: process.env.NEW_YIELDS_WEBHOOK,
STALE_PROJECTS_WEBHOOK: process.env.STALE_PROJECTS_WEBHOOK,
ZEROX_API: process.env.ZEROX_API,
SMARDEX_SUBGRAPH_API_KEY: process.env.SMARDEX_SUBGRAPH_API_KEY,
VENDOR_FINANCE: process.env.VENDOR_FINANCE,
// DB
DATABASE_URL: process.env.DATABASE_URL,
};
12 changes: 12 additions & 0 deletions migrations/lsd.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE IF NOT EXISTS lsd (
timestamp timestamp NOT NULL,
name text NOT NULL,
symbol text NOT NULL,
address text NOT NULL,
type text,
"expectedRate" numeric,
"marketRate" numeric,
"ethPeg" numeric
);

CREATE INDEX IF NOT EXISTS lsd_address_timestamp_idx ON lsd (address, timestamp DESC);
4,355 changes: 4,079 additions & 276 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,38 @@
"deploy": "export NODE_ENV=prod && npm run deploy:env",
"build": "sls package",
"test": "jest",
"migrate": "node-pg-migrate"
"migrate": "node-pg-migrate",
"start:api": "node src/api/server"
},
"author": "",
"license": "ISC",
"dependencies": {
"@balancer-labs/sdk": "1.1.4-beta.17",
"@defillama/sdk": "^2.3.126",
"@defillama/sdk3": "npm:@defillama/sdk@^3.0.55",
"@defillama/sdk4": "npm:@defillama/sdk@^4.0.64",
"@types/jest": "^28.1.6",
"@uniswap/sdk-core": "^3.0.1",
"@uniswap/smart-order-router": "^2.8.0",
"async-retry": "^1.3.3",
"aws-sdk": "^2.1389.0",
"axios": "^0.27.2",
"bignumber.js": "^9.0.2",
"bignumber.js": "^9.1.1",
"csv-writer": "^1.6.0",
"date-fns": "^2.23.0",
"dotenv": "^10.0.0",
"express": "^4.18.2",
"graphql": "^15.5.1",
"graphql-request": "^3.5.0",
"helmet": "^7.0.0",
"lambert-w-function": "^3.0.0",
"limiter": "^2.1.0",
"lodash": "^4.17.21",
"morgan": "^1.10.0",
"node-fetch": "^2.6.1",
"pg-promise": "^10.11.1",
"simple-statistics": "^7.7.5",
"starknet": "^4.22.0",
"superagent": "^6.1.0",
"validator": "^13.9.0",
"web3": "^1.4.0"
Expand All @@ -41,7 +49,6 @@
"@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",
"encoding": "^0.1.13",
Expand All @@ -55,6 +62,7 @@
"eslint-plugin-react": "^7.22.0",
"jest": "^28.1.3",
"node-pg-migrate": "^6.2.2",
"nodemon": "^2.0.22",
"pg": "^8.8.0",
"pg-native": "^3.0.1",
"prettier": "^2.2.1",
Expand Down
10 changes: 2 additions & 8 deletions scripts/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ const superagent = require('superagent');

const { confirm } = require('./confirm');
const { connect } = require('../src/utils/dbConnection');
const {
buildInsertConfigQuery,
} = require('../src/controllers/configController');
const { buildInsertConfigQuery } = require('../src/queries/config');

(async () => {
await confirm(
Expand All @@ -16,11 +14,7 @@ const {
);

const uuids = JSON.parse(fs.readFileSync('./created_uuids.json'));
const urls = (
await superagent.get(
'https://1rwmj4tky9.execute-api.eu-central-1.amazonaws.com/urls'
)
).body;
const urls = (await superagent.get('https://yields.llama.fi/url')).body;
let data = JSON.parse(fs.readFileSync('./yield_snapshot_last.json'));

data = data.map((p) => ({
Expand Down
2 changes: 1 addition & 1 deletion scripts/createMedian.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const ss = require('simple-statistics');

const { confirm } = require('./confirm');
const exclude = require('../src/utils/exclude');
const { insertMedian } = require('../src/controllers/medianController');
const { insertMedian } = require('../src/queries/median');

(async () => {
await confirm(
Expand Down
2 changes: 1 addition & 1 deletion scripts/createStat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs');
const ss = require('simple-statistics');

const { confirm } = require('./confirm');
const { insertStat } = require('../src/controllers/statController');
const { insertStat } = require('../src/queries/stat');

(async () => {
await confirm(
Expand Down
2 changes: 1 addition & 1 deletion scripts/createYield.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('fs');

const { confirm } = require('./confirm');
const { connect } = require('../src/utils/dbConnection');
const { buildInsertYieldQuery } = require('../src/controllers/yieldController');
const { buildInsertYieldQuery } = require('../src/queries/yield');

(async () => {
await confirm(
Expand Down
4 changes: 1 addition & 3 deletions scripts/updatePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const fs = require('fs');

const { confirm } = require('./confirm');
const { pgp, connect } = require('../src/utils/dbConnection');
const {
tableName: configTableName,
} = require('../src/controllers/configController');
const { tableName: configTableName } = require('../src/queries/config');

(async () => {
await confirm(
Expand Down
157 changes: 19 additions & 138 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ provider:
tracing:
apiGateway: true
lambda: true
memorySize: 512
memorySize: 1024
iam:
role:
statements:
Expand All @@ -30,29 +30,10 @@ provider:
Resource: '*'

environment:
# for api handlers
APIG_URL:
{
'Fn::Join':
[
'',
[
'https://',
{ Ref: 'HttpApi' },
'.execute-api.',
{ Ref: 'AWS::Region' },
'.',
{ Ref: 'AWS::URLSuffix' },
],
],
}
BUCKET_DATA: { Ref: BucketData }
DATABASE_URL: ${file(./env.js):DATABASE_URL}
ZEROX_API: ${file(./env.js):ZEROX_API}

httpApi:
metrics: true

functions:
# ---------- TRIGGER HANDLERS
# --- top-lvl-entrypoint
Expand Down Expand Up @@ -90,14 +71,18 @@ functions:
OPTIMISM_RPC: ${file(./env.js):OPTIMISM_RPC}
AVAX_RPC: ${file(./env.js):AVAX_RPC}
ARBITRUM_RPC: ${file(./env.js):ARBITRUM_RPC}
BASE_RPC: ${file(./env.js):BASE_RPC}
TVL_SPIKE_WEBHOOK: ${file(./env.js):TVL_SPIKE_WEBHOOK}
NEW_YIELDS_WEBHOOK: ${file(./env.js):NEW_YIELDS_WEBHOOK}
SMARDEX_SUBGRAPH_API_KEY: ${file(./env.js):SMARDEX_SUBGRAPH_API_KEY}
VENDOR_FINANCE: ${file(./env.js):VENDOR_FINANCE}

# --- data enrichment
triggerEnrichment:
handler: src/handlers/triggerEnrichment.handler
description: Lambda which runs enrichment process
timeout: 600
memorySize: 1024
events:
# every hour at 16 past
- schedule: cron(16 * * * ? *)
Expand Down Expand Up @@ -157,127 +142,23 @@ functions:
# 30min prior midnight
- schedule: cron(30 23 * * ? *)

# ---------- GET HANDLERS
getPoolsEnriched:
handler: src/handlers/getPoolsEnriched.handler
description: Lambda for retrieving the latest enriched data for each unique pool
timeout: 20
events:
- httpApi:
method: get
path: /poolsEnriched
- httpApi:
method: get
path: /pools

# includes old pool values
getPoolsEnrichedOld:
handler: src/handlers/getPoolsEnrichedOld.handler
description: Lambda for retrieving the latest enriched data for each unique pool (includes old pool values)
timeout: 20
events:
- httpApi:
method: get
path: /poolsOld

getChart:
handler: src/handlers/getChart.handler
description: Lambda for retrieving chart data for a particular pool
timeout: 20
events:
- httpApi:
method: get
path: /chart/{configID}

getMedian:
handler: src/handlers/getMedian.handler
description: Lambda for retrieving daily median apy's
timeout: 20
events:
- httpApi:
method: get
path: /median

getUrl:
handler: src/handlers/getUrl.handler
description: Lambda for retrieving project url's
timeout: 20
events:
- httpApi:
method: get
path: /url

getDistinctID:
handler: src/handlers/getDistinctID.handler
description: Lambda for retrieving unique pool id's
timeout: 20
events:
- httpApi:
method: get
path: /distinctID

getLendBorrow:
handler: src/handlers/getLendBorrow.handler
description: Lambda for retrieving lending + borrow data
timeout: 20
events:
- httpApi:
method: get
path: /lendBorrow

getHistoryLendBorrow:
handler: src/handlers/getHistoryLendBorrow.handler
description: Lambda for retrieving chart data for a particular pool
timeout: 20
events:
- httpApi:
method: get
path: /chartLendBorrow/{configID}

getConfigPool:
handler: src/handlers/getConfigPool.handler
description: Lambda for retrieving config data of configIDs
timeout: 20
events:
- httpApi:
method: get
path: /configPool/{configID}

getPerp:
handler: src/handlers/getPerp.handler
description: Lambda for retrieving latest perp data
timeout: 20
events:
- httpApi:
method: get
path: /perps

getLSDRates:
handler: src/handlers/getLSDRates.handler
description: Lambda for retrieving ETH LSD Rates
timeout: 30
events:
- httpApi:
method: get
path: /lsdRates

getLSDRatesNew:
handler: src/handlers/getLSDRatesNew.handler
description: Lambda for retrieving ETH LSD Rates
timeout: 30
triggerLSDRates:
handler: src/handlers/triggerLSDRates.handler
description: Lambda which triggers lsd market rate and expected rate
timeout: 300
events:
- httpApi:
method: get
path: /lsdRatesNew
# every new hour
- schedule: cron(0 * * * ? *)

getMedianProject:
handler: src/handlers/getMedianProject.handler
description: Lambda for retrieving a projects median apy history
timeout: 20
triggerProtocolNameChange:
handler: src/handlers/triggerProtocolNameChange.handler
description: Lambda which checks for protocol renames
timeout: 300
events:
- httpApi:
method: get
path: /medianProject/{project}
# every hour 40min past
- schedule: cron(40 * * * ? *)
environment:
STALE_PROJECTS_WEBHOOK: ${file(./env.js):STALE_PROJECTS_WEBHOOK}

resources:
Resources:
Expand Down
41 changes: 41 additions & 0 deletions src/adaptors/1inch-network/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const utils = require('../utils');

const ADDRESSES = {
ethereum: {
'1INCH': '0x111111111117dc0aa78b770fa6a738034120c302',
dst1INCH: '0x9a0c8ff858d273f57072d714bca7411d717501d7',
},
};

const main = async () => {
const data = await utils.getData(
'https://data-distributor.1inch.io/resolversMetrics'
);
const result = Object.values(data)[0].map((pool) => {
const apyReward = Number(pool.apyBase);

return {
pool: `1INCH-${pool.resolver_address}-${pool.chain}`.toLowerCase(),
chain: utils.formatChain(pool.chain),
project: '1inch-network',
symbol: '1INCH',
poolMeta: pool.pool,
tvlUsd: Number(pool.tvlUsd),
apyReward,
url: `https://app.1inch.io/#/1/earn/delegate/${pool.resolver_address}`,
rewardTokens:
apyReward > 0 ? [ADDRESSES[pool.chain.toLowerCase()]['1INCH']] : [],
underlyingTokens: [
ADDRESSES[pool.chain.toLowerCase()]['1INCH'],
ADDRESSES[pool.chain.toLowerCase()]['dst1INCH'],
],
};
});
return result;
};

module.exports = {
timetravel: false,
apy: main,
// url: "https://app.1inch.io/#/1/dao/staking",
};
Loading

0 comments on commit 90689f8

Please sign in to comment.