Why do they say you learn when you do SC audits? Let’s learn some things by analyzing Raft Protocol
I can guarantee you that the more DeFi protocols you learn about, the easier it will get to audit any other new protocol released.
So, let’s go check what we can learn by reviewing Raft, that we didn’t know before.
What is Raft?
Raft is an immutable, decentralized lending protocol that allows people to take out stablecoin loans against capital-efficient collateral. Raft’s first stablecoin is called R.
What is R?
R is the first Ethereum USD stablecoin backed by stETH (Lido Staked Ether).
R provides the most capital-efficient way to borrow using your stETH.
R aims to be the stablecoin of choice within the decentralized ecosystem, with deep liquidity across many trading pairs and a stable peg.
What is a Position?
A Position is where you take out and maintain your loan. Each Position is linked to an Ethereum address and each address can have just one Position.
If you are familiar with Vaults or Troves from Liquity Protocol, Positions are similar in concept.
Within each Position, wrapped stETH (wstETH) needs to be deposited as collateral to borrow R. Also, stETH and ETH are accepted as collateral.
wstETH stands for wrapped staked ether
As some DeFi protocols require a constant balance mechanism for tokens, wstETH keeps your balance of stETH fixed.
If you want to understand this much better, get into Lido’s documentation
What is R?
R is the first Ethereum USD stablecoin solely backed by stETH.
R provides the most capital-efficient way to borrow using your stETH.
R aims to be the stablecoin of choice within the decentralized ecosystem.
Each R is designed to retain a value of 1 USD. It uses a combination of Hard Peg and Soft Peg mechanisms to maintain its peg value of 1 USD.
Which are the main functionalities of Raft?
Deposit stETH.
Flash mint R
Swap R for stETH
Deposit extra stETH
Borrow R
Repay R flash mint
At the moment of writing this article, the repository is not publicly available, but considering what we know from the similarities that Raft has to other protocols, like, for instance, the Liquity protocol, let’s try to get ahead while preparing for the audit, and understand what we can expect to be present in their smart contracts.
Deposit stETH
Approve and deposit your initial stETH collateral to get started.
So, here we will expect a deposit function and inside with function to mint
R, where we pass the collateral which in this case is either wstETH, stETH, or ETH. Depending on which collateral is passed it will either use it to mint R, directly or it might have to stake it and/or wrap it with Lido.
Flash mint R
The Flash Mint module is a powerful tool that enables users to mint R up to 10% of the total outstanding R supply at once, with the condition that they will pay it back in the same transaction with a 0.5% Flash Mint Rate.
A flash mint is a flash loan provided directly by the Raft protocol. It operates directly within the Raft smart contracts, eliminating the need for a separate money market or liquidity pool to loan R from.
Similarly to Flash Loan, Flash Mint can allow users to borrow
R, swap
it into wstETH, and obtain a leveraged collateral position in 1 step.
From this, we understand that the smart contract for Borrowing
will have external and internal functions for borrowing, which will make sure the collateral is provided and the Position is opened.
Swap R for stETH
The smart contracts swap the flash minted R for stETH via a liquidity pool.
It will also have a swap
function where it will be storing the provided collateral and minting it for R so that it can send it back to the borrower.
Deposit extra stETH
The smart contracts deposit the newly acquired stETH as extra collateral.
This type of protocol usually has 3 main functions: to open
, close
, or adjust
its Vault, Trove, or in this protocol’s case, Position.
So, in this case, the user can increase the collateral by using the function adjust
.
Borrow R
The smart contracts borrow R against the newly deposited stETH collateral.
This is the main functionality, and it is going to be used in multiple places. The main requirement here is going to be that the borrower deposit the collateral first.
This function will be responsible for minting R.
Repay R flash mint
The smart contracts repay the flash mint debt with the newly minted R.
It is always present in borrowing and lending protocols the function to repay
here the borrower has the option to repay all or part of the debt by providing R.
A different usage where we will be seeing this used is in the flash mint as it borrows and returns it all in one transaction.
This is a short analysis that you can do of a protocol once you learn about the date of the audit starts and without having access yet to the GitHub repo.
What I did was go through their website and their documentation and gather the information they provide, adding some potential use cases that are present in other similar protocols.
Now, to gain a better view of what similar protocols look like, I would recommend you read about
Liquity protocol
and AAVE protocol
I think being aware of how DeFi protocols work is of tremendous help and a must, to be honest if you want to increase your auditing skills.
Make sure you follow me on Twitter https://twitter.com/TheBlockChainer for my latest updates.