
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@1inch/solana-fusion-sdk
Advanced tools
Add to package.json
{
"dependencies": {
"@1inch/solana-fusion-sdk": "@1inch/solana-fusion-sdk"
}
}
import { Address, FusionSwapContract, Sdk } from '@1inch/solana-fusion-sdk'
import { AxiosHttpProvider } from '@1inch/solana-fusion-sdk/axios'
import { Connection, Keypair, PublicKey, Transaction } from '@solana/web3.js' // v1
const authKey = '...'
const secretKey = Buffer.from('secret', 'base64') // replace to real secret key
const rpc = 'https://api.mainnet-beta.solana.com'
const connection = new Connection(rpc)
const maker = Keypair.fromSecretKey(secretKey)
const sdk = new Sdk(new AxiosHttpProvider(), { baseUrl: 'https://api.1inch.dev/fusion', authKey, version: 'v1.0' })
// create order
// 1 SOL -> USDC
const order = await sdk.createOrder(
Address.NATIVE, // SOL
new Address('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'), // USDC
1_000_000_000n, // 1 SOL
Address.fromPublicKey(maker.publicKey)
)
const contract = FusionSwapContract.default()
// create escrow instruction
const ix = contract.create(order, {
maker: Address.fromPublicKey(maker.publicKey),
srcTokenProgram: Address.TOKEN_PROGRAM_ID
})
// generate tx
const createOrderTx = new Transaction().add({
...ix,
programId: new PublicKey(ix.programId.toBuffer()),
keys: ix.accounts.map((a) => ({
...a,
pubkey: new PublicKey(a.pubkey.toBuffer())
}))
})
createOrderTx.recentBlockhash = (await connection.getRecentBlockhash()).blockhash
createOrderTx.sign(maker)
// broadcast tx
await connection.sendRawTransaction(createOrderTx.serialize())
while (true) {
const status = await sdk.getOrderStatus(order.getOrderHashBase58())
if (!status.isActive()) {
console.log('order finished', status)
break
}
await sleep(1000)
}
export function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms))
}
import { Address, FusionSwapContract, Sdk } from '@1inch/solana-fusion-sdk'
import { AxiosHttpProvider } from '@1inch/solana-fusion-sdk/axios'
import { Connection, Keypair, PublicKey, Transaction } from '@solana/web3.js' // v1
const authKey = '...'
const secretKey = Buffer.from('secret', 'base64') // replace to real secret key
const rpc = 'https://api.mainnet-beta.solana.com'
const connection = new Connection(rpc)
const maker = Keypair.fromSecretKey(secretKey)
const sdk = new Sdk(new AxiosHttpProvider(), { baseUrl: 'https://api.1inch.dev/fusion', authKey, version: 'v1.0' })
const order = ... // see 'Create and submit order' section
const contract = FusionSwapContract.default()
// close escrow instruction
const ix = contract.cancelOwnOrder(order, {
maker: Address.fromPublicKey(maker.publicKey),
srcTokenProgram: Address.TOKEN_PROGRAM_ID
})
// generate tx
const cancelOrderTx = new Transaction().add({
...ix,
programId: new PublicKey(ix.programId.toBuffer()),
keys: ix.accounts.map((a) => ({
...a,
pubkey: new PublicKey(a.pubkey.toBuffer())
}))
})
cancelOrderTx.recentBlockhash = (await connection.getRecentBlockhash()).blockhash
cancelOrderTx.sign(maker)
// broadcast tx
await connection.sendRawTransaction(createOrderTx.serialize())
import { Address, FusionSwapContract, Sdk } from '@1inch/solana-fusion-sdk'
import { AxiosHttpProvider } from '@1inch/solana-fusion-sdk/axios'
import { Connection, Keypair, PublicKey, Transaction } from '@solana/web3.js' // v1
const authKey = '...'
const secretKey = Buffer.from('secret', 'base64') // replace to real secret key
const rpc = 'https://api.mainnet-beta.solana.com'
const connection = new Connection(rpc)
const resolver = Keypair.fromSecretKey(secretKey)
const sdk = new Sdk(new AxiosHttpProvider(), { baseUrl: 'https://api.1inch.dev/fusion', authKey, version: 'v1.0' })
const contract = FusionSwapContract.default()
const activeOrders = await sdk.getActiveOrders()
const orderToFill = activeOrders[0]
// fill order instruction
const ix = contract.fill(
orderToFill.order,
orderToFill.remainingMakerAmount, // fill for remaining amount
accounts: {
taker: Address.fromPublicKey(resolver.publicKey),
maker: orderToFill.maker
srcTokenProgram: Address.TOKEN_PROGRAM_ID,
dstTokenProgram: Address.TOKEN_PROGRAM_ID,
}
)
// generate tx
const fillTx = new Transaction().add({
// at the moment of `ix` execution resolver must have enough source token, so it can be transferred to user
...ix,
programId: new PublicKey(ix.programId.toBuffer()),
keys: ix.accounts.map((a) => ({
...a,
pubkey: new PublicKey(a.pubkey.toBuffer())
}))
})
fillTx.recentBlockhash = (await connection.getRecentBlockhash()).blockhash
fillTx.sign(resolver)
// broadcast tx
await connection.sendRawTransaction(createOrderTx.serialize())
For canceling expired orders, a resolver will be paid order.resolverCancellationConfig.maxCancellationPremium lamports
import { Address, FusionSwapContract, Sdk } from '@1inch/solana-fusion-sdk'
import { AxiosHttpProvider } from '@1inch/solana-fusion-sdk/axios'
import { Connection, Keypair, PublicKey, Transaction } from '@solana/web3.js' // v1
const authKey = '...'
const secretKey = Buffer.from('secret', 'base64') // replace to real secret key
const rpc = 'https://api.mainnet-beta.solana.com'
const connection = new Connection(rpc)
const maker = Keypair.fromSecretKey(secretKey)
const sdk = new Sdk(new AxiosHttpProvider(), { baseUrl: 'https://api.1inch.dev/fusion', authKey, version: 'v1.0' })
const cancellableOrders = await sdk.getOrdersCancellableByResolver()
const order = cancellableOrders[0]
const contract = FusionSwapContract.default()
// close escrow instruction
const ix = contract.cancelOrderByResolver(order.order, {
maker: order.maker,
resolver: Address.fromPublicKey(resolver.publicKey),
srcTokenProgram: Address.TOKEN_PROGRAM_ID
})
// generate tx
const cancelOrderTx = new Transaction().add({
...ix,
programId: new PublicKey(ix.programId.toBuffer()),
keys: ix.accounts.map((a) => ({
...a,
pubkey: new PublicKey(a.pubkey.toBuffer())
}))
})
cancelOrderTx.recentBlockhash = (await connection.getRecentBlockhash()).blockhash
cancelOrderTx.sign(resolver)
// broadcast tx
await connection.sendRawTransaction(createOrderTx.serialize())
FAQs
SDK for fusion on Solana
We found that @1inch/solana-fusion-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.