Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@jup-ag/core
Advanced tools
Jupiter core typescript library
Yarn
yarn add @jup-ag/core
NPM
npm install @jup-ag/core
import bs58 from 'bs58'
import fetch from 'node-fetch'
import { Connection, PublicKey, Keypair } from '@solana/web3.js'
import { Jupiter, TOKEN_LIST_URL } from '@jup-ag/core'
const SOLANA_RPC_ENDPOINT = "https://solana-api.projectserum.com"
/* *******************
** Wallet/Keypair of Swapper
* *******************/
const WALLET_PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "Paste private key here with funds to swap"
const USER_PRIVATE_KEY = bs58.decode(WALLET_PRIVATE_KEY)
const USER_KEYPAIR = Keypair.fromSecretKey(USER_PRIVATE_KEY)
const main = async () => {
/* *******************
** Setup Solana RPC connection
* *******************/
const connection = new Connection(SOLANA_RPC_ENDPOINT)
/* *******************
** Fetch token list from from Jupiter API
** tokens format
{
chainId: 101,
address: '8f9s1sUmzUbVZMoMh6bufMueYH1u4BJSM57RCEvuVmFp',
symbol: 'TRUE',
name: 'TrueSight',
decimals: 9,
logoURI: 'https://i.ibb.co/pKTWrwP/true.jpg',
tags: [ 'utility-token', 'capital-token' ]
},
* *******************/
const tokens = await (await fetch(TOKEN_LIST_URL['mainnet-beta'])).json()
// console.log(tokens)
/* *******************
** Load Jupiter
* *******************/
const jupiter = await Jupiter.load({
connection,
cluster: 'mainnet-beta',
user: USER_KEYPAIR // or public key
})
/* *******************
** Get routeMap, which maps each tokenMint and their respective tokenMints that are swappable
* *******************/
const routeMap = jupiter.getRouteMap()
// console.log(routeMap)
/* *******************
** Input token: USDC
* *******************/
const inputToken = tokens.find(t => t.address == 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v')
console.log(inputToken)
/* *******************
** Get possible pairs
* *******************/
const possiblePairs = routeMap.get(inputToken.address); // return an array of token mints that can be swapped with SOL
const possiblePairsTokenInfo = {}
possiblePairs.forEach( (address) => {
possiblePairsTokenInfo[address] = tokens.find((t) => {
return t.address == address
})
})
// console.log(possiblePairsTokenInfo)
/* *******************
** Output token: USDT
* *******************/
const outputToken = possiblePairsTokenInfo['Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB']
console.log(outputToken)
/* *******************
** Calculate routes for swapping USDC to USDT with 1% slippage
** routes are sorted based on outputAmount, so ideally the first route is the best.
* *******************/
const inputAmount = parseInt(0.01 * (10**inputToken.decimals))
const slippagePercentage = 1
const routes = await jupiter.computeRoutes(new PublicKey(inputToken.address), new PublicKey(outputToken.address), inputAmount, slippagePercentage);
console.log('Quoted out amount: ', routes[0].outAmount)
/* *******************
** Route Data
{
marketInfos: [
{
marketMeta: [Object],
inputMint: [PublicKey],
outputMint: [PublicKey],
notEnoughLiquidity: false,
minInAmount: undefined,
inAmount: 10000,
outAmount: 9993,
outAmountWithSlippage: 9893,
minOutAmount: undefined,
priceImpactPct: 0,
feeAmount: 4,
feeMint: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
feePct: 0.0004
}
],
getDepositAndFee: [Function: getDepositAndFee],
inAmount: 10000,
outAmount: 9993,
outAmountWithSlippage: 9893,
priceImpactPct: 0
}
* *******************/
// console.log(routes[0])
/* *******************
** Prepare execute exchange
* *******************/
const { execute } = await jupiter.exchange({
route: routes[0]
})
/* *******************
** Swap for keypair
* *******************/
const swapResult = await execute()
if (swapResult.error) {
console.log(swapResult.error)
} else {
console.log(`https://explorer.solana.com/tx/${swapResult.txid}`)
console.log(`inputAddress=${swapResult.inputAddress.toString()} outputAddress=${swapResult.outputAddress.toString()}`)
console.log(`inputAmount=${swapResult.inputAmount} outputAmount=${swapResult.outputAmount}`)
}
}
main()
FAQs
![1*cXNgzu0Pvj4HwOLw4Akwqg](https://user-images.githubusercontent.com/34560707/145749257-e48cb199-521b-476e-9d81-f79bb45ef834.png)
The npm package @jup-ag/core receives a total of 1,072 weekly downloads. As such, @jup-ag/core popularity was classified as popular.
We found that @jup-ag/core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.