@haven-fi/solauto-sdk 1.0.134 → 1.0.135

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. package/dist/clients/solautoClient.d.ts.map +1 -1
  2. package/dist/clients/solautoClient.js +49 -39
  3. package/dist/generated/accounts/solautoPosition.d.ts +1 -7
  4. package/dist/generated/accounts/solautoPosition.d.ts.map +1 -1
  5. package/dist/generated/accounts/solautoPosition.js +2 -6
  6. package/dist/generated/instructions/cancelDCA.d.ts +3 -3
  7. package/dist/generated/instructions/cancelDCA.d.ts.map +1 -1
  8. package/dist/generated/instructions/cancelDCA.js +6 -6
  9. package/dist/generated/instructions/closePosition.d.ts +1 -2
  10. package/dist/generated/instructions/closePosition.d.ts.map +1 -1
  11. package/dist/generated/instructions/closePosition.js +6 -11
  12. package/dist/generated/instructions/updatePosition.d.ts +3 -3
  13. package/dist/generated/instructions/updatePosition.d.ts.map +1 -1
  14. package/dist/generated/instructions/updatePosition.js +6 -6
  15. package/dist/generated/types/dCASettings.d.ts +7 -5
  16. package/dist/generated/types/dCASettings.d.ts.map +1 -1
  17. package/dist/generated/types/dCASettings.js +3 -2
  18. package/dist/generated/types/dCASettingsInp.d.ts +5 -3
  19. package/dist/generated/types/dCASettingsInp.d.ts.map +1 -1
  20. package/dist/generated/types/dCASettingsInp.js +2 -1
  21. package/dist/generated/types/index.d.ts +1 -1
  22. package/dist/generated/types/index.d.ts.map +1 -1
  23. package/dist/generated/types/index.js +1 -1
  24. package/dist/generated/types/{feeType.d.ts → tokenType.d.ts} +6 -6
  25. package/dist/generated/types/tokenType.d.ts.map +1 -0
  26. package/dist/generated/types/tokenType.js +22 -0
  27. package/dist/transactions/transactionUtils.d.ts.map +1 -1
  28. package/dist/transactions/transactionUtils.js +15 -15
  29. package/dist/utils/marginfiUtils.d.ts.map +1 -1
  30. package/dist/utils/solauto/generalUtils.d.ts +15 -5
  31. package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
  32. package/dist/utils/solauto/generalUtils.js +16 -9
  33. package/dist/utils/solauto/rebalanceUtils.d.ts +2 -1
  34. package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
  35. package/dist/utils/solauto/rebalanceUtils.js +7 -5
  36. package/package.json +1 -1
  37. package/src/clients/solautoClient.ts +50 -45
  38. package/src/generated/accounts/solautoPosition.ts +2 -15
  39. package/src/generated/instructions/cancelDCA.ts +9 -9
  40. package/src/generated/instructions/closePosition.ts +7 -13
  41. package/src/generated/instructions/updatePosition.ts +9 -9
  42. package/src/generated/types/dCASettings.ts +14 -7
  43. package/src/generated/types/dCASettingsInp.ts +9 -3
  44. package/src/generated/types/index.ts +1 -1
  45. package/src/generated/types/{feeType.ts → tokenType.ts} +8 -9
  46. package/src/transactions/transactionUtils.ts +35 -25
  47. package/src/utils/marginfiUtils.ts +2 -2
  48. package/src/utils/solauto/generalUtils.ts +21 -13
  49. package/src/utils/solauto/rebalanceUtils.ts +9 -8
  50. package/tests/unit/rebalanceCalculations.ts +14 -14
  51. package/dist/generated/types/feeType.d.ts.map +0 -1
  52. package/dist/generated/types/feeType.js +0 -20
@@ -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;AAC5C,OAAO,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAKjC,MAAM,iBAAiB,CAAC;AAezB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAW1D;AAgBD,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAET;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,EAC9B,oBAAoB,EAAE,MAAM,UAY7B;AAED,wBAAgB,iCAAiC,C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-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,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BAAyB,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,CAiEjB;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"}
@@ -3,6 +3,7 @@ Object.defineProperty(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.135",
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
 
@@ -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
  },
@@ -37,9 +37,9 @@ export type UpdatePositionInstructionAccounts = {
37
37
  systemProgram?: PublicKey | Pda;
38
38
  tokenProgram?: PublicKey | Pda;
39
39
  solautoPosition: PublicKey | Pda;
40
- debtMint?: PublicKey | Pda;
41
- positionDebtTa?: PublicKey | Pda;
42
- signerDebtTa?: PublicKey | Pda;
40
+ dcaMint?: PublicKey | Pda;
41
+ positionDcaTa?: PublicKey | Pda;
42
+ signerDcaTa?: PublicKey | Pda;
43
43
  };
44
44
 
45
45
  // Data.
@@ -111,20 +111,20 @@ export function updatePosition(
111
111
  isWritable: true as boolean,
112
112
  value: input.solautoPosition ?? null,
113
113
  },
