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

[BUG] ERC20 prepare_deposit_collection calculates fees in token base factor, token deposits not working #3048

Open
sh4dowb opened this issue Dec 8, 2022 · 2 comments

Comments

@sh4dowb
Copy link

sh4dowb commented Dec 8, 2022

ETH: 18 subunits
USDT: 6 subunits

Fee amount(902597579.715) is greater than min collection amount(20.0).

Dividing the wanted fee amount by remaining 10^12 results in 0.000902598, which is around the actual ETH fee required (~1 USD)
But convert_from_base_amount function does not calculate fee with parent currency, resulting in this

@sh4dowb
Copy link
Author

sh4dowb commented Dec 8, 2022

I've temporarily fixed this by:

      # We collect fees depending on the number of spread deposit size
      # Example: if deposit spreads on three wallets need to collect eth fee for 3 transactions
      fees = options.fetch(:gas_limit).to_d * options.fetch(:gas_price).to_d / 1000000000000000000 # eth decimals
      amount = fees * deposit_spread.size
      options[:gas_limit] = 21000 # eth gas limit
      transaction.amount = amount
      transaction.options = options
    def create_eth_transaction!(transaction, options = {})
      currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price)
      options.merge!(DEFAULT_ETH_FEE, currency_options)

      amount = (transaction.amount.to_d * 1000000000000000000).to_i # eth decimals

eth is working as well.
also probably you should convert eth amount to token amount for min_collection thingy.

@sh4dowb
Copy link
Author

sh4dowb commented Dec 9, 2022

I realized removing/fixing the "Fee amount is greater than min collection amount" check might also fix this.
810^14 fee is converted to 810^8 by accident, instead of 810^-4
but when sending it will convert 8
10^8 to 8*10^14 again, by accident, so it should send the correct amount. two wrongs make one right lol

either something like above, or calculation of amount again when checking against min_collection must be done to fix this issue.

@sh4dowb sh4dowb changed the title [BUG?] ERC20 prepare_deposit_collection calculates fees in token base factor [BUG] ERC20 prepare_deposit_collection calculates fees in token base factor, token deposits not working Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant