Skip to main content
added 1 character in body
Source Link
Maka
  • 1.4k
  • 1
  • 7
  • 19

I tested it, the prices are different across the two urls, app.sushi.com shows the same as getAmountOut with 2+% price impact.

www.sushi.com shows more as it is aggregating from multiple pools to give you the best price. If anything it is just an inaccuracy in what it is showing as the path on the newer UI.

enter image description here

edit:

Hello brother is there a way i can calculate the amount i get after swap using resrve0 and reserve1. Example The pool MKR/WETH have WETH reserve of 137562296675513055507 and MKR reserve of 95089610234884719383 If i input 1 ETH How to calculate the amount of MKR i get??

On the simplest level you can call getAmountOut, or copy the way the function does it from the Uniswap library.

    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
        require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        uint amountInWithFee = amountIn.mul(997);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    }

An example implementation might look like:

>>> def getAmountOut(amountIn: int, reserveIn: int, reserveOut: int) -> int:
...   amountInWithFee = amountIn * 997
...   numerator = amountInWithFee * reserveOut
...   denominator = (reserveIn * 1000) + amountInWithFee
...   amountOut = numerator // denominator
...   return int(amountOut)
...
>>>
>>> getAmountOut(1*10**18,137562296675513055507,95089610234884719383,137562296675513055507)
6842149439181903361427354024147827329
>>> getAmountOut(1*10**18,137562296675513055507,95089610234884719383)/10**18
0.6842149439181904
>>> getAmountOut(1*10**18,95089610234884719383,137562296675513055507)/10**18
1.42735402414782754273540241478273
>>>

Have included the reserves in reverse of suggested as I think you got them back to front in the question.

The last result suggests 1.4273540241478275 MKR4273540241478273MKR for 1 ETH which is close to the current market rate.

I tested it, the prices are different across the two urls, app.sushi.com shows the same as getAmountOut with 2+% price impact.

www.sushi.com shows more as it is aggregating from multiple pools to give you the best price. If anything it is just an inaccuracy in what it is showing as the path on the newer UI.

enter image description here

edit:

Hello brother is there a way i can calculate the amount i get after swap using resrve0 and reserve1. Example The pool MKR/WETH have WETH reserve of 137562296675513055507 and MKR reserve of 95089610234884719383 If i input 1 ETH How to calculate the amount of MKR i get??

On the simplest level you can call getAmountOut, or copy the way the function does it from the Uniswap library.

    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
        require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        uint amountInWithFee = amountIn.mul(997);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    }

An example implementation might look like:

>>> def getAmountOut(amountIn: int, reserveIn: int, reserveOut: int) -> int:
...   amountInWithFee = amountIn * 997
...   numerator = amountInWithFee * reserveOut
...   denominator = (reserveIn * 1000) + amountInWithFee
...   amountOut = numerator / denominator
...   return int(amountOut)
...
>>>
>>> getAmountOut(1*10**18,137562296675513055507,95089610234884719383)
684214943918190336
>>> getAmountOut(1*10**18,137562296675513055507,95089610234884719383)/10**18
0.6842149439181904
>>> getAmountOut(1*10**18,95089610234884719383,137562296675513055507)/10**18
1.4273540241478275

Have included the reserves in reverse of suggested as I think you got them back to front in the question.

The last result suggests 1.4273540241478275 MKR for 1 ETH which is close to the current market rate.

I tested it, the prices are different across the two urls, app.sushi.com shows the same as getAmountOut with 2+% price impact.

www.sushi.com shows more as it is aggregating from multiple pools to give you the best price. If anything it is just an inaccuracy in what it is showing as the path on the newer UI.

enter image description here

edit:

Hello brother is there a way i can calculate the amount i get after swap using resrve0 and reserve1. Example The pool MKR/WETH have WETH reserve of 137562296675513055507 and MKR reserve of 95089610234884719383 If i input 1 ETH How to calculate the amount of MKR i get??

On the simplest level you can call getAmountOut, or copy the way the function does it from the Uniswap library.

    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
        require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        uint amountInWithFee = amountIn.mul(997);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    }

An example implementation might look like:

