mirror of
https://github.com/autistic-symposium/mev-toolkit.git
synced 2025-08-17 10:30:39 -04:00
💾
This commit is contained in:
parent
bf818f2682
commit
d3a292bfd1
133 changed files with 26 additions and 40 deletions
39
MEV_strategies/liquidations/README.md
Normal file
39
MEV_strategies/liquidations/README.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
## liquidation
|
||||
|
||||
<br>
|
||||
|
||||
### tl, dr
|
||||
|
||||
<br>
|
||||
|
||||
* **lending protocol** work by requiring users to deposit some collateral. users can then borrow different assets and tokens from others depending on what they need, up to a certain amount of their deposited collateral. as the value of a borrower's collateral fluctuates, if the value of the borrowed assets exceeds the value of the collateral, the protocol allows anyone to liquidate the collateral (similar to margin calls in traditional finance).
|
||||
* **searchers compete** to parse blockchain data as fast as possible to determine which borrowers can be liquidated and be the first to submit a liquidation transaction and collect the liquidation fee.
|
||||
* **example of strategy**: bot detects a liquidation opportunity at a block and issues a liquidation tx, which is expected to be included in the next block. to compete with other liquidators, the bot sets high tx fees for their liquidation tx.
|
||||
* **another strategy**: bot observes a tx that will create a liquidation opportunity (e.g., an oracle price update tx rendering a collateralized debit to be liquidated), then backruns this tx with a liquidation tx to avoid the fee bidding competition.
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
### in this dir
|
||||
|
||||
<br>
|
||||
|
||||
* [flashloans](flashloans)
|
||||
* [compound](compound.md)
|
||||
* [liquity](liquity.md)
|
||||
* [aave](aave.md)
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
## resources
|
||||
|
||||
<br>
|
||||
|
||||
* [anatomy of liquidator bots](https://github.com/go-outside-labs/mev-toolkit/blob/main/anatomy_of_mev_bots/bots/liquidators.md)
|
||||
* [liquidation dashboard, by eigenphi](https://eigenphi.io/mev/ethereum/liquidation)
|
||||
* [understanding compound's liquidation, by zengo](https://zengo.com/understanding-compounds-liquidation/)
|
||||
* [nahtan worsley's liquidation strategies, by forbes](https://www.forbes.com/sites/jeffkauflin/2022/10/11/the-secretive-world-of-mev-where-crypto-bots-scalp-investors-for-big-profits/?sh=25489eda2d8d)
|
||||
* [cycle of liquidations in the CRV pool](https://twitter.com/AaveAave/status/1595168982541209611)
|
37
MEV_strategies/liquidations/aave.md
Normal file
37
MEV_strategies/liquidations/aave.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
## aave protocol
|
||||
|
||||
<br>
|
||||
|
||||
### tl; dr
|
||||
|
||||
<br>
|
||||
|
||||
* decentralized lending protocol that lets users lend or borrow crypto assets or real-world assets (RWAs) without going to a centralized intermediary.
|
||||
* users deposit digital assets into liquidity pools, which become funds so that the protocol can lend out.
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
### tl; dr aave v3
|
||||
|
||||
<br>
|
||||
|
||||
* **portal**: allows flow of liquidity between aave v3 markets across different networks (governance-approved bridges can burn atokens while minting them on the destination network)
|
||||
* **emode**: the high-efficiency mode allows borrowers to extract the highest borrowing power out of their collateral when supplied + borrowed assets are price-correlated (e.g. both are derivatives of the same underlying asset).
|
||||
* **isolation mode**: new assets can be listed as isolated so borrowers cannot supply other assets as collateral (but can capture yield) but only approved stablecoins.
|
||||
* **siloed borrowing** allows assets with risky manipulatable oracles to be listed as a single borrow asset.
|
||||
* **multiple rewards** per token.
|
||||
* **chains**: avalanche, pptimism, polygon, fantom, harmony and arbitrum.
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
---
|
||||
|
||||
### resources
|
||||
|
||||
<br>
|
||||
|
||||
* [liquidations, by aave protocol](https://docs.aave.com/developers/guides/liquidations)
|
||||
* [aave v2 whitepaper](https://github.com/aave/protocol-v2/blob/master/aave-v2-whitepaper.pdf)
|
||||
* [aave v3 docs](https://docs.aave.com/developers/getting-started/readme)
|
22
MEV_strategies/liquidations/compound.md
Normal file
22
MEV_strategies/liquidations/compound.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
## compound
|
||||
|
||||
<br>
|
||||
|
||||
### tl; dr
|
||||
|
||||
<br>
|
||||
|
||||
* decentralized protocol that establishes markets with algorithmically set interest rates, based on supply and demand, and allowing users to frictionlessly
|
||||
exchange the time value of crypto assets.
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
### resources
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
* [compound docs](https://docs.compound.finance/)
|
||||
* [compound whitepaper](https://compound.finance/documents/Compound.Whitepaper.pdf)
|
40
MEV_strategies/liquidations/flashloans/README.md
Normal file
40
MEV_strategies/liquidations/flashloans/README.md
Normal file
|
@ -0,0 +1,40 @@
|
|||
|
||||
## flashloans
|
||||
|
||||
<br>
|
||||
|
||||
### tl; dr
|
||||
|
||||
<br>
|
||||
|
||||
* flashloans allow the borrowing of any available amount of assets without any collateral, as long as the liquidity is returned to the protocol within one block tx.
|
||||
* flashloans can be requested through smart contracts that execute the steps to borrow nad pay the loan (+ interest fees) withing the same tx.
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
### in this dir
|
||||
|
||||
<br>
|
||||
|
||||
* [smart contracts](smart_contracts)
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
### resources
|
||||
|
||||
<br>
|
||||
|
||||
* [flashloans dashboard, by eigeinphi](https://eigenphi.io/mev/ethereum/flashloan)
|
||||
* [flashloans from dYdX margin trading, by eigenphi](https://medium.com/coinmonks/get-everything-for-nothing-how-to-use-flash-loans-to-launch-an-arbitrage-d8520827cbfe)
|
||||
* [kollateral aggregator](https://www.kollateral.co/)
|
||||
* [taking undercollaterized loans, by samczsun](https://samczsun.com/taking-undercollateralized-loans-for-fun-and-for-profit/)
|
||||
* [tfusd flashloan writeup](https://github.com/Jonah246/tfusd-flashloan-attack-write-up)
|
||||
* [defi hacks: flashloans](https://wooded-meter-1d8.notion.site/0e85e02c5ed34df3855ea9f3ca40f53b?v=22e5e2c506ef4caeb40b4f78e23517ee)
|
||||
* [flashloan-rs rust crate](https://crates.io/crates/flashloan-rs)
|
||||
* [flashloan monitor](https://tools.blocksec.com/flashloan/eth)
|
||||
* [code for flashmint arb](https://github.com/fifikobayashi/FlashMintArbitrage)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
## flashloans smart contracts
|
||||
|
||||
<br>
|
||||
|
||||
### code
|
||||
|
||||
<br>
|
||||
|
||||
* [sugardad (aave v2)](https://github.com/fifikobayashi/SugarDaddyFlashloan)
|
||||
* [dydx and aave aggregate](https://github.com/fifikobayashi/Aggregated-Flashloan)
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
### resources
|
|
@ -0,0 +1,61 @@
|
|||
function callFunction(address sender, Account.Info memory accountInfo, bytes memory data) external {
|
||||
// Use chi tokens
|
||||
uint256 gasStart = gasleft();
|
||||
|
||||
// Let the executor or the dYdX contract call this function
|
||||
// probably fine to restrict to dYdX
|
||||
require(msg.sender == executor || msg.sender == address(soloMargin));
|
||||
|
||||
// Decode the passed variables from the data object
|
||||
(
|
||||
address[] memory sUSDAddresses,
|
||||
uint256[] memory sUSDLoanIDs,
|
||||
uint256 wethEstimate,
|
||||
uint256 usdcEstimate,
|
||||
uint256 ethToCoinbase
|
||||
)
|
||||
= abi.decode(data,
|
||||
(
|
||||
address[],
|
||||
uint256[],
|
||||
uint256,
|
||||
uint256,
|
||||
uint256
|
||||
));
|
||||
|
||||
// Swap WETH for USDC on uniswap v3
|
||||
uniswapRouter.exactOutputSingle(
|
||||
ISwapRouter.ExactOutputSingleParams(
|
||||
address(WETH), // address tokenIn;
|
||||
usdcTokenAddress, // address tokenOut;
|
||||
3000, // uint24 fee;
|
||||
address(this), // address recipient;
|
||||
10**18, // uint256 deadline;
|
||||
usdcEstimate, // uint256 amountOut;
|
||||
wethEstimate, // uint256 amountInMaximum;
|
||||
0 // uint160 sqrtPriceLimitX96;
|
||||
)
|
||||
);
|
||||
|
||||
// Swap USDC for sUSD on Curve
|
||||
curvePoolSUSD.exchange_underlying(
|
||||
1, // usdc
|
||||
3, // sUSD
|
||||
usdcEstimate, // usdc input
|
||||
1); // min sUSD, generally not advisible to make a trade with a min amount out of 1, but its fine here I think because the overall risk of getting rekt is low
|
||||
|
||||
// Liquidate the loans
|
||||
for (uint256 i = 0; i < sUSDAddresses.length; i++) {
|
||||
sUSDLoansAddress.liquidateUnclosedLoan(sUSDAddresses[i], sUSDLoanIDs[i]);
|
||||
}
|
||||
|
||||
// We got back ETH but must pay dYdX in WETH, so deposit our whole balance sans what is paid to miners
|
||||
WETH.deposit{value: address(this).balance - ethToCoinbase}();
|
||||
|
||||
// Pay the miner
|
||||
block.coinbase.transfer(ethToCoinbase);
|
||||
|
||||
// Use for chi tokens
|
||||
uint256 gasSpent = 21000 + gasStart - gasleft() + (16 * msg.data.length);
|
||||
CHI.freeFromUpTo(owner, (gasSpent + 14154) / 41947);
|
||||
}
|
19
MEV_strategies/liquidations/liquity.md
Normal file
19
MEV_strategies/liquidations/liquity.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
## [liquity](https://www.liquity.org/)
|
||||
|
||||
<br>
|
||||
|
||||
### tl; dr
|
||||
|
||||
<br>
|
||||
|
||||
* decentralized borrowing protocol that allows drawing interest-free loans against ether used as collateral
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
### resources
|
||||
|
||||
<br>
|
||||
|
||||
* [liquity docs](https://docs.liquity.org/)
|
Loading…
Add table
Add a link
Reference in a new issue