Пример #1
0
def test_direct_approval_should_not_approve_if_already_approved():
    # given
    global web3, our_address, second_address, token
    token.approve(second_address, Wad(2**248+17)).transact()

    # when
    directly()(token, second_address, "some-name")

    # then
    assert token.allowance_of(our_address, second_address) == Wad(2**248+17)
Пример #2
0
    def test_approve(self):
        # given
        assert self.token1.allowance_of(self.our_address, self.tx.address) == Wad(0)
        assert self.token2.allowance_of(self.our_address, self.tx.address) == Wad(0)

        # when
        self.tx.approve([self.token1, self.token2], directly())

        # then
        assert self.token1.allowance_of(self.our_address, self.tx.address) == Wad(2**256-1)
        assert self.token2.allowance_of(self.our_address, self.tx.address) == Wad(2**256-1)
Пример #3
0
def test_via_tx_manager_approval_should_not_approve_if_already_approved():
    # given
    global web3, our_address, second_address, token
    tx = TxManager.deploy(web3)
    tx.execute([], [token.approve(second_address, Wad(2**248+19)).invocation()]).transact()

    # when
    via_tx_manager(tx)(token, second_address, "some-name")

    # then
    assert token.allowance_of(tx.address, second_address) == Wad(2**248+19)
Пример #4
0
    def cups(self, cup_id: int) -> Cup:
        """Get the cup details.

        Args:
            cup_id: Id of the cup to get the details of.

        Returns:
            Class encapsulating cup details.
        """
        assert isinstance(cup_id, int)
        array = self._contractTub.call().cups(int_to_bytes32(cup_id))
        return Cup(cup_id, Address(array[0]), Wad(array[1]), Wad(array[2]))
Пример #5
0
 def setup_method(self):
     self.web3 = Web3(EthereumTesterProvider())
     self.web3.eth.defaultAccount = self.web3.eth.accounts[0]
     self.our_address = Address(self.web3.eth.defaultAccount)
     self.etherdelta = EtherDelta.deploy(
         self.web3,
         admin=self.our_address,
         fee_account=self.our_address,
         account_levels_addr=self.our_address,
         fee_make=Wad(0),
         fee_take=Wad(0),
         fee_rebate=Wad(0),
         api_server='http://none.invalid')
     self.token1 = DSToken.deploy(self.web3, 'AAA')
     self.token1.mint(Wad.from_number(100)).transact()
Пример #6
0
    def jar_gap(self) -> Wad:
        """Get the current spread for `join` and `exit`.

        Returns:
            The current spread for `join` and `exit`. `1.0` means no spread, `1.01` means 1% spread.
        """
        return Wad(self._contractJar.call().gap())
Пример #7
0
    def air(self) -> Wad:
        """Get the amount of backing collateral.

        Returns:
            The amount of backing collateral in SKR.
        """
        return Wad(self._contractTub.call().air())
Пример #8
0
    def pie(self) -> Wad:
        """Get the amount of raw collateral.

        Returns:
            The amount of raw collateral in GEM.
        """
        return Wad(self._contractTub.call().pie())
Пример #9
0
    def ice(self) -> Wad:
        """Get the amount of good debt.

        Returns:
            The amount of good debt in SAI.
        """
        return Wad(self._contractTub.call().ice())
Пример #10
0
    def hat(self) -> Wad:
        """Get the debt ceiling.

        Returns:
            The debt ceiling in SAI.
        """
        return Wad(self._contractTub.call().hat())
Пример #11
0
    def pie(self) -> Wad:
        """Get the total pool value (in ref).

        Returns:
            The the total pool value (in ref).
        """
        return Wad(self._contract.call().pie())
Пример #12
0
    def woe(self) -> Wad:
        """Get the amount of bad debt.

        Returns:
            The amount of bad debt in SAI.
        """
        return Wad(self._contract.call().woe())
Пример #13
0
    def gap(self) -> Wad:
        """Get the spread, charged on `take()`.

        Returns:
            The current value of the spread. `1.0` means no spread. `1.02` means 2% spread.
        """
        return Wad(self._contract.call().gap())
Пример #14
0
    def bid(self) -> Wad:
        """Get the current price of SKR in SAI for `boom`.

        Returns:
            The SKR in SAI price that will be used on `boom()`.
        """
        return Wad(self._contract.call().bid())
Пример #15
0
    def gap(self) -> Wad:
        """Get the current spread for `boom` and `bust`.

        Returns:
            The current spread for `boom` and `bust`. `1.0` means no spread, `1.01` means 1% spread.
        """
        return Wad(self._contract.call().gap())
