Skip to content

Commit

Permalink
feat(AllbridgeCoreSdkOptions): add optional jupiterMaxAccounts parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKozAllB committed Jan 27, 2025
1 parent 7e8ae33 commit f1cc941
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export interface AllbridgeCoreSdkOptions {
* Jupiter v6 Swap Api
*/
jupiterUrl: string;
/**
* Jupiter v6 'maxAccounts' parameter</br>
* Rough estimate of the max accounts to be used for the quote, so that you can compose with your own accounts</br>
* {@link https://station.jup.ag/docs/apis/swap-api#using-maxaccounts}
*/
jupiterMaxAccounts?: number;
wormholeMessengerProgramId: string;
solanaLookUpTable: string;
sorobanNetworkPassphrase: string;
Expand Down
1 change: 1 addition & 0 deletions src/services/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export function getChainBridgeService(
solanaLookUpTable: params.solanaLookUpTable,
cctpParams: params.cctpParams,
jupiterUrl: params.jupiterUrl,
jupiterMaxAccounts: params.jupiterMaxAccounts,
},
api,
);
Expand Down
3 changes: 2 additions & 1 deletion src/services/bridge/sol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface SolanaBridgeParams {
solanaLookUpTable: string;
cctpParams: CctpParams;
jupiterUrl: string;
jupiterMaxAccounts?: number;
}

export interface CctpParams {
Expand Down Expand Up @@ -90,7 +91,7 @@ export class SolanaBridgeService extends ChainBridgeService {
public api: AllbridgeCoreClient,
) {
super();
this.jupiterService = new JupiterService(solanaRpcUrl, params.jupiterUrl);
this.jupiterService = new JupiterService(solanaRpcUrl, params.jupiterUrl, params.jupiterMaxAccounts);
}

async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {
Expand Down
16 changes: 9 additions & 7 deletions src/services/bridge/sol/jupiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { fetchAddressLookupTableAccountsFromTx } from "../../../utils/sol/utils"
export class JupiterService {
connection: Connection;
jupiterUrl: string;
maxAccounts?: number;

constructor(solanaRpcUrl: string, jupiterUrl: string) {
constructor(solanaRpcUrl: string, jupiterUrl: string, jupiterMaxAccounts?: number) {
this.connection = new Connection(solanaRpcUrl);
this.jupiterUrl = jupiterUrl.replace(/\/$/, ""); // trim last "/" if exist
this.maxAccounts = jupiterMaxAccounts;
}

async getJupiterSwapTx(
Expand All @@ -22,12 +24,12 @@ export class JupiterService {
let quoteResponse: any;
try {
const swapMode = exactOut ? "ExactOut" : "ExactIn";
quoteResponse = await axios.get(`${this.jupiterUrl}/quote?inputMint=${stableTokenAddress}
&outputMint=${NATIVE_MINT.toString()}
&amount=${amount}
&swapMode=${swapMode}
&slippageBps=100
&onlyDirectRoutes=true`);
let url = `${this.jupiterUrl}/quote?inputMint=${stableTokenAddress}&outputMint=${NATIVE_MINT.toString()}&amount=${amount}&swapMode=${swapMode}&slippageBps=100&onlyDirectRoutes=true`;

if (this.maxAccounts) {
url += `&maxAccounts=${this.maxAccounts}`;
}
quoteResponse = await axios.get(url);
} catch (err) {
if (err instanceof AxiosError && err.response && err.response.data && err.response.data.error) {
throw new JupiterError(err.response.data.error);
Expand Down

0 comments on commit f1cc941

Please sign in to comment.