Giter VIP home page Giter VIP logo

Comments (17)

htkcodes avatar htkcodes commented on August 15, 2024

Should it be..

let newReserveA = reserveA.add(aIn);

from subway.

mmarkell avatar mmarkell commented on August 15, 2024

You have to subtract the 3% fee right?

let newReserveA = reserveA.add(aInWithFee.div(1000))

from subway.

htkcodes avatar htkcodes commented on August 15, 2024
  public getOutputAmount(inputAmount: CurrencyAmount<Token>): [CurrencyAmount<Token>, Pair] {
    invariant(this.involvesToken(inputAmount.currency), 'TOKEN')
    if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO)) {
      throw new InsufficientReservesError()
    }
    const inputReserve = this.reserveOf(inputAmount.currency)
    const outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0)
    const inputAmountWithFee = JSBI.multiply(inputAmount.quotient, _997)
    const numerator = JSBI.multiply(inputAmountWithFee, outputReserve.quotient)
    const denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _1000), inputAmountWithFee)
    const outputAmount = CurrencyAmount.fromRawAmount(
      inputAmount.currency.equals(this.token0) ? this.token1 : this.token0,
      JSBI.divide(numerator, denominator)
    )
    if (JSBI.equal(outputAmount.quotient, ZERO)) {
      throw new InsufficientInputAmountError()
    }
    return [outputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]
  }

i just looked at how uniswap does it in their sdk and they seem to just add the inputamount to the reserve

from subway.

mmarkell avatar mmarkell commented on August 15, 2024

Yeah but inputAmount wasn't multiplied by 997 @htkcodes . Compared to in this project

from subway.

htkcodes avatar htkcodes commented on August 15, 2024

Yeah but inputAmount wasn't multiplied by 997 @htkcodes . Compared to in this project

const inputAmountWithFee = JSBI.multiply(inputAmount.quotient, _997)

same thing

from subway.

mmarkell avatar mmarkell commented on August 15, 2024

When they return the new reserve amount, they add inputAmount, not inputAmountWithFee.

from subway.

libevm avatar libevm commented on August 15, 2024

Code is referencing UniswapV2Library.sol

https://github.com/Uniswap/v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol#L43

Try calculating the amount outs given reserves by hand and compare to the output obtained by the router

from subway.

htkcodes avatar htkcodes commented on August 15, 2024

Yes so input amount in @libevm project is "aIn". Its the same thing @mmarkell

from subway.

jtsiskin avatar jtsiskin commented on August 15, 2024

Code is referencing UniswapV2Library.sol

https://github.com/Uniswap/v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol#L43

Try calculating the amount outs given reserves by hand and compare to the output obtained by the router

@libevm the amount out is correct. The reserveA update is not. amountInWithFee is 1000x larger than the actual reserve update, no? Uniswap just doesn't name its variables amountInWithFeeTimes1000 even when they are

from subway.

mmarkell avatar mmarkell commented on August 15, 2024

Right exactly ^^

from subway.

mmarkell avatar mmarkell commented on August 15, 2024

@htkcodes I agree that input amount is the same, but the newly calculated reserves are different.

from subway.

htkcodes avatar htkcodes commented on August 15, 2024

@htkcodes I agree that input amount is the same, but the newly calculated reserves are different.

So i think this should be the fix no?

let newReserveA = reserveA.add(aIn);

Just like the sdk's

from subway.

libevm avatar libevm commented on August 15, 2024

@libevm the amount out is correct. The reserveA update is not. amountInWithFee is 1000x larger than the actual reserve update, no? Uniswap just doesn't name its variables amountInWithFeeTimes1000 even when they are

@jtsiskin No need for the passive aggressiveness -- I gain nothing open sourcing this

@mmarkell I see, nice find. PRs welcomed!

from subway.

mmarkell avatar mmarkell commented on August 15, 2024

Hmm @libevm when I try to push a PR branch, it says access denied. Do you need to update settings?

from subway.

libevm avatar libevm commented on August 15, 2024

@mmarkell you'll need to fork it, then make a PR from your fork

from subway.

mmarkell avatar mmarkell commented on August 15, 2024

Oh I see

from subway.

libevm avatar libevm commented on August 15, 2024

Closed #4

from subway.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.