diff --git a/docs/spot.md b/docs/spot.md index 9ba375a..b067963 100644 --- a/docs/spot.md +++ b/docs/spot.md @@ -51,8 +51,10 @@ jup spot quote --from --to --raw-amount 1000000000 ```bash jup spot swap --from SOL --to USDC --amount 1 jup spot swap --from SOL --to USDC --amount 1 --key mykey +jup spot swap --from SOL --to USDC --amount 1 --slippage 100 ``` +- `--slippage ` max slippage in basis points (default: 30 = 0.3%) - `--key` overrides the active key for this transaction ```js diff --git a/src/clients/UltraClient.ts b/src/clients/UltraClient.ts index 504618a..a74e9e7 100644 --- a/src/clients/UltraClient.ts +++ b/src/clients/UltraClient.ts @@ -8,6 +8,7 @@ type GetOrderRequest = { outputMint: string; amount: string; taker?: string | undefined; + slippageBps?: number | undefined; }; export type GetOrderResponse = { diff --git a/src/commands/SpotCommand.ts b/src/commands/SpotCommand.ts index c7fa304..9339d15 100644 --- a/src/commands/SpotCommand.ts +++ b/src/commands/SpotCommand.ts @@ -48,6 +48,7 @@ export class SpotCommand { "--raw-amount ", "Amount in on-chain units (no decimal conversion)" ) + .option("--slippage ", "Max slippage in basis points", "30") .option("--key ", "Key to use for signing") .action((opts) => this.swap(opts)); spot @@ -200,10 +201,16 @@ export class SpotCommand { to: string; amount?: string; rawAmount?: string; + slippage?: string; key?: string; }): Promise { this.validateAmountOpts(opts); + const slippageBps = Number(opts.slippage ?? "30"); + if (isNaN(slippageBps) || slippageBps < 0 || slippageBps > 10000) { + throw new Error("--slippage must be 0-10000 (basis points)"); + } + const settings = Config.load(); const [signer, inputToken, outputToken] = await Promise.all([ Signer.load(opts.key ?? settings.activeKey), @@ -224,6 +231,7 @@ export class SpotCommand { inputMultiplier ), taker: signer.address, + slippageBps, }); if (order.error) {