Hot answers tagged

10

The answer is that uniswap is a set of Smart Contract running on the Ethereum platform and thus requires gas in order to execute any functions. Meaning that when you swap token A for token B or token C it is more or less the same function that is being called in order to perform the necessary logic of matching buyers and sellers. This is only an issue (such ...


9

You can use the Uniswap TheGraph for this! For example a query to get the last 10 swaps from the DAI/ETH pair would be: { swaps(first: 10, where: { pair: "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11" } orderBy: timestamp, orderDirection: desc) { transaction { id timestamp } id pair { token0 { ...


8

“The price of a given token on a given exchange can be calculated as the exchange contract's token_balance divided by its ether_balance.” This description means: On-chain price: In opposed to off-chain price, which is what you may see on various exchanges, and which can of course be different on every exchange. Spot price: This is the rate that you will ...


7

One solution appears to be to install @truffle/contract package like so: npm install @truffle/contract Then in the migration file you will need to grab the full contract JSON (not just the bytecode as mentioned in the question) and use the @truffle/contract to create a contract instance from the JSON. You will also need to set the provider manually, and set ...


6

That’s called arbitrage, you swap e.g. ETH for DAI on one exchange and then swap it back from DAI to ETH on another exchange. This works because the so called DEX’s (Decentralized exchanges like Uniswap) have sometimes different exchange rates for token pairs. There is also another version of arbitrage called triangular arbitrage where you swap e.g. ETH for ...


5

A function selector is the first 4 bytes in the hash of the function's prototype. A function prototype is defined as the function's name and its argument types by order. It allows you, for example, to call a function without knowing its exact return-value type: bytes4 private constant FUNC_SELECTOR = bytes4(keccak256("someFunc(address,uint256)")); ...


4

Here is how I debug your issue (which is what you could have easily done yourself): Search 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D on https://etherscan.io Click on the Contract tab and scroll down to the Contract Source Code text box Search for function swapExactTokensForETH in the source code Search for INSUFFICIENT_OUTPUT_AMOUNT inside that function ...


4

If you want to do it programmatically, you can query the contract for the uniswap pool for your token. For example, take USDC token. You can query the uniswap usdc-eth contract to get the # of usdc and eth: the price of eth is then (number of usdc) / (number of eth). In this case, I'm using the ethers.js library. You can also do this with web3. import { ...


4

Get the pool address Go to the Uniswap UI at https://app.uniswap.org/. Choose the token pair you want and then click the View pair analytics ↗. This will take you to a link like https://uniswap.info/pair/<poolAddress>. Note down poolAddress. Approve via Etherscan Go to https://etherscan.io/token/<tokenAddress>#writeContract where tokenAddress ...


4

To my knowledge swap gas fee is 21000 or so A transfer between two EOAs (i.e. normal wallet accounts) is 21,000 gas. As soon as you include smart contracts in the equation the gas cost increases: each opcode associated with each step in the execution of a smart contract incurs a cost. (As outlined in Appendix G of the Yellow Paper.) Without actually digging ...


3

The error that you're getting implies that you first need to submit from your account the transaction token.approve(uniswapContractAddress, amountIn), where token is an ERC20 contract at the address indicated by path[0].


3

The _mint function comes from one of the contract's parents, the UniswapV2ERC20 contract: https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol#L40 The underscore prefix is a convention, as in some other languages, e.g. Python, that it is a "protected" function, i.e. can only be called from itself or a derived class. ...


3

Just for the others who might be facing the same issue (it took me quite a while to fix it). The problem I faced was that I was calling function addLiquidityETH() without sending the ethers to Uniswap smart contract, so {value: msg.value} has to be added to the call: uniswap.addLiquidityETH{ value: msg.value }( token, amountTokenDesired, ...


3

A good overview of frontrunning, and related miner extractable value (MEV), problems are well established and well known at this point. The difference between these two modes of frontrunning that in MEV it is the miners who frontrun you, whereas normal frontrunning bot use the same mempool for transactions are other Ethereum clients. Here are some articles ...


3

You can actually do a double flashloan, but the success will depend on the total amount of gas consumed in the transaction. In fact, you don't need to have two contracts and you can request the two loans from the same contract. Below is a simple example on how this could be done: // SPDX-License-Identifier: MIT pragma solidity ^0.7.3; import {IERC20} from &...


3

This function takes a parameter uint256 amountOutMin. This parameter basically says that if the amount of token you get out of the swap is less than that amount, the swap must be cancelled. If you get an INSUFFICIENT_OUTPUT_AMOUNT error, it means that the token that you would have got from the swap was lower than the amountOutMin that you set. It is ...


2

The issue here is that 0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa and 0xFf795577d9AC8bD7D90Ee22b6C1703490b6512FD aren't the same token. They are both tokens on Kovan, but since they aren't the same address, they aren't the same token. According to MakerDAO, the official DAI address on Kovan is the one that Uniswap is using (...


2

It is obviously the amount of the last token in the path, i.e., amounts[amounts.length - 1].


2

As far as I was aware, this difference is the fee paid to the Liquidity Pool creators. That is, the reward for locking up these funds to create the market via the liquidity pool.


2

Without even opening the link: Scoping a piece of code with { ... } has the same impact as placing that piece of code in a separate function. This option has become available starting from solc 0.5.0.


2

You can only addequal USD value pair to a pool, let's see 1000 USDC/2.6 ETh (Eth price 384), the daily return is about 1.8% at the moment, based on the pool size of 25m for this pool, with daily reward of 83,333 Uni per pool, Uni price is USD5.5, APY would be around 670% which is very good. However, the pool size is likely to go up quickly, the the reward ...


2

You need to create the init_code_hash using your newly deployed Factory contract. This address hard-coded in Uniswap's Github repo is specifically for their deployment in Ethereum networks. In your UniswapV2Factory.sol code, add the following piece of code. bytes32 public constant INIT_CODE_PAIR_HASH = keccak256(abi.encodePacked(type(UniswapV2Pair)....


2

The Uniswap Router is a periphery contract which means that it's not strictly necessary. But still you should use it due to the fact that it protects you against various kinds of attacks on your trades. One of the attack vectors is frontrunning your trades. That means you enter your trade, some bot notices it in the Ethereum mempool (before it's executed), ...


2

Answered by my boss The earned fees are added to your liquidity: to withdraw them you just remove some liquidity from the pool.


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

Token symbols are arbitrary strings. They can be chosen freely by the token creator, so multiple tokens may have the same symbols. Therefore it does not make much sense to search by token symbol. It is also impossible to know which token is which just by looking at the symbols. Token address is the global unique identifier - never trust anything else. So ...


2

You are not providing enough information about your case, but most likely you have been front-run. When you are giving away free money on the blockchain, some people will take it. When you announce your request to buy some asset on Uniswap and you specify "my slippage is 100 bucks", you are giving away free money for the amount 100 bucks. If I have ...


2

Maybe it is because in Coinbase's web interface when an exchange executes, in reality, there is no interaction at all with related blockchains. the onsite exchange is just happening on Coinbase's database, while withdrawals are the ones that are really being processed on the related blockchain.


2

Technically speaking what you propose is possible. Perhaps I would leave the two functions swapExactETHForTokens & swapExactTokensForETH as they are, and I would create a new function to call them in a single transaction in order to adjust the function parameters as needed. However, if your goal is to do arbitrage in order to make some profit, you should ...


2

If you search this site there are multiple questions which ask the same thing but from a bit different angle, so I couldn't find an exact duplicate for your questions, although my answer has all the same data as those answers. The transaction order in the block is entirely up to the miner to decide. And because they can decide it, they typically choose an ...


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