Merge pull request #6 from InstaDApp/uni-lp-tokens

Add resolver method for Uniswap LP token balance and info
This commit is contained in:
Thrilok kumar 2020-12-23 07:29:41 +05:30 committed by GitHub
commit cf33c0acd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,61 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
interface UnipairInterface {
function balanceOf(address) external view returns (uint);
function totalSupply() external view returns (uint);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
}
contract Resolver {
struct UnipairInfo {
address token0;
address token1;
uint reserve0;
uint reserve1;
uint totalSupply;
}
function getUnipairInfo(
address owner,
address[] memory lpTknAddress
) public view returns (uint[] memory, UnipairInfo[] memory) {
uint _length = lpTknAddress.length;
uint[] memory tokensBal = new uint[](_length);
UnipairInfo[] memory unipair = new UnipairInfo[](_length);
address wethAddr = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
for (uint i = 0; i < _length; i++) {
UnipairInterface lp = UnipairInterface(lpTknAddress[i]);
tokensBal[i] = lp.balanceOf(owner);
address tkn0 = lp.token0() == wethAddr ? ethAddr : lp.token0();
address tkn1 = lp.token1() == wethAddr ? ethAddr : lp.token1();
(uint112 res0, uint112 res1, ) = lp.getReserves();
uint supply = lp.totalSupply();
unipair[i] = UnipairInfo({
token0: tkn0,
token1: tkn1,
reserve0: res0,
reserve1: res1,
totalSupply: supply
});
}
return (tokensBal, unipair);
}
}
contract InstaUnipairResolver is Resolver {
string public constant name = "Unipair-Resolver-v1";
}