Anna Kondratenko 👩🏻‍💻 Profile picture
🤖 Self-studying AI, Big Data, Data Science • TensorFlow, Scikit-learn, Keras, Python • @numerai newbie • Currently doing #100DaysOfDefi challenge •

May 18, 2022, 8 tweets

Day 68 of #100DaysOfDeFI 🚀 Today I worked on the Factory smart contract that is a part of the decentralized exchange architecture 💱  Factory creates and keeps track of all Pair contracts 👩🏻‍💻
#womenwhocode #100DaysOfCode

Summary 🧵

1/ The Factory will include:
🔷 createPair - create a Liquidity Pool;
🔷 adjustAmount - adjust a number of tokens using a formula;
🔷 getReserves - a getter function;
🔷 addLiquidity - add liquidity to the LP;
🔷 removeLiquidity - withdraw liquidity;
🔷 trade1for2 - swap tokens.

2/ First, initialize contract and define the state variables 👩🏻‍💻

3/ adjustAmount function is check if the amounts of the tokens to deposit into the LP have the same proportion as the tokens in the Liquidity Pool 👇

4/ Function getReserves implements the Pair’s getReserves function → for that we create an instance of Pair contract 👩🏻‍💻

5/ addLiquidity function 🤖  adds tokens to a Liquidity Pool 💰 it creates a pair of tokens if it doesn’t exist, checks the number of tokens and adjusts them if necessary 👩🏻‍💻

6/ removeLiquidity function - withdraws the tokens from the Liquidity Pool and returns them to a user’s address 👩🏻‍💻

7/ trade1 for 2: swap the tokens B for A 👩🏻‍💻

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling