Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trade_preimage shows too high fee for ERC20 #853

Open
cipig opened this issue Mar 9, 2021 · 11 comments
Open

trade_preimage shows too high fee for ERC20 #853

cipig opened this issue Mar 9, 2021 · 11 comments
Assignees

Comments

@cipig
Copy link
Member

cipig commented Mar 9, 2021

the swap 7df52cbe-4123-4414-8fec-3e51e6916533.txt payed 0.0103168912 Ether for TakerPayment https://etherscan.io/tx/0x4a8726d0de70cb17ff7c979ab3dd432e4d42b29b133482e663d246908e7b78a8 of 55 UNI with gas price 107.8 Gwei

but when i call curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"trade_preimage\",\"base\":\"UNI\",\"rel\":\"KMD\",\"max\":true,\"swap_method\":\"sell\"}" it shows me atm

    "base_coin_fee": {
      "coin": "ETH",
      "amount": "0.0477862"

and https://ethgasstation.info/json/ethgasAPI.json shows atm

   "fast" : 1500,
   "average" : 1160,
   "safeLow" : 1160,
   "fastest" : 1500,

not sure which gas price is used by mm2, but it's max 40% higher than what was payed in 7df52cbe-4123-4414-8fec-3e51e6916533 (107.8 gwei) and that was only 0.0103168912 ETH while trade_preimage shows 0.0477862 ETH

strange is also that the swap JSON from 7df52cbe-4123-4414-8fec-3e51e6916533 contains

               "taker_payment_trade_fee" : {
                  "coin" : "ETH",
                  "amount" : "0.03687915"
               },

while in reality only 0.0103168912 was payed for TakerPayment in that swap

the fee_to_send_taker_fee from trade_preimage seems correct though, 7df52cbe-4123-4414-8fec-3e51e6916533 payed 0.0056782638 Ether in https://etherscan.io/tx/0x42cb2b7ef835c977dce32fcd2bf01cd4c630714d1ad59c8b996bbcf0c987c0ab at 102.3 Gwei and trade_preimage shows me atm

    "fee_to_send_taker_fee": {
      "coin": "ETH",
      "amount": "0.005435014068"
@sergeyboyko0791
Copy link

@cipig thank you for creating the issue!
To send the ETH/ERC20 payment in the worst case you need do 3 smart contract calls: approve, ethPayment/erc20Payment, senderRefund. The trade_preimage reserves 150000 gas for ethPayment/erc20Payment, senderRefund and 50000 gas for approve.
If it's possible to approximate the gas more accurately, as we did for the transfer contract call (using estimate_gas RPC call), that would be great :)

@cipig
Copy link
Member Author

cipig commented Mar 10, 2021

Haven't thought about approve and a possible refund, that explains it. Btw, the above TakerPayment has

Gas Limit: 210,000
Gas Used by Transaction: 55,506 (26.43%)

at least that's what etherscan says: https://etherscan.io/tx/0x42cb2b7ef835c977dce32fcd2bf01cd4c630714d1ad59c8b996bbcf0c987c0ab

@tonymorony
Copy link

It definitely would be great to improve gas calculation estimations. Raw calculations with Artem shown that it's probably possible to reduce it ~3 times

@cipig
Copy link
Member Author

cipig commented Mar 30, 2021

the BEP20 tx also spend less Gas than the limit... from a taker that spent BTC-BEP20 MakerPayment:

Gas Limit: 150,000
Gas Used by Transaction: 54,268 (36.18%)

https://bscscan.com/tx/0x729275e04c8e81b67ec2ab883632f769d10d8ffc89f0a2ffd2170c65ac020c1b

@Milerius
Copy link

Milerius commented Nov 20, 2021

Would like to revive this one @sergeyboyko0791 @tonymorony

Adding a sidechain BTC can now show fees 100% higher than the reality:

image

image

Would be nice if trade_preimage can return best/worst case scenario, so I can use max_taker_vol with best case scenario by default - here I need atleast 40$ of RBTC to be able to place a swap due to trade_preimage calculation

Note that this sidechain on taker side is also affected by #884

@sergeyboyko0791
Copy link

sergeyboyko0791 commented Nov 20, 2021

It's a really big difference in fees. It happens due to the hardcoded 150.000 gas limit for swap contract calls, except approve.
I already worked on integrating estimateGas for every swap contract call. I can continue working on it

@tonymorony
Copy link

Adding a sidechain BTC can now show fees 100% higher than the reality:

what do you mean by "reality" here?

please note that contract execution transactions usually take (at least afaik) much more gas than usual transfer (withdrawal ones)

@Milerius
Copy link

Milerius commented Nov 21, 2021

Adding a sidechain BTC can now show fees 100% higher than the reality:

what do you mean by "reality" here?

please note that contract execution transactions usually take (at least afaik) much more gas than usual transfer (withdrawal ones)

Yes here an approve call is 50000 gas (0.22$) on this chain, but even 9$ estimation ia far from what we really pay

https://explorer.rsk.co/tx/0x1106176fde939f3ea44700592b70ce10f7ba8cfcef34e8ab63ff658669f0d6b0

@cipig
Copy link
Member Author

cipig commented Mar 25, 2023

It's a really big difference in fees. It happens due to the hardcoded 150.000 gas limit for swap contract calls, except approve. I already worked on integrating estimateGas for every swap contract call. I can continue working on it

checked the situation atm again and it looks like this:
image
ADEX Desktop shows 0.29 USD estimate (approve call is not needed anyway for the buyer of a token)

the actual fee payed is 0.10 USD
image
the difference comes from the fixed 150000 gas limit (on BEP20 gas price is always 5 gwei)... of which only 40% were used

@cipig
Copy link
Member Author

cipig commented Jul 24, 2024

we can now set gas limits for each token in part since #2137
so i guess we can now close this issue

@shamardy
Copy link
Collaborator

so i guess we can now close this issue

It's still high for L2 coins/tokens, so I will keep this open until the L2 issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants