Ejemplo n.º 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))

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

    # then
    assert token.allowance_of(our_address, second_address) == Wad(2**248 + 17)
Ejemplo n.º 2
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]))
Ejemplo n.º 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([], [
        Invocation(token.address,
                   token.approve_calldata(second_address, Wad(2**248 + 19)))
    ])

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

    # then
    assert token.allowance_of(tx.address, second_address) == Wad(2**248 + 19)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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())
Ejemplo n.º 6
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())
Ejemplo n.º 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())
Ejemplo n.º 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())
Ejemplo n.º 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())
Ejemplo n.º 10
0
    def hat(self) -> Wad:
        """Get the debt ceiling.

        Returns:
            The debt ceiling in SAI.
        """
        return Wad(self._contractTub.call().hat())
Ejemplo n.º 11
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())
Ejemplo n.º 12
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())
Ejemplo n.º 13
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())
Ejemplo n.º 14
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())
Ejemplo n.º 15
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())
Ejemplo n.º 16
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())
Ejemplo n.º 17
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())
Ejemplo n.º 18
0
    def test_execute(self):
        # given
        self.tx.approve([self.token1], directly())

        # when
        self.tx.execute([self.token1.address], [
            Invocation(
                self.token1.address,
                self.token1.transfer_calldata(self.other_address,
                                              Wad.from_number(500)))
        ])

        # then
        assert self.token1.balance_of(
            self.our_address) == Wad.from_number(999500)
        assert self.token1.balance_of(
            self.other_address) == Wad.from_number(500)
Ejemplo n.º 19
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())
Ejemplo n.º 20
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)
Ejemplo n.º 21
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.other_address = Address(self.web3.eth.accounts[1])
     self.tx = TxManager.deploy(self.web3)
     self.token1 = DSToken.deploy(self.web3, 'ABC')
     self.token1.mint(Wad.from_number(1000000))
     self.token2 = DSToken.deploy(self.web3, 'DEF')
Ejemplo n.º 22
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())
Ejemplo n.º 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())
Ejemplo n.º 24
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)
Ejemplo n.º 25
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)))
Ejemplo n.º 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())
Ejemplo n.º 27
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)))
Ejemplo n.º 28
0
def new_sai() -> SaiDeployment:
    def deploy(web3, contract_name, args=None):
        contract_factory = web3.eth.contract(
            abi=json.loads(
                pkg_resources.resource_string('api.feed',
                                              f'abi/{contract_name}.abi')),
            bytecode=pkg_resources.resource_string('api.feed',
                                                   f'abi/{contract_name}.bin'))
        tx_hash = contract_factory.deploy(args=args)
        receipt = web3.eth.getTransactionReceipt(tx_hash)
        return receipt['contractAddress']

    web3 = Web3(EthereumTesterProvider())
    web3.eth.defaultAccount = web3.eth.accounts[0]
    our_address = Address(web3.eth.defaultAccount)
    sai = DSToken.deploy(web3, 'SAI')
    sin = DSToken.deploy(web3, 'SIN')
    gem = DSToken.deploy(web3, 'ETH')
    pip = DSValue.deploy(web3)
    skr = DSToken.deploy(web3, 'SKR')
    pot = DSVault.deploy(web3)
    pit = DSVault.deploy(web3)
    tip = deploy(web3, 'Tip')
    dad = DSGuard.deploy(web3)
    jug = deploy(web3, 'SaiJug', [sai.address.address, sin.address.address])
    jar = deploy(
        web3, 'SaiJar',
        [skr.address.address, gem.address.address, pip.address.address])

    tub = Tub.deploy(web3, Address(jar), Address(jug), pot.address,
                     pit.address, Address(tip))
    tap = Tap.deploy(web3, tub.address, pit.address)
    top = Top.deploy(web3, tub.address, tap.address)

    # set permissions
    dad.permit(DSGuard.ANY, DSGuard.ANY, DSGuard.ANY)
    for auth in [sai, sin, skr, pot, pit, tub, tap, top]:
        auth.set_authority(dad.address)

    # approve, mint some GEMs
    tub.approve(directly())
    gem.mint(Wad.from_number(1000000))

    web3.currentProvider.rpc_methods.evm_snapshot()
    return SaiDeployment(web3, our_address, gem, sai, skr, tub, tap, top)
Ejemplo n.º 29
0
# logging.info(etherdelta.amount_filled(offchain_order))
# logging.info(etherdelta.can_trade(offchain_order, Wad.from_number(0.0026)))
# logging.info(etherdelta.can_trade(offchain_order, Wad.from_number(0.0025)))
# logging.info(etherdelta.can_trade(offchain_order, Wad.from_number(0.0006)))
# logging.info(etherdelta.trade(offchain_order, Wad.from_number(0.0006)))
# logging.info(etherdelta.amount_available(offchain_order))
# logging.info(etherdelta.amount_filled(offchain_order))
# logging.info(etherdelta.cancel_order(offchain_order))
# logging.info(etherdelta.amount_available(offchain_order))
# logging.info(etherdelta.amount_filled(offchain_order))
#
# logging.info("---")

logging.info(len(etherdelta.active_onchain_orders()))
logging.info(
    etherdelta.place_order_onchain(gem.address, Wad.from_number(0.0025),
                                   sai.address, Wad.from_number(0.1), 3600003))
onchain_order = OnChainOrder(
    gem.address, Wad.from_number(0.0025), sai.address, Wad.from_number(0.1),
    3600003,
    108207123768469167288277382516046143893265072544230933698775098822034023113615,
    our_address)
logging.info(len(etherdelta.active_onchain_orders()))
logging.info(onchain_order)
logging.info(etherdelta.amount_available(onchain_order))
logging.info(etherdelta.amount_filled(onchain_order))
logging.info(len(etherdelta.active_onchain_orders()))
logging.info(etherdelta.cancel_order(onchain_order))
logging.info(etherdelta.amount_available(onchain_order))
logging.info(etherdelta.amount_filled(onchain_order))
logging.info(len(etherdelta.active_onchain_orders()))
Ejemplo n.º 30
0
 def eth_balance(self, address: Address) -> Wad:
     assert (isinstance(address, Address))
     return Wad(self.web3.eth.getBalance(address.address))