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

Common getTokenType used on UI, monitor and Oracle #165

Merged
merged 12 commits into from
Jul 26, 2019
Merged

Conversation

rzadp
Copy link
Contributor

@rzadp rzadp commented Jul 24, 2019

@rzadp
Copy link
Contributor Author

rzadp commented Jul 24, 2019

I'm having trouble understanding usage of getTokenType in monitor. It seems to me like there is an error.

In Oracle and UI, the first parameter of getTokenType is the bridge token contract with ERC677_BRIDGE_TOKEN_ABI, which has address public bridgeContract;

However, in monitor, foreign bridge contract is used as the first parameter of getTokenType. So the bridgeContract().call() always fails because there is no such field, and the getTokenType falls back to erc20.

So it seems to me like currently Monitor is broken and does not work with erc677 bridge token.

@akolotov @patitonar Could you please take a look?
Should we add ERC20_TOKEN_ADDRESS env variable to monitor/.env.example and check the token type in the same way as in oracle and ui?

@rzadp
Copy link
Contributor Author

rzadp commented Jul 24, 2019

@akolotov @patitonar
On another note - In e2e-commons, we have 3 types of bridges:

  1. native-to-erc
  2. erc-to-native
  3. erc-to-erc, with ERC20_EXTENDED_BY_ERC677=false

These 3 types of bridges are tested in oracle-e2e and ui-e2e (and pending #115 for monitor-e2e)

Should we maybe test 4th type of bridge - erc-to-erc, with ERC20_EXTENDED_BY_ERC677=true?
I imagine the error I commented above, would be caught in monitor-e2e if we tested 4 types of bridge.

@akolotov akolotov mentioned this pull request Jul 24, 2019
@patitonar
Copy link
Contributor

Good catch @rzadp! It seems the monitor is not using getTokenType correctly. As you mention it should be using ERC677_BRIDGE_TOKEN_ABI and the address of the token.

There is no need to add a new env variable since we are getting the address of the token from the foreign bridge contract in the following line:

https://github.com/poanetwork/tokenbridge/blob/5d22ad1ecb9d22968479443c95b47dd45763e8f6/monitor/utils/events.js#L38

Regarding the e2e test for this 4th bridge scenario (erc-to-erc with ERC20_EXTENDED_BY_ERC677=true) it does makes sense to me to prevent this kind of issues. If @akolotov agree, we can create an issue for this

@rzadp
Copy link
Contributor Author

rzadp commented Jul 24, 2019

@patitonar In the line you referenced, there is erc20MethodName which is either erc677token or erc20token, regardless of the results of getTokenType.

Seems like a chicken-and-egg situation, when we cannot use getTokenType without having token address, and cannot get token address without knowing if it is erc677token or erc20token

@patitonar
Copy link
Contributor

@rzadp The code is kind of confusing for this. The erc20MethodName method to use in monitor is calculated on a similar way as in UI:

https://github.com/poanetwork/tokenbridge/blob/5d22ad1ecb9d22968479443c95b47dd45763e8f6/ui/src/stores/ForeignStore.js#L184-L188

To know which method use to get the token address from the bridge contract we need to know the bridge mode, we don't need the result of getTokenType. The getTokenType method is used to get specific information from the token contract to know later how to process the events of the bridge.

@rzadp
Copy link
Contributor Author

rzadp commented Jul 24, 2019

@patitonar Thanks for clarifying!

So, to make sure I understand:

  1. Depending on bridge type, we use erc677token().call() or erc20token().call() methods to get token address - it does not determine whether the token is really erc677 or erc20.
  2. Using that token address, we call getTokenType and determine whether it's actually erc677 or erc20.

It that correct?

@rzadp rzadp added the shared shared components label Jul 24, 2019
@patitonar
Copy link
Contributor

@rzadp That's correct!

@rzadp rzadp changed the title [WIP] getTokenType used on UI, monitor and Oracle Common getTokenType used on UI, monitor and Oracle Jul 25, 2019
@rzadp rzadp marked this pull request as ready for review July 25, 2019 12:29
@rzadp
Copy link
Contributor Author

rzadp commented Jul 25, 2019

I've done the changes and the PR is ready for review.

@akolotov
Copy link
Collaborator

Should we maybe test 4th type of bridge - erc-to-erc, with ERC20_EXTENDED_BY_ERC677=true?

We already have an issue for this: #56. Let's address it separately.

@akolotov akolotov requested review from patitonar and akolotov July 26, 2019 07:53
Copy link
Collaborator

@akolotov akolotov left a comment

Choose a reason for hiding this comment

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

Please merge after @patitonar approval

@rzadp rzadp merged commit c669238 into master Jul 26, 2019
@rzadp rzadp deleted the commons-getTokenType branch July 26, 2019 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shared shared components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants