@haven-fi/solauto-sdk 1.0.52 → 1.0.53

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. package/dist/clients/solautoClient.d.ts.map +1 -1
  2. package/dist/clients/solautoClient.js +1 -7
  3. package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
  4. package/dist/clients/solautoMarginfiClient.js +3 -1
  5. package/dist/generated/accounts/referralState.d.ts.map +1 -1
  6. package/dist/generated/accounts/referralState.js +8 -9
  7. package/dist/generated/accounts/solautoPosition.d.ts.map +1 -1
  8. package/dist/generated/accounts/solautoPosition.js +8 -9
  9. package/dist/generated/errors/solauto.js +3 -3
  10. package/dist/generated/instructions/cancelDCA.js +2 -3
  11. package/dist/generated/instructions/claimReferralFees.js +2 -3
  12. package/dist/generated/instructions/closePosition.js +2 -3
  13. package/dist/generated/instructions/convertReferralFees.js +2 -3
  14. package/dist/generated/instructions/marginfiOpenPosition.d.ts +1 -0
  15. package/dist/generated/instructions/marginfiOpenPosition.d.ts.map +1 -1
  16. package/dist/generated/instructions/marginfiOpenPosition.js +22 -18
  17. package/dist/generated/instructions/marginfiProtocolInteraction.js +2 -3
  18. package/dist/generated/instructions/marginfiRebalance.js +2 -3
  19. package/dist/generated/instructions/marginfiRefreshData.js +2 -3
  20. package/dist/generated/instructions/updatePosition.js +2 -3
  21. package/dist/generated/instructions/updateReferralStates.js +2 -3
  22. package/dist/generated/programs/solauto.d.ts.map +1 -1
  23. package/dist/generated/programs/solauto.js +4 -4
  24. package/dist/generated/shared/index.js +4 -5
  25. package/dist/generated/types/automationSettings.js +1 -2
  26. package/dist/generated/types/automationSettingsInp.js +1 -2
  27. package/dist/generated/types/dCASettings.js +1 -2
  28. package/dist/generated/types/dCASettingsInp.js +1 -2
  29. package/dist/generated/types/feeType.js +3 -3
  30. package/dist/generated/types/lendingPlatform.js +3 -3
  31. package/dist/generated/types/podBool.js +1 -2
  32. package/dist/generated/types/positionData.js +1 -2
  33. package/dist/generated/types/positionState.js +1 -2
  34. package/dist/generated/types/positionTokenUsage.js +1 -2
  35. package/dist/generated/types/rebalanceData.js +1 -2
  36. package/dist/generated/types/solautoAction.js +3 -4
  37. package/dist/generated/types/solautoRebalanceType.js +3 -3
  38. package/dist/generated/types/solautoSettingsParameters.js +1 -2
  39. package/dist/generated/types/solautoSettingsParametersInp.js +1 -2
  40. package/dist/generated/types/tokenAmount.js +1 -2
  41. package/dist/generated/types/tokenBalanceAmount.js +3 -4
  42. package/dist/generated/types/updatePositionData.js +1 -2
  43. package/dist/marginfi-sdk/accounts/bank.d.ts.map +1 -1
  44. package/dist/marginfi-sdk/accounts/bank.js +8 -9
  45. package/dist/marginfi-sdk/accounts/marginfiAccount.d.ts.map +1 -1
  46. package/dist/marginfi-sdk/accounts/marginfiAccount.js +8 -9
  47. package/dist/marginfi-sdk/accounts/marginfiGroup.d.ts.map +1 -1
  48. package/dist/marginfi-sdk/accounts/marginfiGroup.js +8 -9
  49. package/dist/marginfi-sdk/errors/marginfi.js +3 -3
  50. package/dist/marginfi-sdk/instructions/lendingAccountBorrow.js +2 -3
  51. package/dist/marginfi-sdk/instructions/lendingAccountCloseBalance.js +2 -3
  52. package/dist/marginfi-sdk/instructions/lendingAccountDeposit.js +2 -3
  53. package/dist/marginfi-sdk/instructions/lendingAccountEndFlashloan.js +2 -3
  54. package/dist/marginfi-sdk/instructions/lendingAccountLiquidate.js +2 -3
  55. package/dist/marginfi-sdk/instructions/lendingAccountRepay.js +2 -3
  56. package/dist/marginfi-sdk/instructions/lendingAccountSettleEmissions.js +2 -3
  57. package/dist/marginfi-sdk/instructions/lendingAccountStartFlashloan.js +2 -3
  58. package/dist/marginfi-sdk/instructions/lendingAccountWithdraw.js +2 -3
  59. package/dist/marginfi-sdk/instructions/lendingAccountWithdrawEmissions.js +2 -3
  60. package/dist/marginfi-sdk/instructions/lendingPoolAccrueBankInterest.js +2 -3
  61. package/dist/marginfi-sdk/instructions/lendingPoolAddBank.js +2 -3
  62. package/dist/marginfi-sdk/instructions/lendingPoolAddBankWithSeed.js +2 -3
  63. package/dist/marginfi-sdk/instructions/lendingPoolCollectBankFees.js +2 -3
  64. package/dist/marginfi-sdk/instructions/lendingPoolConfigureBank.js +2 -3
  65. package/dist/marginfi-sdk/instructions/lendingPoolHandleBankruptcy.js +2 -3
  66. package/dist/marginfi-sdk/instructions/lendingPoolSetupEmissions.js +2 -3
  67. package/dist/marginfi-sdk/instructions/lendingPoolUpdateEmissionsParameters.js +2 -3
  68. package/dist/marginfi-sdk/instructions/marginfiAccountInitialize.js +2 -3
  69. package/dist/marginfi-sdk/instructions/marginfiGroupConfigure.js +2 -3
  70. package/dist/marginfi-sdk/instructions/marginfiGroupInitialize.js +2 -3
  71. package/dist/marginfi-sdk/instructions/setAccountFlag.js +2 -3
  72. package/dist/marginfi-sdk/instructions/setNewAccountAuthority.js +2 -3
  73. package/dist/marginfi-sdk/instructions/unsetAccountFlag.js +2 -3
  74. package/dist/marginfi-sdk/programs/marginfi.d.ts.map +1 -1
  75. package/dist/marginfi-sdk/programs/marginfi.js +4 -4
  76. package/dist/marginfi-sdk/shared/index.js +4 -5
  77. package/dist/marginfi-sdk/types/accountEventHeader.js +1 -2
  78. package/dist/marginfi-sdk/types/balance.js +1 -2
  79. package/dist/marginfi-sdk/types/balanceDecreaseType.js +3 -3
  80. package/dist/marginfi-sdk/types/balanceIncreaseType.js +3 -3
  81. package/dist/marginfi-sdk/types/balanceSide.js +3 -3
  82. package/dist/marginfi-sdk/types/bankConfig.js +1 -2
  83. package/dist/marginfi-sdk/types/bankConfigCompact.js +1 -2
  84. package/dist/marginfi-sdk/types/bankOperationalState.js +3 -3
  85. package/dist/marginfi-sdk/types/bankVaultType.js +3 -3
  86. package/dist/marginfi-sdk/types/groupEventHeader.js +1 -2
  87. package/dist/marginfi-sdk/types/interestRateConfig.js +1 -2
  88. package/dist/marginfi-sdk/types/interestRateConfigCompact.js +1 -2
  89. package/dist/marginfi-sdk/types/interestRateConfigOpt.js +1 -2
  90. package/dist/marginfi-sdk/types/lendingAccount.js +1 -2
  91. package/dist/marginfi-sdk/types/liquidationBalances.js +1 -2
  92. package/dist/marginfi-sdk/types/oracleConfig.js +1 -2
  93. package/dist/marginfi-sdk/types/oraclePriceType.js +3 -3
  94. package/dist/marginfi-sdk/types/oracleSetup.js +3 -3
  95. package/dist/marginfi-sdk/types/priceBias.js +3 -3
  96. package/dist/marginfi-sdk/types/requirementType.js +3 -3
  97. package/dist/marginfi-sdk/types/riskRequirementType.js +3 -3
  98. package/dist/marginfi-sdk/types/riskTier.js +3 -3
  99. package/dist/marginfi-sdk/types/wrappedI80F48.js +1 -2
  100. package/dist/transactions/transactionUtils.js +4 -5
  101. package/dist/transactions/transactionsManager.d.ts.map +1 -1
  102. package/dist/transactions/transactionsManager.js +1 -1
  103. package/dist/types/solauto.js +1 -1
  104. package/dist/utils/accountUtils.d.ts +0 -1
  105. package/dist/utils/accountUtils.d.ts.map +1 -1
  106. package/dist/utils/accountUtils.js +7 -8
  107. package/dist/utils/generalUtils.js +8 -9
  108. package/dist/utils/jupiterUtils.js +1 -2
  109. package/dist/utils/marginfiUtils.js +5 -6
  110. package/dist/utils/numberUtils.js +11 -12
  111. package/dist/utils/solanaUtils.js +13 -14
  112. package/dist/utils/solauto/generalUtils.js +13 -13
  113. package/dist/utils/solauto/rebalanceUtils.js +3 -4
  114. package/package.json +3 -2
  115. package/src/clients/solautoClient.ts +1 -10
  116. package/src/clients/solautoMarginfiClient.ts +2 -0
  117. package/src/generated/instructions/marginfiOpenPosition.ts +21 -15
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUpToDateShareValues = exports.getMarginfiAccountPositionState = exports.getAllMarginfiAccountsByAuthority = exports.getMaxLtvAndLiqThreshold = exports.findMarginfiAccounts = void 0;
3
+ exports.findMarginfiAccounts = findMarginfiAccounts;
4
+ exports.getMaxLtvAndLiqThreshold = getMaxLtvAndLiqThreshold;
5
+ exports.getAllMarginfiAccountsByAuthority = getAllMarginfiAccountsByAuthority;
6
+ exports.getMarginfiAccountPositionState = getMarginfiAccountPositionState;
7
+ exports.getUpToDateShareValues = getUpToDateShareValues;
4
8
  const web3_js_1 = require("@solana/web3.js");
