Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
czbag committed Nov 2, 2023
1 parent b172238 commit cd5efee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 12 additions & 6 deletions modules/layerswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ async def create_swap(self, from_chain: str, to_chain: str, amount: float) -> Un

return False

async def get_swap_path(self, from_chain: str, to_chain: str, amount: float) -> Union[Dict, bool]:
async def prepare_transaction(self, from_chain: str, to_chain: str, amount: float) -> Union[Dict, bool]:
swap_id = await self.create_swap(from_chain, to_chain, amount)

url = f"https://api.layerswap.io/api/swaps/{swap_id}"
url = f"https://api.layerswap.io/api/swaps/{swap_id}/prepare_src_transaction"

params = {
"from_address": self.address
}

async with aiohttp.ClientSession() as session:
response = await session.get(url=url, headers=self.headers)
response = await session.get(url=url, headers=self.headers, params=params)

if response.status == 200:
transaction_data = await response.json()
Expand Down Expand Up @@ -173,13 +177,15 @@ async def bridge(
if swap_rate is False:
return

swap_path = await self.get_swap_path(from_chain, to_chain, amount)
prepare_transaction = await self.prepare_transaction(from_chain, to_chain, amount)

if swap_path is False:
if prepare_transaction is False:
return

logger.info(f"[{self.account_id}][{self.address}] Bridge {from_chain} –> {to_chain} | {amount} ETH")

tx_data = await self.get_tx_data(amount_wei)
tx_data.update({"to": self.w3.to_checksum_address(swap_path["deposit_address"])})
tx_data.update({"to": self.w3.to_checksum_address(prepare_transaction["to_address"])})

signed_txn = await self.sign(tx_data)

Expand Down
5 changes: 3 additions & 2 deletions modules_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ async def bridge_layerswap(account_id, key):

all_amount = True

min_percent = 40
max_percent = 40
min_percent = 5
max_percent = 5

layerswap = LayerSwap(account_id=account_id, private_key=key, chain=from_chain)
await layerswap.bridge(
Expand Down Expand Up @@ -263,6 +263,7 @@ async def custom_routes(account_id, key):
– deposit_scroll
– withdraw_scroll
– bridge_orbiter
– bridge_layerswap
WRAP:
– wrap_eth
– unwrap_eth
Expand Down

0 comments on commit cd5efee

Please sign in to comment.