├── .gitignore ├── LICENSE ├── README.md ├── client ├── .gitignore ├── client.js ├── package.json ├── src │ ├── abi_erc20.js │ ├── chainlink_price_source_abi.json │ ├── chainlink_price_source_cam_abi.json │ ├── networks.json │ ├── qidao_vault_abi.json │ ├── qidao_vault_abi_weth.json │ └── slugs.json └── utils.js └── contracts ├── .gitignore ├── contracts ├── BlackMagic.sol ├── FlashLoanReceiverBase.sol ├── Interfaces.sol └── Libraries.sol ├── hardhat.config.js ├── package.json └── scripts └── deploy.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## The Lickuidator 2 | 3 | Black magic for Polygon liquidations on QiDao. 4 | 5 | ## LEGAL NOTE 6 | 7 | ```bash 8 | THE PURPOSE OF THIS REPOSITORY IS FOR EDUCATIONAL PURPOSES ONLY. 9 | 10 | BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 11 | FOR THE PROGRAM. 12 | THE ENTIRE RISK AS TO THE OUTCOMES, QUALITY AND PERFORMANCE OF THE 13 | PROGRAM IS WITH YOU. 14 | SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY 15 | SERVICING, REPAIR, CORRECTION OR LOSS. 16 | ``` 17 | 18 | ### How to get all the QiDao liquidable vaults 19 | 20 | 21 | ```bash 22 | cd client 23 | 24 | npm install 25 | 26 | # higher cost than 0 MAI (all) 27 | npm run find_liquidations 28 | 29 | # higher cost than 1 MAI 30 | MIN_MAI_COST=1 npm run find_liquidations 1 31 | 32 | # for other networks 33 | # supported networks: matic, avax, arbitrum, moonriver, ftm 34 | NETWORK_NAME=ftm node client.js find_liquidations 1 35 | 36 | # if you want to use a specific RPC endpoint 37 | export PRIVATE_RPC="my_rpc" 38 | 39 | # if the RPC endpoint is username/password protected 40 | export PRIVATE_RPC_USERNAME="user" 41 | export PRIVATE_RPC_PASSWORD="password" 42 | ``` 43 | 44 | ### How to build and deploy the liquidator contract 45 | 46 | ```bash 47 | cd contracts 48 | npm install 49 | 50 | npx hardhat compile 51 | 52 | export ETHEREUM_WALLET_PRIVATE_KEY="YOUR_PRIVATE_KEY" 53 | 54 | npx hardhat run scripts/deploy.js --network matic 55 | 56 | ``` 57 | -------------------------------------------------------------------------------- /client/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | scratchpad 4 | -------------------------------------------------------------------------------- /client/client.js: -------------------------------------------------------------------------------- 1 | const UTILS = require("./utils") 2 | 3 | const ethers = require("ethers") 4 | const Web3 = require("web3") 5 | const BigNumber = require('big-number') 6 | const InputDataDecoder = require('ethereum-input-data-decoder') 7 | const sleep = require('sleep-promise') 8 | 9 | const NETWORKS = require("./src/networks.json") 10 | 11 | let WALLET_PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY 12 | if (!WALLET_PRIVATE_KEY) { 13 | console.log("Provide wallet key as export WALLET_PRIVATE_KEY='KEY'. Using a dummy key now.") 14 | WALLET_PRIVATE_KEY = "0x0000000000000000000000000000000000000000000000000000000000000001" 15 | } 16 | 17 | require('console-stamp')(console, '[HH:MM:ss.l]'); 18 | 19 | const wallet = new ethers.Wallet(WALLET_PRIVATE_KEY); 20 | console.log(wallet.address) 21 | 22 | let GAS_PRICE_MIN = 100 * (10 ** 9) 23 | let GAS_PRICE_MAX = 1000 * (10 ** 9) 24 | let GAS_PRICE = parseInt((GAS_PRICE_MIN + GAS_PRICE_MAX) / 2) 25 | 26 | const NETWORK_NAME = process.env.NETWORK_NAME || "matic" 27 | if (!NETWORKS[NETWORK_NAME]) { 28 | throw (`Network <${NETWORK_NAME}> not supported`) 29 | } 30 | const NETWORK = NETWORKS[NETWORK_NAME] 31 | const QIDAO_VAULTS = NETWORK["qidao_vaults"] 32 | 33 | let RPC_USERNAME_PASS = "" 34 | if (process.env.PRIVATE_RPC_USERNAME && process.env.PRIVATE_RPC_PASSWORD) { 35 | let rpc_username = process.env.PRIVATE_RPC_USERNAME 36 | let rpc_password = process.env.PRIVATE_RPC_PASSWORD 37 | RPC_USERNAME_PASS = `${rpc_username}@${rpc_username}:` 38 | } 39 | 40 | let HTTP_PROVIDER = process.env.PRIVATE_POLYGON_RPC || NETWORK.rpc.url 41 | HTTP_PROVIDER = `${RPC_USERNAME_PASS}${HTTP_PROVIDER}` 42 | 43 | let connectionInfo = { 44 | "url": process.env.PRIVATE_RPC || NETWORK.rpc.url, 45 | "user": process.env.PRIVATE_RPC_USERNAME, 46 | "password": process.env.PRIVATE_RPC_PASSWORD 47 | } 48 | 49 | const provider = new ethers.providers.JsonRpcProvider(connectionInfo) 50 | const tx_getter = new Web3(new Web3.providers.HttpProvider(HTTP_PROVIDER)) 51 | const signer = new ethers.Wallet(WALLET_PRIVATE_KEY).connect(provider) 52 | 53 | 54 | async function main() { 55 | let gasPrice = await provider.getGasPrice() 56 | GAS_PRICE = parseInt(parseInt(gasPrice.toString()) * 120 / 100) 57 | if (GAS_PRICE > GAS_PRICE_MAX) { 58 | GAS_PRICE = GAS_PRICE_MAX 59 | } else { 60 | if (GAS_PRICE < GAS_PRICE_MIN) { 61 | GAS_PRICE = GAS_PRICE_MIN 62 | } 63 | } 64 | let gasPriceHuman = parseInt(GAS_PRICE / 10 ** 9) 65 | console.log(`Gas price used: ${gasPriceHuman} gwei.`) 66 | 67 | if (process.argv[2] == 'find_liquidations') { 68 | let vaults = Object.keys(QIDAO_VAULTS) 69 | let cost_value = process.argv[3] || 0 70 | for (let i = 0; i < vaults.length; i++) { 71 | let vault_name = vaults[i] 72 | let pool_contract = QIDAO_VAULTS[vault_name] 73 | console.log(`Getting all pools for ${pool_contract} ${vault_name} with cost value higher than ${cost_value} MAI`) 74 | UTILS.get_all_qidao_vaults(NETWORK_NAME, pool_contract, signer, cost_value, vault_name) 75 | } 76 | } 77 | 78 | if (process.argv[2] == 'get_vault') { 79 | vaultType = process.argv[3] 80 | vaultId = process.argv[4] 81 | 82 | console.log(`Getting information for vault type ${vaultType} and id ${vaultId}`) 83 | 84 | let vaultInfo = await UTILS.get_vault_info(NETWORK_NAME, signer, vaultType, vaultId) 85 | 86 | console.log(vaultInfo) 87 | } 88 | 89 | if (process.argv[2] == 'find_big_liquidations') { 90 | let vaultType = process.argv[3] 91 | let max_vaults = parseInt(process.argv[4]) 92 | let vaults = [] 93 | let concurrentJobs = [] 94 | for (let i = 0; i < max_vaults; i++) { 95 | concurrentJobs.push(UTILS.get_vault_info(NETWORK_NAME, signer, vaultType, i)) 96 | } 97 | for (let i = 0; i < max_vaults; i++) { 98 | vaults.push(await(concurrentJobs[i])) 99 | } 100 | let orderedVaults = vaults.filter(function(a) { 101 | return a.mai_debt > 1000 && a.collateral_to_debt < 175 102 | }) 103 | orderedVaults = orderedVaults.sort(function(a, b) { 104 | return a.mai_debt - b.mai_debt 105 | }) 106 | 107 | console.log(orderedVaults) 108 | } 109 | 110 | } 111 | 112 | main() 113 | -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client-lickuidator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "find_liquidations": "node client.js find_liquidations $MIN_MAI_COST" 8 | }, 9 | "author": "thelickuidator", 10 | "license": "ISC", 11 | "dependencies": { 12 | "big-number": "^2.0.0", 13 | "bignumber.js": "^9.0.1", 14 | "body-parser": "^1.18.2", 15 | "compression": "^1.7.2", 16 | "console-stamp": "^3.0.3", 17 | "cors": "^2.8.4", 18 | "ethereum-input-data-decoder": "^0.3.1", 19 | "ethereumjs-abi": "^0.6.8", 20 | "ethers": "^5.1.0", 21 | "request": "^2.88.0", 22 | "request-promise": "^4.2.2", 23 | "sleep-promise": "^9.1.0", 24 | "web3": "^1.3.4" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /client/src/abi_erc20.js: -------------------------------------------------------------------------------- 1 | const abi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"dutchAuction","type":"address"},{"name":"owners","type":"address[]"},{"name":"tokens","type":"uint256[]"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}] 2 | 3 | module.exports = abi 4 | -------------------------------------------------------------------------------- /client/src/chainlink_price_source_abi.json: -------------------------------------------------------------------------------- 1 | [{"inputs":[{"internalType":"address","name":"_aggregator","type":"address"},{"internalType":"address","name":"_accessController","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"int256","name":"current","type":"int256"},{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"updatedAt","type":"uint256"}],"name":"AnswerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":true,"internalType":"address","name":"startedBy","type":"address"},{"indexed":false,"internalType":"uint256","name":"startedAt","type":"uint256"}],"name":"NewRound","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"OwnershipTransferRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"accessController","outputs":[{"internalType":"contract AccessControllerInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"aggregator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_aggregator","type":"address"}],"name":"confirmAggregator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"description","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_roundId","type":"uint256"}],"name":"getAnswer","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"_roundId","type":"uint80"}],"name":"getRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_roundId","type":"uint256"}],"name":"getTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestAnswer","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"}],"name":"phaseAggregators","outputs":[{"internalType":"contract AggregatorV2V3Interface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"phaseId","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_aggregator","type":"address"}],"name":"proposeAggregator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proposedAggregator","outputs":[{"internalType":"contract AggregatorV2V3Interface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"_roundId","type":"uint80"}],"name":"proposedGetRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proposedLatestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_accessController","type":"address"}],"name":"setController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}] -------------------------------------------------------------------------------- /client/src/chainlink_price_source_cam_abi.json: -------------------------------------------------------------------------------- 1 | [{"inputs":[{"internalType":"address","name":"_priceSource","type":"address"},{"internalType":"address","name":"_underlying","type":"address"},{"internalType":"address","name":"_shares","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint80","name":"roundId","type":"uint80"},{"indexed":false,"internalType":"int256","name":"price","type":"int256"},{"indexed":false,"internalType":"uint256","name":"startedAt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"updatedAt","type":"uint256"},{"indexed":false,"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"name":"FallbackPrice","type":"event"},{"constant":true,"inputs":[],"name":"fallbackPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"priceSource","outputs":[{"internalType":"contract PriceSource","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"shares","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"underlying","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"updateFallbackPrice","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /client/src/networks.json: -------------------------------------------------------------------------------- 1 | { 2 | "matic": { 3 | "rpc": { 4 | "url": "https://polygon-rpc.com/" 5 | }, 6 | "contracts": { 7 | "mai": "0xa3Fa99A148fA48D14Ed51d610c367C61876997F1", 8 | "usdc": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174" 9 | }, 10 | "qidao_vaults": { 11 | "matic": "0x595b3e98641c4d66900a24aa6ada590b41ef85aa", 12 | "WEMVT": "0x3fd939b017b31eaadf9ae50c7ff7fa5c0661d47c", 13 | "GMVT": "0xF086dEdf6a89e7B16145b03a6CB0C0a9979F1433", 14 | "camDAIMVT": "0xD2FE44055b5C874feE029119f70336447c8e8827", 15 | "SDAM3CRVMVT": "0x57Cbf36788113237D64E46f25A88855c3dff1691", 16 | "camWEMVT": "0x11A33631a5B5349AF3F165d2B7901A4d67e561ad", 17 | "camAMVT": "0x578375c3af7d61586c2C3A7BA87d2eEd640EFA40", 18 | "dQMVT": "0x649Aa6E6b6194250C077DF4fB37c23EE6c098513", 19 | "BMVT": "0x701A1824e5574B0b6b1c8dA808B184a7AB7A2867", 20 | "CMVT": "0x98B5F32dd9670191568b661a3e847Ed764943875", 21 | "AMVT": "0x87ee36f780ae843A78D5735867bc1c13792b7b11", 22 | "camWBMVT": "0x7dDA5e1A389E0C1892CaF55940F5fcE6588a9ae0", 23 | "cMVT": "0x88d84a85A87ED12B8f098e8953B322fF789fCD1a", 24 | "LMVT": "0x61167073E31b1DAd85a3E531211c7B8F1E5cAE72", 25 | "WBMVT": "0x37131aEDd3da288467B6EBe9A77C523A700E6Ca1" 26 | }, 27 | "qidao_vaults_url_slug": { 28 | "matic": "matic", 29 | "WEMVT": "weth", 30 | "GMVT": "ghst", 31 | "camDAIMVT": "camdai", 32 | "SDAM3CRVMVT": "sdam3crv", 33 | "camWEMVT": "camweth", 34 | "camAMVT": "camaave", 35 | "dQMVT": "dquick", 36 | "BMVT": "bal", 37 | "CMVT": "crv", 38 | "AMVT": "aave", 39 | "camWBMVT": "camwbtc", 40 | "cMVT": "camwmatic", 41 | "LMVT": "link", 42 | "WBMVT": "wbtc" 43 | } 44 | }, 45 | 46 | "ftm": { 47 | "rpc": { 48 | "url": "https://ftmrpc.ultimatenodes.io/" 49 | }, 50 | "qidao_vaults": { 51 | "mBIFIMVT": "0x75D4aB6843593C111Eeb02Ff07055009c836A1EF", 52 | "WFTM": "0x1066b8FC999c1eE94241344818486D5f944331A0", 53 | "WETH": "0xD939c268C49c442F037E968F045ba02f499562D4", 54 | "yvWFTM": "0x7efB260662a6FA95c1CE1092c53Ca23733202798", 55 | "yvDAI": "0x682E473FcA490B0adFA7EfE94083C1E63f28F034", 56 | "BTC": "0xE5996a2cB60eA57F03bf332b5ADC517035d8d094", 57 | "LINK": "0xd6488d586E8Fcd53220e4804D767F19F5C846086", 58 | "SUSHI": "0x267bDD1C19C932CE03c7A62BBe5b95375F9160A6", 59 | "AAVE": "0xdB09908b82499CAdb9E6108444D5042f81569bD9", 60 | "mooScreamFTM": "0x3609A304c6A41d87E895b9c1fd18c02ba989Ba90", 61 | "mooScreamETH": "0xC1c7eF18ABC94013F6c58C6CdF9e829A48075b4e", 62 | "mooScreamBTC": "0x5563Cc1ee23c4b17C861418cFF16641D46E12436", 63 | "mooScreamLINK": "0x8e5e4D08485673770Ab372c05f95081BE0636Fa2", 64 | "mooScreamDAI": "0xBf0ff8ac03f3E0DD7d8faA9b571ebA999a854146", 65 | "mooBooBTC-FTM": "0xf34e271312e41bbd7c451b76af2af8339d6f16ed", 66 | "mooBooETH-FTM": "0x9ba01b1279b1f7152b42aca69faf756029a9abde", 67 | "mooBIFI": "0x75d4ab6843593c111eeb02ff07055009c836a1ef" 68 | }, 69 | "qidao_vaults_url_slug": { 70 | "mBIFIMVT": "beefy-bifi", 71 | "WFTM": "ftm", 72 | "WETH": "ftmweth", 73 | "yvWFTM": "yvwftm", 74 | "yvDAI": "yvwdai", 75 | "BTC": "btc", 76 | "LINK": "link", 77 | "SUSHI": "sushi", 78 | "AAVE": "aave", 79 | "mooScreamFTM": "beefy-scream-ftm", 80 | "mooScreamETH": "beefy-scream-eth", 81 | "mooScreamBTC": "beefy-scream-wbtc", 82 | "mooScreamLINK": "beefy-scream-link", 83 | "mooScreamDAI": "beefy-scream-dai", 84 | "mooBooBTC-FTM": "beefy-spooky-btc-ftm", 85 | "mooBooETH-FTM": "beefy-spooky-eth-ftm", 86 | "mooBIFI": "beefy-bifi" 87 | } 88 | }, 89 | "avax": { 90 | "rpc": { 91 | "url": "https://api.avax.network/ext/bc/C/rpc" 92 | }, 93 | "qidao_vaults": { 94 | "moaAVXMVT": "0xfA19c1d104F4AEfb8d5564f02B3AdCa1b515da58" 95 | }, 96 | "qidao_vaults_url_slug": { 97 | "moaAVXMVT": "beefy-aave-avax" 98 | } 99 | }, 100 | 101 | "arbitrum": { 102 | "rpc": { 103 | "url": "https://arb1.arbitrum.io/rpc" 104 | }, 105 | "qidao_vaults": { 106 | "AEMVT": "0xf5c2b1b92456fe1b1208c63d8ea040d464f74a72" 107 | }, 108 | "qidao_vaults_url_slug": { 109 | "AEMVT": "weth" 110 | } 111 | }, 112 | 113 | "moonriver": { 114 | "rpc": { 115 | "url": "https://rpc.moonriver.moonbeam.network" 116 | }, 117 | "qidao_vaults": { 118 | "ETHMVT": "0x4a0474E3262d4DB3306Cea4F207B5d66eC8E0AA9", 119 | "mooSolar-ETHUSDCMVT": "0x97D811A7eb99Ef4Cb027ad59800cE27E68Ee1109", 120 | "MOVRMVT": "0x5dB6617DDF077d76CFD9d7fC0Fa91aAabc3da683", 121 | "mooSolar-ETHUSDCMVT": "0x97D811A7eb99Ef4Cb027ad59800cE27E68Ee1109", 122 | "mooSolar-MOVRUSDCMVT": "0xF4fa968578723580935a00d1e12Fe96Bc6401947" 123 | }, 124 | "qidao_vaults_url_slug": { 125 | "ETHMVT": "eth", 126 | "mooSolar-ETHUSDCMVT": "moo-solar-eth-usdc", 127 | "mooSolar-MOVRUSDCMVT": "moo-solar-movr-usdc", 128 | "MOVRMVT": "movr" 129 | } 130 | } 131 | } 132 | 133 | -------------------------------------------------------------------------------- /client/src/qidao_vault_abi.json: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[{"name":"_vaultId","type":"uint256"}],"name":"checkCost","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"checkMimaticBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"gainRatio","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_vaultId","type":"uint256"}],"name":"checkExtract","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_admin","type":"address"}],"name":"setAdmin","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_vaultId","type":"uint256"}],"name":"checkCollat","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_vaultId","type":"uint256"}],"name":"checkValid","outputs":[{"name":"","type":"bool"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_vaultId","type":"uint256"}],"name":"liquidateVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"maticDebt","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_vaultId","type":"uint256"}],"name":"checkLiquidation","outputs":[],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"debtRatio","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"getPaid","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_debtRatio","type":"uint256"}],"name":"setDebtRatio","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"admin","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_gainRatio","type":"uint256"}],"name":"setGainRatio","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_vaultContract","type":"address"},{"name":"_mimatic","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"}] 2 | -------------------------------------------------------------------------------- /client/src/qidao_vault_abi_weth.json: -------------------------------------------------------------------------------- 1 | [{"inputs":[{"internalType":"address","name":"ethPriceSourceAddress","type":"address"},{"internalType":"uint256","name":"minimumCollateralPercentage","type":"uint256"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"address","name":"_mai","type":"address"},{"internalType":"address","name":"_collateral","type":"address"},{"internalType":"address","name":"meta","type":"address"},{"internalType":"string","name":"baseURI","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"vaultID","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"BorrowToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"vaultID","type":"uint256"},{"indexed":false,"internalType":"address","name":"creator","type":"address"}],"name":"CreateVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"vaultID","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DepositCollateral","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"vaultID","type":"uint256"}],"name":"DestroyVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"vaultID","type":"uint256"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"uint256","name":"debtRepaid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralLiquidated","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"closingFee","type":"uint256"}],"name":"LiquidateVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"vaultID","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"closingFee","type":"uint256"}],"name":"PayBackToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"vaultID","type":"uint256"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"}],"name":"TransferVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"vaultID","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawCollateral","type":"event"},{"constant":true,"inputs":[],"name":"_meta","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_minimumCollateralPercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"base","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"baseURI","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"borrowToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"ethPriceSourceAddress","type":"address"}],"name":"changeEthPriceSource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"}],"name":"checkCollateralPercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"}],"name":"checkCost","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"}],"name":"checkExtract","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"}],"name":"checkLiquidation","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"closingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"collateral","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"collateralDecimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"createVault","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"debtRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositCollateral","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"}],"name":"destroyVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"ethPriceSource","outputs":[{"internalType":"contract shareOracle","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"gainRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getClosingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getDebtCeiling","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getEthPriceSource","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getOpeningFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"getPaid","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getTokenPriceSource","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"}],"name":"liquidateVault","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"mai","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maticDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"openingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"payBackToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"string","name":"baseURI","type":"string"}],"name":"setBaseURI","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"setClosingFee","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_debtRatio","type":"uint256"}],"name":"setDebtRatio","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_gainRatio","type":"uint256"}],"name":"setGainRatio","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"minimumCollateralPercentage","type":"uint256"}],"name":"setMinCollateralRatio","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"setOpeningFee","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_pool","type":"address"}],"name":"setStabilityPool","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_tokenPeg","type":"uint256"}],"name":"setTokenPeg","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_treasury","type":"uint256"}],"name":"setTreasury","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"stabilityPool","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenPeg","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"}],"name":"transferToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountToken","type":"uint256"}],"name":"transferToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"treasury","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"vaultCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"vaultCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"vaultDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"vaultID","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawCollateral","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] 2 | -------------------------------------------------------------------------------- /client/src/slugs.json: -------------------------------------------------------------------------------- 1 | La = [{ 2 | slug: "camwmatic", 3 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-amwmatic-vaults", 4 | vaultAddress: "0x88d84a85A87ED12B8f098e8953B322fF789fCD1a", 5 | token: new N.q(N.b.MATIC,"0x7068ea5255cb05931efa8026bd04b18f3deb8b0b",18,"camWMATIC","Compounding Aave Market MATIC"), 6 | minimumCDR: 135, 7 | aaveId: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf12700xd05e3e715d945b59290df0ae8ef85c1bdb684744", 8 | camMeta: { 9 | zappable: !0, 10 | underlying: new N.q(N.b.MATIC,"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",18,"WMATIC","Wrapped MATIC"), 11 | amToken: new N.q(N.b.MATIC,"0x8dF3aad3a84da6b69A4DA8aeC3eA40d9091B2Ac4",18,"amWMATIC","Aave Matic Market WMATIC"), 12 | camToken: new N.q(N.b.MATIC,"0x7068Ea5255cb05931EFa8026Bd04b18F3DeB8b0B",18,"camWMATIC","Compounding Aave Market Wrapped MATIC") 13 | } 14 | }, { 15 | slug: "weth", 16 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/mai-finance-weth-vaults", 17 | vaultAddress: "0x3fd939B017b31eaADF9ae50C7fF7Fa5c0661d47C", 18 | token: new N.q(N.b.MATIC,"0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",18,"WETH","Wrapped Ether"), 19 | minimumCDR: 130 20 | }, { 21 | slug: "camweth", 22 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/mai-finance-cam-weth-vaults", 23 | vaultAddress: "0x11A33631a5B5349AF3F165d2B7901A4d67e561ad", 24 | token: new N.q(N.b.MATIC,"0x0470cd31c8fcc42671465880ba81d631f0b76c1d",18,"camWETH","Compounding Aave Market WETH"), 25 | minimumCDR: 135, 26 | aaveId: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f6190xd05e3e715d945b59290df0ae8ef85c1bdb684744", 27 | camMeta: { 28 | zappable: !0, 29 | underlying: new N.q(N.b.MATIC,"0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",18,"WETH","Wrapped Ether"), 30 | amToken: new N.q(N.b.MATIC,"0x28424507fefb6f7f8E9D3860F56504E4e5f5f390",18,"amWETH","Aave Matic Market WETH"), 31 | camToken: new N.q(N.b.MATIC,"0x0470cd31c8fcc42671465880ba81d631f0b76c1d",18,"camWETH","Compounding Aave Market WETH") 32 | } 33 | }, { 34 | slug: "camaave", 35 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/mai-finance-cam-aave-vaults", 36 | vaultAddress: "0x578375c3af7d61586c2C3A7BA87d2eEd640EFA40", 37 | token: new N.q(N.b.MATIC,"0xeA4040B21cb68afb94889cB60834b13427CFc4EB",18,"camAAVE","Compounding Aave Market AAVE"), 38 | minimumCDR: 135, 39 | aaveId: "0xd6df932a45c0f255f85145f286ea0b292b21c90b0xd05e3e715d945b59290df0ae8ef85c1bdb684744", 40 | camMeta: { 41 | zappable: !0, 42 | underlying: new N.q(N.b.MATIC,"0xD6DF932A45C0f255f85145f286eA0b292B21C90B",18,"AAVE","Aave"), 43 | amToken: new N.q(N.b.MATIC,"0x1d2a0E5EC8E5bBDCA5CB219e649B565d8e5c3360",18,"amAAVE","Aave Matic Market AAVE"), 44 | camToken: new N.q(N.b.MATIC,"0xeA4040B21cb68afb94889cB60834b13427CFc4EB",18,"camAAVE","Compounding Aave Market AAVE") 45 | } 46 | }, { 47 | slug: "aave", 48 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/mai-finance-aave-vaults", 49 | vaultAddress: "0x87ee36f780ae843A78D5735867bc1c13792b7b11", 50 | token: new N.q(N.b.MATIC,"0xD6DF932A45C0f255f85145f286eA0b292B21C90B",18,"AAVE","Aave"), 51 | minimumCDR: 130 52 | }, { 53 | slug: "link", 54 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/mai-finance-link-vaults", 55 | vaultAddress: "0x61167073E31b1DAd85a3E531211c7B8F1E5cAE72", 56 | token: new N.q(N.b.MATIC,"0x53E0bca35eC356BD5ddDFebbD1Fc0fD03FaBad39",18,"LINK","ChainLink Token"), 57 | minimumCDR: 130 58 | }, { 59 | slug: "crv", 60 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/mai-finance-curve-vaults", 61 | vaultAddress: "0x98B5F32dd9670191568b661a3e847Ed764943875", 62 | token: new N.q(N.b.MATIC,"0x172370d5Cd63279eFa6d502DAB29171933a610AF",18,"CRV","Curve Dao Token"), 63 | minimumCDR: 130 64 | }, { 65 | slug: "wbtc", 66 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-wbtc-vaults", 67 | vaultAddress: "0x37131aEDd3da288467B6EBe9A77C523A700E6Ca1", 68 | token: new N.q(N.b.MATIC,"0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6",8,"WBTC","Wrapped BTC"), 69 | minimumCDR: 130 70 | }, { 71 | slug: "camwbtc", 72 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-cam-wbtc-vaults", 73 | vaultAddress: "0x7dDA5e1A389E0C1892CaF55940F5fcE6588a9ae0", 74 | token: new N.q(N.b.MATIC,"0xBa6273A78a23169e01317bd0f6338547F869E8Df",8,"camWBTC","Compounding Aave Market WBTC"), 75 | minimumCDR: 135, 76 | aaveId: "0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd60xd05e3e715d945b59290df0ae8ef85c1bdb684744", 77 | camMeta: { 78 | zappable: !0, 79 | underlying: new N.q(N.b.MATIC,"0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",8,"WBTC","Wrapped BTC"), 80 | amToken: new N.q(N.b.MATIC,"0x5c2ed810328349100A66B82b78a1791B101C9D61",8,"amWBTC","Aave Matic Market WBTC"), 81 | camToken: new N.q(N.b.MATIC,"0xBa6273A78a23169e01317bd0f6338547F869E8Df",8,"camWBTC","Compounding Aave Market WBTC") 82 | } 83 | }, { 84 | slug: "bal-old", 85 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-bal-vaults", 86 | vaultAddress: "0xf6906b1Cf79Ab14c79DdC7D763c1A517cF9968A5", 87 | token: new N.q(N.b.MATIC,"0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3",18,"BAL OLD","Balancer"), 88 | minimumCDR: 130, 89 | deprecated: !0 90 | }, { 91 | slug: "dquick-old", 92 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-dquick-vaults", 93 | vaultAddress: "0x9e6e3e8161Fffb31a6030E56a3E024842567154F", 94 | token: new N.q(N.b.MATIC,"0xf28164A485B0B2C90639E47b0f377b4a438a16B1",18,"dQUICK OLD","Dragon QUICK"), 95 | minimumCDR: 130, 96 | deprecated: !0 97 | }, { 98 | slug: "bal", 99 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-bal-vaults-v2", 100 | vaultAddress: "0x701A1824e5574B0b6b1c8dA808B184a7AB7A2867", 101 | token: new N.q(N.b.MATIC,"0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3",18,"BAL","Balancer"), 102 | minimumCDR: 130 103 | }, { 104 | slug: "dquick", 105 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-dquick-vaults-v2", 106 | vaultAddress: "0x649Aa6E6b6194250C077DF4fB37c23EE6c098513", 107 | token: new N.q(N.b.MATIC,"0xf28164A485B0B2C90639E47b0f377b4a438a16B1",18,"dQUICK","Dragon QUICK"), 108 | minimumCDR: 130 109 | }, { 110 | slug: "ghst", 111 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-ghst-vaults", 112 | vaultAddress: "0xF086dEdf6a89e7B16145b03a6CB0C0a9979F1433", 113 | token: new N.q(N.b.MATIC,"0x385eeac5cb85a38a9a07a70c73e0a3271cfb54a7",18,"GHST","Aavegotchi GHST"), 114 | minimumCDR: 130 115 | }, { 116 | slug: "camdai", 117 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-camdai-vaults", 118 | vaultAddress: "0xD2FE44055b5C874feE029119f70336447c8e8827", 119 | token: new N.q(N.b.MATIC,"0xe6c23289ba5a9f0ef31b8eb36241d5c800889b7b",18,"camDAI","Compounding Aave Market DAI"), 120 | minimumCDR: 110, 121 | aaveId: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a0630xd05e3e715d945b59290df0ae8ef85c1bdb684744", 122 | camMeta: { 123 | zappable: !0, 124 | underlying: new N.q(N.b.MATIC,"0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",18,"DAI","Dai Stablecoin"), 125 | amToken: new N.q(N.b.MATIC,"0x27F8D03b3a2196956ED754baDc28D73be8830A6e",18,"amDAI","Aave Matic Market DAI"), 126 | camToken: new N.q(N.b.MATIC,"0xE6C23289Ba5A9F0Ef31b8EB36241D5c800889b7b",18,"camDAI","Compounding Aave Matic Market DAI") 127 | } 128 | }, { 129 | slug: "sdam3crv", 130 | vaultAddress: "0x57Cbf36788113237D64E46f25A88855c3dff1691", 131 | subgraph: "", 132 | minimumCDR: 135, 133 | token: new N.q(N.b.MATIC,"0x7d60F21072b585351dFd5E8b17109458D97ec120",18,"sdam3CRV","Stake DAO am3CRV Strategy") 134 | }], Wa = (Te = {}, 135 | Object(W.a)(Te, N.b.AVALANCHE, []), 136 | Object(W.a)(Te, N.b.FANTOM, [{ 137 | slug: "ftm", 138 | vaultAddress: "0x1066b8FC999c1eE94241344818486D5f944331A0", 139 | chainId: N.b.FANTOM, 140 | token: new N.q(N.b.FANTOM,"0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83",18,"FTM","Fantom"), 141 | minimumCDR: 130, 142 | native: !0, 143 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-fantom-vaults" 144 | }, { 145 | slug: "yvwftm", 146 | vaultAddress: "0x7efB260662a6FA95c1CE1092c53Ca23733202798", 147 | chainId: N.b.FANTOM, 148 | token: new N.q(N.b.FANTOM,"0x0DEC85e74A92c52b7F708c4B10207D9560CEFaf0",18,"yvWFTM","Yearn Fantom"), 149 | minimumCDR: 135, 150 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-yvwftm-vaults" 151 | }, { 152 | slug: "yvwdai", 153 | vaultAddress: "0x682E473FcA490B0adFA7EfE94083C1E63f28F034", 154 | chainId: N.b.FANTOM, 155 | token: new N.q(N.b.FANTOM,"0x637eC617c86D24E421328e6CAEa1d92114892439",18,"yvDAI","Yearn DAI"), 156 | minimumCDR: 110, 157 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-yvdai-vaults" 158 | }, { 159 | slug: "ftmweth", 160 | vaultAddress: "0xD939c268C49c442F037E968F045ba02f499562D4", 161 | chainId: N.b.FANTOM, 162 | token: new N.q(N.b.FANTOM,"0x74b23882a30290451A17c44f4F05243b6b58C76d",18,"ETH","Ethereum"), 163 | minimumCDR: 135, 164 | subgraph: "https://api.thegraph.com/subgraphs/name/0xlaozi/qi-dao-fantom-eth-vaults" 165 | }, { 166 | slug: "aave", 167 | vaultAddress: "0xdB09908b82499CAdb9E6108444D5042f81569bD9", 168 | chainId: N.b.FANTOM, 169 | token: new N.q(N.b.FANTOM,"0x6a07A792ab2965C72a5B8088d3a069A7aC3a993B",18,"AAVE","Aave"), 170 | minimumCDR: 130 171 | }, { 172 | slug: "sushi", 173 | vaultAddress: "0x267bDD1C19C932CE03c7A62BBe5b95375F9160A6", 174 | chainId: N.b.FANTOM, 175 | token: new N.q(N.b.FANTOM,"0xae75A438b2E0cB8Bb01Ec1E1e376De11D44477CC",18,"SUSHI","Sushi"), 176 | minimumCDR: 130 177 | }, { 178 | slug: "link", 179 | vaultAddress: "0xd6488d586E8Fcd53220e4804D767F19F5C846086", 180 | chainId: N.b.FANTOM, 181 | token: new N.q(N.b.FANTOM,"0xb3654dc3D10Ea7645f8319668E8F54d2574FBdC8",18,"LINK","ChainLink"), 182 | minimumCDR: 130 183 | }, { 184 | slug: "btc", 185 | vaultAddress: "0xE5996a2cB60eA57F03bf332b5ADC517035d8d094", 186 | chainId: N.b.FANTOM, 187 | token: new N.q(N.b.FANTOM,"0x321162Cd933E2Be498Cd2267a90534A804051b11",8,"BTC","Bitcoin"), 188 | minimumCDR: 130 189 | }, { 190 | slug: "beefy-scream-wbtc", 191 | vaultAddress: "0x5563Cc1ee23c4b17C861418cFF16641D46E12436", 192 | chainId: N.b.FANTOM, 193 | token: new N.q(N.b.FANTOM,"0x97927aBfE1aBBE5429cBe79260B290222fC9fbba",18,"mooScreamWBTC","Beefy Scream WBTC"), 194 | minimumCDR: 135 195 | }, { 196 | slug: "beefy-scream-dai", 197 | vaultAddress: "0xBf0ff8ac03f3E0DD7d8faA9b571ebA999a854146", 198 | chainId: N.b.FANTOM, 199 | token: new N.q(N.b.FANTOM,"0x920786cff2A6f601975874Bb24C63f0115Df7dc8",18,"mooScreamDAI","Beefy Scream DAI"), 200 | minimumCDR: 135 201 | }, { 202 | slug: "beefy-scream-eth", 203 | vaultAddress: "0xC1c7eF18ABC94013F6c58C6CdF9e829A48075b4e", 204 | chainId: N.b.FANTOM, 205 | token: new N.q(N.b.FANTOM,"0x0a03D2C1cFcA48075992d810cc69Bd9FE026384a",18,"mooScreamETH","Beefy Scream ETH"), 206 | minimumCDR: 135 207 | }, { 208 | slug: "beefy-scream-ftm", 209 | vaultAddress: "0x3609A304c6A41d87E895b9c1fd18c02ba989Ba90", 210 | chainId: N.b.FANTOM, 211 | token: new N.q(N.b.FANTOM,"0x49c68eDb7aeBd968F197121453e41b8704AcdE0C",18,"mooScreamFTM","Beefy Scream FTM"), 212 | minimumCDR: 135 213 | }, { 214 | slug: "beefy-scream-link", 215 | vaultAddress: "0x8e5e4D08485673770Ab372c05f95081BE0636Fa2", 216 | chainId: N.b.FANTOM, 217 | token: new N.q(N.b.FANTOM,"0x6DfE2AAEA9dAadADf0865B661b53040E842640f8",18,"mooScreamLINK","Beefy Scream LINK"), 218 | minimumCDR: 135 219 | }, { 220 | slug: "beefy-spooky-btc-ftm", 221 | vaultAddress: "0xF34e271312e41Bbd7c451B76Af2AF8339D6f16ED", 222 | deprecated: !0, 223 | chainId: N.b.FANTOM, 224 | token: new N.q(N.b.FANTOM,"0xA3e3Af161943CfB3941B631676134bb048739727",18,"mooBooBTC-FTM","Beefy SpookySwap BTC-FTM LP"), 225 | minimumCDR: 135 226 | }, { 227 | slug: "beefy-spooky-eth-ftm", 228 | vaultAddress: "0x9BA01B1279B1F7152b42aCa69fAF756029A9ABDe", 229 | deprecated: !0, 230 | chainId: N.b.FANTOM, 231 | token: new N.q(N.b.FANTOM,"0x2a30C5e0d577108F694d2A96179cd73611Ee069b",18,"mooBooETH-FTM","Beefy SpookySwap ETH-FTM LP"), 232 | minimumCDR: 135 233 | }, { 234 | slug: "beefy-bifi", 235 | vaultAddress: "0x75D4aB6843593C111Eeb02Ff07055009c836A1EF", 236 | chainId: N.b.FANTOM, 237 | token: new N.q(N.b.FANTOM,"0xbF07093ccd6adFC3dEB259C557b61E94c1F66945",18,"mooFantomBIFI","Beefy Staked BIFI"), 238 | minimumCDR: 140 239 | }]), 240 | Object(W.a)(Te, N.b.AVALANCHE, [{ 241 | slug: "beefy-aave-avax", 242 | vaultAddress: "0xfA19c1d104F4AEfb8d5564f02B3AdCa1b515da58", 243 | chainId: N.b.AVALANCHE, 244 | token: new N.q(N.b.AVALANCHE,"0x1B156C5c75E9dF4CAAb2a5cc5999aC58ff4F9090",18,"mooAaveAVAX","Beefy Aave AVAX"), 245 | minimumCDR: 135 246 | }]), 247 | Object(W.a)(Te, N.b.ARBITRUM, [{ 248 | slug: "weth", 249 | deprecated: !0, 250 | vaultAddress: "0xf5c2b1b92456fe1b1208c63d8ea040d464f74a72", 251 | chainId: N.b.ARBITRUM, 252 | token: new N.q(N.b.ARBITRUM,"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",18,"WETH","Wrapped Ether"), 253 | minimumCDR: 135 254 | }]), 255 | Object(W.a)(Te, N.b.MOONRIVER, [{ 256 | slug: "eth", 257 | vaultAddress: "0x4a0474E3262d4DB3306Cea4F207B5d66eC8E0AA9", 258 | chainId: N.b.MOONRIVER, 259 | token: new N.q(N.b.MOONRIVER,"0x639A647fbe20b6c8ac19E48E2de44ea792c62c5C",18,"ETH","Ethereum"), 260 | minimumCDR: 130 261 | }, { 262 | slug: "moo-solar-eth-usdc", 263 | vaultAddress: "0x97D811A7eb99Ef4Cb027ad59800cE27E68Ee1109", 264 | deprecated: !0, 265 | chainId: N.b.MOONRIVER, 266 | token: new N.q(N.b.MOONRIVER,"0x932009984bd2a7dA8C6396694E811Da5C0952d05",18,"mooSolarETH-USDC","Beefy Solarbeam ETH-USDC LP"), 267 | minimumCDR: 135 268 | }, { 269 | slug: "movr", 270 | native: !0, 271 | vaultAddress: "0x5dB6617DDF077d76CFD9d7fC0Fa91aAabc3da683", 272 | chainId: N.b.MOONRIVER, 273 | token: new N.q(N.b.MOONRIVER,"0x98878B06940aE243284CA214f92Bb71a2b032B8A",18,"MOVR","Moonriver"), 274 | minimumCDR: 130 275 | }, { 276 | slug: "moo-solar-movr-usdc", 277 | vaultAddress: "0xF4fa968578723580935a00d1e12Fe96Bc6401947", 278 | deprecated: !0, 279 | chainId: N.b.MOONRIVER, 280 | token: new N.q(N.b.MOONRIVER,"0x78Dc4b7C7A89812fb337dD8C3B0ccB3e04E02D7C",18,"mooSolarMOVR-USDC","Beefy Solarbeam MOVR-USDC LP"), 281 | minimumCDR: 135 282 | }]), 283 | Object(W.a)(Te, N.b.HARMONY, [{ 284 | slug: "eth", 285 | vaultAddress: "0x46469f995A5CB60708200C25EaD3cF1667Ed36d6", 286 | chainId: N.b.HARMONY, 287 | token: new N.q(N.b.HARMONY,"0x6983d1e6def3690c4d616b13597a09e6193ea013",18,"1ETH","Wrapped Ethereum"), 288 | minimumCDR: 130 289 | }, { 290 | slug: "one", 291 | vaultAddress: "0x12FcB286D664F37981a42cbAce92eAf28d1dA94f", 292 | native: !0, 293 | chainId: N.b.HARMONY, 294 | token: new N.q(N.b.HARMONY,"0xcF664087a5bB0237a0BAd6742852ec6c8d69A27a",18,"ONE","Harmony (ONE)"), 295 | minimumCDR: 130 296 | }, { 297 | slug: "btc_old", 298 | vaultAddress: "0x9f4E3d01c634441F284beb92bBAEeb76133BbB28", 299 | deprecated: !0, 300 | chainId: N.b.HARMONY, 301 | token: new N.q(N.b.HARMONY,"0x3095c7557bCb296ccc6e363DE01b760bA031F2d9",8,"1WBTC OLD","Wrapped Bitcoin OLD"), 302 | minimumCDR: 130 303 | }, { 304 | slug: "btc", 305 | vaultAddress: "0x4592e0bcf01121757e70404915f220a77ffb4e15", 306 | chainId: N.b.HARMONY, 307 | token: new N.q(N.b.HARMONY,"0x3095c7557bCb296ccc6e363DE01b760bA031F2d9",8,"1WBTC","Wrapped Bitcoin"), 308 | minimumCDR: 130, 309 | deprecated: !0 310 | }]), 311 | -------------------------------------------------------------------------------- /client/utils.js: -------------------------------------------------------------------------------- 1 | const ethers = require("ethers") 2 | const Web3 = require("web3") 3 | const BigNumber = require('big-number') 4 | const InputDataDecoder = require('ethereum-input-data-decoder') 5 | const sleep = require('sleep-promise') 6 | 7 | const ERC20_ABI = require('./src/abi_erc20') 8 | const QIDAO_VAULT_ABI = require("./src/qidao_vault_abi.json") 9 | const QIDAO_VAULT_ABI_WETH = require("./src/qidao_vault_abi_weth.json") 10 | 11 | const CHAINLINK_PRICE_SOURCE_ABI = require("./src/chainlink_price_source_abi.json") 12 | const CHAINLINK_PRICE_SOURCE_CAM_ABI = require("./src/chainlink_price_source_cam_abi.json") 13 | 14 | const NETWORKS = require("./src/networks.json") 15 | 16 | let DECODER = new InputDataDecoder(ERC20_ABI) 17 | require('console-stamp')(console, '[HH:MM:ss.l]'); 18 | 19 | let GAS_PRICE_MIN = 100 * (10 ** 9) 20 | let GAS_PRICE_MAX = 1000 * (10 ** 9) 21 | let GAS_PRICE = parseInt((GAS_PRICE_MIN + GAS_PRICE_MAX) / 2) 22 | 23 | function hex_to_ascii(str1) { 24 | var hex = str1.toString(); 25 | var str = ''; 26 | for (var n = 0; n < hex.length; n += 2) { 27 | str += String.fromCharCode(parseInt(hex.substr(n, 2), 16)); 28 | } 29 | return str; 30 | } 31 | 32 | async function reason(provider, hash) { 33 | 34 | let tx = await provider.getTransaction(hash) 35 | if (!tx) { 36 | console.log('tx not found') 37 | } else { 38 | let code = await provider.call(tx, tx.blockNumber) 39 | return hex_to_ascii(code.substr(138)) 40 | } 41 | } 42 | 43 | async function get_all_qidao_vaults(network_name, pool_contract_address, signer, cost_value, vault_name) { 44 | let NETWORK = NETWORKS[network_name] 45 | if (!NETWORK) { 46 | throw (`Network <${network_name}> not supported`) 47 | } 48 | const NETWORK_CONTRACTS = NETWORK["constracts"] 49 | const QIDAO_VAULTS = NETWORK["qidao_vaults"] 50 | const QIDAO_URL_SLUGS = NETWORK["qidao_vaults_url_slug"] 51 | 52 | let abi = QIDAO_VAULT_ABI_WETH 53 | let max_vault_nr = 100 54 | let tokenName = '' 55 | let pool_contract = await new ethers.Contract(pool_contract_address, abi, signer) 56 | if (pool_contract_address == NETWORKS["matic"]["qidao_vaults"]["matic"]) { 57 | abi = QIDAO_VAULT_ABI 58 | tokenName = "Matic" 59 | } else { 60 | max_vault_nr = await pool_contract.vaultCount() 61 | tokenName = await pool_contract.symbol() 62 | } 63 | for (let i = 0; i < max_vault_nr; i++) { 64 | try { 65 | let is_liquidable = await pool_contract.checkLiquidation(i); 66 | if (i % 50 == 0 && i > 0) { 67 | console.log(`Checked ${i} ${tokenName} vaults so far...`) 68 | } 69 | if (is_liquidable) { 70 | let check_extract = (parseInt(await pool_contract.checkExtract(i)) / 10 ** 18).toFixed(4) 71 | let check_cost = (parseInt(await pool_contract.checkCost(i)) / 10 ** 18).toFixed(4) 72 | let check_collateral_percentage = 0 73 | if (pool_contract_address == NETWORKS["matic"]["qidao_vaults"]["matic"]) { 74 | check_collateral_percentage = (parseInt(await pool_contract.checkCollat(i))).toFixed(4) 75 | } else { 76 | check_collateral_percentage = (parseInt(await pool_contract.checkCollateralPercentage(i))).toFixed(4) 77 | } 78 | if (check_cost >= cost_value) { 79 | let slug = QIDAO_URL_SLUGS[vault_name] || vault_name 80 | console.log(`Vault ${vault_name} ${i} is liquidable ${is_liquidable}. Cost and extract: ${check_cost} MAI, ${check_extract} ${tokenName}, collat % ${check_collateral_percentage}. app.mai.finance/vaults/${slug}/${i}`) 81 | } 82 | } 83 | } catch (ex) { 84 | console.log(`${ex}`) 85 | } 86 | } 87 | } 88 | 89 | async function get_vault_info(network_name, signer, vault_type, vault_id) { 90 | let NETWORK = NETWORKS[network_name] 91 | if (!NETWORK) { 92 | throw (`Network <${network_name}> not supported`) 93 | } 94 | const NETWORK_CONTRACTS = NETWORK["constracts"] 95 | const QIDAO_VAULTS = NETWORK["qidao_vaults"] 96 | 97 | let vault_contract_address = QIDAO_VAULTS[vault_type] 98 | 99 | let vault_info = { 100 | "id": vault_id, 101 | "name": vault_type, 102 | "contract": vault_contract_address, 103 | } 104 | 105 | let abi = QIDAO_VAULT_ABI_WETH 106 | let vault_contract = await new ethers.Contract(vault_contract_address, abi, signer) 107 | let collateral_decimals = 18 108 | 109 | try { 110 | vault_info.collateral_decimals = parseInt(await vault_contract.collateralDecimals()) 111 | // this is the chainlink decimal I think 112 | //collateral_decimals = vault_info.collateral_decimals 113 | } catch (ex) { 114 | console.log(`Vault vault_info.collateral_decimals cannot be retrieved`) 115 | //throw (`Vault ${vault_type}:${vault_id} does not exist`) 116 | } 117 | 118 | try { 119 | vault_info.min_collateral_percentage = (await vault_contract._minimumCollateralPercentage()).toString() 120 | } catch (ex){ 121 | console.log(`Vault vault_info.min_collateral_percentage cannot be retrieved`) 122 | } 123 | 124 | try { 125 | vault_info.price_source_address = (await vault_contract.ethPriceSource()) 126 | } catch (ex) { 127 | console.log(`Vault vault_info.price_source_address cannot be retrieved`) 128 | } 129 | 130 | try { 131 | let chainlink_price_source_contract = await new ethers.Contract(vault_info.price_source_address, CHAINLINK_PRICE_SOURCE_ABI, signer) 132 | vault_info.price_source_aggregator_address = await chainlink_price_source_contract.aggregator() 133 | } catch (ex) { 134 | console.log(`Vault vault_info.price_source_aggregator_address cannot be retrieved, maybe a wrapped token.`) 135 | // if there is no aggregator, it means this is a CAM token 136 | // with underlying shares 137 | try { 138 | let chainlink_price_source_cam_contract = await new ethers.Contract(vault_info.price_source_address, CHAINLINK_PRICE_SOURCE_CAM_ABI, signer) 139 | vault_info.price_source_aggregator_address_intermediate = await chainlink_price_source_cam_contract.priceSource() 140 | let chainlink_price_source_contract_last = await new ethers.Contract(vault_info.price_source_aggregator_address_intermediate, CHAINLINK_PRICE_SOURCE_ABI, signer) 141 | vault_info.price_source_aggregator_address = await chainlink_price_source_contract_last.aggregator() 142 | } catch(ex) { 143 | console.log(`Vault vault_info.price_source_aggregator_address cannot be retrieved, maybe a double wrapped token.`) 144 | } 145 | } 146 | 147 | try { 148 | vault_info.collateral_address = (await vault_contract.collateral()) 149 | } catch { 150 | console.log(`Vault vault_info.collateral_address cannot be retrieved`) 151 | } 152 | 153 | try { 154 | vault_info.collateral_raw = await vault_contract.vaultCollateral(vault_id) 155 | vault_info.collateral = (vault_info.collateral_raw / 10 ** collateral_decimals).toString() 156 | } catch { 157 | console.log(`Vault vault_info.collateral cannot be retrieved`) 158 | } 159 | 160 | try { 161 | vault_info.cost = (await vault_contract.checkCost(vault_id) / 10 ** collateral_decimals).toString() 162 | } catch { 163 | console.log(`Vault vault_info.cost cannot be retrieved`) 164 | } 165 | 166 | try { 167 | vault_info.collateral_percentage = (await vault_contract.checkCollateralPercentage(vault_id)).toString() 168 | } catch { 169 | console.log(`Vault vault_info.collateral_percentage cannot be retrieved`) 170 | } 171 | 172 | try { 173 | vault_info.extract = (await vault_contract.checkExtract(vault_id) / 10 ** collateral_decimals).toString() 174 | } catch { 175 | console.log(`Vault vault_info.extract cannot be retrieved`) 176 | } 177 | 178 | try { 179 | vault_info.is_liquidable = await vault_contract.checkLiquidation(vault_id) 180 | } catch { 181 | console.log(`Vault vault_info.is_liquidable cannot be retrieved`) 182 | } 183 | 184 | try { 185 | vault_info.mai_debt_raw = await vault_contract.vaultDebt(vault_id) 186 | vault_info.mai_debt = (await vault_contract.vaultDebt(vault_id) / 10 ** collateral_decimals).toString() 187 | } catch { 188 | console.log(`Vault vault_info.mai_debt cannot be retrieved`) 189 | } 190 | 191 | try { 192 | vault_info.mai_contract = (await vault_contract.mai()) 193 | } catch { 194 | console.log(`Vault vault_info.mai_contract cannot be retrieved`) 195 | } 196 | if (vault_info.mai_contract.toLowerCase() != "0xa3Fa99A148fA48D14Ed51d610c367C61876997F1".toLowerCase()) { 197 | throw (`MAI contract does not match the correct one ${vault_info.mai_contract}`) 198 | } 199 | 200 | try { 201 | vault_info.collateral_usdc_price = (await vault_contract.getEthPriceSource() / 10 ** 8).toString() 202 | vault_info.collateral_usdc_price_raw = parseInt(await vault_contract.getEthPriceSource()) 203 | } catch { 204 | console.log(`Vault vault_info.vault_info.collateral_usdc_price cannot be retrieved`) 205 | } 206 | 207 | vault_info.debt_usdc = vault_info.mai_debt 208 | vault_info.collateral_usdc_raw = vault_info.collateral_usdc_price_raw * vault_info.collateral_raw 209 | vault_info.collateral_usdc = vault_info.collateral_usdc_raw / 10 ** 18 / 10 ** 8 210 | vault_info.collateral_to_debt = vault_info.collateral_usdc_raw / vault_info.debt_usdc / 10 ** (18 + 8 - 2) 211 | 212 | vault_info.liquidation_collateral_price_raw = parseInt(vault_info.min_collateral_percentage) * (vault_info.debt_usdc * 10 ** (18 + 8 - 2)) / vault_info.collateral_raw 213 | vault_info.liquidation_collateral_price = vault_info.liquidation_collateral_price_raw / 10 ** (8) 214 | 215 | return vault_info 216 | } 217 | 218 | module.exports = { 219 | get_all_qidao_vaults, 220 | get_vault_info 221 | } 222 | 223 | -------------------------------------------------------------------------------- /contracts/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | artifacts 4 | artifacts/** 5 | cache 6 | cache/** 7 | -------------------------------------------------------------------------------- /contracts/contracts/BlackMagic.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma solidity 0.8.9; 3 | 4 | 5 | import { FlashLoanReceiverBase } from "./FlashLoanReceiverBase.sol"; 6 | import { ILendingPool, ILendingPoolAddressesProvider, IERC20 } from "./Interfaces.sol"; 7 | import { SafeMath } from "./Libraries.sol"; 8 | 9 | interface QidaoVault { 10 | function liquidateVault(uint256 vaultID) external; 11 | function checkLiquidation(uint256 vaultID) external view returns (bool); 12 | function getPaid() external; 13 | function checkCost(uint256 vaultID) external view returns (uint256); 14 | function collateral() external view returns (address); 15 | } 16 | 17 | interface IAsset { 18 | // solhint-disable-previous-line no-empty-blocks 19 | } 20 | 21 | enum SwapKind { GIVEN_IN, GIVEN_OUT } 22 | 23 | struct SingleSwap { 24 | bytes32 poolId; 25 | SwapKind kind; 26 | IAsset assetIn; 27 | IAsset assetOut; 28 | uint256 amount; 29 | bytes userData; 30 | } 31 | 32 | struct FundManagement { 33 | address sender; 34 | bool fromInternalBalance; 35 | address recipient; 36 | bool toInternalBalance; 37 | } 38 | 39 | interface BalancerV2Swap { 40 | function swap( 41 | SingleSwap memory singleSwap, 42 | FundManagement memory funds, 43 | uint256 limit, 44 | uint256 deadline 45 | ) external returns (uint256); 46 | } 47 | 48 | interface BalancerV2Pool { 49 | function getPoolId() external view returns (bytes32); 50 | } 51 | 52 | interface UniswapV2Router02 { 53 | 54 | function swapExactTokensForTokens( 55 | uint amountOut, 56 | uint amountInMax, 57 | address[] calldata path, 58 | address to, 59 | uint deadline 60 | ) external returns (uint[] memory amounts); 61 | 62 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) 63 | external 64 | payable 65 | returns (uint[] memory amounts); 66 | 67 | } 68 | 69 | 70 | contract BlackMagic is FlashLoanReceiverBase { 71 | 72 | using SafeMath for uint256; 73 | uint256 constant public MAX_SPEND_INT_NUMBER = 1329227995784915872903807060280344575; 74 | uint256 constant public MAX_INT_NUMBER = 115792089237316195423570985008687907853269984665640564039457584007913129639935; 75 | 76 | address public owner; 77 | 78 | ILendingPoolAddressesProvider provider; 79 | address lendingPoolAddr; 80 | 81 | address usdcErc20Matic = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174; 82 | address maiErc20Matic = 0xa3Fa99A148fA48D14Ed51d610c367C61876997F1; 83 | 84 | address balancerV2Approval = 0xBA12222222228d8Ba445958a75a0704d566BF2C8; 85 | address usdcMaiBalancerPool = 0x06Df3b2bbB68adc8B0e302443692037ED9f91b42; 86 | 87 | uint256 internal liquidatingVaultId = 0; 88 | address internal liquidatingVaultContract = maticVaultContract; 89 | address maticVaultContract = 0x595B3E98641C4d66900a24aa6Ada590b41eF85AA; 90 | 91 | address quickSwapRouter = 0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff; 92 | 93 | constructor(ILendingPoolAddressesProvider _addressProvider) FlashLoanReceiverBase(_addressProvider) { 94 | 95 | owner = msg.sender; 96 | provider = _addressProvider; 97 | lendingPoolAddr = provider.getLendingPool(); 98 | 99 | // Approve Balancer for swapping 100 | IERC20(usdcErc20Matic).approve(address(balancerV2Approval), MAX_SPEND_INT_NUMBER); 101 | IERC20(maiErc20Matic).approve(address(balancerV2Approval), MAX_SPEND_INT_NUMBER); 102 | 103 | } 104 | 105 | function getOwnerTokens() private { 106 | require(IERC20(usdcErc20Matic).transferFrom(owner, address(this), IERC20(usdcErc20Matic).balanceOf(owner)), "Usdc transfer failed"); 107 | require(IERC20(maiErc20Matic).transferFrom(owner, address(this), IERC20(maiErc20Matic).balanceOf(owner)), "Mimatic transfer failed"); 108 | } 109 | 110 | function startLoan(uint256 vaultId, address vaultContract, bytes calldata _params) public onlyOwner { 111 | // get all the owner usdc / mimatic so that it is used to cover the delta 112 | getOwnerTokens(); 113 | 114 | // set params to be used later on 115 | liquidatingVaultId = vaultId; 116 | liquidatingVaultContract = vaultContract; 117 | 118 | // check mimatic cost 119 | uint256 costMai = QidaoVault(liquidatingVaultContract).checkCost(vaultId); 120 | // borrow more than needed to cover the fees 121 | uint256 costUsdc = (costMai / 1000000000000) * 110 / 100; 122 | 123 | address receiverAddress = address(this); 124 | 125 | address[] memory assets = new address[](1); 126 | assets[0] = usdcErc20Matic; 127 | uint256[] memory amounts = new uint256[](1); 128 | amounts[0] = costUsdc; 129 | uint256[] memory modes = new uint256[](1); 130 | modes[0] = 0; 131 | 132 | LENDING_POOL.flashLoan( 133 | receiverAddress, 134 | assets, 135 | amounts, 136 | modes, 137 | receiverAddress, 138 | new bytes(0), 139 | 0 140 | ); 141 | } 142 | 143 | /** 144 | This function is called after your contract has received the flash loaned amount 145 | */ 146 | function executeOperation( 147 | address[] calldata assets, 148 | uint256[] calldata amounts, 149 | uint256[] calldata premiums, 150 | address initiator, 151 | bytes calldata params 152 | ) 153 | external 154 | override 155 | returns (bool) 156 | { 157 | FundManagement memory fundManagement; 158 | fundManagement.sender = address(this); 159 | fundManagement.recipient = address(this); 160 | 161 | // swap all USDC to MAI 162 | SingleSwap memory singleSwap; 163 | singleSwap.assetIn = IAsset(usdcErc20Matic); 164 | singleSwap.assetOut = IAsset(maiErc20Matic); 165 | singleSwap.poolId = BalancerV2Pool(usdcMaiBalancerPool).getPoolId(); 166 | singleSwap.amount = IERC20(usdcErc20Matic).balanceOf(address(this)); 167 | BalancerV2Swap(balancerV2Approval).swap(singleSwap, fundManagement, 0, MAX_INT_NUMBER); 168 | 169 | // liquidate 170 | uint256 costMatic = QidaoVault(liquidatingVaultContract).checkCost(liquidatingVaultId); 171 | require(costMatic <= IERC20(maiErc20Matic).balanceOf(address(this)), "Not enough mimatic"); 172 | 173 | // Approve vaults 174 | IERC20(maiErc20Matic).approve(liquidatingVaultContract, MAX_SPEND_INT_NUMBER); 175 | 176 | QidaoVault(liquidatingVaultContract).liquidateVault(liquidatingVaultId); 177 | QidaoVault(liquidatingVaultContract).getPaid(); 178 | 179 | // swap all MAI BACK to USDC 180 | SingleSwap memory singleSwapMaiToUsdc; 181 | singleSwapMaiToUsdc.assetOut = IAsset(usdcErc20Matic); 182 | singleSwapMaiToUsdc.assetIn = IAsset(maiErc20Matic); 183 | singleSwapMaiToUsdc.poolId = BalancerV2Pool(usdcMaiBalancerPool).getPoolId(); 184 | singleSwapMaiToUsdc.amount = IERC20(maiErc20Matic).balanceOf(address(this)); 185 | BalancerV2Swap(balancerV2Approval).swap(singleSwapMaiToUsdc, fundManagement, 0, MAX_INT_NUMBER); 186 | 187 | // Approve the LendingPool contract allowance to *pull* the owed amount 188 | // i.e. AAVE V2's way of repaying the flash loan 189 | uint256 amountOwing = amounts[0].add(premiums[0]); 190 | IERC20(assets[0]).approve(address(LENDING_POOL), amountOwing); 191 | 192 | if (liquidatingVaultContract == maticVaultContract) { 193 | // send matic or the other token 194 | (bool sent,) = owner.call{value: address(this).balance}(""); 195 | require(sent, "2"); 196 | } else { 197 | // approve quickswap to take all the convertFromTokens 198 | IERC20(QidaoVault(liquidatingVaultContract).collateral()).approve(quickSwapRouter, MAX_SPEND_INT_NUMBER); 199 | 200 | // swap collateral for USDC on Quickswap 201 | address[] memory path = new address[](2); 202 | path[0] = QidaoVault(liquidatingVaultContract).collateral(); 203 | path[1] = usdcErc20Matic; 204 | UniswapV2Router02(quickSwapRouter).swapExactTokensForTokens(IERC20(QidaoVault(liquidatingVaultContract).collateral()).balanceOf(address(this)), 0, path, address(this), block.timestamp); 205 | 206 | // send the collateral tokens left back, if any 207 | require(IERC20(QidaoVault(liquidatingVaultContract).collateral()).transfer(owner, IERC20(QidaoVault(liquidatingVaultContract).collateral()).balanceOf(address(this))), "Collateral transfer failed"); 208 | } 209 | 210 | //send everything back home 211 | require(IERC20(usdcErc20Matic).transfer(owner, IERC20(usdcErc20Matic).balanceOf(address(this)) - amountOwing), "Usdc transfer failed"); 212 | require(IERC20(maiErc20Matic).transfer(owner, IERC20(maiErc20Matic).balanceOf(address(this))), "Mimatic transfer failed"); 213 | 214 | return true; 215 | } 216 | 217 | 218 | modifier onlyOwner() { 219 | require(msg.sender == owner, "Caller is not owner"); 220 | _; 221 | } 222 | 223 | } 224 | 225 | -------------------------------------------------------------------------------- /contracts/contracts/FlashLoanReceiverBase.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: agpl-3.0 2 | pragma solidity 0.8.9; 3 | 4 | import {IFlashLoanReceiver, ILendingPoolAddressesProvider, ILendingPool, IERC20 } from "./Interfaces.sol"; 5 | import { SafeERC20, SafeMath } from "./Libraries.sol"; 6 | 7 | abstract contract FlashLoanReceiverBase is IFlashLoanReceiver { 8 | using SafeERC20 for IERC20; 9 | using SafeMath for uint256; 10 | 11 | ILendingPoolAddressesProvider public immutable ADDRESSES_PROVIDER; 12 | ILendingPool public immutable LENDING_POOL; 13 | 14 | constructor(ILendingPoolAddressesProvider provider) { 15 | ADDRESSES_PROVIDER = provider; 16 | LENDING_POOL = ILendingPool(provider.getLendingPool()); 17 | } 18 | receive() payable external {} 19 | } 20 | 21 | -------------------------------------------------------------------------------- /contracts/contracts/Interfaces.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: agpl-3.0 2 | pragma solidity 0.8.9; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import { DataTypes } from "./Libraries.sol"; 6 | 7 | /** 8 | * @dev Interface of the ERC20 standard as defined in the EIP. 9 | */ 10 | interface IERC20 { 11 | /** 12 | * @dev Returns the amount of tokens in existence. 13 | */ 14 | function totalSupply() external view returns (uint256); 15 | 16 | /** 17 | * @dev Returns the amount of tokens owned by `account`. 18 | */ 19 | function balanceOf(address account) external view returns (uint256); 20 | 21 | /** 22 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 23 | * 24 | * Returns a boolean value indicating whether the operation succeeded. 25 | * 26 | * Emits a {Transfer} event. 27 | */ 28 | function transfer(address recipient, uint256 amount) external returns (bool); 29 | 30 | /** 31 | * @dev Returns the remaining number of tokens that `spender` will be 32 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 33 | * zero by default. 34 | * 35 | * This value changes when {approve} or {transferFrom} are called. 36 | */ 37 | function allowance(address owner, address spender) external view returns (uint256); 38 | 39 | /** 40 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 41 | * 42 | * Returns a boolean value indicating whether the operation succeeded. 43 | * 44 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 45 | * that someone may use both the old and the new allowance by unfortunate 46 | * transaction ordering. One possible solution to mitigate this race 47 | * condition is to first reduce the spender's allowance to 0 and set the 48 | * desired value afterwards: 49 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 50 | * 51 | * Emits an {Approval} event. 52 | */ 53 | function approve(address spender, uint256 amount) external returns (bool); 54 | 55 | /** 56 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 57 | * allowance mechanism. `amount` is then deducted from the caller's 58 | * allowance. 59 | * 60 | * Returns a boolean value indicating whether the operation succeeded. 61 | * 62 | * Emits a {Transfer} event. 63 | */ 64 | function transferFrom( 65 | address sender, 66 | address recipient, 67 | uint256 amount 68 | ) external returns (bool); 69 | 70 | /** 71 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 72 | * another (`to`). 73 | * 74 | * Note that `value` may be zero. 75 | */ 76 | event Transfer(address indexed from, address indexed to, uint256 value); 77 | 78 | /** 79 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 80 | * a call to {approve}. `value` is the new allowance. 81 | */ 82 | event Approval(address indexed owner, address indexed spender, uint256 value); 83 | } 84 | 85 | interface IFlashLoanReceiver { 86 | function executeOperation( 87 | address[] calldata assets, 88 | uint256[] calldata amounts, 89 | uint256[] calldata premiums, 90 | address initiator, 91 | bytes calldata params 92 | ) external returns (bool); 93 | } 94 | 95 | /** 96 | * @title LendingPoolAddressesProvider contract 97 | * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles 98 | * - Acting also as factory of proxies and admin of those, so with right to change its implementations 99 | * - Owned by the Aave Governance 100 | * @author Aave 101 | **/ 102 | interface ILendingPoolAddressesProvider { 103 | event LendingPoolUpdated(address indexed newAddress); 104 | event ConfigurationAdminUpdated(address indexed newAddress); 105 | event EmergencyAdminUpdated(address indexed newAddress); 106 | event LendingPoolConfiguratorUpdated(address indexed newAddress); 107 | event LendingPoolCollateralManagerUpdated(address indexed newAddress); 108 | event PriceOracleUpdated(address indexed newAddress); 109 | event LendingRateOracleUpdated(address indexed newAddress); 110 | event ProxyCreated(bytes32 id, address indexed newAddress); 111 | event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy); 112 | 113 | function setAddress(bytes32 id, address newAddress) external; 114 | 115 | function setAddressAsProxy(bytes32 id, address impl) external; 116 | 117 | function getAddress(bytes32 id) external view returns (address); 118 | 119 | function getLendingPool() external view returns (address); 120 | 121 | function setLendingPoolImpl(address pool) external; 122 | 123 | function getLendingPoolConfigurator() external view returns (address); 124 | 125 | function setLendingPoolConfiguratorImpl(address configurator) external; 126 | 127 | function getLendingPoolCollateralManager() external view returns (address); 128 | 129 | function setLendingPoolCollateralManager(address manager) external; 130 | 131 | function getPoolAdmin() external view returns (address); 132 | 133 | function setPoolAdmin(address admin) external; 134 | 135 | function getEmergencyAdmin() external view returns (address); 136 | 137 | function setEmergencyAdmin(address admin) external; 138 | 139 | function getPriceOracle() external view returns (address); 140 | 141 | function setPriceOracle(address priceOracle) external; 142 | 143 | function getLendingRateOracle() external view returns (address); 144 | 145 | function setLendingRateOracle(address lendingRateOracle) external; 146 | } 147 | 148 | interface ILendingPool { 149 | /** 150 | * @dev Emitted on deposit() 151 | * @param reserve The address of the underlying asset of the reserve 152 | * @param user The address initiating the deposit 153 | * @param onBehalfOf The beneficiary of the deposit, receiving the aTokens 154 | * @param amount The amount deposited 155 | * @param referral The referral code used 156 | **/ 157 | event Deposit( 158 | address indexed reserve, 159 | address user, 160 | address indexed onBehalfOf, 161 | uint256 amount, 162 | uint16 indexed referral 163 | ); 164 | 165 | /** 166 | * @dev Emitted on withdraw() 167 | * @param reserve The address of the underlyng asset being withdrawn 168 | * @param user The address initiating the withdrawal, owner of aTokens 169 | * @param to Address that will receive the underlying 170 | * @param amount The amount to be withdrawn 171 | **/ 172 | event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount); 173 | 174 | /** 175 | * @dev Emitted on borrow() and flashLoan() when debt needs to be opened 176 | * @param reserve The address of the underlying asset being borrowed 177 | * @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just 178 | * initiator of the transaction on flashLoan() 179 | * @param onBehalfOf The address that will be getting the debt 180 | * @param amount The amount borrowed out 181 | * @param borrowRateMode The rate mode: 1 for Stable, 2 for Variable 182 | * @param borrowRate The numeric rate at which the user has borrowed 183 | * @param referral The referral code used 184 | **/ 185 | event Borrow( 186 | address indexed reserve, 187 | address user, 188 | address indexed onBehalfOf, 189 | uint256 amount, 190 | uint256 borrowRateMode, 191 | uint256 borrowRate, 192 | uint16 indexed referral 193 | ); 194 | 195 | /** 196 | * @dev Emitted on repay() 197 | * @param reserve The address of the underlying asset of the reserve 198 | * @param user The beneficiary of the repayment, getting his debt reduced 199 | * @param repayer The address of the user initiating the repay(), providing the funds 200 | * @param amount The amount repaid 201 | **/ 202 | event Repay( 203 | address indexed reserve, 204 | address indexed user, 205 | address indexed repayer, 206 | uint256 amount 207 | ); 208 | 209 | /** 210 | * @dev Emitted on swapBorrowRateMode() 211 | * @param reserve The address of the underlying asset of the reserve 212 | * @param user The address of the user swapping his rate mode 213 | * @param rateMode The rate mode that the user wants to swap to 214 | **/ 215 | event Swap(address indexed reserve, address indexed user, uint256 rateMode); 216 | 217 | /** 218 | * @dev Emitted on setUserUseReserveAsCollateral() 219 | * @param reserve The address of the underlying asset of the reserve 220 | * @param user The address of the user enabling the usage as collateral 221 | **/ 222 | event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user); 223 | 224 | /** 225 | * @dev Emitted on setUserUseReserveAsCollateral() 226 | * @param reserve The address of the underlying asset of the reserve 227 | * @param user The address of the user enabling the usage as collateral 228 | **/ 229 | event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user); 230 | 231 | /** 232 | * @dev Emitted on rebalanceStableBorrowRate() 233 | * @param reserve The address of the underlying asset of the reserve 234 | * @param user The address of the user for which the rebalance has been executed 235 | **/ 236 | event RebalanceStableBorrowRate(address indexed reserve, address indexed user); 237 | 238 | /** 239 | * @dev Emitted on flashLoan() 240 | * @param target The address of the flash loan receiver contract 241 | * @param initiator The address initiating the flash loan 242 | * @param asset The address of the asset being flash borrowed 243 | * @param amount The amount flash borrowed 244 | * @param premium The fee flash borrowed 245 | * @param referralCode The referral code used 246 | **/ 247 | event FlashLoan( 248 | address indexed target, 249 | address indexed initiator, 250 | address indexed asset, 251 | uint256 amount, 252 | uint256 premium, 253 | uint16 referralCode 254 | ); 255 | 256 | /** 257 | * @dev Emitted when the pause is triggered. 258 | */ 259 | event Paused(); 260 | 261 | /** 262 | * @dev Emitted when the pause is lifted. 263 | */ 264 | event Unpaused(); 265 | 266 | /** 267 | * @dev Emitted when a borrower is liquidated. This event is emitted by the LendingPool via 268 | * LendingPoolCollateral manager using a DELEGATECALL 269 | * This allows to have the events in the generated ABI for LendingPool. 270 | * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation 271 | * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation 272 | * @param user The address of the borrower getting liquidated 273 | * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover 274 | * @param liquidatedCollateralAmount The amount of collateral received by the liiquidator 275 | * @param liquidator The address of the liquidator 276 | * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants 277 | * to receive the underlying collateral asset directly 278 | **/ 279 | event LiquidationCall( 280 | address indexed collateralAsset, 281 | address indexed debtAsset, 282 | address indexed user, 283 | uint256 debtToCover, 284 | uint256 liquidatedCollateralAmount, 285 | address liquidator, 286 | bool receiveAToken 287 | ); 288 | 289 | /** 290 | * @dev Emitted when the state of a reserve is updated. NOTE: This event is actually declared 291 | * in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal, 292 | * the event will actually be fired by the LendingPool contract. The event is therefore replicated here so it 293 | * gets added to the LendingPool ABI 294 | * @param reserve The address of the underlying asset of the reserve 295 | * @param liquidityRate The new liquidity rate 296 | * @param stableBorrowRate The new stable borrow rate 297 | * @param variableBorrowRate The new variable borrow rate 298 | * @param liquidityIndex The new liquidity index 299 | * @param variableBorrowIndex The new variable borrow index 300 | **/ 301 | event ReserveDataUpdated( 302 | address indexed reserve, 303 | uint256 liquidityRate, 304 | uint256 stableBorrowRate, 305 | uint256 variableBorrowRate, 306 | uint256 liquidityIndex, 307 | uint256 variableBorrowIndex 308 | ); 309 | 310 | /** 311 | * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens. 312 | * - E.g. User deposits 100 USDC and gets in return 100 aUSDC 313 | * @param asset The address of the underlying asset to deposit 314 | * @param amount The amount to be deposited 315 | * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user 316 | * wants to receive them on his own wallet, or a different address if the beneficiary of aTokens 317 | * is a different wallet 318 | * @param referralCode Code used to register the integrator originating the operation, for potential rewards. 319 | * 0 if the action is executed directly by the user, without any middle-man 320 | **/ 321 | function deposit( 322 | address asset, 323 | uint256 amount, 324 | address onBehalfOf, 325 | uint16 referralCode 326 | ) external; 327 | 328 | /** 329 | * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned 330 | * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC 331 | * @param asset The address of the underlying asset to withdraw 332 | * @param amount The underlying amount to be withdrawn 333 | * - Send the value type(uint256).max in order to withdraw the whole aToken balance 334 | * @param to Address that will receive the underlying, same as msg.sender if the user 335 | * wants to receive it on his own wallet, or a different address if the beneficiary is a 336 | * different wallet 337 | **/ 338 | function withdraw( 339 | address asset, 340 | uint256 amount, 341 | address to 342 | ) external; 343 | 344 | /** 345 | * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower 346 | * already deposited enough collateral, or he was given enough allowance by a credit delegator on the 347 | * corresponding debt token (StableDebtToken or VariableDebtToken) 348 | * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet 349 | * and 100 stable/variable debt tokens, depending on the `interestRateMode` 350 | * @param asset The address of the underlying asset to borrow 351 | * @param amount The amount to be borrowed 352 | * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable 353 | * @param referralCode Code used to register the integrator originating the operation, for potential rewards. 354 | * 0 if the action is executed directly by the user, without any middle-man 355 | * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself 356 | * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator 357 | * if he has been given credit delegation allowance 358 | **/ 359 | function borrow( 360 | address asset, 361 | uint256 amount, 362 | uint256 interestRateMode, 363 | uint16 referralCode, 364 | address onBehalfOf 365 | ) external; 366 | 367 | /** 368 | * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned 369 | * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address 370 | * @param asset The address of the borrowed underlying asset previously borrowed 371 | * @param amount The amount to repay 372 | * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode` 373 | * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable 374 | * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the 375 | * user calling the function if he wants to reduce/remove his own debt, or the address of any other 376 | * other borrower whose debt should be removed 377 | **/ 378 | function repay( 379 | address asset, 380 | uint256 amount, 381 | uint256 rateMode, 382 | address onBehalfOf 383 | ) external; 384 | 385 | /** 386 | * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa 387 | * @param asset The address of the underlying asset borrowed 388 | * @param rateMode The rate mode that the user wants to swap to 389 | **/ 390 | function swapBorrowRateMode(address asset, uint256 rateMode) external; 391 | 392 | /** 393 | * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve. 394 | * - Users can be rebalanced if the following conditions are satisfied: 395 | * 1. Usage ratio is above 95% 396 | * 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been 397 | * borrowed at a stable rate and depositors are not earning enough 398 | * @param asset The address of the underlying asset borrowed 399 | * @param user The address of the user to be rebalanced 400 | **/ 401 | function rebalanceStableBorrowRate(address asset, address user) external; 402 | 403 | /** 404 | * @dev Allows depositors to enable/disable a specific deposited asset as collateral 405 | * @param asset The address of the underlying asset deposited 406 | * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise 407 | **/ 408 | function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external; 409 | 410 | /** 411 | * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1 412 | * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives 413 | * a proportionally amount of the `collateralAsset` plus a bonus to cover market risk 414 | * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation 415 | * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation 416 | * @param user The address of the borrower getting liquidated 417 | * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover 418 | * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants 419 | * to receive the underlying collateral asset directly 420 | **/ 421 | function liquidationCall( 422 | address collateralAsset, 423 | address debtAsset, 424 | address user, 425 | uint256 debtToCover, 426 | bool receiveAToken 427 | ) external; 428 | 429 | /** 430 | * @dev Allows smartcontracts to access the liquidity of the pool within one transaction, 431 | * as long as the amount taken plus a fee is returned. 432 | * IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept into consideration. 433 | * For further details please visit https://developers.aave.com 434 | * @param receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface 435 | * @param assets The addresses of the assets being flash-borrowed 436 | * @param amounts The amounts amounts being flash-borrowed 437 | * @param modes Types of the debt to open if the flash loan is not returned: 438 | * 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver 439 | * 1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address 440 | * 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address 441 | * @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2 442 | * @param params Variadic packed params to pass to the receiver as extra information 443 | * @param referralCode Code used to register the integrator originating the operation, for potential rewards. 444 | * 0 if the action is executed directly by the user, without any middle-man 445 | **/ 446 | function flashLoan( 447 | address receiverAddress, 448 | address[] calldata assets, 449 | uint256[] calldata amounts, 450 | uint256[] calldata modes, 451 | address onBehalfOf, 452 | bytes calldata params, 453 | uint16 referralCode 454 | ) external; 455 | 456 | /** 457 | * @dev Returns the user account data across all the reserves 458 | * @param user The address of the user 459 | * @return totalCollateralETH the total collateral in ETH of the user 460 | * @return totalDebtETH the total debt in ETH of the user 461 | * @return availableBorrowsETH the borrowing power left of the user 462 | * @return currentLiquidationThreshold the liquidation threshold of the user 463 | * @return ltv the loan to value of the user 464 | * @return healthFactor the current health factor of the user 465 | **/ 466 | function getUserAccountData(address user) 467 | external 468 | view 469 | returns ( 470 | uint256 totalCollateralETH, 471 | uint256 totalDebtETH, 472 | uint256 availableBorrowsETH, 473 | uint256 currentLiquidationThreshold, 474 | uint256 ltv, 475 | uint256 healthFactor 476 | ); 477 | 478 | function initReserve( 479 | address reserve, 480 | address aTokenAddress, 481 | address stableDebtAddress, 482 | address variableDebtAddress, 483 | address interestRateStrategyAddress 484 | ) external; 485 | 486 | function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress) 487 | external; 488 | 489 | function setConfiguration(address reserve, uint256 configuration) external; 490 | 491 | /** 492 | * @dev Returns the configuration of the reserve 493 | * @param asset The address of the underlying asset of the reserve 494 | * @return The configuration of the reserve 495 | **/ 496 | function getConfiguration(address asset) external view returns (DataTypes.ReserveConfigurationMap memory); 497 | 498 | /** 499 | * @dev Returns the configuration of the user across all the reserves 500 | * @param user The user address 501 | * @return The configuration of the user 502 | **/ 503 | function getUserConfiguration(address user) external view returns (DataTypes.UserConfigurationMap memory); 504 | 505 | /** 506 | * @dev Returns the normalized income normalized income of the reserve 507 | * @param asset The address of the underlying asset of the reserve 508 | * @return The reserve's normalized income 509 | */ 510 | function getReserveNormalizedIncome(address asset) external view returns (uint256); 511 | 512 | /** 513 | * @dev Returns the normalized variable debt per unit of asset 514 | * @param asset The address of the underlying asset of the reserve 515 | * @return The reserve normalized variable debt 516 | */ 517 | function getReserveNormalizedVariableDebt(address asset) external view returns (uint256); 518 | 519 | /** 520 | * @dev Returns the state and configuration of the reserve 521 | * @param asset The address of the underlying asset of the reserve 522 | * @return The state of the reserve 523 | **/ 524 | function getReserveData(address asset) external view returns (DataTypes.ReserveData memory); 525 | 526 | function finalizeTransfer( 527 | address asset, 528 | address from, 529 | address to, 530 | uint256 amount, 531 | uint256 balanceFromAfter, 532 | uint256 balanceToBefore 533 | ) external; 534 | 535 | function getReservesList() external view returns (address[] memory); 536 | 537 | function getAddressesProvider() external view returns (ILendingPoolAddressesProvider); 538 | 539 | function setPause(bool val) external; 540 | 541 | function paused() external view returns (bool); 542 | } 543 | 544 | 545 | -------------------------------------------------------------------------------- /contracts/contracts/Libraries.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: agpl-3.0 2 | pragma solidity 0.8.9; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import { IERC20 } from "./Interfaces.sol"; 6 | 7 | library SafeMath { 8 | /** 9 | * @dev Returns the addition of two unsigned integers, reverting on 10 | * overflow. 11 | * 12 | * Counterpart to Solidity's `+` operator. 13 | * 14 | * Requirements: 15 | * - Addition cannot overflow. 16 | */ 17 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 18 | uint256 c = a + b; 19 | require(c >= a, 'SafeMath: addition overflow'); 20 | 21 | return c; 22 | } 23 | 24 | /** 25 | * @dev Returns the subtraction of two unsigned integers, reverting on 26 | * overflow (when the result is negative). 27 | * 28 | * Counterpart to Solidity's `-` operator. 29 | * 30 | * Requirements: 31 | * - Subtraction cannot overflow. 32 | */ 33 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 34 | return sub(a, b, 'SafeMath: subtraction overflow'); 35 | } 36 | 37 | /** 38 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 39 | * overflow (when the result is negative). 40 | * 41 | * Counterpart to Solidity's `-` operator. 42 | * 43 | * Requirements: 44 | * - Subtraction cannot overflow. 45 | */ 46 | function sub( 47 | uint256 a, 48 | uint256 b, 49 | string memory errorMessage 50 | ) internal pure returns (uint256) { 51 | require(b <= a, errorMessage); 52 | uint256 c = a - b; 53 | 54 | return c; 55 | } 56 | 57 | /** 58 | * @dev Returns the multiplication of two unsigned integers, reverting on 59 | * overflow. 60 | * 61 | * Counterpart to Solidity's `*` operator. 62 | * 63 | * Requirements: 64 | * - Multiplication cannot overflow. 65 | */ 66 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 67 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 68 | // benefit is lost if 'b' is also tested. 69 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 70 | if (a == 0) { 71 | return 0; 72 | } 73 | 74 | uint256 c = a * b; 75 | require(c / a == b, 'SafeMath: multiplication overflow'); 76 | 77 | return c; 78 | } 79 | 80 | /** 81 | * @dev Returns the integer division of two unsigned integers. Reverts on 82 | * division by zero. The result is rounded towards zero. 83 | * 84 | * Counterpart to Solidity's `/` operator. Note: this function uses a 85 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 86 | * uses an invalid opcode to revert (consuming all remaining gas). 87 | * 88 | * Requirements: 89 | * - The divisor cannot be zero. 90 | */ 91 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 92 | return div(a, b, 'SafeMath: division by zero'); 93 | } 94 | 95 | /** 96 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 97 | * division by zero. The result is rounded towards zero. 98 | * 99 | * Counterpart to Solidity's `/` operator. Note: this function uses a 100 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 101 | * uses an invalid opcode to revert (consuming all remaining gas). 102 | * 103 | * Requirements: 104 | * - The divisor cannot be zero. 105 | */ 106 | function div( 107 | uint256 a, 108 | uint256 b, 109 | string memory errorMessage 110 | ) internal pure returns (uint256) { 111 | // Solidity only automatically asserts when dividing by 0 112 | require(b > 0, errorMessage); 113 | uint256 c = a / b; 114 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 115 | 116 | return c; 117 | } 118 | 119 | /** 120 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 121 | * Reverts when dividing by zero. 122 | * 123 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 124 | * opcode (which leaves remaining gas untouched) while Solidity uses an 125 | * invalid opcode to revert (consuming all remaining gas). 126 | * 127 | * Requirements: 128 | * - The divisor cannot be zero. 129 | */ 130 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 131 | return mod(a, b, 'SafeMath: modulo by zero'); 132 | } 133 | 134 | /** 135 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 136 | * Reverts with custom message when dividing by zero. 137 | * 138 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 139 | * opcode (which leaves remaining gas untouched) while Solidity uses an 140 | * invalid opcode to revert (consuming all remaining gas). 141 | * 142 | * Requirements: 143 | * - The divisor cannot be zero. 144 | */ 145 | function mod( 146 | uint256 a, 147 | uint256 b, 148 | string memory errorMessage 149 | ) internal pure returns (uint256) { 150 | require(b != 0, errorMessage); 151 | return a % b; 152 | } 153 | } 154 | 155 | library Address { 156 | /** 157 | * @dev Returns true if `account` is a contract. 158 | * 159 | * [IMPORTANT] 160 | * ==== 161 | * It is unsafe to assume that an address for which this function returns 162 | * false is an externally-owned account (EOA) and not a contract. 163 | * 164 | * Among others, `isContract` will return false for the following 165 | * types of addresses: 166 | * 167 | * - an externally-owned account 168 | * - a contract in construction 169 | * - an address where a contract will be created 170 | * - an address where a contract lived, but was destroyed 171 | * ==== 172 | */ 173 | function isContract(address account) internal view returns (bool) { 174 | // According to EIP-1052, 0x0 is the value returned for not-yet created accounts 175 | // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned 176 | // for accounts without code, i.e. `keccak256('')` 177 | bytes32 codehash; 178 | bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; 179 | // solhint-disable-next-line no-inline-assembly 180 | assembly { 181 | codehash := extcodehash(account) 182 | } 183 | return (codehash != accountHash && codehash != 0x0); 184 | } 185 | 186 | /** 187 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 188 | * `recipient`, forwarding all available gas and reverting on errors. 189 | * 190 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 191 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 192 | * imposed by `transfer`, making them unable to receive funds via 193 | * `transfer`. {sendValue} removes this limitation. 194 | * 195 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 196 | * 197 | * IMPORTANT: because control is transferred to `recipient`, care must be 198 | * taken to not create reentrancy vulnerabilities. Consider using 199 | * {ReentrancyGuard} or the 200 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 201 | */ 202 | function sendValue(address payable recipient, uint256 amount) internal { 203 | require(address(this).balance >= amount, 'Address: insufficient balance'); 204 | 205 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 206 | (bool success, ) = recipient.call{value: amount}(''); 207 | require(success, 'Address: unable to send value, recipient may have reverted'); 208 | } 209 | } 210 | 211 | 212 | 213 | /** 214 | * @title SafeERC20 215 | * @dev Wrappers around ERC20 operations that throw on failure (when the token 216 | * contract returns false). Tokens that return no value (and instead revert or 217 | * throw on failure) are also supported, non-reverting calls are assumed to be 218 | * successful. 219 | * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, 220 | * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. 221 | */ 222 | library SafeERC20 { 223 | using SafeMath for uint256; 224 | using Address for address; 225 | 226 | function safeTransfer( 227 | IERC20 token, 228 | address to, 229 | uint256 value 230 | ) internal { 231 | callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); 232 | } 233 | 234 | function safeTransferFrom( 235 | IERC20 token, 236 | address from, 237 | address to, 238 | uint256 value 239 | ) internal { 240 | callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); 241 | } 242 | 243 | function safeApprove( 244 | IERC20 token, 245 | address spender, 246 | uint256 value 247 | ) internal { 248 | require( 249 | (value == 0) || (token.allowance(address(this), spender) == 0), 250 | 'SafeERC20: approve from non-zero to non-zero allowance' 251 | ); 252 | callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); 253 | } 254 | 255 | function callOptionalReturn(IERC20 token, bytes memory data) private { 256 | require(address(token).isContract(), 'SafeERC20: call to non-contract'); 257 | 258 | // solhint-disable-next-line avoid-low-level-calls 259 | (bool success, bytes memory returndata) = address(token).call(data); 260 | require(success, 'SafeERC20: low-level call failed'); 261 | 262 | if (returndata.length > 0) { 263 | // Return data is optional 264 | // solhint-disable-next-line max-line-length 265 | require(abi.decode(returndata, (bool)), 'SafeERC20: ERC20 operation did not succeed'); 266 | } 267 | } 268 | } 269 | 270 | library DataTypes { 271 | // refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties. 272 | struct ReserveData { 273 | //stores the reserve configuration 274 | ReserveConfigurationMap configuration; 275 | //the liquidity index. Expressed in ray 276 | uint128 liquidityIndex; 277 | //variable borrow index. Expressed in ray 278 | uint128 variableBorrowIndex; 279 | //the current supply rate. Expressed in ray 280 | uint128 currentLiquidityRate; 281 | //the current variable borrow rate. Expressed in ray 282 | uint128 currentVariableBorrowRate; 283 | //the current stable borrow rate. Expressed in ray 284 | uint128 currentStableBorrowRate; 285 | uint40 lastUpdateTimestamp; 286 | //tokens addresses 287 | address aTokenAddress; 288 | address stableDebtTokenAddress; 289 | address variableDebtTokenAddress; 290 | //address of the interest rate strategy 291 | address interestRateStrategyAddress; 292 | //the id of the reserve. Represents the position in the list of the active reserves 293 | uint8 id; 294 | } 295 | 296 | struct ReserveConfigurationMap { 297 | //bit 0-15: LTV 298 | //bit 16-31: Liq. threshold 299 | //bit 32-47: Liq. bonus 300 | //bit 48-55: Decimals 301 | //bit 56: Reserve is active 302 | //bit 57: reserve is frozen 303 | //bit 58: borrowing is enabled 304 | //bit 59: stable rate borrowing enabled 305 | //bit 60-63: reserved 306 | //bit 64-79: reserve factor 307 | uint256 data; 308 | } 309 | 310 | struct UserConfigurationMap { 311 | uint256 data; 312 | } 313 | 314 | enum InterestRateMode {NONE, STABLE, VARIABLE} 315 | } 316 | 317 | -------------------------------------------------------------------------------- /contracts/hardhat.config.js: -------------------------------------------------------------------------------- 1 | require("@nomiclabs/hardhat-waffle"); 2 | module.exports = { 3 | defaultNetwork: "matic", 4 | networks: { 5 | hardhat: { 6 | }, 7 | matic: { 8 | url: "https://polygon-rpc.com/", 9 | chainId: 137, 10 | accounts: [process.env.ETHEREUM_WALLET_PRIVATE_KEY || "0x0000000000000000000000000000000000000000000000000000000000000001"] 11 | } 12 | }, 13 | solidity: { 14 | compilers: [ 15 | { 16 | version: "0.8.9", 17 | settings: { 18 | optimizer: { 19 | enabled: true, 20 | runs: 200, 21 | } 22 | } 23 | }, 24 | ] 25 | } 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /contracts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hardhat", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "@nomiclabs/hardhat-ethers": "^2.0.4", 14 | "@nomiclabs/hardhat-waffle": "^2.0.2", 15 | "chai": "^4.3.4", 16 | "ethereum-waffle": "^3.4.0", 17 | "ethers": "^5.5.3", 18 | "hardhat": "^2.8.3" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /contracts/scripts/deploy.js: -------------------------------------------------------------------------------- 1 | async function main() { 2 | const [deployer] = await ethers.getSigners(); 3 | 4 | console.log("Deploying contracts with the account:", deployer.address); 5 | 6 | console.log("Account balance:", (await deployer.getBalance()).toString()); 7 | 8 | const Token = await ethers.getContractFactory("BlackMagic"); 9 | const token = await Token.deploy("0xd05e3E715d945B59290df0ae8eF85c1BdB684744"); 10 | await token.deployed(); 11 | console.log("Contract address: ", token.address); 12 | } 13 | 14 | main() 15 | .then(() => process.exit(0)) 16 | .catch((error) => { 17 | console.error(error); 18 | process.exit(1); 19 | }); 20 | 21 | --------------------------------------------------------------------------------