Skip to content

Commit

Permalink
feat: ensure eth is receivable
Browse files Browse the repository at this point in the history
in case eth gets kicked to our contract from one of the deposit assets
  • Loading branch information
jparklev committed Apr 25, 2024
1 parent ebc9c85 commit 473ee76
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions contracts/PointTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,6 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall
}

function _authorizeUpgrade(address _newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}

receive() external payable {}
}
10 changes: 5 additions & 5 deletions contracts/script/PointTokenVault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ contract PointTokenVaultScripts is BatchScript {
function run(string memory version) public returns (PointTokenVault) {
PointTokenVault pointTokenVaultImplementation = new PointTokenVault{salt: keccak256(abi.encode(version))}();

PointTokenVault pointTokenVault = PointTokenVault(
PointTokenVault pointTokenVault = PointTokenVault(payable(
address(
new ERC1967Proxy{salt: keccak256(abi.encode(version))}(
address(pointTokenVaultImplementation),
abi.encodeCall(PointTokenVault.initialize, (msg.sender)) // msg.sender is admin
)
)
))
);

return pointTokenVault;
Expand All @@ -69,7 +69,7 @@ contract PointTokenVaultScripts is BatchScript {
vm.startBroadcast(JIM_PRIVATE_KEY);

ERC20 token = ERC20(0x791a051631c9c4cDf4E03Fb7Aec3163AE164A34B);
PointTokenVault pointTokenVault = PointTokenVault(0xbff7Fb79efC49504afc97e74F83EE618768e63E9);
PointTokenVault pointTokenVault = PointTokenVault(payable(0xbff7Fb79efC49504afc97e74F83EE618768e63E9));
token.symbol();

token.approve(address(pointTokenVault), 2.5e18);
Expand All @@ -83,7 +83,7 @@ contract PointTokenVaultScripts is BatchScript {
function upgrade() public {
vm.startBroadcast();

PointTokenVault currentPointTokenVault = PointTokenVault(0xbff7Fb79efC49504afc97e74F83EE618768e63E9);
PointTokenVault currentPointTokenVault = PointTokenVault(payable(0xbff7Fb79efC49504afc97e74F83EE618768e63E9));

PointTokenVault PointTokenVaultImplementation = new PointTokenVault();

Expand All @@ -95,7 +95,7 @@ contract PointTokenVaultScripts is BatchScript {
function deployPToken() public {
vm.startBroadcast(JIM_PRIVATE_KEY);

PointTokenVault pointTokenVault = PointTokenVault(0xbff7Fb79efC49504afc97e74F83EE618768e63E9);
PointTokenVault pointTokenVault = PointTokenVault(payable(0xbff7Fb79efC49504afc97e74F83EE618768e63E9));

pointTokenVault.deployPToken(LibString.packTwo("ETHERFI Points", "pEF"));

Expand Down
16 changes: 16 additions & 0 deletions contracts/test/PointTokenVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,22 @@ contract PointTokenVaultTest is Test {
assertEq(rewardToken.balanceOf(vitalik), 2e18);
assertEq(pointTokenVault.pTokens(eigenPointsId).balanceOf(vitalik), 0);
}

function test_ReceiveETH() public payable {
// Amount of ETH to send
uint256 amountToSend = 1 ether;

// Record the initial balance of the PointTokenVault
uint256 initialBalance = address(pointTokenVault).balance;

// Send ETH to the PointTokenVault
(bool sent,) = address(pointTokenVault).call{value: 1 ether}("");
require(sent, "Failed to send Ether");

// Check the new balance of the PointTokenVault
uint256 newBalance = address(pointTokenVault).balance;
assertEq(newBalance, initialBalance + amountToSend);
}
}

contract Echo {
Expand Down

0 comments on commit 473ee76

Please sign in to comment.