Fork Uniswap & Create Your Own Sushiswap | Full Tutorial

Investment Rookie
25 followers
6 Video Views·Oct 28, 2022
40 million USD. It's how much a blockchain developer made for one week of work.
Not a bad hourly rate, right?
And this is not science fiction. I'm talking of Chef Nomi, the developer of SushiSwap.
In order to make that kind of money, Chef Nomi had to create his own
decentralized exchange by forking Uniswap.
So forking a decentralized exchange like Uniswap can obviously pay off massively financially.
And besides this, this is also a great starting point
if you want to create your own decentralized exchange and add new features on top of Uniswap.
And going forward, a forking DeFi project is probably going to be a big trend.
So it's really important to understand how it works.
So in this video, I'm going to give you a step-by-step instruction to fork Uniswap.
You're going to see how to copy and paste the code of Uniswap and deploy it on the blockchain.
We're also going to learn how we can do a vampire attack by taking the liquidity of
an exchange and bringing it to our own exchange.
And before we continue, if you don't already know how Uniswap works,
I recommend to first watch another of my videos on my channel where I introduce Uniswap.
If you don't know me, I'm Julien and on my channel EatTheBlocks,
I teach DeFi blockchain development and how to find your first blockchain job.
And very briefly, quick mention to my two free trainings.
First, if you want to learn how you can become a professional blockchain developer
and make $100,000 a year, you'll find a free training below.
Also, if you want to learn how you can make profitable flash loans,
you'll find another free training.
With software and blockchain, a fork can mean very different things.
So let's clear this up.
First, we have a blockchain fork.
For example, when Bitcoin Cash forked off the main chain of Bitcoin.
So this happened because a part of the Bitcoin community
disagreed with the future evolution of the Bitcoin protocol.
So a part of the Bitcoin community decided to create their own version of the Bitcoin software.
So that means from a certain block in the future,
the miners of this new blockchain will run a different version of Bitcoin called Bitcoin Cash.
If you send a transaction credit for Bitcoin Cash,
it will only work in the branch of Bitcoin Cash and same thing for the main chain of Bitcoin.
On Ethereum, we also had a fork when Ethereum Classic and Ethereum decided to separate.
You can also have forks in blockchain because of technical issues,
but this is usually temporary and resolve itself pretty quickly.
Another kind of fork in the world of software is when you fork a project on GitHub.
So GitHub is a collaborative platform where developers work together to build software,
including blockchain projects.
If you go on GitHub, each project is organized in what we call a repo.
And for each repo, it's possible to create a fork.
When you create a fork on GitHub,
it means you create a copy of the original repo on another repo that you control.
This way, you can make any modifications you want,
create your own project independently of the original project.
This is also the workflow that is used when you want to make a contribution to a project
as an open source contributor.
So this kind of fork is all about code, nothing about blockchain.
And finally, we have DeFi forks like when SushiSwap decided to fork Uniswap.
This happens when some people like an existing DeFi project,
but want to make some modifications
that are not accepted by the community of the original project.
In this case, you say, all right, I'll just do my own version of your DeFi project.
In this case, you need to do a couple of things.
You need to copy paste the code of the original DeFi project.
Then you customize the spot contract and the frontend.
Then you deploy the modified spot contract and frontend.
The last step, if you want to bootstrap liquidity on your DeFi project,
you can create an incentive to steal some liquidity from the first DeFi project.
And we'll see how to do this later in this video.
Okay, so now you understand the different kind of forks in software and blockchain.
So next, we are going to fork the smart contracts of Uniswap.
The first smart contract we need is the factory.
So this is used to create markets for different pairs like Dai Ether, USDC Ether, etc.
This smart contract is located in the Uniswap v2 core repo
in the organization of Uniswap on GitHub.
We could use the fork feature of GitHub,
but this is mainly used for open source contribution.
In our case, we just need to copy this once and after we'll have our own version.
So it's more simple to just download this repo.
If you don't have git installed, you can download the code by clicking here.
But I prefer to use git, it's more clean.
So I've created a folder for this project.
And inside, I'm going to download the repo with the git clone command.
And I copy paste the URL of the repo on GitHub.
Once you have the code locally, you can do your customization.
So here we can go in the Uniswap v2 core folder, contracts.
And here you see the smart contract of Uniswap including the factory.
So you probably at least want to change the name of the smart contract for your project.
But for our tutorial, we are going to keep things simple
and we will not change the smart contract of Uniswap.
So beside the factory contract, there is another contract that we need from Uniswap.
It's the router.
So with the router smart contract, you can use the ecosystem of Uniswap more easily.
So we're going in the organization of Uniswap.
And there is another repo called periphery.
So that's the one that we need.
So I'm going to copy the URL back to my project folder.
And at the root, I'm going to git clone this other repo.
And in this other repo, we also have a smart contract inside the contract directory.
Okay, so we have forked the smart contract of Uniswap.
The next step is to deploy them to the blockchain.
If you look at the code we downloaded from GitHub, there is nothing to deploy the smart contracts.
But because we are smart and lazy, like good programmers always are,
we will not build a deployment system from scratch.
We will use the deployment system of Truffle,
which is the most popular framework for writing solidity smart contracts.
Truffle is written in Node.js.
So you need to install Node.js first.
And after you need to install Truffle with this command.
And after we create a new folder for the core smart contract of Uniswap.
And inside, we are going to initialize a new Truffle project.
So now we have these files inside.
And we are supposed to put all our smart contracts in the contracts folder.
So we are going to copy paste the smart contract of the core repo of Uniswap.
So now if we check what we have in contracts,
then we can see all the contracts of Uniswap.
And after that, we need to create a migration file
to tell Truffle how to deploy the smart contract of Uniswap.
So for that, we create a new file here.
Let's open this.
And as a template, we can use what we have in the initial migration file.
So that's something that is used internally by Truffle.
So let's paste this in our new file.
Then we need to change what we import here.
So we import Uniswap v2 factory.sol.
So we call this factory.
And here, we deploy this factory.
And we also need to give an argument to the constructor.
So for that, we can check out the constructor of the factory.
So here, this is an address.
And that's the address that received the payment for the trading fees.
So we are going to choose the address used by the deployment.
So here, there is a parameter network that we're not going to use.
But after, there is an array of addresses that is available to us.
And by default, the first one is going to be used for the deployment.
So we pass this to the constructor.
So next, we want to deploy a market so that people can trade on our fork of Uniswap.
So for that, first, we need to have a reference to the factory contract.
So we need to await this.
And here, we need to make this async so that we are able to use the await keyword.
And after, to have a reference to the factory, we're going to use factory.deployed.
So it's always a bit confusing that we have to do these two things
to have a reference to a smart contract.
That's because the first statement sends a transaction for the deployment.
And the second statement waits for this transaction to be mined.
And finally, we have our reference.
And when we have this, then we can execute function on the smart contract.
So we want to execute create pair.
So here, it's going to take two arguments, the addresses of the two tokens of this market.
So here, we're going to have two cases.
So if we are doing the deployment to mainnet, let's remove this underscore here.
So in this case, the tokens will already be deployed.
So token one address equals something, token two address another one.
It depends on which market you want to create.
But if we are not deploying to mainnet, for example,
if we deploy to a local development blockchain with Ganache,
or if we deploy to a public testnet like Kovan,
in this case, we will deploy ourselves the ERC20 token for this market.
And for that, we will need to create smart contracts.
So let's go back to the command line.
And first, at the root of the project,
we're going to initialize NPM project.
So after we're going to install OpenZeppelin,
which is a very popular library for Solidity.
And we're going to specify a specific version because we're going to be using
Solidity 0.5 to be compatible with the smart contract of Uniswap.
So we want version 2.5.1.
And after we're going to create two smart contracts,
token1.sol and token2.sol.
All right.
So now we're going to create these contracts.
So for the version of Solidity, we're going to use 0.5.16,
which is the same used by Uniswap.
And we're going to import a contract from OpenZeppelin.
So we want ERC20 detail.sol.
And we also need another contract called ERC20.
And after, we're going to inherit from these two contracts.
And we create a constructor.
And we also trigger the constructor of ERC20 detailed.
You're going to pass it three parameters.
First, the name of the token, then the ticker, then the number of decimal.
So if you check the code of OpenZeppelin on the master branch,
you will see the latest version of OpenZeppelin,
which is different than what I'm showing you here.
So this is the old way of creating an ERC20 token with OpenZeppelin.
And we're going to do the same thing for the other token.
So let's copy this.
Let's open the other file for token2.
And now, we're just going to change here the argument.
So token2, token2, all right.
So now, we're going to open the migration file.
And we're going to import these two token and token2.
And so if we are not deploying to mainnet,
we're going to deploy these two tokens.
Then we're going to get a reference to this token.
And then we save the address, token1 address.
Same for token2.
We pass this to create pair.
OK, and we're good for the deployment script.
And we still need to change the configuration of truffle in truffle-config.js.
So we go at the bottom of the config.
And we're going to specify the correct version of Solidity
that is used by the smart contract of Uniswap, 0.5.16.
OK, so now, we will be able to deploy our contract.
So we're going to exit this.
So we are going to deploy to a local development blockchain on our computer.
So that's the best when you are developing.
And for that, we're going to use a software called Ganache.
So Ganache runs an Ethereum blockchain locally, totally isolated from mainnet.
So you can play around, make mistakes, it doesn't matter at all.
And Ganache also generates 10 addresses pre-funded with 10 fake Ether.
So that's very convenient to send all your transactions.
So in order to install Ganache,
you can do it very easily with npm install global ganache-cli.
And after, you can start Ganache with ganache-cli.
OK, so now it's running at localhost port 8545.
So now, I create a new terminal.
And actually, we still have a configuration to do in Truffle config
if you want to connect to this Ganache blockchain.
So we scroll down in the configuration.
And at some point, you will see comment that a configuration for a network called development.
So that's the one we want.
So host, this is localhost port 8545.
Yeah, so this is correct.
All right, I'm going to create another terminal.
And so now, we can run the deployment script with truffle migrate reset.
And by default, it's going to choose the network development.
But don't need to specify this.
This is the default.
OK, so we have an error here.
So you cannot find token2.
So probably, there is a mistake in the import path token2.solve.
No, the import path is correct.
It's probably the name of the contract.
Let me see token.
OK, yeah.
So here, we haven't changed.
This should be token2.
All right, so let's try again.
And this time, it does work.
Great.
So if we scroll, we can see the address of the Uniswap factory.
Great.
So next, we are going to deploy the router swap contract.
OK, so let me enlarge my terminal here.
And we are going to create a folder for the periphery code, exactly like we did for core.
And we're going to create another truffle project inside.
So we have to separate core and periphery contracts because they use a different version
of Solidity.
And there is no way to deal with this easily in a single truffle project.
So truffle init.
And after, let's copy over the contract.
So we copy from the repo that we got from GitHub.
Contracts.
We put everything in the contracts folder of our truffle project.
So now, here we can see the Uniswap contract, including the router.
And this smart contract has some import paths that reference some NPM packages.
So we need to install these NPM packages.
So first, we init the NPM project.
And after, we're going to install Uniswap slash lib and Uniswap v2 core.
OK.
And next, we need to change the version of Solidity.
So the router contract uses Solidity 0.6.6.
OK.
And after that, we need to create a Wrapped Ether smart contract.
So why we need this?
Because in Uniswap, when you create a market, Uniswap doesn't use Ether, but it uses Wrapped
Ether, which is an S20 token version of Ether.
To deploy factory or pair contracts, you don't need to buy this Wrapped Ether token.
However, for the router contract, it makes use of this Wrapped Ether contract.
So we need it.
So let's create this in the contracts folder.
And after, for the code, we're going to Ether scan.
So on Ether scan, we search for Wrapped Ether.
OK.
This one.
So just a side note.
So it's a bit dangerous to do like I'm doing, searching something on Ether scan and taking
the code from there, because anybody can deploy a contract that I call Wrapped Ether.
So you have to verify in the documentation of Uniswap that this address is correct.
But here, I can see that they have many, many addresses, a lot of Ether in it.
So it's probably the correct one.
And I click on contract, contract.
And here I can see the code.
So we're going to copy the code and paste it in our file.
So we're going to change the version of Solidity to Solidity 0.6.
So let's see if we have to make some changes to make it work.
So in Solidity 0.6, when you emit an event, you need to have the emit keyword.
So we need to add this.
Emit.
All right.
Should be fine.
So now let's try to compile everything to make sure that it works.
Oh, yeah.
The way fallback function at declare is different in Solidity 0.6.
We need to use the receive keyword.
So let's go back in the contract.
And here I call this receive.
OK.
So now it should be fine.
And now we need to replace this by address this.
OK.
So let's do this.
It's a little bit annoying, but when you have code from different places,
you need to harmonize a version of Solidity sometime.
So where do we have this?
So here, address this.
Let's try to compile again.
OK.
And finally, the receive function must be declare external.
So annoying.
But we're almost there.
OK.
So here, external.
Come on, Sweetie.
Give me a break.
Tell me to compile this time.
Yeah.
Finally.
Awesome.
Oh, last thing.
I actually don't want this contract to be called with 9, but just with normal.
This is cleaner like this.
All right.
OK.
So next, we need to write the migration file.
So migration folder.
It creates a file called deploy-contracts.js.
And like we did before, we're going to copy the template from initial migration.
And after, we're going to import the router contract of Uniswap.
So this is called uniswap-v2-router-02.sol.
We're also going to import wrapEther.
So here, we make this function async because we're going to use the await keyword inside.
So we define a variable to point to wrapEther.
And also, we define a constant for the address of the factory.
OK.
So for that, we're going to go to the terminal output of Ganache.
And when we deploy the factory, we add the contract address here.
OK.
Let's copy this.
OK.
And after, if we are deploying on mainnet, and in this case, we don't need to deploy
wrapEther.
It already exists.
So we're just going to connect to the deployed version.
Oh, yeah.
So we need to have the network argument here.
So in this case, the pointer to wrapEther is going to point to the contract.
To get the address, let's go back to Etherscan, where we search wrapEther.
And here, we have the address.
We're just going to copy this to the clipboard and back to our code.
And if this is not mainnet, then we need to deploy the wrapEther.
So in that case, deploy it first.
We wait for the transaction to be mined, and we get a pointer to this contract.
And once we have this, we can finally deploy the router.
Deploy, deploy.
And the first argument of the constructor is the address of the factory and after the
address of wrapEther.
And oh, yeah.
We also need to define in TruffleConfig the development network so that we deploy on the
same network as just before.
Oops.
This was before development here.
Okay.
And so now we're going to the periphery folder.
When we run TruffleMigrateReset, it's going to connect to the same Ganache instance that
we started before.
Even though we started this instance from another folder, it doesn't matter where you
started from.
What matters is the port, the port 8545.
We're connecting to the same port here.
So now we deploy our router, and we have an error.
And it says, did the deployment run out of gas?
Oh, yeah.
I know why.
So there is a problem with the contract of Uniswap, the router.
For some reason, it seems it's actually too big.
So in order to make it work, I had to comment that part of the contract.
So we're going to do the same thing.
Let me scroll down.
Yeah.
So all these functions, swap, exact token, for token supporting fee on transfer tokens.
It's a function that is rarely used.
So we can comment out a lot of this.
So let's comment out everything up to here at this point.
Library functions are important.
We need to keep them.
OK.
So all this block is commented out.
OK.
So now we're going to run the migration command again.
And normally, it should work this time.
Oh, yeah.
So now it complains because basically, we are inheriting from an interface here.
And we don't implement all the functions of this interface.
So in order to solve this problem, we're going to comment out some function of the interface.
And here, we're going to comment out that one.
Swap exact token, supporting fee, blah, blah, blah, like super long function name.
OK.
So now let's run the migration again.
Wow.
That wasn't easy, but we made it.
So one of the big difficulty in forking Uniswap
is that in the repo of the smart contract of Uniswap,
they don't put any code to deploy the smart contract.
So we need to manage this ourself with Truffle.
Another issue is that they separate the smart contract into different repo.
And for each smart contract, they use different version of 3DT.
The router use 3DT 0.6.6.
And the core smart contract use 3DT 0.5.16.
So that forces us to have two separate Truffle project.
So I'll show you how to deploy to a local development blockchain.
But if you want to deploy to a public testnet like Kovan,
or if you want to deploy to Mainnet, the procedure is very similar.
You only have to make a few changes in Truffle config and connect to Infra.
And I already have a video where I explain this.
So in the description of this video, I'm going to link to the other video
where you can learn how to do a deployment to Mainnet or public testnet.
But we are not done yet because we still need to bootstrap the liquidity of our exchange.
So I'm going to show you how you can attack the liquidity
of another exchange exactly like SushiSwap did.
Okay, so now that we have a full Uniswap, it's time to bootstrap our liquidity.
And we are going to do a liquidity attack
by taking some liquidity out of Uniswap into our exchange.
Exactly like SushiSwap did.
So I'm going to explain you how it works.
It has two steps.
So first, you need to get the liquidity provider token.
So these are the tokens you get when you provide liquidity to the Uniswap exchange.
And in order to get this LP token from investors, you need to give some incentives.
So we are going to create a migration contract that gives out some bonus tokens
to anyone who invests in Uniswap LP tokens.
And also, of course, any LP token invested in this migration contract
will be redeemable against LP token of our fork of Uniswap.
So in the end, investor will be able to recover the underlying tokens
they invested initially in Uniswap.
And the second step, once you have attracted enough LP token in your migration contract,
is to actually do the liquidity migration.
So for that, you are going to send all the LP tokens from the migration contract to Uniswap.
So you're going to redeem these LP tokens.
And in exchange, you're going to get all the underlying tokens.
So token 0 and token 1.
So these are specific for each market.
For example, for DAI wrapped Ether,
token 0 is going to be DAI and token 1 is going to be wrapped Ether.
And after, you're going to forward these tokens
into your pair contract of your Uniswap fork.
So in exchange, you're going to get the LP token of your Uniswap fork
and you are going to distribute this LP token to all the investors
who send the LP token to the migration contract.
Okay, so that's the plan.
So next, we are going to implement this with code.
Okay, so we're going to go at the root of our project.
We're going to create a new directory called Migrator.
Step into it.
Initial a Truffle project.
And after, we're going to initialize an npm project
because we're going to need to install a couple of npm packages.
So first, Uniswap v2 periphery to use the router smart contract.
And also open Zeppelin contracts
because we're going to manipulate some ERS-20 tokens.
Okay, so let's install this.
Oops, that was a typo here.
Okay, let's try again.
Okay, so next, we are going to change the configuration of our project
to use Solidity 0.6.6.
So the same version as the router of Uniswap.
All right, so next, we're going to create the bonus token
that we're going to give as a bonus to anyone
who stakes the LP token in our migration smart contract.
We're going to call this bonustoken.sol.
All right, so let's open this.
And this is going to be for Solidity 0.6.
And we're going to import ERC-20 token from OpenZeppelin.
So this time, it's going to be the latest version of OpenZeppelin that we installed.
So it's a little bit more simple.
That's what we did before.
ERC-20.sol, that's all we need to import.
Bonus token is ERC-20.
So we inherit from it.
And after in the constructor, we're going to trigger the constructor of ERC-20.
We give it two arguments, the name and a symbol.
So the name is bonus token and the symbol is going to be,
for example, BTK for bonus token.
Okay, make this public.
Inside, we're going to save the deployment address.
We're going to call this admin.
It's going to be useful after.
And after, we're going to have another function to set the liquidator.
So this will be useful to mint new token.
So address liquidator.
And only the admin can send the liquidator.
Otherwise, this is security risk.
And so the liquidator is going to be what we pass as arguments.
We also need to save this address in the state of the smart contract.
Okay.
And after that, we need to create another function to mint bonus token
every time someone sends the LP token.
So we want to know the recipient and the amount.
And only the liquidator can call this function.
Okay.
And after that, we're going to call the underscore mint function
that is provided by OpenZipLink.
Remember that here, we inherited from ERC20.
So we inherit from a bunch of functions, including underscore mint.
And here, we just forward the argument we receive.
And boom, that's how you can give your bonus to the investor.
Okay.
After, we need to import an interface for the pair of Uniswap.
So we're going to call this iUniswapV2Pair.sol.
And we go in the repo of Uniswap core contracts interfaces.
And here, you will see iUniswapV2Pair.
We're going to copy this.
And the only reason why we do this and not take it directly from the npm package of Uniswap
is because we need to change the Solidity version here.
So back in our code, we paste this and then we replace here by Solidity 0.6.6.
Okay.
So I think it's going to be all right like this and we don't need to change anything.
And after that, we're going to create another smart contract called Liquidity
Migrator.
So that's where all the action is going to take place.
Okay.
So let's open this.
So that's Solidity 0.6.6.
So first, we need to import a couple of stuff like the interface
of OpenThePling for ERC20 token.
So we need to manipulate the bonus token.
That's why.
Right after, we need to import an interface from Uniswap.
So periphery contracts interfaces.
We need the interface of the router.
Uniswap v2 router02.sol.
All right.
We also need to import the interface of Uniswap pair that we just created before.
And we also need to import the bonus token.
Okay.
So now we define our contract.
So we're going to define a couple of pointers.
So first, to the router of Uniswap.
Then to the pair of Uniswap.
Then to the router of our fork.
So we're going to call this router fork.
Then to the pair of our fork.
Then to pointer to the bonus token.
Then we need to know the address of the admin.
Then we need to know the balances of people who invested the LP token in the contract.
So it's going to map the address of the investor to
the balance of LP token they initially invested.
So that we can give them the equivalent amount of LP token,
but for our fork and claim balances.
And then a boolean value that just tells us if the migration was done.
So after we're going to have a constructor to initialize a couple of variables.
So first, the address of the router of the pair of the router fork of the pair fork.
And of the bonus token is after which is going to initialize all these pointer.
Same thing for the fork.
Same thing for the token.
Okay.
Finally, also we need to save the address of the admin.
So that we can protect some function.
Okay.
So the first step is to deposit LP token to the liquidity contract.
So here we need to indicate how much we want to deposit.
So we need to make sure that the migration was not done before.
After we are going to transfer the LP token.
And for that, we use the pair contract of Uniswap.
And we can use the transfer from functions.
Of course, that means before you call deposit,
you need to call the approve function with the address of the migration contract.
And so we're going to transfer from the sender to our contract.
And for the amount that was specified.
And after we need to give the bonus token to the sender.
As a reward for sending its LP token.
So we're going to give as many bonus token as LP token to make it simple.
And we're going to increment the unclaim balance mapping for the sender.
And we increment of the amount.
Okay.
So all the investors are going to send the LP token.
And finally, when we have enough LP token, we're going to proceed to the actual migration.
So we're going to call this migrate.
And only the admin can do this.
And it can only be done when the migration was not done before.
And we need to have a pointer to the two underlying tokens of our market.
So for that, we can call the token zero function
of the Uniswap pair to get the address of the first and second token.
We also need to know what's the LP token balance of our smart contract.
For that, we can use the pair pointer and balance of function for our address.
And once we know this, then we can withdraw everything.
So for that, we're going to use roger.remove liquidity.
We're going to pass a couple of function like the address of the two token,
the total balance of LP token.
We want to withdraw the minimum amount of token zero and token one we want.
So here I make it simple, but it's actually possible to specify a minimum amount.
And then for the recipients of the underlying token,
so that's going to be our smart contract.
And for the limit date for this action, so that's going to be now.
And so OK, so with this, we remove the liquidity from Uniswap to our smart contract.
And next, we're going to forward the underlying tokens to our fork of Uniswap.
So now we need to know what's our balance in the two underlying token, token zero and token one.
So for that, we define new variable token zero balance.
And we can get the balance of our contract like this.
Same thing for the other token.
And after we are going to approve our Uniswap fork to spend this token on our behalf.
So we can approve the router fork for the token zero balance.
Same thing for the other token.
And now we can call router fork dot add liquidity to pass the two address.
Let's copy this.
And for the two balances of token.
So that's token zero balance, token one balance.
And you can also specify a minimum amount for these two tokens.
So we're going to put the same one.
And it's going to be credited to the address of our smart contract.
And the limit for this action is now.
And after that, we change the flag for migration down to true.
And with this, the liquidity is sent to our fork of Uniswap.
So next, once this is done, all the LP tokens are credited to the address of our smart contract.
But we need to allocate this to the different investors so they can redeem this new LP token.
So the investor will have individually to call a function called claim LP token.
And the reason why we don't do this allocation
outset here in the migrate function is because we can have a very large number
of addresses where we need to send all these LP token.
And this can have a very high gas cost.
So we want to avoid this.
So here, first, we're going to require that the caller of this function actually has some token.
I would call this no and claim balance if there is an error.
Then we want the migration to be done.
Migration done.
Call true.
And the error message is migration not done yet.
OK.
Then we need to save the amount to send because we're going to set this to zero after.
And claim balances of MSG sender.
And after that, the unclaimed balances of the sender is going to switch to be set to zero.
And finally, using our pair fork, we are going to transfer the LP token.
So to the sender of the transaction and the amount to send is this.
And so now our investor owns the LP tokens and can redeem them against the underlying tokens.
And on top of it, he also has received the bonus tokens.
OK.
So let's exit this.
And let's try to compile all of this just to make sure that there is no compilation error.
OK.
So line 21, compilation error here.
All right.
So now is it fine?
OK.
So pragma solidity.
I forgot in Uniswap v2 pair.
I forgot here this.
OK.
Let's try to compile again.
Yes, it's working.
Great.
So the last thing we need to do is to write the migration script.
So let's do this.
Deploy contracts.
All right.
Let's copy paste from the template of migration.
First, we are going to import bonus token.
artifact.require bonus token.sol
And we also need to import liquidity migrator.
All right.
We make this async.
And first, we're going to deploy our token.
And after, we need to have a reference to this.
OK.
And after, we're going to define the different address.
router address pair address.
So these are supposed to be the address of Uniswap router fork address.
So this is what you deploy yourself.
Pair fork address.
And after, we're going to deploy the migrator.
So first, we specify liquidity migrator.
And we're going to pass a bunch of addresses.
So basically, all these addresses here.
All right.
Let's get rid of this.
Don't need this.
OK.
Let's put some comma everywhere.
OK.
And we also need to put the address of the bonus token that was deployed just before.
And now, we need to have a reference to the liquidity migrator.
OK.
And finally, we need to call the setLiquidator on the bonus token.
So that the liquidity migrator is allowed to mint token on bonus token.
Liquidity, liquidity migrator address.
All right.
And we're pretty much done.
So what's next?
Are you going to create the next SushiSwap?
So just to be clear, I don't recommend to just copy-paste the code of UniSwap
with some minor modification like Chef Nomi did for SushiSwap.
Think of forking like a quick way to get some foundations.
But after you get this foundation, you actually need to bring some added value.
Otherwise, there is no point.
Another idea I haven't mentioned.
If you just want to experiment with forking DeFi protocol
and you don't want to hurt the UniSwap project,
what you can do is you can fork some UniSwap fork like SushiSwap.
And if you want to keep watching some other tutorials about cool DeFi project,
check out these videos on my channel.
I'll see you there.
