Fife
Fife

Reputation: 1

PancakeSwap universal router usage. Web3, PancakeSwap, Bsc testnet

I'm working on an integration with PancakeSwap using Java and Web3J. All my tests were conducted on BSC Testnet.

After conducting some research, I used the UI to perform a transaction that went through the Universal Router on BSC Testnet. By examining its ABI, I found out that the transaction utilized the execute method.

The ABI for this method looks like this:

{
  "inputs": [
    {
      "internalType": "bytes",
      "name": "commands",
      "type": "bytes"
    },
    {
      "internalType": "bytes[]",
      "name": "inputs",
      "type": "bytes[]"
    }
  ],
  "name": "execute",
  "outputs": [],
  "stateMutability": "payable",
  "type": "function"
}

It takes in commands, but I'm not sure what exactly needs to be passed there. Similarly, I have trouble understanding what should go into inputs. As far as I understand, it should contain token addresses, my wallet address, and values such as amountIn and amountOut.

I tried using SmartRouter, which has a more straightforward-to-fill method called swapTokenForExactToken. Calling this function was successful, but the number of tokens I received from the exchange differed from what I got when performing the transaction via the UI. Additionally, the gas fee paid was significantly higher than the values I observed during manual swaps via the UI.

I suspect the difference in rates might stem from the fact that Smart and Universal use different pools. Similarly, regarding the gas cost, I think Universal selects a more optimal route for the transaction, so I believe I need to configure work specifically with it.

Do you happen to have any documentation that could help me?
Or perhaps my conclusions are incorrect, and the problem lies elsewhere?
It would be great if someone already has the code snippets I need (it doesn't necessarily have to be in Java; I'll try to figure it out with ChatGPT's assistance).

Any help would be greatly appreciated!

all info in question

Upvotes: 0

Views: 27

Answers (0)

Related Questions