Skip to content

Commit

Permalink
fix: remove hardcoded usdc address
Browse files Browse the repository at this point in the history
  • Loading branch information
Divya-Solulab committed Nov 13, 2024
1 parent 22a4ba5 commit e221cfa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions report.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def generate_report():
_print_status(f"Address ({chain_name})", safe_info.get('address', 'N/A'))
_print_status(f"{safe_info.get('token', 'ETH')} Balance", safe_info.get('balance_formatted', 'N/A'))

# Check for USDC balance on Ethereum Mainnet
if chain_id == "1":
# Check for USDC balance on Principal Chain
if chain_name.lower() == optimus_config.principal_chain:
usdc_balance_formatted = safe_info.get('usdc_balance_formatted', 'N/A')
_print_status("USDC Balance", usdc_balance_formatted)

Expand Down
14 changes: 6 additions & 8 deletions wallet_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(message)s')

# Ensure USDC_ADDRESS is set (if not, define it here)
USDC_ADDRESS = USDC_ADDRESS or "0xA0b86991c6218b36c1d19d4a2e9Eb0cE3606eB48" # Ethereum Mainnet USDC address

USDC_ABI = [{
"constant": True,
"inputs": [{"name": "_owner", "type": "address"}],
Expand Down Expand Up @@ -70,9 +67,10 @@ def get_balance(web3, address):
print(f"Error getting balance for address {address}: {e}")
return Decimal(0)

def get_usdc_balance(web3, address):
def get_usdc_balance(web3, address, chain_name):
try:
usdc_contract = web3.eth.contract(address=USDC_ADDRESS, abi=USDC_ABI)
usdc_address = USDC_ADDRESS[chain_name]
usdc_contract = web3.eth.contract(address=usdc_address, abi=USDC_ABI)
balance = usdc_contract.functions.balanceOf(address).call()
return Decimal(balance) / Decimal(1e6) # USDC has 6 decimal places
except Exception as e:
Expand Down Expand Up @@ -137,9 +135,9 @@ def save_wallet_info():
"balance_formatted": f"{safe_balance:.6f} ETH"
}

# Get USDC balance for Ethereum Mainnet (chain ID 1)
if chain_id == "1":
usdc_balance = get_usdc_balance(web3, safe_address)
# Get USDC balance for Principal Chain
if chain_name.lower() == optimus_config.principal_chain:
usdc_balance = get_usdc_balance(web3, safe_address, chain_name.lower())
safe_balances[chain_name]["usdc_balance"] = usdc_balance
safe_balances[chain_name]["usdc_balance_formatted"] = f"{usdc_balance:.2f} USDC"

Expand Down

0 comments on commit e221cfa

Please sign in to comment.