@haven-fi/solauto-sdk 1.0.699 → 1.0.700

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":"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,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAiC,MAAM,iBAAiB,CAAC;AAU3E,qBAAa,oBAAoB;IAQ7B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,SAAS,CAAC;IAXb,UAAU,EAAG,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,cAAc,CAAkB;gBAG9B,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,cAAc,CAAC,EAAE,qBAAqB,YAAA,EACtC,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,SAAS,CAAC,EAAE,SAAS,YAAA;IAK/B,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;IA6BnB,OAAO,CAAC,kCAAkC;YA4B5B,mBAAmB;IAoCjC,OAAO,CAAC,mBAAmB;IAIrB,aAAa,CAAC,UAAU,EAAE,MAAM;IAyEhC,aAAa;;;;;;CAWpB"}
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,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAiC,MAAM,iBAAiB,CAAC;AAU3E,qBAAa,oBAAoB;IAQ7B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,SAAS,CAAC;IAXb,UAAU,EAAG,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,cAAc,CAAkB;gBAG9B,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,cAAc,CAAC,EAAE,qBAAqB,YAAA,EACtC,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,SAAS,CAAC,EAAE,SAAS,YAAA;IAK/B,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;IAyCnB,OAAO,CAAC,kCAAkC;YAqC5B,mBAAmB;IA2CjC,OAAO,CAAC,mBAAmB;IAIrB,aAAa,CAAC,UAAU,EAAE,MAAM;IAyEhC,aAAa;;;;;;CAWpB"}
@@ -27,53 +27,66 @@ class RebalanceSwapManager {
27
27
  const output = this.isBoost()
28
28
  ? this.client.pos.state.supply
29
29
  : this.client.pos.state.debt;
30
- // const supplyPrice = this.client.pos.supplyPrice(this.priceType)!;
31
- // const debtPrice = this.client.pos.debtPrice(this.priceType)!;
32
- // const inputPrice = this.isBoost() ? debtPrice : supplyPrice;
33
- // const outputPrice = this.isBoost() ? supplyPrice : debtPrice;
34
- const inputPrice = (0, utils_1.safeGetPrice)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint), this.priceType);
35
- const outputPrice = (0, utils_1.safeGetPrice)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint), this.priceType);
30
+ // const inputPrice = safeGetPrice(
31
+ // toWeb3JsPublicKey(input.mint),
32
+ // this.priceType
33
+ // )!;
34
+ // const outputPrice = safeGetPrice(
35
+ // toWeb3JsPublicKey(output.mint),
36
+ // this.priceType
37
+ // )!;
38
+ const supplyPrice = this.client.pos.supplyPrice(this.priceType);
39
+ const debtPrice = this.client.pos.debtPrice(this.priceType);
40
+ const biasedInputPrice = this.isBoost() ? debtPrice : supplyPrice;
41
+ const biasedOutputPrice = this.isBoost() ? supplyPrice : debtPrice;
42
+ const inputPrice = biasedInputPrice;
43
+ const outputPrice = biasedOutputPrice;
36
44
  let inputAmount = (0, utils_1.toBaseUnit)(this.usdToSwap() / inputPrice, input.decimals);
37
45
  return {
38
46
  inputAmount,
39
47
  input,
40
48
  inputPrice,
49
+ biasedInputPrice,
41
50
  output,
42
51
  outputPrice,
52
+ biasedOutputPrice,
43
53
  };
44
54
  }
45
- postRebalanceLiqUtilizationRateBps(swapOutputAmount) {
55
+ postRebalanceLiqUtilizationRateBps(swapOutputAmount, swapInputAmount) {
46
56
  let supplyUsd = this.client.pos.supplyUsd(this.priceType);
47
57
  let debtUsd = this.client.pos.debtUsd(this.priceType);
48
58
  // TODO: add token balance change
49
- const { output, outputPrice } = this.swapDetails();
59
+ const { input, biasedInputPrice, output, biasedOutputPrice } = this.swapDetails();
60
+ const swapInputUsd = swapInputAmount
61
+ ? (0, utils_1.fromBaseUnit)(swapInputAmount, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint)).decimals) * biasedInputPrice
62
+ : this.usdToSwap();
50
63
  const swapOutputUsd = swapOutputAmount
