Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 0xekez/0e96f6a26257f49c341c753345dec9a9 to your computer and use it in GitHub Desktop.
Save 0xekez/0e96f6a26257f49c341c753345dec9a9 to your computer and use it in GitHub Desktop.

Automatic payment for execution of Gas Free CosmWasm

In Gas Free CosmWasm there is a single web2 server that commits messages to the chain, call this piece of software an executor. This gives all the power over what messages get executed to whoever runs the executor. Here I describe a system that allows anyone to run an executor and automatically get paid for doing so.


  1. We extend the Gas Free CosmWasm spec so that whenever a message is committed to the chain a tally for the message sender increases.
  2. The DAO DAO validator votes to send their commission to a payment splitter contract.
  3. This payment splitter sends a percentage of commission to another payment splitter contract that distributes payments proportional to the number of messages sent out of the total messages per block.

In this way the Juno blockchain automatically pays people to execute Gas Free CosmWasm messages.

Picking a commission percentage

In a particular block, let $t$ be the total number of messages sent so far, $r$ be the amount of Juno being distributed to executors this block, $f$ be the average fee for executing a transaction, and $x$ be the number of transactions you submit this block.

$$ profit = r \frac{x}{t+x} - fx $$

For it to be profitable to submit a message, $x>=1 \land profit > 0$ . Per Wolfram Alpha, this happens when,

$$ 0 \le t \lt \frac{r-f}{f} $$

DAO DAO governance controls $r$.

Let $D$ be the target number of messages per block DAO DAO would like to make profitable, $G$ be the maximum amount of gas allowed per transaction, $g$ be the average gas cost of a CosmWasm transaction, and $m$ be the number of transactions required to execute $x$ messages.

$$ \frac{gx}{m} \le G $$

$$ m \ge \frac{gx}{G} $$

To execute $D$ messages per block,

$$ m \ge \frac{gD}{G} $$

Our earlier equation for $t$ tells us the value of $t$ for which it is profitable to submit a single additional transaction. To make it profitable to submit $m$ transactions, we set $t$ to $m-1$ so that it is profitable to submit one more, $m$, transactions.

$$ m - 1 < \frac{r-f}{f} $$

$$ \frac{gD}{G} - 1 < \frac{r-f}{f} $$

$$ r > f\frac{gD}{G} $$

Note that $g$ scales with $f$ as $fee = gas * gasCost$, call $k$ that scaling factor, $f=gk$.

$$ r > g^2\frac{kD}{G} $$

A smart contract can allow governance to select values for these constants and tune the rest of the system appropriately. DAO DAO governance can select values that balance potential for farming with execution rates that keep CosmWasm transactions gas free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment