@haven-fi/solauto-sdk 1.0.13 → 1.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) 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 +22 -21
  4. package/dist/clients/solautoMarginfiClient.js +9 -9
  5. package/dist/constants/tokenConstants.d.ts +4 -0
  6. package/dist/constants/tokenConstants.d.ts.map +1 -1
  7. package/dist/constants/tokenConstants.js +5 -1
  8. package/dist/transactions/transactionUtils.d.ts.map +1 -1
  9. package/dist/transactions/transactionUtils.js +10 -10
  10. package/dist/utils/deleteme.js +1 -1
  11. package/dist/utils/generalUtils.js +1 -1
  12. package/dist/utils/jupiterUtils.d.ts.map +1 -1
  13. package/dist/utils/jupiterUtils.js +2 -3
  14. package/dist/utils/marginfiUtils.d.ts.map +1 -1
  15. package/dist/utils/marginfiUtils.js +3 -3
  16. package/dist/utils/numberUtils.d.ts +3 -0
  17. package/dist/utils/numberUtils.d.ts.map +1 -1
  18. package/dist/utils/numberUtils.js +14 -1
  19. package/dist/utils/solanaUtils.js +1 -1
  20. package/dist/utils/solauto/generalUtils.d.ts +0 -3
  21. package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
  22. package/dist/utils/solauto/generalUtils.js +2 -15
  23. package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
  24. package/dist/utils/solauto/rebalanceUtils.js +11 -10
  25. package/package.json +1 -1
  26. package/src/clients/solautoClient.ts +27 -28
  27. package/src/clients/solautoMarginfiClient.ts +10 -10
  28. package/src/constants/tokenConstants.ts +6 -1
  29. package/src/transactions/transactionUtils.ts +10 -11
  30. package/src/utils/deleteme.ts +2 -2
  31. package/src/utils/generalUtils.ts +1 -1
  32. package/src/utils/jupiterUtils.ts +10 -8
  33. package/src/utils/marginfiUtils.ts +4 -5
  34. package/src/utils/numberUtils.ts +23 -0
  35. package/src/utils/solanaUtils.ts +1 -1
  36. package/src/utils/solauto/generalUtils.ts +1 -25
  37. package/src/utils/solauto/rebalanceUtils.ts +13 -12
  38. package/tests/unit/rebalanceCalculations.ts +6 -4
@@ -11,8 +11,8 @@ export interface SolautoClientArgs {
11
11
  positionId: number;
12
12
  signer?: Signer;
13
13
  wallet?: WalletAdapter;
14
- supplyLiquidityMint?: PublicKey;
15
- debtLiquidityMint?: PublicKey;
14
+ supplyMint?: PublicKey;
15
+ debtMint?: PublicKey;
16
16
  referralFeesDestMint?: PublicKey;
17
17
  referredByAuthority?: PublicKey;
18
18
  }
@@ -29,10 +29,10 @@ export declare abstract class SolautoClient {
29
29
  solautoPosition: PublicKey;
30
30
  solautoPositionData: SolautoPosition | null;
31
31
  solautoPositionState: PositionState | undefined;
32
- supplyLiquidityMint: PublicKey;
32
+ supplyMint: PublicKey;
33
33
  positionSupplyLiquidityTa: PublicKey;
34
34
  signerSupplyLiquidityTa: PublicKey;
35
- debtLiquidityMint: PublicKey;
35
+ debtMint: PublicKey;
36
36
  positionDebtLiquidityTa: PublicKey;
37
37
  signerDebtLiquidityTa: PublicKey;
38
38
  authorityReferralState: PublicKey;
@@ -1 +1 @@
1
- {"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAEL,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAQJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EASvB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKvD,OAAO,EAAE,g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AAwB;IAoB9B,mBAAmB,IAAI,MAAM,EAAE;IAK/B,gBAAgB,IAAI,SAAS,EAAE;IAiBzB,iCAAiC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAUzD,iBAAiB,IAAI,OAAO,CAChC;QAAE,WAAW,EAAE,kBAAkB,CAAC;QAAC,iBAAiB,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAC5E;IAwDD,uBAAuB,IAAI,yBAAyB,GAAG,SAAS;IAOhE,wBAAwB,IAAI,WAAW,GAAG,SAAS;IAOnD,sBAAsB,IAAI,kBAAkB;IAiB5C,mBAAmB,IAAI,kBAAkB;IAmBzC,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAuBrB,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,GAAG,kBAAkB;IA2DlE,eAAe,IAAI,kBAAkB;IAWrC,WAAW,IAAI,kBAAkB;IA4BjC,QAAQ,CAAC,OAAO,IAAI,kBAAkB;IAEtC,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAuFhE,QAAQ,CAAC,WAAW,CAClB,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IAErB,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAE3E,QAAQ,CAAC,SAAS,CAChB,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAYlE"}
@@ -43,16 +43,16 @@ class SolautoClient {
43
43
  this.solautoPosition = await (0, accountUtils_1.getSolautoPositionAccount)(this.authority, this.positionId);
44
44
  this.solautoPositionData = await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition));
45
45
  this.solautoPositionState = this.solautoPositionData?.state;
46
- this.supplyLiquidityMint =
47
- args.supplyLiquidityMint ??
46
+ this.supplyMint =
47
+ args.supplyMint ??
48
48
  (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.solautoPositionData.position.supplyMint);
49
- this.positionSupplyLiquidityTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.supplyLiquidityMint);
50
- this.signerSupplyLiquidityTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.supplyLiquidityMint);
51
- this.debtLiquidityMint =
52
- args.debtLiquidityMint ??
49
+ this.positionSupplyLiquidityTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.supplyMint);
50
+ this.signerSupplyLiquidityTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.supplyMint);
51
+ this.debtMint =
52
+ args.debtMint ??
53
53
  (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.solautoPositionData.position.debtMint);
54
- this.positionDebtLiquidityTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.debtLiquidityMint);
55
- this.signerDebtLiquidityTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.debtLiquidityMint);
54
+ this.positionDebtLiquidityTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.debtMint);
55
+ this.signerDebtLiquidityTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.debtMint);
56
56
  this.authorityReferralState = await (0, accountUtils_1.getReferralState)(this.authority);
57
57
  this.authorityReferralStateData = await (0, generated_1.safeFetchReferralState)(this.umi, (0, umi_1.publicKey)(this.authorityReferralState));
58
58
  this.authorityReferralFeesDestMint = args.referralFeesDestMint
@@ -61,24 +61,25 @@ class SolautoClient {
61
61
  ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.authorityReferralStateData?.destFeesMint)
62
62
  : spl_token_1.NATIVE_MINT;
63
63
  this.authorityReferralDestTa = (0, accountUtils_1.getTokenAccount)(this.authorityReferralState, this.authorityReferralFeesDestMint);
64
- const referredByAuthority = args.referredByAuthority &&
64
+ const hasReferredBy = this.authorityReferralStateData &&
65
+ this.authorityReferralStateData.referredByState !==
66
+ (0, umi_1.publicKey)(web3_js_1.PublicKey.default);
67
+ const referredByAuthority = !hasReferredBy &&
68
+ args.referredByAuthority &&
65
69
  !args.referredByAuthority.equals((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey))
66
70
  ? args.referredByAuthority
67
71
  : undefined;
68
- this.referredByState =
69
- this.authorityReferralStateData &&
70
- this.authorityReferralStateData.referredByState !==
71
- (0, umi_1.publicKey)(web3_js_1.PublicKey.default)
72
- ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.authorityReferralStateData.referredByState)
73
- : referredByAuthority
74
- ? await (0, accountUtils_1.getReferralState)(referredByAuthority)
75
- : undefined;
72
+ this.referredByState = hasReferredBy
73
+ ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.authorityReferralStateData.referredByState)
74
+ : referredByAuthority
75
+ ? await (0, accountUtils_1.getReferralState)(referredByAuthority)
76
+ : undefined;
76
77
  this.referredByAuthority = referredByAuthority;
77
78
  if (this.referredByState !== undefined) {
78
- this.referredBySupplyTa = (0, accountUtils_1.getTokenAccount)(this.referredByState, this.supplyLiquidityMint);
79
+ this.referredBySupplyTa = (0, accountUtils_1.getTokenAccount)(this.referredByState, this.supplyMint);
79
80
  }
