Added logging objects to classes.

This commit is contained in:
Geoff Taylor 2021-04-26 16:43:40 +01:00
parent add7f5648c
commit 1c6c81cc0d
7 changed files with 213 additions and 156 deletions

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "eleven-plenty", "id": "instrumental-enlargement",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ⚠ Warning\n", "# ⚠ Warning\n",
@ -16,7 +16,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "limiting-stanford", "id": "alleged-creator",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🥭 AccountScout\n", "# 🥭 AccountScout\n",
@ -28,7 +28,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "documentary-darwin", "id": "becoming-kingston",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Required Accounts\n", "## Required Accounts\n",
@ -47,7 +47,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "finished-today", "id": "regulated-senate",
"metadata": { "metadata": {
"jupyter": { "jupyter": {
"source_hidden": true "source_hidden": true
@ -55,6 +55,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"import logging\n",
"import typing\n", "import typing\n",
"\n", "\n",
"from solana.publickey import PublicKey\n", "from solana.publickey import PublicKey\n",
@ -67,7 +68,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "velvet-contributor", "id": "varying-cocktail",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ScoutReport class\n", "# ScoutReport class\n",
@ -78,7 +79,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "expensive-producer", "id": "short-british",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -141,7 +142,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "dated-citizenship", "id": "governing-intervention",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# AccountScout class\n", "# AccountScout class\n",
@ -154,7 +155,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "unlimited-study", "id": "peaceful-clear",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -234,7 +235,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "italian-demographic", "id": "advised-stanford",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🏃 Running\n", "# 🏃 Running\n",
@ -247,7 +248,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "joint-savage", "id": "mental-burns",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -257,11 +258,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "rational-agriculture", "id": "million-intelligence",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"if __name__ == \"__main__\":\n", "if __name__ == \"__main__\":\n",
" logging.basicConfig(level=logging.DEBUG)\n",
"\n",
" if ACCOUNT_TO_VERIFY == \"\":\n", " if ACCOUNT_TO_VERIFY == \"\":\n",
" raise Exception(\"No account to look up - try setting the variable ACCOUNT_TO_LOOK_UP to an account public key.\")\n", " raise Exception(\"No account to look up - try setting the variable ACCOUNT_TO_LOOK_UP to an account public key.\")\n",
"\n", "\n",

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "responsible-sample", "id": "specific-litigation",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ⚠ Warning\n", "# ⚠ Warning\n",
@ -16,7 +16,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "adequate-rotation", "id": "brilliant-burlington",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🥭 Classes\n", "# 🥭 Classes\n",
@ -33,7 +33,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "silver-prospect", "id": "choice-sunset",
"metadata": { "metadata": {
"jupyter": { "jupyter": {
"source_hidden": true "source_hidden": true
@ -43,6 +43,7 @@
"source": [ "source": [
"import datetime\n", "import datetime\n",
"import enum\n", "import enum\n",
"import logging\n",
"import typing\n", "import typing\n",
"\n", "\n",
"import Layouts as layouts\n", "import Layouts as layouts\n",
@ -60,7 +61,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "developed-initial", "id": "loaded-baltimore",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Version enum\n", "## Version enum\n",
@ -71,7 +72,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "clean-recorder", "id": "likely-harmony",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -86,7 +87,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "noticed-immunology", "id": "sustainable-liverpool",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## SerumAccountFlags class\n", "## SerumAccountFlags class\n",
@ -97,13 +98,14 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "damaged-sport", "id": "adaptive-light",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class SerumAccountFlags:\n", "class SerumAccountFlags:\n",
" def __init__(self, version: Version, initialized: bool, market: bool, open_orders: bool, request_queue: bool,\n", " def __init__(self, version: Version, initialized: bool, market: bool, open_orders: bool, request_queue: bool,\n",
" event_queue: bool, bids: bool, asks: bool, disabled: bool):\n", " event_queue: bool, bids: bool, asks: bool, disabled: bool):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.initialized = initialized\n", " self.initialized = initialized\n",
" self.market = market\n", " self.market = market\n",
@ -139,7 +141,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "massive-choice", "id": "brilliant-block",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## MangoAccountFlags class\n", "## MangoAccountFlags class\n",
@ -150,12 +152,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "leading-external", "id": "assigned-acrylic",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MangoAccountFlags:\n", "class MangoAccountFlags:\n",
" def __init__(self, version: Version, initialized: bool, group: bool, margin_account: bool, srm_account: bool):\n", " def __init__(self, version: Version, initialized: bool, group: bool, margin_account: bool, srm_account: bool):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.initialized = initialized\n", " self.initialized = initialized\n",
" self.group = group\n", " self.group = group\n",
@ -183,7 +186,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "talented-therapy", "id": "indoor-marking",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Index class" "## Index class"
@ -192,12 +195,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "french-sunrise", "id": "yellow-miami",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Index:\n", "class Index:\n",
" def __init__(self, version: Version, last_update: datetime.datetime, borrow: Decimal, deposit: Decimal):\n", " def __init__(self, version: Version, last_update: datetime.datetime, borrow: Decimal, deposit: Decimal):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.last_update: datetime.datetime = last_update\n", " self.last_update: datetime.datetime = last_update\n",
" self.borrow: Decimal = borrow\n", " self.borrow: Decimal = borrow\n",
@ -218,7 +222,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "fewer-eating", "id": "special-paradise",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## AggregatorConfig class" "## AggregatorConfig class"
@ -227,7 +231,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "jewish-specification", "id": "offshore-albuquerque",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -235,6 +239,7 @@
" def __init__(self, version: Version, description: str, decimals: Decimal, restart_delay: Decimal,\n", " def __init__(self, version: Version, description: str, decimals: Decimal, restart_delay: Decimal,\n",
" max_submissions: Decimal, min_submissions: Decimal, reward_amount: Decimal,\n", " max_submissions: Decimal, min_submissions: Decimal, reward_amount: Decimal,\n",
" reward_token_account: PublicKey):\n", " reward_token_account: PublicKey):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.description: str = description\n", " self.description: str = description\n",
" self.decimals: Decimal = decimals\n", " self.decimals: Decimal = decimals\n",
@ -259,7 +264,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "formal-language", "id": "bright-constitution",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Round class" "## Round class"
@ -268,12 +273,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "endangered-directive", "id": "wooden-prerequisite",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Round:\n", "class Round:\n",
" def __init__(self, version: Version, id: Decimal, created_at: datetime.datetime, updated_at: datetime.datetime):\n", " def __init__(self, version: Version, id: Decimal, created_at: datetime.datetime, updated_at: datetime.datetime):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.id: Decimal = id\n", " self.id: Decimal = id\n",
" self.created_at: datetime.datetime = created_at\n", " self.created_at: datetime.datetime = created_at\n",
@ -292,7 +298,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "potential-reader", "id": "intended-princess",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Answer class" "## Answer class"
@ -301,12 +307,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "naked-worker", "id": "geological-merit",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Answer:\n", "class Answer:\n",
" def __init__(self, version: Version, round_id: Decimal, median: Decimal, created_at: datetime.datetime, updated_at: datetime.datetime):\n", " def __init__(self, version: Version, round_id: Decimal, median: Decimal, created_at: datetime.datetime, updated_at: datetime.datetime):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.round_id: Decimal = round_id\n", " self.round_id: Decimal = round_id\n",
" self.median: Decimal = median\n", " self.median: Decimal = median\n",
@ -326,7 +333,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "residential-scientist", "id": "regulated-worship",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Aggregator class" "## Aggregator class"
@ -335,7 +342,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "loaded-lecture", "id": "mighty-amateur",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -343,6 +350,7 @@
" def __init__(self, version: Version, config: AggregatorConfig, initialized: bool, name: str,\n", " def __init__(self, version: Version, config: AggregatorConfig, initialized: bool, name: str,\n",
" address: PublicKey, owner: PublicKey, round_: Round, round_submissions: PublicKey,\n", " address: PublicKey, owner: PublicKey, round_: Round, round_submissions: PublicKey,\n",
" answer: Answer, answer_submissions: PublicKey):\n", " answer: Answer, answer_submissions: PublicKey):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.config: AggregatorConfig = config\n", " self.config: AggregatorConfig = config\n",
" self.initialized: bool = initialized\n", " self.initialized: bool = initialized\n",
@ -401,7 +409,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "later-belarus", "id": "narrative-revision",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## BasketTokenMetadata class\n" "## BasketTokenMetadata class\n"
@ -410,12 +418,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "greatest-causing", "id": "brief-occasions",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class BasketTokenMetadata:\n", "class BasketTokenMetadata:\n",
" def __init__(self, name: str, mint: PublicKey, decimals: Decimal, vault: PublicKey, index: Index):\n", " def __init__(self, name: str, mint: PublicKey, decimals: Decimal, vault: PublicKey, index: Index):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.name: str = name\n", " self.name: str = name\n",
" self.mint: PublicKey = mint\n", " self.mint: PublicKey = mint\n",
" self.decimals: Decimal = decimals\n", " self.decimals: Decimal = decimals\n",
@ -438,7 +447,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "intensive-regulation", "id": "opposite-turkey",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## MarketMetadata class" "## MarketMetadata class"
@ -447,13 +456,14 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "short-malawi", "id": "extreme-marsh",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MarketMetadata:\n", "class MarketMetadata:\n",
" def __init__(self, name: str, address: PublicKey, base: BasketTokenMetadata, quote: BasketTokenMetadata,\n", " def __init__(self, name: str, address: PublicKey, base: BasketTokenMetadata, quote: BasketTokenMetadata,\n",
" spot: PublicKey, oracle: PublicKey, decimals: Decimal):\n", " spot: PublicKey, oracle: PublicKey, decimals: Decimal):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.name: str = name\n", " self.name: str = name\n",
" self.address: PublicKey = address\n", " self.address: PublicKey = address\n",
" self.base: BasketTokenMetadata = base\n", " self.base: BasketTokenMetadata = base\n",
@ -482,7 +492,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "golden-intermediate", "id": "worth-commons",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Group class" "## Group class"
@ -491,7 +501,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "adaptive-protection", "id": "front-pendant",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -503,6 +513,7 @@
" total_deposits: typing.List[Decimal], total_borrows: typing.List[Decimal],\n", " total_deposits: typing.List[Decimal], total_borrows: typing.List[Decimal],\n",
" maint_coll_ratio: Decimal, init_coll_ratio: Decimal, srm_vault: PublicKey,\n", " maint_coll_ratio: Decimal, init_coll_ratio: Decimal, srm_vault: PublicKey,\n",
" admin: PublicKey, borrow_limits: typing.List[Decimal]):\n", " admin: PublicKey, borrow_limits: typing.List[Decimal]):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.context: Context = context\n", " self.context: Context = context\n",
" self.address: PublicKey = address\n", " self.address: PublicKey = address\n",
@ -609,7 +620,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "neither-infrastructure", "id": "sunrise-genome",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## TokenAccount class" "## TokenAccount class"
@ -618,12 +629,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "headed-sacrifice", "id": "immune-struggle",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class TokenAccount:\n", "class TokenAccount:\n",
" def __init__(self, version: Version, mint: PublicKey, owner: PublicKey, amount: Decimal):\n", " def __init__(self, version: Version, mint: PublicKey, owner: PublicKey, amount: Decimal):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.mint: PublicKey = mint\n", " self.mint: PublicKey = mint\n",
" self.owner: PublicKey = owner\n", " self.owner: PublicKey = owner\n",
@ -650,7 +662,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "alleged-firmware", "id": "indian-literacy",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## OpenOrders class\n" "## OpenOrders class\n"
@ -659,7 +671,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "sapphire-qualification", "id": "separated-edinburgh",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -670,6 +682,7 @@
" quote_token_total: Decimal, free_slot_bits: Decimal, is_bid_bits: Decimal,\n", " quote_token_total: Decimal, free_slot_bits: Decimal, is_bid_bits: Decimal,\n",
" orders: typing.List[Decimal], client_ids: typing.List[Decimal],\n", " orders: typing.List[Decimal], client_ids: typing.List[Decimal],\n",
" referrer_rebate_accrued: Decimal):\n", " referrer_rebate_accrued: Decimal):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.group: Group = group\n", " self.group: Group = group\n",
" self.address: PublicKey = address\n", " self.address: PublicKey = address\n",
@ -759,7 +772,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "primary-netherlands", "id": "motivated-honey",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## BalanceSheet class" "## BalanceSheet class"
@ -768,12 +781,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "stunning-carnival", "id": "compliant-glasgow",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class BalanceSheet:\n", "class BalanceSheet:\n",
" def __init__(self, token: typing.Optional[BasketTokenMetadata], liabilities: Decimal, settled_assets: Decimal, unsettled_assets: Decimal):\n", " def __init__(self, token: typing.Optional[BasketTokenMetadata], liabilities: Decimal, settled_assets: Decimal, unsettled_assets: Decimal):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.token: typing.Optional[BasketTokenMetadata] = token\n", " self.token: typing.Optional[BasketTokenMetadata] = token\n",
" self.liabilities: Decimal = liabilities\n", " self.liabilities: Decimal = liabilities\n",
" self.settled_assets: Decimal = settled_assets\n", " self.settled_assets: Decimal = settled_assets\n",
@ -814,7 +828,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "asian-donor", "id": "funky-royal",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## MarginAccount class\n" "## MarginAccount class\n"
@ -823,7 +837,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "missing-eight", "id": "intimate-kingston",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -831,6 +845,7 @@
" def __init__(self, version: Version, address: PublicKey, account_flags: MangoAccountFlags,\n", " def __init__(self, version: Version, address: PublicKey, account_flags: MangoAccountFlags,\n",
" mango_group: PublicKey, owner: PublicKey, deposits: typing.List[Decimal],\n", " mango_group: PublicKey, owner: PublicKey, deposits: typing.List[Decimal],\n",
" borrows: typing.List[Decimal], open_orders: typing.List[PublicKey]):\n", " borrows: typing.List[Decimal], open_orders: typing.List[PublicKey]):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.version: Version = version\n", " self.version: Version = version\n",
" self.address: PublicKey = address\n", " self.address: PublicKey = address\n",
" self.account_flags: MangoAccountFlags = account_flags\n", " self.account_flags: MangoAccountFlags = account_flags\n",
@ -1005,7 +1020,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "attended-backing", "id": "robust-learning",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🏃 Running" "# 🏃 Running"
@ -1014,11 +1029,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "altered-danger", "id": "retained-litigation",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"if __name__ == \"__main__\":\n", "if __name__ == \"__main__\":\n",
" logging.basicConfig(level=logging.DEBUG)\n",
"\n",
" import base64\n", " import base64\n",
" from Context import default_context\n", " from Context import default_context\n",
"\n", "\n",

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "characteristic-evidence", "id": "composite-former",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ⚠ Warning\n", "# ⚠ Warning\n",
@ -16,7 +16,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "regulated-forward", "id": "accompanied-harvest",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🥭 Context\n", "# 🥭 Context\n",
@ -26,7 +26,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "medium-gravity", "id": "hydraulic-vampire",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Environment Variables\n", "## Environment Variables\n",
@ -41,7 +41,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "continuous-service", "id": "executive-wells",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Provided Configured Objects\n", "## Provided Configured Objects\n",
@ -61,7 +61,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "under-millennium", "id": "medical-gregory",
"metadata": { "metadata": {
"jupyter": { "jupyter": {
"source_hidden": true "source_hidden": true
@ -69,6 +69,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"import logging\n",
"import os\n", "import os\n",
"import typing\n", "import typing\n",
"\n", "\n",
@ -85,7 +86,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "naval-killing", "id": "liked-picnic",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## AccountInfo class\n", "## AccountInfo class\n",
@ -96,12 +97,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "pleased-plaza", "id": "japanese-intro",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class AccountInfo:\n", "class AccountInfo:\n",
" def __init__(self, address: PublicKey, executable: bool, lamports: Decimal, owner: PublicKey, rent_epoch: Decimal, data: bytes):\n", " def __init__(self, address: PublicKey, executable: bool, lamports: Decimal, owner: PublicKey, rent_epoch: Decimal, data: bytes):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.address: PublicKey = address\n", " self.address: PublicKey = address\n",
" self.executable: bool = executable\n", " self.executable: bool = executable\n",
" self.lamports: Decimal = lamports\n", " self.lamports: Decimal = lamports\n",
@ -139,7 +141,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "separate-capacity", "id": "built-insight",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Context class" "## Context class"
@ -148,13 +150,14 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "blessed-biography", "id": "disturbed-austria",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Context:\n", "class Context:\n",
" def __init__(self, cluster: str, cluster_url: str, program_id: PublicKey, dex_program_id: PublicKey,\n", " def __init__(self, cluster: str, cluster_url: str, program_id: PublicKey, dex_program_id: PublicKey,\n",
" group_name: str, group_id: PublicKey):\n", " group_name: str, group_id: PublicKey):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.cluster: str = cluster\n", " self.cluster: str = cluster\n",
" self.cluster_url: str = cluster_url\n", " self.cluster_url: str = cluster_url\n",
" self.client: Client = Client(cluster_url)\n", " self.client: Client = Client(cluster_url)\n",
@ -278,7 +281,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "rising-anthony", "id": "fabulous-designation",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## default_context object\n", "## default_context object\n",
@ -289,7 +292,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "victorian-gossip", "id": "adequate-custom",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -308,7 +311,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "precious-twins", "id": "vulnerable-prophet",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## solana_context object\n", "## solana_context object\n",
@ -319,7 +322,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "dramatic-indication", "id": "electrical-chapter",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -331,7 +334,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "radical-avenue", "id": "fuzzy-break",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## serum_context object\n", "## serum_context object\n",
@ -342,7 +345,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "infinite-giant", "id": "little-exploration",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -354,7 +357,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "alone-stanford", "id": "contrary-fiber",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🏃 Running\n", "# 🏃 Running\n",
@ -365,11 +368,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "noticed-aquarium", "id": "boolean-spectacular",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"if __name__ == \"__main__\":\n", "if __name__ == \"__main__\":\n",
" logging.basicConfig(level=logging.DEBUG)\n",
"\n",
" print(default_context)\n", " print(default_context)\n",
"\n", "\n",
" single_account_info = default_context.load_account(default_context.dex_program_id)\n", " single_account_info = default_context.load_account(default_context.dex_program_id)\n",

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "joint-pride", "id": "compressed-rendering",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ⚠ Warning\n", "# ⚠ Warning\n",
@ -16,7 +16,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "optical-effects", "id": "southwest-trauma",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🥭 Instructions\n", "# 🥭 Instructions\n",
@ -27,11 +27,16 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "buried-colombia", "id": "vocational-arabic",
"metadata": {}, "metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import abc\n", "import abc\n",
"import logging\n",
"import struct\n", "import struct\n",
"import typing\n", "import typing\n",
"\n", "\n",
@ -50,7 +55,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "mobile-enforcement", "id": "acceptable-sheep",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# InstructionBuilder class\n", "# InstructionBuilder class\n",
@ -61,12 +66,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "interstate-thirty", "id": "arctic-robertson",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class InstructionBuilder(metaclass=abc.ABCMeta):\n", "class InstructionBuilder(metaclass=abc.ABCMeta):\n",
" def __init__(self, context: Context):\n", " def __init__(self, context: Context):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.context = context\n", " self.context = context\n",
"\n", "\n",
" @abc.abstractmethod\n", " @abc.abstractmethod\n",
@ -79,7 +85,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "according-oriental", "id": "native-manor",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ForceCancelOrdersInstructionBuilder class" "# ForceCancelOrdersInstructionBuilder class"
@ -87,7 +93,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "dying-camping", "id": "unlikely-phone",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Rust Interface\n", "## Rust Interface\n",
@ -119,7 +125,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "golden-falls", "id": "theoretical-conversation",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Client API call\n", "## Client API call\n",
@ -163,7 +169,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "listed-armor", "id": "national-behavior",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -187,7 +193,7 @@
" self.dex_signer = dex_signer\n", " self.dex_signer = dex_signer\n",
"\n", "\n",
" def build(self) -> TransactionInstruction:\n", " def build(self) -> TransactionInstruction:\n",
" return TransactionInstruction(\n", " transaction = TransactionInstruction(\n",
" keys=[\n", " keys=[\n",
" AccountMeta(is_signer=False, is_writable=True, pubkey=self.group.address),\n", " AccountMeta(is_signer=False, is_writable=True, pubkey=self.group.address),\n",
" AccountMeta(is_signer=True, is_writable=False, pubkey=self.wallet.address),\n", " AccountMeta(is_signer=True, is_writable=False, pubkey=self.wallet.address),\n",
@ -211,6 +217,8 @@
" program_id=self.context.program_id,\n", " program_id=self.context.program_id,\n",
" data=FORCE_CANCEL.build({\"limit\": ForceCancelOrdersInstructionBuilder.max_cancels_per_instruction})\n", " data=FORCE_CANCEL.build({\"limit\": ForceCancelOrdersInstructionBuilder.max_cancels_per_instruction})\n",
" )\n", " )\n",
" self.logger.debug(f\"Built transaction: {transaction}\")\n",
" return transaction\n",
"\n", "\n",
" @staticmethod\n", " @staticmethod\n",
" def from_margin_account_and_market(context: Context, group: Group, wallet: Wallet, margin_account: MarginAccount, market_metadata: MarketMetadata) -> \"ForceCancelOrdersInstructionBuilder\":\n", " def from_margin_account_and_market(context: Context, group: Group, wallet: Wallet, margin_account: MarginAccount, market_metadata: MarketMetadata) -> \"ForceCancelOrdersInstructionBuilder\":\n",
@ -221,8 +229,10 @@
" \n", " \n",
" return ForceCancelOrdersInstructionBuilder(context, group, wallet, margin_account, market_metadata, market, oracles, dex_signer)\n", " return ForceCancelOrdersInstructionBuilder(context, group, wallet, margin_account, market_metadata, market, oracles, dex_signer)\n",
"\n", "\n",
" @staticmethod\n", " @classmethod\n",
" def multiple_instructions_from_margin_account_and_market(context: Context, group: Group, wallet: Wallet, margin_account: MarginAccount, market_metadata: MarketMetadata, at_least_this_many_cancellations: int) -> typing.List[\"ForceCancelOrdersInstructionBuilder\"]:\n", " def multiple_instructions_from_margin_account_and_market(context: Context, group: Group, wallet: Wallet, margin_account: MarginAccount, market_metadata: MarketMetadata, at_least_this_many_cancellations: int) -> typing.List[\"ForceCancelOrdersInstructionBuilder\"]:\n",
" logger: logging.Logger = logging.getLogger(cls.__name__)\n",
"\n",
" # We cancel up to max_cancels_per_instruction orders with each instruction, but if\n", " # We cancel up to max_cancels_per_instruction orders with each instruction, but if\n",
" # we have more than cancel_limit we create more instructions (each handling up to\n", " # we have more than cancel_limit we create more instructions (each handling up to\n",
" # 5 orders)\n", " # 5 orders)\n",
@ -235,6 +245,8 @@
" for counter in range(instruction_count):\n", " for counter in range(instruction_count):\n",
" instructions += [ForceCancelOrdersInstructionBuilder.from_margin_account_and_market(context, group, wallet, margin_account, market_metadata)]\n", " instructions += [ForceCancelOrdersInstructionBuilder.from_margin_account_and_market(context, group, wallet, margin_account, market_metadata)]\n",
"\n", "\n",
" logger.debug(f\"Built {len(instructions)} transaction(s).\")\n",
"\n",
" return instructions\n", " return instructions\n",
"\n", "\n",
" def __str__(self) -> str:\n", " def __str__(self) -> str:\n",
@ -263,7 +275,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "charged-plaintiff", "id": "second-amino",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# LiquidateInstructionBuilder class\n", "# LiquidateInstructionBuilder class\n",
@ -275,7 +287,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "looking-western", "id": "cutting-distance",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Rust Interface\n", "## Rust Interface\n",
@ -321,7 +333,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "invisible-theater", "id": "alternate-america",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Client API call\n", "## Client API call\n",
@ -358,7 +370,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "incoming-proceeding", "id": "caroline-liver",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## from_margin_account_and_market() function\n", "## from_margin_account_and_market() function\n",
@ -379,7 +391,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "applied-exception", "id": "creative-witness",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -397,7 +409,7 @@
" self.maximum_input_amount: Decimal = maximum_input_amount\n", " self.maximum_input_amount: Decimal = maximum_input_amount\n",
"\n", "\n",
" def build(self) -> TransactionInstruction:\n", " def build(self) -> TransactionInstruction:\n",
" return TransactionInstruction(\n", " transaction = TransactionInstruction(\n",
" keys=[\n", " keys=[\n",
" AccountMeta(is_signer=False, is_writable=True, pubkey=self.group.address),\n", " AccountMeta(is_signer=False, is_writable=True, pubkey=self.group.address),\n",
" AccountMeta(is_signer=True, is_writable=False, pubkey=self.wallet.address),\n", " AccountMeta(is_signer=True, is_writable=False, pubkey=self.wallet.address),\n",
@ -415,13 +427,17 @@
" program_id=self.context.program_id,\n", " program_id=self.context.program_id,\n",
" data=PARTIAL_LIQUIDATE.build({\"maxDeposit\": int(self.maximum_input_amount)})\n", " data=PARTIAL_LIQUIDATE.build({\"maxDeposit\": int(self.maximum_input_amount)})\n",
" )\n", " )\n",
" self.logger.debug(f\"Built transaction: {transaction}\")\n",
" return transaction\n",
"\n",
" @classmethod\n",
" def from_margin_account_and_market(cls, context: Context, group: Group, wallet: Wallet, margin_account: MarginAccount, prices: typing.List[Decimal]) -> typing.Optional[\"LiquidateInstructionBuilder\"]:\n",
" logger: logging.Logger = logging.getLogger(cls.__name__)\n",
"\n", "\n",
" @staticmethod\n",
" def from_margin_account_and_market(context: Context, group: Group, wallet: Wallet, margin_account: MarginAccount, prices: typing.List[Decimal]) -> typing.Optional[\"LiquidateInstructionBuilder\"]:\n",
" oracles = list([mkt.oracle for mkt in group.markets])\n", " oracles = list([mkt.oracle for mkt in group.markets])\n",
"\n", "\n",
" balance_sheets = margin_account.get_priced_balance_sheets(group, prices)\n", " balance_sheets = margin_account.get_priced_balance_sheets(group, prices)\n",
" print(\"Priced balance sheets\", balance_sheets)\n", " logger.debug(\"Priced balance sheets\", balance_sheets)\n",
"\n", "\n",
" sorted_by_assets = sorted(balance_sheets, key=lambda sheet: sheet.assets)\n", " sorted_by_assets = sorted(balance_sheets, key=lambda sheet: sheet.assets)\n",
" sorted_by_liabilities = sorted(balance_sheets, key=lambda sheet: sheet.liabilities)\n", " sorted_by_liabilities = sorted(balance_sheets, key=lambda sheet: sheet.liabilities)\n",
@ -434,11 +450,11 @@
" most_assets = sorted_by_assets[1]\n", " most_assets = sorted_by_assets[1]\n",
"\n", "\n",
" if most_assets.value == Decimal(0):\n", " if most_assets.value == Decimal(0):\n",
" print(f\"Margin account {margin_account.address} has no assets to take.\")\n", " logger.warning(f\"Margin account {margin_account.address} has no assets to take.\")\n",
" return None\n", " return None\n",
"\n", "\n",
" if most_liabilities.value == Decimal(0):\n", " if most_liabilities.value == Decimal(0):\n",
" print(f\"Margin account {margin_account.address} has no liabilities to fund.\")\n", " logger.warning(f\"Margin account {margin_account.address} has no liabilities to fund.\")\n",
" return None\n", " return None\n",
"\n", "\n",
" wallet_input_token_account = wallet.fetch_largest_token_account(context, most_liabilities.token.mint)\n", " wallet_input_token_account = wallet.fetch_largest_token_account(context, most_liabilities.token.mint)\n",
@ -471,7 +487,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "baking-genealogy", "id": "after-measure",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🏃 Running" "# 🏃 Running"
@ -480,11 +496,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "ultimate-zimbabwe", "id": "regulated-authentication",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"if __name__ == \"__main__\":\n", "if __name__ == \"__main__\":\n",
" logging.basicConfig(level=logging.DEBUG)\n",
"\n",
" import os.path\n", " import os.path\n",
"\n", "\n",
" filename = \"id.json\"\n", " filename = \"id.json\"\n",
@ -512,6 +530,7 @@
" prices = group.get_prices()\n", " prices = group.get_prices()\n",
"\n", "\n",
" liquidate = LiquidateInstructionBuilder.from_margin_account_and_market(default_context, group, wallet, margin_account, prices)\n", " liquidate = LiquidateInstructionBuilder.from_margin_account_and_market(default_context, group, wallet, margin_account, prices)\n",
" if liquidate is not None:\n",
" liquidate_instruction = liquidate.build()\n", " liquidate_instruction = liquidate.build()\n",
" print(\"LiquidateInstruction\", liquidate_instruction, \"Data:\", \" \".join(f\"{x:02x}\" for x in liquidate_instruction.data))\n" " print(\"LiquidateInstruction\", liquidate_instruction, \"Data:\", \" \".join(f\"{x:02x}\" for x in liquidate_instruction.data))\n"
] ]

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "experienced-klein", "id": "indirect-preference",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ⚠ Warning\n", "# ⚠ Warning\n",
@ -16,7 +16,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "postal-albert", "id": "applied-spotlight",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🥭 Layouts\n", "# 🥭 Layouts\n",
@ -35,7 +35,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "external-canyon", "id": "pleasant-butler",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -50,7 +50,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "knowing-astrology", "id": "mobile-zambia",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Adapters\n", "# Adapters\n",
@ -60,7 +60,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "chubby-truck", "id": "minute-million",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## DecimalAdapter class\n", "## DecimalAdapter class\n",
@ -71,7 +71,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "warming-installation", "id": "false-probability",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -89,7 +89,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "radio-business", "id": "knowing-cedar",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Float64Adapter class\n", "## Float64Adapter class\n",
@ -105,7 +105,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "duplicate-induction", "id": "educated-cooling",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -124,7 +124,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "known-jurisdiction", "id": "expected-squad",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## PublicKeyAdapter\n", "## PublicKeyAdapter\n",
@ -135,7 +135,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "desperate-speed", "id": "vulnerable-forward",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -152,7 +152,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "speaking-debut", "id": "eleven-pathology",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## DatetimeAdapter\n", "## DatetimeAdapter\n",
@ -163,7 +163,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "basic-reviewer", "id": "vertical-anderson",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -182,7 +182,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "nonprofit-roberts", "id": "living-harvey",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Layout Structs" "# Layout Structs"
@ -190,7 +190,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "joined-fountain", "id": "amber-headquarters",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## SERUM_ACCOUNT_FLAGS\n", "## SERUM_ACCOUNT_FLAGS\n",
@ -217,7 +217,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "improved-pottery", "id": "experimental-permission",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -238,7 +238,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "opened-injury", "id": "expected-browser",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## MANGO_ACCOUNT_FLAGS\n", "## MANGO_ACCOUNT_FLAGS\n",
@ -263,7 +263,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "respective-remove", "id": "celtic-clearance",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -280,7 +280,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "absent-thailand", "id": "noble-german",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## INDEX\n", "## INDEX\n",
@ -300,7 +300,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "selected-contact", "id": "sensitive-israel",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -313,7 +313,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "turkish-eight", "id": "amateur-handle",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## AGGREGATOR_CONFIG\n", "## AGGREGATOR_CONFIG\n",
@ -349,7 +349,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "individual-fusion", "id": "biblical-canal",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -366,7 +366,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "treated-douglas", "id": "harmful-empty",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## ROUND\n", "## ROUND\n",
@ -385,7 +385,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "chinese-regulation", "id": "proved-sunday",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -398,7 +398,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "entire-mentor", "id": "julian-assessment",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## ANSWER\n", "## ANSWER\n",
@ -418,7 +418,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "monthly-pasta", "id": "right-rally",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -432,7 +432,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "broadband-dealer", "id": "raised-basin",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## AGGREGATOR\n", "## AGGREGATOR\n",
@ -459,7 +459,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "ongoing-consent", "id": "naval-dimension",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -476,7 +476,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "stretch-manhattan", "id": "controlling-kenya",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## GROUP\n", "## GROUP\n",
@ -522,7 +522,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "effective-glass", "id": "unlikely-equality",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -553,7 +553,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "stable-catalyst", "id": "built-superintendent",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## TOKEN_ACCOUNT" "## TOKEN_ACCOUNT"
@ -562,7 +562,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "provincial-nancy", "id": "another-ireland",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -576,7 +576,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "loose-fellowship", "id": "coordinated-distribution",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## OPEN_ORDERS\n", "## OPEN_ORDERS\n",
@ -587,7 +587,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "adaptive-office", "id": "selected-shadow",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -611,7 +611,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "eleven-mathematics", "id": "operational-officer",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## MARGIN_ACCOUNT\n", "## MARGIN_ACCOUNT\n",
@ -643,7 +643,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "square-animation", "id": "flush-notification",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -660,7 +660,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "egyptian-andrew", "id": "compliant-joyce",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## FORCE_CANCEL" "## FORCE_CANCEL"
@ -669,7 +669,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "differential-princess", "id": "grand-contribution",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -681,7 +681,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "changing-madison", "id": "frequent-timothy",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## PARTIAL_LIQUIDATE" "## PARTIAL_LIQUIDATE"
@ -690,7 +690,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "illegal-worthy", "id": "satellite-drive",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -702,7 +702,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "roman-lecture", "id": "unlimited-desperate",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🏃 Running" "# 🏃 Running"
@ -711,11 +711,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "northern-mauritius", "id": "mysterious-spice",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"if __name__ == \"__main__\":\n", "if __name__ == \"__main__\":\n",
" logging.basicConfig(level=logging.DEBUG)\n",
"\n",
" import base64\n", " import base64\n",
"\n", "\n",
" encoded = \"AwAAAAAAAACCaOmpoURMK6XHelGTaFawcuQ/78/15LAemWI8jrt3SRKLy2R9i60eclDjuDS8+p/ZhvTUd9G7uQVOYCsR6+BhmqGCiO6EPYP2PQkf/VRTvw7JjXvIjPFJy06QR1Cq1WfTonHl0OjCkyEf60SD07+MFJu5pVWNFGGEO/8AiAYfduaKdnFTaZEHPcK5Eq72WWHeHg2yIbBF09kyeOhlCJwOoG8O5SgpPV8QOA64ZNV4aKroFfADg6kEy/wWCdp3fv0O4GJgAAAAAPH6Ud6jtjwAAQAAAAAAAADiDkkCi9UOAAEAAAAAAAAADuBiYAAAAACNS5bSy7soAAEAAAAAAAAACMvgO+2jCwABAAAAAAAAAA7gYmAAAAAAZFeDUBNVhwABAAAAAAAAABtRNytozC8AAQAAAAAAAABIBGiCcyaEZdNhrTyeqUY692vOzzPdHaxAxguht3JQGlkzjtd05dX9LENHkl2z1XvUbTNKZlweypNRetmH0lmQ9VYQAHqylxZVK65gEg85g27YuSyvOBZAjJyRmYU9KdCO1D+4ehdPu9dQB1yI1uh75wShdAaFn2o4qrMYwq3SQQEAAAAAAAAAAiH1PPJKAuh6oGiE35aGhUQhFi/bxgKOudpFv8HEHNCFDy1uAqR6+CTQmradxC1wyyjL+iSft+5XudJWwSdi7wvphsxb96x7Obj/AgAAAAAKlV4LL5ow6r9LMhIAAAAADvsOtqcVFmChDPzPnwAAAE33lx1h8hPFD04AAAAAAAA8YRV3Oa309B2wGwAAAAAA+yPBZRlZz7b605n+AQAAAACgmZmZmZkZAQAAAAAAAAAAMDMzMzMzMwEAAAAAAAAA25D1XcAtRzSuuyx3U+X7aE9vM1EJySU9KprgL0LMJ/vat9+SEEUZuga7O5tTUrcMDYWDg+LYaAWhSQiN2fYk7aCGAQAAAAAAgIQeAAAAAAAA8gUqAQAAAAYGBgICAAAA\"\n", " encoded = \"AwAAAAAAAACCaOmpoURMK6XHelGTaFawcuQ/78/15LAemWI8jrt3SRKLy2R9i60eclDjuDS8+p/ZhvTUd9G7uQVOYCsR6+BhmqGCiO6EPYP2PQkf/VRTvw7JjXvIjPFJy06QR1Cq1WfTonHl0OjCkyEf60SD07+MFJu5pVWNFGGEO/8AiAYfduaKdnFTaZEHPcK5Eq72WWHeHg2yIbBF09kyeOhlCJwOoG8O5SgpPV8QOA64ZNV4aKroFfADg6kEy/wWCdp3fv0O4GJgAAAAAPH6Ud6jtjwAAQAAAAAAAADiDkkCi9UOAAEAAAAAAAAADuBiYAAAAACNS5bSy7soAAEAAAAAAAAACMvgO+2jCwABAAAAAAAAAA7gYmAAAAAAZFeDUBNVhwABAAAAAAAAABtRNytozC8AAQAAAAAAAABIBGiCcyaEZdNhrTyeqUY692vOzzPdHaxAxguht3JQGlkzjtd05dX9LENHkl2z1XvUbTNKZlweypNRetmH0lmQ9VYQAHqylxZVK65gEg85g27YuSyvOBZAjJyRmYU9KdCO1D+4ehdPu9dQB1yI1uh75wShdAaFn2o4qrMYwq3SQQEAAAAAAAAAAiH1PPJKAuh6oGiE35aGhUQhFi/bxgKOudpFv8HEHNCFDy1uAqR6+CTQmradxC1wyyjL+iSft+5XudJWwSdi7wvphsxb96x7Obj/AgAAAAAKlV4LL5ow6r9LMhIAAAAADvsOtqcVFmChDPzPnwAAAE33lx1h8hPFD04AAAAAAAA8YRV3Oa309B2wGwAAAAAA+yPBZRlZz7b605n+AQAAAACgmZmZmZkZAQAAAAAAAAAAMDMzMzMzMwEAAAAAAAAA25D1XcAtRzSuuyx3U+X7aE9vM1EJySU9KprgL0LMJ/vat9+SEEUZuga7O5tTUrcMDYWDg+LYaAWhSQiN2fYk7aCGAQAAAAAAgIQeAAAAAAAA8gUqAQAAAAYGBgICAAAA\"\n",

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "thirty-prediction", "id": "chubby-hindu",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ⚠ Warning\n", "# ⚠ Warning\n",
@ -16,7 +16,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "minute-regulation", "id": "respective-twins",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🥭 Liquidation\n", "# 🥭 Liquidation\n",
@ -33,8 +33,12 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "necessary-spoke", "id": "meaningful-northeast",
"metadata": {}, "metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import time\n", "import time\n",
@ -51,7 +55,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "forbidden-token", "id": "olympic-foster",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Collateralisation Ratios\n", "## Collateralisation Ratios\n",
@ -69,7 +73,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "relevant-burst", "id": "authorized-vulnerability",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Safety\n", "## Safety\n",
@ -83,7 +87,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "liked-browser", "id": "proof-challenge",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 💧 Liquidation Process" "# 💧 Liquidation Process"
@ -91,7 +95,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "impaired-mirror", "id": "reverse-trout",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Steps\n", "## Steps\n",
@ -119,12 +123,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "technological-stake", "id": "urban-rainbow",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Liquidator:\n", "class Liquidator:\n",
" def __init__(self, context: Context, wallet: Wallet, group: Group):\n", " def __init__(self, context: Context, wallet: Wallet, group: Group):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.context = context\n", " self.context = context\n",
" self.wallet = wallet\n", " self.wallet = wallet\n",
" self.group = group\n", " self.group = group\n",
@ -150,12 +155,12 @@
" transaction.add(liquidate_instruction.build())\n", " transaction.add(liquidate_instruction.build())\n",
"\n", "\n",
" for instruction in transaction.instructions:\n", " for instruction in transaction.instructions:\n",
" print(\"INSTRUCTION\")\n", " self.logger.debug(\"INSTRUCTION\")\n",
" print(\" Keys:\")\n", " self.logger.debug(\" Keys:\")\n",
" for key in instruction.keys:\n", " for key in instruction.keys:\n",
" print(\" \", f\"{key.pubkey}\".ljust(45), f\"{key.is_signer}\".ljust(6), f\"{key.is_writable}\".ljust(6))\n", " self.logger.debug(\" \", f\"{key.pubkey}\".ljust(45), f\"{key.is_signer}\".ljust(6), f\"{key.is_writable}\".ljust(6))\n",
" print(\" Data:\", \" \".join(f\"{x:02x}\" for x in instruction.data))\n", " self.logger.debug(\" Data:\", \" \".join(f\"{x:02x}\" for x in instruction.data))\n",
" print(\" Program ID:\", instruction.program_id)\n", " self.logger.debug(\" Program ID:\", instruction.program_id)\n",
"\n", "\n",
" transaction_response = self.context.client.send_transaction(transaction, wallet.account)\n", " transaction_response = self.context.client.send_transaction(transaction, wallet.account)\n",
" return transaction_response[\"result\"]\n", " return transaction_response[\"result\"]\n",
@ -164,7 +169,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "supreme-specialist", "id": "settled-detroit",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🏃 Running" "# 🏃 Running"
@ -173,7 +178,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "governmental-february", "id": "intimate-stable",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -183,11 +188,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "environmental-calgary", "id": "knowing-diary",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"if __name__ == \"__main__\":\n", "if __name__ == \"__main__\":\n",
" logging.basicConfig(level=logging.DEBUG)\n",
"\n",
" if MARGIN_ACCOUNT_TO_LIQUIDATE == \"\":\n", " if MARGIN_ACCOUNT_TO_LIQUIDATE == \"\":\n",
" raise Exception(\"No margin account to liquidate - try setting the variable MARGIN_ACCOUNT_TO_LIQUIDATE to a margin account public key.\")\n", " raise Exception(\"No margin account to liquidate - try setting the variable MARGIN_ACCOUNT_TO_LIQUIDATE to a margin account public key.\")\n",
"\n", "\n",

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "awful-usage", "id": "fifth-yield",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ⚠ Warning\n", "# ⚠ Warning\n",
@ -16,7 +16,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "dental-federation", "id": "cardiovascular-heating",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🥭 Wallet\n", "# 🥭 Wallet\n",
@ -29,7 +29,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "controversial-introduction", "id": "irish-illinois",
"metadata": { "metadata": {
"jupyter": { "jupyter": {
"source_hidden": true "source_hidden": true
@ -38,6 +38,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"import json\n", "import json\n",
"import logging\n",
"import typing\n", "import typing\n",
"\n", "\n",
"from solana.account import Account\n", "from solana.account import Account\n",
@ -48,7 +49,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "directed-momentum", "id": "relative-notebook",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Wallet class\n", "## Wallet class\n",
@ -67,12 +68,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "violent-angel", "id": "female-bailey",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Wallet:\n", "class Wallet:\n",
" def __init__(self, secret_key):\n", " def __init__(self, secret_key):\n",
" self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)\n",
" self.secret_key = secret_key[0:32]\n", " self.secret_key = secret_key[0:32]\n",
" self.account = Account(self.secret_key)\n", " self.account = Account(self.secret_key)\n",
"\n", "\n",
@ -93,7 +95,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "identified-investor", "id": "alpine-standing",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🏃 Running\n", "# 🏃 Running\n",
@ -106,11 +108,13 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "incorporated-river", "id": "related-thanks",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"if __name__ == \"__main__\":\n", "if __name__ == \"__main__\":\n",
" logging.basicConfig(level=logging.DEBUG)\n",
"\n",
" import os.path\n", " import os.path\n",
" from Context import default_context\n", " from Context import default_context\n",
"\n", "\n",