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

Fix canColonyMintNativeToken resover to work with all tokens #3273

Merged
merged 1 commit into from
Mar 29, 2022

Conversation

rdig
Copy link
Member

@rdig rdig commented Mar 28, 2022

The current implementation of this resolver assumes that all tokens have the authority() function built in their contract, but this is rather of our doing, so only Colony Contract created tokens do have it. Others might not (most likely will not)

Due to this, if a colony will have been created using an external token (in this case the actual metacolony), the dapp will actually crash as we don't handle this case.

Even worse, tokens might be able to be minted, even if they don't have the authority method, as the mint function is somewhat standard on most, and the user creating the colony might actually be the owner of said token, so we need to check for that as well.

For this I've chosen to go the "estimate route", by estimating gas on the call to mint, and if it succeeds assume the user can mint, and if it fails, they can't.

This approach should cover most cases

Testing

This is quite tricky to test (it's actually easier on QA), but I'll try to do my best to explain how to.

1. Start the truffle console

Inside the src/lib/colonyNetwork folder, run yarn truffle console (or ./node_modules/.bin/truffle console)

2. Deploy a new "non-standard" token. We'll use ERC20PresetMinterPauser since it's available to us already.

Inside the truffle console, run:

tk = await ERC20PresetMinterPauser.new("Token Name", "TKN")

then

tk.address

3. Create a new colony via the Dapp and use the above address as an external token (don't create a new token)

Once created, if the colony loads, and doesn't show the "Mint" and "Unlock" menu entries in the "Actions" menu, then this fix worked.

Changes

  • canColonyMintNativeToken resolver in the colony resolvers file

@rdig rdig requested a review from a team March 28, 2022 12:35
@rdig rdig self-assigned this Mar 28, 2022
@rdig rdig added the bug label Mar 28, 2022
Copy link
Member

@arrenv arrenv left a comment

Choose a reason for hiding this comment

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

@rdig I like the approach, I will have to remember this one. It is working well for me.

Tested with newly created token:

download (25)

Tested with existing token and permission:

download45

Test with existing token and no permission

download (26)

Test with existing token and no permission and Motions & Disputes extension

download (26)

download (27)

Copy link
Contributor

@chinins chinins left a comment

Choose a reason for hiding this comment

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

I like this approach too!

Copy link
Contributor

@ArmandoGraterol ArmandoGraterol left a comment

Choose a reason for hiding this comment

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

Didn't know that you could also do this to check if the colony can mint! TIL

@rdig rdig force-pushed the fix/colony-token-unlock-resolver branch from ff884cd to 25e9f56 Compare March 29, 2022 15:08
@rdig rdig merged commit 01d8afe into master Mar 29, 2022
@rdig rdig deleted the fix/colony-token-unlock-resolver branch March 29, 2022 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants