Hot answers tagged

6

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 may prefer to call DeFi as Open Finance, Distributed Finance, or EthFi(referring to the fact that at the moment most of existing DeFi products built on Ethereum....


5

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 diving into root causes and analytics. Flash loans are loans given out without collateral and returned in the same transaction that they were lent out. This is ...


4

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 to work for your pool. The easiest way to do this is to go inspect the Uniswap webpage, find an "eth_call" query (not a "eth_blocknumber", ...


3

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 parameter Your contract relies on nobody having more than a certain amount of ETH to prevent integer overflow 2. The balance of an address (and ETH received from an ...


3

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 the users a better conversion-rate when the pool is deeper (higher reserve balances), then a user can attack it by executing atomically: Add liquidity and ...


3

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 model. They may or may not contain counterparty risk, but you need to break this down product by product, lending pool by lending pool.


2

Generally speaking, the main risk for DeFi platforms when your are a lender is in potential vulnerabilities within the smart contracts, rather than on parameters such as liquidation only affecting the borrowers. The top DeFi projects go through extensive auditing processes before their launch to the mainnet, but you will never have a 0 risk. I see the higher ...


2

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, including Sushiswap, use this variable to create a new contract with create2. When a dapp wants to create a contract with a known address, they will use the create2 ...


2

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 contract. At best, the contract can check it's balance but it won't know who sent money, so this is no good. uint myTokenBalance = IERC20(<tokenAddress>)....


2

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 anything Cardano-related? Uniswap is a smart contract on the Ethereum blockchain. It has no knowledge that Cardano exists. (See the first question in their FAQ: ...


2

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 interfaces and libraries. uniswap-v2-periphery: additional smart contracts to interact with the Core ones. They simplify the process of doing swaps or adding/...


2

"DeFi Smart Accounts" is not standard terminology and probably invented by a single person or a single marketing agency. It is impossible to tell and does not mean anything without context.


2

The best place for the equations behind liquidity allocation is the V3 whitepaper https://uniswap.org/whitepaper-v3.pdf


2

Binance documentation describes the BETH/ETH pair. In short, this pool is less exposed to impermanent loss because the relative volatility between BETH and ETH is much lower than for something like ETH and BUSD. In other words, the price of ETH and BETH should generally remain in a small price range, so the effects of impermanent loss are mild. Is BETH's ...


2

By calling the "DeBank Open API". Exmaple: Random Wallet Address: 0x6741ad42f42564c3f21587d080880b2e79731eb1 Uniswap V3 Positions: DYDX + WETH API call : https://openapi.debank.com/v1/user/protocol?id=0x6741ad42f42564c3f21587d080880b2e79731eb1&protocol_id=uniswap3 The DeBank Open API output is as below: { "id":"uniswap3&...


2

IMO it is, as long as you trust the contract you approve to be good. limited allowances are definitely safer (in the case an exploit would be discovered somehow that would allow a malicious actor to call transferFrom through a contract to its wallet. But that seems highly unlikely) but they are more cumbersome as you said. However when i'm writing code that ...


2

Prices are set by the market. The best practice is to set the price to its fair value on the market. If there is no market yet, you have to evaluate it. This is basically what investment banks will do before a stock IPO. It's very hard to do and their army of finance professionals often screw up anyways. All in all, it is not an Ethereum question, but an ...


2

I'm not sure that using just Java and Solidity will get you very far (at least as a beginner). Solidity "back end"/smart contracts and javascript front end using web3.js is the probably the place to start. I recommend the following: This guys videos seem like a pretty good all round introduction https://www.youtube.com/watch?v=3681ZYbDSSk ...


2

Different tokens can cost different amounts when transferred, i.e during a swap. 0xAPI doesn't know the gas cost of every token in existence. 0xAPI will perform a more accurate gas estimate for you under the following circumstances: takerAddress is provided and skipValidation=false (default) Taker must have the funds and the allowance Without the above we ...


2

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 approve and transferFrom. This way you do two different transaction: first you give approval for the receiver to withdraw your tokens. Then you call some ...


2

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 confronted with an instance of the classical path dependence problem. Here's a guide that dives deep into ERC-20 allowances. And here are some practical ...


1

https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/base/LiquidityManagement.sol#L51 https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/libraries/LiquidityAmounts.sol#L56 https://github.com/Uniswap/uniswap-v3-core/blob/main/contracts/UniswapV3Pool.sol#L327 use amount0 user inputed and lower/upper price to calculate ...


1

0x8ac7230489e80000 is hex, which is 10000000000000000000 (10 ether in int when converted from Wei), so if you change TOKENS_PER_BLOCK to 100, you should get reward per block set to 100 ( in ether unit) and output should be hex in Wei unit. (TOKENS_PER_BLOCK).mul(BigNumber.from(String(10 ** 18)) performs conversion to Wei from int value of TOKENS_PER_BLOCK ...


1

To change the blockchain status (in this case the current balances of the holders of the ERC20 token, that is a contract, i.e. to write in this contract's storage) someone must submit a valid transaction and it has to be added to a block. This means that you have two possibilities: a program that automatically sends transactions with a fixed cadence, this ...


1

_lp is the Pancake liquidity provider token to stake in the farm pool and wbnb is a wrapped BNB token on Binance Smart Chain.


1

Ethereum doesn't do that. You need a price source which could be on-chain or off-chain. Off-chain would be an exchange or other service, e.g CoinMarketCap and that would be an API. On-chain could be a price Oracle or liquidity pool, e.g. ChainLink or Uniswap. There are many in both cases. Hope it helps.


1

It is unlikely anybody is willing to invest unless you have what takes it to execute it before the ICO. Because it is unlikely you do not know what you are doing and you fail and people lose their money. Even better you first build a working minimal viable product, then raise money.


1

Metamask shows “ALERT: Transaction Error. Exception thrown in contract code” but transaction succeeds without error It's likely that Metamask's pre-flight check is failing for some reason, rather than the actual transaction. Before submitting your transaction, Metamask runs a "dummy" transaction to check the probable outcome. From experience, this ...


1

You can use the nonce and transaction count to validate if the nonce was mined. if (tx.nonce < getTransactionCount(sender)) { drop transaction } I don't think this situation is particular to testnets. I'd say it is worse in mainnet where short chain reorgs are common.


1

Q: What are the risks of DeFi lending? A: It depends The most important to me personally: smart contract risk and team risk (especially if anon). Even if audited, the team can rug pull, dump and what not. Even if there is a timelock, do you know to interpret byte data on the blockchain? Good resources to assess risk https://defisafety.com/ https://...


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