Skip to content

Instantly share code, notes, and snippets.

@naddison36
Last active April 12, 2021 01:56
Show Gist options
  • Save naddison36/f80a06eaa742f4256f3d6a38245d5477 to your computer and use it in GitHub Desktop.
Save naddison36/f80a06eaa742f4256f3d6a38245d5477 to your computer and use it in GitHub Desktop.
mUSD V3 Upgrade Flash Loans

DyDx Flash Loans to rebalance mUSD

The Flash Loans transactions used to rebalance the mUSD basket as part of the mUSD V3 contract upgrade.

  1. Swap out TUSD from mUSD
  • Flash loan 1m USDC from DyDx
  • mUSD swap 1m USDC->TUSD
  • Swap 0.5m TUSD->USDC using Curve Y pool
  • Swap 0.5m TUSD->USDC using Curve TUSD pool
  • Loan shortfall 634 USDC
  • Gas used 2,318,563. 0.310687442 Ether ($558.23)

https://etherscan.io/tx/0xe71da8d2b5447d095ff6a8cbfae6ee3975230a03fd459912b07bfce54bc8ecd4

Tranaction Sequence diagram without params

Tranaction Sequence diagram with params

  1. Attempt to swap out TUSD and USDT
  • Flash loan 5.5m DAI from DyDx ran out of gas
  • Gas limit was 3,233,929
  • Gas used was 3,090,548. 0.3863185 Ether ($693.94)
  • Next tx was the same but with a higher gas limit so the gas estimation was wrong

https://etherscan.io/tx/0xbb0592b5dcd4155b52d2bcd0dba3f768f8d475da34168ccf3ce5fb9621b21d6d/advanced

  1. Swap out TUSD and USDT from mUSD
  • Flash loan 5.5m DAI from DyDx
  • mUSD swap 2.7m DAI->TUSD
  • mUSD swap 2.7m DAI->USDT
  • Swap 1.35m TUSD->DAI using Curve Y pool
  • Swap 1.35m TUSD->DAI using Curve TUSD pool
  • Swap 2.7m USDT->DAI using Curve 3pool
  • loan shortfall 9,979 DAI
  • Gas used 2,764,284. 0.34337708 Ether ($615.98)

https://etherscan.io/tx/0x77cea5a059bf8e86a1f51b53e661918d2bc05cc3961a9c0c0f9ce04c51a32952

Tranaction Sequence diagram without params

Tranaction Sequence diagram with params

  1. Swap out TUSD from mUSD
  • Flash loan 5.2m DAI from DyDx
  • mUSD swap 5.2m DAI->TUSD
  • Swap 2.6m TUSD->DAI using Curve Y pool
  • Swap 2.6m TUSD->DAI using Curve TUSD pool
  • loan shortfall 14,400 DAI
  • Gas used 2,764,284. 0.323421228 Ether ($580.97)

https://etherscan.io/tx/0xbcaa641d718e1627d21a6b0fc26b7390271dfd288059a96b5b366a0c97c44586

Tranaction Sequence diagram without params

Tranaction Sequence diagram with params

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment