Skip to content

Commit

Permalink
feat: refacto randomness mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt committed Jul 1, 2024
1 parent 3487641 commit 1f7e24c
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 276 deletions.
4 changes: 4 additions & 0 deletions pragma/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@
}

ALL_ASSETS = AssetConfig.from_yaml(SUPPORTED_ASSETS_FILE_PATH)

RANDOMNESS_REQUEST_EVENT_SELECTOR = (
"0xe3e1c077138abb6d570b1a7ba425f5479b12f50a78a72be680167d4cf79c48"
)
25 changes: 13 additions & 12 deletions pragma/core/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from starknet_py.contract import Contract as StarknetContract
from starknet_py.contract import ContractFunction, InvokeResult
from starknet_py.net.client_models import SentTransactionResponse, ResourceBounds
from starknet_py.net.client_models import SentTransactionResponse

from pragma.core.types import ExecutionConfig


class Contract(StarknetContract):
Expand All @@ -19,10 +21,7 @@ def __getattr__(self, attr):
async def invoke_(
self,
*args,
max_fee: Optional[int] = None,
auto_estimate: bool = False,
enable_strk_fees: Optional[bool] = False,
l1_resource_bounds: Optional[ResourceBounds] = None,
execution_config: Optional[ExecutionConfig] = None,
callback: Optional[Callable[[SentTransactionResponse], None]] = None,
**kwargs,
) -> InvokeResult:
Expand All @@ -33,23 +32,25 @@ async def invoke_(

prepared_call = (
self.prepare_invoke_v3(*args, **kwargs)
if enable_strk_fees
if execution_config.enable_strk_fees
else self.prepare_invoke_v1(*args, **kwargs)
)

# transfer ownership to the prepared call
self = prepared_call
if max_fee is not None:
self.max_fee = max_fee
if execution_config.max_fee is not None:
self.max_fee = execution_config.max_fee

transaction = (
await self.get_account.sign_invoke_v3(
calls=self,
l1_resource_bounds=l1_resource_bounds,
auto_estimate=auto_estimate,
l1_resource_bounds=execution_config.l1_resource_bounds,
auto_estimate=execution_config.auto_estimate,
)
if execution_config.enable_strk_fees
else await self.get_account.sign_invoke_v1(
calls=self, max_fee=execution_config.max_fee
)
if enable_strk_fees
else await self.get_account.sign_invoke_v1(calls=self, max_fee=max_fee)
)

response = await self._client.send_transaction(transaction)
Expand Down
Loading

0 comments on commit 1f7e24c

Please sign in to comment.