114
- debtMint: {
114
+ dcaMint: {
115
115
  index: 4,
116
116
  isWritable: false as boolean,
117
- value: input.debtMint ?? null,
117
+ value: input.dcaMint ?? null,
118
118
  },
119
- positionDebtTa: {
119
+ positionDcaTa: {
120
120
  index: 5,
121
121
  isWritable: true as boolean,
122
- value: input.positionDebtTa ?? null,
122
+ value: input.positionDcaTa ?? null,
123
123
  },
124
- signerDebtTa: {
124
+ signerDcaTa: {
125
125
  index: 6,
126
126
  isWritable: true as boolean,
127
- value: input.signerDebtTa ?? null,
127
+ value: input.signerDcaTa ?? null,
128
128
  },
129
129
  } satisfies ResolvedAccountsWithIndices;
130
130
 
@@ -8,26 +8,32 @@
8
8
 
9
9
  import {
10
10
  Serializer,
11
- bytes,
11
+ array,
12
12
  struct,
13
13
  u64,
14
+ u8,
14
15
  } from '@metaplex-foundation/umi/serializers';
15
16
  import {
16
17
  AutomationSettings,
17
18
  AutomationSettingsArgs,
19
+ TokenType,
20
+ TokenTypeArgs,
18
21
  getAutomationSettingsSerializer,
22
+ getTokenTypeSerializer,
19
23
  } from '.';
20
24
 
21
25
  export type DCASettings = {
22
26
  automation: AutomationSettings;
23
- debtToAddBaseUnit: bigint;
24
- padding: Uint8Array;
27
+ dcaInBaseUnit: bigint;
28
+ tokenType: TokenType;
29
+ padding: Array<number>;
25
30
  };
26
31
 
27
32
  export type DCASettingsArgs = {
28
33
  automation: AutomationSettingsArgs;
29
- debtToAddBaseUnit: number | bigint;
30
- padding: Uint8Array;
34
+ dcaInBaseUnit: number | bigint;
35
+ tokenType: TokenTypeArgs;
36
+ padding: Array<number>;
31
37
  };
32
38
 
33
39
  export function getDCASettingsSerializer(): Serializer<
@@ -37,8 +43,9 @@ export function getDCASettingsSerializer(): Serializer<
37
43
  return struct<DCASettings>(
38
44
  [
39
45
  ['automation', getAutomationSettingsSerializer()],
40
- ['debtToAddBaseUnit', u64()],
41
- ['padding', bytes({ size: 32 })],
46
+ ['dcaInBaseUnit', u64()],
47
+ ['tokenType', getTokenTypeSerializer()],
48
+ ['padding', array(u8(), { size: 31 })],
42
49
  ],
43
50
  { description: 'DCASettings' }
44
51
  ) as Serializer<DCASettingsArgs, DCASettings>;
@@ -10,17 +10,22 @@ import { Serializer, struct, u64 } from '@metaplex-foundation/umi/serializers';
10
10
  import {
11
11
  AutomationSettingsInp,
12
12
  AutomationSettingsInpArgs,
13
+ TokenType,
14
+ TokenTypeArgs,
13
15
  getAutomationSettingsInpSerializer,
16
+ getTokenTypeSerializer,
14
17
  } from '.';
15
18
 
16
19
  export type DCASettingsInp = {
17
20
  automation: AutomationSettingsInp;
18
- debtToAddBaseUnit: bigint;
21
+ dcaInBaseUnit: bigint;
22
+ tokenType: TokenType;
19
23
  };
20
24
 
21
25
  export type DCASettingsInpArgs = {
22
26
  automation: AutomationSettingsInpArgs;
23
- debtToAddBaseUnit: number | bigint;
27
+ dcaInBaseUnit: number | bigint;
28
+ tokenType: TokenTypeArgs;
24
29
  };
25
30
 
26
31
  export function getDCASettingsInpSerializer(): Serializer<
@@ -30,7 +35,8 @@ export function getDCASettingsInpSerializer(): Serializer<
30
35
  return struct<DCASettingsInp>(
31
36
  [
32
37
  ['automation', getAutomationSettingsInpSerializer()],
33
- ['debtToAddBaseUnit', u64()],
38
+ ['dcaInBaseUnit', u64()],
39
+ ['tokenType', getTokenTypeSerializer()],
34
40
  ],
35
41
  { description: 'DCASettingsInp' }
36
42
  ) as Serializer<DCASettingsInpArgs, DCASettingsInp>;
@@ -10,7 +10,6 @@ export * from './automationSettings';
10
10
  export * from './automationSettingsInp';
11
11
  export * from './dCASettings';
12
12
  export * from './dCASettingsInp';
13
- export * from './feeType';
14
13
  export * from './lendingPlatform';
15
14
  export * from './podBool';
16
15
  export * from './positionData';
@@ -23,4 +22,5 @@ export * from './solautoSettingsParameters';
23
22
  export * from './solautoSettingsParametersInp';
24
23
  export * from './tokenAmount';
25
24
  export * from './tokenBalanceAmount';
25
+ export * from './tokenType';
26
26
  export * from './updatePositionData';