7 votes
Accepted

How to swap BTC to WBTC

The custodians hold funds on BTC and mint / burn WBTC on Ethereum. They are centralized entities, and when you deposit BTC with one of them, you are trusting their servers and software to issue you ...
Paul Pham's user avatar
  • 638
6 votes
Accepted

How to query Uniswap api in order to get the pair ID of a chosen token?

You can write a query to filter all the liquidity pairs on Uniswap and get the pair address { pairs (where :{token0 : "0x0f7f961648ae6db43c75663ac7e5414eb79b5704", token1 :"...
Maaz Jawaid's user avatar
6 votes

How to swap BTC to WBTC

If you are interested in actually wrapping your BTC for reasonable fees, there are currently 2 good options available: coinlist, 0.25% fee (https://coinlist.co/asset/wrapped-bitcoin) wBTC cafè, 0.17% ...
ratio's user avatar
  • 61
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.6k
5 votes
Accepted

Uniswap V3 - How to make a Multicall

Here a working example for a multicall Uniswap V3: var calls = []; const swap = swapRouter.methods.exactOutputSingle([token1, token0, ...
user66732's user avatar
  • 455
4 votes

Proxy contract to avoid sniping bot

That is not going to make a difference, bots are looking for pending transactions that execute the addLiquidity method. In order for that to work, the addLiquidity method on the router contract needs ...
Chainwire's user avatar
4 votes

How to trade directly with Uniswap V3 pool instead of through router?

Check out the Charm Finance github for an example of how to do so. You need to call pool.swap() with the correct parameters, and have a swap callback function inside your contract. I don't believe it'...
Meriadoc's user avatar
  • 427
4 votes
Accepted

UniswapV3 Get unclaimed fees

The following solution to get the liquidity and accrued unclaimed fees from a Uniswap V3 position: const { Pool } = require("@uniswap/v3-sdk"); const { Position } = require("@uniswap/v3-...
user66732's user avatar
  • 455
2 votes
Accepted

How does "swap" work between ERC20 tokens? And what is "swap"?

What is "swap" presicely between ERC20 tokens? Is it exchanging one ERC20 token for the other without fees, A "swap" is a trade, which may or may not include an explicit fee. By &...
Richard Horrocks's user avatar
2 votes

Unable to understand master-chef contract in pancake-swap

Dev Address - Some percentage of cake minted is sent to the dev address. For every 100 cake, 10 is sent to dev address. The dev address will then burn it. Update pool fn - Straight forward, it is ...
Mohamed Sohail's user avatar
2 votes

Why is it so expensive to trade with Uniswap?

There are three fees that apply when you make a trade on Uniswap. I don't know which fee you are referring to so I will break them all down. Gas fee. This is the fee that you pay so that miners will ...
Undead8's user avatar
  • 3,570
2 votes

"Price Impact Too High" swapping tokens back to ETH on basic contract with liquidity (Uniswap)

I contacted Uniswap support on Discord, and they said it's a known issue on testnets due to them using "fake dollar prices", and it can be worked around by enabling Expert Mode, which I did, ...
Neo's user avatar
  • 158
2 votes
Accepted

swapExactTokensForTokens ignore amountOutMin parameter

The AMM is only checking that it is sending you the amountOutMin, not that you are receiving it. In other words, it calls a transfer for that token for an amount greater than or equal amountOutMin. ...
Undead8's user avatar
  • 3,570
2 votes
Accepted

How accurate are 0x gas estimations?

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 ...
Jacob Evans's user avatar
2 votes
Accepted

Member "concat" not found or not visible after argument-dependent lookup

It fails because the compiler is looking for the concat function as a member of bytes type. You can use concat as a regular function return string(concat(bytes(api0xUrl), concat(...
Ismael's user avatar
  • 30.6k
2 votes

How to use existing ERC20 tokens in local testnet?

You need to enable mainnet forking in Hardhat network to be able to access a copy of mainnet-deployed contracts in your local running instance. You could enable mainnet forking with the following ...
Ahmed Ihsan Tawfeeq's user avatar
2 votes
Accepted

How to understand the constant product formula?

The product k would actually be constant, if the swap fee was 0%. Since AMMs usually have a fee, the product of the reserves is not really a constant in practice. The name ‘constant product market’ ...
pwagner's user avatar
  • 900
2 votes

How to determine the path router of swapExactTokensForTokens

if i got your question correctly, you would like to determine when have 2 address or 3 address in your path. There are instances where you would like to trade your tokenA and tokenB through WETH. That ...
Kelvin Chelenje's user avatar
2 votes
Accepted

Why is there a price difference for pair contracts and swap pair contracts in Uniswap?

The pair price is the price that you will get if you trade an infinitesimally small amount. It is a theoretical equilibrium price that you will never get in practice. The swap price is the price that ...
Undead8's user avatar
  • 3,570
2 votes
Accepted

uniswap price for pair

You're mistaken, Uniswap v3 does not use the formula x*y=k for real amounts of assets. It's a concentrated liquidity AMM and uses a concentrated liquidity formula. Read Uniswap v3 whitepaper. ...
kfx's user avatar
  • 1,516
2 votes

Can i use the data returned from 1inch's api swap, to perform a swap from a smart contract? (i.e for flashloans)

Sure. There are a couple examples in the wild but my favorite example is the swapProxy by smye To get the data from the API disableEstimate=true is a required parameter. Make sure the fromAddress is ...
Belac's user avatar
  • 21
2 votes

Trouble making UniV2 swap on Sepolia with web3py

Because you use function swapETHForExactTokens, thus, you have to define "value" when build_transaction to send ETH with transaction. That why in the transaction hash you can see 0 at value ...
tqdpham96's user avatar
  • 608
1 vote
Accepted

why I can't add slippage percentage greater than 1 in 0x API? what if I want to use 5% of slippage?

The name is misleading. 1 = 100%, so 0.05 = 5%.
Lawrence Forman's user avatar
1 vote

Trying to understand pricing of defi swap pools (x*y=k)

The price impact is not the ratio between the old and new mid price (mid price being the ratio of the reserves). Rather, it is the difference between the mid price and the market price: price_impact = ...
vlj614's user avatar
  • 396
1 vote

How are UniSwap V2 flash swaps recorded

Yes, a flash swap will trigger the same events as a normal swap. The only difference is that in a flash swap, the contract that called the swap can perform some arbitrary code between the moment it ...
Undead8's user avatar
  • 3,570
1 vote

PancakeSwap V2 swapExactTokensForTokens not working, getting stuck

Looks like it was a problem with the BSC node (QuickNode). I have just started using this service but so far it looks very unreliable. Perhaps I am doing something else wrong, I would love to know ...
lobis's user avatar
  • 145
1 vote

PancakeSwap V2 swapExactTokensForTokens not working, getting stuck

You need to call swapExactETHForTokens for swapping WBNB to a token, NOT swapExactTokensForTokens. swapExactTokensForTokens is for swapping a non-BNB token to another non-BNB token. (At least, that is ...
bru53001's user avatar
  • 721
1 vote

Swap error balancer.exchange

The transaction you posted is an Approval transaction, it is not a Swap transaction. You just gave permission to ExchangeProxy contract to run your trades. That's all you did. Nothing to fix. Now you ...
Nulik's user avatar
  • 4,061
1 vote

I tried to buy token with DAI. Its approved but I didnt receive any coin. Help please

I didnt understand what is approved then? You must first run the approve() transaction to allow the Uniswap contracts to withdraw from your token balance on your behalf. (See the approve() part of ...
Richard Horrocks's user avatar
1 vote

I lost my eths? Error encountered during contract execution [Reverted]

The transaction reverted so funds should have been returned immediately. If they didn't then it is a bug in the wallet. Either contact the wallet developers or if you have the seed or private key ...
Ismael's user avatar
  • 30.6k

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