@haven-fi/solauto-sdk 1.0.698 → 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;AAS3E,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;IA2BnB,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,51 +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 inputPrice = safeGetPrice(
31
+ // toWeb3JsPublicKey(input.mint),
32
+ // this.priceType
33
+ // )!;
34
+ // const outputPrice = safeGetPrice(
35
+ // toWeb3JsPublicKey(output.mint),
36
+ // this.priceType
37
+ // )!;
30
38
  const supplyPrice = this.client.pos.supplyPrice(this.priceType);
31
39
  const debtPrice = this.client.pos.debtPrice(this.priceType);
32
- const inputPrice = this.isBoost() ? debtPrice : supplyPrice;
33
- const outputPrice = this.isBoost() ? supplyPrice : debtPrice;
40
+ const biasedInputPrice = this.isBoost() ? debtPrice : supplyPrice;
41
+ const biasedOutputPrice = this.isBoost() ? supplyPrice : debtPrice;
42
+ const inputPrice = biasedInputPrice;
43
+ const outputPrice = biasedOutputPrice;
34
44
  let inputAmount = (0, utils_1.toBaseUnit)(this.usdToSwap() / inputPrice, input.decimals);
35
45
  return {
36
46
  inputAmount,
37
47
  input,
38
48
  inputPrice,
49
+ biasedInputPrice,
39
50
  output,
40
51
  outputPrice,
52
+ biasedOutputPrice,
41
53
  };
42
54
  }
