@haven-fi/solauto-sdk 1.0.132 → 1.0.134

Sign up to get free protection for your applications and to get access to all the features.
@@ -74,7 +74,7 @@ function getSolautoFeesBps(isReferred, targetLiqUtilizationRateBps, positionNetW
74
74
  const k = 1.5;
75
75
  let feeBps = 0;
76
76
  if (targetLiqUtilizationRateBps !== undefined) {
77
- feeBps = 10;
77
+ feeBps = 25;
78
78
  }
79
79
  else if (positionNetWorthUsd <= minSize) {
80
80
  feeBps = maxFeeBps;
@@ -1 +1 @@
1
- {"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;AAezB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAU1D;AAgBD,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAET;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,EAC9B,oBAAoB,EAAE,MAAM,UAY7B;AAED,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,EACnC,eAAe,EAAE,MAAM,GACtB,yBAAyB,CAgB3B;AAED,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,yBAAyB,EAC3C,WAAW,EAAE,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U,EAChB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB,aAAa,CA8Df;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,gCAAgC,GACzC,yBAAyB,CA8B3B;AAED,KAAK,kBAAkB,GACnB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,gCAAgC,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE/C,qBAAa,mBAAmB;IACvB,gBAAgB,EAAE,MAAM,CAAa;IACrC,cAAc,EAAE,MAAM,CAAa;IACnC,uBAAuB,EAAE,MAAM,CAAa;IAC5C,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAEtD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IA0B9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
@@ -27,7 +27,8 @@ const marginfiUtils_1 = require("../marginfiUtils");
27
27
  function findMintByTicker(ticker) {
28
28
  for (const key in constants_1.TOKEN_INFO) {
29
29
  const account = constants_1.TOKEN_INFO[key];
30
- if (account.ticker.toString().toLowerCase() === ticker.toString().toLowerCase()) {
30
+ if (account.ticker.toString().toLowerCase() ===
31
+ ticker.toString().toLowerCase()) {
31
32
  return new web3_js_1.PublicKey(key);
32
33
  }
33
34
  }
@@ -102,13 +103,17 @@ async function getSolautoManagedPositions(umi, authority) {
102
103
  // position_id: [u8; 1]
103
104
  // self_managed: u8 - (1 for true, 0 for false)
104
105
  // padding: [u8; 5]
105
- // authority: Pubkey
106
+ // authority: pubkey
106
107
  // lending_platform: u8
108
+ // padding: [u8; 7]
109
+ // protocol account: pubkey
110
+ // supply mint: pubkey
111
+ // debt mint: pubkey
107
112
  const accounts = await umi.rpc.getProgramAccounts(generated_1.SOLAUTO_PROGRAM_ID, {
108
113
  commitment: "confirmed",
109
114
  dataSlice: {
110
115
  offset: 0,
111
- length: 1 + 1 + 1 + 5 + 32 + 1, // bump + position_id + self_managed + padding + authority (pubkey) + lending_platform
116
+ length: 1 + 1 + 1 + 5 + 32 + 1 + 7 + 32 + 32 + 32, // bump + position_id + self_managed + padding (5) + authority (pubkey) + lending_platform + padding (7) + protocol account (pubkey) + supply mint (pubkey) + debt mint (pubkey)
112
117
  },
113
118
  filters: [
114
119
  {
@@ -142,6 +147,9 @@ async function getSolautoManagedPositions(umi, authority) {
142
147
  authority: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.authority),
143
148
  positionId: position.positionId[0],
144
149
  lendingPlatform: position.position.lendingPlatform,
150
+ protocolAccount: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.position.protocolAccount),
151
+ supplyMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.position.supplyMint),
152
+ debtMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.position.debtMint),
145
153
  };
146
154
  });
147
155
  }
@@ -187,29 +195,32 @@ async function getReferralsByUser(umi, user) {
187
195
  return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
188
196
  }
189
197
  async function getAllPositionsByAuthority(umi, user) {
190
- const allPositions = [];
191
- const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
192
- allPositions.push(...solautoManagedPositions.map((x) => ({
193
- publicKey: x.publicKey,
194
- authority: user,
195
- positionId: x.positionId,
196
- lendingPlatform: x.lendingPlatform,
197
- })));
198
- let marginfiPositions = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(umi, user, true);
199
- marginfiPositions = marginfiPositions.filter((x) => x.supplyMint &&
200
- (x.debtMint.equals(web3_js_1.PublicKey.default) ||
201
- constants_1.ALL_SUPPORTED_TOKENS.includes(x.debtMint.toString())));
202
- allPositions.push(...marginfiPositions.map((x) => ({
203
- publicKey: x.marginfiAccount,
204
- authority: user,
205
- positionId: 0,
206
- lendingPlatform: generated_1.LendingPlatform.Marginfi,
207
- protocolAccount: x.marginfiAccount,
208
- supplyMint: x.supplyMint,
209
- debtMint: x.debtMint,
210
- })));
211
- // TODO support other platforms
212
- return allPositions;
198
+ const solautoCompatiblePositions = await Promise.all([
199
+ (async () => {
200
+ const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
201
+ return solautoManagedPositions.map((x) => ({
202
+ ...x,
203
+ authority: user,
204
+ }));
205
+ })(),
206
+ (async () => {
207
+ let marginfiPositions = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(umi, user, true);
208
+ marginfiPositions = marginfiPositions.filter((x) => x.supplyMint &&
209
+ (x.debtMint.equals(web3_js_1.PublicKey.default) ||
210
+ constants_1.ALL_SUPPORTED_TOKENS.includes(x.debtMint.toString())));
211
+ return marginfiPositions.map((x) => ({
212
+ publicKey: x.marginfiAccount,
213
+ authority: user,
214
+ positionId: 0,
215
+ lendingPlatform: generated_1.LendingPlatform.Marginfi,
216
+ protocolAccount: x.marginfiAccount,
217
+ supplyMint: x.supplyMint,
218
+ debtMint: x.debtMint,
219
+ }));
220
+ })(),
221
+ // TODO support other platforms
222
+ ]);
223
+ return solautoCompatiblePositions.flat();
213
224
  }
214
225
  async function positionStateWithLatestPrices(state, supplyPrice, debtPrice) {
215
226
  if (!supplyPrice || !debtPrice) {
@@ -320,8 +331,7 @@ function createSolautoSettings(settings) {
320
331
  padding: new Uint8Array([]),
321
332
  padding1: [],
322
333
  },
323
- targetBoostToBps: (0, umi_1.isOption)(settings.targetBoostToBps) &&
324
- (0, umi_1.isSome)(settings.targetBoostToBps)
334
+ targetBoostToBps: (0, umi_1.isOption)(settings.targetBoostToBps) && (0, umi_1.isSome)(settings.targetBoostToBps)
325
335
  ? settings.targetBoostToBps.value
326
336
  : 0,
327
337
  boostGap: settings.boostGap,
@@ -1 +1 @@
1
- {"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,yBAAyB,EAC1B,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAkJjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CA0EjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG,SAAS,CAmE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EAC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AU,CAAC,EAAE,MAAM,GAClB,cAAc,CAkChB"}
@@ -80,11 +80,6 @@ function getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, target
80
80
  }
81
81
  }
82
82
  function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps, limitGapBps) {
83
- if (state === undefined ||
84
- state.lastUpdated <
85
- BigInt(Math.round((0, generalUtils_2.currentUnixSeconds)() - solautoConstants_1.MIN_POSITION_STATE_FRESHNESS_SECS))) {
86
- console.warn("Requires a fresh position state to get rebalance details");
87
- }
88
83
  const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, targetLiqUtilizationRateBps);
89
84
  const amountUsdToDcaIn = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountToDcaIn ?? 0)), state.debt.decimals) *
