Session 12
Agenda
- Welcome
- Hello
- Logistics
- Topic of today
- Module 3
- 1 - Introduction to the Design Phase
- 2 - Variable Definitions and Prices
- Open questions
- Closing
Topics of Today
1 - Introduction to the Design Phase
In the Design Phase we look for a more formal mathematical description of the system.
The Design Phase
In the Discovery Phase, we identified business requirements and the structure of our system. In the Design Phase we translate this information into precise mathematical variables, so we analyze objectives and system optimization in a precise way.
The design phase is an iterative process: the knowledge we gain as we progress impacts the architecture of the system, and that can force us to rethink and redesign parts of it. The Design Phase is neither a sprint nor a marathon. It is more like orienteering: a trial-and-error, step-by-step approach towards a desired outcome.
The goal here is to find a mathematical state space representation of the system, which encodes all quantities in variables. These variables give a total description of the system at any moment in time. This description will also tell how the state of the system changes in reaction to actions of the participants. Having the state system representation creates a kind of roadmap for the system's behavior.

We have already identified two important participants in the system: the liquidity provider and the trader.
The liquidity provider is interested in secure and profitable investments: He wants his assets to gain value and tries to prevent any losses.
The trader may be interested in fast profit by closing price gaps via arbitrage trades, or may just want to exchange one token for another. She is interested in a fast and cheap execution of her trades and wants to avoid both slippage and fees.
Our approach:
We first start with a simplified AMM that does not take into account any fees. We need to identify the specific variables of the system and how they are related to one another. The system should make it possible to trade different tokens; that is, the system takes in a specific amount of one token and hands out the corresponding amount of an other token. Now let's look at the relevant variables for this.
2 - Variable Definitions and Prices
To implement our system, we need to have a mathematical description that reflects the goals and requirements.
Translating To a Mathematical Description
In the Design Phase, we gained a clear understanding of the variables in the system. In moving to a mathematical model, each variable corresponds to a measurable quantity in the real world. The variables we use should be represented by the stocks in our stock-and-flow diagrams.
We need to keep track of things like
- the amount of each token in the pool
- the amount of each token in each trader's wallet
These will allow us to track metrics of interest, including things like liquidity, slippage, impermanent loss, and fees accumulated to the protocol.
Let's start with a very simplified system: a single pool with two types of tokens, and a single trader. We can scale up once we understand this system well.
Defining System Variables
Let's consider the variables that we would need for a simple system with one trader, one liquidity provider, and one pool that holds two tokens.
Step 1: Defining Token Amounts in the Pool
Let’s suppose we have Token X and Token Y in the pool. We can use
- x to represent the amount of Token X in the pool
- y to represent the amount of Token Y in the pool
Step 2: Defining Token Amounts in the Trader's Wallet
We need to track the same things for our trader, so let’s use
- Ax for the amount of Token X the trader has in their wallet
- Ay for the amount of Token Y the trader has in their wallet
Step 3: Pool Shares
In addition to tracking the amounts of each coin, we also need to track the total pool shares held by the pool, and by the agent.
Let's use
- Sp, for the total shares in the pool
- SA, for the total shares held by the agent.


Price is Defined via Trade
Price is a relationship between two assets in a market. Each successful trade defines the latest price.
See the videos in the material from TE Academy for more explanation.
Thinking about price as a ratio helps to illustrate some important properties of constant product market makers and constant sum market makers.
Visualizing Price Using Slope
It's often helpful to plot relationships between amount of Token X and amount of Token Y on an x-y plane. Let's examine that more deeply.
Step 1:

Step 2:

Step 3:

Geometry of Markets and Prices
The key idea to hold onto is the importance of representing the quantities of our system as variables, which can then be analyzed mathematically.
In particular, the definition of these variables is crucial to an understanding of market maker curves where token amounts are represented by numbers, market states are represented as points, and prices are represented by slopes.
The prices in an Automated Market Maker can be understood by using two concepts from Calculus: secant lines and tangent lines.
The video in the TE Academy Material explains more.