<commit_before># This file is part of Maker Keeper Framework.
#
# Copyright (C) 2017 reverendus
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from typing import Optional

from web3 import Web3

from api.Address import Address
from api.Contract import Contract
from api.Ray import Ray
from api.Receipt import Receipt
from api.Wad import Wad


class Lpc(Contract):
    """A client for the `SaiLPC` contract, a simple two-token liquidity pool created together for Sai.

    `SaiLPC` relies on an external price feed (the `tip`).

    Makers
    - `pool()` their gems and receive LPS tokens, which are a claim on the pool.
    - `exit()` and trade their LPS tokens for a share of the gems in the pool.

    Takers
    - `take()` and exchange one gem for another, whilst paying a fee (the `gap`). The collected fee goes into the pool.

    Attributes:
        web3: An instance of `Web` from `web3.py`.
        address: Ethereum address of the `SaiLPC` contract.
    """

    abi = Contract._load_abi(__name__, 'Lpc.abi')

    def __init__(self, web3: Web3, address: Address):
        self.web3 = web3
        self.address = address
        self._assert_contract_exists(web3, address)
        self._contract = web3.eth.contract(abi=self.abi)(address=address.address)

    def ref(self) -> Address:
        """Get the ref token.

        Returns:
            The address of the ref token.
        """
        return Address(self._contract.call().ref())

    def alt(self) -> Address:
        """Get the alt token.

        Returns:
            The address of the alt token.
        """
        return Address(self._contract.call().alt())

    def pip(self) -> Address:
        """Get the price feed (giving refs per alt).

        You can get the current feed value by calling `tag()`.

        Returns:
            The address of the price feed, which could be a `DSValue`, a `DSCache`, a `Mednianizer` etc.
        """
        return Address(self._contract.call().pip())

    def gap(self) -> Wad:
        """Get the spread, charged on `take()`.

        Returns:
            The current value of the spread.
        """
        return Wad(self._contract.call().gap())

    def lps(self) -> Address:
        """Get the LPS token (liquidity provider shares).

        Returns:
            The address of the LPS token.
        """
        return Address(self._contract.call().lps())

    def jump(self, new_gap: Wad) -> Optional[Receipt]:<commit_msg>`tip()` added to the LPC API<commit_after># This file is part of Maker Keeper Framework.
#
# Copyright (C) 2017 reverendus
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from typing import Optional

from web3 import Web3

from api.Address import Address
from api.Contract import Contract
from api.Ray import Ray
from api.Receipt import Receipt
from api.Wad import Wad


class Lpc(Contract):
    """A client for the `SaiLPC` contract, a simple two-token liquidity pool created together for Sai.

    `SaiLPC` relies on an external price feed (the `tip`).

    Makers
    - `pool()` their gems and receive LPS tokens, which are a claim on the pool.
    - `exit()` and trade their LPS tokens for a share of the gems in the pool.

    Takers
    - `take()` and exchange one gem for another, whilst paying a fee (the `gap`). The collected fee goes into the pool.

    Attributes:
        web3: An instance of `Web` from `web3.py`.
        address: Ethereum address of the `SaiLPC` contract.
    """

    abi = Contract._load_abi(__name__, 'Lpc.abi')

    def __init__(self, web3: Web3, address: Address):
        self.web3 = web3
        self.address = address
        self._assert_contract_exists(web3, address)
        self._contract = web3.eth.contract(abi=self.abi)(address=address.address)

    def ref(self) -> Address:
        """Get the ref token.

        Returns:
            The address of the ref token.
        """
        return Address(self._contract.call().ref())

    def alt(self) -> Address:
        """Get the alt token.

        Returns:
            The address of the alt token.
        """
        return Address(self._contract.call().alt())

    def pip(self) -> Address:
        """Get the price feed (giving refs per alt).

        You can get the current feed value by calling `tag()`.

        Returns:
            The address of the price feed, which could be a `DSValue`, a `DSCache`, a `Mednianizer` etc.
        """
        return Address(self._contract.call().pip())

    def tip(self) -> Address:
        """Get the target price engine.

        Returns:
            The address of the target price engine. It is an internal component of Sai.
        """
        return Address(self._contract.call().tip())

    def gap(self) -> Wad:
        """Get the spread, charged on `take()`.

        Returns:
            The current value of the spread.
        """
        return Wad(self._contract.call().gap())

    def lps(self) -> Address:
        """Get the LPS token (liquidity provider shares).

        Returns:
            The address of the LPS token.
        """
        return Address(self._contract.call().lps())

    def jump(self, new_gap: Wad) -> Optional[Receipt]:
{'fraction_non_alphanumeric': 0.09544740973312402, 'fraction_numerical': 0.004709576138147566, 'mean_word_length': 2.595372460496614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6667148', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1715, 'n_words': 761}