Пример #1
0
def test_get_OCEAN_in_BPTs(alice_info):
    state = MockSimState()

    pool, DT = alice_info.pool, alice_info.DT
    pool_agent = PoolAgent("pool_agent", pool)
    state.agents["agent1"] = pool_agent

    foo_agent = FooAgent("foo_agent")

    OCEAN_address = globaltokens.OCEAN_address()
    price = fromBase18(pool.getSpotPrice(OCEAN_address, DT.address))
    pool_value_DT = price * fromBase18(pool.getBalance(DT.address))
    pool_value_OCEAN = fromBase18(pool.getBalance(OCEAN_address))
    pool_value = pool_value_DT + pool_value_OCEAN

    # case: foo_agent no BPTs
    value_held = KPIs.get_OCEAN_in_BPTs(state, foo_agent)
    foo_agent_pool_shape = foo_agent._BPT / fromBase18(pool.totalSupply())

    assert value_held == approx(foo_agent_pool_shape * pool_value)

    # case: foo_agent has all BPTs
    foo_agent._BPT = fromBase18(
        pool.totalSupply())  # make pool think agent has 100% of BPTs
    value_held = KPIs.get_OCEAN_in_BPTs(state, foo_agent)

    assert value_held == 1.0 * pool_value
Пример #2
0
def _spotPrices(T1, T2, bal1: float, bal2: float, w1: float, w2: float):  # pylint: disable=too-many-arguments
    pool = _createPoolWith2Tokens(T1, T2, bal1, bal2, w1, w2)
    a1, a2 = T1.address, T2.address
    return (
        fromBase18(pool.getSpotPrice(a1, a2)),
        fromBase18(pool.getSpotPriceSansFee(a1, a2)),
    )
Пример #3
0
def get_OCEAN_in_BPTs(state, agent):
    """Value of BPTs that this agent owns across all pools, denominated in OCEAN

    Args:
        state: SimState -- SimState, holds all pool agents (& their pools)
        agent:  AgentBase -- agent of interest

    Returns:
        value_held: float -- value of BPTs, denominated in OCEAN
    """
    OCEAN_address = globaltokens.OCEAN_address()
    value_held = 0

    for pool_agent in state.agents.filterToPool().values():
        pool = pool_agent._pool
        DT = pool_agent._dt

        price = fromBase18(pool.getSpotPrice(OCEAN_address, DT.address))
        pool_value_DT = price * fromBase18(pool.getBalance(DT.address))
        pool_value_OCEAN = fromBase18(pool.getBalance(OCEAN_address))
        pool_value = pool_value_DT + pool_value_OCEAN

        amt_pool_BPTs = fromBase18(pool.totalSupply())
        agent_percent_pool = agent.BPT(pool) / amt_pool_BPTs

        value_held += agent_percent_pool * pool_value

    return value_held
Пример #4
0
def test_exitswapPoolAmountIn(T1, T2):
    pool = _createPoolWith2Tokens(T1, T2, 90.0, 10.0, 9.0, 1.0)
    BPT = pool
    pool.finalize({"from": account0})
    assert fromBase18(T1.balanceOf(address0)) == 910.0
    tokenOut_address = T1.address
    poolAmountIn = toBase18(10.0)  # BPT spent
    minAmountOut = toBase18(1.0)  # min T1 wanted
    pool.exitswapPoolAmountIn(tokenOut_address, poolAmountIn, minAmountOut,
                              {"from": account0})
    assert fromBase18(T1.balanceOf(address0)) >= (910.0 + 1.0)
    assert fromBase18(BPT.balanceOf(address0)) == (100.0 - 10.0)
Пример #5
0
def test_joinswapPoolAmountOut(T1, T2):
    pool = _createPoolWith2Tokens(T1, T2, 90.0, 10.0, 9.0, 1.0)
    BPT = pool
    pool.finalize({"from": account0})
    T1.approve(pool.address, toBase18(90.0), {"from": account0})
    assert fromBase18(T1.balanceOf(address0)) == 910.0
    tokenIn_address = T1.address
    poolAmountOut = toBase18(10.0)  # BPT wanted
    maxAmountIn = toBase18(90.0)  # max T1 to spend
    pool.joinswapPoolAmountOut(tokenIn_address, poolAmountOut, maxAmountIn,
                               {"from": account0})
    assert fromBase18(T1.balanceOf(address0)) >= (910.0 - 90.0)
    assert fromBase18(BPT.balanceOf(address0)) == (100.0 + 10.0)
Пример #6
0
def _make_info(account):
    assert account.address != GOD_ACCOUNT.address

    OCEAN = globaltokens.OCEANtoken()

    # reset OCEAN balances on-chain, to avoid relying on brownie chain reverts
    # -assumes that DT and BPT in each test are new tokens each time, and
    #  therefore don't need re-setting
    for a in accounts:
        if a.address != GOD_ACCOUNT.address:
            OCEAN.transfer(GOD_ACCOUNT, OCEAN.balanceOf(a), {"from": a})

    class Info:
        def __init__(self):
            self.account = None
            self.agent = None
            self.DT = None
            self.pool = None

    info = Info()
    info.account = account

    class SimpleAgent(AgentBase.AgentBaseEvm):
        def takeStep(self, state):
            pass

    info.agent = SimpleAgent("agent1", USD=0.0, OCEAN=0.0)
    info.agent._wallet._account = account  # force agent to use this account
    info.agent._wallet.resetCachedInfo()  # because account changed wallet

    info.DT = _createDT(account)
    info.agent._wallet.resetCachedInfo()  # because DT was deposited to account
    assert info.DT.balanceOf(account) == toBase18(_DT_INIT)

    globaltokens.fundOCEANFromAbove(account.address, toBase18(_OCEAN_INIT))
    info.agent._wallet.resetCachedInfo(
    )  # because OCEAN was deposited to account

    info.pool = _createPool(info.DT, account)  # create pool, stake DT & OCEAN
    info.agent._wallet.resetCachedInfo()  # because OCEAN & DT was staked

    # postconditions
    w = info.agent._wallet
    OCEAN1 = w.OCEAN()
    assert w._cached_OCEAN_base is not None
    OCEAN2 = fromBase18(int(w._cached_OCEAN_base))
    OCEAN3 = fromBase18(OCEAN.balanceOf(account))
    assert OCEAN1 == OCEAN2 == OCEAN3, (OCEAN1, OCEAN2, OCEAN3)

    return info
Пример #7
0
    def transferOCEAN(self, dst_wallet, amt: float) -> None:
        assert isinstance(dst_wallet, (AgentWalletEvm, BurnWallet))
        dst_address = dst_wallet.address

        amt_base = toBase18(amt)
        assert amt_base >= 0
        if amt_base == 0:
            return

        OCEAN_base = self._OCEAN_base()
        if OCEAN_base == 0:
            raise ValueError("no funds to transfer from")

        tol = 1e-12
        if (1.0 - tol) <= amt / fromBase18(OCEAN_base) <= (1.0 + tol):
            amt_base = OCEAN_base

        if amt_base > OCEAN_base:
            raise ValueError(
                "transfer amt ({fromBase18(amt_base)})"
                " exceeds OCEAN holdings ({fromBase18(OCEAN_base)})"
            )

        globaltokens.OCEANtoken().transfer(
            dst_address, amt_base, {"from": self._account}
        )

        dst_wallet._total_OCEAN_in += amt
        self.resetCachedInfo()
        dst_wallet.resetCachedInfo()
Пример #8
0
def test_stakeOCEAN(alice_info):
    alice_info.agent._wallet.resetCachedInfo()
    agent_wallet, pool = alice_info.agent._wallet, alice_info.pool
    OCEAN = globaltokens.OCEANtoken()

    BPT_before = agent_wallet.BPT(pool)
    OCEAN1 = agent_wallet.OCEAN()
    OCEAN2 = fromBase18(agent_wallet._cached_OCEAN_base)
    OCEAN3 = fromBase18(OCEAN.balanceOf(agent_wallet.address))
    assert OCEAN1 == OCEAN2 == OCEAN3

    agent_wallet.stakeOCEAN(OCEAN_stake=20.0, pool=pool)

    OCEAN_after, BPT_after = agent_wallet.OCEAN(), agent_wallet.BPT(pool)
    assert OCEAN_after == (OCEAN1 - 20.0)
    assert BPT_after > BPT_before
