Example #1
0
def test4_takeStep():
    class DummyTollAgent:
        def __init__(self):
            self.USD = 3.0

        def receiveUSD(self, USD):
            self.USD += USD

    class DummyKpis:
        def mktsRNDToSalesRatio(self):
            return 0.0

    class DummySS:
        def __init__(self):
            self.time_step = S_PER_DAY

        def annualMktsGrowthRate(self, dummy_ratio):
            return 0.25

    class DummySimState:
        def __init__(self):
            self.kpis, self.ss = DummyKpis(), DummySS()
            self._toll_agent = DummyTollAgent()

        def marketplacePercentTollToOcean(self) -> float:
            return 0.05

        def getAgent(self, name: str):
            assert name == "toll_agent"
            return self._toll_agent

    state = DummySimState()
    a = MarketplacesAgent(name="marketplaces",
                          USD=10.0,
                          OCEAN=20.0,
                          toll_agent_name="toll_agent",
                          n_marketplaces=100.0,
                          revenue_per_marketplace_per_s=2.0,
                          time_step=state.ss.time_step)
    g = _annualToDailyGrowthRate(0.25)

    a.takeStep(state)
    assert a._n_marketplaces == (100.0 * (1.0 + g))
    assert a._revenue_per_marketplace_per_s == (2.0 * (1.0 + g))
    assert a._salesPerTick() == \
        (a._n_marketplaces * a._revenue_per_marketplace_per_s * S_PER_DAY)
    expected_toll = 0.05 * a._salesPerTick()
    assert state._toll_agent.USD == (3.0 + expected_toll)

    a.takeStep(state)
    assert a._n_marketplaces == (100.0 * (1.0 + g) * (1.0 + g))
    assert a._revenue_per_marketplace_per_s == (2.0 * (1.0 + g) * (1.0 + g))

    for i in range(10):
        a.takeStep(state)
    assert pytest.approx(
        a._n_marketplaces) == 100.0 * math.pow(1.0 + g, 1 + 1 + 10)
    assert pytest.approx(a._revenue_per_marketplace_per_s) == \
        2.0*math.pow(1.0+g,1+1+10)
Example #2
0
def test3_growthRatePerTick_025():
    a = MarketplacesAgent("mkts", 0.0, 0.0, "toll", 10.0, 0.1, S_PER_DAY)
    assert a._growthRatePerTick(0.0) == 0.0
    assert a._growthRatePerTick(0.25) == _annualToDailyGrowthRate(0.25)
Example #3
0
def test2_growthRatePerTick_000():
    a = MarketplacesAgent("mkts", 0.0, 0.0, "toll", 10.0, 0.1, S_PER_YEAR)
    assert a._growthRatePerTick(0.0) == 0.0
    assert a._growthRatePerTick(0.25) == 0.25
Example #4
0
def test1_basic():
    a = MarketplacesAgent("mkts", 0.0, 0.0, "toll", 10.0, 0.1, 1)
    assert a.numMarketplaces() == 10.0
    assert a.revenuePerMarketplacePerSecond() == 0.1
