@@ -2675,6 +2675,7 @@ const CONET_guardian_purchase_Receiving_Address = (networkName) => {
26752675
26762676const parseEther = ( _ether , tokenName ) => {
26772677 const ether = typeof ( _ether ) === 'number' ? _ether . toFixed ( 8 ) : _ether
2678+
26782679 switch ( tokenName ) {
26792680 case 'arb_usdt' :
26802681 case 'usdt' : {
@@ -3059,6 +3060,7 @@ const transferAssetToCONET_wallet = (privateKey, token, transferNumber, toAddr)
30593060 const provide = new ethers . JsonRpcProvider ( getNetwork ( token . name ) )
30603061 const wallet = new ethers . Wallet ( privateKey , provide )
30613062 const smartContractAddr = getAssetERC20Address ( token . name )
3063+
30623064 if ( smartContractAddr ) {
30633065 const transferObj = new ethers . Contract ( smartContractAddr , blast_CNTPAbi , wallet )
30643066 const amount = parseEther ( transferNumber , token . name )
@@ -4018,6 +4020,63 @@ const bridge = async (cmd: any) => {
40184020 cmd . data . push ( error ?. reason ) ;
40194021 return returnUUIDChannel ( cmd ) ;
40204022 }
4023+ }
4024+
4025+ const estimateGasForBridge = async ( cmd : any ) => {
4026+ const walletAddress = cmd . data [ 0 ] ;
4027+ const tokenName = cmd . data [ 1 ] ;
4028+ const amount = cmd . data [ 2 ] ;
4029+
4030+ if ( ! CoNET_Data || ! walletAddress || ! tokenName || ! amount ) {
4031+ cmd . err = "FAILURE" ;
4032+ return returnUUIDChannel ( cmd ) ;
4033+ }
4034+
4035+ const profile = CoNET_Data . profiles ?. find ( ( profile ) => profile . keyID === walletAddress ) ;
4036+
4037+ if ( ! profile ) {
4038+ cmd . err = "FAILURE" ;
4039+ return returnUUIDChannel ( cmd ) ;
4040+ }
4041+
4042+ if ( ! profile . tokens ) {
4043+ cmd . err = "FAILURE" ;
4044+ return returnUUIDChannel ( cmd ) ;
4045+ }
40214046
4047+ const provider = new ethers . JsonRpcProvider ( getNetwork ( tokenName ) ) ;
4048+ const wallet = new ethers . Wallet ( profile . privateKeyArmor , provider ) ;
40224049
4050+ const tx = {
4051+ to : ethTreasuryContractAddress ,
4052+ value : parseEther ( amount , tokenName ) ,
4053+ } ;
4054+
4055+ let _fee ;
4056+ try {
4057+ try {
4058+ _fee = await wallet . estimateGas ( tx )
4059+ } catch ( error ) {
4060+ throw new Error ( 'Getting gas failed. Check your ETH balance and try again!' ) ;
4061+ }
4062+
4063+ const Fee = await provider . getFeeData ( ) ;
4064+ const gasPrice = ethers . formatUnits ( Fee . gasPrice , "gwei" ) ;
4065+ const fee = parseFloat ( ethers . formatEther ( _fee * Fee . gasPrice ) ) . toFixed ( 8 ) ;
4066+
4067+ cmd . data = [ fee , gasPrice ] ;
4068+
4069+ return returnUUIDChannel ( cmd ) ;
4070+ } catch ( error : any ) {
4071+ cmd . err = "FAILURE" ;
4072+
4073+ if ( ! error ?. reason ) {
4074+ error . reason =
4075+ "Getting gas failed. Check your ETH balance and try again!" ;
4076+ }
4077+
4078+ cmd . data = [ ]
4079+ cmd . data . push ( error ?. reason ) ;
4080+ return returnUUIDChannel ( cmd ) ;
4081+ }
40234082}
0 commit comments