BTP Token Service (BTS) is a service handler smart contract responsible for token transfer operations.
Since BTS is a service handler, it should be registered to BMC and should implement the BSH interface as well.
BTS is responsible for Token Transfer Operations, and should implement the following 3 eventlogs.
Similarly, the handleBTPMessage method should handle
- TokenTransferRequest
- TokenTransferResponse
- BlacklistMessage
- ChangeTokenLimitMessage
- Event
- TransferStart
- Params
Name Type Description _from address Address of sender (indexed) _to String BTP Address of destination _sn Integer Serial number of the message. _assetDetails Bytes Name of coin and amount to transfer - Description
- Indicates transfer has originated.
- Emitted by BTS of source chain
- Event
- TransferReceived
- Params
Name Type Description _from string BTP Address of BMC of sender's chain (indexed) _to String receiver address(indexed) _sn Integer Serial number of the message. _assetDetails Bytes Name of coin and amount to transfer - Description
- Emitted by BTS of destination chain
- Indicates transfer successful on destination chain
- Event
- TransferEnd
- Params
Name Type Description _from address Address of sender (indexed) _to String BTP Address of destination _sn Integer Serial number of the message. _response String/Byte Response message - Description
- Emitted by BTS of source chain
- Indicates message of transfer successful on destination chain has been recieved on source chain
- REQUEST_COIN_TRANSFER = 0
- REQUEST_COIN_REGISTER = 1
- REPONSE_HANDLE_SERVICE = 2
- BLACKLIST_MESSAGE = 3
- CHANGE_TOKEN_LIMIT = 4
- UNKNOWN_TYPE = 5
- Handled on destination chain
- Token transfer originates on source chain, and Message event is generated, which is picked up by the BMV and calls handleRelayMessage with message as parameter on the BMC on destination chain and it calls handleBTPMessage of the BTS Contract.
- The Message event generated by source among other info, should have:
- code for BTSMessage.REQUEST_COIN_TRANSFER (0)
- from, to, name and amount of tokens to be tranferred
- BTS Contract of destination decodes the message and knows the message is a token transfer request chain.
- The TransferRequest contains information about from, to (address on destination chain to which the tokens are to be transferred), name and amount of tokens to transfer to
to
address. - Check if the address is blacklisted or amount exceeds token transfer limit.
- The amount is transferred/minted to
to
adddress and if successful, emits a TransferReceived event and a successful Message event. - Error handling if token transfer request was not successful, and a unsuccessful Message event.
- Handled on source chain
- Recieved once token transfer operation is done on destination chain and destination chain sends a Message event with code for successful/unsuccessful transfer operation.
- The Message event generated by source among other info, should have:
- code for BTSMessage.REPONSE_HANDLE_SERVICE (2)
- code for successful/failed transfer operation on destination chain
- For successful response, burn equivalent amount minus fees of that token on source chain that were minted on destination chain (burn only if the token is wrapped token)
- For unsuccessful response, refund the amounts to address on source chain by deducting the fee.
- Generate a TransferEnd event.
- Blacklist originates on ICON network, and other chains should handle blacklist message on handleBTPMessage method on the BTS contract.
- The Message event includes the following info among others:
- code for BTSMessage.BLACKLIST_MESSAGE (3)
- code for whether to add to blacklist or remove from blacklist
- addresses to blacklist/remove on the destination chain
- Destination BTS should maintain a data structure for to keep track if the address is blacklisted. A mapping/hashmap of addresses with key as address and value boolean is enough
- Check if the address is a valid address, and then add/remove the address to/from blacklist.
- Error handling in case adding/removing is not successful
- Send Message back to ICON whether adding/removing to/from blacklist was successful or not.
- Check for blacklist on each token transfer operations
- Token Limit originates on ICON network, and other chains should handle token limit message on handleBTPMessage method on the BTS contract.
- The Message event includes the following info among others:
- code for BTSMessage.CHANGE_TOKEN_LIMIT (4)
- array of coin names and respective amount as token limit
- array of coin names and limits for those coins
- Destination BTS should maintain a data structure for to keep track of token limit. A mapping/hashmap with key as coinNames and value as uint for token limit is enough
- Set token limit for coinNames
- Error handling in case this operation is unsuccessful
- Send Message back to ICON whether token limit operation is successful or not.
- Check for tokenlimit for that coinName on each token transfer operation