51
- ? (0, utils_1.fromBaseUnit)(swapOutputAmount, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint)).decimals) * outputPrice
64
+ ? (0, utils_1.fromBaseUnit)(swapOutputAmount, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint)).decimals) * biasedOutputPrice
52
65
  : this.usdToSwap();
53
66
  supplyUsd = this.isBoost()
54
67
  ? supplyUsd + swapOutputUsd
55
- : supplyUsd - this.usdToSwap();
56
- debtUsd = this.isBoost()
57
- ? debtUsd + this.usdToSwap()
58
- : debtUsd - swapOutputUsd;
68
+ : supplyUsd - swapInputUsd;
69
+ debtUsd = this.isBoost() ? debtUsd + swapInputUsd : debtUsd - swapOutputUsd;
59
70
  return (0, utils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, this.client.pos.state.liqThresholdBps ?? 0);
60
71
  }
61
72
  async findSufficientQuote(swapInput, criteria) {
62
73
  let swapQuote;
63
74
  let insufficient = false;
64
- for (let i = 0; i < 10; i++) {
75
+ for (let i = 0; i < 20; i++) {
65
76
  (0, utils_1.consoleLog)("Finding sufficient quote...");
66
77
  swapQuote = await this.jupSwapManager.getQuote(swapInput);
67
78
  const outputAmount = parseInt(swapQuote.outAmount);
68
- const postRebalanceRate = this.postRebalanceLiqUtilizationRateBps(BigInt(outputAmount));
79
+ const postRebalanceRate = this.postRebalanceLiqUtilizationRateBps(BigInt(outputAmount), BigInt(parseInt(swapQuote.inAmount)));
69
80
  insufficient = criteria.minOutputAmount
70
81
  ? outputAmount < Number(criteria.minOutputAmount)
71
82
  : criteria.minLiqUtilizationRateBps
72
83
  ? postRebalanceRate < criteria.minLiqUtilizationRateBps
73
84
  : postRebalanceRate > criteria.maxLiqUtilizationRateBps;
85
+ (0, utils_1.consoleLog)(postRebalanceRate, criteria.maxLiqUtilizationRateBps);
74
86
  if (insufficient) {
75
87
  (0, utils_1.consoleLog)("Insufficient swap quote:", swapQuote);
76
- swapInput.amount = this.bigIntWithIncrement(swapInput.amount, 0.01);
88
+ const increment = 0.01 + i * 0.005;
89
+ swapInput.amount = this.bigIntWithIncrement(swapInput.amount, this.isBoost() ? increment * -1 : increment);
77
90
  }
78
91
  else {
79
92
  break;
@@ -116,11 +129,11 @@ class RebalanceSwapManager {
116
129
  amount: swapAmount,
117
130
  };
118
131
  (0, utils_1.consoleLog)("Swap input:", swapInput);
119
- if (exactIn && (rebalanceToZero || this.values.repayingCloseToMaxLtv)) {
132
+ if (exactIn) {
120
133
  this.swapQuote = await this.findSufficientQuote(swapInput, {
121
134
  minOutputAmount: rebalanceToZero ? outputAmount : undefined,
122
- maxLiqUtilizationRateBps: this.values.repayingCloseToMaxLtv
123
- ? this.client.pos.maxRepayToBps - 15
135
+ maxLiqUtilizationRateBps: !rebalanceToZero
136
+ ? this.client.pos.maxBoostToBps
124
137
  : undefined,
125
138
  });
126
139
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AA8BrB,qBAAa,kBAAkB;IAQ3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,YAAY,CAAC;IATvB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,SAAS,CAAiC;gBAGxC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,YAAY,CAAC,EAAE,OAAO,YAAA;IAGhC,OAAO,CAAC,0BAA0B;IAclC,OAA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qB,GAAG,SAAS,CAAC;CAe9C"}
@@ -200,6 +200,11 @@ class RebalanceTxBuilder {
200
200
  };
201
201
  (0, utils_1.consoleLog)("Rebalance details:", rebalanceDetails);
202
202
  (0, utils_1.consoleLog)("Prices:", this.client.pos.supplyPrice(this.priceType), this.client.pos.debtPrice(this.priceType));
203
+ if ((0, utils_1.isMarginfiPosition)(this.client.pos)) {
204
+ const supply = this.values.endResult.supplyUsd * (0, utils_1.bytesToI80F48)(this.client.pos.supplyBank.config.assetWeightInit.value);
205
+ const debt = this.values.endResult.debtUsd * (0, utils_1.bytesToI80F48)(this.client.pos.debtBank.config.liabilityWeightInit.value);
206
+ (0, utils_1.consoleLog)("Weighted values", supply, debt);
207
+ }
203
208
  const firstRebalance = this.client.rebalanceIx(generated_1.RebalanceStep.PreSwap, rebalanceDetails);
204
209
  const lastRebalance = this.client.rebalanceIx(generated_1.RebalanceStep.PostSwap, rebalanceDetails);
205
210
  if (!flashLoanDetails) {
@@ -58,7 +58,7 @@ export declare abstract class SolautoClient extends ReferralStateManager {
58
58
  updatePositionIx(args: UpdatePositionDataArgs): TransactionBuilder;
59
59
  abstract closePositionIx(): TransactionBuilder;
60
60
  cancelDCAIx(): TransactionBuilder;
61
- abstract refreshIx(priceType: PriceType): TransactionBuilder;
61
+ abstract refreshIx(priceType?: PriceType): TransactionBuilder;
62
62
  protocolInteractionIx(args: SolautoActionArgs): TransactionBuilder;
63
63
  abstract rebalanceIx(rebalanceStep: RebalanceStep, data: RebalanceDetails): TransactionBuilder;
64
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT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C,gBAAgB,IAAI,SAAS,GAAG,SAAS;IAOnC,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO;IAe1C,mBAAmB,IAAI,MAAM,EAAE;IAS/B,gBAAgB,IAAI,SAAS,EAAE;IAezB,iCAAiC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAUzD,iBAAiB,IAAI,OAAO,CAC9B;QACE,EAAE,EAAE,kBAAkB,CAAC;QACvB,GAAG,EAAE,OAAO,CAAC;QACb,aAAa,EAAE,SAAS,EAAE,CAAC;KAC5B,GACD,SAAS,CACZ;IAgEK,cAAc,IAAI,OAAO,CAAC;QAC9B,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IAgBF,cAAc,CACZ,QAAQ,CAAC,EAAE,gCAAgC,EAC3C,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IA0BrB,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,GAAG,kBAAkB;IAsDlE,QAAQ,CAAC,eAAe,IAAI,kBAAkB;IAE9C,WAAW,IAAI,kBAAkB;IAcjC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,kBAAkB;IAE7D,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAqFlE,QAAQ,CAAC,WAAW,CAClB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,gBAAgB,GACrB,kBAAkB;CACtB"}
@@ -22,7 +22,7 @@ export declare class SolautoMarginfiClient extends SolautoClient {
22
22
  openPositionIx(settings?: SolautoSettingsParametersInpArgs, dca?: DCASettingsInpArgs): TransactionBuilder;
23
23
  private marginfiOpenPositionIx;
24
24
  closePositionIx(): TransactionBuilder;
25
- refreshIx(priceType: PriceType): TransactionBuilder;
25
+ refreshIx(priceType?: PriceType): TransactionBuilder;
26
26
  protocolInteractionIx(args: SolautoActionArgs): TransactionBuilder;
27
27
  private marginfiProtocolInteractionIx;
28
28
  private marginfiSolautoProtocolInteractionIx;
@@ -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,GAAG,kBAAkB;IAStE,cAAc,CACZ,QAAQ,CAAC,EAAE,gCAAgC,EAC3C,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;I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IA6ExC,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;IAkFrC,OAAO,CAAC,oCAAoC;IA0D5C,WAAW,CACT,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,gBAAgB,GACrB,kBAAkB;CA4EtB"}
@@ -140,7 +140,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
140
140
  debtBank: (0, umi_1.publicKey)(this.marginfiDebtAccounts.bank),
141
141
  debtPriceOracle: (0, umi_1.publicKey)(this.debtPriceOracle),
142
142
  solautoPosition: (0, umi_1.publicKey)(this.pos.publicKey),
143
- priceType,
143
+ priceType: priceType ?? generated_1.PriceType.Realtime,
144
144
  });
145
145
  }
146
146
  protocolInteractionIx(args) {
@@ -24,7 +24,7 @@ class JupSwapManager {
24
24
  ? "ExactIn"
25
25
  : undefined,
26
26
  slippageBps,
27
- maxAccounts: !data.exactOut ? 15 + attemptNum * 5 : undefined,
27
+ maxAccounts: !data.exactOut ? (memeSwap ? 25 : 15) + attemptNum * 5 : undefined,
28
28
  }), 4, 150);
29
29
  }
30
30
  async getJupInstructions(data) {
@@ -5,8 +5,8 @@ import { LendingPlatform, PriceType } from "../generated";
5
5
  export declare class MarginfiSolautoPositionEx extends SolautoPositionEx {
6
6
  lendingPlatform: LendingPlatform;
7
7
  maxLtvPriceType: PriceType;
8
- private supplyBank;
9
- private debtBank;
8
+ supplyBank: Bank | null;
9
+ debtBank: Bank | null;
10
10
  supplyPrice(priceType?: PriceType): number | undefined;
11
11
  debtPrice(priceType?: PriceType): number | undefined;
12
12
  private getBankAccounts;
@@ -1 +1 @@
1
- {"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAA+B,MAAM,iBAAiB,CAAC;AAepE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,eAAe,kBAA4B;IAC3C,eAAe,YAAiB;IAEhC,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,QAAQ,CAAqB;IAErC,WAAW,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAItD,SAAS,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAIpD,OAAO,CAAC,eAAe;IAMjB,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAW3B,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IASpC,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAa3D,OAAO,CAAC,6BAA6B;IAwBrC,gCAAgC,CAAC,KAAK,EAAE,IAAI,EAAE;IAK9C,4BAA4B,CAAC,KAAK,EAAE,IAAI,EAAE;IAQ1C,IAAI,eAAe,cAElB;IAED,IAAI,aAAa,cAEhB;IAED,IAAI,wBAAwB,IAAI,MAAM,CAKrC;IAEK,oBAAoB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BjE"}
1
+ {"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAA+B,MAAM,iBAAiB,CAAC;AAepE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,eAAe,kBAA4B;IAC3C,eAAe,YAAiB;IAEzB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAQ;IAC/B,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAQ;IAEpC,WAAW,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAItD,SAAS,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAIpD,OAAO,CAAC,eAAe;IAMjB,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAW3B,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IASpC,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAa3D,OAAO,CAAC,6BAA6B;IAwBrC,gCAAgC,CAAC,KAAK,EAAE,IAAI,EAAE;IAK9C,4BAA4B,CAAC,KAAK,EAAE,IAAI,EAAE;IAQ1C,IAAI,eAAe,cAElB;IAED,IAAI,aAAa,cAEhB;IAED,IAAI,wBAAwB,IAAI,MAAM,CAKrC;IAEK,oBAAoB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BjE"}
@@ -82,7 +82,7 @@ async function simulateJitoBundle(umi, txs) {
82
82
  throw new Error(res.error.message);
83
83
  }
84
84
  return res.value;
85
- });
85
+ }, 2);
86
86
  const transactionResults = simulationResult.transactionResults;
87
87
  return transactionResults;
88
88
  }
@@ -265,7 +265,7 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, txType, prior
265
265
  const blockhash = await connection.getLatestBlockhash("confirmed");
266
266
  let cuLimit = undefined;
267
267
  if (txType !== "skip-simulation") {
268
- const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(umi, connection, assembleFinalTransaction(umi, tx, undefined, 1400000).setBlockhash(blockhash)), 3);
268
+ const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(umi, connection, assembleFinalTransaction(umi, tx, undefined, 1400000).setBlockhash(blockhash)), 2);
269
269
  cuLimit = Math.round(simulationResult.value.unitsConsumed * 1.15);
