Пример #1
0
    def approve(self, payee: Address,
                limit: Wad = Wad(2**256 - 1)) -> Transact:
        """Modifies the current allowance of a specified `payee` (delegate account).

        Allowance is an ERC20 concept allowing the `payee` (delegate account) to spend a fixed amount of tokens
        (`limit`) on behalf of the token owner.

        If `limit` is omitted, a maximum possible value is granted.

        Args:
            payee: The address of the delegate account (it's the address that can spend the tokens).
            limit: The value of the allowance i.e. the value of tokens that the `payee` (delegate account)
                can spend on behalf of their owner.

        Returns:
            A :py:class:`pymaker.Transact` instance, which can be used to trigger the transaction.
        """
        assert (isinstance(payee, Address))
        assert (isinstance(limit, Wad))

        return Transact(self, self.web3, self.abi, self.address,
                        self._contract, 'approve',
                        [payee.address, limit.value])
Пример #2
0
    def cancel_order(self, order: Order) -> Transact:
        """Cancels an existing order.

        Orders can be cancelled only by their owners.

        Args:
            order: The order you want to cancel.

        Returns:
            A :py:class:`pymaker.Transact` instance, which can be used to trigger the transaction.
        """
        assert(isinstance(order, Order))

        return Transact(self, self.web3, self.abi, self.address, self._contract, 'cancelOrder',
                        [order.buy_token.address,
                         order.buy_amount.value,
                         order.pay_token.address,
                         order.pay_amount.value,
                         order.expires,
                         order.nonce,
                         order.v if hasattr(order, 'v') else 0,
                         order.r if hasattr(order, 'r') else bytes(),
                         order.s if hasattr(order, 's') else bytes()])
Пример #3
0
    def add_liquidity_eth(self, amounts: dict, token: Token, eth_position: int) -> Transact:
        """ Add liquidity to token-weth pair.

        It is assumed that eth will always be token_a

        Args:
            amounts: dictionary[Wad, Wad, Wad, Wad]
            token_b: Token side of the pool
        Returns:
            A :py:class:`pymaker.Transact` instance, which can be used to trigger the transaction.
        """
        assert (isinstance(amounts, dict))
        assert (isinstance(token, Token))
        assert (isinstance(eth_position, int))

        if eth_position == 0:
            token_desired = amounts['amount_b_desired'].value
            token_min = amounts['amount_b_min'].value
            eth_desired = amounts['amount_a_desired'].value
            eth_min = amounts['amount_a_min'].value
        elif eth_position == 1:
            token_desired = amounts['amount_a_desired'].value
            token_min = amounts['amount_a_min'].value
            eth_desired = amounts['amount_b_desired'].value
            eth_min = amounts['amount_b_min'].value

        addLiquidityArgs = [
            token.address.address,
            token_desired,
            token_min,
            eth_min,
            self.account_address.address,
            self._deadline()
        ]

        return Transact(self, self.web3, self.router_abi, self.router_address, self._router_contract,
                        'addLiquidityETH', addLiquidityArgs, {'value': eth_desired})
Пример #4
0
    def permit(self, src, dst, sig: bytes) -> Transact:
        """Grant access to a function call.

        Args:
            src: Address of the caller, or `ANY`.
            dst: Address of the called contract, or `ANY`.
            sig: Signature of the called function, or `ANY`.

        Returns:
            A :py:class:`pymaker.Transact` instance, which can be used to trigger the transaction.
        """
        assert(isinstance(src, Address) or isinstance(src, bytes))
        assert(isinstance(dst, Address) or isinstance(dst, bytes))
        assert(isinstance(sig, bytes) and len(sig) in (4, 32))

        if isinstance(src, Address) and isinstance(dst, Address):
            method = 'permit(address,address,bytes32)'
            src = src.address
            dst = dst.address

        else:
            method = 'permit(bytes32,bytes32,bytes32)'

        return Transact(self, self.web3, self.abi, self.address, self._contract, method, [src, dst, sig])
Пример #5
0
    def make(self, pay_token: Address, pay_amount: Wad, buy_token: Address, buy_amount: Wad) -> Transact:
        """Create a new order.

        The `pay_amount` of `pay_token` token will be taken from you on order creation and deposited
        in the market contract. Allowance needs to be set first - refer to the `approve()` method.

        Args:
            pay_token: Address of the ERC20 token you want to put on sale.
            pay_amount: Amount of the `pay_token` token you want to put on sale.
            buy_token: Address of the ERC20 token you want to be paid with.
            buy_amount: Amount of the `buy_token` you want to receive.

        Returns:
            A :py:class:`pymaker.Transact` instance, which can be used to trigger the transaction.
        """
        assert(isinstance(pay_token, Address))
        assert(isinstance(pay_amount, Wad))
        assert(isinstance(buy_token, Address))
        assert(isinstance(buy_amount, Wad))
        assert(pay_amount > Wad(0))
        assert(buy_amount > Wad(0))

        return Transact(self, self.web3, self.abi, self.address, self._contract,
                        'make', [pay_token.address, buy_token.address, pay_amount.value, buy_amount.value])
