Category: Solidity

The Solana Token 2022 Specification
The Solana Token 2022 Specification Token-2022 is a new backward-compatible version of the SPL Token program that supports additional features in the form of extensions. The bytecode for these extensions…

Time Travel Testing with LiteSVM
Time Travel Testing with LiteSVM In Solana, writing test cases that depend on the passing of time is tricky. We might want to test that something happens in our code…

Implementing Token Metadata with Metaplex
Implementing Token Metadata with Metaplex We introduced the Metaplex metadata standard in the previous tutorial. In this one, we’ll create an SPL token and attach metadata to it using the…

How Metaplex Metadata for Tokens Works
How Metaplex Metadata for Tokens Works We have deployed and interacted with SPL tokens, but none of them had a name, symbol, or any metadata attached. Instead, we identified each…

Basic Bank Tutorial
Basic Bank Tutorial with SPL Tokens and Anchor In this tutorial, we’ll build a simple bank program on Solana with the basic features you’d expect from a regular bank. Users…

Token Sale with Total Supply Tutorial
Token Sale with Total Supply Tutorial A token sale program is a smart contract that sells a specific token, usually in exchange for a native token like SOL, at a…

Transferring SPL Tokens with Anchor and Web3.js
Transferring SPL Tokens with Anchor and Web3.js In the previous tutorial, we learned how SPL tokens work. In this tutorial, we’ll implement a full SPL token lifecycle: create, mint, transfer,…

How the SPL Token Works
How the SPL Token Works Solana Program Library Token (SPL Token) is Solana’s standard for tokens: how to create tokens and how they should behave. It is Solana’s equivalent to…

Calculating the real reserves between two prices in the Uniswap V3 codebase
Calculating the real reserves between two prices in the Uniswap V3 codebase In previous chapters, we derived formulas to calculate the real reserves of tokens X and Y between two…

The Fundamental Theorem of Finite Cyclic Groups
The Fundamental Theorem of Finite Cyclic Groups The Fundamental Theorem of Cyclic Groups provides guarantees about the existence of cyclic subgroups within a cyclic group. In the context of the…

The constant product formula in Uniswap v3
The constant product formula in Uniswap v3 Our goal is to derive the constant product formula based on real reserves for a segment, given by $$ L^2 = (x_r+\frac{L}{\sqrt{p_u}})(y_r+L\sqrt{p_l})$$ and…

How Ethereum address are derived (EOAs, CREATE, and CREATE2)
How Ethereum address are derived (EOAs, CREATE, and CREATE2) On Ethereum, smart contracts can be deployed in one of three ways: An Externally Owned Account (EOA) initiates the transaction where…

Real reserves in Uniswap v3
Real reserves in Uniswap v3 In the last chapter, we introduced two new concepts: real reserves and virtual reserves. The real reserves of a segment are the amount of tokens…

Real and virtual reserves in Uniswap v3
Real and virtual reserves in Uniswap v3 Uniswap v3 uses two types of reserves: real reserves and virtual reserves. Real reserves represent the actual amount of tokens present in a…

ERC-6551 Standard: Token Bound Accounts (TBA)
ERC-6551 Standard: Token Bound Accounts (TBA) Introduction NFTs were originally created to represent ownership of digital or physical assets, like collectibles. However, they were limited to tracking ownership of an…

Square and Multiply Algorithm
Square and Multiply Algorithm The square and multiply algorithm computes integer exponents in $\mathcal{O}(\log n)$ (logarithmic time). The naive way to compute an exponent $x^n$ is to multiply $x$ by…

Uniswap V2 Architecture: An Introduction to Automated Market Makers
Uniswap V2 Architecture: An Introduction to Automated Market Makers Uniswap is a DeFi app that enables traders to swap one token for another in a trustless manner. It was one…

Multiplicative Subgroups and Primitive Elements
Multiplicative Subgroups and Primitive Elements Introduction This chapter continues our study of group theory by exploring subgroups and generators. The concept of a primitive element will be introduced at the…

20 Common Solidity Beginner Mistakes
20 Common Solidity Beginner Mistakes Our intent is not to be patronizing towards developers early in their journey with this article. Having reviewed code from numerous Solidity developers, we’ve seen…

Smart Contract Foundry Upgrades with the OpenZeppelin Plugin
Smart Contract Foundry Upgrades with the OpenZeppelin Plugin Upgrading a smart contract is a multistep and error-prone process, so to minimize the chances of human error, it is desirable to…

UUPS: Universal Upgradeable Proxy Standard (ERC-1822)
UUPS: Universal Upgradeable Proxy Standard (ERC-1822) The UUPS pattern is a proxy pattern where the upgrade function resides in the implementation contract, but changes the implementation address stored in the…

Try Catch and all the ways Solidity can revert
Try Catch and all the ways Solidity can revert This article describes all the kinds of errors that can happen when a smart contract is called, and how the Solidity…

The Beacon Proxy Pattern Explained
The Beacon Proxy Pattern Explained A Beacon Proxy is a smart contract upgrade pattern where multiple proxies use the same implementation contract, and all the proxies can be upgraded in…

Storage Slots in Solidity: Storage Allocation and Low-level assembly storage operations
Storage Slots in Solidity: Storage Allocation and Low-level assembly storage operations This article examines the storage architecture of the Ethereum Smart Contracts. It explains how variables are kept in the…

Invariant Testing in Foundry
Invariant Testing in Foundry Introduction In this article, we will discuss invariants and how to perform an invariant test on solidity smart contracts using foundry test suites. Invariant testing is…

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…

Transparent Upgradeable Proxy
The Transparent Upgradeable Proxy Pattern Explained in Detail The Transparent Upgradeable Proxy is a design pattern for upgrading a proxy while eliminating the possibility of a function selector clash. A…