High Level Flow
Deposit ERC20 -
- Approve ERC20Predicate contract to spend the tokens that have to be deposited.
- Make depositFor call on RootChainManager.
Withdraw ERC20 -
- Burn tokens on matic chain.
- Call exit function on RootChainManager to submit proof of burn transaction. This call can be made after checkpoint is submitted for the block containing burn transaction.
Configuring Matic SDK
Install Matic SDK (2.0.2)
While creating MaticPOSClient object network,version,maticProvider, parentProvider, posERC20Predicate and posRootChainManager need to be provided.
This is a normal ERC20 approval so that ERC20Predicate can call transferFrom function. Matic POS client exposes approveERC20ForDeposit method to make this call.
Deposit can be done by calling depositFor on RootChainManager contract. Note that token needs to be mapped and approved for transfer beforehand. Once tokens are transferred deposit proceeds using StateSync mechanism. Matic POS client exposes depositERC20ForUser method to make this call.
deposit function of ChildToken is called by the ChildChainManager. Tokens should be minted when this call is made.
User can call withdraw function of ChildToken contract. This function should burn the tokens. Matic POS client exposes burnERC20 method to make this call.
Store the transaction hash for this call and use it while generating burn proof.
Once the checkpoint has been submitted for the block containing burn transaction, user should call the exit function of RootChainManager contract and submit the proof of burn. Upon submitting valid proof tokens are transferred to the user. Matic POS client exposes exitERC20 method to make this call.