Пример #9
0
def test_exitswapExternAmountOut(T1, T2):
    pool = _createPoolWith2Tokens(T1, T2, 90.0, 10.0, 9.0, 1.0)
    BPT = pool
    pool.finalize({"from": account0})
    assert fromBase18(T1.balanceOf(address0)) == 910.0
    tokenOut_address = T1.address
    tokenAmountOut = toBase18(2.0)  # T1 wanted
    maxPoolAmountIn = toBase18(10.0)  # max BPT spent
    pool.exitswapExternAmountOut(
        tokenOut_address,
        tokenAmountOut,  # T1 wanted
        maxPoolAmountIn,  # max BPT spent
        {"from": account0},
    )
    assert fromBase18(T1.balanceOf(address0)) == (910.0 + 2.0)
    assert fromBase18(BPT.balanceOf(address0)) >= (100.0 - 10.0)
Пример #10
0
def test_unbind(T1, T2):
    pool = _createPoolWith2Tokens(T1, T2, 1.0, 1.0, 1.0, 1.0)

    pool.unbind(T1.address, {"from": account0})

    assert pool.getNumTokens() == 1
    assert pool.getCurrentTokens() == [T2.address]
    assert fromBase18(pool.getBalance(T2.address)) == 1.0
Пример #11
0
def test_calcSpotPrice():
    pool = _deployBPool()
    tokenBalanceIn = toBase18(10.0)
    tokenWeightIn = toBase18(1.0)
    tokenBalanceOut = toBase18(11.0)
    tokenWeightOut = toBase18(1.0)
    swapFee = 0
    x = pool.calcSpotPrice(tokenBalanceIn, tokenWeightIn, tokenBalanceOut,
                           tokenWeightOut, swapFee)
    assert round(fromBase18(x), 3) == 0.909
Пример #12
0
def test_calcPoolOutGivenSingleIn():
    pool = _deployBPool()
    tokenBalanceIn = toBase18(10.0)
    tokenWeightIn = toBase18(1.0)
    poolSupply = toBase18(120.0)
    totalWeight = toBase18(2.0)
    tokenAmountIn = toBase18(0.1)
    swapFee = 0
    x = pool.calcPoolOutGivenSingleIn(tokenBalanceIn, tokenWeightIn,
                                      poolSupply, totalWeight, tokenAmountIn,
                                      swapFee)
    assert round(fromBase18(x), 3) == 0.599
Пример #13
0
def test_calcSingleOutGivenPoolIn():
    pool = _deployBPool()
    tokenBalanceOut = toBase18(10.0)
    tokenWeightOut = toBase18(1.0)
    poolSupply = toBase18(120.0)
    totalWeight = toBase18(2.0)
    poolAmountIn = toBase18(10.0)
    swapFee = 0
    x = pool.calcSingleOutGivenPoolIn(tokenBalanceOut, tokenWeightOut,
                                      poolSupply, totalWeight, poolAmountIn,
                                      swapFee)
    assert round(fromBase18(x), 3) == 1.597
Пример #14
0
def test_joinSwapExternAmountIn(T1, T2):
    pool = _createPoolWith2Tokens(T1, T2, 90.0, 10.0, 9.0, 1.0)
    T1.approve(pool.address, toBase18(100.0), {"from": account0})

    # pool's not public
    with pytest.raises(Exception):
        tokenIn_address = T1.address
        maxAmountIn = toBase18(100.0)
        tokenOut_address = T2.address
        tokenAmountOut = toBase18(10.0)
        maxPrice = HUGEINT
        pool.swapExactAmountOut(
            tokenIn_address,
            maxAmountIn,
            tokenOut_address,
            tokenAmountOut,
            maxPrice,
            {"from": account0},
        )

    # pool's public
    pool.setPublicSwap(True, {"from": account0})
    tokenIn_address = T1.address
    maxAmountIn = toBase18(100.0)
    tokenOut_address = T2.address
    tokenAmountOut = toBase18(1.0)
    maxPrice = HUGEINT
    pool.swapExactAmountOut(
        tokenIn_address,
        maxAmountIn,
        tokenOut_address,
        tokenAmountOut,
        maxPrice,
        {"from": account0},
    )
    assert 908.94 <= fromBase18(T1.balanceOf(address0)) <= 908.95
    assert fromBase18(T2.balanceOf(address0)) == (1000.0 - 9.0)
