Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/rpc/withdraw_and_bridge_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main():
load_dotenv()

# Retrieve the margin account ID from environment variables
account_id = int(os.environ["ACCOUNT_ID"])
account_id = 95681
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just there for testing with my account, need to remove


# Load configuration
config = get_config()
Expand Down
7 changes: 4 additions & 3 deletions sdk/reya_rpc/actions/bridge_in.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import pathlib
from dataclasses import dataclass

from web3 import Web3
Expand All @@ -17,10 +18,10 @@ class BridgeInParams:


# Load contract ABI files
with open("sdk/reya_rpc/abis/SocketVaultWithPayload.json", encoding="utf-8") as f:
with open(pathlib.Path(__file__).parent.parent/"abis/SocketVaultWithPayload.json", encoding="utf-8") as f:
vault_abi = json.load(f)

with open("sdk/reya_rpc/abis/Erc20.json", encoding="utf-8") as f:
with open(pathlib.Path(__file__).parent.parent/"abis/Erc20.json", encoding="utf-8") as f:
erc20_abi = json.load(f)


Expand Down Expand Up @@ -157,7 +158,7 @@ def _build_bridge_transaction(
periphery = config["w3contracts"]["periphery"]
reya_usdc = config["w3contracts"]["usdc"]

periphery_calldata = periphery.encodeABI(fn_name="deposit", args=[(account.address, reya_usdc.address)])
periphery_calldata = periphery.functions.deposit((account.address, reya_usdc.address))._encode_transaction_data()
socket_bridge_options = Web3.to_bytes(hexstr=HexStr("0x"))

return vault.functions.bridge(
Expand Down
32 changes: 26 additions & 6 deletions sdk/reya_rpc/actions/bridge_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,19 @@ def _approve_rusd_spending(config: dict, params: BridgeOutParams):
periphery = config["w3contracts"]["periphery"]
rusd = config["w3contracts"]["rusd"]

tx_hash = rusd.functions.approve(periphery.address, params.amount).transact({"from": account.address})
# Build transaction
tx = rusd.functions.approve(periphery.address, params.amount).build_transaction({
'from': account.address,
'nonce': w3.eth.get_transaction_count(account.address),
'gas': 100000, # Standard gas limit for ERC20 approve
'gasPrice': w3.eth.gas_price,
})

# Sign and send transaction
signed_tx = w3.eth.account.sign_transaction(tx, config["private_key"])
tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f"Approved rUSD to periphery: {tx_receipt.transactionHash.hex()}")
print(f"Approved rUSD to periphery: {tx_receipt['transactionHash'].hex()}")


def _execute_bridge_out_withdrawal(
Expand All @@ -129,18 +139,28 @@ def _execute_bridge_out_withdrawal(
periphery = config["w3contracts"]["periphery"]
rusd = config["w3contracts"]["rusd"]

tx_hash = periphery.functions.withdraw(
# Build transaction
tx = periphery.functions.withdraw(
(
params.amount,
rusd.address,
socket_msg_gas_limit,
dest_chain_id,
account.address,
)
).transact({"from": account.address, "value": socket_fees})

).build_transaction({
'from': account.address,
'nonce': w3.eth.get_transaction_count(account.address),
'gas': 500000, # Higher gas limit for bridge withdrawal
'gasPrice': w3.eth.gas_price,
'value': socket_fees
})

# Sign and send transaction
signed_tx = w3.eth.account.sign_transaction(tx, config["private_key"])
tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f"Initiated bridge out: {tx_receipt.transactionHash.hex()}")
print(f"Initiated bridge out: {tx_receipt['transactionHash'].hex()}")
return tx_receipt


Expand Down