예제 #1
0
 def unstakeOCEAN(self, BPT_unstake: float, pool: bpool.BPool):
     pool.exitswapPoolAmountIn(
         tokenOut_address=globaltokens.OCEAN_address(),
         poolAmountIn_base=toBase18(BPT_unstake),
         minAmountOut_base=toBase18(0.0),
         from_wallet=self._web3wallet)
     self.resetCachedInfo()
예제 #2
0
    def _buy(self, state):
        """Buy, and consume dataset"""
        OCEAN_address = globaltokens.OCEAN_address()
        OCEAN = self.OCEAN()
        OCEAN_base = self._wallet._OCEAN_base()
        DT_amount_out_base = toBase18(1.0)

        cand_pool_agents = self._candPoolAgents()
        assert cand_pool_agents
        random.shuffle(cand_pool_agents)

        #FIXME: there will be times when slippage is sufficiently high that
        # the data consumer won't be able to successfully buy the DT.
        # In that case, should pick the second choice in cand_pool_agents. Etc.
        pool_agent = cand_pool_agents[0]
        pool = pool_agent.pool
        DT_address = pool_agent.datatoken_address

        pool.swapExactAmountOut(tokenIn_address=OCEAN_address,
                                maxAmountIn_base=OCEAN_base,
                                tokenOut_address=DT_address,
                                tokenAmountOut_base=DT_amount_out_base,
                                maxPrice_base=constants.HUGEINT,
                                from_wallet=self._wallet._web3wallet)

        self._wallet.resetCachedInfo()
예제 #3
0
    def _candPoolAgents(self, state):
        """Pools that this agent can afford to buy 1.0 datatokens from,
        at least based on a first approximation. 
        """
        OCEAN_address = globaltokens.OCEAN_address()
        OCEAN = self.OCEAN()
        all_pool_agents = state.agents.filterToPool().values()
        cand_pool_agents = []
        for pool_agent in all_pool_agents:
            pool = pool_agent.pool
            DT_address = pool_agent.datatoken_address

            pool_DT_balance_base = pool.getBalance_base(DT_address)
            pool_OCEAN_balance_base = pool.getBalance_base(OCEAN_address)
            pool_DT_weight_base = pool.getDenormalizedWeight_base(DT_address)
            pool_OCEAN_weight_base = pool.getDenormalizedWeight_base(
                OCEAN_address)
            pool_swapFee_base = pool.getSwapFee_base()

            DT_amount_out_base = toBase18(1.0)

            spotPriceBefore_base = pool.getSpotPrice_base(
                tokenIn_address=OCEAN_address, tokenOut_address=DT_address)
            OCEANamountIn_base = pool.calcInGivenOut_base(
                tokenBalanceIn_base=pool_OCEAN_balance_base,
                tokenWeightIn_base=pool_OCEAN_weight_base,
                tokenBalanceOut_base=pool_DT_balance_base,
                tokenWeightOut_base=pool_DT_weight_base,
                tokenAmountOut_base=DT_amount_out_base,
                swapFee_base=pool_swapFee_base)

            if OCEANamountIn_base < OCEAN:
                cand_pool_agents.append(pool)

        return cand_pool_agents
예제 #4
0
def test_conftest(alice_info):
    #are alice_pool's datatokens the same as alice_DT?
    #Note: we use alice_info here in order to get addresses to line up;
    # if we had two separate args then we'd need to resort to caching
    alice_pool, alice_DT = alice_info.pool, alice_info.DT
    OCEAN_address = globaltokens.OCEAN_address()
    alice_pool_DT_address = [
        a for a in alice_pool.getFinalTokens() if a != OCEAN_address
    ][0]
    assert alice_pool_DT_address == alice_DT.address
예제 #5
0
 def stakeOCEAN(self, OCEAN_stake: float, pool: bpool.BPool):
     OCEAN = globaltokens.OCEANtoken()
     OCEAN.approve(pool.address,
                   toBase18(OCEAN_stake),
                   from_wallet=self._web3wallet)
     pool.joinswapExternAmountIn(
         tokenIn_address=globaltokens.OCEAN_address(),
         tokenAmountIn_base=toBase18(OCEAN_stake),
         minPoolAmountOut_base=toBase18(0.0),
         from_wallet=self._web3wallet)
     self.resetCachedInfo()
예제 #6
0
def test_conftest(alice_pool:bpool.BPool, alice_DT:datatoken.Datatoken):
    #are alice_pool's datatokens the same as alice_DT?
    OCEAN_address = globaltokens.OCEAN_address()
    alice_pool_DT_address = [a for a in alice_pool.getFinalTokens()
                             if a != OCEAN_address][0]
    assert alice_pool_DT_address == alice_DT.address