原文标题:《 Paradigm backs disruptive crypto companies, protocols, and currencies with as little as $1M and as much as $100M+ 》
Source: Dave White, Dan Robinson, Hayden Adams The first two are partners in Paradigm research and the second is & NBSP; Uniswap The founder of
Text compilation: chain smell
This paper introduces a new type of automated market maker (AMM) that helps traders on Ethereum efficiently execute large orders.
We call them time-weighted automatic market makers (TWAMM) (pronounced "tee-wham").
It works by splitting long-term orders into an infinite number of infinitesimal pieces and using the embedded constant product AMM to execute them smoothly with time spans.
If Alice wants to buy 100 million USDC worth of ETH on the chain, it is very expensive to execute an order of this size on an existing AMM such as Uniswap, and they have to charge Alice a high price in case Alice knows something they don't.
At the moment, Alice's best option is to manually break her order into pieces and execute them over a few hours, giving the market time to realize she has no inside information and give her a better price.
If she sends several very large sub-orders, each order will still have a significant impact on the price and be vulnerable to a malicious trader's sandwich attack. On the other hand, if she sends a lot of small sub-orders, she will have to take on the huge workload and risk of active trading and pay gas fees on a transaction-by-transaction basis, thus incurring high costs to the miners.
TWAMM can help Alice solve this dilemma by trading on her behalf. TWAMM splits her orders into infinite infinitesimal virtual orders to ensure that they are executed flawlessly, taking advantage of the time span, and uses special functional formulas embedded in AMM to spread gas costs across these virtual orders. Because it processes transactions between blocks, it is also less vulnerable to sandwich attacks.
In a market involving two types of financial assets, such as USDC and ETH, the market maker is a participant in the market and is willing to trade one asset for the other at any time.
If you have a $100 million USDC and want to use it to buy ETH, you may not be able to find someone who wants to do the opposite at exactly the same time. Instead, you are likely to enter a market of one or more market makers and trade with them.
Adverse selection
Market-makers take advantage of the spread, which is essentially what they charge for each trade. They lose money when the price moves in the opposite direction to their trade (for example, when they buy an asset and its price subsequently falls, or when they sell it and its price subsequently rises).
Unfortunately for market makers, prices often move in the opposite direction. This phenomenon is known as "adverse selection". This happens because traders who have information about future price movements are more likely to make large trades with market makers.
The most dangerous orders are those that are large and urgent, because these are the types of orders that informed traders tend to place. Therefore, the most basic market-making strategy is to fade in orders, raising the price when there is a big buy and lowering the price when there is a big sell.
Automated Market Maker (AMM)
Automated AMMs, led by Uniswap, have become hugely popular on Ethereum over the past year, handling billions of dollars in daily transactions. As the name suggests, AMM automates much of the market-making process.
Constant product formula
The constant product formula is a simple rule that allows anyone to instantly create a new market and a new AMM for a new pair of assets.
In order to create a new constant product AMM (CPAMM) between two assets X and Y, a user called a "liquidity provider" (LP) deposits reserves X and Y in both asset forms.
The ratio of these two assets at any time represents the instantaneous price on the AMM, or the price it charges for very small orders. For example, if a CPAMM's reserve asset contains 2,000 USDC and 1 ETH, the instantaneous price of its ETH will be 2,000 USDC.
When a trader trades with AMM, AMM will decide what price to quote the trader according to the formula x * y = k, where x and Y respectively represent the reserve size of the two assets, and k is a constant. This means that the product of the two reserves remains constant throughout the transaction (fees are ignored).
Suppose a CPAMM containing ETH/USDC assets has 2,000 USDC and 1 ETH in its reserve assets, so x = 2,000, y = 1 and x * y = k = 2,000. The instantaneous price of the AMM is 2,000/1 = 2,000 USDC/ETH.
A trader comes in and wants to buy 2000 USDC ETH, which means he has to put 2000 USDC in reserve X, so we have x=2000+2000=4000.
If k = 2000, we must get y = k/x = 2000/4000 = 0.5 after the above transaction. Since y was originally 1,1 -- 0.5 = 0.5 ETH, the above trader gained 0.5 ETH in this transaction.
Since traders bought 0.5 ETH for 2000 USDC, the average price they actually paid was 4,000 USDC/ETH. The relationship between high prices and instantaneous prices reflects that large orders are closely related to AMM liquidity.
Price shocks and adverse selection
In the above scenario, traders have to pay the high price of 4,000 USDC/ETH for their large order when the small order costs only 2,000 USDC/ETH. This price difference is called the price shock of the order. The larger the incoming order, the greater the impact on prices.
This is AMM's way of fighting adverse selection: large orders are more likely to be knowingly initiated, so AMM makes them pay a high price. It is equivalent to an automated fade in order.
Manually split the order
As we can see, the design mechanism of AMM makes it very expensive to execute a single large order on AMM. This excellent article explores the problem in depth and recommends some solutions.
In short, traders who wish to execute a large order on an AMM should not execute with a single trade: they are better off breaking the order into pieces. This would involve sending orders to more than one AMM at a time, but those AMMs might also have limited liquidity at any given point in time. The bigger the order, the more attractive it is to break it up over time.
For example, suppose an investor wants to buy 100 million USDC of ETH on the chain. They don't have any short-term information on ETH prices, so they don't care if their order takes some time span to execute. In this case, they might break their order into 10 parts of $10 million each and execute one part every hour to limit the price hit to each part.
Suborder size tradeoff
Obviously, if a very large order is broken up into parts, the individual sub-orders of each part are still large and there will be a corresponding price shock. Breaking the order into smaller pieces can reduce costs, but it creates two new problems.
The first problem is the complexity of the operation, which means increased risk and workload. A trader may enter the wrong input value or even choose the wrong direction for a given trade. Or the computer might crash, leaving her unable to execute some orders. Even when all goes well, the process is time and effort consuming, distracting people from more lucrative deals.
The second problem is that each transaction incurs fixed transaction costs, such as the gas paid to ethereum miners to process the transaction. If the trader divides her order into too many parts, she may end up spending more in fees than she actually paid for the ETH.
The traditional finance of other mountain stone
In traditional finance, if an investor or institution wants to buy $100 million of Apple shares, they don't send a $100 million market order directly to the exchange. They also don't send out 10 $10 million orders. For most people who do not have dedicated trading staff and infrastructure, it is impractical to divide orders into much smaller parts than this.
They are likely to send large orders to brokers, who make algorithmic trades for them in exchange for fees. The broker will execute trades over a specified time span, say eight hours, at a benchmark price. The broker will have a team dedicated to executing such trades safely and inexpensively.
TWAP (time weighted Price Algorithm) order
Perhaps the most basic type of algorithmic transaction is a time-weighted price or TWAP (pronounced "tee-whap") order. As the name suggests, a TWAP order to buy $100 million worth of Apple stock over an eight-hour period will be traded at a price close to the time-weighted average of Apple stock over that period.
For example, if Apple stock is priced at $100 for four hours and $120 for four hours during this period, the time-weighted price will be ($100 * 4 + $120 * 4)/8 = $110, and the broker will execute TWAP orders close to that price.
The details vary, but brokers are most likely to execute the trade by breaking the order into many small pieces and sending them to the market over the course of a day. Buying $100 million of Apple stock in eight hours would mean buying about $350 of Apple stock every 100 milliseconds, and the brokerage could indeed live up to its mandate.
With so many small transactions, brokers have the infrastructure to reduce or eliminate the operational complexity involved, and because they are directly linked to the market, they may not have to pay much in transaction costs.
Time-weighted Automatic Market Maker (TWAMM)
Time-weighted Automated Market Maker (TWAMM) provides an on-chain version of TWAP orders. TWAMM has specialized logic for order splitting and is directly linked to an embedded exchange to provide smooth execution at low GAS costs. Arbitrageurs can help TWAMM's embedded exchange price align with the market price, ensuring execution is around the time-weighted average price of the asset.
Each TWAMM instance facilitates transactions between specific asset transaction pairs, such as ETH and USDC.
TWAMM includes an embedded AMM, which is a constant product of the two assets to make the market. Anyone can use this embedded AMM for transactions at any time, just like a normal AMM.
Traders can place long-term orders with TWAMM, which are orders to sell a fixed number of certain assets over a fixed number of blocks -- for example, an order to sell 100 ETH over the next 2,000 blocks.
TWAMM breaks these long-term orders into an infinite number of infinitesimally small virtual suborders that transact with the embedded AMM at a uniform speed over a certain time span. Dealing with these virtual suborders individually, one by one, would cost an infinite amount of gas, but the closed-form mathematical formula allows us to calculate their cumulative impact only when needed.
The execution of long-term orders will drive the embedded AMM price away from the price in other markets over a certain time span. When this happens, arbitrageurs will carry trades based on the embedded AMM's price to bring it back into line with the mainstream market, thus ensuring good execution of long-term orders.
For example, if a long-term sell order makes ETH cheaper on an embedded AMM than on a particular centralized exchange, the arbitrageurs will buy ETH from the embedded AMM, cause its price to rise on that AMM, and then sell it on the centralized exchange for a profit.
block
Ethereum bundles transactions into contiguous groups of blocks, which are produced roughly every 13 seconds. For the sake of clarity in this article, we will number each block: Block 1 is followed by block 2, then block 3, and so on.
The miners
Distributed teams of miners compete to process each block. Anyone with an Internet connection can become an Ethereum miner. This means that applications such as AMM running on Ethereum cannot keep any secrets: everyone must be able to calculate exactly what they would do given input.
Gas
On Ethereum, computing is a scarce resource, so users must pay miners in the form of GAS. The more calculations involved in a given transaction, the more gas it consumes. The gas fee is paid entirely by the person who submitted the transaction.
Orders for a long time
Alice wants to buy 100 million USDC worth of ETH in the next 8 hours (approximately 2,000 blocks). She entered a standing order into TWAMM for 100 million USDC worth of ETH across 2,000 blocks, or 50,000 USDC per block.
As mentioned above, we don't know in advance which miners will be processing future transactions on TWAMM. This means that Alice's order must be visible to everyone, which leads to the information leak problem we discuss below.
Order pool
Bob wants to sell 500 ETH in the next 5,000 blocks in exchange for the USDC, which is 0.1 ETH per block.
Charlie wants to sell 100 ETH in the next 2,000 blocks for USDC, which is 0.05 ETH per block.
Bob's and Charlie's orders will be combined in an order pool until Charlie's order expires after 2,000 blocks.
This ETH sales pool will sell ETH at a rate of 0.15 ETH per block in the next 2,000 blocks. Of the USDC earned by the pool in this way, Bob will get 0.1/0.15 ≈ 66% and Charlie will get 0.05/0.15 ≈ 33%.
Virtual orders
For each of the next 2,000 blocks, TWAMM must buy 50,000 USDC worth of ETH on Alice's behalf and sell 0.15 ETH for USDC on behalf of the ETH sales pool.
We can imagine TWAMM breaking each of these two sub-orders into trillions of tiny sub-orders, which we call virtual orders (in fact, they would be broken down into an infinite number of infinitesimal virtual orders).
TWAMM then takes turns executing these virtual orders with its embedded AMM: first a virtual order from Alice, then a virtual order from the ETH sales pool, then another virtual order from Alice, and so on.
arbitrage
Because Alice buys much more ETH than the ETH pool sells, the PRICE of ETH on an embedded AMM will increase per block.
When this price is high enough relative to ETH prices elsewhere, arbitrageurs will buy cheaper ETH on other exchanges and sell it on this embedded AMM, returning its price to the market average and ensuring that Alice's order is well executed.
Order due
After the 2,000th block, Alice's order has been fully executed, as has Charlie's. Bob's order to sell ETH remains active for the next 3,000 blocks, during which time TWAMM will continue to execute the order at a rate of 0.1 ETH per block.
Unless there is any outside activity, this will drive ETH prices down on embedded AMM over time, this time encouraging arbitrageurs to arbitrage prices back up once they are completely out of line.
Principles of economics
Since neither Alice, Bob, or Charlie is in a hurry to execute their order, other market participants can infer that their order represents less adverse selection than would otherwise be the case, helping them complete the execution of a trade with a low price shock.
Since TWAMM will then be the best place for People like Alice, Bob, and Charlie to trade, LP on embedded AMM in TWAMM may interact with a large amount of uninformed trade flow like theirs. This helps LPS make money from transaction fees while reducing their risk of adverse selection.
Infinitesimal virtual order
We mentioned earlier that TWAMM splits a long order into an infinite number of infinitesimally small suborders. There are two reasons for doing this: fluency and efficiency.
fluency
TWAMM's main goal is to execute its long-term orders smoothly over time so that they execute at prices close to the mainstream time-weighted average price.
As we compress the size of virtual transactions as small as possible, the price curve on AMM gets flatter and flatter.
In the extreme case, with an infinite number of infinitesimally small transactions, price changes are very smooth when virtual transactions are executed.