43
- postRebalanceLiqUtilizationRateBps(swapOutputAmount) {
55
+ postRebalanceLiqUtilizationRateBps(swapOutputAmount, swapInputAmount) {
44
56
  let supplyUsd = this.client.pos.supplyUsd(this.priceType);
45
57
  let debtUsd = this.client.pos.debtUsd(this.priceType);
46
58
  // TODO: add token balance change
47
- 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();
48
63
  const swapOutputUsd = swapOutputAmount
49
- ? (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
50
65
  : this.usdToSwap();
51
66
  supplyUsd = this.isBoost()
52
67
  ? supplyUsd + swapOutputUsd
53
- : supplyUsd - this.usdToSwap();
54
- debtUsd = this.isBoost()
55
- ? debtUsd + this.usdToSwap()
56
- : debtUsd - swapOutputUsd;
68
+ : supplyUsd - swapInputUsd;
69
+ debtUsd = this.isBoost() ? debtUsd + swapInputUsd : debtUsd - swapOutputUsd;
57
70
  return (0, utils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, this.client.pos.state.liqThresholdBps ?? 0);
58
71
  }
59
72
  async findSufficientQuote(swapInput, criteria) {
60
73
  let swapQuote;
61
74
  let insufficient = false;
62
- for (let i = 0; i < 10; i++) {
75
+ for (let i = 0; i < 20; i++) {
63
76
  (0, utils_1.consoleLog)("Finding sufficient quote...");
64
77
  swapQuote = await this.jupSwapManager.getQuote(swapInput);
65
78
  const outputAmount = parseInt(swapQuote.outAmount);
66
- const postRebalanceRate = this.postRebalanceLiqUtilizationRateBps(BigInt(outputAmount));
79
+ const postRebalanceRate = this.postRebalanceLiqUtilizationRateBps(BigInt(outputAmount), BigInt(parseInt(swapQuote.inAmount)));
67
80
  insufficient = criteria.minOutputAmount
68
81
  ? outputAmount < Number(criteria.minOutputAmount)
69
82
  : criteria.minLiqUtilizationRateBps
70
83
  ? postRebalanceRate < criteria.minLiqUtilizationRateBps
71
84
  : postRebalanceRate > criteria.maxLiqUtilizationRateBps;
85
+ (0, utils_1.consoleLog)(postRebalanceRate, criteria.maxLiqUtilizationRateBps);
72
86
  if (insufficient) {
73
87
  (0, utils_1.consoleLog)("Insufficient swap quote:", swapQuote);
74
- 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);
75
90
  }
76
91
  else {
77
92
  break;
@@ -114,11 +129,11 @@ class RebalanceSwapManager {
114
129
  amount: swapAmount,
115
130
  };
116
131
  (0, utils_1.consoleLog)("Swap input:", swapInput);
117
- if (exactIn && (rebalanceToZero || this.values.repayingCloseToMaxLtv)) {
132
+ if (exactIn) {
118
133
  this.swapQuote = await this.findSufficientQuote(swapInput, {
119
134
  minOutputAmount: rebalanceToZero ? outputAmount : undefined,
120
- maxLiqUtilizationRateBps: this.values.repayingCloseToMaxLtv
121
- ? this.client.pos.maxRepayToBps - 15
135
+ maxLiqUtilizationRateBps: !rebalanceToZero
136
+ ? this.client.pos.maxBoostToBps
122
137
  : undefined,
123
138
  });
124
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,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;IAwC5B,OAAO,CAAC,iCAAiC;YAgC3B,qBAAqB;IA0CnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAyBnB,sBAAsB;YAyBtB,mBAAmB;IAwEpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CAe9C"}
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;AAiCrB,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,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;IAwC5B,OAAO,CAAC,iCAAiC;YAgC3B,qBAAqB;IA0CnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAyBnB,sBAAsB;YAyBtB,mBAAmB;IA8EpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,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,aAAa,EACb,iBAAiB,EACjB,gCAAgC,EAEhC,sBAAsB,EAGvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAKL,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAA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AClB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,gBAAgB,GACrB,kBAAkB;CACtB"}
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,aAAa,EACb,iBAAiB,EACjB,gCAAgC,EAEhC,sBAAsB,EAGvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAKL,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,WAAW,iBAAkB,SAAQ,wBAAwB;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAChD,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,CACtC,GACC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC,CAAC;AAEhD,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAC3C,IAAI,CACF,iBAAiB,EACjB,YAAY,GAAG,YAAY,GAAG,UAAU,GAAG,eAAe,CAC3D,CACF,CAAC;AAEF,MAA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AAE,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,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A0C9B,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,SA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O,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
  }
@@ -1 +1 @@
1
- {"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAerE,OAAO,EAAE,SAAS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AAW;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,SAAS,EAAE,EAClB,SAAS,GAAE,SAA8B,EACzC,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CAAC,MAAM,EAAE,CAAC,CA0CnB;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAqDtC;AAkBD,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CA+CtC;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAiBtC;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,EACnD,SAAS,GAAE,SAA8B,EACzC,SAAS,CAAC,EAAE,SAAS,GACpB,MAAM,GAAG,SAAS,CAyBpB"}
@@ -167,14 +167,12 @@ function safeGetPrice(mint, priceType = generated_1.PriceType.Realtime, priceBia
167
167
  ? priceData.emaConfInterval
168
168
  : priceData.confInterval;
169
169
  const conf = Math.min(confInterval, price * 0.05);
170
- (0, generalUtils_1.consoleLog)("before", price, conf);
171
170
  if (priceBias === marginfi_sdk_1.PriceBias.Low) {
172
171
  price -= conf;
173
172
  }
174
173
  else {
175
174
  price += conf;
176
175
  }
177
- (0, generalUtils_1.consoleLog)("after", price);
178
176
  }
179
177
  return price;
180
178
  }
@@ -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.698",
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",
@@ -9,6 +9,7 @@ import {
9
9
  consoleLog,
10
10
  fromBaseUnit,
11
11
  getLiqUtilzationRateBps,
12
+ safeGetPrice,
12
13
  toBaseUnit,
13
14
  tokenInfo,
14
15
  } from "../../utils";
@@ -46,10 +47,22 @@ export class RebalanceSwapManager {
46
47
  ? this.client.pos.state.supply
47
48
  : this.client.pos.state.debt;
48
49
 
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
+
49
59
  const supplyPrice = this.client.pos.supplyPrice(this.priceType)!;
50
60
  const debtPrice = this.client.pos.debtPrice(this.priceType)!;
51
- const inputPrice = this.isBoost() ? debtPrice : supplyPrice;
52
- const outputPrice = this.isBoost() ? supplyPrice : debtPrice;
61
+ const biasedInputPrice = this.isBoost() ? debtPrice : supplyPrice;
62
+ const biasedOutputPrice = this.isBoost() ? supplyPrice : debtPrice;
63
+
64
+ const inputPrice = biasedInputPrice;
65
+ const outputPrice = biasedOutputPrice;
53
66
 
54
67
  let inputAmount = toBaseUnit(
55
68
  this.usdToSwap() / inputPrice!,
@@ -60,31 +73,42 @@ export class RebalanceSwapManager {
60
73
  inputAmount,
61
74
  input,
62
75
  inputPrice,
76
+ biasedInputPrice,
63
77
  output,
64
78
  outputPrice,
79
+ biasedOutputPrice,
65
80
  };
66
81
  }
67
82
 
68
- private postRebalanceLiqUtilizationRateBps(swapOutputAmount?: bigint) {
83
+ private postRebalanceLiqUtilizationRateBps(
84
+ swapOutputAmount?: bigint,
85
+ swapInputAmount?: bigint
86
+ ) {
69
87
  let supplyUsd = this.client.pos.supplyUsd(this.priceType);
70
88
  let debtUsd = this.client.pos.debtUsd(this.priceType);
71
89
  // TODO: add token balance change
72
90
 
73
- 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();
74
100
 
75
101
  const swapOutputUsd = swapOutputAmount
76
102
  ? fromBaseUnit(
77
103
  swapOutputAmount,
78
104
  tokenInfo(toWeb3JsPublicKey(output.mint)).decimals
79
- ) * outputPrice
105
+ ) * biasedOutputPrice
80
106
  : this.usdToSwap();
81
107
 
82
108
  supplyUsd = this.isBoost()
83
109
  ? supplyUsd + swapOutputUsd
84
- : supplyUsd - this.usdToSwap();
85
- debtUsd = this.isBoost()
86
- ? debtUsd + this.usdToSwap()
87
- : debtUsd - swapOutputUsd;
110
+ : supplyUsd - swapInputUsd;
111
+ debtUsd = this.isBoost() ? debtUsd + swapInputUsd : debtUsd - swapOutputUsd;
88
112
 
89
113
  return getLiqUtilzationRateBps(
90
114
  supplyUsd,
@@ -104,13 +128,14 @@ export class RebalanceSwapManager {
104
128
  let swapQuote: QuoteResponse;
105
129
  let insufficient: boolean = false;
106
130
 
107
- for (let i = 0; i < 10; i++) {
131
+ for (let i = 0; i < 20; i++) {
108
132
  consoleLog("Finding sufficient quote...");
109
133
  swapQuote = await this.jupSwapManager.getQuote(swapInput);
110
134
 
111
135
  const outputAmount = parseInt(swapQuote.outAmount);
112
136
  const postRebalanceRate = this.postRebalanceLiqUtilizationRateBps(
113
- BigInt(outputAmount)
137
+ BigInt(outputAmount),
138
+ BigInt(parseInt(swapQuote.inAmount))
114
139
  );
115
140
  insufficient = criteria.minOutputAmount
116
141
  ? outputAmount < Number(criteria.minOutputAmount)
@@ -118,9 +143,15 @@ export class RebalanceSwapManager {
118
143
  ? postRebalanceRate < criteria.minLiqUtilizationRateBps
119
144
  : postRebalanceRate > criteria.maxLiqUtilizationRateBps!;
120
145
 
146
+ consoleLog(postRebalanceRate, criteria.maxLiqUtilizationRateBps);
121
147
  if (insufficient) {
122
148
  consoleLog("Insufficient swap quote:", swapQuote);
123
- 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
+ );
124
155
  } else {
125
156
  break;
126
157
  }
@@ -180,11 +211,11 @@ export class RebalanceSwapManager {
180
211
  };
181
212
  consoleLog("Swap input:", swapInput);
182
213
 
183
- if (exactIn && (rebalanceToZero || this.values.repayingCloseToMaxLtv)) {
214
+ if (exactIn) {
184
215
  this.swapQuote = await this.findSufficientQuote(swapInput, {
185
216
  minOutputAmount: rebalanceToZero ? outputAmount : undefined,
186
- maxLiqUtilizationRateBps: this.values.repayingCloseToMaxLtv
187
- ? this.client.pos.maxRepayToBps - 15
217
+ maxLiqUtilizationRateBps: !rebalanceToZero
218
+ ? this.client.pos.maxBoostToBps
188
219
  : undefined,
189
220
  });
190
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[];
@@ -236,13 +236,11 @@ export function safeGetPrice(
236
236
  : priceData.confInterval;
237
237
  const conf = Math.min(confInterval, price * 0.05);
238
238
 
239
- consoleLog("before", price, conf);
240
239
  if (priceBias === PriceBias.Low) {
241
240
  price -= conf;
242
241
  } else {
243
242
  price += conf;
244
243
  }
245
- consoleLog("after", price);
246
244
  }
247
245
 
248
246
  return price;
@@ -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);