Skip to content

Commit

Permalink
Merge pull request #39 from defipy-devs/order_book
Browse files Browse the repository at this point in the history
v 1.5.0
  • Loading branch information
icmoore authored May 8, 2024
2 parents 2ae8e3f + 57296a6 commit b5a4e80
Show file tree
Hide file tree
Showing 29 changed files with 2,701 additions and 1,319 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified notebooks/.DS_Store
Binary file not shown.
562 changes: 0 additions & 562 deletions notebooks/medium_articles/deposit_like_a_baller_v3.ipynb

This file was deleted.

6 changes: 3 additions & 3 deletions notebooks/medium_articles/simple_simulation.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions notebooks/medium_articles/withdraw_like_an_og.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Main Python",
"display_name": "py3",
"language": "python",
"name": "py3.10"
"name": "py3"
},
"language_info": {
"codemirror_mode": {
Expand Down
79 changes: 65 additions & 14 deletions notebooks/tutorials/compare_v2_v3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 1,
"id": "186f7163-b9f0-4be2-a25f-4e7a9033ac68",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -79,7 +79,7 @@
"text": [
"Exchange ETH-DAI (LP)\n",
"Real Reserves: ETH = 3162.277660168379, DAI = 316227.7660168379\n",
"Liquidity: 31622.776601683792 \n",
"Gross Liquidity: 31622.776601683792 \n",
"\n"
]
}
Expand Down Expand Up @@ -127,8 +127,7 @@
"text": [
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 9996, DAI = 1000\n",
"Virual Reserves: TKN = 9.995959683792247e-15, DAI = 9.995959683792248e-16\n",
"Liquidity: 3161 \n",
"Gross Liquidity: 3161 \n",
"\n"
]
}
Expand Down Expand Up @@ -185,11 +184,11 @@
"text": [
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 10000.0, DAI = 1000.0\n",
"Liquidity: 3162.2776601683795 \n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n",
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 6837.722339831621, DAI = 683.7722339831621\n",
"Liquidity: 2162.2776601683795 \n",
"Gross Liquidity: 2162.2776601683795 \n",
"\n"
]
}
Expand Down Expand Up @@ -220,6 +219,58 @@
"lp.summary()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "3fc11e6f-c8c7-44ef-9812-6408f2479d50",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 993.2512634810848, DAI = 9932.627274984854\n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n",
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 1003.2512634810848, DAI = 9833.911471545149\n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n"
]
}
],
"source": [
"user = 'user_intro'\n",
"fee = UniV3Utils.FeeAmount.MEDIUM\n",
"tick_spacing = UniV3Utils.TICK_SPACINGS[fee]\n",
"lwr_tick = UniV3Utils.getMinTick(tick_spacing)\n",
"upr_tick = UniV3Utils.getMaxTick(tick_spacing)\n",
"init_price = UniV3Utils.encodePriceSqrt(10, 1)\n",
"\n",
"tkn = ERC20(\"TKN\", \"0x111\")\n",
"dai = ERC20(\"DAI\", \"0x09\")\n",
"\n",
"exchg_data = UniswapExchangeData(tkn0 = tkn, tkn1 = dai, symbol=\"LP\", \n",
" address=\"0x011\", version = 'V3', \n",
" tick_spacing = tick_spacing, \n",
" fee = fee)\n",
"\n",
"#lwr_tick = UniV3Utils.getMinTick(tick_spacing)\n",
"#upr_tick = UniV3Utils.getMaxTick(tick_spacing)\n",
"lwr_tick = lp.get_tick_price(-1, 10, 100000)\n",
"upr_tick = lp.get_tick_price(1, 10, 100000)\n",
"\n",
"factory = UniswapFactory(\"TKN pool factory\", \"0x2\")\n",
"lp = factory.deploy(exchg_data)\n",
"lp.initialize(init_price)\n",
"out = lp.mint(user, lwr_tick, upr_tick, 3162.2776601683795)\n",
"lp.summary()\n",
"\n",
"out_v3 = lp.swapExact0For1(user, 10, None)\n",
"lp.summary()"
]
},
{
"cell_type": "markdown",
"id": "008623b1-cc77-4882-b239-ea10ad383e30",
Expand All @@ -240,11 +291,11 @@
"text": [
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 10000.0, DAI = 1000.0\n",
"Liquidity: 3162.2776601683795 \n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n",
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 10100.0, DAI = 990.1284196560295\n",
"Liquidity: 3162.2776601683795 \n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n"
]
}
Expand Down Expand Up @@ -342,11 +393,11 @@
"text": [
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 10000.0, DAI = 1000.0\n",
"Liquidity: 3162.2776601683795 \n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n",
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 11114.454474534716, DAI = 900.0\n",
"Liquidity: 3162.2776601683795 \n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n"
]
}
Expand Down Expand Up @@ -444,11 +495,11 @@
"text": [
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 10000.0, DAI = 1000.0\n",
"Liquidity: 3162.2776601683795 \n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n",
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 9093.389106119852, DAI = 1100.0\n",
"Liquidity: 3162.2776601683795 \n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n"
]
}
Expand Down Expand Up @@ -546,11 +597,11 @@
"text": [
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 10000.0, DAI = 1000.0\n",
"Liquidity: 3162.2776601683795 \n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n",
"Exchange TKN-DAI (LP)\n",
"Real Reserves: TKN = 9900.0, DAI = 1010.131404313952\n",
"Liquidity: 3162.2776601683795 \n",
"Gross Liquidity: 3162.2776601683795 \n",
"\n"
]
}
Expand Down
645 changes: 645 additions & 0 deletions notebooks/tutorials/order_book.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit b5a4e80

Please sign in to comment.