Example #5
0
    def __init__(self, ss: SimStrategy.SimStrategy):
        log.debug("init:begin")

        #main
        self.ss = ss
        self.tick = 0

        #used to manage names
        self._next_free_marketplace_number = 0

        #used to add agents
        self._marketplace_tick_previous_add = 0

        #main storage of agents. Fill this below
        self.agents = AgentDict()  #agent_name : Agent instance

        #<<Note many magic numbers below, for simplicity>>
        #note: KPIs class also has some magic number

        #as ecosystem improves, these parameters may change / improve
        self._marketplace_percent_toll_to_ocean = 0.002  #magic number
        self._percent_burn: float = 0.05  #to burning, vs to DAO #magic number

        self._total_OCEAN_minted: float = 0.0
        self._total_OCEAN_burned: float = 0.0
        self._total_OCEAN_burned_USD: float = 0.0

        self._speculation_valuation = 5e6  #in USD #magic number
        self._percent_increase_speculation_valuation_per_s = 0.10 / S_PER_YEAR  # ""

        #Instantiate and connnect agent instances. "Wire up the circuit"
        new_agents: Set[BaseAgent] = set()

        #FIXME: replace MarketplacesAgent with DataecosystemAgent, when ready
        new_agents.add(
            MarketplacesAgent(
                name="marketplaces1",
                USD=0.0,
                OCEAN=0.0,
                toll_agent_name="opc_address",
                n_marketplaces=float(ss.init_n_marketplaces),
                revenue_per_marketplace_per_s=2e3 / S_PER_MONTH,  #magic number
                time_step=self.ss.time_step,
            ))

        new_agents.add(
            RouterAgent(name="opc_address",
                        USD=0.0,
                        OCEAN=0.0,
                        receiving_agents={
                            "ocean_dao": self.percentToOceanDao,
                            "opc_burner": self.percentToBurn
                        }))

        new_agents.add(OCEANBurnerAgent(name="opc_burner", USD=0.0, OCEAN=0.0))

        #func = MinterAgents.ExpFunc(H=4.0)
        func = MinterAgents.RampedExpFunc(
            H=4.0,  #magic number
            T0=0.5,
            T1=1.0,
            T2=1.4,
            T3=3.0,  #""
            M1=0.10,
            M2=0.25,
            M3=0.50)  #""
        new_agents.add(
            MinterAgents.OCEANFuncMinterAgent(
                name="ocean_51",
                receiving_agent_name="ocean_dao",
                total_OCEAN_to_mint=UNMINTED_OCEAN_SUPPLY,
                s_between_mints=S_PER_DAY,
                func=func))

        new_agents.add(
            GrantGivingAgent(
                name="opf_treasury_for_ocean_dao",
                USD=0.0,
                OCEAN=OPF_TREASURY_OCEAN_FOR_OCEAN_DAO,  #magic number
                receiving_agent_name="ocean_dao",
                s_between_grants=S_PER_MONTH,
                n_actions=12 * 3))  #""

        new_agents.add(
            GrantGivingAgent(
                name="opf_treasury_for_opf_mgmt",
                USD=OPF_TREASURY_USD,
                OCEAN=OPF_TREASURY_OCEAN_FOR_OPF_MGMT,  #magic number
                receiving_agent_name="opf_mgmt",
                s_between_grants=S_PER_MONTH,
                n_actions=12 * 3))  #""

        new_agents.add(
            GrantGivingAgent(
                name="bdb_treasury",
                USD=BDB_TREASURY_USD,
                OCEAN=BDB_TREASURY_OCEAN,  #magic number
                receiving_agent_name="bdb_mgmt",
                s_between_grants=S_PER_MONTH,
                n_actions=17))  #""

        new_agents.add(
            RouterAgent(name="ocean_dao",
                        receiving_agents={"opc_workers": funcOne},
                        USD=0.0,
                        OCEAN=0.0))

        new_agents.add(
            RouterAgent(name="opf_mgmt",
                        receiving_agents={"opc_workers": funcOne},
                        USD=0.0,
                        OCEAN=0.0))

        new_agents.add(
            RouterAgent(name="bdb_mgmt",
                        receiving_agents={"bdb_workers": funcOne},
                        USD=0.0,
                        OCEAN=0.0))

        new_agents.add(GrantTakingAgent(name="opc_workers", USD=0.0,
                                        OCEAN=0.0))

        new_agents.add(GrantTakingAgent(name="bdb_workers", USD=0.0,
                                        OCEAN=0.0))

        for agent in new_agents:
            self.agents[agent.name] = agent

        #track certain metrics over time, so that we don't have to load
        self.kpis = Kpis.KPIs(self.ss.time_step)

        log.debug("init: end")
def test4_takeStep():
    class DummyTollAgent:
        def __init__(self):
            self.USD = 3.0

        def receiveUSD(self, USD):
            self.USD += USD

    class DummyKpis:
        def mktsRNDToSalesRatio(self):  # pylint: disable=no-self-use
            return 0.0

    class DummySS:
        def __init__(self):
            self.time_step = S_PER_DAY
            self._percent_consume_sales_for_network = 0.05

        def annualMktsGrowthRate(self, dummy_ratio):  # pylint: disable=no-self-use, unused-argument
            return 0.25

        def networkRevenue(self, consume_sales: float) -> float:
            return self._percent_consume_sales_for_network * consume_sales

    class DummySimState:
        def __init__(self):
            self.kpis, self.ss = DummyKpis(), DummySS()
            self._toll_agent = DummyTollAgent()

        def getAgent(self, name: str):
            assert name == "toll_agent"
            return self._toll_agent

    state = DummySimState()
    a = MarketplacesAgent(
        name="marketplaces",
        USD=10.0,
        OCEAN=20.0,
        toll_agent_name="toll_agent",
        n_marketplaces=100.0,
        sales_per_marketplace_per_s=2.0,
        time_step=state.ss.time_step,
    )
    g = _annualToDailyGrowthRate(0.25)

    a.takeStep(state)
    assert a._n_marketplaces == (100.0 * (1.0 + g))
    assert a._consume_sales_per_marketplace_per_s == (2.0 * (1.0 + g))
    assert a._consumeSalesPerTick() == (
        a._n_marketplaces * a._consume_sales_per_marketplace_per_s * S_PER_DAY)
    expected_toll = 0.05 * a._consumeSalesPerTick()
    assert state._toll_agent.USD == (3.0 + expected_toll)

    a.takeStep(state)
    assert a._n_marketplaces == (100.0 * (1.0 + g) * (1.0 + g))
    assert a._consume_sales_per_marketplace_per_s == (2.0 * (1.0 + g) *
                                                      (1.0 + g))

    for _ in range(10):
        a.takeStep(state)
    assert pytest.approx(
        a._n_marketplaces) == 100.0 * math.pow(1.0 + g, 1 + 1 + 10)
    assert pytest.approx(
        a._consume_sales_per_marketplace_per_s) == 2.0 * math.pow(
            1.0 + g, 1 + 1 + 10)
