Giter Club home page Giter Club logo

homework-2's Introduction

2024-Spring-HW2

Please complete the report problem below:

Problem 1

Provide your profitable path, the amountIn, amountOut value for each swap, and your final reward (your tokenB balance).

Solution

profitable path : tokenB->tokenA->tokenD->tokenC->tokenB

tokenB->tokenA :

amountIn-5 , amountOut-5.655321988655322

tokenA->tokenD :

amountIn-5.655321988655322 , amountOut-2.4587813170979333

tokenD->tokenC :

amountIn-2.45878131709793335 , amountOut-5.0889272933015155

tokenC->tokenB :

amountIn-5.0889272933015155 , amountOut-20.129888944077443

final reward (tokenB balance) : 20.129888944077443

Problem 2

What is slippage in AMM, and how does Uniswap V2 address this issue? Please illustrate with a function as an example.

Solution

Slippage is the difference between the expected price and the actual price of a trade, which is primarily caused by volatility and other factors like the size of the trade and the speed of the chain.

Slippage is unavoidable, but it can be minimized through Slippage tolerance. Uniswap V2 addressed this issue by using "constant product invariant", which ensures the product of the reserve amounts of the two tokens in a trading pair remains constant. When trades occur, the ratio of the reserve amounts changes to maintain this product, which in turn helps to minimize slippage.

alt text

Problem 3

Please examine the mint function in the UniswapV2Pair contract. Upon initial liquidity minting, a minimum liquidity is subtracted. What is the rationale behind this design?

Solution

The rationale behind subtracting a minimum liquidity upon initial minting is aim to require users to provide a minimum amount of liquidity, in order to ensure price stability, efficient trading, and to avoid market manipulation.

Problem 4

Investigate the minting function in the UniswapV2Pair contract. When depositing tokens (not for the first time), liquidity can only be obtained using a specific formula. What is the intention behind this?

Solution

The intention behind this specific formula is to maintain the constant product invariant, which ensures the product of the reserves of the two tokens in the liquidity pool remain constant all the time, which can minimizing slippage for traders.

Problem 5

What is a sandwich attack, and how might it impact you when initiating a swap?

Solution

A sandwich attack is a type of front-running attack that occur in decentralized exchanges. In a sandwich attack, attacker places two transactions around a target transaction in quick succession, aiming to exploit the price movement caused by the target transaction, which can let the attacker profit.

Sandwich attack can make me paying higher prices, acquiring fewer assets, experiencing slower transaction speeds, and facing increased transaction costs when initiating a swap.

homework-2's People

Contributors

bernit-chen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.