@haven-fi/solauto-sdk 1.0.24 → 1.0.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. package/dist/clients/solautoClient.d.ts +4 -4
  2. package/dist/clients/solautoClient.d.ts.map +1 -1
  3. package/dist/clients/solautoClient.js +25 -23
  4. package/dist/clients/solautoMarginfiClient.d.ts +1 -0
  5. package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
  6. package/dist/clients/solautoMarginfiClient.js +83 -23
  7. package/dist/generated/instructions/closePosition.d.ts +4 -4
  8. package/dist/generated/instructions/closePosition.d.ts.map +1 -1
  9. package/dist/generated/instructions/closePosition.js +8 -8
  10. package/dist/generated/instructions/marginfiProtocolInteraction.d.ts +2 -2
  11. package/dist/generated/instructions/marginfiProtocolInteraction.d.ts.map +1 -1
  12. package/dist/generated/instructions/marginfiProtocolInteraction.js +4 -4
  13. package/dist/generated/instructions/marginfiRebalance.d.ts +2 -0
  14. package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -1
  15. package/dist/generated/instructions/marginfiRebalance.js +17 -7
  16. package/dist/transactions/transactionUtils.js +8 -8
  17. package/dist/transactions/transactionsManager.d.ts.map +1 -1
  18. package/dist/transactions/transactionsManager.js +6 -2
  19. package/dist/types/solauto.d.ts +13 -0
  20. package/dist/types/solauto.d.ts.map +1 -0
  21. package/dist/types/solauto.js +2 -0
  22. package/dist/utils/marginfiUtils.d.ts +5 -1
  23. package/dist/utils/marginfiUtils.d.ts.map +1 -1
  24. package/dist/utils/marginfiUtils.js +8 -2
  25. package/dist/utils/solauto/generalUtils.d.ts +1 -5
  26. package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
  27. package/dist/utils/solauto/generalUtils.js +6 -2
  28. package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
  29. package/dist/utils/solauto/rebalanceUtils.js +2 -2
  30. package/package.json +1 -1
  31. package/src/clients/solautoClient.ts +33 -31
  32. package/src/clients/solautoMarginfiClient.ts +88 -31
  33. package/src/generated/instructions/closePosition.ts +12 -12
  34. package/src/generated/instructions/marginfiProtocolInteraction.ts +6 -6
  35. package/src/generated/instructions/marginfiRebalance.ts +19 -7
  36. package/src/transactions/transactionUtils.ts +8 -8
  37. package/src/transactions/transactionsManager.ts +8 -6
  38. package/src/types/solauto.ts +14 -0
  39. package/src/utils/marginfiUtils.ts +11 -3
  40. package/src/utils/solauto/generalUtils.ts +21 -12
  41. package/src/utils/solauto/rebalanceUtils.ts +2 -3
  42. package/tests/transactions/solautoMarginfi.ts +28 -25
  43. package/tests/unit/lookupTables.ts +4 -3
@@ -193,11 +193,15 @@ class TransactionsManager {
193
193
  choresBefore.prepend(updateLookupTable.updateLutTx);
194
194
  }
195
195
  if (choresBefore.getInstructions().length > 0) {
196
- this.items.unshift(new TransactionItem(async () => ({ tx: choresBefore }), "create account(s)"));
196
+ const chore = new TransactionItem(async () => ({ tx: choresBefore }), "create account(s)");
197
+ await chore.initialize();
198
+ this.items.unshift(chore);
197
199
  this.client.log("Chores before: ", choresBefore.getInstructions().length);
198
200
  }
199
201
  if (choresAfter.getInstructions().length > 0) {
200
- this.items.push(new TransactionItem(async () => ({ tx: choresAfter })));
202
+ const chore = new TransactionItem(async () => ({ tx: choresAfter }));
203
+ await chore.initialize();
204
+ this.items.push(chore);
201
205
  this.client.log("Chores after: ", choresAfter.getInstructions().length);
202
206
  }
203
207
  const itemSets = await this.assembleTransactionSets(this.items);
@@ -0,0 +1,13 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { LendingPlatform } from "../generated";
3
+ export interface SolautoPositionDetails {
4
+ positionId: number;
5
+ selfManaged: boolean;
6
+ lendingPlatform: LendingPlatform;
7
+ }
8
+ export interface SelfManagedPositionDetails extends SolautoPositionDetails {
9
+ protocolAccount: PublicKey;
10
+ supplyMint: PublicKey;
11
+ debtMint: PublicKey;
12
+ }
13
+ //# sourceMappingURL=solauto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,EAAE,eAAe,CAAC;CACpC;AAED,MAAM,WAAW,0BAA2B,SAAQ,sBAAsB;IACtE,eAAe,EAAE,SAAS,CAAC;IAC3B,UAAU,EAAE,SAAS,CAAC;IACtB,QAAQ,EAAE,SAAS,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -9,7 +9,11 @@ export declare function findMarginfiBankAccounts({ mint, bank, }: {
9
9
  bank?: string;
