-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathgenerateERC20.ts
More file actions
139 lines (117 loc) · 3.42 KB
/
generateERC20.ts
File metadata and controls
139 lines (117 loc) · 3.42 KB
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
130
131
132
133
134
135
136
137
138
139
import { erc20, erc20Token, terc20 } from '../account';
import { BaseCoin, CoinFeature, UnderlyingAsset } from '../base';
import { AccountNetwork, EthereumNetwork, Networks } from '../networks';
import { getFilteredFeatures, ofcerc20, tofcerc20 } from '../ofc';
// --- Shared config interfaces ---
interface BaseErc20Config {
id: string;
name: string;
fullName: string;
decimalPlaces: number;
contractAddress: string;
asset: UnderlyingAsset;
features?: CoinFeature[];
prefix?: string;
suffix?: string;
}
interface Erc20WithOfcConfig extends BaseErc20Config {
ofcId: string;
ofcName: string;
ofcFeatures: CoinFeature[];
ofcAddressCoin?: string;
skipOfc?: false;
}
interface Erc20WithoutOfcConfig extends BaseErc20Config {
skipOfc: true;
}
type Erc20Config = Erc20WithOfcConfig | Erc20WithoutOfcConfig;
type Erc20CoinConfig = Erc20Config & { network?: EthereumNetwork };
type Erc20TokenConfig = Erc20Config & { network: AccountNetwork };
function createOfcCoin(
config: Erc20WithOfcConfig,
features: CoinFeature[],
defaultAddressCoin: string,
isTestnet: boolean
) {
const ofcFn = isTestnet ? tofcerc20 : ofcerc20;
return ofcFn(
config.ofcId,
config.ofcName,
config.fullName,
config.decimalPlaces,
config.asset,
undefined, // kind
getFilteredFeatures(features),
undefined, // prefix
undefined, // suffix
undefined, // network
true, // isToken
config.ofcAddressCoin ?? defaultAddressCoin
);
}
// --- Ethereum ERC20 generators (erc20 / terc20) ---
export function generateErc20Coin(config: Erc20CoinConfig): Readonly<BaseCoin>[] {
const onChain = erc20(
config.id,
config.name,
config.fullName,
config.decimalPlaces,
config.contractAddress,
config.asset,
config.features,
config.prefix,
config.suffix,
config.network
);
if (config.skipOfc) return [onChain];
return [onChain, createOfcCoin(config, config.ofcFeatures ?? onChain.features, 'eth', false)];
}
export function generateTestErc20Coin(config: Erc20CoinConfig): Readonly<BaseCoin>[] {
const onChain = terc20(
config.id,
config.name,
config.fullName,
config.decimalPlaces,
config.contractAddress,
config.asset,
config.features,
config.prefix,
config.suffix,
config.network ?? Networks.test.hoodi //default testnet eth network for new tokens
);
if (config.skipOfc) return [onChain];
return [onChain, createOfcCoin(config, config.ofcFeatures ?? onChain.features, 'teth', true)];
}
// --- ERC20 Token generators (erc20Token for non-Ethereum EVM chains) ---
export function generateErc20Token(config: Erc20TokenConfig): Readonly<BaseCoin>[] {
const onChain = erc20Token(
config.id,
config.name,
config.fullName,
config.decimalPlaces,
config.contractAddress,
config.asset,
config.network,
config.features,
config.prefix,
config.suffix
);
if (config.skipOfc) return [onChain];
return [onChain, createOfcCoin(config, onChain.features, 'eth', false)];
}
export function generateTestErc20Token(config: Erc20TokenConfig): Readonly<BaseCoin>[] {
const onChain = erc20Token(
config.id,
config.name,
config.fullName,
config.decimalPlaces,
config.contractAddress,
config.asset,
config.network,
config.features,
config.prefix,
config.suffix
);
if (config.skipOfc) return [onChain];
return [onChain, createOfcCoin(config, onChain.features, 'teth', true)];
}