This repository is aimed at providing reference implementations for very standard actions done in and out of the MagicBlock's Ephemeral Rollups engine's runtime.
This crate provide an example implementation on how to wrap/unwrap Lamports (SOL) and SPL Tokens in and out of the Ephemeral Rollups.
For escrowing/wrapping lamports, the following IX are provided:
lamport_escrow_create-> Create a newLamportEscrowaccount, holding escrowed lamports (is controlled by an "authority" wallet)lamport_escrow_claim-> The "authority" wallet can withdraw the lamports contained in theLamportEscrowto any wallet (can be used both on-chain and in the ER)lamport_escrow_delegate-> Delegate theLamportEscrowinto the ER (becomes unusable on-chain)lamport_escrow_undelegate-> Undelegate theLamportEscrowback out from the ER (becomes usable again on-chain)
A typical example scenario could like like this:
lamport_escrow_createis called, creating anwallet1_lamport_escrowowned bywallet1on-chainwallet2transfers lamports into thewallet1_lamport_escrowlamport_escrow_delegateis called, delegating thewallet1_lamport_escrowinto the ERwallet1can now claim all available lamports usinglamport_escrow_claimfrom INSIDE the ERlamport_escrow_undelegatecan optionally be called to be able to claim remaining lamports from the chain later
For escrowing/wrapping SPL tokens, the following IX are provided:
token_escrow_create-> Create a newTokenEscrowaccount representing a wallet's escrowed token balance (controlled by an "authority" wallet)token_escrow_deposit-> Deposit a SPL token account balance into aTokenEscrowpreviously created (can only be used on-chain)token_escrow_transfer-> Transfer an amount of escrowed token from aTokenEscrowto anotherTokenEscrow(can be used both on-chain and in the ER)token_escrow_withdraw-> Withdraw aTokenEscrowbalance back into a SPL token account (can only be used on-chain)token_escrow_delegate-> Delegate theTokenEscrowinto the ER (becomes unusable on-chain)token_escrow_undelegate-> Undelegate theTokenEscrowback out from the ER (becomes usable again on-chain)
A typical example scenario could look like this:
token_escrow_createis called on chain forwallet1, creating awallet1_token_escrowtoken_escrow_depositis called on chain, depositing some tokens intowallet1_token_escrowtoken_escrow_delegateis called, movingwallet1_token_escrowinto the ERtoken_escrow_createis called on chain forwallet2, creating awallet2_token_escrowtoken_escrow_delegateis called, movingwallet2_token_escrowinto the ERtoken_escrow_transferis called, moving funds fromwallet1_token_escrowintowallet2_token_escrow, all heppening in the ERtoken_escrow_undelegateis called forwallet2_token_escrow, bringing it back to chaintoken_escrow_withdrawis then called bywallet2to withdraw regular SPL tokens fromwallet2_token_escrowon-chain
It's possible to escrow cNFT to the ER so that they can be traded/transfered as part of ER transactions. The following IXs are provided:
bubblegum_escrow_deposit-> Create a newBubblegumEscrowaccount representing the wrapped cNFT, initially owned by the depositor's chosen authority walletbubblegum_escrow_transfer-> Transfer ownership of the wrapped cNFT to a new authority wallet (can be used both on-chain and in the ER)bubblegum_escrow_withdraw-> Destroy theBubblegumEscrowand return the cNFT back to the specified owner (can only be used on-chain)bubblegum_escrow_delegate-> Delegate theBubblegumEscrowinto the ER (becomes unusable on-chain)bubblegum_escrow_undelegate-> Undelegate theBubblegumEscrowback out from the ER (becomes usable again on-chain)
A typical example scenario could look like this:
bubblegum_escrow_depositis called on chain withwallet1, creating abubblegum_escrowbubblegum_escrow_delegateis called on chain, moving control of thebubblegum_escrowto inside the ERbubblegum_escrow_transferis used many time inside the ER to trade the wrapped cNFTbubblegum_escrow_undelegateis used in the ER after a while, moving back control of thebubblegum_escrowback to chainbubblegum_escrow_withdrawis called by the latest owner of the cNFT on-chain to destroy the escrow and gain access to the raw cNFT for usage with the bubblegum metaplex's programs
This crate provide example tests and scenario that can be used to help understand how each instructions can be used.
Checkout fully functional wrapping scenarios working on devnet:
- SPL Token Trading in the ER devnet_token_escrow_create_deposit_delegate_undelegate
- Bubblegum cNFT Trading in the ER devnet_bubblegum_escrow_deposit_delegate_undelegate