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

unbonding v2 #105

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 7 additions & 4 deletions src/xian/tools/genesis/contracts/elect_members.s.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ def register():

@export
def unregister():
mns = election_house.current_value_for_policy(controller.get())
mns = election_house.current_value_for_policy(controller.get())["members"]
scheduled_for_removal = election_house.current_value_for_policy(controller.get())["scheduled_for_removal"]
assert candidate_state['registered', ctx.caller], 'Not registered.'

assert ctx.caller not in mns, "Can't unstake if in governance."
assert datetime.now() > scheduled_for_removal.get(ctx.caller), "Can't unstake until unbonding period is over."

currency.transfer(member_cost.get(), ctx.caller)

candidate_state['registered', ctx.caller] = False
candidate_state['votes', ctx.caller] = 0

importlib.import_module(controller.get()).remove_from_scheduled_removal(ctx.caller)


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # VOTE CANDIDATE
@export
Expand Down Expand Up @@ -97,7 +100,7 @@ def pop_top():
@export
def vote_no_confidence(address: str):
# Determine if caller can vote
assert address in election_house.current_value_for_policy(controller.get()), \
assert address in election_house.current_value_for_policy(controller.get())["members"], \
'Cannot vote against a non-committee member'

v = no_confidence_state['last_voted', ctx.caller]
Expand Down Expand Up @@ -156,7 +159,7 @@ def force_removal(address: str):

@export
def relinquish():
assert ctx.caller in election_house.current_value_for_policy(controller.get())
assert ctx.caller in election_house.current_value_for_policy(controller.get())["members"]

r = to_be_relinquished.get()
assert r is None, 'Someone is already trying to relinquish!'
Expand Down
50 changes: 48 additions & 2 deletions src/xian/tools/genesis/contracts/members.s.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
REMOVE_MEMBER = 1
ADD_SEAT = 2
REMOVE_SEAT = 3
CHANGE_MINIMUM = 4
CHANGE_UNBONDING_PERIOD = 5

VOTING_PERIOD = datetime.DAYS * 1

S = Hash()
minimum_nodes = Variable()
candidate_contract = Variable()
unbonding_period = Variable()


@construct
def seed(initial_members: list, minimum: int=1, candidate: str='elect_members'):
S['members'] = initial_members
S['scheduled_for_removal'] = {}
minimum_nodes.set(minimum)
candidate_contract.set(candidate)
unbonding_period.set(datetime.DAYS * 7)

S['yays'] = 0
S['nays'] = 0
Expand All @@ -36,8 +42,30 @@ def quorum_min():

@export
def current_value():
return S['members']
return {"members": S['members'], "scheduled_for_removal": S['scheduled_for_removal']}

@export
def remove_from_scheduled_removal(vk: str):
assert ctx.caller == candidate_contract.get(), 'Not authorized.'
scheduled_for_removal = S['scheduled_for_removal']
assert vk in scheduled_for_removal, 'VK not scheduled for removal.'
scheduled_for_removal.pop(vk)
S['scheduled_for_removal'] = scheduled_for_removal
remove_from_members(vk)

def remove_from_members(vk: str):
members = S['members']
assert vk in members, 'VK not in members.'
members.remove(vk)
S['members'] = members

@export
def i_quit():
assert ctx.caller in S['members'], 'Not a member.'
assert len(S['members']) > minimum_nodes.get(), 'Cannot drop below current quorum.'
scheduled_for_removal = S['scheduled_for_removal']
scheduled_for_removal[ctx.caller] = now + unbonding_period.get()
S['scheduled_for_removal'] = scheduled_for_removal

@export
def vote(vk: str, obj: list):
Expand Down Expand Up @@ -108,6 +136,14 @@ def introduce_motion(position: int, arg: Any):
assert arg in S['members'], 'Member does not exist.'
assert len(S['members']) > minimum_nodes.get(), 'Cannot drop below current quorum.'
S['member_in_question'] = arg
if position == CHANGE_MINIMUM:
assert arg > 0, 'Minimum must be greater than zero.'
assert isinstance(arg, int), 'Minimum must be an integer.'
S['proposed_minimum'] = arg
if position == CHANGE_UNBONDING_PERIOD:
assert arg > 0, 'Unbonding period must be greater than zero.'
assert isinstance(arg, int), 'Unbonding period must be an integer.'
S['proposed_unbonding_period'] = arg

S['current_motion'] = position
S['motion_opened'] = now
Expand Down Expand Up @@ -137,9 +173,19 @@ def pass_current_motion():

# Remove them from the list and pop them from deprecating
if old_mem is not None:
members.remove(old_mem)
scheduled_for_removal = S['scheduled_for_removal']
scheduled_for_removal[old_mem] = now + unbonding_period.get()
S['scheduled_for_removal'] = scheduled_for_removal
member_candidates.pop_last()

elif current_motion == CHANGE_MINIMUM:
minimum_nodes.set(S['proposed_minimum'])
S['proposed_minimum'] = None

elif current_motion == CHANGE_UNBONDING_PERIOD:
unbonding_period.set(datetime.DAYS * S['proposed_unbonding_period'])
S['proposed_unbonding_period'] = None

S['members'] = members


Expand Down