@haven-fi/solauto-sdk 1.0.134 → 1.0.136

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. package/dist/clients/solautoClient.d.ts.map +1 -1
  2. package/dist/clients/solautoClient.js +49 -39
  3. package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
  4. package/dist/clients/solautoMarginfiClient.js +2 -4
  5. package/dist/generated/accounts/solautoPosition.d.ts +1 -7
  6. package/dist/generated/accounts/solautoPosition.d.ts.map +1 -1
  7. package/dist/generated/accounts/solautoPosition.js +2 -6
  8. package/dist/generated/instructions/cancelDCA.d.ts +3 -3
  9. package/dist/generated/instructions/cancelDCA.d.ts.map +1 -1
  10. package/dist/generated/instructions/cancelDCA.js +6 -6
  11. package/dist/generated/instructions/closePosition.d.ts +1 -2
  12. package/dist/generated/instructions/closePosition.d.ts.map +1 -1
  13. package/dist/generated/instructions/closePosition.js +6 -11
  14. package/dist/generated/instructions/marginfiRebalance.d.ts +2 -2
  15. package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -1
  16. package/dist/generated/instructions/marginfiRebalance.js +4 -4
  17. package/dist/generated/instructions/updatePosition.d.ts +3 -3
  18. package/dist/generated/instructions/updatePosition.d.ts.map +1 -1
  19. package/dist/generated/instructions/updatePosition.js +6 -6
  20. package/dist/generated/types/dCASettings.d.ts +7 -5
  21. package/dist/generated/types/dCASettings.d.ts.map +1 -1
  22. package/dist/generated/types/dCASettings.js +3 -2
  23. package/dist/generated/types/dCASettingsInp.d.ts +5 -3
  24. package/dist/generated/types/dCASettingsInp.d.ts.map +1 -1
  25. package/dist/generated/types/dCASettingsInp.js +2 -1
  26. package/dist/generated/types/index.d.ts +1 -1
  27. package/dist/generated/types/index.d.ts.map +1 -1
  28. package/dist/generated/types/index.js +1 -1
  29. package/dist/generated/types/{feeType.d.ts → tokenType.d.ts} +6 -6
  30. package/dist/generated/types/tokenType.d.ts.map +1 -0
  31. package/dist/generated/types/tokenType.js +22 -0
  32. package/dist/transactions/transactionUtils.d.ts.map +1 -1
  33. package/dist/transactions/transactionUtils.js +15 -15
  34. package/dist/utils/marginfiUtils.d.ts.map +1 -1
  35. package/dist/utils/solauto/generalUtils.d.ts +15 -5
  36. package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
  37. package/dist/utils/solauto/generalUtils.js +16 -9
  38. package/dist/utils/solauto/rebalanceUtils.d.ts +2 -1
  39. package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
  40. package/dist/utils/solauto/rebalanceUtils.js +7 -5
  41. package/package.json +1 -1
  42. package/src/clients/solautoClient.ts +50 -45
  43. package/src/clients/solautoMarginfiClient.ts +2 -4
  44. package/src/generated/accounts/solautoPosition.ts +2 -15
  45. package/src/generated/instructions/cancelDCA.ts +9 -9
  46. package/src/generated/instructions/closePosition.ts +7 -13
  47. package/src/generated/instructions/marginfiRebalance.ts +6 -6
  48. package/src/generated/instructions/updatePosition.ts +9 -9
  49. package/src/generated/types/dCASettings.ts +14 -7
  50. package/src/generated/types/dCASettingsInp.ts +9 -3
  51. package/src/generated/types/index.ts +1 -1
  52. package/src/generated/types/{feeType.ts → tokenType.ts} +8 -9
  53. package/src/transactions/transactionUtils.ts +35 -25
  54. package/src/utils/marginfiUtils.ts +2 -2
  55. package/src/utils/solauto/generalUtils.ts +21 -13
  56. package/src/utils/solauto/rebalanceUtils.ts +9 -8
  57. package/tests/unit/rebalanceCalculations.ts +14 -14
  58. package/dist/generated/types/feeType.d.ts.map +0 -1
  59. package/dist/generated/types/feeType.js +0 -20
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * This code was AUTOGENERATED using the kinobi library.
4
+ * Please DO NOT EDIT THIS FILE, instead use visitors
5
+ * to add features, then rerun kinobi to update it.
6
+ *
7
+ * @see https://github.com/metaplex-foundation/kinobi
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TokenType = void 0;
11
+ exports.getTokenTypeSerializer = getTokenTypeSerializer;
12
+ const serializers_1 = require("@metaplex-foundation/umi/serializers");
13
+ var TokenType;
14
+ (function (TokenType) {
15
+ TokenType[TokenType["Supply"] = 0] = "Supply";
16
+ TokenType[TokenType["Debt"] = 1] = "Debt";
17
+ })(TokenType || (exports.TokenType = TokenType = {}));
18
+ function getTokenTypeSerializer() {
19
+ return (0, serializers_1.scalarEnum)(TokenType, {
20
+ description: 'TokenType',
21
+ });
22
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AA8MzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAmLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,CA4HA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD"}
1
+ {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAEL,aAAa,EAUd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAyNzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAmLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,CA4HA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD"}
@@ -24,17 +24,18 @@ function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn)
24
24
  return undefined;
25
25
  }
26
26
  const usingSupplyTaAction = solautoActions?.find((args) => (0, generated_1.isSolautoAction)("Deposit", args) || (0, generated_1.isSolautoAction)("Withdraw", args));
27
- const usingDebtTaAction = solautoActions?.find((args) => (0, generated_1.isSolautoAction)("Borrow", args) ||
28
- (0, generated_1.isSolautoAction)("Repay", args) ||
29
- initiatingDcaIn ||
30
- cancellingDcaIn);
31
- if (supplyIsWsol && usingSupplyTaAction) {
27
+ const usingDebtTaAction = solautoActions?.find((args) => (0, generated_1.isSolautoAction)("Borrow", args) || (0, generated_1.isSolautoAction)("Repay", args));
28
+ const dcaSupply = (initiatingDcaIn && initiatingDcaIn.tokenType === generated_1.TokenType.Supply) ||
29
+ (cancellingDcaIn !== undefined && cancellingDcaIn === generated_1.TokenType.Supply);
30
+ const dcaDebt = (initiatingDcaIn && initiatingDcaIn.tokenType === generated_1.TokenType.Debt) ||
31
+ (cancellingDcaIn !== undefined && cancellingDcaIn === generated_1.TokenType.Debt);
32
+ if (supplyIsWsol && (usingSupplyTaAction || dcaSupply)) {
32
33
  return {
33
34
  wSolTokenAccount: client.signerSupplyTa,
34
35
  solautoAction: usingSupplyTaAction,
35
36
  };
36
37
  }
37
- else if (debtIsWsol && usingDebtTaAction) {
38
+ else if (debtIsWsol && (usingDebtTaAction || dcaDebt)) {
38
39
  return {
39
40
  wSolTokenAccount: client.signerDebtTa,
40
41
  solautoAction: usingDebtTaAction,
@@ -72,16 +73,17 @@ async function transactionChoresBefore(client, accountsGettingCreated, solautoAc
72
73
  chores = chores.add((0, solanaUtils_1.closeTokenAccountUmiIx)(client.signer, wSolUsage.wSolTokenAccount, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey)));
73
74
  }
74
75
  let amountToTransfer = BigInt(0);
75
- if ((0, generated_1.isSolautoAction)("Deposit", wSolUsage.solautoAction)) {
76
+ if (wSolUsage.solautoAction &&
77
+ (0, generated_1.isSolautoAction)("Deposit", wSolUsage.solautoAction)) {
76
78
  amountToTransfer = BigInt(wSolUsage.solautoAction.fields[0]);
77
79
  }
78
- else if ((0, generated_1.isSolautoAction)("Repay", wSolUsage.solautoAction) &&
80
+ else if (wSolUsage.solautoAction &&
81
+ (0, generated_1.isSolautoAction)("Repay", wSolUsage.solautoAction) &&
79
82
  wSolUsage.solautoAction.fields[0].__kind === "Some") {
80
83
  amountToTransfer = BigInt(wSolUsage.solautoAction.fields[0].fields[0]);
81
84
  }
82
- else if (initiatingDcaIn &&
83
- client.debtMint.toString() === spl_token_1.NATIVE_MINT.toString()) {
84
- amountToTransfer = initiatingDcaIn;
85
+ else if (initiatingDcaIn) {
86
+ amountToTransfer = initiatingDcaIn.amount;
85
87
  }
86
88
  if (amountToTransfer > 0) {
87
89
  const amount = amountToTransfer +
@@ -314,12 +316,10 @@ async function getTransactionChores(client, tx) {
314
316
  const accountsGettingCreated = [];
315
317
  const solautoActions = getSolautoActions(tx);
316
318
  choresBefore = choresBefore.add([
317
- await transactionChoresBefore(client, accountsGettingCreated, solautoActions, client.livePositionUpdates.debtTaBalanceAdjustment > 0
318
- ? client.livePositionUpdates.debtTaBalanceAdjustment
319
- : undefined),
319
+ await transactionChoresBefore(client, accountsGettingCreated, solautoActions, client.livePositionUpdates.dcaInBalance),
320
320
  await rebalanceChoresBefore(client, tx, accountsGettingCreated),
321
321
  ]);
322
- choresAfter = choresAfter.add(transactionChoresAfter(client, solautoActions, client.livePositionUpdates.debtTaBalanceAdjustment < 0));
322
+ choresAfter = choresAfter.add(transactionChoresAfter(client, solautoActions, client.livePositionUpdates.cancellingDca));
323
323
  return [choresBefore, choresAfter];
324
324
  }
325
325
  async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRateBps, attemptNum) {
@@ -1 +1 @@
1
- {"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAyB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAEtE,OAAO,EACL,IAAI,EAKL,MAAM,iBAAiB,CAAC;AAWzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,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AAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0B3B"}
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { Umi } from "@metaplex-foundation/umi";
3
- import { AutomationSettings, DCASettings, DCASettingsInpArgs, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../../generated";
3
+ import { AutomationSettings, DCASettings, DCASettingsInpArgs, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, TokenType } from "../../generated";
4
4
  import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
5
5
  export declare function findMintByTicker(ticker: string): PublicKey;
6
6
  export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
@@ -27,22 +27,32 @@ type PositionAdjustment = {
27
27
  } | {
28
28
  type: "debt";
29
29
  value: bigint;
30
- } | {
31
- type: "debtDcaIn";
32
- value: bigint;
33
30
  } | {
34
31
  type: "settings";
35
32
  value: SolautoSettingsParametersInpArgs;
36
33
  } | {
37
34
  type: "dca";
38
35
  value: DCASettingsInpArgs;
36
+ } | {
37
+ type: "dcaInBalance";
38
+ value: {
39
+ amount: bigint;
40
+ tokenType: TokenType;
41
+ };
42
+ } | {
43
+ type: "cancellingDca";
44
+ value: TokenType;
39
45
  };
40
46
  export declare class LivePositionUpdates {
41
47
  supplyAdjustment: bigint;
42
48
  debtAdjustment: bigint;
43
- debtTaBalanceAdjustment: bigint;
44
49
  settings: SolautoSettingsParameters | undefined;
45
50
  activeDca: DCASettings | undefined;
51
+ dcaInBalance?: {
52
+ amount: bigint;
53
+ tokenType: TokenType;
54
+ };
55
+ cancellingDca: TokenType | undefined;
46
56
  new(update: PositionAdjustment): void;
47
57
  reset(): void;
48
58
  hasUpdates(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5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AAE,kBAAkB,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAC;KAAE,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,SAAS,CAAC;CAAE,CAAC;AAEjD,qBAAa,mBAAmB;IACvB,gBAAgB,SAAa;IAC7B,cAAc,SAAa;IAC3B,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAC/C,YAAY,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAC;KAAE,CAAa;IACrE,aAAa,EAAE,SAAS,GAAG,SAAS,CAAa;IAExD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IA6B9B,KAAK;IASL,UAAU,IAAI,OAAO;CAStB"}
@@ -346,9 +346,10 @@ class LivePositionUpdates {
346
346
  constructor() {
347
347
  this.supplyAdjustment = BigInt(0);
348
348
  this.debtAdjustment = BigInt(0);
349
- this.debtTaBalanceAdjustment = BigInt(0);
350
349
  this.settings = undefined;
351
350
  this.activeDca = undefined;
351
+ this.dcaInBalance = undefined;
352
+ this.cancellingDca = undefined;
352
353
  }
353
354
  new(update) {
354
355
  if (update.type === "supply") {
@@ -357,9 +358,6 @@ class LivePositionUpdates {
357
358
  else if (update.type === "debt") {
358
359
  this.debtAdjustment += update.value;
359
360
  }
360
- else if (update.type === "debtDcaIn") {
361
- this.debtTaBalanceAdjustment += update.value;
362
- }
363
361
  else if (update.type === "settings") {
364
362
  const settings = update.value;
365
363
  this.settings = createSolautoSettings(settings);
@@ -374,23 +372,32 @@ class LivePositionUpdates {
374
372
  padding: new Uint8Array([]),
375
373
  padding1: [],
376
374
  },
377
- debtToAddBaseUnit: BigInt(dca.debtToAddBaseUnit),
378
- padding: new Uint8Array([]),
375
+ dcaInBaseUnit: BigInt(dca.dcaInBaseUnit),
376
+ tokenType: dca.tokenType,
377
+ padding: [],
379
378
  };
380
379
  }
380
+ else if (update.type === "cancellingDca") {
381
+ this.cancellingDca = update.value;
382
+ }
383
+ else if (update.type === "dcaInBalance") {
384
+ this.dcaInBalance = update.value;
385
+ }
381
386
  }
382
387
  reset() {
383
388
  this.supplyAdjustment = BigInt(0);
384
389
  this.debtAdjustment = BigInt(0);
385
- this.debtTaBalanceAdjustment = BigInt(0);
386
390
  this.settings = undefined;
387
391
  this.activeDca = undefined;
392
+ this.dcaInBalance = undefined;
393
+ this.cancellingDca = undefined;
388
394
  }
389
395
  hasUpdates() {
390
396
  return (this.supplyAdjustment !== BigInt(0) ||
391
397
  this.debtAdjustment !== BigInt(0) ||
392
- this.debtTaBalanceAdjustment !== BigInt(0) ||
393
- this.settings !== undefined);
398
+ this.dcaInBalance !== undefined ||
399
+ this.settings !== undefined ||
400
+ this.cancellingDca !== undefined);
394
401
  }
395
402
  }
396
403
  exports.LivePositionUpdates = LivePositionUpdates;
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { SolautoClient } from "../../clients/solautoClient";
3
- import { DCASettings, PositionState, SolautoSettingsParameters } from "../../generated";
3
+ import { DCASettings, PositionState, SolautoSettingsParameters, TokenType } from "../../generated";
4
4
  import { QuoteResponse } from "@jup-ag/api";
5
5
  import { JupSwapDetails } from "../jupiterUtils";
6
6
  export interface RebalanceValues {
@@ -8,6 +8,7 @@ export interface RebalanceValues {
8
8
  debtAdjustmentUsd: number;
9
9
  amountToDcaIn: number;
10
10
  amountUsdToDcaIn: number;
11
+ dcaTokenType?: TokenType;
11
12
  }
12
13
  export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number, limitGapBps?: number): RebalanceValues;
13
14
  export interface FlashLoanDetails {
@@ -1 +1 @@
1
- {"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,yBAAyB,EAC1B,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAkJjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CAgEjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG,SAAS,CAmE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAkChB"}
1
+ {"version":3,"file":"rebalanceUtils.d.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ineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRebalanceValues = getRebalanceValues;
4
4
  exports.getFlashLoanDetails = getFlashLoanDetails;
5
5
  exports.getJupSwapRebalanceDetails = getJupSwapRebalanceDetails;
6
+ const generated_1 = require("../../generated");
6
7
  const generalUtils_1 = require("./generalUtils");
7
8
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
8
9
  const generalUtils_2 = require("../generalUtils");
@@ -10,10 +11,10 @@ const numberUtils_1 = require("../numberUtils");
10
11
  const generalAccounts_1 = require("../../constants/generalAccounts");
11
12
  const solautoConstants_1 = require("../../constants/solautoConstants");
12
13
  function getAdditionalAmountToDcaIn(dca) {
13
- if (dca.debtToAddBaseUnit === BigInt(0)) {
14
+ if (dca.dcaInBaseUnit === BigInt(0)) {
14
15
  return 0;
15
16
  }
16
- const debtBalance = Number(dca.debtToAddBaseUnit);
17
+ const debtBalance = Number(dca.dcaInBaseUnit);
17
18
  const updatedDebtBalance = (0, generalUtils_1.getUpdatedValueFromAutomation)(debtBalance, 0, dca.automation, (0, generalUtils_2.currentUnixSeconds)());
18
19
  return debtBalance - updatedDebtBalance;
19
20
  }
@@ -34,7 +35,7 @@ function getStandardTargetLiqUtilizationRateBps(state, settings) {
34
35
  function targetLiqUtilizationRateBpsFromDCA(state, settings, dca, currentUnixTime) {
35
36
  const adjustedSettings = (0, generalUtils_1.getAdjustedSettingsFromAutomation)(settings, currentUnixTime);
36
37
  let targetRateBps = 0;
37
- if (dca.debtToAddBaseUnit > BigInt(0)) {
38
+ if (dca.dcaInBaseUnit > BigInt(0)) {
38
39
  targetRateBps = Math.max(state.liqUtilizationRateBps, adjustedSettings.boostToBps);
39
40
  }
40
41
  else {
@@ -110,10 +111,11 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
110
111
  debtAdjustmentUsd,
111
112
  amountToDcaIn: amountToDcaIn ?? 0,
112
113
  amountUsdToDcaIn,
114
+ dcaTokenType: dca?.tokenType
113
115
  };
114
116
  }
115
117
  function getFlashLoanDetails(client, values, jupQuote) {
116
- let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
118
+ let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) + (values.dcaTokenType === generated_1.TokenType.Supply ? values.amountUsdToDcaIn : 0);
117
119
  let debtUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
118
120
  const debtAdjustmentWithSlippage = Math.abs(values.debtAdjustmentUsd) +
119
121
  Math.abs(values.debtAdjustmentUsd) * (0, numberUtils_1.fromBps)(jupQuote.slippageBps);
@@ -159,7 +161,7 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
159
161
  const output = values.increasingLeverage
160
162
  ? client.solautoPositionState.supply
161
163
  : client.solautoPositionState.debt;
162
- const usdToSwap = Math.abs(values.debtAdjustmentUsd) + values.amountUsdToDcaIn;
164
+ const usdToSwap = Math.abs(values.debtAdjustmentUsd) + (values.dcaTokenType === generated_1.TokenType.Debt ? values.amountUsdToDcaIn : 0);
163
165
  const inputPrice = values.increasingLeverage
164
166
  ? (0, generalUtils_2.safeGetPrice)(client.debtMint)
165
167
  : (0, generalUtils_2.safeGetPrice)(client.supplyMint);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.134",
3
+ "version": "1.0.136",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -25,6 +25,7 @@ import {
25
25
  SolautoRebalanceTypeArgs,
26
26
  SolautoSettingsParameters,
27
27
  SolautoSettingsParametersInpArgs,
28
+ TokenType,
28
29
  UpdatePositionDataArgs,
29
30
  cancelDCA,
30
31
  closePosition,
@@ -360,10 +361,13 @@ export abstract class SolautoClient extends TxHandler {
360
361
  settingParams?: SolautoSettingsParametersInpArgs,
361
362
  dca?: DCASettingsInpArgs
362
363
  ): TransactionBuilder {
363
- if (dca && dca.debtToAddBaseUnit > 0) {
364
+ if (dca && dca.dcaInBaseUnit > 0) {
364
365
  this.livePositionUpdates.new({
365
- type: "debtDcaIn",
366
- value: BigInt(dca.debtToAddBaseUnit),
366
+ type: "dcaInBalance",
367
+ value: {
368
+ amount: BigInt(dca.dcaInBaseUnit),
369
+ tokenType: dca.tokenType
370
+ },
367
371
  });
368
372
  }
369
373
  if (settingParams) {
@@ -383,38 +387,35 @@ export abstract class SolautoClient extends TxHandler {
383
387
  }
384
388
 
385
389
  updatePositionIx(args: UpdatePositionDataArgs): TransactionBuilder {
386
- let debtMint: UmiPublicKey | undefined = undefined;
387
- let positionDebtTa: UmiPublicKey | undefined = undefined;
388
- let signerDebtTa: UmiPublicKey | undefined = undefined;
390
+ let dcaMint: UmiPublicKey | undefined = undefined;
391
+ let positionDcaTa: UmiPublicKey | undefined = undefined;
392
+ let signerDcaTa: UmiPublicKey | undefined = undefined;
389
393
  if (isOption(args.dca) && isSome(args.dca)) {
390
- debtMint = publicKey(this.debtMint);
391
- positionDebtTa = publicKey(this.positionDebtTa);
392
- signerDebtTa = publicKey(this.signerDebtTa);
394
+ if (args.dca.value.tokenType === TokenType.Supply) {
395
+ dcaMint = publicKey(this.supplyMint);
396
+ positionDcaTa = publicKey(this.positionSupplyTa);
397
+ signerDcaTa = publicKey(this.signerSupplyTa);
398
+ } else {
399
+ dcaMint = publicKey(this.debtMint);
400
+ positionDcaTa = publicKey(this.positionDebtTa);
401
+ signerDcaTa = publicKey(this.signerDebtTa);
402
+ }
393
403
 
394
404
  let addingToPos = false;
395
405
  if (
396
406
  isOption(args.dca) &&
397
407
  isSome(args.dca) &&
398
- args.dca.value.debtToAddBaseUnit > 0
408
+ args.dca.value.dcaInBaseUnit > 0
399
409
  ) {
400
410
  this.livePositionUpdates.new({
401
- type: "debtDcaIn",
402
- value: BigInt(args.dca.value.debtToAddBaseUnit),
411
+ type: "dcaInBalance",
412
+ value: {
413
+ amount: BigInt(args.dca.value.dcaInBaseUnit),
414
+ tokenType: args.dca.value.tokenType
415
+ },
403
416
  });
404
417
  addingToPos = true;
405
418
  }
406
-
407
- if (
408
- this.solautoPositionData?.position.dca.debtToAddBaseUnit &&
409
- !addingToPos
410
- ) {
411
- this.livePositionUpdates.new({
412
- type: "debtDcaIn",
413
- value:
414
- this.solautoPositionData.position.dca.debtToAddBaseUnit *
415
- BigInt(-1),
416
- });
417
- }
418
419
  }
419
420
 
420
421
  if (isOption(args.settingParams) && isSome(args.settingParams)) {
@@ -434,9 +435,9 @@ export abstract class SolautoClient extends TxHandler {
434
435
  return updatePosition(this.umi, {
435
436
  signer: this.signer,
436
437
  solautoPosition: publicKey(this.solautoPosition),
437
- debtMint,
438
- positionDebtTa,
439
- signerDebtTa,
438
+ dcaMint,
439
+ positionDcaTa,
440
+ signerDcaTa,
440
441
  updatePositionData: args,
441
442
  });
442
443
  }
@@ -454,30 +455,34 @@ export abstract class SolautoClient extends TxHandler {
454
455
  }
455
456
 
456
457
  cancelDCAIx(): TransactionBuilder {
457
- let debtMint: UmiPublicKey | undefined = undefined;
458
- let positionDebtTa: UmiPublicKey | undefined = undefined;
459
- let signerDebtTa: UmiPublicKey | undefined = undefined;
460
-
461
- if (this.solautoPositionData !== null && !this.selfManaged) {
462
- const positionData = this.solautoPositionData!.position;
463
- if (positionData.dca.debtToAddBaseUnit) {
464
- debtMint = publicKey(this.debtMint);
465
- positionDebtTa = publicKey(this.positionDebtTa);
466
- signerDebtTa = publicKey(this.signerDebtTa);
467
-
468
- this.livePositionUpdates.new({
469
- type: "debtDcaIn",
470
- value: positionData.dca.debtToAddBaseUnit * BigInt(-1),
471
- });
458
+ let dcaMint: UmiPublicKey | undefined = undefined;
459
+ let positionDcaTa: UmiPublicKey | undefined = undefined;
460
+ let signerDcaTa: UmiPublicKey | undefined = undefined;
461
+
462
+ const currDca = this.solautoPositionActiveDca()!;
463
+ if (currDca.dcaInBaseUnit > 0) {
464
+ if (currDca.tokenType === TokenType.Supply) {
465
+ dcaMint = publicKey(this.supplyMint);
466
+ positionDcaTa = publicKey(this.positionSupplyTa);
467
+ signerDcaTa = publicKey(this.signerSupplyTa);
468
+ } else {
469
+ dcaMint = publicKey(this.debtMint);
470
+ positionDcaTa = publicKey(this.positionDebtTa);
471
+ signerDcaTa = publicKey(this.signerDebtTa);
472
472
  }
473
+
474
+ this.livePositionUpdates.new({
475
+ type: "cancellingDca",
476
+ value: this.solautoPositionData!.position.dca.tokenType,
477
+ });
473
478
  }
474
479
 
475
480
  return cancelDCA(this.umi, {
476
481
  signer: this.signer,
477
482
  solautoPosition: publicKey(this.solautoPosition),
478
- debtMint,
479
- positionDebtTa,
480
- signerDebtTa,
483
+ dcaMint,
484
+ positionDcaTa,
485
+ signerDcaTa,
481
486
  });
482
487
  }
483
488
 
@@ -465,9 +465,7 @@ export class SolautoMarginfiClient extends SolautoClient {
465
465
  supplyBank: publicKey(this.marginfiSupplyAccounts.bank),
466
466
  supplyPriceOracle: publicKey(this.supplyPriceOracle),
467
467
  positionSupplyTa: publicKey(this.positionSupplyTa),
468
- signerSupplyTa: this.selfManaged
469
- ? publicKey(this.signerSupplyTa)
470
- : undefined,
468
+ authoritySupplyTa: publicKey(getTokenAccount(this.authority, this.supplyMint)),
471
469
  vaultSupplyTa: needSupplyAccounts
472
470
  ? publicKey(this.marginfiSupplyAccounts.liquidityVault)
473
471
  : undefined,
@@ -477,7 +475,7 @@ export class SolautoMarginfiClient extends SolautoClient {
477
475
  debtBank: publicKey(this.marginfiDebtAccounts.bank),
478
476
  debtPriceOracle: publicKey(this.debtPriceOracle),
479
477
  positionDebtTa: publicKey(this.positionDebtTa),
480
- signerDebtTa: this.selfManaged ? publicKey(this.signerDebtTa) : undefined,
478
+ authorityDebtTa: publicKey(getTokenAccount(this.authority, this.debtMint)),
481
479
  vaultDebtTa: needDebtAccounts
482
480
  ? publicKey(this.marginfiDebtAccounts.liquidityVault)
483
481
  : undefined,
@@ -28,8 +28,6 @@ import {
28
28
  u8,
29
29
  } from '@metaplex-foundation/umi/serializers';
30
30
  import {
31
- FeeType,
32
- FeeTypeArgs,
33
31
  PodBool,
34
32
  PodBoolArgs,
35
33
  PositionData,
@@ -38,7 +36,6 @@ import {
38
36
  PositionStateArgs,
39
37
  RebalanceData,
40
38
  RebalanceDataArgs,
41
- getFeeTypeSerializer,
42
39
  getPodBoolSerializer,
43
40
  getPositionDataSerializer,
44
41
  getPositionStateSerializer,
@@ -56,8 +53,6 @@ export type SolautoPositionAccountData = {
56
53
  position: PositionData;
57
54
  state: PositionState;
58
55
  rebalance: RebalanceData;
59
- feeType: FeeType;
60
- padding2: Array<number>;
61
56
  padding: Array<number>;
62
57
  };
63
58
 
@@ -70,8 +65,6 @@ export type SolautoPositionAccountDataArgs = {
70
65
  position: PositionDataArgs;
71
66
  state: PositionStateArgs;
72
67
  rebalance: RebalanceDataArgs;
73
- feeType: FeeTypeArgs;
74
- padding2: Array<number>;
75
68
  padding: Array<number>;
76
69
  };
77
70
 
@@ -89,9 +82,7 @@ export function getSolautoPositionAccountDataSerializer(): Serializer<
89
82
  ['position', getPositionDataSerializer()],
90
83
  ['state', getPositionStateSerializer()],
91
84
  ['rebalance', getRebalanceDataSerializer()],
92
- ['feeType', getFeeTypeSerializer()],
93
- ['padding2', array(u8(), { size: 7 })],
94
- ['padding', array(u32(), { size: 30 })],
85
+ ['padding', array(u32(), { size: 32 })],
95
86
  ],
96
87
  { description: 'SolautoPositionAccountData' }
97
88
  ) as Serializer<SolautoPositionAccountDataArgs, SolautoPositionAccountData>;
@@ -179,8 +170,6 @@ export function getSolautoPositionGpaBuilder(
179
170
  position: PositionDataArgs;
180
171
  state: PositionStateArgs;
181
172
  rebalance: RebalanceDataArgs;
182
- feeType: FeeTypeArgs;
183
- padding2: Array<number>;
184
173
  padding: Array<number>;
185
174
  }>({
186
175
  bump: [0, array(u8(), { size: 1 })],
@@ -191,9 +180,7 @@ export function getSolautoPositionGpaBuilder(
191
180
  position: [40, getPositionDataSerializer()],
192
181
  state: [360, getPositionStateSerializer()],
193
182
  rebalance: [648, getRebalanceDataSerializer()],
194
- feeType: [704, getFeeTypeSerializer()],
195
- padding2: [705, array(u8(), { size: 7 })],
196
- padding: [712, array(u32(), { size: 30 })],
183
+ padding: [704, array(u32(), { size: 32 })],
197
184
  })
198
185
  .deserializeUsing<SolautoPosition>((account) =>
199
186
  deserializeSolautoPosition(account)
@@ -33,9 +33,9 @@ export type CancelDCAInstructionAccounts = {
33
33
  tokenProgram?: PublicKey | Pda;
34
34
  ataProgram?: PublicKey | Pda;
35
35
  solautoPosition: PublicKey | Pda;
36
- debtMint?: PublicKey | Pda;
37
- positionDebtTa?: PublicKey | Pda;
38
- signerDebtTa?: PublicKey | Pda;
36
+ dcaMint?: PublicKey | Pda;
37
+ positionDcaTa?: PublicKey | Pda;
38
+ signerDcaTa?: PublicKey | Pda;
39
39
  };
40
40
 
41
41
  // Data.
@@ -97,20 +97,20 @@ export function cancelDCA(
97
97
  isWritable: true as boolean,
98
98
  value: input.solautoPosition ?? null,
99
99
  },
100
- debtMint: {
100
+ dcaMint: {
101
101
  index: 5,
102
102
  isWritable: false as boolean,
103
- value: input.debtMint ?? null,
103
+ value: input.dcaMint ?? null,
104
104
  },
105
- positionDebtTa: {
105
+ positionDcaTa: {
106
106
  index: 6,
107
107
  isWritable: true as boolean,
108
- value: input.positionDebtTa ?? null,
108
+ value: input.positionDcaTa ?? null,
109
109
  },
110
- signerDebtTa: {
110
+ signerDcaTa: {
111
111
  index: 7,
112
112
  isWritable: true as boolean,
113
- value: input.signerDebtTa ?? null,
113
+ value: input.signerDcaTa ?? null,
114
114
  },
115
115
  } satisfies ResolvedAccountsWithIndices;
116
116
 
@@ -34,9 +34,8 @@ export type ClosePositionInstructionAccounts = {
34
34
  ataProgram?: PublicKey | Pda;
35
35
  solautoPosition: PublicKey | Pda;
36
36
  protocolAccount: PublicKey | Pda;
37
- signerSupplyTa: PublicKey | Pda;
38
37
  positionSupplyTa: PublicKey | Pda;
39
- positionSupplyCollateralTa?: PublicKey | Pda;
38
+ signerSupplyTa: PublicKey | Pda;
40
39
  positionDebtTa: PublicKey | Pda;
41
40
  signerDebtTa: PublicKey | Pda;
42
41
  };
@@ -108,28 +107,23 @@ export function closePosition(
108
107
  isWritable: true as boolean,
109
108
  value: input.protocolAccount ?? null,
110
109
  },
111
- signerSupplyTa: {
112
- index: 6,
113
- isWritable: true as boolean,
114
- value: input.signerSupplyTa ?? null,
115
- },
116
110
  positionSupplyTa: {
117
- index: 7,
111
+ index: 6,
118
112
  isWritable: true as boolean,
119
113
  value: input.positionSupplyTa ?? null,
120
114
  },
121
- positionSupplyCollateralTa: {
122
- index: 8,
115
+ signerSupplyTa: {
116
+ index: 7,
123
117
  isWritable: true as boolean,
124
- value: input.positionSupplyCollateralTa ?? null,
118
+ value: input.signerSupplyTa ?? null,
125
119
  },
126
120
  positionDebtTa: {
127
- index: 9,
121
+ index: 8,
128
122
  isWritable: true as boolean,
129
123
  value: input.positionDebtTa ?? null,
130
124
  },
131
125
  signerDebtTa: {
132
- index: 10,
126
+ index: 9,
133
127
  isWritable: true as boolean,
134
128
  value: input.signerDebtTa ?? null,
135
129
  },