-
Notifications
You must be signed in to change notification settings - Fork 18
/
vite-plugin-whip-003.ts
92 lines (85 loc) · 2.46 KB
/
vite-plugin-whip-003.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
import { Plugin } from 'vite'
export function whip003(): Plugin {
return {
name: 'build-tokens',
async buildStart(options) {
const { chains, tokens, snips } = await import('./src/utils/config')
const whip003 = {
chains: {},
contracts: {}
}
// add chain definitions
for (const chain of Object.values(chains)) {
whip003.chains[chain.chain_id] = {
namespace: 'cosmos',
reference: chain.chain_id,
label: chain.chain_name,
bech32s: chain.bech32_prefix
}
}
// add IBC tokens
for (const token of Object.values(tokens)) {
whip003.contracts[token.name] = {
chain: 'cosmos:secret-4',
address: token.address,
label:
1 === token.withdrawals.length
? token.deposits[0].chain_name
: 'SCRT' === token.name
? 'Secret Network'
: token.name,
interfaces: {
snip20: {
symbol: token.name,
decimals: token.decimals,
coingeckoId: token.coingecko_id
}
}
}
}
// add IBC tokens
for (const token of Object.values(tokens)) {
whip003.contracts[token.name] = {
chain: 'cosmos:secret-4',
address: token.address,
label:
1 === token.withdrawals.length
? token.deposits[0].chain_name
: 'SCRT' === token.name
? 'Secret Network'
: token.name,
interfaces: {
snip20: {
symbol: token.name,
decimals: token.decimals,
coingeckoId: token.coingecko_id
}
}
}
}
// add SNIPs
for (const snip of Object.values(snips)) {
whip003.contracts[snip.name] = {
chain: 'cosmos:secret-4',
address: snip.address,
label: snip.coingecko_id
? snip.coingecko_id.replace(/-/g, ' ').replace(/\b[a-z]/g, (s) => s.toUpperCase())
: snip.name,
interfaces: {
snip20: {
symbol: snip.name,
decimals: snip.decimals,
coingeckoId: snip.coingecko_id
}
}
}
}
// emit the whip-003 JSON definition
this.emitFile({
type: 'asset',
fileName: 'whip-003.json',
source: JSON.stringify(whip003, null, '\t')
})
}
}
}