Пример #15
0
def test_2tokens_basic(T1, T2):
    pool = _deployBPool()
    assert T1.address != T2.address
    assert T1.address != pool.address

    assert fromBase18(T1.balanceOf(address0)) >= 90.0
    assert fromBase18(T2.balanceOf(address0)) >= 10.0

    with pytest.raises(Exception):  # can't bind until we approve
        pool.bind(T1.address, toBase18(90.0), toBase18(9.0))

    # Bind two tokens to the pool
    T1.approve(pool.address, toBase18(90.0), {"from": account0})
    T2.approve(pool.address, toBase18(10.0), {"from": account0})

    assert fromBase18(T1.allowance(address0, pool.address)) == 90.0
    assert fromBase18(T2.allowance(address0, pool.address)) == 10.0

    assert not pool.isBound(T1.address) and not pool.isBound(T1.address)
    pool.bind(T1.address, toBase18(90.0), toBase18(9.0), {"from": account0})
    pool.bind(T2.address, toBase18(10.0), toBase18(1.0), {"from": account0})
    assert pool.isBound(T1.address) and pool.isBound(T2.address)

    assert pool.getNumTokens() == 2
    assert pool.getCurrentTokens() == [T1.address, T2.address]

    assert pool.getDenormalizedWeight(T1.address) == toBase18(9.0)
    assert pool.getDenormalizedWeight(T2.address) == toBase18(1.0)
    assert pool.getTotalDenormalizedWeight() == toBase18(9.0 + 1.0)

    assert pool.getNormalizedWeight(T1.address) == toBase18(0.9)
    assert pool.getNormalizedWeight(T2.address) == toBase18(0.1)

    assert pool.getBalance(T1.address) == toBase18(90.0)
    assert pool.getBalance(T2.address) == toBase18(10.0)

    assert str(pool)
Пример #16
0
def test_get_OCEAN_in_DTs(alice_info):
    state = MockSimState()

    pool, DT = alice_info.pool, alice_info.DT
    pool_agent = PoolAgent("pool_agent", pool)
    state.agents["agent1"] = pool_agent

    foo_agent = FooAgent("foo_agent")

    OCEAN_address = globaltokens.OCEAN_address()
    price = fromBase18(pool.getSpotPrice(OCEAN_address, DT.address))

    amt_DT = foo_agent.DT("bar")
    assert amt_DT == 3.0

    value_held = KPIs.get_OCEAN_in_DTs(state, foo_agent)
    assert value_held == amt_DT * price
Пример #17
0
def test_calcPoolInGivenSingleOut():
    pool = _deployBPool()
    tokenBalanceOut = toBase18(1000.0)
    tokenWeightOut = toBase18(5.0)
    poolSupply = toBase18(100.0)
    totalWeight = toBase18(10.0)
    tokenAmountOut = toBase18(0.1)
    swapFee = 0
    x = pool.calcPoolInGivenSingleOut(
        tokenBalanceOut,
        tokenWeightOut,
        poolSupply,
        totalWeight,
        tokenAmountOut,
        swapFee,
    )
    assert round(fromBase18(x), 3) == 0.005
Пример #18
0
def test_calcInGivenOut():
    pool = _deployBPool()
    tokenBalanceIn = toBase18(10.0)
    tokenWeightIn = toBase18(1.0)
    tokenBalanceOut = toBase18(10.1)
    tokenWeightOut = toBase18(1.0)
    tokenAmountOut = toBase18(1.0)
    swapFee = 0
    x = pool.calcInGivenOut(
        tokenBalanceIn,
        tokenWeightIn,
        tokenBalanceOut,
        tokenWeightOut,
        tokenAmountOut,
        swapFee,
    )
    assert round(fromBase18(x), 3) == 1.099
Пример #19
0
def get_OCEAN_in_DTs(state, agent) -> float:
    """Value of DT that this agent staked across all pools, denominated in OCEAN
    Args:
        state: SimState -- SimState, holds all pool agents (& their pools)
        agent:  AgentBase -- agent of interest
    Returns:
        value_held: float -- value staked, denominated in OCEAN
    """
    OCEAN_address = globaltokens.OCEAN_address()
    value_held = 0.0

    for pool_agent in state.agents.filterToPoolV4().values():
        pool = pool_agent._pool
        DT = pool_agent._dt
        swapFee = pool.getSwapFee()
        price = fromBase18(pool.getSpotPrice(OCEAN_address, DT.address, swapFee))
        amt_DT = agent.DT(DT)
        value_held += amt_DT * price

    return value_held
