<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id>https://bwg-loonshots.pages.dev/en/articles</id>
    <title>BWG Loonshots Blog Blog</title>
    <updated>2026-08-31T00:00:00.000Z</updated>
    <generator>https://github.com/jpmonette/feed</generator>
    <link rel="alternate" href="https://bwg-loonshots.pages.dev/en/articles"/>
    <subtitle>BWG Loonshots Blog Blog</subtitle>
    <icon>https://bwg-loonshots.pages.dev/en/img/favicon.svg</icon>
    <rights>Copyright © 2026 Bankware Global.</rights>
    <entry>
        <title type="html"><![CDATA[Can We Return the MEV Left Behind by a Swap to the User?]]></title>
        <id>https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev</id>
        <link href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev"/>
        <updated>2026-08-31T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Revisiting a 2022 design that internalizes post-swap arbitrage with flash liquidity and cross-DEX rebalancing, along with its limits.]]></summary>
        <content type="html"><![CDATA[<p>In 2022, a DeFi swap could finish in seconds. Its economic afterlife did not.</p>
<p>A user makes a large swap through an AMM. The pool's reserve ratio moves, opening a price gap against another DEX.
A searcher spots the gap and immediately submits the opposite trade. The two prices that had drifted apart move closer
again, and the searcher captures the arbitrage profit.</p>
<p>The market appears to have worked as intended: arbitrage brought prices back into line. But the transaction leaves an
uneasy ending for the trader. The user's action created the price gap, and the user paid the slippage and gas. The value
created by that trade went instead to whoever followed it fastest.</p>
<p>At the end of 2022, our question began there.</p>
<blockquote>
<p>What if the arbitrage did not have to wait outside the user's transaction? Could the protocol capture it first and
return the remaining value to the user?</p>
</blockquote>
<!-- -->
<p>This post revisits that question and the design that followed. At the time, we called it a way to "prevent trading
distortion caused by MEV." Several years of research and protocol development have made that language look too broad.
More precisely, this design was <strong>not a universal solution to MEV. It was an attempt to bring some of the backrun value
created by a user's swap inside the transaction itself.</strong></p>
<h2 class="anchor anchorTargetStickyNavbar_SAay" id="the-question-began-with-four-pools">The question began with four pools<a href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev#the-question-began-with-four-pools" class="hash-link" aria-label="Direct link to The question began with four pools" title="Direct link to The question began with four pools" translate="no">​</a></h2>
<p>Our internal simulation used four constant-product pools containing the same token pair. We assigned simple reserve
values to each pool and calculated how to bring their diverging ratios back toward balance after a swap moved one side.</p>
<p>The spreadsheet contained neither a complex market nor a sophisticated searcher competition. It had only the simplest
AMM, with every pool maintaining <code>a * b = k</code>. Yet this small model made one important question unusually clear.</p>
<p>If a user's swap leaves a price difference behind, the protocol executing that swap could perform the offsetting trade
before an external arbitrageur closes the gap. If the protocol then returns the resulting net surplus to the user, the
same price-recovery process ends with a different allocation of value.</p>
<p>The goal is not to eliminate arbitrage. It is to change <strong>who performs it and who receives its proceeds</strong>.</p>
<h2 class="anchor anchorTargetStickyNavbar_SAay" id="from-observation-to-return">From observation to return<a href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev#from-observation-to-return" class="hash-link" aria-label="Direct link to From observation to return" title="Direct link to From observation to return" translate="no">​</a></h2>
<p>At the center of the design is an aggregator that watches two or more DEXs. Translated from the component names in the
patent specification into an execution sequence, the flow looks like this:</p>
<ol>
<li class="">Read the reserves and swap prices of the same token pair across multiple DEXs.</li>
<li class="">Detect the ratio change caused by the user's swap and the resulting price difference between DEXs.</li>
<li class="">Calculate the gross proceeds and every execution cost of a cross-DEX swap.</li>
<li class="">Only when the net result is positive, borrow the relatively overvalued token through a flash loan.</li>
<li class="">Sell on the DEX where the token is overvalued and buy it back on the DEX where it is undervalued.</li>
<li class="">Repay the flash loan and return the remaining net surplus as price improvement or a refund to the user.</li>
</ol>
<p>A flash loan does not manufacture profit. It provides the liquidity needed to close an existing price gap within one
execution flow without requiring the protocol to supply its own capital. If the principal and premium cannot be repaid
in the same transaction, the entire execution reverts. This is why the
<a href="https://developers.uniswap.org/docs/protocols/v2/concepts/flash-swap" target="_blank" rel="noopener noreferrer" class="">Uniswap v2 flash swap documentation</a> lists
arbitrage as a representative use case.</p>
<p>The existence of a price difference is therefore not sufficient. The following value must be positive:</p>
<div class="language-text codeBlockContainer_ZGJx theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_kX1v"><pre tabindex="0" class="prism-code language-text codeBlock_TAPP thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_AdAo"><div class="token-line" style="color:#393A34"><span class="token plain">user price improvement = gross cross-DEX arbitrage</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">                       - DEX fees</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">                       - flash-loan premium</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">                       - gas and execution overhead</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">                       - protocol fee, if any</span><br></div></code></pre></div></div>
<p>A real implementation should stop the entire path when this value falls below its minimum-profit threshold or when the
user's <code>minOut</code> cannot be satisfied.</p>
<h3 class="anchor anchorTargetStickyNavbar_SAay" id="working-through-the-numbers">Working through the numbers<a href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev#working-through-the-numbers" class="hash-link" aria-label="Direct link to Working through the numbers" title="Direct link to Working through the numbers" translate="no">​</a></h3>
<p>Assume that immediately after the user's swap, two pools containing the same A/B pair have the following state:</p>
<table><thead><tr><th>Pool</th><th style="text-align:right">A reserve</th><th style="text-align:right">B reserve</th><th style="text-align:right">Marginal price of A (<code>B/A</code>)</th></tr></thead><tbody><tr><td>DEX A</td><td style="text-align:right">100</td><td style="text-align:right">100</td><td style="text-align:right">1.0 B</td></tr><tr><td>DEX B</td><td style="text-align:right">100</td><td style="text-align:right">120</td><td style="text-align:right">1.2 B</td></tr></tbody></table>
<p>A is relatively more valuable on DEX B, so a candidate cycle borrows A, sells it on DEX B, and uses the received B to
buy A back on DEX A. With a 0.3% swap fee on both pools, the output for an input amount <code>q</code> is:</p>
<div class="language-text codeBlockContainer_ZGJx theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_kX1v"><pre tabindex="0" class="prism-code language-text codeBlock_TAPP thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_AdAo"><div class="token-line" style="color:#393A34"><span class="token plain">gamma = 1 - 0.003 = 0.997</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">amountOut = reserveOut * gamma * q</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">            / (reserveIn + gamma * q)</span><br></div></code></pre></div></div>
<p>Now assume a 0.05% flash-loan premium and a gas cost valued at 0.01 A. Under these assumptions, the loan size that
maximizes net profit is approximately 4.196 A. Rounding it to 4.2 A for readability gives the following calculation:</p>
<div class="language-text codeBlockContainer_ZGJx theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_kX1v"><pre tabindex="0" class="prism-code language-text codeBlock_TAPP thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_AdAo"><div class="token-line" style="color:#393A34"><span class="token plain">1. Borrow 4.2 A through a flash loan</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">2. Swap 4.2 A -&gt; 4.822925 B on DEX B</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">3. Swap 4.822925 B -&gt; 4.587851 A on DEX A</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">gross cross-DEX profit    4.587851 - 4.2     = 0.387851 A</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">flash-loan premium        4.2 * 0.0005       = 0.002100 A</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">gas cost valued in A                            0.010000 A</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">net surplus returned to user                    0.375751 A</span><br></div></code></pre></div></div>
<p>The two 0.3% DEX fees are already included in the <code>amountOut</code> calculations. With no protocol fee and all surplus paid
in A, the user receives approximately 0.375751 A in improvement. If the surplus is converted into B, the user's output
token, that conversion's fee and price impact must be included as well.</p>
<p>After the cycle, the marginal price of A is approximately 1.0986 B on DEX A and 1.1053 B on DEX B. The fact that the
prices do not become exactly equal is not an error. In a market with fees, a difference smaller than the cost of two
swaps is no longer profitable, leaving a no-arbitrage band. This example shows why "maximize net profit after costs" is
closer to a real execution condition than "make every pool ratio identical."</p>
<h3 class="anchor anchorTargetStickyNavbar_SAay" id="translating-the-flow-into-code">Translating the flow into code<a href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev#translating-the-flow-into-code" class="hash-link" aria-label="Direct link to Translating the flow into code" title="Direct link to Translating the flow into code" translate="no">​</a></h3>
<p>Pseudocode that separates pre-execution simulation from onchain execution might look like this:</p>
<div class="language-text codeBlockContainer_ZGJx theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_kX1v"><pre tabindex="0" class="prism-code language-text codeBlock_TAPP thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_AdAo"><div class="token-line" style="color:#393A34"><span class="token plain">function swapWithInternalizedArbitrage(order):</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    snapshot  = readEligiblePools(order.pair)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    baseline  = simulateBestUserRoute(order, snapshot)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    candidate = optimizeCrossDexTrade(baseline.postSwapState)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    if candidate.netSurplus &lt;= MIN_PROFIT:</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">        return executeBaselineSwap(order, baseline)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    result = atomicExecute([</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">        validateQuotes(snapshot, order.deadline),</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">        executeUserSwap(order, baseline.route),</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">        flashBorrow(candidate.borrowToken, candidate.amount),</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">        executeCrossDexTrade(candidate.route),</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">        repayFlashLoan(),</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">        convertSurplusTo(order.tokenOut),</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">        refundSurplus(order.owner),</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    ])</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    require(result.totalUserOut &gt;= order.minOut)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    require(result.totalUserOut &gt;= baseline.userOut)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    require(result.flashLoanRepaid)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    require(result.netSurplus &gt; MIN_PROFIT)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    require(result.unaccountedBalance &lt;= DUST_LIMIT)</span><br></div></code></pre></div></div>
<p>Whenever possible, <code>baseline.userOut</code> should be calculated from execution-time state or a signed quote with a bounded
validity period. Otherwise it may become an impossible guarantee when the price moves between simulation and block
inclusion. If refunds are not normalized into the user's output token, comparing <code>totalUserOut</code> also requires a trusted
price reference.</p>
<p>The important part of this pseudocode is not merely that the arbitrage succeeds. The following invariants must hold at
the same time:</p>
<ul>
<li class="">The internalized path must not leave the user worse off than the baseline path.</li>
<li class="">The flash-loan principal and premium must be repaid in full during the same execution.</li>
<li class="">A minimum net surplus must remain after every cost has been deducted.</li>
<li class="">Every residual token must be accounted for as a user refund, an explicit fee, or permitted dust.</li>
<li class="">If any condition fails, the full path, including the user swap, must revert, or the system must safely fall back to
the baseline route.</li>
</ul>
<h2 class="anchor anchorTargetStickyNavbar_SAay" id="the-equation-was-a-starting-point-not-the-answer">The equation was a starting point, not the answer<a href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev#the-equation-was-a-starting-point-not-the-answer" class="hash-link" aria-label="Direct link to The equation was a starting point, not the answer" title="Direct link to The equation was a starting point, not the answer" translate="no">​</a></h2>
<p>The 2022 model began by naming the two reserves in each pool <code>a_i</code> and <code>b_i</code>:</p>
<div class="language-text codeBlockContainer_ZGJx theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_kX1v"><pre tabindex="0" class="prism-code language-text codeBlock_TAPP thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_AdAo"><div class="token-line" style="color:#393A34"><span class="token plain">k_i = a_i * b_i</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">A = sum(a_i)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">B = sum(b_i)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">S = A / B</span><br></div></code></pre></div></div>
<p>Here, <code>S</code> is a target ratio derived from the aggregate reserves of all reference pools. The model calculates target
reserves that preserve each pool's invariant while moving its reserve ratio toward <code>S</code>:</p>
<div class="language-text codeBlockContainer_ZGJx theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_kX1v"><pre tabindex="0" class="prism-code language-text codeBlock_TAPP thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_AdAo"><div class="token-line" style="color:#393A34"><span class="token plain">a_i' = sqrt(S * a_i * b_i)</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">b_i' = (a_i * b_i) / a_i'</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">required trade direction and amount = a_i' - a_i</span><br></div></code></pre></div></div>
<p>When <code>a_i' - a_i</code> is positive, the pool requires a trade that sends token A into it. When it is negative, the trade
must move in the opposite direction. The idea was to aggregate the required amounts across pools, determine which token
to borrow and how much, execute the cross-DEX swaps, and repay the loan.</p>
<p>The equations are concise. That is also why they carry so many assumptions.</p>
<p>The model assumes fee-free constant-product AMMs. It does not account for concentrated liquidity, different fee tiers,
or stable-swap curves. Nor is <code>S=A/B</code> an external fair price. It is an internal reference derived from the selected
pools, making it sensitive both to pool selection and reserve manipulation. When the price of token A is quoted in B,
the price direction may be the inverse of the reserve ratio, so the notation must be made explicit as well.</p>
<p>It is also not enough to verify that each pool preserves <code>k</code>. The entire path must account for token conservation, the
flash-loan principal and premium, what remains after repayment, and the token in which that remainder is delivered to
the user.</p>
<p>The equations are therefore better understood not as a finished optimization algorithm, but as <strong>a first model that
reveals where arbitrage exists and in which direction a trade must move</strong>.</p>
<h2 class="anchor anchorTargetStickyNavbar_SAay" id="what-it-means-to-bring-the-trade-inside-the-transaction">What it means to bring the trade inside the transaction<a href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev#what-it-means-to-bring-the-trade-inside-the-transaction" class="hash-link" aria-label="Direct link to What it means to bring the trade inside the transaction" title="Direct link to What it means to bring the trade inside the transaction" translate="no">​</a></h2>
<p>Atomicity is the most important boundary of this approach.</p>
<p>If the user swap and the subsequent loan, cross-DEX swaps, repayment, and refund can be combined into a single
transaction, an outside participant cannot insert its own transaction between those internal calls. If any profit or
repayment condition fails, the entire transaction can revert.</p>
<div class="language-text codeBlockContainer_ZGJx theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_kX1v"><pre tabindex="0" class="prism-code language-text codeBlock_TAPP thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_AdAo"><div class="token-line" style="color:#393A34"><span class="token plain">ordering inside the block is controlled by the builder</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">┌────────────────────────────────────────────────────────────┐</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">│ attacker transaction: can be placed before the whole path  │</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">├────────────────────────────────────────────────────────────┤</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">│ our single transaction                                     │</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">│ quote check -&gt; user swap -&gt; flash borrow -&gt; cross-DEX swap │</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">│             -&gt; repayment -&gt; user refund                    │</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">│ no external transaction can enter between these calls      │</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">├────────────────────────────────────────────────────────────┤</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">│ attacker transaction: can be placed after the whole path   │</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">└────────────────────────────────────────────────────────────┘</span><br></div></code></pre></div></div>
<p>This does not solve transaction ordering as a whole. A builder or proposer can still place another transaction before
or after this transaction. If the user's order reaches the public mempool first, frontrunning and sandwiching of the
entire transaction remain possible. Atomicity between internal calls and transaction-level ordering protection within
a block are different problems.</p>
<p>This is why private order flow, batch auctions, intents, and builder-level protection matter.
<a href="https://docs.cow.fi/" target="_blank" rel="noopener noreferrer" class="">CoW Protocol</a> uses batch auctions and Coincidence of Wants, while
<a href="https://www.flashbots.net/" target="_blank" rel="noopener noreferrer" class="">Flashbots</a> addresses private transactions and MEV revenue sharing along a different axis.
These designs are not competing versions of one answer; they address different attack surfaces.</p>
<p>A minimal threat model for this design, organized around its execution boundary, looks like this:</p>
<table><thead><tr><th>Attack surface</th><th>Possible failure</th><th>Required defense</th></tr></thead><tbody><tr><td>Builder / proposer</td><td>Place transactions before or after the entire path, or delay inclusion</td><td>Private submission, deadline, <code>minOut</code>, quote-validity checks</td></tr><tr><td>Shallow or manipulated reference pool</td><td>Temporarily change reserves to induce a false target price and trade size</td><td>Minimum liquidity, deviation limits, external reference price, per-pool weighting</td></tr><tr><td>Malicious DEX adapter</td><td>Return false values, trigger arbitrary callbacks, or reenter to drain balances</td><td>Adapter allowlist, balance-delta accounting, reentrancy guard</td></tr><tr><td>Stale state</td><td>Change reserves after simulation, breaking profitability or repayment conditions</td><td>Revalidate at execution, enforce minimum profit, revert the full path</td></tr><tr><td>Non-standard token</td><td>Make expected amounts diverge through fee-on-transfer, rebasing, or callbacks</td><td>Restrict supported tokens, settle from actual balance changes, enforce dust limits</td></tr></tbody></table>
<p>What the contract can directly guarantee is the state transition and balance invariants inside the middle transaction.
Order exposure and block ordering outside that boundary require a separate delivery channel and market structure.</p>
<h2 class="anchor anchorTargetStickyNavbar_SAay" id="which-mev-does-this-actually-reduce">Which MEV does this actually reduce?<a href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev#which-mev-does-this-actually-reduce" class="hash-link" aria-label="Direct link to Which MEV does this actually reduce?" title="Direct link to Which MEV does this actually reduce?" translate="no">​</a></h2>
<p>The design targets a narrow scope:</p>
<ul>
<li class="">Residual arbitrage left across DEXs immediately after a user's swap</li>
<li class="">External backrun competition for that arbitrage</li>
<li class="">A value-allocation rule in which none of the surplus, after costs, returns to the user</li>
</ul>
<p>The following problems remain:</p>
<ul>
<li class="">Frontrunning and sandwiching around the entire transaction</li>
<li class="">Transaction inclusion, exclusion, reordering, and censorship by builders</li>
<li class="">Other forms of MEV, including liquidations and oracle manipulation</li>
<li class="">Manipulated reference pools or an incorrect target ratio</li>
<li class="">Stale quotes, malicious adapters, callbacks, and reentrancy</li>
<li class="">Execution failure when fees and gas exceed the arbitrage profit</li>
</ul>
<p>This is why we would not repeat the original phrases "prevent MEV damage" or "eliminate slippage" without qualification.
A more accurate description is <strong>internalization of swap-induced arbitrage</strong>. The approach does not eliminate the
economic role of arbitrage. It changes the execution path and allocation rule so that its value does not flow only to an
external searcher.</p>
<p>This distinction matters from the LP's perspective as well. As the
<a href="https://arxiv.org/abs/2208.06046" target="_blank" rel="noopener noreferrer" class="">Loss-Versus-Rebalancing paper</a> explains, arbitrage between an AMM and an external
market is also connected to LP performance. Returning the arbitrage to the user does not eliminate the underlying
adverse selection. The beneficiary may change, but the source of that value must still be measured separately.</p>
<h2 class="anchor anchorTargetStickyNavbar_SAay" id="the-question-was-not-ours-alone-in-2022">The question was not ours alone in 2022<a href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev#the-question-was-not-ours-alone-in-2022" class="hash-link" aria-label="Direct link to The question was not ours alone in 2022" title="Direct link to The question was not ours alone in 2022" translate="no">​</a></h2>
<p>We cannot call this idea the first of its kind. Similar questions appeared elsewhere around the same time.</p>
<p>In August 2022, <a href="https://medium.com/wowmax-exchange/wowmax-fc317c63eae6" target="_blank" rel="noopener noreferrer" class="">WOWMAX described</a> executing a swap and
arbitrage within one atomic transaction, rebalancing prices across DEXs, and returning the profit to the trader. Later,
the <a href="https://app.uniswap.org/whitepaper-uniswapx.pdf" target="_blank" rel="noopener noreferrer" class="">UniswapX whitepaper</a> described filler competition, routing, and
batching as ways to internalize MEV and return surplus as price improvement.</p>
<p>The implementations differ, but they share one question:</p>
<blockquote>
<p>Must the surplus created by a user's order always belong to the fastest searcher?</p>
</blockquote>
<p>The small 2022 spreadsheet is interesting not because it contained an exclusive answer. It shows that several designs
were converging on the same question, and that a protocol can design not only how an order executes but also <strong>who
receives the value left behind by that execution</strong>.</p>
<h2 class="anchor anchorTargetStickyNavbar_SAay" id="the-patent-and-the-decision-to-disclose">The patent and the decision to disclose<a href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev#the-patent-and-the-decision-to-disclose" class="hash-link" aria-label="Direct link to The patent and the decision to disclose" title="Direct link to The patent and the decision to disclose" translate="no">​</a></h2>
<p>The design discussed in this post is described in Republic of Korea Patent No. 10-2564770, "Token Swap System and
Method Through a Decentralized Exchange for Preventing Transaction Distortion," held by Bankware Global Co., Ltd. The
application was filed on January 12, 2023, and the patent was registered on August 3, 2023.</p>
<p>The existence of a patent is neither proof that the technology is complete nor a badge of authority for this post. It
is disclosed here to make the source and history of a design that began in 2022 transparent. Nor does this post itself
constitute a patent license or a non-assertion pledge. Treating the technology as something closer to a public good would
require a separately defined defensive-use policy, patent pledge, or explicit license scope alongside open-source code.</p>
<p>In the blockchain ecosystem, how a patent is used matters more than the mere fact that it exists. The purpose of this
record is not to lead with the right itself. It is to disclose the assumptions and limits of the idea so that someone
else can build a better model.</p>
<h2 class="anchor anchorTargetStickyNavbar_SAay" id="back-to-the-moment-after-the-swap">Back to the moment after the swap<a href="https://bwg-loonshots.pages.dev/en/articles/internalizing-swap-induced-mev#back-to-the-moment-after-the-swap" class="hash-link" aria-label="Direct link to Back to the moment after the swap" title="Direct link to Back to the moment after the swap" translate="no">​</a></h2>
<p>Return to the question from 2022.</p>
<p>If a price gap remains after the user's swap and someone must close it, who should receive the value created in that
process?</p>
<p>This design cannot eliminate MEV. It cannot control every external ordering decision, and a simple reserve ratio should
not be mistaken for a fair price. But it presents one clear alternative: the arbitrage created by a user's action need
not remain solely a prize for external competition. It can be brought inside protocol execution and returned to the
user.</p>
<p>A swap finishes in seconds. Code decides where the value created by that swap ultimately goes.</p>
<p>That was the question we began asking in 2022.</p>]]></content>
        <author>
            <name>BWG Loonshots</name>
        </author>
        <category label="Financial Infrastructure" term="Financial Infrastructure"/>
        <category label="Protocol Engineering" term="Protocol Engineering"/>
    </entry>
</feed>