Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@paraswap/sdk
Advanced tools
Refer to the documentation of the ParaSwap API: https://developers.paraswap.network
Versatility: it works with both web3 and ethers and without direct dependency
Canonicity: bring only the functions you actually need
Lightweight: 400B Gzipped for the most minimalistic variant
yarn add @paraswap/sdk
import { constructSDK, constructAxiosFetcher, constructEthersContractCaller } from '@paraswap/sdk';
const signer = ethers.Wallet.fromMnmemonic('__your_mnemonic__') // or any other signer/provider
const account = '__signer_address__'
const contractCaller = constructEthersContractCaller(signer, account); // alternatively constructWeb3ContractCaller
const fetcher = constructAxiosFetcher(axios); // alternatively constructFetchFetcher
const paraswap = constructSDK({
network: 1,
fetcher,
contractCaller,
});
const txHash = await paraSwap.approveToken(amount, tokenAddress);
const srcToken = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; // ETH
const destToken = '0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5'; // PSP
const srcAmount = '1000000000000000000'; //The source amount multiplied by its decimals: 10 ** 18 here
const srcDecimals = 18
const destDecimals = 18
const priceRoute = await paraSwap.getRate(
{
srcToken,
destToken,
amount,
srcDecimals,
destDecimals,
}
);
Where priceRoute contains the rate and the distribution among exchanges, checkout the OptimalRates type for more details.
const srcToken = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
const srcDecimals = 18
const srcAmount = '1000000000000000000'; // The source amount multiplied by its decimals
const destToken = '0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5';
const destDecimals = 18
const destAmount = priceRoute.destAmount // price route being output of paraSwap.getRate()
const senderAddress = '__sender_address__'; // mandatory
const receiver = '__receiver_address__'; // optional: for swap and transfer
const partnerAddress = '__fee_receiver_address__' // optional: for permission-less monetization
const partnerFeeBps = 50 // optional: fee in base point, for permission-less monetization
const txParams = await paraSwap.buildTx(
{
srcAmount,
srcToken,
srcDecimals,
destAmount,
destToken,
destDecimals,
priceRoute,
senderAddress,
receiver,
partnerAddress,
partnerFeeBps,
}
);
const transactionResponse = await signer.sendTransaction(txParams);
const transactionReceipt = await transactionResponse.wait();
For bundle-size savvy developers, you can construct a lightweight version of this sdk to bring only the functions you need.
For e.g. for fetching rate and allowance only
import { constructPartialSDK, constructFetchFetcher, constructGetRate, constructGetAllowance } from '@paraswap/sdk';
const fetcher = constructFetchFetcher(window.fetch)
const minParaSwap = constructPartialSDK({
network: 1,
fetcher,
}, constructGetRate, constructGetAllowance)
const priceRoute = await minParaSwap.getRate(params)
const allowance = await minParaSwap.getAllowance(userAddress, tokenAddress);
The ParaSwap class is exposed with some effort on backward compatibility with previous versions.
import { ParaSwap } from '@paraswap/sdk'
import axios from 'axios'
import Web3 from 'web3'
const web3Provider = new Web3(window.ethereum)
const account = '__user_address__'
const paraswap = new ParaSwap(
1,
undefined,
web3Provider,
undefined,
account,
axios
)
By analogy to constructPartialSDK
, you can leverage a lightweight version of the sdk for fetching only
import { ParaSwap } from '@paraswap/sdk'
const paraswap = new ParaSwap(
1,
undefined,
undefined,
undefined,
undefined,
undefined,
window.fetch
)
Refer to this README for depecreated documentation for functions usage.
FAQs
ParaSwap SDK
The npm package @paraswap/sdk receives a total of 2,845 weekly downloads. As such, @paraswap/sdk popularity was classified as popular.
We found that @paraswap/sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.