mango-explorer/Constants.ipynb

292 lines
7.9 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "markdown",
"id": "increasing-fundamental",
"metadata": {},
"source": [
"# ⚠ Warning\n",
"\n",
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gl/OpinionatedGeek%2Fmango-explorer/HEAD?filepath=Constants.ipynb) _🏃 To run this notebook press the ⏩ icon in the toolbar above._\n",
"\n",
"[🥭 Mango Markets](https://mango.markets/) support is available at: [Docs](https://docs.mango.markets/) | [Discord](https://discord.gg/67jySBhxrg) | [Twitter](https://twitter.com/mangomarkets) | [Github](https://github.com/blockworks-foundation) | [Email](mailto:hello@blockworks.foundation)"
]
},
{
"cell_type": "markdown",
"id": "lined-maximum",
"metadata": {},
"source": [
"# 🥭 Constants\n",
"\n",
"This notebook contains some hard-coded values, all kept in one place, as well as the mechanism for loading the Mango `ids.json` file."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "functioning-howard",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"import decimal\n",
"import json\n",
"import logging\n",
"\n",
"from solana.publickey import PublicKey\n"
]
},
{
"cell_type": "markdown",
"id": "brazilian-living",
"metadata": {},
"source": [
"## SYSTEM_PROGRAM_ADDRESS\n",
"\n",
"The Solana system program address is always 11111111111111111111111111111111."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "moral-attitude",
"metadata": {},
"outputs": [],
"source": [
"SYSTEM_PROGRAM_ADDRESS = PublicKey(\"11111111111111111111111111111111\")"
]
},
{
"cell_type": "markdown",
"id": "spanish-wireless",
"metadata": {},
"source": [
"## SOL_DECIMALS\n",
"\n",
"The number of decimal places used to convert Lamports into SOLs."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "disturbed-broadcast",
"metadata": {},
"outputs": [],
"source": [
"SOL_DECIMALS = decimal.Decimal(9)"
]
},
{
"cell_type": "markdown",
"id": "billion-maximum",
"metadata": {},
"source": [
"## SOL_DECIMAL_DIVISOR decimal\n",
"\n",
"The divisor to use to turn an integer value of SOLs from an account's `balance` into a value with the correct number of decimal places."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "velvet-induction",
"metadata": {},
"outputs": [],
"source": [
"SOL_DECIMAL_DIVISOR = decimal.Decimal(10 ** SOL_DECIMALS)"
]
},
{
"cell_type": "markdown",
"id": "chinese-inquiry",
"metadata": {},
"source": [
"## NUM_TOKENS\n",
"\n",
"This is currently hard-coded to 3."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "convinced-history",
"metadata": {},
"outputs": [],
"source": [
"NUM_TOKENS = 3\n"
]
},
{
"cell_type": "markdown",
"id": "statistical-soccer",
"metadata": {},
"source": [
"## NUM_MARKETS\n",
"\n",
"There is one fewer market than tokens."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "british-miracle",
"metadata": {},
"outputs": [],
"source": [
"NUM_MARKETS = NUM_TOKENS - 1\n"
]
},
{
"cell_type": "markdown",
"id": "attended-canada",
"metadata": {},
"source": [
"# WARNING_DISCLAIMER_TEXT\n",
"\n",
"This is the warning text that is output on each run of a command."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "prompt-wright",
"metadata": {},
"outputs": [],
"source": [
"WARNING_DISCLAIMER_TEXT = \"\"\"\n",
"⚠ WARNING ⚠\n",
"\n",
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"\n",
" 🥭 Mango Markets: https://mango.markets\n",
" 📄 Documentation: https://docs.mango.markets/\n",
" 💬 Discord: https://discord.gg/67jySBhxrg\n",
" 🐦 Twitter: https://twitter.com/mangomarkets\n",
" 🚧 Github: https://github.com/blockworks-foundation\n",
" 📧 Email: mailto:hello@blockworks.foundation\n",
"\"\"\""
]
},
{
"cell_type": "markdown",
"id": "stupid-glasgow",
"metadata": {},
"source": [
"## MangoConstants\n",
"\n",
"Load all Mango Market's constants from its own `ids.json` file (retrieved from [GitHub](https://raw.githubusercontent.com/blockworks-foundation/mango-client-ts/main/src/ids.json)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "renewable-logan",
"metadata": {},
"outputs": [],
"source": [
"with open(\"ids.json\") as json_file:\n",
" MangoConstants = json.load(json_file)\n"
]
},
{
"cell_type": "markdown",
"id": "handled-legend",
"metadata": {},
"source": [
"# 🏃 Running\n",
"\n",
"As a simple harness, just try to access some things and print them out to make sure we have loaded properly."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "elect-southwest",
"metadata": {},
"outputs": [],
"source": [
"if __name__ == \"__main__\":\n",
" logging.getLogger().setLevel(logging.INFO)\n",
"\n",
" print(\"System program address:\", SYSTEM_PROGRAM_ADDRESS)\n",
" print(\"SOL decimal divisor:\", SOL_DECIMAL_DIVISOR)\n",
" print(\"Number of tokens:\", NUM_TOKENS)\n",
" print(\"Number of markets:\", NUM_MARKETS)\n",
" mango_group = MangoConstants[\"mainnet-beta\"]\n",
" print(f\"Mango program ID: {mango_group['mango_program_id']}\")\n",
" for oracle in mango_group[\"oracles\"]:\n",
" print(f\"Oracle [{oracle}]: {mango_group['oracles'][oracle]}\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}