Hey guys does anyone know assembly ?
I am trying to get the reserve0, reserve1 and block timestamp value from a pair smart contract (https://bscscan.com/address/0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16#readContract) . I am able to get the value but i am missing some concept on how to actually decode the bytes i get back into those 3 values. reaserve0 and reserve1 are uint112 and block timestamp is uint32. I know i can use an interface to do all this but i want to do it using assembly.
Here is what i have so far :
pragma solidity ^0.6.6;
//
contract TestContract {
uint reserve0;
uint reserve1;
uint block_timestamp;
function test(address _address) external {
bytes4 sig = bytes4(keccak256("getReserves()"));
assembly {
let x := mload(0x40)
mstore(x,sig)
let success := call(5000, _address, 0, x, 0x44, x, 0x20)
// I know the return value is stored in x but don't know how to split it into reserve0, reserve1, block_timestamp
mstore(0x40,add(x,0x44))
}
}
}
contract TestContract {
uint reserve0;
uint reserve1;
uint block_timestamp;
function test(address _address) external {
bytes4 sig = bytes4(keccak256("getReserves()"));
assembly {
let x := mload(0x40)
mstore(x,sig)
let success := call(5000, _address, 0, x, 0x44, x, 0x20)
// I know the return value is stored in x but don't know how to split it into reserve0, reserve1, block_timestamp
mstore(0x40,add(x,0x44))
}
}
}
Jul 16, 2021, 6:18 PM