Giter VIP home page Giter VIP logo

jupiter-core-example's People

Contributors

arrowana avatar benchow avatar jakeburden avatar siong1987 avatar worlddlckgh avatar zhengyutay 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jupiter-core-example's Issues

Unexpected timeouts while using jup.ag swap api in NodeJS

Hi guys, I just started to use the Jupiter APIs, but I have one problem with them. It is terribly slow. The code does work, it will swap, but 9 out of 10 times it will time out and I don't know why. I tried to find out where the code gets stuck and it is on the following code: await connection.confirmTransaction(txid); Why could that be? I have also used different RPC endpoints, for example the Helius one, and it was still super slow. I have also made a "race" between trying to swap in in the Jupiter GUI using my custom Helios RPC endpoint and my code with the same Helios RPC endpoint and the GUI was significantly faster. What am I missing please?
This is the code:

const { Connection, Keypair, VersionedTransaction } = require('@solana/web3.js');
const fetch = require('cross-fetch');
const bs58 = require('bs58');


const private_key = 'YOUR_PRIVATE_KEY';
const inputMint = 'So11111111111111111111111111111111111111112';
const outputMint = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
const amount = 100000;
const slippageBps = 10;
const rpcEndpoint = 'https://api.mainnet-beta.solana.com';

//setup connection
const connection = new Connection(rpcEndpoint);

// Setup wallet
const secretKey = bs58.decode(private_key);
const wallet = Keypair.fromSecretKey(secretKey);

async function swap() {
    try {
        // Get quote
        const quoteResponse = await (
            await fetch(`https://quote-api.jup.ag/v6/quote?inputMint=${inputMint}&outputMint=${outputMint}&amount=${amount}&slippageBps=${slippageBps}`)
        ).json();

        // Get serialized transactions for the swap
        const { swapTransaction } = await (
                await fetch('https://quote-api.jup.ag/v6/swap', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    quoteResponse,
                    userPublicKey: wallet.publicKey.toString(),
                    wrapAndUnwrapSol: true,
                    dynamicComputeUnitLimit: true,
                    prioritizationFeeLamports: 'auto'
                })
            })
        ).json();

        // Deserialize and sign the transaction
        const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
        const transaction = VersionedTransaction.deserialize(swapTransactionBuf);
        transaction.sign([wallet]);

        // Execute the transaction
        const rawTransaction = transaction.serialize();
        const txid = await connection.sendRawTransaction(rawTransaction, {
            skipPreflight: true,
            maxRetries: 2
        });
        await connection.confirmTransaction(txid);

        console.log(`Swap successful! Transaction ID: ${txid}`);
        console.log(`View the transaction on Solscan: https://solscan.io/tx/${txid}`);
    } catch (error) {
        console.error('Error during swap:', error);
    }
}

// Run the swap function
swap();

Thank you for you time!

Tick Array error

Keep getting the following errors:
Error: Invariant failed: tickArray is null
Error: Crossed the maximum number of tick arrays

Error - error: TypeError: items.at is not a function or its return value is not iterable

When I run the project with yarn start I got this error:

Getting routes for 1 USDC -> USDT...
{
error: TypeError: items.at is not a function or its return value is not iterable
at r (/Users/daro/projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/src/lib/computeRouteInfos.ts:113:48)
at cartesianIterator.next ()
at cartesianIterator (/Users/daro/projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/src/lib/computeRouteInfos.ts:113:12)
at cartesianIterator.next ()
at cartesian (/Users/daro/projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/src/lib/computeRouteInfos.ts:117:44)
at forEach (/Users/daro/projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/src/lib/computeRouteInfos.ts:221:41)
at Map.forEach ()
at walkTheTree (/Users/daro/projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/src/lib/computeRouteInfos.ts:171:25)
at /Users/daro/projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/src/lib/computeRouteInfos.ts:202:11
at Map.forEach ()
}

TypeError: fields must be array of Layout instances

Right after the start of the application, it's crashing.

