Skip to content

Commit 3b428fe

Browse files
committed
Store pluginId token types in couch
1 parent 8bac484 commit 3b428fe

9 files changed

Lines changed: 111 additions & 194 deletions

File tree

src/v3/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export const ONE_HOUR = 60 * ONE_MINUTE
44
export const TWENTY_FOUR_HOURS = 24 * ONE_HOUR
55

66
export const LEADERBOARD_KEY = 'edgerates:top100'
7+
export const TOKEN_TYPES_KEY = 'tokenTypes'

src/v3/providers/coingecko/coingecko.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { asArray, asMaybe, asNumber, asObject, asString } from 'cleaners'
2-
import { syncedDocument } from 'edge-server-tools'
2+
import { asCouchDoc, syncedDocument } from 'edge-server-tools'
33

44
import { config } from '../../../config'
55
import { dateOnly, snooze } from '../../../utils/utils'
6+
import { TOKEN_TYPES_KEY } from '../../constants'
67
import {
7-
asPlatformIdMapping,
8+
asStringNullMap,
89
asTokenMap,
9-
EdgeCurrencyPluginId,
1010
NumberMap,
1111
RateBuckets,
1212
RateEngine,
@@ -103,7 +103,7 @@ const automatedTokenMappingsSyncDoc = syncedDocument(
103103
)
104104
const platformIdMappingSyncDoc = syncedDocument(
105105
'coingecko:platforms',
106-
asPlatformIdMapping
106+
asStringNullMap
107107
)
108108
manualTokenMappingsSyncDoc.onChange(manualMappings => {
109109
coingeckoTokenIdMap = {
@@ -133,6 +133,9 @@ const tokenMapping: RateEngine = async () => {
133133
const json = await fetchCoingecko(
134134
`${config.providers.coingeckopro.uri}/api/v3/coins/list?include_platform=true`
135135
)
136+
const tokenTypes = asCouchDoc(asStringNullMap)(
137+
await dbSettings.get(TOKEN_TYPES_KEY)
138+
)
136139

137140
const data = asCoingeckoAssetResponse(json)
138141

@@ -155,7 +158,7 @@ const tokenMapping: RateEngine = async () => {
155158

156159
try {
157160
const tokenId = createTokenId(
158-
pluginId as EdgeCurrencyPluginId,
161+
tokenTypes.doc[pluginId],
159162
asset.symbol,
160163
contractAddress
161164
)

src/v3/providers/coingecko/defaultPluginIdMapping.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EdgeCurrencyPluginIdUIDMap } from '../../types'
1+
import { StringNullMap } from '../../types'
22

3-
export const coingeckoMainnetCurrencyMapping: EdgeCurrencyPluginIdUIDMap = {
3+
export const coingeckoMainnetCurrencyMapping: StringNullMap = {
44
algorand: 'algorand',
55
arbitrum: 'ethereum',
66
avalanche: 'avalanche-2',
@@ -67,7 +67,7 @@ export const coingeckoMainnetCurrencyMapping: EdgeCurrencyPluginIdUIDMap = {
6767
zksync: 'ethereum'
6868
}
6969

70-
export const coingeckoPlatformIdMapping: EdgeCurrencyPluginIdUIDMap = {
70+
export const coingeckoPlatformIdMapping: StringNullMap = {
7171
algorand: 'algorand',
7272
arbitrum: 'arbitrum-one',
7373
avalanche: 'avalanche',

src/v3/providers/coinmarketcap/coinmarketcap.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import {
66
asObject,
77
asString
88
} from 'cleaners'
9-
import { syncedDocument } from 'edge-server-tools'
9+
import { asCouchDoc, syncedDocument } from 'edge-server-tools'
1010

1111
import { config } from '../../../config'
1212
import { daysBetween, snooze } from '../../../utils/utils'
13+
import { TOKEN_TYPES_KEY } from '../../constants'
1314
import {
14-
asPlatformIdMapping,
15+
asStringNullMap,
1516
asTokenMap,
16-
EdgeCurrencyPluginId,
1717
NumberMap,
1818
RateBuckets,
1919
RateEngine,
@@ -142,7 +142,7 @@ const automatedTokenMappingsSyncDoc = syncedDocument(
142142
)
143143
const platformIdMappingSyncDoc = syncedDocument(
144144
'coinmarketcap:platforms',
145-
asPlatformIdMapping
145+
asStringNullMap
146146
)
147147
userTokenMappingsSyncDoc.onChange(userMappings => {
148148
coinmarketcapTokenIdMap = {
@@ -174,6 +174,9 @@ const tokenMapping: RateEngine = async () => {
174174
const json = await fetchCoinmarketcap(
175175
`${config.providers.coinMarketCapHistorical.uri}/v1/cryptocurrency/map?aux=platform`
176176
)
177+
const tokenTypes = asCouchDoc(asStringNullMap)(
178+
await dbSettings.get(TOKEN_TYPES_KEY)
179+
)
177180

178181
const data = asCoinMarketCapAssetResponse(json)
179182

@@ -190,7 +193,7 @@ const tokenMapping: RateEngine = async () => {
190193

191194
try {
192195
const tokenId = createTokenId(
193-
pluginId as EdgeCurrencyPluginId,
196+
tokenTypes.doc[pluginId],
194197
asset.symbol,
195198
asset.platform.token_address
196199
)

src/v3/providers/coinmarketcap/defaultPluginIdMapping.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EdgeCurrencyPluginIdUIDMap } from '../../types'
1+
import { StringNullMap } from '../../types'
22

3-
export const coinmarketcapMainnetCurrencyMapping: EdgeCurrencyPluginIdUIDMap = {
3+
export const coinmarketcapMainnetCurrencyMapping: StringNullMap = {
44
algorand: '4030',
55
arbitrum: '1027',
66
avalanche: '5805',
@@ -67,7 +67,7 @@ export const coinmarketcapMainnetCurrencyMapping: EdgeCurrencyPluginIdUIDMap = {
6767
zksync: '1027'
6868
}
6969

70-
export const coinmarketcapPlatformIdMapping: EdgeCurrencyPluginIdUIDMap = {
70+
export const coinmarketcapPlatformIdMapping: StringNullMap = {
7171
algorand: '17',
7272
arbitrum: '51',
7373
avalanche: '28',

src/v3/providers/edgerates/defaults.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EdgeAsset } from '../../types'
1+
import { EdgeAsset, StringNullMap } from '../../types'
22

33
export const defaultCrypto: EdgeAsset[] = [
44
{ pluginId: 'bitcoin', tokenId: null },
@@ -425,3 +425,70 @@ export const defaultFiat: string[] = [
425425
'XAG',
426426
'ZWL'
427427
]
428+
429+
export const defaultTokenTypes: StringNullMap = {
430+
algorand: 'simple',
431+
arbitrum: 'evm',
432+
avalanche: 'evm',
433+
axelar: 'cosmos',
434+
base: 'evm',
435+
binance: null,
436+
binancesmartchain: 'evm',
437+
bitcoin: null,
438+
bitcoincash: null,
439+
bitcoingold: null,
440+
bitcoinsv: null,
441+
bobevm: 'evm',
442+
cardano: null,
443+
celo: 'evm',
444+
coreum: 'cosmos',
445+
cosmoshub: 'cosmos',
446+
dash: null,
447+
digibyte: null,
448+
dogecoin: null,
449+
eboost: null,
450+
ecash: null,
451+
eos: null,
452+
ethereum: 'evm',
453+
ethereumclassic: 'evm',
454+
ethereumpow: 'evm',
455+
fantom: 'evm',
456+
feathercoin: null,
457+
filecoin: null,
458+
filecoinfevm: 'evm',
459+
fio: null,
460+
groestlcoin: null,
461+
hedera: null,
462+
hyperevm: 'evm',
463+
liberland: 'simple',
464+
litecoin: null,
465+
monero: null,
466+
optimism: 'evm',
467+
osmosis: 'cosmos',
468+
piratechain: null,
469+
pivx: null,
470+
polkadot: null,
471+
polygon: 'evm',
472+
pulsechain: 'evm',
473+
qtum: null,
474+
ravencoin: null,
475+
ripple: 'xrpl',
476+
rsk: 'evm',
477+
smartcash: null,
478+
solana: 'simple',
479+
sonic: 'evm',
480+
stellar: null,
481+
sui: 'colon-delimited',
482+
telos: null,
483+
tezos: null,
484+
thorchainrune: 'cosmos',
485+
ton: null,
486+
tron: 'simple',
487+
ufo: null,
488+
vertcoin: null,
489+
wax: null,
490+
zano: 'lowercase',
491+
zcash: null,
492+
zcoin: null,
493+
zksync: 'evm'
494+
}

src/v3/providers/edgerates/edgerates.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { fromCryptoKey } from '../../utils'
1414
import { dbSettings } from '../couch'
1515
import { client } from '../redis'
16-
import { defaultCrypto, defaultFiat } from './defaults'
16+
import { defaultCrypto, defaultFiat, defaultTokenTypes } from './defaults'
1717

1818
const asEdgeRates = asObject({
1919
crypto: asArray(asEdgeAsset),
@@ -114,7 +114,8 @@ export const edgerates: RateProvider = {
114114
edgerates: {
115115
crypto: defaultCrypto,
116116
fiat: defaultFiat
117-
}
117+
},
118+
tokenTypes: defaultTokenTypes
118119
}
119120
}
120121
],

src/v3/types.ts

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -116,77 +116,8 @@ export interface StringMap {
116116
[key: string]: string
117117
}
118118

119-
export type EdgeCurrencyPluginId =
120-
| 'algorand'
121-
| 'arbitrum'
122-
| 'avalanche'
123-
| 'axelar'
124-
| 'base'
125-
| 'binance'
126-
| 'binancesmartchain'
127-
| 'bitcoin'
128-
| 'bitcoincash'
129-
| 'bitcoingold'
130-
| 'bitcoinsv'
131-
| 'bobevm'
132-
| 'cardano'
133-
| 'celo'
134-
| 'coreum'
135-
| 'cosmoshub'
136-
| 'dash'
137-
| 'digibyte'
138-
| 'dogecoin'
139-
| 'eboost'
140-
| 'ecash'
141-
| 'eos'
142-
| 'ethereum'
143-
| 'ethereumclassic'
144-
| 'ethereumpow'
145-
| 'fantom'
146-
| 'feathercoin'
147-
| 'filecoin'
148-
| 'filecoinfevm'
149-
| 'fio'
150-
| 'groestlcoin'
151-
| 'hedera'
152-
| 'hyperevm'
153-
| 'liberland'
154-
| 'litecoin'
155-
| 'monero'
156-
| 'optimism'
157-
| 'osmosis'
158-
| 'piratechain'
159-
| 'pivx'
160-
| 'polkadot'
161-
| 'polygon'
162-
| 'pulsechain'
163-
| 'qtum'
164-
| 'ravencoin'
165-
| 'ripple'
166-
| 'rsk'
167-
| 'smartcash'
168-
| 'solana'
169-
| 'sonic'
170-
| 'stellar'
171-
| 'sui'
172-
| 'telos'
173-
| 'tezos'
174-
| 'thorchainrune'
175-
| 'ton'
176-
| 'tron'
177-
| 'ufo'
178-
| 'vertcoin'
179-
| 'wax'
180-
| 'zcash'
181-
| 'zcoin'
182-
| 'zano'
183-
| 'zksync'
184-
185-
export type EdgeCurrencyPluginIdUIDMap = Record<
186-
EdgeCurrencyPluginId,
187-
string | null
188-
>
189-
export const asPlatformIdMapping = asObject(asEither(asString, asNull))
119+
export const asStringNullMap = asObject(asEither(asString, asNull))
120+
export type StringNullMap = Record<string, string | null>
190121

191122
export interface NumberMap {
192123
[key: string]: number

0 commit comments

Comments
 (0)