This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use DualVmToken for Coinbase (#1487)
Resolves: #1486 <!-- 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/1487) <!-- Reviewable:end -->
- Loading branch information
1 parent
521d141
commit f247bab
Showing
15 changed files
with
698 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
solidity_contracts/src/CairoPrecompiles/EthStarknetBridge.sol
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
import {DualVmToken} from "../CairoPrecompiles/DualVmToken.sol"; | ||
|
||
contract Coinbase { | ||
/// @dev The EVM address of the DualVmToken for Kakarot ETH. | ||
DualVmToken public immutable kakarotEth; | ||
|
||
/// @dev State variable to store the owner of the contract | ||
address public owner; | ||
|
||
/// Constructor sets the owner of the contract | ||
constructor(address _kakarotEth) { | ||
owner = msg.sender; | ||
kakarotEth = DualVmToken(_kakarotEth); | ||
} | ||
|
||
/// Modifier to restrict access to owner only | ||
/// @dev Assert that msd.sender is the owner | ||
modifier onlyOwner() { | ||
require(msg.sender == owner, "Not the contract owner"); | ||
_; | ||
} | ||
|
||
/// @notice Withdraws ETH from the contract to a Starknet address | ||
/// @dev DualVmToken.balanceOf(this) is the same as address(this).balance | ||
/// @param toStarknetAddress The Starknet address to withdraw to | ||
function withdraw(uint256 toStarknetAddress) external onlyOwner { | ||
uint256 balance = address(this).balance; | ||
kakarotEth.transfer(toStarknetAddress, balance); | ||
} | ||
|
||
/// @notice Transfers ownership of the contract to a new address | ||
/// @param newOwner The address to transfer ownership to | ||
function transferOwnership(address newOwner) external onlyOwner { | ||
require(newOwner != address(0), "New owner cannot be the zero address"); | ||
owner = newOwner; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Copyright 2019-2022 StarkWare Industries Ltd. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.starkware.co/open-source-license/ | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions | ||
and limitations under the License. | ||
*/ | ||
// SPDX-License-Identifier: Apache-2.0. | ||
pragma solidity ^0.8.0; | ||
|
||
import "./IStarknetMessagingEvents.sol"; | ||
|
||
interface IStarknetMessaging is IStarknetMessagingEvents { | ||
/** | ||
Returns the max fee (in Wei) that StarkNet will accept per single message. | ||
*/ | ||
function getMaxL1MsgFee() external pure returns (uint256); | ||
|
||
/** | ||
Sends a message to an L2 contract. | ||
This function is payable, the paid amount is the message fee. | ||
Returns the hash of the message and the nonce of the message. | ||
*/ | ||
function sendMessageToL2( | ||
uint256 toAddress, | ||
uint256 selector, | ||
uint256[] calldata payload | ||
) external payable returns (bytes32, uint256); | ||
|
||
/** | ||
Consumes a message that was sent from an L2 contract. | ||
Returns the hash of the message. | ||
*/ | ||
function consumeMessageFromL2(uint256 fromAddress, uint256[] calldata payload) | ||
external | ||
returns (bytes32); | ||
|
||
/** | ||
Starts the cancellation of an L1 to L2 message. | ||
A message can be canceled messageCancellationDelay() seconds after this function is called. | ||
Note: This function may only be called for a message that is currently pending and the caller | ||
must be the sender of the that message. | ||
*/ | ||
function startL1ToL2MessageCancellation( | ||
uint256 toAddress, | ||
uint256 selector, | ||
uint256[] calldata payload, | ||
uint256 nonce | ||
) external returns (bytes32); | ||
|
||
/** | ||
Cancels an L1 to L2 message, this function should be called at least | ||
messageCancellationDelay() seconds after the call to startL1ToL2MessageCancellation(). | ||
A message may only be cancelled by its sender. | ||
If the message is missing, the call will revert. | ||
Note that the message fee is not refunded. | ||
*/ | ||
function cancelL1ToL2Message( | ||
uint256 toAddress, | ||
uint256 selector, | ||
uint256[] calldata payload, | ||
uint256 nonce | ||
) external returns (bytes32); | ||
} |
66 changes: 66 additions & 0 deletions
66
solidity_contracts/src/Starknet/IStarknetMessagingEvents.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2019-2022 StarkWare Industries Ltd. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.starkware.co/open-source-license/ | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions | ||
and limitations under the License. | ||
*/ | ||
// SPDX-License-Identifier: Apache-2.0. | ||
pragma solidity ^0.8.0; | ||
|
||
interface IStarknetMessagingEvents { | ||
// This event needs to be compatible with the one defined in Output.sol. | ||
event LogMessageToL1(uint256 indexed fromAddress, address indexed toAddress, uint256[] payload); | ||
|
||
// An event that is raised when a message is sent from L1 to L2. | ||
event LogMessageToL2( | ||
address indexed fromAddress, | ||
uint256 indexed toAddress, | ||
uint256 indexed selector, | ||
uint256[] payload, | ||
uint256 nonce, | ||
uint256 fee | ||
); | ||
|
||
// An event that is raised when a message from L2 to L1 is consumed. | ||
event ConsumedMessageToL1( | ||
uint256 indexed fromAddress, | ||
address indexed toAddress, | ||
uint256[] payload | ||
); | ||
|
||
// An event that is raised when a message from L1 to L2 is consumed. | ||
event ConsumedMessageToL2( | ||
address indexed fromAddress, | ||
uint256 indexed toAddress, | ||
uint256 indexed selector, | ||
uint256[] payload, | ||
uint256 nonce | ||
); | ||
|
||
// An event that is raised when a message from L1 to L2 Cancellation is started. | ||
event MessageToL2CancellationStarted( | ||
address indexed fromAddress, | ||
uint256 indexed toAddress, | ||
uint256 indexed selector, | ||
uint256[] payload, | ||
uint256 nonce | ||
); | ||
|
||
// An event that is raised when a message from L1 to L2 is canceled. | ||
event MessageToL2Canceled( | ||
address indexed fromAddress, | ||
uint256 indexed toAddress, | ||
uint256 indexed selector, | ||
uint256[] payload, | ||
uint256 nonce | ||
); | ||
} |
Oops, something went wrong.