-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: rewrite python functions in javascript
This fixes an issue with oversized builds which include node_modules inside the python functions despite the folder being excluded by the build process
- Loading branch information
Showing
6 changed files
with
85 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,3 +122,4 @@ dist | |
.vscode | ||
/.env.development.local.example | ||
/.env | ||
.vercel |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.