80
81
  this.solautoFeesWallet = generalAccounts_1.SOLAUTO_FEES_WALLET;
81
- this.solautoFeesSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoFeesWallet, this.supplyLiquidityMint);
82
+ this.solautoFeesSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoFeesWallet, this.supplyMint);
82
83
  this.authorityLutAddress = this.authorityReferralStateData?.lookupTable
83
84
  ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.authorityReferralStateData?.lookupTable)
84
85
  : undefined;
@@ -241,7 +242,7 @@ class SolautoClient {
241
242
  let positionDebtTa = undefined;
242
243
  let signerDebtTa = undefined;
243
244
  if ((0, umi_1.isOption)(args.dca) && (0, umi_1.isSome)(args.dca)) {
244
- debtMint = (0, umi_1.publicKey)(this.debtLiquidityMint);
245
+ debtMint = (0, umi_1.publicKey)(this.debtMint);
245
246
  positionDebtTa = (0, umi_1.publicKey)(this.positionDebtLiquidityTa);
246
247
  signerDebtTa = (0, umi_1.publicKey)(this.signerDebtLiquidityTa);
247
248
  let addingToPos = false;
@@ -301,7 +302,7 @@ class SolautoClient {
301
302
  if (this.solautoPositionData !== null && !this.selfManaged) {
302
303
  const positionData = this.solautoPositionData.position;
303
304
  if (positionData.dca.debtToAddBaseUnit) {
304
- debtMint = (0, umi_1.publicKey)(this.debtLiquidityMint);
305
+ debtMint = (0, umi_1.publicKey)(this.debtMint);
305
306
  positionDebtTa = (0, umi_1.publicKey)(this.positionDebtLiquidityTa);
306
307
  signerDebtTa = (0, umi_1.publicKey)(this.signerDebtLiquidityTa);
307
308
  this.livePositionUpdates.new({
@@ -18,8 +18,8 @@ function newMarginfiSolautoManagedPositionArgs(positionId, signer, wallet, suppl
18
18
  signer,
19
19
  wallet,
20
20
  marginfiAccountSeedIdx: positionId > 0 ? (0, generalUtils_1.generateRandomU64)() : undefined,
21
- supplyLiquidityMint: supplyMint,
22
- debtLiquidityMint: debtMint,
21
+ supplyMint: supplyMint,
22
+ debtMint: debtMint,
23
23
  referredByAuthority,
24
24
  };
25
25
  }
@@ -45,10 +45,10 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
45
45
  ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(marginfiAccountData.group)
46
46
  : args.marginfiGroup ?? new web3_js_1.PublicKey(marginfiAccounts_1.DEFAULT_MARGINFI_GROUP);
47
47
  this.marginfiSupplyBankAccounts = (0, marginfiUtils_1.findMarginfiBankAccounts)({
48
- mint: this.supplyLiquidityMint.toString(),
48
+ mint: this.supplyMint.toString(),
49
49
  });
50
50
  this.marginfiDebtBankAccounts = (0, marginfiUtils_1.findMarginfiBankAccounts)({
51
- mint: this.debtLiquidityMint.toString(),
51
+ mint: this.debtMint.toString(),
52
52
  });
53
53
  const existingMarginfiAccounts = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(this.umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), false);
54
54
  const emptyMarginfiAccounts = (await (0, marginfi_sdk_1.safeFetchAllMarginfiAccount)(this.umi, existingMarginfiAccounts.map((x) => (0, umi_1.publicKey)(x)))).filter((x) => x.lendingAccount.balances.find((y) => y.bankPk.toString() !== web3_js_1.PublicKey.default.toString() &&
@@ -102,10 +102,10 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
102
102
  marginfiAccount: this.marginfiAccountSeedIdx !== undefined
103
103
  ? (0, umi_1.publicKey)(this.marginfiAccount)
104
104
  : this.marginfiAccount,
105
- supplyMint: (0, umi_1.publicKey)(this.supplyLiquidityMint),
105
+ supplyMint: (0, umi_1.publicKey)(this.supplyMint),
106
106
  supplyBank: (0, umi_1.publicKey)(this.marginfiSupplyBankAccounts.bank),
107
107
  positionSupplyTa: (0, umi_1.publicKey)(this.positionSupplyLiquidityTa),
108
- debtMint: (0, umi_1.publicKey)(this.debtLiquidityMint),
108
+ debtMint: (0, umi_1.publicKey)(this.debtMint),
109
109
  debtBank: (0, umi_1.publicKey)(this.marginfiDebtBankAccounts.bank),
110
110
  positionDebtTa: (0, umi_1.publicKey)(this.positionDebtLiquidityTa),
111
111
  signerDebtTa: signerDebtLiquidityTa,
@@ -213,7 +213,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
213
213
  });
214
214
  }
215
215
  flashBorrow(flashLoanDetails, destinationTokenAccount) {
216
- const bank = flashLoanDetails.mint.equals(this.supplyLiquidityMint)
216
+ const bank = flashLoanDetails.mint.equals(this.supplyMint)
217
217
  ? this.marginfiSupplyBankAccounts
218
218
  : this.marginfiDebtBankAccounts;
219
219
  return (0, umi_1.transactionBuilder)()
@@ -235,7 +235,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
235
235
  }));
236
236
  }
237
237
  flashRepay(flashLoanDetails) {
238
- const bank = flashLoanDetails.mint.equals(this.supplyLiquidityMint)
238
+ const bank = flashLoanDetails.mint.equals(this.supplyMint)
239
239
  ? this.marginfiSupplyBankAccounts
240
240
  : this.marginfiDebtBankAccounts;
241
241
  const remainingAccounts = [];
@@ -305,7 +305,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
305
305
  if (state) {
306
306
  return state;
307
307
  }
308
- const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, this.supplyLiquidityMint, this.debtLiquidityMint, this.livePositionUpdates);
308
+ const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, this.supplyMint, this.debtMint, this.livePositionUpdates);
309
309
  this.log(freshState);
310
310
  return freshState;
311
311
  }
@@ -1,3 +1,7 @@
1
1
  export declare const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
2
2
  export declare const ALL_SUPPORTED_TOKENS: string[];
3
+ export declare const TOKEN_DECIMALS: {
4
+ [x: string]: number;
5
+ EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: number;
6
+ };
3
7
  //# sourceMappingURL=tokenConstants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokenConstants.d.ts","sourceRoot":"","sources":["../../src/constants/tokenConstants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,iDAAiD,CAAC;AAGxE,eAAO,MAAM,oBAAoB,UAGhC,CAAC"}
