mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
addLiquidity in process
This commit is contained in:
parent
fc6111de62
commit
672952a858
|
|
@ -129,8 +129,8 @@ contract Helper {
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
function setApproval(address token) internal returns (uint) {
|
function setApproval(address token, address exchangeAdd) internal returns (uint) {
|
||||||
IERC20(token).approve(getAddressUniFactory(), 2**255);
|
IERC20(token).approve(getExchangeAddress(token), 2**255);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -138,11 +138,32 @@ contract Helper {
|
||||||
* @param token is the token
|
* @param token is the token
|
||||||
*/
|
*/
|
||||||
function manageApproval(address token, uint srcAmt) internal returns (uint) {
|
function manageApproval(address token, uint srcAmt) internal returns (uint) {
|
||||||
uint tokenAllowance = IERC20(token).allowance(address(this), getAddressUniFactory());
|
address exchangeAdd = getExchangeAddress(token);
|
||||||
|
uint tokenAllowance = IERC20(token).allowance(address(this), exchangeAdd);
|
||||||
if (srcAmt > tokenAllowance) {
|
if (srcAmt > tokenAllowance) {
|
||||||
setApproval(token);
|
setApproval(token, exchangeAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
contract InstaUniswapPool is Helper {
|
||||||
|
|
||||||
|
function addLiquidity(address token, uint maxDepositedTokens) public payable returns (uint256) {
|
||||||
|
address uniswapExchangeAdd = getExchangeAddress(token);
|
||||||
|
UniswapPool uniswapExchange = UniswapPool(uniswapExchangeAdd);
|
||||||
|
uint ethQty = msg.value;
|
||||||
|
(uint exchangeEthBal, uint exchangeTokenBal) = getBal(token, uniswapExchangeAdd);
|
||||||
|
uint tokenToDeposit = ethQty*(exchangeTokenBal/exchangeEthBal);
|
||||||
|
require(tokenToDeposit < maxDepositedTokens, "Token to deposit is greater than Max token to Deposit");
|
||||||
|
manageApproval(token, tokenToDeposit);
|
||||||
|
uint tokensMinted = uniswapExchange.addLiquidity.value(ethQty)(
|
||||||
|
uint(0),
|
||||||
|
tokenToDeposit,
|
||||||
|
uint(1899063809) // 6th March 2030 GMT // no logic
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user