near:master
← near:evm-precompile
Meta Transaction payments:
We add an extra `(address feeTokenAddress, uint256… feeAmount)` parameter to meta message.
This parameter tells protocol to charge this amount of given token from the signer of the message's account.
Relayer decides if they want to relay such transaction based on the token address and amount -- e.g. if they want to accept payment in DAI or not.
```
fn meta_call(&mut self, args: Vec<u8>) {
let { signature, fee_token_address, fee_amount, contract_id, args } = parse_args(args);
sender = ecrecovery(hash(prepare_message(fee_token_id, fee_amount, contract_id, args)), signature);
// calling ERC20(payment_token_id).transfer(relayer_id, amount) on behalf of the message signer.
let {result, _} = interpreter::call(sender, fee_token_address, erc20_abi::encode::transfer(relayer_id, fee_amount));
if result == failure -> abort
let {result, gas} = interpreter::call(sender, contract_id, args);
let relayer_id = near_account_to_evm(self.predecessor_id);
result
}
```
Flow:
- User indicates to frontend what action they want to execute and what token to pay with
- Frontend queries relayers to get a "quote" on payment. Relayers can decide for themself on amount and if they want to support requested tokens
- User signs a transaction that shows some amount of some token will be charged (or 0x0 if it’s free)
- Any relayer can check again if they want to accept such message with given payment token/amount
- Protocol executed the message and charges user, by transferring to the `predeccessor_id`'s address given amount.
DApp specific relayers can decide to not charge anything, and accept `fee_token_address == 0x0`, which will pretty much waive the payment.
Question:
> Should user (frontend) specify the amount or should amount be inferred from the gas cost + gas amount inside EVM + some mark up to cover for external gas?
Pros for specifying amount, is that relayer can charge whatever they want. User can decide to sign or not based on the cost.
But this may lead to cost of relayer growing is the cost of the gas increased.
Alternatively protocol (`near_evm_runner::EvmContext::meta_call`) knows the current gas costs that are paid and can charge the exact amount that was spent. Relayer paid extra fee.
### Concerns
Relayer grieving
- user signs a message that will pay 1 DAI to relayer to execute tx
- relayer checks that user has 1 DAI
- user transfers out 1 DAI away from account
relayer sends the tx paying $NEAR for fee but tx fails because there is no DAI on users account
I don't think it's a big issue, as user doesn't win anything and 1s blocks prevent doing this really easily as relayer may send their tx faster most of the times.