Skip to content

Commit

Permalink
feat: allow to pass 'onlyDirectRoutes' params into default Jupiter sw…
Browse files Browse the repository at this point in the history
…apper (#439)
  • Loading branch information
egor-humandone authored Dec 15, 2023
1 parent 687c3f7 commit 88a01df
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
47 changes: 38 additions & 9 deletions packages/kamino-sdk/src/Kamino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2420,7 +2420,8 @@ export class Kamino {
swapIxsBuilder?: SwapperIxBuilder,
initialUserTokenAtaBalances?: TokensBalances,
priceAInB?: Decimal,
includeAtaIxns: boolean = true // if true it includes create and close wsol and token atas,
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
onlyDirectRoutes?: boolean
): Promise<InstructionsWithLookupTables> => {
const strategyWithAddress = await this.getStrategyStateIfNotFetched(strategy);

Expand Down Expand Up @@ -2467,7 +2468,18 @@ export class Kamino {
user: PublicKey,
slippageBps: Decimal,
allAccounts: PublicKey[]
) => this.getJupSwapIxsV6(input, tokenAMint, tokenBMint, user, slippageBps, false, allAccounts, profiler);
) =>
this.getJupSwapIxsV6(
input,
tokenAMint,
tokenBMint,
user,
slippageBps,
false,
allAccounts,
profiler,
onlyDirectRoutes
);

console.log('single sided deposit tokenA tokenAMinPostDepositBalance', tokenAMinPostDepositBalance);
console.log('single sided deposit tokenA userTokenBalances.b', userTokenBalances.b);
Expand Down Expand Up @@ -2498,7 +2510,8 @@ export class Kamino {
swapIxsBuilder?: SwapperIxBuilder,
initialUserTokenAtaBalances?: TokensBalances,
priceAInB?: Decimal,
includeAtaIxns: boolean = true // if true it includes create and close wsol and token atas,
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
onlyDirectRoutes?: boolean
): Promise<InstructionsWithLookupTables> => {
const strategyWithAddress = await this.getStrategyStateIfNotFetched(strategy);

Expand Down Expand Up @@ -2544,7 +2557,18 @@ export class Kamino {
user: PublicKey,
slippageBps: Decimal,
allAccounts: PublicKey[]
) => this.getJupSwapIxsV6(input, tokenAMint, tokenBMint, user, slippageBps, false, allAccounts, profiler);
) =>
this.getJupSwapIxsV6(
input,
tokenAMint,
tokenBMint,
user,
slippageBps,
false,
allAccounts,
profiler,
onlyDirectRoutes
);

return await profiler(
this.getSingleSidedDepositIxs(
Expand Down Expand Up @@ -2927,7 +2951,8 @@ export class Kamino {
useOnlyLegacyTransaction: boolean,
existingAccounts: PublicKey[],
maxAccounts: number,
profiler: ProfiledFunctionExecution = noopProfiledFunctionExecution
profiler: ProfiledFunctionExecution = noopProfiledFunctionExecution,
onlyDirectRoutes?: boolean
): Promise<[TransactionInstruction[], PublicKey[]]> => {
let jupiterQuote: SwapResponse = input.tokenAToSwapAmount.lt(ZERO)
? await profiler(
Expand All @@ -2938,7 +2963,8 @@ export class Kamino {
tokenBMint,
slippageBps.toNumber(),
useOnlyLegacyTransaction,
maxAccounts
maxAccounts,
onlyDirectRoutes
),
'C-getBestRouteV6',
[]
Expand All @@ -2951,7 +2977,8 @@ export class Kamino {
tokenAMint,
slippageBps.toNumber(),
useOnlyLegacyTransaction,
maxAccounts
maxAccounts,
onlyDirectRoutes
),
'C-getBestRouteV6',
[]
Expand Down Expand Up @@ -2991,7 +3018,8 @@ export class Kamino {
slippageBps: Decimal,
useOnlyLegacyTransaction: boolean,
existingAccounts: PublicKey[],
profiledFunctionExecution: ProfiledFunctionExecution = noopProfiledFunctionExecution
profiledFunctionExecution: ProfiledFunctionExecution = noopProfiledFunctionExecution,
onlyDirectRoutes?: boolean
): Promise<[TransactionInstruction[], PublicKey[]]> => {
console.log('getJupSwapIxsV6', JSON.stringify(input));

Expand All @@ -3018,7 +3046,8 @@ export class Kamino {
useOnlyLegacyTransaction,
existingAccounts,
maxAccounts,
profiledFunctionExecution
profiledFunctionExecution,
onlyDirectRoutes
);

return result;
Expand Down
11 changes: 7 additions & 4 deletions packages/kamino-sdk/src/services/JupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class JupService {
outputMint: PublicKey,
slippageBps: number,
asLegacyTransaction?: boolean,
maxAccounts?: number
maxAccounts?: number,
onlyDirectRoutes?: boolean
): Promise<SwapResponse> => {
try {
const jupiterQuoteApi = createJupiterApiClient(); // config is optional
Expand All @@ -49,7 +50,8 @@ export class JupService {
outputMint,
slippageBps,
asLegacyTransaction,
maxAccounts
maxAccounts,
onlyDirectRoutes
);

const transaction: SwapResponse = await jupiterQuoteApi.swapPost({
Expand All @@ -73,7 +75,8 @@ export class JupService {
outputMint: PublicKey,
slippageBps: number,
asLegacyTransaction?: boolean,
maxAccounts?: number
maxAccounts?: number,
onlyDirectRoutes?: boolean
): Promise<QuoteResponse> => {
try {
const jupiterQuoteApi = createJupiterApiClient(); // config is optional
Expand All @@ -83,7 +86,7 @@ export class JupService {
outputMint: outputMint.toString(),
amount: amount.floor().toNumber(),
slippageBps,
onlyDirectRoutes: false,
onlyDirectRoutes: onlyDirectRoutes,
asLegacyTransaction,
maxAccounts,
};
Expand Down

0 comments on commit 88a01df

Please sign in to comment.