Category: Defi

26 September 2024
14 minutes

get_D() and get_y() in Curve StableSwap

get_D() and get_y() in Curve StableSwap This article shows algebraically step-by-step how the code for get_D() and get_y() are derived from the StableSwap invariant. Given the StableSwap Invariant: $$ An^n\sum…

Read Article
10 June 2024
11 minutes

Fixed Point Arithmetic in Solidity (Using Solady, Solmate, and ABDK as Examples)

Fixed Point Arithmetic in Solidity (Using Solady, Solmate, and ABDK as Examples) A fixed-point number is an integer that stores only the numerator of a fraction — while the denominator…

Read Article
17 April 2024
7 minutes

Uniswap V2: Calculating the Settlement Price of an AMM Swap

Uniswap V2: Calculating the Settlement Price of an AMM Swap This article explains how to determine the price settlement of a trading pair in an Automated Market Maker (AMM). It…

Read Article
11 January 2024
4 minutes

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…

Read Article
10 January 2024
7 minutes

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 the a market’s lending and borrowing. The algorithm…

Read Article
09 January 2024
4 minutes

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…

Read Article
08 January 2024
11 minutes

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…

Read Article
07 January 2024
6 minutes

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…

Read Article
05 January 2024
7 minutes

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…

Read Article
04 January 2024
6 minutes

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…

Read Article
03 January 2024
10 minutes

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…

Read Article
30 December 2023
11 minutes

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…

Read Article
01 December 2023
7 minutes

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…

Read Article
21 November 2023
11 minutes

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…

Read Article
14 November 2023
6 minutes

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…

Read Article
10 November 2023
10 minutes

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…

Read Article
07 November 2023
13 minutes

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 3156 Flash loans are loans between smart contracts that must be repaid in the same transaction. This article…

Read Article
06 November 2023
4 minutes

UniswapV2Library Code Walkthrough

UniswapV2Library Code Walkthrough UniswapV2Library The Uniswap V2 Library simplifies some interactions with pair contracts and is used heavily by the Router contracts. It contains eight functions that are not state-changing,.…

Read Article
03 November 2023
10 minutes

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 price…

Read Article
01 November 2023
3 minutes

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…

Read Article
30 October 2023
8 minutes

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…

Read Article
28 October 2023
8 minutes

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…

Read Article
27 June 2023
35 minutes

How Tornado Cash Works (Line by Line for Devs)

How Tornado Cash Works (Line by Line for Devs) Introduction to Tornado Cash Tornado cash is a cryptocurrency smart contract mixer that enables users to deposit crypto with one address…

Read Article
Load More Articles