5
9
  const umi_1 = require("@metaplex-foundation/umi");
6
10
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
@@ -23,7 +27,6 @@ function findMarginfiAccounts({ mint, bank, }) {
23
27
  }
24
28
  throw new Error(`Marginfi accounts not found by the mint: ${mint}`);
25
29
  }
26
- exports.findMarginfiAccounts = findMarginfiAccounts;
27
30
  async function getMaxLtvAndLiqThreshold(umi, supply, debt, supplyPrice) {
28
31
  if (!supply.bank) {
29
32
  supply.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(findMarginfiAccounts({
@@ -58,7 +61,6 @@ async function getMaxLtvAndLiqThreshold(umi, supply, debt, supplyPrice) {
58
61
  }
59
62
  return [maxLtv, liqThreshold];
60
63
  }
61
- exports.getMaxLtvAndLiqThreshold = getMaxLtvAndLiqThreshold;
62
64
  async function getAllMarginfiAccountsByAuthority(umi, authority, compatibleWithSolauto) {
63
65
  const marginfiAccounts = await umi.rpc.getProgramAccounts(marginfi_sdk_1.MARGINFI_PROGRAM_ID, {
64
66
  commitment: "finalized",
@@ -97,7 +99,6 @@ async function getAllMarginfiAccountsByAuthority(umi, authority, compatibleWithS
97
99
  }));
98
100
  }
99
101
  }
100
- exports.getAllMarginfiAccountsByAuthority = getAllMarginfiAccountsByAuthority;
101
102
  async function getTokenUsage(umi, bank, isAsset, shares, amountUsedAdjustment) {
102
103
  let amountUsed = 0;
103
104
  let amountCanBeUsed = 0;
@@ -209,7 +210,6 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMin
209
210
  padding: [],
210
211
  };
211
212
  }
212
- exports.getMarginfiAccountPositionState = getMarginfiAccountPositionState;
213
213
  function marginfiInterestRateCurve(bank, utilizationRatio) {
214
214
  const optimalUr = (0, numberUtils_1.bytesToI80F48)(bank.config.interestRateConfig.optimalUtilizationRate.value);
215
215
  const plateauIr = (0, numberUtils_1.bytesToI80F48)(bank.config.interestRateConfig.plateauInterestRate.value);
@@ -253,4 +253,3 @@ async function getUpToDateShareValues(umi, bank) {
253
253
  calcAccruedInterestPaymentPerPeriod(borrowingApr, timeDelta, (0, numberUtils_1.bytesToI80F48)(bank.liabilityShareValue.value)),
254
254
  ];
255
255
  }
256
- exports.getUpToDateShareValues = getUpToDateShareValues;
@@ -1,6 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
3
+ exports.getLiqUtilzationRateBps = getLiqUtilzationRateBps;
4
+ exports.toBaseUnit = toBaseUnit;
5
+ exports.fromBaseUnit = fromBaseUnit;
6
+ exports.fromBps = fromBps;
7
+ exports.toBps = toBps;
8
+ exports.bytesToI80F48 = bytesToI80F48;
9
+ exports.uint8ArrayToBigInt = uint8ArrayToBigInt;
10
+ exports.getDebtAdjustmentUsd = getDebtAdjustmentUsd;
11
+ exports.getMaxLiqUtilizationRate = getMaxLiqUtilizationRate;
12
+ exports.maxRepayFrom = maxRepayFrom;
13
+ exports.maxRepayTo = maxRepayTo;
4
14
  const constants_1 = require("../constants");
5
15
  function getLiqUtilzationRateBps(supplyUsd, debtUsd, liqThresholdBps) {
6
16
  if (supplyUsd === 0) {
@@ -8,23 +18,18 @@ function getLiqUtilzationRateBps(supplyUsd, debtUsd, liqThresholdBps) {
8
18
  }
9
19
  return toBps(debtUsd / (supplyUsd * fromBps(liqThresholdBps)));
10
20
  }
11
- exports.getLiqUtilzationRateBps = getLiqUtilzationRateBps;
12
21
  function toBaseUnit(value, decimals) {
13
22
  return BigInt(Math.round(value * Math.pow(10, decimals)));
14
23
  }
15
- exports.toBaseUnit = toBaseUnit;
16
24
  function fromBaseUnit(value, decimals) {
17
25
  return Number(value) / Math.pow(10, decimals);
18
26
  }
19
- exports.fromBaseUnit = fromBaseUnit;
20
27
  function fromBps(value) {
21
28
  return value / 10000;
22
29
  }
23
- exports.fromBps = fromBps;
24
30
  function toBps(value) {
25
31
  return Math.round(value * 10000);
26
32
  }
27
- exports.toBps = toBps;
28
33
  function bytesToI80F48(bytes) {
29
34
  if (bytes.length !== 16) {
30
35
  throw new Error('Byte array must be exactly 16 bytes.');
@@ -41,7 +46,6 @@ function bytesToI80F48(bytes) {
41
46
  const fullValue = integerPart * BigInt(2 ** 48) + fractionalPart;
42
47
  return Number(fullValue) / (2 ** 48);
43
48
  }
44
- exports.bytesToI80F48 = bytesToI80F48;
45
49
  function uint8ArrayToBigInt(uint8Array) {
46
50
  if (uint8Array.length !== 8) {
47
51
  throw new Error('Uint8Array must be exactly 8 bytes long to convert to u64.');
@@ -52,7 +56,6 @@ function uint8ArrayToBigInt(uint8Array) {
52
56
  const high = dataView.getUint32(4, true);
53
57
  return BigInt(high) << 32n | BigInt(low);
54
58
  }
55
- exports.uint8ArrayToBigInt = uint8ArrayToBigInt;
56
59
  function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtilizationRateBps, adjustmentFeeBps) {
57
60
  const adjustmentFee = adjustmentFeeBps && adjustmentFeeBps > 0 ? fromBps(adjustmentFeeBps) : 0;
58
61
  const liqThreshold = fromBps(liqThresholdBps);
@@ -60,16 +63,12 @@ function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtil
60
63
  const debtAdjustmentUsd = (targetLiqUtilizationRate * supplyUsd * liqThreshold - debtUsd) / (1 - targetLiqUtilizationRate * (1 - adjustmentFee) * liqThreshold);
61
64
  return debtAdjustmentUsd;
62
65
  }
63
- exports.getDebtAdjustmentUsd = getDebtAdjustmentUsd;
64
66
  function getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps) {
65
67
  return toBps((fromBps(maxLtvBps) - 0.015) / fromBps(liqThresholdBps)) - 1; // -1 to account for any rounding issues
66
68
  }
67
- exports.getMaxLiqUtilizationRate = getMaxLiqUtilizationRate;
68
69
  function maxRepayFrom(maxLtvBps, liqThresholdBps) {
69
70
  return Math.min(9000, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps - 1000));
70
71
  }
71
- exports.maxRepayFrom = maxRepayFrom;
72
72
  function maxRepayTo(maxLtvBps, liqThresholdBps) {
73
73
  return Math.min(maxRepayFrom(maxLtvBps, liqThresholdBps) - constants_1.MAX_REPAY_GAP_BPS, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps));
74
74
  }
75
- exports.maxRepayTo = maxRepayTo;
@@ -3,7 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sendSingleOptimizedTransaction = exports.getComputeUnitPriceEstimate = exports.assembleFinalTransaction = exports.getAdressLookupInputs = exports.splTokenTransferUmiIx = exports.closeTokenAccountUmiIx = exports.systemTransferUmiIx = exports.createAssociatedTokenAccountUmiIx = exports.setComputeUnitPriceUmiIx = exports.setComputeUnitLimitUmiIx = exports.getWrappedInstruction = exports.currentUnixSecondsSolana = exports.getSolanaRpcConnection = void 0;
6
+ exports.getSolanaRpcConnection = getSolanaRpcConnection;
7
+ exports.currentUnixSecondsSolana = currentUnixSecondsSolana;
8
+ exports.getWrappedInstruction = getWrappedInstruction;
9
+ exports.setComputeUnitLimitUmiIx = setComputeUnitLimitUmiIx;
10
+ exports.setComputeUnitPriceUmiIx = setComputeUnitPriceUmiIx;
11
+ exports.createAssociatedTokenAccountUmiIx = createAssociatedTokenAccountUmiIx;
12
+ exports.systemTransferUmiIx = systemTransferUmiIx;
13
+ exports.closeTokenAccountUmiIx = closeTokenAccountUmiIx;
14
+ exports.splTokenTransferUmiIx = splTokenTransferUmiIx;
15
+ exports.getAdressLookupInputs = getAdressLookupInputs;
16
+ exports.assembleFinalTransaction = assembleFinalTransaction;
17
+ exports.getComputeUnitPriceEstimate = getComputeUnitPriceEstimate;
18
+ exports.sendSingleOptimizedTransaction = sendSingleOptimizedTransaction;
7
19
  const bs58_1 = __importDefault(require("bs58"));
8
20
  const umi_1 = require("@metaplex-foundation/umi");
9
21
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
@@ -19,7 +31,6 @@ function getSolanaRpcConnection(heliusApiKey) {
19
31
  const umi = (0, umi_bundle_defaults_1.createUmi)(connection);
20
32
  return [connection, umi];
21
33
  }
22
- exports.getSolanaRpcConnection = getSolanaRpcConnection;
23
34
  async function currentUnixSecondsSolana(umi) {
24
35
  return await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
25
36
  const blockTime = await umi.rpc.getBlockTime(await umi.rpc.getSlot());
@@ -29,7 +40,6 @@ async function currentUnixSecondsSolana(umi) {
29
40
  return Number(blockTime);
30
41
  });
31
42
  }
32
- exports.currentUnixSecondsSolana = currentUnixSecondsSolana;
33
43
  function getWrappedInstruction(signer, ix) {
34
44
  return {
35
45
  instruction: (0, umi_web3js_adapters_1.fromWeb3JsInstruction)(ix),
@@ -37,23 +47,19 @@ function getWrappedInstruction(signer, ix) {
37
47
  bytesCreatedOnChain: 0,
38
48
  };
39
49
  }
40
- exports.getWrappedInstruction = getWrappedInstruction;
41
50
  function setComputeUnitLimitUmiIx(signer, maxComputeUnits) {
42
51
  return getWrappedInstruction(signer, web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
43
52
  units: maxComputeUnits,
44
53
  }));
45
54
  }
46
- exports.setComputeUnitLimitUmiIx = setComputeUnitLimitUmiIx;
47
55
  function setComputeUnitPriceUmiIx(signer, lamports) {
48
56
  return getWrappedInstruction(signer, web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
49
57
  microLamports: lamports,
50
58
  }));
51
59
  }
52
- exports.setComputeUnitPriceUmiIx = setComputeUnitPriceUmiIx;
53
60
  function createAssociatedTokenAccountUmiIx(signer, wallet, mint) {
54
61
  return getWrappedInstruction(signer, (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey), (0, accountUtils_1.getTokenAccount)(wallet, mint), wallet, mint));
55
62
  }
56
- exports.createAssociatedTokenAccountUmiIx = createAssociatedTokenAccountUmiIx;
57
63
  function systemTransferUmiIx(signer, destination, lamports) {
58
64
  return getWrappedInstruction(signer, web3_js_1.SystemProgram.transfer({
59
65
  fromPubkey: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey),
@@ -61,15 +67,12 @@ function systemTransferUmiIx(signer, destination, lamports) {
61
67
  lamports,
62
68
  }));
63
69
  }
64
- exports.systemTransferUmiIx = systemTransferUmiIx;
65
70
  function closeTokenAccountUmiIx(signer, tokenAccount, authority) {
66
71
  return getWrappedInstruction(signer, (0, spl_token_1.createCloseAccountInstruction)(tokenAccount, authority, authority));
67
72
  }
68
- exports.closeTokenAccountUmiIx = closeTokenAccountUmiIx;
69
73
  function splTokenTransferUmiIx(signer, fromTa, toTa, authority, amount) {
70
74
  return getWrappedInstruction(signer, (0, spl_token_1.createTransferInstruction)(fromTa, toTa, authority, amount));
71
75
  }
