Conversion path suggestions
bugduino opened this issue · comments
Hi,
I have trouble understanding how should I interact with your contract(s).
I have a currency_id (from /currencies
endpoint) and I need to buy/sell that currency with ETH, how should procede?
I mean I thought I could use some function like
convert(from_id, to_id, amount, min_return)
or
convert(from_token_address, to_token_address, amount, min_return)
instead the main entry point seems to be
function convert(IERC20Token[] _path, uint256 _amount, uint256 _minReturn) public payable returns (uint256)
is there a way to get the correct path for buying or selling a token with ETH?
Thank you
Hey,
You can use the following:
convert(from_token_address, to_token_address, amount, min_return)
If you call a converter directly.
If you call the BancorNetwork contract, you'll indeed need to pass the path as an argument.
You can find the path format in the top comment in the BancorNetwork contract.
Yeah I understand that but how to get a default path which can be used with BancorNetwork convert method?
How does converters work?
Let's say I want to convert ETH to STORM, from the api I see that the only relay related to STORM is STORMBNT which has a changer (BancorConverter) at address 0x58b249b613ce917b6ccc2f66787856ef39f4f0b6.
Should I use the convert function of the STORMBNT changer like this:
convert("0x0", "0xd0a4b8946cb52f0661273bfbc6fd0e0c75fc6433", amount, min_return)
where "0xd0a4b8946cb52f0661273bfbc6fd0e0c75fc6433" is the address of the STORM token ?
in case the conversion is from STORM to ETH I just have to switch the addresses and use the same changer?
If you want to convert STORM to ETH, you must use a path since these two are not directly connected.
In that case you'll need to pass in a path that includes:
STORM -> STORMBNT
STORMBNT -> BNT
BNT -> ETH
So that path would be -
STORM, STORMBNT (smart token that points to the converter), BNT, BNT (smart token that points to the converter), ETH token (0xc0829421C1d260BD3cB3E0F06cfE2D52db2cE315).
Makes sense?
Yes more or less for the case from STORM to ETH, Currently no erc20 token is connected to ETH directly right?
For the opposite case from ETH to STORM is correct the following
ETH -> BTN -> BNT -> STORMBNT -> STORMBNT -> STORM ?
Generally speaking If I want to convert any erc20 token to ETH the path would always be
TOKEN -> TOKENBTN -> TOKENBTN -> BNT -> BNT -> ETH ?
and the opposite case from ETH to TOKEN ?
ETH -> BTN -> BNT -> TOKENBNT -> TOKENBNT -> TOKEN ?
Thank you
Almost :)
The only ERC20 token that's connected to ETH is BNT.
The path however doesn't need to include STORMBNT twice, since you can convert directly between STORM and BNT using the STORMBNT converter.
So the path is actually ETH -> BNT -> BNT -> STORMBNT -> STORM
and the opposite for selling STORM.
Ok seems more clear 👍 Last thing the path (which is an array of addresses right?) can be used directly in the convert function of the BancorNetwork contract? Or I have to use the convert method of the BancorConverter contract of the specific token I am dealing with?
Yeah, you can use the path in the BancorNetwork contract directly.
Just remember that when you call any of these functions, when selling an ERC20, you'll need to provide allowance to the network or converter.
If you try to sell one of the smart tokens (BNT, STORMBNT), no allowance is required since the converter can handle that for you.
Ok, now I have stuff to try :) thank you for your support!
Np! :)
A couple more questions:
- BNT address and BNT (smart token that points to the converter) address are the same? specifically this one 0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c ?
- I currently have ETH but no ETH token, is this wrapping handled by BancorNetwork once I call the convert with a msg.value and the corresponding amount param?
- how does the conversion work for ETH to BNT and BNT to ETH? ETH -> BNT -> BNT and BNT -> BNT -> ETH ?
- Regarding the allowance, I need to grant allowance only to the BancorNetwork contract if I interact only with it? How the allowance works with ETH Token?
- Yup, that's the one -
0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c
- Yes, that's correct
- Yes, that's correct as well, from token is ETH or BNT, the converter is BNT and the to token is ETH or BNT again
- You need to grant allowance to BancorNetwork only when you want to sell an ERC20 token. If you just want to use ETH, no allowance is needed