Programmability support in the Plasma Next Mainnet is currently under development. The contents of this document cannot be tested on the Mainnet at present. Please wait until the support is fully implemented.
We will implement ZKPTLC on Plasma Next for Atomic Swaps between ETH on Plasma and an NFT on L1. ZKPTLC verifies that the Merkle Proof has been passed from the Operator to Bob. This allows for two transfers. One is a payment of ETH from Alice to the Operator through a payment channel. The other is the transfer of an NFT from Bob to Alice on L1. The transfer of the NFT is done using a deposit & withdraw method because if the Operator does not pass the Merkle Proof to Bob, the transfer of the NFT must be cancelled.
Let's calculate the instance. The instance must include information such as the type of NFT and details of the transaction, like who is sending to whom. It should also include a transfer on the PN from the Operator to Bob.
Here, instanceSetAt is a mapping that manages when the deposit was made.
mapping(bytes32=>uint256) public instanceSetAt;
Withdrawal can be performed by submitting an evidenceMerkleProof which provides evidence that a transfer has been made from the Operator to Bob.
functionwithdraw(address from,address nftContract,uint256 tokenId,ITransfer.Transfermemory transfer,IMerkleProof.EvidenceWithMerkleProofmemory proof) external {bytes32 instance =computeInstance( from, msg.sender, nftContract, tokenId, transfer );require(instanceSetAt[instance] !=0,"Instance does not exist"); instanceSetAt[instance] =0;_verifyExistence(transfer, proof);IERC721(nftContract).transferFrom(address(this), msg.sender, tokenId);}
If a certain amount of time has elapsed since the deposit, Bob will be able to cancel. The cancellation period needs to be longer than the three-day challenge period of Plasma Next's withdraw request. This is to ensure that if the Operator withholds the Merkle Proof from Bob and challenges Alice's withdraw request at the very end of the challenge period, thus revealing the Merkle Proof to Bob, Alice can acquire Carol's NFT.
functioncancell(address to,address nftContract,uint256 tokenId,ITransfer.Transfermemory transfer) external {bytes32 instance =computeInstance( msg.sender, to, nftContract, tokenId, transfer );require(instanceSetAt[instance] !=0,"Instance does not exist");require( instanceSetAt[instance] +4days< block.timestamp,"Instance is not expired" ); instanceSetAt[instance] =0;IERC721(nftContract).transferFrom(address(this), msg.sender, tokenId);}
The verifyCondition simply ensures that a transfer from the Operator to Bob exists on Plasma Next, just like the default ZKPTLC.