72
- exports.splTokenTransferUmiIx = splTokenTransferUmiIx;
73
76
  async function getAdressLookupInputs(umi, lookupTableAddresses) {
74
77
  const addressLookupTableAccountInfos = await umi.rpc.getAccounts(lookupTableAddresses.map((key) => (0, umi_1.publicKey)(key)));
75
78
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
@@ -83,7 +86,6 @@ async function getAdressLookupInputs(umi, lookupTableAddresses) {
83
86
  return acc;
84
87
  }, new Array());
85
88
  }
86
- exports.getAdressLookupInputs = getAdressLookupInputs;
87
89
  function assembleFinalTransaction(signer, tx, computeUnitPrice, computeUnitLimit) {
88
90
  tx = tx
89
91
  .prepend(setComputeUnitPriceUmiIx(signer, computeUnitPrice))
@@ -125,7 +127,6 @@ function assembleFinalTransaction(signer, tx, computeUnitPrice, computeUnitLimit
125
127
  }
126
128
  return tx;
127
129
  }
128
- exports.assembleFinalTransaction = assembleFinalTransaction;
129
130
  async function simulateTransaction(connection, transaction) {
130
131
  const simulationResult = await connection.simulateTransaction(transaction, {
131
132
  sigVerify: false,
@@ -153,7 +154,6 @@ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting, attemptNum)
153
154
  const feeEstimate = Math.round(resp.priorityFeeEstimate);
154
155
  return feeEstimate;
155
156
  }
156
- exports.getComputeUnitPriceEstimate = getComputeUnitPriceEstimate;
157
157
  async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly, attemptNum, prioritySetting = types_1.PriorityFeeSetting.Default) {
158
158
  console.log("Sending single optimized transaction...");
159
159
  console.log("Instructions: ", tx.getInstructions().length);
@@ -179,4 +179,3 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly,
179
179
  }
