Skip to content

Commit

Permalink
Update - add new oracles
Browse files Browse the repository at this point in the history
  • Loading branch information
SinaKhalili committed Dec 17, 2024
1 parent 4c98403 commit 15171b0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 43 deletions.
2 changes: 1 addition & 1 deletion protocol-v2
Submodule protocol-v2 updated 64 files
+5 −1 Anchor.toml
+4 −0 CHANGELOG.md
+291 −0 Cargo.lock
+13 −0 deps/configs/pyth_lazer_storage.json
+22 −21 package.json
+1 −0 programs/drift/Cargo.toml
+10 −2 programs/drift/src/error.rs
+5 −0 programs/drift/src/ids.rs
+78 −32 programs/drift/src/instructions/admin.rs
+81 −0 programs/drift/src/instructions/keeper.rs
+2 −0 programs/drift/src/instructions/mod.rs
+136 −0 programs/drift/src/instructions/pyth_lazer_oracle.rs
+20 −0 programs/drift/src/lib.rs
+1 −1 programs/drift/src/math/constants.rs
+2 −1 programs/drift/src/math/margin.rs
+1 −0 programs/drift/src/state/mod.rs
+62 −14 programs/drift/src/state/oracle.rs
+29 −14 programs/drift/src/state/oracle_map.rs
+30 −14 programs/drift/src/state/perp_market.rs
+22 −0 programs/drift/src/state/pyth_lazer_oracle.rs
+1 −1 sdk/VERSION
+ sdk/bun.lockb
+28 −26 sdk/package.json
+63 −29 sdk/scripts/postbuild.js
+18 −0 sdk/src/addresses/pda.ts
+32 −1 sdk/src/adminClient.ts
+21 −0 sdk/src/bankrun/bankrunConnection.ts
+5 −0 sdk/src/config.ts
+12 −0 sdk/src/constants/perpMarkets.ts
+23 −1 sdk/src/constants/spotMarkets.ts
+73 −228 sdk/src/dlob/DLOB.ts
+0 −39 sdk/src/dlob/DLOBApiClient.ts
+24 −1 sdk/src/dlob/DLOBNode.ts
+0 −49 sdk/src/dlob/DLOBOrders.ts
+1 −19 sdk/src/dlob/NodeList.ts
+0 −248 sdk/src/dlob/dlobIdl.json
+105 −5 sdk/src/driftClient.ts
+5 −0 sdk/src/factory/oracleClient.ts
+145 −2 sdk/src/idl/drift.json
+2 −3 sdk/src/index.ts
+9 −0 sdk/src/memcmp.ts
+1 −0 sdk/src/oracles/oracleId.ts
+102 −0 sdk/src/oracles/pythLazerClient.ts
+4 −0 sdk/src/tx/baseTxSender.ts
+4 −1 sdk/src/tx/whileValidTxSender.ts
+2 −0 sdk/src/types.ts
+8 −1 sdk/src/userMap/WebsocketSubscription.ts
+8 −1 sdk/src/userMap/grpcSubscription.ts
+6 −1 sdk/src/userMap/userMap.ts
+3 −1 sdk/src/userMap/userMapConfig.ts
+2 −0 sdk/src/util/computeUnits.ts
+136 −0 sdk/src/util/pythOracleUtils.ts
+0 −11 sdk/src/util/pythPullOracleUtils.ts
+13 −184 sdk/tests/dlob/test.ts
+56 −110 sdk/yarn.lock
+2 −1 test-scripts/run-anchor-local-validator-tests.sh
+1 −0 test-scripts/run-anchor-tests.sh
+1 −1 test-scripts/single-anchor-test.sh
+15 −0 tests/admin.ts
+264 −29 tests/placeAndMakeSwiftPerpBankrun.ts
+147 −0 tests/pythLazer.ts
+155 −0 tests/pythLazerBankrun.ts
+10 −0 tests/pythLazerData.ts
+27 −20 yarn.lock
14 changes: 9 additions & 5 deletions src/driftpy/accounts/bulk_account_loader.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import asyncio
from typing import Callable, List, Optional
from dataclasses import dataclass
import jsonrpcclient
from base64 import b64decode
from dataclasses import dataclass
from typing import Callable, List, Optional

from solana.rpc.commitment import Commitment
import jsonrpcclient
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Commitment
from solders.pubkey import Pubkey


