Skip to content

Commit

Permalink
update jupiterSwap
Browse files Browse the repository at this point in the history
  • Loading branch information
POPPIN-FUMI committed Oct 7, 2024
1 parent 107df69 commit b656c90
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
9 changes: 9 additions & 0 deletions packages/sol-swap/src/examples/jupiter/getQuote.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import getJupiterQuote from '@/lib/jupiter/getJupiterQuote'

const getQuote = async () => {
const inputMint = 'inputMint'
const outputMint = 'outputMint'
const inputAmountLamport = 100
const platformFeeBps = 0
const swapMode = 'ExactIn'
const quote = await getJupiterQuote(
inputMint,
outputMint,
inputAmountLamport,
platformFeeBps,
swapMode,
)
}
20 changes: 3 additions & 17 deletions packages/sol-swap/src/lib/jupiter/jupiterSwap.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
import { readFile } from 'fs/promises'
import { Connection, Keypair, VersionedTransaction } from '@solana/web3.js'
import getJupiterQuote, { JupiterSwapMode } from '@/lib/jupiter/getJupiterQuote'
import postJupiterSwap from '@/lib/jupiter/postJupiterSwap'
import 'dotenv/config'
import type { QuoteResponse } from '@jup-ag/api'

const SOLANA_RPC_URL = process.env.SOLANA_RPC_URL || 'http://localhost:8899'
const KEY_FILE_PATH =
process.env.KEY_FILE_PATH || '/home/solv/mainnet-validator-keypair.json'
process.env.KEY_FILE_PATH || '~/mainnet-validator-keypair.json'

const jupiterSwap = async (
inputMint: string,
outputMint: string,
inputAmountLamport: number,
platformFeeBps = 0,
swapMode = 'ExactIn' as JupiterSwapMode,
maxRetries = 3,
) => {
const jupiterSwap = async (quoteResponse: QuoteResponse, maxRetries = 3) => {
try {
const connection = new Connection(SOLANA_RPC_URL, 'confirmed')
const quoteResponse = await getJupiterQuote(
inputMint,
outputMint,
inputAmountLamport,
platformFeeBps,
swapMode,
)

if (typeof quoteResponse === 'string') {
return quoteResponse
Expand Down
4 changes: 2 additions & 2 deletions packages/sol-swap/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tests/cli.test.ts
import { describe, it, expect } from 'vitest'
import { exec } from 'child_process'
import util from 'util'
import { exec } from 'node:child_process'
import util from 'node:util'

const execPromise = util.promisify(exec)

Expand Down
4 changes: 2 additions & 2 deletions packages/sol-swap/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
}
},
"compileOnSave": true,
"include": ["src/lib", "src/index.ts"],
"exclude": ["node_modules", "**/*.spec.ts", "dist", "src/examples"]
"include": ["src/lib", "src/**/*.ts"],
"exclude": ["node_modules", "**/*.spec.ts", "dist"]
}
3 changes: 1 addition & 2 deletions packages/sol-swap/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ export default defineConfig({
sourcemap: true,
clean: true,
dts: true,
external: [
],
external: [],
})

0 comments on commit b656c90

Please sign in to comment.