| … | … | @@ -139,11 +139,76 @@ function walletMnemonicExists() { |
| 139 | 139 | return fs.existsSync(WALLET_MNEMONIC_FILE) |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | /** |
| 143 | * Token contract addresses for ERC-20 tokens |
| 144 | * Format: { 'chain-token': { mainnet: 'address', testnet: 'address' } } |
| 145 | */ |
| 146 | const TOKEN_CONTRACTS = { |
| 147 | 'ethereum-usdt': { |
| 148 | mainnet: '0xdac17f958d2ee523a2206206994597c13d831ec7', |
| 149 | testnet: '0x7169D38820dfd117C3FA1f22a697dBA58d90BA06' // Sepolia USDT |
| 150 | }, |
| 151 | 'ethereum-usdc': { |
| 152 | mainnet: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', |
| 153 | testnet: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238' // Sepolia USDC |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Check if a chain parameter refers to a token (e.g., 'ethereum-usdt') |
| 159 | * @param {string} chain - Chain identifier |
| 160 | * @returns {boolean} |
| 161 | */ |
| 162 | function isTokenChain(chain) { |
| 163 | return chain.includes('-') && chain !== 'testnet' && chain !== 'mainnet' |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Get base chain from token chain identifier |
| 168 | * @param {string} chain - Chain identifier (e.g., 'ethereum-usdt' or 'ethereum') |
| 169 | * @returns {string} - Base chain (e.g., 'ethereum') |
| 170 | */ |
| 171 | function getBaseChain(chain) { |
| 172 | if (!isTokenChain(chain)) { |
| 173 | return chain |
| 174 | } |
| 175 | // Extract base chain from 'ethereum-usdt' -> 'ethereum' |
| 176 | return chain.split('-')[0] |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Get token contract information |
| 181 | * @param {string} chain - Token chain identifier (e.g., 'ethereum-usdt') |
| 182 | * @param {boolean} isTestnet - Whether to use testnet contracts |
| 183 | * @returns {Object} - Token info { contract, symbol, decimals } |
| 184 | */ |
| 185 | function getTokenInfo(chain, isTestnet = true) { |
| 186 | const tokenContracts = TOKEN_CONTRACTS[chain] |
| 187 | if (!tokenContracts) { |
| 188 | throw new Error(`Unsupported token: ${chain}`) |
| 189 | } |
| 190 | |
| 191 | const contract = isTestnet ? tokenContracts.testnet : tokenContracts.mainnet |
| 192 | |
| 193 | // Extract token symbol from chain (ethereum-usdt -> USDT) |
| 194 | const symbol = chain.split('-')[1]?.toUpperCase() || 'TOKEN' |
| 195 | |
| 196 | return { |
| 197 | contract, |
| 198 | symbol, |
| 199 | decimals: 6 // USDT/USDC use 6 decimals |
| 200 | } |
| 201 | } |
| 202 | |
| 142 | 203 | module.exports = { |
| 143 | 204 | generateWalletMnemonic, |
| 144 | 205 | saveWalletMnemonic, |
| 145 | 206 | loadWalletMnemonic, |
| 146 | 207 | initializeWDK, |
| 147 | 208 | getFirstAddress, |
| 148 | | walletMnemonicExists |
| 209 | walletMnemonicExists, |
| 210 | isTokenChain, |
| 211 | getBaseChain, |
| 212 | getTokenInfo, |
| 213 | TOKEN_CONTRACTS |
| 149 | 214 | } |