Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
dev: send remaining eoa ETH to coinbase after TX
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Nov 5, 2024
1 parent c5413db commit 0986d4f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 49 deletions.
2 changes: 1 addition & 1 deletion deployments/starknet-sepolia/kakarot_deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"address": "0xba5ed099633d3b313e4d5f7bdc1305d3c28ba5ed",
"starknet_address": "0x2361be1b7ded312bfc16c2547eaaf2308d3c9b6aa9037d8fc9ee57329f00951"
}
}
}
2 changes: 1 addition & 1 deletion kakarot_scripts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class NetworkType(Enum):
"type": NetworkType.DEV,
"check_interval": 0.01,
"max_wait": 3,
"relayers": [
"relayers": [
{
"address": 0xE29882A1FCBA1E7E10CAD46212257FEA5C752A4F9B1B1EC683C503A2CF5C8A,
"private_key": 0x14D6672DCB4B77CA36A887E9A11CD9D637D5012468175829E9C6E770C61642,
Expand Down
1 change: 1 addition & 0 deletions kakarot_scripts/deployment/evm_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async def deploy_evm_contracts():
"address": int(contract.address, 16),
"starknet_address": contract.starknet_address,
}
logger.info(f"✅ Coinbase deployed at {contract.address}")
await invoke("kakarot", "set_coinbase", int(contract.address, 16))

# %% Tear down
Expand Down
4 changes: 3 additions & 1 deletion solidity_contracts/src/Kakarot/Coinbase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ contract Coinbase is Ownable2Step {
nativeTokenStarknetAddress = _nativeTokenStarknetAddress;
}

receive() external payable {}

/// @notice Withdraws the native token collected by the contract to an address
/// @dev Uses CairoLib to make a StarknetCall to transfer this contract's balance to a starknet address.
/// @param toStarknetAddress The Starknet address to withdraw to
function withdraw(uint256 toStarknetAddress) external onlyOwner {
uint256 balance = address(this).balance;
uint128 balanceLow = uint128(balance & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint128 balanceLow = uint128(balance);
uint128 balanceHigh = uint128(balance >> 128);
uint256[] memory data = new uint256[](3);
data[0] = toStarknetAddress; // recipient
Expand Down
65 changes: 26 additions & 39 deletions tests/end_to_end/CairoPrecompiles/test_dual_vm_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pytest_asyncio
from eth_utils import keccak

from kakarot_scripts.utils.kakarot import get_contract as get_contract_evm
from kakarot_scripts.utils.kakarot import get_deployments as get_evm_deployments
from kakarot_scripts.utils.kakarot import deploy as deploy_kakarot
from kakarot_scripts.utils.starknet import deploy as deploy_starknet
from kakarot_scripts.utils.starknet import get_contract as get_contract_starknet
from kakarot_scripts.utils.starknet import (
get_starknet_account,
Expand All @@ -13,25 +13,35 @@
from tests.utils.errors import cairo_error


@pytest_asyncio.fixture(scope="session")
async def dual_vm_token(owner):
evm_deployments = get_evm_deployments()
ether = evm_deployments["Ether"]["address"]
return await get_contract_evm(
@pytest_asyncio.fixture(scope="function")
async def starknet_token(owner):
address = await deploy_starknet(
"StarknetToken",
"MyToken",
"MTK",
int(2**256 - 1),
owner.starknet_contract.address,
)
return get_contract_starknet("StarknetToken", address=address)


@pytest_asyncio.fixture(scope="function")
async def dual_vm_token(kakarot, starknet_token, owner):
dual_vm_token = await deploy_kakarot(
"CairoPrecompiles",
"DualVmToken",
address=ether,
kakarot.address,
starknet_token.address,
caller_eoa=owner.starknet_contract,
)


@pytest_asyncio.fixture(scope="session")
async def starknet_token(dual_vm_token):
starknet_address = await dual_vm_token.starknetToken()
deployer = await get_starknet_account()
return get_contract_starknet(
"StarknetToken", address=starknet_address, provider=deployer
await invoke(
"kakarot",
"set_authorized_cairo_precompile_caller",
int(dual_vm_token.address, 16),
True,
)
return dual_vm_token


@pytest_asyncio.fixture(scope="function", autouse=True)
Expand All @@ -54,30 +64,7 @@ async def fund_owner(owner, starknet_token, max_fee):
(balance,) = await starknet_token.functions["balance_of"].call(
owner.starknet_contract.address
)
assert (
balance >= amount
), f"Transfer failed. Expected min balance: {amount}, Actual balance: {balance}"


@pytest_asyncio.fixture(scope="function")
async def starknet_token(owner):
address = await deploy_starknet(
"StarknetToken", int(2**256 - 1), owner.starknet_contract.address
)
return get_contract_starknet("StarknetToken", address=address)



@pytest_asyncio.fixture(scope="function")
async def dual_vm_token(owner):
evm_deployments = get_evm_deployments()
ether = evm_deployments["Ether"]["address"]
return await get_contract_evm(
"CairoPrecompiles",
"DualVmToken",
address=ether,
caller_eoa=owner.starknet_contract,
)
assert balance >= amount


@pytest.mark.asyncio(scope="module")
Expand Down
14 changes: 7 additions & 7 deletions tests/end_to_end/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ async def _factory(amount=0):

yield _factory

kakarot_eth = await get_solidity_contract(
"CairoPrecompiles",
"DualVmToken",
address=get_deployments()["Ether"]["address"],
coinbase = await get_solidity_contract(
"Kakarot",
"Coinbase",
address=get_deployments()["Coinbase"]["address"],
)
gas_price = (await call("kakarot", "get_base_fee")).base_fee
gas_limit = 40_000
Expand All @@ -86,10 +86,10 @@ async def _factory(amount=0):
if balance < tx_cost:
continue

await kakarot_eth.functions["transfer(uint256,uint256)"](
deployer.address,
balance - tx_cost,
# Send the funds to the coinbase contract. The owner will be able to withdraw them.
await coinbase.functions["receive()"](
caller_eoa=wallet.starknet_contract,
value=balance - tx_cost,
gas_limit=gas_limit,
gas_price=gas_price,
)
Expand Down

0 comments on commit 0986d4f

Please sign in to comment.