Mixtral_ether / buildf.py
jeduardogruiz's picture
Create buildf.py
a285bb7 verified
// **** ADD LIQUIDITY ****
function _addLiquidity( # to tokens 'honey' with the liquidity view code '0.00'[for example:
address tokenA, ## token A(0xb0557906c617f0048A700758606f64b33D0C41A6),
address tokenB, ## token B(0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d)
uint amountADesired,### <!-- rest of code -->
uint amountBDesired,
uint /amountAMin,
uint amountBMin
) internal virtual returns (uint amountA, uint amountB) {
// create the pair if it doesn't exist yet
if (IOKCSwapFactory(factory).getPair(tokenA, tokenB) == address(0)) {
IOKCSwapFactory(factory).createPair(tokenA, tokenB);
}
(uint reserveA, uint reserveB) = OKCSwapLibrary.getReserves(factory, tokenA, tokenB, pairCodeHash);
if (reserveA == 0 && reserveB == 0) {
(amountA, amountB) = (amountADesired, amountBDesired);
} else {
uint amountBOptimal = OKCSwapLibrary.quote(amountADesired, reserveA, reserveB);
if (amountBOptimal <= amountBDesired) {
require(amountBOptimal >= amountBMin, 'OKCSwapRouter: INSUFFICIENT_B_AMOUNT');
(amountA, amountB) = (amountADesired, amountBOptimal);
} else {
uint amountAOptimal = OKCSwapLibrary.quote(amountBDesired, reserveB, reserveA);
assert(amountAOptimal <= amountADesired);
require(amountAOptimal >= amountAMin, 'OKCSwapRouter: INSUFFICIENT_A_AMOUNT');
(amountA, amountB) = (amountAOptimal, amountBDesired);
}
}
}
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external virtual override ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) {
(amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);
address pair = OKCSwapLibrary.pairFor(factory, tokenA, tokenB, pairCodeHash);
TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA);
TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB);
liquidity = IOKCSwapPair(pair).mint(to);
}
function addLiquidityOKT( # add liquidity for to token: (0xb0557906c617f0048A700758606f64b33D0C41A6)
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountOKTMin,
address to,
uint deadline
) external virtual override payable ensure(deadline) returns (uint amountToken, uint amountOKT, uint liquidity) {
(amountToken, amountOKT) = _addLiquidity(
token,
WOKT,
amountTokenDesired,
msg.value,
amountTokenMin,
amountOKTMin
);
address pair = OKCSwapLibrary.pairFor(factory, token, WOKT, pairCodeHash);
TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken);
IWOKT(WOKT).deposit{value: amountOKT}();
assert(IWOKT(WOKT).transfer(pair, amountOKT));
liquidity = IOKCSwapPair(pair).mint(to);
// refund dust OKT, if any
if (msg.value > amountOKT) TransferHelper.safeTransferOKT(msg.sender, msg.value - amountOKT);
}