Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: rewrite python functions in javascript #1630

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ dist
.vscode
/.env.development.local.example
/.env
.vercel
166 changes: 0 additions & 166 deletions api/health.py

This file was deleted.

4 changes: 0 additions & 4 deletions api/requirements.txt

This file was deleted.

81 changes: 81 additions & 0 deletions api/supply_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const KINT_SUBSCAN_URL = 'https://kintsugi.api.subscan.io/'
const INTR_SUBSCAN_URL = 'https://interlay.api.subscan.io/'

const KINT_API_KEY = process.env.SUBSCAN_API_KEY
const INTR_API_KEY = process.env.INTR_SUBSCAN_API_KEY

function fromDecimals (val, decimals) {
return val / Math.pow(10, decimals)
}

async function subscanRequest (url, method = 'GET', json = null) {
const headers = {
'Content-Type': 'application/json',
'X-API-KEY': url.startsWith(INTR_SUBSCAN_URL) ? INTR_API_KEY : KINT_API_KEY
}

const options = { method, headers }
if (json) {
options.body = JSON.stringify(json)
}

const response = await fetch(url, options)
return await response.json()
}

export default async function (request, response) {
if (request.method !== 'GET') {
return response.status(400).send('Bad Request')
}
const path = request.url.split('?')[0]
switch (path) {
case '/supply/intr-total-supply': {
const INTR_SUPPLY = 1_000_000_000
return response
.status(200)
.send(INTR_SUPPLY.toString())
}
case '/supply/kint-total-supply': {
const KINT_SUPPLY = 10_000_000
return response
.status(200)
.send(KINT_SUPPLY.toString())
}
case '/supply/intr-circ-supply': {
const unvestedSupply = fromDecimals(parseInt((await subscanRequest(INTR_SUBSCAN_URL + 'api/scan/token')).data.detail.INTR.available_balance), 10)
const systemAccountsSupply = (await subscanRequest(INTR_SUBSCAN_URL + 'api/scan/accounts', 'POST',
{ filter: 'system', row: 25, page: 0 })).data.list
.reduce((acc, curr) => acc + parseFloat(curr.balance), 0)
const circulatingSupply = unvestedSupply - systemAccountsSupply

return response
.status(200)
.send(circulatingSupply.toString())
}
case '/supply/kint-circ-supply': {
const kintUnvestedSupply = fromDecimals(parseInt((await subscanRequest(KINT_SUBSCAN_URL + 'api/scan/token')).data.detail.KINT.available_balance), 12)
const kintSystemAccountsSupply = (await subscanRequest(KINT_SUBSCAN_URL + 'api/scan/accounts', 'POST',
{ filter: 'system', row: 25, page: 0 })).data.list
.reduce((acc, curr) => acc + parseFloat(curr.balance), 0)
const kintCirculatingSupply = kintUnvestedSupply - kintSystemAccountsSupply

return response
.status(200)
.send(kintCirculatingSupply.toString())
}
case '/supply/ibtc-supply': {
const ibtcSupply = fromDecimals(parseInt((await subscanRequest(INTR_SUBSCAN_URL + 'api/scan/token')).data.detail.IBTC.available_balance), 10)
return response
.status(200)
.send(ibtcSupply.toString())
}
case '/supply/kbtc-supply': {
const kbtcSupply = fromDecimals(parseInt((await subscanRequest(KINT_SUBSCAN_URL + 'api/scan/token')).data.detail.KBTC.available_balance), 8)
return response
.status(200)
.send(kbtcSupply.toString())
}
default:
response.status(404).send('Not Found')
}
};
125 changes: 0 additions & 125 deletions api/supply_info.py

This file was deleted.

Loading
Loading