ABCDEFGHIJKLMNOPQRSTUVWXY
1
ETHUSDC999.95OracleQuantity10
2
ETHUSDC1000SpotDebt6000
3
Flash loan fee0.05%
4
Contango fee0.10%
5
6
Scenario #ActionCashflowCashflow
Ccy
Desired
Quantity Δ
CashflowSpot CostDebt ΔLeverageFL FeeCostFee Final
quantity Δ
ObsTrader position size/collateral/leverage changes Detailed steps
7
1OpenAddBase104-600060032.5018764073-100030.019.99Borrow 6k, Sell 6k for ~= 6 ETH- flash loan 6000 USDC
- swap 6000 USDC for ~6ETH
- take 4 ETH from trader
- take 0.01 ETH as fees
- lend ~6 ETH + 3.99 ETH = ~9.99 ETH
- borrow 6000 + 3 USDC
- repay 6003 USDC to the flash loan
8
2OpenAddQuote104000-1000060032.5018764073-100030.019.99Borrow 6k, Sell 10k for ~= 10 ETH- flash loan 6000 USDC
- take 4000 USDC from trader
- swap 10000 USDC for ~10 ETH
- take ~0.01 ETH fees
- lend ~9.99 ETH
- borrow 6000 + 3 USDC
- repay 6003 USDC to the flash loan
9
3Increase--4-400040023.5017508752-40020.0043.996Borrow 4k, Sell 4k for ~= 4 ETH- increase position size
- no collateral change
- increase leverage
- flash loan 4000 USDC
- swap 4000 USDC to ~4ETH
- take 0.004 ETH as fees
- lend ~3.996 ETH
- borrow 4000 + 2 USDC
- repay 4002 USDC to the flash loan
10
4IncreaseAddBase43-10001000.52.0001428670.5-3999.50.0043.996Sell 1k for ~= 1 ETH- increase position size
- add collateral in base
- decrease leverage
- flash loan 1000 USDC
- swap 1000 USDC to ~1ETH
- take 3 ETH from trader
- take 0.004 ETH as fees
- lend ~1ETH + 2.996 ETH = ~3.996 ETH
- borrow 1000 + 0.50 USDC
- repay 1000.50 USDC to the flash loan
11
5IncreaseAddBase44001.750-3999.80.0043.996Just lend 4 ETH, no spot trade needed- increase position size
- add collateral in base
- decrease leverage
- take 4 ETH from trader
- take 0.004 ETH as fees
- lend 3.996 ETH
12
6IncreaseAddBase46-2000-20001.40-40000.0043.996Lend 4 ETH & Sell 2 ETH, repay debt with the proceeds- increase position size
- add collateral
- decrease leverage
- take 6 ETH from trader
- take 0.004 ETH as fees
- lend 3.996 ETH
- swap 2 ETH for ~2000 USDC
- use the ~2000 USDC to repay debt
13
7-AddBase02-2000-20001.6666666670000Sell 2 ETH, repay debt with the proceeds- no position quantity change
- add collateral in base
- decrease leverage
- take 2 ETH from trader
- swap 2 ETH for ~2000 USDC
- use the ~2000 USDC to repay debt
14
8IncreaseAddQuote43000-40001000.52.0001428670.5-3999.50.0043.996Buy 4 ETH but only borrow what the trader's not paying for (borrow 1k)- increase position size
- add collateral in quote
- decrease leverage
- flash loan 1000 USDC
- take 3000 USDC from trader
- swap 4000 USDC to ~4 ETH
- take ~0.004 as fees
- lend ~3.996 ETH
- borrow 1000 + 0.50 USDC
- repay 1000.50 USDC to the flash loan
15
9IncreaseAddQuote44000-400001.750-40000.0043.996Buy 4 ETH, no changes on debt- increase position size
- add collateral in quote
- decrease leverage
- get 4000 USDC from trader
- swap 4000 USDC to ~4ETH
- take 0.004 ETH as fees
- lend ~3.996 ETH
16
10IncreaseAddQuote46000-4000-20001.40-40000.0043.996Buy 4 ETH & repay debt with the excess cashflow- increase position size
- add collateral in quote
- decrease leverage
- get 6000 USDC from trader
- swap 4000 USDC to ~4ETH
- take 0.004 ETH as fees
- lend ~3.996 ETH
- use remaining 2000 USDC to repay debt
17
11-AddQuote020000-20001.6666666670000Repay debt with cashflow- no change on position size
- add collateral in quote
- decrease leverage
- get 2000 USDC from trader
- use 2000 USDC to repay debt
18
12IncreaseRemoveBase4-0.1-41004102.053.5916314992.05-4002.050.0043.996Buy 4.1 ETH, Lend 4, Withdraw 0.1 (take 4.1k new debt)- increase position size
- remove collateral in base
- increase leverage
- flash loan 4100 USDC
- swap 4100 USDC to ~4.1 ETH
- give 0.1 ETH to trader
- take 0.004 ETH as fees
- lend ~3.996 ETH
- borrow 4100 + 2.05 USDC
- repay 4102.50 USDC to the flash loan
19
13IncreaseRemoveBase1-1.1-21002101.053.7944773111.05-10010.0010.999Buy 2.1 ETH, Lend 1, Withdraw 1.1 (take 1.1k new debt)- increase position size
- remove collateral in base
- increase leverage
- flash loan 2100 USDC
- swap 2100 USDC for ~2.1 ETH
- give 1.1 ETH to trader
- take 0.001 ETH as fees
- lend ~0.999 ETH
- borrow 2100 + 1.05 USDC
- repay 2101.05 USDC to the flash loan
20
14IncreaseRemoveQuote4-10040004102.053.5916314992.054002.050.0043.996Buy 4 ETH, Withdraw 100 (take 4.1k new debt)- increase position size
- remove collateral in quote
- increase leverage
- flash loan 4100 USDC
- give 100 USDC to the trader
- swap 4000 USDC to ~4ETH
- take 0.004 ETH as fees
- lend ~3.996 ETH
- borrow 4100 + 2.05 USDC
- repay 4102.05 USDC to the flash loan
21
15IncreaseRemoveQuote1-110010002101.053.7944773111.051001.050.0010.999Buy 1 ETH, Withdraw 1.1k (take 2.1k new debt)- increase position size
- remove collateral in quote
- increase leverage
- flash loan 2100 USDC
- give 1100 USDC to trader
- swap 1000 USDC to ~1ETH
- take 0.001 ETH as fees
- lend ~1 ETH
- borrow 2100 + 1.05 USDC
- repay 2101.05 USDC to the flash loan
22
16Decrease---43994-39941.502253380.002-3994.0020.004-4Sell 4 ETH, repay debt with proceeds- decrease position size
- no collateral change
- decrease leverage
- flash loan 4 - 0.002 - 0.004 = 3.994 ETH
- swap 3.994 ETH for ~3994 USDC to repay debt
- unlend 4 ETH
- keep 0.004 ETH for fees
- repay 3.994 + ~0.002 = ~3.996 ETH to the flash loan
23
17DecreaseAddBase-414993.5-4993.51.2015620310.00253992.8035980.004-4Sell 5 ETH, repay debt with proceeds- decreasing position size
- add collateral
- decrease leverage
- flash loan 5 - 0.0025 - 0.004 = 4.9935 ETH
- swap 4.9935 ETH for ~4993.50 USDC to repay debt
- unlend 4 ETH
- keep 0.004 ETH for fees
- get 1 ETH from the trader
- repay 4.9935 + ~0.0025 = ~4.996 ETH to the flash loan
24
18DecreaseAddQuote-410003994-49941.201441730.00239940.004-4Sell 4 ETH, repay debt worth 5k- decreasing position size
- adding collateral in quote
- decrease leverage
- flash loan 4 - 0.002 - 0.004 = 3.994 ETH
- swap 3.994 ETH for ~3994 USDC
- get 1000 USDC from trader
- use 1000 + ~3994 = ~4994 USDC to repay debt
- unlend 4 ETH
- keep 0.004 ETH for fees
- repay 3.994 + ~0.002 = ~3.996 ETH to the flash loan
25
19DecreaseRemoveBase-4-2.51494-14944.0160642570.0023978.6950730.004-4Sell 4 ETH, withdraw 2.5 ETH, repay 1.5k- decreasing position size
- remove collateral in base
- increase leverage
- flash loan 4 - 0.002 - 0.004 = 3.994 ETH
- transfer 2.5 ETH to the trader
- swap 1.494 ETH for ~1494 USDC to repay debt
- unlend 4 ETH
- keep 0.004 ETH for the fees
- repay 3.994 + ~0.002 = ~3.996 ETH to the flash loan
26
20DecreaseRemoveBase-1-2100010004.50-10000.001-1Borrow 1k, Sell 1k, withdraw approx 2 ETH- decreasing position size
- remove collateral in base
- increasing leverage
- unlend 1 ETH
- keep 0.001 ETH fee
- borrow 1000 USDC and swap for ~1 ETH
- give ~1 + 0.999 = ~1.999 ETH to trader
27
21DecreaseRemoveQuote-4-25003994-14944.0160642570.00239940.004-4Sell 4 ETH, repay 1.5k debt, withdraw 2.5k- decrease position size
- remove collateral in quote
- increase leverage
- flash loan 4 - 0.002 - 0.004 = 3.994 ETH
- swap 3.994 ETH for ~3994 USDC
- transfer 2500 USDC to trader
- use ~1494 USDC to repay debt
- unlend 4 ETH
- keep 0.004 ETH fee
- repay 3.994 + ~0.002 = ~3.996 ETH to the flash loan
28
22DecreaseRemoveQuote-1-2000998.51001.54.5033775330.0005998.50.001-1Sell 1 ETH, take 1k debt, withdraw 2k- decrease position size
- remove collateral in quote
- increase leverage
- flash loan 1 - 0.0005 - 0.001 = 0.9985 ETH
- swap 0.9985 ETH for ~998.50 USDC
- borrow the difference between what you need (2000 USDC) and what you get (~998.50 USDC), which is ~1001.50 USDC
- transfer 2000 USDC to the trader
- unlend 1 ETH
- keep 0.001 ETH fee
- repay 0.9985 + ~0.0005 = 0.999 ETH to the flash loan
29
23CloseRemoveBase-10-46000-60000.0039995.0024990.01-10Sell 6 ETH, repay 6k, withdraw 4 ETHfully close and get base- overshoot amount needed for the swap. e.g. slippage tolerance of 0.1%, then swap 6.006 ETH for ~6006 USDC (WE NEED TO ENSURE WE HAVE 6k FOR THE DEBT, NO MATTER THE SLIPPAGE)
- flash loan 6 + 0.006 ETH = 6.006 ETH
- swap 6.006 ETH for ~6006 USDC
- use 6000 USDC to repay debt
- unlend 10 ETH (unlend the full lending position, more money could be unlent depending on the interest on the lending position)
- keep 0.01 ETH fee
- repay 6.006 + 0.003003 = 6.009003 ETH to the flash loan
- transfer 10 - 6.009003 - 0.01 = 3.980997 ETH and ~6 USDC to the trader
30
24CloseRemoveQuote-10-40009985-60000.00599850.01-10Sell 10 ETH, repay 6k, withdraw 4kfully close and get quote- flash loan 10 - 0.005 = 9.995 ETH
- unlend 10 ETH (unlend full lending position, more money could be unlent depending on the interest on the lending position)
- keep 0.01 ETH fee
- repay 10 + 0.005 = 10.005 ETH to the flash loan
- swap 9.985 ETH for ~9985 USDC
- use 6000 USDC to repay debt
- transfer ~9985 - 6000 = ~3985 USDC to the trader
31
25-RemoveBase0-1100010003.3333333330000Borrow 1k, Buy 1 ETH, withdraw 1 ETH- no change in position size
- remove collateral in base
- increase leverage
- borrow 1000 USDC
- swap to ~1 ETH
- transfer ~1 ETH to the trader
32
26-RemoveQuote0-1000010003.3333333330000Borrow 1k, withdraw 1k- no change in position size
- remove collateral in quote
- increase leverage
- borrow 1000 USDC
- give the 1000 USDC to the trader
33
27DecreaseRemoveBase-1-10030-999.950.001-1Just withdraw 1 ETH, no spot trade needed- decrease position size
- remove collateral in base
- increase leverage
- unlend 1 ETH
- take 0.001 ETH fee
- transfer 0.999 ETH to the trader
34
28IncreaseAddBase51-400040023.001200482-49980.0054.995Sell 4k for ~= 4 ETH- increase position size
- add collateral in base
- increase leverage
- flash loan 4000 USDC
- swap 4000 USDC to ~4ETH
- take 1 ETH from trader
- take 0.004 ETH as fees
- lend ~4ETH + 0.996 ETH = ~4.996 ETH
- borrow 4000 + 2 USDC
- repay 4002 USDC to the flash loan
35
29IncreaseAddQuote51000-500040023.001200482-49980.0054.995Buy 5 ETH but only borrow what the trader's not paying for (borrow 4k)- increase position size
- add collateral in quote
- increase leverage
- flash loan 4000 USDC
- take 1000 USDC from trader
- swap 5000 USDC to ~5 ETH
- take ~0.005 as fees
- lend ~4.995 ETH
- borrow 4000 + 2 USDC
- repay 4002 USDC to the flash loan
36
30DecreaseRemoveBase-4-12994-29942.0040080160.0023989.340440.004-4Sell 3 ETH, withdraw 1 ETH, repay 3k- decreasing position size
- remove collateral in base
- decrease leverage
- flash loan 4 - 0.002 - 0.004 = 3.994 ETH
- transfer 1 ETH to the trader
- swap 2.994 ETH for ~2994 USDC to repay debt
- unlend 4 ETH
- keep 0.004 ETH for the fees
- repay 3.994 + ~0.002 = ~3.996 ETH to the flash loan
37
31DecreaseRemoveQuote-4-100039942994-2.0040080160.00239940.004-4Sell 4 ETH, repay 3k debt, withdraw 1k- decrease position size
- remove collateral in quote
- decrease leverage
- flash loan 4 - 0.002 - 0.004 = 3.994 ETH
- swap 3.994 ETH for ~3994 USDC
- transfer 1000 USDC to trader
- use ~2994 USDC to repay debt
- unlend 4 ETH
- keep 0.004 ETH fee
- repay 3.994 + ~0.002 = ~3.996 ETH to the flash loan
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100