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

Rollback ve changes #696

Merged
merged 5 commits into from
Sep 1, 2022
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
25 changes: 0 additions & 25 deletions contracts/df/DFStrategyV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,4 @@ contract DFStrategyV1 is ReentrancyGuard {
return result;
}

function claimAndStake(
address tokenAddress,
uint256 totalAmount,
address _veOCEAN
) public nonReentrant returns (bool) {
require(
dfrewards.claimable(msg.sender, tokenAddress) >= totalAmount,
"Not enough rewards"
);
uint256 balanceBefore = IERC20(tokenAddress).balanceOf(address(this));
uint256 claimed = dfrewards.claimForStrat(msg.sender, tokenAddress); // claim rewards for the strategy
uint256 balanceAfter = IERC20(tokenAddress).balanceOf(address(this));
require(balanceAfter - balanceBefore == claimed, "Not enough rewards");
IERC20(tokenAddress).safeApprove(_veOCEAN, totalAmount);
IveOCEAN(_veOCEAN).deposit_for(msg.sender, totalAmount);

if (claimed > totalAmount) {
IERC20(tokenAddress).safeTransfer(
msg.sender,
claimed - totalAmount
);
}

return true;
}
}
47 changes: 15 additions & 32 deletions contracts/ve/veDelegation.vy
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ IDENTITY_PRECOMPILE: constant(address) = 0x0000000000000000000000000000000000000
MAX_PCT: constant(uint256) = 10_000
WEEK: constant(uint256) = 86400 * 7

VOTING_ESCROW: immutable(address)


veOcean: public(address)
balanceOf: public(HashMap[address, uint256])
getApproved: public(HashMap[uint256, address])
isApprovedForAll: public(HashMap[address, HashMap[address, bool]])
Expand Down Expand Up @@ -132,14 +133,15 @@ grey_list: public(HashMap[address, HashMap[address, bool]])


@external
def __init__(_name: String[32], _symbol: String[32], _base_uri: String[128], _ve:address):
def __init__(_name: String[32], _symbol: String[32], _base_uri: String[128], _ve: address):
self.name = _name
self.symbol = _symbol
self.base_uri = _base_uri
self.veOcean = _ve

self.admin = msg.sender

VOTING_ESCROW = _ve


