Fixed problem with logging messages and token dereference.

This commit is contained in:
Geoff Taylor 2021-05-02 14:36:16 +01:00
parent 9881f5f3dc
commit 9ff7619985
3 changed files with 41 additions and 40 deletions

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "olympic-beatles",
"id": "historical-repeat",
"metadata": {},
"source": [
"# ⚠ Warning\n",
@ -16,7 +16,7 @@
},
{
"cell_type": "markdown",
"id": "meaning-feature",
"id": "pretty-cylinder",
"metadata": {},
"source": [
"# 🥭 Context\n",
@ -26,7 +26,7 @@
},
{
"cell_type": "markdown",
"id": "assigned-american",
"id": "interim-cherry",
"metadata": {},
"source": [
"## Environment Variables\n",
@ -41,7 +41,7 @@
},
{
"cell_type": "markdown",
"id": "written-heavy",
"id": "generous-handy",
"metadata": {},
"source": [
"## Provided Configured Objects\n",
@ -61,7 +61,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cross-passport",
"id": "commercial-milton",
"metadata": {
"jupyter": {
"source_hidden": true
@ -87,7 +87,7 @@
},
{
"cell_type": "markdown",
"id": "corrected-disclaimer",
"id": "boxed-peoples",
"metadata": {},
"source": [
"## AccountInfo class\n",
@ -98,7 +98,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cutting-miller",
"id": "metropolitan-layer",
"metadata": {},
"outputs": [],
"source": [
@ -142,7 +142,7 @@
},
{
"cell_type": "markdown",
"id": "flying-mount",
"id": "unauthorized-cycling",
"metadata": {},
"source": [
"## Context class"
@ -151,7 +151,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "strong-recycling",
"id": "steady-hotel",
"metadata": {},
"outputs": [],
"source": [
@ -268,13 +268,14 @@
" return Context._lookup_name_by_address(token_address, MangoConstants[self.cluster][\"symbols\"]) or \"« Unknown Token »\"\n",
"\n",
" def wait_for_confirmation(self, transaction_id: str, max_wait_in_seconds: int = 60) -> None:\n",
" self.logger.info(f\"Waiting up to {max_wait_in_seconds} seconds for {transaction_id}.\")\n",
" for wait in range(0, max_wait_in_seconds):\n",
" time.sleep(1)\n",
" confirmed = default_context.client.get_confirmed_transaction(transaction_id)\n",
" if confirmed[\"result\"] is not None:\n",
" print(f\"Confirmed after {wait} seconds.\")\n",
" self.logger.info(f\"Confirmed after {wait} seconds.\")\n",
" return\n",
" print(f\"Timed out after {wait} seconds waiting on transaction {transaction_id}.\")\n",
" self.logger.info(f\"Timed out after {wait} seconds waiting on transaction {transaction_id}.\")\n",
"\n",
" def __str__(self) -> str:\n",
" return f\"\"\"« Context:\n",
@ -292,7 +293,7 @@
},
{
"cell_type": "markdown",
"id": "defined-station",
"id": "stainless-aurora",
"metadata": {},
"source": [
"## default_context object\n",
@ -303,7 +304,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "enhanced-victor",
"id": "geographic-chaos",
"metadata": {},
"outputs": [],
"source": [
@ -322,7 +323,7 @@
},
{
"cell_type": "markdown",
"id": "metric-attachment",
"id": "alternative-surname",
"metadata": {},
"source": [
"## solana_context object\n",
@ -333,7 +334,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "vietnamese-reducing",
"id": "individual-extraction",
"metadata": {},
"outputs": [],
"source": [
@ -345,7 +346,7 @@
},
{
"cell_type": "markdown",
"id": "vocational-salvation",
"id": "systematic-split",
"metadata": {},
"source": [
"## serum_context object\n",
@ -356,7 +357,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "combined-messaging",
"id": "political-trading",
"metadata": {},
"outputs": [],
"source": [
@ -368,7 +369,7 @@
},
{
"cell_type": "markdown",
"id": "hollywood-administrator",
"id": "quarterly-breast",
"metadata": {},
"source": [
"# 🏃 Running\n",
@ -379,7 +380,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "handmade-following",
"id": "religious-amateur",
"metadata": {},
"outputs": [],
"source": [

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "suitable-circuit",
"id": "pressing-banner",
"metadata": {},
"source": [
"# ⚠ Warning\n",
@ -16,7 +16,7 @@
},
{
"cell_type": "markdown",
"id": "natural-persian",
"id": "champion-control",
"metadata": {},
"source": [
"# 🥭 Liquidation\n",
@ -31,7 +31,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "interesting-fleet",
"id": "awful-rocket",
"metadata": {
"jupyter": {
"source_hidden": true
@ -49,7 +49,7 @@
},
{
"cell_type": "markdown",
"id": "overall-canadian",
"id": "compact-english",
"metadata": {},
"source": [
"## 🦺 Safety\n",
@ -63,7 +63,7 @@
},
{
"cell_type": "markdown",
"id": "false-billy",
"id": "revised-premises",
"metadata": {},
"source": [
"## 📇 Collateralisation Ratios Details\n",
@ -81,7 +81,7 @@
},
{
"cell_type": "markdown",
"id": "polish-hartford",
"id": "found-lloyd",
"metadata": {},
"source": [
"# 💧 Liquidation Process"
@ -89,7 +89,7 @@
},
{
"cell_type": "markdown",
"id": "productive-mailman",
"id": "short-project",
"metadata": {},
"source": [
"## 📇 Steps\n",
@ -117,7 +117,7 @@
},
{
"cell_type": "markdown",
"id": "speaking-retirement",
"id": "cellular-shell",
"metadata": {},
"source": [
"# 🏃 Running\n",
@ -134,17 +134,17 @@
{
"cell_type": "code",
"execution_count": null,
"id": "middle-dancing",
"id": "passing-count",
"metadata": {},
"outputs": [],
"source": [
"MARGIN_ACCOUNT_TO_LIQUIDATE = \"6u4kaF4UT4uZ2oczR63nHtydXGevDRBpSYNXGsHNNXVL\""
"MARGIN_ACCOUNT_TO_LIQUIDATE = \"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "virtual-capitol",
"id": "naughty-compiler",
"metadata": {},
"outputs": [],
"source": [

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "standard-football",
"id": "dressed-devices",
"metadata": {},
"source": [
"# ⚠ Warning\n",
@ -16,7 +16,7 @@
},
{
"cell_type": "markdown",
"id": "little-africa",
"id": "random-numbers",
"metadata": {},
"source": [
"# 🥭 SimpleLiquidator\n",
@ -27,7 +27,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "rubber-given",
"id": "excited-sword",
"metadata": {
"jupyter": {
"source_hidden": true
@ -46,7 +46,7 @@
},
{
"cell_type": "markdown",
"id": "chinese-lease",
"id": "manual-captain",
"metadata": {},
"source": [
"# SimpleLiquidator class\n",
@ -68,14 +68,14 @@
{
"cell_type": "code",
"execution_count": null,
"id": "positive-capacity",
"id": "positive-champagne",
"metadata": {},
"outputs": [],
"source": [
"def token_balances_from_wallet(context: Context, wallet: Wallet, group: Group) -> typing.List[TokenValue]:\n",
" balances: typing.List[TokenValue] = []\n",
" for token in group.tokens:\n",
" balance = TokenValue(token.token, context.fetch_token_balance(wallet.address, token.mint))\n",
" balance = TokenValue(token, context.fetch_token_balance(wallet.address, token.mint))\n",
" balances += [balance]\n",
"\n",
" return balances\n",
@ -157,14 +157,14 @@
" group_after = Group.load(self.context)\n",
" margin_account_after_liquidation = MarginAccount.load(self.context, mam.margin_account.address, group_after)\n",
" intrinsic_balances_after = margin_account_after_liquidation.get_intrinsic_balances(group_after)\n",
" self.logger.info(\"Margin Account After:\", intrinsic_balances_after)\n",
" self.logger.info(f\"Margin account balances after: {intrinsic_balances_after}\")\n",
" wallet_balances_after = token_balances_from_wallet(self.context, self.wallet, group)\n",
" self.logger.info(f\"Wallet balances after:\\n{wallet_balances_after}\")\n"
]
},
{
"cell_type": "markdown",
"id": "organic-leather",
"id": "fallen-sustainability",
"metadata": {},
"source": [
"# 🏃 Running"
@ -173,7 +173,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "blind-logic",
"id": "excited-recycling",
"metadata": {},
"outputs": [],
"source": [