This repository was archived by the owner on Jul 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrevenue.py
More file actions
162 lines (147 loc) · 6.39 KB
/
Copy pathrevenue.py
File metadata and controls
162 lines (147 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
class Revenue(object):
def __init__(
self,
cruize_price,
staked_asset_price,
dip_days,
staked_eth_size,
cover_pool,
current_price_of_asset,
tuner=None,
trading_transaction_ratio=0.1,
transactions=0,
transactions_per_day=5,
):
self.cruize_price = cruize_price
self.staked_asset_price = staked_asset_price
self.dip_days = dip_days
self.staked_eth_size = staked_eth_size
self.cover_pool = cover_pool
self.current_price_of_asset = current_price_of_asset
self.tuner = tuner
self.trading_transaction_ratio = trading_transaction_ratio
self.transactions = transactions
self.transactions_per_day = transactions_per_day
def _adjust_tuner(self):
if self.dip_days <= 90:
self.tuner = 0.6
elif 90 < self.dip_days <= 182:
self.tuner = 0.8
else:
self.tuner = 1
def calculate_revenue(self):
if not self.tuner:
self._adjust_tuner()
price_floor = 0.85 * self.staked_asset_price * self.staked_eth_size
print("PF: ", price_floor)
users_eth_market_price = self.current_price_of_asset * self.staked_eth_size
print("UEMP: ", self.current_price_of_asset, users_eth_market_price)
price_difference = price_floor - users_eth_market_price
print("PD: ", price_difference)
fee_percentage = (
(price_difference / (price_difference + (365 / self.dip_days)))
* 100
* self.tuner
)
fee = price_difference * (fee_percentage / 100)
fee_percentage_on_price_difference = (fee / price_difference) * 100
user_received = price_floor
# protocol_spent = user_received
protocol_spent = price_floor - (
self.current_price_of_asset * self.staked_eth_size
)
protocol_retained = self.cover_pool - user_received
current_cover_pool = self.cover_pool - protocol_spent
fee_object = self.get_fee_data(
required_fee=fee + price_difference,
transactions_per_day=self.transactions_per_day,
trading_transaction_ratio=self.trading_transaction_ratio,
)
revenue_data = {
"protocol_retained_usdc": protocol_retained,
"protocol_spent_usdc": protocol_spent,
"user_received_usd": user_received,
"fee_percentage_on_price_difference": fee_percentage_on_price_difference,
"current_cover_pool_usdc": current_cover_pool,
}
revenue_data.update(fee_object)
return revenue_data
def get_fee_data(
self,
required_fee,
eth_yield_apy=0.0366,
trader_fee=0.003,
trading_transaction_ratio=0.1,
transactions=0,
transactions_per_day=5,
):
"""
@params:
required_fee: Fee (to be accumulated via LP fees) that a user owes to the protocol.
eth_yield_apy: Yield Generated on 1 unit of ETH on AAVE lending protocol
trader_fee: 0.3% (0.003) is the optimal trader fee for trading on any open uniswap dex pool
trading_transaction_ratio: The size of the transaction a trader is making from the dex pool.
Eg: Trader extracts 100 cruize tokens out of the pool for trading purposes.
transactions_per_day: Number of transactions occurring on the open dex pool
apy_fee_ratio: %age of apy that the protocol takes as a fee.
Logic:
1. Specify a user_lp_size or users proportion in the open dex pool
2. Specify a dex_pool size. As more users hedge and provide cruize-eth or cruize-usdc to the open dex pool,
the dex pool size increases.
3. Calculate user_portion_in_dex_pool based on the current pool size.
4. Calculate trading_transaction_size (trading_transaction_ratio * dex_pool).
5. Accumulate trader fee generated per transaction until the required_fee is accumulated.
increment count of transactions to check how many transactions will be required.
6. Calculate fee accumulated via the yield (apy_fee) generated on the users hedged asset.
7. Calculate the total_fee_accumulated.
8. Generate the required fee object and return it.
returns: {'total_trading_fee_accumulated': 31.656510000047245,
'total_apy_fee_accumulated': 1.098,
'total_fee_accumulated': 32.75451000004725,
'transactions': 351739,
'days': 703.478}
"""
# cr_yield_apy = 10 / 100
# usdc_yield_apy = 15 / 100
apy_fee_ratio = 10 / 100
user_lp_size = self.staked_eth_size * self.staked_asset_price
dex_pool = self.staked_eth_size * self.staked_asset_price * 50000
user_portion_in_dex_pool = user_lp_size / dex_pool
trading_transaction_size = dex_pool * trading_transaction_ratio
total_trading_fee_accumulated = 0
if not transactions or transactions == 0:
while total_trading_fee_accumulated <= required_fee:
total_trading_fee_accumulated += (
trading_transaction_size * trader_fee * user_portion_in_dex_pool
)
transactions += 1
else:
trading_fee_per_transaction = trading_transaction_size * trader_fee
total_trading_fee_accumulated = transactions * trading_fee_per_transaction
# Compute fee on hedged asset's APY
apy = eth_yield_apy * self.staked_eth_size * self.staked_asset_price
apy_fee = apy * apy_fee_ratio
total_fee_accumulated = total_trading_fee_accumulated + apy_fee
fee_object = {
"total_trading_fee_accumulated": total_trading_fee_accumulated,
"total_apy_fee_accumulated": apy_fee,
"total_fee_accumulated": total_fee_accumulated,
"transactions": transactions,
"days": transactions / transactions_per_day,
}
return fee_object
if __name__ == "__main__":
from pprint import pprint
r = Revenue(
cruize_price=1,
staked_asset_price=100000,
dip_days=15,
staked_eth_size=1,
cover_pool=100000,
current_price_of_asset=65000,
tuner=0.1,
trading_transaction_ratio=0.1,
transactions_per_day=5,
)
pprint(r.calculate_revenue())
# r.calculate_revenue_via_trader_fee()