@haven-fi/solauto-sdk 1.0.762 → 1.0.764

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"marginfiFlProvider.d.ts","sourceRoot":"","sources":["../../../src/services/flashLoans/marginfiFlProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAML,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAclC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAiBlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,qBAAa,kBAAmB,SAAQ,cAAc;IACpD,OAAO,CAAC,wBAAwB,CAAqB;IACrD,OAAO,CAAC,yBAAyB,CAAQ;IACzC,OAAO,CAAC,uBAAuB,CAAQ;IAEvC,OAAO,CAAC,iBAAiB,CAAe;IACxC,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,uBAAuB,CAAiB;IAChD,OAAO,CAAC,qBAAqB,CAAiB;IAExC,UAAU;YAiBF,iBAAiB;YA6CjB,sBAAsB;IAsD9B,sBAAsB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAyC3D,gBAAgB,IAAI,SAAS,EAAE;IAY/B,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS;IAI7C,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,WAAW;IAMnB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAI7C,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM;IAc9D,WAAW,CACT,SAAS,EAAE,gBAAgB,EAC3B,gBAAgB,EAAE,SAAS,GAC1B,kBAAkB;IAoCrB,UAAU,CAAC,SAAS,EAAE,g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BAAkB;IAgD3D,YAAY,CACV,eAAe,EAAE,SAAS,EAC1B,IAAI,EAAE,SAAS,EACf,aAAa,EAAE,SAAS;CAW3B"}
@@ -198,7 +198,7 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
198
198
  .add((0, marginfi_1.lendingAccountEndFlashloan)(this.umi, {
199
199
  marginfiAccount: (0, umi_1.publicKey)(iMfiAccount.accountPk),
200
200
  signer: this.signer,
201
- }).addRemainingAccounts(remainingAccounts));
201
+ }).addRemainingAccounts((0, utils_1.composeRemainingAccounts)(remainingAccounts)));
202
202
  }
