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 newLamportEscrow
account, holding escrowed lamports (is controlled by an "authority" wallet)lamport_escrow_claim
-> The "authority" wallet can withdraw the lamports contained in theLamportEscrow
to any wallet (can be used both on-chain and in the ER)lamport_escrow_delegate
-> Delegate theLamportEscrow
into the ER (becomes unusable on-chain)lamport_escrow_undelegate
-> Undelegate theLamportEscrow
back out from the ER (becomes usable again on-chain)
A typical example scenario could like like this:
lamport_escrow_create
is called, creating anwallet1_lamport_escrow
owned bywallet1
on-chainwallet2
transfers lamports into thewallet1_lamport_escrow
lamport_escrow_delegate
is called, delegating thewallet1_lamport_escrow
into the ERwallet1
can now claim all available lamports usinglamport_escrow_claim
from INSIDE the ERlamport_escrow_undelegate
can 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 newTokenEscrow
account representing a wallet's escrowed token balance (controlled by an "authority" wallet)token_escrow_deposit
-> Deposit a SPL token account balance into aTokenEscrow
previously created (can only be used on-chain)token_escrow_transfer
-> Transfer an amount of escrowed token from aTokenEscrow
to anotherTokenEscrow
(can be used both on-chain and in the ER)token_escrow_withdraw
-> Withdraw aTokenEscrow
balance back into a SPL token account (can only be used on-chain)token_escrow_delegate
-> Delegate theTokenEscrow
into the ER (becomes unusable on-chain)token_escrow_undelegate
-> Undelegate theTokenEscrow
back out from the ER (becomes usable again on-chain)
A typical example scenario could look like this:
token_escrow_create
is called on chain forwallet1
, creating awallet1_token_escrow
token_escrow_deposit
is called on chain, depositing some tokens intowallet1_token_escrow
token_escrow_delegate
is called, movingwallet1_token_escrow
into the ERtoken_escrow_create
is called on chain forwallet2
, creating awallet2_token_escrow
token_escrow_delegate
is called, movingwallet2_token_escrow
into the ERtoken_escrow_transfer
is called, moving funds fromwallet1_token_escrow
intowallet2_token_escrow
, all heppening in the ERtoken_escrow_undelegate
is called forwallet2_token_escrow
, bringing it back to chaintoken_escrow_withdraw
is then called bywallet2
to withdraw regular SPL tokens fromwallet2_token_escrow
on-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 newBubblegumEscrow
account 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 theBubblegumEscrow
and return the cNFT back to the specified owner (can only be used on-chain)bubblegum_escrow_delegate
-> Delegate theBubblegumEscrow
into the ER (becomes unusable on-chain)bubblegum_escrow_undelegate
-> Undelegate theBubblegumEscrow
back out from the ER (becomes usable again on-chain)
A typical example scenario could look like this:
bubblegum_escrow_deposit
is called on chain withwallet1
, creating abubblegum_escrow
bubblegum_escrow_delegate
is called on chain, moving control of thebubblegum_escrow
to inside the ERbubblegum_escrow_transfer
is used many time inside the ER to trade the wrapped cNFTbubblegum_escrow_undelegate
is used in the ER after a while, moving back control of thebubblegum_escrow
back to chainbubblegum_escrow_withdraw
is 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