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

Metatransactions backend functionality #350

Open
gamarin2 opened this issue Dec 17, 2021 · 1 comment
Open

Metatransactions backend functionality #350

gamarin2 opened this issue Dec 17, 2021 · 1 comment
Assignees

Comments

@gamarin2
Copy link
Contributor

gamarin2 commented Dec 17, 2021

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)

  1. User A creates a metatransaction for the swap, and adds a tip of 0.05 ATOM, worth $0.11.
  2. User A signs the metatransaction, which is sent to Emeris backend.

(backend)
3. The metatx functionality in Emeris backend picks up the tx, checks that the tip is sufficient.
4. The metatx function adds a transaction fee of 0.1 ROWAN, countersigns the tx.
5. The tx is broadcasted to Sifchain
6. 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:

  1. Run /simulate on the tx, which checks validity of the tx and returns gas estimation.
  2. 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.
  3. Multiply the gas value returned by /simulate with the gas-price obtained previously. Convert the value to dollars using the price oracle.
  4. Convert the value of the tip provided in the metatx in dollars using the price oracle.
  5. If the dollar value of the tip is greater than the dollar value obtained at step 3., append the fees to the metatx using feat: add cli for tips transactions cosmos/cosmos-sdk#10311 (use the gas and gas-prices values of step 3).
  6. Append our signature to the tx.
  7. 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.

@sahith-narahari sahith-narahari self-assigned this Feb 3, 2022
@sgerogia sgerogia changed the title Metatransactions backend service Metatransactions backend functionality Feb 16, 2022
@akc2267
Copy link
Contributor

akc2267 commented Feb 21, 2022

bug on tx flow is blocking this - it's reading 2 signatures but only 1 given - should be fixed in v46

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

3 participants