-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathgenerateSupplyTokens.ts
129 lines (107 loc) · 3.52 KB
/
generateSupplyTokens.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { TokenType, TokenVerification } from '@injectivelabs/sdk-ts'
import { Network, isMainnet, isTestnet } from '@injectivelabs/networks'
import {
readJSONFile,
updateJSONFile,
tokensToDenomMap,
getNetworkFileName
} from './helper/utils'
import { symbolMeta } from './data/symbolMeta'
import { getInsuranceFundToken } from './helper/getter'
import { fetchIbcTokenMetaData } from './fetchIbcDenomTrace'
import { fetchPeggyTokenMetaData } from './fetchPeggyMetadata'
import { untaggedSymbolMeta } from './data/untaggedSymbolMeta'
const mainnetStaticTokensMap = tokensToDenomMap([
...readJSONFile({ path: 'tokens/staticTokens/mainnet.json' }),
...readJSONFile({ path: 'tokens/externalTokens.json' })
])
const devnetStaticTokensMap = tokensToDenomMap(
readJSONFile({ path: 'tokens/staticTokens/devnet.json' })
)
const testnetStaticTokensMap = tokensToDenomMap(
readJSONFile({ path: 'tokens/staticTokens/testnet.json' })
)
export const generateSupplyToken = async (network: Network) => {
let supplyDenoms = readJSONFile({
path: 'data/bankSupplyDenoms/devnet.json'
})
let existingStaticTokensMap = devnetStaticTokensMap
if (isTestnet(network)) {
supplyDenoms = readJSONFile({
path: 'data/bankSupplyDenoms/testnet.json'
})
existingStaticTokensMap = testnetStaticTokensMap
}
if (isMainnet(network)) {
supplyDenoms = readJSONFile({
path: 'data/bankSupplyDenoms/mainnet.json'
})
existingStaticTokensMap = mainnetStaticTokensMap
}
try {
const filteredDenoms = supplyDenoms.filter(
(denom: string) => !existingStaticTokensMap[denom.toLowerCase()]
)
const supplyTokens = []
for (const denom of filteredDenoms) {
/*
all factory denoms on chain are handled in
the generateFactoryTokens script
*/
if (denom.startsWith('factory')) {
continue
}
if (denom.startsWith('share')) {
const insuranceToken = getInsuranceFundToken(
denom,
Network.MainnetSentry
)
if (insuranceToken) {
supplyTokens.push(insuranceToken)
} else {
supplyTokens.push({
denom,
name: denom,
decimals: 18,
symbol: denom,
address: denom,
logo: symbolMeta.INJ.logo,
externalLogo: symbolMeta.INJ.logo,
tokenType: TokenType.InsuranceFund,
tokenVerification: TokenVerification.Unverified,
coinGeckoId: untaggedSymbolMeta.Unknown.coinGeckoId
})
}
continue
}
if (denom.startsWith('peggy') || denom.startsWith('0x')) {
const peggyToken = await fetchPeggyTokenMetaData(denom, network)
if (peggyToken) {
supplyTokens.push(peggyToken)
continue
}
}
if (denom.startsWith('ibc/')) {
const ibcToken = await fetchIbcTokenMetaData(denom, network)
if (ibcToken) {
supplyTokens.push(ibcToken)
continue
}
}
}
const filteredTokens = [...supplyTokens].filter(({ denom }) => denom)
if (filteredTokens.length === 0) {
return
}
await updateJSONFile(
`tokens/bankSupplyTokens/${getNetworkFileName(network)}.json`,
filteredTokens.sort((a, b) => a.denom.localeCompare(b.denom))
)
console.log(`✅✅✅ GenerateSupplyTokens ${network}`)
} catch (e) {
console.log('Error generating supply tokens')
}
}
generateSupplyToken(Network.Devnet)
generateSupplyToken(Network.MainnetSentry)
generateSupplyToken(Network.TestnetSentry)