Expand Down Expand Up @@ -63,7 +63,11 @@ def add_account(
if existing_account_to_load is not None:
buffer_and_slot = self.buffer_and_slot_map.get(pubkey_str)
if buffer_and_slot is not None and buffer_and_slot.buffer is not None:
self.handle_callbacks(existing_account_to_load, buffer_and_slot.buffer, buffer_and_slot.slot)
self.handle_callbacks(
existing_account_to_load,
buffer_and_slot.buffer,
buffer_and_slot.slot,
)

return callback_id

Expand Down
29 changes: 16 additions & 13 deletions src/driftpy/accounts/ws/drift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@
from typing import Optional, Sequence, Union

from anchorpy import Program
from solana.rpc.commitment import Commitment

from driftpy.accounts.oracle import get_oracle_decode_fn
from driftpy.accounts.types import DataAndSlot
from driftpy.accounts.types import DriftClientAccountSubscriber
from driftpy.accounts.types import FullOracleWrapper
from driftpy.accounts.types import (
DataAndSlot,
DriftClientAccountSubscriber,
FullOracleWrapper,
)
from driftpy.accounts.ws.account_subscriber import WebsocketAccountSubscriber
from driftpy.addresses import *
from driftpy.constants.config import find_all_market_and_oracles
from driftpy.market_map.market_map import MarketMap
from driftpy.market_map.market_map_config import MarketMapConfig
from driftpy.market_map.market_map_config import WebsocketConfig
from driftpy.market_map.market_map_config import MarketMapConfig, WebsocketConfig
from driftpy.oracles.oracle_id import get_oracle_id
from driftpy.types import MarketType
from driftpy.types import OracleInfo
from driftpy.types import OraclePriceData
from driftpy.types import PerpMarketAccount
from driftpy.types import SpotMarketAccount
from driftpy.types import StateAccount
from solana.rpc.commitment import Commitment
from driftpy.types import (
MarketType,
OracleInfo,
OraclePriceData,
PerpMarketAccount,
SpotMarketAccount,
StateAccount,
)


class WebsocketDriftClientAccountSubscriber(DriftClientAccountSubscriber):
Expand Down Expand Up @@ -349,4 +353,3 @@ def get_oracle_price_data_and_slot_for_spot_market(
asyncio.create_task(self._set_spot_oracle_map())

return self.get_oracle_price_data_and_slot(oracle_id)

24 changes: 16 additions & 8 deletions src/driftpy/admin.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
from typing import Optional

from anchorpy import Context
from solders.pubkey import Pubkey
from solders.signature import Signature
from solders.system_program import ID
from solders.sysvar import RENT
from spl.token.constants import TOKEN_PROGRAM_ID
from anchorpy import Context

from driftpy.drift_client import (
DriftClient,
)
from driftpy.constants.numeric_constants import BASE_PRECISION, PEG_PRECISION, PRICE_PRECISION
from driftpy.types import AssetTier, ContractTier, OracleGuardRails, OracleSource, PrelaunchOracleParams
from driftpy.accounts import get_perp_market_account, get_state_account
from driftpy.addresses import *
from driftpy.accounts import get_state_account
from driftpy.constants.numeric_constants import (
BASE_PRECISION,
PEG_PRECISION,
PRICE_PRECISION,
SPOT_RATE_PRECISION,
SPOT_WEIGHT_PRECISION,
)
from driftpy.accounts import get_perp_market_account
from driftpy.drift_client import (
DriftClient,
)
from driftpy.types import (
AssetTier,
ContractTier,
OracleGuardRails,
OracleSource,
PrelaunchOracleParams,
)


class Admin(DriftClient):
Expand Down
34 changes: 18 additions & 16 deletions src/driftpy/setup/helpers.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
from solana.rpc.async_api import AsyncClient
import math
from base64 import b64decode
from dataclasses import dataclass
from typing import Optional

from anchorpy import Context, Program, Provider
from construct import Int32sl, Int64ul
from solana.rpc.async_api import AsyncClient
from solana.transaction import Signature, Transaction
from solders.keypair import Keypair
from solders.pubkey import Pubkey
from solders.system_program import create_account, CreateAccountParams
from anchorpy import Program, Context, Provider
from solana.transaction import Transaction
from spl.token.constants import TOKEN_PROGRAM_ID
from spl.token._layouts import MINT_LAYOUT
from solders.system_program import CreateAccountParams, create_account
from spl.token._layouts import ACCOUNT_LAYOUT, MINT_LAYOUT
from spl.token.async_client import AsyncToken
from spl.token.instructions import initialize_mint, InitializeMintParams
import math

from spl.token._layouts import ACCOUNT_LAYOUT
from spl.token.constants import TOKEN_PROGRAM_ID
from spl.token.instructions import (
initialize_account,
InitializeAccountParams,
mint_to,
InitializeMintParams,
MintToParams,
initialize_account,
initialize_mint,
mint_to,
)
from solana.transaction import Signature

from driftpy.types import *
from driftpy.math.amm import calculate_amm_reserves_after_swap, calculate_price
from driftpy.admin import Admin
from driftpy.constants.numeric_constants import *
from driftpy.math.amm import calculate_amm_reserves_after_swap, calculate_price
from driftpy.types import *

NATIVE_MINT = Pubkey.from_string("So11111111111111111111111111111111111111112")

Expand Down Expand Up @@ -334,7 +333,10 @@ async def mock_oracle(


async def initialize_sol_spot_market(
admin: Admin, sol_oracle: Pubkey, sol_mint: Pubkey = NATIVE_MINT, oracle_source: OracleSource = OracleSource.Pyth()
admin: Admin,
sol_oracle: Pubkey,
sol_mint: Pubkey = NATIVE_MINT,
oracle_source: OracleSource = OracleSource.Pyth(),
):
optimal_utilization = SPOT_RATE_PRECISION // 2
optimal_rate = SPOT_RATE_PRECISION * 20
Expand Down

0 comments on commit 15171b0

Please sign in to comment.