@@ -3,6 +3,12 @@ import { Framework, SFError } from '@superfluid-finance/sdk-core';
33
44import { ERC20__factory , getContractAddress } from '../contracts' ;
55import { getEvmRpcUrl } from '../config/evm' ;
6+ import {
7+ TIME_CONSTANTS ,
8+ CRYPTO_CONSTANTS ,
9+ CHAIN_IDS ,
10+ ADDRESS_CONSTANTS ,
11+ } from '../utils/constants/values' ;
612
713export interface WalletConnection {
814 address : string ;
@@ -44,7 +50,7 @@ export interface SuperfluidStreamResult {
4450 streamId : string ;
4551}
4652
47- const SECONDS_PER_MONTH = 30 * 24 * 60 * 60 ;
53+ const SECONDS_PER_MONTH = TIME_CONSTANTS . SECONDS_PER_MONTH ;
4854
4955function isUserRejectedError ( error : unknown ) : boolean {
5056 if ( error == null || typeof error !== 'object' ) return false ;
@@ -59,7 +65,7 @@ function superTokenResolverSymbol(chainId: number, tokenSymbol: string): string
5965 if ( s === 'USDC' || s === 'USDC.E' ) return 'USDCx' ;
6066 if ( s === 'MATIC' ) return 'MATICx' ;
6167 if ( s === 'ETH' ) {
62- if ( chainId === 137 ) return 'MATICx' ;
68+ if ( chainId === CHAIN_IDS . POLYGON ) return 'MATICx' ;
6369 return 'ETHx' ;
6470 }
6571 if ( s === 'ARB' ) {
@@ -154,11 +160,11 @@ export class WalletServiceManager {
154160 name : this . getNativeName ( chainId ) ,
155161 address : '0x0000000000000000000000000000000000000000' ,
156162 balance : ethers . utils . formatEther ( nativeBalance ) ,
157- decimals : 18 ,
163+ decimals : CRYPTO_CONSTANTS . ETH_DECIMALS ,
158164 } ) ;
159165
160166 // Get USDC balance if on supported chains
161- if ( chainId === 1 || chainId === 137 || chainId === 42161 ) {
167+ if ( chainId === CHAIN_IDS . ETHEREUM || chainId === CHAIN_IDS . POLYGON || chainId === CHAIN_IDS . ARBITRUM ) {
162168 const usdcAddress = getContractAddress ( chainId , 'usdc' ) ;
163169 if ( ! usdcAddress ) {
164170 return balances ;
@@ -171,8 +177,8 @@ export class WalletServiceManager {
171177 symbol : 'USDC' ,
172178 name : 'USD Coin' ,
173179 address : usdcAddress ,
174- balance : ethers . utils . formatUnits ( usdcBalance , 6 ) ,
175- decimals : 6 ,
180+ balance : ethers . utils . formatUnits ( usdcBalance , CRYPTO_CONSTANTS . USDC_DECIMALS ) ,
181+ decimals : CRYPTO_CONSTANTS . USDC_DECIMALS ,
176182 } ) ;
177183 } catch {
178184 console . log ( 'USDC not available on this chain' ) ;
@@ -211,11 +217,11 @@ export class WalletServiceManager {
211217 value : ethers . utils . parseEther ( value || '0' ) ,
212218 } ) ;
213219 // Network-specific buffer: higher for Polygon due to congestion variability
214- const bufferMultiplier = chainId === 137 ? 130 : 120 ;
220+ const bufferMultiplier = chainId === CHAIN_IDS . POLYGON ? CRYPTO_CONSTANTS . POLYGON_GAS_BUFFER_MULTIPLIER : CRYPTO_CONSTANTS . DEFAULT_GAS_BUFFER_MULTIPLIER ;
215221 gasLimit = estimated . mul ( bufferMultiplier ) . div ( 100 ) ;
216222 } catch ( err ) {
217223 console . warn ( 'Gas estimation failed, using safe fallback:' , err ) ;
218- gasLimit = ethers . BigNumber . from ( 100000 ) ;
224+ gasLimit = ethers . BigNumber . from ( CRYPTO_CONSTANTS . FALLBACK_GAS_LIMIT ) ;
219225 }
220226 }
221227
@@ -393,7 +399,7 @@ export class WalletServiceManager {
393399 const amountBn = ethers . utils . parseUnits ( amount , decimals ) ;
394400
395401 // Sablier V2 LockupLinear is consistently deployed at this address across major EVM networks
396- const SABLIER_V2_LOCKUP_LINEAR = '0xAFb979d9afAd1aD27C5eFf4E27226E3AB9e5dCC9' ;
402+ const SABLIER_V2_LOCKUP_LINEAR = ADDRESS_CONSTANTS . SABLIER_V2_LOCKUP_LINEAR ;
397403
398404 // 2. Approve Token Spending
399405 const txApprove = await erc20 . approve ( SABLIER_V2_LOCKUP_LINEAR , amountBn ) ;
@@ -421,7 +427,7 @@ export class WalletServiceManager {
421427 cliff : 0 ,
422428 total : totalDuration ,
423429 } ,
424- broker : ethers . constants . AddressZero ,
430+ broker : ADDRESS_CONSTANTS . ZERO_ADDRESS ,
425431 } ;
426432
427433 const txCreate = await sablierContract . createWithDurations ( params ) ;
@@ -447,18 +453,18 @@ export class WalletServiceManager {
447453
448454 private getNativeSymbol ( chainId : number ) : string {
449455 const symbols : Record < number , string > = {
450- 1 : 'ETH' ,
451- 137 : 'MATIC' ,
452- 42161 : 'ETH' ,
456+ [ CHAIN_IDS . ETHEREUM ] : 'ETH' ,
457+ [ CHAIN_IDS . POLYGON ] : 'MATIC' ,
458+ [ CHAIN_IDS . ARBITRUM ] : 'ETH' ,
453459 } ;
454460 return symbols [ chainId ] || 'ETH' ;
455461 }
456462
457463 private getNativeName ( chainId : number ) : string {
458464 const names : Record < number , string > = {
459- 1 : 'Ethereum' ,
460- 137 : 'Polygon' ,
461- 42161 : 'Arbitrum' ,
465+ [ CHAIN_IDS . ETHEREUM ] : 'Ethereum' ,
466+ [ CHAIN_IDS . POLYGON ] : 'Polygon' ,
467+ [ CHAIN_IDS . ARBITRUM ] : 'Arbitrum' ,
462468 } ;
463469 return names [ chainId ] || 'Ethereum' ;
464470 }
0 commit comments