Comments (3)
fallback() external payable {
assembly {
let pair := shr(96, calldataload(0))
let tokenAmountOut := calldataload(4)
mstore(0, PAIR_SWAP)
mstore(4, tokenAmountOut)
mstore(0x24, 0)
mstore(0x44, address())
mstore8(0x64, 0)
let result := call(gas(), pair, callvalue(), 0, 0x84, 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {revert(0, returndatasize())}
default {return (0, returndatasize())}
}
}
from v2-core.
In order to pass a zero-length bytes value to the swap function of the UniswapV2 pair, you can simply store a single zero byte at memory location 0x64. This can be done using the mstore8 opcode, which stores a single byte at the specified memory location.
Here's the modified assembly code with the mstore8 instruction to set the length of the data parameter to zero:
fallback() external payable { assembly { let pair := shr(96, calldataload(0)) let tokenAmountOut := calldataload(4) mstore(0, PAIR_SWAP) mstore(4, tokenAmountOut) mstore(0x24, 0) mstore(0x44, address()) mstore8(0x64, 0) let result := call(gas(), pair, callvalue(), 0, 0x84, 0, 0) returndatacopy(0, 0, returndatasize()) switch result case 0 {revert(0, returndatasize())} default {return (0, returndatasize())} } }
Note that in addition to setting the length of the data parameter to zero, this code also includes some additional changes to handle the result of the call to the swap function, and to copy the return data back to the caller.
from v2-core.
much appreciated, this works!
from v2-core.
Related Issues (20)
- I don't know how to claim dcp token reward on decrypt is over or ended distribution.
- Unbalanced liquidity affects prices HOT 2
- Uniswap getPair() does not deliver address(0) HOT 1
- Error Building v2-core HOT 1
- Token migration issue, balance not loading
- Yarn compile has error. HOT 1
- No SPDX License Identifier HOT 2
- Ultraswap
- `CheckContract` for token contracts HOT 3
- .
- how to get the full and right address[] path for swapExactTokensForTokens ? HOT 1
- 0xd5173949c2d40c9863b9aD6B91a4CCAD3c9B05Fe
- Let's earn the bitcoins daily!
- getPair call via Ethers.Contract does not return a pair address HOT 1
- Both Amount0In and Amount0Out Present in Logs
- Keccak256 init code hash
- yarn test meet error HOT 4
- How to run this?
- Improve Integer Square Root
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 v2-core.