>>> def getAmountOut(amountIn: int, reserveIn: int, reserveOut: int) -> int:
...   amountInWithFee = amountIn * 997
...   numerator = amountInWithFee * reserveOut
...   denominator = (reserveIn * 1000) + amountInWithFee
...   amountOut = numerator // denominator
...   return int(amountOut)
...
>>> getAmountOut(1*10**18,95089610234884719383,137562296675513055507)
1427354024147827329
>>> getAmountOut(1*10**18,137562296675513055507,95089610234884719383)/10**18
0.6842149439181904
>>> getAmountOut(1*10**18,95089610234884719383,137562296675513055507)/10**18
1.4273540241478273
>>>

Have included the reserves in reverse of suggested as I think you got them back to front in the question.

The last result suggests 1.4273540241478273MKR for 1 ETH which is close to the current market rate.

added 1812 characters in body
Source Link
Maka
  • 1.4k
  • 1
  • 7
  • 19

I tested it, the prices are different across the two urls, app.sushi.com shows the same as getAmountOut with 2+% price impact.

www.sushi.com shows more as it is aggregating from multiple pools to give you the best price. If anything it is just an inaccuracy in what it is showing as the path on the newer UI.

enter image description here

edit:

Hello brother is there a way i can calculate the amount i get after swap using resrve0 and reserve1. Example The pool MKR/WETH have WETH reserve of 137562296675513055507 and MKR reserve of 95089610234884719383 If i input 1 ETH How to calculate the amount of MKR i get??

On the simplest level you can call getAmountOut, or copy the way the function does it from the Uniswap library.

    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
        require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        uint amountInWithFee = amountIn.mul(997);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    }

An example implementation might look like:

>>> def getAmountOut(amountIn: int, reserveIn: int, reserveOut: int) -> int:
...   amountInWithFee = amountIn * 997
...   numerator = amountInWithFee * reserveOut
...   denominator = (reserveIn * 1000) + amountInWithFee
...   amountOut = numerator / denominator
...   return int(amountOut)
...
>>>
>>> getAmountOut(1*10**18,137562296675513055507,95089610234884719383)
684214943918190336
>>> getAmountOut(1*10**18,137562296675513055507,95089610234884719383)/10**18
0.6842149439181904
>>> getAmountOut(1*10**18,95089610234884719383,137562296675513055507)/10**18
1.4273540241478275

Have included the reserves in reverse of suggested as I think you got them back to front in the question.

The last result suggests 1.4273540241478275 MKR for 1 ETH which is close to the current market rate.

I tested it, the prices are different across the two urls, app.sushi.com shows the same as getAmountOut with 2+% price impact.

www.sushi.com shows more as it is aggregating from multiple pools to give you the best price. If anything it is just an inaccuracy in what it is showing as the path on the newer UI.

enter image description here

I tested it, the prices are different across the two urls, app.sushi.com shows the same as getAmountOut with 2+% price impact.

www.sushi.com shows more as it is aggregating from multiple pools to give you the best price. If anything it is just an inaccuracy in what it is showing as the path on the newer UI.

enter image description here

edit:

Hello brother is there a way i can calculate the amount i get after swap using resrve0 and reserve1. Example The pool MKR/WETH have WETH reserve of 137562296675513055507 and MKR reserve of 95089610234884719383 If i input 1 ETH How to calculate the amount of MKR i get??

On the simplest level you can call getAmountOut, or copy the way the function does it from the Uniswap library.

    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
        require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        uint amountInWithFee = amountIn.mul(997);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    }

An example implementation might look like:

>>> def getAmountOut(amountIn: int, reserveIn: int, reserveOut: int) -> int:
...   amountInWithFee = amountIn * 997
...   numerator = amountInWithFee * reserveOut
...   denominator = (reserveIn * 1000) + amountInWithFee
...   amountOut = numerator / denominator
...   return int(amountOut)
...
>>>
>>> getAmountOut(1*10**18,137562296675513055507,95089610234884719383)
684214943918190336
>>> getAmountOut(1*10**18,137562296675513055507,95089610234884719383)/10**18
0.6842149439181904
>>> getAmountOut(1*10**18,95089610234884719383,137562296675513055507)/10**18
1.4273540241478275

Have included the reserves in reverse of suggested as I think you got them back to front in the question.

The last result suggests 1.4273540241478275 MKR for 1 ETH which is close to the current market rate.

Source Link
Maka
  • 1.4k
  • 1
  • 7
  • 19

I tested it, the prices are different across the two urls, app.sushi.com shows the same as getAmountOut with 2+% price impact.

www.sushi.com shows more as it is aggregating from multiple pools to give you the best price. If anything it is just an inaccuracy in what it is showing as the path on the newer UI.

enter image description here