Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…o next
  • Loading branch information
EvolveArt committed Jul 3, 2024
2 parents 5706416 + ad675c9 commit 8cb64db
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 331 deletions.
File renamed without changes.
8 changes: 7 additions & 1 deletion sdk/pragma/common/configs/asset_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,21 @@ def as_currency(self) -> Currency:
)

@staticmethod
def get_pair_from_asset_configs(base_asset: Self, quote_asset: Self) -> Pair:
def get_pair_from_asset_configs(
base_asset: "AssetConfig", quote_asset: "AssetConfig"
) -> Optional[Pair]:
"""
Return a Pair from two AssetConfigs.
Return None if the base and quote assets are the same.
:param base_asset: Base asset
:param quote_asset: Quote asset
:return: Pair
"""

if base_asset == quote_asset:
return None

return Pair(
base_currency=base_asset.as_currency(),
quote_currency=quote_asset.as_currency(),
Expand Down
6 changes: 3 additions & 3 deletions sdk/pragma/common/types/pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Pair:
quote_currency: Currency

def __init__(self, base_currency: Currency, quote_currency: Currency):
self.id = felt_to_str(
self.id = str_to_felt(
currency_pair_to_pair_id(base_currency.id, quote_currency.id)
)

Expand All @@ -29,8 +29,8 @@ def serialize(self) -> List[str]:
def to_dict(self) -> dict:
return {
"id": self.id,
"base_currency": self.base_currency,
"quote_currency": self.quote_currency,
"base_currency_id": self.base_currency.id,
"quote_currency_id": self.quote_currency.id,
}

def __repr__(self):
Expand Down
8 changes: 4 additions & 4 deletions sdk/pragma/common/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class DataTypes(StrEnum):

@dataclass(frozen=True)
class ExecutionConfig:
pagination: Optional[int] = 40
max_fee: Optional[int] = int(1e18)
enable_strk_fees: Optional[bool] = False
pagination: int = 40
max_fee: int = int(1e18)
enable_strk_fees: bool = False
l1_resource_bounds: Optional[ResourceBounds] = None
auto_estimate: Optional[bool] = False
auto_estimate: bool = False
5 changes: 4 additions & 1 deletion sdk/pragma/onchain/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from starknet_py.net.account.account import Account
from starknet_py.net.full_node_client import FullNodeClient
from starknet_py.net.client import Client
from starknet_py.net.signer.stark_curve_signer import KeyPair, StarkCurveSigner
from starknet_py.net.models import StarknetChainId
from starknet_py.contract import InvokeResult
Expand Down Expand Up @@ -40,10 +41,11 @@ class PragmaOnChainClient(
account_contract_address: Optional[ADDRESS] = None
account: Account = None
full_node_client: FullNodeClient = None
client: Client = None

def __init__(
self,
network: Network = "devnet",
network: Network = "sepolia",
account_private_key: Optional[int] = None,
account_contract_address: Optional[ADDRESS] = None,
contract_addresses_config: Optional[ContractAddresses] = None,
Expand Down Expand Up @@ -113,6 +115,7 @@ def _setup_contracts(self):
Setup the contracts for the client.
For now, this includes the Oracle and PublisherRegistry contracts.
"""

provider = self.account if self.account else self.client
self.oracle = Contract(
address=self.contract_addresses_config.oracle_proxy_addresss,
Expand Down
1 change: 0 additions & 1 deletion sdk/pragma/onchain/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
CHAIN_IDS: Dict[Network, int] = {
"devnet": 23448594291968334,
"mainnet": 23448594291968334,
"fork_devnet": 23448594291968334,
"sepolia": 393402133025997798000961,
}

Expand Down
20 changes: 7 additions & 13 deletions sdk/pragma/onchain/mixins/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def publish_spot_entry(
"self._setup_account_client(private_key, account_contract_address)"
)

config = execution_config or self.execution_config
config = execution_config or ExecutionConfig()

invocation = await self.oracle.functions["publish_data"].invoke(
new_entry={
Expand All @@ -61,10 +61,7 @@ async def publish_spot_entry(
"volume": volume,
}
},
max_fee=config.max_fee,
l1_resource_bounds=config.l1_resource_bounds,
auto_estimate=config.auto_estimate,
enable_strk_fees=config.enable_strk_fees,
execution_config=config,
)
return invocation

Expand Down Expand Up @@ -127,11 +124,8 @@ async def _invoke_publish(
self, entries: List[Dict], data_type: DataTypes, config: ExecutionConfig
) -> InvokeResult:
return await self.oracle.functions["publish_data_entries"].invoke(
new_entries=[{data_type.name: entry} for entry in entries],
enable_strk_fees=config.enable_strk_fees,
max_fee=config.max_fee,
l1_resource_bounds=config.l1_resource_bounds,
auto_estimate=config.auto_estimate,
new_entries=[{data_type: entry} for entry in entries],
execution_config=config,
callback=self.track_nonce,
)

Expand Down Expand Up @@ -322,7 +316,7 @@ async def set_future_checkpoints(
"self._setup_account_client(private_key, account_contract_address)"
)

config = execution_config or self.execution_config
config = execution_config or ExecutionConfig()

invocation = None
if config.pagination:
Expand Down Expand Up @@ -373,7 +367,7 @@ async def set_checkpoints(
"self._setup_account_client(private_key, account_contract_address)"
)

config = execution_config or self.execution_config
config = execution_config or ExecutionConfig()

invocation = None
if config.pagination:
Expand Down Expand Up @@ -428,7 +422,7 @@ async def update_oracle(
:return: InvokeResult
"""

config = execution_config or self.execution_config
config = execution_config or ExecutionConfig()

if not self.is_user_client:
raise AttributeError(
Expand Down
14 changes: 4 additions & 10 deletions sdk/pragma/onchain/types/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ def __getattr__(self, attr):
async def invoke_(
self,
*args,
execution_config: Optional[ExecutionConfig] = None,
callback: Optional[Callable[[SentTransactionResponse, str], Awaitable[None]]] = None,
execution_config: ExecutionConfig = ExecutionConfig(),
callback: Optional[
Callable[[SentTransactionResponse, str], Awaitable[None]]
] = None,
**kwargs,
) -> InvokeResult:
"""
Allows for a callback in the invocation of a contract method.
This is useful for tracking the nonce changes
"""
if execution_config is None :
raise AttributeError("Invalid Attribute")

prepared_call = (
self.prepare_invoke_v3(*args, **kwargs)
Expand All @@ -55,12 +55,6 @@ async def invoke_(
)
)

<<<<<<< Updated upstream
transaction = None


=======
>>>>>>> Stashed changes
response = await self._client.send_transaction(transaction)
if callback:
await callback(transaction.nonce, response.transaction_hash)
Expand Down
1 change: 0 additions & 1 deletion sdk/pragma/onchain/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
Literal[
"devnet",
"mainnet",
"fork_devnet",
"sepolia",
],
HttpUrl,
Expand Down
3 changes: 2 additions & 1 deletion sdk/pragma/onchain/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_rpc_url(network: Network = "devnet", port: int = 5050) -> str:
case "sepolia" | "mainnet":
urls = RPC_URLS[network]
return random.choice(urls)
case "devnet" | "fork_devnet":
case "devnet":
return f"http://127.0.0.1:{port}/rpc"
case _:
raise ValueError(f"Unsupported network: {network}")
Expand All @@ -31,4 +31,5 @@ def get_full_node_client_from_network(network: Network, port: int = 5050):
"""
Create a new full node client for the passed network/port (rpc url).
"""
print(get_rpc_url(network, port=port))
return FullNodeClient(node_url=get_rpc_url(network, port=port))
10 changes: 5 additions & 5 deletions sdk/pragma/tests/api_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
from starknet_py.net.client import Client

from pragma.onchain.client import PragmaOnChainClient
from pragma.common.types import RPC_URLS
from pragma.publisher.client import PragmaAPIClient, PragmaAPIError
from pragma.tests.constants import MOCK_DIR, SAMPLE_ASSETS
from pragma.onchain.constants import RPC_URLS
from pragma.offchain.client import PragmaAPIClient
from pragma.offchain.exceptions import PragmaAPIError
from pragma.tests.constants import MOCK_DIR, USD_PAIRS
from pragma.tests.fixtures.devnet import get_available_port

JEDISWAP_POOL = "0x4e021092841c1b01907f42e7058f97e5a22056e605dce08a22868606ad675e0"

ACCOUNT_ADDRESS = os.getenv("TESTNET_ACCOUNT_ADDRESS")
ACCOUNT_PRIVATE_KEY = os.getenv("TESTNET_PRIVATE_KEY")
# %% SPOT


@pytest.fixture(scope="module")
Expand All @@ -37,7 +37,7 @@ def forked_client(request, module_mocker, pytestconfig) -> Client:
block_number = request.param.get("block_number", None)
network = request.param.get("network", "mainnet")

rpc_url = RPC_URLS[network][random.randint(0, len(RPC_URLS[network]) - 1)]
rpc_url = RPC_URLS[network][random.choice(list(RPC_URLS[network]))]
command = [
"starknet-devnet",
"--fork-network",
Expand Down
Loading

0 comments on commit 8cb64db

Please sign in to comment.