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

Unable to fund relayer when using rootchain originated native token #2002

Conversation

Stefan-Ethernal
Copy link
Collaborator

@Stefan-Ethernal Stefan-Ethernal commented Oct 20, 2023

Description

This PR introduces the addGenesisBalance function on the CustomSupernetManager and integrates those changes in the Edge. It enables genesis accounts to lock root chain-originated Supernets native tokens on the RootERC20Predicate and be premined with the exact same amount of native tokens in the genesis time on a Supernets. This is especially significant for relayer nodes, because they are executing bridge transactions. Without this change, it was not possible to execute any bridge transaction with non-zero gas price transactions, which is the case for the London hard fork being enabled.

These commands were added:

  1. bridge mint-erc20 command - mints ERC20 tokens to specified addresses. It has these flags:
    --addresses - list of addresses for which ERC20 tokens should be minted (separated by a coma).
    --amounts - list of amounts of ERC20 tokens that should be minted to given addresses (separated by a coma).
    --erc20-token - address of the ERC20 token that should be minted.
    --private-key - private key of the ERC20 token deployer, since only token deployer can mint tokens.
    --jsonrpc - json RPC url to a node on chain on which mint transactions are sent.
    Please note that addresses and amounts flags need to be the same length.
  2. rootchain premine command - only used for non-mintable native ERC20 tokens on bootstrap of a Supernet. It locks the specified amount of native tokens on the RootERC20Predicate. Those tokens will than be premined in the genesis time on a Supernet, as described eariler. Each account that wants to have some non-mintable native ERC20 token premined on a supernet, needs to call this command itself, meaning that each validator, each relayer node, and any other node that wants to have some native ERC20 balance on Supernet from the genesis (in case of non-mintable token), needs to do this command.
    It has these flags:
    --data-dir - the directory for the Polygon Edge data if the local FS is used.
    --config - the path to the SecretsManager config file, if omitted, the local FS secrets manager is used.
    --private-key - hex-encoded private key of the account which executes command.
    --supernet-manager - address of the CustomSupernetManager contract on root.
    --erc20-token - address of the native root ERC20 token.
    --root-erc20-predicate - address of the RootERC20Predicate contract on root.
    --amount - amount of tokens to be premined.
    --jsonrpc - json RPC url to a node on root chain on which premine transactions are sent.
    Please note that --data-dir, --config and --private-key flags are mutually exclusive. The account who is calling the premine command needs to have that amount of native root ERC20 tokens. You can use the mint-erc20 command to mint him some before he premines.

Changes in deployment of a Supernet if non-mintable ERC20 native token is used

After the validators are whitelisted, registered and do the initial staking, premine to at least the relayer nodes have to be done as well. This should be the last step before the supernet command.
Here we can simply call mint-erc20 command to mint him some tokens first:

    $ polygon-edge bridge mint-erc20 \ 
       --erc20-token {address_of_native_root_erc20_token} \
       --private-key {hex_encoded_private_key_of_token_deployer} \
       --addresses {address_of_relayer_node} \
       --amounts {ammount_of_tokens_to_mint_to_relayer}

After this is done, relayer node needs to call the premine command:

    $ polygon-edge rootchain premine \ 
       --erc20-token {address_of_native_root_erc20_token} \
       --root-erc20-predicate {address_of_root_erc20_predicate_on_root} \
       --supernet-manager {address_of_CustomSupernetManager_contract_on_root} \
       --private-key {hex_encoded_private_key_of_relayer_node \
       --amount {ammount_of_tokens_to_premine}

After that, supernet command is called, which finalizes the stake and premined tokens on root, and signals that Supernet nodes can be started.

IMPORTANT: If non-mintable native ERC20 token is used, a custom reward token must be provided to genesis command through the -reward-token-code flag. (user provides hex encoded byte code of the custom ERC20 reward token). This is done because since non-mintable native ERC20 token originates on root, we can not just mint rewards on L2 in this case.

untitled

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Checklist

  • I have assigned this PR to myself
  • I have added at least 1 reviewer
  • I have added the relevant labels
  • I have updated the official documentation
  • I have added sufficient documentation in code

Testing

  • I have tested this code with the official test suite
  • I have tested this code manually

@Stefan-Ethernal Stefan-Ethernal changed the title Evm 865 unable to fund relayer when using rootchain originated native token Unable to fund relayer when using rootchain originated native token Oct 20, 2023
@Stefan-Ethernal Stefan-Ethernal force-pushed the EVM-865-unable-to-fund-relayer-when-using-rootchain-originated-native-token branch from 7583ccc to 003b62b Compare October 23, 2023 06:21
@Stefan-Ethernal Stefan-Ethernal added bug fix Functionality that fixes a bug feature New update to Polygon Edge labels Oct 25, 2023
@goran-ethernal goran-ethernal force-pushed the EVM-865-unable-to-fund-relayer-when-using-rootchain-originated-native-token branch 4 times, most recently from 2d8db65 to 2ebc4d3 Compare October 27, 2023 08:17
@Stefan-Ethernal Stefan-Ethernal force-pushed the EVM-865-unable-to-fund-relayer-when-using-rootchain-originated-native-token branch from 2ebc4d3 to a88d2ff Compare October 30, 2023 07:47
@goran-ethernal goran-ethernal force-pushed the EVM-865-unable-to-fund-relayer-when-using-rootchain-originated-native-token branch 2 times, most recently from de844fd to 0c6a692 Compare October 30, 2023 11:02
@goran-ethernal goran-ethernal force-pushed the EVM-865-unable-to-fund-relayer-when-using-rootchain-originated-native-token branch from 82fc683 to 210b4e2 Compare October 31, 2023 08:06
@Stefan-Ethernal Stefan-Ethernal force-pushed the EVM-865-unable-to-fund-relayer-when-using-rootchain-originated-native-token branch from ea7821a to c54e0b4 Compare October 31, 2023 08:16
@Stefan-Ethernal Stefan-Ethernal force-pushed the EVM-865-unable-to-fund-relayer-when-using-rootchain-originated-native-token branch from 4a66df4 to 6bb3a69 Compare October 31, 2023 08:48
@Stefan-Ethernal Stefan-Ethernal merged commit 9ace673 into develop Nov 3, 2023
6 of 7 checks passed
@Stefan-Ethernal Stefan-Ethernal deleted the EVM-865-unable-to-fund-relayer-when-using-rootchain-originated-native-token branch November 3, 2023 15:30
@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fix Functionality that fixes a bug feature New update to Polygon Edge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v1.3] Error when Bridging Rootchain ERC20 to Native Supernet Tokens
4 participants