180
180
  return undefined;
181
181
  }
182
- exports.sendSingleOptimizedTransaction = sendSingleOptimizedTransaction;
@@ -1,6 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LivePositionUpdates = exports.positionStateWithLatestPrices = exports.getAllPositionsByAuthority = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.eligibleForRebalance = exports.getSolautoFeesBps = exports.getAdjustedSettingsFromAutomation = exports.getUpdatedValueFromAutomation = exports.eligibleForNextAutomationPeriod = exports.nextAutomationPeriodTimestamp = void 0;
3
+ exports.LivePositionUpdates = void 0;
4
+ exports.nextAutomationPeriodTimestamp = nextAutomationPeriodTimestamp;
5
+ exports.eligibleForNextAutomationPeriod = eligibleForNextAutomationPeriod;
6
+ exports.getUpdatedValueFromAutomation = getUpdatedValueFromAutomation;
7
+ exports.getAdjustedSettingsFromAutomation = getAdjustedSettingsFromAutomation;
8
+ exports.getSolautoFeesBps = getSolautoFeesBps;
9
+ exports.eligibleForRebalance = eligibleForRebalance;
10
+ exports.eligibleForRefresh = eligibleForRefresh;
11
+ exports.getSolautoManagedPositions = getSolautoManagedPositions;
12
+ exports.getAllReferralStates = getAllReferralStates;
13
+ exports.getReferralsByUser = getReferralsByUser;
14
+ exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
15
+ exports.positionStateWithLatestPrices = positionStateWithLatestPrices;
4
16
  const umi_1 = require("@metaplex-foundation/umi");
