Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add Superfluid Oracle token adapter #381

Merged
merged 1 commit into from
Oct 24, 2022
Merged

Conversation

brymut
Copy link
Contributor

@brymut brymut commented Oct 24, 2022

As a continuation from here: safe-global/safe-transaction-service#772 (comment)

This work contributes towards adding a price data for Superfluid Super Tokens with the price data of their underlying tokens.
This PR adds the Superfluid Oracle token adapter and related test.

Related Issue: safe-global/safe-transaction-service#772

Original issue: superfluid-finance/protocol-monorepo#732

@brymut brymut requested a review from a team as a code owner October 24, 2022 11:13
@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2022

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@brymut
Copy link
Contributor Author

brymut commented Oct 24, 2022

I have read the CLA Document and I hereby sign the CLA

@brymut

This comment was marked as resolved.

github-actions bot added a commit that referenced this pull request Oct 24, 2022
@brymut
Copy link
Contributor Author

brymut commented Oct 24, 2022

Hi @Uxio0, this is a continuation of this: safe-global/safe-transaction-service#772 (comment). I'd appreciate your feedback on this and direction for next steps. 🙂

Comment on lines 576 to 577
if not (Web3.isChecksumAddress(token_address)):
token_address = Web3.toChecksumAddress(token_address.lower())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for these 2 lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was getting errors in the testing, but I'll remove if the token_address here has already been checked when Oracle in cuse. For reference:

web3.exceptions.InvalidAddress: ('Web3.py only accepts checksum addresses. The software that gave you this non-checksum address should be considered unsafe, please file it as a bug on their platform. Try using an ENS name instead. Or, if you must accept lower safety, use Web3.toChecksumAddress(lower_case_address).', '0x1dbc1809486460dcd189b8a15990bca3272ee04e')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because you are using not checksummed addresses in the tests

@@ -245,6 +246,38 @@ def test_get_price(self):
cream_oracle.get_price(Account.create().address)


class TestSuperfluidOracle(EthereumTestCaseMixin, TestCase):
def test_get_price(self):
ethereum_client_polygon = EthereumClient("https://polygon-rpc.com")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like hardcoding nodes here as it will add more dependencies and point of failures during testing, is there any chance that you could use mainnet as the other end to end tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tokens not on mainnet, query will fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then please implement something like this for Polygon using an environment variable `ETHEREUM_POLYGON_NODE: https://github.com/safe-global/safe-transaction-service/blob/master/safe_transaction_service/history/tests/utils.py#L7

Leave out Arbitrum as it's too many dependencies and if it works for Polygon it should work for Arbitrum

@@ -544,6 +546,48 @@ def get_price(self, token_address: str) -> float:
)


class SuperfluidOracle(PriceOracle):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create the oracle in gnosis/eth/oracles/superfluid.py , we are doing that for the new oracles and will be migrating the old ones, that way it's easier to maintain

@brymut
Copy link
Contributor Author

brymut commented Oct 24, 2022

Applied changes from feedback @Uxio0

Copy link
Member

@Uxio0 Uxio0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fix the environment variable name and I will merge

@@ -40,6 +40,36 @@ def just_test_if_mainnet_node() -> str:
return mainnet_node_url


def just_test_if_polygon_node() -> str:
polygon_node_url = os.environ.get("POLYGON_NODE")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, but please use ETHEREUM_POLYGON_NODE (as we use ETHEREUM as the namespace for RPC related stuff)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated @Uxio0

Copy link
Member

@Uxio0 Uxio0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really neat code, thank you for your PR

@coveralls
Copy link

coveralls commented Oct 24, 2022

Pull Request Test Coverage Report for Build 3313527665

  • 11 of 20 (55.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 83.8%

Changes Missing Coverage Covered Lines Changed/Added Lines %
gnosis/eth/oracles/superfluid.py 11 20 55.0%
Totals Coverage Status
Change from base Build 3298643468: 0.05%
Covered Lines: 3290
Relevant Lines: 3926

💛 - Coveralls

@brymut
Copy link
Contributor Author

brymut commented Oct 24, 2022

Really neat code, thank you for your PR

Thanks for the support too!

@Uxio0 Uxio0 merged commit d1f9d2c into safe-global:master Oct 24, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants