Exemple #1
0
def test_setSwapFee_fails(alice_wallet, alice_address, bob_wallet,
                          bob_address):
    factory = bfactory.BFactory()
    pool_address = factory.newBPool(alice_wallet)
    pool = bpool.BPool(pool_address)
    with pytest.raises(Exception):
        pool.setSwapFee(toBase18(0.011),
                        from_wallet=bob_wallet)  #not ok, bob isn't controller
    pool.setController(bob_address, from_wallet=alice_wallet)
    pool.setSwapFee(toBase18(0.011), from_wallet=bob_wallet)  #ok now
Exemple #2
0
def _createPool(DT:datatoken.Datatoken, web3_w:web3wallet.Web3Wallet):
    OCEAN = globaltokens.OCEANtoken()
    
    #Create OCEAN-DT pool
    p_address = bfactory.BFactory().newBPool(from_wallet=web3_w)
    pool = bpool.BPool(p_address)

    DT.approve(pool.address, toBase18(_DT_STAKE), from_wallet=web3_w)
    OCEAN.approve(pool.address, toBase18(_OCEAN_STAKE),from_wallet=web3_w)

    pool.bind(DT.address, toBase18(_DT_STAKE),
              toBase18(POOL_WEIGHT_DT), from_wallet=web3_w)
    pool.bind(OCEAN.address, toBase18(_OCEAN_STAKE),
              toBase18(POOL_WEIGHT_OCEAN), from_wallet=web3_w)

    pool.finalize(from_wallet=web3_w)
    
    return pool
    def _createPoolAgent(self, state) -> PoolAgent:
        assert self.OCEAN() > 0.0, "should not call if no OCEAN"
        wallet = self._wallet._web3wallet
        OCEAN = globaltokens.OCEANtoken()

        #name
        pool_i = len(state.agents.filterToPool())
        dt_name = f'DT{pool_i}'
        pool_agent_name = f'pool{pool_i}'

        #new DT
        DT = self._createDatatoken(dt_name, mint_amt=1000.0)  #magic number

        #new pool
        pool_address = bfactory.BFactory().newBPool(from_wallet=wallet)
        pool = bpool.BPool(pool_address)

        #bind tokens & add initial liquidity
        OCEAN_bind_amt = self.OCEAN()  #magic number: use all the OCEAN
        DT_bind_amt = 20.0  #magic number

        DT.approve(pool.address, toBase18(DT_bind_amt), from_wallet=wallet)
        OCEAN.approve(pool.address,
                      toBase18(OCEAN_bind_amt),
                      from_wallet=wallet)

        pool.bind(DT.address,
                  toBase18(DT_bind_amt),
                  toBase18(POOL_WEIGHT_DT),
                  from_wallet=wallet)
        pool.bind(OCEAN.address,
                  toBase18(OCEAN_bind_amt),
                  toBase18(POOL_WEIGHT_OCEAN),
                  from_wallet=wallet)

        pool.finalize(from_wallet=wallet)

        #create agent
        pool_agent = PoolAgent(pool_agent_name, pool)
        state.addAgent(pool_agent)
        self._wallet.resetCachedInfo()

        return pool_agent
Exemple #4
0
def _deployBPool(from_wallet: web3wallet.Web3Wallet) -> bpool.BPool:
    f = bfactory.BFactory()
    p_address = f.newBPool(from_wallet=from_wallet)
    p = bpool.BPool(p_address)
    return p