1
+ {"version":3,"file":"tokenConstants.d.ts","sourceRoot":"","sources":["../../src/constants/tokenConstants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,iDAAiD,CAAC;AAGxE,eAAO,MAAM,oBAAoB,UAGhC,CAAC;AAEF,eAAO,MAAM,cAAc;;;CAG1B,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ALL_SUPPORTED_TOKENS = exports.USDC_MINT = void 0;
3
+ exports.TOKEN_DECIMALS = exports.ALL_SUPPORTED_TOKENS = exports.USDC_MINT = void 0;
4
4
  const spl_token_1 = require("@solana/spl-token");
5
5
  exports.USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
6
6
  // When adding token ensure a price feed is provided in pythConstants.ts
@@ -8,3 +8,7 @@ exports.ALL_SUPPORTED_TOKENS = [
8
8
  spl_token_1.NATIVE_MINT.toString(),
9
9
  exports.USDC_MINT,
10
10
  ];
11
+ exports.TOKEN_DECIMALS = {
12
+ [spl_token_1.NATIVE_MINT.toString()]: 9,
13
+ [exports.USDC_MINT]: 6
14
+ };
@@ -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;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EAQd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAiLzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,kBAAkB,CAAC,CAsE7B;AA0DD,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,CA2GA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,eAAe,GAC5B,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CA8BzC"}
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;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EAQd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAgLzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,kBAAkB,CAAC,CAsE7B;AA0DD,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,CA2GA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,eAAe,GAC5B,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CA8BzC"}
@@ -14,8 +14,8 @@ const numberUtils_1 = require("../utils/numberUtils");
14
14
  const generalUtils_2 = require("../utils/solauto/generalUtils");
15
15
  const accountUtils_1 = require("../utils/accountUtils");
16
16
  function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn) {
17
- const supplyIsWsol = client.supplyLiquidityMint.equals(spl_token_1.NATIVE_MINT);
18
- const debtIsWsol = client.debtLiquidityMint.equals(spl_token_1.NATIVE_MINT);
17
+ const supplyIsWsol = client.supplyMint.equals(spl_token_1.NATIVE_MINT);
18
+ const debtIsWsol = client.debtMint.equals(spl_token_1.NATIVE_MINT);
19
19
  if (!supplyIsWsol && !debtIsWsol) {
20
20
  return undefined;
21
21
  }
@@ -70,7 +70,7 @@ async function transactionChoresBefore(client, solautoActions, initiatingDcaIn)
70
70
  amountToTransfer += BigInt(wSolUsage.solautoAction.fields[0].fields[0]);
71
71
  }
72
72
  else if (initiatingDcaIn &&
73
- client.debtLiquidityMint.toString() === spl_token_1.NATIVE_MINT.toString()) {
73
+ client.debtMint.toString() === spl_token_1.NATIVE_MINT.toString()) {
74
74
  amountToTransfer += initiatingDcaIn;
75
75
  }
76
76
  if (amountToTransfer > 0) {
@@ -96,8 +96,8 @@ async function transactionChoresBefore(client, solautoActions, initiatingDcaIn)
96
96
  }
97
97
  if (!(0, generalUtils_1.getSolanaAccountCreated)(client.umi, tokenAccount)) {
98
98
  chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), (0, generated_1.isSolautoAction)("Withdraw", solautoAction)
99
- ? client.supplyLiquidityMint
100
- : client.debtLiquidityMint));
99
+ ? client.supplyMint
100
+ : client.debtMint));
101
101
  accountsGettingCreated.push(tokenAccount.toString());
102
102
  }
103
103
  }
@@ -123,12 +123,12 @@ async function rebalanceChoresBefore(client, tx) {
123
123
  const [referredBySupplyTa, solautoFeesSupplyTa, intermediaryMarginfiAccount] = await client.umi.rpc.getAccounts(accountsNeeded.map((x) => (0, umi_1.publicKey)(x ?? web3_js_1.PublicKey.default)));
124
124
  let chores = (0, umi_1.transactionBuilder)();
125
125
  if (checkReferralSupplyTa && !(0, generalUtils_1.rpcAccountCreated)(referredBySupplyTa)) {
126
- client.log("Creating referred-by TA for ", client.supplyLiquidityMint.toString());
127
- chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.referredByState, client.supplyLiquidityMint));
126
+ client.log("Creating referred-by TA for ", client.supplyMint.toString());
127
+ chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.referredByState, client.supplyMint));
128
128
  }
129
129
  if (checkSolautoFeesTa && !(0, generalUtils_1.rpcAccountCreated)(solautoFeesSupplyTa)) {
130
- client.log("Creating Solauto fees TA for ", client.supplyLiquidityMint.toString());
131
- chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.solautoFeesWallet, client.supplyLiquidityMint));
130
+ client.log("Creating Solauto fees TA for ", client.supplyMint.toString());
131
+ chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.solautoFeesWallet, client.supplyMint));
132
132
  }
133
133
  if (checkIntermediaryMfiAccount &&
134
134
  !(0, generalUtils_1.rpcAccountCreated)(intermediaryMarginfiAccount)) {
@@ -228,7 +228,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
228
228
  ]);
229
229
  }
230
230
  if (client.solautoPositionState.liqUtilizationRateBps >
231
- (0, generalUtils_2.getMaxLiqUtilizationRate)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps)) {
231
+ (0, numberUtils_1.getMaxLiqUtilizationRate)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps)) {
232
232
  tx = tx.prepend(client.refresh());
233
233
  }
234
234
  return {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const numberUtils_1 = require("./numberUtils");
4
- // // TODO delete this file
4
+ // TODO delete this file
5
5
  function check() {
6
6
  let supply = 458948;
7
7
  let debt = 212846;
@@ -45,7 +45,7 @@ function arraysAreEqual(arrayA, arrayB) {
45
45
  exports.arraysAreEqual = arraysAreEqual;
46
46
  async function getTokenPrices(mints) {
47
47
  const currentTime = currentUnixSeconds();
48
- if (!mints.some(mint => !(mint.toString() in solautoConstants_1.PRICES) || currentTime - solautoConstants_1.PRICES[mint.toString()].time > 5)) {
48
+ if (!mints.some(mint => !(mint.toString() in solautoConstants_1.PRICES) || currentTime - solautoConstants_1.PRICES[mint.toString()].time > 3)) {
49
49
  console.log("Accessing price cache");
50
50
  return mints.map(mint => solautoConstants_1.PRICES[mint.toString()].price);
51
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CA+D7B"}
1
+ {"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CAiE7B"}
@@ -31,9 +31,8 @@ async function getJupSwapTransaction(signer, swapDetails) {
31
31
  ? "ExactIn"
32
32
  : undefined,
33
33
  });
34
- // Up price slippage bps by an extra swapDetails.slippageBpsIncFactor of the estimated price impact (minimum 0.1% price slippage no matter what)
35
- const finalPriceSlippageBps = Math.max(quoteResponse.slippageBps ?? 10, Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct)) *
36
- (1 + (swapDetails.slippageBpsIncFactor ?? 0))));
34
+ const finalPriceSlippageBps = Math.round(Math.max(quoteResponse.slippageBps ?? 10, Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct)))) *
35
+ (1 + (swapDetails.slippageBpsIncFactor ?? 0)));
37
36
  quoteResponse.slippageBps = finalPriceSlippageBps;
38
37
  console.log(quoteResponse);
39
38
  console.log("Getting jup instructions...");
@@ -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,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAOL,MAAM,iBAAiB,CAAC;AAUzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,wBAAgB,wBAAwB,CAAC,EACvC,IAAI,EACJ,IAAI,GACL,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,qBAAqB,CAWxB;AAED,wBAAsB,wBAAwB,CAC5C,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAkC3B;AAED,wBAAsB,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,CACrD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAAC,SAAS,EAAE,CAAC,CAuCtB;AAoDD,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,SAAS,EAC5B,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,EACpB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA4IpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0B3B"}
@@ -64,11 +64,11 @@ async function getAllMarginfiAccountsByAuthority(umi, authority, compatibleWithS
64
64
  ],
65
65
  });