➜  jupiter-core-example git:(main) ✗ yarn start
yarn run v1.22.5
$ npm run watch & nodemon --watch ./dist --exec 'node ./dist/main.js' --delay 1000ms
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): dist/**/*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./dist/main.js`
npm WARN lifecycle The node binary used for scripts is /var/folders/b_/695p375x3cd0tfxp0nzgyb9w0000gp/T/yarn--1641625841043-0.08431479813294107/node but npm is using /Users/necmttn/.nvm/versions/node/v14.17.6/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.

> [email protected] watch /Users/necmttn/Projects/crypto/jupiter-core-example
> parcel watch

/Users/necmttn/Projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/node_modules/@saberhq/stableswap-sdk/node_modules/@saberhq/token-utils/node_modules/@solana/buffer-layout/lib/Layout.js:999
            throw new TypeError('fields must be array of Layout instances');
            ^

TypeError: fields must be array of Layout instances
    at new Structure (/Users/necmttn/Projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/node_modules/@saberhq/stableswap-sdk/node_modules/@saberhq/token-utils/node_modules/@solana/buffer-layout/lib/Layout.js:999:19)
    at Object.exports.struct (/Users/necmttn/Projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/node_modules/@saberhq/stableswap-sdk/node_modules/@saberhq/token-utils/node_modules/@solana/buffer-layout/lib/Layout.js:2373:57)
    at structLayout (/Users/necmttn/Projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/node_modules/@saberhq/stableswap-sdk/node_modules/@saberhq/token-utils/dist/cjs/layout.js:18:73)
    at Object.<anonymous> (/Users/necmttn/Projects/crypto/jupiter-core-example/node_modules/@jup-ag/core/node_modules/@saberhq/stableswap-sdk/dist/cjs/state/layout.js:23:59)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
[nodemon] app crashed - waiting for file changes before starting...

SDK: can't cancel orders + expired orders issue

I'm trying to cancel orders via SDK (batchCancelExpiredOrder, cancelOrder). It runs without errors, but the orders are never canceled, although if you go to the website, they are canceled there.

Also, when creating an order createOrder, I specify expiredAt, but the orders remain open, do they need to be manually closed with batchCancelExpiredOrder?

Errors while creating open orders for serum.

Jupiter swap often makes an error when creating open orders for serum.

> Program log: Instruction: CreateOpenOrders
> Invoking System Program
  > Allocate: account Address { address: CQeJQmFyxTVvpEhpoeNMGuEzFs2od8hPrb3y5wHbCqC8, base: None } already in use
  > Program returned error: custom program error: 0x0
> Program [Jupiter Aggregator v3](https://solscan.io/address/JUP3c2Uh3WA4Ng34tw6kPd2G4C5BB21Xo36Je1s32Ph)  consumed 8440 of 1231817 compute units

Buffer Layout Type throwing error - causes Jupiter SDK to globally fail and crash app

I'm getting a resolution issue related to the "@solana/buffer-layout": "4.0.0" resolution and breaking changes to the lib.

There's an extensive thread related to this issue located at solana-labs/solana-program-library#2534 and I've tried all the options suggested without success.

The issue first surfaces when doing a yarn install where the following warning appears: warning Resolution field "@solana/[email protected]" is incompatible with requested version "@solana/buffer-layout@^3.0.0"

If I use typescript types I get the following stack trace error:

TypeError: fields must be array of Layout instances
    at new Structure (~/arby/node_modules/@jup-ag/lifinity-sdk/node_modules/@project-serum/anchor/node_modules/@solana/buffer-layout/src/Layout.ts:1107:13)
    at Object.struct (~/arby/node_modules/@jup-ag/lifinity-sdk/node_modules/@project-serum/anchor/node_modules/@solana/buffer-layout/src/Layout.ts:2615:5)
    at Object.<anonymous> (~/arby/node_modules/@jup-ag/lifinity-sdk/node_modules/@project-serum/anchor/node_modules/@solana/web3.js/src/system-program.ts:648:26)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.require.extensions.<computed> [as .js] (~/arby/node_modules/ts-node/src/index.ts:1445:43)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
[nodemon] app crashed - waiting for file changes before starting...

If I switch to JS without the need for types I get the following stack trace error:

~/arby/node_modules/@jup-ag/lifinity-sdk/node_modules/@project-serum/anchor/node_modules/@solana/buffer-layout/lib/Layout.js:999
            throw new TypeError('fields must be array of Layout instances');
            ^

TypeError: fields must be array of Layout instances
    at new Structure (~/arby/node_modules/@jup-ag/lifinity-sdk/node_modules/@project-serum/anchor/node_modules/@solana/buffer-layout/lib/Layout.js:999:19)
    at Object.exports.struct (~/arby/node_modules/@jup-ag/lifinity-sdk/node_modules/@project-serum/anchor/node_modules/@solana/buffer-layout/lib/Layout.js:2373:57)
    at Object.<anonymous> (~/arby/node_modules/@jup-ag/lifinity-sdk/node_modules/@project-serum/anchor/node_modules/@solana/web3.js/lib/index.cjs.js:3525:37)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (~/arby/node_modules/@jup-ag/lifinity-sdk/node_modules/@project-serum/anchor/dist/cjs/index.js:32:29)

Here's my package.json deps:

{
"dependencies": {
    "@jup-ag/core": "^1.0.0-beta.24",
    "@solana/web3.js": "^1.42.0",
    "axios": "^0.27.2",
    "bcrypt": "^5.0.1",
    "client-sessions": "^0.8.0",
    "crypto-js": "^4.1.1",
    "dotenv": "^16.0.1",
    "express": "^4.17.1",
    "helmet": "^4.6.0",
    "migrate": "^1.7.0",
    "morgan": "^1.10.0",
    "pg": "^8.7.1",
    "sql-template-strings": "^2.2.2",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "@types/client-sessions": "^0.8.3",
    "@types/express": "^4.17.13",
    "@types/morgan": "^1.9.3",
    "@types/node": "^17.0.33",
    "nodemon": "^2.0.12",
    "ts-node": "^10.7.0",
    "typescript": "^4.6.4"
  },
  "resolutions": {
    "@solana/buffer-layout": "4.0.0"
  }
}

I'm out of options for this one. Any help, feedback or fix suggestions welcome.

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.