Пример #6
0
 def gulp(self, address: Address):
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'gulp(address)', [address.address])
Пример #7
0
    def drip(self, ilk: Ilk) -> Transact:
        assert isinstance(ilk, Ilk)

        return Transact(self, self.web3, self.abi, self.address, self._contract, 'drip', [ilk.toBytes()])
Пример #8
0
    def flop(self) -> Transact:
        """Initiate a debt auction"""
        logger.info(f"Initiating a flop auction with woe={self.woe()}")

        return Transact(self, self.web3, self.abi, self.address, self._contract, 'flop', [])
Пример #9
0
    def heal(self, rad: Rad) -> Transact:
        assert isinstance(rad, Rad)
        logger.info(f"Healing joy={self.vat.dai(self.address)} woe={self.woe()}")

        return Transact(self, self.web3, self.abi, self.address, self._contract, 'heal', [rad.value])
Пример #10
0
    def rely(self, guy: Address) -> Transact:
        assert isinstance(guy, Address)

        return Transact(self, self.web3, self.abi, self.address, self._contract, 'rely', [guy.address])
Пример #11
0
    def hope(self, address: Address):
        assert isinstance(address, Address)

        return Transact(self, self.web3, self.abi, self.address, self._contract, 'hope', [address.address])
Пример #12
0
 def skim(self, ilk: Ilk, address: Address) -> Transact:
     """Cancels undercollateralized CDP debt to determine collateral shortfall"""
     assert isinstance(ilk, Ilk)
     assert isinstance(address, Address)
     return Transact(self, self.web3, self.abi, self.address, self._contract,
                     'skim', [ilk.toBytes(), address.address])
Пример #13
0
 def skip(self, ilk: Ilk, flip_id: int) -> Transact:
     """Cancel a flip auction and seize it's collateral"""
     assert isinstance(ilk, Ilk)
     assert isinstance(flip_id, int)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'skip', [ilk.toBytes(), flip_id])
Пример #14
0
 def cage(self, ilk: Ilk) -> Transact:
     """Set the `cage` price for the collateral"""
     assert isinstance(ilk, Ilk)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'cage(bytes32)', [ilk.toBytes()])
Пример #15
0
 def set_authority(self, address: Address) -> Transact:
     assert (isinstance(address, Address))
     return Transact(self, self.web3, self.abi, self.address,
                     self._contract, 'setAuthority', [address.address])
Пример #16
0
 def schedule(self):
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'schedule', [])
Пример #17
0
 def cast(self):
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'cast', [])
Пример #18
0
 def free(self, ilk: Ilk) -> Transact:
     """Releases excess collateral after `skim`ming"""
     assert isinstance(ilk, Ilk)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'free', [ilk.toBytes()])
Пример #19
0
    def heal(self, vice: Rad) -> Transact:
        assert isinstance(vice, Rad)

        return Transact(self, self.web3, self.abi, self.address, self._contract, 'heal', [vice.value])
Пример #20
0
 def thaw(self):
     """Fix the total outstanding supply of Dai"""
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'thaw', [])
Пример #21
0
    def flog(self, era: int) -> Transact:
        assert isinstance(era, int)

        return Transact(self, self.web3, self.abi, self.address, self._contract, 'flog', [era])
Пример #22
0
 def flow(self, ilk: Ilk) -> Transact:
     """Calculate the `fix`, the cash price for a given collateral"""
     assert isinstance(ilk, Ilk)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'flow', [ilk.toBytes()])
Пример #23
0
    def kiss(self, rad: Rad) -> Transact:
        assert isinstance(rad, Rad)

        return Transact(self, self.web3, self.abi, self.address, self._contract, 'kiss', [rad.value])
Пример #24
0
 def pack(self, dai: Wad) -> Transact:
     """Deposit Dai into the `bag`, from which it cannot be withdrawn"""
     assert isinstance(dai, Wad)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'pack', [dai.value])
Пример #25
0
    def flap(self) -> Transact:
        """Initiate a surplus auction"""
        logger.info(f"Initiating a flap auction with joy={self.vat.dai(self.address)}")

        return Transact(self, self.web3, self.abi, self.address, self._contract, 'flap', [])
Пример #26
0
 def cash(self, ilk: Ilk, dai: Wad):
     """Exchange an amount of dai (already `pack`ed in the `bag`) for collateral"""
     assert isinstance(ilk, Ilk)
     assert isinstance(dai, Wad)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'cash', [ilk.toBytes(), dai.value])
Пример #27
0
 def drip(self) -> Transact:
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'drip', [])
Пример #28
0
 def join(self, value: Wad) -> Transact:
     """Before `fire` can be called, sufficient MKR must be `join`ed to this contract"""
     assert isinstance(value, Wad)
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'join', [value.value])
Пример #29
0
 def test_empty_tx(self):
     empty_tx = Transact(self, self.web3, None, self.keeper_address, None,
                         None,
                         [self.keeper_address, Wad(0)])
     empty_tx.transact()
Пример #30
0
 def fire(self):
     """Calls `cage` on the `end` contract, initiating a shutdown."""
     logger.info("Calling fire to cage the end")
     return Transact(self, self.web3, self.abi, self.address, self._contract, 'fire', [])