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

disable OMM staking #300

Open
wants to merge 12 commits into
base: development
Choose a base branch
from
1 change: 1 addition & 0 deletions score/ommToken/addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
REWARDS = 'rewards'
LENDING_POOL = 'lendingPool'
oUSDs = "oUSDS"
BOOSTED_OMM = "bOMM"


class Addresses(IconScoreBase):
Expand Down
6 changes: 2 additions & 4 deletions score/ommToken/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ class TokenFallbackInterface(InterfaceScore):
def tokenFallback(self, _from: Address, _value: int, _data: bytes):
pass


class DelegationInterface(InterfaceScore):
class BoostedOmmInterface(InterfaceScore):
@interface
def updateDelegations(self, _delegations: List[PrepDelegationDetails] = None, _user: Address = None):
def getLocked(self, _user: Address):
pass


class RewardDistributionInterface(InterfaceScore):
@interface
def handleAction(self, _userDetails: UserDetails) -> None:
Expand Down
32 changes: 29 additions & 3 deletions score/ommToken/tokens/IRC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ def _require(_condition: bool, _message: str):
@only_lending_pool
@external
def stake(self, _value: int, _user: Address) -> None:
revert(f"{TAG}: Staking no longer supported.")
userBalance = self._balances[_user]
IRC2._require(_value > 0, f'Cannot stake less than zero'f'value to stake {_value}')
IRC2._require(_value >= self._minimum_stake.get(),
Expand Down Expand Up @@ -360,6 +361,7 @@ def stake(self, _value: int, _user: Address) -> None:

@external
def cancelUnstake(self, _value: int):
revert(f"{TAG}: Staking no longer supported. Lock your tokens.")
IRC2._require(_value > 0, f'Cannot cancel negative unstake')

_user = self.msg.sender
Expand Down Expand Up @@ -435,6 +437,33 @@ def unstake(self, _value: int, _user: Address) -> None:
"_user_old_staked_balance": staked_balance
})

@external
def lockStakedOMM(self, _amount: int, _lockPeriod: int):
_user = self.msg.sender
staked_balance = self.staked_balanceOf(_user)
IRC2._require(staked_balance >= _amount, "Cannot lock more than staked.")
boosted_omm_addr = self._addresses[BOOSTED_OMM]
boosted_omm = self.create_interface_score(boosted_omm_addr, BoostedOmmInterface)
locked_balance = boosted_omm.getLocked(_user)

if locked_balance.get('amount') > 0 :
# increaseAmount
depositData = {'method': 'increaseAmount', 'params': {'unlockTime': _lockPeriod}}
_data = json_dumps(depositData).encode('utf-8')
else:
# createLock
depositData = {'method': 'createLock', 'params': {'unlockTime': _lockPeriod}}
_data = json_dumps(depositData).encode('utf-8')

self._staked_balances[_user][Status.STAKED] -= _amount
self._total_staked_balance.set(self._total_staked_balance.get() - _amount)

new_staked_balance = self._staked_balances[_user][Status.STAKED]
if new_staked_balance == 0:
self._removeStaker(_user)

self._transfer(_user, boosted_omm_addr, _amount, _data)

def onStakeChanged(self, params: OnStakeChangedParams):
_user = params['_user']
_new_total_staked_balance = params['_new_total_staked_balance']
Expand All @@ -443,9 +472,6 @@ def onStakeChanged(self, params: OnStakeChangedParams):
_user_old_staked_balance = params['_user_old_staked_balance']

self._total_staked_balance.set(_new_total_staked_balance)
delegation = self.create_interface_score(self._addresses[DELEGATION], DelegationInterface)
delegation.updateDelegations(_user=_user)
self._handleAction(_user, _user_old_staked_balance, _old_total_staked_balance)
_initial_timestamp: int = self._snapshot_started_at.get()
self._create_initial_snapshot(_user, _initial_timestamp, _user_old_staked_balance)
self._createSnapshot(_user, _user_old_staked_balance, _user_new_staked_balance, _new_total_staked_balance)
Expand Down