@drift-labs/sdk 2.31.1-beta.25 → 2.31.1-beta.26

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.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.31.1-beta.25
1
+ 2.31.1-beta.26
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.24",
2
+ "version": "2.31.1-beta.25",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
package/lib/user.d.ts CHANGED
@@ -266,12 +266,16 @@ export declare class User {
266
266
  * @param outMarketIndex
267
267
  * @param calculateSwap function to similate in to out swa
268
268
  * @param iterationLimit how long to run appromixation before erroring out
269
+ * @param inDelta how much to initially add to inAmount
270
+ * @param outDelta how much to initially add to outAmount
269
271
  */
270
- getMaxSwapAmount({ inMarketIndex, outMarketIndex, calculateSwap, iterationLimit, }: {
272
+ getMaxSwapAmount({ inMarketIndex, outMarketIndex, calculateSwap, iterationLimit, inDelta, outDelta, }: {
271
273
  inMarketIndex: number;
272
274
  outMarketIndex: number;
273
275
  calculateSwap?: (inAmount: BN) => BN;
274
276
  iterationLimit?: number;
277
+ inDelta?: BN;
278
+ outDelta?: BN;
275
279
  }): {
276
280
  inAmount: BN;
277
281
  outAmount: BN;
package/lib/user.js CHANGED
@@ -1105,8 +1105,10 @@ class User {
1105
1105
  * @param outMarketIndex
1106
1106
  * @param calculateSwap function to similate in to out swa
1107
1107
  * @param iterationLimit how long to run appromixation before erroring out
1108
+ * @param inDelta how much to initially add to inAmount
1109
+ * @param outDelta how much to initially add to outAmount
1108
1110
  */
1109
- getMaxSwapAmount({ inMarketIndex, outMarketIndex, calculateSwap, iterationLimit = 1000, }) {
1111
+ getMaxSwapAmount({ inMarketIndex, outMarketIndex, calculateSwap, iterationLimit = 1000, inDelta, outDelta, }) {
1110
1112
  const inMarket = this.driftClient.getSpotMarketAccount(inMarketIndex);
1111
1113
  const outMarket = this.driftClient.getSpotMarketAccount(outMarketIndex);
1112
1114
  const inOraclePrice = this.getOracleDataForSpotMarket(inMarketIndex).price;
@@ -1114,10 +1116,16 @@ class User {
1114
1116
  const inPrecision = new _1.BN(10 ** inMarket.decimals);
1115
1117
  const outPrecision = new _1.BN(10 ** outMarket.decimals);
1116
1118
  const outSaferThanIn = inMarket.initialAssetWeight < outMarket.initialAssetWeight;
1117
- const inSpotPosition = this.getSpotPosition(inMarketIndex) ||
1119
+ let inSpotPosition = this.getSpotPosition(inMarketIndex) ||
1118
1120
  this.getEmptySpotPosition(inMarketIndex);
1119
- const outSpotPosition = this.getSpotPosition(outMarketIndex) ||
1121
+ if (inDelta) {
1122
+ inSpotPosition = this.cloneAndUpdateSpotPosition(inSpotPosition, inDelta, inMarket);
1123
+ }
1124
+ let outSpotPosition = this.getSpotPosition(outMarketIndex) ||
1120
1125
  this.getEmptySpotPosition(outMarketIndex);
1126
+ if (outDelta) {
1127
+ outSpotPosition = this.cloneAndUpdateSpotPosition(outSpotPosition, outDelta, outMarket);
1128
+ }
1121
1129
  const freeCollateral = this.getFreeCollateral();
1122
1130
  const inContributionInitial = this.calculateSpotPositionFreeCollateralContribution(inSpotPosition);
1123
1131
  const { totalAssetValue: inTotalAssetValueInitial, totalLiabilityValue: inTotalLiabilityValueInitial, } = this.calculateSpotPositionLeverageContribution(inSpotPosition);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.31.1-beta.25",
3
+ "version": "2.31.1-beta.26",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.25",
2
+ "version": "2.31.1-beta.26",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
package/src/user.ts CHANGED
@@ -1987,17 +1987,23 @@ export class User {
1987
1987
  * @param outMarketIndex
1988
1988
  * @param calculateSwap function to similate in to out swa
1989
1989
  * @param iterationLimit how long to run appromixation before erroring out
1990
+ * @param inDelta how much to initially add to inAmount
1991
+ * @param outDelta how much to initially add to outAmount
1990
1992
  */
1991
1993
  public getMaxSwapAmount({
1992
1994
  inMarketIndex,
1993
1995
  outMarketIndex,
1994
1996
  calculateSwap,
1995
1997
  iterationLimit = 1000,
1998
+ inDelta,
1999
+ outDelta,
1996
2000
  }: {
1997
2001
  inMarketIndex: number;
1998
2002
  outMarketIndex: number;
1999
2003
  calculateSwap?: (inAmount: BN) => BN;
2000
2004
  iterationLimit?: number;
2005
+ inDelta?: BN;
2006
+ outDelta?: BN;
2001
2007
  }): { inAmount: BN; outAmount: BN; leverage: BN } {
2002
2008
  const inMarket = this.driftClient.getSpotMarketAccount(inMarketIndex);
2003
2009
  const outMarket = this.driftClient.getSpotMarketAccount(outMarketIndex);
@@ -2012,12 +2018,26 @@ export class User {
2012
2018
  const outSaferThanIn =
2013
2019
  inMarket.initialAssetWeight < outMarket.initialAssetWeight;
2014
2020
 
2015
- const inSpotPosition =
2021
+ let inSpotPosition =
2016
2022
  this.getSpotPosition(inMarketIndex) ||
2017
2023
  this.getEmptySpotPosition(inMarketIndex);
2018
- const outSpotPosition =
2024
+ if (inDelta) {
2025
+ inSpotPosition = this.cloneAndUpdateSpotPosition(
2026
+ inSpotPosition,
2027
+ inDelta,
2028
+ inMarket
2029
+ );
2030
+ }
2031
+ let outSpotPosition =
2019
2032
  this.getSpotPosition(outMarketIndex) ||
2020
2033
  this.getEmptySpotPosition(outMarketIndex);
2034
+ if (outDelta) {
2035
+ outSpotPosition = this.cloneAndUpdateSpotPosition(
2036
+ outSpotPosition,
2037
+ outDelta,
2038
+ outMarket
2039
+ );
2040
+ }
2021
2041
 
2022
2042
  const freeCollateral = this.getFreeCollateral();
2023
2043