Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This document explains how the vlPUFFER system works in simple terms. vlPUFFER i

The amount of vlPUFFER (voting power) you receive depends on how long you lock:

| Lock Duration | Approximate Multiplier |
| Lock Duration | Multiplier |
|---------------|------------------------|
| 30 days | 1x |
| 3 months | 3x |
Expand All @@ -23,7 +23,7 @@ The amount of vlPUFFER (voting power) you receive depends on how long you lock:
| 18 months | 18x |
| 24 months | 24x |

For example, if you lock 100 PUFFER for 6 months, you'll receive approximately 600 vlPUFFER tokens.
For example, if you lock 100 PUFFER for 12 months, you'll receive 1200 vlPUFFER tokens.

## Entry Points (How to Lock)

Expand All @@ -32,7 +32,7 @@ For example, if you lock 100 PUFFER for 6 months, you'll receive approximately 6
3. **Re-lock** - You can:
- Add more PUFFER to your existing lock
- Extend your lock duration
- Both add more tokens and extend the duration
- Both add more tokens and extend the duration to get more vlPUFFER tokens

Minimum lock amount: 10 PUFFER

Expand All @@ -49,7 +49,7 @@ vlPUFFER supports vote delegation, allowing you to:

- Delegate your voting power to another address (including yourself)
- By default, new locks are automatically self-delegated if you haven't chosen a delegate
- Delegate using a signature (delegateBySig) without requiring a transaction from the delegating account
- Delegation is handled by OpenZeppelin's `lib/openzeppelin-contracts/contracts/governance/utils/Votes.sol` contract

### Multiple Account Strategy

Expand Down Expand Up @@ -95,7 +95,8 @@ graph TD

## Important Notes

