{"id":22492269,"url":"https://github.com/rita94105/compoundpractice","last_synced_at":"2025-03-27T20:25:39.981Z","repository":{"id":210388585,"uuid":"726438217","full_name":"Rita94105/CompoundPractice","owner":"Rita94105","description":"Understanding how blockchain-based lending agreements work, as well as how to utilize Lightning loans.","archived":false,"fork":false,"pushed_at":"2023-12-31T15:59:03.000Z","size":4969,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T22:47:52.566Z","etag":null,"topics":["aave-v3","compound","flashloan","liquidation"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rita94105.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-02T11:58:14.000Z","updated_at":"2025-01-02T10:17:04.000Z","dependencies_parsed_at":"2023-12-10T02:41:46.935Z","dependency_job_id":null,"html_url":"https://github.com/Rita94105/CompoundPractice","commit_stats":null,"previous_names":["rita94105/compoundpractice"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rita94105%2FCompoundPractice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rita94105%2FCompoundPractice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rita94105%2FCompoundPractice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rita94105%2FCompoundPractice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rita94105","download_url":"https://codeload.github.com/Rita94105/CompoundPractice/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245918272,"owners_count":20693675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aave-v3","compound","flashloan","liquidation"],"created_at":"2024-12-06T18:16:55.945Z","updated_at":"2025-03-27T20:25:39.950Z","avatar_url":"https://github.com/Rita94105.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Delpoy a simple Compound contract with Foundry Script\n\nwrite a Foundry Script to deploy a CErc20Delegator(CErc20Delegators.sol, henceforth referred to as 'cERC20), a Unitroller(Unitroller.sol), and others contracts which are necessary in implementation.\n\nHere are some rules for this Script:\n\n1. The decimals of cERC20 is 18.\n2. Deploy an underlying ERC20 token, and its decimals is 18.\n3. Implement SimplePriceOracle as Oracle.\n4. Implement WhitePaperInterestRateModel as InterestRateModel, and the borrow and loan rates in the model are both 0%.\n5. Initate the exchangeRate as 1:1.\n\n### Test\n\n```\nforge script script/CompoundPractice.s.sol:CompoundPractice\n```\n\nOutput\n\n```\n(base) rita@RitadeMacBook-Pro CompoundPractice % forge script script/CompoundPractice.s.sol:CompoundPractice\n[⠊] Compiling...\nNo files changed, compilation skipped\nScript ran successfully.\nGas used: 10481242\n\nIf you wish to simulate on-chain transactions pass a RPC URL.\n```\n\n## Implement practical functions in Compound\n\n1. test mint and redeem\n\n- user1 use 100 ether TC1 to mint 100 ether cTC1\n- redeem those 100 ether cTC1 to get back 100 ether TC1\n\n2. test borrow and repay\n\n- user1 use 1 ether TC2 to mint cTC2\n- use those cTC2 to borrow 50 ether TC1\n- repay 25 ether TC1\n\n  Here are some rules for these test:\n\n  1. set TC1 underlying price as 1 USD and TC2 as 100 USD in oracle.\n  2. set TC2 collateral factor as 50%.\n\n3. test liquidate by changing collateral factor\n\n- based on scenario 2, adjust TC2's collateral factor from 50% to 30%\n- user2 calculate user1 can be liquidated or not\n- calculate how much seizes can user2 get from this liquidation\n- set liquidation incentive as 108%\n\n4. test liquidate by changing underlying price in Oracle\n\n- based on scenario 2, adjust TC2's underlying price from 100 USD to 90 USD\n- user2 calculate user1 can be liquidated or not\n- calculate how much seizes can user2 get from this liquidation\n- set liquidation incentive as 108%\n\n### Test\n\n```\ngit clone https://github.com/Rita94105/CompoundPractice.git\ncd CompoundPractice\nforge install\nnpm install\nforge build\nforge test\n```\n\noutput\n\n```\n(base) rita@RitadeMacBook-Pro CompoundPractice % forge test\n[⠘] Compiling...\nNo files changed, compilation skipped\n\nRunning 4 tests for test/CompoundPractice.sol:CompoundPracticeTest\n[PASS] testBorrowAndRepay() (gas: 903298)\n[PASS] testCollateralFactortoLiquidate() (gas: 1269892)\n[PASS] testMintAndRedeem() (gas: 348051)\n[PASS] testOracletoLiquidate() (gas: 1268158)\nTest result: ok. 4 passed; 0 failed; 0 skipped; finished in 38.36ms\n\nRan 1 test suites: 4 tests passed, 0 failed, 0 skipped (4 total tests)\n```\n\n## Implement Compound Loan Protocol and AAVEv3 Flash Loan and Liquidate\n\n- use fork testing in Foundry.\n- fork Ethereum mainnet at block 17465000.\n- use USDC as Token A and UNI as Token B.\n- both decimals of USDC and UNI are 18.\n- both exchange rates of USDC and UNI are 1:1.\n- set Close Factor as 50%.\n- set liquidation incentive as 108%.\n- set USDC underlying price as 1 USD and UNI as 5 USD in Oracle.\n- set UNI collateral factor as 50%.\n- user1 use 1000 UNI to borrow 2500 USDC in Compound v2.\n- adjust UNI's underlying price from 5 USD to 4 USD, and user1 will be liquidate by user2.\n- user2 use AAVE v3 Flash Loan to loan USDC and liquidate user1.\n- user2 will earn 63 USDC approximately in this liquidation.\n- the way to swap UNI to USDC\n\n```\n// https://docs.uniswap.org/protocol/guides/swaps/single-swaps\n\nISwapRouter.ExactInputSingleParams memory swapParams =\n  ISwapRouter.ExactInputSingleParams({\n    tokenIn: UNI_ADDRESS,\n    tokenOut: USDC_ADDRESS,\n    fee: 3000, // 0.3%\n    recipient: address(this),\n    deadline: block.timestamp,\n    amountIn: uniAmount,\n    amountOutMinimum: 0,\n    sqrtPriceLimitX96: 0\n  });\n\n// The call to `exactInputSingle` executes the swap.\n// swap Router = 0xE592427A0AEce92De3Edee1F18E0157C05861564\nuint256 amountOut = swapRouter.exactInputSingle(swapParams);\n```\n\n## Test\n\n```\ngit clone https://github.com/Rita94105/CompoundPractice.git\ncd CompoundPractice\nforge install\nnpm install\nforge build\nforge test --mc AAVEv3FlashLoan -vvv\n```\n\nOutput\n\n```\n(base) rita@RitadeMacBook-Pro CompoundPractice % forge test --mc AAVEv3FlashLoan -vvv\n[⠑] Compiling...\nNo files changed, compilation skipped\n\nRunning 1 test for test/AAVEv3FlashLoan.sol:AAVEv3FlashLoan\n[PASS] testLiquidate() (gas: 2025699)\nLogs:\n  user2 USDC balance 63638693\n\nTest result: ok. 1 passed; 0 failed; 0 skipped; finished in 2.37s\n\nRan 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frita94105%2Fcompoundpractice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frita94105%2Fcompoundpractice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frita94105%2Fcompoundpractice/lists"}