Skip to content

Commit

Permalink
refactor(example): improve topic0 naming
Browse files Browse the repository at this point in the history
  • Loading branch information
peyha committed Apr 18, 2024
1 parent d3061c1 commit dc1d948
Showing 1 changed file with 45 additions and 102 deletions.
147 changes: 45 additions & 102 deletions examples/morpho_blue.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -20,19 +20,19 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"CREATION_MARKET_TOPIC = \"0xac4b2400f169220b0c0afdde7a0b32e775ba727ea1cb30b35f935cdaab8683ac\"\n",
"INTEREST_TOPIC = \"0x9d9bd501d0657d7dfe415f779a620a62b78bc508ddc0891fbbd8b7ac0f8fce87\"\n",
"BORROW_TOPIC = \"0x570954540bed6b1304a87dfe815a5eda4a648f7097a16240dcd85c9b5fd42a43\"\n",
"REPAY_TOPIC = \"0x52acb05cebbd3cd39715469f22afbf5a17496295ef3bc9bb5944056c63ccaa09\"\n",
"SUPPLY_COLLATERAL_TOPIC = \"0xa3b9472a1399e17e123f3c2e6586c23e504184d504de59cdaa2b375e880c6184\"\n",
"WITHDRAW_COLLATERAL_TOPIC = \"0xe80ebd7cc9223d7382aab2e0d1d6155c65651f83d53c8b9b06901d167e321142\"\n",
"SUPPLY_TOPIC = \"0xedf8870433c83823eb071d3df1caa8d008f12f6440918c20d75a3602cda30fe0\"\n",
"WITHDRAW_TOPIC = \"0xa56fc0ad5702ec05ce63666221f796fb62437c32db1aa1aa075fc6484cf58fbf\"\n",
"LIQUIDATION_TOPIC = \"0xa4946ede45d0c6f06a0f5ce92c9ad3b4751452d2fe0e25010783bcab57a67e41\"\n",
"CREATION_MARKET_SIG_HASH = \"0xac4b2400f169220b0c0afdde7a0b32e775ba727ea1cb30b35f935cdaab8683ac\"\n",
"ACCRUE_INTEREST_SIG_HASH = \"0x9d9bd501d0657d7dfe415f779a620a62b78bc508ddc0891fbbd8b7ac0f8fce87\"\n",
"BORROW_SIG_HASH = \"0x570954540bed6b1304a87dfe815a5eda4a648f7097a16240dcd85c9b5fd42a43\"\n",
"REPAY_SIG_HASH = \"0x52acb05cebbd3cd39715469f22afbf5a17496295ef3bc9bb5944056c63ccaa09\"\n",
"SUPPLY_COLLATERAL_SIG_HASH = \"0xa3b9472a1399e17e123f3c2e6586c23e504184d504de59cdaa2b375e880c6184\"\n",
"WITHDRAW_COLLATERAL_SIG_HASH = \"0xe80ebd7cc9223d7382aab2e0d1d6155c65651f83d53c8b9b06901d167e321142\"\n",
"SUPPLY_SIG_HASH = \"0xedf8870433c83823eb071d3df1caa8d008f12f6440918c20d75a3602cda30fe0\"\n",
"WITHDRAW_SIG_HASH = \"0xa56fc0ad5702ec05ce63666221f796fb62437c32db1aa1aa075fc6484cf58fbf\"\n",
"LIQUIDATE_SIG_HASH = \"0xa4946ede45d0c6f06a0f5ce92c9ad3b4751452d2fe0e25010783bcab57a67e41\"\n",
"\n",
"# Id is an alias for bytes32\n",
"# MarketParams is a struct with the following fields:\n",
Expand All @@ -48,8 +48,8 @@
"REPAY_SIG = \"event Repay(Id indexed id, address indexed caller, address indexed onBehalf, uint256 assets, uint256 shares)\".replace('Id', \"bytes32\")\n",
"SUPPLY_COLLATERAL_SIG = \"event SupplyCollateral(Id indexed id, address indexed caller, address indexed onBehalf, uint256 assets)\".replace('Id', \"bytes32\")\n",
"WITHDRAW_COLLATERAL_SIG = \"event WithdrawCollateral(Id indexed id, address caller, address indexed onBehalf, address indexed receiver, uint256 assets)\".replace('Id', \"bytes32\")\n",
"LIQUIDATION_SIG = \"event Liquidate(Id indexed id,address indexed caller,address indexed borrower,uint256 repaidAssets,uint256 repaidShares,uint256 seizedAssets,uint256 badDebtAssets,uint256 badDebtShares);\".replace('Id', \"bytes32\")\n",
"INTEREST_SIG = \"event AccrueInterest(Id indexed id, uint256 prevBorrowRate, uint256 interest, uint256 feeShares);\".replace('Id', \"bytes32\")\n",
"LIQUIDATE_SIG = \"event Liquidate(Id indexed id,address indexed caller,address indexed borrower,uint256 repaidAssets,uint256 repaidShares,uint256 seizedAssets,uint256 badDebtAssets,uint256 badDebtShares);\".replace('Id', \"bytes32\")\n",
"ACCRUE_INTEREST_SIG = \"event AccrueInterest(Id indexed id, uint256 prevBorrowRate, uint256 interest, uint256 feeShares);\".replace('Id', \"bytes32\")\n",
"\n",
"BLUE_CONTRACT_ADDRESS = \"0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb\"\n"
]
Expand All @@ -63,7 +63,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -159,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 25,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -205,7 +205,7 @@
"└─────────────┴─────────────┴───────────┴────────────┴───┴────────┴────────┴────────────┴──────────┘"
]
},
"execution_count": 7,
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -218,7 +218,7 @@
" \"blocks\": [\"18.9M:\"],\n",
" \"inner_request_size\": 10000,\n",
" \"contract\": [BLUE_CONTRACT_ADDRESS],\n",
" \"topic0\": [CREATION_MARKET_TOPIC],\n",
" \"topic0\": [CREATION_MARKET_SIG_HASH],\n",
"}\n",
"\n",
"# Collect the raw events with cryo\n",
Expand All @@ -231,7 +231,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 26,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -286,7 +286,7 @@
"└───────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴──────────┘"
]
},
"execution_count": 8,
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -316,7 +316,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 27,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -371,7 +371,7 @@
"└────────────┴────────────┴────────────┴───────────┴───────────┴───────────┴───────────┴───────────┘"
]
},
"execution_count": 6,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -383,7 +383,7 @@
" \"blocks\": [\"18.9M:\"],\n",
" \"inner_request_size\": 10000,\n",
" \"contract\": [BLUE_CONTRACT_ADDRESS],\n",
" \"topic0\": [SUPPLY_TOPIC],\n",
" \"topic0\": [SUPPLY_SIG_HASH],\n",
"}\n",
"blue_supply_raw = cryo.collect(\n",
" **params\n",
Expand All @@ -403,7 +403,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -458,7 +458,7 @@
"└───────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴──────────┘"
]
},
"execution_count": 7,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -469,7 +469,7 @@
" \"blocks\": [\"18.9M:\"],\n",
" \"inner_request_size\": 10000,\n",
" \"contract\": [BLUE_CONTRACT_ADDRESS],\n",
" \"topic0\": [WITHDRAW_TOPIC],\n",
" \"topic0\": [WITHDRAW_SIG_HASH],\n",
"}\n",
"\n",
"blue_withdraw_raw = cryo.collect(\n",
Expand All @@ -490,7 +490,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 29,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -540,7 +540,7 @@
"└──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴───────────┴───────────┘"
]
},
"execution_count": 8,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -552,7 +552,7 @@
" \"blocks\": [\"18.9M:\"],\n",
" \"inner_request_size\": 10000,\n",
" \"contract\": [BLUE_CONTRACT_ADDRESS],\n",
" \"topic0\": [SUPPLY_COLLATERAL_TOPIC]\n",
" \"topic0\": [SUPPLY_COLLATERAL_SIG_HASH]\n",
"}\n",
"\n",
"blue_supply_collateral_raw = cryo.collect(\n",
Expand All @@ -573,7 +573,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -628,7 +628,7 @@
"└────────────┴────────────┴────────────┴───────────┴───────────┴───────────┴───────────┴───────────┘"
]
},
"execution_count": 9,
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -640,7 +640,7 @@
" \"blocks\": [\"18.9M:\"],\n",
" \"inner_request_size\": 10000,\n",
" \"contract\": [BLUE_CONTRACT_ADDRESS],\n",
" \"topic0\": [WITHDRAW_COLLATERAL_TOPIC]\n",
" \"topic0\": [WITHDRAW_COLLATERAL_SIG_HASH]\n",
"}\n",
"\n",
"blue_withdraw_collateral_raw = cryo.collect(\n",
Expand All @@ -661,7 +661,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -716,7 +716,7 @@
"└───────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴──────────┘"
]
},
"execution_count": 10,
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -728,7 +728,7 @@
" \"blocks\": [\"18.9M:\"],\n",
" \"inner_request_size\": 10000,\n",
" \"contract\": [BLUE_CONTRACT_ADDRESS],\n",
" \"topic0\": [BORROW_TOPIC]\n",
" \"topic0\": [BORROW_SIG_HASH]\n",
"}\n",
"\n",
"blue_borrow_raw = cryo.collect(\n",
Expand All @@ -749,74 +749,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 35,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Parsing Event name: event Repay\n",
"Indexed types: [('bytes32', 'id'), ('address', 'caller'), ('address', 'onBehalf')]\n",
"Data types: [('uint256', 'assets'), ('uint256', 'shares')]\n"
]
},
{
"data": {
"text/html": [
"<div><style>\n",
".dataframe > thead > tr,\n",
".dataframe > tbody > tr {\n",
" text-align: right;\n",
" white-space: pre-wrap;\n",
"}\n",
"</style>\n",
"<small>shape: (5, 8)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>id</th><th>caller</th><th>onBehalf</th><th>block_number</th><th>transaction_index</th><th>log_index</th><th>assets</th><th>shares</th></tr><tr><td>str</td><td>str</td><td>str</td><td>u32</td><td>u32</td><td>u32</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;0x4a8221eef163…</td><td>&quot;0xa7995f71aa11…</td><td>&quot;0x4563364bd619…</td><td>18942670</td><td>70</td><td>185</td><td>4e7</td><td>3.9997e13</td></tr><tr><td>&quot;0x4a8221eef163…</td><td>&quot;0xa7995f71aa11…</td><td>&quot;0x2b5469940fa5…</td><td>18949974</td><td>81</td><td>160</td><td>100000.0</td><td>9.9991e10</td></tr><tr><td>&quot;0x4a8221eef163…</td><td>&quot;0xa7995f71aa11…</td><td>&quot;0x2b5469940fa5…</td><td>18965474</td><td>31</td><td>109</td><td>3.726e6</td><td>3.7254e12</td></tr><tr><td>&quot;0xd7a576506870…</td><td>&quot;0xa7995f71aa11…</td><td>&quot;0x6e632701fd42…</td><td>18975191</td><td>117</td><td>179</td><td>1.0775e14</td><td>1.0774e20</td></tr><tr><td>&quot;0x4a8221eef163…</td><td>&quot;0x9106cbf2c882…</td><td>&quot;0x9106cbf2c882…</td><td>18982559</td><td>54</td><td>77</td><td>9.5115e9</td><td>9.5088e15</td></tr></tbody></table></div>"
],
"text/plain": [
"shape: (5, 8)\n",
"┌────────────┬────────────┬────────────┬───────────┬───────────┬───────────┬───────────┬───────────┐\n",
"│ id ┆ caller ┆ onBehalf ┆ block_num ┆ transacti ┆ log_index ┆ assets ┆ shares │\n",
"│ --- ┆ --- ┆ --- ┆ ber ┆ on_index ┆ --- ┆ --- ┆ --- │\n",
"│ str ┆ str ┆ str ┆ --- ┆ --- ┆ u32 ┆ f64 ┆ f64 │\n",
"│ ┆ ┆ ┆ u32 ┆ u32 ┆ ┆ ┆ │\n",
"╞════════════╪════════════╪════════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╡\n",
"│ 0x4a8221ee ┆ 0xa7995f71 ┆ 0x4563364b ┆ 18942670 ┆ 70 ┆ 185 ┆ 4e7 ┆ 3.9997e13 │\n",
"│ f163e4bccf ┆ aa11525db0 ┆ d61976ba6f ┆ ┆ ┆ ┆ ┆ │\n",
"│ dedc2a6f46 ┆ 2fc2473c37 ┆ 1297c253be ┆ ┆ ┆ ┆ ┆ │\n",
"│ 96… ┆ de… ┆ ae… ┆ ┆ ┆ ┆ ┆ │\n",
"│ 0x4a8221ee ┆ 0xa7995f71 ┆ 0x2b546994 ┆ 18949974 ┆ 81 ┆ 160 ┆ 100000.0 ┆ 9.9991e10 │\n",
"│ f163e4bccf ┆ aa11525db0 ┆ 0fa577bc40 ┆ ┆ ┆ ┆ ┆ │\n",
"│ dedc2a6f46 ┆ 2fc2473c37 ┆ 82c6940ee4 ┆ ┆ ┆ ┆ ┆ │\n",
"│ 96… ┆ de… ┆ d8… ┆ ┆ ┆ ┆ ┆ │\n",
"│ 0x4a8221ee ┆ 0xa7995f71 ┆ 0x2b546994 ┆ 18965474 ┆ 31 ┆ 109 ┆ 3.726e6 ┆ 3.7254e12 │\n",
"│ f163e4bccf ┆ aa11525db0 ┆ 0fa577bc40 ┆ ┆ ┆ ┆ ┆ │\n",
"│ dedc2a6f46 ┆ 2fc2473c37 ┆ 82c6940ee4 ┆ ┆ ┆ ┆ ┆ │\n",
"│ 96… ┆ de… ┆ d8… ┆ ┆ ┆ ┆ ┆ │\n",
"│ 0xd7a57650 ┆ 0xa7995f71 ┆ 0x6e632701 ┆ 18975191 ┆ 117 ┆ 179 ┆ 1.0775e14 ┆ 1.0774e20 │\n",
"│ 6870346a78 ┆ aa11525db0 ┆ fd42a9b856 ┆ ┆ ┆ ┆ ┆ │\n",
"│ a11a6762e2 ┆ 2fc2473c37 ┆ 294a2172dd ┆ ┆ ┆ ┆ ┆ │\n",
"│ cc… ┆ de… ┆ 63… ┆ ┆ ┆ ┆ ┆ │\n",
"│ 0x4a8221ee ┆ 0x9106cbf2 ┆ 0x9106cbf2 ┆ 18982559 ┆ 54 ┆ 77 ┆ 9.5115e9 ┆ 9.5088e15 │\n",
"│ f163e4bccf ┆ c882340b23 ┆ c882340b23 ┆ ┆ ┆ ┆ ┆ │\n",
"│ dedc2a6f46 ┆ cc40985c05 ┆ cc40985c05 ┆ ┆ ┆ ┆ ┆ │\n",
"│ 96… ┆ 64… ┆ 64… ┆ ┆ ┆ ┆ ┆ │\n",
"└────────────┴────────────┴────────────┴───────────┴───────────┴───────────┴───────────┴───────────┘"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"\n",
"params = {\n",
" \"datatype\": \"events\",\n",
" \"blocks\": [\"18.9M:\"],\n",
" \"inner_request_size\": 10000,\n",
" \"contract\": [BLUE_CONTRACT_ADDRESS],\n",
" \"topic0\": [REPAY_TOPIC]\n",
" \"topic0\": [REPAY_SIG_HASH]\n",
"}\n",
"\n",
"blue_repay_raw = cryo.collect(\n",
Expand All @@ -837,7 +780,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 33,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -892,7 +835,7 @@
"└───────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴──────────┘"
]
},
"execution_count": 12,
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -903,14 +846,14 @@
" \"blocks\": [\"18.9M:\"],\n",
" \"inner_request_size\": 10000,\n",
" \"contract\": [BLUE_CONTRACT_ADDRESS],\n",
" \"topic0\": [LIQUIDATION_TOPIC]\n",
" \"topic0\": [LIQUIDATE_SIG_HASH]\n",
"}\n",
"\n",
"blue_liquidation_raw = cryo.collect(\n",
" **params\n",
")\n",
"\n",
"blue_liquidation = parse_raw_events(blue_liquidation_raw, LIQUIDATION_SIG)\n",
"blue_liquidation = parse_raw_events(blue_liquidation_raw, LIQUIDATE_SIG)\n",
"\n",
"blue_liquidation.head(5)"
]
Expand All @@ -924,7 +867,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 34,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -974,7 +917,7 @@
"└────────────────┴──────────────┴───────────────┴───────────┴───────────────┴──────────┴───────────┘"
]
},
"execution_count": 13,
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -986,14 +929,14 @@
" \"blocks\": [\"18.9M:\"],\n",
" \"inner_request_size\": 10000,\n",
" \"contract\": [BLUE_CONTRACT_ADDRESS],\n",
" \"topic0\": [INTEREST_TOPIC]\n",
" \"topic0\": [ACCRUE_INTEREST_SIG_HASH]\n",
"}\n",
"\n",
"blue_interest_raw = cryo.collect(\n",
" **params\n",
")\n",
"\n",
"blue_interest = parse_raw_events(blue_interest_raw, INTEREST_SIG)\n",
"blue_interest = parse_raw_events(blue_interest_raw, ACCRUE_INTEREST_SIG)\n",
"\n",
"blue_interest.head(5)"
]
Expand Down

0 comments on commit dc1d948

Please sign in to comment.