2021-06-07 07:10:18 -07:00
# # ⚠ Warning
#
# 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.
#
# [🥭 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)
import decimal
import json
2021-10-08 09:30:20 -07:00
import logging
2021-06-25 02:33:40 -07:00
import os . path
2021-10-07 09:05:43 -07:00
import typing
2021-06-07 07:10:18 -07:00
from solana . publickey import PublicKey
# # 🥭 Constants
#
# This file contains some hard-coded values, all kept in one place, as well as the mechanism
# for loading the Mango `ids.json` file.
# ## SYSTEM_PROGRAM_ADDRESS
#
# The Solana system program address is always 11111111111111111111111111111111.
2021-10-07 09:05:43 -07:00
#
2021-06-07 07:10:18 -07:00
SYSTEM_PROGRAM_ADDRESS = PublicKey ( " 11111111111111111111111111111111 " )
# ## SOL_MINT_ADDRESS
#
# The fake mint address of the SOL token. **Note:** Wrapped SOL has a different mint address - it is So11111111111111111111111111111111111111112.
2021-10-07 09:05:43 -07:00
#
2021-06-07 07:10:18 -07:00
SOL_MINT_ADDRESS = PublicKey ( " So11111111111111111111111111111111111111111 " )
# ## SOL_DECIMALS
#
# The number of decimal places used to convert Lamports into SOLs.
2021-10-07 09:05:43 -07:00
#
2021-06-07 07:10:18 -07:00
SOL_DECIMALS = decimal . Decimal ( 9 )
# ## SOL_DECIMAL_DIVISOR decimal
#
# 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.
2021-10-07 09:05:43 -07:00
#
2021-06-07 07:10:18 -07:00
SOL_DECIMAL_DIVISOR = decimal . Decimal ( 10 * * SOL_DECIMALS )
# ## NUM_TOKENS
#
# This is currently hard-coded to 3.
2021-10-07 09:05:43 -07:00
#
2021-06-07 07:10:18 -07:00
NUM_TOKENS = 3
# ## NUM_MARKETS
#
# There is one fewer market than tokens.
2021-10-07 09:05:43 -07:00
#
2021-06-07 07:10:18 -07:00
NUM_MARKETS = NUM_TOKENS - 1
# # WARNING_DISCLAIMER_TEXT
#
# This is the warning text that is output on each run of a command.
2021-10-07 09:05:43 -07:00
#
2021-06-07 07:10:18 -07:00
WARNING_DISCLAIMER_TEXT = """
⚠ WARNING ⚠
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 .
🥭 Mango Markets : https : / / mango . markets
📄 Documentation : https : / / docs . mango . markets /
💬 Discord : https : / / discord . gg / 67 jySBhxrg
🐦 Twitter : https : / / twitter . com / mangomarkets
🚧 Github : https : / / github . com / blockworks - foundation
📧 Email : mailto : hello @blockworks.foundation
"""
2021-10-07 09:05:43 -07:00
def _build_data_path ( ) - > str :
2021-10-08 09:30:20 -07:00
possibilities : typing . Sequence [ str ] = [ " ../data " , " data " , " . " , " ../../data " , " ../../../data " ]
attempts : typing . Sequence [ str ] = [ ]
file_root : str = os . path . dirname ( __file__ )
2021-10-07 09:05:43 -07:00
for possibility in possibilities :
2021-10-08 09:30:20 -07:00
data_path : str = os . path . normpath ( os . path . join ( file_root , possibility ) )
attempts + = [ data_path ]
try :
logging . debug ( f " Trying to find ids.json in data path: { data_path } " )
attempted_ids_path : str = os . path . normpath ( os . path . join ( data_path , " ids.json " ) )
with open ( attempted_ids_path ) as ids_file :
logging . debug ( f " Success with ids.json at: { attempted_ids_path } " )
json . load ( ids_file )
return data_path
except :
logging . debug ( f " Failure - no ids.json at: { attempted_ids_path } " )
raise Exception ( f " Could not determine data path - ids.json not found in: { attempts } " )
2021-10-07 09:05:43 -07:00
# # DATA_PATH
2021-06-07 07:10:18 -07:00
#
2021-10-07 09:05:43 -07:00
# This is the path to the data directory that contains (among other things) the ids.json.
#
DATA_PATH : str = _build_data_path ( )
2021-06-07 07:10:18 -07:00
2021-10-07 09:05:43 -07:00
# ## MangoConstants
#
# 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).
#
with open ( os . path . join ( DATA_PATH , " ids.json " ) ) as json_file :
2021-06-07 07:10:18 -07:00
MangoConstants = json . load ( json_file )