@talismn/token-rates 2.0.12 → 3.0.0
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.
@@ -1,6 +1,7 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var dexie = require('dexie');
|
4
|
+
var chaindataProvider = require('@talismn/chaindata-provider');
|
4
5
|
|
5
6
|
class TalismanTokenRatesDatabase extends dexie.Dexie {
|
6
7
|
constructor() {
|
@@ -146,22 +147,18 @@ const DEFAULT_COINSAPI_CONFIG = {
|
|
146
147
|
};
|
147
148
|
async function fetchTokenRates(tokens, currencyIds = ALL_CURRENCY_IDS, config = DEFAULT_COINSAPI_CONFIG) {
|
148
149
|
// create a map from `coingeckoId` -> `tokenId` for each token
|
149
|
-
const coingeckoIdToTokenIds = Object.values(tokens)
|
150
|
-
// ignore testnet tokens
|
151
|
-
.filter(({
|
152
|
-
isTestnet
|
153
|
-
}) => !isTestnet).flatMap(token => {
|
150
|
+
const coingeckoIdToTokenIds = Object.values(tokens).flatMap(token => {
|
154
151
|
// BEGIN: LP tokens have a rate which is calculated later on, using the rates of two other tokens.
|
155
152
|
//
|
156
153
|
// This section contains the logic such that: if token is an LP token, then fetch the rates for the two underlying tokens.
|
157
154
|
if (token.type === "evm-uniswapv2") {
|
158
|
-
if (
|
155
|
+
if (token.platform !== "ethereum") return [];
|
159
156
|
const getToken = (evmNetworkId, tokenAddress, coingeckoId) => ({
|
160
|
-
id: evmErc20TokenId(evmNetworkId, tokenAddress),
|
157
|
+
id: chaindataProvider.evmErc20TokenId(evmNetworkId, tokenAddress),
|
161
158
|
coingeckoId
|
162
159
|
});
|
163
|
-
const token0 = token.coingeckoId0 ? [getToken(token.
|
164
|
-
const token1 = token.coingeckoId1 ? [getToken(token.
|
160
|
+
const token0 = token.coingeckoId0 ? [getToken(token.networkId, token.tokenAddress0, token.coingeckoId0)] : [];
|
161
|
+
const token1 = token.coingeckoId1 ? [getToken(token.networkId, token.tokenAddress1, token.coingeckoId1)] : [];
|
165
162
|
return [...token0, ...token1];
|
166
163
|
}
|
167
164
|
// END: LP tokens have a rate which is calculated later on, using the rates of two other tokens.
|
@@ -237,10 +234,6 @@ async function fetchTokenRates(tokens, currencyIds = ALL_CURRENCY_IDS, config =
|
|
237
234
|
return ratesList;
|
238
235
|
}
|
239
236
|
|
240
|
-
// TODO: Move this into a common module which can then be imported both here and into EvmErc20Module
|
241
|
-
// We can't import this directly from EvmErc20Module because this package doesn't depend on `@talismn/balances`
|
242
|
-
const evmErc20TokenId = (chainId, tokenContractAddress) => `${chainId}-evm-erc20-${tokenContractAddress}`.toLowerCase();
|
243
|
-
|
244
237
|
// To save on bandwidth and work around response size limits, values are returned without json property names
|
245
238
|
// (e.g. [[[12, 12332, 0.5]]] instead of { dot : {usd: { value: 12, marketCap: 12332, change24h: 0.5 }} })
|
246
239
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var dexie = require('dexie');
|
4
|
+
var chaindataProvider = require('@talismn/chaindata-provider');
|
4
5
|
|
5
6
|
class TalismanTokenRatesDatabase extends dexie.Dexie {
|
6
7
|
constructor() {
|
@@ -146,22 +147,18 @@ const DEFAULT_COINSAPI_CONFIG = {
|
|
146
147
|
};
|
147
148
|
async function fetchTokenRates(tokens, currencyIds = ALL_CURRENCY_IDS, config = DEFAULT_COINSAPI_CONFIG) {
|
148
149
|
// create a map from `coingeckoId` -> `tokenId` for each token
|
149
|
-
const coingeckoIdToTokenIds = Object.values(tokens)
|
150
|
-
// ignore testnet tokens
|
151
|
-
.filter(({
|
152
|
-
isTestnet
|
153
|
-
}) => !isTestnet).flatMap(token => {
|
150
|
+
const coingeckoIdToTokenIds = Object.values(tokens).flatMap(token => {
|
154
151
|
// BEGIN: LP tokens have a rate which is calculated later on, using the rates of two other tokens.
|
155
152
|
//
|
156
153
|
// This section contains the logic such that: if token is an LP token, then fetch the rates for the two underlying tokens.
|
157
154
|
if (token.type === "evm-uniswapv2") {
|
158
|
-
if (
|
155
|
+
if (token.platform !== "ethereum") return [];
|
159
156
|
const getToken = (evmNetworkId, tokenAddress, coingeckoId) => ({
|
160
|
-
id: evmErc20TokenId(evmNetworkId, tokenAddress),
|
157
|
+
id: chaindataProvider.evmErc20TokenId(evmNetworkId, tokenAddress),
|
161
158
|
coingeckoId
|
162
159
|
});
|
163
|
-
const token0 = token.coingeckoId0 ? [getToken(token.
|
164
|
-
const token1 = token.coingeckoId1 ? [getToken(token.
|
160
|
+
const token0 = token.coingeckoId0 ? [getToken(token.networkId, token.tokenAddress0, token.coingeckoId0)] : [];
|
161
|
+
const token1 = token.coingeckoId1 ? [getToken(token.networkId, token.tokenAddress1, token.coingeckoId1)] : [];
|
165
162
|
return [...token0, ...token1];
|
166
163
|
}
|
167
164
|
// END: LP tokens have a rate which is calculated later on, using the rates of two other tokens.
|
@@ -237,10 +234,6 @@ async function fetchTokenRates(tokens, currencyIds = ALL_CURRENCY_IDS, config =
|
|
237
234
|
return ratesList;
|
238
235
|
}
|
239
236
|
|
240
|
-
// TODO: Move this into a common module which can then be imported both here and into EvmErc20Module
|
241
|
-
// We can't import this directly from EvmErc20Module because this package doesn't depend on `@talismn/balances`
|
242
|
-
const evmErc20TokenId = (chainId, tokenContractAddress) => `${chainId}-evm-erc20-${tokenContractAddress}`.toLowerCase();
|
243
|
-
|
244
237
|
// To save on bandwidth and work around response size limits, values are returned without json property names
|
245
238
|
// (e.g. [[[12, 12332, 0.5]]] instead of { dot : {usd: { value: 12, marketCap: 12332, change24h: 0.5 }} })
|
246
239
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Dexie } from 'dexie';
|
2
|
+
import { evmErc20TokenId } from '@talismn/chaindata-provider';
|
2
3
|
|
3
4
|
class TalismanTokenRatesDatabase extends Dexie {
|
4
5
|
constructor() {
|
@@ -144,22 +145,18 @@ const DEFAULT_COINSAPI_CONFIG = {
|
|
144
145
|
};
|
145
146
|
async function fetchTokenRates(tokens, currencyIds = ALL_CURRENCY_IDS, config = DEFAULT_COINSAPI_CONFIG) {
|
146
147
|
// create a map from `coingeckoId` -> `tokenId` for each token
|
147
|
-
const coingeckoIdToTokenIds = Object.values(tokens)
|
148
|
-
// ignore testnet tokens
|
149
|
-
.filter(({
|
150
|
-
isTestnet
|
151
|
-
}) => !isTestnet).flatMap(token => {
|
148
|
+
const coingeckoIdToTokenIds = Object.values(tokens).flatMap(token => {
|
152
149
|
// BEGIN: LP tokens have a rate which is calculated later on, using the rates of two other tokens.
|
153
150
|
//
|
154
151
|
// This section contains the logic such that: if token is an LP token, then fetch the rates for the two underlying tokens.
|
155
152
|
if (token.type === "evm-uniswapv2") {
|
156
|
-
if (
|
153
|
+
if (token.platform !== "ethereum") return [];
|
157
154
|
const getToken = (evmNetworkId, tokenAddress, coingeckoId) => ({
|
158
155
|
id: evmErc20TokenId(evmNetworkId, tokenAddress),
|
159
156
|
coingeckoId
|
160
157
|
});
|
161
|
-
const token0 = token.coingeckoId0 ? [getToken(token.
|
162
|
-
const token1 = token.coingeckoId1 ? [getToken(token.
|
158
|
+
const token0 = token.coingeckoId0 ? [getToken(token.networkId, token.tokenAddress0, token.coingeckoId0)] : [];
|
159
|
+
const token1 = token.coingeckoId1 ? [getToken(token.networkId, token.tokenAddress1, token.coingeckoId1)] : [];
|
163
160
|
return [...token0, ...token1];
|
164
161
|
}
|
165
162
|
// END: LP tokens have a rate which is calculated later on, using the rates of two other tokens.
|
@@ -235,10 +232,6 @@ async function fetchTokenRates(tokens, currencyIds = ALL_CURRENCY_IDS, config =
|
|
235
232
|
return ratesList;
|
236
233
|
}
|
237
234
|
|
238
|
-
// TODO: Move this into a common module which can then be imported both here and into EvmErc20Module
|
239
|
-
// We can't import this directly from EvmErc20Module because this package doesn't depend on `@talismn/balances`
|
240
|
-
const evmErc20TokenId = (chainId, tokenContractAddress) => `${chainId}-evm-erc20-${tokenContractAddress}`.toLowerCase();
|
241
|
-
|
242
235
|
// To save on bandwidth and work around response size limits, values are returned without json property names
|
243
236
|
// (e.g. [[[12, 12332, 0.5]]] instead of { dot : {usd: { value: 12, marketCap: 12332, change24h: 0.5 }} })
|
244
237
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/token-rates",
|
3
|
-
"version": "
|
3
|
+
"version": "3.0.0",
|
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.
|
25
|
+
"@talismn/chaindata-provider": "1.0.0"
|
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,
|