270
270
  (0, generalUtils_1.consoleLog)("Compute unit limit: ", cuLimit);
271
271
  }
@@ -3,7 +3,9 @@ import { createSignerFromKeypair } from "@metaplex-foundation/umi";
3
3
  import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
4
4
  import {
5
5
  ClientTransactionsManager,
6
+ closeSolautoPosition,
6
7
  consoleLog,
8
+ deposit,
7
9
  getBatches,
8
10
  getClient,
9
11
  getPositionExBulk,
@@ -11,14 +13,19 @@ import {
11
13
  getSolautoManagedPositions,
12
14
  LendingPlatform,
13
15
  LOCAL_IRONFORGE_API_URL,
16
+ openSolautoPosition,
14
17
  PriceType,
15
18
  PriorityFeeSetting,
16
19
  ProgramEnv,
17
20
  rebalance,
21
+ RETARDIO,
18
22
  SOLAUTO_PROD_PROGRAM,
19
23
  SOLAUTO_TEST_PROGRAM,
20
24
  SolautoClient,
25
+ toBaseUnit,
21
26
  TransactionItem,
27
+ USDC,
28
+ withdraw,
22
29
  } from "../src";
23
30
  import { getSecretKey } from "./shared";
24
31
 
@@ -34,7 +41,7 @@ let [, umi] = getSolanaRpcConnection(
34
41
 
35
42
  const signer = createSignerFromKeypair(
36
43
  umi,
37
- fromWeb3JsKeypair(Keypair.fromSecretKey(getSecretKey("solauto-manager")))
44
+ fromWeb3JsKeypair(Keypair.fromSecretKey(getSecretKey()))
38
45
  );
39
46
 
40
47
  export async function main() {
@@ -47,20 +54,52 @@ export async function main() {
47
54
  });
48
55
 
49
56
  await client.initializeExistingSolautoPosition({
50
- positionId: 2,
51
- authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
57
+ positionId: 3,
58
+ // authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
52
59
  // lpUserAccount: new PublicKey(
53
60
  // "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
54
61
  // ),
62
+ // lpPoolAccount: new PublicKey(
63
+ // "EpzY5EYF1A5eFDRfjtsPXSYMPmEx1FXKaXPnouTMF4dm"
64
+ // ),
65
+ // supplyMint: new PublicKey(USDC),
66
+ // debtMint: new PublicKey(RETARDIO),
55
67
  });
56
68
 
57
- const transactionItems = [rebalance(client)];
69
+ await client.pos.refreshPositionState();
70
+
71
+ // const transactionItems = [
72
+ // openSolautoPosition(client, {
73
+ // boostGap: 100,
74
+ // boostToBps: client.pos.maxBoostToBps,
75
+ // repayGap: 100,
76
+ // repayToBps: client.pos.maxRepayToBps,
77
+ // }),
78
+ // ];
79
+ const transactionItems = [
80
+ // openSolautoPosition(client, {
81
+ // boostGap: 100,
82
+ // boostToBps: client.pos.maxBoostToBps,
83
+ // repayGap: 100,
84
+ // repayToBps: client.pos.maxRepayToBps,
85
+ // }),
86
+ deposit(client, toBaseUnit(5, client.pos.supplyMintInfo.decimals)),
87
+ rebalance(client, client.pos.maxBoostToBps),
88
+ // withdraw(client, "All"),
89
+ // closeSolautoPosition(client)
90
+ // new TransactionItem(
91
+ // async () => ({ tx: client.refreshIx() }),
92
+ // `refresh`,
93
+ // true
94
+ // ),
95
+ ];
58
96
 
59
97
  const txManager = new ClientTransactionsManager({
60
98
  txHandler: client,
61
99
  txRunType: payForTransaction ? "normal" : "only-simulate",
62
100
  priorityFeeSetting: PriorityFeeSetting.Default,
63
- retryConfig: { totalRetries: 5 },
101
+ retryConfig: { totalRetries: 0 },
102
+ // atomically: false,
64
103
  });
65
104
  const statuses = await txManager.send(transactionItems);
66
105
  consoleLog(statuses);
@@ -105,7 +144,7 @@ async function refreshAll() {
105
144
  txHandler: client!,
106
145
  txRunType: payForTransaction ? "normal" : "only-simulate",
107
146
  priorityFeeSetting: PriorityFeeSetting.Default,
108
- retryConfig: { totalRetries: 5 },
147
+ retryConfig: { totalRetries: 2 },
109
148
  });
110
149
  const statuses = await txManager.send(batch);
111
150
  consoleLog(statuses);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.699",
3
+ "version": "1.0.700",
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",
@@ -47,12 +47,22 @@ export class RebalanceSwapManager {
47
47
  ? this.client.pos.state.supply
48
48
  : this.client.pos.state.debt;
49
49
 
50
- // const supplyPrice = this.client.pos.supplyPrice(this.priceType)!;
51
- // const debtPrice = this.client.pos.debtPrice(this.priceType)!;
52
- // const inputPrice = this.isBoost() ? debtPrice : supplyPrice;
53
- // const outputPrice = this.isBoost() ? supplyPrice : debtPrice;
54
- const inputPrice = safeGetPrice(toWeb3JsPublicKey(input.mint), this.priceType)!;
55
- const outputPrice = safeGetPrice(toWeb3JsPublicKey(output.mint), this.priceType)!;
50
+ // const inputPrice = safeGetPrice(
51
+ // toWeb3JsPublicKey(input.mint),
52
+ // this.priceType
53
+ // )!;
54
+ // const outputPrice = safeGetPrice(
55
+ // toWeb3JsPublicKey(output.mint),
56
+ // this.priceType
57
+ // )!;
58
+
59
+ const supplyPrice = this.client.pos.supplyPrice(this.priceType)!;
60
+ const debtPrice = this.client.pos.debtPrice(this.priceType)!;
61
+ const biasedInputPrice = this.isBoost() ? debtPrice : supplyPrice;
62
+ const biasedOutputPrice = this.isBoost() ? supplyPrice : debtPrice;
63
+
64
+ const inputPrice = biasedInputPrice;
65
+ const outputPrice = biasedOutputPrice;
56
66
 
57
67
  let inputAmount = toBaseUnit(
58
68
  this.usdToSwap() / inputPrice!,
@@ -63,31 +73,42 @@ export class RebalanceSwapManager {
63
73
  inputAmount,
64
74
  input,
65
75
  inputPrice,
76
+ biasedInputPrice,
66
77
  output,
67
78
  outputPrice,
79
+ biasedOutputPrice,
68
80
  };
69
81
  }
70
82
 
71
- private postRebalanceLiqUtilizationRateBps(swapOutputAmount?: bigint) {
83
+ private postRebalanceLiqUtilizationRateBps(
84
+ swapOutputAmount?: bigint,
85
+ swapInputAmount?: bigint
86
+ ) {
72
87
  let supplyUsd = this.client.pos.supplyUsd(this.priceType);
73
88
  let debtUsd = this.client.pos.debtUsd(this.priceType);
74
89
  // TODO: add token balance change
75
90
 
76
- const { output, outputPrice } = this.swapDetails();
91
+ const { input, biasedInputPrice, output, biasedOutputPrice } =
92
+ this.swapDetails();
93
+
94
+ const swapInputUsd = swapInputAmount
95
+ ? fromBaseUnit(
96
+ swapInputAmount,
97
+ tokenInfo(toWeb3JsPublicKey(input.mint)).decimals
98
+ ) * biasedInputPrice
99
+ : this.usdToSwap();
77
100
 
78
101
  const swapOutputUsd = swapOutputAmount
79
102
  ? fromBaseUnit(
80
103
  swapOutputAmount,
81
104
  tokenInfo(toWeb3JsPublicKey(output.mint)).decimals
82
- ) * outputPrice
105
+ ) * biasedOutputPrice
83
106
  : this.usdToSwap();
84
107
 
85
108
  supplyUsd = this.isBoost()
86
109
  ? supplyUsd + swapOutputUsd
87
- : supplyUsd - this.usdToSwap();
88
- debtUsd = this.isBoost()
89
- ? debtUsd + this.usdToSwap()
90
- : debtUsd - swapOutputUsd;
110
+ : supplyUsd - swapInputUsd;
111
+ debtUsd = this.isBoost() ? debtUsd + swapInputUsd : debtUsd - swapOutputUsd;
91
112
 
92
113
  return getLiqUtilzationRateBps(
93
114
  supplyUsd,
@@ -107,13 +128,14 @@ export class RebalanceSwapManager {
107
128
  let swapQuote: QuoteResponse;
108
129
  let insufficient: boolean = false;
109
130
 
110
- for (let i = 0; i < 10; i++) {
131
+ for (let i = 0; i < 20; i++) {
111
132
  consoleLog("Finding sufficient quote...");
112
133
  swapQuote = await this.jupSwapManager.getQuote(swapInput);
113
134
 
114
135
  const outputAmount = parseInt(swapQuote.outAmount);
115
136
  const postRebalanceRate = this.postRebalanceLiqUtilizationRateBps(
116
- BigInt(outputAmount)
137
+ BigInt(outputAmount),
138
+ BigInt(parseInt(swapQuote.inAmount))
117
139
  );
118
140
  insufficient = criteria.minOutputAmount
119
141
  ? outputAmount < Number(criteria.minOutputAmount)
@@ -121,9 +143,15 @@ export class RebalanceSwapManager {
121
143
  ? postRebalanceRate < criteria.minLiqUtilizationRateBps
122
144
  : postRebalanceRate > criteria.maxLiqUtilizationRateBps!;
123
145
 
146
+ consoleLog(postRebalanceRate, criteria.maxLiqUtilizationRateBps);
124
147
  if (insufficient) {
125
148
  consoleLog("Insufficient swap quote:", swapQuote);
126
- swapInput.amount = this.bigIntWithIncrement(swapInput.amount, 0.01);
149
+
150
+ const increment = 0.01 + i * 0.005;
151
+ swapInput.amount = this.bigIntWithIncrement(
152
+ swapInput.amount,
153
+ this.isBoost() ? increment * -1 : increment
154
+ );
127
155
  } else {
128
156
  break;
129
157
  }
@@ -183,11 +211,11 @@ export class RebalanceSwapManager {
183
211
  };
184
212
  consoleLog("Swap input:", swapInput);
185
213
 
186
- if (exactIn && (rebalanceToZero || this.values.repayingCloseToMaxLtv)) {
214
+ if (exactIn) {
187
215
  this.swapQuote = await this.findSufficientQuote(swapInput, {
188
216
  minOutputAmount: rebalanceToZero ? outputAmount : undefined,
189
- maxLiqUtilizationRateBps: this.values.repayingCloseToMaxLtv
190
- ? this.client.pos.maxRepayToBps - 15
217
+ maxLiqUtilizationRateBps: !rebalanceToZero
218
+ ? this.client.pos.maxBoostToBps
191
219
  : undefined,
192
220
  });
193
221
  }
@@ -8,13 +8,16 @@ import {
8
8
  TransactionItemInputs,
9
9
  } from "../../types";
10
10
  import {
11
+ bytesToI80F48,
11
12
  consoleLog,
12
13
  fromBaseUnit,
13
14
  fromBps,
15
+ getLiqUtilzationRateBps,
14
16
  getMaxLiqUtilizationRateBps,
15
17
  getTokenAccount,
16
18
  hasFirstRebalance,
17
19
  hasLastRebalance,
20
+ isMarginfiPosition,
18
21
  safeGetPrice,
19
22
  tokenInfo,
20
23
  } from "../../utils";
@@ -346,6 +349,12 @@ export class RebalanceTxBuilder {
346
349
  this.client.pos.debtPrice(this.priceType)
347
350
  );
348
351
 
352
+ if (isMarginfiPosition(this.client.pos)) {
353
+ const supply = this.values.endResult.supplyUsd * bytesToI80F48(this.client.pos.supplyBank!.config.assetWeightInit.value);
354
+ const debt = this.values.endResult.debtUsd * bytesToI80F48(this.client.pos.debtBank!.config.liabilityWeightInit.value);
355
+ consoleLog("Weighted values", supply, debt);
356
+ }
357
+
349
358
  const firstRebalance = this.client.rebalanceIx(
350
359
  RebalanceStep.PreSwap,
351
360
  rebalanceDetails
@@ -437,7 +437,7 @@ export abstract class SolautoClient extends ReferralStateManager {
437
437
  });
438
438
  }
439
439
 
440
- abstract refreshIx(priceType: PriceType): TransactionBuilder;
440
+ abstract refreshIx(priceType?: PriceType): TransactionBuilder;
441
441
 
442
442
  protocolInteractionIx(args: SolautoActionArgs): TransactionBuilder {
443
443
  let tx = transactionBuilder();
@@ -230,7 +230,7 @@ export class SolautoMarginfiClient extends SolautoClient {
230
230
  });
231
231
  }
232
232
 
233
- refreshIx(priceType: PriceType): TransactionBuilder {
233
+ refreshIx(priceType?: PriceType): TransactionBuilder {
234
234
  return marginfiRefreshData(this.umi, {
235
235
  signer: this.signer,
236
236
  marginfiProgram: publicKey(this.mfiAccounts.program),
@@ -241,7 +241,7 @@ export class SolautoMarginfiClient extends SolautoClient {
241
241
  debtBank: publicKey(this.marginfiDebtAccounts.bank),
242
242
  debtPriceOracle: publicKey(this.debtPriceOracle),
243
243
  solautoPosition: publicKey(this.pos.publicKey),
244
- priceType,
244
+ priceType: priceType ?? PriceType.Realtime,
245
245
  });
246
246
  }
247
247
 
@@ -69,7 +69,7 @@ export class JupSwapManager {
69
69
  ? "ExactIn"
70
70
  : undefined,
71
71
  slippageBps,
72
- maxAccounts: !data.exactOut ? 15 + attemptNum * 5 : undefined,
72
+ maxAccounts: !data.exactOut ? (memeSwap ? 25 : 15) + attemptNum * 5 : undefined,
73
73
  }),
74
74
  4,
75
75
  150
@@ -21,8 +21,8 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
21
21
  lendingPlatform = LendingPlatform.Marginfi;
22
22
  maxLtvPriceType = PriceType.Ema;
23
23
 
24
- private supplyBank: Bank | null = null;
25
- private debtBank: Bank | null = null;
24
+ public supplyBank: Bank | null = null;
25
+ public debtBank: Bank | null = null;
26
26
 
27
27
  supplyPrice(priceType?: PriceType): number | undefined {
28
28
  return this._supplyPrice ?? safeGetPrice(this.supplyMint, priceType, PriceBias.Low);
@@ -121,7 +121,7 @@ async function simulateJitoBundle(umi: Umi, txs: VersionedTransaction[]) {
121
121
  }
122
122
 
123
123
  return res.value;
124
- });
124
+ }, 2);
125
125
 
126
126
  const transactionResults =
127
127
  simulationResult.transactionResults as SimulatedTransactionResponse[];
@@ -462,7 +462,7 @@ export async function sendSingleOptimizedTransaction(
462
462
  blockhash
463
463
  )
464
464
  ),
465
- 3
465
+ 2
466
466
  );
467
467
  cuLimit = Math.round(simulationResult.value.unitsConsumed! * 1.15);
468
468
  consoleLog("Compute unit limit: ", cuLimit);