mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
Code cleanup and refactoring.
This commit is contained in:
parent
672952a858
commit
b73037d079
|
@ -44,6 +44,7 @@ contract UniswapPool {
|
||||||
uint256 minTokens,
|
uint256 minTokens,
|
||||||
uint256 deadline
|
uint256 deadline
|
||||||
) external returns (uint256, uint256);
|
) external returns (uint256, uint256);
|
||||||
|
|
||||||
// ERC20 comaptibility for liquidity tokens
|
// ERC20 comaptibility for liquidity tokens
|
||||||
function name() external returns (bytes32);
|
function name() external returns (bytes32);
|
||||||
function symbol() external returns (bytes32);
|
function symbol() external returns (bytes32);
|
||||||
|
@ -77,8 +78,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 getExchangeAddress(address _token) public view returns (address) {
|
||||||
UniswapFactory uniswapMain = UniswapFactory(getAddressUniFactory());
|
return UniswapFactory(getAddressUniFactory()).getExchange(_token);
|
||||||
return uniswapMain.getExchange(_token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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, address exchangeAdd) internal returns (uint) {
|
function setApproval(address token, address exchangeAddr) internal {
|
||||||
IERC20(token).approve(getExchangeAddress(token), 2**255);
|
IERC20(token).approve(exchangeAddr, 2**255);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,10 +138,10 @@ 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) {
|
||||||
address exchangeAdd = getExchangeAddress(token);
|
address exchangeAddr = getExchangeAddress(token);
|
||||||
uint tokenAllowance = IERC20(token).allowance(address(this), exchangeAdd);
|
uint tokenAllowance = IERC20(token).allowance(address(this), exchangeAddr);
|
||||||
if (srcAmt > tokenAllowance) {
|
if (srcAmt > tokenAllowance) {
|
||||||
setApproval(token, exchangeAdd);
|
setApproval(token, exchangeAddr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,20 +150,17 @@ contract Helper {
|
||||||
|
|
||||||
contract InstaUniswapPool is Helper {
|
contract InstaUniswapPool is Helper {
|
||||||
|
|
||||||
function addLiquidity(address token, uint maxDepositedTokens) public payable returns (uint256) {
|
function addLiquidity(address token, uint maxDepositedTokens) public payable returns (uint256 tokensMinted) {
|
||||||
address uniswapExchangeAdd = getExchangeAddress(token);
|
address exchangeAddr = getExchangeAddress(token);
|
||||||
UniswapPool uniswapExchange = UniswapPool(uniswapExchangeAdd);
|
(uint exchangeEthBal, uint exchangeTokenBal) = getBal(token, exchangeAddr);
|
||||||
uint ethQty = msg.value;
|
uint tokenToDeposit = msg.value * (exchangeTokenBal/exchangeEthBal);
|
||||||
(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");
|
require(tokenToDeposit < maxDepositedTokens, "Token to deposit is greater than Max token to Deposit");
|
||||||
manageApproval(token, tokenToDeposit);
|
manageApproval(token, tokenToDeposit);
|
||||||
uint tokensMinted = uniswapExchange.addLiquidity.value(ethQty)(
|
tokensMinted = UniswapPool(exchangeAddr).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
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user