@internal
def _approve(_owner: address, _approved: address, _token_id: uint256):
Expand Down Expand Up @@ -309,7 +311,7 @@ def _burn_boost(_token_id: uint256, _delegator: address, _receiver: address, _bi
next_expiry: uint256 = expiry_data % 2 ** 128
active_delegations: uint256 = shift(expiry_data, -128) - 1

expiries: uint256 = self.account_expiries[_delegator][expire_time] - 1
expiries: uint256 = self.account_expiries[_delegator][expire_time]

if active_delegations != 0 and expire_time == next_expiry and expiries == 0:
# Will be passed if
Expand All @@ -331,7 +333,7 @@ def _burn_boost(_token_id: uint256, _delegator: address, _receiver: address, _bi
next_expiry = 0

self.boost[_delegator].expiry_data = shift(active_delegations, 128) + next_expiry
self.account_expiries[_delegator][expire_time] = expiries
self.account_expiries[_delegator][expire_time] = expiries - 1


@internal
Expand Down Expand Up @@ -553,25 +555,6 @@ def burn(_token_id: uint256):
self._burn(_token_id)


#@ if mode == "test":
@external
def _mint_for_testing(_to: address, _token_id: uint256):
self._mint(_to, _token_id)


@external
def _burn_for_testing(_token_id: uint256):
self._burn(_token_id)


@view
@external
def uint_to_string(_value: uint256) -> String[78]:
return self._uint_to_string(_value)

#@ endif


@external
def create_boost(
_delegator: address,
Expand Down Expand Up @@ -614,7 +597,7 @@ def create_boost(
assert _cancel_time <= expire_time # dev: cancel time is after expiry

assert expire_time >= block.timestamp + WEEK # dev: boost duration must be atleast WEEK
assert expire_time <= VotingEscrow(self.veOcean).locked__end(_delegator) # dev: boost expiration is past voting escrow lock expiry
assert expire_time <= VotingEscrow(VOTING_ESCROW).locked__end(_delegator) # dev: boost expiration is past voting escrow lock expiry
assert _id < 2 ** 96 # dev: id out of bounds

# [delegator address 160][cancel_time uint40][id uint56]
Expand All @@ -630,7 +613,7 @@ def create_boost(
# delegated boost will be positive, if any of circulating boosts are negative
# we have already reverted
delegated_boost: int256 = point.slope * time + point.bias
y: int256 = _percentage * (VotingEscrow(self.veOcean).balanceOf(_delegator) - delegated_boost) / MAX_PCT
y: int256 = _percentage * (VotingEscrow(VOTING_ESCROW).balanceOf(_delegator) - delegated_boost) / MAX_PCT
assert y > 0 # dev: no boost

point = self._calc_bias_slope(time, y, convert(expire_time, int256))
Expand Down Expand Up @@ -679,7 +662,7 @@ def extend_boost(_token_id: uint256, _percentage: int256, _expire_time: uint256,

assert _cancel_time <= expire_time # dev: cancel time is after expiry
assert expire_time >= block.timestamp + WEEK # dev: boost duration must be atleast one day
assert expire_time <= VotingEscrow(self.veOcean).locked__end(delegator) # dev: boost expiration is past voting escrow lock expiry
assert expire_time <= VotingEscrow(VOTING_ESCROW).locked__end(delegator) # dev: boost expiration is past voting escrow lock expiry

point: Point = self._deconstruct_bias_slope(token.data)

Expand Down Expand Up @@ -710,7 +693,7 @@ def extend_boost(_token_id: uint256, _percentage: int256, _expire_time: uint256,

# verify delegated boost isn't negative, else it'll inflate out veOCEAN balance
delegated_boost: int256 = point.slope * time + point.bias
y: int256 = _percentage * (VotingEscrow(self.veOcean).balanceOf(delegator) - delegated_boost) / MAX_PCT
y: int256 = _percentage * (VotingEscrow(VOTING_ESCROW).balanceOf(delegator) - delegated_boost) / MAX_PCT
# a delegator can snipe the exact moment a token expires and create a boost
# with 10_000 or some percentage of their boost, which is perfectly fine.
# this check is here so the user can't extend a boost unless they actually
Expand Down Expand Up @@ -817,7 +800,7 @@ def adjusted_balance_of(_account: address) -> uint256:
# value
return 0

adjusted_balance: int256 = VotingEscrow(self.veOcean).balanceOf(_account)
adjusted_balance: int256 = VotingEscrow(VOTING_ESCROW).balanceOf(_account)

boost: Boost = self.boost[_account]
time: int256 = convert(block.timestamp, int256)
Expand Down Expand Up @@ -948,7 +931,7 @@ def calc_boost_bias_slope(
assert _percentage <= MAX_PCT # dev: percentage must be less than or equal to 100%
assert _expire_time > time + WEEK # dev: Invalid min expiry time

lock_expiry: int256 = convert(VotingEscrow(self.veOcean).locked__end(_delegator), int256)
lock_expiry: int256 = convert(VotingEscrow(VOTING_ESCROW).locked__end(_delegator), int256)
assert _expire_time <= lock_expiry

ddata: uint256 = self.boost[_delegator].delegated
Expand All @@ -963,7 +946,7 @@ def calc_boost_bias_slope(
delegated_boost: int256 = dpoint.slope * time + dpoint.bias
assert delegated_boost >= 0 # dev: outstanding negative boosts

y: int256 = _percentage * (VotingEscrow(self.veOcean).balanceOf(_delegator) - delegated_boost) / MAX_PCT
y: int256 = _percentage * (VotingEscrow(VOTING_ESCROW).balanceOf(_delegator) - delegated_boost) / MAX_PCT
assert y > 0 # dev: no boost

slope: int256 = -y / (_expire_time - time)
Expand Down Expand Up @@ -1009,4 +992,4 @@ def accept_transfer_ownership():
@external
def set_base_uri(_base_uri: String[128]):
assert msg.sender == self.admin
self.base_uri = _base_uri
self.base_uri = _base_uri
4 changes: 2 additions & 2 deletions contracts/ve/veDelegationProxy.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @version 0.3.1
# @version 0.2.15
"""
@title Voting Escrow Delegation Proxy
@author Curve Finance
Expand Down Expand Up @@ -114,4 +114,4 @@ def apply_set_admins():
self.ownership_admin = _o_admin
self.emergency_admin = _e_admin

log ApplyAdmins(_o_admin, _e_admin)
log ApplyAdmins(_o_admin, _e_admin)
13 changes: 2 additions & 11 deletions contracts/ve/veFeeDistributor.vy
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ interface VotingEscrow:
def user_point_history(addr: address, loc: uint256) -> Point: view
def point_history(loc: uint256) -> Point: view
def checkpoint(): nonpayable
def locked__end(_addr:address) -> uint256: view
def deposit_for(_addr: address, _value: uint256): nonpayable


event CommitAdmin:
Expand Down Expand Up @@ -323,15 +321,8 @@ def claim(_addr: address = msg.sender) -> uint256:

amount: uint256 = self._claim(_addr, self.voting_escrow, last_token_time)
if amount != 0:
ve: address = self.voting_escrow
token: address = self.token

if VotingEscrow(ve).locked__end(_addr) < block.timestamp:
assert ERC20(token).transfer(_addr, amount)
else:
assert ERC20(token).approve(self.voting_escrow, amount)
VotingEscrow(ve).deposit_for(_addr, amount)

assert ERC20(token).transfer(_addr, amount)
self.token_last_balance -= amount

return amount
Expand Down Expand Up @@ -472,4 +463,4 @@ def recover_balance(_coin: address) -> bool:
if len(response) != 0:
assert convert(response, bool)

return True
return True
17 changes: 8 additions & 9 deletions contracts/ve/veOCEAN.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @version 0.3.1
# @version 0.2.4
"""
@title Voting Escrow
@author Curve Finance
Expand Down Expand Up @@ -254,7 +254,6 @@ def _checkpoint(addr: address, old_locked: LockedBalance, new_locked: LockedBala
u_new.slope = new_locked.amount / MAXTIME
u_new.bias = u_new.slope * convert(new_locked.end - block.timestamp, int128)


# Read values of scheduled changes in the slope
# old_locked.end can be in the past and in the future
# new_locked.end can ONLY by in the FUTURE unless everything expired: than zeros
Expand Down Expand Up @@ -349,7 +348,7 @@ def _checkpoint(addr: address, old_locked: LockedBalance, new_locked: LockedBala


@internal
def _deposit_for(_addr: address, _value: uint256, unlock_time: uint256, locked_balance: LockedBalance, type: int128, _payer: address):
def _deposit_for(_addr: address, _value: uint256, unlock_time: uint256, locked_balance: LockedBalance, type: int128):
"""
@notice Deposit and lock tokens for a user
@param _addr User's wallet address
Expand All @@ -375,7 +374,7 @@ def _deposit_for(_addr: address, _value: uint256, unlock_time: uint256, locked_b
self._checkpoint(_addr, old_locked, _locked)

if _value != 0:
assert ERC20(self.token).transferFrom(_payer, self, _value)
assert ERC20(self.token).transferFrom(_addr, self, _value)

log Deposit(_addr, _value, _locked.end, type, block.timestamp)
log Supply(supply_before, supply_before + _value)
Expand Down Expand Up @@ -405,7 +404,7 @@ def deposit_for(_addr: address, _value: uint256):
assert _locked.amount > 0, "No existing lock found"
assert _locked.end > block.timestamp, "Cannot add to expired lock. Withdraw"

self._deposit_for(_addr, _value, 0, self.locked[_addr], DEPOSIT_FOR_TYPE, msg.sender)
self._deposit_for(_addr, _value, 0, self.locked[_addr], DEPOSIT_FOR_TYPE)


@external
Expand All @@ -425,7 +424,7 @@ def create_lock(_value: uint256, _unlock_time: uint256):
assert unlock_time > block.timestamp, "Can only lock until time in the future"
assert unlock_time <= block.timestamp + MAXTIME, "Voting lock can be 4 years max"

self._deposit_for(msg.sender, _value, unlock_time, _locked, CREATE_LOCK_TYPE, msg.sender)
self._deposit_for(msg.sender, _value, unlock_time, _locked, CREATE_LOCK_TYPE)


@external
Expand All @@ -443,7 +442,7 @@ def increase_amount(_value: uint256):
assert _locked.amount > 0, "No existing lock found"
assert _locked.end > block.timestamp, "Cannot add to expired lock. Withdraw"

self._deposit_for(msg.sender, _value, 0, _locked, INCREASE_LOCK_AMOUNT, msg.sender)
self._deposit_for(msg.sender, _value, 0, _locked, INCREASE_LOCK_AMOUNT)


@external
Expand All @@ -462,7 +461,7 @@ def increase_unlock_time(_unlock_time: uint256):
assert unlock_time > _locked.end, "Can only increase lock duration"
assert unlock_time <= block.timestamp + MAXTIME, "Voting lock can be 4 years max"

self._deposit_for(msg.sender, 0, unlock_time, _locked, INCREASE_UNLOCK_TIME, msg.sender)
self._deposit_for(msg.sender, 0, unlock_time, _locked, INCREASE_UNLOCK_TIME)


@external
Expand Down Expand Up @@ -669,4 +668,4 @@ def changeController(_newController: address):
@dev Dummy method required for Aragon compatibility
"""
assert msg.sender == self.controller
self.controller = _newController
self.controller = _newController
2 changes: 1 addition & 1 deletion hardhat.config.barge.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
overrides: {},
},
vyper: {
compilers: [{ version: "0.3.1" }, { version: "0.2.7" }],
compilers: [{ version: "0.3.1" }, { version: "0.2.15" }, { version: "0.2.7" }, { version: "0.2.4" }],
},
networks: {
ganache: {
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
overrides: {},
},
vyper: {
compilers: [{ version: "0.3.1" }, { version: "0.2.7" }],
compilers: [{ version: "0.3.1" }, { version: "0.2.15" }, { version: "0.2.7" }, { version: "0.2.4" }],
},
networks: {
hardhat: {
Expand Down