5
17
  const generated_1 = require("../../generated");
6
18
  const generalUtils_1 = require("../generalUtils");
@@ -20,11 +32,9 @@ function nextAutomationPeriodTimestamp(automation) {
20
32
  : Number(automation.unixStartDate) +
21
33
  automation.periodsPassed * Number(automation.intervalSeconds);
22
34
  }
23
- exports.nextAutomationPeriodTimestamp = nextAutomationPeriodTimestamp;
24
35
  function eligibleForNextAutomationPeriod(automation) {
25
36
  return (0, generalUtils_1.currentUnixSeconds)() >= nextAutomationPeriodTimestamp(automation);
26
37
  }
27
- exports.eligibleForNextAutomationPeriod = eligibleForNextAutomationPeriod;
28
38
  function getUpdatedValueFromAutomation(currValue, targetValue, automation, currentUnixTimestamp) {
29
39
  const currRateDiff = currValue - targetValue;
30
40
  const progressPct = 1 /
@@ -33,7 +43,6 @@ function getUpdatedValueFromAutomation(currValue, targetValue, automation, curre
33
43
  const newValue = currValue - currRateDiff * progressPct;
34
44
  return newValue;
35
45
  }
36
- exports.getUpdatedValueFromAutomation = getUpdatedValueFromAutomation;
37
46
  function getAdjustedSettingsFromAutomation(settings, currentUnixSeconds) {
38
47
  const boostToBps = settings.automation.targetPeriods > 0 &&
39
48
  eligibleForNextAutomationPeriod(settings.automation)
@@ -44,7 +53,6 @@ function getAdjustedSettingsFromAutomation(settings, currentUnixSeconds) {
44
53
  boostToBps,
45
54
  };
46
55
  }
47
- exports.getAdjustedSettingsFromAutomation = getAdjustedSettingsFromAutomation;
48
56
  function getSolautoFeesBps(isReferred, feeType) {
49
57
  const fees = feeType === generated_1.FeeType.Small ? 100 : 500;
50
58
  let referrer = 0;
@@ -57,7 +65,6 @@ function getSolautoFeesBps(isReferred, feeType) {
57
65
  total: fees,
58
66
  };
59
67
  }
60
- exports.getSolautoFeesBps = getSolautoFeesBps;
61
68
  function eligibleForRebalance(positionState, positionSettings, positionDca) {
62
69
  if (positionDca.automation.targetPeriods > 0 &&
63
70
  eligibleForNextAutomationPeriod(positionDca.automation)) {
@@ -80,7 +87,6 @@ function eligibleForRebalance(positionState, positionSettings, positionDca) {
80
87
  }
81
88
  return undefined;
82
89
  }
83
- exports.eligibleForRebalance = eligibleForRebalance;
84
90
  function eligibleForRefresh(positionState, positionSettings) {
85
91
  if (positionSettings.automation.targetPeriods > 0) {
86
92
  return eligibleForNextAutomationPeriod(positionSettings.automation);
@@ -90,7 +96,6 @@ function eligibleForRefresh(positionState, positionSettings) {
90
96
  60 * 60 * 24 * 7);
91
97
  }
92
98
  }
93
- exports.eligibleForRefresh = eligibleForRefresh;
94
99
  async function getSolautoManagedPositions(umi, authority) {
95
100
  // bump: [u8; 1]
96
101
  // position_id: [u8; 1]
@@ -139,7 +144,6 @@ async function getSolautoManagedPositions(umi, authority) {
139
144
  };
140
145
  });
141
146
  }
