-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
hydradx/notebooks/Stableswap/RepeggingStableswapArbAttack2.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"outputs": [], | ||
"execution_count": null, | ||
"source": [ | ||
"import sys\n", | ||
"sys.path.append('../..')\n", | ||
"\n", | ||
"from model.amm.stableswap_amm import StableSwapPoolState\n", | ||
"from model.amm.agents import Agent\n", | ||
"import matplotlib.pyplot as plt\n" | ||
], | ||
"id": "8b003c868a5fd00e" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"outputs": [], | ||
"execution_count": null, | ||
"source": [ | ||
"highest_pct = 0.0003\n", | ||
"lowest_pct = 0.000001\n", | ||
"t = 100\n", | ||
"repeg_pcts = [lowest_pct + i * (highest_pct - lowest_pct) / t for i in range(t)]\n", | ||
"balance_pct = 10\n", | ||
"\n", | ||
"init_vDOT_price = 1\n", | ||
"t=1\n", | ||
"fee = 0.0001\n", | ||
"amp = 100\n" | ||
], | ||
"id": "5daf3cd065915a22" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"outputs": [], | ||
"execution_count": null, | ||
"source": [ | ||
"arb_size = 1\n", | ||
"agent = Agent(holdings={'DOT': arb_size}) # value of vDOT is going up so agent will buy vDOT before repeg, sell vDOT after repeg" | ||
], | ||
"id": "5c3c979e81f71149" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"outputs": [], | ||
"execution_count": null, | ||
"source": [ | ||
"balanced_tokens = {'DOT': init_vDOT_price * 1000000, 'vDOT': 1000000}\n", | ||
"tokens = {'DOT': balance_pct / (balance_pct + 1) * balanced_tokens['DOT'], 'vDOT': 1 / (balance_pct + 1) * balanced_tokens['vDOT']}\n", | ||
"print(tokens)\n", | ||
"pool = StableSwapPoolState(tokens, amp, trade_fee=fee, peg=init_vDOT_price)\n", | ||
"# spot_prices = [pool.spot_price(1)]\n", | ||
"print(pool.spot_price(1))\n", | ||
"profits = []\n", | ||
"for repeg_pct in repeg_pcts:\n", | ||
" temp_pool = pool.copy()\n", | ||
" temp_agent = agent.copy()\n", | ||
" temp_pool.swap(temp_agent, 'DOT', 'vDOT', sell_quantity=arb_size)\n", | ||
" temp_pool.set_peg(pool.peg[1] * (1 + repeg_pct))\n", | ||
" temp_pool.swap(temp_agent, 'vDOT', 'DOT', sell_quantity=temp_agent.holdings['vDOT'])\n", | ||
" profits.append(temp_agent.holdings['DOT'] - agent.holdings['DOT'])\n" | ||
], | ||
"id": "80c9b20252132662" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"outputs": [], | ||
"execution_count": null, | ||
"source": [ | ||
"# plt.plot(repeg_pcts)\n", | ||
"# plt.show()\n", | ||
"plt.plot(repeg_pcts, profits)\n", | ||
"plt.show()" | ||
], | ||
"id": "86150823c98fb703" | ||
}, | ||
{ | ||
"metadata": {}, | ||
"cell_type": "code", | ||
"outputs": [], | ||
"execution_count": null, | ||
"source": "", | ||
"id": "31927c298f5f7ffc" | ||
} | ||
], | ||
"metadata": {}, | ||
"nbformat": 5, | ||
"nbformat_minor": 9 | ||
} |