10
10
  }): MarginfiTokenAccounts;
11
11
  export declare function getMaxLtvAndLiqThreshold(supplyBank: Bank, debtBank: Bank, supplyPrice?: number): Promise<[number, number]>;
12
- export declare function getAllMarginfiAccountsByAuthority(umi: Umi, authority: PublicKey, compatibleWithSolauto?: boolean): Promise<PublicKey[]>;
12
+ export declare function getAllMarginfiAccountsByAuthority(umi: Umi, authority: PublicKey, compatibleWithSolauto?: boolean): Promise<{
13
+ marginfiAccount: PublicKey;
14
+ supplyMint?: PublicKey;
15
+ debtMint?: PublicKey;
16
+ }[]>;
13
17
  export declare function getMarginfiAccountPositionState(umi: Umi, marginfiAccountPk: PublicKey, supplyMint?: PublicKey, debtMint?: PublicKey, livePositionUpdates?: LivePositionUpdates): Promise<PositionState | undefined>;
14
18
  export declare function getUpToDateShareValues(umi: Umi, bank: Bank): Promise<[number, number]>;
15
19
  //# sourceMappingURL=marginfiUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CA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umi, authority, compatibleWithS
70
70
  })));
71
71
  return positionStates
72
72
  .filter((x) => x.state !== undefined)
73
- .map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
73
+ .map((x) => ({
74
+ marginfiAccount: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey),
75
+ supplyMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.state.supply.mint),
76
+ debtMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.state.debt.mint),
77
+ }));
74
78
  }
75
79
  else {
76
- return marginfiAccounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
80
+ return marginfiAccounts.map((x) => ({
81
+ marginfiAccount: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey),
82
+ }));
77
83
  }
78
84
  }
79
85
  exports.getAllMarginfiAccountsByAuthority = getAllMarginfiAccountsByAuthority;
@@ -1,6 +1,7 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { Umi } from "@metaplex-foundation/umi";
3
3
  import { AutomationSettings, DCASettings, DCASettingsInpArgs, FeeType, LendingPlatform, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../../generated";
4
+ import { SolautoPositionDetails } from "../../types/solauto";
4
5
  export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
5
6
  export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings): boolean;
6
7
  export declare function getUpdatedValueFromAutomation(currValue: number, targetValue: number, automation: AutomationSettings, currentUnixTimestamp: number): number;
@@ -19,11 +20,6 @@ export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicK
19
20
  }[]>;
20
21
  export declare function getAllReferralStates(umi: Umi): Promise<PublicKey[]>;
21
22
  export declare function getReferralsByUser(umi: Umi, user: PublicKey): Promise<PublicKey[]>;
22
- export interface SolautoPositionDetails {
23
- positionId: number;
24
- lendingPlatform: LendingPlatform;
25
- protocolAccount?: PublicKey;
26
- }
27
23
  export declare function getAllPositionsByAuthority(umi: Umi, user: PublicKey): Promise<SolautoPositionDetails[]>;
28
24
  type PositionAdjustment = {
29
25
  type: "supply";
@@ -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,EAAoB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,eAAe,EACf,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;AA6BzB,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,GAC7B,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,CAC/C,QAAQ,EAAE,yBAAyB,EACnC,kBAAkB,EAAE,MAAM,GACzB,yBAAyB,CAgB3B;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,OAAO,GACf;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAYA;AAED,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,yBAAyB,EAC3C,WAAW,EAAE,WAAW,GACvB,OAAO,CA+BT;AAED,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,yBAAyB,GAC1C,OAAO,CAST;AAED,wBAAsB,0BAA0B,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16 @@ async function getAllPositionsByAuthority(umi, user) {
186
186
  allPositions.push(...solautoManagedPositions.map((x) => ({
187
187
  positionId: x.positionId,
188
188
  lendingPlatform: x.lendingPlatform,
189
+ selfManaged: false,
189
190
  })));
190
191
  const marginfiPositions = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(umi, user, true);
191
- allPositions.push(...marginfiPositions.map((pubkey) => ({
192
+ allPositions.push(...marginfiPositions.map((x) => ({
192
193
  positionId: 0,
194
+ selfManaged: true,
193
195
  lendingPlatform: generated_1.LendingPlatform.Marginfi,
194
- protocolAccount: pubkey,
196
+ protocolAccount: x.marginfiAccount,
197
+ supplyMint: x.supplyMint,
198
+ debtMint: x.debtMint,
195
199
  })));
196
200
  // TODO support other platforms
197
201
  return allPositions;
@@ -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;AAS5D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA4IjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CA+EjB;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,CAkE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAmChB"}
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;AAS5D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA4IjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CA8EjB;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,CAkE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAmChB"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getJupSwapRebalanceDetails = exports.getFlashLoanDetails = exports.getRebalanceValues = void 0;
4
+ const generated_1 = require("../../generated");
4
5
  const generalUtils_1 = require("./generalUtils");
5
6
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
6
7
  const generalUtils_2 = require("../generalUtils");
@@ -98,12 +99,11 @@ function getRebalanceValues(client, targetLiqUtilizationRateBps, limitGapBps) {
98
99
  client.solautoPositionState.liqUtilizationRateBps < targetRateBps;
99
100
  let adjustmentFeeBps = 0;
100
101
  if (increasingLeverage) {
101
- adjustmentFeeBps = (0, generalUtils_1.getSolautoFeesBps)(client.referredByState !== undefined, client.solautoPositionData.feeType).total;
102
+ adjustmentFeeBps = (0, generalUtils_1.getSolautoFeesBps)(client.referredByState !== undefined, client.solautoPositionData?.feeType ?? generated_1.FeeType.Small).total;
102
103
  }
103
104
  const supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) + amountUsdToDcaIn;
104
105
  const debtUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
105
106
  let debtAdjustmentUsd = (0, numberUtils_1.getDebtAdjustmentUsd)(client.solautoPositionState.liqThresholdBps, supplyUsd, debtUsd, targetRateBps, adjustmentFeeBps);
106
- debtAdjustmentUsd *= 500;
107
107
  const input = increasingLeverage
108
108
  ? client.solautoPositionState.debt
109
109
  : client.solautoPositionState.supply;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
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",
@@ -88,12 +88,12 @@ export abstract class SolautoClient {
88
88
  public solautoPositionState!: PositionState | undefined;
89
89
 
90
90
  public supplyMint!: PublicKey;
91
- public positionSupplyLiquidityTa!: PublicKey;
92
- public signerSupplyLiquidityTa!: PublicKey;
91
+ public positionSupplyTa!: PublicKey;
92
+ public signerSupplyTa!: PublicKey;
93
93
 
94
94
  public debtMint!: PublicKey;
95
- public positionDebtLiquidityTa!: PublicKey;
96
- public signerDebtLiquidityTa!: PublicKey;
95
+ public positionDebtTa!: PublicKey;
96
+ public signerDebtTa!: PublicKey;
97
97
 
98
98
  public authorityReferralState!: PublicKey;
99
99
  public authorityReferralStateData!: ReferralState | null;
@@ -157,11 +157,11 @@ export abstract class SolautoClient {
157
157
  this.supplyMint =
158
158
  args.supplyMint ??
159
159
  toWeb3JsPublicKey(this.solautoPositionData!.position.supplyMint);
160
- this.positionSupplyLiquidityTa = getTokenAccount(
160
+ this.positionSupplyTa = getTokenAccount(
161
161
  this.solautoPosition,
162
162
  this.supplyMint
163
163
  );
164
- this.signerSupplyLiquidityTa = getTokenAccount(
164
+ this.signerSupplyTa = getTokenAccount(
165
165
  toWeb3JsPublicKey(this.signer.publicKey),
166
166
  this.supplyMint
167
167
  );
@@ -169,11 +169,11 @@ export abstract class SolautoClient {
169
169
  this.debtMint =
170
170
  args.debtMint ??
171
171
  toWeb3JsPublicKey(this.solautoPositionData!.position.debtMint);
172
- this.positionDebtLiquidityTa = getTokenAccount(
172
+ this.positionDebtTa = getTokenAccount(
173
173
  this.solautoPosition,
174
174
  this.debtMint
175
175
  );
176
- this.signerDebtLiquidityTa = getTokenAccount(
176
+ this.signerDebtTa = getTokenAccount(
177
177
  toWeb3JsPublicKey(this.signer.publicKey),
178
178
  this.debtMint
179
179
  );
@@ -280,14 +280,14 @@ export abstract class SolautoClient {
280
280
  return [
281
281
  this.authority,
282
282
  ...(this.signer.publicKey.toString() === this.authority.toString()
283
- ? [this.signerSupplyLiquidityTa]
283
+ ? [this.signerSupplyTa]
284
284
  : []),
285
285
  ...(this.signer.publicKey.toString() === this.authority.toString()
286
- ? [this.signerDebtLiquidityTa]
286
+ ? [this.signerDebtTa]
287
287
  : []),
288
288
  this.solautoPosition,
289
- this.positionSupplyLiquidityTa,
290
- this.positionDebtLiquidityTa,
289
+ this.positionSupplyTa,
290
+ this.positionDebtTa,
291
291
  this.authorityReferralState,
292
292
  ...(this.referredBySupplyTa ? [this.referredBySupplyTa] : []),
293
293
  ];
@@ -317,7 +317,6 @@ export abstract class SolautoClient {
317
317
  return undefined;
318
318
  }
319
319
 
320
- this.log("Updating authority lookup table...");
321
320
  let tx = transactionBuilder();
322
321
 
323
322
  if (this.authorityLutAddress === undefined) {
@@ -353,10 +352,13 @@ export abstract class SolautoClient {
353
352
  );
354
353
  }
355
354
 
356
- const addingReferredBy =
357
- accountsToAdd.length === 1 &&
358
- accountsToAdd[0].toString().toLowerCase() ===
359
- this.referredBySupplyTa?.toString().toLowerCase();
355
+ const addingReferredBy = accountsToAdd.length === 1
356
+ // && accountsToAdd[0].toString().toLowerCase() ===
357
+ // this.referredBySupplyTa?.toString().toLowerCase();
358
+
359
+ if (tx.getInstructions().length > 0) {
360
+ this.log("Updating authority lookup table...");
361
+ }
360
362
 
361
363
  return { updateLutTx: tx, needsToBeIsolated: !addingReferredBy };
362
364
  }
@@ -443,8 +445,8 @@ export abstract class SolautoClient {
443
445
  let signerDebtTa: UmiPublicKey | undefined = undefined;
444
446
  if (isOption(args.dca) && isSome(args.dca)) {
445
447
  debtMint = publicKey(this.debtMint);
446
- positionDebtTa = publicKey(this.positionDebtLiquidityTa);
447
- signerDebtTa = publicKey(this.signerDebtLiquidityTa);
448
+ positionDebtTa = publicKey(this.positionDebtTa);
449
+ signerDebtTa = publicKey(this.signerDebtTa);
448
450
 
449
451
  let addingToPos = false;
450
452
  if (
@@ -500,10 +502,10 @@ export abstract class SolautoClient {
500
502
  return closePosition(this.umi, {
501
503
  signer: this.signer,
502
504
  solautoPosition: publicKey(this.solautoPosition),
503
- signerSupplyLiquidityTa: publicKey(this.signerSupplyLiquidityTa),
504
- positionSupplyLiquidityTa: publicKey(this.positionSupplyLiquidityTa),
505
- positionDebtLiquidityTa: publicKey(this.positionDebtLiquidityTa),
506
- signerDebtLiquidityTa: publicKey(this.signerDebtLiquidityTa),
505
+ signerSupplyTa: publicKey(this.signerSupplyTa),
506
+ positionSupplyTa: publicKey(this.positionSupplyTa),
507
+ positionDebtTa: publicKey(this.positionDebtTa),
508
+ signerDebtTa: publicKey(this.signerDebtTa),
507
509
  });
508
510
  }
509
511
 
@@ -516,8 +518,8 @@ export abstract class SolautoClient {
516
518
  const positionData = this.solautoPositionData!.position;
517
519
  if (positionData.dca.debtToAddBaseUnit) {
518
520
  debtMint = publicKey(this.debtMint);
519
- positionDebtTa = publicKey(this.positionDebtLiquidityTa);
520
- signerDebtTa = publicKey(this.signerDebtLiquidityTa);
521
+ positionDebtTa = publicKey(this.positionDebtTa);
522
+ signerDebtTa = publicKey(this.signerDebtTa);
521
523
 
522
524
  this.livePositionUpdates.new({
523
525
  type: "debtDcaIn",
@@ -545,8 +547,8 @@ export abstract class SolautoClient {
545
547
  tx = tx.add(
546
548
  splTokenTransferUmiIx(
547
549
  this.signer,
548
- this.signerSupplyLiquidityTa,
549
- this.positionSupplyLiquidityTa,
550
+ this.signerSupplyTa,
551
+ this.positionSupplyTa,
550
552
  toWeb3JsPublicKey(this.signer.publicKey),
551
553
  BigInt(args.fields[0])
552
554
  )
@@ -556,8 +558,8 @@ export abstract class SolautoClient {
556
558
  tx = tx.add(
557
559
  splTokenTransferUmiIx(
558
560
  this.signer,
559
- this.signerDebtLiquidityTa,
560
- this.positionDebtLiquidityTa,
561
+ this.signerDebtTa,
562
+ this.positionDebtTa,
561
563
  toWeb3JsPublicKey(this.signer.publicKey),
562
564
  BigInt(args.fields[0].fields[0])
563
565
  )
@@ -566,8 +568,8 @@ export abstract class SolautoClient {
566
568
  tx = tx.add(
567
569
  splTokenTransferUmiIx(
568
570
  this.signer,
569
- this.signerDebtLiquidityTa,
570
- this.positionDebtLiquidityTa,
571
+ this.signerDebtTa,
572
+ this.positionDebtTa,
571
573
  toWeb3JsPublicKey(this.signer.publicKey),
572
574
  BigInt(
573
575
  Math.round(
@@ -11,9 +11,10 @@ import {
11
11
  transactionBuilder,
12
12
  createSignerFromKeypair,
13
13
  AccountMeta,
14
- createUmi,
15
14
  } from "@metaplex-foundation/umi";
15
+ import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
16
16
  import {
17
+ clusterApiUrl,
17
18
  Keypair,
18
19
  PublicKey,
19
20
  SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -42,9 +43,11 @@ import {
42
43
  MARGINFI_PROGRAM_ID,
43
44
  MarginfiAccount,
44
45
  lendingAccountBorrow,
46
+ lendingAccountDeposit,
45
47
  lendingAccountEndFlashloan,
46
48
  lendingAccountRepay,
47
49
  lendingAccountStartFlashloan,
50
+ lendingAccountWithdraw,
48
51
  marginfiAccountInitialize,
49
52
  safeFetchAllMarginfiAccount,
50
53
  safeFetchMarginfiAccount,
@@ -73,16 +76,14 @@ export function newSolautoMarginfiPositionArgs(
73
76
  debtMint: PublicKey,
74
77
  referredByAuthority?: PublicKey
75
78
  ): SolautoMarginfiClientArgs {
79
+ const umi = createUmi(clusterApiUrl("mainnet-beta"));
76
80
  return {
77
81
  positionId,
78
82
  signer,
79
83
  wallet,
80
84
  marginfiAccount:
81
85
  positionId === 0
82
- ? createSignerFromKeypair(
83
- createUmi(),
84
- fromWeb3JsKeypair(Keypair.generate())
85
- )
86
+ ? createSignerFromKeypair(umi, umi.eddsa.generateKeypair())
86
87
  : undefined,
87
88
  marginfiAccountSeedIdx: positionId > 0 ? generateRandomU64() : undefined,
88
89
  supplyMint: supplyMint,
@@ -151,7 +152,7 @@ export class SolautoMarginfiClient extends SolautoClient {
151
152
  const emptyMarginfiAccounts = (
152
153
  await safeFetchAllMarginfiAccount(
153
154
  this.umi,
154
- existingMarginfiAccounts.map((x) => publicKey(x))
155
+ existingMarginfiAccounts.map((x) => publicKey(x.marginfiAccount))
155
156
  )
156
157
  ).filter(
157
158
  (x) =>
@@ -166,10 +167,7 @@ export class SolautoMarginfiClient extends SolautoClient {
166
167
  this.intermediaryMarginfiAccountSigner =
167
168
  emptyMarginfiAccounts.length > 0
168
169
  ? undefined
169
- : createSignerFromKeypair(
170
- this.umi,
171
- fromWeb3JsKeypair(Keypair.generate())
172
- );
170
+ : createSignerFromKeypair(this.umi, this.umi.eddsa.generateKeypair());
173
171
  this.intermediaryMarginfiAccountPk =
174
172
  emptyMarginfiAccounts.length > 0
175
173
  ? toWeb3JsPublicKey(emptyMarginfiAccounts[0].publicKey)
@@ -203,9 +201,9 @@ export class SolautoMarginfiClient extends SolautoClient {
203
201
  settingParams?: SolautoSettingsParametersInpArgs,
204
202
  dca?: DCASettingsInpArgs
205
203
  ): TransactionBuilder {
206
- let signerDebtLiquidityTa: UmiPublicKey | undefined = undefined;
204
+ let signerDebtTa: UmiPublicKey | undefined = undefined;
207
205
  if (dca) {
208
- signerDebtLiquidityTa = publicKey(this.signerDebtLiquidityTa);
206
+ signerDebtTa = publicKey(this.signerDebtTa);
209
207
  }
210
208
 
211
209
  return marginfiOpenPosition(this.umi, {
@@ -228,11 +226,11 @@ export class SolautoMarginfiClient extends SolautoClient {
228
226
  : (this.marginfiAccount as Signer),
229
227
  supplyMint: publicKey(this.supplyMint),
230
228
  supplyBank: publicKey(this.marginfiSupplyBankAccounts.bank),
231
- positionSupplyTa: publicKey(this.positionSupplyLiquidityTa),
229
+ positionSupplyTa: publicKey(this.positionSupplyTa),
232
230
  debtMint: publicKey(this.debtMint),
233
231
  debtBank: publicKey(this.marginfiDebtBankAccounts.bank),
234
- positionDebtTa: publicKey(this.positionDebtLiquidityTa),
235
- signerDebtTa: signerDebtLiquidityTa,
232
+ positionDebtTa: publicKey(this.positionDebtTa),
233
+ signerDebtTa: signerDebtTa,
236
234
  positionData: {
237
235
  positionId: this.positionId!,
238
236
  settingParams: settingParams ?? null,
@@ -257,22 +255,79 @@ export class SolautoMarginfiClient extends SolautoClient {
257
255
  }
258
256
 
259
257
  protocolInteraction(args: SolautoActionArgs): TransactionBuilder {
260
- return super
261
- .protocolInteraction(args)
262
- .add(this.marginfiProtocolInteractionIx(args));
258
+ let tx = super.protocolInteraction(args);
259
+
260
+ if (this.selfManaged) {
261
+ return tx.add(this.marginfiProtocolInteractionIx(args));
262
+ } else {
263
+ return tx.add(this.marginfiSolautoProtocolInteractionIx(args));
264
+ }
265
+ }
266
+
267
+ private marginfiProtocolInteractionIx(args: SolautoActionArgs) {
268
+ switch (args.__kind) {
269
+ case "Deposit": {
270
+ return lendingAccountDeposit(this.umi, {
271
+ amount: args.fields[0],
272
+ signer: this.signer,
273
+ signerTokenAccount: publicKey(this.signerSupplyTa),
274
+ marginfiAccount: publicKey(this.marginfiAccountPk),
275
+ marginfiGroup: publicKey(this.marginfiGroup),
276
+ bank: publicKey(this.marginfiSupplyBankAccounts.bank),
277
+ bankLiquidityVault: publicKey(this.marginfiSupplyBankAccounts.liquidityVault),
278
+ });
279
+ }
280
+ case "Borrow": {
281
+ return lendingAccountBorrow(this.umi, {
282
+ amount: args.fields[0],
283
+ signer: this.signer,
284
+ destinationTokenAccount: publicKey(this.signerDebtTa),
285
+ marginfiAccount: publicKey(this.marginfiAccountPk),
286
+ marginfiGroup: publicKey(this.marginfiGroup),
287
+ bank: publicKey(this.marginfiDebtBankAccounts.bank),
288
+ bankLiquidityVault: publicKey(this.marginfiDebtBankAccounts.liquidityVault),
289
+ bankLiquidityVaultAuthority: publicKey(this.marginfiDebtBankAccounts.vaultAuthority),
290
+ });
291
+ }
292
+ case "Repay": {
293
+ return lendingAccountRepay(this.umi, {
294
+ amount: args.fields[0].__kind === "Some" ? args.fields[0].fields[0] : 0,
295
+ repayAll: args.fields[0].__kind === "All" ? true : false,
296
+ signer: this.signer,
297
+ signerTokenAccount: publicKey(this.signerDebtTa),
298
+ marginfiAccount: publicKey(this.marginfiAccountPk),
299
+ marginfiGroup: publicKey(this.marginfiGroup),
300
+ bank: publicKey(this.marginfiDebtBankAccounts.bank),
301
+ bankLiquidityVault: publicKey(this.marginfiDebtBankAccounts.liquidityVault),
302
+ });
303
+ }
304
+ case "Withdraw": {
305
+ return lendingAccountWithdraw(this.umi, {
306
+ amount: args.fields[0].__kind === "Some" ? args.fields[0].fields[0] : 0,
307
+ withdrawAll: args.fields[0].__kind === "All" ? true : false,
308
+ signer: this.signer,
309
+ destinationTokenAccount: publicKey(this.signerSupplyTa),
310
+ marginfiAccount: publicKey(this.marginfiAccountPk),
311
+ marginfiGroup: publicKey(this.marginfiGroup),
312
+ bank: publicKey(this.marginfiSupplyBankAccounts.bank),
313
+ bankLiquidityVault: publicKey(this.marginfiSupplyBankAccounts.liquidityVault),
314
+ bankLiquidityVaultAuthority: publicKey(this.marginfiSupplyBankAccounts.vaultAuthority),
315
+ });
316
+ }
317
+ }
263
318
  }
264
319
 
265
- private marginfiProtocolInteractionIx(
320
+ private marginfiSolautoProtocolInteractionIx(
266
321
  args: SolautoActionArgs
267
322
  ): TransactionBuilder {
268
- let sourceSupplyTa: UmiPublicKey | undefined = undefined;
323
+ let positionSupplyTa: UmiPublicKey | undefined = undefined;
269
324
  let vaultSupplyTa: UmiPublicKey | undefined = undefined;
270
325
  let supplyVaultAuthority: UmiPublicKey | undefined = undefined;
271
326
  if (args.__kind === "Deposit" || args.__kind === "Withdraw") {
272
- sourceSupplyTa = publicKey(
327
+ positionSupplyTa = publicKey(
273
328
  args.__kind === "Withdraw" || this.selfManaged
274
- ? this.signerSupplyLiquidityTa
275
- : this.positionSupplyLiquidityTa
329
+ ? this.signerSupplyTa
330
+ : this.positionSupplyTa
276
331
  );
277
332
  vaultSupplyTa = publicKey(this.marginfiSupplyBankAccounts.liquidityVault);
278
333
  supplyVaultAuthority = publicKey(
@@ -280,14 +335,14 @@ export class SolautoMarginfiClient extends SolautoClient {
280
335
  );
281
336
  }
282
337
 
283
- let sourceDebtTa: UmiPublicKey | undefined = undefined;
338
+ let positionDebtTa: UmiPublicKey | undefined = undefined;
284
339
  let vaultDebtTa: UmiPublicKey | undefined = undefined;
285
340
  let debtVaultAuthority: UmiPublicKey | undefined = undefined;
286
341
  if (args.__kind === "Borrow" || args.__kind === "Repay") {
287
- sourceDebtTa = publicKey(
342
+ positionDebtTa = publicKey(
288
343
  args.__kind === "Borrow" || this.selfManaged
289
- ? this.signerDebtLiquidityTa
290
- : this.positionDebtLiquidityTa
344
+ ? this.signerDebtTa
345
+ : this.positionDebtTa
291
346
  );
292
347
  vaultDebtTa = publicKey(this.marginfiDebtBankAccounts.liquidityVault);
293
348
  debtVaultAuthority = publicKey(
@@ -312,12 +367,12 @@ export class SolautoMarginfiClient extends SolautoClient {
312
367
  marginfiAccount: publicKey(this.marginfiAccountPk),
313
368
  supplyBank: publicKey(this.marginfiSupplyBankAccounts.bank),
314
369
  supplyPriceOracle,
315
- sourceSupplyTa,
370
+ positionSupplyTa,
316
371
  vaultSupplyTa,
317
372
  supplyVaultAuthority,
318
373
  debtBank: publicKey(this.marginfiDebtBankAccounts.bank),
319
374
  debtPriceOracle,
320
- sourceDebtTa,
375
+ positionDebtTa,
321
376
  vaultDebtTa,
322
377
  debtVaultAuthority,
323
378
  solautoAction: args,
@@ -356,14 +411,16 @@ export class SolautoMarginfiClient extends SolautoClient {
356
411
  ),
357
412
  supplyBank: publicKey(this.marginfiSupplyBankAccounts.bank),
358
413
  supplyPriceOracle: publicKey(this.marginfiSupplyBankAccounts.priceOracle),
359
- positionSupplyTa: publicKey(this.positionSupplyLiquidityTa),
414
+ positionSupplyTa: publicKey(this.positionSupplyTa),
415
+ signerSupplyTa: this.selfManaged ? publicKey(this.signerSupplyTa) : undefined,
360
416
  vaultSupplyTa: publicKey(this.marginfiSupplyBankAccounts.liquidityVault),
361
417
  supplyVaultAuthority: publicKey(
362
418
  this.marginfiSupplyBankAccounts.vaultAuthority
363
419
  ),
364
420
  debtBank: publicKey(this.marginfiDebtBankAccounts.bank),
365
421
  debtPriceOracle: publicKey(this.marginfiDebtBankAccounts.priceOracle),
366
- positionDebtTa: publicKey(this.positionDebtLiquidityTa),
422
+ positionDebtTa: publicKey(this.positionDebtTa),
423
+ signerDebtTa: this.selfManaged ? publicKey(this.signerDebtTa) : undefined,
367
424
  vaultDebtTa: publicKey(this.marginfiDebtBankAccounts.liquidityVault),
368
425
  debtVaultAuthority: publicKey(
369
426
  this.marginfiDebtBankAccounts.vaultAuthority
@@ -33,11 +33,11 @@ export type ClosePositionInstructionAccounts = {
33
33
  tokenProgram?: PublicKey | Pda;
34
34
  ataProgram?: PublicKey | Pda;
35
35
  solautoPosition: PublicKey | Pda;
36
- signerSupplyLiquidityTa: PublicKey | Pda;
37
- positionSupplyLiquidityTa: PublicKey | Pda;
36
+ signerSupplyTa: PublicKey | Pda;
37
+ positionSupplyTa: PublicKey | Pda;
38
38
  positionSupplyCollateralTa?: PublicKey | Pda;
39
- positionDebtLiquidityTa: PublicKey | Pda;
40
- signerDebtLiquidityTa: PublicKey | Pda;
39
+ positionDebtTa: PublicKey | Pda;
40
+ signerDebtTa: PublicKey | Pda;
41
41
  };
42
42
 
43
43
  // Data.
@@ -102,30 +102,30 @@ export function closePosition(
102
102
  isWritable: true as boolean,
103
103
  value: input.solautoPosition ?? null,
104
104
  },
105
- signerSupplyLiquidityTa: {
105
+ signerSupplyTa: {
106
106
  index: 5,
107
107
  isWritable: true as boolean,
108
- value: input.signerSupplyLiquidityTa ?? null,
108
+ value: input.signerSupplyTa ?? null,
109
109
  },
110
- positionSupplyLiquidityTa: {
110
+ positionSupplyTa: {
111
111
  index: 6,
112
112
  isWritable: true as boolean,
113
- value: input.positionSupplyLiquidityTa ?? null,
113
+ value: input.positionSupplyTa ?? null,
114
114
  },
115
115
  positionSupplyCollateralTa: {
116
116
  index: 7,
117
117
  isWritable: true as boolean,
118
118
  value: input.positionSupplyCollateralTa ?? null,
119
119
  },
120
- positionDebtLiquidityTa: {
120
+ positionDebtTa: {
121
121
  index: 8,
122
122
  isWritable: true as boolean,
123
- value: input.positionDebtLiquidityTa ?? null,
123
+ value: input.positionDebtTa ?? null,
124
124
  },
125
- signerDebtLiquidityTa: {
125
+ signerDebtTa: {
126
126
  index: 9,
127
127
  isWritable: true as boolean,
128
- value: input.signerDebtLiquidityTa ?? null,
128
+ value: input.signerDebtTa ?? null,
129
129
  },
130
130
  } satisfies ResolvedAccountsWithIndices;
131
131
 
@@ -45,12 +45,12 @@ export type MarginfiProtocolInteractionInstructionAccounts = {
45
45
  marginfiAccount: PublicKey | Pda;
46
46
  supplyBank: PublicKey | Pda;
47
47
  supplyPriceOracle?: PublicKey | Pda;
48
- sourceSupplyTa?: PublicKey | Pda;
48
+ positionSupplyTa?: PublicKey | Pda;
49
49
  vaultSupplyTa?: PublicKey | Pda;
50
50
  supplyVaultAuthority?: PublicKey | Pda;
51
51
  debtBank: PublicKey | Pda;
52
52
  debtPriceOracle?: PublicKey | Pda;
53
- sourceDebtTa?: PublicKey | Pda;
53
+ positionDebtTa?: PublicKey | Pda;
54
54
  vaultDebtTa?: PublicKey | Pda;
55
55
  debtVaultAuthority?: PublicKey | Pda;
56
56
  };
@@ -157,10 +157,10 @@ export function marginfiProtocolInteraction(
157
157
  isWritable: false as boolean,
158
158
  value: input.supplyPriceOracle ?? null,
159
159
  },
160
- sourceSupplyTa: {
160
+ positionSupplyTa: {
161
161
  index: 11,
162
162
  isWritable: true as boolean,
163
- value: input.sourceSupplyTa ?? null,
163
+ value: input.positionSupplyTa ?? null,
164
164
  },
165
165
  vaultSupplyTa: {
166
166
  index: 12,
@@ -182,10 +182,10 @@ export function marginfiProtocolInteraction(
182
182
  isWritable: false as boolean,
183
183
  value: input.debtPriceOracle ?? null,
184
184
  },
185
- sourceDebtTa: {
185
+ positionDebtTa: {
186
186
  index: 16,
187
187
  isWritable: true as boolean,
188
- value: input.sourceDebtTa ?? null,
188
+ value: input.positionDebtTa ?? null,
189
189
  },
190
190
  vaultDebtTa: {
191
191
  index: 17,