142
- exports.getSolautoManagedPositions = getSolautoManagedPositions;
143
147
  async function getAllReferralStates(umi) {
144
148
  const accounts = await umi.rpc.getProgramAccounts(generated_1.SOLAUTO_PROGRAM_ID, {
145
149
  commitment: "finalized",
@@ -155,7 +159,6 @@ async function getAllReferralStates(umi) {
155
159
  });
156
160
  return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
157
161
  }
158
- exports.getAllReferralStates = getAllReferralStates;
159
162
  async function getReferralsByUser(umi, user) {
160
163
  // bump: [u8; 1],
161
164
  // padding: [u8; 7],
@@ -182,7 +185,6 @@ async function getReferralsByUser(umi, user) {
182
185
  });
183
186
  return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
184
187
  }
185
- exports.getReferralsByUser = getReferralsByUser;
186
188
  async function getAllPositionsByAuthority(umi, user) {
187
189
  const allPositions = [];
188
190
  const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
@@ -205,7 +207,6 @@ async function getAllPositionsByAuthority(umi, user) {
205
207
  // TODO support other platforms
206
208
  return allPositions;
207
209
  }
208
- exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
209
210
  async function positionStateWithLatestPrices(umi, state, protocolAccount, lendingPlatform) {
210
211
  if ((0, generalUtils_1.currentUnixSeconds)() - Number(state.lastUpdated) > 60 * 60 * 24 * 7) {
211
212
  if (lendingPlatform === generated_1.LendingPlatform.Marginfi) {
@@ -246,7 +247,6 @@ async function positionStateWithLatestPrices(umi, state, protocolAccount, lendin
246
247
  },
247
248
  };
248
249
  }
249
- exports.positionStateWithLatestPrices = positionStateWithLatestPrices;
250
250
  class LivePositionUpdates {
251
251
  constructor() {
252
252
  this.supplyAdjustment = BigInt(0);
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getJupSwapRebalanceDetails = exports.getFlashLoanDetails = exports.getRebalanceValues = void 0;
3
+ exports.getRebalanceValues = getRebalanceValues;
4
+ exports.getFlashLoanDetails = getFlashLoanDetails;
5
+ exports.getJupSwapRebalanceDetails = getJupSwapRebalanceDetails;
4
6
  const generated_1 = require("../../generated");
5
7
  const generalUtils_1 = require("./generalUtils");
6
8
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
@@ -127,7 +129,6 @@ function getRebalanceValues(client, targetLiqUtilizationRateBps, limitGapBps) {
127
129
  amountUsdToDcaIn,
128
130
  };
129
131
  }
130
- exports.getRebalanceValues = getRebalanceValues;
131
132
  function getFlashLoanDetails(client, values, jupQuote) {
132
133
  let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
133
134
  let debtUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
@@ -168,7 +169,6 @@ function getFlashLoanDetails(client, values, jupQuote) {
168
169
  }
169
170
  : undefined;
170
171
  }
171
- exports.getFlashLoanDetails = getFlashLoanDetails;
172
172
  function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps, attemptNum) {
173
173
  const input = values.increasingLeverage
174
174
  ? client.solautoPositionState.debt
@@ -196,4 +196,3 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
196
196
  exactOut: rebalancingToZero,
197
197
  };
198
198
  }
199
- exports.getJupSwapRebalanceDetails = getJupSwapRebalanceDetails;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.52",
3
+ "version": "1.0.53",
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",
@@ -32,6 +32,7 @@
32
32
  "@types/mocha": "^9.1.1",
33
33
  "chai": "^4.3.4",
34
34
  "mocha": "^9.2.2",
35
- "ts-mocha": "^10.0.0"
35
+ "ts-mocha": "^10.0.0",
36
+ "typescript": "^5.5.4"
36
37
  }
37
38
  }
