{ "cells": [ { "cell_type": "markdown", "id": "1c81447d", "metadata": {}, "source": [ "[🥭 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)\n", "\n", "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/blockworks-foundation/mango-explorer-examples/HEAD?labpath=Deposit.ipynb) [Run this code](https://mybinder.org/v2/gh/blockworks-foundation/mango-explorer-examples/HEAD?labpath=Deposit.ipynb) on Binder.\n", "\n", "_🏃‍♀️ To run this notebook press the ⏩ icon in the toolbar above._" ] }, { "cell_type": "markdown", "id": "055fbf67", "metadata": {}, "source": [ "# 🥭 Deposit\n", "\n", "This code will connect to the _devnet_ cluster and deposit 0.1 SOL into a Mango `Account`." ] }, { "cell_type": "code", "execution_count": null, "id": "88779eaa", "metadata": {}, "outputs": [], "source": [ "import decimal\n", "import mango\n", "\n", "from solana.publickey import PublicKey\n", "\n", "\n", "# Use our hard-coded devnet wallet for DeekipCw5jz7UgQbtUbHQckTYGKXWaPQV4xY93DaiM6h.\n", "# For real-world use you'd load the bytes from the environment or a file. This wallet\n", "# has a Mango Account at HhepjyhSzvVP7kivdgJH9bj32tZFncqKUwWidS1ja4xL.\n", "wallet = mango.Wallet(bytes([67,218,68,118,140,171,228,222,8,29,48,61,255,114,49,226,239,89,151,110,29,136,149,118,97,189,163,8,23,88,246,35,187,241,107,226,47,155,40,162,3,222,98,203,176,230,34,49,45,8,253,77,136,241,34,4,80,227,234,174,103,11,124,146]))\n", "\n", "with mango.ContextBuilder.build(cluster_name=\"devnet\") as context:\n", " group = mango.Group.load(context)\n", " account = mango.Account.load(context, PublicKey(\"HhepjyhSzvVP7kivdgJH9bj32tZFncqKUwWidS1ja4xL\"), group)\n", " sol_token = mango.token(context, \"SOL\")\n", "\n", " print(\"Wrapped SOL in account\", account.slot_by_instrument(sol_token).net_value)\n", "\n", " deposit_value = mango.InstrumentValue(sol_token, decimal.Decimal(\"0.1\"))\n", " deposit_signatures = account.deposit(context, wallet, deposit_value)\n", " print(\"Waiting for deposit transaction to confirm...\", deposit_signatures)\n", " mango.WebSocketTransactionMonitor.wait_for_all(\n", " context.client.cluster_ws_url, deposit_signatures, commitment=\"processed\"\n", " )\n", "\n", " account = mango.Account.load(context, account.address, group)\n", " print(\"Wrapped SOL after deposit\", account.slot_by_instrument(sol_token).net_value)\n", "\n", "print(\"Example complete.\")" ] } ], "metadata": { "interpreter": { "hash": "ac2eaa0ea0ebeafcc7822e65e46aa9d4f966f30b695406963e145ea4a91cd4fc" }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.10" }, "metadata": { "interpreter": { "hash": "ac2eaa0ea0ebeafcc7822e65e46aa9d4f966f30b695406963e145ea4a91cd4fc" } }, "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 }