├── .DS_Store ├── .editorconfig ├── .env.example ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .idea ├── .gitignore ├── FlashLoans.iml ├── inspectionProfiles │ └── Project_Default.xml ├── jsLibraryMappings.xml ├── modules.xml └── vcs.xml ├── .npmignore ├── .prettierignore ├── .solhint.json ├── .solhintignore ├── README.md ├── backups └── contracts │ └── ethereum │ ├── arbitrage │ ├── KyUniFlashloan.sol │ └── SushiUniFlashloan.sol │ └── interfaces │ └── 5.0 │ ├── IUniswapV2Router01.sol │ └── IUniswapV2Router02.sol ├── contracts ├── binance │ ├── arbitrage │ │ ├── ApeBakeryArbitrage.sol │ │ ├── PancakeApeArbitrage.sol │ │ └── PancakeBakeryArbitrage.sol │ └── swap │ │ ├── ApeTokenSwap.sol │ │ ├── BakeryTokenSwap.sol │ │ └── PancakeTokenSwap.sol ├── interfaces │ ├── 5.0 │ │ ├── IUniswapV2Callee.sol │ │ ├── IUniswapV2Factory.sol │ │ ├── IUniswapV2Pair.sol │ │ ├── IWeth.sol │ │ ├── UniswapV2Library.sol │ │ ├── apeswap │ │ │ └── interfaces │ │ │ │ ├── IApeCallee.sol │ │ │ │ ├── IApeFactory.sol │ │ │ │ ├── IApePair.sol │ │ │ │ ├── IApeRouter01.sol │ │ │ │ └── IApeRouter02.sol │ │ └── pancakeswap │ │ │ └── interfaces │ │ │ ├── IBEP20.sol │ │ │ ├── IERC20.sol │ │ │ ├── IPancakeCallee.sol │ │ │ ├── IPancakeERC20.sol │ │ │ ├── IPancakeFactory.sol │ │ │ ├── IPancakePair.sol │ │ │ ├── IPancakeRouter01.sol │ │ │ └── IPancakeRouter02.sol │ └── 6.0 │ │ ├── IERC20.sol │ │ ├── IUniswapV2Router01.sol │ │ └── IUniswapV2Router02.sol └── utils │ ├── 4.0 │ └── SafeMath.sol │ ├── Context.sol │ ├── Ownable.sol │ └── SafeMath.sol ├── hardhat.config.js ├── index.js ├── migrations ├── 1-deploy-contracts.js ├── hardhat │ ├── binance │ │ ├── deploy-arbitrage-contracts.js │ │ └── deploy-swap-contracts.js │ └── ethereum │ │ ├── deploy-arbitrage-contracts.js │ │ ├── kovan │ │ └── deploy-kovan-arbitrage-contracts.js │ │ └── ropsten │ │ └── deploy-ropsten-arbitrage-contracts.js └── truffle │ ├── binance │ ├── 1-deploy-binance-arbitrage-contracts.js │ └── 2-deploy-binance-swap-contracts.js │ └── ethereum │ ├── 1-deploy-ethereum-arbitrage-contracts.js │ ├── kovan │ └── 1-deploy-kovan-arbitrage-contracts.js │ └── ropsten │ └── 1-deploy-ropsten-arbitrage-contracts.js ├── package-lock.json ├── package.json ├── program ├── index.js ├── lib │ ├── index.js │ └── interactive │ │ ├── actions.js │ │ ├── binance │ │ ├── actions.js │ │ ├── index.js │ │ └── interactive │ │ │ ├── arbitrage │ │ │ ├── actions.js │ │ │ └── index.js │ │ │ ├── monitor │ │ │ ├── actions.js │ │ │ ├── index.js │ │ │ └── interactive │ │ │ │ ├── arbitrage │ │ │ │ ├── actions.js │ │ │ │ └── index.js │ │ │ │ └── price │ │ │ │ ├── actions.js │ │ │ │ └── index.js │ │ │ ├── prices │ │ │ ├── actions.js │ │ │ └── index.js │ │ │ └── swap │ │ │ ├── actions.js │ │ │ └── index.js │ │ ├── ethereum │ │ ├── actions.js │ │ ├── index.js │ │ └── interactive │ │ │ ├── arbitrage │ │ │ ├── actions.js │ │ │ └── index.js │ │ │ ├── monitor │ │ │ ├── actions.js │ │ │ ├── index.js │ │ │ └── interactive │ │ │ │ ├── arbitrage │ │ │ │ ├── actions.js │ │ │ │ └── index.js │ │ │ │ └── price │ │ │ │ ├── actions.js │ │ │ │ └── index.js │ │ │ ├── prices │ │ │ ├── actions.js │ │ │ └── index.js │ │ │ └── swap │ │ │ ├── actions.js │ │ │ └── index.js │ │ └── index.js ├── utils │ ├── addresses │ │ ├── index.js │ │ ├── kovan │ │ │ ├── dydx-kovan.json │ │ │ ├── index.js │ │ │ ├── kyber-kovan.json │ │ │ ├── suishiswap-kovan.json │ │ │ ├── token-pairs-kovan.json │ │ │ ├── tokens-kovan.json │ │ │ └── uniswap-kovan.json │ │ ├── mainnet │ │ │ ├── apeswap-mainnet.json │ │ │ ├── bakeryswap-mainnet.json │ │ │ ├── dydx-mainnet.json │ │ │ ├── index.js │ │ │ ├── kyber-mainnet.json │ │ │ ├── pancakeswap-mainnet.json │ │ │ ├── sushiswap-mainnet.json │ │ │ ├── token-pairs-mainnet.json │ │ │ ├── tokens-mainnet.json │ │ │ └── uniswap-mainnet.json │ │ └── ropsten │ │ │ ├── dydx-ropsten.json │ │ │ ├── index.js │ │ │ ├── kyber-ropsten.json │ │ │ ├── suishiswap-ropsten.json │ │ │ ├── token-pairs-ropsten.json │ │ │ ├── tokens-ropsten.json │ │ │ └── uniswap-ropsten.json │ ├── arbitrage │ │ ├── binance │ │ │ ├── ApeBakeryArbitrage.js │ │ │ ├── PancakeApeArbitrage.js │ │ │ └── PancakeBakeryArbitrage.js │ │ ├── ethereum │ │ │ ├── KySushiArbitrage.js │ │ │ ├── KyUniArbitrage.js │ │ │ ├── SushiKyArbitrage.js │ │ │ ├── SushiUniArbitrage.js │ │ │ ├── UniKyArbitrage.js │ │ │ └── UniSushiArbitrage.js │ │ └── index.js │ ├── directions │ │ ├── binance │ │ │ └── binance-directions.json │ │ ├── ethereum │ │ │ └── ethereum-directions.json │ │ └── index.js │ ├── monitor │ │ ├── binance │ │ │ ├── arbitrage │ │ │ │ ├── apeswap │ │ │ │ │ ├── ApeBakeryArbitrageMonitor.js │ │ │ │ │ ├── ApePancakeArbitrageMonitor.js │ │ │ │ │ └── index.js │ │ │ │ ├── bakeryswap │ │ │ │ │ ├── BakeryApeArbitrageMonitor.js │ │ │ │ │ ├── BakeryPancakeArbitrageMonitor.js │ │ │ │ │ └── index.js │ │ │ │ └── pancakeswap │ │ │ │ │ ├── PancakeApeArbitrageMonitor.js │ │ │ │ │ ├── PancakeBakeryArbitrageMonitor.js │ │ │ │ │ └── index.js │ │ │ ├── index.js │ │ │ └── prices │ │ │ │ ├── apeswap │ │ │ │ ├── apeswapPriceMonitor.js │ │ │ │ └── index.js │ │ │ │ ├── bakeryswap │ │ │ │ ├── bakeryswapPriceMonitor.js │ │ │ │ └── index.js │ │ │ │ └── pancakeswap │ │ │ │ ├── index.js │ │ │ │ └── pancakeswapPriceMonitor.js │ │ ├── ethereum │ │ │ ├── arbitrage │ │ │ │ ├── kyber │ │ │ │ │ ├── KySushiArbitrageMonitor.js │ │ │ │ │ ├── KyUniArbitrageMonitor.js │ │ │ │ │ └── index.js │ │ │ │ ├── sushiswap │ │ │ │ │ ├── SushiKyArbitrageMonitor.js │ │ │ │ │ ├── SushiUniArbitrageMonitor.js │ │ │ │ │ └── index.js │ │ │ │ └── uniswap │ │ │ │ │ ├── UniKyArbitrageMonitor.js │ │ │ │ │ ├── UniSushiArbitrageMonitor.js │ │ │ │ │ └── index.js │ │ │ ├── index.js │ │ │ └── prices │ │ │ │ ├── kyber │ │ │ │ ├── index.js │ │ │ │ └── kyberPriceMonitor.js │ │ │ │ ├── sushiswap │ │ │ │ ├── index.js │ │ │ │ └── sushiswapPriceMonitor.js │ │ │ │ └── uniswap │ │ │ │ ├── index.js │ │ │ │ └── uniswapPriceMonitor.js │ │ └── index.js │ ├── pricefetcher │ │ ├── binance │ │ │ ├── apeswap │ │ │ │ ├── apeswapPriceFetcher.js │ │ │ │ └── index.js │ │ │ ├── bakeryswap │ │ │ │ ├── bakeryswapPriceFetcher.js │ │ │ │ └── index.js │ │ │ └── pancakeswap │ │ │ │ ├── index.js │ │ │ │ └── pancakeswapPriceFetcher.js │ │ ├── ethereum │ │ │ ├── dydx │ │ │ │ └── index.js │ │ │ ├── kyber │ │ │ │ ├── index.js │ │ │ │ └── kyberPriceFetcher.js │ │ │ ├── sushiswap │ │ │ │ ├── index.js │ │ │ │ └── sushiswapPriceFetcher.js │ │ │ └── uniswap │ │ │ │ ├── index.js │ │ │ │ └── uniswapPriceFetcher.js │ │ ├── index.js │ │ └── vendors │ │ │ └── cmk │ │ │ └── index.js │ ├── tokens │ │ └── index.js │ └── tokenswapper │ │ ├── binance │ │ ├── apeswap │ │ │ ├── apeswapTokenSwapper.js │ │ │ └── index.js │ │ ├── bakeryswap │ │ │ ├── bakeryswapTokenSwapper.js │ │ │ └── index.js │ │ └── pancakeswap │ │ │ ├── index.js │ │ │ └── pancakeswapTokenSwapper.js │ │ ├── ethereum │ │ ├── kyber │ │ │ ├── index.js │ │ │ └── kyberTokenSwapper.js │ │ ├── sushiswap │ │ │ ├── index.js │ │ │ └── sushiswapTokenSwapper.js │ │ └── uniswap │ │ │ ├── index.js │ │ │ └── uniswapTokenSwapper.js │ │ └── index.js └── views │ └── banner │ └── index.js ├── test └── sample-test.js └── truffle-config.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrMaxis/DefiTerminal/2b6559d2464545488480229ac08855168b6195b0/.DS_Store -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = false 9 | max_line_length = 120 10 | tab_width = 4 11 | 12 | [{*.js, *.json}] 13 | indent_size = 2 14 | tab_width = 2 15 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | MAINNET_INFURA_URL="" 2 | MAINNET_INFURA_WSS_URL="" 3 | 4 | 5 | BSC_MAINNET_WSS_URL="" 6 | 7 | BSC_MAINNET_HTTPS="https://bsc-dataseed.binance.org/" 8 | 9 | MORALIAS_BSC_MAINNET_WSS_URL="" 10 | 11 | 12 | ROPSTEN_INFURA_URL="" 13 | ROPSTEN_INFURA_WSS_URL="" 14 | 15 | KOVAN_INFURA_URL="" 16 | KOVAN_INFURA_WSS_URL="" 17 | 18 | PRIVATE_KEY="" 19 | ACCOUNT="" 20 | 21 | CMK_QUOTE_API_URL="https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest" 22 | CMK_API_KEY="" 23 | 24 | DYDX_V3_MARKETS_API_URL="https://api.dydx.exchange/v3/markets" 25 | DYDX_V1_INDEX_PRICE_URL="https://api.dydx.exchange/v1/index-price" 26 | DYDX_V2_MARKETS_API_URL="https://api.dydx.exchange/v2/markets" 27 | 28 | ETHERSCAN_API_KEY="" 29 | 30 | REPORT_GAS="" -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | artifacts 3 | cache 4 | coverage 5 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: false, 4 | es2021: true, 5 | mocha: true, 6 | node: true, 7 | }, 8 | extends: [ 9 | "standard", 10 | "plugin:prettier/recommended", 11 | "plugin:node/recommended", 12 | ], 13 | parserOptions: { 14 | ecmaVersion: 12, 15 | }, 16 | overrides: [ 17 | { 18 | files: ["hardhat.config.js"], 19 | globals: { task: true }, 20 | }, 21 | ], 22 | }; 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | artifacts 4 | cache 5 | build -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/FlashLoans.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /.idea/jsLibraryMappings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | hardhat.config.js 2 | scripts 3 | test 4 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | artifacts 3 | cache 4 | coverage* 5 | gasReporterOutput.json 6 | -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:recommended", 3 | "rules": { 4 | "compiler-version": ["error", "^0.8.0"], 5 | "func-visibility": ["warn", { "ignoreConstructors": true }] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.solhintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Setup 3 | 4 | - Install and make sure you are running Node JS 12 5 | - Clone the Repo 6 | - Open a Node terminal & change directory to the project root 7 | - Run `npm install` 8 | - Run `truffle compile` 9 | - Copy `.env.example` to a new `.env` file and insert your secrets 10 | - To start the program run `node ./` 11 | 12 | 13 | # Deployments 14 | The migrations' folder holds the scripts for deploying the contracts categorized by type and chain. 15 | 16 | You can use either Hardhat or Truffle to compile and deploy the contracts. 17 | 18 | #### Hardhat 19 | 20 | - Run `npx hardhat run --network /<.js file>` 21 | 22 | #### Truffle 23 | 24 | - Modify the script prefixed with `1-` to specify which contract you would like to deploy. 25 | - Run the migration with `truffle migrate --network --reset` 26 | 27 | # Testing 28 | 29 | - Run `npx hardhat node --fork YOUR_HTTPS_PROVIDER` 30 | - Open a new terminal and set the WebSocketProvider to consume `http://127.0.0.1/8545` 31 | - Run `npx hardhat run --network localhost /<.js file>` 32 | - Start the program with `node ./` 33 | - Run the scripts provided by selected `Local` in the prompt. 34 | 35 | *Note* Make sure the services provided are using the `http://127.0.0.1/8545` websocket url. 36 | [Example](https://github.com/AfriaDev/DefiTerminal/blob/master/program/utils/monitor/ethereum/prices/kyber/kyberPriceMonitor.js#L43) 37 | 38 | 39 | - Pending Hardhat test scripts 40 | 41 | 42 | -------------------------------------------------------------------------------- /backups/contracts/ethereum/interfaces/5.0/IUniswapV2Router01.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IUniswapV2Router01 { 4 | function factory() external pure returns (address); 5 | function WETH() external pure returns (address); 6 | 7 | function addLiquidity( 8 | address tokenA, 9 | address tokenB, 10 | uint amountADesired, 11 | uint amountBDesired, 12 | uint amountAMin, 13 | uint amountBMin, 14 | address to, 15 | uint deadline 16 | ) external returns (uint amountA, uint amountB, uint liquidity); 17 | function addLiquidityETH( 18 | address token, 19 | uint amountTokenDesired, 20 | uint amountTokenMin, 21 | uint amountETHMin, 22 | address to, 23 | uint deadline 24 | ) external payable returns (uint amountToken, uint amountETH, uint liquidity); 25 | function removeLiquidity( 26 | address tokenA, 27 | address tokenB, 28 | uint liquidity, 29 | uint amountAMin, 30 | uint amountBMin, 31 | address to, 32 | uint deadline 33 | ) external returns (uint amountA, uint amountB); 34 | function removeLiquidityETH( 35 | address token, 36 | uint liquidity, 37 | uint amountTokenMin, 38 | uint amountETHMin, 39 | address to, 40 | uint deadline 41 | ) external returns (uint amountToken, uint amountETH); 42 | function removeLiquidityWithPermit( 43 | address tokenA, 44 | address tokenB, 45 | uint liquidity, 46 | uint amountAMin, 47 | uint amountBMin, 48 | address to, 49 | uint deadline, 50 | bool approveMax, uint8 v, bytes32 r, bytes32 s 51 | ) external returns (uint amountA, uint amountB); 52 | function removeLiquidityETHWithPermit( 53 | address token, 54 | uint liquidity, 55 | uint amountTokenMin, 56 | uint amountETHMin, 57 | address to, 58 | uint deadline, 59 | bool approveMax, uint8 v, bytes32 r, bytes32 s 60 | ) external returns (uint amountToken, uint amountETH); 61 | function swapExactTokensForTokens( 62 | uint amountIn, 63 | uint amountOutMin, 64 | address[] calldata path, 65 | address to, 66 | uint deadline 67 | ) external returns (uint[] memory amounts); 68 | function swapTokensForExactTokens( 69 | uint amountOut, 70 | uint amountInMax, 71 | address[] calldata path, 72 | address to, 73 | uint deadline 74 | ) external returns (uint[] memory amounts); 75 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) 76 | external 77 | payable 78 | returns (uint[] memory amounts); 79 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) 80 | external 81 | returns (uint[] memory amounts); 82 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) 83 | external 84 | returns (uint[] memory amounts); 85 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) 86 | external 87 | payable 88 | returns (uint[] memory amounts); 89 | 90 | function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); 91 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); 92 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); 93 | function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); 94 | function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); 95 | } 96 | -------------------------------------------------------------------------------- /backups/contracts/ethereum/interfaces/5.0/IUniswapV2Router02.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | import './IUniswapV2Router01.sol'; 4 | 5 | contract IUniswapV2Router02 is IUniswapV2Router01 { 6 | function removeLiquidityETHSupportingFeeOnTransferTokens( 7 | address token, 8 | uint liquidity, 9 | uint amountTokenMin, 10 | uint amountETHMin, 11 | address to, 12 | uint deadline 13 | ) external returns (uint amountETH); 14 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 15 | address token, 16 | uint liquidity, 17 | uint amountTokenMin, 18 | uint amountETHMin, 19 | address to, 20 | uint deadline, 21 | bool approveMax, uint8 v, bytes32 r, bytes32 s 22 | ) external returns (uint amountETH); 23 | 24 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 25 | uint amountIn, 26 | uint amountOutMin, 27 | address[] calldata path, 28 | address to, 29 | uint deadline 30 | ) external; 31 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 32 | uint amountOutMin, 33 | address[] calldata path, 34 | address to, 35 | uint deadline 36 | ) external payable; 37 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 38 | uint amountIn, 39 | uint amountOutMin, 40 | address[] calldata path, 41 | address to, 42 | uint deadline 43 | ) external; 44 | } 45 | -------------------------------------------------------------------------------- /contracts/binance/arbitrage/ApeBakeryArbitrage.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.6; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import '../../utils/SafeMath.sol'; 5 | import '../../interfaces/5.0/UniswapV2Library.sol'; 6 | import '../../interfaces/6.0/IERC20.sol'; 7 | import '../../interfaces/5.0/IUniswapV2Pair.sol'; 8 | import '../../interfaces/5.0/IUniswapV2Factory.sol'; 9 | import '../../interfaces/6.0/IUniswapV2Router01.sol'; 10 | import '../../interfaces/6.0/IUniswapV2Router02.sol'; 11 | import "../../interfaces/5.0/IWeth.sol"; 12 | 13 | 14 | contract ApeBakeryArbitrage { 15 | IWeth immutable WETH; 16 | address Beneficiary; 17 | address ApeSwapFactory; 18 | address BakeryFactory; 19 | address BakeryRouter; 20 | address ApeRouter; 21 | constructor(address apeFactory, address bakeryFactory, address wethAddress , address bakeryRouter, address apeRouter, address beneficiaryAddress) public { 22 | ApeSwapFactory = apeFactory; 23 | BakeryFactory = bakeryFactory; 24 | WETH = IWeth(wethAddress); 25 | Beneficiary = beneficiaryAddress; 26 | BakeryRouter = bakeryRouter; 27 | ApeRouter = apeRouter; 28 | } 29 | 30 | 31 | function startArbitrage( 32 | address token0, 33 | address token1, 34 | uint amount0, 35 | uint amount1, 36 | address startFactory, 37 | address endRouterAddress, 38 | uint repay 39 | ) external { 40 | 41 | address pairAddress = IUniswapV2Factory(startFactory).getPair(token0, token1); 42 | require(pairAddress != address(0), 'This pool does not exist'); 43 | IUniswapV2Pair(pairAddress).swap( 44 | amount0, 45 | amount1, 46 | address(this), 47 | abi.encode(endRouterAddress, repay) //not empty bytes param will trigger flashloan 48 | ); 49 | } 50 | 51 | receive() external payable {} 52 | 53 | function pancakeCall(address sender, uint amount0, uint amount1, bytes calldata data) external { 54 | address[] memory path = new address[](2); 55 | ( address endRouter, uint repay) = abi.decode(data, (address, uint)); 56 | uint amountToken; 57 | uint amountEth; 58 | 59 | 60 | // scope for token{0,1}, avoids stack too deep errors 61 | { 62 | address token0 = IUniswapV2Pair(msg.sender).token0(); 63 | address token1 = IUniswapV2Pair(msg.sender).token1(); 64 | path[0] = amount0 == 0 ? token1 : token0; 65 | path[1] = amount0 == 0 ? token0 : token1; 66 | 67 | amountToken = token0 == address(WETH) ? amount1 : amount0; 68 | amountEth = token0 == address(WETH) ? amount0 : amount1; 69 | 70 | } 71 | IERC20 token = IERC20(path[0] == address(WETH) ? path[1] : path[0]); 72 | 73 | if (amountToken > 0) { 74 | token.approve(endRouter, amountToken); 75 | uint[] memory amountReceived = IUniswapV2Router02(endRouter).swapExactTokensForETH(amountToken, 0, path,address(this),block.timestamp); 76 | WETH.deposit{value: amountReceived[1]}(); 77 | require(WETH.transfer(msg.sender, repay), "Could Not Repay loan amount!"); // return WETH to V2 pair 78 | if(amountReceived[1] - repay > 0) { 79 | WETH.transfer(Beneficiary, (amountReceived[1] - repay)); 80 | } 81 | } else { 82 | WETH.withdraw(amountEth); 83 | uint [] memory amountReceived = IUniswapV2Router02(endRouter).swapExactETHForTokens{value: address(this).balance}(0, path, address(this), block.timestamp); 84 | require(amountReceived[1] > repay, "Failed to get enough from swap to repay"); // fail if we didn't get enough tokens back to repay our flash loan 85 | token.transfer(msg.sender, repay); // return tokens to V2 pair 86 | if(amountReceived[1] - repay > 0) { 87 | token.transfer(Beneficiary, token.balanceOf(address(this))); 88 | } 89 | 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /contracts/binance/arbitrage/PancakeApeArbitrage.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.6; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import '../../utils/SafeMath.sol'; 5 | import '../../interfaces/5.0/UniswapV2Library.sol'; 6 | import '../../interfaces/6.0/IERC20.sol'; 7 | import '../../interfaces/5.0/IUniswapV2Pair.sol'; 8 | import '../../interfaces/5.0/IUniswapV2Factory.sol'; 9 | import '../../interfaces/6.0/IUniswapV2Router01.sol'; 10 | import '../../interfaces/6.0/IUniswapV2Router02.sol'; 11 | import "../../interfaces/5.0/IWeth.sol"; 12 | 13 | 14 | 15 | contract PancakeApeArbitrage { 16 | IWeth immutable WETH; 17 | address Beneficiary; 18 | address ApeSwapFactory; 19 | address PancakeFactory; 20 | address PancakeRouter; 21 | address ApeRouter; 22 | constructor(address pancakeFactory, address apeFactory, address wethAddress , address apeRouter, address pancakeRouter, address beneficiaryAddress) public { 23 | ApeSwapFactory = apeFactory; 24 | PancakeFactory = pancakeFactory; 25 | WETH = IWeth(wethAddress); 26 | Beneficiary = beneficiaryAddress; 27 | PancakeRouter = pancakeRouter; 28 | ApeRouter = apeRouter; 29 | } 30 | 31 | 32 | function startArbitrage( 33 | address token0, 34 | address token1, 35 | uint amount0, 36 | uint amount1, 37 | address startFactory, 38 | address endRouterAddress, 39 | uint repay 40 | ) external { 41 | 42 | address pairAddress = IUniswapV2Factory(startFactory).getPair(token0, token1); 43 | require(pairAddress != address(0), 'This pool does not exist'); 44 | IUniswapV2Pair(pairAddress).swap( 45 | amount0, 46 | amount1, 47 | address(this), 48 | abi.encode(endRouterAddress, repay) //not empty bytes param will trigger flashloan 49 | ); 50 | } 51 | 52 | receive() external payable {} 53 | 54 | function pancakeCall(address sender, uint amount0, uint amount1, bytes calldata data) external { 55 | address[] memory path = new address[](2); 56 | ( address endRouter, uint repay) = abi.decode(data, (address, uint)); 57 | uint amountToken; 58 | uint amountEth; 59 | 60 | 61 | // scope for token{0,1}, avoids stack too deep errors 62 | { 63 | address token0 = IUniswapV2Pair(msg.sender).token0(); 64 | address token1 = IUniswapV2Pair(msg.sender).token1(); 65 | path[0] = amount0 == 0 ? token1 : token0; 66 | path[1] = amount0 == 0 ? token0 : token1; 67 | 68 | amountToken = token0 == address(WETH) ? amount1 : amount0; 69 | amountEth = token0 == address(WETH) ? amount0 : amount1; 70 | 71 | } 72 | IERC20 token = IERC20(path[0] == address(WETH) ? path[1] : path[0]); 73 | 74 | if (amountToken > 0) { 75 | token.approve(endRouter, amountToken); 76 | uint[] memory amountReceived = IUniswapV2Router02(endRouter).swapExactTokensForETH(amountToken, 0, path,address(this),block.timestamp); 77 | WETH.deposit{value: amountReceived[1]}(); 78 | require(WETH.transfer(msg.sender, repay), "Could Not Repay loan amount!"); // return WETH to V2 pair 79 | if(amountReceived[1] - repay > 0) { 80 | WETH.transfer(Beneficiary, (amountReceived[1] - repay)); 81 | } 82 | } else { 83 | WETH.withdraw(amountEth); 84 | uint [] memory amountReceived = IUniswapV2Router02(endRouter).swapExactETHForTokens{value: address(this).balance}(0, path, address(this), block.timestamp); 85 | require(amountReceived[1] > repay, "Failed to get enough from swap to repay"); // fail if we didn't get enough tokens back to repay our flash loan 86 | token.transfer(msg.sender, repay); // return tokens to V2 pair 87 | if(amountReceived[1] - repay > 0) { 88 | token.transfer(Beneficiary, token.balanceOf(address(this))); 89 | } 90 | 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /contracts/binance/swap/ApeTokenSwap.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | 3 | pragma solidity >=0.6.6 <0.8.0; 4 | 5 | import '../../utils/Ownable.sol'; 6 | import '../../utils/SafeMath.sol'; 7 | import '../../interfaces/5.0/UniswapV2Library.sol'; 8 | import '../../interfaces/6.0/IERC20.sol'; 9 | import '../../interfaces/5.0/IUniswapV2Pair.sol'; 10 | import '../../interfaces/5.0/IUniswapV2Factory.sol'; 11 | import '../../interfaces/6.0/IUniswapV2Router02.sol'; 12 | 13 | contract ApeTokenSwap is Ownable { 14 | using SafeMath for uint; 15 | address private constant apeRouter = 0xcF0feBd3f17CEf5b47b0cD257aCf6025c5BFf3b7; 16 | 17 | constructor() {} 18 | 19 | function startSwap( 20 | address token0, 21 | address token1, 22 | uint amount0, 23 | uint amount1 24 | ) external { 25 | // transfer input tokens to this contract address 26 | IERC20(token0).transferFrom(msg.sender, address(this), amount0); 27 | // approve apeRouter to transfer tokens from this contract 28 | IERC20(token0).approve(apeRouter, amount0); 29 | 30 | address[] memory path; 31 | 32 | require(address(token1) != address(token0), "You cannot swap between the same tokens"); 33 | 34 | path = new address[](2); 35 | path[0] = token0; 36 | path[1] = token1; 37 | 38 | IUniswapV2Router02(apeRouter).swapExactTokensForTokens( 39 | amount0, 40 | amount1, 41 | path, 42 | msg.sender, 43 | block.timestamp 44 | ); 45 | } 46 | 47 | function destruct() public onlyOwner { 48 | address payable owner = payable(owner()); 49 | selfdestruct(owner); 50 | } 51 | 52 | receive() external payable {} 53 | } 54 | -------------------------------------------------------------------------------- /contracts/binance/swap/BakeryTokenSwap.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | 3 | pragma solidity >=0.6.6 <0.8.0; 4 | 5 | import '../../utils/Ownable.sol'; 6 | import '../../utils/SafeMath.sol'; 7 | import '../../interfaces/5.0/UniswapV2Library.sol'; 8 | import '../../interfaces/6.0/IERC20.sol'; 9 | import '../../interfaces/5.0/IUniswapV2Pair.sol'; 10 | import '../../interfaces/5.0/IUniswapV2Factory.sol'; 11 | import '../../interfaces/6.0/IUniswapV2Router02.sol'; 12 | 13 | contract BakeryTokenSwap is Ownable { 14 | using SafeMath for uint; 15 | address private constant bakeryRouter = 0xCDe540d7eAFE93aC5fE6233Bee57E1270D3E330F; 16 | 17 | constructor() {} 18 | 19 | function startSwap( 20 | address token0, 21 | address token1, 22 | uint amount0, 23 | uint amount1 24 | ) external { 25 | // transfer input tokens to this contract address 26 | IERC20(token0).transferFrom(msg.sender, address(this), amount0); 27 | // approve bakeryRouter to transfer tokens from this contract 28 | IERC20(token0).approve(bakeryRouter, amount0); 29 | 30 | address[] memory path; 31 | 32 | require(address(token1) != address(token0), "You cannot swap between the same tokens"); 33 | 34 | path = new address[](2); 35 | path[0] = token0; 36 | path[1] = token1; 37 | 38 | IUniswapV2Router02(bakeryRouter).swapExactTokensForTokens( 39 | amount0, 40 | amount1, 41 | path, 42 | msg.sender, 43 | block.timestamp 44 | ); 45 | } 46 | 47 | function destruct() public onlyOwner { 48 | address payable owner = payable(owner()); 49 | selfdestruct(owner); 50 | } 51 | 52 | receive() external payable {} 53 | } 54 | -------------------------------------------------------------------------------- /contracts/binance/swap/PancakeTokenSwap.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | 3 | pragma solidity >=0.6.6 <0.8.0; 4 | 5 | import '../../utils/Ownable.sol'; 6 | import '../../utils/SafeMath.sol'; 7 | import '../../interfaces/5.0/UniswapV2Library.sol'; 8 | import '../../interfaces/6.0/IERC20.sol'; 9 | import '../../interfaces/5.0/IUniswapV2Pair.sol'; 10 | import '../../interfaces/5.0/IUniswapV2Factory.sol'; 11 | import '../../interfaces/6.0/IUniswapV2Router02.sol'; 12 | 13 | contract PancakeTokenSwap is Ownable { 14 | using SafeMath for uint; 15 | address private constant pancakeRouter = 0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F; 16 | 17 | constructor() {} 18 | 19 | function startSwap( 20 | address token0, 21 | address token1, 22 | uint amount0, 23 | uint amount1 24 | ) external { 25 | // transfer input tokens to this contract address 26 | IERC20(token0).transferFrom(msg.sender, address(this), amount0); 27 | // approve pancakeRouter to transfer tokens from this contract 28 | IERC20(token0).approve(pancakeRouter, amount0); 29 | 30 | address[] memory path; 31 | 32 | require(address(token1) != address(token0), "You cannot swap between the same tokens"); 33 | 34 | path = new address[](2); 35 | path[0] = token0; 36 | path[1] = token1; 37 | 38 | IUniswapV2Router02(pancakeRouter).swapExactTokensForTokens( 39 | amount0, 40 | amount1, 41 | path, 42 | msg.sender, 43 | block.timestamp 44 | ); 45 | } 46 | 47 | function destruct() public onlyOwner { 48 | address payable owner = payable(owner()); 49 | selfdestruct(owner); 50 | } 51 | 52 | receive() external payable {} 53 | } 54 | -------------------------------------------------------------------------------- /contracts/interfaces/5.0/IUniswapV2Callee.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.5.0; 4 | 5 | interface IUniswapV2Callee { 6 | function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external; 7 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/IUniswapV2Factory.sol: -------------------------------------------------------------------------------- 1 | 2 | 3 | // SPDX-License-Identifier: MIT 4 | 5 | pragma solidity >=0.5.0; 6 | 7 | interface IUniswapV2Factory { 8 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 9 | function getPair(address tokenA, address tokenB) external view returns (address pair); 10 | function allPairs(uint) external view returns (address pair); 11 | function allPairsLength() external view returns (uint); 12 | function feeTo() external view returns (address); 13 | function feeToSetter() external view returns (address); 14 | function createPair(address tokenA, address tokenB) external returns (address pair); 15 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/IUniswapV2Pair.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.5.0; 4 | 5 | interface IUniswapV2Pair { 6 | event Approval(address indexed owner, address indexed spender, uint value); 7 | event Transfer(address indexed from, address indexed to, uint value); 8 | 9 | function name() external pure returns (string memory); 10 | function symbol() external pure returns (string memory); 11 | function decimals() external pure returns (uint8); 12 | function totalSupply() external view returns (uint); 13 | function balanceOf(address owner) external view returns (uint); 14 | function allowance(address owner, address spender) external view returns (uint); 15 | 16 | function approve(address spender, uint value) external returns (bool); 17 | function transfer(address to, uint value) external returns (bool); 18 | function transferFrom(address from, address to, uint value) external returns (bool); 19 | 20 | function DOMAIN_SEPARATOR() external view returns (bytes32); 21 | function PERMIT_TYPEHASH() external pure returns (bytes32); 22 | function nonces(address owner) external view returns (uint); 23 | 24 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 25 | 26 | event Mint(address indexed sender, uint amount0, uint amount1); 27 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); 28 | event Swap( 29 | address indexed sender, 30 | uint amount0In, 31 | uint amount1In, 32 | uint amount0Out, 33 | uint amount1Out, 34 | address indexed to 35 | ); 36 | event Sync(uint112 reserve0, uint112 reserve1); 37 | 38 | function MINIMUM_LIQUIDITY() external pure returns (uint); 39 | function factory() external view returns (address); 40 | function token0() external view returns (address); 41 | function token1() external view returns (address); 42 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 43 | function price0CumulativeLast() external view returns (uint); 44 | function price1CumulativeLast() external view returns (uint); 45 | function kLast() external view returns (uint); 46 | 47 | function mint(address to) external returns (uint liquidity); 48 | function burn(address to) external returns (uint amount0, uint amount1); 49 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; 50 | function skim(address to) external; 51 | function sync() external; 52 | 53 | function initialize(address, address) external; 54 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/IWeth.sol: -------------------------------------------------------------------------------- 1 | 2 | // Copyright (C) 2015, 2016, 2017, 2019 Dapphub 3 | 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | pragma solidity >=0.5.0; 18 | 19 | interface IWeth { 20 | function deposit() external payable; 21 | function withdraw(uint wad) external; 22 | function transfer(address to, uint value) external returns (bool); 23 | function balanceOf(address owner) external view returns(uint); 24 | } 25 | -------------------------------------------------------------------------------- /contracts/interfaces/5.0/apeswap/interfaces/IApeCallee.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | /* 4 | * ApeSwapFinance 5 | * App: https://apeswap.finance 6 | * Medium: https://ape-swap.medium.com 7 | * Twitter: https://twitter.com/ape_swap 8 | * Telegram: https://t.me/ape_swap 9 | * Announcements: https://t.me/ape_swap_news 10 | * GitHub: https://github.com/ApeSwapFinance 11 | */ 12 | 13 | interface IApeCallee { 14 | function apeCall(address sender, uint amount0, uint amount1, bytes calldata data) external; 15 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/apeswap/interfaces/IApeFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | /* 4 | * ApeSwapFinance 5 | * App: https://apeswap.finance 6 | * Medium: https://ape-swap.medium.com 7 | * Twitter: https://twitter.com/ape_swap 8 | * Telegram: https://t.me/ape_swap 9 | * Announcements: https://t.me/ape_swap_news 10 | * GitHub: https://github.com/ApeSwapFinance 11 | */ 12 | 13 | interface IApeFactory { 14 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 15 | 16 | function feeTo() external view returns (address); 17 | function feeToSetter() external view returns (address); 18 | 19 | function getPair(address tokenA, address tokenB) external view returns (address pair); 20 | function allPairs(uint) external view returns (address pair); 21 | function allPairsLength() external view returns (uint); 22 | 23 | function createPair(address tokenA, address tokenB) external returns (address pair); 24 | 25 | function setFeeTo(address) external; 26 | function setFeeToSetter(address) external; 27 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/apeswap/interfaces/IApePair.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | /* 4 | * ApeSwapFinance 5 | * App: https://apeswap.finance 6 | * Medium: https://ape-swap.medium.com 7 | * Twitter: https://twitter.com/ape_swap 8 | * Telegram: https://t.me/ape_swap 9 | * Announcements: https://t.me/ape_swap_news 10 | * GitHub: https://github.com/ApeSwapFinance 11 | */ 12 | 13 | interface IApePair { 14 | event Approval(address indexed owner, address indexed spender, uint value); 15 | event Transfer(address indexed from, address indexed to, uint value); 16 | 17 | function name() external pure returns (string memory); 18 | function symbol() external pure returns (string memory); 19 | function decimals() external pure returns (uint8); 20 | function totalSupply() external view returns (uint); 21 | function balanceOf(address owner) external view returns (uint); 22 | function allowance(address owner, address spender) external view returns (uint); 23 | 24 | function approve(address spender, uint value) external returns (bool); 25 | function transfer(address to, uint value) external returns (bool); 26 | function transferFrom(address from, address to, uint value) external returns (bool); 27 | 28 | function DOMAIN_SEPARATOR() external view returns (bytes32); 29 | function PERMIT_TYPEHASH() external pure returns (bytes32); 30 | function nonces(address owner) external view returns (uint); 31 | 32 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 33 | 34 | event Mint(address indexed sender, uint amount0, uint amount1); 35 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); 36 | event Swap( 37 | address indexed sender, 38 | uint amount0In, 39 | uint amount1In, 40 | uint amount0Out, 41 | uint amount1Out, 42 | address indexed to 43 | ); 44 | event Sync(uint112 reserve0, uint112 reserve1); 45 | 46 | function MINIMUM_LIQUIDITY() external pure returns (uint); 47 | function factory() external view returns (address); 48 | function token0() external view returns (address); 49 | function token1() external view returns (address); 50 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 51 | function price0CumulativeLast() external view returns (uint); 52 | function price1CumulativeLast() external view returns (uint); 53 | function kLast() external view returns (uint); 54 | 55 | function mint(address to) external returns (uint liquidity); 56 | function burn(address to) external returns (uint amount0, uint amount1); 57 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; 58 | function skim(address to) external; 59 | function sync() external; 60 | 61 | function initialize(address, address) external; 62 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/apeswap/interfaces/IApeRouter01.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.2; 2 | 3 | interface IApeRouter01 { 4 | function factory() external pure returns (address); 5 | function WETH() external pure returns (address); 6 | 7 | function addLiquidity( 8 | address tokenA, 9 | address tokenB, 10 | uint amountADesired, 11 | uint amountBDesired, 12 | uint amountAMin, 13 | uint amountBMin, 14 | address to, 15 | uint deadline 16 | ) external returns (uint amountA, uint amountB, uint liquidity); 17 | function addLiquidityETH( 18 | address token, 19 | uint amountTokenDesired, 20 | uint amountTokenMin, 21 | uint amountETHMin, 22 | address to, 23 | uint deadline 24 | ) external payable returns (uint amountToken, uint amountETH, uint liquidity); 25 | function removeLiquidity( 26 | address tokenA, 27 | address tokenB, 28 | uint liquidity, 29 | uint amountAMin, 30 | uint amountBMin, 31 | address to, 32 | uint deadline 33 | ) external returns (uint amountA, uint amountB); 34 | function removeLiquidityETH( 35 | address token, 36 | uint liquidity, 37 | uint amountTokenMin, 38 | uint amountETHMin, 39 | address to, 40 | uint deadline 41 | ) external returns (uint amountToken, uint amountETH); 42 | function removeLiquidityWithPermit( 43 | address tokenA, 44 | address tokenB, 45 | uint liquidity, 46 | uint amountAMin, 47 | uint amountBMin, 48 | address to, 49 | uint deadline, 50 | bool approveMax, uint8 v, bytes32 r, bytes32 s 51 | ) external returns (uint amountA, uint amountB); 52 | function removeLiquidityETHWithPermit( 53 | address token, 54 | uint liquidity, 55 | uint amountTokenMin, 56 | uint amountETHMin, 57 | address to, 58 | uint deadline, 59 | bool approveMax, uint8 v, bytes32 r, bytes32 s 60 | ) external returns (uint amountToken, uint amountETH); 61 | function swapExactTokensForTokens( 62 | uint amountIn, 63 | uint amountOutMin, 64 | address[] calldata path, 65 | address to, 66 | uint deadline 67 | ) external returns (uint[] memory amounts); 68 | function swapTokensForExactTokens( 69 | uint amountOut, 70 | uint amountInMax, 71 | address[] calldata path, 72 | address to, 73 | uint deadline 74 | ) external returns (uint[] memory amounts); 75 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) 76 | external 77 | payable 78 | returns (uint[] memory amounts); 79 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) 80 | external 81 | returns (uint[] memory amounts); 82 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) 83 | external 84 | returns (uint[] memory amounts); 85 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) 86 | external 87 | payable 88 | returns (uint[] memory amounts); 89 | 90 | function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); 91 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); 92 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); 93 | function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); 94 | function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); 95 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/apeswap/interfaces/IApeRouter02.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.2; 2 | 3 | import './IApeRouter01.sol'; 4 | 5 | interface IApeRouter02 is IApeRouter01 { 6 | function removeLiquidityETHSupportingFeeOnTransferTokens( 7 | address token, 8 | uint liquidity, 9 | uint amountTokenMin, 10 | uint amountETHMin, 11 | address to, 12 | uint deadline 13 | ) external returns (uint amountETH); 14 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 15 | address token, 16 | uint liquidity, 17 | uint amountTokenMin, 18 | uint amountETHMin, 19 | address to, 20 | uint deadline, 21 | bool approveMax, uint8 v, bytes32 r, bytes32 s 22 | ) external returns (uint amountETH); 23 | 24 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 25 | uint amountIn, 26 | uint amountOutMin, 27 | address[] calldata path, 28 | address to, 29 | uint deadline 30 | ) external; 31 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 32 | uint amountOutMin, 33 | address[] calldata path, 34 | address to, 35 | uint deadline 36 | ) external payable; 37 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 38 | uint amountIn, 39 | uint amountOutMin, 40 | address[] calldata path, 41 | address to, 42 | uint deadline 43 | ) external; 44 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/pancakeswap/interfaces/IBEP20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | pragma solidity >=0.4.0; 4 | 5 | interface IBEP20 { 6 | /** 7 | * @dev Returns the amount of tokens in existence. 8 | */ 9 | function totalSupply() external view returns (uint256); 10 | 11 | /** 12 | * @dev Returns the token decimals. 13 | */ 14 | function decimals() external view returns (uint8); 15 | 16 | /** 17 | * @dev Returns the token symbol. 18 | */ 19 | function symbol() external view returns (string memory); 20 | 21 | /** 22 | * @dev Returns the token name. 23 | */ 24 | function name() external view returns (string memory); 25 | 26 | /** 27 | * @dev Returns the bep token owner. 28 | */ 29 | function getOwner() external view returns (address); 30 | 31 | /** 32 | * @dev Returns the amount of tokens owned by `account`. 33 | */ 34 | function balanceOf(address account) external view returns (uint256); 35 | 36 | /** 37 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 38 | * 39 | * Returns a boolean value indicating whether the operation succeeded. 40 | * 41 | * Emits a {Transfer} event. 42 | */ 43 | function transfer(address recipient, uint256 amount) external returns (bool); 44 | 45 | /** 46 | * @dev Returns the remaining number of tokens that `spender` will be 47 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 48 | * zero by default. 49 | * 50 | * This value changes when {approve} or {transferFrom} are called. 51 | */ 52 | function allowance(address _owner, address spender) external view returns (uint256); 53 | 54 | /** 55 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 56 | * 57 | * Returns a boolean value indicating whether the operation succeeded. 58 | * 59 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 60 | * that someone may use both the old and the new allowance by unfortunate 61 | * transaction ordering. One possible solution to mitigate this race 62 | * condition is to first reduce the spender's allowance to 0 and set the 63 | * desired value afterwards: 64 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 65 | * 66 | * Emits an {Approval} event. 67 | */ 68 | function approve(address spender, uint256 amount) external returns (bool); 69 | 70 | /** 71 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 72 | * allowance mechanism. `amount` is then deducted from the caller's 73 | * allowance. 74 | * 75 | * Returns a boolean value indicating whether the operation succeeded. 76 | * 77 | * Emits a {Transfer} event. 78 | */ 79 | function transferFrom( 80 | address sender, 81 | address recipient, 82 | uint256 amount 83 | ) external returns (bool); 84 | 85 | /** 86 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 87 | * another (`to`). 88 | * 89 | * Note that `value` may be zero. 90 | */ 91 | event Transfer(address indexed from, address indexed to, uint256 value); 92 | 93 | /** 94 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 95 | * a call to {approve}. `value` is the new allowance. 96 | */ 97 | event Approval(address indexed owner, address indexed spender, uint256 value); 98 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/pancakeswap/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IERC20 { 4 | event Approval(address indexed owner, address indexed spender, uint value); 5 | event Transfer(address indexed from, address indexed to, uint value); 6 | 7 | function name() external view returns (string memory); 8 | function symbol() external view returns (string memory); 9 | function decimals() external view returns (uint8); 10 | function totalSupply() external view returns (uint); 11 | function balanceOf(address owner) external view returns (uint); 12 | function allowance(address owner, address spender) external view returns (uint); 13 | 14 | function approve(address spender, uint value) external returns (bool); 15 | function transfer(address to, uint value) external returns (bool); 16 | function transferFrom(address from, address to, uint value) external returns (bool); 17 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/pancakeswap/interfaces/IPancakeCallee.sol: -------------------------------------------------------------------------------- 1 | 2 | 3 | pragma solidity >=0.5.0; 4 | 5 | interface IPancakeCallee { 6 | function pancakeCall(address sender, uint amount0, uint amount1, bytes calldata data) external; 7 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/pancakeswap/interfaces/IPancakeERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IPancakeERC20 { 4 | event Approval(address indexed owner, address indexed spender, uint value); 5 | event Transfer(address indexed from, address indexed to, uint value); 6 | 7 | function name() external pure returns (string memory); 8 | function symbol() external pure returns (string memory); 9 | function decimals() external pure returns (uint8); 10 | function totalSupply() external view returns (uint); 11 | function balanceOf(address owner) external view returns (uint); 12 | function allowance(address owner, address spender) external view returns (uint); 13 | 14 | function approve(address spender, uint value) external returns (bool); 15 | function transfer(address to, uint value) external returns (bool); 16 | function transferFrom(address from, address to, uint value) external returns (bool); 17 | 18 | function DOMAIN_SEPARATOR() external view returns (bytes32); 19 | function PERMIT_TYPEHASH() external pure returns (bytes32); 20 | function nonces(address owner) external view returns (uint); 21 | 22 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 23 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/pancakeswap/interfaces/IPancakeFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IPancakeFactory { 4 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 5 | 6 | function feeTo() external view returns (address); 7 | function feeToSetter() external view returns (address); 8 | 9 | function getPair(address tokenA, address tokenB) external view returns (address pair); 10 | function allPairs(uint) external view returns (address pair); 11 | function allPairsLength() external view returns (uint); 12 | 13 | function createPair(address tokenA, address tokenB) external returns (address pair); 14 | 15 | function setFeeTo(address) external; 16 | function setFeeToSetter(address) external; 17 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/pancakeswap/interfaces/IPancakePair.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IPancakePair { 4 | event Approval(address indexed owner, address indexed spender, uint value); 5 | event Transfer(address indexed from, address indexed to, uint value); 6 | 7 | function name() external pure returns (string memory); 8 | function symbol() external pure returns (string memory); 9 | function decimals() external pure returns (uint8); 10 | function totalSupply() external view returns (uint); 11 | function balanceOf(address owner) external view returns (uint); 12 | function allowance(address owner, address spender) external view returns (uint); 13 | 14 | function approve(address spender, uint value) external returns (bool); 15 | function transfer(address to, uint value) external returns (bool); 16 | function transferFrom(address from, address to, uint value) external returns (bool); 17 | 18 | function DOMAIN_SEPARATOR() external view returns (bytes32); 19 | function PERMIT_TYPEHASH() external pure returns (bytes32); 20 | function nonces(address owner) external view returns (uint); 21 | 22 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 23 | 24 | event Mint(address indexed sender, uint amount0, uint amount1); 25 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); 26 | event Swap( 27 | address indexed sender, 28 | uint amount0In, 29 | uint amount1In, 30 | uint amount0Out, 31 | uint amount1Out, 32 | address indexed to 33 | ); 34 | event Sync(uint112 reserve0, uint112 reserve1); 35 | 36 | function MINIMUM_LIQUIDITY() external pure returns (uint); 37 | function factory() external view returns (address); 38 | function token0() external view returns (address); 39 | function token1() external view returns (address); 40 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 41 | function price0CumulativeLast() external view returns (uint); 42 | function price1CumulativeLast() external view returns (uint); 43 | function kLast() external view returns (uint); 44 | 45 | function mint(address to) external returns (uint liquidity); 46 | function burn(address to) external returns (uint amount0, uint amount1); 47 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; 48 | function skim(address to) external; 49 | function sync() external; 50 | 51 | function initialize(address, address) external; 52 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/pancakeswap/interfaces/IPancakeRouter01.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.2; 2 | 3 | interface IPancakeRouter01 { 4 | function factory() external pure returns (address); 5 | function WETH() external pure returns (address); 6 | 7 | function addLiquidity( 8 | address tokenA, 9 | address tokenB, 10 | uint amountADesired, 11 | uint amountBDesired, 12 | uint amountAMin, 13 | uint amountBMin, 14 | address to, 15 | uint deadline 16 | ) external returns (uint amountA, uint amountB, uint liquidity); 17 | function addLiquidityETH( 18 | address token, 19 | uint amountTokenDesired, 20 | uint amountTokenMin, 21 | uint amountETHMin, 22 | address to, 23 | uint deadline 24 | ) external payable returns (uint amountToken, uint amountETH, uint liquidity); 25 | function removeLiquidity( 26 | address tokenA, 27 | address tokenB, 28 | uint liquidity, 29 | uint amountAMin, 30 | uint amountBMin, 31 | address to, 32 | uint deadline 33 | ) external returns (uint amountA, uint amountB); 34 | function removeLiquidityETH( 35 | address token, 36 | uint liquidity, 37 | uint amountTokenMin, 38 | uint amountETHMin, 39 | address to, 40 | uint deadline 41 | ) external returns (uint amountToken, uint amountETH); 42 | function removeLiquidityWithPermit( 43 | address tokenA, 44 | address tokenB, 45 | uint liquidity, 46 | uint amountAMin, 47 | uint amountBMin, 48 | address to, 49 | uint deadline, 50 | bool approveMax, uint8 v, bytes32 r, bytes32 s 51 | ) external returns (uint amountA, uint amountB); 52 | function removeLiquidityETHWithPermit( 53 | address token, 54 | uint liquidity, 55 | uint amountTokenMin, 56 | uint amountETHMin, 57 | address to, 58 | uint deadline, 59 | bool approveMax, uint8 v, bytes32 r, bytes32 s 60 | ) external returns (uint amountToken, uint amountETH); 61 | function swapExactTokensForTokens( 62 | uint amountIn, 63 | uint amountOutMin, 64 | address[] calldata path, 65 | address to, 66 | uint deadline 67 | ) external returns (uint[] memory amounts); 68 | function swapTokensForExactTokens( 69 | uint amountOut, 70 | uint amountInMax, 71 | address[] calldata path, 72 | address to, 73 | uint deadline 74 | ) external returns (uint[] memory amounts); 75 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) 76 | external 77 | payable 78 | returns (uint[] memory amounts); 79 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) 80 | external 81 | returns (uint[] memory amounts); 82 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) 83 | external 84 | returns (uint[] memory amounts); 85 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) 86 | external 87 | payable 88 | returns (uint[] memory amounts); 89 | 90 | function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); 91 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); 92 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); 93 | function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); 94 | function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); 95 | } -------------------------------------------------------------------------------- /contracts/interfaces/5.0/pancakeswap/interfaces/IPancakeRouter02.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.2; 2 | 3 | import './IPancakeRouter01.sol'; 4 | 5 | interface IPancakeRouter02 is IPancakeRouter01 { 6 | function removeLiquidityETHSupportingFeeOnTransferTokens( 7 | address token, 8 | uint liquidity, 9 | uint amountTokenMin, 10 | uint amountETHMin, 11 | address to, 12 | uint deadline 13 | ) external returns (uint amountETH); 14 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 15 | address token, 16 | uint liquidity, 17 | uint amountTokenMin, 18 | uint amountETHMin, 19 | address to, 20 | uint deadline, 21 | bool approveMax, uint8 v, bytes32 r, bytes32 s 22 | ) external returns (uint amountETH); 23 | 24 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 25 | uint amountIn, 26 | uint amountOutMin, 27 | address[] calldata path, 28 | address to, 29 | uint deadline 30 | ) external; 31 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 32 | uint amountOutMin, 33 | address[] calldata path, 34 | address to, 35 | uint deadline 36 | ) external payable; 37 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 38 | uint amountIn, 39 | uint amountOutMin, 40 | address[] calldata path, 41 | address to, 42 | uint deadline 43 | ) external; 44 | } -------------------------------------------------------------------------------- /contracts/interfaces/6.0/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.2 <0.8.0; 4 | 5 | interface IERC20 { 6 | /** 7 | * @dev Returns the amount of tokens in existence. 8 | */ 9 | function totalSupply() external view returns (uint256); 10 | 11 | /** 12 | * @dev Returns the amount of tokens owned by `account`. 13 | */ 14 | function balanceOf(address account) external view returns (uint256); 15 | 16 | /** 17 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 18 | * 19 | * Returns a boolean value indicating whether the operation succeeded. 20 | * 21 | * Emits a {Transfer} event. 22 | */ 23 | function transfer(address recipient, uint256 amount) external returns (bool); 24 | 25 | /** 26 | * @dev Returns the remaining number of tokens that `spender` will be 27 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 28 | * zero by default. 29 | * 30 | * This value changes when {approve} or {transferFrom} are called. 31 | */ 32 | function allowance(address owner, address spender) external view returns (uint256); 33 | 34 | /** 35 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 36 | * 37 | * Returns a boolean value indicating whether the operation succeeded. 38 | * 39 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 40 | * that someone may use both the old and the new allowance by unfortunate 41 | * transaction ordering. One possible solution to mitigate this race 42 | * condition is to first reduce the spender's allowance to 0 and set the 43 | * desired value afterwards: 44 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 45 | * 46 | * Emits an {Approval} event. 47 | */ 48 | function approve(address spender, uint256 amount) external returns (bool); 49 | 50 | /** 51 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 52 | * allowance mechanism. `amount` is then deducted from the caller's 53 | * allowance. 54 | * 55 | * Returns a boolean value indicating whether the operation succeeded. 56 | * 57 | * Emits a {Transfer} event. 58 | */ 59 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 60 | 61 | /** 62 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 63 | * another (`to`). 64 | * 65 | * Note that `value` may be zero. 66 | */ 67 | event Transfer(address indexed from, address indexed to, uint256 value); 68 | 69 | /** 70 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 71 | * a call to {approve}. `value` is the new allowance. 72 | */ 73 | event Approval(address indexed owner, address indexed spender, uint256 value); 74 | } -------------------------------------------------------------------------------- /contracts/interfaces/6.0/IUniswapV2Router01.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.2; 4 | 5 | interface IUniswapV2Router01 { 6 | function factory() external pure returns (address); 7 | function WETH() external pure returns (address); 8 | 9 | function addLiquidity( 10 | address tokenA, 11 | address tokenB, 12 | uint amountADesired, 13 | uint amountBDesired, 14 | uint amountAMin, 15 | uint amountBMin, 16 | address to, 17 | uint deadline 18 | ) external returns (uint amountA, uint amountB, uint liquidity); 19 | function addLiquidityETH( 20 | address token, 21 | uint amountTokenDesired, 22 | uint amountTokenMin, 23 | uint amountETHMin, 24 | address to, 25 | uint deadline 26 | ) external payable returns (uint amountToken, uint amountETH, uint liquidity); 27 | function removeLiquidity( 28 | address tokenA, 29 | address tokenB, 30 | uint liquidity, 31 | uint amountAMin, 32 | uint amountBMin, 33 | address to, 34 | uint deadline 35 | ) external returns (uint amountA, uint amountB); 36 | function removeLiquidityETH( 37 | address token, 38 | uint liquidity, 39 | uint amountTokenMin, 40 | uint amountETHMin, 41 | address to, 42 | uint deadline 43 | ) external returns (uint amountToken, uint amountETH); 44 | function removeLiquidityWithPermit( 45 | address tokenA, 46 | address tokenB, 47 | uint liquidity, 48 | uint amountAMin, 49 | uint amountBMin, 50 | address to, 51 | uint deadline, 52 | bool approveMax, uint8 v, bytes32 r, bytes32 s 53 | ) external returns (uint amountA, uint amountB); 54 | function removeLiquidityETHWithPermit( 55 | address token, 56 | uint liquidity, 57 | uint amountTokenMin, 58 | uint amountETHMin, 59 | address to, 60 | uint deadline, 61 | bool approveMax, uint8 v, bytes32 r, bytes32 s 62 | ) external returns (uint amountToken, uint amountETH); 63 | function swapExactTokensForTokens( 64 | uint amountIn, 65 | uint amountOutMin, 66 | address[] calldata path, 67 | address to, 68 | uint deadline 69 | ) external returns (uint[] memory amounts); 70 | function swapTokensForExactTokens( 71 | uint amountOut, 72 | uint amountInMax, 73 | address[] calldata path, 74 | address to, 75 | uint deadline 76 | ) external returns (uint[] memory amounts); 77 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) 78 | external 79 | payable 80 | returns (uint[] memory amounts); 81 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) 82 | external 83 | returns (uint[] memory amounts); 84 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) 85 | external 86 | returns (uint[] memory amounts); 87 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) 88 | external 89 | payable 90 | returns (uint[] memory amounts); 91 | 92 | function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); 93 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); 94 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); 95 | function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); 96 | function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); 97 | } -------------------------------------------------------------------------------- /contracts/interfaces/6.0/IUniswapV2Router02.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.2; 4 | 5 | import './IUniswapV2Router01.sol'; 6 | 7 | interface IUniswapV2Router02 is IUniswapV2Router01 { 8 | function removeLiquidityETHSupportingFeeOnTransferTokens( 9 | address token, 10 | uint liquidity, 11 | uint amountTokenMin, 12 | uint amountETHMin, 13 | address to, 14 | uint deadline 15 | ) external returns (uint amountETH); 16 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 17 | address token, 18 | uint liquidity, 19 | uint amountTokenMin, 20 | uint amountETHMin, 21 | address to, 22 | uint deadline, 23 | bool approveMax, uint8 v, bytes32 r, bytes32 s 24 | ) external returns (uint amountETH); 25 | 26 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 27 | uint amountIn, 28 | uint amountOutMin, 29 | address[] calldata path, 30 | address to, 31 | uint deadline 32 | ) external; 33 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 34 | uint amountOutMin, 35 | address[] calldata path, 36 | address to, 37 | uint deadline 38 | ) external payable; 39 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 40 | uint amountIn, 41 | uint amountOutMin, 42 | address[] calldata path, 43 | address to, 44 | uint deadline 45 | ) external; 46 | } -------------------------------------------------------------------------------- /contracts/utils/Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.6 <0.8.0; 4 | 5 | /** 6 | * @dev Provides information about the current execution context, including the 7 | * sender of the transaction and its data. While these are generally available 8 | * via msg.sender and msg.data, they should not be accessed in such a direct 9 | * manner, since when dealing with meta-transactions the account sending and 10 | * paying for execution may not be the actual sender (as far as an application 11 | * is concerned). 12 | * 13 | * This contract is only required for intermediate, library-like contracts. 14 | */ 15 | abstract contract Context { 16 | function _msgSender() internal view virtual returns (address) { 17 | return msg.sender; 18 | } 19 | 20 | function _msgData() internal view virtual returns (bytes calldata) { 21 | return msg.data; 22 | } 23 | } -------------------------------------------------------------------------------- /contracts/utils/Ownable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.6 <0.8.0; 4 | import "./Context.sol"; 5 | 6 | /** 7 | * @dev Contract module which provides a basic access control mechanism, where 8 | * there is an account (an owner) that can be granted exclusive access to 9 | * specific functions. 10 | * 11 | * By default, the owner account will be the one that deploys the contract. This 12 | * can later be changed with {transferOwnership}. 13 | * 14 | * This module is used through inheritance. It will make available the modifier 15 | * `onlyOwner`, which can be applied to your functions to restrict their use to 16 | * the owner. 17 | */ 18 | abstract contract Ownable is Context { 19 | address private _owner; 20 | 21 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 22 | 23 | /** 24 | * @dev Initializes the contract setting the deployer as the initial owner. 25 | */ 26 | constructor() { 27 | _transferOwnership(_msgSender()); 28 | } 29 | 30 | /** 31 | * @dev Returns the address of the current owner. 32 | */ 33 | function owner() public view virtual returns (address) { 34 | return _owner; 35 | } 36 | 37 | /** 38 | * @dev Throws if called by any account other than the owner. 39 | */ 40 | modifier onlyOwner() { 41 | require(owner() == _msgSender(), "Ownable: caller is not the owner"); 42 | _; 43 | } 44 | 45 | /** 46 | * @dev Leaves the contract without owner. It will not be possible to call 47 | * `onlyOwner` functions anymore. Can only be called by the current owner. 48 | * 49 | * NOTE: Renouncing ownership will leave the contract without an owner, 50 | * thereby removing any functionality that is only available to the owner. 51 | */ 52 | function renounceOwnership() public virtual onlyOwner { 53 | _transferOwnership(address(0)); 54 | } 55 | 56 | /** 57 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 58 | * Can only be called by the current owner. 59 | */ 60 | function transferOwnership(address newOwner) public virtual onlyOwner { 61 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 62 | _transferOwnership(newOwner); 63 | } 64 | 65 | /** 66 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 67 | * Internal function without access restriction. 68 | */ 69 | function _transferOwnership(address newOwner) internal virtual { 70 | address oldOwner = _owner; 71 | _owner = newOwner; 72 | emit OwnershipTransferred(oldOwner, newOwner); 73 | } 74 | } -------------------------------------------------------------------------------- /contracts/utils/SafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.2 <0.8.0; 4 | 5 | library SafeMath { 6 | /** 7 | * @dev Returns the addition of two unsigned integers, reverting on 8 | * overflow. 9 | * 10 | * Counterpart to Solidity's `+` operator. 11 | * 12 | * Requirements: 13 | * 14 | * - Addition cannot overflow. 15 | */ 16 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 17 | uint256 c = a + b; 18 | require(c >= a, "SafeMath: addition overflow"); 19 | 20 | return c; 21 | } 22 | 23 | /** 24 | * @dev Returns the subtraction of two unsigned integers, reverting on 25 | * overflow (when the result is negative). 26 | * 27 | * Counterpart to Solidity's `-` operator. 28 | * 29 | * Requirements: 30 | * 31 | * - Subtraction cannot overflow. 32 | */ 33 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 34 | require(b <= a, "SafeMath: subtraction overflow"); 35 | uint256 c = a - b; 36 | 37 | return c; 38 | } 39 | 40 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 41 | require(b <= a, errorMessage); 42 | uint256 c = a - b; 43 | 44 | return c; 45 | } 46 | 47 | /** 48 | * @dev Returns the multiplication of two unsigned integers, reverting on 49 | * overflow. 50 | * 51 | * Counterpart to Solidity's `*` operator. 52 | * 53 | * Requirements: 54 | * 55 | * - Multiplication cannot overflow. 56 | */ 57 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 58 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 59 | // benefit is lost if 'b' is also tested. 60 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 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 | 71 | /** 72 | * @dev Returns the integer division of two unsigned integers. Reverts on 73 | * division by zero. The result is rounded towards zero. 74 | * 75 | * Counterpart to Solidity's `/` operator. Note: this function uses a 76 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 77 | * uses an invalid opcode to revert (consuming all remaining gas). 78 | * 79 | * Requirements: 80 | * 81 | * - The divisor cannot be zero. 82 | */ 83 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 84 | require(b > 0, "SafeMath: division by zero"); 85 | uint256 c = a / b; 86 | 87 | return c; 88 | } 89 | 90 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 91 | require(b > 0, errorMessage); 92 | uint256 c = a / b; 93 | 94 | return c; 95 | } 96 | 97 | /** 98 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 99 | * Reverts with custom message when dividing by zero. 100 | * 101 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 102 | * opcode (which leaves remaining gas untouched) while Solidity uses an 103 | * invalid opcode to revert (consuming all remaining gas). 104 | * 105 | * Requirements: 106 | * 107 | * - The divisor cannot be zero. 108 | */ 109 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 110 | require(b != 0, "SafeMath: modulo by zero"); 111 | uint256 c = a % b; 112 | 113 | return c; 114 | } 115 | 116 | } -------------------------------------------------------------------------------- /hardhat.config.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | 3 | require("@nomiclabs/hardhat-etherscan"); 4 | require("@nomiclabs/hardhat-waffle"); 5 | require("hardhat-gas-reporter"); 6 | require("solidity-coverage"); 7 | require("@nomiclabs/hardhat-truffle5"); 8 | 9 | 10 | // This is a sample Hardhat task. To learn how to create your own go to 11 | // https://hardhat.org/guides/create-task.html 12 | task("accounts", "Prints the list of accounts", async (taskArgs, hre) => { 13 | const accounts = await hre.ethers.getSigners(); 14 | 15 | for (const account of accounts) { 16 | console.log(account.address); 17 | } 18 | }); 19 | 20 | // You need to export an object to set up your config 21 | // Go to https://hardhat.org/config/ to learn more 22 | 23 | /** 24 | * @type import('hardhat/config').HardhatUserConfig 25 | */ 26 | module.exports = { 27 | solidity: { 28 | compilers: [ 29 | { 30 | version: "0.5.0", 31 | }, 32 | { 33 | version: "0.5.7", 34 | }, 35 | ], 36 | }, 37 | networks: { 38 | ropsten: { 39 | url: process.env.ROPSTEN_INFURA_URL || "", 40 | accounts: 41 | process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], 42 | }, 43 | kovan: { 44 | url: process.env.KOVAN_INFURA_URL || "", 45 | accounts: 46 | process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], 47 | }, 48 | }, 49 | gasReporter: { 50 | enabled: process.env.REPORT_GAS !== undefined, 51 | currency: "USD", 52 | }, 53 | etherscan: { 54 | apiKey: process.env.ETHERSCAN_API_KEY, 55 | }, 56 | }; 57 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const {program} = require('./program'); 2 | // Start the app 3 | program.init(); 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /migrations/1-deploy-contracts.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | 3 | const {mainnet} = require('../program/utils/addresses') 4 | const PancakeApeArbitrage = artifacts.require("PancakeApeArbitrage"); 5 | const PancakeBakeryArbitrage = artifacts.require("PancakeBakeryArbitrage"); 6 | const ApeBakeryArbitrage = artifacts.require("ApeBakeryArbitrage"); 7 | 8 | module.exports = function (deployer) { 9 | 10 | deployer.deploy( 11 | ApeBakeryArbitrage, 12 | mainnet.apeswap.factory.address, //apefactory 13 | mainnet.bakeryswap.factory.address, //bakeryfactory 14 | mainnet.tokens.Binance.wbnb.address, //WBNB Token 15 | mainnet.apeswap.router.address, //aperouter 16 | mainnet.bakeryswap.router.address, //bakeryrouter 17 | process.env.ACCOUNT, 18 | ); 19 | 20 | deployer.deploy( 21 | PancakeApeArbitrage, 22 | mainnet.pancakeswap.factory.address, //pancakefactory 23 | mainnet.apeswap.factory.address, //apefactory 24 | mainnet.tokens.Binance.wbnb.address, //WBNB Token 25 | mainnet.pancakeswap.router.address, //pancakerouter 26 | mainnet.apeswap.router.address, //aperouter 27 | process.env.ACCOUNT, 28 | ); 29 | 30 | 31 | deployer.deploy( 32 | PancakeBakeryArbitrage, 33 | mainnet.pancakeswap.factory.address, //pancakefactory 34 | mainnet.bakeryswap.factory.address, //bakeryfactory 35 | mainnet.tokens.Binance.wbnb.address, //WBNB Token 36 | mainnet.pancakeswap.router.address, //pancakerouter 37 | mainnet.bakeryswap.router.address, //bakeryrouter 38 | process.env.ACCOUNT, 39 | ); 40 | 41 | }; 42 | -------------------------------------------------------------------------------- /migrations/hardhat/binance/deploy-swap-contracts.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const hre = require("hardhat"); 3 | 4 | async function main() { 5 | await hre.run('compile'); 6 | await deployContracts(); 7 | } 8 | 9 | async function deployContracts() { 10 | 11 | await deployApeTokenSwapContract(); 12 | await deployBakeryTokenSwapContract(); 13 | await deployPancakeTokenSwapContract(); 14 | } 15 | 16 | async function deployApeTokenSwapContract(){ 17 | let ApeTokenSwap = await hre.ethers.getContractFactory("ApeTokenSwap"); 18 | let contract = ApeTokenSwap.deploy(); 19 | await contract.deployed(); 20 | console.log("ApeTokenSwap Contract deployed to:", contract.address); 21 | } 22 | 23 | 24 | async function deployBakeryTokenSwapContract(){ 25 | let BakeryTokenSwap = await hre.ethers.getContractFactory("BakeryTokenSwap"); 26 | let contract = BakeryTokenSwap.deploy(); 27 | await contract.deployed(); 28 | console.log("BakeryTokenSwap Contract deployed to:", contract.address); 29 | } 30 | 31 | async function deployPancakeTokenSwapContract(){ 32 | let PancakeTokenSwap = await hre.ethers.getContractFactory("PancakeTokenSwap"); 33 | let contract = PancakeTokenSwap.deploy(); 34 | await contract.deployed(); 35 | console.log("BakeryTokenSwap Contract deployed to:", contract.address); 36 | } 37 | 38 | 39 | main().catch((error) => { 40 | console.error(error); 41 | process.exitCode = 1; 42 | }); 43 | 44 | 45 | -------------------------------------------------------------------------------- /migrations/truffle/binance/1-deploy-binance-arbitrage-contracts.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | 3 | const {mainnet} = require('../../../program/utils/addresses') 4 | const ApeBakeryArbitrage = require('../../../build/contracts/ApeBakeryArbitrage.json'); 5 | const ApePancakeArbitrage = require('../../../build/contracts/ApePancakeArbitrage.json'); 6 | const BakeryApeArbitrage = require('../../../build/contracts/BakeryApeArbitrage.json'); 7 | const BakeryPancakeArbitrage = require('../../../build/contracts/BakeryPancakeArbitrage.json'); 8 | const PancakeApeArbitrage = require('../../../build/contracts/PancakeApeArbitrage.json'); 9 | const PancakeBakeryArbitrage = require('../../../build/contracts/PancakeBakeryArbitrage.json'); 10 | 11 | 12 | module.exports = function (deployer) { 13 | 14 | // Deploying them all at once wouldnt be ideal. 15 | // Uncomment out the specfic contract you want to deploy 16 | // and run the migration one at a time. 17 | 18 | // deployer.deploy( 19 | // ApeBakeryArbitrage, 20 | // mainnet.apeswap.factory.address, //apefactory 21 | // mainnet.bakeryswap.factory.address, //bakeryfactory 22 | // mainnet.tokens.Binance.wbnb.address, //WBNB Token 23 | // mainnet.apeswap.router.address, //aperouter 24 | // mainnet.bakeryswap.router.address, //bakeryrouter 25 | // process.env.ACCOUNT, 26 | // ); 27 | 28 | 29 | // deployer.deploy( 30 | // ApePancakeArbitrage, 31 | // mainnet.apeswap.factory.address, //apefactory 32 | // mainnet.pancakeswap.factory.address, //pancakefactory 33 | // mainnet.tokens.Binance.wbnb.address, //WBNB Token 34 | // mainnet.apeswap.router.address, //aperouter 35 | // mainnet.pancakeswap.router.address, //pancakerouter 36 | // process.env.ACCOUNT, 37 | // ); 38 | 39 | 40 | // deployer.deploy( 41 | // BakeryApeArbitrage, 42 | // mainnet.bakeryswap.factory.address, //bakeryfactory 43 | // mainnet.apeswap.factory.address, //apefactory 44 | // mainnet.tokens.Binance.wbnb.address, //WBNB Token 45 | // mainnet.bakeryswap.router.address, //bakeryrouter 46 | // mainnet.apeswap.router.address, //aperouter 47 | // process.env.ACCOUNT, 48 | // ); 49 | 50 | // deployer.deploy( 51 | // BakeryPancakeArbitrage, 52 | // mainnet.bakeryswap.factory.address, //bakeryfactory 53 | // mainnet.pancakeswap.factory.address, //apefactory 54 | // mainnet.tokens.Binance.wbnb.address, //WBNB Token 55 | // mainnet.bakeryswap.router.address, //bakeryrouter 56 | // mainnet.pancakeswap.router.address, //pancakerouter 57 | // process.env.ACCOUNT, 58 | // ); 59 | 60 | 61 | deployer.deploy( 62 | PancakeApeArbitrage, 63 | mainnet.pancakeswap.factory.address, //pancakefactory 64 | mainnet.apeswap.factory.address, //apefactory 65 | mainnet.tokens.Binance.wbnb.address, //WBNB Token 66 | mainnet.pancakeswap.router.address, //pancakerouter 67 | mainnet.apeswap.router.address, //aperouter 68 | process.env.ACCOUNT, 69 | ); 70 | 71 | 72 | // deployer.deploy( 73 | // PancakeBakeryArbitrage, 74 | // mainnet.pancakeswap.factory.address, //pancakefactory 75 | // mainnet.bakeryswap.factory.address, //bakeryfactory 76 | // mainnet.tokens.Binance.wbnb.address, //WBNB Token 77 | // mainnet.pancakeswap.router.address, //pancakerouter 78 | // mainnet.bakeryswap.router.address, //bakeryrouter 79 | // process.env.ACCOUNT, 80 | // ); 81 | 82 | }; 83 | -------------------------------------------------------------------------------- /migrations/truffle/binance/2-deploy-binance-swap-contracts.js: -------------------------------------------------------------------------------- 1 | const ApeTokenSwap = require('../build/contracts/ApeTokenSwap.json'); 2 | const BakeryTokenSwap = require('../build/contracts/BakeryTokenSwap.json'); 3 | const PancakeTokenSwap = require('../../../build/contracts/PancakeTokenSwap.json'); 4 | 5 | module.exports = function (deployer) { 6 | //deployer.deploy(ApeTokenSwap); 7 | //deployer.deploy(BakeryTokenSwap); 8 | //deployer.deploy(PancakeTokenSwap); 9 | }; -------------------------------------------------------------------------------- /migrations/truffle/ethereum/1-deploy-ethereum-arbitrage-contracts.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | 3 | const {mainnet} = require('../../../program/utils/addresses') 4 | const KySushiArbitrage = require('../build/contracts/KySushiArbitrage.json'); 5 | const KyUniArbitrage = require('../build/contracts/KyUniArbitrage.json'); 6 | const SushiKyArbitrage = require('../build/contracts/SushiKyArbitrage.json'); 7 | const SushiUniArbitrage = require('../build/contracts/SushiUniArbitrage.json'); 8 | const UniKyArbitrage = require('../build/contracts/UniKyArbitrage.json'); 9 | const UniSushiArbitrage = require('../build/contracts/UniSushiArbitrage.json'); 10 | 11 | 12 | module.exports = function (deployer) { 13 | 14 | 15 | // Deploying them all at once wouldnt be ideal. 16 | // Uncomment out the specfic contract you want to deploy 17 | // and run the migration one at a time. 18 | 19 | 20 | // deployer.deploy( 21 | // KySushiArbitrage, 22 | // mainnet.kyber.proxy.address, // kyber proxy 23 | // mainnet.sushiswap.router.address, // sushi router 24 | // mainnet.tokens.Ethereum.weth.address, // WETH 25 | // mainnet.tokens.Ethereum.dai, // dai 26 | // process.env.ACCOUNT, 27 | // ); 28 | 29 | 30 | // deployer.deploy( 31 | // KyUniArbitrage, 32 | // mainnet.kyber.proxy.address, // kyber proxy 33 | // mainnet.uniswap.router.address, // uniswap router 34 | // mainnet.tokens.Ethereum.weth.address, // WETH 35 | // mainnet.tokens.Ethereum.dai, // dai 36 | // process.env.ACCOUNT, 37 | // ); 38 | 39 | 40 | // deployer.deploy( 41 | // SushiKyArbitrage, 42 | // mainnet.sushiswap.router.address, // sushi router 43 | // mainnet.kyber.proxy.address, // kyber proxy 44 | // mainnet.tokens.Ethereum.weth.address, // WETH 45 | // mainnet.tokens.Ethereum.dai, // dai 46 | // process.env.ACCOUNT, 47 | // ); 48 | 49 | // deployer.deploy( 50 | // SushiUniArbitrage, 51 | // mainnet.sushiswap.router.address, // sushi router 52 | // mainnet.uniswap.router.address, // uniswap router 53 | // mainnet.tokens.Ethereum.weth.address, // WETH 54 | // mainnet.tokens.Ethereum.dai, // dai 55 | // process.env.ACCOUNT, 56 | // ); 57 | 58 | 59 | // deployer.deploy( 60 | // UniKyArbitrage, 61 | // mainnet.uniswap.router.address, // uniswap router 62 | // mainnet.kyber.proxy.address, // kyber proxy 63 | // mainnet.tokens.Ethereum.weth.address, // WETH 64 | // mainnet.tokens.Ethereum.dai, // dai 65 | // process.env.ACCOUNT, 66 | // ); 67 | 68 | 69 | // deployer.deploy( 70 | // UniSushiArbitrage, 71 | // mainnet.uniswap.router.address, // uniswap router 72 | // mainnet.sushiswap.router.address, // sushi router 73 | // mainnet.tokens.Ethereum.weth.address, // WETH 74 | // mainnet.tokens.Ethereum.dai, // dai 75 | // process.env.ACCOUNT, 76 | // ); 77 | 78 | }; 79 | -------------------------------------------------------------------------------- /migrations/truffle/ethereum/kovan/1-deploy-kovan-arbitrage-contracts.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | 3 | const {kovan} = require('../../../../program/utils/addresses') 4 | const KySushiArbitrage = require('../build/contracts/KySushiArbitrage.json'); 5 | const KyUniArbitrage = require('../build/contracts/KyUniArbitrage.json'); 6 | const SushiKyArbitrage = require('../build/contracts/SushiKyArbitrage.json'); 7 | const SushiUniArbitrage = require('../build/contracts/SushiUniArbitrage.json'); 8 | const UniKyArbitrage = require('../build/contracts/UniKyArbitrage.json'); 9 | const UniSushiArbitrage = require('../build/contracts/UniSushiArbitrage.json'); 10 | 11 | 12 | module.exports = function (deployer) { 13 | 14 | 15 | // Deploying them all at once wouldnt be ideal. 16 | // Uncomment out the specfic contract you want to deploy 17 | // and run the migration one at a time. 18 | 19 | 20 | // deployer.deploy( 21 | // KySushiArbitrage, 22 | // kovan.kyber.proxy.address, // kyber proxy 23 | // kovan.sushiswap.router.address, // sushi router 24 | // kovan.tokens.weth.address, // WETH 25 | // kovan.tokens.dai, // dai 26 | // process.env.ACCOUNT, 27 | // ); 28 | 29 | 30 | // deployer.deploy( 31 | // KyUniArbitrage, 32 | // kovan.kyber.proxy.address, // kyber proxy 33 | // kovan.uniswap.router.address, // uniswap router 34 | // kovan.tokens.weth.address, // WETH 35 | // kovan.tokens.dai, // dai 36 | // process.env.ACCOUNT, 37 | // ); 38 | 39 | 40 | // deployer.deploy( 41 | // SushiKyArbitrage, 42 | // kovan.sushiswap.router.address, // sushi router 43 | // kovan.kyber.proxy.address, // kyber proxy 44 | // kovan.tokens.weth.address, // WETH 45 | // kovan.tokens.dai, // dai 46 | // process.env.ACCOUNT, 47 | // ); 48 | 49 | // deployer.deploy( 50 | // SushiUniArbitrage, 51 | // kovan.sushiswap.router.address, // sushi router 52 | // kovan.uniswap.router.address, // uniswap router 53 | // kovan.tokens.weth.address, // WETH 54 | // kovan.tokens.dai, // dai 55 | // process.env.ACCOUNT, 56 | // ); 57 | 58 | 59 | // deployer.deploy( 60 | // UniKyArbitrage, 61 | // kovan.uniswap.router.address, // uniswap router 62 | // kovan.kyber.proxy.address, // kyber proxy 63 | // kovan.tokens.weth.address, // WETH 64 | // kovan.tokens.dai, // dai 65 | // process.env.ACCOUNT, 66 | // ); 67 | 68 | 69 | // deployer.deploy( 70 | // UniSushiArbitrage, 71 | // kovan.uniswap.router.address, // uniswap router 72 | // kovan.sushiswap.router.address, // sushi router 73 | // kovan.tokens.weth.address, // WETH 74 | // kovan.tokens.dai, // dai 75 | // process.env.ACCOUNT, 76 | // ); 77 | 78 | }; 79 | -------------------------------------------------------------------------------- /migrations/truffle/ethereum/ropsten/1-deploy-ropsten-arbitrage-contracts.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | 3 | const {ropsten} = require('../../../../program/utils/addresses') 4 | const KySushiArbitrage = require('../build/contracts/KySushiArbitrage.json'); 5 | const KyUniArbitrage = require('../build/contracts/KyUniArbitrage.json'); 6 | const SushiKyArbitrage = require('../build/contracts/SushiKyArbitrage.json'); 7 | const SushiUniArbitrage = require('../build/contracts/SushiUniArbitrage.json'); 8 | const UniKyArbitrage = require('../build/contracts/UniKyArbitrage.json'); 9 | const UniSushiArbitrage = require('../build/contracts/UniSushiArbitrage.json'); 10 | 11 | 12 | module.exports = function (deployer) { 13 | 14 | 15 | // Deploying them all at once wouldnt be ideal. 16 | // Uncomment out the specfic contract you want to deploy 17 | // and run the migration one at a time. 18 | 19 | 20 | // deployer.deploy( 21 | // KySushiArbitrage, 22 | // ropsten.kyber.proxy.address, // kyber proxy 23 | // ropsten.sushiswap.router.address, // sushi router 24 | // ropsten.tokens.weth.address, // WETH 25 | // ropsten.tokens.dai, // dai 26 | // process.env.ACCOUNT, 27 | // ); 28 | 29 | 30 | // deployer.deploy( 31 | // KyUniArbitrage, 32 | // ropsten.kyber.proxy.address, // kyber proxy 33 | // ropsten.uniswap.router.address, // uniswap router 34 | // ropsten.tokens.weth.address, // WETH 35 | // ropsten.tokens.dai, // dai 36 | // process.env.ACCOUNT, 37 | // ); 38 | 39 | 40 | // deployer.deploy( 41 | // SushiKyArbitrage, 42 | // ropsten.sushiswap.router.address, // sushi router 43 | // ropsten.kyber.proxy.address, // kyber proxy 44 | // ropsten.tokens.weth.address, // WETH 45 | // ropsten.tokens.dai, // dai 46 | // process.env.ACCOUNT, 47 | // ); 48 | 49 | // deployer.deploy( 50 | // SushiUniArbitrage, 51 | // ropsten.sushiswap.router.address, // sushi router 52 | // ropsten.uniswap.router.address, // uniswap router 53 | // ropsten.tokens.weth.address, // WETH 54 | // ropsten.tokens.dai, // dai 55 | // process.env.ACCOUNT, 56 | // ); 57 | 58 | 59 | // deployer.deploy( 60 | // UniKyArbitrage, 61 | // ropsten.uniswap.router.address, // uniswap router 62 | // ropsten.kyber.proxy.address, // kyber proxy 63 | // ropsten.tokens.weth.address, // WETH 64 | // ropsten.tokens.dai, // dai 65 | // process.env.ACCOUNT, 66 | // ); 67 | 68 | 69 | // deployer.deploy( 70 | // UniSushiArbitrage, 71 | // ropsten.uniswap.router.address, // uniswap router 72 | // ropsten.sushiswap.router.address, // sushi router 73 | // ropsten.tokens.weth.address, // WETH 74 | // ropsten.tokens.dai, // dai 75 | // process.env.ACCOUNT, 76 | // ); 77 | 78 | }; 79 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "defiterminal", 3 | "version": "1.0.0", 4 | "description": "Commit Arbitrage, Check Market Prices, or Swap Tokens using a command-line interface powered by node js.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node ./" 9 | }, 10 | "keywords": [ 11 | "Decentralized", 12 | "Finance", 13 | "Terminal" 14 | ], 15 | "author": "Nathan Antwi - https://github.com/DrMaxis", 16 | "homepage": "https://github.com/AfriaDev/DefiTerminal", 17 | "license": "ISC", 18 | "dependencies": { 19 | "@studydefi/money-legos": "^2.3.3", 20 | "@sushiswap/core": "^1.4.2", 21 | "@truffle/hdwallet-provider": "^1.5.1", 22 | "@uniswap/sdk": "^2.0.5", 23 | "@uniswap/v2-core": "^1.0.1", 24 | "@uniswap/v2-periphery": "^1.1.0-beta.0", 25 | "axios": "^0.21.2", 26 | "bignumber.js": "^9.0.1", 27 | "colors": "^1.4.0", 28 | "commander": "^8.2.0", 29 | "console.table": "^0.10.0", 30 | "ejs": "^2.5.6", 31 | "express": "^4.15.2", 32 | "figlet": "^1.5.2", 33 | "infura-web3-provider": "0.0.3", 34 | "inquirer": "^8.2.0", 35 | "lodash": "^4.17.15", 36 | "log4js": "^6.3.0", 37 | "moment": "^2.29.1", 38 | "moment-timezone": "^0.5.28", 39 | "numeral": "^2.0.6", 40 | "pad": "^3.2.0", 41 | "truffle": "^5.4.14", 42 | "websocket": "^1.0.34", 43 | "ws": "^8.2.3" 44 | }, 45 | "engines": { 46 | "node": "12.x" 47 | }, 48 | "devDependencies": { 49 | "@nomiclabs/hardhat-ethers": "^2.0.2", 50 | "@nomiclabs/hardhat-etherscan": "^2.1.6", 51 | "@nomiclabs/hardhat-truffle5": "^2.0.2", 52 | "@nomiclabs/hardhat-waffle": "^2.0.1", 53 | "@nomiclabs/hardhat-web3": "^2.0.0", 54 | "chai": "^4.3.4", 55 | "dotenv": "^10.0.0", 56 | "eslint": "^7.32.0", 57 | "eslint-config-prettier": "^8.3.0", 58 | "eslint-config-standard": "^16.0.3", 59 | "eslint-plugin-import": "^2.25.2", 60 | "eslint-plugin-node": "^11.1.0", 61 | "eslint-plugin-prettier": "^3.4.1", 62 | "eslint-plugin-promise": "^5.1.0", 63 | "ethereum-waffle": "^3.4.0", 64 | "ethers": "^5.4.7", 65 | "hardhat": "^2.6.6", 66 | "hardhat-gas-reporter": "^1.0.4", 67 | "prettier": "^2.4.1", 68 | "prettier-plugin-solidity": "^1.0.0-beta.18", 69 | "request-promise": "^4.2.6", 70 | "solhint": "^3.3.6", 71 | "solidity-coverage": "^0.7.17", 72 | "web3": "^1.6.0" 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /program/index.js: -------------------------------------------------------------------------------- 1 | const banner = require('./views/banner'); 2 | const programStarter = require('./lib'); 3 | 4 | async function run() { 5 | console.log(await showBanner()); 6 | programStarter.start(); 7 | } 8 | 9 | async function showBanner() { 10 | return new Promise((resolve, reject) => { 11 | banner.showBanner(resolve, reject) 12 | }) 13 | } 14 | 15 | module.exports = { 16 | program: { 17 | init: function() { 18 | run(); 19 | } 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /program/lib/index.js: -------------------------------------------------------------------------------- 1 | const {Command} = require('commander'); 2 | const program = new Command(); 3 | const interactiveProgram = require('./interactive'); 4 | 5 | 6 | function startProgram() { 7 | if (process.argv.length <= 2) { 8 | interactiveProgram.init(); 9 | } else { 10 | // start interactive cli 11 | program 12 | .command('interactive') 13 | .alias('-i') 14 | .description('Interactive') 15 | .action(function () { 16 | interactiveProgram.init(); 17 | }); 18 | 19 | program.parse(process.argv); 20 | } 21 | 22 | } 23 | 24 | exports.start = () => { 25 | startProgram(); 26 | } -------------------------------------------------------------------------------- /program/lib/interactive/actions.js: -------------------------------------------------------------------------------- 1 | const chains = [ 2 | { 3 | name: 'Ethereum' 4 | }, 5 | { 6 | name: 'Binance' 7 | } 8 | ]; 9 | 10 | exports.chains = chains.map(function (a) { 11 | return a.name; 12 | }); 13 | -------------------------------------------------------------------------------- /program/lib/interactive/binance/actions.js: -------------------------------------------------------------------------------- 1 | const actions = [ 2 | { 3 | name: 'Commit Arbitrage' 4 | }, 5 | { 6 | name: 'Swap Tokens' 7 | }, 8 | { 9 | name: 'Fetch Exchange Prices' 10 | }, 11 | { 12 | name: 'Monitor Exchange Prices' 13 | } 14 | ]; 15 | exports.actions = actions.map(function (a) { 16 | return a.name; 17 | }); -------------------------------------------------------------------------------- /program/lib/interactive/binance/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require("inquirer"); 2 | const actionChoices = require('./actions'); 3 | 4 | 5 | function runInteractiveArbitrage() { 6 | let interactiveArbitrage = require('./interactive/arbitrage'); 7 | interactiveArbitrage.init(); 8 | } 9 | 10 | function runInteractivePrices() { 11 | let interactivePrices = require('./interactive/prices'); 12 | interactivePrices.init(); 13 | } 14 | 15 | function runInteractiveMonitor() { 16 | let interactiveMonitor = require('./interactive/monitor'); 17 | interactiveMonitor.init(); 18 | } 19 | 20 | function runInteractiveSwap() { 21 | let interactiveSwap = require('./interactive/swap'); 22 | interactiveSwap.init(); 23 | } 24 | 25 | 26 | function startInteractiveBinanceProgram() { 27 | const questions = [ 28 | {type: 'list', name: 'action', message: 'What do you want to do?', choices: actionChoices.actions}, 29 | ]; 30 | 31 | inquirer 32 | .prompt(questions) 33 | .then(function (answers) { 34 | if (answers.action === 'Commit Arbitrage') { 35 | runInteractiveArbitrage(); 36 | } 37 | if (answers.action === 'Fetch Exchange Prices') { 38 | runInteractivePrices(); 39 | } 40 | if (answers.action === 'Monitor Exchange Prices') { 41 | runInteractiveMonitor(); 42 | } 43 | if (answers.action === 'Swap Tokens') { 44 | runInteractiveSwap(); 45 | } 46 | }); 47 | 48 | } 49 | 50 | 51 | exports.init = () => { 52 | startInteractiveBinanceProgram(); 53 | } -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/arbitrage/actions.js: -------------------------------------------------------------------------------- 1 | const pairs = [ 2 | { 3 | name: 'WBNBBUSDC', 4 | description: 'Wrapped Binance Coin Over Binance Pegged USD Coin', 5 | stableToken: 'BUSDC', 6 | tradingToken: 'WBNB' 7 | }, 8 | { 9 | name: 'WBNBBUSD', 10 | description: 'Wrapped Binance Coin Over Binance Pegged USD', 11 | stableToken: 'BUSD', 12 | tradingToken: 'WBNB' 13 | } 14 | ]; 15 | 16 | const exchanges = [ 17 | { 18 | name: 'Apeswap', 19 | description: 'Apeswap Decentralized Exchange' 20 | }, 21 | { 22 | name: 'Bakeryswap', 23 | description: 'Bakeryswap Decentralized Exchange' 24 | }, 25 | { 26 | name: 'Pancakeswap', 27 | description: 'Pancakeswap Decentralized Exchange' 28 | }, 29 | ]; 30 | 31 | const networks = [ 32 | { 33 | name: 'Mainnet', 34 | description: 'The Main Binance Network' 35 | }, 36 | { 37 | name: 'Local', 38 | description: 'Local Test Network' 39 | } 40 | ] 41 | 42 | exports.pairs = pairs.map(function (pair) { 43 | return { 44 | name: pair.name, 45 | stableToken: pair.stableToken, 46 | tradingToken: pair.tradingToken 47 | }; 48 | }); 49 | 50 | exports.exchanges = exchanges.map(function (exchange) { 51 | return exchange.name; 52 | }); 53 | 54 | exports.networks = networks.map(function (network) { 55 | return network.name; 56 | }) -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/arbitrage/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer'); 2 | const arbitrageActions = require('./actions'); 3 | const ArbitrageService = require('../../../../../utils/arbitrage') 4 | 5 | function startInteractiveArbitrage() { 6 | const questions = [ 7 | {type: 'list', name: 'pair', message: 'Target Asset Pair', choices: arbitrageActions.pairs}, 8 | {type: 'list', name: 'buyingExchange', message: 'Exchange You Will Buy From', choices: arbitrageActions.exchanges}, 9 | {type: 'list', name: 'sellingExchange', message: 'Exchange You Will Sell At', choices: arbitrageActions.exchanges}, 10 | {type: 'list', name: 'network', message: 'Target Network', choices: arbitrageActions.networks}, 11 | {type: 'input', name: 'borrowAmount', message: 'Borrow Amount (WBNB)'}, 12 | ]; 13 | 14 | inquirer 15 | .prompt(questions) 16 | .then(function (answers) { 17 | let data = { 18 | pair: answers.pair, 19 | network: answers.network, 20 | buyingExchange: answers.buyingExchange, 21 | sellingExchange: answers.sellingExchange, 22 | borrowAmount: answers.borrowAmount, 23 | chain: 'Binance' 24 | 25 | }; 26 | ArbitrageService.binance.runArbitrage(data); 27 | }); 28 | } 29 | 30 | 31 | exports.init = () => { 32 | startInteractiveArbitrage(); 33 | } -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/monitor/actions.js: -------------------------------------------------------------------------------- 1 | const monitors = [ 2 | { 3 | name: 'Arbitrage' 4 | }, 5 | { 6 | name: 'Prices' 7 | }, 8 | ]; 9 | exports.monitors = monitors.map(function (a) { 10 | return a.name; 11 | }); 12 | -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/monitor/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer'); 2 | const monitorActions = require('./actions'); 3 | 4 | 5 | function runInteractiveArbitrageMonitorProgram() { 6 | let interactiveArbitrageMonitorProgram = require('./interactive/arbitrage') 7 | interactiveArbitrageMonitorProgram.init(); 8 | } 9 | 10 | function runInteractivePriceMonitorProgram() { 11 | let interactivePriceMonitorProgram = require('./interactive/price'); 12 | interactivePriceMonitorProgram.init(); 13 | } 14 | 15 | async function startInteractiveMonitor() { 16 | const questions = [ 17 | {type: 'list', name: 'monitor', message: 'What Would You Like To Monitor?', choices: monitorActions.monitors}, 18 | 19 | ]; 20 | 21 | inquirer 22 | .prompt(questions) 23 | .then(function (answers) { 24 | switch (answers.monitor) { 25 | case 'Arbitrage': 26 | runInteractiveArbitrageMonitorProgram(); 27 | break; 28 | case 'Prices': 29 | runInteractivePriceMonitorProgram(); 30 | break; 31 | default: 32 | } 33 | }); 34 | } 35 | 36 | exports.init = () => { 37 | return startInteractiveMonitor(); 38 | } -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/monitor/interactive/arbitrage/actions.js: -------------------------------------------------------------------------------- 1 | const pairs = [ 2 | { 3 | name: 'WBNBBUSDC', 4 | description: 'Wrapped Binance Coin Over Binance Pegged USD Coin', 5 | stableToken: 'BUSDC', 6 | tradingToken: 'WBNB' 7 | }, 8 | { 9 | name: 'WBNBBUSD', 10 | description: 'Wrapped Binance Coin Over Binance Pegged USD', 11 | stableToken: 'BUSD', 12 | tradingToken: 'WBNB' 13 | } 14 | ]; 15 | 16 | const exchanges = [ 17 | { 18 | name: 'Apeswap', 19 | description: 'Apeswap Decentralized Exchange' 20 | }, 21 | { 22 | name: 'Bakeryswap', 23 | description: 'Bakeryswap Decentralized Exchange' 24 | }, 25 | { 26 | name: 'Pancakeswap', 27 | description: 'Pancakeswap Decentralized Exchange' 28 | }, 29 | ]; 30 | 31 | const networks = [ 32 | { 33 | name: 'Mainnet', 34 | description: 'The Main Binance Network' 35 | }, 36 | { 37 | name: 'Local', 38 | description: 'Local Test Network' 39 | } 40 | ] 41 | 42 | exports.pairs = pairs.map(function (pair) { 43 | return { 44 | name: pair.name, 45 | stableToken: pair.stableToken, 46 | tradingToken: pair.tradingToken 47 | }; 48 | }); 49 | 50 | exports.exchanges = exchanges.map(function (exchange) { 51 | return exchange.name; 52 | }); 53 | 54 | exports.networks = networks.map(function (network) { 55 | return network.name; 56 | }) -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/monitor/interactive/arbitrage/index.js: -------------------------------------------------------------------------------- 1 | const arbitrageActions = require("./actions"); 2 | const inquirer = require("inquirer"); 3 | const monitor = require("../../../../../../../utils/monitor"); 4 | 5 | 6 | function startInteractiveArbitrageMonitor() { 7 | 8 | } const questions = [ 9 | {type: 'list', name: 'pair', message: 'Target Asset Pair', choices: arbitrageActions.pairs}, 10 | {type: 'list', name: 'buyingExchange', message: 'Exchange You Will Buy From', choices: arbitrageActions.exchanges}, 11 | {type: 'list', name: 'sellingExchange', message: 'Exchange You Will Sell At', choices: arbitrageActions.exchanges}, 12 | {type: 'list', name: 'network', message: 'Target Network', choices: arbitrageActions.networks}, 13 | {type: 'input', name: 'borrowAmount', message: 'Borrow Amount(WBNB)'}, 14 | ]; 15 | 16 | inquirer 17 | .prompt(questions) 18 | .then(function (answers) { 19 | let data = { 20 | pair: answers.pair, 21 | network: answers.network, 22 | buyingExchange: answers.buyingExchange, 23 | sellingExchange: answers.sellingExchange, 24 | borrowAmount: answers.borrowAmount, 25 | 26 | }; 27 | monitor.binance.arbitrage.initArbitrageMonitor(data); 28 | }); 29 | 30 | 31 | exports.init = () => { 32 | startInteractiveArbitrageMonitor(); 33 | } -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/monitor/interactive/price/actions.js: -------------------------------------------------------------------------------- 1 | const pairs = [ 2 | { 3 | name: 'WBNBBUSDC', 4 | description: 'Wrapped Binance Coin Over Binance Pegged USD Coin', 5 | stableToken: 'BUSDC', 6 | tradingToken: 'WBNB' 7 | }, 8 | { 9 | name: 'WBNBBUSD', 10 | description: 'Wrapped Binance Coin Over Binance Pegged USD', 11 | stableToken: 'BUSD', 12 | tradingToken: 'WBNB' 13 | } 14 | ]; 15 | 16 | const exchanges = [ 17 | { 18 | name: 'Apeswap', 19 | description: 'Apeswap Decentralized Exchange' 20 | }, 21 | { 22 | name: 'Bakeryswap', 23 | description: 'Bakeryswap Decentralized Exchange' 24 | }, 25 | { 26 | name: 'Pancakeswap', 27 | description: 'Pancakeswap Decentralized Exchange' 28 | }, 29 | ]; 30 | 31 | const networks = [ 32 | { 33 | name: 'Mainnet', 34 | description: 'The Main Binance Network' 35 | }, 36 | { 37 | name: 'Local', 38 | description: 'Local Test Network' 39 | } 40 | ] 41 | 42 | exports.pairs = pairs.map(function (pair) { 43 | return { 44 | name: pair.name, 45 | stableToken: pair.stableToken, 46 | tradingToken: pair.tradingToken 47 | }; 48 | }); 49 | 50 | exports.exchanges = exchanges.map(function (exchange) { 51 | return exchange.name; 52 | }); 53 | 54 | exports.networks = networks.map(function (network) { 55 | return network.name; 56 | }); -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/monitor/interactive/price/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require("inquirer"); 2 | const arbitrageActions = require("./actions"); 3 | const monitor = require('../../../../../../../utils/monitor') 4 | 5 | 6 | function startInteractivePriceMonitor() { 7 | const questions = [ 8 | {type: 'list', name: 'pair', message: 'Target Asset Pair', choices: arbitrageActions.pairs}, 9 | {type: 'list', name: 'exchange', message: 'Exchange', choices: arbitrageActions.exchanges}, 10 | {type: 'list', name: 'network', message: 'Target Network', choices: arbitrageActions.networks}, 11 | ]; 12 | 13 | inquirer 14 | .prompt(questions) 15 | .then(function (answers) { 16 | let data = { 17 | pair: answers.pair, 18 | network: answers.network, 19 | exchange: answers.exchange, 20 | }; 21 | 22 | monitor.binance.prices.initPriceMonitor(data); 23 | }); 24 | } 25 | 26 | 27 | 28 | 29 | exports.init = () => { 30 | startInteractivePriceMonitor(); 31 | } -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/prices/actions.js: -------------------------------------------------------------------------------- 1 | const pairs = [ 2 | { 3 | name: 'WBNBBUSDC', 4 | description: 'Wrapped Binance Coin Over Binance Pegged USD Coin', 5 | stableToken: 'BUSDC', 6 | tradingToken: 'WBNB' 7 | }, 8 | { 9 | name: 'WBNBBUSD', 10 | description: 'Wrapped Binance Coin Over Binance Pegged USD', 11 | stableToken: 'BUSD', 12 | tradingToken: 'WBNB' 13 | } 14 | ]; 15 | 16 | const exchanges = [ 17 | { 18 | name: 'Apeswap', 19 | description: 'Apeswap Decentralized Exchange' 20 | }, 21 | { 22 | name: 'Bakeryswap', 23 | description: 'Bakeryswap Decentralized Exchange' 24 | }, 25 | { 26 | name: 'Pancakeswap', 27 | description: 'Pancakeswap Decentralized Exchange' 28 | }, 29 | ]; 30 | 31 | const networks = [ 32 | { 33 | name: 'Mainnet', 34 | description: 'The Main Binance Network' 35 | }, 36 | { 37 | name: 'Local', 38 | description: 'Local Test Network' 39 | } 40 | ] 41 | 42 | exports.pairs = pairs.map(function(pair) { 43 | return { 44 | name: pair.name, 45 | stableToken: pair.stableToken, 46 | tradingToken: pair.tradingToken 47 | }; 48 | }); 49 | 50 | exports.exchanges = exchanges.map(function (exchange) { 51 | return exchange.name; 52 | }); 53 | 54 | exports.networks = networks.map(function (network) { 55 | return network.name; 56 | }) 57 | -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/prices/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer'); 2 | const marketFetcherActions = require("./actions"); 3 | const {fetcher} = require('../../../../../utils/pricefetcher'); 4 | 5 | function startInteractivePriceFetcher() { 6 | const questions = [ 7 | { type: 'list', name: 'exchange', message: 'Choose An Exchange', choices: marketFetcherActions.exchanges }, 8 | { type: 'list', name: 'network', message: 'On What Network', choices: marketFetcherActions.networks }, 9 | { type: 'list', name: 'pair', message: 'Choose A Pair', choices: marketFetcherActions.pairs } 10 | ]; 11 | 12 | inquirer 13 | .prompt(questions) 14 | .then(function (answers) { 15 | switch (answers.exchange){ 16 | case 'Apeswap': 17 | fetcher.binance.fetchApeswapPairPrice(answers.pair); 18 | break; 19 | case 'Bakeryswap': 20 | fetcher.binance.fetchBakeryswapPairPrice(answers.pair); 21 | break; 22 | case 'Pancakeswap': 23 | fetcher.binance.fetchPancakeswapPairPrice(answers.pair); 24 | break; 25 | default: 26 | } 27 | }); 28 | } 29 | 30 | exports.init = () => { 31 | startInteractivePriceFetcher(); 32 | } -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/swap/actions.js: -------------------------------------------------------------------------------- 1 | const tokens = [ 2 | { 3 | name: 'WBNB', 4 | description: 'Wrapped Binance Coin' 5 | }, 6 | { 7 | name: 'BUSD', 8 | description: 'Binance-Pegged US-Dollar' 9 | }, 10 | { 11 | name: 'BUSDC', 12 | description: 'Binance-Pegged US-Dollar Coin' 13 | } 14 | ]; 15 | 16 | const exchanges = [ 17 | { 18 | name: 'Apeswap', 19 | description: 'Apeswap Decentralized Exchange' 20 | }, 21 | { 22 | name: 'Bakeryswap', 23 | description: 'Bakeryswap Decentralized Exchange' 24 | }, 25 | { 26 | name: 'Pancakeswap', 27 | description: 'Pancakeswap Decentralized Exchange' 28 | }, 29 | ]; 30 | 31 | 32 | exports.tokens = tokens.map(function(token) { 33 | return token.name; 34 | }); 35 | 36 | exports.exchanges = exchanges.map(function(exchange) { 37 | return exchange.name; 38 | }); -------------------------------------------------------------------------------- /program/lib/interactive/binance/interactive/swap/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer'); 2 | const colors = require('colors'); 3 | const pad = require('pad'); 4 | const swapActions = require("./actions"); 5 | const {swapper} = require("../../../../../utils/tokenswapper"); 6 | 7 | 8 | function startInteractiveSwap() { 9 | 10 | 11 | const questions = [ 12 | { type: 'input', name: 'swapToken', message: 'What Token Do You Want To Swap? (Contract Address)' }, 13 | { type: 'input', name: 'returnToken', message: 'What Token Do You Want Back? (Contract Address)' }, 14 | { type: 'input', name: 'digits', message: 'Insert the amount of decimals your tokens contain. (Leave blank to default to 18)' }, 15 | { type: 'list', name: 'exchange', message: 'What Exchange Do You Want To Use', choices: swapActions.exchanges }, 16 | {type: 'input', name: 'amount', message: 'How much Do You Want To Swap?'}, 17 | {type: 'input', name: 'slippage', message: 'Desired slippage'}, 18 | ]; 19 | 20 | inquirer 21 | .prompt(questions) 22 | .then(function (answers) { 23 | 24 | let data = { 25 | swapToken: answers.swapToken, 26 | returnToken: answers.returnToken, 27 | exchange: answers.exchange, 28 | amount:answers.amount, 29 | slippage:answers.slippage, 30 | digits: answers.digits 31 | }; 32 | 33 | switch (answers.exchange){ 34 | case 'Apeswap': 35 | swapper.binance.swapOnApeswap(data); 36 | break; 37 | case 'Bakeryswap': 38 | swapper.binance.swapOnBakeryswap(data); 39 | break; 40 | case 'Pancakeswap': 41 | swapper.binance.swapOnPancakeswap(data); 42 | break; 43 | default: 44 | } 45 | }); 46 | } 47 | 48 | exports.init = () => { 49 | startInteractiveSwap(); 50 | } -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/actions.js: -------------------------------------------------------------------------------- 1 | const actions = [ 2 | { 3 | name: 'Commit Arbitrage' 4 | }, 5 | { 6 | name: 'Swap Tokens' 7 | }, 8 | { 9 | name: 'Fetch Exchange Prices' 10 | }, 11 | { 12 | name: 'Monitor Exchange Prices' 13 | } 14 | ]; 15 | exports.actions = actions.map(function (a) { 16 | return a.name; 17 | }); -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require("inquirer"); 2 | const actionChoices = require('./actions'); 3 | 4 | 5 | function runInteractiveArbitrage() { 6 | let interactiveArbitrage = require('./interactive/arbitrage'); 7 | interactiveArbitrage.init(); 8 | } 9 | 10 | function runInteractivePrices() { 11 | let interactivePrices = require('./interactive/prices'); 12 | interactivePrices.init(); 13 | } 14 | 15 | function runInteractiveMonitor() { 16 | let interactiveMonitor = require('./interactive/monitor'); 17 | interactiveMonitor.init(); 18 | } 19 | 20 | function runInteractiveSwap() { 21 | let interactiveSwap = require('./interactive/swap'); 22 | interactiveSwap.init(); 23 | } 24 | 25 | function startInteractiveEthereumProgram() { 26 | 27 | const questions = [ 28 | {type: 'list', name: 'action', message: 'What do you want to do?', choices: actionChoices.actions}, 29 | ]; 30 | 31 | inquirer 32 | .prompt(questions) 33 | .then(function (answers) { 34 | if (answers.action === 'Commit Arbitrage') { 35 | runInteractiveArbitrage(); 36 | } 37 | if (answers.action === 'Fetch Exchange Prices') { 38 | runInteractivePrices(); 39 | } 40 | if (answers.action === 'Monitor Exchange Prices') { 41 | runInteractiveMonitor(); 42 | } 43 | if (answers.action === 'Swap Tokens') { 44 | runInteractiveSwap(); 45 | } 46 | }); 47 | 48 | } 49 | 50 | 51 | exports.init = () => { 52 | startInteractiveEthereumProgram(); 53 | } -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/arbitrage/actions.js: -------------------------------------------------------------------------------- 1 | const pairs = [ 2 | { 3 | name: 'WETHDAI', 4 | description: 'Wrapped Ethereum Version 9 Over Dai StableCoin', 5 | stableToken: 'DAI', 6 | tradingToken: 'WETH' 7 | }, 8 | { 9 | name: 'WETHUSDC', 10 | description: 'Wrapped Ethereum Version 9 Over USD-Coin StableCoin', 11 | stableToken: 'USDC', 12 | tradingToken: 'WETH' 13 | } 14 | ]; 15 | 16 | const exchanges = [ 17 | { 18 | name: 'Uniswap', 19 | description: 'Uniswap Decentralized Exchange' 20 | }, 21 | { 22 | name: 'Kyber', 23 | description: 'Kyber Decentralized Exchange' 24 | }, 25 | { 26 | name: 'Sushiswap', 27 | description: 'Sushiswap Decentralized Exchange' 28 | }, 29 | ]; 30 | 31 | const networks = [ 32 | { 33 | name: 'Mainnet', 34 | description: 'The Ethereum Main Network' 35 | }, 36 | { 37 | name: 'Kovan', 38 | description: 'The Ethereum Kovan Test Network' 39 | }, 40 | { 41 | name: 'Ropsten', 42 | description: 'The Ethereum Ropsten Test Network' 43 | }, 44 | { 45 | name: 'Local', 46 | description: 'Local Test Network' 47 | } 48 | ] 49 | 50 | exports.pairs = pairs.map(function (pair) { 51 | return { 52 | name: pair.name, 53 | stableToken: pair.stableToken, 54 | tradingToken: pair.tradingToken 55 | }; 56 | }); 57 | 58 | exports.exchanges = exchanges.map(function (exchange) { 59 | return exchange.name; 60 | }); 61 | 62 | exports.networks = networks.map(function (network) { 63 | return network.name; 64 | }) -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/arbitrage/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer'); 2 | const arbitrageActions = require('./actions'); 3 | const ArbitrageService = require('../../../../../utils/arbitrage') 4 | 5 | function startInteractiveArbitrage() { 6 | const questions = [ 7 | {type: 'list', name: 'pair', message: 'Target Asset Pair', choices: arbitrageActions.pairs}, 8 | {type: 'list', name: 'buyingExchange', message: 'Exchange You Will Buy From', choices: arbitrageActions.exchanges}, 9 | {type: 'list', name: 'sellingExchange', message: 'Exchange You Will Sell At', choices: arbitrageActions.exchanges}, 10 | {type: 'list', name: 'network', message: 'Target Network', choices: arbitrageActions.networks}, 11 | {type: 'input', name: 'borrowAmount', message: 'Borrow Amount (WETH)'}, 12 | ]; 13 | 14 | inquirer 15 | .prompt(questions) 16 | .then(function (answers) { 17 | let data = { 18 | pair: answers.pair, 19 | network: answers.network, 20 | buyingExchange: answers.buyingExchange, 21 | sellingExchange: answers.sellingExchange, 22 | borrowAmount: answers.borrowAmount, 23 | chain: 'Ethereum' 24 | 25 | }; 26 | ArbitrageService.ethereum.runArbitrage(data); 27 | }); 28 | } 29 | 30 | 31 | exports.init = () => { 32 | startInteractiveArbitrage(); 33 | } -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/monitor/actions.js: -------------------------------------------------------------------------------- 1 | const monitors = [ 2 | { 3 | name: 'Arbitrage' 4 | }, 5 | { 6 | name: 'Prices' 7 | }, 8 | ]; 9 | exports.monitors = monitors.map(function (a) { 10 | return a.name; 11 | }); 12 | -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/monitor/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer'); 2 | const monitorActions = require('./actions'); 3 | 4 | 5 | function runIntersctiveArbitrageMonitorProgram() { 6 | let interactiveArbitrageMonitorProgram = require('./interactive/arbitrage') 7 | return interactiveArbitrageMonitorProgram.init(); 8 | } 9 | 10 | function runInteractivePriceMonitorProgram() { 11 | let interactivePriceMonitorProgram = require('./interactive/price'); 12 | interactivePriceMonitorProgram.init(); 13 | } 14 | 15 | function startInteractiveMonitor() { 16 | const questions = [ 17 | {type: 'list', name: 'monitor', message: 'What Would You Like To Monitor?', choices: monitorActions.monitors}, 18 | 19 | ]; 20 | 21 | inquirer 22 | .prompt(questions) 23 | .then(function (answers) { 24 | switch (answers.monitor) { 25 | case 'Arbitrage': 26 | runIntersctiveArbitrageMonitorProgram(); 27 | break; 28 | case 'Prices': 29 | runInteractivePriceMonitorProgram(); 30 | break; 31 | default: 32 | } 33 | }); 34 | } 35 | 36 | exports.init = () => { 37 | startInteractiveMonitor(); 38 | } -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/monitor/interactive/arbitrage/actions.js: -------------------------------------------------------------------------------- 1 | const pairs = [ 2 | { 3 | name: 'WETHDAI', 4 | description: 'Wrapped Ethereum Version 9 Over Dai StableCoin', 5 | stableToken: 'DAI', 6 | tradingToken: 'WETH' 7 | }, 8 | { 9 | name: 'WETHUSDC', 10 | description: 'Wrapped Ethereum Version 9 Over USD-Coin StableCoin', 11 | stableToken: 'USDC', 12 | tradingToken: 'WETH' 13 | } 14 | ]; 15 | 16 | const exchanges = [ 17 | { 18 | name: 'Uniswap', 19 | description: 'Uniswap Decentralized Exchange' 20 | }, 21 | { 22 | name: 'Kyber', 23 | description: 'Kyber Decentralized Exchange' 24 | }, 25 | { 26 | name: 'Sushiswap', 27 | description: 'Sushiswap Decentralized Exchange' 28 | }, 29 | ]; 30 | 31 | const networks = [ 32 | { 33 | name: 'Mainnet', 34 | description: 'The Ethereum Main Network' 35 | }, 36 | { 37 | name: 'Kovan', 38 | description: 'The Ethereum Kovan Test Network' 39 | }, 40 | { 41 | name: 'Ropsten', 42 | description: 'The Ethereum Ropsten Test Network' 43 | }, 44 | { 45 | name: 'Local', 46 | description: 'Local Test Network' 47 | } 48 | ] 49 | 50 | exports.pairs = pairs.map(function (pair) { 51 | return { 52 | name: pair.name, 53 | stableToken: pair.stableToken, 54 | tradingToken: pair.tradingToken 55 | }; 56 | }); 57 | 58 | exports.exchanges = exchanges.map(function (exchange) { 59 | return exchange.name; 60 | }); 61 | 62 | exports.networks = networks.map(function (network) { 63 | return network.name; 64 | }) -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/monitor/interactive/arbitrage/index.js: -------------------------------------------------------------------------------- 1 | const arbitrageActions = require("./actions"); 2 | const inquirer = require("inquirer"); 3 | const monitor = require('../../../../../../../utils/monitor'); 4 | 5 | 6 | function startInteractiveArbitrageMonitor() { 7 | const questions = [ 8 | {type: 'list', name: 'pair', message: 'Target Asset Pair', choices: arbitrageActions.pairs}, 9 | {type: 'list', name: 'buyingExchange', message: 'Exchange You Will Buy From', choices: arbitrageActions.exchanges}, 10 | {type: 'list', name: 'sellingExchange', message: 'Exchange You Will Sell At', choices: arbitrageActions.exchanges}, 11 | {type: 'list', name: 'network', message: 'Target Network', choices: arbitrageActions.networks}, 12 | {type: 'input', name: 'borrowAmount', message: 'Borrow Amount(WETH)'}, 13 | ]; 14 | 15 | inquirer 16 | .prompt(questions) 17 | .then(function (answers) { 18 | let data = { 19 | pair: answers.pair, 20 | network: answers.network, 21 | buyingExchange: answers.buyingExchange, 22 | sellingExchange: answers.sellingExchange, 23 | borrowAmount: answers.borrowAmount, 24 | chain: 'Ethereum' 25 | 26 | }; 27 | monitor.ethereum.arbitrage.initArbitrageMonitor(data); 28 | }); 29 | } 30 | 31 | 32 | exports.init = () => { 33 | startInteractiveArbitrageMonitor(); 34 | } -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/monitor/interactive/price/actions.js: -------------------------------------------------------------------------------- 1 | const pairs = [ 2 | { 3 | name: 'WETHDAI', 4 | description: 'Wrapped Ethereum Version 9 Over Dai StableCoin', 5 | stableToken: 'DAI', 6 | tradingToken: 'WETH' 7 | }, 8 | { 9 | name: 'WETHUSDC', 10 | description: 'Wrapped Ethereum Version 9 Over USD-Coin StableCoin', 11 | stableToken: 'USDC', 12 | tradingToken: 'WETH' 13 | } 14 | ]; 15 | 16 | const exchanges = [ 17 | { 18 | name: 'Uniswap', 19 | description: 'Uniswap Decentralized Exchange' 20 | }, 21 | { 22 | name: 'Kyber', 23 | description: 'Kyber Decentralized Exchange' 24 | }, 25 | { 26 | name: 'Sushiswap', 27 | description: 'Sushiswap Decentralized Exchange' 28 | }, 29 | ]; 30 | 31 | const networks = [ 32 | { 33 | name: 'Mainnet', 34 | description: 'The Ethereum Main Network' 35 | }, 36 | { 37 | name: 'Kovan', 38 | description: 'The Ethereum Kovan Test Network' 39 | }, 40 | { 41 | name: 'Ropsten', 42 | description: 'The Ethereum Ropsten Test Network' 43 | }, 44 | { 45 | name: 'Local', 46 | description: 'Local Test Network' 47 | } 48 | ]; 49 | 50 | exports.pairs = pairs.map(function (pair) { 51 | return { 52 | name: pair.name, 53 | stableToken: pair.stableToken, 54 | tradingToken: pair.tradingToken 55 | }; 56 | }); 57 | 58 | exports.exchanges = exchanges.map(function (exchange) { 59 | return exchange.name; 60 | }); 61 | 62 | exports.networks = networks.map(function (network) { 63 | return network.name; 64 | }) -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/monitor/interactive/price/index.js: -------------------------------------------------------------------------------- 1 | const arbitrageActions = require("./actions"); 2 | const inquirer = require("inquirer"); 3 | const monitor = require('../../../../../../../utils/monitor') 4 | 5 | 6 | function startInteractivePriceMonitor() { 7 | const questions = [ 8 | {type: 'list', name: 'pair', message: 'Target Asset Pair', choices: arbitrageActions.pairs}, 9 | {type: 'list', name: 'exchange', message: 'Exchange', choices: arbitrageActions.exchanges}, 10 | {type: 'list', name: 'network', message: 'Target Network', choices: arbitrageActions.networks}, 11 | ]; 12 | 13 | inquirer 14 | .prompt(questions) 15 | .then(function (answers) { 16 | let data = { 17 | pair: answers.pair, 18 | network: answers.network, 19 | exchange: answers.exchange, 20 | }; 21 | 22 | monitor.ethereum.prices.initPriceMonitor(data); 23 | }); 24 | } 25 | 26 | 27 | exports.init = () => { 28 | startInteractivePriceMonitor(); 29 | } -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/prices/actions.js: -------------------------------------------------------------------------------- 1 | const pairs = [ 2 | { 3 | name: 'WETHDAI', 4 | description: 'Wrapped Ethereum Version 9 Over Dai StableCoin', 5 | stableToken: 'DAI', 6 | tradingToken: 'WETH' 7 | }, 8 | { 9 | name: 'WETHUSDC', 10 | description: 'Wrapped Ethereum Version 9 Over USD-Coin StableCoin', 11 | stableToken: 'USDC', 12 | tradingToken: 'WETH' 13 | }, 14 | ]; 15 | 16 | const exchanges = [ 17 | { 18 | name: 'Kyber', 19 | description: 'Kyber Decentralized Exchange' 20 | }, 21 | { 22 | name: 'Uniswap', 23 | description: 'Uniswap Decentralized Exchange' 24 | }, 25 | { 26 | name: 'Sushiswap', 27 | description: 'Sushiswap Decentralized Exchange' 28 | }, 29 | ]; 30 | 31 | const networks = [ 32 | { 33 | name: 'Mainnet', 34 | description: 'The Main Ethereum Network' 35 | }, 36 | { 37 | name: 'Kovan', 38 | description: 'The Ethereum Kovan Test Network' 39 | }, 40 | { 41 | name: 'Ropsten', 42 | description: 'The Ethereum Ropsten Test Network' 43 | }, 44 | { 45 | name: 'Local', 46 | description: 'Local Test Network' 47 | } 48 | ] 49 | 50 | exports.pairs = pairs.map(function(pair) { 51 | return { 52 | name: pair.name, 53 | stableToken: pair.stableToken, 54 | tradingToken: pair.tradingToken 55 | }; 56 | }); 57 | 58 | exports.exchanges = exchanges.map(function (exchange) { 59 | return exchange.name; 60 | }); 61 | 62 | exports.networks = networks.map(function (network) { 63 | return network.name; 64 | }) 65 | -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/prices/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer'); 2 | const marketFetcherActions = require("./actions"); 3 | const {fetcher} = require('../../../../../utils/pricefetcher'); 4 | 5 | function startInteractivePriceFetcher() { 6 | const questions = [ 7 | { type: 'list', name: 'exchange', message: 'Choose An Exchange', choices: marketFetcherActions.exchanges }, 8 | { type: 'list', name: 'network', message: 'On What Network', choices: marketFetcherActions.networks }, 9 | { type: 'list', name: 'pair', message: 'Choose A Pair', choices: marketFetcherActions.pairs } 10 | ]; 11 | 12 | inquirer 13 | .prompt(questions) 14 | .then(function (answers) { 15 | switch (answers.exchange){ 16 | case 'Uniswap': 17 | fetcher.ethereum.fetchUniswapPairPrice(answers.exchange, answers.network, answers.pair); 18 | break; 19 | case 'Kyber': 20 | fetcher.ethereum.fetchKyberPairPrice(answers.exchange, answers.network, answers.pair); 21 | break; 22 | case 'Sushiswap': 23 | fetcher.ethereum.fetchSushiswapPairPrice(answers.exchange, answers.network, answers.pair); 24 | break; 25 | default: 26 | } 27 | }); 28 | } 29 | 30 | exports.init = () => { 31 | startInteractivePriceFetcher(); 32 | } -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/swap/actions.js: -------------------------------------------------------------------------------- 1 | const tokens = [ 2 | { 3 | name: 'WETH', 4 | description: 'Wrapped Ethereum Version 9' 5 | }, 6 | { 7 | name: 'DAI', 8 | description: 'Dai Stablecoin' 9 | }, 10 | { 11 | name: 'USDC', 12 | description: 'US-Dollar Stablecoin' 13 | } 14 | ]; 15 | 16 | const exchanges = [ 17 | { 18 | name: 'Kyber', 19 | description: 'Kyber Decentralized Exchange' 20 | }, 21 | { 22 | name: 'Uniswap', 23 | description: 'Uniswap Decentralized Exchange' 24 | }, 25 | { 26 | name: 'Sushiswap', 27 | description: 'Sushiswap Decentralized Exchange' 28 | }, 29 | ]; 30 | 31 | exports.tokens = tokens.map(function(token) { 32 | return { 33 | name: token.name, 34 | }; 35 | }); 36 | 37 | exports.exchanges = exchanges.map(function (exchange) { 38 | return exchange.name; 39 | }); -------------------------------------------------------------------------------- /program/lib/interactive/ethereum/interactive/swap/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer'); 2 | const colors = require('colors'); 3 | const pad = require('pad'); 4 | const swapActions = require("./actions"); 5 | const {swapper} = require("../../../../../utils/tokenswapper"); 6 | 7 | 8 | function startInteractiveSwap() { 9 | 10 | 11 | const questions = [ 12 | { type: 'input', name: 'swapToken', message: 'What Token Do You Want To Swap? (Contract Address)' }, 13 | { type: 'input', name: 'returnToken', message: 'What Token Do You Want Back? (Contract Address)' }, 14 | { type: 'input', name: 'digits', message: 'Insert the amount of decimals your tokens contain. (Leave blank to default to 18)' }, 15 | { type: 'list', name: 'exchange', message: 'What Exchange Do You Want To Use', choices: swapActions.exchanges }, 16 | {type: 'input', name: 'amount', message: 'How much Do You Want To Swap?'}, 17 | {type: 'input', name: 'slippage', message: 'Desired slippage'}, 18 | ]; 19 | 20 | inquirer 21 | .prompt(questions) 22 | .then(function (answers) { 23 | 24 | let data = { 25 | swapToken: answers.swapToken, 26 | returnToken: answers.returnToken, 27 | exchange: answers.exchange, 28 | amount:answers.amount, 29 | slippage:answers.slippage, 30 | digits: answers.digits 31 | }; 32 | 33 | switch (answers.exchange){ 34 | case 'Kyber': 35 | swapper.ethereum.swapOnKyber(data); 36 | break; 37 | case 'Sushiswap': 38 | swapper.ethereum.swapOnSushiswap(data); 39 | break; 40 | case 'Uniswap': 41 | swapper.ethereum.swapOnUniswap(data); 42 | break; 43 | default: 44 | } 45 | }); 46 | } 47 | 48 | exports.init = () => { 49 | startInteractiveSwap(); 50 | } -------------------------------------------------------------------------------- /program/lib/interactive/index.js: -------------------------------------------------------------------------------- 1 | const inquirer = require('inquirer'); 2 | const chainChoices = require('./actions'); 3 | const interactiveEthereumProgram = require('./ethereum'); 4 | // 5 | 6 | function startInteractiveProgram() { 7 | const questions = [ 8 | {type: 'list', name: 'chain', message: 'What Chain Do You Want To Work On', choices: chainChoices.chains}, 9 | ]; 10 | 11 | 12 | inquirer 13 | .prompt(questions) 14 | .then(function (answers) { 15 | if (answers.chain === 'Ethereum') { 16 | interactiveEthereumProgram.init(); 17 | } 18 | 19 | if (answers.chain === 'Binance') { 20 | let interactiveBinanceProgram = require('./binance') 21 | interactiveBinanceProgram.init(); 22 | } 23 | 24 | }); 25 | } 26 | 27 | exports.init = () => { 28 | startInteractiveProgram(); 29 | } -------------------------------------------------------------------------------- /program/utils/addresses/index.js: -------------------------------------------------------------------------------- 1 | const {mainnet} = require("./mainnet"); 2 | const {kovan} = require("./kovan"); 3 | const {ropsten} = require("./ropsten"); 4 | 5 | 6 | module.exports = { 7 | mainnet: mainnet, 8 | kovan: kovan, 9 | ropsten: ropsten, 10 | }; 11 | -------------------------------------------------------------------------------- /program/utils/addresses/kovan/index.js: -------------------------------------------------------------------------------- 1 | const kyberKovan = require('./kyber-kovan.json'); 2 | const uniswapKovan = require('./uniswap-kovan.json'); 3 | const dydxKovan = require('./dydx-kovan.json'); 4 | const tokensKovan = require('./tokens-kovan.json'); 5 | const tokenPairsKovan = require('./token-pairs-kovan.json'); 6 | const sushiswapKovan = require('./suishiswap-kovan.json'); 7 | module.exports = { 8 | kovan: { 9 | kyber: kyberKovan, 10 | uniswap: uniswapKovan, 11 | sushiswap: sushiswapKovan, 12 | dydx: dydxKovan, 13 | tokens: tokensKovan, 14 | tokenPairs: tokenPairsKovan 15 | } 16 | }; -------------------------------------------------------------------------------- /program/utils/addresses/mainnet/index.js: -------------------------------------------------------------------------------- 1 | const kyberMainnet = require('./kyber-mainnet.json'); 2 | const uniswapMainnet = require('./uniswap-mainnet.json'); 3 | const dydxMainnet = require('./dydx-mainnet.json'); 4 | const tokensMainnet = require('./tokens-mainnet.json'); 5 | const tokenPairsMainnet = require('./token-pairs-mainnet.json'); 6 | const suishiswapMainnet = require('./sushiswap-mainnet.json'); 7 | const apeswapMainnet = require('./apeswap-mainnet.json'); 8 | const bakeryswapMainnet = require('./bakeryswap-mainnet.json'); 9 | const pancakeswapMainnet = require('./pancakeswap-mainnet.json'); 10 | 11 | module.exports = { 12 | mainnet: { 13 | kyber: kyberMainnet, 14 | uniswap: uniswapMainnet, 15 | sushiswap: suishiswapMainnet, 16 | dydx: dydxMainnet, 17 | apeswap: apeswapMainnet, 18 | bakeryswap: bakeryswapMainnet, 19 | pancakeswap: pancakeswapMainnet, 20 | tokens: tokensMainnet, 21 | tokenPairs: tokenPairsMainnet 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /program/utils/addresses/ropsten/dydx-ropsten.json: -------------------------------------------------------------------------------- 1 | { 2 | "solo": "" 3 | } 4 | -------------------------------------------------------------------------------- /program/utils/addresses/ropsten/index.js: -------------------------------------------------------------------------------- 1 | const kyberRopsten = require('./kyber-ropsten.json'); 2 | const uniswapRopsten = require('./uniswap-ropsten.json'); 3 | const dydxRopsten = require('./dydx-ropsten.json'); 4 | const tokensRopsten = require('./tokens-ropsten.json'); 5 | const tokenPairsRopsten = require('./token-pairs-ropsten.json'); 6 | const sushiswapRopsten = require('./suishiswap-ropsten.json'); 7 | 8 | module.exports = { 9 | ropsten: { 10 | kyber: kyberRopsten, 11 | uniswap: uniswapRopsten, 12 | sushiswap: sushiswapRopsten, 13 | dydx: dydxRopsten, 14 | tokens: tokensRopsten, 15 | tokenPairs: tokenPairsRopsten, 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /program/utils/arbitrage/ethereum/KySushiArbitrage.js: -------------------------------------------------------------------------------- 1 | //Implement -------------------------------------------------------------------------------- /program/utils/arbitrage/ethereum/SushiKyArbitrage.js: -------------------------------------------------------------------------------- 1 | // Implement -------------------------------------------------------------------------------- /program/utils/arbitrage/ethereum/UniKyArbitrage.js: -------------------------------------------------------------------------------- 1 | // Implement -------------------------------------------------------------------------------- /program/utils/directions/binance/binance-directions.json: -------------------------------------------------------------------------------- 1 | { 2 | "Apeswap": { 3 | "APESWAPBAKERYSWAP": { 4 | "buy": "APESWAP_TO_BAKERYSWAP", 5 | "sell": "BAKERYSWAP_TO_APESWAP" 6 | }, 7 | "APESWAPPANCAKESWAP": { 8 | "buy": "APESWAP_TO_PANCAKESWAP", 9 | "sell": "PANCAKESWAP_TO_APESWAP" 10 | } 11 | }, 12 | 13 | "Bakeryswap": { 14 | "BAKERYSWAPAPESWAP": { 15 | "buy": "BAKERYSWAP_TO_APESWAP", 16 | "sell": "APESWAP_TO_BAKERYSWAP" 17 | }, 18 | "BAKERYSWAPPANCAKESWAP": { 19 | "buy": "BAKERYSWAP_TO_PANCAKESWAP", 20 | "sell": "PANCAKESWAP_TO_BAKERYSWAP" 21 | } 22 | }, 23 | 24 | "Pancakeswap": { 25 | "PANCAKESWAPAPESWAP": { 26 | "buy": "PANCAKESWAP_TO_APESWAP", 27 | "sell": "APESWAP_TO_PANCAKESWAP" 28 | }, 29 | "PANCAKESWAPBAKERYSWAP": { 30 | "buy": "PANCAKESWAP_TO_BAKERYSWAP", 31 | "sell": "BAKERYSWAP_TO_PANCAKESWAP" 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /program/utils/directions/ethereum/ethereum-directions.json: -------------------------------------------------------------------------------- 1 | { 2 | "Kyber" : { 3 | "KYBERUNISWAP": { 4 | "buy": "KYBER_TO_UNISWAP", 5 | "sell": "UNISWAP_TO_KYBER" 6 | }, 7 | "KYBERSUSHISWAP": { 8 | "buy": "KYBER_TO_SUSHISWAP", 9 | "sell": "SUSHISWAP_TO_KYBER" 10 | } 11 | }, 12 | "Uniswap": { 13 | "UNISWAPKYBER": { 14 | "buy": "UNISWAP_TO_KYBER", 15 | "sell": "KYBER_TO_UNISWAP" 16 | }, 17 | "UNISWAPSUSHISWAP": { 18 | "buy": "UNISWAP_TO_SUSHISWAP", 19 | "sell": "SUSHISWAP_TO_UNISWAP" 20 | } 21 | }, 22 | "Sushiswap": { 23 | "SUSHISWAPUNISWAP": { 24 | "buy": "SUSHISWAP_TO_UNISWAP", 25 | "sell": "UNISWAP_TO_SUSHISWAP" 26 | }, 27 | "SUSHISWAPKYBER": { 28 | "buy": "SUSHISWAP_TO_KYBER", 29 | "sell": "KYBER_TO_SUSHISWAP" 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /program/utils/directions/index.js: -------------------------------------------------------------------------------- 1 | const binanceDirections = require('./binance/binance-directions.json'); 2 | const ethereumDirections = require('./ethereum/ethereum-directions.json'); 3 | 4 | module.exports = { 5 | directions: { 6 | ethereum: ethereumDirections, 7 | binance: binanceDirections 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /program/utils/monitor/binance/arbitrage/apeswap/index.js: -------------------------------------------------------------------------------- 1 | const monitoringProcess = require("child_process"); 2 | 3 | function apeBakeryMonitor(data) { 4 | const process = monitoringProcess.fork(__dirname + '/ApeBakeryArbitrageMonitor.js', [], {silent: true}); 5 | process.send(data) 6 | process.stdout.on('data', function (standardOutData) { 7 | console.log(standardOutData.toString()); 8 | }); 9 | 10 | process.stderr.on('data', function (standardErrorData) { 11 | if (standardErrorData.toString().includes('Warning:')) { 12 | } else { 13 | console.log('Error: ' + standardErrorData); 14 | } 15 | }); 16 | 17 | process.on('message', function (response) { 18 | console.log('response:', response) 19 | }); 20 | 21 | process.on('close', function (code, data) { 22 | console.log('Done. Closing ' + code); 23 | }) 24 | } 25 | 26 | function apePancakeMonitor(data) { 27 | const process = monitoringProcess.fork(__dirname + '/ApePancakeArbitrageMonitor.js', [], {silent: true}); 28 | process.send(data) 29 | process.stdout.on('data', function (standardOutData) { 30 | console.log(standardOutData.toString()); 31 | }); 32 | 33 | process.stderr.on('data', function (standardErrorData) { 34 | if (standardErrorData.toString().includes('Warning:')) { 35 | } else { 36 | console.log('Error: ' + standardErrorData); 37 | } 38 | }); 39 | 40 | process.on('message', function (response) { 41 | console.log('response:', response) 42 | }); 43 | 44 | process.on('close', function (code, data) { 45 | console.log('Done. Closing ' + code); 46 | }) 47 | } 48 | 49 | module.exports = { 50 | monitorApeBakeryArbitrage: function(data){ 51 | return apeBakeryMonitor(data); 52 | }, 53 | monitorApePancakeArbitrage: function(data){ 54 | return apePancakeMonitor(data); 55 | } 56 | } -------------------------------------------------------------------------------- /program/utils/monitor/binance/arbitrage/bakeryswap/index.js: -------------------------------------------------------------------------------- 1 | const monitoringProcess = require("child_process"); 2 | 3 | function bakeryPancakeMonitor(data) { 4 | const process = monitoringProcess.fork(__dirname + '/BakeryPancakeArbitrageMonitor.js', [], {silent: true}); 5 | process.send(data) 6 | process.stdout.on('data', function (standardOutData) { 7 | console.log(standardOutData.toString()); 8 | }); 9 | 10 | process.stderr.on('data', function (standardErrorData) { 11 | if (standardErrorData.toString().includes('Warning:')) { 12 | } else { 13 | console.log('Error: ' + standardErrorData); 14 | } 15 | }); 16 | 17 | process.on('message', function (response) { 18 | console.log('response:', response) 19 | }); 20 | 21 | process.on('close', function (code, data) { 22 | console.log('Done. Closing ' + code); 23 | }) 24 | } 25 | 26 | function bakeryApeMonitor(data) { 27 | const process = monitoringProcess.fork(__dirname + '/BakeryApeArbitrageMonitor.js', [], {silent: true}); 28 | process.send(data) 29 | process.stdout.on('data', function (standardOutData) { 30 | console.log(standardOutData.toString()); 31 | }); 32 | 33 | process.stderr.on('data', function (standardErrorData) { 34 | if (standardErrorData.toString().includes('Warning:')) { 35 | } else { 36 | console.log('Error: ' + standardErrorData); 37 | } 38 | }); 39 | 40 | process.on('message', function (response) { 41 | console.log('response:', response) 42 | }); 43 | 44 | process.on('close', function (code, data) { 45 | console.log('Done. Closing ' + code); 46 | }) 47 | } 48 | 49 | module.exports = { 50 | monitorBakeryApeArbitrage: function(data){ 51 | return bakeryApeMonitor(data); 52 | }, 53 | monitorBakeryPancakeArbitrage: function(data){ 54 | return bakeryPancakeMonitor(data); 55 | } 56 | } -------------------------------------------------------------------------------- /program/utils/monitor/binance/arbitrage/pancakeswap/index.js: -------------------------------------------------------------------------------- 1 | const monitoringProcess = require("child_process"); 2 | 3 | function pancakeApeMonitor(data) { 4 | const process = monitoringProcess.fork(__dirname + '/PancakeApeArbitrageMonitor.js', [], {silent: true}); 5 | process.send(data) 6 | process.stdout.on('data', function (standardOutData) { 7 | console.log(standardOutData.toString()); 8 | }); 9 | 10 | process.stderr.on('data', function (standardErrorData) { 11 | if (standardErrorData.toString().includes('Warning:')) { 12 | } else { 13 | console.log('Error: ' + standardErrorData); 14 | } 15 | }); 16 | 17 | process.on('message', function (response) { 18 | console.log('response:', response) 19 | }); 20 | 21 | process.on('close', function (code, data) { 22 | console.log('Done. Closing ' + code); 23 | }) 24 | } 25 | 26 | function pancakeBakeryMonitor(data) { 27 | const process = monitoringProcess.fork(__dirname + '/PancakeBakeryArbitrageMonitor.js', [], {silent: true}); 28 | process.send(data) 29 | process.stdout.on('data', function (standardOutData) { 30 | console.log(standardOutData.toString()); 31 | }); 32 | 33 | process.stderr.on('data', function (standardErrorData) { 34 | if (standardErrorData.toString().includes('Warning:')) { 35 | } else { 36 | console.log('Error: ' + standardErrorData); 37 | } 38 | }); 39 | 40 | process.on('message', function (response) { 41 | console.log('response:', response) 42 | }); 43 | 44 | process.on('close', function (code, data) { 45 | console.log('Done. Closing ' + code); 46 | }) 47 | } 48 | 49 | module.exports = { 50 | monitorPancakeApeArbitrage: function(data){ 51 | return pancakeApeMonitor(data); 52 | }, 53 | monitorPancakeBakeryArbitrage: function(data){ 54 | return pancakeBakeryMonitor(data); 55 | } 56 | } -------------------------------------------------------------------------------- /program/utils/monitor/binance/index.js: -------------------------------------------------------------------------------- 1 | const ApeswapPriceMonitor = require('./prices/apeswap'); 2 | const BakeryswapPriceMonitor = require('./prices/bakeryswap'); 3 | const PancakeswapPriceMonitor = require('./prices/pancakeswap'); 4 | const ApeSwapArbitrageMonitor = require("./arbitrage/apeswap"); 5 | const BakeryswapArbitrageMonitor = require('./arbitrage/bakeryswap'); 6 | const PancakeswapArbitrageMonitor = require('./arbitrage/pancakeswap'); 7 | 8 | 9 | function startArbitrageMonitor(data) { 10 | 11 | if (data.buyingExchange === data.sellingExchange) { 12 | console.log('You cannot commit arbitrage on the same exchange'); 13 | process.exit(1); 14 | } 15 | 16 | switch (data.buyingExchange) { 17 | case 'Apeswap': 18 | if (data.sellingExchange === 'Bakeryswap') { 19 | monitorApeBakeryArbitrage(data); 20 | } 21 | if (data.sellingExchange === 'Pancakeswap') { 22 | monitorApePancakeArbitrage(data); 23 | } 24 | break; 25 | case 'Bakeryswap': 26 | if (data.sellingExchange === 'Apeswap') { 27 | monitorBakeryApeArbitrage(data); 28 | } 29 | if (data.sellingExchange === 'Pancakeswap') { 30 | monitorBakeryPancakeArbitrage(data); 31 | } 32 | break; 33 | case 'Pancakeswap': 34 | if (data.sellingExchange === 'Apeswap') { 35 | monitorPancakeApeArbitrage(data); 36 | } 37 | if (data.sellingExchange === 'Bakeryswap') { 38 | monitorPancakeBakeryArbitrage(data); 39 | } 40 | break; 41 | default: 42 | 43 | } 44 | } 45 | 46 | function startPriceMonitor(data) { 47 | switch (data.exchange) { 48 | case 'Apeswap': 49 | monitorApeswapPairPrices(data); 50 | break; 51 | case 'Bakeryswap': 52 | monitorBakeryswapPairPrices(data); 53 | break; 54 | case 'Pancakeswap': 55 | monitorPancakeswapPairPrices(data); 56 | break; 57 | default: 58 | } 59 | } 60 | 61 | function monitorApeBakeryArbitrage(data) { 62 | return ApeSwapArbitrageMonitor.monitorApeBakeryArbitrage(data); 63 | } 64 | 65 | function monitorApePancakeArbitrage(data) { 66 | return ApeSwapArbitrageMonitor.monitorApePancakeArbitrage(data); 67 | } 68 | 69 | function monitorBakeryApeArbitrage(data) { 70 | return BakeryswapArbitrageMonitor.monitorBakeryApeArbitrage(data) 71 | } 72 | 73 | function monitorBakeryPancakeArbitrage(data) { 74 | return BakeryswapArbitrageMonitor.monitorBakeryPancakeArbitrage(data); 75 | } 76 | 77 | function monitorPancakeApeArbitrage(data) { 78 | return PancakeswapArbitrageMonitor.monitorPancakeApeArbitrage(data); 79 | } 80 | 81 | function monitorPancakeBakeryArbitrage(data) { 82 | return PancakeswapArbitrageMonitor.monitorPancakeBakeryArbitrage(data); 83 | } 84 | 85 | function monitorApeswapPairPrices(data) { 86 | return ApeswapPriceMonitor.monitorPrices(data); 87 | } 88 | 89 | function monitorBakeryswapPairPrices(data) { 90 | return BakeryswapPriceMonitor.monitorPrices(data); 91 | } 92 | 93 | function monitorPancakeswapPairPrices(data) { 94 | return PancakeswapPriceMonitor.monitorPrices(data); 95 | } 96 | 97 | 98 | module.exports = { 99 | arbitrage: { 100 | initArbitrageMonitor: function (data) { 101 | return startArbitrageMonitor(data); 102 | } 103 | }, 104 | prices: { 105 | initPriceMonitor: function (data) { 106 | return startPriceMonitor(data); 107 | }, 108 | }, 109 | } -------------------------------------------------------------------------------- /program/utils/monitor/binance/prices/apeswap/apeswapPriceMonitor.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const pad = require("pad"); 4 | const moment = require("moment"); 5 | const colors = require("colors"); 6 | const BigNumber = require("bignumber.js"); 7 | const { mainnet } = require('../../../../addresses'); 8 | const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MORALIAS_BSC_MAINNET_WSS_URL)); 9 | 10 | const apeswap = { 11 | factory: new web3.eth.Contract(mainnet.apeswap.factory.ABI, mainnet.apeswap.factory.address), 12 | router: new web3.eth.Contract(mainnet.apeswap.router.ABI, mainnet.apeswap.router.address), 13 | } 14 | 15 | const baseAmount = 1; 16 | 17 | process.on('message', function (data) { 18 | if (data === false) { 19 | process.exit(1); 20 | } else { 21 | monitor(data); 22 | } 23 | }); 24 | 25 | async function monitor(data) { 26 | let stableToken = { 27 | name: mainnet.tokenPairs.Binance[data.pair].stableToken.name, 28 | address: mainnet.tokenPairs.Binance[data.pair].stableToken.address, 29 | decimals: mainnet.tokenPairs.Binance[data.pair].stableToken.decimals, 30 | } 31 | 32 | let tradingToken = { 33 | name: mainnet.tokenPairs.Binance[data.pair].tradingToken.name, 34 | address: mainnet.tokenPairs.Binance[data.pair].tradingToken.address, 35 | decimals: mainnet.tokenPairs.Binance[data.pair].tradingToken.decimals, 36 | } 37 | 38 | 39 | console.log(`Monitoring Ape Swap Prices...`) 40 | web3.eth.subscribe('newBlockHeaders', (error, result) => { 41 | if (!error) { 42 | return; 43 | } 44 | console.error(error); 45 | }) 46 | .on("Connected To Binance SmartChain", subscriptionId => { 47 | console.log(`You are connected on ${subscriptionId}`); 48 | }) 49 | .on('data', async block => { 50 | console.log('-------------------------------------------------------------'); 51 | const exchangeAmount = await new BigNumber(baseAmount); 52 | const shiftedExchangeAmount = await new BigNumber(exchangeAmount).shiftedBy(tradingToken.decimals); 53 | let tokenIn = tradingToken.address 54 | let tokenOut = stableToken.address; 55 | const rawValue = await apeswap.router.methods.getAmountsOut(shiftedExchangeAmount, [tokenIn, tokenOut]).call(); 56 | const shiftedValue = await new BigNumber(rawValue[1]).shiftedBy(-stableToken.decimals); 57 | 58 | 59 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), moment().format('ll')+' '+moment().format('LTS')); 60 | console.log( 61 | pad(colors.red('Token In:'), 30), tradingToken.name, 62 | pad(colors.red('Value: '), 30), exchangeAmount.toString()); 63 | console.log( 64 | pad(colors.green('Token Out: '), 30), stableToken.name, 65 | pad(colors.green('Value Out: '), 30), shiftedValue.toString()); 66 | }) 67 | .on('error', error => { 68 | console.log(error); 69 | }); 70 | } -------------------------------------------------------------------------------- /program/utils/monitor/binance/prices/apeswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | 3 | async function monitor(data) { 4 | const process = fetchProcess.fork(__dirname+'/apeswapPriceMonitor.js', [], {silent: true}); 5 | process.send(data) 6 | process.stdout.on('data', function(standardOutData) { 7 | console.log(standardOutData.toString()); 8 | }); 9 | 10 | process.stderr.on('data', function(standardErrorData) { 11 | if(standardErrorData.toString().includes('Warning:')) { 12 | } else { 13 | console.log('Error: ' + standardErrorData ); 14 | } 15 | }); 16 | 17 | process.on('close', function(code, data) { 18 | console.log('Done. Closing ' + code); 19 | }); 20 | } 21 | 22 | 23 | module.exports = { 24 | monitorPrices: function(data) { 25 | return monitor(data); 26 | } 27 | } -------------------------------------------------------------------------------- /program/utils/monitor/binance/prices/bakeryswap/bakeryswapPriceMonitor.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const pad = require("pad"); 4 | const moment = require("moment"); 5 | const colors = require("colors"); 6 | const BigNumber = require("bignumber.js"); 7 | const { mainnet } = require('../../../../addresses'); 8 | const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MORALIAS_BSC_MAINNET_WSS_URL)); 9 | 10 | const bakeryswap = { 11 | factory: new web3.eth.Contract(mainnet.bakeryswap.factory.ABI, mainnet.bakeryswap.factory.address), 12 | router: new web3.eth.Contract(mainnet.bakeryswap.router.ABI, mainnet.bakeryswap.router.address), 13 | } 14 | 15 | const baseAmount = 1; 16 | 17 | process.on('message', function (data) { 18 | if (data === false) { 19 | process.exit(1); 20 | } else { 21 | monitor(data); 22 | } 23 | }); 24 | 25 | async function monitor(data) { 26 | let stableToken = { 27 | name: mainnet.tokenPairs.Binance[data.pair].stableToken.name, 28 | address: mainnet.tokenPairs.Binance[data.pair].stableToken.address, 29 | decimals: mainnet.tokenPairs.Binance[data.pair].stableToken.decimals, 30 | } 31 | 32 | let tradingToken = { 33 | name: mainnet.tokenPairs.Binance[data.pair].tradingToken.name, 34 | address: mainnet.tokenPairs.Binance[data.pair].tradingToken.address, 35 | decimals: mainnet.tokenPairs.Binance[data.pair].tradingToken.decimals, 36 | } 37 | 38 | 39 | console.log(`Monitoring Bakery Swap Prices...`) 40 | web3.eth.subscribe('newBlockHeaders', (error, result) => { 41 | if (!error) { 42 | return; 43 | } 44 | console.error(error); 45 | }) 46 | .on("Connected To Binance SmartChain", subscriptionId => { 47 | console.log(`You are connected on ${subscriptionId}`); 48 | }) 49 | .on('data', async block => { 50 | console.log('-------------------------------------------------------------'); 51 | const exchangeAmount = await new BigNumber(baseAmount); 52 | const shiftedExchangeAmount = await new BigNumber(exchangeAmount).shiftedBy(tradingToken.decimals); 53 | let tokenIn = tradingToken.address 54 | let tokenOut = stableToken.address; 55 | const rawValue = await bakeryswap.router.methods.getAmountsOut(shiftedExchangeAmount, [tokenIn, tokenOut]).call(); 56 | const shiftedValue = await new BigNumber(rawValue[1]).shiftedBy(-stableToken.decimals); 57 | 58 | 59 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), moment().format('ll')+' '+moment().format('LTS')); 60 | console.log( 61 | pad(colors.red('Token In:'), 30), tradingToken.name, 62 | pad(colors.red('Value: '), 30), exchangeAmount.toString()); 63 | console.log( 64 | pad(colors.green('Token Out: '), 30), stableToken.name, 65 | pad(colors.green('Value Out: '), 30), shiftedValue.toString()); 66 | }) 67 | .on('error', error => { 68 | console.log(error); 69 | }); 70 | } -------------------------------------------------------------------------------- /program/utils/monitor/binance/prices/bakeryswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | 3 | async function monitor(data) { 4 | const process = fetchProcess.fork(__dirname+'/bakeryswapPriceMonitor.js', [], {silent: true}); 5 | process.send(data) 6 | process.stdout.on('data', function(standardOutData) { 7 | console.log(standardOutData.toString()); 8 | }); 9 | 10 | process.stderr.on('data', function(standardErrorData) { 11 | if(standardErrorData.toString().includes('Warning:')) { 12 | } else { 13 | console.log('Error: ' + standardErrorData ); 14 | } 15 | }); 16 | 17 | process.on('close', function(code, data) { 18 | console.log('Done. Closing ' + code); 19 | }); 20 | } 21 | 22 | 23 | module.exports = { 24 | monitorPrices: function(data) { 25 | return monitor(data); 26 | } 27 | } -------------------------------------------------------------------------------- /program/utils/monitor/binance/prices/pancakeswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | 3 | async function monitor(data) { 4 | const process = fetchProcess.fork(__dirname+'/pancakeswapPriceMonitor.js', [], {silent: true}); 5 | process.send(data) 6 | process.stdout.on('data', function(standardOutData) { 7 | console.log(standardOutData.toString()); 8 | }); 9 | 10 | process.stderr.on('data', function(standardErrorData) { 11 | if(standardErrorData.toString().includes('Warning:')) { 12 | } else { 13 | console.log('Error: ' + standardErrorData ); 14 | } 15 | }); 16 | 17 | process.on('close', function(code, data) { 18 | console.log('Done. Closing ' + code); 19 | }); 20 | } 21 | 22 | 23 | module.exports = { 24 | monitorPrices: function(data) { 25 | return monitor(data); 26 | } 27 | } -------------------------------------------------------------------------------- /program/utils/monitor/binance/prices/pancakeswap/pancakeswapPriceMonitor.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const pad = require("pad"); 4 | const moment = require("moment"); 5 | const colors = require("colors"); 6 | const BigNumber = require("bignumber.js"); 7 | const { mainnet } = require('../../../../addresses'); 8 | const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MORALIAS_BSC_MAINNET_WSS_URL)); 9 | 10 | const pancakeswap = { 11 | factory: new web3.eth.Contract(mainnet.pancakeswap.factory.ABI, mainnet.pancakeswap.factory.address), 12 | router: new web3.eth.Contract(mainnet.pancakeswap.router.ABI, mainnet.pancakeswap.router.address), 13 | } 14 | 15 | const baseAmount = 1; 16 | 17 | process.on('message', function (data) { 18 | if (data === false) { 19 | process.exit(1); 20 | } else { 21 | monitor(data); 22 | } 23 | }); 24 | 25 | async function monitor(data) { 26 | let stableToken = { 27 | name: mainnet.tokenPairs.Binance[data.pair].stableToken.name, 28 | address: mainnet.tokenPairs.Binance[data.pair].stableToken.address, 29 | decimals: mainnet.tokenPairs.Binance[data.pair].stableToken.decimals, 30 | } 31 | 32 | let tradingToken = { 33 | name: mainnet.tokenPairs.Binance[data.pair].tradingToken.name, 34 | address: mainnet.tokenPairs.Binance[data.pair].tradingToken.address, 35 | decimals: mainnet.tokenPairs.Binance[data.pair].tradingToken.decimals, 36 | } 37 | 38 | 39 | console.log(`Monitoring Pancake Swap Prices...`) 40 | web3.eth.subscribe('newBlockHeaders', (error, result) => { 41 | if (!error) { 42 | return; 43 | } 44 | console.error(error); 45 | }) 46 | .on("Connected To Binance SmartChain", subscriptionId => { 47 | console.log(`You are connected on ${subscriptionId}`); 48 | }) 49 | .on('data', async block => { 50 | console.log('-------------------------------------------------------------'); 51 | const exchangeAmount = await new BigNumber(baseAmount); 52 | const shiftedExchangeAmount = await new BigNumber(exchangeAmount).shiftedBy(tradingToken.decimals); 53 | let tokenIn = tradingToken.address 54 | let tokenOut = stableToken.address; 55 | const rawValue = await pancakeswap.router.methods.getAmountsOut(shiftedExchangeAmount, [tokenIn, tokenOut]).call(); 56 | const shiftedValue = await new BigNumber(rawValue[1]).shiftedBy(-stableToken.decimals); 57 | 58 | 59 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), moment().format('ll')+' '+moment().format('LTS')); 60 | console.log( 61 | pad(colors.red('Token In:'), 30), tradingToken.name, 62 | pad(colors.red('Value: '), 30), exchangeAmount.toString()); 63 | console.log( 64 | pad(colors.green('Token Out: '), 30), stableToken.name, 65 | pad(colors.green('Value Out: '), 30), shiftedValue.toString()); 66 | }) 67 | .on('error', error => { 68 | console.log(error); 69 | }); 70 | } -------------------------------------------------------------------------------- /program/utils/monitor/ethereum/arbitrage/kyber/index.js: -------------------------------------------------------------------------------- 1 | const monitoringProcess = require("child_process"); 2 | 3 | function kyUniMonitor(data) { 4 | const process = monitoringProcess.fork(__dirname + '/KyUniArbitrageMonitor.js', [], {silent: true}); 5 | process.send(data) 6 | process.stdout.on('data', function (standardOutData) { 7 | console.log(standardOutData.toString()); 8 | }); 9 | 10 | process.stderr.on('data', function (standardErrorData) { 11 | if (standardErrorData.toString().includes('Warning:')) { 12 | } else { 13 | console.log('Error: ' + standardErrorData); 14 | } 15 | }); 16 | 17 | process.on('message', function (response) { 18 | console.log('response:', response) 19 | //process.send(data = false); 20 | }); 21 | 22 | process.on('close', function (code, data) { 23 | console.log('Done. Closing ' + code); 24 | }); 25 | } 26 | 27 | function kySushiMonitor(data) { 28 | const process = monitoringProcess.fork(__dirname + '/KySushiArbitrageMonitor.js', [], {silent: true}); 29 | process.send(data) 30 | process.stdout.on('data', function (standardOutData) { 31 | console.log(standardOutData.toString()); 32 | }); 33 | 34 | process.stderr.on('data', function (standardErrorData) { 35 | if (standardErrorData.toString().includes('Warning:')) { 36 | } else { 37 | console.log('Error: ' + standardErrorData); 38 | } 39 | }); 40 | 41 | process.on('message', function (response) { 42 | console.log('response:', response) 43 | //process.send(data = false); 44 | }); 45 | 46 | process.on('close', function (code, data) { 47 | console.log('Done. Closing ' + code); 48 | }); 49 | } 50 | 51 | module.exports = { 52 | monitorKySushiArbitrage: function(data){ 53 | return kySushiMonitor(data); 54 | }, 55 | monitorKyUniArbitrage: function(data){ 56 | return kyUniMonitor(data); 57 | } 58 | } -------------------------------------------------------------------------------- /program/utils/monitor/ethereum/arbitrage/sushiswap/index.js: -------------------------------------------------------------------------------- 1 | const monitoringProcess = require("child_process"); 2 | 3 | 4 | function sushiUniMonitor(data) { 5 | const process = monitoringProcess.fork(__dirname + '/SushiUniArbitrageMonitor.js', [], {silent: true}); 6 | process.send(data) 7 | process.stdout.on('data', function (standardOutData) { 8 | console.log(standardOutData.toString()); 9 | }); 10 | 11 | process.stderr.on('data', function (standardErrorData) { 12 | if (standardErrorData.toString().includes('Warning:')) { 13 | } else { 14 | console.log('Error: ' + standardErrorData); 15 | } 16 | }); 17 | 18 | process.on('message', function (response) { 19 | console.log('response:', response) 20 | //process.send(data = false); 21 | }); 22 | 23 | process.on('close', function (code, data) { 24 | console.log('Done. Closing ' + code); 25 | }); 26 | } 27 | 28 | function sushiKyMonitor(data) { 29 | const process = monitoringProcess.fork(__dirname + '/SushiKyArbitrageMonitor.js', [], {silent: true}); 30 | process.send(data) 31 | process.stdout.on('data', function (standardOutData) { 32 | console.log(standardOutData.toString()); 33 | }); 34 | 35 | process.stderr.on('data', function (standardErrorData) { 36 | if (standardErrorData.toString().includes('Warning:')) { 37 | } else { 38 | console.log('Error: ' + standardErrorData); 39 | } 40 | }); 41 | 42 | process.on('message', function (response) { 43 | console.log('response:', response) 44 | //process.send(data = false); 45 | }); 46 | 47 | process.on('close', function (code, data) { 48 | console.log('Done. Closing ' + code); 49 | }); 50 | } 51 | 52 | module.exports = { 53 | monitorSushiKyArbitrage: function(data){ 54 | return sushiKyMonitor(data); 55 | }, 56 | monitorSushiUniArbitrage: function(data){ 57 | return sushiUniMonitor(data); 58 | } 59 | } -------------------------------------------------------------------------------- /program/utils/monitor/ethereum/arbitrage/uniswap/index.js: -------------------------------------------------------------------------------- 1 | const monitoringProcess = require("child_process"); 2 | 3 | function uniKyMonitor(data) { 4 | const process = monitoringProcess.fork(__dirname + '/UniKyArbitrageMonitor.js', [], {silent: true}); 5 | process.send(data) 6 | process.stdout.on('data', function (standardOutData) { 7 | console.log(standardOutData.toString()); 8 | }); 9 | 10 | process.stderr.on('data', function (standardErrorData) { 11 | if (standardErrorData.toString().includes('Warning:')) { 12 | } else { 13 | console.log('Error: ' + standardErrorData); 14 | } 15 | }); 16 | 17 | process.on('message', function (response) { 18 | console.log('response:', response) 19 | //process.send(data = false); 20 | }); 21 | 22 | process.on('close', function (code, data) { 23 | console.log('Done. Closing ' + code); 24 | }); 25 | } 26 | 27 | function uniSushiMonitor(data) { 28 | const process = monitoringProcess.fork(__dirname + '/UniSushiArbitrageMonitor.js', [], {silent: true}); 29 | process.send(data) 30 | process.stdout.on('data', function (standardOutData) { 31 | console.log(standardOutData.toString()); 32 | }); 33 | 34 | process.stderr.on('data', function (standardErrorData) { 35 | if (standardErrorData.toString().includes('Warning:')) { 36 | } else { 37 | console.log('Error: ' + standardErrorData); 38 | } 39 | }); 40 | 41 | process.on('message', function (response) { 42 | console.log('response:', response) 43 | //process.send(data = false); 44 | }); 45 | 46 | process.on('close', function (code, data) { 47 | console.log('Done. Closing ' + code); 48 | }); 49 | } 50 | 51 | module.exports = { 52 | monitorUniKyArbitrage: function (data) { 53 | return uniKyMonitor(data); 54 | }, 55 | monitorUniSushiArbitrage: function (data) { 56 | return uniSushiMonitor(data); 57 | } 58 | } -------------------------------------------------------------------------------- /program/utils/monitor/ethereum/index.js: -------------------------------------------------------------------------------- 1 | const KyberPriceMonitor = require('./prices/kyber'); 2 | const KyUniArbitrageMonitor = require('./arbitrage/kyber/'); 3 | const KySushiArbitrageMonitor = require('./arbitrage/kyber/'); 4 | const UniKyArbitrageMonitor = require('./arbitrage/uniswap/'); 5 | const UniSushiArbitrageMonitor = require('./arbitrage/uniswap/'); 6 | const UniswapPriceMonitor = require('./prices/uniswap'); 7 | const SushiKyArbitrageMonitor = require('./arbitrage/sushiswap/'); 8 | const SushiUniArbitrageMonitor = require('./arbitrage/sushiswap/'); 9 | const SushiswapPriceMonitor = require('./prices/sushiswap'); 10 | 11 | function startArbitrageMonitor(data) { 12 | 13 | if (data.buyingExchange === data.sellingExchange) { 14 | console.log('You cannot commit arbitrage on the same exchange'); 15 | process.exit(1); 16 | } 17 | 18 | switch (data.buyingExchange) { 19 | case 'Kyber': 20 | if (data.sellingExchange === 'Sushiswap') { 21 | monitorKySushiArbitrage(data); 22 | } 23 | if (data.sellingExchange === 'Uniswap') { 24 | monitorKyUniArbitrage(data); 25 | } 26 | break; 27 | case 'Sushiswap': 28 | if (data.sellingExchange === 'Kyber') { 29 | monitorSushiKyArbitrage(data); 30 | } 31 | if (data.sellingExchange === 'Uniswap') { 32 | monitorSushiUniArbitrage(data); 33 | } 34 | break; 35 | case 'Uniswap': 36 | if (data.sellingExchange === 'Kyber') { 37 | monitorUniKyArbitrage(data); 38 | } 39 | if (data.sellingExchange === 'Sushiswap') { 40 | monitorUniSushiArbitrage(data); 41 | } 42 | break; 43 | default: 44 | 45 | } 46 | } 47 | 48 | function startPriceMonitor(data) { 49 | switch (data.exchange) { 50 | case 'Kyber': 51 | monitorKyberPairPrices(data); 52 | break; 53 | case 'Sushiswap': 54 | monitorSushiswapPairPrices(data); 55 | break; 56 | case 'Uniswap': 57 | monitorUniswapPairPrices(data); 58 | break; 59 | default: 60 | } 61 | } 62 | 63 | function monitorKyUniArbitrage(data) { 64 | return KyUniArbitrageMonitor.monitorKyUniArbitrage(data); 65 | } 66 | 67 | function monitorKySushiArbitrage(data) { 68 | return KySushiArbitrageMonitor.monitorKySushiArbitrage(data) 69 | } 70 | 71 | function monitorUniKyArbitrage(data) { 72 | return UniKyArbitrageMonitor.monitorUniKyArbitrage(data) 73 | } 74 | 75 | function monitorSushiUniArbitrage(data) { 76 | return SushiUniArbitrageMonitor.monitorSushiUniArbitrage(data); 77 | } 78 | 79 | function monitorSushiKyArbitrage(data) { 80 | return SushiKyArbitrageMonitor.monitorSushiKyArbitrage(data); 81 | } 82 | 83 | function monitorUniSushiArbitrage(data) { 84 | return UniSushiArbitrageMonitor.monitorUniSushiArbitrage(data); 85 | } 86 | 87 | function monitorKyberPairPrices(data) { 88 | return KyberPriceMonitor.monitorPrices(data); 89 | } 90 | 91 | function monitorSushiswapPairPrices(data) { 92 | return SushiswapPriceMonitor.monitorPrices(data); 93 | } 94 | 95 | function monitorUniswapPairPrices(data) { 96 | return UniswapPriceMonitor.monitorPrices(data); 97 | } 98 | 99 | 100 | module.exports = { 101 | arbitrage: { 102 | initArbitrageMonitor: function (data) { 103 | return startArbitrageMonitor(data); 104 | } 105 | }, 106 | prices: { 107 | initPriceMonitor: function (data) { 108 | return startPriceMonitor(data); 109 | }, 110 | }, 111 | } -------------------------------------------------------------------------------- /program/utils/monitor/ethereum/prices/kyber/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | 3 | async function monitor(data) { 4 | 5 | const process = fetchProcess.fork(__dirname + '/kyberPriceMonitor.js', [], {silent: true}); 6 | process.send(data) 7 | process.stdout.on('data', function (standardOutData) { 8 | console.log(standardOutData.toString()); 9 | }); 10 | 11 | process.stderr.on('data', function (standardErrorData) { 12 | if (standardErrorData.toString().includes('Warning:')) { 13 | } else { 14 | console.log('Error: ' + standardErrorData); 15 | } 16 | }); 17 | 18 | 19 | process.on('close', function (code, data) { 20 | console.log('Done. Closing ' + code); 21 | }); 22 | } 23 | 24 | module.exports = { 25 | monitorPrices: function (data) { 26 | return monitor(data); 27 | } 28 | } -------------------------------------------------------------------------------- /program/utils/monitor/ethereum/prices/sushiswap/index.js: -------------------------------------------------------------------------------- 1 | 2 | const fetchProcess = require('child_process'); 3 | 4 | async function monitor(data) { 5 | const process = fetchProcess.fork(__dirname + '/sushiswapPriceMonitor.js', [], {silent: true}); 6 | process.send(data) 7 | process.stdout.on('data', function (standardOutData) { 8 | console.log(standardOutData.toString()); 9 | }); 10 | 11 | process.stderr.on('data', function (standardErrorData) { 12 | if (standardErrorData.toString().includes('Warning:')) { 13 | } else { 14 | console.log('Error: ' + standardErrorData); 15 | } 16 | }); 17 | 18 | process.on('close', function (code, data) { 19 | console.log('Done. Closing ' + code); 20 | }); 21 | } 22 | 23 | module.exports = { 24 | monitorPrices: function (data) { 25 | return monitor(data); 26 | } 27 | } -------------------------------------------------------------------------------- /program/utils/monitor/ethereum/prices/sushiswap/sushiswapPriceMonitor.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const pad = require("pad"); 4 | const colors = require("colors"); 5 | const ONE_WEI = Web3.utils.toBN(Web3.utils.toWei('1')); 6 | const {mainnet, ropsten, kovan} = require('../../../../addresses'); 7 | const moment = require("moment"); 8 | 9 | 10 | process.on('message', function (data) { 11 | if (data === false) { 12 | process.exit(1); 13 | } else { 14 | monitor(data); 15 | } 16 | }); 17 | 18 | 19 | async function monitor(data) { 20 | let stableToken, tradingToken, sushi, web3; 21 | console.log(`Monitoring Sushiswap Prices For Pair: ${data.pair}...`) 22 | switch (data.network) { 23 | case 'Mainnet': 24 | web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MAINNET_INFURA_WSS_URL)); 25 | stableToken = mainnet.tokenPairs.Ethereum[data.pair].stableToken; 26 | tradingToken = mainnet.tokenPairs.Ethereum[data.pair].tradingToken; 27 | sushi = new web3.eth.Contract(mainnet.sushiswap.router.ABI, mainnet.sushiswap.router.address); 28 | break; 29 | case 'Ropsten': 30 | web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.ROPSTEN_INFURA_WSS_URL)); 31 | stableToken = ropsten.tokenPairs[data.pair].stableToken; 32 | tradingToken = ropsten.tokenPairs[data.pair].tradingToken; 33 | sushi = new web3.eth.Contract(ropsten.sushiswap.router.ABI, ropsten.sushiswap.router.address); 34 | break; 35 | case 'Kovan': 36 | web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.KOVAN_INFURA_WSS_URL)); 37 | stableToken = kovan.tokenPairs[data.pair].stableToken; 38 | tradingToken = kovan.tokenPairs[data.pair].tradingToken; 39 | sushi = new web3.eth.Contract(kovan.sushiswap.router.ABI, kovan.sushiswap.router.address); 40 | break; 41 | case 'Local': 42 | web3 = new Web3(new Web3.providers.WebsocketProvider("https://127.0.0.1:8545")); 43 | stableToken = mainnet.tokenPairs.Ethereum[data.pair].stableToken; 44 | tradingToken = mainnet.tokenPairs.Ethereum[data.pair].tradingToken; 45 | sushi = new web3.eth.Contract(mainnet.sushiswap.router.ABI, mainnet.sushiswap.router.address); 46 | break; 47 | } 48 | let sushiswapEthSellPrice, sushiswapEthBuyPrice; 49 | const updateEthPrice = async () => { 50 | const sushiswapBuyPrice = await sushi.methods.getAmountsOut(web3.utils.toWei('1'), [tradingToken.address, stableToken.address]).call(); 51 | const sushiswapSellPrice = await sushi.methods.getAmountsOut(web3.utils.toWei('1'), [stableToken.address, tradingToken.address]).call(); 52 | 53 | sushiswapEthBuyPrice = web3.utils.toBN('1').mul(web3.utils.toBN(sushiswapBuyPrice[1])).div(ONE_WEI); 54 | sushiswapEthSellPrice = web3.utils.toBN('1').mul(web3.utils.toBN(sushiswapSellPrice[1])).div(ONE_WEI); 55 | 56 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), moment().format('ll') + ' ' + moment().format('LTS')); 57 | console.log(pad(colors.red('Sushiswap Buy Price:'), 30), sushiswapEthBuyPrice.toString()); 58 | console.log(pad(colors.green('Sushiswap Sell Price:'), 30), sushiswapEthSellPrice.toString()) 59 | } 60 | 61 | setInterval(updateEthPrice, 5000); 62 | } -------------------------------------------------------------------------------- /program/utils/monitor/ethereum/prices/uniswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | 3 | 4 | async function monitor(data) { 5 | const process = fetchProcess.fork(__dirname + '/uniswapPriceMonitor.js', [], {silent: true}); 6 | process.send(data) 7 | process.stdout.on('data', function (standardOutData) { 8 | console.log(standardOutData.toString()); 9 | }); 10 | 11 | process.stderr.on('data', function (standardErrorData) { 12 | if (standardErrorData.toString().includes('Warning:')) { 13 | } else { 14 | console.log('Error: ' + standardErrorData); 15 | } 16 | }); 17 | 18 | process.on('close', function (code, data) { 19 | console.log('Done. Closing ' + code); 20 | }); 21 | } 22 | 23 | module.exports = { 24 | monitorPrices: function (data) { 25 | return monitor(data); 26 | } 27 | } -------------------------------------------------------------------------------- /program/utils/monitor/index.js: -------------------------------------------------------------------------------- 1 | const binanceMonitor = require('./binance'); 2 | const ethereumMonitor = require('./ethereum'); 3 | 4 | 5 | 6 | module.exports = { 7 | binance: binanceMonitor, 8 | ethereum: ethereumMonitor 9 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/binance/apeswap/apeswapPriceFetcher.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const BigNumber = require("bignumber.js"); 4 | const {mainnet} = require('../../../addresses'); 5 | const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MORALIAS_BSC_MAINNET_WSS_URL)); 6 | 7 | const apeswap = { 8 | factory: new web3.eth.Contract(mainnet.apeswap.factory.ABI, mainnet.apeswap.factory.address), 9 | router: new web3.eth.Contract(mainnet.apeswap.router.ABI, mainnet.apeswap.router.address), 10 | } 11 | 12 | const baseAmount = 1; 13 | 14 | process.on('message', function (data) { 15 | if (data === false) { 16 | process.exit(1); 17 | } else { 18 | fetchData(data); 19 | } 20 | }); 21 | 22 | async function fetchData(data) { 23 | let stableToken = { 24 | name: mainnet.tokenPairs.Binance[data.pair].stableToken.name, 25 | address: mainnet.tokenPairs.Binance[data.pair].stableToken.address, 26 | decimals: mainnet.tokenPairs.Binance[data.pair].stableToken.decimals, 27 | } 28 | 29 | let tradingToken = { 30 | name: mainnet.tokenPairs.Binance[data.pair].tradingToken.name, 31 | address: mainnet.tokenPairs.Binance[data.pair].tradingToken.address, 32 | decimals: mainnet.tokenPairs.Binance[data.pair].tradingToken.decimals, 33 | } 34 | 35 | 36 | console.log(`Fetching Ape Swap Prices...`) 37 | web3.eth.subscribe('newBlockHeaders', (error, result) => { 38 | if (!error) { 39 | return; 40 | } 41 | console.error(error); 42 | }) 43 | .on("Connected To Binance SmartChain", subscriptionId => { 44 | console.log(`You are connected on ${subscriptionId}`); 45 | }) 46 | .on('data', async block => { 47 | console.log('-------------------------------------------------------------'); 48 | const exchangeAmount = await new BigNumber(baseAmount); 49 | const shiftedExchangeAmount = await new BigNumber(exchangeAmount).shiftedBy(tradingToken.decimals); 50 | let tokenIn = tradingToken.address 51 | let tokenOut = stableToken.address; 52 | const rawValue = await apeswap.router.methods.getAmountsOut(shiftedExchangeAmount, [tokenIn, tokenOut]).call(); 53 | const shiftedValue = await new BigNumber(rawValue[1]).shiftedBy(-stableToken.decimals); 54 | 55 | process.send({ 56 | tokenIn: { 57 | name: tradingToken.name, 58 | value: exchangeAmount.toString(), 59 | }, 60 | tokenOut: { 61 | name: stableToken.name, 62 | value: shiftedValue.toString() 63 | } 64 | }); 65 | 66 | }) 67 | .on('error', error => { 68 | console.log(error); 69 | }); 70 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/binance/apeswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | const pad = require("pad"); 3 | const colors = require("colors"); 4 | const moment = require("moment"); 5 | 6 | async function fetchData(data) { 7 | const process = fetchProcess.fork(__dirname + '/apeswapPriceFetcher.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | 22 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), 23 | moment().format('ll') + '' + moment().format('LTS')); 24 | 25 | console.log( 26 | pad(colors.red('Token In:'), 30), response.tokenIn.name, 27 | pad(colors.red('Value: '), 30), response.tokenIn.value); 28 | console.log( 29 | pad(colors.green('Token Out: '), 30), response.tokenOut.name, 30 | pad(colors.green('Value Out: '), 30), response.tokenOut.value); 31 | 32 | 33 | process.send(data = false); 34 | }); 35 | 36 | process.on('close', function (code, data) { 37 | console.log('Done. Closing ' + code); 38 | }); 39 | } 40 | 41 | module.exports = { 42 | getAssetInfo: function (data) { 43 | return fetchData(data); 44 | } 45 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/binance/bakeryswap/bakeryswapPriceFetcher.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const BigNumber = require("bignumber.js"); 4 | const {mainnet} = require('../../../addresses'); 5 | const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MORALIAS_BSC_MAINNET_WSS_URL)); 6 | 7 | const bakeryswap = { 8 | factory: new web3.eth.Contract(mainnet.bakeryswap.factory.ABI, mainnet.bakeryswap.factory.address), 9 | router: new web3.eth.Contract(mainnet.bakeryswap.router.ABI, mainnet.bakeryswap.router.address), 10 | } 11 | 12 | const baseAmount = 1; 13 | 14 | process.on('message', function (data) { 15 | if (data === false) { 16 | process.exit(1); 17 | } else { 18 | fetchData(data); 19 | } 20 | }); 21 | 22 | async function fetchData(data) { 23 | let stableToken = { 24 | name: mainnet.tokenPairs.Binance[data.pair].stableToken.name, 25 | address: mainnet.tokenPairs.Binance[data.pair].stableToken.address, 26 | decimals: mainnet.tokenPairs.Binance[data.pair].stableToken.decimals, 27 | } 28 | 29 | let tradingToken = { 30 | name: mainnet.tokenPairs.Binance[data.pair].tradingToken.name, 31 | address: mainnet.tokenPairs.Binance[data.pair].tradingToken.address, 32 | decimals: mainnet.tokenPairs.Binance[data.pair].tradingToken.decimals, 33 | } 34 | 35 | 36 | console.log(`Fetching Bakery Swap Prices...`) 37 | web3.eth.subscribe('newBlockHeaders', (error, result) => { 38 | if (!error) { 39 | return; 40 | } 41 | console.error(error); 42 | }) 43 | .on("Connected To Binance SmartChain", subscriptionId => { 44 | console.log(`You are connected on ${subscriptionId}`); 45 | }) 46 | .on('data', async block => { 47 | console.log('-------------------------------------------------------------'); 48 | const exchangeAmount = await new BigNumber(baseAmount); 49 | const shiftedExchangeAmount = await new BigNumber(exchangeAmount).shiftedBy(tradingToken.decimals); 50 | let tokenIn = tradingToken.address 51 | let tokenOut = stableToken.address; 52 | const rawValue = await bakeryswap.router.methods.getAmountsOut(shiftedExchangeAmount, [tokenIn, tokenOut]).call(); 53 | const shiftedValue = await new BigNumber(rawValue[1]).shiftedBy(-stableToken.decimals); 54 | 55 | 56 | process.send({ 57 | tokenIn: { 58 | name: tradingToken.name, 59 | value: exchangeAmount.toString(), 60 | }, 61 | tokenOut: { 62 | name: stableToken.name, 63 | value: shiftedValue.toString() 64 | } 65 | }); 66 | 67 | }) 68 | .on('error', error => { 69 | console.log(error); 70 | }); 71 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/binance/bakeryswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | const pad = require("pad"); 3 | const colors = require("colors"); 4 | const moment = require("moment"); 5 | 6 | async function fetchData(data) { 7 | const process = fetchProcess.fork(__dirname + '/bakeryswapPriceFetcher.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | 22 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), 23 | moment().format('ll') + ' ' + moment().format('LTS')); 24 | 25 | console.log( 26 | pad(colors.red('Token In:'), 30), response.tokenIn.name, 27 | pad(colors.red('Value: '), 30), response.tokenIn.value 28 | ); 29 | console.log( 30 | pad(colors.green('Token Out: '), 30), response.tokenOut.name, 31 | pad(colors.green('Value Out: '), 30), response.tokenOut.value) 32 | ; 33 | 34 | 35 | process.send(data = false); 36 | }); 37 | 38 | process.on('close', function (code, data) { 39 | console.log('Done. Closing ' + code); 40 | }); 41 | } 42 | 43 | module.exports = { 44 | getAssetInfo: function (data) { 45 | return fetchData(data); 46 | } 47 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/binance/pancakeswap/index.js: -------------------------------------------------------------------------------- 1 | const pad = require("pad"); 2 | const colors = require("colors"); 3 | const fetchProcess = require('child_process'); 4 | const moment = require("moment"); 5 | 6 | async function fetchData(data) { 7 | const process = fetchProcess.fork(__dirname+'/pancakeswapPriceFetcher.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function(standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function(standardErrorData) { 14 | if(standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData ); 17 | } 18 | }); 19 | 20 | process.on('message', function(response) { 21 | 22 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), 23 | moment().format('ll') + ' ' + moment().format('LTS')); 24 | 25 | console.log( 26 | pad(colors.red('Token In:'), 30), response.tokenIn.name, 27 | pad(colors.red('Value: '), 30), response.tokenIn.value 28 | ); 29 | console.log( 30 | pad(colors.green('Token Out: '), 30), response.tokenOut.name, 31 | pad(colors.green('Value Out: '), 30), response.tokenOut.value) 32 | ; 33 | 34 | 35 | process.send(data = false); 36 | }); 37 | 38 | process.on('close', function(code, data) { 39 | console.log('Done. Closing ' + code); 40 | }); 41 | } 42 | 43 | module.exports = { 44 | getAssetInfo: function(data) { 45 | return fetchData(data); 46 | } 47 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/binance/pancakeswap/pancakeswapPriceFetcher.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const BigNumber = require("bignumber.js"); 4 | const {mainnet} = require('../../../addresses'); 5 | const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MORALIAS_BSC_MAINNET_WSS_URL)); 6 | 7 | const pancakeSwap = { 8 | factory: new web3.eth.Contract(mainnet.pancakeswap.factory.ABI, mainnet.pancakeswap.factory.address), 9 | router: new web3.eth.Contract(mainnet.pancakeswap.router.ABI, mainnet.pancakeswap.router.address), 10 | } 11 | 12 | const baseAmount = 1; 13 | 14 | process.on('message', function (data) { 15 | if (data === false) { 16 | process.exit(1); 17 | } else { 18 | fetchData(data); 19 | } 20 | }); 21 | 22 | async function fetchData(data) { 23 | let stableToken = { 24 | name: mainnet.tokenPairs.Binance[data.pair].stableToken.name, 25 | address: mainnet.tokenPairs.Binance[data.pair].stableToken.address, 26 | decimals: mainnet.tokenPairs.Binance[data.pair].stableToken.decimals, 27 | } 28 | 29 | let tradingToken = { 30 | name: mainnet.tokenPairs.Binance[data.pair].tradingToken.name, 31 | address: mainnet.tokenPairs.Binance[data.pair].tradingToken.address, 32 | decimals: mainnet.tokenPairs.Binance[data.pair].tradingToken.decimals, 33 | } 34 | 35 | 36 | //console.log(mainnet.tokenPairs.Binance[data.pair].stableToken.name); 37 | console.log(`Fetching Pancake Swap Prices...`) 38 | web3.eth.subscribe('newBlockHeaders', (error, result) => { 39 | if (!error) { 40 | return; 41 | } 42 | console.error(error); 43 | }) 44 | .on("Connected To Binance SmartChain", subscriptionId => { 45 | console.log(`You are connected on ${subscriptionId}`); 46 | }) 47 | .on('data', async block => { 48 | console.log('-------------------------------------------------------------'); 49 | const exchangeAmount = await new BigNumber(baseAmount); 50 | const shiftedExchangeAmount = await new BigNumber(exchangeAmount).shiftedBy(tradingToken.decimals); 51 | let tokenIn = tradingToken.address 52 | let tokenOut = stableToken.address; 53 | // call getAmountsOut in PancakeSwap 54 | const rawPancakeValue = await pancakeSwap.router.methods.getAmountsOut(shiftedExchangeAmount, [tokenIn, tokenOut]).call(); 55 | const shiftedPancakeValue = await new BigNumber(rawPancakeValue[1]).shiftedBy(-stableToken.decimals); 56 | 57 | 58 | process.send({ 59 | tokenIn: { 60 | name: tradingToken.name, 61 | value: exchangeAmount.toString(), 62 | }, 63 | tokenOut: { 64 | name: stableToken.name, 65 | value: shiftedPancakeValue.toString() 66 | } 67 | }); 68 | 69 | }) 70 | .on('error', error => { 71 | console.log(error); 72 | }); 73 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/ethereum/dydx/index.js: -------------------------------------------------------------------------------- 1 | const axios = require("axios"); 2 | 3 | 4 | //const client = new WebSocket(); 5 | 6 | 7 | async function fetchData(token, url) { 8 | 9 | const result = await axios.get(url) 10 | .then(function (response) { 11 | if (token.symbol === 'ETH' || token.symbol === 'BTC') { 12 | return { 13 | token: token.name, 14 | pair: token.symbol + ' / ' + 'USD', 15 | price: response.data.markets[token.symbol + '-USD'].indexPrice 16 | } 17 | } 18 | }) 19 | .catch(function (error) { 20 | console.log(error); 21 | }) 22 | return getData(result); 23 | } 24 | 25 | function getData(response) { 26 | return response; 27 | } 28 | 29 | module.exports = { 30 | getAssetInfo: function (token, url) { 31 | return fetchData(token, url); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /program/utils/pricefetcher/ethereum/kyber/index.js: -------------------------------------------------------------------------------- 1 | const pad = require("pad"); 2 | const colors = require("colors"); 3 | const fetchProcess = require('child_process'); 4 | const moment = require("moment"); 5 | 6 | async function fetchData(data) { 7 | const process = fetchProcess.fork(__dirname + '/kyberPriceFetcher.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), 22 | moment().format('ll') + ' ' + moment().format('LTS')); 23 | console.log(pad(colors.red('Kyber WETH Buy Price:'), 30), response.rate.buy); 24 | console.log(pad(colors.green('Kyber WETH Sell Price:'), 30), response.rate.sell); 25 | process.send(data = false); 26 | }); 27 | 28 | process.on('close', function (code, data) { 29 | console.log('Done. Closing ' + code); 30 | }); 31 | } 32 | 33 | module.exports = { 34 | getAssetInfo: function (data) { 35 | return fetchData(data); 36 | } 37 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/ethereum/kyber/kyberPriceFetcher.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const {mainnet, ropsten, kovan} = require('../../../addresses'); 4 | const AMOUNT_ETH = 100; 5 | const RECENT_ETH_PRICE = 1; 6 | const AMOUNT_TRADINGTOKEN_WEI = Web3.utils.toWei(AMOUNT_ETH.toString()); 7 | const AMOUNT_STABLETOKEN_WEI = Web3.utils.toWei((AMOUNT_ETH * RECENT_ETH_PRICE).toString()); 8 | 9 | 10 | process.on('message', function (data) { 11 | if (data === false) { 12 | process.exit(1); 13 | } else { 14 | fetchData(data); 15 | } 16 | }) 17 | 18 | 19 | function fetchData(data) { 20 | let stableToken, web3, kyber; 21 | console.log(`Fetching Kyber Prices For Pair: ${data.pair}...`) 22 | switch (data.network) { 23 | case 'Mainnet': 24 | stableToken = mainnet.tokenPairs.Ethereum[data.pair].stableToken; 25 | web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MAINNET_INFURA_WSS_URL)); 26 | kyber = new web3.eth.Contract(mainnet.kyber.proxy.ABI, mainnet.kyber.proxy.address); 27 | break; 28 | case 'Ropsten': 29 | stableToken = ropsten.tokenPairs[data.pair].stableToken; 30 | web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.ROPSTEN_INFURA_WSS_URL)); 31 | kyber = new web3.eth.Contract(ropsten.kyber.proxy.ABI, ropsten.kyber.proxy.address); 32 | break; 33 | case 'Kovan': 34 | stableToken = kovan.tokenPairs[data.pair].stableToken; 35 | web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.KOVAN_INFURA_WSS_URL)); 36 | kyber = new web3.eth.Contract(kovan.kyber.proxy.ABI, kovan.kyber.proxy.address); 37 | break; 38 | case 'Local': 39 | stableToken = mainnet.tokenPairs.Ethereum[data.pair].stableToken; 40 | web3 = new Web3(new Web3.providers.WebsocketProvider("http://localhost:8545")); 41 | kyber = new web3.eth.Contract(mainnet.kyber.proxy.ABI, mainnet.kyber.proxy.address); 42 | } 43 | 44 | if (data.network === 'Local') { 45 | (async () => { 46 | const kyberResults = await Promise.all([ 47 | kyber 48 | .methods 49 | .getExpectedRate( 50 | stableToken.address, 51 | '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', //Kyber ETH //TODO: implement kyber focused tokens 52 | AMOUNT_STABLETOKEN_WEI 53 | ) 54 | .call(), 55 | kyber 56 | .methods 57 | .getExpectedRate( 58 | '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', //Kyber ETH //TODO: implement kyber focused tokens 59 | stableToken.address, 60 | AMOUNT_TRADINGTOKEN_WEI 61 | ) 62 | .call() 63 | ]); 64 | const kyberRates = { 65 | buy: parseFloat(1 / (kyberResults[0].expectedRate / (10 ** 18))), 66 | sell: parseFloat(kyberResults[1].expectedRate / (10 ** 18)) 67 | }; 68 | process.send({rate: kyberRates}) 69 | })() 70 | } 71 | web3.eth.subscribe('newBlockHeaders') 72 | .on('data', async block => { 73 | const kyberResults = await Promise.all([ 74 | kyber 75 | .methods 76 | .getExpectedRate( 77 | stableToken.address, 78 | '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 79 | AMOUNT_STABLETOKEN_WEI 80 | ) 81 | .call(), 82 | kyber 83 | .methods 84 | .getExpectedRate( 85 | '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 86 | stableToken.address, 87 | AMOUNT_TRADINGTOKEN_WEI 88 | ) 89 | .call() 90 | ]); 91 | const kyberRates = { 92 | buy: parseFloat(1 / (kyberResults[0].expectedRate / (10 ** 18))), 93 | sell: parseFloat(kyberResults[1].expectedRate / (10 ** 18)) 94 | }; 95 | process.send({rate: kyberRates}) 96 | }) 97 | .on('error', error => { 98 | console.log(error.toString()); 99 | }); 100 | 101 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/ethereum/sushiswap/index.js: -------------------------------------------------------------------------------- 1 | const pad = require("pad"); 2 | const colors = require("colors"); 3 | const fetchProcess = require('child_process'); 4 | const moment = require("moment"); 5 | 6 | async function fetchData(data) { 7 | const process = fetchProcess.fork(__dirname + '/sushiswapPriceFetcher.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), 22 | moment().format('ll') + ' ' + moment().format('LTS')); 23 | console.log(pad(colors.green('Sushiswap Price:'), 30), response.sushiswapPrice); 24 | process.send(data = false); 25 | }); 26 | 27 | process.on('close', function (code, data) { 28 | console.log('Done. Closing ' + code); 29 | }); 30 | } 31 | 32 | module.exports = { 33 | getAssetInfo: function (data) { 34 | return fetchData(data); 35 | } 36 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/ethereum/sushiswap/sushiswapPriceFetcher.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const {mainnet, ropsten, kovan} = require('../../../addresses'); 4 | const ONE_WEI = Web3.utils.toBN(Web3.utils.toWei('1')); 5 | 6 | 7 | process.on('message', function (data) { 8 | if (data === false) { 9 | process.exit(1); 10 | } else { 11 | fetchData(data); 12 | } 13 | }); 14 | 15 | 16 | async function fetchData(data) { 17 | let stableToken, tradingToken, sushi, web3; 18 | console.log(`Fetching Sushiswap Prices For Pair: ${data.pair}...`); 19 | switch (data.network) { 20 | case 'Mainnet': 21 | web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MAINNET_INFURA_WSS_URL)); 22 | stableToken = mainnet.tokenPairs.Ethereum[data.pair].stableToken; 23 | tradingToken = mainnet.tokenPairs.Ethereum[data.pair].tradingToken; 24 | sushi = new web3.eth.Contract(mainnet.sushiswap.router.ABI, mainnet.sushiswap.router.address); 25 | break; 26 | case 'Ropsten': 27 | web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.ROPSTEN_INFURA_WSS_URL)); 28 | stableToken = ropsten.tokenPairs[data.pair].stableToken; 29 | tradingToken = ropsten.tokenPairs[data.pair].tradingToken; 30 | sushi = new web3.eth.Contract(ropsten.sushiswap.router.ABI, ropsten.sushiswap.router.address); 31 | break; 32 | case 'Kovan': 33 | web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.KOVAN_INFURA_WSS_URL)); 34 | stableToken = kovan.tokenPairs[data.pair].stableToken; 35 | tradingToken = kovan.tokenPairs[data.pair].tradingToken; 36 | sushi = new web3.eth.Contract(kovan.sushiswap.router.ABI, kovan.sushiswap.router.address); 37 | break; 38 | case 'Local': 39 | web3 = new Web3(new Web3.providers.WebsocketProvider("https://127.0.0.1:8545")); 40 | stableToken = mainnet.tokenPairs.Ethereum[data.pair].stableToken; 41 | tradingToken = mainnet.tokenPairs.Ethereum[data.pair].tradingToken; 42 | sushi = new web3.eth.Contract(mainnet.sushiswap.router.ABI, mainnet.sushiswap.router.address); 43 | break; 44 | } 45 | let sushiswapEthPrice; 46 | const updateEthPrice = async () => { 47 | const sushiswapPrice = await sushi.methods.getAmountsOut(web3.utils.toWei('1'), [tradingToken.address, stableToken.address]).call(); 48 | sushiswapEthPrice = web3.utils.toBN('1').mul(web3.utils.toBN(sushiswapPrice[1])).div(ONE_WEI); 49 | process.send({sushiswapPrice: sushiswapEthPrice.toString()}); 50 | } 51 | setInterval(updateEthPrice, 5000); 52 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/ethereum/uniswap/index.js: -------------------------------------------------------------------------------- 1 | const pad = require("pad"); 2 | const colors = require("colors"); 3 | const fetchProcess = require('child_process'); 4 | const moment = require("moment"); 5 | 6 | async function fetchData(data) { 7 | const process = fetchProcess.fork(__dirname + '/uniswapPriceFetcher.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), 22 | moment().format('ll') + ' ' + moment().format('LTS')); 23 | console.log(pad(colors.red('Uniswap WETH Buy Price:'), 30), response.rate.buy); 24 | console.log(pad(colors.green('Uniswap WETH Sell Price:'), 30), response.rate.sell); 25 | process.send(data = false); 26 | }); 27 | 28 | process.on('close', function (code, data) { 29 | console.log('Done. Closing ' + code); 30 | }); 31 | } 32 | 33 | module.exports = { 34 | getAssetInfo: function (data) { 35 | return fetchData(data); 36 | } 37 | } -------------------------------------------------------------------------------- /program/utils/pricefetcher/index.js: -------------------------------------------------------------------------------- 1 | const CMKService = require('../pricefetcher/vendors/cmk'); 2 | const DyDxService = require('../pricefetcher/ethereum/dydx'); 3 | const ApeswapService = require('../pricefetcher/binance/apeswap'); 4 | const BakeryswapService = require('../pricefetcher/binance/bakeryswap'); 5 | const UniswapService = require('../pricefetcher/ethereum/uniswap'); 6 | const KyberService = require('../pricefetcher/ethereum/kyber'); 7 | const SushiswapService = require('../pricefetcher/ethereum/sushiswap'); 8 | const PancakeswapService = require('../pricefetcher/binance/pancakeswap'); 9 | 10 | 11 | function fetchApeswapPairPrice(pair) { 12 | let data = {pair:pair}; 13 | return ApeswapService.getAssetInfo(data); 14 | } 15 | 16 | function fetchBakeryswapPairPrice(pair) { 17 | let data = {pair:pair}; 18 | return BakeryswapService.getAssetInfo(data); 19 | } 20 | 21 | function fetchUniswapPairPrice(exchange, network, tokenPair) { 22 | let data = {exchange: exchange, network: network, pair: tokenPair}; 23 | return UniswapService.getAssetInfo(data); 24 | } 25 | 26 | function fetchKyberPairPrice(exchange, network, tokenPair) { 27 | let data = {exchange: exchange, network: network, pair: tokenPair}; 28 | return KyberService.getAssetInfo(data); 29 | } 30 | 31 | function fetchSushiswapPairPrice(exchange, network, tokenPair) { 32 | let data = {exchange: exchange, network: network, pair: tokenPair}; 33 | return SushiswapService.getAssetInfo(data); 34 | } 35 | 36 | function fetchPancakeswapPairPrice(pair) { 37 | let data = { pair: pair}; 38 | return PancakeswapService.getAssetInfo(data); 39 | } 40 | 41 | async function fetchCMKPrice(token) { 42 | return await CMKService.getAssetInfo(token, process.env.CMK_QUOTE_API_URL); 43 | } 44 | 45 | async function fetchDyDxPrice(token) { 46 | return await DyDxService.getAssetInfo(token, process.env.DYDX_V3_MARKETS_API_URL); 47 | } 48 | 49 | 50 | 51 | module.exports = { 52 | fetcher: { 53 | binance: { 54 | fetchApeswapPairPrice: function(pair) { 55 | return fetchApeswapPairPrice(pair); 56 | }, 57 | fetchBakeryswapPairPrice: function(pair) { 58 | return fetchBakeryswapPairPrice(pair); 59 | }, 60 | fetchPancakeswapPairPrice: function(pair) { 61 | return fetchPancakeswapPairPrice(pair); 62 | } 63 | }, 64 | ethereum: { 65 | fetchUniswapPairPrice: function(exchange, network, tokenPair) { 66 | return fetchUniswapPairPrice(exchange, network, tokenPair) 67 | }, 68 | fetchKyberPairPrice: function(exchange, network, tokenPair) { 69 | return fetchKyberPairPrice(exchange, network, tokenPair) 70 | }, 71 | fetchSushiswapPairPrice: function(exchange, network, tokenPair) { 72 | return fetchSushiswapPairPrice(exchange, network, tokenPair); 73 | }, 74 | } 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /program/utils/pricefetcher/vendors/cmk/index.js: -------------------------------------------------------------------------------- 1 | const rp = require('request-promise'); 2 | 3 | async function fetchInfo(token, url) { 4 | const requestOptions = { 5 | method: 'GET', 6 | uri: url, 7 | qs: { 8 | 'id': token.id, 9 | }, 10 | headers: { 11 | 'X-CMC_PRO_API_KEY': process.env.CMK_API_KEY, 12 | }, 13 | json: true, 14 | gzip: true 15 | }; 16 | 17 | const result = await rp(requestOptions).then(response => { 18 | return { 19 | token: token.name, 20 | pair: 'USD' + ' / '+ token.symbol, 21 | price: response.data[token.id].quote['USD'].price 22 | }; 23 | }).catch((err) => { 24 | console.log('API call error:', err.message); 25 | }); 26 | return getData(result); 27 | } 28 | function getData(response) { 29 | return response 30 | } 31 | 32 | module.exports = { 33 | getAssetInfo: function (token, url) { 34 | return fetchInfo(token, url); 35 | } 36 | } -------------------------------------------------------------------------------- /program/utils/tokens/index.js: -------------------------------------------------------------------------------- 1 | const tokens = [ 2 | { 3 | name: 'Bitcoin', 4 | coinMarketCapID: '1', 5 | slug: 'bitcoin', 6 | symbol: 'BTC' 7 | }, 8 | { 9 | name: 'Ethereum', 10 | coinMarketCapID: '1027', 11 | slug: 'eth', 12 | symbol: 'ETH' 13 | }, 14 | { 15 | name: 'Binance Coin', 16 | coinMarketCapID: '3', 17 | slug: 'bnb', 18 | symbol: 'BNB' 19 | }, 20 | { 21 | name: 'Wrapped Ethereum', 22 | coinMarketCapID: '2396', 23 | slug: 'weth', 24 | symbol: 'WETH' 25 | }, 26 | { 27 | name: 'Dai', 28 | coinMarketCapID: '4943', 29 | slug: 'multi-collateral-dai', 30 | symbol: 'DAI' 31 | }, 32 | { 33 | name: 'USD Coin', 34 | coinMarketCapID: '3408', 35 | slug: 'usd-coin', 36 | symbol: 'USDC' 37 | }, 38 | 39 | ]; 40 | 41 | exports.tokens = tokens.map(function(token) { 42 | return { 43 | id: token.coinMarketCapID, 44 | name: token.name, 45 | slug: token.slug, 46 | symbol: token.symbol 47 | }; 48 | }); -------------------------------------------------------------------------------- /program/utils/tokenswapper/binance/apeswap/apeswapTokenSwapper.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const BigNumber = require("bignumber.js"); 4 | const {mainnet} = require('../../../addresses'); 5 | const pad = require("pad"); 6 | const colors = require("colors"); 7 | const moment = require("moment"); 8 | const ApeTokenSwapContract = require('../../../../../build/contracts/ApeTokenSwap.json') 9 | const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MORALIAS_BSC_MAINNET_WSS_URL)); 10 | 11 | 12 | 13 | process.on('message', function (data) { 14 | if (data === false) { 15 | process.exit(1); 16 | } else { 17 | swap(data); 18 | } 19 | 20 | async function swap(data) { 21 | 22 | let decimals; 23 | const networkID = await web3.eth.net.getId(); 24 | const SwapContract = new web3.eth.Contract(ApeTokenSwapContract.abi, ApeTokenSwapContract.networks[networkID].address); 25 | 26 | if(data.digits === '' || typeof data.digits === 'undefined') { 27 | decimals = Number(18); 28 | } else { 29 | decimals = data.digits; 30 | } 31 | const admin = web3.eth.accounts.wallet.add(process.env.PRIVATE_KEY); 32 | 33 | const apeswap = { 34 | factory: new web3.eth.Contract(mainnet.apeswap.factory.ABI, mainnet.apeswap.factory.address), 35 | router: new web3.eth.Contract(mainnet.apeswap.router.ABI, mainnet.apeswap.router.address), 36 | } 37 | 38 | let fromToken = { 39 | address: data.swapToken, 40 | ABI: new web3.eth.Contract(mainnet.tokens.Binance.BEP20.ABI, data.swapToken), 41 | decimals: decimals, 42 | }; 43 | 44 | let toToken = { 45 | address: data.returnToken, 46 | ABI: new web3.eth.Contract(mainnet.tokens.Binance.BEP20.ABI, data.returnToken), 47 | decimals: decimals, 48 | }; 49 | 50 | let tokenPair = { 51 | address: await apeswap.factory.methods.getPair(fromToken.address, toToken.address).call() 52 | }; 53 | 54 | if(tokenPair.address === null || typeof tokenPair.address === 'undefined') { 55 | console.log( 56 | pad(colors.magenta('A token pair could not be found with the specified addresses.'), 30), fromToken.address, 57 | pad(colors.magenta('=> '), 30), toToken.address); 58 | process.exit(1); 59 | } 60 | 61 | 62 | const swapAmount = new BigNumber(data.amount); 63 | const swapAmountInWei = new BigNumber(swapAmount).shiftedBy(decimals); 64 | 65 | 66 | const amountOutOfReturnToken = await apeswap.router.methods.getAmountsOut(swapAmountInWei, [fromToken.address, toToken.address]).call(); 67 | let shiftedAmountOutOfReturn = new BigNumber(amountOutOfReturnToken[1]).shiftedBy(-decimals); 68 | const returnAmountInWei = new BigNumber(amountOutOfReturnToken[1]); 69 | 70 | 71 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), 72 | moment().format('ll') + '' + moment().format('LTS')); 73 | 74 | console.log( 75 | pad(colors.magenta('Swapping token at address'), 30), fromToken.address, 76 | pad(colors.magenta('For token at address'), 30), toToken.address); 77 | 78 | console.log( 79 | pad(colors.green('Amount Going Out'), 30), swapAmount.toString(), 80 | pad(colors.green('Amount Being Returned'), 30), shiftedAmountOutOfReturn.toString()); 81 | 82 | 83 | const tx = await ApeTokenSwapContract.methods.startSwap( 84 | fromToken.address, 85 | toToken.address, 86 | swapAmountInWei, 87 | 0, 88 | ); 89 | 90 | const requestData = tx.encodeABI(); 91 | const txData = { 92 | from: admin.address, 93 | to: SwapContract.options.address, 94 | requestData, 95 | gas: 310000, 96 | gasPrice: 5000000000, // 5Gwei 97 | }; 98 | const receipt = await web3.eth.sendTransaction(txData); 99 | process.send(receipt) 100 | 101 | } 102 | 103 | }); -------------------------------------------------------------------------------- /program/utils/tokenswapper/binance/apeswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | const pad = require("pad"); 3 | const colors = require("colors"); 4 | const moment = require("moment"); 5 | 6 | async function swap(data) { 7 | const process = fetchProcess.fork(__dirname + '/apeswapTokenSwapper.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | console.log(`Transaction hash: ${response.transactionHash}`); 22 | 23 | process.send(data = false); 24 | }); 25 | 26 | process.on('close', function (code, data) { 27 | console.log('Done. Closing ' + code); 28 | }); 29 | } 30 | 31 | module.exports = { 32 | swapTokens: function (data) { 33 | return swap(data); 34 | } 35 | } -------------------------------------------------------------------------------- /program/utils/tokenswapper/binance/bakeryswap/bakeryswapTokenSwapper.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const BigNumber = require("bignumber.js"); 4 | const {mainnet} = require('../../../addresses'); 5 | const pad = require("pad"); 6 | const colors = require("colors"); 7 | const moment = require("moment"); 8 | const BakeryTokenSwapContract = require('../../../../../build/contracts/BakeryTokenSwap.json') 9 | const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MORALIAS_BSC_MAINNET_WSS_URL)); 10 | 11 | 12 | 13 | process.on('message', function (data) { 14 | if (data === false) { 15 | process.exit(1); 16 | } else { 17 | swap(data); 18 | } 19 | 20 | async function swap(data) { 21 | 22 | let decimals; 23 | const networkID = await web3.eth.net.getId(); 24 | const SwapContract = new web3.eth.Contract(BakeryTokenSwapContract.abi, BakeryTokenSwapContract.networks[networkID].address); 25 | 26 | if(data.digits === '' || typeof data.digits === 'undefined') { 27 | decimals = Number(18); 28 | } else { 29 | decimals = data.digits; 30 | } 31 | const admin = web3.eth.accounts.wallet.add(process.env.PRIVATE_KEY); 32 | 33 | const bakeryswap = { 34 | factory: new web3.eth.Contract(mainnet.bakeryswap.factory.ABI, mainnet.bakeryswap.factory.address), 35 | router: new web3.eth.Contract(mainnet.bakeryswap.router.ABI, mainnet.bakeryswap.router.address), 36 | } 37 | 38 | let fromToken = { 39 | address: data.swapToken, 40 | ABI: new web3.eth.Contract(mainnet.tokens.Binance.BEP20.ABI, data.swapToken), 41 | decimals: decimals, 42 | }; 43 | 44 | let toToken = { 45 | address: data.returnToken, 46 | ABI: new web3.eth.Contract(mainnet.tokens.Binance.BEP20.ABI, data.returnToken), 47 | decimals: decimals, 48 | }; 49 | 50 | let tokenPair = { 51 | address: await bakeryswap.factory.methods.getPair(fromToken.address, toToken.address).call() 52 | }; 53 | 54 | if(tokenPair.address === null || typeof tokenPair.address === 'undefined') { 55 | console.log( 56 | pad(colors.magenta('A token pair could not be found with the specified addresses.'), 30), fromToken.address, 57 | pad(colors.magenta('=> '), 30), toToken.address); 58 | process.exit(1); 59 | } 60 | 61 | 62 | const swapAmount = new BigNumber(data.amount); 63 | const swapAmountInWei = new BigNumber(swapAmount).shiftedBy(decimals); 64 | 65 | 66 | const amountOutOfReturnToken = await bakeryswap.router.methods.getAmountsOut(swapAmountInWei, [fromToken.address, toToken.address]).call(); 67 | let shiftedAmountOutOfReturn = new BigNumber(amountOutOfReturnToken[1]).shiftedBy(-decimals); 68 | const returnAmountInWei = new BigNumber(amountOutOfReturnToken[1]); 69 | 70 | 71 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), 72 | moment().format('ll') + '' + moment().format('LTS')); 73 | 74 | console.log( 75 | pad(colors.magenta('Swapping token at address'), 30), fromToken.address, 76 | pad(colors.magenta('For token at address'), 30), toToken.address); 77 | 78 | console.log( 79 | pad(colors.green('Amount Going Out'), 30), swapAmount.toString(), 80 | pad(colors.green('Amount Being Returned'), 30), shiftedAmountOutOfReturn.toString()); 81 | 82 | 83 | const tx = await BakeryTokenSwapContract.methods.startSwap( 84 | fromToken.address, 85 | toToken.address, 86 | swapAmountInWei, 87 | 0, 88 | ); 89 | 90 | const requestData = tx.encodeABI(); 91 | const txData = { 92 | from: admin.address, 93 | to: SwapContract.options.address, 94 | requestData, 95 | gas: 310000, 96 | gasPrice: 5000000000, // 5Gwei 97 | }; 98 | const receipt = await web3.eth.sendTransaction(txData); 99 | process.send(receipt) 100 | 101 | } 102 | 103 | }); -------------------------------------------------------------------------------- /program/utils/tokenswapper/binance/bakeryswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | const pad = require("pad"); 3 | const colors = require("colors"); 4 | const moment = require("moment"); 5 | 6 | async function swap(data) { 7 | const process = fetchProcess.fork(__dirname + '/bakeryswapTokenSwapper.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | 22 | 23 | 24 | process.send(data = false); 25 | }); 26 | 27 | process.on('close', function (code, data) { 28 | console.log('Done. Closing ' + code); 29 | }); 30 | } 31 | 32 | module.exports = { 33 | swapTokens: function (data) { 34 | return swap(data); 35 | } 36 | } -------------------------------------------------------------------------------- /program/utils/tokenswapper/binance/pancakeswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | const pad = require("pad"); 3 | const colors = require("colors"); 4 | const moment = require("moment"); 5 | 6 | async function swap(data) { 7 | const process = fetchProcess.fork(__dirname + '/pancakeswapTokenSwapper.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | 22 | 23 | 24 | process.send(data = false); 25 | }); 26 | 27 | process.on('close', function (code, data) { 28 | console.log('Done. Closing ' + code); 29 | }); 30 | } 31 | 32 | module.exports = { 33 | swapTokens: function (data) { 34 | return swap(data); 35 | } 36 | } -------------------------------------------------------------------------------- /program/utils/tokenswapper/binance/pancakeswap/pancakeswapTokenSwapper.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const Web3 = require('web3'); 3 | const BigNumber = require("bignumber.js"); 4 | const {mainnet} = require('../../../addresses'); 5 | const pad = require("pad"); 6 | const colors = require("colors"); 7 | const moment = require("moment"); 8 | const PancakeTokenSwapContract = require('../../../../../build/contracts/PancakeTokenSwap.json') 9 | const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MORALIAS_BSC_MAINNET_WSS_URL)); 10 | 11 | 12 | 13 | process.on('message', function (data) { 14 | if (data === false) { 15 | process.exit(1); 16 | } else { 17 | swap(data); 18 | } 19 | 20 | async function swap(data) { 21 | 22 | let decimals; 23 | const networkID = await web3.eth.net.getId(); 24 | const SwapContract = new web3.eth.Contract(PancakeTokenSwapContract.abi, PancakeTokenSwapContract.networks[networkID].address); 25 | 26 | if(data.digits === '' || typeof data.digits === 'undefined') { 27 | decimals = Number(18); 28 | } else { 29 | decimals = data.digits; 30 | } 31 | const admin = web3.eth.accounts.wallet.add(process.env.PRIVATE_KEY); 32 | 33 | const pancakeswap = { 34 | factory: new web3.eth.Contract(mainnet.pancakeswap.factory.ABI, mainnet.pancakeswap.factory.address), 35 | router: new web3.eth.Contract(mainnet.pancakeswap.router.ABI, mainnet.pancakeswap.router.address), 36 | } 37 | 38 | let fromToken = { 39 | address: data.swapToken, 40 | ABI: new web3.eth.Contract(mainnet.tokens.Binance.BEP20.ABI, data.swapToken), 41 | decimals: decimals, 42 | }; 43 | 44 | let toToken = { 45 | address: data.returnToken, 46 | ABI: new web3.eth.Contract(mainnet.tokens.Binance.BEP20.ABI, data.returnToken), 47 | decimals: decimals, 48 | }; 49 | 50 | let tokenPair = { 51 | address: await pancakeswap.factory.methods.getPair(fromToken.address, toToken.address).call() 52 | }; 53 | 54 | if(tokenPair.address === null || typeof tokenPair.address === 'undefined') { 55 | console.log( 56 | pad(colors.magenta('A token pair could not be found with the specified addresses.'), 30), fromToken.address, 57 | pad(colors.magenta('=> '), 30), toToken.address); 58 | process.exit(1); 59 | } 60 | 61 | 62 | const swapAmount = new BigNumber(data.amount); 63 | const swapAmountInWei = new BigNumber(swapAmount).shiftedBy(decimals); 64 | 65 | 66 | const amountOutOfReturnToken = await pancakeswap.router.methods.getAmountsOut(swapAmountInWei, [fromToken.address, toToken.address]).call(); 67 | let shiftedAmountOutOfReturn = new BigNumber(amountOutOfReturnToken[1]).shiftedBy(-decimals); 68 | const returnAmountInWei = new BigNumber(amountOutOfReturnToken[1]); 69 | 70 | 71 | console.log(pad(colors.yellow('Current I/O Values as of '), 30), 72 | moment().format('ll') + '' + moment().format('LTS')); 73 | 74 | console.log( 75 | pad(colors.magenta('Swapping token at address'), 30), fromToken.address, 76 | pad(colors.magenta('For token at address'), 30), toToken.address); 77 | 78 | console.log( 79 | pad(colors.green('Amount Going Out'), 30), swapAmount.toString(), 80 | pad(colors.green('Amount Being Returned'), 30), shiftedAmountOutOfReturn.toString()); 81 | 82 | 83 | const tx = await PancakeTokenSwapContract.methods.startSwap( 84 | fromToken.address, 85 | toToken.address, 86 | swapAmountInWei, 87 | 0, 88 | ); 89 | 90 | const requestData = tx.encodeABI(); 91 | const txData = { 92 | from: admin.address, 93 | to: SwapContract.options.address, 94 | requestData, 95 | gas: 310000, 96 | gasPrice: 5000000000, // 5Gwei 97 | }; 98 | const receipt = await web3.eth.sendTransaction(txData); 99 | process.send(receipt) 100 | 101 | } 102 | 103 | }); -------------------------------------------------------------------------------- /program/utils/tokenswapper/ethereum/kyber/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | const pad = require("pad"); 3 | const colors = require("colors"); 4 | const moment = require("moment"); 5 | 6 | async function swap(data) { 7 | const process = fetchProcess.fork(__dirname + '/kyberTokenSwapper.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | 22 | 23 | 24 | process.send(data = false); 25 | }); 26 | 27 | process.on('close', function (code, data) { 28 | console.log('Done. Closing ' + code); 29 | }); 30 | } 31 | 32 | module.exports = { 33 | swapTokens: function (data) { 34 | return swap(data); 35 | } 36 | } -------------------------------------------------------------------------------- /program/utils/tokenswapper/ethereum/kyber/kyberTokenSwapper.js: -------------------------------------------------------------------------------- 1 | // Implement -------------------------------------------------------------------------------- /program/utils/tokenswapper/ethereum/sushiswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | const pad = require("pad"); 3 | const colors = require("colors"); 4 | const moment = require("moment"); 5 | 6 | async function swap(data) { 7 | const process = fetchProcess.fork(__dirname + '/sushiswapTokenSwapper.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | 22 | 23 | 24 | process.send(data = false); 25 | }); 26 | 27 | process.on('close', function (code, data) { 28 | console.log('Done. Closing ' + code); 29 | }); 30 | } 31 | 32 | module.exports = { 33 | swapTokens: function (data) { 34 | return swap(data); 35 | } 36 | } -------------------------------------------------------------------------------- /program/utils/tokenswapper/ethereum/sushiswap/sushiswapTokenSwapper.js: -------------------------------------------------------------------------------- 1 | // Implement -------------------------------------------------------------------------------- /program/utils/tokenswapper/ethereum/uniswap/index.js: -------------------------------------------------------------------------------- 1 | const fetchProcess = require('child_process'); 2 | const pad = require("pad"); 3 | const colors = require("colors"); 4 | const moment = require("moment"); 5 | 6 | async function swap(data) { 7 | const process = fetchProcess.fork(__dirname + '/uniswapTokenSwapper.js', [], {silent: true}); 8 | process.send(data) 9 | process.stdout.on('data', function (standardOutData) { 10 | console.log(standardOutData.toString()); 11 | }); 12 | 13 | process.stderr.on('data', function (standardErrorData) { 14 | if (standardErrorData.toString().includes('Warning:')) { 15 | } else { 16 | console.log('Error: ' + standardErrorData); 17 | } 18 | }); 19 | 20 | process.on('message', function (response) { 21 | 22 | 23 | 24 | process.send(data = false); 25 | }); 26 | 27 | process.on('close', function (code, data) { 28 | console.log('Done. Closing ' + code); 29 | }); 30 | } 31 | 32 | module.exports = { 33 | swapTokens: function (data) { 34 | return swap(data); 35 | } 36 | } -------------------------------------------------------------------------------- /program/utils/tokenswapper/ethereum/uniswap/uniswapTokenSwapper.js: -------------------------------------------------------------------------------- 1 | // Implement -------------------------------------------------------------------------------- /program/utils/tokenswapper/index.js: -------------------------------------------------------------------------------- 1 | const ApeTokenSwapService = require("./binance/apeswap"); 2 | const BakeryTokenSwapService = require("./binance/bakeryswap"); 3 | const PancakeTokenSwapService = require('./binance/pancakeswap'); 4 | const KyberTokenSwapService = require('./ethereum/kyber'); 5 | const SushiTokenSwapService = require('./ethereum/sushiswap'); 6 | const UniTokenSwapService = require('./ethereum/uniswap'); 7 | 8 | function swapTokensOnApeswap(data) { 9 | return ApeTokenSwapService.swapTokens(data); 10 | } 11 | 12 | function swapTokensOnBakeryswap(data) { 13 | return BakeryTokenSwapService.swapTokens(data); 14 | } 15 | 16 | function swapTokensOnPancakeswap(data) { 17 | return PancakeTokenSwapService.swapTokens(data); 18 | } 19 | 20 | function swapTokensOnKyber(data) { 21 | return KyberTokenSwapService.swapTokens(data); 22 | } 23 | 24 | function swapTokensOnSushiswap(data) { 25 | return SushiTokenSwapService.swapTokens(data); 26 | } 27 | 28 | function swapTokensOnUniswap(data) { 29 | return UniTokenSwapService.swapTokens(data); 30 | } 31 | 32 | module.exports = { 33 | swapper: { 34 | binance: { 35 | swapOnApeswap: function(data) { 36 | return swapTokensOnApeswap(data); 37 | }, 38 | swapOnBakeryswap: function(data) { 39 | return swapTokensOnBakeryswap(data); 40 | }, 41 | swapOnPancakeswap: function(data) { 42 | return swapTokensOnPancakeswap(data) 43 | } 44 | }, 45 | ethereum: { 46 | swapOnKyber: function(data) { 47 | return swapTokensOnKyber(data); 48 | }, 49 | swapOnSushiswap: function(data) { 50 | return swapTokensOnSushiswap(data); 51 | }, 52 | swapOnUniswap: function(data) { 53 | return swapTokensOnUniswap(data) 54 | } 55 | } 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /program/views/banner/index.js: -------------------------------------------------------------------------------- 1 | const decorator = require('figlet'); 2 | 3 | function displayBanner(resolve, reject) { 4 | 5 | decorator.text('AFX', { 6 | font: 'Standard', 7 | horizontalLayout: 'default', 8 | verticalLayout: 'default', 9 | width: 80, 10 | whitespaceBreak: true 11 | }, function(err, data) { 12 | if (err) { 13 | console.log('Something went wrong...'); 14 | console.dir(err); 15 | reject(err); 16 | } 17 | resolve(data); 18 | }) 19 | } 20 | exports.showBanner = function (resolve, reject) { 21 | displayBanner(resolve, reject); 22 | } 23 | -------------------------------------------------------------------------------- /test/sample-test.js: -------------------------------------------------------------------------------- 1 | const { expect } = require("chai"); 2 | const { ethers } = require("hardhat"); 3 | 4 | describe("Greeter", function () { 5 | it("Should return the new greeting once it's changed", async function () { 6 | const Greeter = await ethers.getContractFactory("Greeter"); 7 | const greeter = await Greeter.deploy("Hello, world!"); 8 | await greeter.deployed(); 9 | 10 | expect(await greeter.greet()).to.equal("Hello, world!"); 11 | 12 | const setGreetingTx = await greeter.setGreeting("Hola, mundo!"); 13 | 14 | // wait until the transaction is mined 15 | await setGreetingTx.wait(); 16 | 17 | expect(await greeter.greet()).to.equal("Hola, mundo!"); 18 | }); 19 | }); 20 | --------------------------------------------------------------------------------