Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.

UMA Long Short Uniswap Pair Broker

UMA

• version 1.0.0Finance

Utility

Pair

Uniswap

Audited

Audited

1.0.0

UMA

11/5/2022

Any contract you deploy is yours.

Fully owned and controlled by your wallet.

Fully owned and controlled by your wallet.

Documentation

Source Code

atomicMintAddLiquidity(bool,uint256,uint256,uint256) :

This function is used to add liquidity to an Uniswap V2 pool. It takes in a LongShortPair, an IUniswapV2Router01 router, an amount of collateral, a minimum amount of LP tokens, and a deadline. It first checks that the LongShortPair and router are valid, and that the amount of collateral is not 0. It then transfers the collateral to the LongShortPair, and creates the corresponding amount of tokens. It then computes the ratio of tokens to mint at the pool, and swaps the tokens for the corresponding amount of tokens. It then approves the router to transfer the tokens, and adds liquidity to the pool. Finally, it transfers the LP tokens (autogenerated documentation)

computeSwapToMintAtPoolRatio() :

This function computes the ratio of tokens to mint at a pool given the current pool balances and the amount of tokens to swap. It does this by calculating the numerator and denominator of the ratio, and then dividing the numerator by the denominator. The function also returns a boolean value indicating whether the swap is from token A to token B or from token B to token A. (autogenerated documentation)

sqrt() :

This function calculates the square root of a given number using the Babylonian method. It takes a FixedPoint.Signed memory _num as an argument and returns a FixedPoint.Signed memory as the result. The Babylonian method works by iteratively calculating the square root of a number by taking the average of the number and its inverse. This process is repeated until the result converges to the desired accuracy. (autogenerated documentation)

num(int256) :

This function takes an integer as an input and returns a fixed-point number. It does this by using the fromUnscaledInt() function from the FixedPoint library, which takes an integer and converts it into a fixed-point number. The returned fixed-point number is stored in memory. (autogenerated documentation)

applySwapFee() :

This function applies a swap fee of 0.3% to a given number. It does this by multiplying the number by 997 and then dividing it by 1000. This results in a number that is 0.3% lower than the original number. (autogenerated documentation)

lambda() :

This function is a private, pure function that returns a fixed-point signed memory value. It calculates the swap fee by taking a fixed-point value of 1 and applying the swap fee to it. The swap fee is a fee that is charged when a user swaps one asset for another. (autogenerated documentation)

lambda2() :

This function is a private, pure function that returns a fixed-point signed memory value. It works by first calling the lambda() function, which returns a fixed-point value, and then applying the swap fee to that value using the applySwapFee() function. The result is then returned as a fixed-point signed memory value. (autogenerated documentation)

atomicMintSellOneSide(bool,bool,uint256,uint256) :

This function is used to atomically mint and sell a LongShortPair token on one side of the market. It first requires that the long short pair and router are valid, and that the amount of collateral to mint with is not 0. It then transfers the collateral to the long short pair contract, and mints the corresponding amount of tokens. It then approves the router to transfer the sold token, and swaps it for the tokens in the swap path. Finally, if the function is called as an external owned account, it transfers the purchased token to the sender. (autogenerated documentation)

getReserves(address,address,address) :

This function retrieves the reserves of a Uniswap V2 pair. It takes in the address of the factory, and the addresses of two tokens, and returns the reserves of each token in the pair. It works by first sorting the two tokens, then retrieving the reserves from the pair associated with the factory and the two tokens. Finally, it returns the reserves in the correct order based on the sorted tokens. (autogenerated documentation)

sortTokens(address,address) :

This function is used to sort two token addresses. It takes two token addresses as parameters and returns two sorted token addresses. It first checks if the two addresses are the same, and if they are, it throws an error. It then checks if the first address is not equal to zero, and if it is, it throws an error. Finally, it sorts the two addresses and returns them. (autogenerated documentation)

pairFor(address,address,address) :

This function is used to create a UniswapV2Pair contract address from two token addresses. It takes in the address of the factory contract, as well as the addresses of two tokens, and returns an IUniswapV2Pair contract address. It does this by first sorting the two token addresses, then using the keccak256 hashing algorithm to generate a unique address for the pair. Finally, it returns the IUniswapV2Pair contract address. (autogenerated documentation)

Share

Download Source

npx cookbookdev i long-short-uniswap-broker

11/5/2022

1.0.0

Cookbook is free.

Any contract you deploy is yours.

Your contract is owned and controlled by you.

Any contract you deploy is yours.

Your contract is owned and controlled by you.