- You can only withdraw after your lock period ends
- You can only withdraw after your lock period ends.
- You can only have one lock at a time.
- Your vlPUFFER tokens cannot be transferred to other addresses
- If you don't withdraw within 1 week after lock expiry, anyone can kick you
- If you don't withdraw within 1 week after lock expiry, anyone can kick you and receive 1% of your PUFFER tokens
- Re-locking cannot result in less voting power than you currently have
43 changes: 29 additions & 14 deletions src/vlPUFFER.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ contract vlPUFFER is ERC20, ERC20Votes, Ownable2Step, Pausable {
uint256 internal constant _GRACE_PERIOD = 1 weeks;
// 1% in basis points
uint256 internal constant _KICKER_FEE_BPS = 100;
// 10000 in basis points
uint256 internal constant _KICKER_FEE_DENOMINATOR = 10_000;
// 100% in basis points
// forgefmt: disable-next-line
uint256 internal constant _KICKER_FEE_DENOMINATOR = 100_00;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100_00 ? it should be 10_000

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually we don't even need this as a constant. the term BPS already implies 10,000

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, but since it is not upgradeable contract, and we are hardcoding it. it might as well be a readable. this suggestion was made by @eladiosch because 10k bps = 100 %, so i just followed up on it

// Multiplier for vlPUFFER amount calculation
uint256 internal constant _LOCK_TIME_MULTIPLIER = 30 days;
// The minimum amount of PUFFER (PUFFER has 18 decimals, so this is 10 PUFFER) tokens that can be locked to receive vlPUFFER
Expand All @@ -88,6 +89,17 @@ contract vlPUFFER is ERC20, ERC20Votes, Ownable2Step, Pausable {
uint256 unlockTime;
}

/**
* @dev notice Permit struct
*/
struct Permit {
uint256 deadline;
uint256 amount;
uint8 v;
bytes32 r;
bytes32 s;
}

/**
* @notice Mapping of user addresses to their lock information
* @dev The key is the user address, and the value is a LockInfo struct containing:
Expand Down Expand Up @@ -120,25 +132,25 @@ contract vlPUFFER is ERC20, ERC20Votes, Ownable2Step, Pausable {
* @param unlockTime Timestamp (in seconds) when the lock will expire
*/
function createLock(uint256 amount, uint256 unlockTime) external {
// Transfer PUFFER tokens to this contract using SafeERC20
PUFFER.safeTransferFrom(msg.sender, address(this), amount);

_createLock(amount, unlockTime);
}

/**
* @notice Create a new lock with permit, allowing approval and locking in a single transaction
* @param value Amount of PUFFER tokens to lock
* @param unlockTime Timestamp (in seconds) when the lock will expire
* @param deadline Timestamp until which the signature is valid
* @param v Recovery byte of the signature
* @param r First 32 bytes of the signature
* @param s Second 32 bytes of the signature
* @param permitData Permit struct containing the signature
*/
function createLockWithPermit(uint256 value, uint256 unlockTime, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external
{
IERC20Permit(address(PUFFER)).permit(msg.sender, address(this), value, deadline, v, r, s);
function createLockWithPermit(uint256 value, uint256 unlockTime, Permit calldata permitData) external {
IERC20Permit(address(PUFFER)).permit({
owner: msg.sender,
spender: address(this),
value: permitData.amount,
deadline: permitData.deadline,
v: permitData.v,
s: permitData.s,
r: permitData.r
});

_createLock(value, unlockTime);
}
Expand All @@ -150,13 +162,16 @@ contract vlPUFFER is ERC20, ERC20Votes, Ownable2Step, Pausable {
{
multiplier = ((unlockTime - block.timestamp) / _LOCK_TIME_MULTIPLIER);
// Round down the unlockTime to the nearest 30-day multiplier
roundedUnlockTime = block.timestamp + (multiplier * _LOCK_TIME_MULTIPLIER);
roundedUnlockTime = uint256(block.timestamp) + (multiplier * _LOCK_TIME_MULTIPLIER);
}

function _createLock(uint256 amount, uint256 unlockTime) internal onlyValidLockDuration(unlockTime) whenNotPaused {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting multiplier as param directly instead of unlock time would make it more readable since there would be no uncertainty or mental calculations

require(amount >= _MIN_LOCK_AMOUNT, InvalidAmount());
require(lockInfos[msg.sender].pufferAmount == 0, LockAlreadyExists());

// Transfer PUFFER tokens to this contract using SafeERC20
PUFFER.safeTransferFrom(msg.sender, address(this), amount);

(uint256 roundedUnlockTime, uint256 multiplier) = _calculateUnlockTimeAndMultiplier(unlockTime);

// Calculate vlPUFFER amount based on the lock duration
Expand Down
15 changes: 13 additions & 2 deletions test/vlPUFFER.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ contract vlPUFFERTest is Test {
vm.startPrank(owner);
bytes32 digest = puffer.getPermitDigest(owner, address(vlPuffer), amount, 0, deadline);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digest);
vlPuffer.createLockWithPermit(amount, unlockTime, deadline, v, r, s);

vlPUFFER.Permit memory permit = vlPUFFER.Permit({ deadline: deadline, amount: amount, v: v, r: r, s: s });

vlPuffer.createLockWithPermit(amount, unlockTime, permit);
vm.stopPrank();

// 100 * 365 / 30 = 1200
assertEq(vlPuffer.balanceOf(owner), amount * 12, "Bad vlPUFFER balance");
assertEq(puffer.balanceOf(address(vlPuffer)), amount, "Bad PUFFER balance in vlPUFFER");
}

function test_createLockWithPermit_expired() public {
Expand All @@ -97,8 +101,11 @@ contract vlPUFFERTest is Test {
vm.startPrank(owner);
bytes32 digest = puffer.getPermitDigest(owner, address(vlPuffer), amount, 0, deadline);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digest);

vlPUFFER.Permit memory permit = vlPUFFER.Permit({ deadline: deadline, amount: amount, v: v, r: r, s: s });

vm.expectRevert(abi.encodeWithSignature("ERC2612ExpiredSignature(uint256)", 0));
vlPuffer.createLockWithPermit(amount, unlockTime, deadline, v, r, s);
vlPuffer.createLockWithPermit(amount, unlockTime, permit);
vm.stopPrank();
}

Expand All @@ -114,6 +121,7 @@ contract vlPUFFERTest is Test {

// Check that alice is delegated to herself by default
assertEq(vlPuffer.delegates(alice), alice, "Default delegation should be to self");
assertEq(puffer.balanceOf(address(vlPuffer)), amount, "Bad PUFFER balance in vlPUFFER");
}

function test_reLock() public {
Expand All @@ -136,6 +144,9 @@ contract vlPUFFERTest is Test {
// (100 + 50) * 24 = 3600 vlPUFFER
// that is x24 multiplier
assertEq(vlPuffer.balanceOf(alice), 3600 ether, "Bad vlPUFFER balance after reLock");
assertEq(
puffer.balanceOf(address(vlPuffer)), initialAmount + additionalAmount, "Bad PUFFER balance in vlPUFFER"
);
}

function test_reLock_withZeroAmountAndSameUnlockTime() public {
Expand Down