Comments (17)
Should it be..
let newReserveA = reserveA.add(aIn);
from subway.
You have to subtract the 3% fee right?
let newReserveA = reserveA.add(aInWithFee.div(1000))
from subway.
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.
Yeah but inputAmount wasn't multiplied by 997 @htkcodes . Compared to in this project
from subway.
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.
When they return the new reserve amount, they add inputAmount, not inputAmountWithFee.
from subway.
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.
Yes so input amount in @libevm project is "aIn". Its the same thing @mmarkell
from subway.
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.
Right exactly ^^
from subway.
@htkcodes I agree that input amount is the same, but the newly calculated reserves are different.
from subway.
@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 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.
Hmm @libevm when I try to push a PR branch, it says access denied. Do you need to update settings?
from subway.
@mmarkell you'll need to fork it, then make a PR from your fork
from subway.
Oh I see
from subway.
Closed #4
from subway.
Related Issues (18)
- Could you explain the calling of call() function in Sandwich.sol? HOT 1
- 此程序本人已吃透,需要用夹子的可以联系Telegram: james1847
- Flashbots: Execution reverted, why? HOT 1
- node:events:504 throw er; // Unhandled 'error' event
- Transcation reverted. HOT 1
- Yulp Contract deployement HOT 3
- Use a wrong variable in univ2.js HOT 1
- Duplicated code in relayer.js HOT 1
- Missing variables despite them all being filled in... HOT 3
- getUniv2ExactWethTokenMinRecv for loop never runs / function does nothing HOT 1
- issue HOT 2
- error while simulating HOT 2
- Remove Flashbots HOT 4
- buy/sell problem HOT 1
- weth and token in payloads looks switched. I think it should be the other way around HOT 17
- frontrun tx always reverts with ERC20: transfer amount exceeds balance HOT 2
- What's next when found potentially sandwichable txs ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from subway.