Metatransactions are coming to the Cosmos SDK to solve a fundamental issue with cross-chain UX: transactions fees.
Each chain accepts only a restricted set of denoms to pay for transactions fees (e.g. ATOM on the Cosmos Hub, AKT on Akash, LUNA and UST on Terra, etc.). The problem is that users generally own a few assets, and not necessarily the ones they need to pay for fees. For example, if a user does not own ROWAN, they can't trade using Sifchain DEX.
To solve this, the SDK will introduce a new type of transaction: metatransactions. Metatransactions are transactions that are signed by the end-user without a transaction fee. Instead of a fee, they can add a tip in whatever currency they own. Then, anyone (in most cases, it will be a backend service that we operate) can pick it up, add a transaction fee countersign the tx and broadcast it. When the tx is processed on chain, whoever signed the tx fee will automatically claim the provided tip.
Example: User A wants to do a simple swap on Sifchain DEX, but they only own ATOM. In this example, we assume the standard tx fee on Sifchain is 0.1 ROWAN, worth $0.1
(frontend)
User A creates a metatransaction for the swap, and adds a tip of 0.05 ATOM, worth $0.11.
User A signs the metatransaction, which is sent to Emeris backend.
(backend)
The metatx functionality in Emeris backend picks up the tx, checks that the tip is sufficient.
The metatx function adds a transaction fee of 0.1 ROWAN, countersigns the tx.
The tx is broadcasted to Sifchain
Transaction is processed, Emeris backend balance looses 0.1 ROWAN and gains 0.05 ATOM.
Description of the Metatx Backend Service
First, we will need a separate endpoint for broadcasting metatxs from the frontend. This endpoint relays the metatx to the Metatx Backend Service (called Service in the rest of this issue), which processes it.
In the first version, the Service will do the following:
Run /simulate on the tx, which checks validity of the tx and returns gas estimation.
If /simulate returns without error, fetch the fee token for the chain the tx needs to be submitted to from the CNS, as well as the gas-price for this token.
Multiply the gas value returned by /simulate with the gas-price obtained previously. Convert the value to dollars using the price oracle.
Convert the value of the tip provided in the metatx in dollars using the price oracle.
If the dollar value of the tip is greater than the dollar value obtained at step 3., append the fees to the metatx using https://github.com/cosmos/cosmos-sdk/pull/10311 (use the gas and gas-prices values of step 3).
Append our signature to the tx.
Broadcast the tx to the chain.
Evolution of the Backend Service
In later versions, we will want to make this service a P2P service, i.e. enable third parties to act as metatx relayers themselves. This is needed primarily for legal reasons.
In essence, we "just" need to add a step 2.5. to the process above:
2.5. broadcast raw metatx to peers
Obviously, we would need to open source this service as a standalone software.
Context
Metatransactions are coming to the Cosmos SDK to solve a fundamental issue with cross-chain UX: transactions fees. Each chain accepts only a restricted set of denoms to pay for transactions fees (e.g. ATOM on the Cosmos Hub, AKT on Akash, LUNA and UST on Terra, etc.). The problem is that users generally own a few assets, and not necessarily the ones they need to pay for fees. For example, if a user does not own ROWAN, they can't trade using Sifchain DEX.
To solve this, the SDK will introduce a new type of transaction: metatransactions. Metatransactions are transactions that are signed by the end-user without a transaction fee. Instead of a fee, they can add a tip in whatever currency they own. Then, anyone (in most cases, it will be a backend service that we operate) can pick it up, add a transaction fee countersign the tx and broadcast it. When the tx is processed on chain, whoever signed the tx fee will automatically claim the provided tip.
Example: User A wants to do a simple swap on Sifchain DEX, but they only own ATOM. In this example, we assume the standard tx fee on Sifchain is 0.1 ROWAN, worth $0.1
(frontend)
(backend)
Description of the Metatx Backend Service
First, we will need a separate endpoint for broadcasting metatxs from the frontend. This endpoint relays the metatx to the Metatx Backend Service (called Service in the rest of this issue), which processes it.
In the first version, the Service will do the following:
Evolution of the Backend Service
In later versions, we will want to make this service a P2P service, i.e. enable third parties to act as metatx relayers themselves. This is needed primarily for legal reasons.
In essence, we "just" need to add a step 2.5. to the process above:
2.5. broadcast raw metatx to peers
Obviously, we would need to open source this service as a standalone software.