66
66
  if (compatibleWithSolauto) {
67
- const compatiblePositions = await Promise.all(marginfiAccounts.map((x) => ({
67
+ const positionStates = await Promise.all(marginfiAccounts.map(async (x) => ({
68
68
  publicKey: x.publicKey,
69
- state: getMarginfiAccountPositionState(umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey)),
69
+ state: await getMarginfiAccountPositionState(umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey)),
70
70
  })));
71
- return compatiblePositions
71
+ return positionStates
72
72
  .filter((x) => x.state !== undefined)
73
73
  .map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
74
74
  }
@@ -6,4 +6,7 @@ export declare function toBps(value: number): number;
6
6
  export declare function bytesToI80F48(bytes: number[]): number;
7
7
  export declare function uint8ArrayToBigInt(uint8Array: Uint8Array): bigint;
8
8
  export declare function getDebtAdjustmentUsd(liqThresholdBps: number, supplyUsd: number, debtUsd: number, targetLiqUtilizationRateBps: number, adjustmentFeeBps?: number): number;
9
+ export declare function getMaxLiqUtilizationRate(maxLtvBps: number, liqThresholdBps: number): number;
10
+ export declare function maxRepayFrom(maxLtvBps: number, liqThresholdBps: number): number;
11
+ export declare function maxRepayTo(maxLtvBps: number, liqThresholdBps: number): number;
9
12
  //# sourceMappingURL=numberUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAM3G;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhE;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAqBrD;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAajE;AAED,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,2BAA2B,EAAE,MAAM,EACnC,gBAAgB,CAAC,EAAE,MAAM,UAQ1B"}
1
+ {"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAM3G;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhE;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAqBrD;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAajE;AAED,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,2BAA2B,EAAE,MAAM,EACnC,gBAAgB,CAAC,EAAE,MAAM,UAQ1B;AAED,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB,MAAM,CAER;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKtE;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKpE"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDebtAdjustmentUsd = exports.uint8ArrayToBigInt = exports.bytesToI80F48 = exports.toBps = exports.fromBps = exports.fromBaseUnit = exports.toBaseUnit = exports.getLiqUtilzationRateBps = void 0;
3
+ exports.maxRepayTo = exports.maxRepayFrom = exports.getMaxLiqUtilizationRate = exports.getDebtAdjustmentUsd = exports.uint8ArrayToBigInt = exports.bytesToI80F48 = exports.toBps = exports.fromBps = exports.fromBaseUnit = exports.toBaseUnit = exports.getLiqUtilzationRateBps = void 0;
4
+ const constants_1 = require("../constants");
4
5
  function getLiqUtilzationRateBps(supplyUsd, debtUsd, liqThresholdBps) {
5
6
  if (supplyUsd === 0) {
6
7
  return 0;
@@ -60,3 +61,15 @@ function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtil
60
61
  return debtAdjustmentUsd;
61
62
  }
62
63
  exports.getDebtAdjustmentUsd = getDebtAdjustmentUsd;
64
+ function getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps) {
65
+ return toBps((fromBps(maxLtvBps) - 0.01) / fromBps(liqThresholdBps)) - 1;
66
+ }
67
+ exports.getMaxLiqUtilizationRate = getMaxLiqUtilizationRate;
68
+ function maxRepayFrom(maxLtvBps, liqThresholdBps) {
69
+ return Math.min(9000, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps - 1000));
70
+ }
71
+ exports.maxRepayFrom = maxRepayFrom;
72
+ function maxRepayTo(maxLtvBps, liqThresholdBps) {
73
+ return Math.min(maxRepayFrom(maxLtvBps, liqThresholdBps) - constants_1.MAX_REPAY_GAP_BPS, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps));
74
+ }
75
+ exports.maxRepayTo = maxRepayTo;
@@ -150,7 +150,7 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly,
150
150
  const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, attemptNum);
151
151
  console.log("Compute unit price: ", feeEstimate);
152
152
  const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(connection, (0, umi_web3js_adapters_1.toWeb3JsTransaction)(await (await assembleFinalTransaction(umi.identity, tx, feeEstimate, 1400000).setLatestBlockhash(umi)).buildAndSign(umi))));
153
- const computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.15);
153
+ const computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.1);
154
154
  console.log("Compute unit limit: ", computeUnitLimit);
155
155
  if (!simulateOnly) {
156
156
  const result = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await assembleFinalTransaction(umi.identity, tx, feeEstimate, computeUnitLimit).sendAndConfirm(umi, {
@@ -10,9 +10,6 @@ export declare function getSolautoFeesBps(isReferred: boolean, feeType: FeeType)
10
10
  referrer: number;
11
11
  total: number;
12
12
  };
13
- export declare function getMaxLiqUtilizationRate(maxLtvBps: number, liqThresholdBps: number): number;
14
- export declare function maxRepayFrom(maxLtvBps: number, liqThresholdBps: number): number;
15
- export declare function maxRepayTo(maxLtvBps: number, liqThresholdBps: number): number;
16
13
  export declare function eligibileForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings): boolean;
17
14
  export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters): boolean;
18
15
  export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey): Promise<{
@@ -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;AAgCzB,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,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M,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,gCAAgC,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE/C,qBAAa,mBAAmB;IACvB,gBAAgB,EAAE,MAAM,CAAa;IACrC,cAAc,EAAE,MAAM,CAAa;IACnC,uBAAuB,EAAE,MAAM,CAAa;IAC5C,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAEtD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IAyD9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LivePositionUpdates = exports.getAllPositionsByAuthority = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.eligibileForRebalance = exports.maxRepayTo = exports.maxRepayFrom = exports.getMaxLiqUtilizationRate = exports.getSolautoFeesBps = exports.getAdjustedSettingsFromAutomation = exports.getUpdatedValueFromAutomation = exports.eligibleForNextAutomationPeriod = exports.nextAutomationPeriodTimestamp = void 0;
3
+ exports.LivePositionUpdates = exports.getAllPositionsByAuthority = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.eligibileForRebalance = exports.getSolautoFeesBps = exports.getAdjustedSettingsFromAutomation = exports.getUpdatedValueFromAutomation = exports.eligibleForNextAutomationPeriod = exports.nextAutomationPeriodTimestamp = void 0;
4
4
  const umi_1 = require("@metaplex-foundation/umi");
5
5
  const generated_1 = require("../../generated");
6
6
  const generalUtils_1 = require("../generalUtils");
7
7
  const numberUtils_1 = require("../numberUtils");
8
- const solautoConstants_1 = require("../../constants/solautoConstants");
9
8
  const accountUtils_1 = require("../accountUtils");
10
9
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
11
10
  const constants_1 = require("../../constants");
@@ -59,18 +58,6 @@ function getSolautoFeesBps(isReferred, feeType) {
59
58
  };
60
59
  }
61
60
  exports.getSolautoFeesBps = getSolautoFeesBps;
62
- function getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps) {
63
- return (0, numberUtils_1.toBps)(((0, numberUtils_1.fromBps)(maxLtvBps) - 0.015) / (0, numberUtils_1.fromBps)(liqThresholdBps)) - 1;
64
- }
65
- exports.getMaxLiqUtilizationRate = getMaxLiqUtilizationRate;
66
- function maxRepayFrom(maxLtvBps, liqThresholdBps) {
67
- return Math.min(9000, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps - 1000));
68
- }
69
- exports.maxRepayFrom = maxRepayFrom;
70
- function maxRepayTo(maxLtvBps, liqThresholdBps) {
71
- return Math.min(maxRepayFrom(maxLtvBps, liqThresholdBps) - solautoConstants_1.MAX_REPAY_GAP_BPS, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps));
72
- }
73
- exports.maxRepayTo = maxRepayTo;
74
61
  function eligibileForRebalance(positionState, positionSettings, positionDca) {
75
62
  if (positionDca.automation.targetPeriods > 0 &&
76
63
  eligibleForNextAutomationPeriod(positionDca.automation)) {
@@ -207,7 +194,7 @@ async function getAllPositionsByAuthority(umi, user) {
207
194
  protocolAccount: pubkey,
208
195
  })));
209
196
  // TODO support other platforms
210
- return [];
197
+ return allPositions;
211
198
  }
212
199
  exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
213
200
  async function positionStateWithLatestPrices(umi, state, protocolAccount, lendingPlatform) {
@@ -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;AAU5D,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,CAiE9B;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,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"}
@@ -93,7 +93,7 @@ function getRebalanceValues(client, targetLiqUtilizationRateBps, limitGapBps) {
93
93
  throw new Error("Requires a fresh position state to get rebalance details");
94
94
  }
95
95
  const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(client, targetLiqUtilizationRateBps);
96
- const amountUsdToDcaIn = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountToDcaIn ?? 0)), client.solautoPositionState.debt.decimals) * solautoConstants_1.PRICES[client.debtLiquidityMint.toString()].price;
96
+ const amountUsdToDcaIn = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountToDcaIn ?? 0)), client.solautoPositionState.debt.decimals) * solautoConstants_1.PRICES[client.debtMint.toString()].price;
97
97
  const increasingLeverage = amountUsdToDcaIn > 0 ||
98
98
  client.solautoPositionState.liqUtilizationRateBps < targetRateBps;
99
99
  let adjustmentFeeBps = 0;
@@ -103,12 +103,13 @@ function getRebalanceValues(client, targetLiqUtilizationRateBps, limitGapBps) {
103
103
  const supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) + amountUsdToDcaIn;
104
104
  const debtUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
105
105
  let debtAdjustmentUsd = (0, numberUtils_1.getDebtAdjustmentUsd)(client.solautoPositionState.liqThresholdBps, supplyUsd, debtUsd, targetRateBps, adjustmentFeeBps);
106
+ debtAdjustmentUsd *= 500;
106
107
  const input = increasingLeverage
107
108
  ? client.solautoPositionState.debt
108
109
  : client.solautoPositionState.supply;
