- Notifications
You must be signed in to change notification settings - Fork2
A guide on how to complete flashloan transactions. Runner up winner of Aave Grants Dao Forex Tools 2022, ETHGlobal at ETHOnline 2022.
License
mmsaki/rush
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
First rename the.env.example
file in this directory to.env
. Replace the API keys as needed.
After adding your api keys, run the following command from your terminal.
source .env
This command allows brownie config to access your environment variables.
Run the following command to get token balances for all aave tokens in your account.
brownie run scripts/aave/aave_balances.py
Output:
Browniev1.19.1-PythondevelopmentframeworkforEthereumRushProjectistheactiveproject.Running'scripts/aave/aave_balances.py::main'...TokensinAccount====================================================================================================indexTokenNamebalanceaddress0AAVE1000000000000000000000x63242B9Bd3C22f18706d5c4E627B4735973f1f071DAI100000000000000000000000xDF1742fE5b0bFc12331D8EAec6b478DfDbD314642LINK10000000000000000000000x07C725d58437504CA5f814AE406e70E21C5e8e9e3EURS10000000xaA63E0C86b531E2eDFE9F91F6436dF20C301963D4USDC100000000000xA2025B15a1757311bfD68cb14eaeFCc237AF5b435USDT100000000000xC2C527C0CACF457746Bd31B2a698Fe89de2b6d496WETH00x2e3A2fb8473316A02b8A297B982498E661E1f6f57WBTC2000000000x8869DFd060c682675c2A8aE5B21F2cF738A0E3CEInterestaTokensinAccount====================================================================================================indexTokenNamebalanceaddress0aAAVE00xC4bf7684e627ee069e9873B70dD0a8a1241bf72c1aDAI00x310839bE20Fc6a8A89f33A59C7D5fC651365068f2aLINK00x6A639d29454287B3cBB632Aa9f93bfB89E3fd18f3aEURS00xc31E63CB07209DFD2c7Edb3FB385331be2a172094aUSDC00x1Ee669290939f8a8864497Af3BC83728715265FF5aUSDT00x73258E6fb96ecAc8a979826d503B45803a382d686aWETH00x27B4692C93959048833f40702b22FE3578E777597aWBTC2000000000xc0ac343EA11A8D05AAC3c5186850A659dD40B81BStableDebtTokensinAccount====================================================================================================indexTokenNamebalanceaddress0stableDebtAAVE00x4a8aF512B73Fd896C8877cE0Ebed19b0a11B593C1stableDebtDAI00xbaBd1C3912713d598CA2E6DE3303fC59b19d0B0F2stableDebtLINK00x4f094AB301C8787F0d06753CA3238bfA9CFB9c913stableDebtEURS00x512ad2D2fb3Bef82ca0A15d4dE6544246e2D32c74stableDebtUSDC00xF04958AeA8b7F24Db19772f84d7c2aC801D9Cf8b5stableDebtUSDT00x7720C270Fa5d8234f0DFfd2523C64FdeB333Fa506stableDebtWBTC00x15FF4188463c69FD18Ea39F68A0C9B730E23dE817stableDebtWETH00xCAF956bD3B3113Db89C0584Ef3B562153faB87D5VariableDebtTokensinAccount====================================================================================================indexTokenNamebalanceaddress0variableDebtAAVE00xad958444c255a71C659f7c30e18AFafdE910EB5a1variableDebtDAI00xEa5A7CB3BDF6b2A8541bd50aFF270453F1505A722variableDebtLINK00x593D1bB0b6052FB6c3423C42FA62275b3D95a9433variableDebtEURS00x257b4a23b3026E04790c39fD3Edd7101E5F311924variableDebtUSDC00x3e491EB1A98cD42F9BBa388076Fd7a74B3470CA05variableDebtUSDT00x45c3965f6FAbf2fB04e3FE019853813B2B7cC3A36variableDebtWBTC00x480B8b39d1465b8049fbf03b8E0a072Ab7C9A4227variableDebtWETH2062701383561597470x2b848bA14583fA79519Ee71E7038D0d1061cd0F1
If you set up your .env you should see this from your terminal.
Keep in mind that all the scripts you will be running for this demo are found in/scripts/aave directory. Read through them to see what they are doing.
The following script will deploy two flashloan contracts. One will be used to flashloan one token at a timeSimpleFlashLoan, the other will be used to combine multiple tokens in one flashloan transactionFlashLoan.
brownie run scripts/aave/deploy_flashloan.py
Ouput:
Browniev1.19.1-PythondevelopmentframeworkforEthereumRushProjectistheactiveproject.Running'scripts/aave/deploy_flashloan.py::main'...DeployingSimpleRushflashloanreceivercontract ...===============================================Transactionsent:0x0a39f260819c1e3a9d71010ccc64ba9bddc4f2d677d0d94b67c5fac9939cb520Gasprice:36.756769064gweiGaslimit:541641Nonce:90FlashLoan.constructorconfirmedBlock:8282174Gasused:492401 (90.91%)FlashLoandeployedat:0xD86bF68ADaf5C6389F1e7379700B01217f3f8129ViewcontractonOptimismGoerli:https://goerli.etherscan.io/address/0xD86bF68ADaf5C6389F1e7379700B01217f3f8129TransactionwasMined---------------------TxHash:0x0a39f260819c1e3a9d71010ccc64ba9bddc4f2d677d0d94b67c5fac9939cb520From:0xFE948CB2122FDD87bAf43dCe8aFa254B1242c199NewFlashLoanaddress:0xD86bF68ADaf5C6389F1e7379700B01217f3f8129Block:8282174GasUsed:492401/541641 (90.9%)
Checout outthis transaction.After you deploy your contracts, you are ready to submit transactions. The flashloan contracts will receive and repay your loan. Here's an example:
Run command on terminal.
brownie run scripts/aave/simple_flashloan.py
Output:
Browniev1.19.1-PythondevelopmentframeworkforEthereumRushProjectistheactiveproject.Running'scripts/aave/simple_flashloan.py::main'...Transactionsent:0xe0298379f63293c6bb8ec2bfbd147684c3c73087e5ede19eb7409bcd844fcabbGasprice:33.986319221gweiGaslimit:37951Nonce:93MintableERC20.transferconfirmedBlock:8282256Gasused:34501 (90.91%)Transactionsent:0x58180124eadc669c23c0cfa28053e0c79496b48713f0f160734710ace2b92577Gasprice:32.188179381gweiGaslimit:209116Nonce:94TransactionconfirmedBlock:8282267Gasused:165364 (79.08%)Congrats!Youhaveflippedaflashloan.Checkitout!https://goerli.etherscan.io/tx/0x58180124eadc669c23c0cfa28053e0c79496b48713f0f160734710ace2b92577
Brownie has a simple way to quickly instantly verify your contract on etherscan. Run the following command.
>>>contract=RushFlashLoan.at("0x9db7BcB878E9b3eFDf8FAfcfbbF11a54d80f089c")>>>contract<RushFlashLoanContract'0x9db7BcB878E9b3eFDf8FAfcfbbF11a54d80f089c'>>>>RushFlashLoan.publish_source(contract)Verificationsubmittedsuccessfully.Waitingforresult...Verificationcomplete.Result:Pass-VerifiedTrue
Here the flashloan contract is requesting 1M from the pool provider.
frombrownieimportaccounts,config,network,interface,RushSimpleFlashLoanfromscripts.aave.helper_functionsimportget_address_provider,get_token,get_accounttx_url="https://goerli.etherscan.io/tx/{}"pool=interface.IPool(get_address_provider().getPool())flashloan_receiver=RushSimpleFlashLoan[len(RushSimpleFlashLoan)-1]usdc=get_token("USDC")usdc_amount=1_000_000*10**usdc.decimals()defrun_flashloan():dev=get_account()receiver=flashloan_receiver.addressassets=usdc.addressamount=usdc_amount# 'flashLoanSimple': "0x42b0b77c"params="0x42b0b77c"referral=0tx=pool.flashLoanSimple(receiver,assets,amount,params,referral, {"from":dev})
If you run this command, you can flashloan over 100M+ in tokens. Checkoutthis transaction.
brownie run scripts/aave/multi_flashloan.py
Browniev1.19.1-PythondevelopmentframeworkforEthereumRushProjectistheactiveproject.Running'scripts/aave/multi_flashloan.py::main'...Transactionsent:0x310974980351e66748421d1ef01b3d940202090525a99630e03150cb9aeae859Gasprice:4.924637698gweiGaslimit:1578971Nonce:83TransactionconfirmedBlock:8265853Gasused:1113994 (70.55%)TransactionconfirmedBlock:8265853Gasused:1113994 (70.55%)Congrats!Youhaveflippedaflashloan.Checkitout!https://goerli.etherscan.io/tx/0x310974980351e66748421d1ef01b3d940202090525a99630e03150cb9aeae859
Go to/scripts/aave/multi_flashloan.py and adjust token amounts. Try it out or yourself.
If you want to support me, you can. I accept ETH. Currently struggling to find a job.
ETH: msaki.eth 0x04655832bcb0a9a0be8c5ab71e4d311464c97af5
BTC: bc1qafvljh25wxd7ser9vsawzm95aaju883r9twd0p
DOGE: D5y6zYKN4WsWCr4YmnKhAFqCCFC31AN3We
| I should warn you. You will not make any profits from using flashloans in the current state on this repo.
About
A guide on how to complete flashloan transactions. Runner up winner of Aave Grants Dao Forex Tools 2022, ETHGlobal at ETHOnline 2022.