diff --git a/contracts/LiquidityMining/VotingEscrow/VotingEscrowFuseMainchain.sol b/contracts/LiquidityMining/VotingEscrow/VotingEscrowFuseMainchain.sol index d55db08c..fca2b85e 100644 --- a/contracts/LiquidityMining/VotingEscrow/VotingEscrowFuseMainchain.sol +++ b/contracts/LiquidityMining/VotingEscrow/VotingEscrowFuseMainchain.sol @@ -50,16 +50,6 @@ contract VotingEscrowFuseMainchain is VotingEscrowTokenBase, IPVotingEscrowMainc __BoringOwnable_init(); } - /// @notice basically a proxy function to call increaseLockPosition & broadcastUserPosition at the same time - function increaseLockPositionAndBroadcast( - uint128 additionalAmountToLock, - uint128 newExpiry, - uint256[] calldata chainIds - ) external payable refundUnusedEth returns (uint128 newVeBalance) { - newVeBalance = increaseLockPosition(additionalAmountToLock, newExpiry); - broadcastUserPosition(msg.sender, chainIds); - } - /** * @notice increases the lock position of a user (amount and/or expiry). Applicable even when * user has no position or the current position has expired. @@ -73,9 +63,10 @@ contract VotingEscrowFuseMainchain is VotingEscrowTokenBase, IPVotingEscrowMainc function increaseLockPosition( uint128 additionalAmountToLock, uint128 newExpiry - ) public returns (uint128 newVeBalance) { + ) public payable returns (uint128 newVeBalance) { address user = msg.sender; + if (msg.value < additionalAmountToLock) revert Errors.VEInsufficientFunds(); if (!WeekMath.isValidWTime(newExpiry)) revert Errors.InvalidWTime(newExpiry); if (MiniHelpers.isTimeInThePast(newExpiry)) revert Errors.ExpiryInThePast(newExpiry); @@ -89,10 +80,6 @@ contract VotingEscrowFuseMainchain is VotingEscrowTokenBase, IPVotingEscrowMainc uint128 additionalDurationToLock = newExpiry - positionData[user].expiry; - if (additionalAmountToLock > 0) { - fuse.safeTransferFrom(user, address(this), additionalAmountToLock); - } - newVeBalance = _increasePosition(user, additionalAmountToLock, additionalDurationToLock); emit NewLockPosition(user, newTotalAmountLocked, newExpiry); @@ -113,7 +100,8 @@ contract VotingEscrowFuseMainchain is VotingEscrowTokenBase, IPVotingEscrowMainc delete positionData[user]; - fuse.safeTransfer(user, amount); + (bool success, ) = user.call{value: amount}(""); + require(success, "Transfer failed"); emit Withdraw(user, amount); } @@ -127,20 +115,6 @@ contract VotingEscrowFuseMainchain is VotingEscrowTokenBase, IPVotingEscrowMainc return supply.getCurrentValue(); } - /// @notice updates and broadcast the current totalSupply to different chains - function broadcastTotalSupply(uint256[] calldata chainIds) public payable refundUnusedEth { - _broadcastPosition(address(0), chainIds); - } - - /** - * @notice updates and broadcast the position of `user` to different chains, also updates and - * broadcasts totalSupply - */ - function broadcastUserPosition(address user, uint256[] calldata chainIds) public payable refundUnusedEth { - if (user == address(0)) revert Errors.ZeroAddress(); - _broadcastPosition(user, chainIds); - } - function getUserHistoryLength(address user) external view returns (uint256) { return userHistory[user].length(); } @@ -149,18 +123,6 @@ contract VotingEscrowFuseMainchain is VotingEscrowTokenBase, IPVotingEscrowMainc return userHistory[user].get(index); } - function getBroadcastSupplyFee(uint256[] calldata chainIds) external view returns (uint256 fee) { - for (uint256 i = 0; i < chainIds.length; i++) { - fee += _getSendMessageFee(chainIds[i], SAMPLE_SUPPLY_UPDATE_MESSAGE); - } - } - - function getBroadcastPositionFee(uint256[] calldata chainIds) external view returns (uint256 fee) { - for (uint256 i = 0; i < chainIds.length; i++) { - fee += _getSendMessageFee(chainIds[i], SAMPLE_POSITION_UPDATE_MESSAGE); - } - } - /** * @notice increase the locking position of the user * @dev works by simply removing the old position from all relevant data (as if the user has @@ -222,27 +184,4 @@ contract VotingEscrowFuseMainchain is VotingEscrowTokenBase, IPVotingEscrowMainc return (supply, wTime); } - - /// @notice broadcast position to all chains in chainIds - function _broadcastPosition(address user, uint256[] calldata chainIds) internal { - if (chainIds.length == 0) revert Errors.ArrayEmpty(); - - (VeBalance memory supply, ) = _applySlopeChange(); - - bytes memory userData = (user == address(0) ? EMPTY_BYTES : abi.encode(user, positionData[user])); - - for (uint256 i = 0; i < chainIds.length; ++i) { - if (!destinationContracts.contains(chainIds[i])) revert Errors.ChainNotSupported(chainIds[i]); - _broadcast(chainIds[i], uint128(block.timestamp), supply, userData); - } - - if (user != address(0)) { - emit BroadcastUserPosition(user, chainIds); - } - emit BroadcastTotalSupply(supply, chainIds); - } - - function _broadcast(uint256 chainId, uint128 msgTime, VeBalance memory supply, bytes memory userData) internal { - _sendMessage(chainId, abi.encode(msgTime, supply, userData)); - } } diff --git a/contracts/core/libraries/Errors.sol b/contracts/core/libraries/Errors.sol index 0cfea0e2..b61767e6 100644 --- a/contracts/core/libraries/Errors.sol +++ b/contracts/core/libraries/Errors.sol @@ -137,6 +137,7 @@ library Errors { error VEZeroPosition(); error VEZeroSlope(uint128 bias, uint128 slope); error VEReceiveOldSupply(uint256 msgTime); + error VEInsufficientFunds(); error GCNotPendleMarket(address caller); error GCNotVotingController(address caller); diff --git a/contracts/interfaces/IPVotingEscrowMainchain.sol b/contracts/interfaces/IPVotingEscrowMainchain.sol index f39191b6..87743d30 100644 --- a/contracts/interfaces/IPVotingEscrowMainchain.sol +++ b/contracts/interfaces/IPVotingEscrowMainchain.sol @@ -17,7 +17,7 @@ interface IPVotingEscrowMainchain is IPVeToken { // ============= ACTIONS ============= - function increaseLockPosition(uint128 additionalAmountToLock, uint128 expiry) external returns (uint128); + function increaseLockPosition(uint128 additionalAmountToLock, uint128 expiry) external payable returns (uint128); function withdraw() external returns (uint128);