mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
pool details function complete
This commit is contained in:
parent
5f52694075
commit
375ce3c92f
|
@ -49,11 +49,7 @@ contract UniswapPool {
|
||||||
function name() external returns (bytes32);
|
function name() external returns (bytes32);
|
||||||
function symbol() external returns (bytes32);
|
function symbol() external returns (bytes32);
|
||||||
function decimals() external returns (uint256);
|
function decimals() external returns (uint256);
|
||||||
function transfer(address _to, uint256 _value) external returns (bool);
|
function totalSupply() external returns (uint256);
|
||||||
function transferFrom(address _from, address _to, uint256 value) external returns (bool);
|
|
||||||
function approve(address _spender, uint256 _value) external returns (bool);
|
|
||||||
function allowance(address _owner, address _spender) external view returns (uint256);
|
|
||||||
function balanceOf(address _owner) external view returns (uint256);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,13 +58,6 @@ contract Helper {
|
||||||
using SafeMath for uint;
|
using SafeMath for uint;
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev get ethereum address for trade
|
|
||||||
*/
|
|
||||||
function getAddressETH() public pure returns (address eth) {
|
|
||||||
eth = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev get Uniswap Proxy address
|
* @dev get Uniswap Proxy address
|
||||||
*/
|
*/
|
||||||
|
@ -77,7 +66,7 @@ contract Helper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Uniswap's Exchange address from Factory Contract
|
// Get Uniswap's Exchange address from Factory Contract
|
||||||
function getExchangeAddress(address _token) public view returns (address) {
|
function getAddressPool(address _token) public view returns (address) {
|
||||||
return UniswapFactory(getAddressUniFactory()).getExchange(_token);
|
return UniswapFactory(getAddressUniFactory()).getExchange(_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,29 +91,10 @@ contract Helper {
|
||||||
* @return tknBal - if not eth, erc20 balance
|
* @return tknBal - if not eth, erc20 balance
|
||||||
*/
|
*/
|
||||||
function getBal(address src, address _owner) public view returns (uint, uint) {
|
function getBal(address src, address _owner) public view returns (uint, uint) {
|
||||||
uint tknBal;
|
uint tknBal = IERC20(src).balanceOf(address(_owner));
|
||||||
if (src != getAddressETH()) {
|
|
||||||
tknBal = IERC20(src).balanceOf(address(_owner));
|
|
||||||
}
|
|
||||||
return (address(_owner).balance, tknBal);
|
return (address(_owner).balance, tknBal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev fetching token from the trader if ERC20
|
|
||||||
* @param trader is the trader
|
|
||||||
* @param src is the token which is being sold
|
|
||||||
* @param srcAmt is the amount of token being sold
|
|
||||||
*/
|
|
||||||
function getToken(address trader, address src, uint srcAmt) internal returns (uint ethQty) {
|
|
||||||
if (src == getAddressETH()) {
|
|
||||||
require(msg.value == srcAmt, "not-enough-src");
|
|
||||||
ethQty = srcAmt;
|
|
||||||
} else {
|
|
||||||
manageApproval(src, srcAmt);
|
|
||||||
IERC20(src).transferFrom(trader, address(this), srcAmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev setting allowance to kyber for the "user proxy" if required
|
* @dev setting allowance to kyber for the "user proxy" if required
|
||||||
* @param token is the token address
|
* @param token is the token address
|
||||||
|
@ -149,6 +119,37 @@ contract Helper {
|
||||||
|
|
||||||
contract InstaUniswapPool is Helper {
|
contract InstaUniswapPool is Helper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Uniswap's pool basic details
|
||||||
|
* @param token token address to get pool. Eg:- DAI address, MKR address, etc
|
||||||
|
* @param poolAddress Uniswap pool's address
|
||||||
|
* @param name name of pool token
|
||||||
|
* @param symbol symbol of pool token
|
||||||
|
* @param decimals decimals of pool token
|
||||||
|
* @param totalSupply total supply of pool token
|
||||||
|
* @param ethReserve Total ETH balance of uniswap's pool
|
||||||
|
* @param tokenReserve Total Token balance of uniswap's pool
|
||||||
|
*/
|
||||||
|
function poolDetails(
|
||||||
|
address token
|
||||||
|
) public view returns (
|
||||||
|
address poolAddress,
|
||||||
|
bytes32 name,
|
||||||
|
bytes32 symbol,
|
||||||
|
uint256 decimals,
|
||||||
|
uint totalSupply,
|
||||||
|
uint ethReserve,
|
||||||
|
uint tokenReserve
|
||||||
|
)
|
||||||
|
{
|
||||||
|
poolAddress = getAddressPool(token);
|
||||||
|
name = UniswapPool(poolAddress).name();
|
||||||
|
symbol = UniswapPool(poolAddress).symbol();
|
||||||
|
decimals = UniswapPool(poolAddress).decimals();
|
||||||
|
totalSupply = UniswapPool(poolAddress).totalSupply();
|
||||||
|
(ethReserve, tokenReserve) = getBal(token, poolAddress);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title to add liquidity in pool
|
* @title to add liquidity in pool
|
||||||
* @dev payable function token qty to deposit is decided as per the ETH sent by the user
|
* @dev payable function token qty to deposit is decided as per the ETH sent by the user
|
||||||
|
@ -156,13 +157,13 @@ contract InstaUniswapPool is Helper {
|
||||||
* @param maxDepositedTokens Max token to be deposited
|
* @param maxDepositedTokens Max token to be deposited
|
||||||
*/
|
*/
|
||||||
function addLiquidity(address token, uint maxDepositedTokens) public payable returns (uint256 tokensMinted) {
|
function addLiquidity(address token, uint maxDepositedTokens) public payable returns (uint256 tokensMinted) {
|
||||||
address exchangeAddr = getExchangeAddress(token);
|
address poolAddr = getAddressPool(token);
|
||||||
(uint exchangeEthBal, uint exchangeTokenBal) = getBal(token, exchangeAddr);
|
(uint ethReserve, uint tokenReserve) = getBal(token, poolAddr);
|
||||||
uint tokenToDeposit = msg.value * exchangeTokenBal / exchangeEthBal + 1;
|
uint tokenToDeposit = msg.value * tokenReserve / ethReserve + 1;
|
||||||
require(tokenToDeposit < maxDepositedTokens, "Token to deposit is greater than Max token to Deposit");
|
require(tokenToDeposit < maxDepositedTokens, "Token to deposit is greater than Max token to Deposit");
|
||||||
IERC20(token).transferFrom(msg.sender, address(this), tokenToDeposit);
|
IERC20(token).transferFrom(msg.sender, address(this), tokenToDeposit);
|
||||||
manageApproval(token, tokenToDeposit, exchangeAddr);
|
manageApproval(token, tokenToDeposit, poolAddr);
|
||||||
tokensMinted = UniswapPool(exchangeAddr).addLiquidity.value(msg.value)(
|
tokensMinted = UniswapPool(poolAddr).addLiquidity.value(msg.value)(
|
||||||
uint(0),
|
uint(0),
|
||||||
tokenToDeposit,
|
tokenToDeposit,
|
||||||
uint(1899063809) // 6th March 2030 GMT // no logic
|
uint(1899063809) // 6th March 2030 GMT // no logic
|
||||||
|
@ -184,9 +185,9 @@ contract InstaUniswapPool is Helper {
|
||||||
uint minTokens
|
uint minTokens
|
||||||
) public returns (uint ethReturned, uint tokenReturned)
|
) public returns (uint ethReturned, uint tokenReturned)
|
||||||
{
|
{
|
||||||
address exchangeAddr = getExchangeAddress(token);
|
address poolAddr = getAddressPool(token);
|
||||||
manageApproval(exchangeAddr, amount, exchangeAddr);
|
manageApproval(poolAddr, amount, poolAddr);
|
||||||
(ethReturned, tokenReturned) = UniswapPool(exchangeAddr).removeLiquidity(
|
(ethReturned, tokenReturned) = UniswapPool(poolAddr).removeLiquidity(
|
||||||
amount,
|
amount,
|
||||||
minEth,
|
minEth,
|
||||||
minTokens,
|
minTokens,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user