Пример #20
0
    def transferDT(self, dst_wallet, DT, amt: float) -> None:
        assert isinstance(dst_wallet, (AgentWalletEvm, BurnWallet))
        dst_address = dst_wallet.address

        amt_base = toBase18(amt)
        assert amt_base >= 0
        if amt_base == 0:
            return

        DT_base = self._DT_base(DT)
        if DT_base == 0:
            raise ValueError("no data tokens to transfer")

        tol = 1e-12
        if (1.0 - tol) <= amt / fromBase18(DT_base) <= (1.0 + tol):
            amt_base = DT_base

        if amt_base > DT_base:
            raise ValueError(
                f"transfer amt ({fromBase18(amt_base)})"
                " exceeds DT holdings ({fromBase18(DT_base)})"
            )

        DT.transfer(dst_address, amt_base, {"from": self._account})
Пример #21
0
def test_public_pool(T1, T2):
    pool = _createPoolWith2Tokens(T1, T2, 90.0, 10.0, 9.0, 1.0)
    BPT = pool

    # alice give Bob some tokens
    T1.transfer(address1, toBase18(100.0), {"from": account0})
    T2.transfer(address1, toBase18(100.0), {"from": account0})

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

    assert fromBase18(T1.balanceOf(address1)) == 100.0
    assert fromBase18(T2.balanceOf(address1)) == 100.0
    assert fromBase18(BPT.balanceOf(address1)) == 0

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

    # finalize
    pool.finalize({"from": account0})

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

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

    # bob join pool. Wants 10 BPT
    T1.approve(pool.address, toBase18(100.0), {"from": account1})
    T2.approve(pool.address, toBase18(100.0), {"from": account1})
    poolAmountOut = toBase18(10.0)  # 10 BPT
    maxAmountsIn = [toBase18(100.0), toBase18(100.0)]
    pool.joinPool(poolAmountOut, maxAmountsIn, {"from": account1})

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

    assert fromBase18(T1.balanceOf(address1)) == (100.0 - 9.0)
    assert fromBase18(T2.balanceOf(address1)) == (100.0 - 1.0)
    assert fromBase18(BPT.balanceOf(address1)) == 10.0

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

    # bob sells 2 BPT
    # -this is where BLabs fee kicks in. But the fee is currently set to 0.
    poolAmountIn = toBase18(2.0)
    minAmountsOut = [toBase18(0.0), toBase18(0.0)]
    pool.exitPool(poolAmountIn, minAmountsOut, {"from": account1})
    assert fromBase18(T1.balanceOf(address1)) == 92.8
    assert fromBase18(T2.balanceOf(address1)) == 99.2
    assert fromBase18(BPT.balanceOf(address1)) == 8.0

    # bob buys 5 more BPT
    poolAmountOut = toBase18(5.0)
    maxAmountsIn = [toBase18(90.0), toBase18(90.0)]
    pool.joinPool(poolAmountOut, maxAmountsIn, {"from": account1})
    assert fromBase18(BPT.balanceOf(address1)) == 13.0

    # bob fully exits
    poolAmountIn = toBase18(13.0)
    minAmountsOut = [toBase18(0.0), toBase18(0.0)]
    pool.exitPool(poolAmountIn, minAmountsOut, {"from": account1})
    assert fromBase18(BPT.balanceOf(address1)) == 0.0