Example #7
0
    def __init__(self, ss=None):
        # initialize self.tick, ss, agents, kpis
        super().__init__(ss)

        # now, fill in actual values for ss, agents, kpis
        if self.ss is None:
            self.ss = SimStrategy()
        ss = self.ss  # for convenience as we go forward

        # used to manage names
        self._next_free_marketplace_number = 0

        # used to add agents
        self._marketplace_tick_previous_add = 0

        # as ecosystem improves, these parameters may change
        self._total_OCEAN_minted: float = 0.0
        self._total_OCEAN_burned: float = 0.0
        self._total_OCEAN_burned_USD: float = 0.0
        self._speculation_valuation = ss._init_speculation_valuation

        # Instantiate and connnect agent instances. "Wire up the circuit"
        new_agents: Set[AgentBase.AgentBase] = set()

        # Note: could replace MarketplacesAgent with DataecosystemAgent, for a
        # higher-fidelity simulation using EVM agents
        new_agents.add(
            MarketplacesAgent(
                name="marketplaces1",
                USD=0.0,
                OCEAN=0.0,
                toll_agent_name="opc_address",
                n_marketplaces=float(ss.init_n_marketplaces),
                sales_per_marketplace_per_s=20e3 / S_PER_MONTH,  # magic number
                time_step=self.ss.time_step,
            )
        )

        new_agents.add(
            RouterAgent(
                name="opc_address",
                USD=0.0,
                OCEAN=0.0,
                receiving_agents={
                    "ocean_dao": self.ss.percentToOceanDao,
                    "opc_burner": self.ss.percentToBurn,
                },
            )
        )

        new_agents.add(OCEANBurnerAgent(name="opc_burner", USD=0.0, OCEAN=0.0))

        # func = MinterAgents.ExpFunc(H=4.0)
        func = MinterAgents.RampedExpFunc(
            H=4.0, T0=0.5, T1=1.0, T2=1.4, T3=3.0, M1=0.10, M2=0.25, M3=0.50
        )
        new_agents.add(
            MinterAgents.OCEANFuncMinterAgent(
                name="ocean_51",
                receiving_agent_name="ocean_dao",
                total_OCEAN_to_mint=ss.UNMINTED_OCEAN_SUPPLY,
                s_between_mints=S_PER_DAY,
                func=func,
            )
        )

        new_agents.add(
            GrantGivingAgent(
                name="opf_treasury_for_ocean_dao",
                USD=0.0,
                OCEAN=ss.OPF_TREASURY_OCEAN_FOR_OCEAN_DAO,
                receiving_agent_name="ocean_dao",
                s_between_grants=S_PER_MONTH,
                n_actions=12 * 3,
            )
        )

        new_agents.add(
            GrantGivingAgent(
                name="opf_treasury_for_opf_mgmt",
                USD=ss.OPF_TREASURY_USD,
                OCEAN=ss.OPF_TREASURY_OCEAN_FOR_OPF_MGMT,
                receiving_agent_name="opf_mgmt",
                s_between_grants=S_PER_MONTH,
                n_actions=12 * 3,
            )
        )

        new_agents.add(
            GrantGivingAgent(
                name="bdb_treasury",
                USD=ss.BDB_TREASURY_USD,
                OCEAN=ss.BDB_TREASURY_OCEAN,
                receiving_agent_name="bdb_mgmt",
                s_between_grants=S_PER_MONTH,
                n_actions=17,
            )
        )

        new_agents.add(
            RouterAgent(
                name="ocean_dao",
                receiving_agents={"opc_workers": funcOne},
                USD=0.0,
                OCEAN=0.0,
            )
        )

        new_agents.add(
            RouterAgent(
                name="opf_mgmt",
                receiving_agents={"opc_workers": funcOne},
                USD=0.0,
                OCEAN=0.0,
            )
        )

        new_agents.add(
            RouterAgent(
                name="bdb_mgmt",
                receiving_agents={"bdb_workers": funcOne},
                USD=0.0,
                OCEAN=0.0,
            )
        )

        new_agents.add(GrantTakingAgent(name="opc_workers", USD=0.0, OCEAN=0.0))

        new_agents.add(GrantTakingAgent(name="bdb_workers", USD=0.0, OCEAN=0.0))

        for agent in new_agents:
            self.agents[agent.name] = agent

        # track certain metrics over time, so that we don't have to load
        self.kpis = KPIs(self.ss)