From 649d4b7c2063e6821b351e5f8bf6c5c458bce910 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Sun, 26 Nov 2023 16:05:33 -0500 Subject: [PATCH] rename bank to spot markets --- src/driftpy/constants/config.py | 24 ++++++--- src/driftpy/constants/numeric_constants.py | 1 - .../constants/{markets.py => perp_markets.py} | 50 +++++++++---------- .../constants/{banks.py => spot_markets.py} | 28 +++++------ src/driftpy/drift_user.py | 6 +-- 5 files changed, 58 insertions(+), 51 deletions(-) rename src/driftpy/constants/{markets.py => perp_markets.py} (87%) rename src/driftpy/constants/{banks.py => spot_markets.py} (76%) diff --git a/src/driftpy/constants/config.py b/src/driftpy/constants/config.py index 955f2878..c97e8824 100644 --- a/src/driftpy/constants/config.py +++ b/src/driftpy/constants/config.py @@ -1,7 +1,15 @@ from typing import Literal -from driftpy.constants.banks import devnet_banks, mainnet_banks, Bank -from driftpy.constants.markets import devnet_markets, mainnet_markets, Market +from driftpy.constants.spot_markets import ( + devnet_spot_market_configs, + mainnet_spot_market_configs, + SpotMarketConfig, +) +from driftpy.constants.perp_markets import ( + devnet_perp_market_configs, + mainnet_perp_market_configs, + PerpMarketConfig, +) from dataclasses import dataclass from solders.pubkey import Pubkey @@ -17,8 +25,8 @@ class Config: usdc_mint_address: Pubkey default_http: str default_ws: str - markets: list[Market] - banks: list[Bank] + perp_markets: list[PerpMarketConfig] + spot_markets: list[SpotMarketConfig] market_lookup_table: Pubkey @@ -33,8 +41,8 @@ class Config: ), default_http="https://api.devnet.solana.com", default_ws="wss://api.devnet.solana.com", - markets=devnet_markets, - banks=devnet_banks, + perp_markets=devnet_perp_market_configs, + spot_markets=devnet_spot_market_configs, market_lookup_table=Pubkey.from_string( "FaMS3U4uBojvGn5FSDEPimddcXsCfwkKsFgMVVnDdxGb" ), @@ -49,8 +57,8 @@ class Config: ), default_http="https://api.mainnet-beta.solana.com", default_ws="wss://api.mainnet-beta.solana.com", - markets=mainnet_markets, - banks=mainnet_banks, + perp_markets=mainnet_perp_market_configs, + spot_markets=mainnet_spot_market_configs, market_lookup_table=Pubkey.from_string( "GPZkp76cJtNL2mphCvT6FXkJCVPpouidnacckR6rzKDN" ), diff --git a/src/driftpy/constants/numeric_constants.py b/src/driftpy/constants/numeric_constants.py index 5ccc7800..f598921a 100644 --- a/src/driftpy/constants/numeric_constants.py +++ b/src/driftpy/constants/numeric_constants.py @@ -11,7 +11,6 @@ PERP_DECIMALS = 9 CONCENTRATION_PRECISION = 1_000_000 IF_FACTOR_PRECISION = 1_000_000 -QUOTE_ASSET_BANK_INDEX = 0 SPOT_BALANCE_PRECISION = 1_000_000_000 SPOT_CUMULATIVE_INTEREST_PRECISION = 10_000_000_000 diff --git a/src/driftpy/constants/markets.py b/src/driftpy/constants/perp_markets.py similarity index 87% rename from src/driftpy/constants/markets.py rename to src/driftpy/constants/perp_markets.py index 0e03dd51..cae00627 100644 --- a/src/driftpy/constants/markets.py +++ b/src/driftpy/constants/perp_markets.py @@ -3,75 +3,75 @@ @dataclass -class Market: +class PerpMarketConfig: symbol: str base_asset_symbol: str market_index: int pyth_oracle: Pubkey -devnet_markets: list[Market] = [ - Market( +devnet_perp_market_configs: list[PerpMarketConfig] = [ + PerpMarketConfig( base_asset_symbol="SOL", symbol="SOL-PERP", market_index=0, pyth_oracle=Pubkey.from_string("J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix"), ), - Market( + PerpMarketConfig( base_asset_symbol="BTC", symbol="BTC-PERP", market_index=1, pyth_oracle=Pubkey.from_string("HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J"), ), - Market( + PerpMarketConfig( base_asset_symbol="ETH", symbol="ETH-PERP", market_index=2, pyth_oracle=Pubkey.from_string("EdVCmQ9FSPcVe5YySXDPCRmc8aDQLKJ9xvYBMZPie1Vw"), ), - Market( + PerpMarketConfig( base_asset_symbol="APT", symbol="APT-PERP", market_index=3, pyth_oracle=Pubkey.from_string("5d2QJ6u2NveZufmJ4noHja5EHs3Bv1DUMPLG5xfasSVs"), ), - Market( + PerpMarketConfig( symbol="1MBONK-PERP", base_asset_symbol="1MBONK", market_index=4, pyth_oracle=Pubkey.from_string("6bquU99ktV1VRiHDr8gMhDFt3kMfhCQo5nfNrg2Urvsn"), ), - Market( + PerpMarketConfig( symbol="MATIC-PERP", base_asset_symbol="MATIC", market_index=5, pyth_oracle=Pubkey.from_string("FBirwuDFuRAu4iSGc7RGxN5koHB7EJM1wbCmyPuQoGur"), ), - Market( + PerpMarketConfig( symbol="ARB-PERP", base_asset_symbol="ARB", market_index=6, pyth_oracle=Pubkey.from_string("4mRGHzjGerQNWKXyQAmr9kWqb9saPPHKqo1xziXGQ5Dh"), ), - Market( + PerpMarketConfig( symbol="DOGE-PERP", base_asset_symbol="DOGE", market_index=7, pyth_oracle=Pubkey.from_string("4L6YhY8VvUgmqG5MvJkUJATtzB2rFqdrJwQCmFLv4Jzy"), ), - Market( + PerpMarketConfig( symbol="BNB-PERP", base_asset_symbol="BNB", market_index=8, pyth_oracle=Pubkey.from_string("GwzBgrXb4PG59zjce24SF2b9JXbLEjJJTBkmytuEZj1b"), ), - Market( + PerpMarketConfig( symbol="SUI-PERP", base_asset_symbol="SUI", market_index=9, pyth_oracle=Pubkey.from_string("6SK9vS8eMSSj3LUX2dPku93CrNv8xLCp9ng39F39h7A5"), ), - Market( + PerpMarketConfig( symbol="1MPEPE-PERP", base_asset_symbol="1MPEPE", market_index=10, @@ -79,68 +79,68 @@ class Market: ), ] -mainnet_markets: list[Market] = [ - Market( +mainnet_perp_market_configs: list[PerpMarketConfig] = [ + PerpMarketConfig( symbol="SOL-PERP", base_asset_symbol="SOL", market_index=0, pyth_oracle=Pubkey.from_string("H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG"), ), - Market( + PerpMarketConfig( symbol="BTC-PERP", base_asset_symbol="BTC", market_index=1, pyth_oracle=Pubkey.from_string("GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU"), ), - Market( + PerpMarketConfig( symbol="ETH-PERP", base_asset_symbol="ETH", market_index=2, pyth_oracle=Pubkey.from_string("JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB"), ), - Market( + PerpMarketConfig( symbol="APT-PERP", base_asset_symbol="APT", market_index=3, pyth_oracle=Pubkey.from_string("FNNvb1AFDnDVPkocEri8mWbJ1952HQZtFLuwPiUjSJQ"), ), - Market( + PerpMarketConfig( symbol="1MBONK", base_asset_symbol="1MBONK", market_index=4, pyth_oracle=Pubkey.from_string("8ihFLu5FimgTQ1Unh4dVyEHUGodJ5gJQCrQf4KUVB9bN"), ), - Market( + PerpMarketConfig( symbol="MATIC-PERP", base_asset_symbol="MATIC", market_index=5, pyth_oracle=Pubkey.from_string("7KVswB9vkCgeM3SHP7aGDijvdRAHK8P5wi9JXViCrtYh"), ), - Market( + PerpMarketConfig( symbol="ARB-PERP", base_asset_symbol="ARB", market_index=6, pyth_oracle=Pubkey.from_string("5HRrdmghsnU3i2u5StaKaydS7eq3vnKVKwXMzCNKsc4C"), ), - Market( + PerpMarketConfig( symbol="DOGE-PERP", base_asset_symbol="DOGE", market_index=7, pyth_oracle=Pubkey.from_string("FsSM3s38PX9K7Dn6eGzuE29S2Dsk1Sss1baytTQdCaQj"), ), - Market( + PerpMarketConfig( symbol="BNB-PERP", base_asset_symbol="BNB", market_index=8, pyth_oracle=Pubkey.from_string("4CkQJBxhU8EZ2UjhigbtdaPbpTe6mqf811fipYBFbSYN"), ), - Market( + PerpMarketConfig( symbol="SUI-PERP", base_asset_symbol="SUI", market_index=9, pyth_oracle=Pubkey.from_string("3Qub3HaAJaa2xNY7SUqPKd3vVwTqDfDDkEUMPjXD2c1q"), ), - Market( + PerpMarketConfig( symbol="1MPEPE-PERP", base_asset_symbol="1MPEPE", market_index=10, diff --git a/src/driftpy/constants/banks.py b/src/driftpy/constants/spot_markets.py similarity index 76% rename from src/driftpy/constants/banks.py rename to src/driftpy/constants/spot_markets.py index f0a4c013..6b72b9a5 100644 --- a/src/driftpy/constants/banks.py +++ b/src/driftpy/constants/spot_markets.py @@ -4,49 +4,49 @@ @dataclass -class Bank: +class SpotMarketConfig: symbol: str - bank_index: int + market_index: int oracle: Pubkey oracle_source: OracleSource mint: Pubkey -devnet_banks: list[Bank] = [ - Bank( +devnet_spot_market_configs: list[SpotMarketConfig] = [ + SpotMarketConfig( symbol="USDC", - bank_index=0, + market_index=0, oracle=Pubkey.default(), oracle_source=OracleSource.QUOTE_ASSET, mint=Pubkey.from_string("8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2"), ), - Bank( + SpotMarketConfig( symbol="SOL", - bank_index=1, + market_index=1, oracle=Pubkey.from_string("J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix"), oracle_source=OracleSource.PYTH, mint=Pubkey.from_string("So11111111111111111111111111111111111111112"), ), - Bank( + SpotMarketConfig( symbol="BTC", - bank_index=2, + market_index=2, oracle=Pubkey.from_string("HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J"), oracle_source=OracleSource.PYTH, mint=Pubkey.from_string("3BZPwbcqB5kKScF3TEXxwNfx5ipV13kbRVDvfVp5c6fv"), ), ] -mainnet_banks: list[Bank] = [ - Bank( +mainnet_spot_market_configs: list[SpotMarketConfig] = [ + SpotMarketConfig( symbol="USDC", - bank_index=0, + market_index=0, oracle=Pubkey.default(), oracle_source=OracleSource.QUOTE_ASSET, mint=Pubkey.from_string("8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2"), ), - Bank( + SpotMarketConfig( symbol="SOL", - bank_index=1, + market_index=1, oracle=Pubkey.from_string("H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG"), oracle_source=OracleSource.PYTH, mint=Pubkey.from_string("So11111111111111111111111111111111111111112"), diff --git a/src/driftpy/drift_user.py b/src/driftpy/drift_user.py index 4ef97128..edb837e0 100644 --- a/src/driftpy/drift_user.py +++ b/src/driftpy/drift_user.py @@ -99,7 +99,7 @@ async def get_spot_market_liability( spot_market = await self.get_spot_market(position.market_index) - if position.market_index == QUOTE_ASSET_BANK_INDEX: + if position.market_index == QUOTE_SPOT_MARKET_INDEX: if str(position.balance_type) == "SpotBalanceType.Borrow()": token_amount = get_token_amount( position.scaled_balance, spot_market, position.balance_type @@ -305,7 +305,7 @@ async def get_unrealized_pnl( with_weight_margin_category: Optional[MarginCategory] = None, ): user = await self.get_user() - quote_spot_market = await self.get_spot_market(QUOTE_ASSET_BANK_INDEX) + quote_spot_market = await self.get_spot_market(QUOTE_SPOT_MARKET_INDEX) unrealized_pnl = 0 position: PerpPosition @@ -355,7 +355,7 @@ async def get_spot_market_asset_value( spot_market = await self.get_spot_market(position.market_index) - if position.market_index == QUOTE_ASSET_BANK_INDEX: + if position.market_index == QUOTE_SPOT_MARKET_INDEX: spot_token_value = get_token_amount( position.scaled_balance, spot_market, position.balance_type )