def setUp(self): self.params = { "debug": True, "probability_func": new_probability_func(seed=None), "exponential_func": new_exponential_func(seed=None), "gamma_func": new_gamma_func(seed=None), "random_number_func": new_random_number_func(seed=None) } vesting_participants = [ TokenBatch(1000, 1000, vesting_options=VestingOptions(10, 30)) for _ in range(2) ] nonvesting_participants = [ TokenBatch(0, 1000, vesting_options=VestingOptions(10, 30)) for _ in range(2) ] self.network = bootstrap_network( vesting_participants + nonvesting_participants, 1, 3000, 4e6, 0.2, self.params["probability_func"], self.params["random_number_func"], self.params["gamma_func"], self.params["exponential_func"]) self.commons = Commons(1000, 1000) self.network, _ = add_proposal(self.network, Proposal(100, 1), self.params["random_number_func"]) self.default_state = { "network": self.network, "commons": self.commons, "funding_pool": 1000, "token_supply": 1000 }
def gen_new_participant(network, new_participant_tokens): i = len([node for node in network.nodes]) network.add_node(i) network.nodes[i]['type'] = "participant" s_rv = np.random.rand() network.nodes[i]['sentiment'] = s_rv network.nodes[i]['holdings_vesting'] = None network.nodes[i]['holdings_nonvesting'] = TokenBatch( new_participant_tokens, 5, 5) # Connect this new participant to existing proposals. for j in get_nodes_by_type(network, 'proposal'): network.add_edge(i, j) rv = np.random.rand() a_rv = 1 - 4 * (1 - rv) * rv #polarized distribution network.edges[(i, j)]['affinity'] = a_rv network.edges[( i, j )]['tokens'] = a_rv * network.nodes[i]['holdings_nonvesting'].value network.edges[(i, j)]['conviction'] = 0 network.edges[(i, j)]['type'] = 'support' return network
def setUp(self): self.params = { "debug": False, "days_to_80p_of_max_voting_weight": 10, "probability_func": new_probability_func(seed=None), "exponential_func": new_exponential_func(seed=None), "gamma_func": new_gamma_func(seed=None), "random_number_func": new_random_number_func(seed=None) } self.network = bootstrap_network([ TokenBatch(1000, 0, vesting_options=VestingOptions(10, 30)) for _ in range(4) ], 1, 3000, 4e6, 0.2, self.params["probability_func"], self.params["random_number_func"], self.params["gamma_func"], self.params["exponential_func"]) self.network, _ = add_proposal(self.network, Proposal(100, 1), self.params["random_number_func"]) """ For proper testing, we need to make sure the Proposals are CANDIDATE and ensure Proposal-Participant affinities are not some random value """ self.network.nodes[4]["item"].status = ProposalStatus.CANDIDATE self.network.nodes[5]["item"].status = ProposalStatus.CANDIDATE support_edges = get_edges_by_type(self.network, "support") for u, v in support_edges: self.network[u][v]["support"] = self.network[u][v][ "support"]._replace(affinity=0.9)
def test_stake_across_all_supported_proposals(self): """ Test that the rebalancing code works as intended. Given 4 Proposals which the Participant has affinity 0.9, 0.9, 0.8, 0.6 to, we should expect an allocation of 0.28125, 0.28125, 02.5, 0.1872 respectively. The calculation should also include vesting and nonvesting TokenBatches. """ supported_proposals = [ (0.9, 0), (0.9, 1), (0.8, 2), (0.6, 3), ] self.p.holdings = TokenBatch(500, 500) ans = self.p.stake_across_all_supported_proposals(supported_proposals) reference = { 0: 281.25000000000006, 1: 281.25000000000006, 2: 250.00000000000006, 3: 187.5, } self.assertEqual(ans, reference)
def su_add_to_network(params, step, sL, s, _input): network = s["network"] if _input["new_participant"]: i = len(network.nodes) network.add_node(i, item=Participant( holdings_vesting=None, holdings_nonvesting=TokenBatch(_input["new_participant_tokens"]))) network = setup_influence_edges_single(network, i) network = setup_support_edges(network, i) return "network", network
def setUp(self): self.commons = Commons(10000, 1000) self.sentiment = 0.5 self.network = bootstrap_network([ TokenBatch(1000, 0, vesting_options=VestingOptions(10, 30)) for _ in range(4) ], 1, 3000, 4e6, 0.2) self.params = {"debug": False}
def setUp(self): self.network = bootstrap_network( [TokenBatch(1000, VestingOptions(10, 30)) for _ in range(4)], 1, 3000, 4e6) self.network, _ = add_proposal(self.network, Proposal(100, 1)) self.network.nodes[4]["item"].status = ProposalStatus.ACTIVE self.network.nodes[5]["item"].status = ProposalStatus.ACTIVE
def create_network(participants: List[TokenBatch]) -> nx.DiGraph: """ Creates a new DiGraph with Participants corresponding to the input TokenBatches. """ network = nx.DiGraph() for i, p in enumerate(participants): p_instance = Participant(holdings_vesting=p, holdings_nonvesting=TokenBatch(0)) network.add_node(i, item=p_instance) return network
def su_add_to_network(params, step, sL, s, _input, **kwargs): network = s["network"] if _input["new_participant"]: network, i = add_participant( network, Participant(TokenBatch(0, _input["new_participant_tokens"]))) if params.get("debug"): print( "GenerateNewParticipant: A new Participant {} invested {}DAI for {} tokens" .format(i, _input['new_participant_investment'], _input['new_participant_tokens'])) return "network", network
def test_bootstrap_network(self): """ Tests that the network was created and that the subcomponents work too. """ token_batches = [TokenBatch(1000, VestingOptions(10, 30)) for _ in range(4)] network = bootstrap_network(token_batches, 1, 3000, 4e6, 0.2) edges = list(network.edges(data="type")) _, _, edge_types = list(zip(*edges)) self.assertEqual(edge_types.count('support'), 4) self.assertEqual(len(get_participants(network)), 4) self.assertEqual(len(get_proposals(network)), 1)
def setUp(self): self.network = bootstrap_network([ TokenBatch(1000, 0, vesting_options=VestingOptions(10, 30)) for _ in range(4) ], 1, 3000, 4e6, 0.2) self.network, _ = add_proposal(self.network, Proposal(100, 1)) self.network.nodes[4]["item"].status = ProposalStatus.CANDIDATE self.network.nodes[5]["item"].status = ProposalStatus.CANDIDATE self.params = { "max_proposal_request": 0.2, "alpha_days_to_80p_of_max_voting_weight": 10 }
def test_add_participant(self): """ This test ensures that the Participant was added and that setup_influence_edges and setup_support_edges was executed for that particular node. """ n1, j = add_participant(self.network, Participant(TokenBatch(0, 0))) self.assertIsInstance(n1.nodes[j]["item"], Participant) self.assertEqual(len(n1.edges), 5) for u, v, t in n1.edges(data="type"): self.assertEqual(u, 10) self.assertIn(v, [1, 3, 5, 7, 9]) self.assertEqual(t, "support")
def setUp(self): self.network = bootstrap_network([ TokenBatch(1000, 1000, vesting_options=VestingOptions(10, 30)) for _ in range(4) ], 1, 3000, 4e6, 0.2) self.commons = Commons(1000, 1000) self.network, _ = add_proposal(self.network, Proposal(100, 1)) self.params = {"debug": True} self.default_state = { "network": self.network, "commons": self.commons, "funding_pool": 1000, "token_supply": 1000 }
def test_stake_across_all_supported_proposals(self): """ Test that the rebalancing code works as intended. Given 4 Proposals which the Participant has affinity 0.9, 0.9, 0.8, 0.6 to, we should expect an allocation of 0.28125, 0.28125, 02.5, 0.1872 respectively. The calculation should also include vesting and nonvesting TokenBatches. """ p = [Proposal(0, 0) for _ in range(4)] p[0].uuid = uuid.UUID(int=179821351946450230734044638685583215499) p[1].uuid = uuid.UUID(int=215071290061070589371009813111193284959) p[2].uuid = uuid.UUID(int=20468923874830131214536379780280861909) p[3].uuid = uuid.UUID(int=268821512376988039567204465930241984322) supported_proposals = [ (0.9, p[0]), (0.9, p[1]), (0.8, p[2]), (0.6, p[3]), ] self.p.holdings_vesting = TokenBatch(500) self.p.holdings_nonvesting = TokenBatch(500) ans = self.p.stake_across_all_supported_proposals(supported_proposals) print(ans) self.assertEqual( ans[uuid.UUID(int=179821351946450230734044638685583215499)], 281.25000000000006) self.assertEqual( ans[uuid.UUID(int=215071290061070589371009813111193284959)], 281.25000000000006) self.assertEqual( ans[uuid.UUID(int=20468923874830131214536379780280861909)], 250.00000000000006) self.assertEqual( ans[uuid.UUID(int=268821512376988039567204465930241984322)], 187.5)
def setUp(self): self.params = { "debug": True, "probability_func": new_probability_func(seed=None), "exponential_func": new_exponential_func(seed=None), "gamma_func": new_gamma_func(seed=None), "random_number_func": new_random_number_func(seed=None) } self.network = bootstrap_network([ TokenBatch(1000, 0, vesting_options=VestingOptions(10, 30)) for _ in range(4) ], 1, 3000, 4e6, 0.2, self.params["probability_func"], self.params["random_number_func"], self.params["gamma_func"], self.params["exponential_func"])
def su_add_to_network(params, step, sL, s, _input, **kwargs): network = s["network"] if _input["new_participant"]: i = len(network.nodes) network.add_node(i, item=Participant( TokenBatch(0, _input["new_participant_tokens"]))) network = setup_influence_edges_single(network, i) network = setup_support_edges(network, i) if params[0].get("debug"): print( "GenerateNewParticipant: A new Participant {} invested {}DAI for {} tokens" .format(i, _input['new_participant_investment'], _input['new_participant_tokens'])) return "network", network
def setUp(self): self.network = nx.DiGraph() self.params = { "probability_func": new_probability_func(seed=None), "exponential_func": new_exponential_func(seed=None), "gamma_func": new_gamma_func(seed=None), "random_number_func": new_random_number_func(seed=None) } for i in range(0, 10, 2): self.network.add_node(i, item=Participant( TokenBatch(0, 0), self.params["probability_func"], self.params["random_number_func"])) self.network.add_node(i + 1, item=Proposal(10, 5))
def su_add_to_network(params, step, sL, s, _input, **kwargs): network = s["network"] probability_func = params["probability_func"] exponential_func = params["exponential_func"] random_number_func = params["random_number_func"] for i in _input: ans = _input[i] if ans != 0: network, i = add_participant(network, Participant(TokenBatch( 0, ans["new_participant_tokens"]), probability_func, random_number_func), exponential_func, random_number_func) if params.get("debug"): print("GenerateNewParticipant: A new Participant {} invested {}DAI for {} tokens".format( i, ans['new_participant_investment'], ans['new_participant_tokens'])) return "network", network
def setUp(self): self.network = bootstrap_network([ TokenBatch(1000, 0, vesting_options=VestingOptions(10, 30)) for _ in range(4) ], 1, 3000, 4e6, 0.2) self.network, _ = add_proposal(self.network, Proposal(100, 1)) self.params = {"debug": False, "days_to_80p_of_max_voting_weight": 10} """ For proper testing, we need to make sure the Proposals are CANDIDATE and ensure Proposal-Participant affinities are not some random value """ self.network.nodes[4]["item"].status = ProposalStatus.CANDIDATE self.network.nodes[5]["item"].status = ProposalStatus.CANDIDATE support_edges = get_edges_by_type(self.network, "support") for u, v in support_edges: self.network[u][v]["affinity"] = 0.9
def setUp(self): self.params = { "probability_func": new_probability_func(seed=None), "exponential_func": new_exponential_func(seed=None), "gamma_func": new_gamma_func(seed=None), "random_number_func": new_random_number_func(seed=None) } self.network = bootstrap_network([ TokenBatch(1000, 0, vesting_options=VestingOptions(10, 30)) for _ in range(4) ], 1, 3000, 4e6, 0.2, self.params["probability_func"], self.params["random_number_func"], self.params["gamma_func"], self.params["exponential_func"]) self.network, _ = add_proposal(self.network, Proposal(100, 1), self.params["random_number_func"]) self.network.nodes[4]["item"].status = ProposalStatus.ACTIVE self.network.nodes[5]["item"].status = ProposalStatus.ACTIVE
def test_p_participant_votes_on_proposal_according_to_affinity_vesting_nonvesting( self): """ Ensure that when a Participant with vesting and nonvesting tokens votes on 2 Proposals of equal affinity, all of his tokens will be split 50-50 between them. """ participants = get_participants(self.network) for _, participant in participants: participant.holdings = TokenBatch(1000, 1000) with patch("entities.probability") as p: p.return_value = True ans = ParticipantVoting.p_participant_votes_on_proposal_according_to_affinity( self.params, 0, 0, { "network": copy.copy(self.network), "funding_pool": 1000, "token_supply": 1000 }) reference = { 'participants_stake_on_proposals': { 0: { 4: 1000.0, 5: 1000.0 }, 1: { 4: 1000.0, 5: 1000.0 }, 2: { 4: 1000.0, 5: 1000.0 }, 3: { 4: 1000.0, 5: 1000.0 } } } self.assertEqual(ans, reference)
def setUp(self): self.params = { "max_proposal_request": 0.2, "alpha_days_to_80p_of_max_voting_weight": 10, "probability_func": new_probability_func(seed=None), "exponential_func": new_exponential_func(seed=None), "gamma_func": new_gamma_func(seed=None), "random_number_func": new_random_number_func(seed=None) } self.commons = Commons(1000, 1000) self.network = bootstrap_network([ TokenBatch(1000, 0, vesting_options=VestingOptions(10, 30)) for _ in range(4) ], 1, 3000, 4e6, 0.2, self.params["probability_func"], self.params["random_number_func"], self.params["gamma_func"], self.params["exponential_func"]) self.network, _ = add_proposal(self.network, Proposal(100, 1), self.params["random_number_func"]) self.network.nodes[4]["item"].status = ProposalStatus.CANDIDATE self.network.nodes[5]["item"].status = ProposalStatus.CANDIDATE
def setUp(self): self.network = bootstrap_network([ TokenBatch(1000, 0, vesting_options=VestingOptions(10, 30)) for _ in range(4) ], 1, 3000, 4e6, 0.2) self.params = {"max_proposal_request": 0.2}
def setUp(self): self.p = Participant(TokenBatch(100, 100))
def setUp(self): self.commons = Commons(10000, 1000) self.sentiment = 0.5 self.network = bootstrap_network( [TokenBatch(1000, VestingOptions(10, 30)) for _ in range(4)], 1, 3000, 4e6)
def setUp(self): self.network = bootstrap_network( [TokenBatch(1000, VestingOptions(10, 30)) for _ in range(4)], 1, 3000, 4e6)
def setUp(self): self.params = { "probability_func": new_probability_func(seed=None), "random_number_func": new_random_number_func(seed=None) } self.p = Participant(TokenBatch(100, 100), self.params["probability_func"], self.params["random_number_func"])
def setUp(self): self.network = nx.DiGraph() for i in range(0, 10, 2): self.network.add_node(i, item=Participant(TokenBatch(0, 0))) self.network.add_node(i + 1, item=Proposal(10, 5))