Constant Sum Automated Market Maker | Solidity 0.8

Поделиться
HTML-код
  • Опубликовано: 16 сен 2024

Комментарии • 39

  • @smartcontractprogrammer
    @smartcontractprogrammer  2 года назад

    0:00 - Intro
    0:45 - State variables and constructor
    3:35 - Internal functions - mint and burn
    5:04 - Swap
    13:20 - Refactor swap function
    19:40 - Add liquidity
    23:48 - Remove liquidity
    26:26 - Fix compilation errors
    26:50 - Deploy
    28:08 - Demo add liquidity
    30:04 - Demo swap
    31:36 - Demo remove liquidity
    CSAMM math
    ruclips.net/video/-JhgcqvyYeM/видео.html
    Code
    solidity-by-example.org/defi/constant-sum-amm
    Take a course
    www.smartcontract.engineer/

  • @Sydra.
    @Sydra. 2 года назад +1

    Most needed Solidity video in EVM's history!

  • @muniapriyansu8805
    @muniapriyansu8805 2 года назад +2

    Ohh lord! Thank you so much SCP for this. I really needed this explanation in solidity

  • @avazB
    @avazB 2 года назад +1

    Excellent youtube channel! THE BEST. Please make more tutorials like complicated contracts etc.

  • @meka4996
    @meka4996 Год назад

    This is more than GOLD! Thank you

  • @hurdurstudy295
    @hurdurstudy295 2 года назад +1

    great video man, love these sort of tutorials !

  • @Flaminia..
    @Flaminia.. 2 года назад

    Great explanation! Very clear!

  • @ChesterSerenity
    @ChesterSerenity Год назад

    Sooo this is how DEX work... thanks a lot!

  • @labadi5723
    @labadi5723 2 года назад

    Great example. Also, a caveat about sandwich attacks could be said. There is no sandwich attack protection within the example!

    • @MrCoreyTexas
      @MrCoreyTexas 2 месяца назад

      I'll hav eto look that up, there are many ways to exploit these contracts ( I don't call them smart, because often they are dumb!) But I think the point of this series is to get you up to speed, he has other videos where he goes over exploits, think of this as a 101 or 102 course.

  • @valentynazaytseva8767
    @valentynazaytseva8767 11 месяцев назад +1

    Why the reserves in 'swap()' are updated by incoming '_amountIn'. Shouldn't they be updated by more precise recalculated 'amountIn'?

  • @呆湾南坡丸
    @呆湾南坡丸 2 года назад +1

    dear scp~ I have some questions.
    1. so as dx will always be equal to dy, the price for x and y will always be 1:1?
    2. what kind of exchange will use this 1:1 price model? as the price will never change?
    3. when adding liquidity into the pool, someone adds 100x and 150y, so the 50y will never be able to withdraw?

    • @smartcontractprogrammer
      @smartcontractprogrammer  2 года назад +1

      1. yes
      2. No exchange. Hybrid of CSAMM and CPAMM exists. (Curve and Yield Space)
      3. X and Y are treated equally. So they will be able to withdraw both tokens

    • @呆湾南坡丸
      @呆湾南坡丸 2 года назад

      ​@@smartcontractprogrammer ok ,maybe just do the dx==dy check when adding the liquidity? In the PAMM you do the dx*y = dy*x.

  • @vivekascoder
    @vivekascoder 2 года назад +1

    I have a question.
    Generally a lot of AMMs handle decimals explicitly in case in which you don't have tokens with same decimals by upscaling the amount and downscaling to make it 18 deicmals.
    Can you tell how important is that ?

    • @smartcontractprogrammer
      @smartcontractprogrammer  2 года назад

      Very important, I forgot to mention in the video

    • @Lopol2010
      @Lopol2010 2 года назад

      @@smartcontractprogrammer haha cool answer :D

  • @MrCoreyTexas
    @MrCoreyTexas 2 месяца назад

    Note what happens if the user tries to swap 1 wei of token0 for token1; they get 0 wei of token1, since 1*997/1000 = 0 in integer math! That's kind of silly, but I did notice that. I saw that AAVE uses fixed point decimal arithmetic, but I guess that has a higher gas cost.

  • @harshitsharma9474
    @harshitsharma9474 2 года назад +2

    Hii... Please also cover a full series of Solidity smart Contracts Audit... Examples....

  • @grayworld9580
    @grayworld9580 2 года назад

    Thank you for your video. And I have a question. There is no need to consider about token price?? Always swap 1:1 token pairs? If initial added liquidity 100:400 then, is it swap 1:1 too?

  • @MrCoreyTexas
    @MrCoreyTexas 2 месяца назад

    If you did away with the private function _update(), what would that do to the gas expenditure? It's be a little more to deploy the contract, since there'd be repetitive code, but wouldn't it save gas for the users when they call swap / addlqiuidity / removeliquidity? I assume there is some gas overhead involved in calling a private function.

  • @givenmahlangu4720
    @givenmahlangu4720 2 года назад

    this is gold!!!!!

  • @MrCoreyTexas
    @MrCoreyTexas 2 месяца назад

    I think on line 13 you should have called totalSupply totalShares to be clearer, just a small disagreement. Because when I see supply, my brain goes, 'supply of what? Shares or tokens?'

  • @user-qf2fm4js1z
    @user-qf2fm4js1z 2 года назад

    Why the red"!"(line 6) disappear after you compile it at 3:36? I have observed that kind of case happened several times in your other class videos? some magic happen?

  • @MrCoreyTexas
    @MrCoreyTexas 2 месяца назад

    At about 31:30 you say you're going to put token 0 (0xD9...) in and get token 1 (0xD8...) out, but you approved a transfer for 10 of token 0 (0xD9), and then you go on to swap 10 of token 1 for 10 of token 0. But you didn't approve a spend of 10 of token 1. What am I missing here?

  • @MrCoreyTexas
    @MrCoreyTexas 2 месяца назад

    why do you even need line 51, isn't amountIn==_amountIn? Maybe it's safer to do it this way? Seems like a waste of gas?

    • @smartcontractprogrammer
      @smartcontractprogrammer  2 месяца назад

      some ERC20 tokens have transfer on fees and other ERC20 token allow transfer of type(uint256).max to mean transfer all the balance

  • @devteepy
    @devteepy Год назад

    Great video 😎. How do we factor in fees into this model?

    • @smartcontractprogrammer
      @smartcontractprogrammer  Год назад +1

      it's usually taken from amount that goes out

    • @devteepy
      @devteepy Год назад

      @@smartcontractprogrammer ooohhh.... got it. Thanks

  • @salem232
    @salem232 2 года назад

    🤓🍜