The efficiency of
Since TWAMM was designed for use on Ethereum, it would be prohibitively expensive to explicitly calculate transactions for multiple virtual transactions per block. However, when we have an infinite number of infinitesimal trades, we can calculate the result for the trader in a single calculation, regardless of how many blocks have passed since the last check.
Implement solution lazy evaluation
TWAMM treats virtual suborders as occurring in the space between blocks, which is important to avoid sandwich attacks.
To do this in a gas-saving way, TWAMM uses lazy evaluation, calculating the impact of a virtual transaction only when the outcome of the interaction needs to be determined.
Each time a user interacts with TWAMM (for example, by using embedded AMM to trade or add a new standing order), TWAMM calculates retrospectively the impact of all virtual transactions that have occurred since the last interaction.
Since these virtual transactions only interact with TWAMM's embedded AMM, the behavior of TWAMM is completely determined between external interactions. Even if TWAMM has a million blocks between external interactions, the next time someone interacts with it, it will be able to accurately calculate the results of all the transactions involved.
The front end plugged into TWAMM will be able to process virtual transactions that have not yet been displayed on the chain by tracking the current block number and doing its own TWAMM calculations.
As the example shows, when we have multiple standing orders in the same trading direction (for example, selling ETH for USDC), we pool them together and then split them into virtual orders. TWAMM can then use the "billion dollar algorithm" used to track fluctuations in LP rewards in protocols such as Compound and Uniswap to track account balances.
Technically, each TWAMM always has two pools of long-term orders, one for each asset: for example, a pool to sell USDC and a pool to sell ETH. At any given time, one or both of these pools may be empty.
A complication arises when order pools are used in combination with lazy evaluation.
Imagine Bob placing an order to sell 100 ETH in the next 100 blocks and Charlie placing an order to sell 200 ETH in the next 200 blocks. Both orders were sold at a rate of 1 ETH per block.
Assuming no one interacts with TWAMM for the next 150 blocks, a new external interaction occurs. For the first 100 blocks after Bob and Charlie placed their order, their orders were pooled into a common order, with each block selling 2 ETH. For the next 50 blocks, however, Charlie's order is independent, with each block selling only 1 ETH.
This meant that we had to do two separate transaction calculations to find out what was happening: one for the first 100 blocks and one for the last 50 blocks. In a worst-case scenario, if each of the past 150 blocks has an order due, this means TWAMM will have to process one transaction per block, and the expected savings in GAS efficiency will be greatly reduced.
The simplest solution to this is to limit the number of blocks that meet the order expiration criteria: For example, TWAMM can specify that the order can only expire once every 250 blocks, or roughly once every hour.
Cancellation of standing order
Users can cancel standing orders at any time. In practice, this allows users to block specific when to cancel their orders. This does not add gas to the system, since customers who want to cancel their orders pay gas themselves.
define
Assume that there have been T blocks since the last time TWAMM executed a virtual transaction.
For simplicity, assume that there are no long-term orders that expire, so the pool selling X sells Xrate in each block over the entire time period, and the pool selling Y sells Yrate in each block over the entire time period.
So the total amount of X sold during this period is txrate=xin , and the total amount of Y sold during this period is tyrate= Yin.
Let's set the AMM asset reserves embedded at the start of the time period to xammStart and yammStart, respectively.
The formula
After processing all virtual transactions, the X reserve in embedded AMM is

