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: handle nam as denominated amount #1301

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mateuszjasiuk
Copy link
Collaborator

@mateuszjasiuk mateuszjasiuk commented Nov 22, 2024

Indexer part: anoma/namada-indexer#157
Issue: anoma/namada-indexer#156

Changes:

  • We do not have to denominate NAM manually in namadillo
  • Added envs so you can optionally develop against localnet. You have to specify: VITE_LOCALNET=true, VITE_LOCALNET_CHAIN_ID, VITE_LOCALNET_NAM_TOKEN
  • added localnet-config.toml, by default added to gitignore. You can add it to namadillo/public/localnet-config.toml if you want to develop against local chain. Example file:
# Localnet configuration file
enabled = true
chain_id = "local.040061ff54009d1fb42c0ac5"
token_address = "tnam1qxp7u2vmlgcrpn9j0ml7hrtr79g2w2fdesteh7tu"

@mateuszjasiuk mateuszjasiuk force-pushed the feat/handle-queried-nam-as-denominated-amount branch from c4220b5 to 97750a1 Compare November 22, 2024 12:02
@mateuszjasiuk mateuszjasiuk marked this pull request as draft November 22, 2024 12:04
@mateuszjasiuk mateuszjasiuk force-pushed the feat/handle-queried-nam-as-denominated-amount branch from 97750a1 to 0f1d83d Compare November 22, 2024 12:53
@mateuszjasiuk mateuszjasiuk force-pushed the feat/handle-queried-nam-as-denominated-amount branch from 0f1d83d to afbcacc Compare November 22, 2024 13:06
@mateuszjasiuk mateuszjasiuk marked this pull request as ready for review November 22, 2024 13:07
@mateuszjasiuk mateuszjasiuk force-pushed the feat/handle-queried-nam-as-denominated-amount branch from 5bc89d8 to ebc47b3 Compare November 22, 2024 14:42
@mateuszjasiuk mateuszjasiuk force-pushed the feat/handle-queried-nam-as-denominated-amount branch from f333ac5 to dd3a3ae Compare November 25, 2024 09:53

// We can't return "satisfies Asset" from fn
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const namadaAsset = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm removing this implementation and moving it to namada-chain-registry #1308

Do you think it could have some impact here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be fine I can fix conflict later

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, the conflict arrived 🙈 #1308

"ts-jest",
{
diagnostics: {
ignoreCodes: [1343],
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add some reference why we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can try xD

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tbh with current solution this might not be needed. Just jest is having problems resolving import.meta.env syntax. I will remove this all togehter if it works fine witout it

Copy link
Collaborator

@emccorson emccorson left a comment

Choose a reason for hiding this comment

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

Looks good to me! I just found a couple of things that might not be working.

...internalDevnetAssets,
chain_name: "localnet",
assets: internalDevnetAssets.assets.map((asset) =>
asset.name === "NAM" ?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not going to work once we're using the registry with anoma/namada-chain-registry#13 merged. Maybe could use "Namada" or check against symbol or base instead?


export const toDisplayAmount = (
asset: Asset,
baseAmount: BigNumber
): BigNumber => {
if (isNamAsset(asset)) return baseAmount;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this won't work for NAM transferred from other chains. The indexer will return the balances in display denom for NAM from the current chain, but in base denom for NAM from other chains. But this check here will assume any token with symbol as NAM is in display denom.

I was wondering if this check should be outside the toDisplayAmount function anyway, since to me it seems like that logic is outside of the scope of the function. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I just also realised I think it's not going to work for displaying NAM on Cosmos chains either. The NAM balance we get from a Cosmos chain will be in base denom, but this check will stop it being converted to display denom.

Copy link
Collaborator Author

@mateuszjasiuk mateuszjasiuk Nov 26, 2024

Choose a reason for hiding this comment

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

yeah maybe moving this outside makes sense :D Just so I understand better, what do you mean by "NAM transferred from other chains." For NAM to arrive on other chain it first has to be sent from namada chain. So if we send NAM to cosmos and we send it back, will be it treated as different token than regular NAM?

Copy link
Collaborator

@emccorson emccorson Nov 26, 2024

Choose a reason for hiding this comment

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

The two cases I think won't work are:

  1. NAM that has been sent to a Cosmos chain (since the balance query for cosmjs returns amounts in base denom)
  2. NAM from something other than the current chain e.g. your current chain is housefire but you sent some NAM from internal devnet to housefire

In both cases, these should display properly as the Namada asset in Namadillo, but the denomation will be wrong in this PR because Namadillo thinks it's already in display denom but it's actually in base denom.

The case you're talking about where you send NAM from Namada to Cosmos and then back should work fine I think, because the indexer will still return the balance using the original tnam address and in display denom (as far as I know).

(Also, even though in case 2, the NAM from internal devnet displays as the Namada asset, it is a different thing from NAM from housefire, but we don't actually indicate that anywhere right now.)

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.

3 participants