109
110
  const inputMarketPrice = increasingLeverage
110
- ? solautoConstants_1.PRICES[client.debtLiquidityMint.toString()].price
111
- : solautoConstants_1.PRICES[client.supplyLiquidityMint.toString()].price;
111
+ ? solautoConstants_1.PRICES[client.debtMint.toString()].price
112
+ : solautoConstants_1.PRICES[client.supplyMint.toString()].price;
112
113
  const limitGap = limitGapBps
113
114
  ? (0, numberUtils_1.fromBps)(limitGapBps)
114
115
  : (0, numberUtils_1.fromBps)(solautoConstants_1.DEFAULT_LIMIT_GAP_BPS);
@@ -141,18 +142,18 @@ function getFlashLoanDetails(client, values, jupQuote) {
141
142
  ? debtUsd + debtAdjustmentWithSlippage
142
143
  : debtUsd;
143
144
  const tempLiqUtilizationRateBps = (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, client.solautoPositionState.liqThresholdBps);
144
- const requiresFlashLoan = supplyUsd === 0 ||
145
+ const requiresFlashLoan = supplyUsd <= 0 ||
145
146
  tempLiqUtilizationRateBps >
146
- (0, generalUtils_1.getMaxLiqUtilizationRate)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps);
147
+ (0, numberUtils_1.getMaxLiqUtilizationRate)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps);
147
148
  let flashLoanToken = undefined;
148
149
  let flashLoanTokenPrice = 0;
149
150
  if (values.increasingLeverage) {
150
151
  flashLoanToken = client.solautoPositionState.debt;
151
- flashLoanTokenPrice = solautoConstants_1.PRICES[client.debtLiquidityMint.toString()].price;
152
+ flashLoanTokenPrice = solautoConstants_1.PRICES[client.debtMint.toString()].price;
152
153
  }
153
154
  else {
154
155
  flashLoanToken = client.solautoPositionState.supply;
155
- flashLoanTokenPrice = solautoConstants_1.PRICES[client.supplyLiquidityMint.toString()].price;
156
+ flashLoanTokenPrice = solautoConstants_1.PRICES[client.supplyMint.toString()].price;
156
157
  }
157
158
  const exactAmountBaseUnit = jupQuote && jupQuote.swapMode === "ExactOut"
158
159
  ? BigInt(parseInt(jupQuote.inAmount))
@@ -177,15 +178,15 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
177
178
  : client.solautoPositionState.debt;
178
179
  const usdToSwap = Math.abs(values.debtAdjustmentUsd) + values.amountUsdToDcaIn;
179
180
  const inputPrice = values.increasingLeverage
180
- ? solautoConstants_1.PRICES[client.debtLiquidityMint.toString()].price
181
- : solautoConstants_1.PRICES[client.supplyLiquidityMint.toString()].price;
181
+ ? solautoConstants_1.PRICES[client.debtMint.toString()].price
182
+ : solautoConstants_1.PRICES[client.supplyMint.toString()].price;
182
183
  const inputAmount = (0, numberUtils_1.toBaseUnit)(usdToSwap / inputPrice, input.decimals);
183
184
  const rebalancingToZero = targetLiqUtilizationRateBps === 0;
184
185
  return {
185
186
  inputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint),
186
187
  outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint),
187
188
  destinationWallet: client.solautoPosition,
188
- // slippageBpsIncFactor: (values.increasingLeverage ? 0.1 : 0.2) + ((attemptNum ?? 0) * 0.1),
189
+ // slippageBpsIncFactor: (!values.increasingLeverage ? 0.1 : 0) + ((attemptNum ?? 0) * 0.15),
189
190
  slippageBpsIncFactor: (attemptNum ?? 0) * 0.15,
190
191
  amount: rebalancingToZero
191
192
  ? client.solautoPositionState.debt.amountUsed.baseUnit +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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",
@@ -66,8 +66,8 @@ export interface SolautoClientArgs {
66
66
  signer?: Signer;
67
67
  wallet?: WalletAdapter;
68
68
 
69
- supplyLiquidityMint?: PublicKey;
70
- debtLiquidityMint?: PublicKey;
69
+ supplyMint?: PublicKey;
70
+ debtMint?: PublicKey;
71
71
 
72
72
  referralFeesDestMint?: PublicKey;
73
73
  referredByAuthority?: PublicKey;
@@ -87,11 +87,11 @@ export abstract class SolautoClient {
87
87
  public solautoPositionData!: SolautoPosition | null;
88
88
  public solautoPositionState!: PositionState | undefined;
89
89
 
90
- public supplyLiquidityMint!: PublicKey;
90
+ public supplyMint!: PublicKey;
91
91
  public positionSupplyLiquidityTa!: PublicKey;
92
92
  public signerSupplyLiquidityTa!: PublicKey;
93
93
 
94
- public debtLiquidityMint!: PublicKey;
94
+ public debtMint!: PublicKey;
95
95
  public positionDebtLiquidityTa!: PublicKey;
96
96
  public signerDebtLiquidityTa!: PublicKey;
97
97
 
@@ -127,10 +127,7 @@ export abstract class SolautoClient {
127
127
  });
128
128
  }
129
129
 
130
- async initialize(
131
- args: SolautoClientArgs,
132
- lendingPlatform: LendingPlatform,
133
- ) {
130
+ async initialize(args: SolautoClientArgs, lendingPlatform: LendingPlatform) {
134
131
  if (!args.signer && !args.wallet) {
135
132
  throw new Error("Signer or wallet must be provided");
136
133
  }
@@ -157,28 +154,28 @@ export abstract class SolautoClient {
157
154
  );
158
155
  this.solautoPositionState = this.solautoPositionData?.state;
159
156
 
160
- this.supplyLiquidityMint =
161
- args.supplyLiquidityMint ??
157
+ this.supplyMint =
158
+ args.supplyMint ??
162
159
  toWeb3JsPublicKey(this.solautoPositionData!.position.supplyMint);
163
160
  this.positionSupplyLiquidityTa = getTokenAccount(
164
161
  this.solautoPosition,
165
- this.supplyLiquidityMint
162
+ this.supplyMint
166
163
  );
167
164
  this.signerSupplyLiquidityTa = getTokenAccount(
168
165
  toWeb3JsPublicKey(this.signer.publicKey),
169
- this.supplyLiquidityMint
166
+ this.supplyMint
170
167
  );
171
168
 
172
- this.debtLiquidityMint =
173
- args.debtLiquidityMint ??
169
+ this.debtMint =
170
+ args.debtMint ??
174
171
  toWeb3JsPublicKey(this.solautoPositionData!.position.debtMint);
175
172
  this.positionDebtLiquidityTa = getTokenAccount(
176
173
  this.solautoPosition,
177
- this.debtLiquidityMint
174
+ this.debtMint
178
175
  );
179
176
  this.signerDebtLiquidityTa = getTokenAccount(
180
177
  toWeb3JsPublicKey(this.signer.publicKey),
181
- this.debtLiquidityMint
178
+ this.debtMint
182
179
  );
183
180
 
184
181
  this.authorityReferralState = await getReferralState(this.authority);
@@ -196,31 +193,33 @@ export abstract class SolautoClient {
196
193
  this.authorityReferralFeesDestMint
197
194
  );
198
195
 
196
+ const hasReferredBy =
197
+ this.authorityReferralStateData &&
198
+ this.authorityReferralStateData.referredByState !==
199
+ publicKey(PublicKey.default);
199
200
  const referredByAuthority =
201
+ !hasReferredBy &&
200
202
  args.referredByAuthority &&
201
203
  !args.referredByAuthority.equals(toWeb3JsPublicKey(this.signer.publicKey))
202
204
  ? args.referredByAuthority
203
205
  : undefined;
204
- this.referredByState =
205
- this.authorityReferralStateData &&
206
- this.authorityReferralStateData.referredByState !==
207
- publicKey(PublicKey.default)
208
- ? toWeb3JsPublicKey(this.authorityReferralStateData.referredByState)
209
- : referredByAuthority
210
- ? await getReferralState(referredByAuthority!)
211
- : undefined;
206
+ this.referredByState = hasReferredBy
207
+ ? toWeb3JsPublicKey(this.authorityReferralStateData!.referredByState)
208
+ : referredByAuthority
209
+ ? await getReferralState(referredByAuthority!)
210
+ : undefined;
212
211
  this.referredByAuthority = referredByAuthority;
213
212
  if (this.referredByState !== undefined) {
214
213
  this.referredBySupplyTa = getTokenAccount(
215
214
  this.referredByState,
216
- this.supplyLiquidityMint
215
+ this.supplyMint
217
216
  );
218
217
  }
219
218
 
220
219
  this.solautoFeesWallet = SOLAUTO_FEES_WALLET;
221
220
  this.solautoFeesSupplyTa = getTokenAccount(
222
221
  this.solautoFeesWallet,
223
- this.supplyLiquidityMint
222
+ this.supplyMint
224
223
  );
225
224
 
226
225
  this.authorityLutAddress = this.authorityReferralStateData?.lookupTable
@@ -443,7 +442,7 @@ export abstract class SolautoClient {
443
442
  let positionDebtTa: UmiPublicKey | undefined = undefined;
444
443
  let signerDebtTa: UmiPublicKey | undefined = undefined;
445
444
  if (isOption(args.dca) && isSome(args.dca)) {
446
- debtMint = publicKey(this.debtLiquidityMint);
445
+ debtMint = publicKey(this.debtMint);
447
446
  positionDebtTa = publicKey(this.positionDebtLiquidityTa);
448
447
  signerDebtTa = publicKey(this.signerDebtLiquidityTa);
449
448
 
@@ -516,7 +515,7 @@ export abstract class SolautoClient {
516
515
  if (this.solautoPositionData !== null && !this.selfManaged) {
517
516
  const positionData = this.solautoPositionData!.position;
518
517
  if (positionData.dca.debtToAddBaseUnit) {
519
- debtMint = publicKey(this.debtLiquidityMint);
518
+ debtMint = publicKey(this.debtMint);
520
519
  positionDebtTa = publicKey(this.positionDebtLiquidityTa);
521
520
  signerDebtTa = publicKey(this.signerDebtLiquidityTa);
522
521
 
@@ -77,8 +77,8 @@ export function newMarginfiSolautoManagedPositionArgs(
77
77
  signer,
78
78
  wallet,
79
79
  marginfiAccountSeedIdx: positionId > 0 ? generateRandomU64() : undefined,
80
- supplyLiquidityMint: supplyMint,
81
- debtLiquidityMint: debtMint,
80
+ supplyMint: supplyMint,
81
+ debtMint: debtMint,
82
82
  referredByAuthority,
83
83
  };
84
84
  }
@@ -129,10 +129,10 @@ export class SolautoMarginfiClient extends SolautoClient {
129
129
  : args.marginfiGroup ?? new PublicKey(DEFAULT_MARGINFI_GROUP);
130
130
 
131
131
  this.marginfiSupplyBankAccounts = findMarginfiBankAccounts({
132
- mint: this.supplyLiquidityMint.toString(),
132
+ mint: this.supplyMint.toString(),
133
133
  })!;
134
134
  this.marginfiDebtBankAccounts = findMarginfiBankAccounts({
135
- mint: this.debtLiquidityMint.toString(),
135
+ mint: this.debtMint.toString(),
136
136
  })!;
137
137
 
138
138
  const existingMarginfiAccounts = await getAllMarginfiAccountsByAuthority(
@@ -218,10 +218,10 @@ export class SolautoMarginfiClient extends SolautoClient {
218
218
  this.marginfiAccountSeedIdx !== undefined
219
219
  ? publicKey(this.marginfiAccount)
220
220
  : (this.marginfiAccount as Signer),
221
- supplyMint: publicKey(this.supplyLiquidityMint),
221
+ supplyMint: publicKey(this.supplyMint),
222
222
  supplyBank: publicKey(this.marginfiSupplyBankAccounts.bank),
223
223
  positionSupplyTa: publicKey(this.positionSupplyLiquidityTa),
224
- debtMint: publicKey(this.debtLiquidityMint),
224
+ debtMint: publicKey(this.debtMint),
225
225
  debtBank: publicKey(this.marginfiDebtBankAccounts.bank),
226
226
  positionDebtTa: publicKey(this.positionDebtLiquidityTa),
227
227
  signerDebtTa: signerDebtLiquidityTa,
@@ -370,7 +370,7 @@ export class SolautoMarginfiClient extends SolautoClient {
370
370
  flashLoanDetails: FlashLoanDetails,
371
371
  destinationTokenAccount: PublicKey
372
372
  ): TransactionBuilder {
373
- const bank = flashLoanDetails.mint.equals(this.supplyLiquidityMint)
373
+ const bank = flashLoanDetails.mint.equals(this.supplyMint)
374
374
  ? this.marginfiSupplyBankAccounts
375
375
  : this.marginfiDebtBankAccounts;
376
376
  return transactionBuilder()
@@ -397,7 +397,7 @@ export class SolautoMarginfiClient extends SolautoClient {
397
397
  }
398
398
 
399
399
  flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder {
400
- const bank = flashLoanDetails.mint.equals(this.supplyLiquidityMint)
400
+ const bank = flashLoanDetails.mint.equals(this.supplyMint)
401
401
  ? this.marginfiSupplyBankAccounts
402
402
  : this.marginfiDebtBankAccounts;
403
403
 
@@ -492,8 +492,8 @@ export class SolautoMarginfiClient extends SolautoClient {
492
492
  const freshState = await getMarginfiAccountPositionState(
493
493
  this.umi,
494
494
  this.marginfiAccountPk,
495
- this.supplyLiquidityMint,
496
- this.debtLiquidityMint,
495
+ this.supplyMint,
496
+ this.debtMint,
497
497
  this.livePositionUpdates
498
498
  );
499
499
  this.log(freshState);
@@ -6,4 +6,9 @@ export const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
6
6
  export const ALL_SUPPORTED_TOKENS = [
7
7
  NATIVE_MINT.toString(),
8
8
  USDC_MINT,
9
- ];
9
+ ];
10
+
11
+ export const TOKEN_DECIMALS = {
12
+ [NATIVE_MINT.toString()]: 9,
13
+ [USDC_MINT]: 6
14
+ };
@@ -40,10 +40,9 @@ import {
40
40
  rpcAccountCreated,
41
41
  } from "../utils/generalUtils";
42
42
  import { SolautoMarginfiClient } from "../clients/solautoMarginfiClient";
43
- import { uint8ArrayToBigInt } from "../utils/numberUtils";
43
+ import { getMaxLiqUtilizationRate, uint8ArrayToBigInt } from "../utils/numberUtils";
44
44
  import {
45
45
  eligibileForRebalance,
46
- getMaxLiqUtilizationRate,
47
46
  } from "../utils/solauto/generalUtils";
48
47
  import { getTokenAccount } from "../utils/accountUtils";
49
48
 
@@ -58,8 +57,8 @@ function getWSolUsage(
58
57
  initiatingDcaIn?: bigint,
59
58
  cancellingDcaIn?: boolean
60
59
  ): wSolTokenUsage | undefined {
61
- const supplyIsWsol = client.supplyLiquidityMint.equals(NATIVE_MINT);
62
- const debtIsWsol = client.debtLiquidityMint.equals(NATIVE_MINT);
60
+ const supplyIsWsol = client.supplyMint.equals(NATIVE_MINT);
61
+ const debtIsWsol = client.debtMint.equals(NATIVE_MINT);
63
62
  if (!supplyIsWsol && !debtIsWsol) {
64
63
  return undefined;
65
64
  }
@@ -142,7 +141,7 @@ async function transactionChoresBefore(
142
141
  amountToTransfer += BigInt(wSolUsage.solautoAction.fields[0].fields[0]);
143
142
  } else if (
144
143
  initiatingDcaIn &&
145
- client.debtLiquidityMint.toString() === NATIVE_MINT.toString()
144
+ client.debtMint.toString() === NATIVE_MINT.toString()
146
145
  ) {
147
146
  amountToTransfer += initiatingDcaIn;
148
147
  }
@@ -189,8 +188,8 @@ async function transactionChoresBefore(
189
188
  client.signer,
190
189
  toWeb3JsPublicKey(client.signer.publicKey),
191
190
  isSolautoAction("Withdraw", solautoAction)
192
- ? client.supplyLiquidityMint
193
- : client.debtLiquidityMint
191
+ ? client.supplyMint
192
+ : client.debtMint
194
193
  )
195
194
  );
196
195
  accountsGettingCreated.push(tokenAccount.toString());
@@ -238,13 +237,13 @@ export async function rebalanceChoresBefore(
238
237
  if (checkReferralSupplyTa && !rpcAccountCreated(referredBySupplyTa)) {
239
238
  client.log(
240
239
  "Creating referred-by TA for ",
241
- client.supplyLiquidityMint.toString()
240
+ client.supplyMint.toString()
242
241
  );
243
242
  chores = chores.add(
244
243
  createAssociatedTokenAccountUmiIx(
245
244
  client.signer,
246
245
  client.referredByState!,
247
- client.supplyLiquidityMint
246
+ client.supplyMint
248
247
  )
249
248
  );
250
249
  }
@@ -252,13 +251,13 @@ export async function rebalanceChoresBefore(
252
251
  if (checkSolautoFeesTa && !rpcAccountCreated(solautoFeesSupplyTa)) {
253
252
  client.log(
254
253
  "Creating Solauto fees TA for ",
255
- client.supplyLiquidityMint.toString()
254
+ client.supplyMint.toString()
256
255
  );
257
256
  chores = chores.add(
258
257
  createAssociatedTokenAccountUmiIx(
259
258
  client.signer,
260
259
  client.solautoFeesWallet,
261
- client.supplyLiquidityMint
260
+ client.supplyMint
262
261
  )
263
262
  );
264
263
  }
@@ -1,6 +1,6 @@
1
1
  import { getDebtAdjustmentUsd, getLiqUtilzationRateBps } from "./numberUtils";
2
2
 
3
- // // TODO delete this file
3
+ // TODO delete this file
4
4
  function check() {
5
5
  let supply = 458948;
6
6
  let debt = 212846;
@@ -37,4 +37,4 @@ function check() {
37
37
  console.log!(liq_utilization_rate);
38
38
  }
39
39
 
40
- check();
40
+ check();
@@ -44,7 +44,7 @@ export function arraysAreEqual(arrayA: number[], arrayB: number[]): boolean {
44
44
 
45
45
  export async function getTokenPrices(mints: PublicKey[]): Promise<number[]> {
46
46
  const currentTime = currentUnixSeconds();
47
- if (!mints.some(mint => !(mint.toString() in PRICES) || currentTime - PRICES[mint.toString()].time > 5)) {
47
+ if (!mints.some(mint => !(mint.toString() in PRICES) || currentTime - PRICES[mint.toString()].time > 3)) {
48
48
  console.log("Accessing price cache");
49
49
  return mints.map(mint => PRICES[mint.toString()].price);
50
50
  }
@@ -64,13 +64,12 @@ export async function getJupSwapTransaction(
64
64
  : undefined,
65
65
  });
66
66
 
67
- // Up price slippage bps by an extra swapDetails.slippageBpsIncFactor of the estimated price impact (minimum 0.1% price slippage no matter what)
68
- const finalPriceSlippageBps = Math.max(
69
- quoteResponse.slippageBps ?? 10,
70
- Math.round(
71
- toBps(parseFloat(quoteResponse.priceImpactPct)) *
72
- (1 + (swapDetails.slippageBpsIncFactor ?? 0))
73
- )
67
+ const finalPriceSlippageBps = Math.round(
68
+ Math.max(
69
+ quoteResponse.slippageBps ?? 10,
70
+ Math.round(toBps(parseFloat(quoteResponse.priceImpactPct)))
71
+ ) *
72
+ (1 + (swapDetails.slippageBpsIncFactor ?? 0))
74
73
  );
75
74
  quoteResponse.slippageBps = finalPriceSlippageBps;
76
75
  console.log(quoteResponse);
@@ -82,7 +81,10 @@ export async function getJupSwapTransaction(
82
81
  quoteResponse,
83
82
  wrapAndUnwrapSol: false,
84
83
  useTokenLedger: !swapDetails.exactOut && !swapDetails.exactIn,
85
- destinationTokenAccount: getTokenAccount(swapDetails.destinationWallet, swapDetails.outputMint).toString(),
84
+ destinationTokenAccount: getTokenAccount(
85
+ swapDetails.destinationWallet,
86
+ swapDetails.outputMint
87
+ ).toString(),
86
88
  },
87
89
  });
88
90
 
@@ -112,17 +112,16 @@ export async function getAllMarginfiAccountsByAuthority(
112
112
  );
113
113
 
114
114
  if (compatibleWithSolauto) {
115
- const compatiblePositions = await Promise.all(
116
- marginfiAccounts.map((x) => ({
115
+ const positionStates = await Promise.all(
116
+ marginfiAccounts.map(async (x) => ({
117
117
  publicKey: x.publicKey,
118
- state: getMarginfiAccountPositionState(
118
+ state: await getMarginfiAccountPositionState(
119
119
  umi,
120
120
  toWeb3JsPublicKey(x.publicKey)
121
121
  ),
122
122
  }))
123
123
  );
124
-
125
- return compatiblePositions
124
+ return positionStates
126
125
  .filter((x) => x.state !== undefined)
127
126
  .map((x) => toWeb3JsPublicKey(x.publicKey));
128
127
  } else {
@@ -1,3 +1,5 @@
1
+ import { MAX_REPAY_GAP_BPS } from "../constants";
2
+
1
3
  export function getLiqUtilzationRateBps(supplyUsd: number, debtUsd: number, liqThresholdBps: number): number {
2
4
  if (supplyUsd === 0) {
3
5
  return 0;
@@ -73,4 +75,25 @@ export function getDebtAdjustmentUsd(
73
75
 
74
76
  const debtAdjustmentUsd = (targetLiqUtilizationRate * supplyUsd * liqThreshold - debtUsd) / (1 - targetLiqUtilizationRate * (1 - adjustmentFee) * liqThreshold);
75
77
  return debtAdjustmentUsd;
78
+ }
79
+
80
+ export function getMaxLiqUtilizationRate(
81
+ maxLtvBps: number,
82
+ liqThresholdBps: number
83
+ ): number {
84
+ return toBps((fromBps(maxLtvBps) - 0.01) / fromBps(liqThresholdBps)) - 1;
85
+ }
86
+
87
+ export function maxRepayFrom(maxLtvBps: number, liqThresholdBps: number) {
88
+ return Math.min(
89
+ 9000,
90
+ getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps - 1000)
91
+ );
92
+ }
93
+
94
+ export function maxRepayTo(maxLtvBps: number, liqThresholdBps: number) {
95
+ return Math.min(
96
+ maxRepayFrom(maxLtvBps, liqThresholdBps) - MAX_REPAY_GAP_BPS,
97
+ getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps)
98
+ );
76
99
  }
@@ -293,7 +293,7 @@ export async function sendSingleOptimizedTransaction(
293
293
  );
294
294
 
295
295
  const computeUnitLimit = Math.round(
296
- simulationResult.value.unitsConsumed! * 1.15
296
+ simulationResult.value.unitsConsumed! * 1.1
297
297
  );
298
298
  console.log("Compute unit limit: ", computeUnitLimit);
299
299
 
@@ -17,12 +17,9 @@ import {
17
17
  import { currentUnixSeconds, getTokenPrices } from "../generalUtils";
18
18
  import {
19
19
  fromBaseUnit,
20
- fromBps,
21
20
  getLiqUtilzationRateBps,
22
21
  toBaseUnit,
23
- toBps,
24
22
  } from "../numberUtils";
25
- import { MAX_REPAY_GAP_BPS } from "../../constants/solautoConstants";
26
23
  import { getReferralState } from "../accountUtils";
27
24
  import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
28
25
  import { USD_DECIMALS } from "../../constants";
@@ -120,27 +117,6 @@ export function getSolautoFeesBps(
120
117
  };
121
118
  }
122
119
 
123
- export function getMaxLiqUtilizationRate(
124
- maxLtvBps: number,
125
- liqThresholdBps: number
126
- ): number {
127
- return toBps((fromBps(maxLtvBps) - 0.015) / fromBps(liqThresholdBps)) - 1;
128
- }
129
-
130
- export function maxRepayFrom(maxLtvBps: number, liqThresholdBps: number) {
131
- return Math.min(
132
- 9000,
133
- getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps - 1000)
134
- );
135
- }
136
-
137
- export function maxRepayTo(maxLtvBps: number, liqThresholdBps: number) {
138
- return Math.min(
139
- maxRepayFrom(maxLtvBps, liqThresholdBps) - MAX_REPAY_GAP_BPS,
140
- getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps)
141
- );
142
- }
143
-
144
120
  export function eligibileForRebalance(
145
121
  positionState: PositionState,
146
122
  positionSettings: SolautoSettingsParameters,
@@ -333,7 +309,7 @@ export async function getAllPositionsByAuthority(
333
309
 
334
310
  // TODO support other platforms
335
311
 
336
- return [];
312
+ return allPositions;
337
313
  }
338
314
 
339
315
  async function positionStateWithLatestPrices(
@@ -4,7 +4,6 @@ import { PositionTokenUsage } from "../../generated";
4
4
  import {
5
5
  eligibleForNextAutomationPeriod,
6
6
  getAdjustedSettingsFromAutomation,
7
- getMaxLiqUtilizationRate,
8
7
  getSolautoFeesBps,
9
8
  getUpdatedValueFromAutomation,
10
9
  } from "./generalUtils";
@@ -17,6 +16,7 @@ import {
17
16
  fromBps,
18
17
  getDebtAdjustmentUsd,
19
18
  getLiqUtilzationRateBps,
19
+ getMaxLiqUtilizationRate,
20
20
  toBaseUnit,
21
21
  } from "../numberUtils";
22
22
  import { USD_DECIMALS } from "../../constants/generalAccounts";
@@ -144,8 +144,7 @@ function getTargetRateAndDcaAmount(
144
144
  };
145
145
  } else {
146
146
  return {
147
- targetRateBps:
148
- getStandardTargetLiqUtilizationRateBps(client),
147
+ targetRateBps: getStandardTargetLiqUtilizationRateBps(client),
149
148
  };
150
149
  }
151
150
  }
@@ -180,7 +179,7 @@ export function getRebalanceValues(
180
179
  fromBaseUnit(
181
180
  BigInt(Math.round(amountToDcaIn ?? 0)),
182
181
  client.solautoPositionState!.debt.decimals
183
- ) * PRICES[client.debtLiquidityMint.toString()].price;
182
+ ) * PRICES[client.debtMint.toString()].price;
184
183
 
185
184
  const increasingLeverage =
186
185
  amountUsdToDcaIn > 0 ||
@@ -209,13 +208,14 @@ export function getRebalanceValues(
209
208
  targetRateBps,
210
209
  adjustmentFeeBps
211
210
  );
211
+ debtAdjustmentUsd *= 500;
212
212
 
213
213
  const input = increasingLeverage
214
214
  ? client.solautoPositionState!.debt
215
215
  : client.solautoPositionState!.supply;
216
216
  const inputMarketPrice = increasingLeverage
217
- ? PRICES[client.debtLiquidityMint.toString()].price
218
- : PRICES[client.supplyLiquidityMint.toString()].price;
217
+ ? PRICES[client.debtMint.toString()].price
218
+ : PRICES[client.supplyMint.toString()].price;
219
219
 
220
220
  const limitGap = limitGapBps
221
221
  ? fromBps(limitGapBps)
@@ -270,13 +270,14 @@ export function getFlashLoanDetails(
270
270
  values.debtAdjustmentUsd > 0
271
271
  ? debtUsd + debtAdjustmentWithSlippage
272
272
  : debtUsd;
273
+
273
274
  const tempLiqUtilizationRateBps = getLiqUtilzationRateBps(
274
275
  supplyUsd,
275
276
  debtUsd,
276
277
  client.solautoPositionState!.liqThresholdBps
277
278
  );
278
279
  const requiresFlashLoan =
279
- supplyUsd === 0 ||
280
+ supplyUsd <= 0 ||
280
281
  tempLiqUtilizationRateBps >
281
282
  getMaxLiqUtilizationRate(
282
283
  client.solautoPositionState!.maxLtvBps,
@@ -287,10 +288,10 @@ export function getFlashLoanDetails(
287
288
  let flashLoanTokenPrice = 0;
288
289
  if (values.increasingLeverage) {
289
290
  flashLoanToken = client.solautoPositionState!.debt;
290
- flashLoanTokenPrice = PRICES[client.debtLiquidityMint.toString()].price;
291
+ flashLoanTokenPrice = PRICES[client.debtMint.toString()].price;
291
292
  } else {
292
293
  flashLoanToken = client.solautoPositionState!.supply;
293
- flashLoanTokenPrice = PRICES[client.supplyLiquidityMint.toString()].price;
294
+ flashLoanTokenPrice = PRICES[client.supplyMint.toString()].price;
294
295
  }
295
296
 
296
297
  const exactAmountBaseUnit =
@@ -333,8 +334,8 @@ export function getJupSwapRebalanceDetails(
333
334
  Math.abs(values.debtAdjustmentUsd) + values.amountUsdToDcaIn;
334
335
 
335
336
  const inputPrice = values.increasingLeverage
336
- ? PRICES[client.debtLiquidityMint.toString()].price
337
- : PRICES[client.supplyLiquidityMint.toString()].price;
337
+ ? PRICES[client.debtMint.toString()].price
338
+ : PRICES[client.supplyMint.toString()].price;
338
339
  const inputAmount = toBaseUnit(usdToSwap / inputPrice!, input.decimals);
339
340
 
340
341
  const rebalancingToZero = targetLiqUtilizationRateBps === 0;
@@ -342,7 +343,7 @@ export function getJupSwapRebalanceDetails(
342
343
  inputMint: toWeb3JsPublicKey(input.mint),
343
344
  outputMint: toWeb3JsPublicKey(output.mint),
344
345
  destinationWallet: client.solautoPosition,
345
- // slippageBpsIncFactor: (values.increasingLeverage ? 0.1 : 0.2) + ((attemptNum ?? 0) * 0.1),
346
+ // slippageBpsIncFactor: (!values.increasingLeverage ? 0.1 : 0) + ((attemptNum ?? 0) * 0.15),
346
347
  slippageBpsIncFactor: (attemptNum ?? 0) * 0.15,
347
348
  amount: rebalancingToZero
348
349
  ? client.solautoPositionState!.debt.amountUsed.baseUnit +
@@ -92,11 +92,12 @@ async function getFakePosition(
92
92
  settings: SolautoSettingsParameters,
93
93
  dca?: DCASettings
94
94
  ): Promise<SolautoClient> {
95
- const client = new SolautoMarginfiClient(true);
95
+ const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY ?? "", true);
96
96
  await client.initialize(
97
97
  newMarginfiSolautoManagedPositionArgs(
98
98
  1,
99
99
  signer,
100
+ undefined,
100
101
  new PublicKey(NATIVE_MINT),
101
102
  new PublicKey(MARGINFI_ACCOUNTS.USDC.mint)
102
103
  )
@@ -124,8 +125,8 @@ async function getFakePosition(
124
125
  padding: new Uint8Array([]),
125
126
  },
126
127
  lendingPlatform: LendingPlatform.Marginfi,
127
- supplyMint: publicKey(client.supplyLiquidityMint),
128
- debtMint: publicKey(client.debtLiquidityMint),
128
+ supplyMint: publicKey(client.supplyMint),
129
+ debtMint: publicKey(client.debtMint),
129
130
  protocolAccount: publicKey(PublicKey.default),
130
131
  settingParams: settings,
131
132
  padding1: [],
@@ -267,11 +268,12 @@ describe("Rebalance tests", async () => {
267
268
  });
268
269
 
269
270
  it("Standard rebalance with target rate", async () => {
270
- const client = new SolautoMarginfiClient(true);
271
+ const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY ?? "", true);
271
272
  await client.initialize(
272
273
  newMarginfiSolautoManagedPositionArgs(
273
274
  1,
274
275
  signer,
276
+ undefined,
275
277
  new PublicKey(NATIVE_MINT),
276
278
  new PublicKey(MARGINFI_ACCOUNTS.USDC.mint)
277
279
  )