203
203
  closeBalance(marginfiAccount, bank, marginfiGroup) {
204
204
  return (0, umi_1.transactionBuilder)().add((0, marginfi_1.lendingAccountCloseBalance)(this.umi, {
@@ -1 +1 @@
1
- {"version":3,"file":"rebalanceSwapManager.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceSwapManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAkB,UAAU,EAAa,MAAM,SAAS,CAAC;AAChE,OAAO,EAA0B,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAiC,MAAM,iBAAiB,CAAC;AAY3E,qBAAa,oBAAoB;IAS7B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,SAAS,CAAC;IAZb,UAAU,EAAG,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,aAAa,CAAU;gBAGrB,MAAM,EAAE,a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,EAAE,SAAS,YAAA;IAU/B,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;IAsCnB,OAAO,CAAC,kCAAkC;YAwD5B,mBAAmB;IA4CjC,OAAO,CAAC,mBAAmB;IAIrB,aAAa,CAAC,UAAU,EAAE,MAAM;IAuEhC,aAAa;;;;;;CAWpB"}
@@ -74,19 +74,6 @@ class RebalanceSwapManager {
74
74
  flashLoan: this.flRequirements?.flFeeBps ?? 0,
75
75
  lpBorrow: this.client.pos.state.debt.borrowFeeBps,
76
76
  });
77
- // if (isMarginfiPosition(this.client.pos)) {
78
- // console.log(res.newPos.supplyUsd, res.newPos.debtUsd);
79
- // console.log(
80
- // res.newPos.supplyUsd *
81
- // bytesToI80F48(
82
- // this.client.pos.supplyBank!.config.assetWeightInit.value
83
- // ),
84
- // res.newPos.debtUsd *
85
- // bytesToI80F48(
86
- // this.client.pos.debtBank!.config.liabilityWeightInit.value
87
- // )
88
- // );
89
- // }
90
77
  return (0, utils_1.getLiqUtilzationRateBps)(res.newPos.supplyUsd, res.newPos.debtUsd, this.client.pos.state.liqThresholdBps ?? 0);
91
78
  }
92
79
  async findSufficientQuote(swapInput, criteria) {
@@ -18,7 +18,7 @@ class RebalanceTxBuilder {
18
18
  this.priceType = generated_1.PriceType.Realtime;
19
19
  }
20
20
  shouldProceedWithRebalance() {
21
- if (this.client.pos.selfManaged && !this.targetLiqUtilizationRateBps) {
21
+ if (this.client.pos.selfManaged && this.targetLiqUtilizationRateBps === undefined) {
22
22
  throw new Error("A target rate must be provided for self managed position rebalances");
23
23
  }
24
24
  return (this.client.pos.supplyUsd() > 0 &&
@@ -1 +1 @@
1
- {"version":3,"file":"solautoFees.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/solautoFees.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,qBAAa,cAAc;IAEvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,2BAA2B;IACnC,OAAO,CAAC,mBAAmB;gBAFnB,UAAU,EAAE,OAAO,EACnB,2BAA2B,EAAE,MAAM,GAAG,SAAS,EAC/C,mBAAmB,EAAE,MAAM;IAGrC,MAAM,CAAC,MAAM,CACX,UAAU,EAAE,OAAO,EACnB,2BAA2B,EAAE,MAAM,GAAG,SAAS,EAC/C,WAAW,EAAE,MAAM;IASrB,iBAAiB,CAAC,kBAAkB,EAAE,kBAAkB;;;;;CAqCzD"}
1
+ {"version":3,"file":"solautoFees.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/solautoFees.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,qBAAa,cAAc;IAEvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,2BAA2B;IACnC,OAAO,CAAC,mBAAmB;gBAFnB,UAAU,EAAE,OAAO,EACnB,2BAA2B,EAAE,MAAM,GAAG,SAAS,EAC/C,mBAAmB,EAAE,MAAM;IAGrC,MAAM,CAAC,MAAM,CACX,UAAU,EAAE,OAAO,EACnB,2BAA2B,EAAE,MAAM,GAAG,SAAS,EAC/C,WAAW,EAAE,MAAM;IASrB,iBAAiB,CAAC,kBAAkB,EAAE,kBAAkB;;;;;CAyCzD"}
@@ -20,7 +20,12 @@ class SolautoFeesBps {
20
20
  const k = 1.5;
21
21
  let feeBps = 0;
22
22
  if (this.targetLiqUtilizationRateBps !== undefined) {
23
- feeBps = 10;
23
+ if (this.targetLiqUtilizationRateBps === 0) {
24
+ feeBps = 15;
25
+ }
26
+ else {
27
+ feeBps = 10;
28
+ }
24
29
  }
25
30
  else if (rebalanceDirection === generated_1.RebalanceDirection.Repay) {
26
31
  feeBps = 25;
@@ -9,7 +9,7 @@ export declare class SolautoMarginfiClient extends SolautoClient {
9
9
  mfiAccounts: MarginfiProgramAccounts;
10
10
  marginfiAccount: PublicKey | Signer;
11
11
  marginfiAccountPk: PublicKey;
12
- healthCheckRemainingAccounts?: AccountMeta[];
12
+ healthCheckRemainingAccounts: AccountMeta[];
13
13
  marginfiGroup: PublicKey;
14
14
  marginfiSupplyAccounts: MarginfiAssetAccounts;
15
15
  marginfiDebtAccounts: MarginfiAssetAccounts;
@@ -1 +1 @@
1
- {"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/solautoMarginfiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EACL,MAAM,EACN,kBAAkB,EAIlB,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAuB,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,eAAe,EAEf,SAAS,EAET,aAAa,EACb,iBAAiB,EAEjB,gCAAgC,EAOjC,MAAM,iBAAiB,CAAC;AAmBzB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAMnE,qBAAa,qBAAsB,SAAQ,aAAa;IAC/C,eAAe,kBAA4B;IAE3C,WAAW,EAAG,uBAAuB,CAAC;IAEtC,eAAe,EAAG,SAAS,GAAG,MAAM,CAAC;IACrC,iBAAiB,EAAG,SAAS,CAAC;IAC9B,4BAA4B,CAAC,EAAE,WAAW,EAAE,CAAC;IAC7C,aAAa,EAAG,SAAS,CAAC;IAE1B,sBAAsB,EAAG,qBAAqB,CAAC;IAC/C,oBAAoB,EAAG,qBAAqB,CAAC;IAE7C,iBAAiB,EAAG,SAAS,CAAC;IAC9B,eAAe,EAAG,SAAS,CAAC;IAE7B,UAAU,CAAC,IAAI,EAAE,iBAAiB;IA6ExC,mBAAmB,IAAI,MAAM,EAAE;IAO/B,gBAAgB,IAAI,SAAS,EAAE;IAI/B,yBAAyB,CAAC,eAAe,EAAE,MAAM,GAA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oBAAoB,EAAG,qBAAqB,CAAC;IAE7C,iBAAiB,EAAG,SAAS,CAAC;IAC9B,eAAe,EAAG,SAAS,CAAC;IAE7B,UAAU,CAAC,IAAI,EAAE,iBAAiB;IA8ExC,mBAAmB,IAAI,MAAM,EAAE;IAO/B,gBAAgB,IAAI,SAAS,EAAE;IAI/B,yBAAyB,CAAC,eAAe,EAAE,MAAM,GAAG,kBAAkB;IAStE,cAAc,CACZ,QAAQ,CAAC,EAAE,gCAAgC,EAC3C,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA0C9B,eAAe,IAAI,kBAAkB;IAYrC,SAAS,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,kBAAkB;IAepD,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUlE,OAAO,CAAC,6BAA6B;IAiGrC,OAAO,CAAC,oCAAoC;IA0D5C,WAAW,CACT,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,gBAAgB,GACrB,kBAAkB;CA4EtB"}
@@ -21,6 +21,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
21
21
  await super.initialize(args);
22
22
  this.mfiAccounts = (0, constants_1.getMarginfiAccounts)(this.lpEnv);
23
23
  this.marginfiGroup = this.pos.lpPoolAccount;
24
+ this.healthCheckRemainingAccounts = [];
24
25
  if (this.pos.selfManaged) {
25
26
  this.marginfiAccount =
26
27
  args.lpUserAccount ??
@@ -155,6 +156,14 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
155
156
  marginfiProtocolInteractionIx(args) {
156
157
  switch (args.__kind) {
157
158
  case "Deposit": {
159
+ if (!this.healthCheckRemainingAccounts
160
+ .map((x) => x.pubkey.toString())
161
+ .includes(this.marginfiSupplyAccounts.bank)) {
162
+ this.healthCheckRemainingAccounts.push(...[
163
+ (0, utils_1.getAccountMeta)(new web3_js_1.PublicKey(this.marginfiSupplyAccounts.bank)),
164
+ (0, utils_1.getAccountMeta)(this.supplyPriceOracle),
165
+ ]);
166
+ }
158
167
  return (0, marginfi_1.lendingAccountDeposit)(this.umi, {
159
168
  signer: this.signer,
160
169
  signerTokenAccount: (0, umi_1.publicKey)(this.signerSupplyTa),
@@ -167,7 +176,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
167
176
  });
168
177
  }
169
178
  case "Borrow": {
170
- const remainingAccounts = this.healthCheckRemainingAccounts ?? [];
179
+ const remainingAccounts = this.healthCheckRemainingAccounts;
171
180
  if (!remainingAccounts.find((x) => x.pubkey.toString() === this.marginfiDebtAccounts.bank.toString())) {
172
181
  remainingAccounts.push(...[
173
182
  (0, utils_1.getAccountMeta)(new web3_js_1.PublicKey(this.marginfiDebtAccounts.bank)),
@@ -183,7 +192,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
183
192
  bank: (0, umi_1.publicKey)(this.marginfiDebtAccounts.bank),
184
193
  bankLiquidityVault: (0, umi_1.publicKey)(this.marginfiDebtAccounts.liquidityVault),
185
194
  bankLiquidityVaultAuthority: (0, umi_1.publicKey)(this.marginfiDebtAccounts.vaultAuthority),
186
- }).addRemainingAccounts(remainingAccounts);
195
+ }).addRemainingAccounts((0, utils_1.composeRemainingAccounts)(remainingAccounts));
187
196
  }
188
197
  case "Repay": {
189
198
  return (0, marginfi_1.lendingAccountRepay)(this.umi, {
@@ -208,7 +217,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
208
217
  bank: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.bank),
209
218
  bankLiquidityVault: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.liquidityVault),
210
219
  bankLiquidityVaultAuthority: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.vaultAuthority),
211
- }).addRemainingAccounts(this.healthCheckRemainingAccounts ?? []);
220
+ }).addRemainingAccounts((0, utils_1.composeRemainingAccounts)(this.healthCheckRemainingAccounts));
212
221
  }
213
222
  }
214
223
  }
@@ -79,7 +79,7 @@ class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
79
79
  get supplyUsdWithdrawable() {
80
80
  const deposits = (0, utils_1.fromBaseUnit)((0, utils_1.getBankLiquidityUsedBaseUnit)(this.supplyBank, true), this.supplyMintInfo.decimals);
81
81
  const borrows = (0, utils_1.fromBaseUnit)((0, utils_1.getBankLiquidityUsedBaseUnit)(this.supplyBank, false), this.supplyMintInfo.decimals);
82
- return Math.min((deposits - borrows), this.totalSupply) * this.supplyPrice();
82
+ return Math.min(deposits - borrows, this.totalSupply) * this.supplyPrice();
83
83
  }
84
84
  async refreshPositionState(priceType) {
85
85
  if (!this.canRefreshPositionState()) {
@@ -188,7 +188,7 @@ async function sendJitoBundledTransactions(umi, connection, userSigner, otherSig
188
188
  (0, generalUtils_1.consoleLog)("Transactions: ", txs.length);
189
189
  (0, generalUtils_1.consoleLog)(txs.map((tx) => tx.getInstructions().map((x) => x.programId.toString())));
190
190
  (0, generalUtils_1.consoleLog)("Transaction sizes: ", txs.map((x) => x.getTransactionSize(umi)));
191
- txs[0] = txs[0].prepend(getTipInstruction(userSigner, 150000));
191
+ txs[0] = txs[0].prepend(getTipInstruction(userSigner, 250000));
192
192
  const latestBlockhash = (await umi.rpc.getLatestBlockhash({ commitment: "confirmed" })).blockhash;
193
193
  if (abortController?.signal.aborted) {
194
194
  return;
@@ -23,5 +23,6 @@ export declare function findMarginfiAccounts(bank: PublicKey): AllMarginfiAssetA
23
23
  export declare function getRemainingAccountsForMarginfiHealthCheck(umi: Umi, balance: Balance): Promise<AccountMeta[]>;
24
24
  export declare function calcMarginfiMaxLtvAndLiqThresholdBps(supplyBank: Bank, debtBank: Bank, supplyPrice: number): [number, number];
25
25
  export declare function marginfiAccountEmpty(marginfiAccount: MarginfiAccount): boolean;
26
+ export declare function composeRemainingAccounts(accs: AccountMeta[]): AccountMeta[];
26
27
  export {};
27
28
  //# sourceMappingURL=general.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"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WxB;AAED,wBAAgB,oCAAoC,CAClD,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,WAAW,EAAE,MAAM,GAClB,CAAC,MAAM,EAAE,MAAM,CAAC,CA6BlB;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,WASpE;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAW3E"}
@@ -9,6 +9,7 @@ exports.findMarginfiAccounts = findMarginfiAccounts;
9
9
  exports.getRemainingAccountsForMarginfiHealthCheck = getRemainingAccountsForMarginfiHealthCheck;
10
10
  exports.calcMarginfiMaxLtvAndLiqThresholdBps = calcMarginfiMaxLtvAndLiqThresholdBps;
11
11
  exports.marginfiAccountEmpty = marginfiAccountEmpty;
12
+ exports.composeRemainingAccounts = composeRemainingAccounts;
12
13
  const web3_js_1 = require("@solana/web3.js");
13
14
  const umi_1 = require("@metaplex-foundation/umi");
14
15
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
@@ -144,3 +145,9 @@ function marginfiAccountEmpty(marginfiAccount) {
144
145
  ((0, numberUtils_1.bytesToI80F48)(x.assetShares.value) > 0.000001 ||
145
146
  (0, numberUtils_1.bytesToI80F48)(x.liabilityShares.value) > 0.000001)) === undefined);
146
147
  }
148
+ function composeRemainingAccounts(accs) {
149
+ const banksAndOracles = accs.reduce((acc, _, i) => i % 2 === 0 ? [...acc, [accs[i], accs[i + 1]]] : acc, []);
150
+ return banksAndOracles
151
+ .sort((a, b) => b[0].pubkey.toString().localeCompare(a[0].pubkey.toString()))
152
+ .flat();
153
+ }
@@ -2,18 +2,14 @@ import { Keypair, PublicKey } from "@solana/web3.js";
2
2
  import { createSignerFromKeypair, publicKey } from "@metaplex-foundation/umi";
3
3
  import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
4
4
  import {
5
- bytesToI80F48,
6
5
  ClientTransactionsManager,
7
6
  consoleLog,
8
- fetchBank,
9
- fetchMarginfiAccount,
10
7
  getBatches,
11
8
  getClient,
12
9
  getPositionExBulk,
13
10
  getSolanaRpcConnection,
14
11
  getSolautoManagedPositions,
15
12
  LendingPlatform,
16
- lendingPoolAccrueBankInterest,
17
13
  LOCAL_IRONFORGE_API_URL,
18
14
  PriceType,
19
15
  PriorityFeeSetting,
@@ -25,7 +21,6 @@ import {
25
21
  TransactionItem,
26
22
  } from "../src";
27
23
  import { getSecretKey } from "./shared";
28
- import { fromBaseUnit } from "../dist";
29
24
 
30
25
  const payForTransaction = true;
31
26
  const testProgram = false;
@@ -53,22 +48,13 @@ export async function main() {
53
48
 
54
49
  await client.initializeExistingSolautoPosition({
55
50
  positionId: 1,
56
- authority: new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"),
51
+ authority: new PublicKey("7TfyMCk8WD7FwscRyZJeyw9CRPxcgSKpz9tmhMGvyuRz"),
57
52
  // lpUserAccount: new PublicKey(
58
53
  // "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
59
54
  // ),
60
55
  });
61
56
 
62
- const transactionItems = [
63
- new TransactionItem(async () => ({
64
- tx: lendingPoolAccrueBankInterest(umi, {
65
- marginfiGroup: publicKey(
66
- "DQ2jqDJw9uzTwttf6h6r217BQ7kws3jZbJXDkfbCJa1q"
67
- ),
68
- bank: publicKey("EXrnNVfLagt3j4hCHSD9WqK75o6dkZBtjpnrSrSC78MA"),
69
- }),
70
- })),
71
- ];
57
+ const transactionItems = [rebalance(client)];
72
58
 
73
59
  const txManager = new ClientTransactionsManager({
74
60
  txHandler: client,
@@ -78,34 +64,6 @@ export async function main() {
78
64
  });
79
65
  const statuses = await txManager.send(transactionItems);
80
66
  consoleLog(statuses);
81
-
82
- await new Promise((resolve) => setTimeout(resolve, 5000));
83
-
84
- const mfiAccount = await fetchMarginfiAccount(
85
- umi,
86
- publicKey("Fun9UD87tLCxqxoTvpGYAy6Uwk2eevFGDk1VvxpXbd5x")
87
- );
88
- const bank = await fetchBank(
89
- umi,
90
- publicKey("EXrnNVfLagt3j4hCHSD9WqK75o6dkZBtjpnrSrSC78MA"),
91
- { commitment: "confirmed" }
92
- );
93
-
94
- console.log(
95
- fromBaseUnit(
96
- BigInt(
97
- Math.round(
98
- bytesToI80F48(
99
- mfiAccount.lendingAccount.balances[0].assetShares.value
100
- ) * bytesToI80F48(bank.assetShareValue.value)
101
- )
102
- ),
103
- 6
104
- )
105
- );
106
- // 1:34pm - $4479.61
107
- // 2:51pm - $4513.30
108
- // 12:58pm - $4529.16
109
67
  }
110
68
 
111
69
  async function refreshAll() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.762",
3
+ "version": "1.0.764",
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",
@@ -23,6 +23,7 @@ import {
23
23
  import { FlProviderBase } from "./flProviderBase";
24
24
  import {
25
25
  bytesToI80F48,
26
+ composeRemainingAccounts,
26
27
  consoleLog,
27
28
  fetchTokenPrices,
28
29
  findMarginfiAccounts,
@@ -342,7 +343,7 @@ export class MarginfiFlProvider extends FlProviderBase {
342
343
  lendingAccountEndFlashloan(this.umi, {
343
344
  marginfiAccount: publicKey(iMfiAccount.accountPk),
344
345
  signer: this.signer,
345
- }).addRemainingAccounts(remainingAccounts)
346
+ }).addRemainingAccounts(composeRemainingAccounts(remainingAccounts))
346
347
  );
347
348
  }
348
349
 
@@ -134,20 +134,6 @@ export class RebalanceSwapManager {
134
134
  }
135
135
  );
136
136
 
137
- // if (isMarginfiPosition(this.client.pos)) {
138
- // console.log(res.newPos.supplyUsd, res.newPos.debtUsd);
139
- // console.log(
140
- // res.newPos.supplyUsd *
141
- // bytesToI80F48(
142
- // this.client.pos.supplyBank!.config.assetWeightInit.value
143
- // ),
144
- // res.newPos.debtUsd *
145
- // bytesToI80F48(
146
- // this.client.pos.debtBank!.config.liabilityWeightInit.value
147
- // )
148
- // );
149
- // }
150
-
151
137
  return getLiqUtilzationRateBps(
152
138
  res.newPos.supplyUsd,
153
139
  res.newPos.debtUsd,
@@ -53,7 +53,7 @@ export class RebalanceTxBuilder {
53
53
  ) {}
54
54
 
55
55
  private shouldProceedWithRebalance() {
56
- if (this.client.pos.selfManaged && !this.targetLiqUtilizationRateBps) {
56
+ if (this.client.pos.selfManaged && this.targetLiqUtilizationRateBps === undefined) {
57
57
  throw new Error(
58
58
  "A target rate must be provided for self managed position rebalances"
59
59
  );
@@ -29,7 +29,11 @@ export class SolautoFeesBps {
29
29
 
30
30
  let feeBps: number = 0;
31
31
  if (this.targetLiqUtilizationRateBps !== undefined) {
32
- feeBps = 10;
32
+ if (this.targetLiqUtilizationRateBps === 0) {
33
+ feeBps = 15;
34
+ } else {
35
+ feeBps = 10;
36
+ }
33
37
  } else if (rebalanceDirection === RebalanceDirection.Repay) {
34
38
  feeBps = 25;
35
39
  } else if (this.positionNetWorthUsd <= minSize) {
@@ -37,6 +37,7 @@ import {
37
37
  hasFirstRebalance,
38
38
  getRemainingAccountsForMarginfiHealthCheck,
39
39
  getAccountMeta,
40
+ composeRemainingAccounts,
40
41
  } from "../../utils";
41
42
  import {
42
43
  Bank,
@@ -61,7 +62,7 @@ export class SolautoMarginfiClient extends SolautoClient {
61
62
 
62
63
  public marginfiAccount!: PublicKey | Signer;
63
64
  public marginfiAccountPk!: PublicKey;
64
- public healthCheckRemainingAccounts?: AccountMeta[];
65
+ public healthCheckRemainingAccounts!: AccountMeta[];
65
66
  public marginfiGroup!: PublicKey;
66
67
 
67
68
  public marginfiSupplyAccounts!: MarginfiAssetAccounts;
@@ -76,6 +77,7 @@ export class SolautoMarginfiClient extends SolautoClient {
76
77
  this.mfiAccounts = getMarginfiAccounts(this.lpEnv);
77
78
 
78
79
  this.marginfiGroup = this.pos.lpPoolAccount;
80
+ this.healthCheckRemainingAccounts = [];
79
81
 
80
82
  if (this.pos.selfManaged) {
81
83
  this.marginfiAccount =
@@ -258,6 +260,18 @@ export class SolautoMarginfiClient extends SolautoClient {
258
260
  private marginfiProtocolInteractionIx(args: SolautoActionArgs) {
259
261
  switch (args.__kind) {
260
262
  case "Deposit": {
263
+ if (
264
+ !this.healthCheckRemainingAccounts
265
+ .map((x) => x.pubkey.toString())
266
+ .includes(this.marginfiSupplyAccounts.bank)
267
+ ) {
268
+ this.healthCheckRemainingAccounts.push(
269
+ ...[
270
+ getAccountMeta(new PublicKey(this.marginfiSupplyAccounts.bank)),
271
+ getAccountMeta(this.supplyPriceOracle),
272
+ ]
273
+ );
274
+ }
261
275
  return lendingAccountDeposit(this.umi, {
262
276
  signer: this.signer,
263
277
  signerTokenAccount: publicKey(this.signerSupplyTa),
@@ -272,7 +286,7 @@ export class SolautoMarginfiClient extends SolautoClient {
272
286
  });
273
287
  }
274
288
  case "Borrow": {
275
- const remainingAccounts = this.healthCheckRemainingAccounts ?? [];
289
+ const remainingAccounts = this.healthCheckRemainingAccounts;
276
290
  if (
277
291
  !remainingAccounts.find(
278
292
  (x) =>
@@ -286,6 +300,7 @@ export class SolautoMarginfiClient extends SolautoClient {
286
300
  ]
287
301
  );
288
302
  }
303
+
289
304
  return lendingAccountBorrow(this.umi, {
290
305
  amount: args.fields[0],
291
306
  signer: this.signer,
@@ -299,7 +314,7 @@ export class SolautoMarginfiClient extends SolautoClient {
299
314
  bankLiquidityVaultAuthority: publicKey(
300
315
  this.marginfiDebtAccounts.vaultAuthority
301
316
  ),
302
- }).addRemainingAccounts(remainingAccounts);
317
+ }).addRemainingAccounts(composeRemainingAccounts(remainingAccounts));
303
318
  }
304
319
  case "Repay": {
305
320
  return lendingAccountRepay(this.umi, {
@@ -332,7 +347,9 @@ export class SolautoMarginfiClient extends SolautoClient {
332
347
  bankLiquidityVaultAuthority: publicKey(
333
348
  this.marginfiSupplyAccounts.vaultAuthority
334
349
  ),
335
- }).addRemainingAccounts(this.healthCheckRemainingAccounts ?? []);
350
+ }).addRemainingAccounts(
351
+ composeRemainingAccounts(this.healthCheckRemainingAccounts)
352
+ );
336
353
  }
337
354
  }
338
355
  }
@@ -138,7 +138,7 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
138
138
  getBankLiquidityUsedBaseUnit(this.supplyBank, false),
139
139
  this.supplyMintInfo.decimals
140
140
  );
141
- return Math.min((deposits - borrows), this.totalSupply) * this.supplyPrice()!;
141
+ return Math.min(deposits - borrows, this.totalSupply) * this.supplyPrice()!;
142
142
  }
143
143
 
144
144
  async refreshPositionState(priceType?: PriceType): Promise<void> {
@@ -301,7 +301,7 @@ export async function sendJitoBundledTransactions(
301
301
  txs.map((x) => x.getTransactionSize(umi))
302
302
  );
303
303
 
304
- txs[0] = txs[0].prepend(getTipInstruction(userSigner, 150_000));
304
+ txs[0] = txs[0].prepend(getTipInstruction(userSigner, 250_000));
305
305
 
306
306
  const latestBlockhash = (
307
307
  await umi.rpc.getLatestBlockhash({ commitment: "confirmed" })
@@ -224,3 +224,16 @@ export function marginfiAccountEmpty(marginfiAccount: MarginfiAccount) {
224
224
  ) === undefined
225
225
  );
226
226
  }
227
+
228
+ export function composeRemainingAccounts(accs: AccountMeta[]): AccountMeta[] {
229
+ const banksAndOracles: [AccountMeta, AccountMeta][] = accs.reduce(
230
+ (acc: [AccountMeta, AccountMeta][], _, i) =>
231
+ i % 2 === 0 ? [...acc, [accs[i], accs[i + 1]]] : acc,
232
+ []
233
+ );
234
+ return banksAndOracles
235
+ .sort((a, b) =>
236
+ b[0].pubkey.toString().localeCompare(a[0].pubkey.toString())
237
+ )
238
+ .flat();
239
+ }
@@ -22,6 +22,7 @@ import {
22
22
  closeSolautoPosition,
23
23
  getMarginfiAccounts,
24
24
  ClientTransactionsManager,
25
+ ProgramEnv,
25
26
  } from "../../src";
26
27
 
27
28
  export async function e2eTransactionTest(
@@ -29,13 +30,15 @@ export async function e2eTransactionTest(
29
30
  testProgram: boolean,
30
31
  lendingPlatform: LendingPlatform,
31
32
  withFlashLoan: boolean,
32
- showLogs?: boolean
33
+ showLogs?: boolean,
34
+ lpEnv?: ProgramEnv
33
35
  ) {
34
36
  const client = getClient(lendingPlatform, {
35
37
  signer,
36
38
  showLogs,
37
39
  rpcUrl: LOCAL_IRONFORGE_API_URL,
38
40
  programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
41
+ lpEnv,
39
42
  });
40
43
 
41
44
  const supplyMint = new PublicKey(NATIVE_MINT);
@@ -43,7 +46,7 @@ export async function e2eTransactionTest(
43
46
 
44
47
  await client.initializeNewSolautoPosition({
45
48
  positionId: 1,
46
- lpPoolAccount: getMarginfiAccounts().defaultGroup,
49
+ lpPoolAccount: getMarginfiAccounts(lpEnv).defaultGroup,
47
50
  supplyMint,
48
51
  debtMint,
49
52
  });
@@ -1,11 +1,13 @@
1
1
  import { describe, it } from "mocha";
2
- import { LendingPlatform } from "../../src";
2
+ import { LendingPlatform, ProgramEnv } from "../../src";
3
3
  import { setupTest } from "../shared";
4
4
  import { e2eTransactionTest } from "./shared";
5
5
 
6
6
  describe("Solauto Marginfi tests", async () => {
7
7
  const signer = setupTest();
8
8
  const testProgram = false;
9
+ const showLogs = false;
10
+ const lpEnv: ProgramEnv = "Prod";
9
11
 
10
12
  it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
11
13
  await e2eTransactionTest(
@@ -13,7 +15,8 @@ describe("Solauto Marginfi tests", async () => {
13
15
  testProgram,
14
16
  LendingPlatform.Marginfi,
15
17
  false,
16
- false
18
+ showLogs,
19
+ lpEnv
17
20
  );
18
21
  });
19
22
 
@@ -23,7 +26,8 @@ describe("Solauto Marginfi tests", async () => {
23
26
  testProgram,
24
27
  LendingPlatform.Marginfi,
25
28
  true,
26
- false
29
+ showLogs,
30
+ lpEnv
27
31
  );
28
32
  });
29
33
  });