Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/improve eth contracts #69

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
17 changes: 8 additions & 9 deletions core/eth/contracts/Terabethia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,26 @@ contract Terabethia is Initializable, ITerabethiaCore {
external
returns (bytes32)
{
simpleStorage().nonce += 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a PR open for this change already #27

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Its the fist commit of this branch I used it as base

unchecked {
simpleStorage().nonce += 1;
}

uint256 nonce = simpleStorage().nonce;

bytes32 msgHash = keccak256(
abi.encodePacked(
uint256(uint160(msg.sender)),
to_address,
simpleStorage().nonce,
nonce,
payload.length,
payload
)
);

simpleStorage().messages[msgHash] += 1;
simpleStorage().messages[msgHash] = 1;

// we only emit event, so we can auto-trigger message consumption on the IC
emit LogMessageToL2(
msg.sender,
to_address,
simpleStorage().nonce,
payload
);
emit LogMessageToL2(msg.sender, to_address, nonce, payload);

return msgHash;
}
Expand Down
44 changes: 35 additions & 9 deletions eth_bridge/eth/contracts/EthProxy.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
pragma solidity ^0.8.0;
pragma solidity 0.8.17;

import "./ITerabethiaCore.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";

contract EthProxy {
contract EthProxy is Ownable, Pausable {
// Terabethia core contract.
ITerabethiaCore terabethiaCore;

// L2 Canister address
uint256 constant CANISTER_ADDRESS = 0x00000000003001090101;

// Init event
event InitLog(address indexed terabethia_core);

/**
Initializes the contract state.
*/
constructor(ITerabethiaCore terabethiaCore_) {
terabethiaCore = terabethiaCore_;

// emit init event
emit InitLog(address(terabethiaCore));
}

function withdraw(uint256 amount) external {
function withdraw(uint256 amount) external whenNotPaused {
// Construct the withdrawal message's payload.
uint256[] memory payload = new uint256[](2);
payload[0] = uint256(uint160(msg.sender));
Expand All @@ -27,19 +35,14 @@ contract EthProxy {
terabethiaCore.consumeMessage(CANISTER_ADDRESS, payload);

// withdraw eth
require(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this condition was removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, cause it is useless, its gonna fail anyways

address(this).balance >= amount,
"Address: insufficient balance"
);

(bool success, ) = payable(msg.sender).call{value: amount}("");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}

function deposit(uint256 user) external payable {
function deposit(uint256 user) external payable whenNotPaused {
require(msg.value >= 1 gwei, "DepositContract: deposit value too low");
require(
msg.value % 1 gwei == 0,
Expand All @@ -61,4 +64,27 @@ contract EthProxy {
// Send the message to the IC
terabethiaCore.sendMessage(CANISTER_ADDRESS, payload);
}

function send(address recipient, uint256 amount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this function for? Also does just give arbitrary ownership of all funds in the contract to the owner?

external
payable
onlyOwner
{
require(recipient != address(0), "Cannot send to zero address");

// withdraw eth
(bool success, ) = payable(recipient).call{value: amount}("");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}

function pause() public onlyOwner {
_pause();
}

function unpause() public onlyOwner {
_unpause();
}
}
2 changes: 1 addition & 1 deletion eth_bridge/eth/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
});

const config: HardhatUserConfig = {
solidity: "0.8.11",
solidity: "0.8.17",
networks: {
goerli: {
url: process.env.ALCHEMY_ENDPOINT,
Expand Down
Loading