Skip to content

Commit

Permalink
Merge pull request #92 from Synthetixio/dev
Browse files Browse the repository at this point in the history
promote dev to master
  • Loading branch information
drptbl authored May 23, 2024
2 parents ca64f60 + f618a5e commit f2d06d8
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/audit_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29

- name: Audit dependencies
run: audit-ci --critical --report-type full
Expand All @@ -36,7 +36,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29

- name: Set pnpm cache directory
run: pnpm config set store-dir .pnpm-store
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29

- name: Initialize CodeQL
uses: github/codeql-action/init@99c9897648dded3fe63d6f328c46089dd57735ca
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ Docker with latest docker compose is mandatory.

## Development (auto-reload included)

- `pnpm dev`
- `pnpm dev` (use this for dev)

## Production

- `pnpm start`
- `pnpm start` (this is not intended to work on localhost)

## Release

- push changes to dev
- open PR from dev to main (promote dev to main)
- merge PR
- wait for API to be automatically deployed to production
220 changes: 203 additions & 17 deletions src/routes/v3/base/sc-pool-apy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,112 @@ setInterval(fetchDataFromPostgres, cacheTime < 30000 ? 30000 : cacheTime);
* description: Returns current APY for Spartan Council Pool on Base.
* responses:
* 200:
* description: Successful response.
* content:
* application/json:
* schema:
* type: object
* properties:
* aprPnl:
* type: number
* example: 0.13656878060168257
* aprRewards:
* type: number
* example: 0.33047981877022653
* aprCombined:
* type: number
* example: 0.46704859937190907
* description: Successful response.
* content:
* application/json:
* schema:
* type: object
* properties:
* timestamp:
* type: string
* format: date-time
* example: '2024-05-23T14:00:00.000Z'
* poolId:
* type: integer
* example: 1
* collateralType:
* type: string
* example: '0xc74ea762cf06c9151ce074e6a569a5945b6302e7'
* collateralValue:
* type: number
* example: 23075347.609146226
* debtAmount:
* type: number
* example: -38219.337186378914
* hourlyIssuance:
* type: number
* example: 500
* hourlyPnl:
* type: number
* example: 12954.05122107834
* cumulativePnl:
* type: number
* example: 43985.56313904079
* cumulativeIssuance:
* type: number
* example: 5766.225952661871
* rewardsUSD:
* type: number
* example: 325.5208333342384
* hourlyPnlPct:
* type: number
* example: 0.0005613805451816391
* hourlyRewardsPct:
* type: number
* example: 0.00001410686585736259
* apr24h:
* type: number
* example: 0.45592422360763046
* apy24h:
* type: number
* example: 0.57761207594964
* apr7d:
* type: number
* example: 0.3960274742990924
* apy7d:
* type: number
* example: 0.4858968400315962
* apr28d:
* type: number
* example: 0.4384330174128003
* apy28d:
* type: number
* example: 0.550259050183527
* apr24hPnl:
* type: number
* example: 0.33291916703302443
* apy24hPnl:
* type: number
* example: 0.39502570410440424
* apr7dPnl:
* type: number
* example: 0.19503277851939582
* apy7dPnl:
* type: number
* example: 0.21534818462340294
* apr28dPnl:
* type: number
* example: 0.13876757264702413
* apy28dPnl:
* type: number
* example: 0.14885578045932418
* apr24hRewards:
* type: number
* example: 0.12300505657460604
* apy24hRewards:
* type: number
* example: 0.13088916273804313
* apr7dRewards:
* type: number
* example: 0.20099469577969659
* apy7dRewards:
* type: number
* example: 0.22261546761516451
* apr28dRewards:
* type: number
* example: 0.29966544476577617
* apy28dRewards:
* type: number
* example: 0.34940036452177975
* aprPnl:
* type: number
* example: 0.19503277851939582
* aprRewards:
* type: number
* example: 0.20099469577969659
* aprCombined:
* type: number
* example: 0.3960274742990924
* 401:
* description: Unauthorized.
* 403:
Expand Down Expand Up @@ -72,15 +163,110 @@ module.exports = router;
async function fetchDataFromPostgres() {
log.debug('[v3BaseSCPoolAPY] Fetching data from postgres..');
const queryResult = await postgresClient.query(
'select ts, pool_id, collateral_type, apr_7d, apr_7d_pnl, apr_7d_rewards from base_mainnet.fct_core_apr WHERE pool_id = 1 order by ts desc limit 1;',
'select ts, pool_id, collateral_type, collateral_value, debt, hourly_issuance, hourly_pnl, cumulative_pnl, cumulative_issuance, rewards_usd, hourly_pnl_pct, hourly_rewards_pct, apr_24h, apy_24h, apr_7d, apy_7d, apr_28d, apy_28d, apr_24h_pnl, apy_24h_pnl, apr_7d_pnl, apy_7d_pnl, apr_28d_pnl, apy_28d_pnl, apr_24h_rewards, apy_24h_rewards, apr_7d_rewards, apy_7d_rewards, apr_28d_rewards, apy_28d_rewards from base_mainnet.fct_core_apr WHERE pool_id = 1 order by ts desc limit 1;',
);

const { apr_7d, apr_7d_pnl, apr_7d_rewards } = queryResult.rows[0];
const {
ts,
pool_id,
collateral_type,
collateral_value,
debt,
hourly_issuance,
hourly_pnl,
cumulative_pnl,
cumulative_issuance,
rewards_usd,
hourly_pnl_pct,
hourly_rewards_pct,
apr_24h,
apy_24h,
apr_7d,
apy_7d,
apr_28d,
apy_28d,
apr_24h_pnl,
apy_24h_pnl,
apr_7d_pnl,
apy_7d_pnl,
apr_28d_pnl,
apy_28d_pnl,
apr_24h_rewards,
apy_24h_rewards,
apr_7d_rewards,
apy_7d_rewards,
apr_28d_rewards,
apy_28d_rewards,
} = queryResult.rows[0];

const timestamp = ts;
const poolId = pool_id;
const collateralType = collateral_type;
const collateralValue = parseFloat(collateral_value);
const debtAmount = parseFloat(debt);
const hourlyIssuance = parseFloat(hourly_issuance);
const hourlyPnl = parseFloat(hourly_pnl);
const cumulativePnl = parseFloat(cumulative_pnl);
const cumulativeIssuance = parseFloat(cumulative_issuance);
const rewardsUSD = parseFloat(rewards_usd);
const hourlyPnlPct = parseFloat(hourly_pnl_pct);
const hourlyRewardsPct = parseFloat(hourly_rewards_pct);
const apr24h = parseFloat(apr_24h);
const apy24h = parseFloat(apy_24h);
const apr7d = parseFloat(apr_7d);
const apy7d = parseFloat(apy_7d);
const apr28d = parseFloat(apr_28d);
const apy28d = parseFloat(apy_28d);
const apr24hPnl = parseFloat(apr_24h_pnl);
const apy24hPnl = parseFloat(apy_24h_pnl);
const apr7dPnl = parseFloat(apr_7d_pnl);
const apy7dPnl = parseFloat(apy_7d_pnl);
const apr28dPnl = parseFloat(apr_28d_pnl);
const apy28dPnl = parseFloat(apy_28d_pnl);
const apr24hRewards = parseFloat(apr_24h_rewards);
const apy24hRewards = parseFloat(apy_24h_rewards);
const apr7dRewards = parseFloat(apr_7d_rewards);
const apy7dRewards = parseFloat(apy_7d_rewards);
const apr28dRewards = parseFloat(apr_28d_rewards);
const apy28dRewards = parseFloat(apy_28d_rewards);

// old code - left for backward compatiblity
const aprPnl = parseFloat(apr_7d_pnl);
const aprRewards = parseFloat(apr_7d_rewards);
const aprCombined = parseFloat(apr_7d);

const responseData = {
timestamp,
poolId,
collateralType,
collateralValue,
debtAmount,
hourlyIssuance,
hourlyPnl,
cumulativePnl,
cumulativeIssuance,
rewardsUSD,
hourlyPnlPct,
hourlyRewardsPct,
apr24h,
apy24h,
apr7d,
apy7d,
apr28d,
apy28d,
apr24hPnl,
apy24hPnl,
apr7dPnl,
apy7dPnl,
apr28dPnl,
apy28dPnl,
apr24hRewards,
apy24hRewards,
apr7dRewards,
apy7dRewards,
apr28dRewards,
apy28dRewards,
// old code - left for backward compatiblity
aprPnl,
aprRewards,
aprCombined,
Expand Down

0 comments on commit f2d06d8

Please sign in to comment.