At the same time

From the constant product formula, we get

The pool that sells X gets all the Y that is not in the embedded AMM asset reserve -- in other words,

In the same way,

Sandwich attack
describe
During the sandwich attack, the attacker Atticus sees trader Trey about to trade on the AMM. Atticus sent out two orders, turning Trey's into sandwiches and profiting from them.
Imagine that Trey sends an order to AMM to buy ETH with USDC. After seeing the deal, Atticus placed an order to buy ETH on AMM before Trey, driving the price up. Atticus will lose money on the order because he pays AMM and has a price shock.
When Trey's order was executed, he was forced to buy ETH at his higher price because Atticus had pushed up the price. Trey's order pushed the price even higher.
Now Atticus is selling his ETH back to AMM. Since the purchase of Trey has driven up the price on AMM, Atticus can be sold for more than it was bought for and can make a profit.
Such an attack would be profitable for Atticus if it could guarantee to sell its ETH back to AMM immediately after Trey's purchase. Within a given block, it is possible to do this if Atticus is a miner, if he makes a deal with a miner, or if he uses a service like Flashbots.
At first glance, virtual orders seem particularly vulnerable to the sandwich attack because everyone knows they're coming.
However, because they are executed between ** blocks, they are fulfilled. An attacker who wants to clamp a TWAMM virtual order must trade with the embedded AMM at the end of one block, causing the virtual order to execute at a bad price between blocks, and then trade in the other direction at the start of the next block.
Currently, attackers have no way to guarantee that they will only trade at the end of a given block, even if they can trade at the beginning of the next block. This may become a more serious problem as this multi-block miner extractable value (MEV) becomes more common, allowing traders to conduct sandwich attacks across multiple blocks.
The biggest tradeoff that a long-term trader may encounter in TWAMM is the information leak they face when publishing publicly visible orders, which is necessary due to the nature of Ethereum.
If a trader places a large enough long-term order, other traders may want to launch a preemptive trade attack, buying assets in TWAMM's embedded AMM and elsewhere, in order to sell them back to the trader later after the long-term order drives up the price.
Since users can cancel their standing orders at any time, we expect aggressive front-runner attackers to be outflanked by other traders, making the impact of the leak entirely manageable.
The sample
Imagine that scammer Sally has noticed an aggressive pre-emptive attack on TWAMM. She bought a million USDC's ETH from the liquidity aggregator, pushing up prices across the market. She then placed a huge long-term order on TWAMM for 100,000 USDC of ETH per block over the next 24 hours.
Frank, the front-trade attacker, immediately saw the order and purchased 1 million USDC ETH through the aggregator, further driving up the price of ETH. Sally sells her ETH back through the aggregator to make a profit, driving down the price and making Frank suffer a loss. In the end, she canceled her standing orders that never materialized.
You can click here to see a Python reference implementation.
Jupyter notes demonstrate the price behavior of TWAMM with multiple hedging long-term orders and arbitrageurs.
For simplicity, this Python version does not implement gas optimizations like order pools or true lazy evaluation.
We've already sketched out a design for TWAMM, but we're just getting started.
The original link
Welcome to join the official BlockBeats community:
Telegram Subscription Group: https://t.me/theblockbeats
Telegram Discussion Group: https://t.me/BlockBeats_App
Official Twitter Account: https://twitter.com/BlockBeatsAsia