Skip to content

Commit 0de9157

Browse files
authored
Extract CommonPredicates lib into its own file (#142)
Closes #111 Some automatic prettier reformatting seems to have taken place
1 parent 5ff4491 commit 0de9157

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

.changeset/tame-seals-bake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fuel-bridge/solidity-contracts': minor
3+
---
4+
5+
Extract CommonPredicates lib into its own file

packages/solidity-contracts/contracts/fuelchain/FuelMessagePortal.sol

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {FuelChainState} from "./FuelChainState.sol";
1111
import {FuelBlockHeader, FuelBlockHeaderLib} from "./types/FuelBlockHeader.sol";
1212
import {FuelBlockHeaderLite, FuelBlockHeaderLiteLib} from "./types/FuelBlockHeaderLite.sol";
1313
import {CryptographyLib} from "../lib/Cryptography.sol";
14+
import {CommonPredicates} from "../lib/CommonPredicates.sol";
1415

1516
/// @notice Structure for proving an element in a merkle tree
1617
struct MerkleProof {
@@ -27,12 +28,6 @@ struct Message {
2728
bytes data;
2829
}
2930

30-
/// @notice Common predicates for Fuel inputs
31-
library CommonPredicates {
32-
bytes32 public constant CONTRACT_MESSAGE_PREDICATE =
33-
0xb12658c759d8bae2cdc523ebd7aa8637912f32b1763d242ad3618448057b79cd;
34-
}
35-
3631
/// @title FuelMessagePortal
3732
/// @notice The Fuel Message Portal contract sends messages to and from Fuel
3833
contract FuelMessagePortal is
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: Apache 2.0
2+
3+
pragma solidity 0.8.9;
4+
5+
/// @notice Common predicates for Fuel inputs
6+
library CommonPredicates {
7+
bytes32 public constant CONTRACT_MESSAGE_PREDICATE =
8+
0xb12658c759d8bae2cdc523ebd7aa8637912f32b1763d242ad3618448057b79cd;
9+
}

packages/solidity-contracts/contracts/messaging/gateway/FuelERC20Gateway.sol

+23-20
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ contract FuelERC20Gateway is
3333

3434
/// @dev Emitted when tokens are withdrawn from Fuel to Ethereum
3535
event Withdrawal(
36-
bytes32 indexed recipient, address indexed tokenAddress, bytes32 indexed fuelContractId, uint256 amount
36+
bytes32 indexed recipient,
37+
address indexed tokenAddress,
38+
bytes32 indexed fuelContractId,
39+
uint256 amount
3740
);
3841

3942
///////////////
@@ -108,12 +111,12 @@ contract FuelERC20Gateway is
108111
/// @param fuelContractId ID of the contract on Fuel that manages the deposited tokens
109112
/// @param amount Amount of tokens to deposit
110113
/// @dev Made payable to reduce gas costs
111-
function deposit(bytes32 to, address tokenAddress, bytes32 fuelContractId, uint256 amount)
112-
external
113-
payable
114-
virtual
115-
whenNotPaused
116-
{
114+
function deposit(
115+
bytes32 to,
116+
address tokenAddress,
117+
bytes32 fuelContractId,
118+
uint256 amount
119+
) external payable virtual whenNotPaused {
117120
bytes memory messageData = abi.encodePacked(
118121
fuelContractId,
119122
bytes32(uint256(uint160(tokenAddress))), // OFFSET_TOKEN_ADDRESS = 32
@@ -158,14 +161,12 @@ contract FuelERC20Gateway is
158161
/// @param amount Amount of tokens to withdraw
159162
/// @param tokenId Discriminator for ERC721 / ERC1155 tokens. For ERC20, it must be 0
160163
/// @dev Made payable to reduce gas costs
161-
function finalizeWithdrawal(address to, address tokenAddress, uint256 amount, uint256 tokenId)
162-
external
163-
payable
164-
virtual
165-
override
166-
whenNotPaused
167-
onlyFromPortal
168-
{
164+
function finalizeWithdrawal(
165+
address to,
166+
address tokenAddress,
167+
uint256 amount,
168+
uint256 tokenId
169+
) external payable virtual override whenNotPaused onlyFromPortal {
169170
require(amount > 0, "Cannot withdraw zero");
170171
require(tokenId == 0, "Fungible tokens cannot have a tokenId");
171172
bytes32 fuelContractId = messageSender();
@@ -181,7 +182,7 @@ contract FuelERC20Gateway is
181182
/// @notice Allows the admin to rescue ETH sent to this contract by accident
182183
/// @dev Made payable to reduce gas costs
183184
function rescueETH() external payable virtual onlyRole(DEFAULT_ADMIN_ROLE) {
184-
(bool success,) = address(msg.sender).call{value: address(this).balance}("");
185+
(bool success, ) = address(msg.sender).call{value: address(this).balance}("");
185186
require(success);
186187
}
187188

@@ -194,10 +195,12 @@ contract FuelERC20Gateway is
194195
/// @param fuelContractId ID of the contract on Fuel that manages the deposited tokens
195196
/// @param amount Amount of tokens to deposit
196197
/// @param messageData The data of the message to send for deposit
197-
function _deposit(address tokenAddress, bytes32 fuelContractId, uint256 amount, bytes memory messageData)
198-
internal
199-
virtual
200-
{
198+
function _deposit(
199+
address tokenAddress,
200+
bytes32 fuelContractId,
201+
uint256 amount,
202+
bytes memory messageData
203+
) internal virtual {
201204
require(amount > 0, "Cannot deposit zero");
202205

203206
//transfer tokens to this contract and update deposit balance

0 commit comments

Comments
 (0)