2

I'm trying to programically use RouteProcessor smart contract by Sushi Swap. Here you can see contract https://etherscan.io/address/0xF70c086618dcf2b1A461311275e00D6B722ef914. I gathered information about all parameters but could not find any description about how to determine route parameter. So how do you generate route?

Thanks for any help.

This is a code that i try to run to swap ETH -> ARB in Arbitrum Nova chain.

from eth_abi import encode
from web3 import Web3

arbitrum_nova_rpc_url = 'https://nova.arbitrum.io/rpc'
wallet_address = '<your address here>'

route_processor_abi = '[{"inputs":[{"internalType":"address","name":"_bentoBox","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"bentoBox","outputs":[{"internalType":"contract IBentoBoxMinimal","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"route","type":"bytes"}],"name":"processRoute","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address payable","name":"transferValueTo","type":"address"},{"internalType":"uint256","name":"amountValueTransfer","type":"uint256"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"route","type":"bytes"}],"name":"transferValueAndprocessRoute","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]'
route_processor_arbitrum_nova_address = '0xaB235da7f52d35fb4551AfBa11BFB56e18774A65'

# Generate route here
arbitrum_nova_ether_address = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
arbitrum_nova_weth_address = '0x722E8BdD2ce80A4422E880164f2079488e115365'
arbitrum_nova_arbitrum_address = '0xf823C3cD3CeBE0a1fA952ba88Dc9EEf8e0Bf46AD'

byte_ether_address = encode(['address'], [web3.to_checksum_address(arbitrum_nova_ether_address)])
byte_weth_address = encode(['address'], [web3.to_checksum_address(arbitrum_nova_weth_address)])
byte_arb_address = encode(['address'], [web3.to_checksum_address(arbitrum_nova_arbitrum_address)])

route = byte_ether_address + byte_weth_address + byte_arb_address

web3 = Web3(Web3.HTTPProvider(arbitrum_nova_rpc_url))

contract = web3.eth.contract(
    address=route_processor_arbitrum_nova_address, 
    abi=route_processor_abi
)

tx = contract.functions.processRoute(
    web3.to_checksum_address(arbitrum_nova_ether_address),  # token in
    web3.to_wei(0.0001, 'ether'),  # amount in
    web3.to_checksum_address(arbitrum_nova_arbitrum_address),  # token out
    0,  # amount out min
    web3.to_checksum_address(address),  # to address
    route # route
)

tx.build_transaction({
    "nonce": web3.eth.get_transaction_count(address),
    "value": 0
})

1
  • hey man , you figured it out ? Nov 12, 2023 at 15:52

2 Answers 2

1

Sushiswap cross-chain swap is plugging into Layer0’s Stargate bridge infrastructure. in this project input of the router's value is based on chainID. I recommend reading this doc for a better understanding.

1 - what's Stargate

2 - sushiswap multichain swap article

3 - starGate gitBook

0

The route parameter should be a bytes value that encodes the path of the tokens to be swapped.

like if you want to swap Ether for ARBITRUM, and the path involves first converting Ether to WETH and then converting WETH to ARBITRUM, the route is like the example below

from eth_abi import encode_single

eth_address = web3.to_checksum_address(arbitrum_nova_ether_address)
weth_address = web3.to_checksum_address(arbitrum_nova_weth_address)
arb_address = web3.to_checksum_address(arbitrum_nova_arbitrum_address)

encoded_eth = encode_single('address', eth_address)
encoded_weth = encode_single('address', weth_address)
encoded_arb = encode_single('address', arb_address)

you just have to concatenate the encoded token addresses to form the route paramete: route = encoded_eth + encoded_weth + encoded_arb then pass this route parameter to the processRoute()

2
  • 1
    Hey, man. First of all thanks for help. I did as you said in your comment, just used another method in eth_abi cause there is no one in new version of library. I still get transaction reverted error. I updated my example with real arbitrum nova data. Can you spot what i did wrong? Apr 15, 2023 at 12:57
  • I modified my answer
    – Saxtheowl
    Apr 15, 2023 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.