@haven-fi/solauto-sdk 1.0.60 → 1.0.62

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { Umi } from "@metaplex-foundation/umi";
3
- import { AutomationSettings, DCASettings, DCASettingsInpArgs, FeeType, LendingPlatform, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../../generated";
3
+ import { AutomationSettings, DCASettings, DCASettingsInpArgs, FeeType, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../../generated";
4
4
  import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
5
5
  export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
6
6
  export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings, currentUnixTime: number): boolean;
@@ -11,21 +11,13 @@ export declare function getSolautoFeesBps(isReferred: boolean, feeType: FeeType)
11
11
  referrer: number;
12
12
  total: number;
13
13
  };
14
- export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings, currentUnixSecs: number): RebalanceAction | undefined;
14
+ export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings | undefined, currentUnixSecs: number): RebalanceAction | undefined;
15
15
  export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters, currentUnixTime: number): boolean;
16
16
  export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey): Promise<SolautoPositionDetails[]>;
17
17
  export declare function getAllReferralStates(umi: Umi): Promise<PublicKey[]>;
18
18
  export declare function getReferralsByUser(umi: Umi, user: PublicKey): Promise<PublicKey[]>;
19
19
  export declare function getAllPositionsByAuthority(umi: Umi, user: PublicKey): Promise<SolautoPositionDetails[]>;
20
- interface GetLatestStateProps {
21
- state: PositionState;
22
- umi?: Umi;
23
- protocolAccount?: PublicKey;
24
- lendingPlatform?: LendingPlatform;
25
- supplyPrice?: number;
26
- debtPrice?: number;
27
- }
28
- export declare function positionStateWithPrices({ state, supplyPrice, debtPrice, umi, protocolAccount, lendingPlatform, }: GetLatestStateProps): Promise<PositionState | undefined>;
20
+ export declare function positionStateWithPrices(state: PositionState, supplyPrice?: number, debtPrice?: number): Promise<PositionState | undefined>;
29
21
  interface AssetProps {
30
22
  amountUsedBaseUnit: bigint;
31
23
  decimals: number;
@@ -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,EAClB,OAAO,EACP,eAAe,EACf,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;AAczB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAgB9E,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,iBAAiB,CAC/B,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,OAAO,GACf;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAYA;AAED,wBAAgB,oBAAoB,CAClC,aA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
  };
69
69
  }
