AMM Reserve Monitoring

In this post, we are going to see how we can set up monitoring for AMM’s. This might be required for use-cases like Developing an API service which allows clients to query price of some asset in AMM Develop an arbitrage bot I am referring to AMM’s on the Solana blockchain. But the idea should be generally applicable to the AMMs of any blockchain. We are going to look into simple CFMM based AMM for example Orca....

June 1, 2022 · 3 min · Vivek Bhadauria

Understanding Flash Loans

I was always wondering how Flash loans actually work, how can we get uncollateralized loan on blockchain. I got better understanding of Flash loans while solving Free Rider problem. In this post, I tried to explain how Flash loans actually work using pseudo code. If you want to have a look at actual solidity code. See Reference section. What are Flash Loans? Flash loans are uncollateralized loans in DeFi. They enable users to borrow liquidity instantly without any collateral....

March 13, 2022 · 3 min · Vivek Bhadauria

Arbitrage Bot Analysis on Solana

Recently, I came across bots doing arbitrage on Solana. Was reading about wormhole hack and how it created great opportunities for bots to make free money. Note that the wormhole hack was a long tail event. In general, arbitrage is a very competitive space and needs constant improvements in strategy. Misaka wrote a detailed analysis on bots which made money in the “Golden 30 mins” just after the hacker dumped stolen ETH into Solana AMM pools....

March 5, 2022 · 5 min · Vivek Bhadauria

Damn Vulnerable DeFi Solutions

I recently came across a post “How to become a Smart Contract Auditor” by cmichel. The post breaks down the skills required and points to good resources to get started with Smart Contract security. Before this, I was exploring development on Ethereum using Solidity. Solving these challenges has given me better insights to look at code from a security perspective and improved overall Solidity skills. Code solutions can be found on my fork of damn-vulnerable-defi repo....

January 29, 2022 · 3 min · Vivek Bhadauria

Decoding Raydium Swaps

In this post, we are going to look into how raydium swap works using Serum CLOB (Central limit order book). Before diving into how swap works in raydium, let’s have a brief look into Solana blockchain and Serum DEX. Solana It’s a layer 1 blockchain similar to ethereum but with improvements like supporting very high TPS, parallel smart contract runtime, etc. If you are interested in finding out what makes Solana great in comparison to other layer 1 solutions out there....

June 17, 2021 · 4 min · Vivek Bhadauria

Annotations in Java

Annotations are one of those features of Java whose working is not much clear to the developers. This post is for self reference for annotations in java. Some example of annotations below - @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface FunctionalInterface { } @Target(ElementType.METHOD) @Retention(RetentionPolicy.SOURCE) public @interface Override { } Any annotation has a retention policy attached to it. There are 3 types of “Retention Policy” SOURCE -> These annotations are in source code only....

March 26, 2021 · 2 min · Vivek Bhadauria

Generic Segment Tree

In this post, we are going to create a Generic Segment Tree. Before creating a Generic Segment Tree, we will try to solve a basic segment tree problem and try to find what part of our code is problem specific and abstract it out i.e there are some things which are common in any segment tree problem like creating the tree, querying the tree, etc. We will try to identify the piece of logic which is specific to our problem....

February 20, 2021 · 3 min · Vivek Bhadauria

git rebasing - rewrite history

In this post, I am going to discuss a scenario where I had to use “git rebasing” for something other than squashing commits. Lets build up from the starting, I am going to use a short form “CR” for code review. When I have to work on a feature, I generally cut a branch from the mainline and start development on it. git checkout -b feature-branch-101 The above command will create a branch named “feature-branch-101” and make it the current branch....

January 8, 2021 · 4 min · Vivek Bhadauria

Integer Cache in Java

Before starting with the post, try to find the output for below code snippet: Integer a = 100; Integer b = 100; System.out.println(a == b); Integer c = 1000; Integer d = 1000; System.out.println(c == d); Note the answer somewhere, we will come back to it after looking at some concepts which will help in answering this. Auto-boxing and Auto-unboxing in Java Integer i = 2 doesn’t make sense as i is an object reference and you are assigning it a literal....

June 28, 2020 · 3 min · Vivek Bhadauria
Streams in JAVA

Streams in Java

In this post, we are going to discuss about: what streams are in context of CS their support in Java lazy evaluation in streams how to create finite and infinite streams how streams along with functions help in writing declarative code Stream by definition is a sequence of data which can be finite or infinite. Wikipedia: Stream is a sequence of data elements made available overtime. A Stream can be thought of as items on conveyer belt being processed one at a time rather than in batches....

June 12, 2020 · 7 min · Vivek Bhadauria