|
| 1 | +# This file is part of Maker Keeper Framework. |
| 2 | +# |
| 3 | +# Copyright (C) 2019-2021 EdNoepel |
| 4 | +# |
| 5 | +# This program is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU Affero General Public License as published by |
| 7 | +# the Free Software Foundation, either version 3 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# This program is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU Affero General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU Affero General Public License |
| 16 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +import logging |
| 19 | + |
| 20 | +from chief_keeper.utils.address import Address |
| 21 | +from chief_keeper.utils.contract import Contract |
| 22 | + |
| 23 | +from chief_keeper.makerdao_utils.auctions import AuctionContract, Clipper, Flipper |
| 24 | +from chief_keeper.makerdao_utils.join import GemJoin |
| 25 | +from chief_keeper.makerdao_utils.token import ERC20Token |
| 26 | + |
| 27 | +from pymaker.approval import directly, hope_directly |
| 28 | + |
| 29 | +from pymaker.ilk import Ilk |
| 30 | +from pymaker.gas import DefaultGasPrice |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +logger = logging.getLogger() |
| 35 | + |
| 36 | + |
| 37 | +class Collateral: |
| 38 | + """The `Collateral` object wraps accounting information in the Ilk with token-wide artifacts shared across |
| 39 | + multiple collateral types for the same token. For example, ETH-A and ETH-B are represented by different Ilks, |
| 40 | + but will share the same gem (WETH token), GemJoin instance, and Flipper contract. |
| 41 | + """ |
| 42 | + |
| 43 | + def __init__(self, ilk: Ilk, gem: ERC20Token, adapter: GemJoin, auction: AuctionContract, pip, vat: Contract): |
| 44 | + assert isinstance(ilk, Ilk) |
| 45 | + assert isinstance(gem, ERC20Token) |
| 46 | + assert isinstance(adapter, GemJoin) |
| 47 | + assert isinstance(auction, AuctionContract) |
| 48 | + assert isinstance(vat, Contract) |
| 49 | + |
| 50 | + self.ilk = ilk |
| 51 | + self.gem = gem |
| 52 | + self.adapter = adapter |
| 53 | + if isinstance(auction, Flipper): |
| 54 | + self.flipper = auction |
| 55 | + self.clipper = None |
| 56 | + elif isinstance(auction, Clipper): |
| 57 | + self.flipper = None |
| 58 | + self.clipper = auction |
| 59 | + # Points to `median` for official deployments, `DSValue` for testing purposes. |
| 60 | + # Users generally have no need to interact with the pip. |
| 61 | + self.pip = pip |
| 62 | + self.vat = vat |
| 63 | + |
| 64 | + def approve(self, usr: Address, **kwargs): |
| 65 | + """ |
| 66 | + Allows the user to move this collateral into and out of their CDP. |
| 67 | +
|
| 68 | + Args |
| 69 | + usr: User making transactions with this collateral |
| 70 | + """ |
| 71 | + gas_strategy = kwargs['gas_strategy'] if 'gas_strategy' in kwargs else DefaultGasPrice() |
| 72 | + self.adapter.approve(hope_directly(from_address=usr, gas_strategy=gas_strategy), self.vat.address) |
| 73 | + self.adapter.approve_token(directly(from_address=usr, gas_strategy=gas_strategy)) |
0 commit comments