Skip to content

Commit

Permalink
Update bungee_bridge.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nftscripts authored Jun 17, 2023
1 parent 7d6a8c9 commit fa5c7ca
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions bridges/bungee/bungee_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from web3 import Web3
import random

from bridges.orbiter_bridge.utils.config import (
chain_without_eipstandart,
)

from bridges.bungee.utills.transaction_data import (
get_bungee_limits,
check_balance,
Expand All @@ -14,8 +18,6 @@
decimal_to_int,
round_to,
int_to_decimal,
add_gas_price,
add_gas_limit,
)


Expand Down Expand Up @@ -57,27 +59,44 @@ async def bridge(self) -> None:
logger.error(
f'Amount to bridge ({self.amount_to_bridge}) is out of limits | MIN: {min_limit} MAX: {max_limit}')

contract = self.web3.eth.contract(address=Web3.to_checksum_address(BUNGEE_REFUEL_CONTRACTS[self.from_chain.lower()]),
abi=await load_abi('bungee_refuel'))
contract = self.web3.eth.contract(
address=Web3.to_checksum_address(BUNGEE_REFUEL_CONTRACTS[self.from_chain.lower()]),
abi=await load_abi('bungee_refuel'))

tx = contract.functions.depositNativeToken(await get_chain_id(self.to_chain),
self.address_wallet
). \
build_transaction({
if not (self.from_chain.lower() in chain_without_eipstandart):
tx = contract.functions.depositNativeToken(await get_chain_id(self.to_chain),
self.address_wallet
). \
build_transaction({
'from': self.address_wallet,
'nonce': self.web3.eth.get_transaction_count(self.address_wallet),
'gasPrice': 0,
'gas': 0,
'value': value
'value': self.web3.to_wei(self.amount_to_bridge, 'ether'),
'maxFeePerGas': 0,
'maxPriorityFeePerGas': 0,
'gas': 0
})
tx.update({'maxFeePerGas': self.web3.eth.gas_price})
tx.update({'maxPriorityFeePerGas': self.web3.eth.gas_price})
gasLimit = self.web3.eth.estimate_gas(tx)
tx.update({'gas': gasLimit})

gas_price = await add_gas_price(self.web3)
tx['gasPrice'] = gas_price
gas = await add_gas_limit(self.web3, tx)
tx['gas'] = gas
else:
tx = contract.functions.depositNativeToken(await get_chain_id(self.to_chain),
self.address_wallet
). \
build_transaction({
'from': self.address_wallet,
'nonce': self.web3.eth.get_transaction_count(self.address_wallet),
'value': self.web3.to_wei(self.amount_to_bridge, 'ether'),
'gasPrice': self.web3.eth.gas_price,
'gas': 0
})
gasLimit = self.web3.eth.estimate_gas(tx)
tx.update({'gas': gasLimit})

signed_tx = self.web3.eth.account.sign_transaction(tx, self.private_key)
raw_tx_hash = self.web3.eth.send_raw_transaction(signed_tx.rawTransaction)
tx_hash = self.web3.to_hex(raw_tx_hash)

logger.info(f'Swapped {value / 10 ** 18} ETH from {self.from_chain} => {self.to_chain} | Tx hash: {tx_hash}')

0 comments on commit fa5c7ca

Please sign in to comment.