def new_pool_state(timestep, duration): calc_timestep = genesis_state.data[0]['timestep'] pool_amt = allocate_pool(genesis_state, calc_timestep, duration) collected_amt = p_intitiate_monthly_deposits(genesis_state) updateCircle_ = update_circle_state(genesis_state.data[0]['name'], calc_timestep, collected_amt, pool_amt, genesis_state.data[0]['data']) new_block = create_block(updateCircle_) # create block print("Pool amount: GBP" + str(get_total_active_balance(updateCircle_)) + "\n") print(blockchain) return new_block
def s_updatepool(intial_block): state = intial_block.data[0]['data'] duration = state['Duration'] for x in range(0, duration): # collected_amt = p_intitiate_monthly_deposits(genesis_state) ## initiate contributers behaviour collected_amt = 10000 # pool_amt = p_allocate_pool(genesis_state) ## initiate cheaters behaviour pool_amt = 500 ## intiate borrowers behaviour if(pool_amt != 0 and state['Timestep'] > 2): borrowed_amt = agent_borrow_request(state) pool_amt -= borrowed_amt state['Timestep'] += 1 print("Pool amount: GBP" + str(pool_amt) + "\n") new_block = create_block(genesis_state) # create block
# Create an array of `AgentData` objects def get_initial_deposits(n): agent = [ AgentData(secrets.token_bytes(48), pounds_to_eth(300), i, 0, False, 0, False) for i in range(n) ] return agent # creates circle circle_ = initialise_circle_state("Circle C", get_initial_deposits(10)) # create initial block genesis_state = create_block(circle_) print("print gs -> " + str(genesis_state)) # check moneypool balance get_total_active_balance(circle_) # player decision def randomised_agent_contribution(agent, amount): if random.random() < 0.1: # 10% chance player will default agent.defaulted = True return False else: agent.defaulted = False return True
'Honest_Volume': 0, # volume of honest (contributed) activity (GBP) 'Dishonest_Volume': 0, # volume of dishonest (non-contributed) activity (GBP) 'Cheats_Volume': 0, # volume of cheater activity (GBP) 'Contributers_Rating': 0, # total ratings of contributing agent 'Contributers_Cost': 0, # cost incurred by contributers 'Contributers_Reward': 0, # rewards collected by contributers 'Cheaters_Cost': 0, # costs incurred by cheaters 'Cheater_Reward': 0, # rewards (profit) achieved by cheating 'Timestep': 0, 'Agent_Data': get_initial_deposits(max_amount, participants), 'Duration': 10, 'Participants': 10, 'Surplus_Amout': 0 } # create initial block intial_block = create_block(genesis_state) ## approve borrowing based on partcipants history def approve_borrowing(state, agent_no, amount): ## threshold for a vote to be approved threshold = (state['Participants'] * 0.8) participants = state['Agent_Data'] approve = False if(get_monthly_default_count(participants, agent_no) != 0): print("1") message = "Agent borrowing not approved: Has a defaulting record." elif(amount > participants[agent_no].amount): message = "Agent borrowing not approved: Amount requested to high for agent." print("2")