Пример #22
0
def test_sideStaking_properties():
    brownie.chain.reset()
    OCEAN = OCEANtoken()

    OCEAN_base_funding = 10000
    do_extra_funding = False
    OCEAN_extra_funding = 10000

    OCEAN_init_liquidity = 2000  # initial liquidity in OCEAN on pool creation
    DT_OCEAN_rate = 0.1

    DT_cap = 10000
    DT_vest_amt = 1000
    DT_vest_num_blocks = 600
    (DT, pool, ssbot) = _deployBPool(
        OCEAN_base_funding,
        do_extra_funding,
        OCEAN_extra_funding,
        OCEAN_init_liquidity,
        DT_OCEAN_rate,
        DT_cap,
        DT_vest_amt,
        DT_vest_num_blocks,
    )

    # basic tests
    assert pool.getBaseTokenAddress() == OCEAN.address
    assert ssbot.getBaseTokenAddress(DT.address) == OCEAN.address
    assert ssbot.getBaseTokenBalance(DT.address) == 0

    assert ssbot.getPublisherAddress(DT.address) == address0
    assert ssbot.getPoolAddress(DT.address) == pool.address

    assert fromBase18(ssbot.getvestingAmount(DT.address)) == 1000

    # ssbot manages DTs in two specific ways:
    # 1. Linear vesting of DTs to publisher over a fixed # blocks
    # 2. When OCEAN liquidity is added to the pool, it
    #    moves DT from its balance into the pool (ultimately, DT circ supply)
    #    such that DT:OCEAN ratio stays constant

    # Therefore: (DT_vested) + (ssbot_DT_balance + DT_circ_supply) = DT_cap

    # No blocks have passed since pool creation. Therefore no vesting yet
    assert ssbot.getvestingAmountSoFar(DT.address) == 0

    # We start out with a given OCEAN_init_liquidity. And, DT_OCEAN_rate is
    # the initial DT:OCEAN ratio.
    # Therefore we know how many DT the bot was supposed to add to the pool:
    # OCEAN_init_liquidity * DT_OCEAN_rate = 2000*0.1 = 200
    # Since no one's swapped for DT, then this is also DT circulating supply
    assert fromBase18(ssbot.getDatatokenCirculatingSupply(DT.address)) == 200

    # The ssbot holds the rest of the DT. Rerrange formula above to see amt.
    # So,ssbot_DT_balance = DT_cap - DT_vested - DT_circ_supply
    #                     = 10000  - 0         - 200
    #                     = 9800
    assert fromBase18(DT.balanceOf(ssbot.address)) == 9800

    # ========================================================
    # Test vesting... (recall DT_vest_amt = 1000)
    assert fromBase18(ssbot.getvestingAmount(DT.address)) == 1000

    # datatoken.deployPool()
    # -> call BFactory.newBPool()
    # -> call SideStaking.newDatatokenCreated()
    # -> emit VestingCreated(datatokenAddress, publisherAddress,
    #                       _datatokens[datatokenAddress].vestingEndBlock,
    #                       _datatokens[datatokenAddress].vestingAmount)

    assert ssbot.getAvailableVesting(DT.address) == 0
    assert ssbot.getvestingAmountSoFar(DT.address) == 0

    # Pass enough time to make all vesting happen!
    brownie.chain.mine(blocks=DT_vest_num_blocks)

    # Test key numbers
    block_number = len(brownie.chain)
    vesting_end_block = ssbot.getvestingEndBlock(DT.address)
    vesting_last_block = ssbot.getvestingLastBlock(DT.address)
    blocks_passed = vesting_end_block - vesting_last_block
    available_vesting = fromBase18(ssbot.getAvailableVesting(DT.address))

    assert block_number == 616
    assert vesting_end_block == 615
    assert vesting_last_block == 15  # last block when tokens were vested
    assert blocks_passed == 600
    assert available_vesting == 1000

    # Publisher hasn't claimed yet, so no vesting or DTs
    assert ssbot.getvestingAmountSoFar(DT.address) == 0
    assert DT.balanceOf(account0) == 0

    # Publisher claims. Now he has vesting and DTs
    ssbot.getVesting(DT.address, {"from": account0})  # claim!
    assert fromBase18(ssbot.getvestingAmountSoFar(DT.address)) == 1000
    assert fromBase18(DT.balanceOf(account0)) == 1000

    # The ssbot's holdings are updated too
    # ssbot_DT_balance = DT_cap - DT_vested - DT_circ_supply
    #                  = 10000  - 1000      - 200
    #                  = 8800
    assert fromBase18(ssbot.getDatatokenBalance(DT.address)) == 8800

    #
    assert ssbot.getvestingLastBlock(DT.address) == 616 == block_number
Пример #23
0
 def BPT(self, pool) -> float:
     return fromBase18(self._BPT_base(pool))
Пример #24
0
 def DT(self, dt) -> float:
     return fromBase18(self._DT_base(dt))
Пример #25
0
 def ETH(self) -> float:
     return fromBase18(self._ETH_base())