@@ -419,8 +419,6 @@ export abstract class SolautoClient {
419
419
  settingParams?: SolautoSettingsParametersInpArgs,
420
420
  dca?: DCASettingsInpArgs
421
421
  ): TransactionBuilder {
422
- let tx = transactionBuilder();
423
-
424
422
  if (dca && dca.debtToAddBaseUnit > 0) {
425
423
  this.livePositionUpdates.new({
426
424
  type: "debtDcaIn",
@@ -440,14 +438,7 @@ export abstract class SolautoClient {
440
438
  });
441
439
  }
442
440
 
443
- if (!this.selfManaged) {
444
- // Tip Solauto Manager
445
- tx = tx.add(
446
- systemTransferUmiIx(this.signer, SOLAUTO_MANAGER, toBaseUnit(0.1, 9))
447
- );
448
- }
449
-
450
- return tx;
441
+ return transactionBuilder();
451
442
  }
452
443
 
453
444
  updatePositionIx(args: UpdatePositionDataArgs): TransactionBuilder {
@@ -53,6 +53,7 @@ import {
53
53
  getMarginfiAccountPositionState,
54
54
  } from "../utils/marginfiUtils";
55
55
  import { bytesToI80F48 } from "../utils/numberUtils";
56
+ import { SOLAUTO_MANAGER } from "../constants";
56
57
 
57
58
  export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
58
59
  marginfiAccount?: PublicKey | Signer;
@@ -204,6 +205,7 @@ export class SolautoMarginfiClient extends SolautoClient {
204
205
  return marginfiOpenPosition(this.umi, {
205
206
  signer: this.signer,
206
207
  marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
208
+ solautoManager: publicKey(SOLAUTO_MANAGER),
207
209
  solautoFeesWallet: publicKey(this.solautoFeesWallet),
208
210
  solautoFeesSupplyTa: publicKey(this.solautoFeesSupplyTa),
209
211
  signerReferralState: publicKey(this.authorityReferralState),
@@ -44,6 +44,7 @@ export type MarginfiOpenPositionInstructionAccounts = {
44
44
  tokenProgram?: PublicKey | Pda;
45
45
  ataProgram?: PublicKey | Pda;
46
46
  rent?: PublicKey | Pda;
47
+ solautoManager: PublicKey | Pda;
47
48
  solautoFeesWallet: PublicKey | Pda;
48
49
  solautoFeesSupplyTa: PublicKey | Pda;
49
50
  signerReferralState: PublicKey | Pda;
@@ -141,78 +142,83 @@ export function marginfiOpenPosition(
141
142
  value: input.ataProgram ?? null,
142
143
  },
143
144
  rent: { index: 5, isWritable: false as boolean, value: input.rent ?? null },
144
- solautoFeesWallet: {
145
+ solautoManager: {
145
146
  index: 6,
147
+ isWritable: true as boolean,
148
+ value: input.solautoManager ?? null,
149
+ },
150
+ solautoFeesWallet: {
151
+ index: 7,
146
152
  isWritable: false as boolean,
147
153
  value: input.solautoFeesWallet ?? null,
148
154
  },
149
155
  solautoFeesSupplyTa: {
150
- index: 7,
156
+ index: 8,
151
157
  isWritable: true as boolean,
152
158
  value: input.solautoFeesSupplyTa ?? null,
153
159
  },
154
160
  signerReferralState: {
155
- index: 8,
161
+ index: 9,
156
162
  isWritable: false as boolean,
157
163
  value: input.signerReferralState ?? null,
158
164
  },
159
165
  referredByState: {
160
- index: 9,
166
+ index: 10,
161
167
  isWritable: false as boolean,
162
168
  value: input.referredByState ?? null,
163
169
  },
164
170
  referredBySupplyTa: {
165
- index: 10,
171
+ index: 11,
166
172
  isWritable: true as boolean,
167
173
  value: input.referredBySupplyTa ?? null,
168
174
  },
169
175
  solautoPosition: {
170
- index: 11,
176
+ index: 12,
171
177
  isWritable: true as boolean,
172
178
  value: input.solautoPosition ?? null,
173
179
  },
174
180
  marginfiGroup: {
175
- index: 12,
181
+ index: 13,
176
182
  isWritable: false as boolean,
177
183
  value: input.marginfiGroup ?? null,
178
184
  },
179
185
  marginfiAccount: {
180
- index: 13,
186
+ index: 14,
181
187
  isWritable: true as boolean,
182
188
  value: input.marginfiAccount ?? null,
183
189
  },
184
190
  supplyMint: {
185
- index: 14,
191
+ index: 15,
186
192
  isWritable: false as boolean,
187
193
  value: input.supplyMint ?? null,
188
194
  },
189
195
  supplyBank: {
190
- index: 15,
196
+ index: 16,
191
197
  isWritable: false as boolean,
192
198
  value: input.supplyBank ?? null,
193
199
  },
194
200
  positionSupplyTa: {
195
- index: 16,
201
+ index: 17,
196
202
  isWritable: true as boolean,
197
203
  value: input.positionSupplyTa ?? null,
198
204
  },
199
205
  debtMint: {
200
- index: 17,
206
+ index: 18,
201
207
  isWritable: false as boolean,
202
208
  value: input.debtMint ?? null,
203
209
  },
204
210
  debtBank: {
205
- index: 18,
211
+ index: 19,
206
212
  isWritable: false as boolean,
207
213
  value: input.debtBank ?? null,
208
214
  },
209
215
  positionDebtTa: {
210
- index: 19,
216
+ index: 20,
211
217
  isWritable: true as boolean,
212
218
  value: input.positionDebtTa ?? null,
213
219
  },
214
220
  signerDebtTa: {
215
- index: 20,
221
+ index: 21,
216
222
  isWritable: true as boolean,
217
223
  value: input.signerDebtTa ?? null,
218
224
  },