Пример #1
0
    def bustable_amount_in_sai(self, tap: Tap):
        #TODO we always try to bust 10 SAI less than what the Tub reports
        #in order to discount the growth of `joy()` that might've have happened since the last drip
        #of course this is not the right solution and it won't even work properly if the last
        #drip happened enough time ago
        bustable_woe = tap.woe() - tap.joy() - Wad.from_number(10)

        # we deduct 0.000001 in order to avoid rounding errors
        bustable_fog = tap.fog() * tap.ask() - Wad.from_number(0.000001)

        return Wad.max(bustable_woe, bustable_fog, Wad.from_number(0))
Пример #2
0
 def __init__(self, tub: Tub, tap: Tap):
     self.tub = tub
     self.tap = tap
     super().__init__(source_token=self.tub.sai(),
                      target_token=self.tub.skr(),
                      rate=(Ray.from_number(1) / Ray(tap.ask())),
                      max_source_amount=self.bustable_amount_in_sai(tap),
                      method="tub.bust()")
Пример #3
0
 def __init__(self, tub: Tub, tap: Tap):
     self.tub = tub
     self.tap = tap
     super().__init__(source_token=self.tub.skr(),
                      target_token=self.tub.sai(),
                      rate=Ray(tap.bid()),
                      max_source_amount=self.boomable_amount_in_skr(tap),
                      method="tub.boom()")
Пример #4
0
def new_sai() -> SaiDeployment:
    def deploy(web3, contract_name, args=None):
        contract_factory = web3.eth.contract(
            abi=json.loads(
                pkg_resources.resource_string('keeper.api.feed',
                                              f'abi/{contract_name}.abi')),
            bytecode=pkg_resources.resource_string('keeper.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).transact()
    tub.set_authority(dad.address)
    for auth in [sai, sin, skr, pot, pit, tap, top]:
        auth.set_authority(dad.address).transact()

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

    web3.currentProvider.rpc_methods.evm_snapshot()
    return SaiDeployment(web3, our_address, gem, sai, sin, skr, tub, tap, top)
Пример #5
0
    def __init__(self):
        super().__init__()
        self.tub_address = Address(self.config.get_contract_address("saiTub"))
        self.tub = Tub(web3=self.web3, address=self.tub_address)
        self.tap_address = Address(self.config.get_contract_address("saiTap"))
        self.tap = Tap(web3=self.web3, address=self.tap_address)
        self.top_address = Address(self.config.get_contract_address("saiTop"))
        self.top = Top(web3=self.web3, address=self.top_address)
        self.otc_address = Address(self.config.get_contract_address("otc"))
        self.otc = SimpleMarket(web3=self.web3, address=self.otc_address)

        self.skr = ERC20Token(web3=self.web3, address=self.tub.skr())
        self.sai = ERC20Token(web3=self.web3, address=self.tub.sai())
        self.gem = DSEthToken(web3=self.web3, address=self.tub.gem())
        ERC20Token.register_token(self.tub.skr(), 'SKR')
        ERC20Token.register_token(self.tub.sai(), 'SAI')
        ERC20Token.register_token(self.tub.gem(), 'WETH')
Пример #6
0
 def boomable_amount_in_skr(self, tap: Tap):
     # we deduct 0.000001 in order to avoid rounding errors
     return Wad.max(
         Wad(self.boomable_amount_in_sai(tap) / (tap.bid())) -
         Wad.from_number(0.000001), Wad.from_number(0))
Пример #7
0
 def boomable_amount_in_sai(self, tap: Tap):
     return Wad.max(tap.joy() - tap.woe(), Wad.from_number(0))