Skip to main content
Share Your Experience: Take the 2024 Developer Survey
8 votes

Flash loan security considerations and attacks

As we work on flash loan attack debriefs, we can gather a lot of information about what could have been taken as preventative measures. It's important to understand how these flash loans work before ...
Patrick Collins's user avatar
7 votes
Accepted

Calculate deposit amount when adding to a liquidity pool in Uniswap v3

To answer the question, first you need to calculate the liquidity Liquidity_x that is provided by the asset x given the current price and price range. From the whitepaper it can be derived that if ...
kfx's user avatar
  • 1,630
6 votes
Accepted

What is DeFi decentralized finance?

Decentralized Finance (DeFi) is the movement that leverages decentralized networks to transform old financial products into trustless and transparent protocols that run without intermediaries. Some ...
Nick Sawinyh's user avatar
6 votes
Accepted

What is INIT_CODE_HASH and how is it calculated / used in DeFi smart contracts

https://www.codegrepper.com/code-examples/javascript/calculate+init+code+hash+nodejs This shows how it's used with COMPUTED_INIT_CODE_HASH (https://www.codegrepper.com/code-examples/javascript/...
Sheraj's user avatar
  • 86
6 votes
Accepted

bytes32 Error: incorrect data length - ethers.js

A bytes32 hex string should have 2+64=66 char length. It is possible that some tools can pad zero bytes around a value if it is smaller than the required length, for easy use. // pads 00s from left ...
Soham Zemse's user avatar
  • 2,041
5 votes

Call swapExactETHForTokens from contract and pay with contract balance

You should be able to achieve that if you send the ether along the function call. In solc v0.8 you achieve that using the function call options {value: amount}. The resulting function should look like ...
Ismael's user avatar
  • 30.5k
5 votes

what is math for uniswap calculates the amountout and amountin why 997 and 1000

As Uniswap's fees are 0.3%, the constants 997 and 1000 are corresponding nominators and denominators to help calculate this. 3 / 1000 = 0.003 = 0.3%
Natalia Serene's user avatar
5 votes
Accepted

Understanding `rewardRate` and `rewardPerToken` in Synthetix Staking contract

rewardRate is reward per second, this rate will be multiplied by token user staked / total staked rewardPerToken - math trick R = reward rate l(t) = amount user has staked at time t L(t) = total ...
tsknakamura's user avatar
5 votes

Have any a16z-backed protocols ever been hacked?

DefiLlama maintains a database of a large number of capital raises (including the amount raised and VC investors) and hackes/exploits. If you merge these two databases by company name and filter by ...
Markus Schick's user avatar
5 votes
Accepted

Why concentrated liquidity is capital efficient?

Concentrated liquidity is more capital efficient because with increased concentration, the same amount of tokens invested creates greater depth of liquidity. From Uniswap's blog: By concentrating ...
kfx's user avatar
  • 1,630
4 votes

What is INIT_CODE_HASH and how is it calculated / used in DeFi smart contracts

INIT_CODE_HASH is a hash of the initcode of a contract. The initcode is the code that creates the bytecode that is stored on-chain. You can read more about the types of bytecode here. Most dapps, ...
Shane Fontaine's user avatar
4 votes
Accepted

How to create a Payable function that only accepts a customer token?

You don't use payable for non-protocol type of transfer. ERC20 isn't "protocol" because it is defined in a contract. There is no way to detect ERC20 tokens that are blindly transferred to a ...
Rob Hitchens's user avatar
  • 55.3k
4 votes
Accepted

UniSwap V3 API : How to track **unclaimed fees** programmatically?

I solved this by going through powershell. I query the infura account that the uniswap interface queries to. Here is a powershell script for an DAI/USDC pool. You have to change some things for this ...
Gwen_vere's user avatar
4 votes

Why concentrated liquidity is capital efficient?

how come range is important. Because of price impact. As a market taker (trader) you want to get the most amount of tokens for the amount of your money you put in the trade (quote token, fiat). ...
Mikko Ohtamaa's user avatar
4 votes
Accepted

What is a returnbomb attack?

The general issue is that a regular low-level Solidity call, ie <address>.call(), will automatically copy all bytes returned by the callee to memory. Note that using memory during an EVM ...
merkleplant's user avatar
3 votes

