IMPORTANT: This repo is a work in progress, and contracts have not been audited. Use at your own risk.
- RWAs
- Table of Contents
- The Methodology
- The three examples in this repo
- Getting Started
- Details on the Four Examples
- Fully-reserved On-Chain Asset Representation with On-Chain Collateral: frCross-Chain WETH
- Synthetic On-Chain Asset Representation with On-Chain Collateral: sCross-Chain WETH
- Synthetic Off-Chain Asset Representation with On-Chain Collateral: sMSFT
- Fully-reserved Off-Chain Asset Representation with Off-Chain Collateral: frMSFT
- Currently Live Examples of Tokenized RWAs
- What does this unlock?
- Disclaimer
We can tokenize real world assets by combining any of the following traits:
- Asset location:
- On or Off Chain Asset Represented
- Nomenclature: [
AOn
,AOff
]- Note: By using an on-chain asset, it could be considered no longer "real world".
- Collateral location:
- On or Off-Chain Collateral
- Nomenclature: [
COn
,COff
]
- Backing type:
- Direct backing or Indirect (synthetic)
- Nomenclature: [
DB
,SB
]
So since we have 3 categories each with 2 options, we have 8 different types of RWAs.
Examples of the 8 assets
- Onchain asset, onchain collateral, direct backing
AOnCOnDB
- Examples: WETH
- Not demo'd in this repo
- Onchain asset, onchain collateral, indirect backing (synthetic)
AOnCOnSB
- Examples: WBTC
- Not demo'd in this repo
- Onchain asset, offchain collateral, direct backing
AOnCOffDB
- Examples: N/A
- Maybe like a wrapped BTC ETF?
- Not demo'd in this repo
- Onchain asset, offchain collateral, indirect backing (synthetic)
AOnCOffSB
- Examples: N/A
- Maybe like a wrapped BTC ETF that represents an ETH ETF?
- Not demo'd in this repo
- Offchain asset, onchain collateral, direct backing
AOffCOnDB
- Examples: N/A
- Like a stablecoin backed by other stablecoins (sort of DAI lmao)
- Not demo'd in this repo
- Offchain asset, onchain collateral, indirect backing (synthetic)
AOffCOnSB
- Examples: DAI
- In this repo: sTSLA w/ chainlink price feeds
- Offchain asset, offchain collateral, direct backing
AOffCOffDB
- Examples: USDC
- In this repo: dTSLA w/ chainlink functions
- Offchain asset, offchain collateral, indirect backing (synthetic)
AOffCOffSB
- Examples: USDT
- In this repo: sTSLA w/ chainlink functions
- Directly Backed On-Chain Asset Representation with Off-Chain Collateral
- We would represent ETH on Chain by collateralizing it with some off-chain version of ETH? Like an ETH ETF? Weird...
- Synthetic On-Chain Asset Representation with Off-Chain Collateral
- The same issue as above, but even weirder since we'd back our on-chain asset with something like MSFT shares
- Directly Backed Off-Chain Asset Representation with On-Chain Collateral
- How could you directly back an off-chain asset with on-chain collateral? By doing that you essentially make it "synthetic" automatically
- Synthetic Off-Chain Asset Representation with Off-Chain Collateral
- This would be like a synthetic index fund share, but backed by shares of different stocks.
In this repo, we will go over how to tokenize a real world asset.
- Cross-Chain WETH with On-Chain collateral, Directly Backed:
AOnCOnDB
-CrossChainWETH.sol
- TSLA Share with On-Chain collateral, Synthetic:
AOffCOnSB
-sTSLA.sol
✅ - TSLA Share with Off-Chain collateral, Directly Backed:
AOffCOffDB
-dTSLA.sol
✅
The idea here, is that once you see the power of how to do our fourth example, you should be able to tokenize any real world assets in the world.
The reason we have 4 examples, is that each step from 1 -> 4, we learn a little more about how to tokenize an asset, and the different strategies we can use.
- Only the owner can mint
dTSLA
- Anyone can redeem
dTSLA
forUSDC
or "the stablecoin" of choice.
- Chainlink functions will kick off a
TSLA
sell for USDC, and then send it to the contract
- The user will have to then call
finishRedeem
to get theirUSDC
.
- Users can send USDC ->
dTSLA.sol
viasendMintRequest
via Chainlink Functions. This will kick off the following:
- USDC will be sent to Alpaca
- USDC will be sold for USD
- USD will be used to buy TSLA shares
- The Chainlink Functions will then callback to
_mintFulFillRequest
, to enabledTSLA
tokens to the user.
- The user can then call
finishMint
to withdraw their minteddTSLA
tokens.
This is essentially a synthetic TSLA token, it's follows a similar architecture to a stablecoin, where we use a Chainlink price feed to govern the price of the token.
You can learn more about how to build these by following the Cyfrin Updraft curriculum.
So, token transfers are baked into the CCIP protocol, but you have to work with the DONs to get these setup. We will show you how to create your own token pools with CCIP and not bother working with the DONs, since CCIP allows you to send arbitrary data to the other chain.
- WETH contract on "home" chain
- BridgedWETH contract on all other chains
- Chainlink CCIP Sender & Receiver Contract
- Lock the WETH
- Emit the message to unlock on the other chain
- Mint the WETH
- Will need to burn the WETH and send it back
- git
- You'll know you did it right if you can run
git --version
and you see a response likegit version x.x.x
- You'll know you did it right if you can run
- foundry
- You'll know you did it right if you can run
forge --version
and you see a response likeforge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)
- You'll know you did it right if you can run
- node
- You'll know you did it right if you can run
node --version
and you see a response likev16.13.0
- You'll know you did it right if you can run
- npm
- You'll know you did it right if you can run
npm --version
and you see a response like8.1.0
- You'll know you did it right if you can run
- deno
- You'll know you did it right if you can run
deno --version
and you see a response likedeno 1.40.5 (release, x86_64-apple-darwin) v8 12.1.285.27 typescript 5.3.3
- You'll know you did it right if you can run
- Clone the repo, navigate to the directory, and install dependencies with
make
git clone https://github.com/PatrickAlphaC/rwa-creator
cd rwa-creator
make
- Collateral: On-Chain ETH
- Since the collateral is the same, this is a fully-reserved/backed asset!
- Stability Mechanism: Algorithmic
- Using: Chainlink CCIP
- Would be improved by a Chainlink Proof of Reserve (PoR)
Technically, even the "normal" WETH token could be considered a fully-reserved on-chain collateralized asset!
- Collateral: Random ERC20s
- Since the collateral is different, this is a synthetic asset!
- Stability Mechanism: Algorithmic
- Using: Chainlink Price Feeds, Chainlink CCIP
- Would be improved by a Chainlink Proof of Reserve (PoR)
- Collateral: On-Chain ETH
- Since the collateral is different, this is a synthetic asset!
- Stability Mechanism: Algorithmic
- We can have an algorithmic stability mechanism because we are using on-chain collateral
- Using: Chainlink Price Feeds
- Collateral: Off-Chain MSFT shares
- Makes it fully-reserved!
- Stability Mechanism: Governed / Centralized
- It's borderline impossible to make this algorithmic at the moment
- There is too much trust needed in custodian holding the MSFT shares!
- Using: Chainlink Functions
- Would be improved by a Chainlink Proof of Reserve (PoR)
Some good examples of these are:
- Fully-reserved On-Chain Asset Representation with On-Chain Collateral: Wrapped BTC
- This uses a Chainlink PoR (proof of reserve) network to track the amount of BTC in a wallet on the BTC network.
- Only if that wallet has enough BTC (checked by CL) can they then mint WBTC on the ETH network
- Synthetic On-Chain Asset Representation with On-Chain Collateral: RAI
- RAI token is a "synthetic dollar" that is backed by ETH.
- Most stablecoins fall into either being backed or synthetic dollars.
- Fully-reserved Off-Chain Asset Representation with Off-Chain Collateral: USDC
- Each USDC is backed 1:1 by a dollar equivalent in a bank account.
- It could be improved by a Chainlink PoR, pushing it away from the centralization that comes with it being governed.
- Synthetic Off-Chain Asset Representation with Off-Chain Collateral: USDT
- Each USDT is backed by a basket of assets that equal the value of a dollar.
- This would be improved by a Chainlink PoR
Being able to tokenize real world assets unlocks a whole new world of DeFi. Happy building.
You can use Chainlink Functions to get the pricing information of any asset class.
You can use Chainlink Functions to read from your off-chain custodian untill you have a more professional Chainlink PoR solution.
None of the code has been audited or undergone a security review, use at your own risk. Using Chainlink Functions to read data from is very easy to get wrong if you're doing it wrong in a production system. If you do create a product with this knowledge, please reach out for a security review/audit.
Also in this repo:
- Generalized CCIP setup for the 3 types we demo in this repo. CrossChain functionality will be crucial for RWAs to be useful.