RareSkills Blog

Solana Anchor Program IDL
Solana Anchor Program IDL The IDL (Interface Definition Language) is a JSON file that describes how to interact with a Solana program. It is automatically generated by the Anchor framework.…

Arithmetic and Basic Types in Solana and Rust
Arithmetic and Basic Types in Solana and Rust Today we will learn how to create a Solana program that accomplishes the same things as the Solidity contract below. We will…

Solana Hello World (Installation and Troubleshooting)
Solana Hello World (Installation and Troubleshooting) This is a Solana hello world tutorial. We will walk you through the steps to install Solana and troubleshoot issues that may arise. If…

Layer 2 Calldata Gas Optimization
Layer 2 Calldata Gas Optimization Update for mid 2024 As of the Dencun upgrade, calldata optimization doesn’t have as much of an impact since the transactions on most L2s are…

How Chainlink Price Feeds Work
How Chainlink Price Feeds Work Chainlink price oracles are smart contracts with public view functions that return the price of a particular asset denominated in USD. Off-chain nodes collect the…

How Compound V3 Allocates COMP Rewards
How Compound V3 Allocates COMP Rewards Compound issues rewards in COMP tokens to lenders and borrowers in proportion to their share of a market’s lending and borrowing. The algorithm is…

Bulkers in Compound V3
Bulkers in Compound V3 The bulker contracts in Compound V3 are multicall-like contracts for batching several transactions. For example, if we wanted to supply Ether, LINK, and wBTC as collateral…

Understanding Collateral, Liquidations, and Reserves in Compound V3
Understanding Collateral, Liquidations, and Reserves in Compound V3 In this chapter we will examine the following topics about Compound V3: collateral valuation absorbing insufficiently collateralized loans (liquidations) selling absorbed collateral…

cUSDC V3 (Compound V3) as a non-standard Rebasing Token, CometExt.sol
cUSDC V3 (Compound V3) as a non-standard Rebasing Token, CometExt.sol The Compound V3 contract behaves like a rebasing ERC-20 token. A rebasing token is a token which has an algorithmically…

DeFi Interest Rate Indexes: Principal value and Present Value in Compound V3
DeFi Interest Rate Indexes: Principal value and Present Value in Compound V3 The intuitive way to track lender deposits is to record the amount of USDC they deposited and the…

Compound V3 Interest Per Second
Compound V3 Interest Per Second The Compound V3 protocol measures interest on the scale of seconds. The Compound V3 frontend scales the number up to years for human friendliness. When we check…

The Architecture of the Compound V3 Smart Contract
The Architecture of the Compound V3 Smart Contract Introduction and prerequisites Compound is one of the most significant lending protocols in DeFi, having inspired the design of nearly every lending…

DeFi Lending: Liquidations and Collateral
DeFi Lending: Liquidations and Collateral In TradFi, when someone defaults on a loan, the creditor has the right to seize assets or garnish wages. In DeFi, when someone defaults on…

The Fallback Extension Pattern
The Fallback Extension Pattern The fallback-extension pattern is a simple way to circumvent the 24kb smart contract size limit. Suppose we have functions foo() and bar() in our primary contract…

EIP 1967 Storage Slots for Proxies
EIP 1967 Storage Slots for Proxies EIP 1967 is a standard for where to store information that proxy contracts need to execute. Both the UUPS (Universal Upgradeable Proxy Standard) and…

The interest rate model of AAVE V3 and Compound V2
The interest rate model of Aave V3 and Compound V2 Interest rates in TradFi (traditional finance) are largely determined by central banks and influenced by market factors. In contrast, DeFi…

The second preimage attack for Merkle Trees in Solidity
The second preimage attack for Merkle Trees in Solidity The second preimage attack in Merkle trees can happen when an intermediate node in a merkle tree is presented as a…

The staking algorithm of Sushiswap MasterChef and Synthetix
The staking algorithm of Sushiswap MasterChef and Synthetix The MasterChef and Synthetix staking algorithms distribute a fixed reward pool among stakers according to their time-weighted contributions to a pool. To…

How Uniswap V2 computes the mintFee
How Uniswap V2 computes the mintFee Uniswap V2 was designed to collect 1/6th of the swap fees to the protocol. Since a swap fee is 0.3%, 1/6th of that is…

Uniswap v2 router code walkthrough
Uniswap v2 router code walkthrough The Router contracts provide a user-facing smart contract for safely minting and burning LP tokens (adding and removing liquidity) safely swapping pair tokens They add…

A comprehensive guide to the ERC 721 standard and related security issues
A comprehensive guide to the ERC 721 standard and related security issues ERC721 (or ERC-721) is the most widely used Ethereum standard for nonfungible tokens. It associates a unique number…

Flash Loans and how to hack them: a walk through of ERC 3156
Flash Loans and how to hack them: a walk through of ERC 3156Flash loans are loans between smart contracts that must be repaid in the same transaction. This article describes…

Uniswap V2 Library Code Walkthrough
Uniswap V2 Library Code Walkthrough Uniswap V2 Library The Uniswap V2 Library simplifies some interactions with pair contracts and is used heavily by the Router contracts. It contains eight functions…

How the TWAP Oracle in Uniswap v2 Works
How the TWAP Oracle in Uniswap v2 Works What exactly is “price” in Uniswap? Suppose we have 1 Ether and 2,000 USDC in a pool. This implies that the…

Checklist for building a Uniswap V2 clone
Checklist for building a Uniswap V2 clone It’s very educational to rebuild Uniswap v2 from scratch using modern Solidity (or Huff if you really want to do it in hard…

Uniswap V2 Mint and Burn Functions Explained
Uniswap V2 Mint and Burn Functions Explained The lifecycle of Uniswap V2 is someone mints LP tokens (supplies liquidity, i.e. tokens to the pool) for the first time, then a…

Breaking Down the Uniswap V2 Swap Function
Breaking Down the Uniswap V2 Swap Function Uniswap V2’s swap function is cleverly designed, but many devs find its logic counterintuitive the first time they encounter it. This article explains…