Skip to content

Commit

Permalink
chore: update deploy scripts to use COINBASE from env and set basefee (
Browse files Browse the repository at this point in the history
…#1215)

<!--- 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
- [ ] 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 #1159

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

-
-
-

<!-- 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/1215)
<!-- Reviewable:end -->
  • Loading branch information
enitrat authored Jun 24, 2024
1 parent c5002a7 commit 464d254
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ KAKAROT_STAGING_ACCOUNT_ADDRESS=
KAKAROT_STAGING_PRIVATE_KEY=
KAKAROT_STAGING_RPC_URL=https://juno-kakarot-testnet-stage.karnot.xyz

# An EVM address that receives the fees
KAKAROT_COINBASE_RECIPIENT=0x20eB005C0b9c906691F885eca5895338E15c36De

# Default values in case no network match
ACCOUNT_ADDRESS=
PRIVATE_KEY=
Expand Down
9 changes: 7 additions & 2 deletions kakarot_scripts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# Hardcode block gas limit to 7M
BLOCK_GAS_LIMIT = 7_000_000

DEFAULT_GAS_PRICE = int(1e9)
BEACON_ROOT_ADDRESS = "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"


Expand Down Expand Up @@ -184,7 +184,12 @@ class ChainId(IntEnum):
NETWORK["chain_id"] = ChainId.chain_id

ETH_TOKEN_ADDRESS = 0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7
COINBASE = 0xCA40796AFB5472ABAED28907D5ED6FC74C04954A
COINBASE = int(
os.getenv(
"KAKAROT_COINBASE_RECIPIENT", "0x20eB005C0b9c906691F885eca5895338E15c36De"
),
16,
)
SOURCE_DIR = Path("src")
SOURCE_DIR_FIXTURES = Path("tests/fixtures")
CONTRACTS = {p.stem: p for p in list(SOURCE_DIR.glob("**/*.cairo"))}
Expand Down
9 changes: 8 additions & 1 deletion kakarot_scripts/deploy_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
BLOCK_GAS_LIMIT,
COINBASE,
DECLARED_CONTRACTS,
DEFAULT_GAS_PRICE,
ETH_TOKEN_ADDRESS,
EVM_ADDRESS,
NETWORK,
Expand Down Expand Up @@ -43,8 +44,9 @@ async def main():

# %% Deployments
class_hash = get_declarations()

deployments = get_deployments()
freshly_deployed = False

if deployments.get("kakarot") and NETWORK["type"] is not NetworkType.DEV:
logger.info("ℹ️ Kakarot already deployed, checking version.")
deployed_class_hash = await RPC_CLIENT.get_class_hash_at(
Expand Down Expand Up @@ -75,6 +77,7 @@ async def main():
COINBASE,
BLOCK_GAS_LIMIT,
)
freshly_deployed = True

if NETWORK["type"] is NetworkType.STAGING:
deployments["EVM"] = await upgrade(
Expand Down Expand Up @@ -117,6 +120,10 @@ async def main():
)
await get_eoa(amount=amount)

# Set the base fee if freshly deployed
if freshly_deployed:
await invoke("kakarot", "set_base_fee", DEFAULT_GAS_PRICE)


# %% Run
if __name__ == "__main__":
Expand Down
5 changes: 3 additions & 2 deletions kakarot_scripts/utils/kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from web3.types import LogReceipt

from kakarot_scripts.constants import (
DEFAULT_GAS_PRICE,
EVM_ADDRESS,
EVM_PRIVATE_KEY,
NETWORK,
Expand Down Expand Up @@ -252,7 +253,7 @@ def _wrap_kakarot(fun: str, caller_eoa: Optional[Account] = None):

async def _wrapper(self, *args, **kwargs):
abi = self.get_function_by_name(fun).abi
gas_price = kwargs.pop("gas_price", 1_000)
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)
Expand Down Expand Up @@ -366,7 +367,7 @@ async def eth_send_transaction(
"nonce": nonce,
"gas": gas,
"maxPriorityFeePerGas": 1,
"maxFeePerGas": 100,
"maxFeePerGas": DEFAULT_GAS_PRICE,
"to": to_checksum_address(to) if to else None,
"value": value,
"data": data,
Expand Down
5 changes: 3 additions & 2 deletions kakarot_scripts/utils/l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from web3.exceptions import NoABIFunctionsFound

from kakarot_scripts.constants import (
DEFAULT_GAS_PRICE,
DEPLOYMENTS_DIR,
EVM_ADDRESS,
EVM_PRIVATE_KEY,
Expand Down Expand Up @@ -136,7 +137,7 @@ async def send_l1_transaction(
"nonce": nonce,
"gas": gas,
"maxPriorityFeePerGas": 1,
"maxFeePerGas": int(1e9),
"maxFeePerGas": DEFAULT_GAS_PRICE,
"to": to_checksum_address(to) if to else None,
"value": value,
"data": data,
Expand Down Expand Up @@ -166,7 +167,7 @@ def _wrap_web3(fun: str, caller_eoa_: Optional[EvmAccount] = None):

async def _wrapper(self, *args, **kwargs):
abi = self.get_function_by_name(fun).abi
gas_price = kwargs.pop("gas_price", 1_000)
gas_price = kwargs.pop("gas_price", DEFAULT_GAS_PRICE)
gas_limit = kwargs.pop("gas_limit", TRANSACTION_GAS_LIMIT)
value = kwargs.pop("value", 0)
calldata = self.get_function_by_name(fun)(
Expand Down
15 changes: 13 additions & 2 deletions tests/end_to_end/PlainOpcodes/test_safe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import pytest_asyncio

from kakarot_scripts.constants import DEFAULT_GAS_PRICE
from tests.utils.constants import ACCOUNT_BALANCE


Expand Down Expand Up @@ -38,7 +39,12 @@ async def test_should_withdraw_transfer_eth(self, safe, owner, eth_balance_of):

owner_balance_after = await eth_balance_of(owner.address)
assert await safe.balance() == 0
assert owner_balance_after - owner_balance_before + gas_used == safe_balance
assert (
owner_balance_after
- owner_balance_before
+ gas_used * DEFAULT_GAS_PRICE
== safe_balance
)

class TestWithdrawCall:
async def test_should_withdraw_call_eth(self, safe, owner, eth_balance_of):
Expand All @@ -55,7 +61,12 @@ async def test_should_withdraw_call_eth(self, safe, owner, eth_balance_of):

owner_balance_after = await eth_balance_of(owner.address)
assert await safe.balance() == 0
assert owner_balance_after - owner_balance_before + gas_used == safe_balance
assert (
owner_balance_after
- owner_balance_before
+ gas_used * DEFAULT_GAS_PRICE
== safe_balance
)

class TestDeploySafeWithValue:
async def test_deploy_safe_with_value(self, safe, deploy_contract, owner):
Expand Down

0 comments on commit 464d254

Please sign in to comment.