@velocity-exchange/sdk 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/lib/browser/adminClient.d.ts +4 -3
  2. package/lib/browser/adminClient.js +5 -13
  3. package/lib/browser/equityFloorManager.d.ts +9 -5
  4. package/lib/browser/equityFloorManager.js +9 -5
  5. package/lib/browser/idl/velocity.d.ts +119 -3
  6. package/lib/browser/idl/velocity.json +119 -3
  7. package/lib/browser/index.d.ts +2 -0
  8. package/lib/browser/index.js +3 -0
  9. package/lib/browser/jupiter/jupiterClient.d.ts +31 -27
  10. package/lib/browser/jupiter/jupiterClient.js +61 -35
  11. package/lib/browser/math/amm.d.ts +6 -5
  12. package/lib/browser/math/amm.js +39 -19
  13. package/lib/browser/math/margin.d.ts +12 -10
  14. package/lib/browser/math/margin.js +16 -14
  15. package/lib/browser/math/superStake.d.ts +9 -9
  16. package/lib/browser/math/superStake.js +8 -8
  17. package/lib/browser/swap/UnifiedSwapClient.d.ts +38 -76
  18. package/lib/browser/swap/UnifiedSwapClient.js +46 -117
  19. package/lib/browser/swap/routeInstructions.d.ts +19 -0
  20. package/lib/browser/swap/routeInstructions.js +43 -0
  21. package/lib/browser/swap/types.d.ts +196 -0
  22. package/lib/browser/swap/types.js +88 -0
  23. package/lib/browser/titan/titanClient.d.ts +32 -68
  24. package/lib/browser/titan/titanClient.js +128 -102
  25. package/lib/browser/types.d.ts +2 -0
  26. package/lib/browser/user.d.ts +16 -18
  27. package/lib/browser/user.js +24 -26
  28. package/lib/browser/velocityClient.d.ts +122 -101
  29. package/lib/browser/velocityClient.js +221 -289
  30. package/lib/node/adminClient.d.ts +4 -3
  31. package/lib/node/adminClient.d.ts.map +1 -1
  32. package/lib/node/adminClient.js +5 -13
  33. package/lib/node/equityFloorManager.d.ts +9 -5
  34. package/lib/node/equityFloorManager.d.ts.map +1 -1
  35. package/lib/node/equityFloorManager.js +9 -5
  36. package/lib/node/idl/velocity.d.ts +119 -3
  37. package/lib/node/idl/velocity.d.ts.map +1 -1
  38. package/lib/node/idl/velocity.json +119 -3
  39. package/lib/node/index.d.ts +2 -0
  40. package/lib/node/index.d.ts.map +1 -1
  41. package/lib/node/index.js +3 -0
  42. package/lib/node/jupiter/jupiterClient.d.ts +31 -27
  43. package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
  44. package/lib/node/jupiter/jupiterClient.js +61 -35
  45. package/lib/node/math/amm.d.ts +6 -5
  46. package/lib/node/math/amm.d.ts.map +1 -1
  47. package/lib/node/math/amm.js +39 -19
  48. package/lib/node/math/margin.d.ts +12 -10
  49. package/lib/node/math/margin.d.ts.map +1 -1
  50. package/lib/node/math/margin.js +16 -14
  51. package/lib/node/math/superStake.d.ts +9 -9
  52. package/lib/node/math/superStake.d.ts.map +1 -1
  53. package/lib/node/math/superStake.js +8 -8
  54. package/lib/node/swap/UnifiedSwapClient.d.ts +38 -76
  55. package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
  56. package/lib/node/swap/UnifiedSwapClient.js +46 -117
  57. package/lib/node/swap/routeInstructions.d.ts +20 -0
  58. package/lib/node/swap/routeInstructions.d.ts.map +1 -0
  59. package/lib/node/swap/routeInstructions.js +43 -0
  60. package/lib/node/swap/types.d.ts +197 -0
  61. package/lib/node/swap/types.d.ts.map +1 -0
  62. package/lib/node/swap/types.js +88 -0
  63. package/lib/node/titan/titanClient.d.ts +32 -68
  64. package/lib/node/titan/titanClient.d.ts.map +1 -1
  65. package/lib/node/titan/titanClient.js +128 -102
  66. package/lib/node/types.d.ts +2 -0
  67. package/lib/node/types.d.ts.map +1 -1
  68. package/lib/node/user.d.ts +16 -18
  69. package/lib/node/user.d.ts.map +1 -1
  70. package/lib/node/user.js +24 -26
  71. package/lib/node/velocityClient.d.ts +122 -101
  72. package/lib/node/velocityClient.d.ts.map +1 -1
  73. package/lib/node/velocityClient.js +221 -289
  74. package/package.json +1 -1
