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

ADD - VeFUSE Main Feature #2

Open
wants to merge 1 commit into
base: vefuse
Choose a base branch
from
Open
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 @@ -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.
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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();
}
Expand All @@ -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
Expand Down Expand Up @@ -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));
}
}
1 change: 1 addition & 0 deletions contracts/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IPVotingEscrowMainchain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down