diff --git a/CHANGELOG.md b/CHANGELOG.md index f6456ef..6d16e35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/iamdefinitelyahuman/brownie-token-tester) +## [0.2.2](https://github.com/iamdefinitelyahuman/brownie-token-tester/tree/v0.2.2) - 2021-06-01 + +### Changed +- Generalize minting logic for Synthetix synths + ## [0.2.1](https://github.com/iamdefinitelyahuman/brownie-token-tester/tree/v0.2.1) - 2021-05-26 ### Changed diff --git a/README.md b/README.md index 19bc410..666efb9 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ Tokens for which custom logic is currently implemented: - [x] EURS - [x] LinkUSD - [x] pBTC +- [x] Synthetix synths - [x] renBTC - [x] renZEC - [x] rETH @@ -91,10 +92,6 @@ Tokens for which custom logic is currently implemented: - [x] USDC - [x] USDN - [x] USDT -- [x] sBTC -- [x] sETH -- [x] sEURS -- [x] sUSD - [x] tBTC - [x] wBTC - [x] wZEC diff --git a/brownie_tokens/forked.py b/brownie_tokens/forked.py index a03c33f..c4b3a62 100644 --- a/brownie_tokens/forked.py +++ b/brownie_tokens/forked.py @@ -36,13 +36,13 @@ def _mint_for_testing(self, target: str, amount: Wei, tx: Dict = None) -> None: getattr(sys.modules[__name__], fn_name)(self, target, amount) return - # check for token name if no custom minting - # logic exists for address - for name in _token_names: - if hasattr(self, "name") and self.name().startswith(name): - fn_name = f"mint_{name}" - if hasattr(sys.modules[__name__], fn_name): - getattr(sys.modules[__name__], fn_name)(self, target, amount) + # check for token name if no custom minting logic exists for address + if hasattr(self, "name") and not self.name.abi["inputs"]: + name = self.name() + fn_name = next((f"mint_{i}" for i in _token_names if name.startswith(i)), "") + if fn_name and hasattr(sys.modules[__name__], fn_name): + mint_result = getattr(sys.modules[__name__], fn_name)(self, target, amount) + if mint_result: return # if no custom logic, fetch a list of the top @@ -142,38 +142,6 @@ def mint_0x196f4727526eA7FB1e17b2071B3d8eAA38486988( token.mint(target, amount, {"from": token.minter()}) -def mint_0xfE18be6b3Bd88A2D2A7f928d00292E7a9963CfC6( - token: MintableForkToken, target: str, amount: int -) -> None: - # Synth sBTC - target_contract = Contract("0xDB91E4B3b6E19bF22E810C43273eae48C9037e74") - target_contract.issue(target, amount, {"from": _snx_exchanger()}) - - -def mint_0x5e74C9036fb86BD7eCdcb084a0673EFc32eA31cb( - token: MintableForkToken, target: str, amount: int -) -> None: - # Synth sETH - target_contract = Contract("0x87641989057242Bff28D0D6108d007C79774D06f") - target_contract.issue(target, amount, {"from": _snx_exchanger()}) - - -def mint_0xD71eCFF9342A5Ced620049e616c5035F1dB98620( - token: MintableForkToken, target: str, amount: int -) -> None: - # Synth sEURS - target_contract = Contract("0xC61b352fCc311Ae6B0301459A970150005e74b3E") - target_contract.issue(target, amount, {"from": _snx_exchanger()}) - - -def mint_0x57Ab1ec28D129707052df4dF418D58a2D46d5f51( - token: MintableForkToken, target: str, amount: int -) -> None: - # Synth sUSD - target_contract = Contract("0x6C85C5198C3CC4dB1b87Cb43b2674241a30f4845") - target_contract.issue(target, amount, {"from": _snx_exchanger()}) - - def mint_0x8dAEBADE922dF735c38C80C7eBD708Af50815fAa( token: MintableForkToken, target: str, amount: int ) -> None: @@ -229,14 +197,44 @@ def mint_0x9559Aaa82d9649C7A7b220E7c461d2E74c9a3593( token.mint(target, amount, {"from": minter}) -# to add custom minting logic for a token that starts with [NAME], add [NAME] to -# `_token_names` and add a function `mint_[NAME]` +# To add custom minting logic for a token that starts with [NAME], add [NAME] to `_token_names` +# and add a function `mint_[NAME]`. The function should include sanity-checks to prevent false +# positives, and return a bool indicating if the mint operation was successful. + +def mint_Aave(token: MintableForkToken, target: str, amount: int) -> bool: + # Aave aTokens + if not hasattr(token, "UNDERLYING_ASSET_ADDRESS"): + return False -def mint_Aave(token: MintableForkToken, target: str, amount: int) -> None: - # aave token token = MintableForkToken(token.UNDERLYING_ASSET_ADDRESS()) lending_pool = Contract("0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9") token._mint_for_testing(target, amount) token.approve(lending_pool, amount, {"from": target}) lending_pool.deposit(token, amount, target, 0, {"from": target}) + return True + + +def mint_Synth(token: MintableForkToken, target: str, amount: int) -> bool: + # Synthetix synths + if not hasattr(token, "target"): + return False + + abi = [ + { + "inputs": [{"name": "name", "type": "bytes32"}], + "name": "getAddress", + "outputs": [{"internalType": "uint256", "name": "", "type": "address"}], + "stateMutability": "view", + "type": "function", + } + ] + resolver = Contract.from_abi( + "AddressResolver", "0x4E3b31eB0E5CB73641EE1E65E7dCEFe520bA3ef2", abi + ) + exchanger_key = "0x45786368616e6765720000000000000000000000000000000000000000000000" + exchanger = resolver.getAddress(exchanger_key) + + target_contract = token.target() + target_contract.issue(target, amount, {"from": exchanger}) + return True diff --git a/setup.cfg b/setup.cfg index a8ac676..e8fc067 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.1 +current_version = 0.2.2 [bumpversion:file:setup.py] @@ -28,4 +28,3 @@ addopts = --cov brownie_tokens/ --cov-report term --cov-report xml - diff --git a/setup.py b/setup.py index df9ed17..0e44ac7 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ name="brownie-token-tester", packages=find_packages(exclude=["tests", "tests.*"]), py_modules=["brownie_tokens"], - version="0.2.1", # don't change this manually, use bumpversion instead + version="0.2.2", # don't change this manually, use bumpversion instead license="MIT", description="Helper objects for generating ERC20s while testing a Brownie project.", long_description=long_description,