Skip to content

Commit

Permalink
add cfg token functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JP Angelle committed Dec 11, 2023
1 parent 76b1b9e commit b7d7224
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions functions/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
CENTRIFUGE_SUBGRAPH_URL=
SUBSCAN_API_KEY=
14 changes: 14 additions & 0 deletions functions/src/getCirculatingSupply.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from 'axios'

export default async function getCirculatingSupply(req, res) {
const { data } = await axios.get('https://centrifuge.api.subscan.io/api/scan/token', {
headers: {
'X-API-Key': process.env.SUBSCAN_API_KEY,
},
})

const availableBalance = data.data.detail.CFG.available_balance
const circulatingSupply = availableBalance.substring(0, availableBalance.length - 18)

res.send(circulatingSupply)
}
14 changes: 14 additions & 0 deletions functions/src/getTotalIssuance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ApiPromise, WsProvider } from '@polkadot/api'

export default async function getTotalIssuance(req, res) {
const CENTRIFUGE_MAINNET_WSS_RPC = 'wss://fullnode.centrifuge.io'

const wsProvider = new WsProvider(CENTRIFUGE_MAINNET_WSS_RPC)
const api = await ApiPromise.create({ provider: wsProvider })

const totalIssuanceRaw = await api.query.balances.totalIssuance()
const totalIssuance = totalIssuanceRaw.toString()
const integer = totalIssuance.substring(0, totalIssuance.length - 18)

res.send(integer.toString())
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
"@centrifuge/centrifuge-react": "0.1.0",
"@centrifuge/fabric": "1.3.2",
"@polkadot/util-crypto": "^11",
"axios": "^1.6.2",
"babel-plugin-styled-components": "^2.0.7",
"cheerio": "^1.0.0-rc.12",
"embla-carousel-react": "^7.0.3",
"express": "^4.18.2",
"focus-trap-react": "^10.0.0",
"gatsby": "^4.23.1",
"gatsby-plugin-google-gtag": "^4.24.0",
Expand Down
18 changes: 16 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5213,6 +5213,15 @@ axios@^0.21.1:
dependencies:
follow-redirects "^1.14.0"

axios@^1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.2.tgz#de67d42c755b571d3e698df1b6504cde9b0ee9f2"
integrity sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==
dependencies:
follow-redirects "^1.15.0"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axobject-query@^3.1.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-3.2.1.tgz#39c378a6e3b06ca679f29138151e45b2b32da62a"
Expand Down Expand Up @@ -7725,7 +7734,7 @@ express-http-proxy@^1.6.3:
es6-promise "^4.1.1"
raw-body "^2.3.0"

express@^4.16.4, express@^4.17.1:
express@^4.16.4, express@^4.17.1, express@^4.18.2:
version "4.18.2"
resolved "https://registry.yarnpkg.com/express/-/express-4.18.2.tgz#3fabe08296e930c796c19e3c516979386ba9fd59"
integrity sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==
Expand Down Expand Up @@ -8039,7 +8048,7 @@ focus-trap@^7.5.3:
dependencies:
tabbable "^6.2.0"

follow-redirects@^1.14.0:
follow-redirects@^1.14.0, follow-redirects@^1.15.0:
version "1.15.3"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.3.tgz#fe2f3ef2690afce7e82ed0b44db08165b207123a"
integrity sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==
Expand Down Expand Up @@ -12371,6 +12380,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/proxy-compare/-/proxy-compare-2.5.1.tgz#17818e33d1653fbac8c2ec31406bce8a2966f600"
integrity sha512-oyfc0Tx87Cpwva5ZXezSp5V9vht1c7dZBhvuV/y3ctkgMVUmiAGDVeeB0dKhGSyT0v1ZTEQYpe/RXlBVBNuCLA==

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

pseudomap@^1.0.1, pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
Expand Down

0 comments on commit b7d7224

Please sign in to comment.