@drift-labs/common 1.0.39 → 1.0.41

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.
@@ -6,7 +6,9 @@ export declare const CBBTC_SPOT_MARKET_INDEX = 27;
6
6
  export declare const DEFAULT_MAX_MARKET_LEVERAGE = 10;
7
7
  /**
8
8
  * Low-activity perp markets to hide from the UI.
9
- * Users with active positions/orders/unsettled PnL in these markets should still see them.
9
+ * Key = perp market index, Value = Unix timestamp (seconds) after which the market is hidden.
10
+ * Before the timestamp: market is visible but a warning banner is shown.
11
+ * After the timestamp: market is hidden from dropdowns (unless user has positions/orders/unsettled PnL).
10
12
  * Direct URL navigation (e.g. /TIA-PERP) is unaffected.
11
13
  */
12
- export declare const HIDDEN_PERP_MARKET_INDEXES: ReadonlySet<number>;
14
+ export declare const HIDDEN_PERP_MARKET_INDEXES: ReadonlyMap<number, number>;
@@ -9,30 +9,32 @@ exports.CBBTC_SPOT_MARKET_INDEX = 27;
9
9
  exports.DEFAULT_MAX_MARKET_LEVERAGE = 10;
10
10
  /**
11
11
  * Low-activity perp markets to hide from the UI.
12
- * Users with active positions/orders/unsettled PnL in these markets should still see them.
12
+ * Key = perp market index, Value = Unix timestamp (seconds) after which the market is hidden.
13
+ * Before the timestamp: market is visible but a warning banner is shown.
14
+ * After the timestamp: market is hidden from dropdowns (unless user has positions/orders/unsettled PnL).
13
15
  * Direct URL navigation (e.g. /TIA-PERP) is unaffected.
14
16
  */
15
- exports.HIDDEN_PERP_MARKET_INDEXES = new Set([
16
- 5, // POL
17
- 10, // 1MPEPE
18
- 11, // OP
19
- 14, // HNT
20
- 19, // TIA
21
- 21, // SEI
22
- 27, // W
23
- 31, // CLOUD
24
- 34, // POPCAT
25
- 42, // TON
26
- 61, // ME
27
- 62, // PENGU
28
- 64, // TRUMP
29
- 66, // BERA
30
- 69, // KAITO
31
- 70, // IP
32
- 72, // ADA
33
- 77, // XPL
34
- 78, // 2Z
35
- 80, // MNT
36
- 82, // MET
17
+ exports.HIDDEN_PERP_MARKET_INDEXES = new Map([
18
+ [5, 1772625600], // POL — 4 Mar 2026, 12:00 UTC
19
+ [10, 1772625600], // 1MPEPE — 4 Mar 2026, 12:00 UTC
20
+ [11, 1772625600], // OP — 4 Mar 2026, 12:00 UTC
21
+ [14, 1772625600], // HNT — 4 Mar 2026, 12:00 UTC
22
+ [19, 1772625600], // TIA — 4 Mar 2026, 12:00 UTC
23
+ [21, 1772625600], // SEI — 4 Mar 2026, 12:00 UTC
24
+ [27, 1772625600], // W — 4 Mar 2026, 12:00 UTC
25
+ [31, 1772625600], // CLOUD — 4 Mar 2026, 12:00 UTC
26
+ [34, 1772625600], // POPCAT — 4 Mar 2026, 12:00 UTC
27
+ [42, 1772625600], // TON — 4 Mar 2026, 12:00 UTC
28
+ [61, 1772625600], // ME — 4 Mar 2026, 12:00 UTC
29
+ [62, 1772625600], // PENGU — 4 Mar 2026, 12:00 UTC
30
+ [64, 1772625600], // TRUMP — 4 Mar 2026, 12:00 UTC
31
+ [66, 1772625600], // BERA — 4 Mar 2026, 12:00 UTC
32
+ [69, 1772625600], // KAITO — 4 Mar 2026, 12:00 UTC
33
+ [70, 1772625600], // IP — 4 Mar 2026, 12:00 UTC
34
+ [72, 1772625600], // ADA — 4 Mar 2026, 12:00 UTC
35
+ [77, 1772625600], // XPL — 4 Mar 2026, 12:00 UTC
36
+ [78, 1772625600], // 2Z — 4 Mar 2026, 12:00 UTC
37
+ [80, 1772625600], // MNT — 4 Mar 2026, 12:00 UTC
38
+ [82, 1772625600], // MET — 4 Mar 2026, 12:00 UTC
37
39
  ]);
38
40
  //# sourceMappingURL=markets.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"markets.js","sourceRoot":"","sources":["../../src/constants/markets.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAC3B,QAAA,qBAAqB,GAAG,CAAC,CAAC;AAC1B,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAC3B,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAC3B,QAAA,uBAAuB,GAAG,EAAE,CAAC;AAE7B,QAAA,2BAA2B,GAAG,EAAE,CAAC;AAE9C;;;;GAIG;AACU,QAAA,0BAA0B,GAAwB,IAAI,GAAG,CAAC;IACtE,CAAC,EAAE,MAAM;IACT,EAAE,EAAE,SAAS;IACb,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,SAAS;IACb,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,MAAM;CACV,CAAC,CAAC","sourcesContent":["export const USDC_SPOT_MARKET_INDEX = 0;\nexport const SOL_SPOT_MARKET_INDEX = 1;\nexport const WBTC_SPOT_MARKET_INDEX = 3;\nexport const WETH_SPOT_MARKET_INDEX = 4;\nexport const CBBTC_SPOT_MARKET_INDEX = 27;\n\nexport const DEFAULT_MAX_MARKET_LEVERAGE = 10;\n\n/**\n * Low-activity perp markets to hide from the UI.\n * Users with active positions/orders/unsettled PnL in these markets should still see them.\n * Direct URL navigation (e.g. /TIA-PERP) is unaffected.\n */\nexport const HIDDEN_PERP_MARKET_INDEXES: ReadonlySet<number> = new Set([\n\t5, // POL\n\t10, // 1MPEPE\n\t11, // OP\n\t14, // HNT\n\t19, // TIA\n\t21, // SEI\n\t27, // W\n\t31, // CLOUD\n\t34, // POPCAT\n\t42, // TON\n\t61, // ME\n\t62, // PENGU\n\t64, // TRUMP\n\t66, // BERA\n\t69, // KAITO\n\t70, // IP\n\t72, // ADA\n\t77, // XPL\n\t78, // 2Z\n\t80, // MNT\n\t82, // MET\n]);\n"]}
1
+ {"version":3,"file":"markets.js","sourceRoot":"","sources":["../../src/constants/markets.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAC3B,QAAA,qBAAqB,GAAG,CAAC,CAAC;AAC1B,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAC3B,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAC3B,QAAA,uBAAuB,GAAG,EAAE,CAAC;AAE7B,QAAA,2BAA2B,GAAG,EAAE,CAAC;AAE9C;;;;;;GAMG;AACU,QAAA,0BAA0B,GAAgC,IAAI,GAAG,CAAC;IAC9E,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,8BAA8B;IAC/C,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,iCAAiC;IACnD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,6BAA6B;IAC/C,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,8BAA8B;IAChD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,8BAA8B;IAChD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,8BAA8B;IAChD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,4BAA4B;IAC9C,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,gCAAgC;IAClD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,iCAAiC;IACnD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,8BAA8B;IAChD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,6BAA6B;IAC/C,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,gCAAgC;IAClD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,gCAAgC;IAClD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,+BAA+B;IACjD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,gCAAgC;IAClD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,6BAA6B;IAC/C,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,8BAA8B;IAChD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,8BAA8B;IAChD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,6BAA6B;IAC/C,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,8BAA8B;IAChD,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,8BAA8B;CAChD,CAAC,CAAC","sourcesContent":["export const USDC_SPOT_MARKET_INDEX = 0;\nexport const SOL_SPOT_MARKET_INDEX = 1;\nexport const WBTC_SPOT_MARKET_INDEX = 3;\nexport const WETH_SPOT_MARKET_INDEX = 4;\nexport const CBBTC_SPOT_MARKET_INDEX = 27;\n\nexport const DEFAULT_MAX_MARKET_LEVERAGE = 10;\n\n/**\n * Low-activity perp markets to hide from the UI.\n * Key = perp market index, Value = Unix timestamp (seconds) after which the market is hidden.\n * Before the timestamp: market is visible but a warning banner is shown.\n * After the timestamp: market is hidden from dropdowns (unless user has positions/orders/unsettled PnL).\n * Direct URL navigation (e.g. /TIA-PERP) is unaffected.\n */\nexport const HIDDEN_PERP_MARKET_INDEXES: ReadonlyMap<number, number> = new Map([\n\t[5, 1772625600], // POL — 4 Mar 2026, 12:00 UTC\n\t[10, 1772625600], // 1MPEPE — 4 Mar 2026, 12:00 UTC\n\t[11, 1772625600], // OP — 4 Mar 2026, 12:00 UTC\n\t[14, 1772625600], // HNT — 4 Mar 2026, 12:00 UTC\n\t[19, 1772625600], // TIA — 4 Mar 2026, 12:00 UTC\n\t[21, 1772625600], // SEI — 4 Mar 2026, 12:00 UTC\n\t[27, 1772625600], // W — 4 Mar 2026, 12:00 UTC\n\t[31, 1772625600], // CLOUD — 4 Mar 2026, 12:00 UTC\n\t[34, 1772625600], // POPCAT — 4 Mar 2026, 12:00 UTC\n\t[42, 1772625600], // TON — 4 Mar 2026, 12:00 UTC\n\t[61, 1772625600], // ME — 4 Mar 2026, 12:00 UTC\n\t[62, 1772625600], // PENGU — 4 Mar 2026, 12:00 UTC\n\t[64, 1772625600], // TRUMP — 4 Mar 2026, 12:00 UTC\n\t[66, 1772625600], // BERA — 4 Mar 2026, 12:00 UTC\n\t[69, 1772625600], // KAITO — 4 Mar 2026, 12:00 UTC\n\t[70, 1772625600], // IP — 4 Mar 2026, 12:00 UTC\n\t[72, 1772625600], // ADA — 4 Mar 2026, 12:00 UTC\n\t[77, 1772625600], // XPL — 4 Mar 2026, 12:00 UTC\n\t[78, 1772625600], // 2Z — 4 Mar 2026, 12:00 UTC\n\t[80, 1772625600], // MNT — 4 Mar 2026, 12:00 UTC\n\t[82, 1772625600], // MET — 4 Mar 2026, 12:00 UTC\n]);\n"]}
@@ -20,7 +20,7 @@ const createWithdrawIx = async ({ driftClient, amount, spotMarketConfig, user, i
20
20
  }
21
21
  }
22
22
  const authority = user.getUserAccount().authority;
23
- const associatedDepositTokenAddress = await (0, token_1.getTokenAddressForDepositAndWithdraw)(spotMarketConfig.mint, authority);
23
+ const associatedDepositTokenAddress = await (0, token_1.getTokenAddressForDepositAndWithdraw)(spotMarketConfig.mint, authority, (0, sdk_1.getTokenProgramForSpotMarket)(driftClient.getSpotMarketAccount(spotMarketConfig.marketIndex)));
24
24
  const withdrawIxs = await driftClient.getWithdrawalIxs(finalWithdrawAmount.val, spotMarketConfig.marketIndex, associatedDepositTokenAddress, reduceOnly, user.getUserAccount().subAccountId, undefined);
25
25
  return withdrawIxs;
26
26
  };
@@ -1 +1 @@
1
- {"version":3,"file":"withdraw.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/spot/withdraw.ts"],"names":[],"mappings":";;;AAAA,yCAMyB;AAMzB,mDAA+E;AAWxE,MAAM,gBAAgB,GAAG,KAAK,EAAE,EACtC,WAAW,EACX,MAAM,EACN,gBAAgB,EAChB,IAAI,EACJ,QAAQ,EACR,KAAK,GACmB,EAAqC,EAAE;;IAC/D,MAAM,U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,QAAQ,EACR,KAAK,EACL,QAAQ,GACiB,EAA+C,EAAE;IAC1E,MAAM,WAAW,GAAG,MAAM,IAAA,wBAAgB,EAAC;QAC1C,WAAW;QACX,MAAM;QACN,gBAAgB;QAChB,IAAI;QACJ,QAAQ;QACR,KAAK;KACL,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,gBAAgB,CAAC;QAChE,YAAY,EAAE,WAAW;QACzB,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,WAAW,CAAC,UAAU;QAClC,mBAAmB,EAAE,WAAW;QAChC,iCAAiC,EAChC,WAAW,CAAC,2BAA2B,CAAC,IAAI,CAAC,WAAW,CAAC;QAC1D,QAAQ;KACR,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC;AA7BW,QAAA,iBAAiB,qBA6B5B","sourcesContent":["import {\n\tBigNum,\n\tDriftClient,\n\tSpotMarketConfig,\n\tTxParams,\n\tUser,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport { getTokenAddressForDepositAndWithdraw } from '../../../../utils/token';\n\ninterface CreateWithdrawIxParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tamount: BigNum;\n\tspotMarketConfig: SpotMarketConfig;\n\tisBorrow?: boolean;\n\tisMax?: boolean;\n}\n\nexport const createWithdrawIx = async ({\n\tdriftClient,\n\tamount,\n\tspotMarketConfig,\n\tuser,\n\tisBorrow,\n\tisMax,\n}: CreateWithdrawIxParams): Promise<TransactionInstruction[]> => {\n\tconst reduceOnly = !isBorrow;\n\n\tlet finalWithdrawAmount = amount;\n\n\tif (isMax && reduceOnly) {\n\t\t// we over-estimate to ensure that there is no borrow dust left\n\t\t// since reduceOnly is true, it is safe to over-estimate\n\t\tfinalWithdrawAmount = finalWithdrawAmount.scale(2, 1);\n\t\tconst scaledBalance = user\n\t\t\t.getUserAccount()\n\t\t\t.spotPositions.find(\n\t\t\t\t(position) => position.marketIndex === spotMarketConfig.marketIndex\n\t\t\t)?.scaledBalance;\n\t\tif (scaledBalance && scaledBalance.abs().gtn(0)) {\n\t\t\t// we use scaledBalance in case amount argument is zero\n\t\t\tfinalWithdrawAmount = BigNum.max(\n\t\t\t\tfinalWithdrawAmount,\n\t\t\t\tBigNum.from(scaledBalance, spotMarketConfig.precisionExp).scale(2, 1)\n\t\t\t);\n\t\t}\n\t}\n\n\tconst authority = user.getUserAccount().authority;\n\tconst associatedDepositTokenAddress =\n\t\tawait getTokenAddressForDepositAndWithdraw(\n\t\t\tspotMarketConfig.mint,\n\t\t\tauthority\n\t\t);\n\n\tconst withdrawIxs = await driftClient.getWithdrawalIxs(\n\t\tfinalWithdrawAmount.val,\n\t\tspotMarketConfig.marketIndex,\n\t\tassociatedDepositTokenAddress,\n\t\treduceOnly,\n\t\tuser.getUserAccount().subAccountId,\n\t\tundefined\n\t);\n\n\treturn withdrawIxs;\n};\n\ninterface CreateWithdrawTxnParams extends CreateWithdrawIxParams {\n\ttxParams?: TxParams;\n}\n\nexport const createWithdrawTxn = async ({\n\tdriftClient,\n\tamount,\n\tspotMarketConfig,\n\tuser,\n\tisBorrow,\n\tisMax,\n\ttxParams,\n}: CreateWithdrawTxnParams): Promise<Transaction | VersionedTransaction> => {\n\tconst withdrawIxs = await createWithdrawIx({\n\t\tdriftClient,\n\t\tamount,\n\t\tspotMarketConfig,\n\t\tuser,\n\t\tisBorrow,\n\t\tisMax,\n\t});\n\n\tconst withdrawTxn = await driftClient.txHandler.buildTransaction({\n\t\tinstructions: withdrawIxs,\n\t\ttxVersion: 0,\n\t\tconnection: driftClient.connection,\n\t\tpreFlightCommitment: 'confirmed',\n\t\tfetchAllMarketLookupTableAccounts:\n\t\t\tdriftClient.fetchAllLookupTableAccounts.bind(driftClient),\n\t\ttxParams,\n\t});\n\n\treturn withdrawTxn;\n};\n"]}
1
+ {"version":3,"file":"withdraw.js","sourceRoot":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gBAAgB,CACrD,mBAAmB,CAAC,GAAG,EACvB,gBAAgB,CAAC,WAAW,EAC5B,6BAA6B,EAC7B,UAAU,EACV,IAAI,CAAC,cAAc,EAAE,CAAC,YAAY,EAClC,SAAS,CACT,CAAC;IAEF,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC;AAlDW,QAAA,gBAAgB,oBAkD3B;AAMK,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACvC,WAAW,EACX,MAAM,EACN,gBAAgB,EAChB,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,QAAQ,GACiB,EAA+C,EAAE;IAC1E,MAAM,WAAW,GAAG,MAAM,IAAA,wBAAgB,EAAC;QAC1C,WAAW;QACX,MAAM;QACN,gBAAgB;QAChB,IAAI;QACJ,QAAQ;QACR,KAAK;KACL,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,gBAAgB,CAAC;QAChE,YAAY,EAAE,WAAW;QACzB,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,WAAW,CAAC,UAAU;QAClC,mBAAmB,EAAE,WAAW;QAChC,iCAAiC,EAChC,WAAW,CAAC,2BAA2B,CAAC,IAAI,CAAC,WAAW,CAAC;QAC1D,QAAQ;KACR,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC;AA7BW,QAAA,iBAAiB,qBA6B5B","sourcesContent":["import {\n\tBigNum,\n\tDriftClient,\n\tgetTokenProgramForSpotMarket,\n\tSpotMarketConfig,\n\tTxParams,\n\tUser,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport { getTokenAddressForDepositAndWithdraw } from '../../../../utils/token';\n\ninterface CreateWithdrawIxParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tamount: BigNum;\n\tspotMarketConfig: SpotMarketConfig;\n\tisBorrow?: boolean;\n\tisMax?: boolean;\n}\n\nexport const createWithdrawIx = async ({\n\tdriftClient,\n\tamount,\n\tspotMarketConfig,\n\tuser,\n\tisBorrow,\n\tisMax,\n}: CreateWithdrawIxParams): Promise<TransactionInstruction[]> => {\n\tconst reduceOnly = !isBorrow;\n\n\tlet finalWithdrawAmount = amount;\n\n\tif (isMax && reduceOnly) {\n\t\t// we over-estimate to ensure that there is no borrow dust left\n\t\t// since reduceOnly is true, it is safe to over-estimate\n\t\tfinalWithdrawAmount = finalWithdrawAmount.scale(2, 1);\n\t\tconst scaledBalance = user\n\t\t\t.getUserAccount()\n\t\t\t.spotPositions.find(\n\t\t\t\t(position) => position.marketIndex === spotMarketConfig.marketIndex\n\t\t\t)?.scaledBalance;\n\t\tif (scaledBalance && scaledBalance.abs().gtn(0)) {\n\t\t\t// we use scaledBalance in case amount argument is zero\n\t\t\tfinalWithdrawAmount = BigNum.max(\n\t\t\t\tfinalWithdrawAmount,\n\t\t\t\tBigNum.from(scaledBalance, spotMarketConfig.precisionExp).scale(2, 1)\n\t\t\t);\n\t\t}\n\t}\n\n\tconst authority = user.getUserAccount().authority;\n\tconst associatedDepositTokenAddress =\n\t\tawait getTokenAddressForDepositAndWithdraw(\n\t\t\tspotMarketConfig.mint,\n\t\t\tauthority,\n\t\t\tgetTokenProgramForSpotMarket(\n\t\t\t\tdriftClient.getSpotMarketAccount(spotMarketConfig.marketIndex)\n\t\t\t)\n\t\t);\n\n\tconst withdrawIxs = await driftClient.getWithdrawalIxs(\n\t\tfinalWithdrawAmount.val,\n\t\tspotMarketConfig.marketIndex,\n\t\tassociatedDepositTokenAddress,\n\t\treduceOnly,\n\t\tuser.getUserAccount().subAccountId,\n\t\tundefined\n\t);\n\n\treturn withdrawIxs;\n};\n\ninterface CreateWithdrawTxnParams extends CreateWithdrawIxParams {\n\ttxParams?: TxParams;\n}\n\nexport const createWithdrawTxn = async ({\n\tdriftClient,\n\tamount,\n\tspotMarketConfig,\n\tuser,\n\tisBorrow,\n\tisMax,\n\ttxParams,\n}: CreateWithdrawTxnParams): Promise<Transaction | VersionedTransaction> => {\n\tconst withdrawIxs = await createWithdrawIx({\n\t\tdriftClient,\n\t\tamount,\n\t\tspotMarketConfig,\n\t\tuser,\n\t\tisBorrow,\n\t\tisMax,\n\t});\n\n\tconst withdrawTxn = await driftClient.txHandler.buildTransaction({\n\t\tinstructions: withdrawIxs,\n\t\ttxVersion: 0,\n\t\tconnection: driftClient.connection,\n\t\tpreFlightCommitment: 'confirmed',\n\t\tfetchAllMarketLookupTableAccounts:\n\t\t\tdriftClient.fetchAllLookupTableAccounts.bind(driftClient),\n\t\ttxParams,\n\t});\n\n\treturn withdrawTxn;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/common",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "Common functions for Drift",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",