├── BogOrderRouter.sol
├── LICENSE
├── LimitOrders.sol
└── README.md
/BogOrderRouter.sol:
--------------------------------------------------------------------------------
1 | /** Limit Orders for Pancakeswap, Copyright BogTools 2021.
2 | *
3 | * This program is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU Affero General Public License as
5 | * published by the Free Software Foundation, either version 3 of the
6 | * License, or (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU Affero General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU Affero General Public License
14 | * along with this program. If not, see .
15 | **/
16 |
17 |
18 | pragma solidity ^0.7.4;
19 |
20 | /**
21 | * $$$$$$$\ $$$$$$$$\ $$\
22 | * $$ __$$\ \__$$ __| $$ |
23 | * $$ | $$ | $$$$$$\ $$$$$$\ $$ | $$$$$$\ $$$$$$\ $$ | $$$$$$$\
24 | * $$$$$$$\ |$$ __$$\ $$ __$$\ $$ |$$ __$$\ $$ __$$\ $$ |$$ _____|
25 | * $$ __$$\ $$ / $$ |$$ / $$ |$$ |$$ / $$ |$$ / $$ |$$ |\$$$$$$\
26 | * $$ | $$ |$$ | $$ |$$ | $$ |$$ |$$ | $$ |$$ | $$ |$$ | \____$$\
27 | * $$$$$$$ |\$$$$$$ |\$$$$$$$ |$$ |\$$$$$$ |\$$$$$$ |$$ |$$$$$$$ |
28 | * \_______/ \______/ \____$$ |\__| \______/ \______/ \__|\_______/
29 | * $$\ $$ |
30 | * \$$$$$$ |
31 | * \______/
32 | *
33 | * BogTools / Bogged Finance
34 | *
35 | * Website:
36 | * - https://bogtools.io
37 | * - https://bogged.finance
38 | *
39 | * Telegram: https://t.me/bogtools
40 | */
41 |
42 | /**
43 | * Standard SafeMath, stripped down to just add/sub/mul/div
44 | */
45 | library SafeMath {
46 | function add(uint256 a, uint256 b) internal pure returns (uint256) {
47 | uint256 c = a + b;
48 | require(c >= a, "SafeMath: addition overflow");
49 |
50 | return c;
51 | }
52 | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
53 | return sub(a, b, "SafeMath: subtraction overflow");
54 | }
55 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
56 | require(b <= a, errorMessage);
57 | uint256 c = a - b;
58 |
59 | return c;
60 | }
61 | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
62 | if (a == 0) {
63 | return 0;
64 | }
65 |
66 | uint256 c = a * b;
67 | require(c / a == b, "SafeMath: multiplication overflow");
68 |
69 | return c;
70 | }
71 | function div(uint256 a, uint256 b) internal pure returns (uint256) {
72 | return div(a, b, "SafeMath: division by zero");
73 | }
74 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
75 | // Solidity only automatically asserts when dividing by 0
76 | require(b > 0, errorMessage);
77 | uint256 c = a / b;
78 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold
79 |
80 | return c;
81 | }
82 | }
83 |
84 | /**
85 | * BEP20 standard interface.
86 | */
87 | interface IBEP20 {
88 | function totalSupply() external view returns (uint256);
89 | function decimals() external view returns (uint8);
90 | function symbol() external view returns (string memory);
91 | function name() external view returns (string memory);
92 | function getOwner() external view returns (address);
93 | function balanceOf(address account) external view returns (uint256);
94 | function transfer(address recipient, uint256 amount) external returns (bool);
95 | function allowance(address _owner, address spender) external view returns (uint256);
96 | function approve(address spender, uint256 amount) external returns (bool);
97 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
98 | event Transfer(address indexed from, address indexed to, uint256 value);
99 | event Approval(address indexed owner, address indexed spender, uint256 value);
100 | }
101 |
102 | library PancakeLibrary {
103 | using SafeMath for uint;
104 |
105 | // returns sorted token addresses, used to handle return values from pairs sorted in this order
106 | function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
107 | require(tokenA != tokenB, 'PancakeLibrary: IDENTICAL_ADDRESSES');
108 | (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
109 | require(token0 != address(0), 'PancakeLibrary: ZERO_ADDRESS');
110 | }
111 |
112 | // calculates the CREATE2 address for a pair without making any external calls
113 | function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
114 | (address token0, address token1) = sortTokens(tokenA, tokenB);
115 | pair = address(uint(keccak256(abi.encodePacked(
116 | hex'ff',
117 | factory,
118 | keccak256(abi.encodePacked(token0, token1)),
119 | hex'd0d4c4cd0848c93cb4fd1f498d7013ee6bfb25783ea21593d5834f5d250ece66' // init code hash
120 | ))));
121 | }
122 |
123 | // fetches and sorts the reserves for a pair
124 | function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
125 | (address token0,) = sortTokens(tokenA, tokenB);
126 | pairFor(factory, tokenA, tokenB);
127 | (uint reserve0, uint reserve1,) = IPancakePair(pairFor(factory, tokenA, tokenB)).getReserves();
128 | (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
129 | }
130 |
131 | // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
132 | function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
133 | require(amountA > 0, 'PancakeLibrary: INSUFFICIENT_AMOUNT');
134 | require(reserveA > 0 && reserveB > 0, 'PancakeLibrary: INSUFFICIENT_LIQUIDITY');
135 | amountB = amountA.mul(reserveB) / reserveA;
136 | }
137 |
138 | // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
139 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
140 | require(amountIn > 0, 'PancakeLibrary: INSUFFICIENT_INPUT_AMOUNT');
141 | require(reserveIn > 0 && reserveOut > 0, 'PancakeLibrary: INSUFFICIENT_LIQUIDITY');
142 |
143 | // uniswap
144 | //uint amountInWithFee = amountIn.mul(997);
145 |
146 | //pancakeswap
147 | uint amountInWithFee = amountIn.mul(998);
148 |
149 | uint numerator = amountInWithFee.mul(reserveOut);
150 | uint denominator = reserveIn.mul(1000).add(amountInWithFee);
151 | amountOut = numerator / denominator;
152 | }
153 |
154 | // given an output amount of an asset and pair reserves, returns a required input amount of the other asset
155 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
156 | require(amountOut > 0, 'PancakeLibrary: INSUFFICIENT_OUTPUT_AMOUNT');
157 | require(reserveIn > 0 && reserveOut > 0, 'PancakeLibrary: INSUFFICIENT_LIQUIDITY');
158 | uint numerator = reserveIn.mul(amountOut).mul(1000);
159 | uint denominator = reserveOut.sub(amountOut).mul(998);
160 | amountIn = (numerator / denominator).add(1);
161 | }
162 |
163 | // performs chained getAmountOut calculations on any number of pairs
164 | function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
165 | require(path.length >= 2, 'PancakeLibrary: INVALID_PATH');
166 | amounts = new uint[](path.length);
167 | amounts[0] = amountIn;
168 | for (uint i; i < path.length - 1; i++) {
169 | (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
170 | amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
171 | }
172 | }
173 |
174 | // performs chained getAmountIn calculations on any number of pairs
175 | function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
176 | require(path.length >= 2, 'PancakeLibrary: INVALID_PATH');
177 | amounts = new uint[](path.length);
178 | amounts[amounts.length - 1] = amountOut;
179 | for (uint i = path.length - 1; i > 0; i--) {
180 | (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
181 | amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
182 | }
183 | }
184 | }
185 |
186 | // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
187 | library TransferHelper {
188 | function safeApprove(address token, address to, uint value) internal {
189 | // bytes4(keccak256(bytes('approve(address,uint256)')));
190 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
191 | require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
192 | }
193 |
194 | function safeTransfer(address token, address to, uint value) internal {
195 | // bytes4(keccak256(bytes('transfer(address,uint256)')));
196 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
197 | require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
198 | }
199 |
200 | function safeTransferFrom(address token, address from, address to, uint value) internal {
201 | // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
202 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
203 | require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
204 | }
205 |
206 | function safeTransferETH(address to, uint value) internal {
207 | (bool success,) = to.call{value:value}(new bytes(0));
208 | require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
209 | }
210 | }
211 |
212 | interface IBog {
213 | function distribute(uint256 amount) external;
214 | }
215 |
216 | interface IWBNB {
217 | function deposit() external payable;
218 | function transfer(address to, uint value) external returns (bool);
219 | function withdraw(uint) external;
220 | }
221 |
222 | /**
223 | * PancakeswapFactory
224 | */
225 | interface IPancakeFactory {
226 | event PairCreated(address indexed token0, address indexed token1, address pair, uint);
227 |
228 | function feeTo() external view returns (address);
229 | function feeToSetter() external view returns (address);
230 |
231 | function getPair(address tokenA, address tokenB) external view returns (address pair);
232 | function allPairs(uint) external view returns (address pair);
233 | function allPairsLength() external view returns (uint);
234 |
235 | function createPair(address tokenA, address tokenB) external returns (address pair);
236 |
237 | function setFeeTo(address) external;
238 | function setFeeToSetter(address) external;
239 | }
240 |
241 | /**
242 | * PancakeswapPair
243 | */
244 | interface IPancakePair {
245 | event Approval(address indexed owner, address indexed spender, uint value);
246 | event Transfer(address indexed from, address indexed to, uint value);
247 |
248 | function name() external pure returns (string memory);
249 | function symbol() external pure returns (string memory);
250 | function decimals() external pure returns (uint8);
251 | function totalSupply() external view returns (uint);
252 | function balanceOf(address owner) external view returns (uint);
253 | function allowance(address owner, address spender) external view returns (uint);
254 |
255 | function approve(address spender, uint value) external returns (bool);
256 | function transfer(address to, uint value) external returns (bool);
257 | function transferFrom(address from, address to, uint value) external returns (bool);
258 |
259 | function DOMAIN_SEPARATOR() external view returns (bytes32);
260 | function PERMIT_TYPEHASH() external pure returns (bytes32);
261 | function nonces(address owner) external view returns (uint);
262 |
263 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
264 |
265 | event Mint(address indexed sender, uint amount0, uint amount1);
266 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
267 | event Swap(
268 | address indexed sender,
269 | uint amount0In,
270 | uint amount1In,
271 | uint amount0Out,
272 | uint amount1Out,
273 | address indexed to
274 | );
275 | event Sync(uint112 reserve0, uint112 reserve1);
276 |
277 | function MINIMUM_LIQUIDITY() external pure returns (uint);
278 | function factory() external view returns (address);
279 | function token0() external view returns (address);
280 | function token1() external view returns (address);
281 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
282 | function price0CumulativeLast() external view returns (uint);
283 | function price1CumulativeLast() external view returns (uint);
284 | function kLast() external view returns (uint);
285 |
286 | function mint(address to) external returns (uint liquidity);
287 | function burn(address to) external returns (uint amount0, uint amount1);
288 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
289 | function skim(address to) external;
290 | function sync() external;
291 |
292 | function initialize(address, address) external;
293 | }
294 |
295 | /**
296 | * PancakeswapRouter
297 | */
298 | interface IPancakeRouter01 {
299 | function factory() external pure returns (address);
300 | function WETH() external pure returns (address);
301 |
302 | function addLiquidity(
303 | address tokenA,
304 | address tokenB,
305 | uint amountADesired,
306 | uint amountBDesired,
307 | uint amountAMin,
308 | uint amountBMin,
309 | address to,
310 | uint deadline
311 | ) external returns (uint amountA, uint amountB, uint liquidity);
312 | function addLiquidityETH(
313 | address token,
314 | uint amountTokenDesired,
315 | uint amountTokenMin,
316 | uint amountETHMin,
317 | address to,
318 | uint deadline
319 | ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
320 | function removeLiquidity(
321 | address tokenA,
322 | address tokenB,
323 | uint liquidity,
324 | uint amountAMin,
325 | uint amountBMin,
326 | address to,
327 | uint deadline
328 | ) external returns (uint amountA, uint amountB);
329 | function removeLiquidityETH(
330 | address token,
331 | uint liquidity,
332 | uint amountTokenMin,
333 | uint amountETHMin,
334 | address to,
335 | uint deadline
336 | ) external returns (uint amountToken, uint amountETH);
337 | function removeLiquidityWithPermit(
338 | address tokenA,
339 | address tokenB,
340 | uint liquidity,
341 | uint amountAMin,
342 | uint amountBMin,
343 | address to,
344 | uint deadline,
345 | bool approveMax, uint8 v, bytes32 r, bytes32 s
346 | ) external returns (uint amountA, uint amountB);
347 | function removeLiquidityETHWithPermit(
348 | address token,
349 | uint liquidity,
350 | uint amountTokenMin,
351 | uint amountETHMin,
352 | address to,
353 | uint deadline,
354 | bool approveMax, uint8 v, bytes32 r, bytes32 s
355 | ) external returns (uint amountToken, uint amountETH);
356 | function swapExactTokensForTokens(
357 | uint amountIn,
358 | uint amountOutMin,
359 | address[] calldata path,
360 | address to,
361 | uint deadline
362 | ) external returns (uint[] memory amounts);
363 | function swapTokensForExactTokens(
364 | uint amountOut,
365 | uint amountInMax,
366 | address[] calldata path,
367 | address to,
368 | uint deadline
369 | ) external returns (uint[] memory amounts);
370 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
371 | external
372 | payable
373 | returns (uint[] memory amounts);
374 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
375 | external
376 | returns (uint[] memory amounts);
377 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
378 | external
379 | returns (uint[] memory amounts);
380 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
381 | external
382 | payable
383 | returns (uint[] memory amounts);
384 |
385 | function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
386 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
387 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
388 | function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
389 | function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
390 | }
391 |
392 | interface IPancakeRouter02 is IPancakeRouter01 {
393 | function removeLiquidityETHSupportingFeeOnTransferTokens(
394 | address token,
395 | uint liquidity,
396 | uint amountTokenMin,
397 | uint amountETHMin,
398 | address to,
399 | uint deadline
400 | ) external returns (uint amountETH);
401 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
402 | address token,
403 | uint liquidity,
404 | uint amountTokenMin,
405 | uint amountETHMin,
406 | address to,
407 | uint deadline,
408 | bool approveMax, uint8 v, bytes32 r, bytes32 s
409 | ) external returns (uint amountETH);
410 |
411 | function swapExactTokensForTokensSupportingFeeOnTransferTokens(
412 | uint amountIn,
413 | uint amountOutMin,
414 | address[] calldata path,
415 | address to,
416 | uint deadline
417 | ) external;
418 | function swapExactETHForTokensSupportingFeeOnTransferTokens(
419 | uint amountOutMin,
420 | address[] calldata path,
421 | address to,
422 | uint deadline
423 | ) external payable;
424 | function swapExactTokensForETHSupportingFeeOnTransferTokens(
425 | uint amountIn,
426 | uint amountOutMin,
427 | address[] calldata path,
428 | address to,
429 | uint deadline
430 | ) external;
431 | }
432 |
433 | /**
434 | * Provides ownable & authorized contexts
435 | */
436 | abstract contract BogAuth {
437 | address payable _owner;
438 | mapping (address => bool) _authorizations;
439 |
440 | constructor() {
441 | _owner = msg.sender;
442 | _authorizations[msg.sender] = true;
443 | }
444 |
445 | /**
446 | * Check if address is owner
447 | */
448 | function isOwner(address account) public view returns (bool) {
449 | return account == _owner;
450 | }
451 |
452 | /**
453 | * Function modifier to require caller to be contract owner
454 | */
455 | modifier owned() {
456 | require(isOwner(msg.sender)); _;
457 | }
458 |
459 | /**
460 | * Function modifier to require caller to be authorized
461 | */
462 | modifier authorized() {
463 | require(_authorizations[msg.sender] == true); _;
464 | }
465 |
466 | /**
467 | * Authorize address. Any authorized address
468 | */
469 | function authorize(address adr) public authorized {
470 | _authorizations[adr] = true;
471 | }
472 |
473 | /**
474 | * Remove address' authorization. Owner only
475 | */
476 | function unauthorize(address adr) public authorized {
477 | require(adr != _owner);
478 | _authorizations[adr] = false;
479 | }
480 |
481 | /**
482 | * Transfer ownership to new address. Caller must be owner.
483 | */
484 | function transferOwnership(address payable adr) public owned {
485 | _owner = adr;
486 | _authorizations[adr] = true;
487 | }
488 | }
489 |
490 | /**
491 | * Use second contract for router as allows try catch on external router calls from main contract to make cancelling failing swaps possible in same tx
492 | */
493 | contract BogOrderRouter {
494 | using SafeMath for uint256;
495 |
496 | enum OrderStatus { PENDING, FILLED, CANCELLED }
497 | enum OrderType { BNB_TOKEN, TOKEN_TOKEN, TOKEN_BNB }
498 |
499 | struct Order {
500 | uint256 id; // Order ID
501 | uint256 pendingIndex; // Index in pending order array
502 | address owner; // Order placer
503 | OrderStatus status; // Order status
504 | OrderType swapType; // Order type
505 | address tokenIn; // Token to swap
506 | address tokenOut; // Token to swap for
507 | address pair; // PancakeswapPair
508 | uint256 amountIn; // BNB Amount in
509 | uint256 targetAmountOut; // Price to trigger order at
510 | uint256 minAmountOut; // Max price to trigger order at (in case price changed before tx has been mined)
511 | uint256 timestamp;
512 | uint256 feePaid;
513 | }
514 |
515 | address public constant WBNB = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
516 |
517 | address authorizedCaller;
518 |
519 | constructor () {
520 | authorizedCaller = msg.sender;
521 | }
522 |
523 | modifier onlyAuthorized() {
524 | require(msg.sender == authorizedCaller); _;
525 | }
526 |
527 | receive() external payable {
528 | assert(msg.sender == WBNB);
529 | }
530 |
531 | function makeTokenTokenSwap(address owner, address tokenIn, address tokenOut, address pair, uint256 amountIn, uint256 minAmountOut) external onlyAuthorized {
532 | TransferHelper.safeTransferFrom(
533 | tokenIn, owner, pair, amountIn
534 | );
535 |
536 | uint balanceBefore = IBEP20(tokenOut).balanceOf(owner);
537 | _swap(pair, tokenIn, tokenOut, owner);
538 |
539 | require(
540 | IBEP20(tokenOut).balanceOf(owner).sub(balanceBefore) >= minAmountOut,
541 | 'BogRouter: INSUFFICIENT_OUTPUT_AMOUNT'
542 | );
543 | }
544 |
545 | function makeBNBTokenSwap(address owner, address tokenIn, address tokenOut, address pair, uint256 amountIn, uint256 minAmountOut) external payable onlyAuthorized {
546 | // Swap bnb for wbnb then transfer to pair
547 | IWBNB(WBNB).deposit{value: amountIn}();
548 | assert(IWBNB(WBNB).transfer(pair, amountIn));
549 |
550 | uint balanceBefore = IBEP20(tokenOut).balanceOf(owner);
551 | _swap(pair, tokenIn, tokenOut, owner);
552 |
553 | require(
554 | IBEP20(tokenOut).balanceOf(owner).sub(balanceBefore) >= minAmountOut,
555 | 'BogRouter: INSUFFICIENT_OUTPUT_AMOUNT'
556 | );
557 | }
558 |
559 | function makeTokenBNBSwap(address owner, address tokenIn, address tokenOut, address pair, uint256 amountIn, uint256 minAmountOut) external onlyAuthorized {
560 | TransferHelper.safeTransferFrom(
561 | tokenIn, owner, pair, amountIn
562 | );
563 |
564 | uint balanceBefore = IBEP20(WBNB).balanceOf(address(this));
565 | _swap(pair, tokenIn, tokenOut, address(this));
566 |
567 | uint amountOut = IBEP20(WBNB).balanceOf(address(this)).sub(balanceBefore);
568 |
569 | require(amountOut >= minAmountOut, 'BogRouter: INSUFFICIENT_OUTPUT_AMOUNT');
570 |
571 | IWBNB(WBNB).withdraw(amountOut);
572 |
573 | TransferHelper.safeTransferETH(owner, amountOut);
574 | }
575 |
576 | function _swap(address _pair, address tokenIn, address tokenOut, address to) internal virtual {
577 | (address token0,) = PancakeLibrary.sortTokens(tokenIn, tokenOut);
578 | IPancakePair pair = IPancakePair(_pair);
579 |
580 | uint amountInput;
581 | uint amountOutput;
582 |
583 | { // scope to avoid stack too deep errors
584 | (uint reserve0, uint reserve1,) = pair.getReserves();
585 | (uint reserveInput, uint reserveOutput) = tokenIn == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
586 | amountInput = IBEP20(tokenIn).balanceOf(address(pair)).sub(reserveInput);
587 | amountOutput = PancakeLibrary.getAmountOut(amountInput, reserveInput, reserveOutput);
588 | }
589 |
590 | (uint amount0Out, uint amount1Out) = tokenIn == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0));
591 | pair.swap(amount0Out, amount1Out, to, new bytes(0));
592 | }
593 | }
594 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published by
637 | the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/LimitOrders.sol:
--------------------------------------------------------------------------------
1 | /** Limit Orders for Pancakeswap, Copyright BogTools 2021.
2 | *
3 | * This program is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU Affero General Public License as
5 | * published by the Free Software Foundation, either version 3 of the
6 | * License, or (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU Affero General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU Affero General Public License
14 | * along with this program. If not, see .
15 | **/
16 |
17 | pragma solidity ^0.7.4;
18 |
19 | /**
20 | * $$$$$$$\ $$$$$$$$\ $$\
21 | * $$ __$$\ \__$$ __| $$ |
22 | * $$ | $$ | $$$$$$\ $$$$$$\ $$ | $$$$$$\ $$$$$$\ $$ | $$$$$$$\
23 | * $$$$$$$\ |$$ __$$\ $$ __$$\ $$ |$$ __$$\ $$ __$$\ $$ |$$ _____|
24 | * $$ __$$\ $$ / $$ |$$ / $$ |$$ |$$ / $$ |$$ / $$ |$$ |\$$$$$$\
25 | * $$ | $$ |$$ | $$ |$$ | $$ |$$ |$$ | $$ |$$ | $$ |$$ | \____$$\
26 | * $$$$$$$ |\$$$$$$ |\$$$$$$$ |$$ |\$$$$$$ |\$$$$$$ |$$ |$$$$$$$ |
27 | * \_______/ \______/ \____$$ |\__| \______/ \______/ \__|\_______/
28 | * $$\ $$ |
29 | * \$$$$$$ |
30 | * \______/
31 | *
32 | * BogTools / Bogged Finance
33 | *
34 | * Website:
35 | * - https://bogtools.io
36 | * - https://bogged.finance
37 | *
38 | * Telegram: https://t.me/bogtools
39 | */
40 |
41 | /**
42 | * Standard SafeMath, stripped down to just add/sub/mul/div
43 | */
44 | library SafeMath {
45 | function add(uint256 a, uint256 b) internal pure returns (uint256) {
46 | uint256 c = a + b;
47 | require(c >= a, "SafeMath: addition overflow");
48 |
49 | return c;
50 | }
51 | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
52 | return sub(a, b, "SafeMath: subtraction overflow");
53 | }
54 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
55 | require(b <= a, errorMessage);
56 | uint256 c = a - b;
57 |
58 | return c;
59 | }
60 | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
61 | if (a == 0) {
62 | return 0;
63 | }
64 |
65 | uint256 c = a * b;
66 | require(c / a == b, "SafeMath: multiplication overflow");
67 |
68 | return c;
69 | }
70 | function div(uint256 a, uint256 b) internal pure returns (uint256) {
71 | return div(a, b, "SafeMath: division by zero");
72 | }
73 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
74 | // Solidity only automatically asserts when dividing by 0
75 | require(b > 0, errorMessage);
76 | uint256 c = a / b;
77 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold
78 |
79 | return c;
80 | }
81 | }
82 |
83 | /**
84 | * BEP20 standard interface.
85 | */
86 | interface IBEP20 {
87 | function totalSupply() external view returns (uint256);
88 | function decimals() external view returns (uint8);
89 | function symbol() external view returns (string memory);
90 | function name() external view returns (string memory);
91 | function getOwner() external view returns (address);
92 | function balanceOf(address account) external view returns (uint256);
93 | function transfer(address recipient, uint256 amount) external returns (bool);
94 | function allowance(address _owner, address spender) external view returns (uint256);
95 | function approve(address spender, uint256 amount) external returns (bool);
96 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
97 | event Transfer(address indexed from, address indexed to, uint256 value);
98 | event Approval(address indexed owner, address indexed spender, uint256 value);
99 | }
100 |
101 | library PancakeLibrary {
102 | using SafeMath for uint;
103 |
104 | // returns sorted token addresses, used to handle return values from pairs sorted in this order
105 | function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
106 | require(tokenA != tokenB, 'PancakeLibrary: IDENTICAL_ADDRESSES');
107 | (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
108 | require(token0 != address(0), 'PancakeLibrary: ZERO_ADDRESS');
109 | }
110 |
111 | // calculates the CREATE2 address for a pair without making any external calls
112 | function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
113 | (address token0, address token1) = sortTokens(tokenA, tokenB);
114 | pair = address(uint(keccak256(abi.encodePacked(
115 | hex'ff',
116 | factory,
117 | keccak256(abi.encodePacked(token0, token1)),
118 | hex'd0d4c4cd0848c93cb4fd1f498d7013ee6bfb25783ea21593d5834f5d250ece66' // init code hash
119 | ))));
120 | }
121 |
122 | // fetches and sorts the reserves for a pair
123 | function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
124 | (address token0,) = sortTokens(tokenA, tokenB);
125 | pairFor(factory, tokenA, tokenB);
126 | (uint reserve0, uint reserve1,) = IPancakePair(pairFor(factory, tokenA, tokenB)).getReserves();
127 | (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
128 | }
129 |
130 | // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
131 | function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
132 | require(amountA > 0, 'PancakeLibrary: INSUFFICIENT_AMOUNT');
133 | require(reserveA > 0 && reserveB > 0, 'PancakeLibrary: INSUFFICIENT_LIQUIDITY');
134 | amountB = amountA.mul(reserveB) / reserveA;
135 | }
136 |
137 | // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
138 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
139 | require(amountIn > 0, 'PancakeLibrary: INSUFFICIENT_INPUT_AMOUNT');
140 | require(reserveIn > 0 && reserveOut > 0, 'PancakeLibrary: INSUFFICIENT_LIQUIDITY');
141 |
142 | // uniswap
143 | //uint amountInWithFee = amountIn.mul(997);
144 |
145 | //pancakeswap
146 | uint amountInWithFee = amountIn.mul(998);
147 |
148 | uint numerator = amountInWithFee.mul(reserveOut);
149 | uint denominator = reserveIn.mul(1000).add(amountInWithFee);
150 | amountOut = numerator / denominator;
151 | }
152 |
153 | // given an output amount of an asset and pair reserves, returns a required input amount of the other asset
154 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
155 | require(amountOut > 0, 'PancakeLibrary: INSUFFICIENT_OUTPUT_AMOUNT');
156 | require(reserveIn > 0 && reserveOut > 0, 'PancakeLibrary: INSUFFICIENT_LIQUIDITY');
157 | uint numerator = reserveIn.mul(amountOut).mul(1000);
158 | uint denominator = reserveOut.sub(amountOut).mul(998);
159 | amountIn = (numerator / denominator).add(1);
160 | }
161 |
162 | // performs chained getAmountOut calculations on any number of pairs
163 | function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
164 | require(path.length >= 2, 'PancakeLibrary: INVALID_PATH');
165 | amounts = new uint[](path.length);
166 | amounts[0] = amountIn;
167 | for (uint i; i < path.length - 1; i++) {
168 | (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
169 | amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
170 | }
171 | }
172 |
173 | // performs chained getAmountIn calculations on any number of pairs
174 | function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
175 | require(path.length >= 2, 'PancakeLibrary: INVALID_PATH');
176 | amounts = new uint[](path.length);
177 | amounts[amounts.length - 1] = amountOut;
178 | for (uint i = path.length - 1; i > 0; i--) {
179 | (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
180 | amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
181 | }
182 | }
183 | }
184 |
185 | // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
186 | library TransferHelper {
187 | function safeApprove(address token, address to, uint value) internal {
188 | // bytes4(keccak256(bytes('approve(address,uint256)')));
189 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
190 | require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
191 | }
192 |
193 | function safeTransfer(address token, address to, uint value) internal {
194 | // bytes4(keccak256(bytes('transfer(address,uint256)')));
195 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
196 | require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
197 | }
198 |
199 | function safeTransferFrom(address token, address from, address to, uint value) internal {
200 | // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
201 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
202 | require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
203 | }
204 |
205 | function safeTransferETH(address to, uint value) internal {
206 | (bool success,) = to.call{value:value}(new bytes(0));
207 | require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
208 | }
209 | }
210 |
211 | interface IBog {
212 | function distribute(uint256 amount) external;
213 | }
214 |
215 | interface IWBNB {
216 | function deposit() external payable;
217 | function transfer(address to, uint value) external returns (bool);
218 | function withdraw(uint) external;
219 | }
220 |
221 | /**
222 | * PancakeswapFactory
223 | */
224 | interface IPancakeFactory {
225 | event PairCreated(address indexed token0, address indexed token1, address pair, uint);
226 |
227 | function feeTo() external view returns (address);
228 | function feeToSetter() external view returns (address);
229 |
230 | function getPair(address tokenA, address tokenB) external view returns (address pair);
231 | function allPairs(uint) external view returns (address pair);
232 | function allPairsLength() external view returns (uint);
233 |
234 | function createPair(address tokenA, address tokenB) external returns (address pair);
235 |
236 | function setFeeTo(address) external;
237 | function setFeeToSetter(address) external;
238 | }
239 |
240 | /**
241 | * PancakeswapPair
242 | */
243 | interface IPancakePair {
244 | event Approval(address indexed owner, address indexed spender, uint value);
245 | event Transfer(address indexed from, address indexed to, uint value);
246 |
247 | function name() external pure returns (string memory);
248 | function symbol() external pure returns (string memory);
249 | function decimals() external pure returns (uint8);
250 | function totalSupply() external view returns (uint);
251 | function balanceOf(address owner) external view returns (uint);
252 | function allowance(address owner, address spender) external view returns (uint);
253 |
254 | function approve(address spender, uint value) external returns (bool);
255 | function transfer(address to, uint value) external returns (bool);
256 | function transferFrom(address from, address to, uint value) external returns (bool);
257 |
258 | function DOMAIN_SEPARATOR() external view returns (bytes32);
259 | function PERMIT_TYPEHASH() external pure returns (bytes32);
260 | function nonces(address owner) external view returns (uint);
261 |
262 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
263 |
264 | event Mint(address indexed sender, uint amount0, uint amount1);
265 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
266 | event Swap(
267 | address indexed sender,
268 | uint amount0In,
269 | uint amount1In,
270 | uint amount0Out,
271 | uint amount1Out,
272 | address indexed to
273 | );
274 | event Sync(uint112 reserve0, uint112 reserve1);
275 |
276 | function MINIMUM_LIQUIDITY() external pure returns (uint);
277 | function factory() external view returns (address);
278 | function token0() external view returns (address);
279 | function token1() external view returns (address);
280 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
281 | function price0CumulativeLast() external view returns (uint);
282 | function price1CumulativeLast() external view returns (uint);
283 | function kLast() external view returns (uint);
284 |
285 | function mint(address to) external returns (uint liquidity);
286 | function burn(address to) external returns (uint amount0, uint amount1);
287 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
288 | function skim(address to) external;
289 | function sync() external;
290 |
291 | function initialize(address, address) external;
292 | }
293 |
294 | /**
295 | * PancakeswapRouter
296 | */
297 | interface IPancakeRouter01 {
298 | function factory() external pure returns (address);
299 | function WETH() external pure returns (address);
300 |
301 | function addLiquidity(
302 | address tokenA,
303 | address tokenB,
304 | uint amountADesired,
305 | uint amountBDesired,
306 | uint amountAMin,
307 | uint amountBMin,
308 | address to,
309 | uint deadline
310 | ) external returns (uint amountA, uint amountB, uint liquidity);
311 | function addLiquidityETH(
312 | address token,
313 | uint amountTokenDesired,
314 | uint amountTokenMin,
315 | uint amountETHMin,
316 | address to,
317 | uint deadline
318 | ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
319 | function removeLiquidity(
320 | address tokenA,
321 | address tokenB,
322 | uint liquidity,
323 | uint amountAMin,
324 | uint amountBMin,
325 | address to,
326 | uint deadline
327 | ) external returns (uint amountA, uint amountB);
328 | function removeLiquidityETH(
329 | address token,
330 | uint liquidity,
331 | uint amountTokenMin,
332 | uint amountETHMin,
333 | address to,
334 | uint deadline
335 | ) external returns (uint amountToken, uint amountETH);
336 | function removeLiquidityWithPermit(
337 | address tokenA,
338 | address tokenB,
339 | uint liquidity,
340 | uint amountAMin,
341 | uint amountBMin,
342 | address to,
343 | uint deadline,
344 | bool approveMax, uint8 v, bytes32 r, bytes32 s
345 | ) external returns (uint amountA, uint amountB);
346 | function removeLiquidityETHWithPermit(
347 | address token,
348 | uint liquidity,
349 | uint amountTokenMin,
350 | uint amountETHMin,
351 | address to,
352 | uint deadline,
353 | bool approveMax, uint8 v, bytes32 r, bytes32 s
354 | ) external returns (uint amountToken, uint amountETH);
355 | function swapExactTokensForTokens(
356 | uint amountIn,
357 | uint amountOutMin,
358 | address[] calldata path,
359 | address to,
360 | uint deadline
361 | ) external returns (uint[] memory amounts);
362 | function swapTokensForExactTokens(
363 | uint amountOut,
364 | uint amountInMax,
365 | address[] calldata path,
366 | address to,
367 | uint deadline
368 | ) external returns (uint[] memory amounts);
369 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
370 | external
371 | payable
372 | returns (uint[] memory amounts);
373 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
374 | external
375 | returns (uint[] memory amounts);
376 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
377 | external
378 | returns (uint[] memory amounts);
379 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
380 | external
381 | payable
382 | returns (uint[] memory amounts);
383 |
384 | function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
385 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
386 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
387 | function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
388 | function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
389 | }
390 |
391 | interface IPancakeRouter02 is IPancakeRouter01 {
392 | function removeLiquidityETHSupportingFeeOnTransferTokens(
393 | address token,
394 | uint liquidity,
395 | uint amountTokenMin,
396 | uint amountETHMin,
397 | address to,
398 | uint deadline
399 | ) external returns (uint amountETH);
400 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
401 | address token,
402 | uint liquidity,
403 | uint amountTokenMin,
404 | uint amountETHMin,
405 | address to,
406 | uint deadline,
407 | bool approveMax, uint8 v, bytes32 r, bytes32 s
408 | ) external returns (uint amountETH);
409 |
410 | function swapExactTokensForTokensSupportingFeeOnTransferTokens(
411 | uint amountIn,
412 | uint amountOutMin,
413 | address[] calldata path,
414 | address to,
415 | uint deadline
416 | ) external;
417 | function swapExactETHForTokensSupportingFeeOnTransferTokens(
418 | uint amountOutMin,
419 | address[] calldata path,
420 | address to,
421 | uint deadline
422 | ) external payable;
423 | function swapExactTokensForETHSupportingFeeOnTransferTokens(
424 | uint amountIn,
425 | uint amountOutMin,
426 | address[] calldata path,
427 | address to,
428 | uint deadline
429 | ) external;
430 | }
431 |
432 | /**
433 | * Provides ownable & authorized contexts
434 | */
435 | abstract contract BogAuth {
436 | address payable _owner;
437 | mapping (address => bool) _authorizations;
438 |
439 | constructor() {
440 | _owner = msg.sender;
441 | _authorizations[msg.sender] = true;
442 | }
443 |
444 | /**
445 | * Check if address is owner
446 | */
447 | function isOwner(address account) public view returns (bool) {
448 | return account == _owner;
449 | }
450 |
451 | /**
452 | * Function modifier to require caller to be contract owner
453 | */
454 | modifier owned() {
455 | require(isOwner(msg.sender)); _;
456 | }
457 |
458 | /**
459 | * Function modifier to require caller to be authorized
460 | */
461 | modifier authorized() {
462 | require(_authorizations[msg.sender] == true); _;
463 | }
464 |
465 | /**
466 | * Authorize address. Any authorized address
467 | */
468 | function authorize(address adr) public authorized {
469 | _authorizations[adr] = true;
470 | }
471 |
472 | /**
473 | * Remove address' authorization. Owner only
474 | */
475 | function unauthorize(address adr) public authorized {
476 | require(adr != _owner);
477 | _authorizations[adr] = false;
478 | }
479 |
480 | /**
481 | * Transfer ownership to new address. Caller must be owner.
482 | */
483 | function transferOwnership(address payable adr) public owned {
484 | _owner = adr;
485 | _authorizations[adr] = true;
486 | }
487 | }
488 |
489 | interface IBogLimitOrdersV1 {
490 | enum OrderStatus { PENDING, FILLED, CANCELLED }
491 | enum OrderType { BNB_TOKEN, TOKEN_TOKEN, TOKEN_BNB }
492 |
493 | function getRouterAddress() external view returns (address);
494 |
495 | function placeBNBTokenOrder(address tokenOut, uint256 targetAmountOut, uint256 minAmountOut) external payable;
496 | function placeTokenTokenOrder(address tokenIn, uint256 amountIn, address tokenOut, uint256 targetAmountOut, uint256 minAmountOut) external;
497 | function placeTokenBNBOrder(address tokenIn, uint256 amountIn, uint256 targetAmountOut, uint256 minAmountOut) external;
498 |
499 | function cancelOrder(uint256 orderID) external;
500 |
501 | function canFulfilOrder(uint256 orderID) external view returns (bool);
502 | function shouldFulfilOrder(uint256 orderID) external view returns (bool);
503 |
504 | function fulfilOrder(uint256 orderID) external returns (bool filled);
505 | function fulfilMany(uint256[] calldata orderIDs) external;
506 |
507 | function getPendingOrders() external view returns (uint256[] memory);
508 | function getNextReadyOrder() external view returns (uint256);
509 |
510 | function getOrdersForAddress(address adr) external view returns (uint256[] memory);
511 | function getOrdersForPair(address pair) external view returns (uint256[] memory);
512 | function getOrdersForPair(address tokenIn, address tokenOut) external view returns (uint256[] memory);
513 |
514 | event OrderPlaced(uint256 orderID, address owner, uint256 amountIn, address tokenIn, address tokenOut, uint256 targetAmountOut, uint256 minAmountOut);
515 | event OrderCancelled(uint256 orderID);
516 | event OrderFulfilled(uint256 orderID, address broker);
517 | }
518 |
519 | /**
520 | * Use second contract for router as allows try catch on external router calls from main contract to make cancelling failing swaps possible in same tx
521 | */
522 | contract BogOrderRouter {
523 | using SafeMath for uint256;
524 |
525 | enum OrderStatus { PENDING, FILLED, CANCELLED }
526 | enum OrderType { BNB_TOKEN, TOKEN_TOKEN, TOKEN_BNB }
527 |
528 | struct Order {
529 | uint256 id; // Order ID
530 | uint256 pendingIndex; // Index in pending order array
531 | address owner; // Order placer
532 | OrderStatus status; // Order status
533 | OrderType swapType; // Order type
534 | address tokenIn; // Token to swap
535 | address tokenOut; // Token to swap for
536 | address pair; // PancakeswapPair
537 | uint256 amountIn; // BNB Amount in
538 | uint256 targetAmountOut; // Price to trigger order at
539 | uint256 minAmountOut; // Max price to trigger order at (in case price changed before tx has been mined)
540 | uint256 timestamp;
541 | uint256 feePaid;
542 | }
543 |
544 | address public constant WBNB = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
545 |
546 | address authorizedCaller;
547 |
548 | constructor () {
549 | authorizedCaller = msg.sender;
550 | }
551 |
552 | modifier onlyAuthorized() {
553 | require(msg.sender == authorizedCaller); _;
554 | }
555 |
556 | receive() external payable {
557 | assert(msg.sender == WBNB);
558 | }
559 |
560 | function makeTokenTokenSwap(address owner, address tokenIn, address tokenOut, address pair, uint256 amountIn, uint256 minAmountOut) external onlyAuthorized {
561 | TransferHelper.safeTransferFrom(
562 | tokenIn, owner, pair, amountIn
563 | );
564 |
565 | uint balanceBefore = IBEP20(tokenOut).balanceOf(owner);
566 | _swap(pair, tokenIn, tokenOut, owner);
567 |
568 | require(
569 | IBEP20(tokenOut).balanceOf(owner).sub(balanceBefore) >= minAmountOut,
570 | 'BogRouter: INSUFFICIENT_OUTPUT_AMOUNT'
571 | );
572 | }
573 |
574 | function makeBNBTokenSwap(address owner, address tokenIn, address tokenOut, address pair, uint256 amountIn, uint256 minAmountOut) external payable onlyAuthorized {
575 | // Swap bnb for wbnb then transfer to pair
576 | IWBNB(WBNB).deposit{value: amountIn}();
577 | assert(IWBNB(WBNB).transfer(pair, amountIn));
578 |
579 | uint balanceBefore = IBEP20(tokenOut).balanceOf(owner);
580 | _swap(pair, tokenIn, tokenOut, owner);
581 |
582 | require(
583 | IBEP20(tokenOut).balanceOf(owner).sub(balanceBefore) >= minAmountOut,
584 | 'BogRouter: INSUFFICIENT_OUTPUT_AMOUNT'
585 | );
586 | }
587 |
588 | function makeTokenBNBSwap(address owner, address tokenIn, address tokenOut, address pair, uint256 amountIn, uint256 minAmountOut) external onlyAuthorized {
589 | TransferHelper.safeTransferFrom(
590 | tokenIn, owner, pair, amountIn
591 | );
592 |
593 | uint balanceBefore = IBEP20(WBNB).balanceOf(address(this));
594 | _swap(pair, tokenIn, tokenOut, address(this));
595 |
596 | uint amountOut = IBEP20(WBNB).balanceOf(address(this)).sub(balanceBefore);
597 |
598 | require(amountOut >= minAmountOut, 'BogRouter: INSUFFICIENT_OUTPUT_AMOUNT');
599 |
600 | IWBNB(WBNB).withdraw(amountOut);
601 |
602 | TransferHelper.safeTransferETH(owner, amountOut);
603 | }
604 |
605 | function _swap(address _pair, address tokenIn, address tokenOut, address to) internal virtual {
606 | (address token0,) = PancakeLibrary.sortTokens(tokenIn, tokenOut);
607 | IPancakePair pair = IPancakePair(_pair);
608 |
609 | uint amountInput;
610 | uint amountOutput;
611 |
612 | { // scope to avoid stack too deep errors
613 | (uint reserve0, uint reserve1,) = pair.getReserves();
614 | (uint reserveInput, uint reserveOutput) = tokenIn == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
615 | amountInput = IBEP20(tokenIn).balanceOf(address(pair)).sub(reserveInput);
616 | amountOutput = PancakeLibrary.getAmountOut(amountInput, reserveInput, reserveOutput);
617 | }
618 |
619 | (uint amount0Out, uint amount1Out) = tokenIn == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0));
620 | pair.swap(amount0Out, amount1Out, to, new bytes(0));
621 | }
622 | }
623 |
624 | /**
625 | *
626 | */
627 | contract BogLimitOrdersV1 is BogAuth, IBogLimitOrdersV1 {
628 | using SafeMath for uint256;
629 |
630 | struct Order {
631 | uint256 id; // Order ID
632 | uint256 pendingIndex; // Index in pending order array
633 | address owner; // Order placer
634 | OrderStatus status; // Order status
635 | OrderType swapType; // Order type
636 | address tokenIn; // Token to swap
637 | address tokenOut; // Token to swap for
638 | address pair; // PancakeswapPair
639 | uint256 amountIn; // BNB Amount in
640 | uint256 targetAmountOut; // Price to trigger order at
641 | uint256 minAmountOut; // Max price to trigger order at (in case price changed before tx has been mined)
642 | uint256 timestamp; // Timestamp of last action (placed / filled / cancelled / etc)
643 | uint256 feePaid;
644 | }
645 |
646 | IPancakeRouter02 public constant router = IPancakeRouter02(0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F);
647 | address public constant WBNB = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
648 | address constant BUSD = 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56;
649 | address constant WBNB_BUSD = 0x1B96B92314C44b159149f7E0303511fB2Fc4774f;
650 | address constant BOG = address(0xD7B729ef857Aa773f47D37088A1181bB3fbF0099);
651 |
652 | uint256 public constant UINT_MAX = uint256(-1);
653 |
654 | uint256 public constant PRICE_DECIMALS = 10;
655 |
656 | address public factory;
657 | uint256 public constant ORDER_EXPIRY = 7 days;
658 | uint256 public nextOrder = 1;
659 | uint256 public fee = 250; // $2.50
660 | uint256 public feeSplit = 50; // 50% to stakers
661 | uint256 public totalFees;
662 | uint256 public totalDistributed;
663 |
664 | // token blacklisting
665 | mapping (address => bool) public blacklisted;
666 | mapping (address => bool) public whitelisted;
667 | bool useWhitelist;
668 |
669 | // orders
670 | mapping (uint256 => Order) public orders;
671 | mapping (address => uint256[]) public addressOrders;
672 | mapping (address => uint256[]) public pairOrders;
673 | uint256[] pendingOrders;
674 |
675 | BogOrderRouter bogRouter;
676 |
677 | constructor () {
678 | factory = router.factory();
679 | bogRouter = new BogOrderRouter();
680 | }
681 |
682 | bool entered = false;
683 |
684 | modifier reentrancyGuard() {
685 | require(!entered, "Reentrancy Disallowed");
686 | entered = true;
687 | _;
688 | entered = false;
689 | }
690 |
691 | function getRouterAddress() external view override returns (address) {
692 | return address(bogRouter);
693 | }
694 |
695 | function placeBNBTokenOrder(address tokenOut, uint256 targetAmountOut, uint256 minAmountOut) external payable override {
696 | createOrder(msg.sender, OrderType.BNB_TOKEN, WBNB, tokenOut, msg.value, targetAmountOut, minAmountOut, takeFee());
697 | }
698 |
699 | function placeBNBTokenOrderFor(address owner, address tokenOut, uint256 targetAmountOut, uint256 minAmountOut) external payable {
700 | createOrder(owner, OrderType.BNB_TOKEN, WBNB, tokenOut, msg.value, targetAmountOut, minAmountOut, takeFee());
701 | }
702 |
703 | function placeTokenTokenOrder(address tokenIn, uint256 amountIn, address tokenOut, uint256 targetAmountOut, uint256 minAmountOut) external override {
704 | require(IBEP20(tokenIn).allowance(msg.sender, address(bogRouter)) >= amountIn, "Not enough allowance for order");
705 |
706 | createOrder(msg.sender, OrderType.BNB_TOKEN, WBNB, tokenOut, amountIn, targetAmountOut, minAmountOut, takeFee());
707 | }
708 |
709 | function placeTokenBNBOrder(address tokenIn, uint256 amountIn, uint256 targetAmountOut, uint256 minAmountOut) external override {
710 | require(IBEP20(tokenIn).allowance(msg.sender, address(bogRouter)) >= amountIn, "Not enough allowance for order");
711 |
712 | createOrder(msg.sender, OrderType.TOKEN_BNB, tokenIn, WBNB, amountIn, targetAmountOut, minAmountOut, takeFee());
713 | }
714 |
715 | function createOrder(
716 | address owner,
717 | OrderType swapType,
718 | address tokenIn,
719 | address tokenOut,
720 | uint256 amountIn,
721 | uint256 targetAmountOut,
722 | uint256 minAmountOut,
723 | uint256 feePaid
724 | )
725 | internal
726 | returns (uint256)
727 | {
728 | address pair = IPancakeFactory(factory).getPair(tokenIn, tokenOut);
729 | require(pair != address(0), "Pancakeswap pair does not exist");
730 |
731 | require(minAmountOut <= targetAmountOut, "Invalid output amounts");
732 |
733 | require(!blacklisted[tokenIn] && !blacklisted[tokenOut], "Token blacklisted");
734 | if(useWhitelist){
735 | require(whitelisted[tokenIn] && whitelisted[tokenOut], "Token not whitelisted");
736 | }
737 |
738 | uint256 orderID = nextOrder++;
739 |
740 | uint256 pendingIndex = pendingOrders.length;
741 | pendingOrders.push(orderID);
742 |
743 | addressOrders[msg.sender].push(orderID);
744 | pairOrders[pair].push(orderID);
745 |
746 | orders[orderID] = Order(
747 | orderID,
748 | pendingIndex,
749 | owner,
750 | OrderStatus.PENDING,
751 | swapType,
752 | tokenIn,
753 | tokenOut,
754 | pair,
755 | amountIn,
756 | targetAmountOut,
757 | minAmountOut,
758 | block.timestamp,
759 | feePaid
760 | );
761 |
762 | emit OrderPlaced(orderID, msg.sender, amountIn, tokenIn, tokenOut, targetAmountOut, minAmountOut);
763 | return orderID;
764 | }
765 |
766 | function cancelOrder(uint256 orderID) external override {
767 | Order memory ord = orders[orderID]; // gas saving
768 |
769 | // require caller to be authorized & order be pending
770 | require(msg.sender == ord.owner || ord.timestamp + ORDER_EXPIRY >= block.timestamp || _authorizations[msg.sender] == true, "You are not authorized to cancel this order.");
771 | require(ord.status == OrderStatus.PENDING, "Order must be a pending order");
772 |
773 | _cancelOrder(orderID);
774 | }
775 |
776 | function _cancelOrder(uint256 orderID) internal {
777 | Order memory ord = orders[orderID]; // gas saving
778 |
779 | // refund and close
780 | if(ord.swapType == OrderType.BNB_TOKEN){
781 | payable(ord.owner).transfer(ord.amountIn);
782 | }
783 | closeOrder(orderID, OrderStatus.CANCELLED);
784 |
785 | emit OrderCancelled(orderID);
786 | }
787 |
788 | function fulfilOrder(uint256 orderID) public override reentrancyGuard returns (bool filled) {
789 | Order memory ord = orders[orderID]; // saves gas
790 |
791 | require(ord.status == OrderStatus.PENDING, "Can't fulfil non-pending order");
792 |
793 | if(makeSwap(ord)){
794 | closeOrder(orderID, OrderStatus.FILLED);
795 |
796 | emit OrderFulfilled(orderID, msg.sender);
797 | return true;
798 | }else{
799 | // If order can be filled but wasn't then cancel order as there must be issue with token / slippage / etc
800 | // If unable to fulfil due to balance / allowance then also cancel
801 | if(canFulfilOrder(orderID) || unableToFulfil(orderID)){
802 | _cancelOrder(orderID);
803 | emit OrderCancelled(orderID);
804 | }
805 |
806 | return false;
807 | }
808 | }
809 |
810 | function fulfilMany(uint256[] calldata orderIDs) external override {
811 | for(uint256 i = 0; i < orderIDs.length; i++){
812 | fulfilOrder(orderIDs[i]);
813 | }
814 | }
815 |
816 | function closeOrder(uint256 orderID, OrderStatus status) internal {
817 | // Remove order from pending by swapping in last pending order then pop from array
818 | pendingOrders[orders[orderID].pendingIndex] = pendingOrders[pendingOrders.length - 1];
819 |
820 | // change pending index for moved order
821 | orders[pendingOrders[orders[orderID].pendingIndex]].pendingIndex = orders[orderID].pendingIndex;
822 |
823 | // pop duplicate pending order from end
824 | pendingOrders.pop();
825 |
826 | // close with status
827 | orders[orderID].status = status;
828 | orders[orderID].timestamp = block.timestamp; // update last action timestamp
829 | }
830 |
831 | function canFulfilOrder(uint256 orderID) public view override returns (bool) {
832 | Order memory ord = orders[orderID];
833 | return ord.status == OrderStatus.PENDING && getCurrentAmountOut(orderID) >= ord.minAmountOut;
834 | }
835 |
836 | function unableToFulfil(uint256 orderID) internal view returns (bool) {
837 | Order memory ord = orders[orderID];
838 | return IBEP20(ord.tokenIn).balanceOf(ord.owner) < ord.amountIn || IBEP20(ord.tokenIn).allowance(ord.owner, address(bogRouter)) < ord.amountIn;
839 | }
840 |
841 | function shouldFulfilOrder(uint256 orderID) public view override returns (bool) {
842 | Order memory ord = orders[orderID];
843 | return ord.status == OrderStatus.PENDING && getCurrentAmountOut(orderID) >= ord.targetAmountOut;
844 | }
845 |
846 | function getCurrentAmountOut(uint256 orderID) public view returns (uint256 amount) {
847 | Order memory ord = orders[orderID]; // save gas
848 |
849 | (uint reserveIn, uint reserveOut) = getReserves(ord.pair, ord.tokenIn, ord.tokenOut);
850 | return getAmountOut(ord.amountIn, reserveIn, reserveOut);
851 | }
852 |
853 | // returns sorted token addresses, used to handle return values from pairs sorted in this order
854 | function sortTokens(address tokenA, address tokenB) public pure returns (address token0, address token1) {
855 | (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
856 | }
857 |
858 | // fetches and sorts the reserves for a pair
859 | function getReserves(address pair, address tokenA, address tokenB) public view returns (uint reserveA, uint reserveB) {
860 | (address token0,) = sortTokens(tokenA, tokenB);
861 | (uint reserve0, uint reserve1,) = IPancakePair(pair).getReserves();
862 | (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
863 | }
864 |
865 | // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
866 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) public pure returns (uint amountOut) {
867 | uint amountInWithFee = amountIn.mul(998);
868 | uint numerator = amountInWithFee.mul(reserveOut);
869 | uint denominator = reserveIn.mul(1000).add(amountInWithFee);
870 | amountOut = numerator / denominator;
871 | }
872 |
873 | function makeSwap(Order memory ord) internal returns (bool filled) {
874 | if(ord.swapType == OrderType.BNB_TOKEN){
875 | try bogRouter.makeBNBTokenSwap{value: ord.amountIn}(ord.owner, ord.tokenIn, ord.tokenOut, ord.pair, ord.amountIn, ord.minAmountOut) { return true; } catch { return false; }
876 | }else if(ord.swapType == OrderType.TOKEN_TOKEN){
877 | try bogRouter.makeTokenTokenSwap(ord.owner, ord.tokenIn, ord.tokenOut, ord.pair, ord.amountIn, ord.minAmountOut) { return true; } catch { return false; }
878 | }else{ // OrderType.TOKEN_BNB
879 | try bogRouter.makeTokenBNBSwap(ord.owner, ord.tokenIn, ord.tokenOut, ord.pair, ord.amountIn, ord.minAmountOut) { return true; } catch { return false; }
880 | }
881 | }
882 |
883 | /**
884 | * Distribute fees to staker and owner.
885 | */
886 | function distributeFees() external {
887 | uint256 toDistribute = IBEP20(BOG).balanceOf(address(this)).mul(feeSplit).div(100);
888 | totalDistributed = totalDistributed.add(toDistribute);
889 |
890 | // Distribute to stakers & send to authorized fee taker
891 | IBog(BOG).distribute(toDistribute);
892 | IBEP20(BOG).transfer(_owner, IBEP20(BOG).balanceOf(address(this)));
893 | }
894 |
895 | function getFeeInBOG() public view returns (uint256) {
896 | uint256 bog_bnb = getTokenTokenPrice(WBNB, BOG);
897 | uint256 bnb_usd = getTokenTokenPrice(BUSD, WBNB);
898 |
899 | uint256 bnbAmt = bnb_usd.mul(fee);
900 | uint256 bogAmt = bnbAmt.mul(bog_bnb).div(10 ** PRICE_DECIMALS).mul(10 ** 18).div(10 ** PRICE_DECIMALS).div(100);
901 |
902 | return bogAmt;
903 | }
904 |
905 | function takeFee() internal returns (uint256 amount) {
906 | if(_authorizations[msg.sender]){ return 0; }
907 |
908 | if(msg.sender == tx.origin){
909 | // Take fee
910 | amount = getFeeInBOG();
911 | }else{
912 | // Take 0.25 BOG fee as fiat price could be manipulated
913 | amount = 250 * (10 ** 16);
914 | }
915 |
916 | IBEP20(BOG).transferFrom(msg.sender, address(this), amount);
917 | totalFees = totalFees.add(amount);
918 | }
919 |
920 | function getPendingOrders() external view override returns (uint256[] memory) {
921 | return pendingOrders;
922 | }
923 |
924 | function getNextReadyOrder() external view override returns (uint256 orderID) {
925 | for(uint256 i = 0; i < pendingOrders.length; i++){
926 | if(canFulfilOrder(i)){
927 | return i;
928 | }
929 | }
930 | return 0;
931 | }
932 |
933 | function getOrdersForAddress(address adr) external view override returns (uint256[] memory) {
934 | return addressOrders[adr];
935 | }
936 |
937 | function getOrdersForPair(address pair) external view override returns (uint256[] memory) {
938 | return pairOrders[pair];
939 | }
940 |
941 | function getOrdersForPair(address tokenIn, address tokenOut) external view override returns (uint256[] memory) {
942 | return pairOrders[getPair(tokenIn, tokenOut)];
943 | }
944 |
945 | function getPair(address tokenIn, address tokenOut) public view returns (address) {
946 | return IPancakeFactory(factory).getPair(tokenIn, tokenOut);
947 | }
948 |
949 | /**
950 | * Returns 10^decimals * tokenOut per tokenIn
951 | */
952 | function getTokenTokenPrice(address tokenIn, address tokenOut) public view returns (uint256) {
953 | address pair = getPair(tokenIn, tokenOut);
954 |
955 | (uint112 reserve0, uint112 reserve1,) = IPancakePair(pair).getReserves();
956 |
957 | (uint256 quoteToken, uint256 mainToken) = IPancakePair(pair).token0() == tokenOut ? (reserve0, reserve1) : (reserve1, reserve0);
958 |
959 | return calculatePriceFromReserves(quoteToken, mainToken);
960 | }
961 |
962 | function symbolFor(address token) external view returns (string memory) {
963 | return IBEP20(token).symbol();
964 | }
965 |
966 | /**
967 | * USD per BNB
968 | */
969 | function getBNBSpotPrice() external view returns (uint256) {
970 | // res0 = wbnb, res1 = busd
971 | (uint112 reserve0, uint112 reserve1,) = IPancakePair(WBNB_BUSD).getReserves();
972 |
973 | return calculatePriceFromReserves(reserve1, reserve0);
974 | }
975 |
976 | /**
977 | * Returns 10^decimals * quoteToken per baseToken
978 | */
979 | function calculatePriceFromReserves(uint256 quoteToken, uint256 baseToken) internal pure returns (uint256) {
980 | return quoteToken.mul(10 ** PRICE_DECIMALS).div(baseToken);
981 | }
982 |
983 | function setBlacklist(address token, bool state) external authorized {
984 | blacklisted[token] = state;
985 | }
986 |
987 | function setWhitelist(address token, bool state) external authorized {
988 | whitelisted[token] = state;
989 | }
990 |
991 | function setWhitelistState(bool state) external authorized {
992 | useWhitelist = state;
993 | }
994 |
995 | function changeFeeSplit(uint256 newSplit) external authorized {
996 | require(newSplit > 0 && newSplit < 100);
997 | feeSplit = newSplit;
998 | }
999 |
1000 | function changeFee(uint256 newFee) external authorized {
1001 | require(newFee > 0 && newFee < 500);
1002 | fee = newFee;
1003 | }
1004 | }
1005 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Limit-Orders-Routerv1
2 | The Bogged.Finance Limit Order Router
3 |
--------------------------------------------------------------------------------