@@ -17,7 +17,7 @@ import { AddressLookupTableAccount, Keypair, PublicKey, TransactionInstruction,
17
17
  import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, SolvencyStatus, MarketStatus, ContractTier, AssetTier, TxParams, AddAmmConstituentMappingDatum, SwapReduceOnly, InitializeConstituentParams, ConstituentStatus, LPPoolAccount, TransferFeeAndPnlPoolDirection, MarketType } from './types';
18
18
  import { BN } from './isomorphic/anchor';
19
19
  import { VelocityClient } from './velocityClient';
20
- import { JupiterClient, QuoteResponse } from './jupiter/jupiterClient';
20
+ import { JupiterClient, JupiterSwapQuote } from './jupiter/jupiterClient';
21
21
  import { SwapMode } from './swap/UnifiedSwapClient';
22
22
  export declare class AdminClient extends VelocityClient {
23
23
  /**
@@ -2283,7 +2283,7 @@ export declare class AdminClient extends VelocityClient {
2283
2283
  slippageBps?: number;
2284
2284
  swapMode?: SwapMode;
2285
2285
  onlyDirectRoutes?: boolean;
2286
- quote?: QuoteResponse;
2286
+ quote?: JupiterSwapQuote;
2287
2287
  lpPoolId: number;
2288
2288
  }): Promise<{
2289
2289
  ixs: TransactionInstruction[];
@@ -2604,5 +2604,6 @@ export declare enum HotRole {
2604
2604
  VaultDeposit = "vaultDeposit",
2605
2605
  MmOracleCrank = "mmOracleCrank",
2606
2606
  AmmSpreadAdjust = "ammSpreadAdjust",
2607
- FeeWithdraw = "feeWithdraw"
2607
+ FeeWithdraw = "feeWithdraw",
2608
+ AccountExtension = "accountExtension"
2608
2609
  }
@@ -793,8 +793,7 @@ class AdminClient extends velocityClient_1.VelocityClient {
793
793
  */
794
794
  async getMoveAmmToPriceIx(perpMarketIndex, targetPrice) {
795
795
  const perpMarket = this.getPerpMarketAccountOrThrow(perpMarketIndex);
796
- const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(perpMarket, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
797
- );
796
+ const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(perpMarket, targetPrice, new anchor_1.BN(1000), 'quote', this.getMMOracleDataForPerpMarket(perpMarketIndex));
798
797
  const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(perpMarket.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
799
798
  const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
800
799
  return await this.program.instruction.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, perpMarket.amm.sqrtK, {
@@ -4496,21 +4495,13 @@ class AdminClient extends velocityClient_1.VelocityClient {
4496
4495
  if (!quote) {
4497
4496
  throw new Error('Could not fetch swap quote. Please try again.');
4498
4497
  }
4498
+ this.assertQuoteMatchesMarkets(quote, inMarket, outMarket);
4499
4499
  const isExactOut = swapMode === 'ExactOut' || quote.swapMode === 'ExactOut';
4500
4500
  const amountIn = new anchor_1.BN(quote.inAmount);
4501
4501
  const exactOutBufferedAmountIn = amountIn.muln(1001).divn(1000); // Add 10bp buffer
4502
- const transaction = await jupiterClient.getSwap({
4502
+ const { instructions: jupiterInstructions, lookupTables } = await jupiterClient.getRouteInstructions({
4503
4503
  quote,
4504
4504
  userPublicKey: this.provider.wallet.publicKey,
4505
- slippageBps,
4506
- });
4507
- const { transactionMessage, lookupTables } = await jupiterClient.getTransactionMessageAndLookupTables({
4508
- transaction,
4509
- });
4510
- const jupiterInstructions = jupiterClient.getJupiterInstructions({
4511
- transactionMessage,
4512
- inputMint: inMarket.mint,
4513
- outputMint: outMarket.mint,
4514
4505
  });
4515
4506
  const preInstructions = [];
4516
4507
  const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
@@ -4523,7 +4514,7 @@ class AdminClient extends velocityClient_1.VelocityClient {
4523
4514
  const inAssociatedTokenAccount = await this.getAssociatedTokenAccount(inMarket.marketIndex, false, inTokenProgram);
4524
4515
  const inAccountInfo = await this.connection.getAccountInfo(inAssociatedTokenAccount);
4525
4516
  if (!inAccountInfo) {
4526
- preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint, tokenProgram));
4517
+ preInstructions.push(this.createAssociatedTokenAccountIdempotentInstruction(inAssociatedTokenAccount, this.provider.wallet.publicKey, this.provider.wallet.publicKey, inMarket.mint, inTokenProgram));
4527
4518
  }
4528
4519
  const { beginSwapIx, endSwapIx } = await this.getSwapIx({
4529
4520
  lpPoolId,
@@ -5119,6 +5110,7 @@ var HotRole;
5119
5110
  HotRole["MmOracleCrank"] = "mmOracleCrank";
5120
5111
  HotRole["AmmSpreadAdjust"] = "ammSpreadAdjust";
5121
5112
  HotRole["FeeWithdraw"] = "feeWithdraw";
5113
+ HotRole["AccountExtension"] = "accountExtension";
5122
5114
  })(HotRole || (exports.HotRole = HotRole = {}));
5123
5115
  /** Anchor encodes Rust enums as `{ <variant>: {} }`. */
5124
5116
  function encodeHotRole(role) {
@@ -18,7 +18,7 @@ import { TxParams } from './types';
18
18
  /** One subaccount's standing relative to its floor. All BN values QUOTE_PRECISION. */
19
19
  export type SubaccountFloorStatus = {
20
20
  subAccountId: number;
21
- /** Cross-margin total collateral, strict (TWAP-bounded) pricing — what the on-chain checks see. */
21
+ /** Net equity (`User.getNetUsdValue`, unweighted live-oracle value), what the onchain checks see. */
22
22
  equity: BN;
23
23
  equityFloor: BN;
24
24
  equityFloorBuffer: BN;
@@ -86,7 +86,7 @@ export type EquityFloorManagerConfig = {
86
86
  subAccountIds?: number[];
87
87
  /**
88
88
  * Client-side equity haircut (QUOTE_PRECISION) applied when sizing floor
89
- * deltas, absorbing the dust by which strict on-chain pricing can differ
89
+ * deltas, absorbing the dust by which onchain oracle pricing can differ
90
90
  * from the client's. Defaults to 1 quote unit ($1).
91
91
  */
92
92
  collateralHaircut?: BN;
@@ -123,8 +123,8 @@ export declare class EquityFloorManager {
123
123
  getMaxQuoteTransferable(fromSubAccountId: number, toSubAccountId: number): BN;
124
124
  /**
125
125
  * Resolves a quote transfer into the exact instruction parameters,
126
- * padding the auto floor delta by the haircut so on-chain strict pricing
127
- * dust cannot fail it. The padded delta never exceeds the amount or the
126
+ * padding the auto floor delta by the haircut so onchain pricing dust
127
+ * cannot fail it. The padded delta never exceeds the amount or the
128
128
  * debited side's floor, so the credited side stays backed whenever it was
129
129
  * before.
130
130
  */
@@ -139,7 +139,11 @@ export declare class EquityFloorManager {
139
139
  * pinned in place and the rest is allocated around them. Throws when the
140
140
  * pool's equity cannot back the total floor plus buffers — at that point
141
141
  * no split works and equity must be deposited (or the admin must lower
142
- * the floor).
142
+ * the floor). Each onchain move also carries a proportional share of the
143
+ * debited side's buffer, so buffers drift toward the same split as the
144
+ * floors; the plan sizes against current buffers and the haircut absorbs
145
+ * the drift dust, but a move can still revert if a credited side cannot
146
+ * back the buffer share it receives.
143
147
  */
144
148
  planFloorRebalance(): FloorMove[];
145
149
  /**
@@ -134,7 +134,7 @@ class EquityFloorManager {
134
134
  }
135
135
  getSubaccountStatus(user) {
136
136
  const userAccount = user.getUserAccountOrThrow();
137
- const equity = user.getTotalCollateral('Initial', true);
137
+ const equity = user.getNetUsdValue();
138
138
  const bufferedFloor = userAccount.equityFloor.add(userAccount.equityFloorBuffer);
139
139
  return {
140
140
  subAccountId: userAccount.subAccountId,
@@ -212,15 +212,15 @@ class EquityFloorManager {
212
212
  }
213
213
  /**
214
214
  * Resolves a quote transfer into the exact instruction parameters,
215
- * padding the auto floor delta by the haircut so on-chain strict pricing
216
- * dust cannot fail it. The padded delta never exceeds the amount or the
215
+ * padding the auto floor delta by the haircut so onchain pricing dust
216
+ * cannot fail it. The padded delta never exceeds the amount or the
217
217
  * debited side's floor, so the credited side stays backed whenever it was
218
218
  * before.
219
219
  */
220
220
  planQuoteTransfer(amount, fromSubAccountId, toSubAccountId) {
221
221
  const fromUser = this.velocityClient.getUser(fromSubAccountId, this.velocityClient.authority);
222
222
  const fromAccount = fromUser.getUserAccountOrThrow();
223
- const equityFloorDelta = (0, margin_1.calculateEquityFloorAutoDelta)(amount, fromUser.getTotalCollateral('Initial', true).sub(this.collateralHaircut), fromAccount.equityFloor, fromAccount.equityFloorBuffer);
223
+ const equityFloorDelta = (0, margin_1.calculateEquityFloorAutoDelta)(amount, fromUser.getNetUsdValue().sub(this.collateralHaircut), fromAccount.equityFloor, fromAccount.equityFloorBuffer);
224
224
  return {
225
225
  amount,
226
226
  marketIndex: numericConstants_2.QUOTE_SPOT_MARKET_INDEX,
@@ -242,7 +242,11 @@ class EquityFloorManager {
242
242
  * pinned in place and the rest is allocated around them. Throws when the
243
243
  * pool's equity cannot back the total floor plus buffers — at that point
244
244
  * no split works and equity must be deposited (or the admin must lower
245
- * the floor).
245
+ * the floor). Each onchain move also carries a proportional share of the
246
+ * debited side's buffer, so buffers drift toward the same split as the
247
+ * floors; the plan sizes against current buffers and the haircut absorbs
248
+ * the drift dust, but a move can still revert if a credited side cannot
249
+ * back the buffer share it receives.
246
250
  */
247
251
  planFloorRebalance() {
248
252
  const subaccounts = this.getManagedUsers().map((user) => this.getSubaccountStatus(user));
@@ -8,7 +8,7 @@ export type Velocity = {
8
8
  "address": "vELoC1audYbSYVRXn1vPaV8Axoa9oU6BYmNGZZBDZ1P";
9
9
  "metadata": {
10
10
  "name": "velocity";
11
- "version": "2.164.0";
11
+ "version": "2.165.0";
12
12
  "spec": "0.1.0";
13
13
  "description": "Created with Anchor";
14
14
  };
@@ -2194,6 +2194,104 @@ export type Velocity = {
2194
2194
  }
2195
2195
  ];
2196
2196
  },
2197
+ {
2198
+ "name": "extendAccount";
2199
+ "docs": [
2200
+ "Grow a zero-copy account to the size this program build compiles in",
2201
+ "for its type (resolved from the account discriminator). The migration",
2202
+ "crank after an upgrade that appends fields to an account struct; no-op",
2203
+ "when already at size. Payer covers the rent-exempt shortfall (auth:",
2204
+ "`AccountExtension` hot key, or warm/cold admin). See",
2205
+ "`docs/ACCOUNT-EXTENSION.md`."
2206
+ ];
2207
+ "discriminator": [
2208
+ 234,
2209
+ 102,
2210
+ 194,
2211
+ 203,
2212
+ 150,
2213
+ 72,
2214
+ 62,
2215
+ 229
2216
+ ];
2217
+ "accounts": [
2218
+ {
2219
+ "name": "state";
2220
+ },
2221
+ {
2222
+ "name": "payer";
2223
+ "writable": true;
2224
+ "signer": true;
2225
+ },
2226
+ {
2227
+ "name": "authority";
2228
+ "signer": true;
2229
+ },
2230
+ {
2231
+ "name": "account";
2232
+ "docs": [
2233
+ "size) from the account discriminator"
2234
+ ];
2235
+ "writable": true;
2236
+ },
2237
+ {
2238
+ "name": "systemProgram";
2239
+ "address": "11111111111111111111111111111111";
2240
+ }
2241
+ ];
2242
+ "args": [];
2243
+ },
2244
+ {
2245
+ "name": "extendAccountDevnet";
2246
+ "docs": [
2247
+ "Devnet/test-only: grow a zero-copy account to an arbitrary larger size",
2248
+ "to exercise the extension flow before a real struct extension exists.",
2249
+ "Stripped from production mainnet builds; `anchor-test` keeps it so the",
2250
+ "integration suite (which builds with default features + `anchor-test`)",
2251
+ "can exercise extension end to end."
2252
+ ];
2253
+ "discriminator": [
2254
+ 58,
2255
+ 206,
2256
+ 231,
2257
+ 21,
2258
+ 136,
2259
+ 141,
2260
+ 180,
2261
+ 252
2262
+ ];
2263
+ "accounts": [
2264
+ {
2265
+ "name": "state";
2266
+ },
2267
+ {
2268
+ "name": "payer";
2269
+ "writable": true;
2270
+ "signer": true;
2271
+ },
2272
+ {
2273
+ "name": "authority";
2274
+ "signer": true;
2275
+ },
2276
+ {
2277
+ "name": "account";
2278
+ "docs": [
2279
+ "zero-copy discriminator"
2280
+ ];
2281
+ "writable": true;
2282
+ },
2283
+ {
2284
+ "name": "systemProgram";
2285
+ "address": "11111111111111111111111111111111";
2286
+ }
2287
+ ];
2288
+ "args": [
2289
+ {
2290
+ "name": "newLen";
2291
+ "type": "u64";
2292
+ }
2293
+ ];
2294
+ },
2197
2295
  {
2198
2296
  "name": "fillPerpOrder";
2199
2297
  "discriminator": [
@@ -16370,6 +16468,11 @@ export type Velocity = {
16370
16468
  "code": 6366;
16371
16469
  "name": "cannotModifyBuilderOrder";
16372
16470
  "msg": "Cannot modify a builder-coded order; cancel and re-place instead";
16471
+ },
16472
+ {
16473
+ "code": 6367;
16474
+ "name": "invalidAccountExtension";
16475
+ "msg": "Invalid account extension";
16373
16476
  }
16374
16477
  ];
16375
16478
  "types": [
@@ -18217,6 +18320,9 @@ export type Velocity = {
18217
18320
  },
18218
18321
  {
18219
18322
  "name": "feeWithdraw";
18323
+ },
18324
+ {
18325
+ "name": "accountExtension";
18220
18326
  }
18221
18327
  ];
18222
18328
  };
@@ -23699,12 +23805,21 @@ export type Velocity = {
23699
23805
  ];
23700
23806
  "type": "pubkey";
23701
23807
  },
23808
+ {
23809
+ "name": "hotAccountExtension";
23810
+ "docs": [
23811
+ "Hot key authorized for the `AccountExtension` role (grows zero-copy",
23812
+ "accounts to the deployed program's size after a struct-extending",
23813
+ "upgrade)."
23814
+ ];
23815
+ "type": "pubkey";
23816
+ },
23702
23817
  {
23703
23818
  "name": "padding";
23704
23819
  "type": {
23705
23820
  "array": [
23706
23821
  "u8",
23707
- 271
23822
+ 239
23708
23823
  ];
23709
23824
  };
23710
23825
  }
@@ -24136,7 +24251,8 @@ export type Velocity = {
24136
24251
  {
24137
24252
  "name": "equityFloor";
24138
24253
  "docs": [
24139
- "Minimum account equity (cross-margin total collateral). Below this the",
24254
+ "Minimum account net equity (unweighted assets plus perp pnl minus",
24255
+ "spot liabilities, see `calculate_user_equity`). Below this the",
24140
24256
  "permissionless breaker can trip. Risk-increasing orders, fills,",
24141
24257
  "withdrawals and deposit transfers must clear `equity_floor +",
24142
24258
  "equity_floor_buffer`. Settable only by the warm/cold admin; 0 disables",
@@ -2,7 +2,7 @@
2
2
  "address": "vELoC1audYbSYVRXn1vPaV8Axoa9oU6BYmNGZZBDZ1P",
3
3
  "metadata": {
4
4
  "name": "velocity",
5
- "version": "2.164.0",
5
+ "version": "2.165.0",
6
6
  "spec": "0.1.0",
7
7
  "description": "Created with Anchor"
8
8
  },
@@ -2188,6 +2188,104 @@
2188
2188
  }
2189
2189
  ]
2190
2190
  },
2191
+ {
2192
+ "name": "extend_account",
2193
+ "docs": [
2194
+ "Grow a zero-copy account to the size this program build compiles in",
2195
+ "for its type (resolved from the account discriminator). The migration",
2196
+ "crank after an upgrade that appends fields to an account struct; no-op",
2197
+ "when already at size. Payer covers the rent-exempt shortfall (auth:",
2198
+ "`AccountExtension` hot key, or warm/cold admin). See",
2199
+ "`docs/ACCOUNT-EXTENSION.md`."
2200
+ ],
2201
+ "discriminator": [
2202
+ 234,
2203
+ 102,
2204
+ 194,
2205
+ 203,
2206
+ 150,
2207
+ 72,
2208
+ 62,
2209
+ 229
2210
+ ],
2211
+ "accounts": [
2212
+ {
2213
+ "name": "state"
2214
+ },
2215
+ {
2216
+ "name": "payer",
2217
+ "writable": true,
2218
+ "signer": true
2219
+ },
2220
+ {
2221
+ "name": "authority",
2222
+ "signer": true
2223
+ },
2224
+ {
2225
+ "name": "account",
2226
+ "docs": [
2227
+ "size) from the account discriminator"
2228
+ ],
2229
+ "writable": true
2230
+ },
2231
+ {
2232
+ "name": "system_program",
2233
+ "address": "11111111111111111111111111111111"
2234
+ }
2235
+ ],
2236
+ "args": []
2237
+ },
2238
+ {
2239
+ "name": "extend_account_devnet",
2240
+ "docs": [
2241
+ "Devnet/test-only: grow a zero-copy account to an arbitrary larger size",
2242
+ "to exercise the extension flow before a real struct extension exists.",
2243
+ "Stripped from production mainnet builds; `anchor-test` keeps it so the",
2244
+ "integration suite (which builds with default features + `anchor-test`)",
2245
+ "can exercise extension end to end."
2246
+ ],
2247
+ "discriminator": [
2248
+ 58,
2249
+ 206,
2250
+ 231,
2251
+ 21,
2252
+ 136,
2253
+ 141,
2254
+ 180,
2255
+ 252
2256
+ ],
2257
+ "accounts": [
2258
+ {
2259
+ "name": "state"
2260
+ },
2261
+ {
2262
+ "name": "payer",
2263
+ "writable": true,
2264
+ "signer": true
2265
+ },
2266
+ {
2267
+ "name": "authority",
2268
+ "signer": true
2269
+ },
2270
+ {
2271
+ "name": "account",
2272
+ "docs": [
2273
+ "zero-copy discriminator"
2274
+ ],
2275
+ "writable": true
2276
+ },
2277
+ {
2278
+ "name": "system_program",
2279
+ "address": "11111111111111111111111111111111"
2280
+ }
2281
+ ],
2282
+ "args": [
2283
+ {
2284
+ "name": "new_len",
2285
+ "type": "u64"
2286
+ }
2287
+ ]
2288
+ },
2191
2289
  {
2192
2290
  "name": "fill_perp_order",
2193
2291
  "discriminator": [
@@ -16364,6 +16462,11 @@
16364
16462
  "code": 6366,
16365
16463
  "name": "CannotModifyBuilderOrder",
16366
16464
  "msg": "Cannot modify a builder-coded order; cancel and re-place instead"
16465
+ },
16466
+ {
16467
+ "code": 6367,
16468
+ "name": "InvalidAccountExtension",
16469
+ "msg": "Invalid account extension"
16367
16470
  }
16368
16471
  ],
16369
16472
  "types": [
@@ -18211,6 +18314,9 @@
18211
18314
  },
18212
18315
  {
18213
18316
  "name": "FeeWithdraw"
18317
+ },
18318
+ {
18319
+ "name": "AccountExtension"
18214
18320
  }
18215
18321
  ]
18216
18322
  }
@@ -23693,12 +23799,21 @@
23693
23799
  ],
23694
23800
  "type": "pubkey"
23695
23801
  },
23802
+ {
23803
+ "name": "hot_account_extension",
23804
+ "docs": [
23805
+ "Hot key authorized for the `AccountExtension` role (grows zero-copy",
23806
+ "accounts to the deployed program's size after a struct-extending",
23807
+ "upgrade)."
23808
+ ],
23809
+ "type": "pubkey"
23810
+ },
23696
23811
  {
23697
23812
  "name": "padding",
23698
23813
  "type": {
23699
23814
  "array": [
23700
23815
  "u8",
23701
- 271
23816
+ 239
23702
23817
  ]
23703
23818
  }
23704
23819
  }
@@ -24130,7 +24245,8 @@
24130
24245
  {
24131
24246
  "name": "equity_floor",
24132
24247
  "docs": [
24133
- "Minimum account equity (cross-margin total collateral). Below this the",
24248
+ "Minimum account net equity (unweighted assets plus perp pnl minus",
24249
+ "spot liabilities, see `calculate_user_equity`). Below this the",
24134
24250
  "permissionless breaker can trip. Risk-increasing orders, fills,",
24135
24251
  "withdrawals and deposit transfers must clear `equity_floor +",
24136
24252
  "equity_floor_buffer`. Settable only by the warm/cold admin; 0 disables",
@@ -65,6 +65,8 @@ export * from './events/parse';
65
65
  export * from './events/pollingLogProvider';
66
66
  export * from './jupiter/jupiterClient';
67
67
  export * from './swap/UnifiedSwapClient';
68
+ export * from './swap/types';
69
+ export * from './swap/routeInstructions';
68
70
  export * from './math/auction';
69
71
  export * from './math/builder';
70
72
  export * from './math/spotMarket';
@@ -96,6 +96,9 @@ __exportStar(require("./events/pollingLogProvider"), exports);
96
96
  __exportStar(require("./jupiter/jupiterClient"), exports);
97
97
  // Primary swap client interface - use this for all swap operations
98
98
  __exportStar(require("./swap/UnifiedSwapClient"), exports);
99
+ // The SwapProvider contract both providers implement, and the shared route filter
100
+ __exportStar(require("./swap/types"), exports);
101
+ __exportStar(require("./swap/routeInstructions"), exports);
99
102
  __exportStar(require("./math/auction"), exports);
100
103
  __exportStar(require("./math/builder"), exports);
101
104
  __exportStar(require("./math/spotMarket"), exports);
@@ -1,6 +1,5 @@
1
1
  import { AddressLookupTableAccount, Connection, PublicKey, TransactionInstruction, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
2
- import { BN } from '../isomorphic/anchor';
3
- import { SwapMode } from '../swap/UnifiedSwapClient';
2
+ import { GetRouteInstructionsParams, SwapMode, SwapProvider, SwapQuote, SwapQuoteParams, SwapRouteInstructions } from '../swap/types';
4
3
  export interface MarketInfo {
5
4
  id: string;
6
5
  inAmount: number;
@@ -207,14 +206,17 @@ export interface QuoteResponse {
207
206
  */
208
207
  errorCode?: string;
209
208
  }
209
+ /** A Jupiter quote plus the payload {@link JupiterClient.getRouteInstructions} needs. */
210
+ export type JupiterSwapQuote = QuoteResponse & SwapQuote;
210
211
  export declare const RECOMMENDED_JUPITER_API_VERSION = "/v1";
211
212
  /** @deprecated Use RECOMMENDED_JUPITER_API instead. lite-api.jup.ag requires migration to api.jup.ag with API key. */
212
213
  export declare const LEGACY_JUPITER_API = "https://lite-api.jup.ag/swap";
213
214
  export declare const RECOMMENDED_JUPITER_API = "https://api.jup.ag/swap";
214
- export declare class JupiterClient {
215
+ export declare class JupiterClient implements SwapProvider {
216
+ readonly providerName: "jupiter";
215
217
  url: string;
216
218
  connection: Connection;
217
- lookupTableCahce: Map<string, AddressLookupTableAccount>;
219
+ lookupTableCache: Map<string, AddressLookupTableAccount>;
218
220
  private apiKey?;
219
221
  /**
220
222
  * Create a Jupiter client
@@ -240,31 +242,34 @@ export declare class JupiterClient {
240
242
  * @param swapMode the swap mode (ExactIn or ExactOut)
241
243
  * @param onlyDirectRoutes whether to only return direct routes
242
244
  */
243
- getQuote({ inputMint, outputMint, amount, maxAccounts, // 50 is an estimated amount with buffer
244
- slippageBps, swapMode, onlyDirectRoutes, excludeDexes, autoSlippage, maxAutoSlippageBps, usdEstimate, }: {
245
- inputMint: PublicKey;
246
- outputMint: PublicKey;
247
- amount: BN;
248
- maxAccounts?: number;
249
- slippageBps?: number;
250
- swapMode?: SwapMode;
251
- onlyDirectRoutes?: boolean;
252
- excludeDexes?: string[];
253
- autoSlippage?: boolean;
254
- maxAutoSlippageBps?: number;
255
- usdEstimate?: number;
256
- }): Promise<QuoteResponse>;
245
+ getQuote({ inputMint, outputMint, amount, maxAccounts, slippageBps, swapMode, onlyDirectRoutes, excludeDexes, autoSlippage, maxAutoSlippageBps, usdEstimate, }: SwapQuoteParams): Promise<JupiterSwapQuote>;
257
246
  /**
258
247
  * Get a swap transaction for quote
259
- * @param quoteResponse quote to perform swap
248
+ * @param quote quote to perform swap, from {@link getQuote}
260
249
  * @param userPublicKey the signer's wallet public key
261
- * @param slippageBps the slippage tolerance in basis points
250
+ *
251
+ * Always builds at the quote's own slippage — the price the caller was
252
+ * shown. Re-quote to change it rather than overriding it here.
262
253
  */
263
- getSwap({ quote, userPublicKey, slippageBps, }: {
264
- quote: QuoteResponse;
254
+ getSwap({ quote, userPublicKey, }: {
255
+ quote: QuoteResponse | JupiterSwapQuote;
265
256
  userPublicKey: PublicKey;
266
- slippageBps?: number;
267
257
  }): Promise<VersionedTransaction>;
258
+ /**
259
+ * The standalone transaction Jupiter's `/swap` endpoint returns, setup and
260
+ * teardown included.
261
+ * @throws If the quote came from a different provider or a different wallet.
262
+ */
263
+ getSwapTransaction({ quote, userPublicKey, }: GetRouteInstructionsParams): Promise<VersionedTransaction>;
264
+ /**
265
+ * Builds the route instructions for a quote returned by {@link getQuote}.
266
+ *
267
+ * The quote carries its own route payload, so this reads no client state
268
+ * and two quotes in flight can never be confused for one another. The swap
269
+ * is built at the slippage the quote was priced at — re-quote to change it.
270
+ * @throws If the quote came from a different provider or a different wallet.
271
+ */
272
+ getRouteInstructions({ quote, userPublicKey, }: GetRouteInstructionsParams): Promise<SwapRouteInstructions>;
268
273
  /**
269
274
  * Get the transaction message and lookup tables for a transaction
270
275
  * @param transaction
@@ -277,10 +282,9 @@ export declare class JupiterClient {
277
282
  }>;
278
283
  getLookupTable(accountKey: PublicKey): Promise<AddressLookupTableAccount | undefined>;
279
284
  /**
280
- * Get the jupiter instructions from transaction by filtering out instructions to compute budget and associated token programs
281
- * @param transactionMessage the transaction message
282
- * @param inputMint the input mint
283
- * @param outputMint the output mint
285
+ * Strips the setup/teardown Jupiter wraps around its route.
286
+ * @deprecated Use {@link getRouteInstructions}, which quotes and filters in
287
+ * one step. Kept for callers holding a decompiled message of their own.
284
288
  */
285
289
  getJupiterInstructions({ transactionMessage, inputMint, outputMint, }: {
286
290
  transactionMessage: TransactionMessage;