@drift-labs/common 1.0.40 → 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.
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"withdraw.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/spot/withdraw.ts"],"names":[],"mappings":";;;AAAA,yCAOyB;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,UAAU,GAAG,CAAC,QAAQ,CAAC;IAE7B,IAAI,mBAAmB,GAAG,MAAM,CAAC;IAEjC,IAAI,KAAK,IAAI,UAAU,EAAE,CAAC;QACzB,+DAA+D;QAC/D,wDAAwD;QACxD,mBAAmB,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAA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W;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"]}
|