relevant tag icon
Velodrome Pair
copy icon
velodrome
• version 1.0.0
AMM
Pair
Finance

Velodrome Pair

The base pair of pools, either stable or volatile. Pair is created by the PairFactory and takes in the addresses of two tokens, a boolean to denote whether the pair is stable or volatile, and a name and symbol which are generated based on the tokens' symbols. The contract includes a minimum liquidity requirement, and tracks the reserve ratio of the two tokens in the pair, as well as the cumulative reserves of each token over time. The contract also includes functions for trading, approving, and transferring tokens, and for claiming and calculating fees. The constructor sets up the basic properties of the pair, such as the token addresses, factory address, and name and symbol based on whether it is stable or volatile.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

velodrome

Last Publish

1/20/2023
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
observationLength() :
This function returns the length of the "observations" array. It does this by accessing the length property of the array and returning it as a uint (unsigned integer). (autogenerated documentation)
lastObservation() :
This function returns the last observation stored in the observations array. It does this by accessing the last element in the array and returning it as an Observation memory type. (autogenerated documentation)
metadata() :
This function is used to retrieve the metadata associated with a particular Uniswap exchange contract. It returns the decimals of each token, the reserve balance of each token, a boolean indicating whether the exchange is stable, and the addresses of each token. This function does not modify any state and is viewable by anyone. (autogenerated documentation)
tokens() :
This function is a view function that returns the addresses of two tokens. It does not modify the state of the contract and does not require any input parameters. It simply returns the addresses of the two tokens stored in the contract. (autogenerated documentation)
claimFees() :
This function allows a user to claim fees that have been accrued in the contract. It first updates the claimable fees for the user, then sets the claimable fees to 0. It then calls the PairFees contract to claim the fees for the user, and emits a Claim event. (autogenerated documentation)
_update0() :
This function is used to update the index0 variable of the contract. It takes in an amount as an argument and transfers that amount to the fees address. It then calculates the ratio of the amount to the totalSupply and adds it to the index0 variable. Finally, it emits an event with the sender, amount, and 0 as arguments. (autogenerated documentation)
_update1() :
This function updates the index1 variable by transferring an amount of token1 to the fees address and calculating the ratio of the amount to the totalSupply. It then emits a Fees event with the sender, 0, and amount. This function is used to track the amount of token1 in the totalSupply. (autogenerated documentation)
_updateFor(address) :
This function updates the claimable rewards for a given recipient. It first checks if the recipient has a balance greater than 0, and if so, it calculates the difference between the current supply index and the recipient's supply index for each token. It then calculates the share of rewards that the recipient is entitled to based on their balance and the difference in supply indices, and adds it to the recipient's claimable rewards. If the recipient has a balance of 0, it simply updates their supply indices. (autogenerated documentation)
getReserves() :
This function is used to retrieve the current reserves of the contract, which are stored in the variables reserve0 and reserve1. It also returns the timestamp of the last block that was processed. 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)
_update() :
This function updates the reserves of a token exchange. It takes in two balances (reserve0 and reserve1) and two reserves (_reserve0 and _reserve1) as parameters. It first calculates the time elapsed since the last block timestamp and updates the cumulative reserves accordingly. It then checks if the time elapsed since the last observation is greater than the period size, and if so, it adds a new observation to the observations array. Finally, it updates the reserve0 and reserve1 variables, sets the block timestamp to the current block timestamp, and emits a Sync event with the updated reserves. (autogenerated documentation)
currentCumulativePrices() :
This function returns the cumulative prices of two reserves, as well as the current block timestamp. It does this by first setting the block timestamp, and the cumulative prices of the two reserves to the last known values. It then retrieves the current reserves and block timestamp from the getReserves() function. If the block timestamp retrieved from getReserves() is different from the current block timestamp, the function calculates the time elapsed since the last block timestamp and adds the reserves multiplied by the time elapsed to the cumulative prices of the two reserves. Finally, the function returns the cumulative prices of the two reserves, as well as the current block timestamp. (autogenerated documentation)
current(address) :
This function calculates the amount of a given token (tokenIn) that can be exchanged for a given amount of another token (amountIn). It does this by calculating the current cumulative prices of the two tokens, subtracting the cumulative prices from the last observation, and then dividing the difference by the time elapsed since the last observation. The resulting values are then used in the _getAmountOut() function to calculate the amountOut. (autogenerated documentation)
quote(address) :
This function calculates the average price of a given token (tokenIn) in a given amount (amountIn) by taking a sample of the price (granularity) and averaging the results. It does this by looping through the sample array (_prices) and adding each element to a cumulative total (priceAverageCumulative). Finally, it returns the average price by dividing the cumulative total by the granularity. (autogenerated documentation)
prices(address) :
This function is used to calculate the prices of a given token. It takes in three parameters: the address of the token, the amount of the token, and the number of points to be used in the calculation. It then returns an array of uints containing the prices of the token. The calculation is done by calling the sample() function, which takes in the same three parameters as well as a multiplier value of 1. This function then uses the given parameters to calculate the prices of the token and returns the result as an array of uints. (autogenerated documentation)
sample(address) :
This function calculates the price of a given token (tokenIn) over a given period of time (window) by taking a given amount of the token (amountIn) and calculating the amount of the other token (reserve0 and reserve1) that can be obtained in exchange. It does this by taking a series of observations (observations) of the reserves over the given period of time and calculating the average rate of change of each reserve over the period. It then uses this rate of change to calculate the amount of the other token that can be obtained in exchange for the given amount of the tokenIn. Finally, it returns an array of the calculated prices (prices). (autogenerated documentation)
mint(address) :
This function is used to mint new liquidity tokens for the Uniswap exchange. It takes an address as an argument and returns the amount of liquidity that has been minted. The function first calculates the amount of tokens held in reserve for each token, and then calculates the amount of tokens held by the Uniswap contract. It then calculates the total supply of liquidity tokens and if it is 0, it mints the minimum liquidity amount. Otherwise, it mints the minimum of the amount of tokens held by the Uniswap contract divided by the reserve for each token. Finally, it updates the balances and emits a Mint event. (autogenerated documentation)
burn(address) :
This function allows a user to burn their liquidity from the pool. It takes an address as an argument and returns two amounts of tokens. The function first calculates the reserve amounts, token balances, and liquidity of the pool. It then calculates the amount of tokens to be burned by taking the liquidity and multiplying it by the balance of each token. The function then burns the liquidity and transfers the calculated amounts of tokens to the address provided. Finally, it updates the reserve amounts and emits a Burn event. (autogenerated documentation)
swap(address) :
This function is used to swap tokens between two parties. It takes in four parameters: amount0Out, amount1Out, to, and data. The function first checks that the pair is not paused and that the amounts of tokens being swapped are greater than 0. It then checks that the amount of tokens being swapped is less than the reserves of each token. It then transfers the tokens from the contract to the specified address and calls the hook function with the sender, amounts of tokens being swapped, and data. It then calculates the amount of tokens being swapped in and updates the reserves of each token. Finally, it updates the balances of each token and emits a Swap event. (autogenerated documentation)
skim(address) :
This function is used to transfer the remaining balance of a token pair from the contract to a specified address. It first sets the token addresses to the token0 and token1 variables, then it uses the _safeTransfer function to transfer the balance of token0 and token1 minus the reserve0 and reserve1 amounts 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)
_f() :
This function is an internal pure function that takes two unsigned integers as parameters and returns an unsigned integer. It calculates the product of the two parameters and returns the result. It works by first multiplying the two parameters together, then dividing the result by 1e18 (1 followed by 18 zeroes) three times, and finally adding the result of the first multiplication to the result of the second multiplication. (autogenerated documentation)
_d() :
This function is an internal pure function that takes two unsigned integers as parameters and returns an unsigned integer. It calculates the value of 3x0 multiplied by the square of y divided by 1e18, plus the cube of x0 divided by 1e18. (autogenerated documentation)
_get_y() :
This function is used to calculate the y-coordinate of a point on an elliptic curve given the x-coordinate, the xy-coordinate, and the initial y-coordinate. It uses an iterative approach to find the y-coordinate, using the _f and _d functions to calculate the xy-coordinate and the derivative of the xy-coordinate with respect to y, respectively. The function iterates until the difference between the current and previous y-coordinate is less than or equal to 1. (autogenerated documentation)
getAmountOut(address) :
This function calculates the amount of tokens that will be received when a certain amount of tokens is exchanged. It takes in an amount of tokens and the address of the token to be exchanged as parameters. It then subtracts the amount of tokens by the fee percentage set by the PairFactory contract. Finally, it calls the _getAmountOut() function to calculate the amount of tokens to be received, using the amount of tokens, the address of the token to be exchanged, and the reserves of the two tokens in the pair. (autogenerated documentation)
_getAmountOut(address) :
This function is used to calculate the amount of tokenOut that a user will receive when exchanging tokenIn. It takes in the amount of tokenIn, the address of the tokenIn, and the reserves of both tokens. It first checks if the pool is in stable mode, and if so, it calculates the amount of tokenOut using the k-ratio formula. If the pool is not in stable mode, it uses a simple ratio calculation to determine the amount of tokenOut. (autogenerated documentation)
_k() :
This function is used to calculate the product of two numbers, x and y. It works by first converting the two numbers to 18 decimal places, then multiplying them together and dividing by 1e18. The result is then multiplied by the sum of the squares of the two numbers, and divided by 1e18 again. The final result is then returned. If the 'stable' flag is set to false, the function simply returns the product of the two numbers without any additional calculations. (autogenerated documentation)
_mint(address) :
This function is an internal function that is used to mint new tokens. It takes two parameters, an address and an amount, and updates the total supply of the token and the balance of the address passed in. It then emits a Transfer event with the address of 0 (the contract address) as the sender, the address passed in as the recipient, and the amount as the amount of tokens transferred. (autogenerated documentation)
_burn(address) :
This function is used to burn a certain amount of tokens from a given address. It updates the total supply of tokens by subtracting the amount to be burned, and also updates the balance of the given address by subtracting the amount to be burned. Finally, it emits a Transfer event to indicate that the tokens have been burned. (autogenerated documentation)
approve(address) :
This function allows a user to approve a spender to spend a certain amount of tokens from their account. It sets the allowance of the spender to the amount specified and emits an Approval event with the sender, spender, and amount. It then returns true to indicate that the approval was successful. (autogenerated documentation)
permit(address,address,uint8,bytes32,bytes32) :
This function is used to permit a spender to transfer a certain amount of tokens from an owner's account. It requires the owner to sign a message with their private key, which is then verified using the EIP712 standard. The function then sets the allowance for the spender to the specified value and emits an Approval event. (autogenerated documentation)
transfer(address) :
This function is used to transfer tokens from one address to another. It takes two parameters, an address to send the tokens to and an amount of tokens to send. It then calls the _transferTokens() function, which is responsible for actually transferring the tokens, and returns true to indicate that the transfer was successful. (autogenerated documentation)
transferFrom(address,address) :
This function allows a user (the spender) to transfer tokens from one address (src) to another address (dst). The spender must have an allowance from the src address, which is checked against the type uint max. If the allowance is sufficient, the allowance is updated and an Approval event is emitted. Finally, the tokens are transferred from the src address to the dst address. (autogenerated documentation)
_transferTokens(address,address) :
This function is an internal function that transfers tokens from one address (src) to another address (dst). It updates the balance of both the source and destination addresses, subtracting the amount from the source address and adding it to the destination address. Finally, it emits a Transfer event with the source, destination, and amount of tokens transferred. (autogenerated documentation)
_safeTransfer(address) :
This function is an internal function that is used to transfer tokens from one address to another. It requires that the token address has a code length greater than 0, and then calls the IERC20 transfer selector with the address of the recipient and the value of the tokens to be transferred. It then requires that the call was successful and that the data returned is either empty or a boolean value. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i velodrome-pair
copy icon

Last Publish

1/20/2023

Version

1.0.0

Creator

velodrome

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