90
85
  debtPrice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.132",
3
+ "version": "1.0.134",
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",
@@ -104,7 +104,7 @@ export function getSolautoFeesBps(
104
104
  let feeBps: number = 0;
105
105
 
106
106
  if (targetLiqUtilizationRateBps !== undefined) {
107
- feeBps = 10;
107
+ feeBps = 25;
108
108
  } else if (positionNetWorthUsd <= minSize) {
109
109
  feeBps = maxFeeBps;
110
110
  } else if (positionNetWorthUsd >= maxSize) {
@@ -12,6 +12,7 @@ import {
12
12
  getReferralStateSize,
13
13
  getSolautoPositionAccountDataSerializer,
14
14
  getSolautoPositionSize,
15
+ safeFetchAllSolautoPosition,
15
16
  } from "../../generated";
16
17
  import { currentUnixSeconds, fetchTokenPrices } from "../generalUtils";
17
18
  import {
@@ -33,7 +34,8 @@ export function findMintByTicker(ticker: string): PublicKey {
33
34
  for (const key in TOKEN_INFO) {
34
35
  const account = TOKEN_INFO[key];
35
36
  if (
36
- account.ticker.toString().toLowerCase() === ticker.toString().toLowerCase()
37
+ account.ticker.toString().toLowerCase() ===
38
+ ticker.toString().toLowerCase()
37
39
  ) {
38
40
  return new PublicKey(key);
39
41
  }
@@ -176,14 +178,18 @@ export async function getSolautoManagedPositions(
176
178
  // position_id: [u8; 1]
177
179
  // self_managed: u8 - (1 for true, 0 for false)
178
180
  // padding: [u8; 5]
179
- // authority: Pubkey
181
+ // authority: pubkey
180
182
  // lending_platform: u8
183
+ // padding: [u8; 7]
184
+ // protocol account: pubkey
185
+ // supply mint: pubkey
186
+ // debt mint: pubkey
181
187
 
182
188
  const accounts = await umi.rpc.getProgramAccounts(SOLAUTO_PROGRAM_ID, {
183
189
  commitment: "confirmed",
184
190
  dataSlice: {
185
191
  offset: 0,
186
- length: 1 + 1 + 1 + 5 + 32 + 1, // bump + position_id + self_managed + padding + authority (pubkey) + lending_platform
192
+ length: 1 + 1 + 1 + 5 + 32 + 1 + 7 + 32 + 32 + 32, // bump + position_id + self_managed + padding (5) + authority (pubkey) + lending_platform + padding (7) + protocol account (pubkey) + supply mint (pubkey) + debt mint (pubkey)
187
193
  },
188
194
  filters: [
189
195
  {
@@ -220,6 +226,9 @@ export async function getSolautoManagedPositions(
220
226
  authority: toWeb3JsPublicKey(position.authority),
221
227
  positionId: position.positionId[0],
222
228
  lendingPlatform: position.position.lendingPlatform,
229
+ protocolAccount: toWeb3JsPublicKey(position.position.protocolAccount),
230
+ supplyMint: toWeb3JsPublicKey(position.position.supplyMint),
231
+ debtMint: toWeb3JsPublicKey(position.position.debtMint),
223
232
  };
224
233
  });
225
234
  }
@@ -277,44 +286,44 @@ export async function getAllPositionsByAuthority(
277
286
  umi: Umi,
278
287
  user: PublicKey
279
288
  ): Promise<SolautoPositionDetails[]> {
280
- const allPositions: SolautoPositionDetails[] = [];
281
-
282
- const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
283
- allPositions.push(
284
- ...solautoManagedPositions.map((x) => ({
285
- publicKey: x.publicKey,
286
- authority: user,
287
- positionId: x.positionId,
288
- lendingPlatform: x.lendingPlatform,
289
- }))
290
- );
291
-
292
- let marginfiPositions = await getAllMarginfiAccountsByAuthority(
293
- umi,
294
- user,
295
- true
296
- );
297
- marginfiPositions = marginfiPositions.filter(
298
- (x) =>
299
- x.supplyMint &&
300
- (x.debtMint!.equals(PublicKey.default) ||
301
- ALL_SUPPORTED_TOKENS.includes(x.debtMint!.toString()))
302
- );
303
- allPositions.push(
304
- ...marginfiPositions.map((x) => ({
305
- publicKey: x.marginfiAccount,
306
- authority: user,
307
- positionId: 0,
308
- lendingPlatform: LendingPlatform.Marginfi,
309
- protocolAccount: x.marginfiAccount,
310
- supplyMint: x.supplyMint,
311
- debtMint: x.debtMint,
312
- }))
313
- );
314
-
315
- // TODO support other platforms
289
+ const solautoCompatiblePositions: SolautoPositionDetails[][] =
290
+ await Promise.all([
291
+ (async () => {
292
+ const solautoManagedPositions = await getSolautoManagedPositions(
293
+ umi,
294
+ user
295
+ );
296
+ return solautoManagedPositions.map((x) => ({
297
+ ...x,
298
+ authority: user,
299
+ }));
300
+ })(),
301
+ (async () => {
302
+ let marginfiPositions = await getAllMarginfiAccountsByAuthority(
303
+ umi,
304
+ user,
305
+ true
306
+ );
307
+ marginfiPositions = marginfiPositions.filter(
308
+ (x) =>
309
+ x.supplyMint &&
310
+ (x.debtMint!.equals(PublicKey.default) ||
311
+ ALL_SUPPORTED_TOKENS.includes(x.debtMint!.toString()))
312
+ );
313
+ return marginfiPositions.map((x) => ({
314
+ publicKey: x.marginfiAccount,
315
+ authority: user,
316
+ positionId: 0,
317
+ lendingPlatform: LendingPlatform.Marginfi,
318
+ protocolAccount: x.marginfiAccount,
319
+ supplyMint: x.supplyMint,
320
+ debtMint: x.debtMint,
321
+ }));
322
+ })(),
323
+ // TODO support other platforms
324
+ ]);
316
325
 
317
- return allPositions;
326
+ return solautoCompatiblePositions.flat();
318
327
  }
319
328
 
320
329
  export async function positionStateWithLatestPrices(
@@ -441,15 +450,15 @@ export function createFakePositionState(
441
450
  };
442
451
  }
443
452
 
444
- export function createSolautoSettings(settings: SolautoSettingsParametersInpArgs): SolautoSettingsParameters {
453
+ export function createSolautoSettings(
454
+ settings: SolautoSettingsParametersInpArgs
455
+ ): SolautoSettingsParameters {
445
456
  return {
446
457
  automation:
447
458
  isOption(settings.automation) && isSome(settings.automation)
448
459
  ? {
449
460
  ...settings.automation.value,
450
- intervalSeconds: BigInt(
451
- settings.automation.value.intervalSeconds
452
- ),
461
+ intervalSeconds: BigInt(settings.automation.value.intervalSeconds),
453
462
  unixStartDate: BigInt(settings.automation.value.unixStartDate),
454
463
  padding: new Uint8Array([]),
455
464
  padding1: [],
@@ -463,8 +472,7 @@ export function createSolautoSettings(settings: SolautoSettingsParametersInpArgs
463
472
  padding1: [],
464
473
  },
465
474
  targetBoostToBps:
466
- isOption(settings.targetBoostToBps) &&
467
- isSome(settings.targetBoostToBps)
475
+ isOption(settings.targetBoostToBps) && isSome(settings.targetBoostToBps)
468
476
  ? settings.targetBoostToBps.value
469
477
  : 0,
470
478
  boostGap: settings.boostGap,
@@ -176,16 +176,6 @@ export function getRebalanceValues(
176
176
  targetLiqUtilizationRateBps?: number,
177
177
  limitGapBps?: number
178
178
  ): RebalanceValues {
179
- if (
180
- state === undefined ||
181
- state.lastUpdated <
182
- BigInt(
183
- Math.round(currentUnixSeconds() - MIN_POSITION_STATE_FRESHNESS_SECS)
184
- )
185
- ) {
186
- console.warn("Requires a fresh position state to get rebalance details");
187
- }
188
-
189
179
  const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(
190
180
  state,
191
181
  settings,