- BEP-84: Mirror BEP20 to Binance Chain
This BEP proposes a scheme to facilitate users to issue and bind BEP2 tokens with existing BEP20 tokens.
Currently, if a user wants to issue and bind a BEP2 token with an existing BEP20 token, it has to do a set of complex operations, including issue BEP2 tokens, sending a bind transaction and approving the binding request. The BEP will bring a mechanism to simplify the above process. In the new mechanism, what anyone can do this is just sending a transaction to Binance Smart Chain.
Current bind mechanism is based on the context that our community members are on the Binance Chain and they want to extend their tokens to the Binance Smart Chain. However, with the evolution of our community, things changed. In most cases, users issue bep20 on the Binance Smart Chain first without considering whether they will issue BEP2 on the Binance Chain or not, so a new mechanism to conveniently extend BEP20 assets to the Binance Chain is required. In addition, the new mechanism will encourage users to extend their assets to the Binance Chain which is very helpful to flourish the Binance Chain community.
This BEP is already implemented
Two new permissionless methods will be imported into TokenManager contract: Mirror: If a BEP20 contract is not bound to any BEP2 token, anyone can call the mirror method to automatically issue a BEP2 token and bind them. The user is not required to have any BEP20 token and just needs to pay enough BEP2 issue fee. Besides, the BEP20 contract is even not required to implement getOwner method. After binding, all the initial circulation is on BSC. Sync: For a BEP20 token which has been mirrored to BC, anyone can call sync method to balance the total supply on BC and BSC. For example, someone mint some BEP20 token, after calling sync method, the equivalent token will be minted on BC and transferred to the pure-code-controlled-escrow address. If someone burn some BEP20 token, after calling sync method, the equivalent token will be burned on BC from the pure-code-controlled-escrow address.
Param Name | Type | Description |
---|---|---|
BEP20Addr | Address | BEP20 contract address |
ExpiredTime | uint64 | The deadline to deliver this package on BC |
msg.value | uint256 | Sum of cross chain fee and mirror fee |
- Ensure the BEP20 token hasn’t been bound before and is not in mirror pending status.
- Ensure the BEP20 symbol follows the BEP2 symbol requirements.
- Ensure the BEP20 name follows the BEP2 name requirements.
- Ensure the equivalent total supply is no greater than Max BEP2 total supply.
- Ensure msg.value >= MirrorFee + CrossChainFee and msg.value = N * 10^10
- Ensure expired time is earlier than one day later and no earlier than two minutes later.
- Transfer CrossChainFee to TokenHub
- Mark the BEP20 token as mirror pending status
- RLP Encode mirror package:
Param Name | Type | Description |
---|---|---|
MirrorSender | Address | Mirror sender |
BEP20Addr | Address | BEP20 token address |
BEP20Name | bytes32 | BEP20 token name |
BEP20Symbol | bytes32 | BEP20 token symbol |
BEP20Supply | uint256 | BEP20 total supply |
BEP20Decimals | uint8 | BEP20 decimals |
MirrorFee | uint256 | The mirror fee from users, which will be used to cover issue BEP2 token. |
ExpiredTime | uint64 | The package expired time, counted by second |
- Call CrossChain contract to send a cross chain package.
- If a BEP20 token is in mirror pending status or already mirrored, reject approveBind on it.
-
Fail ack package:
- RLP decode mirror package.
- Refund MirrorFee to mirror sender.
- Set the BEP20 pending mirror status to false
-
Ack package
Param Name Type Description MirrorSender Address Mirror sender BEP20Addr Address BEP20 token address BEP20Decimals uint8 BEP20 decimals BEP2Symbol bytes32 BEP2 token symbol MirrorFee uint256 Mirror fee from sync package ErrorCode uint8 1. Expired time is passed
2. Duplicated BEP2 symbol
3. Already bound
4. Unknown reason- RLP decode ack package.
- If ErrorCode is non-zero:
- Refund MirrorFee to mirror sender
- Emit bound failure event
- If ErrorCode is zero:
- Transfer SyncFee to TokenHub
- Write the bound pair to TokenHub
- Mark the bep20 token as bound by mirror
- Emit bound success event
Param Name | Type | Description |
---|---|---|
BEP20Addr | Address | BEP20 contract address |
ExpiredTime | uint64 | The deadline to deliver this package on BC |
msg.value | uint256 | Sum of cross chain fee and sync fee. |
- Ensure the BEP20 is bound by mirror.
- Ensure msg.value >= SyncFee + CrossChainFee and msg.value = N * 10^10
- Ensure the equivalent total supply on BC doesn’t exceed the maximum limit
- Ensure expired time is earlier than one day later and no earlier than two minutes later.
-
Transfer CrossChainFee to TokenHub
-
RLP encode sync total supply package:
Param Name Type Description SyncSender Address Sync sender BEP20Addr Address BEP20 token address BEP2Symbol bytes32 BEP2 token symbol BEP20Supply uint256 BEP20 total supply SyncFee uint256 Sum of cross chain fee and sync fee ExpiredTime uint64 The package expired time, counted by second -
Call CrossChain contract to send a cross chain package.
-
Fail ack package:
- RLP decode sync total supply package.
- Refund SyncFee to users.
-
Ack package:
Param Name Type Description SyncSender Address Sync sender BEP20Addr Address BEP20 token address SyncFee uint256 Sync fee from sync package ErrorCode uint8 1. Not bound by mirror
2. Expired time is passed
3. Unknown reason- RLP decode ack package.
- If ErrorCode is non-zero:
- Refund SyncFee to sync sender
- Emit sync failure event
- If ErrorCode is zero:
- Transfer SyncFee to TokenHub
- Emit sync success event
Two governance parameters will be imported into TokenManager contract: MirrorFee and SyncFee. TokenManager contract needs to implement the following method: function updateParam(string calldata key, bytes calldata value)
Key | Value | Value Type |
---|---|---|
"BEP2MirrorFee" | BEP2 mirror fee | uint256 |
"BEP2SyncFee" | BEP2 sync fee | uint256 |
- RLP decode mirror package. Generate a fail ack package if failed.
- Ensure expiredTime is not passed.
- Ensure the bep20 contract is not bound.
- Convert BEP20 total supply to the total supply on BC and Ensure the total supply doesn’t exceed the maximum limit of BEP2.
- Issue a new BEP2 token, the suffix should be the hash of oracle payload and current channel sequence. Besides, the new BEP2 token owner will be the pure-code-controlled-escrow address.
- Transfer all tokens to the pure-code-controlled-escrow address and write BEP20 address and decimals to the BEP2 token attribution table.
- Unlock mirror fee from peg account to BC fee pool, so that validators can get these fees.
- If all above steps are successful, generate a success ack package. The mirrorFee in ack package should equal to the value in sync package. Otherwise, generate an ack failure package.
- RLP decode mirror package. Generate a fail ack package if failed.
- Ensure expiredTime is not passed
- Convert BEP20 total supply to BEP2 total supply and ensure the total supply doesn’t exceed the maximum limit of BEP2.
- Mint/Burn
- BSC total supply > BC total supply, mint BEP2 and transfer all new minted tokens to the pure-code-controlled-escrow address.
- BSC total supply == BC total supply, nothing to do
- BSC total supply > BC total supply, burn BEP2 from the pure-code-controlled-escrow address.
- Unlock sync fee from the pure-code-controlled-escrow address to BC fee pool.
- If all above steps are successful, generate a success ack package. The mirrorFee in ack package should equal to the value in sync package. Otherwise, generate an ack failure package.
After BC and BSC are both upgraded, submit a proposal on BC to add two channels:
- Mirror channel
- Channel id: 4
- Handler address: 0x0000000000000000000000000000000000001008
- Is reward from systemReward: false
- Sync total supply channel:
- Channel id: 5
- Handler address: 0x0000000000000000000000000000000000001008
- Is reward from systemReward: false
The content is licensed under CC0.