Skip to content

Commit

Permalink
feat: dualVMToken starknet functions (#1421)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

<!-- Give an estimate of the time you spent on this PR in terms of work
days.
Did you spend 0.5 days on this PR or rather 2 days?  -->

Time spent on this PR:

## Pull request type

<!-- Please try to limit your pull request to one type,
submit multiple pull requests if needed. -->

Please check the type of change your PR introduces:

- [ ] Bugfix
- [x] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying,
or link to a relevant issue. -->

Resolves #1417

## What is the new behavior?
- add tests
- interact directly with starknet address with DualVMToken

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1421)
<!-- Reviewable:end -->
  • Loading branch information
obatirou authored Sep 24, 2024
1 parent f364214 commit 524005d
Show file tree
Hide file tree
Showing 8 changed files with 737 additions and 94 deletions.
22 changes: 16 additions & 6 deletions kakarot_scripts/utils/kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from starknet_py.net.signer.stark_curve_signer import KeyPair
from starkware.starknet.public.abi import starknet_keccak
from web3 import Web3
from web3._utils.abi import get_abi_output_types, map_abi_data
from web3._utils.abi import abi_to_signature, get_abi_output_types, map_abi_data
from web3._utils.events import get_event_data
from web3._utils.normalizers import BASE_RETURN_NORMALIZERS
from web3.contract import Contract as Web3Contract
Expand Down Expand Up @@ -162,8 +162,16 @@ async def get_contract(
contract.bytecode_runtime = HexBytes(bytecode_runtime)

try:
for fun in contract.functions:
setattr(contract, fun, MethodType(_wrap_kakarot(fun, caller_eoa), contract))
for fun in contract.all_functions():
signature = abi_to_signature(fun.abi)
setattr(
contract,
fun.fn_name,
MethodType(_wrap_kakarot(signature, caller_eoa), contract),
)
contract.functions.__dict__[signature] = MethodType(
_wrap_kakarot(signature, caller_eoa), contract
)
except NoABIFunctionsFound:
pass
contract.events.parse_events = MethodType(_parse_events, contract.events)
Expand Down Expand Up @@ -376,7 +384,9 @@ def _parse_events(cls: ContractEvents, tx_receipt):
log_receipts = get_log_receipts(tx_receipt)

return {
event_abi.get("name"): _get_matching_logs_for_event(event_abi, log_receipts)
abi_to_signature(event_abi): _get_matching_logs_for_event(
event_abi, log_receipts
)
for event_abi in cls._events
}

Expand All @@ -396,13 +406,13 @@ def _wrap_kakarot(fun: str, caller_eoa: Optional[Account] = None):
"""Wrap a contract function call with the Kakarot contract."""

async def _wrapper(self, *args, **kwargs):
abi = self.get_function_by_name(fun).abi
abi = self.get_function_by_signature(fun).abi
gas_price = kwargs.pop("gas_price", DEFAULT_GAS_PRICE)
gas_limit = kwargs.pop("gas_limit", TRANSACTION_GAS_LIMIT)
value = kwargs.pop("value", 0)
caller_eoa_ = kwargs.pop("caller_eoa", caller_eoa)
max_fee = kwargs.pop("max_fee", None)
calldata = self.get_function_by_name(fun)(
calldata = self.get_function_by_signature(fun)(
*args, **kwargs
)._encode_transaction_data()

Expand Down
235 changes: 209 additions & 26 deletions solidity_contracts/src/CairoPrecompiles/DualVmToken.sol

Large diffs are not rendered by default.

Loading

0 comments on commit 524005d

Please sign in to comment.