Flash loan security considerations and attacks

Flash loans violate two common intuitive assumptions. 1. "Nobody has that much ETH" Problems can arise when for example: Your contract uses a non-linear formula with an ETH amount as ...
Jesbus's user avatar
  • 10.5k
3 votes

Flash loan security considerations and attacks

Generally speaking, if your system gives the users different terms under different scenarios, then you need to remember that a user can issue a flash-load attack on it. For example, if your pool gives ...
goodvibration's user avatar
3 votes

What are the risks of DeFi lending?

There is no answer for question "what are the risks of DeFi lending" because decentralised finance is an ecosystem and has various lending products. Each lending product has its own risk ...
Mikko Ohtamaa's user avatar
3 votes
Accepted

What programming languages was Uniswap's open-source code written in?

Uniswap protocol is developed in Solidity, and you can find two main building blocks: uniswap-v2-core: Core smart contracts, essentially with the Factory, Pair and ERC20, together with a number of ...
Sergi Juanati's user avatar
3 votes

UniSwap V3 API : How to track **unclaimed fees** programmatically?

By calling the "DeBank Open API". Exmaple: Random Wallet Address: 0x6741ad42f42564c3f21587d080880b2e79731eb1 Uniswap V3 Positions: DYDX + WETH API call : https://openapi.debank.com/v1/user/...
Thai Boy's user avatar
  • 146
3 votes
Accepted

Retrieving Matic Reward Rates on AAVE with a Python script

So I solved the problem. There were two mistakes: For the "REWARD_DECIMAL" and the "TOKEN_DECIMAL" I should use 10 to the power of the number, and not the numbers themselves. ...
Dji enne's user avatar
3 votes

Why do we grant access to our funds instead of just sending them to the smart contract?

Generally, there are two ways to transfer (ERC20) tokens: Direct transfer with transfer. You can call this function to transfer your tokens directly to another address. Indirect transfer with ...
Lauri Peltonen's user avatar
3 votes
Accepted

Why do we grant access to our funds instead of just sending them to the smart contract?

There is no "advantage". The reason most DeFi apps ask users to "allow" the transfer of their funds is that those funds are represented as ERC-20 tokens. The Ethereum community is ...
Paul Razvan Berg's user avatar
3 votes

How come Uniswap 0.3 percent pool fee is 3000?

By Uniswap conventions, the fee level of a certain pool can have four distinct values: 10000 for a 1% fee pool 3000 for a 0.3% fee pool 500 for a 0.05% pool 100 for a 0.01% pool 0.3% or 3000 is also ...
Yongjian P.'s user avatar
  • 4,200
3 votes

how is the EXP opcode priced? and when to use it?

The gas cost of the MUL opcode is set to 5 units because multiplication is a relatively simple operation that does not require many resources. The gas cost of the EXP opcode is more complex because it ...
Yakitori's user avatar
  • 767
3 votes

Why concentrated liquidity is capital efficient?

The concentrated liquidity is capital efficient because it allows LPs to optimize their capital utilization by concentrating their liquidity within a specific price range. Earlier versions of AMMs ...
Naveed Ali's user avatar
3 votes

Keepers explained in Defi

keepers are a fundamental piece of the web3 ecosystem and help contracts execute transactions without manual intervention. Keepers are bots checking and executing when specific conditions are met. ...
donoso.eth's user avatar
  • 1,493
3 votes
Accepted

Keepers explained in Defi

Chainlink automation(previously known as Chainlink keepers) is a solution of smart contract conditional automation. It is pretty straightforward to understand and use Chainlink automation(keepers). ...
Frank Kong's user avatar
3 votes

Error: contract runner does not support sending transactions (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=6.6.3)

You just need to get a signer by const signer = await ethers.provider.getSigner() and then, pass this signer to sign transaction in the ethers.getContractAt() function rather than deployer in your ...
manu sharma's user avatar
2 votes

What is the equivalent of ERC-20 tokens on the Cardano blockchain?

I think this question will be closed as off-topic as it's a question about Cardano. (Please ask on a Cardano forum.) Just to clear one thing up: Why doesn't Uniswap (a decentralized exchange) list ...
Richard Horrocks's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible