@talismn/token-rates 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,10 @@ export declare const SUPPORTED_CURRENCIES: {
|
|
12
12
|
readonly name: "Polkadot";
|
13
13
|
readonly symbol: "D";
|
14
14
|
};
|
15
|
+
readonly tao: {
|
16
|
+
readonly name: "Bittensor";
|
17
|
+
readonly symbol: "τ";
|
18
|
+
};
|
15
19
|
readonly usd: {
|
16
20
|
readonly name: "US Dollar";
|
17
21
|
readonly symbol: "$";
|
@@ -33,6 +33,10 @@ const SUPPORTED_CURRENCIES = {
|
|
33
33
|
name: "Polkadot",
|
34
34
|
symbol: "D"
|
35
35
|
},
|
36
|
+
tao: {
|
37
|
+
name: "Bittensor",
|
38
|
+
symbol: "τ"
|
39
|
+
},
|
36
40
|
usd: {
|
37
41
|
name: "US Dollar",
|
38
42
|
symbol: "$"
|
@@ -108,6 +112,7 @@ const newTokenRates = () => ({
|
|
108
112
|
btc: null,
|
109
113
|
eth: null,
|
110
114
|
dot: null,
|
115
|
+
tao: null,
|
111
116
|
usd: null,
|
112
117
|
cny: null,
|
113
118
|
eur: null,
|
@@ -184,14 +189,47 @@ async function fetchTokenRates(tokens, currencyIds = ALL_CURRENCY_IDS, config =
|
|
184
189
|
|
185
190
|
// skip network request if there is nothing for us to fetch
|
186
191
|
if (coingeckoIds.length < 1) return {};
|
192
|
+
|
193
|
+
// If `currencyIds` includes `tao`, we need to always fetch the `bittensor` coingeckoId and the `usd` currency,
|
194
|
+
// we can use these to calculate the currency rate for TAO relative to all other tokens.
|
195
|
+
//
|
196
|
+
// We support showing balances in TAO just like we support BTC/ETH/DOT, but coingecko doesn't support TAO as a vs currency rate.
|
197
|
+
// We can macgyver our own TOKEN<>TAO rate by combining the TOKEN<>USD data with the TAO<>USD data.
|
198
|
+
const hasVsTao = currencyIds.includes("tao");
|
199
|
+
const [effectiveCoingeckoIds, effectiveCurrencyIds] = hasVsTao ? [[...new Set(coingeckoIds).add("bittensor")], [...new Set(
|
200
|
+
// don't request `tao` from coingecko (we calculate it from `usd`)
|
201
|
+
currencyIds.filter(c => c !== "tao"))
|
202
|
+
// always include `usd` (so we can calculate `tao`)
|
203
|
+
.add("usd")]] : [coingeckoIds, currencyIds];
|
187
204
|
const response = await fetch(`${config.apiUrl}/token-rates`, {
|
188
205
|
method: "POST",
|
189
206
|
body: JSON.stringify({
|
190
|
-
coingeckoIds,
|
191
|
-
currencyIds
|
207
|
+
coingeckoIds: effectiveCoingeckoIds,
|
208
|
+
currencyIds: effectiveCurrencyIds
|
192
209
|
})
|
193
210
|
});
|
194
211
|
const rawTokenRates = await response.json();
|
212
|
+
if (hasVsTao) {
|
213
|
+
// calculate the TAO<>USD rate
|
214
|
+
const effectiveTaoIndex = effectiveCoingeckoIds.indexOf("bittensor");
|
215
|
+
const effectiveUsdIndex = effectiveCurrencyIds.indexOf("usd");
|
216
|
+
const taoUsdRate = rawTokenRates[effectiveTaoIndex]?.[effectiveUsdIndex]?.[0];
|
217
|
+
const taoUsdChange24h = rawTokenRates[effectiveTaoIndex]?.[effectiveUsdIndex]?.[2];
|
218
|
+
|
219
|
+
// insert TOKEN<>TAO rate (calculated based on TAO<>USD rate and TOKEN<>USD rate) into each TOKEN
|
220
|
+
const taoIndex = currencyIds.indexOf("tao");
|
221
|
+
rawTokenRates.forEach(rates => {
|
222
|
+
// get TOKEN<>USD rate
|
223
|
+
const tokenUsdRate = rates?.[effectiveUsdIndex]?.[0];
|
224
|
+
// calculate TOKEN<>TAO rate
|
225
|
+
const tokenTaoRate = typeof tokenUsdRate === "number" && typeof taoUsdRate === "number" && taoUsdRate !== 0 ? tokenUsdRate / taoUsdRate : null;
|
226
|
+
const tokenUsdChange24h = rates?.[effectiveUsdIndex]?.[2];
|
227
|
+
const tokenTaoChange24h = typeof taoUsdChange24h === "number" && typeof tokenUsdChange24h === "number" ? (1 + tokenUsdChange24h) / (1 + taoUsdChange24h) - 1 : null;
|
228
|
+
|
229
|
+
// insert at the correct location (based on the index of `tao` in `currencyIds`)
|
230
|
+
rates?.splice(taoIndex, 0, [tokenTaoRate, null, tokenTaoChange24h]);
|
231
|
+
});
|
232
|
+
}
|
195
233
|
const tokenRates = parseTokenRatesFromApi(rawTokenRates, coingeckoIds, currencyIds);
|
196
234
|
|
197
235
|
// build a TokenRatesList from the token prices result
|
@@ -33,6 +33,10 @@ const SUPPORTED_CURRENCIES = {
|
|
33
33
|
name: "Polkadot",
|
34
34
|
symbol: "D"
|
35
35
|
},
|
36
|
+
tao: {
|
37
|
+
name: "Bittensor",
|
38
|
+
symbol: "τ"
|
39
|
+
},
|
36
40
|
usd: {
|
37
41
|
name: "US Dollar",
|
38
42
|
symbol: "$"
|
@@ -108,6 +112,7 @@ const newTokenRates = () => ({
|
|
108
112
|
btc: null,
|
109
113
|
eth: null,
|
110
114
|
dot: null,
|
115
|
+
tao: null,
|
111
116
|
usd: null,
|
112
117
|
cny: null,
|
113
118
|
eur: null,
|
@@ -184,14 +189,47 @@ async function fetchTokenRates(tokens, currencyIds = ALL_CURRENCY_IDS, config =
|
|
184
189
|
|
185
190
|
// skip network request if there is nothing for us to fetch
|
186
191
|
if (coingeckoIds.length < 1) return {};
|
192
|
+
|
193
|
+
// If `currencyIds` includes `tao`, we need to always fetch the `bittensor` coingeckoId and the `usd` currency,
|
194
|
+
// we can use these to calculate the currency rate for TAO relative to all other tokens.
|
195
|
+
//
|
196
|
+
// We support showing balances in TAO just like we support BTC/ETH/DOT, but coingecko doesn't support TAO as a vs currency rate.
|
197
|
+
// We can macgyver our own TOKEN<>TAO rate by combining the TOKEN<>USD data with the TAO<>USD data.
|
198
|
+
const hasVsTao = currencyIds.includes("tao");
|
199
|
+
const [effectiveCoingeckoIds, effectiveCurrencyIds] = hasVsTao ? [[...new Set(coingeckoIds).add("bittensor")], [...new Set(
|
200
|
+
// don't request `tao` from coingecko (we calculate it from `usd`)
|
201
|
+
currencyIds.filter(c => c !== "tao"))
|
202
|
+
// always include `usd` (so we can calculate `tao`)
|
203
|
+
.add("usd")]] : [coingeckoIds, currencyIds];
|
187
204
|
const response = await fetch(`${config.apiUrl}/token-rates`, {
|
188
205
|
method: "POST",
|
189
206
|
body: JSON.stringify({
|
190
|
-
coingeckoIds,
|
191
|
-
currencyIds
|
207
|
+
coingeckoIds: effectiveCoingeckoIds,
|
208
|
+
currencyIds: effectiveCurrencyIds
|
192
209
|
})
|
193
210
|
});
|
194
211
|
const rawTokenRates = await response.json();
|
212
|
+
if (hasVsTao) {
|
213
|
+
// calculate the TAO<>USD rate
|
214
|
+
const effectiveTaoIndex = effectiveCoingeckoIds.indexOf("bittensor");
|
215
|
+
const effectiveUsdIndex = effectiveCurrencyIds.indexOf("usd");
|
216
|
+
const taoUsdRate = rawTokenRates[effectiveTaoIndex]?.[effectiveUsdIndex]?.[0];
|
217
|
+
const taoUsdChange24h = rawTokenRates[effectiveTaoIndex]?.[effectiveUsdIndex]?.[2];
|
218
|
+
|
219
|
+
// insert TOKEN<>TAO rate (calculated based on TAO<>USD rate and TOKEN<>USD rate) into each TOKEN
|
220
|
+
const taoIndex = currencyIds.indexOf("tao");
|
221
|
+
rawTokenRates.forEach(rates => {
|
222
|
+
// get TOKEN<>USD rate
|
223
|
+
const tokenUsdRate = rates?.[effectiveUsdIndex]?.[0];
|
224
|
+
// calculate TOKEN<>TAO rate
|
225
|
+
const tokenTaoRate = typeof tokenUsdRate === "number" && typeof taoUsdRate === "number" && taoUsdRate !== 0 ? tokenUsdRate / taoUsdRate : null;
|
226
|
+
const tokenUsdChange24h = rates?.[effectiveUsdIndex]?.[2];
|
227
|
+
const tokenTaoChange24h = typeof taoUsdChange24h === "number" && typeof tokenUsdChange24h === "number" ? (1 + tokenUsdChange24h) / (1 + taoUsdChange24h) - 1 : null;
|
228
|
+
|
229
|
+
// insert at the correct location (based on the index of `tao` in `currencyIds`)
|
230
|
+
rates?.splice(taoIndex, 0, [tokenTaoRate, null, tokenTaoChange24h]);
|
231
|
+
});
|
232
|
+
}
|
195
233
|
const tokenRates = parseTokenRatesFromApi(rawTokenRates, coingeckoIds, currencyIds);
|
196
234
|
|
197
235
|
// build a TokenRatesList from the token prices result
|
@@ -31,6 +31,10 @@ const SUPPORTED_CURRENCIES = {
|
|
31
31
|
name: "Polkadot",
|
32
32
|
symbol: "D"
|
33
33
|
},
|
34
|
+
tao: {
|
35
|
+
name: "Bittensor",
|
36
|
+
symbol: "τ"
|
37
|
+
},
|
34
38
|
usd: {
|
35
39
|
name: "US Dollar",
|
36
40
|
symbol: "$"
|
@@ -106,6 +110,7 @@ const newTokenRates = () => ({
|
|
106
110
|
btc: null,
|
107
111
|
eth: null,
|
108
112
|
dot: null,
|
113
|
+
tao: null,
|
109
114
|
usd: null,
|
110
115
|
cny: null,
|
111
116
|
eur: null,
|
@@ -182,14 +187,47 @@ async function fetchTokenRates(tokens, currencyIds = ALL_CURRENCY_IDS, config =
|
|
182
187
|
|
183
188
|
// skip network request if there is nothing for us to fetch
|
184
189
|
if (coingeckoIds.length < 1) return {};
|
190
|
+
|
191
|
+
// If `currencyIds` includes `tao`, we need to always fetch the `bittensor` coingeckoId and the `usd` currency,
|
192
|
+
// we can use these to calculate the currency rate for TAO relative to all other tokens.
|
193
|
+
//
|
194
|
+
// We support showing balances in TAO just like we support BTC/ETH/DOT, but coingecko doesn't support TAO as a vs currency rate.
|
195
|
+
// We can macgyver our own TOKEN<>TAO rate by combining the TOKEN<>USD data with the TAO<>USD data.
|
196
|
+
const hasVsTao = currencyIds.includes("tao");
|
197
|
+
const [effectiveCoingeckoIds, effectiveCurrencyIds] = hasVsTao ? [[...new Set(coingeckoIds).add("bittensor")], [...new Set(
|
198
|
+
// don't request `tao` from coingecko (we calculate it from `usd`)
|
199
|
+
currencyIds.filter(c => c !== "tao"))
|
200
|
+
// always include `usd` (so we can calculate `tao`)
|
201
|
+
.add("usd")]] : [coingeckoIds, currencyIds];
|
185
202
|
const response = await fetch(`${config.apiUrl}/token-rates`, {
|
186
203
|
method: "POST",
|
187
204
|
body: JSON.stringify({
|
188
|
-
coingeckoIds,
|
189
|
-
currencyIds
|
205
|
+
coingeckoIds: effectiveCoingeckoIds,
|
206
|
+
currencyIds: effectiveCurrencyIds
|
190
207
|
})
|
191
208
|
});
|
192
209
|
const rawTokenRates = await response.json();
|
210
|
+
if (hasVsTao) {
|
211
|
+
// calculate the TAO<>USD rate
|
212
|
+
const effectiveTaoIndex = effectiveCoingeckoIds.indexOf("bittensor");
|
213
|
+
const effectiveUsdIndex = effectiveCurrencyIds.indexOf("usd");
|
214
|
+
const taoUsdRate = rawTokenRates[effectiveTaoIndex]?.[effectiveUsdIndex]?.[0];
|
215
|
+
const taoUsdChange24h = rawTokenRates[effectiveTaoIndex]?.[effectiveUsdIndex]?.[2];
|
216
|
+
|
217
|
+
// insert TOKEN<>TAO rate (calculated based on TAO<>USD rate and TOKEN<>USD rate) into each TOKEN
|
218
|
+
const taoIndex = currencyIds.indexOf("tao");
|
219
|
+
rawTokenRates.forEach(rates => {
|
220
|
+
// get TOKEN<>USD rate
|
221
|
+
const tokenUsdRate = rates?.[effectiveUsdIndex]?.[0];
|
222
|
+
// calculate TOKEN<>TAO rate
|
223
|
+
const tokenTaoRate = typeof tokenUsdRate === "number" && typeof taoUsdRate === "number" && taoUsdRate !== 0 ? tokenUsdRate / taoUsdRate : null;
|
224
|
+
const tokenUsdChange24h = rates?.[effectiveUsdIndex]?.[2];
|
225
|
+
const tokenTaoChange24h = typeof taoUsdChange24h === "number" && typeof tokenUsdChange24h === "number" ? (1 + tokenUsdChange24h) / (1 + taoUsdChange24h) - 1 : null;
|
226
|
+
|
227
|
+
// insert at the correct location (based on the index of `tao` in `currencyIds`)
|
228
|
+
rates?.splice(taoIndex, 0, [tokenTaoRate, null, tokenTaoChange24h]);
|
229
|
+
});
|
230
|
+
}
|
193
231
|
const tokenRates = parseTokenRatesFromApi(rawTokenRates, coingeckoIds, currencyIds);
|
194
232
|
|
195
233
|
// build a TokenRatesList from the token prices result
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/token-rates",
|
3
|
-
"version": "2.0.
|
3
|
+
"version": "2.0.5",
|
4
4
|
"author": "Talisman",
|
5
5
|
"homepage": "https://talisman.xyz",
|
6
6
|
"license": "GPL-3.0-or-later",
|
@@ -22,7 +22,7 @@
|
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
24
|
"dexie": "^4.0.9",
|
25
|
-
"@talismn/chaindata-provider": "0.10.
|
25
|
+
"@talismn/chaindata-provider": "0.10.4"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
28
|
"@types/jest": "^29.5.14",
|
@@ -30,8 +30,8 @@
|
|
30
30
|
"jest": "^29.7.0",
|
31
31
|
"ts-jest": "^29.2.5",
|
32
32
|
"typescript": "^5.6.3",
|
33
|
-
"@talismn/
|
34
|
-
"@talismn/
|
33
|
+
"@talismn/eslint-config": "0.0.3",
|
34
|
+
"@talismn/tsconfig": "0.0.2"
|
35
35
|
},
|
36
36
|
"eslintConfig": {
|
37
37
|
"root": true,
|