Skip to content

Commit

Permalink
rename bank to spot markets
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Nov 26, 2023
1 parent 24b5964 commit 649d4b7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 51 deletions.
24 changes: 16 additions & 8 deletions src/driftpy/constants/config.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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


Expand All @@ -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"
),
Expand All @@ -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"
),
Expand Down
1 change: 0 additions & 1 deletion src/driftpy/constants/numeric_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,144 +3,144 @@


@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,
pyth_oracle=Pubkey.from_string("Gz9RfgDeAFSsH7BHDGyNTgCik74rjNwsodJpsCizzmkj"),
),
]

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 3 additions & 3 deletions src/driftpy/drift_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 649d4b7

Please sign in to comment.