Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import { ISemver } from "interfaces/universal/ISemver.sol";

interface INativeAssetLiquidity is ISemver {
error Unauthorized();
error InvalidAmount();

event LiquidityDeposited(address indexed caller, uint256 value);
event LiquidityWithdrawn(address indexed caller, uint256 value);
event LiquidityFunded(address indexed funder, uint256 value);

function deposit() external payable;
function withdraw(uint256 _amount) external;
function fund() external payable;
}
31 changes: 0 additions & 31 deletions packages/contracts-bedrock/snapshots/abi/NativeAssetLiquidity.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "fund",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "version",
Expand Down Expand Up @@ -58,25 +51,6 @@
"name": "LiquidityDeposited",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "funder",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "LiquidityFunded",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand All @@ -96,11 +70,6 @@
"name": "LiquidityWithdrawn",
"type": "event"
},
{
"inputs": [],
"name": "InvalidAmount",
"type": "error"
},
{
"inputs": [],
"name": "Unauthorized",
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/snapshots/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
"sourceCodeHash": "0xb4fca8d4532e88e0dd53d3643aa4022953e37c745753009b3c8f9bcca5806f57"
},
"src/L2/NativeAssetLiquidity.sol:NativeAssetLiquidity": {
"initCodeHash": "0x2c50c7cac8eab6867ffb969a65a8aa3026d415f2e9464726683ff6cd5da0b8f3",
"sourceCodeHash": "0x9432883dd4aa4d5ffc733ad99fa7bcc9cc8c319e654b385b8cd093a37a4c94cb"
"initCodeHash": "0x9e94f5271edad247ed8f9900aabc3fd3ce7404cc0512753a8fd10b7f1143476d",
"sourceCodeHash": "0xf991ff4d47c610778669721c68908beab4336f1eba52a7d8f6cdb8317707c481"
},
"src/L2/OperatorFeeVault.sol:OperatorFeeVault": {
"initCodeHash": "0x3d8c0d7736e8767f2f797da1c20c5fe30bd7f48a4cf75f376290481ad7c0f91f",
Expand Down
13 changes: 1 addition & 12 deletions packages/contracts-bedrock/src/L2/NativeAssetLiquidity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Predeploys } from "src/libraries/Predeploys.sol";
import { ISemver } from "interfaces/universal/ISemver.sol";

// Errors
import { Unauthorized, InvalidAmount } from "src/libraries/errors/CommonErrors.sol";
import { Unauthorized } from "src/libraries/errors/CommonErrors.sol";

/// @custom:predeploy 0x4200000000000000000000000000000000000029
/// @title NativeAssetLiquidity
Expand All @@ -23,9 +23,6 @@ contract NativeAssetLiquidity is ISemver {
/// @notice Emitted when an address deposits native asset liquidity.
event LiquidityDeposited(address indexed caller, uint256 value);

/// @notice Emitted when funds are received.
event LiquidityFunded(address indexed funder, uint256 value);

/// @notice Semantic version.
/// @custom:semver 1.0.0
string public constant version = "1.0.0";
Expand All @@ -46,12 +43,4 @@ contract NativeAssetLiquidity is ISemver {

emit LiquidityWithdrawn(msg.sender, _amount);
}

/// @notice Fund the contract by sending native asset.
/// @dev The function is payable to accept native asset.
function fund() external payable {
if (msg.value == 0) revert InvalidAmount();

emit LiquidityFunded(msg.sender, msg.value);
}
}
40 changes: 1 addition & 39 deletions packages/contracts-bedrock/test/L2/NativeAssetLiquidity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CommonTest } from "test/setup/CommonTest.sol";
import { DevFeatures } from "src/libraries/DevFeatures.sol";

// Error imports
import { Unauthorized, InvalidAmount } from "src/libraries/errors/CommonErrors.sol";
import { Unauthorized } from "src/libraries/errors/CommonErrors.sol";

/// @title NativeAssetLiquidity_TestInit
/// @notice Reusable test initialization for `NativeAssetLiquidity` tests.
Expand Down Expand Up @@ -147,41 +147,3 @@ contract NativeAssetLiquidity_Withdraw_Test is NativeAssetLiquidity_TestInit {
assertEq(address(liquidityController).balance, 0);
}
}

/// @title NativeAssetLiquidity_Fund_Test
/// @notice Tests the `fund` function of the `NativeAssetLiquidity` contract.
contract NativeAssetLiquidity_Fund_Test is NativeAssetLiquidity_TestInit {
/// @notice Tests that the fund function succeeds when called with a non-zero value.
/// @param _amount Amount of native asset (in wei) to call the fund function with.
/// @param _caller Address of the caller to call the fund function with.
function testFuzz_fund_succeeds(uint256 _amount, address _caller) public {
_amount = bound(_amount, 1, 1000 ether);
vm.assume(_caller != address(0));
vm.assume(_caller != address(nativeAssetLiquidity)); // Prevent contract from calling itself

// Deal caller with the amount to fund
vm.deal(_caller, _amount);
uint256 initialContractBalance = address(nativeAssetLiquidity).balance;

// Expect emit LiquidityFunded event
vm.expectEmit(address(nativeAssetLiquidity));
emit LiquidityFunded(_caller, _amount);
vm.prank(_caller);
nativeAssetLiquidity.fund{ value: _amount }();

// Assert caller and contract balances are updated correctly
assertEq(_caller.balance, 0);
assertEq(address(nativeAssetLiquidity).balance, initialContractBalance + _amount);
}

/// @notice Tests that the fund function reverts when called with zero value.
function test_fund_zeroAmount_reverts() public {
uint256 initialContractBalance = address(nativeAssetLiquidity).balance;
// Expect revert with InvalidAmount
vm.expectRevert(InvalidAmount.selector);
nativeAssetLiquidity.fund{ value: 0 }();

// Assert contract balance does not change
assertEq(address(nativeAssetLiquidity).balance, initialContractBalance);
}
}