Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
UniswapV2Pair
copy icon
Uniswap-Labs
• version 1.0.0
ERC20
Token
DEX

UniswapV2Pair

This contract allows for the minting, burning, and swapping of tokens between 2 different ERC-20 tokens, and it also keeps track of the reserves of the tokens in the pool, the cumulative prices of the tokens, and the k value which is the product of the reserve of the two tokens in the pool.

*Visit desktop site to download or deploy

Version

1.0.0

Last Publish

1/13/2023
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
getReserves() :
This function is used to retrieve the current reserves of the contract, which are stored as two uint112 variables (reserve0 and reserve1). It also returns the timestamp of the last block that was processed by the contract. This function is a public view function, meaning that it does not modify the state of the contract and can be called by anyone. (autogenerated documentation)
_safeTransfer(address,address) :
This function is a private function that is used to transfer tokens from one address to another. It uses the ABI encoding to encode the parameters of the transfer (the address of the token, the address of the recipient, and the amount of tokens to be transferred) and then calls the token contract with the encoded parameters. The function then checks the return value of the call to ensure that the transfer was successful. If the transfer was successful, the function returns true, otherwise it throws an error. (autogenerated documentation)
initialize(address,address) :
This function initializes the UniswapV2 contract with two tokens, token0 and token1. It requires that the sender of the message is the factory address, and sets the token0 and token1 variables to the addresses of the two tokens. This allows the UniswapV2 contract to interact with the two tokens and facilitate exchanges between them. (autogenerated documentation)
_update(uint112,uint112) :
This function updates the reserves of a UniswapV2 contract. It takes in two uints, balance0 and balance1, which represent the amount of tokens held in reserve for each token in the pair. It also takes in two uint112s, _reserve0 and _reserve1, which represent the amount of tokens held in reserve for each token in the pair at the time of the last update. The function first checks to make sure that the balances are not greater than the maximum uint112 value. It then calculates the time elapsed since the last update and uses this to calculate the cumulative prices of each token in the pair. Finally, it updates the reserves, the block timestamp, and emits a (autogenerated documentation)
_mintFee(uint112,uint112) :
This function is used to mint fees for the UniswapV2Factory contract. It takes two parameters, _reserve0 and _reserve1, which represent the reserves of the two tokens in the UniswapV2Factory contract. The function first checks if the feeTo address is not 0, and if it is not, it calculates the liquidity of the UniswapV2Factory contract and mints the fees to the feeTo address. The calculation of the liquidity is done by taking the square root of the product of the two reserves, subtracting the square root of the previous kLast value, and then multiplying the result by the totalSupply. The result is then divided by the sum of (autogenerated documentation)
mint(address) :
This function is used to mint new liquidity tokens on the UniswapV2 protocol. It takes an address as an argument and returns the amount of liquidity that has been minted. The function first calculates the current reserves of the two tokens involved in the liquidity pool. It then calculates the amount of each token that can be used to mint new liquidity tokens. It then checks if the total supply of liquidity tokens is zero, and if so, mints the minimum amount of liquidity tokens. If the total supply is not zero, it calculates the amount of liquidity that can be minted based on the current reserves of the two tokens. Finally, it updates the reserves and emits a Mint event. (autogenerated documentation)
burn(address) :
This function is used to burn liquidity from the UniswapV2 contract. It takes an address as an argument and returns two uints representing the amount of tokens burned. The function first retrieves the reserves of the two tokens, then calculates the amount of liquidity held by the contract. It then calculates the amount of tokens to be burned by dividing the liquidity by the total supply. Finally, it transfers the tokens to the specified address, updates the reserves, and emits a Burn event. (autogenerated documentation)
swap(address) :
This function is used to swap tokens between two different ERC20 tokens. It takes in four parameters: amount0Out, amount1Out, to, and data. The function first checks to make sure that the amount of tokens being swapped out is greater than 0, and that there is sufficient liquidity in the reserves. It then transfers the tokens being swapped out to the specified address. After that, it calculates the amount of tokens being swapped in, and checks to make sure that the balance of the two tokens is sufficient. Finally, it updates the reserves and emits a Swap event. (autogenerated documentation)
skim(address) :
This function is used to transfer the remaining balance of two tokens (token0 and token1) from the contract to a specified address (to). It does this by first retrieving the address of the two tokens, then using the _safeTransfer function to transfer the balance of each token minus the reserve amount to the specified address. (autogenerated documentation)
sync() :
This function is used to synchronize the balance of two ERC20 tokens held by a contract. It takes the balance of the two tokens held by the contract, as well as the reserve values of the two tokens, and updates the reserve values accordingly. The function is marked as external and lock, meaning that it can only be called externally and that it will lock the contract while it is running. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i UniswapV2Pair
copy icon

Last Publish

1/13/2023

Version

1.0.0

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.