Пример #26
0
 def OCEAN(self) -> float:
     return fromBase18(self._OCEAN_base())
Пример #27
0
def netlist_createLogData(state): #pylint: disable=too-many-statements
    """SimEngine constructor uses this"""
    s = []  # for console logging
    dataheader = []  # for csv logging: list of string
    datarow = []  # for csv logging: list of float

    # SimEngine already logs: Tick, Second, Min, Hour, Day, Month, Year
    # So we log other things...
    agents_names = [
        "publisher",
        # "consumer",
        "stakerSpeculator",
        "speculator",
        # "buySellRobot",
        # "maliciousPublisher"
        # "erc721"
    ]
    # tracking OCEAN
    OCEANtoken = globaltokens.OCEANtoken()
    OCEAN_address = globaltokens.OCEAN_address()
    for name in agents_names:
        agent = state.getAgent(name)

        # in wallet
        dataheader += [f"{name}_OCEAN"]
        datarow += [agent.OCEAN()]

        # in DTs
        dataheader += [f"{name}_OCEAN_in_DTs"]
        datarow += [get_OCEAN_in_DTs(state, agent)]

        # in BPTs
        dataheader += [f"{name}_OCEAN_in_BPTs"]
        datarow += [get_OCEAN_in_BPTs(state, agent)]

        # networth
        dataheader += [f"{name}_OCEAN_networth"]
        datarow += [
            agent.OCEAN()
            + get_OCEAN_in_DTs(state, agent)
            + get_OCEAN_in_BPTs(state, agent)
        ]

        dataheader += [f"DT_{name}"]
        dataheader += [f"BPT_{name}"]

        # Tracking DT and BPT balances of agents
        if any(state.agents.filterToPoolV4().values()):
            poolAgent_0 = list(state.agents.filterToPoolV4().values())[0]
            DT = poolAgent_0._dt
            amt_DT = agent.DT(DT)
            datarow += [amt_DT]
            datarow += [agent.BPT(poolAgent_0._pool)]  # agent.BPT(pool)
        else:
            datarow += [0, 0]

    # Track pool0
    # 1. DT in pool,
    # 2. DT balance of 1ss contract
    # 3. BPT total supply,
    # 4. BPT balance of 1ss contract,
    # 5. DT spot price
    # 6. OCEAN in pool
    dataheader += ["DT_pool"]
    dataheader += ["DT_1ss_contract"]
    dataheader += ["BPT_total"]
    dataheader += ["BPT_1ss_contract"]
    dataheader += ["DT_price"]
    dataheader += ["pool_OCEAN"]
    if any(state.agents.filterToPoolV4().values()):
        poolAgent_0 = list(state.agents.filterToPoolV4().values())[0]
        pool0 = poolAgent_0._pool
        DT = poolAgent_0._dt
        oneSSContractAddress = pool0.getController()

        datarow += [fromBase18(DT.balanceOf(pool0.address))]  # 1
        datarow += [fromBase18(DT.balanceOf(oneSSContractAddress))]  # 2
        datarow += [fromBase18(pool0.totalSupply())]  # 3
        datarow += [fromBase18(pool0.balanceOf(oneSSContractAddress))]  # 4
        swapFee = pool0.getSwapFee()
        datarow += [
            fromBase18(pool0.getSpotPrice(OCEAN_address, DT.address, swapFee))
        ]  # 5
        datarow += [fromBase18(OCEANtoken.balanceOf(pool0.address))]
    else:
        datarow += [0, 0, 0, 0, 0, 0]

    pool_agents = state.agents.filterToPoolV4()
    n_pools = len(pool_agents)
    s += [f"; # pools={n_pools}"]
    dataheader += ["n_pools"]
    datarow += [n_pools]

    rugged_pool = state.rugged_pools
    n_rugged = len(rugged_pool)
    # s += [f"; # rugged pools={n_rugged}"]
    s += [f"; # block height={brownie.chain.height}"]
    dataheader += ["n_rugged"]
    datarow += [n_rugged]

    return s, dataheader, datarow
Пример #28
0
def test_setSwapFee_works():
    pool = _deployBPool()
    pool.setSwapFee(toBase18(0.011), {"from": account0})
    assert fromBase18(pool.getSwapFee()) == 0.011