jeduardogruiz commited on
Commit
a285bb7
1 Parent(s): b6664fd

Create buildf.py

Browse files
Files changed (1) hide show
  1. buildf.py +70 -0
buildf.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // **** ADD LIQUIDITY ****
2
+ function _addLiquidity( # to tokens 'honey' with the liquidity view code '0.00'[for example:
3
+ address tokenA, ## token A(0xb0557906c617f0048A700758606f64b33D0C41A6),
4
+ address tokenB, ## token B(0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d)
5
+ uint amountADesired,### <!-- rest of code -->
6
+ uint amountBDesired,
7
+ uint /amountAMin,
8
+ uint amountBMin
9
+ ) internal virtual returns (uint amountA, uint amountB) {
10
+ // create the pair if it doesn't exist yet
11
+ if (IOKCSwapFactory(factory).getPair(tokenA, tokenB) == address(0)) {
12
+ IOKCSwapFactory(factory).createPair(tokenA, tokenB);
13
+ }
14
+ (uint reserveA, uint reserveB) = OKCSwapLibrary.getReserves(factory, tokenA, tokenB, pairCodeHash);
15
+ if (reserveA == 0 && reserveB == 0) {
16
+ (amountA, amountB) = (amountADesired, amountBDesired);
17
+ } else {
18
+ uint amountBOptimal = OKCSwapLibrary.quote(amountADesired, reserveA, reserveB);
19
+ if (amountBOptimal <= amountBDesired) {
20
+ require(amountBOptimal >= amountBMin, 'OKCSwapRouter: INSUFFICIENT_B_AMOUNT');
21
+ (amountA, amountB) = (amountADesired, amountBOptimal);
22
+ } else {
23
+ uint amountAOptimal = OKCSwapLibrary.quote(amountBDesired, reserveB, reserveA);
24
+ assert(amountAOptimal <= amountADesired);
25
+ require(amountAOptimal >= amountAMin, 'OKCSwapRouter: INSUFFICIENT_A_AMOUNT');
26
+ (amountA, amountB) = (amountAOptimal, amountBDesired);
27
+ }
28
+ }
29
+ }
30
+ function addLiquidity(
31
+ address tokenA,
32
+ address tokenB,
33
+ uint amountADesired,
34
+ uint amountBDesired,
35
+ uint amountAMin,
36
+ uint amountBMin,
37
+ address to,
38
+ uint deadline
39
+ ) external virtual override ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) {
40
+ (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);
41
+ address pair = OKCSwapLibrary.pairFor(factory, tokenA, tokenB, pairCodeHash);
42
+ TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA);
43
+ TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB);
44
+ liquidity = IOKCSwapPair(pair).mint(to);
45
+ }
46
+ function addLiquidityOKT( # add liquidity for to token: (0xb0557906c617f0048A700758606f64b33D0C41A6)
47
+ address token,
48
+ uint amountTokenDesired,
49
+ uint amountTokenMin,
50
+ uint amountOKTMin,
51
+ address to,
52
+ uint deadline
53
+ ) external virtual override payable ensure(deadline) returns (uint amountToken, uint amountOKT, uint liquidity) {
54
+ (amountToken, amountOKT) = _addLiquidity(
55
+ token,
56
+ WOKT,
57
+ amountTokenDesired,
58
+ msg.value,
59
+ amountTokenMin,
60
+ amountOKTMin
61
+ );
62
+ address pair = OKCSwapLibrary.pairFor(factory, token, WOKT, pairCodeHash);
63
+ TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken);
64
+ IWOKT(WOKT).deposit{value: amountOKT}();
65
+ assert(IWOKT(WOKT).transfer(pair, amountOKT));
66
+ liquidity = IOKCSwapPair(pair).mint(to);
67
+ // refund dust OKT, if any
68
+ if (msg.value > amountOKT) TransferHelper.safeTransferOKT(msg.sender, msg.value - amountOKT);
69
+ }
70
+