How THRYX Gas Sponsorship Works
6 min read
One of the most common questions we get: "How can trading be free?" It isn't free — someone is paying for gas. The difference is that the protocol pays, not the user. Here's how that works under the hood.
Two Gas Sponsorship Models
THRYX uses two different gasless mechanisms depending on the operation. Launches use a true relay model with EIP-712 signatures. Trades use a pre-funding model where the server sponsors gas for the user's custodial wallet.
Gasless Launches: The Relay Model
When you launch a token, you never submit a transaction. Instead, you sign an EIP-712 typed data message containing the token name, symbol, your address, and a deadline. This signature is sent to the Cloudflare relay at thryx-relay.thryx.workers.dev, which submits the actual transaction by calling metaLaunch(name, symbol, user, deadline, v, r, s) on the Diamond contract. The contract verifies your signature on-chain and credits the token to your address — even though the relay paid gas.
Gasless Trades: The Pre-Funding Model
Trades work differently. The Diamond's buy() and sell() functions use msg.sender to determine who receives tokens and whose balances to check. There's no metaBuy() or metaSell() yet — so a relay can't execute trades on behalf of users without receiving the tokens itself.
Instead, before every trade, the server calls ensureGas(). This function checks the user's wallet balance. If it's below 0.00005 ETH, the gas funder wallet sends a small ETH grant — 0.0001 ETH for buys, 0.0002 ETH for sells (sells need more for the DERC20 approve + reset pattern). The trade then executes from the user's own wallet.
// Gas grant sizes (trade.routes.js)
const SELL_GAS_GRANT = ethers.parseEther('0.0002'); // ~5x margin
const BUY_GAS_GRANT = ethers.parseEther('0.0001'); // ~3x margin
const MIN_GAS_BALANCE = ethers.parseEther('0.00005');
Where Does the Gas Money Come From?
The PaymasterFacet allocates 20% of all swap fees to a gas reserve. This makes gas sponsorship self-funding: as long as people are trading, the protocol generates enough fees to keep sponsoring gas for future trades. The gas funder wallet is the same as the relay key (RELAY_PRIVATE_KEY), keeping operational complexity low.
On Base, gas costs fractions of a cent. A buy transaction uses roughly 300K gas, a sell uses about 400K gas (including approve). At Base's typical gas prices, each trade costs well under $0.01 in gas — so even a small fee reserve can sponsor thousands of trades.
Graceful Degradation
The ensureGas() function is designed to never block a trade. If the funder wallet is too low, or the grant transaction fails, it logs a warning but doesn't throw. The trade proceeds anyway — if the user has leftover gas from a previous grant, it might still work. This "best effort" approach means gas sponsorship failures are silent, not catastrophic.
Monitoring
The /api/gasless/status endpoint exposes the current state: funder wallet address, ETH balance, how many buy/sell grants remain, and the grant sizes. This makes it easy for operators and agents to monitor gas reserves and top up the funder wallet when needed.
Update (v2.6): PaymasterFacet v2 + Relay Worker
As of v2.6, the pre-funding model described above has been replaced. The PaymasterFacet v2 now lives on-chain inside the Diamond contract and holds its own ETH reserves. A Cloudflare Worker relay calls sponsorGas(user) on the contract — no private keys live on the Render server. The contract sends ETH directly to users from its reserves. A background keeper auto-rebalances THRYX to ETH when reserves run low. The gas limit for trades has been bumped to 1.5M to accommodate graduation buys (which can cost 968K+ gas when a token graduates mid-buy). See the "Gas Is Free Forever" post for the full v2.6 architecture.