Code Monkey home page Code Monkey logo

examples's People

Contributors

adjkant avatar dannydaniil avatar dongwu-kim avatar florian-s-a-w avatar moodmosaic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

examples's Issues

1000dai/usdt的quote is not accurate !

examples/v3-sdk/quoting/

// #src/libs/constants.ts  File
export const USDT_TOKEN = new Token(
  SupportedChainId.MAINNET,
  '0xdAC17F958D2ee523a2206206994597C13D831ec7',
  6,
  'USDT',
  'USD//T'
)
export const DAI_TOKEN = new Token(
  SupportedChainId.MAINNET,
  '0x6B175474E89094C44Da98b954EedeAC495271d0F',
  18,
  'DAI',
  'Dai Stablecoin'
)

// #config.ts File
export const CurrentConfig: ExampleConfig = {
  rpc: {
    local: 'http://localhost:8545',
    mainnet: 'https://mainnet.infura.io/v3/0ac57a06f2994538829c14745750d721',
  },
  tokens: {
    in: DAI_TOKEN,
    amountIn: 1000,
    out: USDT_TOKEN,
    poolFee: FeeAmount.MEDIUM,
  },
}

The quote returned by SDK is 215.851506 USDT, while the quote returned by Uniswap's official website is 999.731 USDT. The difference is too large!

image image

Can we make "quoting" example compatible with Ethers 6.*?

I tried to make it work in a dApp using Ethers 6.11 but there's some breaking stuff in the way Ethers 5 vs 6 handle Contract instances methods, therefore await quoterContract.callStatic.quoteExactInputSingle() could not execute under Ethers 6.
It would be amazing to have an updated version of this, together with a multi-hop quoting example.
Keep up the good work guys.

Example does not work!

I try to run Uniswap example and always get error in browser console:
Uncaught ReferenceError: Browser is not defined
at Va (encode.js:49:1)

Can anybody help me?

Example trade WETH/USDC fails with `STF` error on mainnet fork

I've been attempting to get the example trade to work using a mainnet fork setup with Anvil, as documented here

As far as I can tell, the example doesn't work with the latest version of the libraries:

    "@uniswap/sdk-core": "^4.0.9",
    "@uniswap/v3-sdk": "^3.10.0",

The error is always:

eth_sendRawTransaction

    Transaction: 0x37640ca5d41ca1e7264fff50678cac102cb88ccc20d002c72ef3355b275fe38c
    Gas used: 115902
    Error: reverted with: revert: STF

    Block Number: 18642983
    Block Hash: 0x31395f673ef6640d4e45273ac643840c9f637c9b5ed826c3d6b1e36c295bf5a9
    Block Time: "Fri, 24 Nov 2023 21:25:20 +0000"

Initially, I was seeing an error with eth_estimateGas:

reason: 'cannot estimate gas; transaction may fail or may require manual gas limit',
  code: 'UNPREDICTABLE_GAS_LIMIT'

So I switched to using a pre-defined gasLimit: 5_000_000 in the Tx.

The steps for getting a quote and approving the swap router for token transfers work but the actual swap fails. As a minor detail, I'm not using the UI code but invoking the functions directly like below, so I can run the example from the command line:

async function performTrade() {
  let t = await createTrade();

  let res = await executeTrade(t);

  console.log(`Trade concluded, ${res}`);
}

performTrade()
  .then(() => console.log(`Complete`))
  .catch((e) => console.error(`Error executing trade`, e));

I can see that the quote returns valid data:

Token0 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
Token1 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Fee 3000
Tick spacing 60
Sqrt PriceX96 BigNumber {
  _hex: '0x55528bdd18dd0fa512bb36b96ace',
  _isBigNumber: true
}
Tick 19984

I'd appreciate any input to troubleshoot this issue. I'd be happy to submit a PR to the docs/example code if there is any change required with the latest version of the v3 SDK.

Space ID SDK support

Please integrate the SDK from Space ID.

At the moment, I have the web3 domain ENS - xandry.eth displayed on Uniswap

But I have registered domains in the BNB and Arbitrum networks, so when I change the network to BNB on Uniswap, I expect to see my domain 115.bnb
And when I switch the network to Arbitrum, I expect to see the 360 domain.

There is documentation page: https://docs.space.id/developer-guide/web3-name-sdk

Снимок2
Снимок1
Снимок

run

action/run/:protocol/api/bridge:main

run problem

Do you have the following problem?
Which node version do you use?

WARNING in ./node_modules/jsbi/dist/jsbi-umd.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/home/wuban/examples/v3-sdk/trading/node_modules/jsbi/lib/jsbi.ts' file: Error: ENOENT: no such file or directory, open '/home/wuban/examples/v3-sdk/trading/node_modules/jsbi/lib/jsbi.ts'

webpack compiled with 1 warning

my node version:
wuban@wuban:~/examples/v3-sdk/trading$ nvm list
-> v16.19.0
v18.16.0
v18.20.0
v20.12.0

> [https://github.com/Uniswap/examples/blame/1ef393c2b8f8206a3dc5a42562382c267bcc361b/v3-sdk/quoting/src/config.ts#L34-L39`](https://github.com/Uniswap/examples/blame/1ef393c2b8f8206a3dc5a42562382c267bcc361b/v3-sdk/quoting/src/config.ts#L34-L39%60)

          > [https://github.com/Uniswap/examples/blame/1ef393c2b8f8206a3dc5a42562382c267bcc361b/v3-sdk/quoting/src/config.ts#L34-L39`](https://github.com/Uniswap/examples/blame/1ef393c2b8f8206a3dc5a42562382c267bcc361b/v3-sdk/quoting/src/config.ts#L34-L39%60)
#27 
| Header |
|--------|
| Cell |
| Cell | 

Originally posted by @Jasonford323 in #53 (comment)

execution reverted error when getting quote on Base

With the Quoting example pointed to Base, I receive this error: {"code":-32000,"message":"execution reverted"

https://github.com/jfbloom22/uniswap-examples

I updated the example to use the latest Uniswap SKD. Got it working pointed to Eth Mainnet. I switched everything to Base, but I can't seem to figure out why I am not able to receive a quote.

I forked base mainnet and am running it locally with: anvil --fork-url https://base-mainnet.chainnodes.org/42e88809-380e-4bcb-8b89-f58ea28dfca0 --fork-block-number 14204436 --fork-chain-id 8453 --chain-id 8453

I pulled the Uniswap contracts from here: https://docs.uniswap.org/contracts/v3/reference/deployments/base-deployments

Any suggestions?

quote.ts problem with direction

examples/v3-sdk/quoting/src/libs/quote.ts

line 21:
const quotedAmountOut = await quoterContract.callStatic.quoteExactInputSingle(
poolConstants.token0,
poolConstants.token1,
poolConstants.fee,
fromReadableAmount(
CurrentConfig.tokens.amountIn,
CurrentConfig.tokens.in.decimals
).toString(),
0
)

poolConstants.token0 and token1=> two tokens of the pool , sorted by address
some time will reverse input and output address ~

Uncaught (in promise) Error: No address for Uniswap Multicall Contract on chain id: 11155111

I got this error when try to use sepolia network in v3sdk/routing

multicall-uniswap-provider.ts:45 Uncaught (in promise) Error: No address for Uniswap Multicall Contract on chain id: 11155111
    at new UniswapMulticallProvider (multicall-uniswap-provider.ts:45:1)
    at new AlphaRouter (alpha-router.ts:385:1)
    at generateRoute (routing.ts:27:1)
    at Example.tsx:62:1
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
    at invokeGuardedCallback (react-dom.development.js:4277:1)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1)
    at executeDispatch (react-dom.development.js:9041:1)
    at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1)

this is in config.ts file

export const CurrentConfig: ExampleConfig = {
  env: Environment.WALLET_EXTENSION,
  rpc: {
    local: 'http://localhost:8545',
    mainnet: 'https://sepolia.infura.io/v3/token',
  },

create new router script

  const router = new AlphaRouter({
    chainId: 11155111,
    provider: getMainnetProvider(),
  })

How to fetch Quotes for Polygon supported tokens

const SFL_TOKEN = new Token(
ChainId.POLYGON,
"0xD1f9c58e33933a993A3891F8acFe05a68E1afC05",
18,
"SFL",
"Sunflower Land"
);

const USDC_TOKEN = new Token(
ChainId.POLYGON,
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
6,
"USDC",
"USD Coin"
);

const CurrentConfig = {
rpc: {
mainnet:
"https://polygon-mainnet.g.alchemy.com/v2/OQu5rBT9v5gr-5zOU2ZvwNzJhaNzTGvj",
},
tokens: {
in: USDC_TOKEN,
amountIn: 1,
out: SFL_TOKEN,
poolFee: FeeAmount.MEDIUM,
},
};

This is my configuration file not able to fetch quotes for SFL_TOKEN swap

Unhandled runtime error

Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="liquidity()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.7.0)

I'm encountering this issue when I change chain from ethereum to polygon.

How to get transaction approval for Polygon network

const WMATIC_TOKEN = new Token(
ChainId.POLYGON,
"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
18,
"WMATIC",
"Wrapped Matic"
);

const USDC_TOKEN = new Token(
ChainId.POLYGON,
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
6,
"USDC",
"USD Coin"
);

const CurrentConfig = {
rpc: {
mainnet:
"https://polygon-mainnet.infura.io/v3/2945612d95e74e4f82e05d4fbf00db6c",
},
tokens: {
in: USDC_TOKEN,
amountIn: 25,
out: WMATIC_TOKEN,
poolFee: FeeAmount.MEDIUM,
},
};

const sendTransaction = async (transaction) => {
if(transaction.value){
transaction.value = BigNumber.from(transaction.value)
}

const txRes = await wallet.sendTransaction(transaction);  // getting error over here
if(txRes){
    console.log('Hurrey')
}else{
    console.log('Hell')
}
let receipt = null
const provider = getProvider();
while(receipt === null){
 try {
     receipt = await provider.getTransactionReceipt(txRes.hash)
     if(receipt === null){
         continue
     }
 } catch (error) {
     console.log(`Receipt error:`, error)
   break
 }
}
if(receipt){
 console.log('Transaction Sent')
 return true;
}else{
 console.log('Transaction Failed')
 return null;
}

}

const getTokenTransferApproval = async (token) => {
const provider = getProvider();
const address = getWalletAddress();

if (!provider || !address) {
console.log("please check provider or walletAddress");
}
try {
const tokenContract = new ethers.Contract(
token.address,
ERC20_ABI,
provider
);

const transaction = await tokenContract.populateTransaction.approve(
    SWAP_ROUTER_ADDRESS,
    fromReadableAmount(
      TOKEN_AMOUNT_TO_APPROVE_FOR_TRANSFER,
      token.decimals
    ).toString()
  )

const resp = await sendTransaction({
  ...transaction,
  from: address,
});

return resp;

} catch (e) {
console.log(e);
console.log('approval failed')
}
};

const tokenApproval = await getTokenTransferApproval(CurrentConfig.tokens.in);

getting error as follow:

Error: transaction underpriced
at /Users/jithendrakumar/Desktop/uniswap/new-uniswap1/node_modules/@ethersproject/providers/lib/json-rpc-batch-provider.js:72:41
at Array.forEach ()
at /Users/jithendrakumar/Desktop/uniswap/new-uniswap1/node_modules/@ethersproject/providers/lib/json-rpc-batch-provider.js:69:27
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: -32000,
data: undefined,
transaction: {
type: 2,
chainId: 137,
nonce: 21,
maxPriorityFeePerGas: BigNumber { _hex: '0x59682f00', _isBigNumber: true },
maxFeePerGas: BigNumber { _hex: '0x6a0d032ab4', _isBigNumber: true },
gasPrice: null,
gasLimit: BigNumber { _hex: '0xb41d', _isBigNumber: true },
to: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
value: BigNumber { _hex: '0x00', _isBigNumber: true },
data: '0x095ea7b3000000000000000000000000e592427a0aece92de3edee1f18e0157c0586156400000000000000000000000000000000000000000001a784379d99db42000000',
accessList: [],
hash: '0x8a40ff615225b916935ceb17e2098b7ff178ef1d24b5ff1ad0bb10d7dd1c693f',
v: 0,
r: '0x0ddf0e88ae53876d4d2d70a556bc25bffab46533ac19ebf75b8150c349c74ebd',
s: '0x6c2ec585a1c12c094bfc7c75b735749cbae97e3056e70de0f1837ae0aba8ee3b',
from: '0xaDe56237C3b7d4E000641eA0484dC9B44B9d366f',
confirmations: 0
},
transactionHash: '0x8a40ff615225b916935ceb17e2098b7ff178ef1d24b5ff1ad0bb10d7dd1c693f'
}

Calculation of Quoting for WETH to USDC is Wrong

Using this configuration in v3-sdk/quoting/config.ts:

  tokens: {
    in: USDC_TOKEN,
    amountIn: 1000,
    out: WETH_TOKEN,
    poolFee: FeeAmount.MEDIUM,
  },

I got this result (which is correct):

Selection_140

On Mar 4th, 2023, 1 ETH is $1570. So with $1000, we would get around 0.63 ETH.

But when I switched the tokens, I got the wrong result. I used this configuration:

  tokens: {
    in: WETH_TOKEN,
    amountIn: 1,
    out: USDC_TOKEN,
    poolFee: FeeAmount.MEDIUM,
  },

Selection_141

The result should be ~1570 USDC.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.