70
70
  function eligibleForRebalance(positionState, positionSettings, positionDca, currentUnixSecs) {
71
- if (positionDca.automation.targetPeriods > 0 &&
71
+ if (positionDca &&
72
+ positionDca.automation.targetPeriods > 0 &&
72
73
  eligibleForNextAutomationPeriod(positionDca.automation, currentUnixSecs)) {
73
74
  return "dca";
74
75
  }
@@ -212,20 +213,7 @@ async function getAllPositionsByAuthority(umi, user) {
212
213
  // TODO support other platforms
213
214
  return allPositions;
214
215
  }
215
- async function positionStateWithPrices({ state, supplyPrice, debtPrice, umi, protocolAccount, lendingPlatform, }) {
216
- if ((0, generalUtils_1.currentUnixSeconds)() - Number(state.lastUpdated) > 60 * 60 * 24 * 7) {
217
- if (umi === undefined ||
218
- protocolAccount === undefined ||
219
- lendingPlatform === undefined) {
220
- throw new Error("Missing required parameters");
221
- }
222
- if (lendingPlatform === generated_1.LendingPlatform.Marginfi) {
223
- return await (0, marginfiUtils_1.getMarginfiAccountPositionState)(umi, protocolAccount, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint), (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint));
224
- }
225
- else {
226
- throw new Error("Lending platorm not yet supported");
227
- }
228
- }
216
+ async function positionStateWithPrices(state, supplyPrice, debtPrice) {
229
217
  if (!supplyPrice || !debtPrice) {
230
218
  [supplyPrice, debtPrice] = await (0, generalUtils_1.getTokenPrices)([
231
219
  (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.60",
3
+ "version": "1.0.62",
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",
@@ -122,10 +122,11 @@ export function getSolautoFeesBps(
122
122
  export function eligibleForRebalance(
123
123
  positionState: PositionState,
124
124
  positionSettings: SolautoSettingsParameters,
125
- positionDca: DCASettings,
125
+ positionDca: DCASettings | undefined,
126
126
  currentUnixSecs: number
127
127
  ): RebalanceAction | undefined {
128
128
  if (
129
+ positionDca &&
129
130
  positionDca.automation.targetPeriods > 0 &&
130
131
  eligibleForNextAutomationPeriod(positionDca.automation, currentUnixSecs)
131
132
  ) {
@@ -325,44 +326,11 @@ export async function getAllPositionsByAuthority(
325
326
  return allPositions;
326
327
  }
327
328
 
328
- interface GetLatestStateProps {
329
- state: PositionState;
330
- umi?: Umi;
331
- protocolAccount?: PublicKey;
332
- lendingPlatform?: LendingPlatform;
333
- supplyPrice?: number;
334
- debtPrice?: number;
335
- }
336
-
337
- export async function positionStateWithPrices({
338
- state,
339
- supplyPrice,
340
- debtPrice,
341
- umi,
342
- protocolAccount,
343
- lendingPlatform,
344
- }: GetLatestStateProps): Promise<PositionState | undefined> {
345
- if (currentUnixSeconds() - Number(state.lastUpdated) > 60 * 60 * 24 * 7) {
346
- if (
347
- umi === undefined ||
348
- protocolAccount === undefined ||
349
- lendingPlatform === undefined
350
- ) {
351
- throw new Error("Missing required parameters");
352
- }
353
-
354
- if (lendingPlatform === LendingPlatform.Marginfi) {
355
- return await getMarginfiAccountPositionState(
356
- umi,
357
- protocolAccount,
358
- toWeb3JsPublicKey(state.supply.mint),
359
- toWeb3JsPublicKey(state.debt.mint)
360
- );
361
- } else {
362
- throw new Error("Lending platorm not yet supported");
363
- }
364
- }
365
-
329
+ export async function positionStateWithPrices(
330
+ state: PositionState,
331
+ supplyPrice?: number,
332
+ debtPrice?: number,
333
+ ): Promise<PositionState | undefined> {
366
334
  if (!supplyPrice || !debtPrice) {
367
335
  [supplyPrice, debtPrice] = await getTokenPrices([
368
336
  toWeb3JsPublicKey(state.supply.mint),
@@ -19,7 +19,6 @@ import {
19
19
  } from "../../src/transactions/transactionsManager";
20
20
  import { PublicKey } from "@solana/web3.js";
21
21
  import { USDC_MINT } from "../../src/constants";
22
- import { positionStateWithLatestPrices } from "../../src/utils/solauto/generalUtils";
23
22
 
24
23
  describe("Solauto Marginfi tests", async () => {
25
24
  // const signer = setupTest();
@@ -117,8 +117,8 @@ async function getFakePosition(
117
117
  const supplyUsd = 1000;
118
118
  const maxLtvBps = 6400;
119
119
  const liqThresholdBps = 8181;
120
- client.solautoPositionState = await positionStateWithPrices({
121
- state: createFakePositionState(
120
+ client.solautoPositionState = await positionStateWithPrices(
121
+ createFakePositionState(
122
122
  {
123
123
  amountUsedBaseUnit: toBaseUnit(supplyUsd / supplyPrice, 9),
124
124
  decimals: 9,
@@ -139,8 +139,8 @@ async function getFakePosition(
139
139
  },
140
140
  maxLtvBps,
141
141
  liqThresholdBps
142
- ),
143
- });
142
+ )
143
+ );
144
144
 
145
145
  client.solautoPositionData = {
146
146
  positionId: [1],