bcnmy / mexa

Repository contains smart contracts for biconomy's Mexa platform to implement meta transactions and allow dapp users to perform blockchain operations without holding any ether or other crypto currency.
MIT License
94 stars 31 forks source link

How do you deduct user ERC20 tokens when user use ERC20 tokens to pay the gas fee? #46

Open etherCrossroads opened 3 years ago

etherCrossroads commented 3 years ago

Maybe user deposit ERC20 to specified contract firstly? Or deposit to your platform? Or user approve ERC20 to your contract and this contract transferFrom user balance?

Your documents(https://docs.biconomy.io/guides/enable-paying-gas-in-erc20) doesn't describe this detail...

livingrock7 commented 3 years ago

It's the later. approve / gasless permit and contract does transfer from based on execution gas.

Pricisely here : https://github.com/bcnmy/mexa/blob/master/contracts/6/forwarder/ERC20Forwarder.sol#L460

Besides execution gas, charge is calculated based on token price / eth price chainlink feeds.

livingrock7 commented 3 years ago

Here is one of the technical threads

https://twitter.com/schin_tomar/status/1375477475493416961?s=21

preston4896 commented 2 years ago

I have a similar question. What happens if a transaction involves an ERC20 transfer that happens to be the same token as req.token ? For example, a user who initially holds 10 USDC wants to make a transfer of 8 USDC, that costs 3 USDC in fees. The user would end up with 2 USDC after executing the inner txn, causing the _transferHandler to revert the txn, with a non-refundable gas cost. I was wondering if there's a good preventive measure for users to not execute such transactions, that could end up with them not being able to pay for fees?

My main concern here is that users may intentionally submit failed txns to dry out the relayer's funds. Would really appreciate some insights.

livingrockrises commented 2 years ago

@preston4896 since the atomicity is maintained and we do gas estimation when transaction goes through relayer infra, If it was gonna fail we don't send it to the chain and stop relay with 417 error. Besides that in the sdk there are checks in place for user balance for transfer and fees, given allowance etc. so yeah there is no on chain check on this but when it goes through relayer infra these measures even the pre flight check (token / eth price volatility) is in place

livingrockrises commented 2 years ago

btw we added another contract for this specific use case of transferring tokens and paying gas fees in same. It allows deployer to sponsor ETH gas fees and same time charge tokens in gas with optional premium.

https://github.com/bcnmy/mexa/blob/internal/forward-v2-RnD/contracts/6/forwarder/TransferHandlerCustom.sol