Skip to content

Commit

Permalink
Fix some errors in lifi formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyRoller committed Dec 5, 2024
1 parent a78b5f9 commit 74ddcbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
31 changes: 13 additions & 18 deletions src/wallet/adapters/lifi/lifi_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def get_quote(
Get a quote for a token swap using LiFi API
Args:
token_in: Address of input token
token_out: Address of output token
chain_id: Chain ID for the transaction
token_in: Input token information
token_out: Output token information
amount_in: Amount of input token (in decimal)
Returns:
Expand All @@ -71,8 +72,8 @@ def get_quote(
amount_base_units = str(int(amount_in * Decimal(10 ** token_in["decimals"])))

params = {
"fromChain": chain_id,
"toChain": chain_id,
"fromChain": str(chain_id),
"toChain": str(chain_id),
"fromToken": token_in["address"],
"toToken": token_out["address"],
"fromAmount": amount_base_units,
Expand All @@ -81,7 +82,11 @@ def get_quote(
}

try:
response = requests.get(f"{self.LIFI_API_URL}/quote", params=params)
response = requests.get(
f"{self.LIFI_API_URL}/quote",
params=params,
headers={"accept": "application/json"},
)
response.raise_for_status()
quote_data = response.json()

Expand All @@ -107,9 +112,6 @@ async def swap(self, quote: Dict[str, Any]) -> AsyncGenerator[Dict[str, Any], No
Returns:
Final swap result with transaction details
"""
from_token = quote["action"]["fromToken"]
to_token = quote["action"]["toToken"]

transaction_request = {
"data": quote["transactionRequest"]["data"],
"to": quote["transactionRequest"]["to"],
Expand All @@ -130,23 +132,16 @@ async def swap(self, quote: Dict[str, Any]) -> AsyncGenerator[Dict[str, Any], No
transaction_request, self._wallet._account.key
)

# Yield broadcasting status
yield {
"status": "broadcasting",
"message": "Broadcasting transaction to network...",
"status": "pending",
"message": "Transaction submitted, waiting for confirmation...",
"transaction_hash": tx_hash.hex(),
}

tx_hash = await self._wallet._web3.eth.send_raw_transaction(
signed_tx.raw_transaction
)

# Yield pending status with transaction hash
yield {
"status": "pending",
"message": "Transaction submitted, waiting for confirmation...",
"transaction_hash": tx_hash.hex(),
}

receipt = await self._wallet._web3.eth.wait_for_transaction_receipt(tx_hash)

# Return final result
Expand Down
5 changes: 3 additions & 2 deletions src/wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ def __init__(self, key_path: Optional[str] = None):
assert rpc_url, "RPC_URL is not set"
self._web3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider(rpc_url))
hardhat_private_key = os.getenv("HARDHAT_PRIVATE_KEY")
keyfile = key_path if key_path else "./keyfile"
if hardhat_private_key:
self._account = self._web3.eth.account.from_key(hardhat_private_key)
else:
private_key = self.load_private_key(key_path if key_path else "./keyfile")
elif keyfile:
private_key = self.load_private_key(keyfile)
self._account = (
None
if not private_key
Expand Down

0 comments on commit 74ddcbb

Please sign in to comment.