Exemple #5
0
def test_public_pool(T1, T2, alice_address, alice_wallet, bob_address,
                     bob_wallet):
    pool = _createPoolWith2Tokens(T1, T2, alice_wallet, 90.0, 10.0, 9.0, 1.0)
    BPT = pool

    #alice give Bob some tokens
    T1.transfer(bob_address, toBase18(100.0), from_wallet=alice_wallet)
    T2.transfer(bob_address, toBase18(100.0), from_wallet=alice_wallet)

    #verify holdings
    assert fromBase18(T1.balanceOf_base(alice_address)) == (1000.0 - 90.0 -
                                                            100.0)
    assert fromBase18(T2.balanceOf_base(alice_address)) == (1000.0 - 10.0 -
                                                            100.0)
    assert fromBase18(BPT.balanceOf_base(alice_address)) == 0

    assert fromBase18(T1.balanceOf_base(bob_address)) == 100.0
    assert fromBase18(T2.balanceOf_base(bob_address)) == 100.0
    assert fromBase18(BPT.balanceOf_base(bob_address)) == 0

    assert fromBase18(T1.balanceOf_base(pool.address)) == 90.0
    assert fromBase18(T2.balanceOf_base(pool.address)) == 10.0
    assert fromBase18(BPT.balanceOf_base(pool.address)) == 0

    #finalize
    pool = bpool.BPool(pool.address)
    pool.finalize(from_wallet=alice_wallet)

    #verify holdings
    assert fromBase18(T1.balanceOf_base(alice_address)) == (1000.0 - 90.0 -
                                                            100.0)
    assert fromBase18(T2.balanceOf_base(alice_address)) == (1000.0 - 10.0 -
                                                            100.0)
    assert fromBase18(BPT.balanceOf_base(alice_address)) == 100.0  #new!

    assert fromBase18(T1.balanceOf_base(pool.address)) == 90.0
    assert fromBase18(T2.balanceOf_base(pool.address)) == 10.0
    assert fromBase18(BPT.balanceOf_base(pool.address)) == 0

    #bob join pool. Wants 10 BPT
    T1.approve(pool.address, toBase18(100.0), from_wallet=bob_wallet)
    T2.approve(pool.address, toBase18(100.0), from_wallet=bob_wallet)
    pool.joinPool(
        poolAmountOut_base=toBase18(10.0),  #10 BPT
        maxAmountsIn_base=[toBase18(100.0), toBase18(100.0)],
        from_wallet=bob_wallet)

    #verify holdings
    assert fromBase18(T1.balanceOf_base(alice_address)) == (1000.0 - 90.0 -
                                                            100.0)
    assert fromBase18(T2.balanceOf_base(alice_address)) == (1000.0 - 10.0 -
                                                            100.0)
    assert fromBase18(BPT.balanceOf_base(alice_address)) == 100.0

    assert fromBase18(T1.balanceOf_base(bob_address)) == (100.0 - 9.0)
    assert fromBase18(T2.balanceOf_base(bob_address)) == (100.0 - 1.0)
    assert fromBase18(BPT.balanceOf_base(bob_address)) == 10.0

    assert fromBase18(T1.balanceOf_base(pool.address)) == (90.0 + 9.0)
    assert fromBase18(T2.balanceOf_base(pool.address)) == (10.0 + 1.0)
    assert fromBase18(BPT.balanceOf_base(pool.address)) == 0

    #bob sells 2 BPT
    # -this is where BLabs fee kicks in. But the fee is currently set to 0.
    pool.exitPool(poolAmountIn_base=toBase18(2.0),
                  minAmountsOut_base=[toBase18(0.0),
                                      toBase18(0.0)],
                  from_wallet=bob_wallet)
    assert fromBase18(T1.balanceOf_base(bob_address)) == 92.8
    assert fromBase18(T2.balanceOf_base(bob_address)) == 99.2
    assert fromBase18(BPT.balanceOf_base(bob_address)) == 8.0

    #bob buys 5 more BPT
    pool.joinPool(poolAmountOut_base=toBase18(5.0),
                  maxAmountsIn_base=[toBase18(90.0),
                                     toBase18(90.0)],
                  from_wallet=bob_wallet)
    assert fromBase18(BPT.balanceOf_base(bob_address)) == 13.0

    #bob fully exits
    pool.exitPool(poolAmountIn_base=toBase18(13.0),
                  minAmountsOut_base=[toBase18(0.0),
                                      toBase18(0.0)],
                  from_wallet=bob_wallet)
    assert fromBase18(BPT.balanceOf_base(bob_address)) == 0.0
Exemple #6
0
def test1(alice_wallet):
    f = bfactory.BFactory()
    p_address = f.newBPool(from_wallet=alice_wallet)
    p = bpool.BPool(p_address)
    assert isinstance(p, bpool.BPool)