Пример #16
0
    def s2s(self) -> Wad:
        """Get the current SKR per SAI rate (for `boom` and `bust`).

        Returns:
            The current SKR per SAI rate.
        """
        return Wad(self._contract.call().s2s())
Пример #17
0
    def fog(self) -> Wad:
        """Get the amount of SKR pending liquidation.

        Returns:
            The amount of SKR pending liquidation, in SKR.
        """
        return Wad(self._contract.call().fog())
Пример #18
0
    def ask(self) -> Wad:
        """Get the current price of SKR in SAI for `bust`.

        Returns:
            The SKR in SAI price that will be used on `bust()`.
        """
        return Wad(self._contract.call().ask())
Пример #19
0
def test_direct_approval():
    # given
    global web3, our_address, second_address, token

    # when
    directly()(token, second_address, "some-name")

    # then
    assert token.allowance_of(our_address, second_address) == Wad(2**256-1)
Пример #20
0
    def tag(self) -> Wad:
        """Get the current price (refs per alt).

        The price is read from the price feed (`tip()`) every time this method gets called.

        Returns:
            The current price (refs per alt).
        """
        return Wad(self._contract.call().tag())
Пример #21
0
    def joy(self) -> Wad:
        """Get the amount of surplus SAI.

        Surplus SAI can be processed using `boom()`.

        Returns:
            The amount of surplus SAI accumulated in the Tub.
        """
        return Wad(self._contract.call().joy())
Пример #22
0
def test_via_tx_manager_approval():
    # given
    global web3, our_address, second_address, token
    tx = TxManager.deploy(web3)

    # when
    via_tx_manager(tx)(token, second_address, "some-name")

    # then
    assert token.allowance_of(tx.address, second_address) == Wad(2**256-1)
Пример #23
0
    def tag(self) -> Wad:
        """Get the reference price (REF per SKR).

        The price is read from the price feed (`tip()`) every time this method gets called.
        Its value is actually the value from the feed (REF per GEM) multiplied by `per()` (GEM per SKR).

        Returns:
            The reference price (REF per SKR).
        """
        return Wad(self._contractJar.call().tag())
Пример #24
0
 def approval_function(token: ERC20Token, spender_address: Address,
                       spender_name: str):
     if token.allowance_of(Address(token.web3.eth.defaultAccount),
                           spender_address) < Wad(2**128 - 1):
         logger = logging.getLogger("api")
         logger.info(
             f"Approving {spender_name} ({spender_address}) to access our {token.name()} directly"
         )
         if not token.approve(spender_address).transact():
             raise RuntimeError("Approval failed!")
Пример #25
0
    def ink(self, cup_id: int) -> Wad:
        """Get the amount of SKR collateral locked in a cup.

        Args:
            cup_id: Id of the cup.

        Returns:
            Amount of SKR collateral locked in the cup, in SKR.
        """
        assert isinstance(cup_id, int)
        return Wad(self._contractTub.call().ink(int_to_bytes32(cup_id)))
Пример #26
0
    def par(self) -> Wad:
        """Get the accrued holder fee (REF per SAI).

        Every invocation of this method calls `prod()` internally, so the value you receive is always up-to-date.
        But as calling it doesn't result in an Ethereum transaction, the actual `_par` value in the smart
        contract storage does not get updated.

        Returns:
            The accrued holder fee.
        """
        return Wad(self._contractTip.call().par())
Пример #27
0
    def tab(self, cup_id: int) -> Wad:
        """Get the amount of debt in a cup.

        Args:
            cup_id: Id of the cup.

        Returns:
            Amount of debt in the cup, in SAI.
        """
        assert isinstance(cup_id, int)
        return Wad(self._contractTub.call().tab(int_to_bytes32(cup_id)))
Пример #28
0
 def approval_function(token: ERC20Token, spender_address: Address,
                       spender_name: str):
     if token.allowance_of(tx_manager.address,
                           spender_address) < Wad(2**128 - 1):
         logger = logging.getLogger("api")
         logger.info(
             f"Approving {spender_name} ({spender_address}) to access our {token.name()}"
             f" via TxManager {tx_manager.address}")
         if not tx_manager.execute([], [
             (token.approve(spender_address).invocation())
         ]).transact():
             raise RuntimeError("Approval failed!")
Пример #29
0
 def eth_balance(self, address: Address) -> Wad:
     assert(isinstance(address, Address))
     return Wad(self.web3.eth.getBalance(address.address))