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

No meta tokens #504

Merged
merged 4 commits into from
Feb 1, 2023
Merged

No meta tokens #504

merged 4 commits into from
Feb 1, 2023

Conversation

swansontec
Copy link
Contributor

@swansontec swansontec commented Jan 31, 2023

This removes metaTokens from all our currency info's.

A big goal here is to have a common source of truth for each currency's tokenId's, so there is no risk of a human or a plugin being inconsistent. We also want to be really clear about what code lives in "info land", and is therefore cheap to load, and which code lives in "currency land", and is therefore expensive to load.

The engines may still refer to these legacy tokens internally, so that still needs to be cleaned up in another PR. We do pass the builtin tokens in our PluginEnvironment, so the engine has access to them.


Copy link
Member

@paullinator paullinator left a comment

Choose a reason for hiding this comment

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

Definitely the direction we want to head in! Main request is to go-all-the-way and use EdgeTokenMap for the built-in tokens

tokens[tokenId]

const cleanLocation = asMaybeContractLocation(networkLocation)
if (cleanLocation == null) continue
Copy link
Member

@paullinator paullinator Feb 1, 2023

Choose a reason for hiding this comment

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

if an plugin doesn't use contractAddress in EdgeMetaToken (xrp doesn't) then you won't get any metatokens. Is this okay? If not, you should probably do the inverse and check if a plugin has metaTokens defined, if so then use them. If not, then derive them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made this up to the plugins to decide. Tron and all the EVM's are calling metaTokens: makeMetaTokens(builtinTokens) in their currencyInfo's, but the Ripple plugin can do whatever it needs to make this work.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. got it.

contractAddress: asString
})

export function getEosTokenId(token: EdgeToken): string {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't feel clean to have asset specific logic in a common file. I would prefer to move these to asset specific files. Besides, they are only used by those specific asset files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I deleted all of them, and just left the common cleaner.

import { EthereumFees, EthereumSettings } from '../ethTypes'
import type { EthereumFees, EthereumSettings } from '../ethTypes'

const builtinTokens: EdgeTokenMap = makeTokenMap(getEvmTokenId, [
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. I'm not liking that the "source of truth" is in a weird array format that's neither the old or new EdgeTokenMap. Why not just use an EdgeTokenMap? That's how XRP is coded.

Copy link
Member

Choose a reason for hiding this comment

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

Admittedly you'd want some code to automate the conversion the first time but then you're done and can commit the results. Given that the format of the EdgeMetaToken array and the new array are different, I presume you did use automation to do the conversion. Might as well go straight to a token map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did the conversion using regular expression search & replace. For the EdgeTokenMap conversion, I had to do it by hand. Now that it's done, we have unit tests to ensure that it always stays correct going forward.

metaTokens: [
// Array of objects describing the supported metatokens
]
metaTokens: [] // Deprecated
Copy link
Member

Choose a reason for hiding this comment

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

Wow. how do we not have any tokens on BSC?

They are mixing `require` and `export` in a bad way that breaks Sucrase.
The old `metaTokens` are deprecated.
@swansontec swansontec force-pushed the william/no-meta-tokens branch from 48a34df to 1ec71c8 Compare February 1, 2023 10:48
@@ -0,0 +1,31 @@
diff --git a/node_modules/@tronscan/client/src/utils/tronWeb.js b/node_modules/@tronscan/client/src/utils/tronWeb.js
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have submitted this patch upstream at tronscan/tronscan-node-client#26

Copy link
Member

@paullinator paullinator left a comment

Choose a reason for hiding this comment

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

This looks great. Much cleaner and really motivates deprecating EdgeMetatoken.

Just one concern about Tron that's more of a question.

import { TronNetworkInfo } from './tronTypes'
import type { TronNetworkInfo } from './tronTypes'

const builtinTokens: EdgeTokenMap = {
Copy link
Member

Choose a reason for hiding this comment

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

The previous code flow is a bit tough to follow, but wouldn't Tron tokens also go through the loadInnerPlugin() routine which calls upgradeMetaTokens which would have lowercased the tokenIds? This is what I ran into when implementing XRP even though my getTokenId didn't do the lowercasing. While the true upper/lower case tokenIds would have been preferred for Tron, we might have tokenIds already saved in user's accounts that are all lowercase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After a sidebar with Matthew to discuss pros & cons, we have decided to go ahead and change the tokenId's. We have a plan for dealing with the fallout, which isn't as terrible as we thought at first.

@swansontec swansontec merged commit 5121e7e into master Feb 1, 2023
@swansontec swansontec deleted the william/no-meta-tokens branch February 1, 2023 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants